@smoothbricks/nx-plugin 0.4.6 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAKL,yBAAyB,EAW1B,MAAM,sBAAsB,CAAC;AAa9B,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAmDrC,KAAK,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;AACxC,KAAK,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1C,UAAU,YAAY;IACpB,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,EAAE,gBAAgB,CAAC;CAChC;AAoGD,UAAU,oBAAqB,SAAQ,YAAY;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB;AA0CD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,oBAAoB,GAAG,MAAM,CAEhF;AA+KD,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAEvG;AAED,eAAO,MAAM,aAAa,EAAE,aAG3B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AAKlC,OAAO,EAKL,yBAAyB,EAW1B,MAAM,sBAAsB,CAAC;AAa9B,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAmDrC,KAAK,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;AACxC,KAAK,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1C,UAAU,YAAY;IACpB,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,EAAE,gBAAgB,CAAC;CAChC;AAwHD,UAAU,oBAAqB,SAAQ,YAAY;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB;AA0CD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,oBAAoB,GAAG,MAAM,CAEhF;AA+KD,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAEvG;AAED,eAAO,MAAM,aAAa,EAAE,aAG3B,CAAC"}
package/dist/index.js CHANGED
@@ -116,7 +116,14 @@ const CARGO_INPUTS = [
116
116
  '{projectRoot}/scripts/*.sh',
117
117
  '!{projectRoot}/**/target/**',
118
118
  ];
119
- const CARGO_OUTPUT_INPUTS = [...CARGO_INPUTS, '{projectRoot}/package.json', '{workspaceRoot}/bun.lock'];
119
+ // A Cargo output is a function of Rust sources and the toolchain, not of the
120
+ // npm package that ships it. `{projectRoot}/package.json` and the lockfile
121
+ // used to be inputs here, and a release bumps exactly those two (the version
122
+ // step runs before the build), so every publish recompiled every native
123
+ // binary on every platform for a change to a version string. What the N-API
124
+ // build really reads is the package's `napi` block (binary name, targets) and
125
+ // the `@napi-rs/cli` it runs; those are hashed as such by napiInputs().
126
+ const CARGO_OUTPUT_INPUTS = CARGO_INPUTS;
120
127
  const REPO_ROOT_CARGO_OUTPUT_INPUTS = [
121
128
  '{workspaceRoot}/**/*.rs',
122
129
  '{workspaceRoot}/**/Cargo.toml',
@@ -124,8 +131,6 @@ const REPO_ROOT_CARGO_OUTPUT_INPUTS = [
124
131
  '{workspaceRoot}/**/.cargo/config.toml',
125
132
  '{workspaceRoot}/scripts/*.sh',
126
133
  '!{workspaceRoot}/**/target/**',
127
- '{projectRoot}/package.json',
128
- '{workspaceRoot}/bun.lock',
129
134
  ];
130
135
  const CARGO_ENVIRONMENT_INPUT = {
131
136
  runtime: `bun -e 'const fs = require("node:fs"); const path = require("node:path"); const home = process.env.CARGO_HOME || path.join(require("node:os").homedir(), ".cargo"); console.log(JSON.stringify({env: Object.entries(process.env).filter(([name]) => /^(?:CARGO_|RUST|NEXTEST_|CLIPPY_|CC(?:_|$)|CXX(?:_|$)|AR(?:_|$)|CFLAGS|CXXFLAGS|CPPFLAGS|LDFLAGS|PKG_CONFIG|TARGET_|HOST_)/.test(name)).sort(([a], [b]) => a.localeCompare(b)), config: ["config", "config.toml"].map(name => { const file = path.join(home, name); return fs.existsSync(file) ? fs.readFileSync(file, "utf8") : null; })}));'`,
@@ -148,7 +153,22 @@ function targetCommandText(target) {
148
153
  ...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
149
154
  ].join('\n');
150
155
  }
151
- const NAPI_INPUTS = CARGO_OUTPUT_INPUTS;
156
+ /**
157
+ * The N-API build's inputs beyond the Cargo sources: the package's `napi`
158
+ * block, which names the binary and the targets, and the napi CLI's resolved
159
+ * version from the lockfile. Neither the package version nor any other
160
+ * lockfile entry is part of the artifact.
161
+ */
162
+ function napiInputs(projectRoot, repoRooted) {
163
+ // Runtime inputs execute from the workspace root, so the manifest is named
164
+ // by its path from there whichever way the Cargo invocation is rooted.
165
+ const packageJson = `./${posix.join(projectRoot, 'package.json')}`;
166
+ return [
167
+ ...(repoRooted ? REPO_ROOT_CARGO_OUTPUT_INPUTS : CARGO_OUTPUT_INPUTS),
168
+ { runtime: `bun -e 'console.log(JSON.stringify(require(${JSON.stringify(packageJson)}).napi ?? null))'` },
169
+ { externalDependencies: ['@napi-rs/cli'] },
170
+ ];
171
+ }
152
172
  const NAPI_TARGET_CONVENTIONS = {
153
173
  'aarch64-apple-darwin': {
154
174
  architecture: 'arm64',
@@ -549,14 +569,23 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
549
569
  cache: cargoWorkspace.inputsCache,
550
570
  })))).flat()),
551
571
  ];
552
- targets[CARGO_TEST_COMPILE_TARGET].inputs = workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS;
572
+ // Generated crate sources (wire codecs, vocabularies, fixtures) are
573
+ // gitignored and invisible to nx's file hasher; they reach these targets
574
+ // as the outputs of the targets a repository adds to `dependsOn`. Hashing
575
+ // those outputs here means a repository never has to restate `inputs` to
576
+ // add them - and a restated `inputs` REPLACES this union with the root
577
+ // project's `default`, which owns no crate file, so the archive then
578
+ // cache-hits against edited crates while every per-crate test reruns on
579
+ // the stale binary. That verdict is wrong, not merely slow.
580
+ const workspaceCargoInputs = [
581
+ ...(workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS),
582
+ { dependentTasksOutputFiles: '**/*', transitive: false },
583
+ ];
584
+ targets[CARGO_TEST_COMPILE_TARGET].inputs = workspaceCargoInputs;
553
585
  targets[CARGO_TEST_ARCHIVE_TARGET] = createCargoTestArchiveTarget(cargoWorkspaceRoot, nextestToolConfigArg(workspaceRoot, cargoWorkspaceRoot, PLUGIN_NEXTEST_CONFIG));
554
586
  // `archive.include` lives in the repository's nextest config, so that file
555
587
  // decides what the archive CONTAINS, not merely how a run behaves.
556
- targets[CARGO_TEST_ARCHIVE_TARGET].inputs = [
557
- ...(workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS),
558
- `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`,
559
- ];
588
+ targets[CARGO_TEST_ARCHIVE_TARGET].inputs = [...workspaceCargoInputs, `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`];
560
589
  const aggregateDependencies = cargoWorkspace.packages.flatMap((plan) => plan.pieces.map((piece) => cargoTargetDependency(projectName, {
561
590
  projectName: plan.package.projectName,
562
591
  targetName: piece.targetName,
@@ -574,7 +603,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
574
603
  targets['cargo-lint'] = {
575
604
  executor: 'nx:run-commands',
576
605
  cache: true,
577
- inputs: workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS,
606
+ inputs: workspaceCargoInputs,
578
607
  outputs: [],
579
608
  options: {
580
609
  commands: ['cargo fmt --all --check', CARGO_LINT_CLIPPY_COMMAND],
@@ -613,7 +642,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
613
642
  targets[CARGO_CROSS_LINT_TARGET] = {
614
643
  executor: 'nx:run-commands',
615
644
  cache: true,
616
- inputs: workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS,
645
+ inputs: workspaceCargoInputs,
617
646
  outputs: [],
618
647
  options: {
619
648
  command: CARGO_CROSS_LINT_COMMAND,
@@ -1112,7 +1141,7 @@ function createNapiTargets(projectRoot, config, hostPlatform, repoRooted) {
1112
1141
  // that stale local artifacts can mask for months.
1113
1142
  const packageJsonPath = repoRooted ? posix.join(projectRoot, 'package.json') : 'package.json';
1114
1143
  const commonCommand = `--manifest-path ${config.manifestPath} --package ${config.cargoPackage} --package-json-path ${packageJsonPath}`;
1115
- const cargoInputs = repoRooted ? REPO_ROOT_CARGO_OUTPUT_INPUTS : NAPI_INPUTS;
1144
+ const cargoInputs = napiInputs(projectRoot, repoRooted);
1116
1145
  const cargoCwd = repoRooted ? '.' : projectRoot;
1117
1146
  // A repository-root Cargo invocation runs outside the owning npm package, so
1118
1147
  // Nx's root-only PATH cannot resolve that package's napi CLI.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
package/src/index.test.ts CHANGED
@@ -395,6 +395,16 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
395
395
  expect(targets[name]?.dependsOn).toContain('cargo-fetch');
396
396
  }
397
397
  expect(targets['cargo-sweep']?.dependsOn).toBeUndefined();
398
+ // The archive and the compile it stands for hash every crate's sources
399
+ // AND the outputs of the targets they depend on: generated crate inputs
400
+ // are gitignored, so a repository that had to restate `inputs` to add
401
+ // them replaced the crate union with the root's `default` and shipped a
402
+ // stale archive to every per-crate test.
403
+ for (const name of ['cargo-test-compile', 'cargo-test-archive', 'cargo-lint', CARGO_CROSS_LINT_TARGET]) {
404
+ const inputs = targets[name]?.inputs ?? [];
405
+ expect(inputs).toContainEqual({ dependentTasksOutputFiles: '**/*', transitive: false });
406
+ expect(inputs).toContain('{projectRoot}/crates/ferris-core/**/*');
407
+ }
398
408
  expect(targets['cargo-test-compile']?.executor).toBe('nx:run-commands');
399
409
  expect(targets['cargo-test-compile']?.cache).toBe(false);
400
410
  expect(targets['cargo-test-compile']?.outputs).toEqual([]);
@@ -682,6 +692,16 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
682
692
  // its tests load the artifact `napi-debug` writes into `target/debug`.
683
693
  expect(native['cargo-test-native-napi']?.dependsOn).toEqual([rootFetch, rootArchive, 'napi-debug']);
684
694
  expect(native['napi-debug']?.dependsOn).toContainEqual(rootCompile);
695
+ // The addon depends on the package's napi block and the napi CLI's version,
696
+ // never on the package version or the whole lockfile: a release bumps both
697
+ // before it builds, and that must not recompile the native code.
698
+ const napiInputs = native['napi-debug']?.inputs ?? [];
699
+ expect(napiInputs).toContainEqual({ externalDependencies: ['@napi-rs/cli'] });
700
+ expect(
701
+ napiInputs.some((input) => typeof input === 'object' && 'runtime' in input && input.runtime.includes('.napi')),
702
+ ).toBe(true);
703
+ expect(napiInputs).not.toContain('{workspaceRoot}/bun.lock');
704
+ expect(napiInputs.some((input) => typeof input === 'string' && input.endsWith('/package.json'))).toBe(false);
685
705
  expect(native['napi-debug']?.options).toMatchObject({
686
706
  cwd: '.',
687
707
  command:
@@ -881,16 +901,15 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
881
901
 
882
902
  const targets = await inferProjectTargets(workspace, 'packages/git-do/package.json');
883
903
 
904
+ // A release bumps package.json and the lockfile before it builds; neither
905
+ // is part of a wasm artifact, so neither may be an input.
906
+ expect(targets['cargo-wasm']?.inputs).not.toContain('{projectRoot}/package.json');
907
+ expect(targets['cargo-wasm']?.inputs).not.toContain('{workspaceRoot}/bun.lock');
884
908
  expect(targets['cargo-wasm']).toMatchObject({
885
909
  executor: 'nx:run-commands',
886
910
  cache: true,
887
911
  dependsOn: ['cargo-fetch', '^build'],
888
- inputs: expect.arrayContaining([
889
- '{projectRoot}/**/*.rs',
890
- '{projectRoot}/**/Cargo.toml',
891
- '{projectRoot}/package.json',
892
- '{workspaceRoot}/bun.lock',
893
- ]),
912
+ inputs: expect.arrayContaining(['{projectRoot}/**/*.rs', '{projectRoot}/**/Cargo.toml']),
894
913
  outputs: ['{projectRoot}/generated/wasm'],
895
914
  options: {
896
915
  commands: [
package/src/index.ts CHANGED
@@ -163,7 +163,14 @@ const CARGO_INPUTS = [
163
163
  '{projectRoot}/scripts/*.sh',
164
164
  '!{projectRoot}/**/target/**',
165
165
  ];
166
- const CARGO_OUTPUT_INPUTS = [...CARGO_INPUTS, '{projectRoot}/package.json', '{workspaceRoot}/bun.lock'];
166
+ // A Cargo output is a function of Rust sources and the toolchain, not of the
167
+ // npm package that ships it. `{projectRoot}/package.json` and the lockfile
168
+ // used to be inputs here, and a release bumps exactly those two (the version
169
+ // step runs before the build), so every publish recompiled every native
170
+ // binary on every platform for a change to a version string. What the N-API
171
+ // build really reads is the package's `napi` block (binary name, targets) and
172
+ // the `@napi-rs/cli` it runs; those are hashed as such by napiInputs().
173
+ const CARGO_OUTPUT_INPUTS = CARGO_INPUTS;
167
174
  const REPO_ROOT_CARGO_OUTPUT_INPUTS = [
168
175
  '{workspaceRoot}/**/*.rs',
169
176
  '{workspaceRoot}/**/Cargo.toml',
@@ -171,8 +178,6 @@ const REPO_ROOT_CARGO_OUTPUT_INPUTS = [
171
178
  '{workspaceRoot}/**/.cargo/config.toml',
172
179
  '{workspaceRoot}/scripts/*.sh',
173
180
  '!{workspaceRoot}/**/target/**',
174
- '{projectRoot}/package.json',
175
- '{workspaceRoot}/bun.lock',
176
181
  ];
177
182
  const CARGO_ENVIRONMENT_INPUT = {
178
183
  runtime: `bun -e 'const fs = require("node:fs"); const path = require("node:path"); const home = process.env.CARGO_HOME || path.join(require("node:os").homedir(), ".cargo"); console.log(JSON.stringify({env: Object.entries(process.env).filter(([name]) => /^(?:CARGO_|RUST|NEXTEST_|CLIPPY_|CC(?:_|$)|CXX(?:_|$)|AR(?:_|$)|CFLAGS|CXXFLAGS|CPPFLAGS|LDFLAGS|PKG_CONFIG|TARGET_|HOST_)/.test(name)).sort(([a], [b]) => a.localeCompare(b)), config: ["config", "config.toml"].map(name => { const file = path.join(home, name); return fs.existsSync(file) ? fs.readFileSync(file, "utf8") : null; })}));'`,
@@ -197,7 +202,22 @@ function targetCommandText(target: TargetConfiguration): string {
197
202
  ...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
198
203
  ].join('\n');
199
204
  }
200
- const NAPI_INPUTS = CARGO_OUTPUT_INPUTS;
205
+ /**
206
+ * The N-API build's inputs beyond the Cargo sources: the package's `napi`
207
+ * block, which names the binary and the targets, and the napi CLI's resolved
208
+ * version from the lockfile. Neither the package version nor any other
209
+ * lockfile entry is part of the artifact.
210
+ */
211
+ function napiInputs(projectRoot: string, repoRooted: boolean): TargetConfiguration['inputs'] {
212
+ // Runtime inputs execute from the workspace root, so the manifest is named
213
+ // by its path from there whichever way the Cargo invocation is rooted.
214
+ const packageJson = `./${posix.join(projectRoot, 'package.json')}`;
215
+ return [
216
+ ...(repoRooted ? REPO_ROOT_CARGO_OUTPUT_INPUTS : CARGO_OUTPUT_INPUTS),
217
+ { runtime: `bun -e 'console.log(JSON.stringify(require(${JSON.stringify(packageJson)}).napi ?? null))'` },
218
+ { externalDependencies: ['@napi-rs/cli'] },
219
+ ];
220
+ }
201
221
 
202
222
  interface NapiTargetConvention extends NapiPlatform {
203
223
  outputName: string;
@@ -688,17 +708,26 @@ async function createProjectTargets(
688
708
  ).flat(),
689
709
  ),
690
710
  ];
691
- targets[CARGO_TEST_COMPILE_TARGET].inputs = workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS;
711
+ // Generated crate sources (wire codecs, vocabularies, fixtures) are
712
+ // gitignored and invisible to nx's file hasher; they reach these targets
713
+ // as the outputs of the targets a repository adds to `dependsOn`. Hashing
714
+ // those outputs here means a repository never has to restate `inputs` to
715
+ // add them - and a restated `inputs` REPLACES this union with the root
716
+ // project's `default`, which owns no crate file, so the archive then
717
+ // cache-hits against edited crates while every per-crate test reruns on
718
+ // the stale binary. That verdict is wrong, not merely slow.
719
+ const workspaceCargoInputs: TargetConfiguration['inputs'] = [
720
+ ...(workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS),
721
+ { dependentTasksOutputFiles: '**/*', transitive: false },
722
+ ];
723
+ targets[CARGO_TEST_COMPILE_TARGET].inputs = workspaceCargoInputs;
692
724
  targets[CARGO_TEST_ARCHIVE_TARGET] = createCargoTestArchiveTarget(
693
725
  cargoWorkspaceRoot,
694
726
  nextestToolConfigArg(workspaceRoot, cargoWorkspaceRoot, PLUGIN_NEXTEST_CONFIG),
695
727
  );
696
728
  // `archive.include` lives in the repository's nextest config, so that file
697
729
  // decides what the archive CONTAINS, not merely how a run behaves.
698
- targets[CARGO_TEST_ARCHIVE_TARGET].inputs = [
699
- ...(workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS),
700
- `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`,
701
- ];
730
+ targets[CARGO_TEST_ARCHIVE_TARGET].inputs = [...workspaceCargoInputs, `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`];
702
731
  const aggregateDependencies = cargoWorkspace.packages.flatMap((plan) =>
703
732
  plan.pieces.map((piece) =>
704
733
  cargoTargetDependency(projectName, {
@@ -720,7 +749,7 @@ async function createProjectTargets(
720
749
  targets['cargo-lint'] = {
721
750
  executor: 'nx:run-commands',
722
751
  cache: true,
723
- inputs: workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS,
752
+ inputs: workspaceCargoInputs,
724
753
  outputs: [],
725
754
  options: {
726
755
  commands: ['cargo fmt --all --check', CARGO_LINT_CLIPPY_COMMAND],
@@ -759,7 +788,7 @@ async function createProjectTargets(
759
788
  targets[CARGO_CROSS_LINT_TARGET] = {
760
789
  executor: 'nx:run-commands',
761
790
  cache: true,
762
- inputs: workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS,
791
+ inputs: workspaceCargoInputs,
763
792
  outputs: [],
764
793
  options: {
765
794
  command: CARGO_CROSS_LINT_COMMAND,
@@ -1341,7 +1370,7 @@ function createNapiTargets(
1341
1370
  // that stale local artifacts can mask for months.
1342
1371
  const packageJsonPath = repoRooted ? posix.join(projectRoot, 'package.json') : 'package.json';
1343
1372
  const commonCommand = `--manifest-path ${config.manifestPath} --package ${config.cargoPackage} --package-json-path ${packageJsonPath}`;
1344
- const cargoInputs = repoRooted ? REPO_ROOT_CARGO_OUTPUT_INPUTS : NAPI_INPUTS;
1373
+ const cargoInputs = napiInputs(projectRoot, repoRooted);
1345
1374
  const cargoCwd = repoRooted ? '.' : projectRoot;
1346
1375
  // A repository-root Cargo invocation runs outside the owning npm package, so
1347
1376
  // Nx's root-only PATH cannot resolve that package's napi CLI.