@smoothbricks/nx-plugin 0.4.25 → 0.4.26
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.
- package/README.md +144 -41
- package/dist/bin/smoo-nx-exec.js +3 -14
- package/dist/cargo-closure-input.d.ts +13 -15
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +29 -37
- package/dist/cargo-source-hash.d.ts +12 -7
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +416 -32
- package/dist/cargo-workspace.d.ts +7 -7
- package/dist/cargo-workspace.js +8 -8
- package/dist/ensure-built.d.ts +6 -0
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +79 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +69 -96
- package/dist/managed-assets.d.ts +6 -0
- package/dist/managed-assets.d.ts.map +1 -1
- package/dist/manifest-hash.d.ts.map +1 -1
- package/dist/manifest-hash.js +6 -2
- package/dist/workspace-manifest.d.ts +0 -1
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/managed/raw/envrc +6 -1
- package/managed/raw/tooling/direnv/developer-links.ts +43 -11
- package/managed/raw/tooling/direnv/devenv.smoo.nix +1 -0
- package/managed/raw/tooling/direnv/inherited-devenv.ts +69 -19
- package/managed/raw/tooling/direnv/setup-environment.ts +79 -2
- package/nextest.toml +3 -37
- package/package.json +2 -2
- package/src/__tests__/counted-cargo-process.ts +286 -0
- package/src/__tests__/counted-cargo.ts +711 -0
- package/src/__tests__/fixture-cargo-home.ts +36 -0
- package/src/__tests__/fixture-nx-env.ts +93 -3
- package/src/bin/smoo-nx-exec.ts +3 -14
- package/src/bounded-test-policy.test.ts +0 -1
- package/src/cargo-closure-input.test.ts +313 -15
- package/src/cargo-closure-input.ts +42 -50
- package/src/cargo-resolve-cache.test.ts +975 -0
- package/src/cargo-source-hash.test.ts +17 -3
- package/src/cargo-source-hash.ts +447 -37
- package/src/cargo-workspace.ts +8 -8
- package/src/ensure-built.test.ts +122 -20
- package/src/ensure-built.ts +82 -5
- package/src/index.test.ts +203 -107
- package/src/index.ts +86 -115
- package/src/managed-assets.ts +12 -0
- package/src/manifest-hash.ts +7 -2
- package/src/nextest-partitions.test.ts +150 -0
- package/src/nx-cache-bound.test.ts +114 -0
- package/src/nx-resident-graph-workers.test.ts +121 -0
- package/src/nx-store-resolution.test.ts +98 -0
- package/src/task-history-namespace.test.ts +183 -0
- package/src/workspace-manifest.ts +0 -1
- package/test-timings.json +30 -28
- package/src/__tests__/in-process-nx-index.ts +0 -9
|
@@ -2,13 +2,13 @@ import { realpath } from 'node:fs/promises';
|
|
|
2
2
|
import { isAbsolute, join, posix, relative, sep } from 'node:path';
|
|
3
3
|
|
|
4
4
|
import type { TargetConfiguration } from 'nx/src/devkit-exports.js';
|
|
5
|
-
import { globWithWorkspaceContext } from 'nx/src/utils/workspace-context.js';
|
|
5
|
+
import { globWithWorkspaceContext, globWithWorkspaceContextSync } from 'nx/src/utils/workspace-context.js';
|
|
6
|
+
import { workspaceRoot as daemonWorkspaceRoot } from 'nx/src/utils/workspace-root.js';
|
|
6
7
|
|
|
7
8
|
import {
|
|
8
9
|
CARGO_ANCESTOR_INPUTS,
|
|
9
10
|
type CargoResolve,
|
|
10
11
|
dependencyClosure,
|
|
11
|
-
governingManifest,
|
|
12
12
|
HASH_SKIPPED_DIRECTORIES,
|
|
13
13
|
readCargoResolve,
|
|
14
14
|
} from './cargo-source-hash.js';
|
|
@@ -22,6 +22,22 @@ export const CARGO_CLOSURE_INPUT = 'cargoClosure';
|
|
|
22
22
|
|
|
23
23
|
type Input = NonNullable<TargetConfiguration['inputs']>[number];
|
|
24
24
|
|
|
25
|
+
/** A closure Nx cannot express exactly is a refusal, never a broader cache key. */
|
|
26
|
+
export class CargoClosureInputError extends Error {
|
|
27
|
+
readonly projectRoot: string;
|
|
28
|
+
|
|
29
|
+
constructor(projectRoot: string, cause: unknown) {
|
|
30
|
+
super(
|
|
31
|
+
`Cannot infer ${CARGO_CLOSURE_INPUT} for ${projectRoot}: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
32
|
+
{
|
|
33
|
+
cause,
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
this.name = 'CargoClosureInputError';
|
|
37
|
+
this.projectRoot = projectRoot;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
25
41
|
/**
|
|
26
42
|
* How a runtime input reaches the hash command. Nx runs it with `sh -c` from
|
|
27
43
|
* the workspace root and puts no `node_modules/.bin` on its PATH; a plugin Nx
|
|
@@ -40,17 +56,14 @@ const GLOB_SYNTAX = /[*?[\]{}()!,]/;
|
|
|
40
56
|
* One Cargo workspace as one project-graph computation sees it. `manifest` is
|
|
41
57
|
* the workspace's root manifest relative to the Nx workspace root.
|
|
42
58
|
*/
|
|
43
|
-
export
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
readonly indexed: ReadonlySet<string>;
|
|
52
|
-
}
|
|
53
|
-
| { readonly kind: 'unresolved'; readonly manifest: string };
|
|
59
|
+
export interface CargoClosureSource {
|
|
60
|
+
readonly manifest: string;
|
|
61
|
+
/** The canonical Nx workspace root. */
|
|
62
|
+
readonly root: string;
|
|
63
|
+
readonly cargo: CargoResolve;
|
|
64
|
+
/** Every `Cargo.toml` in Nx's file index, relative to the workspace root. */
|
|
65
|
+
readonly indexed: ReadonlySet<string>;
|
|
66
|
+
}
|
|
54
67
|
|
|
55
68
|
/**
|
|
56
69
|
* Every `Cargo.toml` Nx's workspace file index holds: .gitignore and .nxignore
|
|
@@ -58,40 +71,26 @@ export type CargoClosureSource =
|
|
|
58
71
|
* here has no files a fileset input can hash.
|
|
59
72
|
*/
|
|
60
73
|
export async function indexedCargoManifests(workspaceRoot: string): Promise<ReadonlySet<string>> {
|
|
61
|
-
|
|
74
|
+
const manifests =
|
|
75
|
+
workspaceRoot === daemonWorkspaceRoot
|
|
76
|
+
? await globWithWorkspaceContext(workspaceRoot, ['**/Cargo.toml'])
|
|
77
|
+
: globWithWorkspaceContextSync(workspaceRoot, ['**/Cargo.toml']);
|
|
78
|
+
return new Set(manifests);
|
|
62
79
|
}
|
|
63
80
|
|
|
64
81
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* closure inputs, hashed at run time by the command that reports the same
|
|
69
|
-
* failure wherever a task needs it. Said once here, not once per project.
|
|
82
|
+
* Content-keyed locked offline metadata. A refusal fails graph inference:
|
|
83
|
+
* a stale closure or runtime whole-workspace fallback cannot establish the
|
|
84
|
+
* precise set of cache inputs.
|
|
70
85
|
*/
|
|
71
86
|
export async function resolveCargoClosureSource(
|
|
72
87
|
manifest: string,
|
|
73
88
|
workspaceRoot: string,
|
|
74
89
|
indexed: Promise<ReadonlySet<string>>,
|
|
75
90
|
): Promise<CargoClosureSource> {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const [{ root, cargo }, index] = await Promise.all([
|
|
80
|
-
realpath(workspaceRoot).then(async (root) => ({
|
|
81
|
-
root,
|
|
82
|
-
cargo: await readCargoResolve(join(root, manifest), root),
|
|
83
|
-
})),
|
|
84
|
-
indexed,
|
|
85
|
-
]);
|
|
86
|
-
return { kind: 'resolved', manifest, root, cargo, indexed: index };
|
|
87
|
-
} catch (error) {
|
|
88
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
89
|
-
process.stderr.write(
|
|
90
|
-
`@smoothbricks/nx-plugin: resolving ${manifest} failed (${message.trim().split('\n').slice(0, 3).join(' ')}); ` +
|
|
91
|
-
`every ${CARGO_CLOSURE_INPUT} under it runs smoo-nx-cargo-hash on each hash instead of reading Nx's file index.\n`,
|
|
92
|
-
);
|
|
93
|
-
return { kind: 'unresolved', manifest };
|
|
94
|
-
}
|
|
91
|
+
const [root, index] = await Promise.all([realpath(workspaceRoot), indexed]);
|
|
92
|
+
const cargo = await readCargoResolve(join(root, manifest), root, index);
|
|
93
|
+
return { manifest, root, cargo, indexed: index };
|
|
95
94
|
}
|
|
96
95
|
|
|
97
96
|
/**
|
|
@@ -110,10 +109,9 @@ export async function resolveCargoClosureSource(
|
|
|
110
109
|
* exist. That command resolves the closure again when it runs, so a member
|
|
111
110
|
* that only an edit outside the workspace brings in is still covered.
|
|
112
111
|
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* the
|
|
116
|
-
* reported on stderr.
|
|
112
|
+
* An in-workspace member missing from Nx's file index is a typed refusal,
|
|
113
|
+
* never a whole-workspace runtime hash. Only outside-workspace members need
|
|
114
|
+
* the external-only runtime input.
|
|
117
115
|
*/
|
|
118
116
|
export async function cargoClosureInputs(
|
|
119
117
|
projectRoot: string,
|
|
@@ -138,8 +136,6 @@ export async function cargoClosureInputs(
|
|
|
138
136
|
async function workspaceClosureInputs(projectRoot: string, source: CargoClosureSource): Promise<Input[]> {
|
|
139
137
|
const lock = posix.join('{workspaceRoot}', posix.dirname(source.manifest), 'Cargo.lock');
|
|
140
138
|
const closureArguments = `--closure ${shellWord(projectRoot)} ${shellWord(source.manifest)}`;
|
|
141
|
-
const runtimeHash: Input[] = [lock, { runtime: `${CARGO_HASH_COMMAND} --include-workspace ${closureArguments}` }];
|
|
142
|
-
if (source.kind === 'unresolved') return runtimeHash;
|
|
143
139
|
|
|
144
140
|
const { root, cargo, indexed } = source;
|
|
145
141
|
const packageDirectories: string[] = [];
|
|
@@ -158,7 +154,7 @@ async function workspaceClosureInputs(projectRoot: string, source: CargoClosureS
|
|
|
158
154
|
throw new Error(`the Cargo package ${directory} is not in Nx's file index (an ignored directory)`);
|
|
159
155
|
}
|
|
160
156
|
packageDirectories.push(directory);
|
|
161
|
-
for (const file of [...pkg.sources,
|
|
157
|
+
for (const file of [...pkg.sources, pkg.governingManifest]) {
|
|
162
158
|
const path = indexablePath(root, file);
|
|
163
159
|
if (path === null) throw new Error(`${directory} compiles ${file}, which Nx's file index cannot hold`);
|
|
164
160
|
files.push(path);
|
|
@@ -167,11 +163,7 @@ async function workspaceClosureInputs(projectRoot: string, source: CargoClosureS
|
|
|
167
163
|
const unglobbable = [...packageDirectories, ...files].find((path) => GLOB_SYNTAX.test(path));
|
|
168
164
|
if (unglobbable !== undefined) throw new Error(`${unglobbable} contains glob syntax, so no fileset can name it`);
|
|
169
165
|
} catch (error) {
|
|
170
|
-
|
|
171
|
-
`@smoothbricks/nx-plugin: ${projectRoot}'s ${CARGO_CLOSURE_INPUT} runs smoo-nx-cargo-hash on each hash ` +
|
|
172
|
-
`instead of reading Nx's file index: ${error instanceof Error ? error.message : String(error)}\n`,
|
|
173
|
-
);
|
|
174
|
-
return runtimeHash;
|
|
166
|
+
throw new CargoClosureInputError(projectRoot, error);
|
|
175
167
|
}
|
|
176
168
|
|
|
177
169
|
// A package nested in another member's directory is already covered by it.
|