Skip to content

Commit e351fee

Browse files
committed
build: isolate publint nix package
Build the Nix publint tool from a synthetic pnpm project instead of the repository workspace manifests and lockfile. This keeps the tool package independent from apps/ccusage/package.json while still using pnpm to fetch and install publint.
1 parent 70f1ccd commit e351fee

3 files changed

Lines changed: 90 additions & 53 deletions

File tree

‎nix/checks.nix‎

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -143,44 +143,35 @@ in
143143
const fs = require("node:fs");
144144
const path = require("node:path");
145145
146-
function touchPackageFile(packageDir, relativePath, executable = false) {
147-
if (!relativePath || relativePath.includes("*")) {
148-
return;
149-
}
146+
const generatedArtifacts = new Map([
147+
["@ccusage/ccusage-darwin-arm64", ["bin/ccusage"]],
148+
["@ccusage/ccusage-darwin-x64", ["bin/ccusage"]],
149+
["@ccusage/ccusage-linux-arm64", ["bin/ccusage"]],
150+
["@ccusage/ccusage-linux-x64", ["bin/ccusage"]],
151+
["@ccusage/ccusage-win32-arm64", ["bin/ccusage.exe"]],
152+
["@ccusage/ccusage-win32-x64", ["bin/ccusage.exe"]],
153+
]);
150154
151-
const normalizedPath = relativePath.replace(/^\.\//, "");
152-
const targetPath = path.join(packageDir, normalizedPath);
155+
function touchGeneratedFile(packageDir, relativePath) {
156+
const targetPath = path.join(packageDir, relativePath);
153157
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
154158
if (!fs.existsSync(targetPath)) {
155-
fs.writeFileSync(targetPath, executable ? "#!/usr/bin/env node\n" : "");
159+
fs.writeFileSync(targetPath, "");
156160
}
157-
if (executable || normalizedPath.startsWith("bin/")) {
161+
if (!relativePath.endsWith(".exe")) {
158162
fs.chmodSync(targetPath, 0o755);
159163
}
160164
}
161165
162-
function touchBinEntries(packageDir, bin) {
163-
if (typeof bin === "string") {
164-
touchPackageFile(packageDir, bin, true);
165-
return;
166-
}
167-
if (bin && typeof bin === "object") {
168-
for (const value of Object.values(bin)) {
169-
touchPackageFile(packageDir, value, true);
170-
}
171-
}
172-
}
173-
174166
for (const manifestPath of process.argv.slice(2)) {
175167
const packageDir = path.dirname(manifestPath);
176168
const packageJson = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
177-
if (Array.isArray(packageJson.files)) {
178-
for (const file of packageJson.files) {
179-
touchPackageFile(packageDir, file);
169+
const files = new Set(packageJson.files ?? []);
170+
for (const relativePath of generatedArtifacts.get(packageJson.name) ?? []) {
171+
if (files.has(relativePath)) {
172+
touchGeneratedFile(packageDir, relativePath);
180173
}
181174
}
182-
touchBinEntries(packageDir, packageJson.bin);
183-
touchBinEntries(packageDir, packageJson.publishConfig?.bin);
184175
}
185176
EOF
186177

‎nix/packages.nix‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ in
3333
models-dev-pricing = pkgs.callPackage ../nix/models-dev-pricing.nix {
3434
modelsDevSrc = inputs.models-dev;
3535
};
36-
publint = pkgs.callPackage ../nix/publint.nix {
37-
inherit root;
38-
};
36+
publint = pkgs.callPackage ../nix/publint.nix { };
3937
in
4038
{
4139
apps = {

‎nix/publint.nix‎

Lines changed: 73 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,83 @@
55
nodejs,
66
pnpmConfigHook,
77
pnpm_11,
8-
root,
8+
runCommand,
99
stdenvNoCC,
1010
}:
1111
let
1212
pnpm = pnpm_11.override { inherit nodejs; };
13+
src = runCommand "publint-pnpm-src" { } ''
14+
mkdir -p "$out"
15+
cat > "$out/package.json" <<'EOF'
16+
{"name":"publint-nix","version":"0.0.0","private":true,"devDependencies":{"publint":"0.3.12"}}
17+
EOF
18+
cat > "$out/pnpm-lock.yaml" <<'EOF'
19+
lockfileVersion: '9.0'
20+
21+
settings:
22+
autoInstallPeers: true
23+
excludeLinksFromLockfile: false
24+
25+
importers:
26+
27+
.:
28+
devDependencies:
29+
publint:
30+
specifier: 0.3.12
31+
version: 0.3.12
32+
33+
packages:
34+
35+
'@publint/[email protected]':
36+
resolution: {integrity: sha512-HDVTWq3H0uTXiU0eeSQntcVUTPP3GamzeXI41+x7uU9J65JgWQh3qWZHblR1i0npXfFtF+mxBiU2nJH8znxWnQ==}
37+
engines: {node: '>=18'}
38+
39+
40+
resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==}
41+
engines: {node: '>=4'}
42+
43+
44+
resolution: {integrity: sha512-61A5ThoTiDG/C8s8UMZwSorAGwMJ0ERVGj2OjoW5pAalsNOg15+iQiPzrLJ4jhZ1HJzmC2PIHT2oEiH3R5fzNA==}
45+
46+
47+
resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==}
48+
49+
50+
resolution: {integrity: sha512-1w3MMtL9iotBjm1mmXtG3Nk06wnq9UhGNRpQ2j6n1Zq7YAD6gnxMMZMIxlRPAydVjVbjSm+n0lhwqsD1m4LD5w==}
51+
engines: {node: '>=18'}
52+
hasBin: true
53+
54+
55+
resolution: {integrity: sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A==}
56+
engines: {node: '>=6'}
57+
58+
snapshots:
59+
60+
'@publint/[email protected]': {}
61+
62+
63+
64+
65+
66+
67+
68+
69+
dependencies:
70+
'@publint/pack': 0.1.4
71+
package-manager-detector: 1.6.0
72+
picocolors: 1.1.1
73+
sade: 1.8.1
74+
75+
76+
dependencies:
77+
mri: 1.2.0
78+
EOF
79+
'';
1380
in
1481
stdenvNoCC.mkDerivation (finalAttrs: {
1582
pname = "publint";
1683
version = "0.3.12";
17-
18-
src = lib.fileset.toSource {
19-
inherit root;
20-
fileset = lib.fileset.unions [
21-
(root + /package.json)
22-
(root + /pnpm-lock.yaml)
23-
(root + /pnpm-workspace.yaml)
24-
(root + /apps/ccusage/package.json)
25-
(root + /packages/ccusage-darwin-arm64/package.json)
26-
(root + /packages/ccusage-darwin-x64/package.json)
27-
(root + /packages/ccusage-linux-arm64/package.json)
28-
(root + /packages/ccusage-linux-x64/package.json)
29-
(root + /packages/ccusage-win32-arm64/package.json)
30-
(root + /packages/ccusage-win32-x64/package.json)
31-
];
32-
};
84+
inherit src;
3385

3486
nativeBuildInputs = [
3587
makeWrapper
@@ -38,17 +90,15 @@ stdenvNoCC.mkDerivation (finalAttrs: {
3890
pnpmConfigHook
3991
];
4092

41-
pnpmWorkspaces = [ "ccusage" ];
4293
pnpmDeps = fetchPnpmDeps {
4394
inherit (finalAttrs)
4495
pname
4596
version
4697
src
47-
pnpmWorkspaces
4898
;
4999
inherit pnpm;
50100
fetcherVersion = 3;
51-
hash = "sha256-KwScYWv7kwS6Wh+MAaX+JcStVXEqNXzncTSJ5rugTXU=";
101+
hash = "sha256-TSLDCjiXj131uLlLNegm6M4cFEgJtjmhNtHDtoHKm6E=";
52102
};
53103

54104
dontBuild = true;
@@ -57,18 +107,16 @@ stdenvNoCC.mkDerivation (finalAttrs: {
57107
runHook preInstall
58108
59109
toolRoot="$out/lib/publint"
60-
mkdir -p "$toolRoot/apps" "$out/bin"
110+
mkdir -p "$toolRoot" "$out/bin"
61111
cp -R node_modules "$toolRoot/node_modules"
62-
cp -R apps/ccusage "$toolRoot/apps/ccusage"
63-
cp -R packages "$toolRoot/packages"
64-
makeWrapper "$toolRoot/apps/ccusage/node_modules/.bin/publint" "$out/bin/publint" \
112+
makeWrapper "$toolRoot/node_modules/.bin/publint" "$out/bin/publint" \
65113
--prefix PATH : ${lib.makeBinPath [ nodejs ]}
66114
67115
runHook postInstall
68116
'';
69117

70118
meta = {
71-
description = "Publint from the ccusage pnpm lockfile";
119+
description = "Lint packaging errors";
72120
homepage = "https://publint.dev";
73121
license = lib.licenses.mit;
74122
mainProgram = "publint";

0 commit comments

Comments
 (0)