@smoothbricks/nx-plugin 0.4.19 → 0.4.20

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,12 +1,2 @@
1
- /**
2
- * Cargo owns resolution, including workspace inheritance, target dependencies,
3
- * patches, and transitive path dependencies. A locked offline query observes
4
- * that graph without fetching dependencies or changing the lockfile. Git and
5
- * registry packages are immutable inputs already identified by Cargo.lock.
6
- *
7
- * This covers Rust sources and Cargo configuration, matching the plugin's
8
- * in-workspace Rust inputs. Build scripts' other data/environment inputs remain
9
- * explicit Nx inputs, just as they are for in-workspace crates.
10
- */
11
1
  export declare function hashCargoPathInputs(manifestPath: string, workspaceRoot: string): Promise<string>;
12
2
  //# sourceMappingURL=cargo-source-hash.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cargo-source-hash.d.ts","sourceRoot":"","sources":["../src/cargo-source-hash.ts"],"names":[],"mappings":"AA+BA;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAgGtG"}
1
+ {"version":3,"file":"cargo-source-hash.d.ts","sourceRoot":"","sources":["../src/cargo-source-hash.ts"],"names":[],"mappings":"AAiDA,wBAAsB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAgGtG"}
@@ -116,9 +116,16 @@ const ancestorInputs = ['Cargo.toml', '.cargo/config', '.cargo/config.toml'];
116
116
  * in-workspace Rust inputs. Build scripts' other data/environment inputs remain
117
117
  * explicit Nx inputs, just as they are for in-workspace crates.
118
118
  */
119
+ // Nx hashes a runtime input's stdout AND stderr. Cargo reports lock contention
120
+ // on stderr ("Blocking waiting for file lock on package cache") a
121
+ // timing-dependent number of times when Nx hashes many tasks at once, which
122
+ // made one unchanged tree produce four different task hashes per run. Cargo's
123
+ // stderr is kept for the failure path only, where execFileSync attaches it to
124
+ // the thrown error.
125
+ const CARGO_STDIO = ['ignore', 'pipe', 'pipe'];
119
126
  export async function hashCargoPathInputs(manifestPath, workspaceRoot) {
120
127
  const root = await realpath(workspaceRoot);
121
- const metadata = parseMetadata(execFileSync('cargo', ['metadata', '--format-version', '1', '--locked', '--offline', '--manifest-path', resolve(manifestPath)], { cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, stdio: ['ignore', 'pipe', 'inherit'] }));
128
+ const metadata = parseMetadata(execFileSync('cargo', ['metadata', '--format-version', '1', '--locked', '--offline', '--manifest-path', resolve(manifestPath)], { cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, stdio: CARGO_STDIO }));
122
129
  const cargoRoot = await realpath(metadata.workspace_root);
123
130
  const directories = new Set();
124
131
  const files = new Set();
@@ -143,7 +150,7 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot) {
143
150
  files.add(manifest);
144
151
  // Cargo resolves explicit package.workspace ownership as well as ancestor
145
152
  // workspaces. Metadata's workspace_root describes only the invoking root.
146
- const governingManifest = execFileSync('cargo', ['locate-project', '--workspace', '--manifest-path', manifest, '--message-format', 'plain'], { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'inherit'] }).trim();
153
+ const governingManifest = execFileSync('cargo', ['locate-project', '--workspace', '--manifest-path', manifest, '--message-format', 'plain'], { cwd: root, encoding: 'utf8', stdio: CARGO_STDIO }).trim();
147
154
  files.add(await realpath(governingManifest));
148
155
  for (const target of pkg.targets)
149
156
  files.add(await realpath(target.src_path));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoothbricks/nx-plugin",
3
- "version": "0.4.19",
3
+ "version": "0.4.20",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./loader.js",
@@ -49,3 +49,44 @@ it.each(['app', '.'])('invalidates transitive and inherited Cargo inputs with Nx
49
49
  await rm(root, { recursive: true, force: true });
50
50
  }
51
51
  });
52
+
53
+ it('the runtime input is byte-identical under cargo lock contention: nothing on stderr', async () => {
54
+ // Nx hashes a runtime input's stdout and stderr together, and hashes once per
55
+ // distinct task env, so the bin runs many times at once at the start of a
56
+ // run. Cargo reports package-cache lock contention on stderr; a private
57
+ // CARGO_HOME makes that contention real here.
58
+ const root = await mkdtemp(join(tmpdir(), 'cargo-hash-'));
59
+ const manifest = join(root, 'Cargo.toml');
60
+ try {
61
+ await mkdir(join(root, 'src'), { recursive: true });
62
+ await writeFile(manifest, '[package]\nname="app"\nversion="0.1.0"\nedition="2021"\n[workspace]\n');
63
+ await writeFile(join(root, 'src', 'lib.rs'), 'pub fn run() {}\n');
64
+ const env = { ...process.env, CARGO_HOME: join(root, '.cargo-home') };
65
+ execFileSync('cargo', ['generate-lockfile', '--offline', '--manifest-path', manifest], { stdio: 'pipe', env });
66
+ // The built bin under node, exactly as nx.json's runtime input invokes it (test depends on build).
67
+ const bin = join(import.meta.dir, '..', 'dist', 'bin', 'smoo-nx-cargo-hash.js');
68
+ const runs = await Promise.all(
69
+ Array.from({ length: 8 }, async () => {
70
+ const proc = Bun.spawn(['node', bin, manifest], {
71
+ cwd: root,
72
+ env,
73
+ stdout: 'pipe',
74
+ stderr: 'pipe',
75
+ });
76
+ const [stdout, stderr, exitCode] = await Promise.all([
77
+ new Response(proc.stdout).text(),
78
+ new Response(proc.stderr).text(),
79
+ proc.exited,
80
+ ]);
81
+ return { stdout, stderr, exitCode };
82
+ }),
83
+ );
84
+ for (const run of runs) {
85
+ expect(run.exitCode).toBe(0);
86
+ expect(run.stderr).toBe('');
87
+ }
88
+ expect(new Set(runs.map((run) => run.stdout)).size).toBe(1);
89
+ } finally {
90
+ await rm(root, { recursive: true, force: true });
91
+ }
92
+ });
@@ -39,13 +39,21 @@ const ancestorInputs = ['Cargo.toml', '.cargo/config', '.cargo/config.toml'];
39
39
  * in-workspace Rust inputs. Build scripts' other data/environment inputs remain
40
40
  * explicit Nx inputs, just as they are for in-workspace crates.
41
41
  */
42
+ // Nx hashes a runtime input's stdout AND stderr. Cargo reports lock contention
43
+ // on stderr ("Blocking waiting for file lock on package cache") a
44
+ // timing-dependent number of times when Nx hashes many tasks at once, which
45
+ // made one unchanged tree produce four different task hashes per run. Cargo's
46
+ // stderr is kept for the failure path only, where execFileSync attaches it to
47
+ // the thrown error.
48
+ const CARGO_STDIO: ['ignore', 'pipe', 'pipe'] = ['ignore', 'pipe', 'pipe'];
49
+
42
50
  export async function hashCargoPathInputs(manifestPath: string, workspaceRoot: string): Promise<string> {
43
51
  const root = await realpath(workspaceRoot);
44
52
  const metadata = parseMetadata(
45
53
  execFileSync(
46
54
  'cargo',
47
55
  ['metadata', '--format-version', '1', '--locked', '--offline', '--manifest-path', resolve(manifestPath)],
48
- { cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, stdio: ['ignore', 'pipe', 'inherit'] },
56
+ { cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, stdio: CARGO_STDIO },
49
57
  ),
50
58
  );
51
59
  const cargoRoot = await realpath(metadata.workspace_root);
@@ -76,7 +84,7 @@ export async function hashCargoPathInputs(manifestPath: string, workspaceRoot: s
76
84
  const governingManifest = execFileSync(
77
85
  'cargo',
78
86
  ['locate-project', '--workspace', '--manifest-path', manifest, '--message-format', 'plain'],
79
- { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'inherit'] },
87
+ { cwd: root, encoding: 'utf8', stdio: CARGO_STDIO },
80
88
  ).trim();
81
89
  files.add(await realpath(governingManifest));
82
90
  for (const target of pkg.targets) files.add(await realpath(target.src_path));