@smoothbricks/nx-plugin 0.4.7 → 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',
@@ -1121,7 +1141,7 @@ function createNapiTargets(projectRoot, config, hostPlatform, repoRooted) {
1121
1141
  // that stale local artifacts can mask for months.
1122
1142
  const packageJsonPath = repoRooted ? posix.join(projectRoot, 'package.json') : 'package.json';
1123
1143
  const commonCommand = `--manifest-path ${config.manifestPath} --package ${config.cargoPackage} --package-json-path ${packageJsonPath}`;
1124
- const cargoInputs = repoRooted ? REPO_ROOT_CARGO_OUTPUT_INPUTS : NAPI_INPUTS;
1144
+ const cargoInputs = napiInputs(projectRoot, repoRooted);
1125
1145
  const cargoCwd = repoRooted ? '.' : projectRoot;
1126
1146
  // A repository-root Cargo invocation runs outside the owning npm package, so
1127
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.7",
3
+ "version": "0.4.8",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
package/src/index.test.ts CHANGED
@@ -692,6 +692,16 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
692
692
  // its tests load the artifact `napi-debug` writes into `target/debug`.
693
693
  expect(native['cargo-test-native-napi']?.dependsOn).toEqual([rootFetch, rootArchive, 'napi-debug']);
694
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);
695
705
  expect(native['napi-debug']?.options).toMatchObject({
696
706
  cwd: '.',
697
707
  command:
@@ -891,16 +901,15 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
891
901
 
892
902
  const targets = await inferProjectTargets(workspace, 'packages/git-do/package.json');
893
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');
894
908
  expect(targets['cargo-wasm']).toMatchObject({
895
909
  executor: 'nx:run-commands',
896
910
  cache: true,
897
911
  dependsOn: ['cargo-fetch', '^build'],
898
- inputs: expect.arrayContaining([
899
- '{projectRoot}/**/*.rs',
900
- '{projectRoot}/**/Cargo.toml',
901
- '{projectRoot}/package.json',
902
- '{workspaceRoot}/bun.lock',
903
- ]),
912
+ inputs: expect.arrayContaining(['{projectRoot}/**/*.rs', '{projectRoot}/**/Cargo.toml']),
904
913
  outputs: ['{projectRoot}/generated/wasm'],
905
914
  options: {
906
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;
@@ -1350,7 +1370,7 @@ function createNapiTargets(
1350
1370
  // that stale local artifacts can mask for months.
1351
1371
  const packageJsonPath = repoRooted ? posix.join(projectRoot, 'package.json') : 'package.json';
1352
1372
  const commonCommand = `--manifest-path ${config.manifestPath} --package ${config.cargoPackage} --package-json-path ${packageJsonPath}`;
1353
- const cargoInputs = repoRooted ? REPO_ROOT_CARGO_OUTPUT_INPUTS : NAPI_INPUTS;
1373
+ const cargoInputs = napiInputs(projectRoot, repoRooted);
1354
1374
  const cargoCwd = repoRooted ? '.' : projectRoot;
1355
1375
  // A repository-root Cargo invocation runs outside the owning npm package, so
1356
1376
  // Nx's root-only PATH cannot resolve that package's napi CLI.