@smoothbricks/nx-plugin 0.4.20 → 0.4.21
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 +68 -18
- package/dist/bin/smoo-nx-cargo-hash.js +5 -3
- package/dist/cargo-source-hash.d.ts +3 -1
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +16 -12
- package/dist/cargo-workspace.d.ts +0 -1
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +9 -2
- package/dist/ensure-built.d.ts +6 -5
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +227 -30
- package/dist/index.js +18 -10
- package/dist/managed-files/ci-workflow.d.ts +20 -0
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +42 -13
- package/dist/managed-files/files.d.ts +1 -1
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +8 -1
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +37 -0
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
- package/dist/managed-files/pr-preview-cleanup-workflow.js +34 -6
- package/dist/workspace-manifest.d.ts +3 -1
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/managed/raw/tooling/direnv/setup-environment.ts +23 -91
- package/managed/raw/tooling/git-hooks/commit-msg.sh +6 -0
- package/managed/raw/tooling/git-hooks/pre-commit.sh +6 -0
- package/managed/raw/tooling/git-hooks/pre-push.sh +6 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +19 -7
- package/package.json +1 -1
- package/src/bin/smoo-nx-cargo-hash.ts +7 -3
- package/src/cargo-source-hash.test.ts +196 -1
- package/src/cargo-source-hash.ts +22 -14
- package/src/cargo-workspace.test.ts +17 -10
- package/src/cargo-workspace.ts +9 -3
- package/src/ensure-built.test.ts +87 -29
- package/src/ensure-built.ts +274 -29
- package/src/index.test.ts +117 -20
- package/src/index.ts +18 -11
- package/src/managed-files/ci-workflow.ts +45 -14
- package/src/managed-files/files.ts +9 -2
- package/src/managed-files/generator.test.ts +5 -1
- package/src/managed-files/github-host-cache-isolation.test.ts +32 -6
- package/src/managed-files/pr-preview-cleanup-workflow.ts +87 -6
- package/src/workspace-manifest.ts +3 -1
package/README.md
CHANGED
|
@@ -90,9 +90,9 @@ source replacement, credentials, and toolchain settings; forwarding it with `--c
|
|
|
90
90
|
access may consequently serialize on Cargo's package-cache lock. Clippy's dedicated target directory keeps its check
|
|
91
91
|
artifacts out of the test build directory without splitting one directory per crate.
|
|
92
92
|
|
|
93
|
-
###
|
|
93
|
+
### Cargo source runtime inputs
|
|
94
94
|
|
|
95
|
-
For a repository-root Cargo workspace, declare the
|
|
95
|
+
For inferred Cargo targets in a repository-root Cargo workspace, declare the external-source input once:
|
|
96
96
|
|
|
97
97
|
```json
|
|
98
98
|
{
|
|
@@ -106,12 +106,40 @@ For a package-root Cargo workspace, pass its manifest relative to the Nx root:
|
|
|
106
106
|
`smoo-nx-cargo-hash packages/example/Cargo.toml`. A shared input covering several Cargo workspaces includes one runtime
|
|
107
107
|
entry per manifest.
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
transitive dependencies, Rust sources, target source files, governing Cargo manifests, and Cargo
|
|
111
|
-
covers path packages under `node_modules`, which Nx's normal file map ignores.
|
|
109
|
+
By default, the command queries `cargo metadata --locked --offline` and hashes the resolved external path packages,
|
|
110
|
+
including transitive dependencies, Rust sources, target source files, governing Cargo manifests, and Cargo
|
|
111
|
+
configuration. It also covers path packages under `node_modules`, which Nx's normal file map ignores. Packages inside
|
|
112
|
+
both the Nx and Cargo workspaces are left to the plugin's inferred file inputs. Adding or moving a dependency does not
|
|
112
113
|
require maintaining a second list of source roots. The command refuses missing dependencies or an unavailable locked
|
|
113
114
|
dependency cache instead of emitting a partial digest.
|
|
114
115
|
|
|
116
|
+
Custom Cargo targets that replace inferred inputs need the in-workspace source closure too. Use
|
|
117
|
+
`smoo-nx-cargo-hash --include-workspace [Cargo.toml]` to include every mutable local package from the same locked,
|
|
118
|
+
offline Cargo metadata result. For a repository-root Cargo workspace:
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"namedInputs": {
|
|
123
|
+
"externalRustCrates": [{ "runtime": "smoo-nx-cargo-hash" }],
|
|
124
|
+
"cargoSources": [
|
|
125
|
+
{ "runtime": "smoo-nx-cargo-hash --include-workspace" },
|
|
126
|
+
"{workspaceRoot}/Cargo.lock",
|
|
127
|
+
"{workspaceRoot}/devenv.lock",
|
|
128
|
+
"{workspaceRoot}/tooling/direnv/devenv.lock"
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Name `cargoSources` in each custom Cargo target's `inputs`, alongside its own scripts and non-Rust build inputs. Keep
|
|
135
|
+
`externalRustCrates` for the plugin's external-source inference contract; unrelated TypeScript targets do not need
|
|
136
|
+
`cargoSources`. For a package-root workspace, pass `--include-workspace packages/example/Cargo.toml` and name that
|
|
137
|
+
workspace's `Cargo.lock`. An Nx `^production` input only follows existing project graph edges; it cannot replace a
|
|
138
|
+
missing Cargo dependency closure.
|
|
139
|
+
|
|
140
|
+
The helper exposes the same choice as `hashCargoPathInputs(manifestPath, workspaceRoot, { includeWorkspace: true })`.
|
|
141
|
+
Omitting the options, or setting `includeWorkspace: false`, retains the external-only behavior.
|
|
142
|
+
|
|
115
143
|
Git and registry dependencies are identified by `Cargo.lock`; uncommitted changes in a Git repository are not changes to
|
|
116
144
|
a pinned Git dependency. Local `path` dependencies stay live and their source edits change the digest. Build-script data
|
|
117
145
|
and environment inputs outside the Rust/Cargo inputs above still require explicit Nx inputs.
|
|
@@ -176,19 +204,22 @@ Concrete targets come from concrete files:
|
|
|
176
204
|
- A workspace-root `Cargo.toml` provides `cargo-test`, `test`, `cargo-lint`, `mutation`, and `bench`.
|
|
177
205
|
`cargo-test-compile` warms one workspace `cargo test --no-run`. `cargo-test-archive` runs one
|
|
178
206
|
`cargo --frozen nextest archive --workspace` into `target/nextest/archive.tar.zst` and is the only cached cargo BUILD:
|
|
179
|
-
it produces a file rather than a mutable build tree.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
207
|
+
it produces a file rather than a mutable build tree. Its inputs, like every cargo-derived fileset, are anchored at
|
|
208
|
+
`{workspaceRoot}`: Nx resolves a `{projectRoot}` glob against only the files its project owns, and a nested package
|
|
209
|
+
owns the crates under it, so a root workspace's archive spelled that way hashes none of its members and replays stale
|
|
210
|
+
binaries against edited crates. Each member crate gets a cached `cargo-test-<package>` run (30s per-test timeout like
|
|
211
|
+
`bun test --timeout=30000`) whose inputs include that crate and its path dependencies, and whose command is
|
|
212
|
+
`cargo --frozen nextest run --archive-file <archive> --workspace-remap . -E 'package(<crate>)'`. Runners therefore
|
|
213
|
+
execute rather than build: they extract binaries into their own temporary directory, write nothing to cargo's flocked
|
|
214
|
+
`target/`, and fan out instead of chaining. `--workspace-remap` is required — an archive records the producing tree's
|
|
215
|
+
absolute paths, and without it a restored archive hands tests another checkout's `CARGO_MANIFEST_DIR`. With it the
|
|
216
|
+
archive is relocatable, so one cache entry serves every checkout of the same commit; nextest re-points
|
|
217
|
+
`CARGO_BIN_EXE_<name>`/`NEXTEST_BIN_EXE_<name>` at the extracted binaries at runtime, but a test that reads them
|
|
218
|
+
through the compile-time `env!` macro keeps the producing tree's path. Per-crate runners accept an empty nextest
|
|
219
|
+
selection because a valid workspace member may have no tests and a hash partition may legitimately be empty.
|
|
220
|
+
`napi-debug` stays behind `cargo-test-compile`, and a crate in the project that builds the debug cdylib runs after it.
|
|
221
|
+
A crate declaring `[package.metadata.smoothbricks.wasm-bindgen]` also receives the cacheable `cargo-wasm` output
|
|
222
|
+
target in its owning project.
|
|
192
223
|
- The plugin's own `nextest.toml` is passed as `--tool-config-file "smoo:$PWD/<path>"`, so it is a layer BENEATH the
|
|
193
224
|
repository's `<cargo-workspace>/.config/nextest.toml` rather than a replacement for it: a repository can raise a
|
|
194
225
|
timeout, add a test group, or declare `archive.include` for a cdylib or fixture the archived test binaries need, and
|
|
@@ -270,10 +301,29 @@ through the inferred `typecheck-tests` target, not through `tsc --build`.
|
|
|
270
301
|
hashes. A full hit returns without running tasks or printing output. A miss runs the task graph through Nx's in-process
|
|
271
302
|
runner with streaming output; only a workspace with the daemon disabled falls back to its checkout-local `nx` CLI.
|
|
272
303
|
|
|
304
|
+
An `nx:noop` task, including a command-less target that Nx normalizes to one, runs nothing and so needs no cache record:
|
|
305
|
+
the tasks it aggregates answer in its place, and any outputs it declares are verified like every other task's. Any other
|
|
306
|
+
uncacheable task is a miss on every call, because only running it can say whether its side effects are current.
|
|
307
|
+
|
|
308
|
+
The probe and runner use the workspace's installed Nx and its normal cache configuration. A build performed by the Nx
|
|
309
|
+
CLI can satisfy the next wrapper invocation without re-executing tasks; changed inputs still go through Nx's runner.
|
|
310
|
+
Both invocations must use the same cache location. Relative `NX_CACHE_DIRECTORY` and `NX_WORKSPACE_DATA_DIRECTORY`
|
|
311
|
+
values resolve against the Nx workspace root, so they remain checkout-local when inherited by another shell. Absolute
|
|
312
|
+
paths remain caller-controlled, including deliberately shared CI locations; an absolute path inherited from another
|
|
313
|
+
checkout does not become local merely because the working directory changed.
|
|
314
|
+
|
|
273
315
|
Before hashing, it compares a native snapshot of the workspace with the daemon's file table. A write the daemon's
|
|
274
316
|
watcher has not delivered yet counts as a miss unless every changed path is a declared output of a task in the graph, so
|
|
275
317
|
a build's own artifacts never turn the next call noisy, and an edit made moments before the call never hits stale.
|
|
276
318
|
|
|
319
|
+
The daemon's output records are lossy: they are held in memory, tracked per collapsed directory, and erased by writes it
|
|
320
|
+
processes more than two seconds late — including, on a busy daemon, a restore's own writes. When it cannot vouch for a
|
|
321
|
+
task's outputs, the working tree is compared with Nx's local cache artifact for that exact task hash, entry by entry as
|
|
322
|
+
Nx's restore expands them: each entry must be reachable through real directories and hold the same node types, symlink
|
|
323
|
+
text (never followed), file permission bits and bytes. A tree the restore would leave unchanged is a hit, and the
|
|
324
|
+
daemon's record is re-armed as Nx's runner does after a restore. A missing or empty artifact, any difference, a read
|
|
325
|
+
error, or a write observed during the comparison is a miss.
|
|
326
|
+
|
|
277
327
|
```typescript
|
|
278
328
|
import { ensureBuilt } from '@smoothbricks/nx-plugin/ensure-built';
|
|
279
329
|
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { hashCargoPathInputs } from '../cargo-source-hash.js';
|
|
4
4
|
const args = process.argv.slice(2);
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const includeWorkspace = args[0] === '--include-workspace';
|
|
6
|
+
const manifest = args[includeWorkspace ? 1 : 0];
|
|
7
|
+
if (args.length > (includeWorkspace ? 2 : 1) || manifest?.startsWith('-')) {
|
|
8
|
+
process.stderr.write('usage: smoo-nx-cargo-hash [--include-workspace] [Cargo.toml]\n');
|
|
7
9
|
process.exit(2);
|
|
8
10
|
}
|
|
9
11
|
try {
|
|
10
|
-
process.stdout.write(`${await hashCargoPathInputs(resolve(
|
|
12
|
+
process.stdout.write(`${await hashCargoPathInputs(resolve(manifest ?? 'Cargo.toml'), process.cwd(), { includeWorkspace })}\n`);
|
|
11
13
|
}
|
|
12
14
|
catch (error) {
|
|
13
15
|
process.stderr.write(`smoo-nx-cargo-hash: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export declare function hashCargoPathInputs(manifestPath: string, workspaceRoot: string
|
|
1
|
+
export declare function hashCargoPathInputs(manifestPath: string, workspaceRoot: string, options?: {
|
|
2
|
+
includeWorkspace?: boolean;
|
|
3
|
+
}): Promise<string>;
|
|
2
4
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"cargo-source-hash.d.ts","sourceRoot":"","sources":["../src/cargo-source-hash.ts"],"names":[],"mappings":"AAmDA,wBAAsB,mBAAmB,CACvC,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE;IAAE,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAAE,GACvC,OAAO,CAAC,MAAM,CAAC,CAkGjB"}
|
|
@@ -111,6 +111,8 @@ const ancestorInputs = ['Cargo.toml', '.cargo/config', '.cargo/config.toml'];
|
|
|
111
111
|
* patches, and transitive path dependencies. A locked offline query observes
|
|
112
112
|
* that graph without fetching dependencies or changing the lockfile. Git and
|
|
113
113
|
* registry packages are immutable inputs already identified by Cargo.lock.
|
|
114
|
+
* By default, Nx's in-workspace inputs own workspace packages; includeWorkspace
|
|
115
|
+
* also covers those packages for custom targets without inferred Cargo inputs.
|
|
114
116
|
*
|
|
115
117
|
* This covers Rust sources and Cargo configuration, matching the plugin's
|
|
116
118
|
* in-workspace Rust inputs. Build scripts' other data/environment inputs remain
|
|
@@ -123,7 +125,7 @@ const ancestorInputs = ['Cargo.toml', '.cargo/config', '.cargo/config.toml'];
|
|
|
123
125
|
// stderr is kept for the failure path only, where execFileSync attaches it to
|
|
124
126
|
// the thrown error.
|
|
125
127
|
const CARGO_STDIO = ['ignore', 'pipe', 'pipe'];
|
|
126
|
-
export async function hashCargoPathInputs(manifestPath, workspaceRoot) {
|
|
128
|
+
export async function hashCargoPathInputs(manifestPath, workspaceRoot, options) {
|
|
127
129
|
const root = await realpath(workspaceRoot);
|
|
128
130
|
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 }));
|
|
129
131
|
const cargoRoot = await realpath(metadata.workspace_root);
|
|
@@ -136,16 +138,18 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot) {
|
|
|
136
138
|
continue;
|
|
137
139
|
const manifest = await realpath(pkg.manifest_path);
|
|
138
140
|
const directory = dirname(manifest);
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
141
|
+
if (!options?.includeWorkspace) {
|
|
142
|
+
const fromRoot = relative(root, directory);
|
|
143
|
+
const fromCargo = relative(cargoRoot, directory);
|
|
144
|
+
if (fromRoot !== '..' &&
|
|
145
|
+
!fromRoot.startsWith(`..${sep}`) &&
|
|
146
|
+
!isAbsolute(fromRoot) &&
|
|
147
|
+
fromCargo !== '..' &&
|
|
148
|
+
!fromCargo.startsWith(`..${sep}`) &&
|
|
149
|
+
!isAbsolute(fromCargo) &&
|
|
150
|
+
!fromRoot.split(sep).includes('node_modules'))
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
149
153
|
directories.add(directory);
|
|
150
154
|
files.add(manifest);
|
|
151
155
|
// Cargo resolves explicit package.workspace ownership as well as ancestor
|
|
@@ -154,7 +158,7 @@ export async function hashCargoPathInputs(manifestPath, workspaceRoot) {
|
|
|
154
158
|
files.add(await realpath(governingManifest));
|
|
155
159
|
for (const target of pkg.targets)
|
|
156
160
|
files.add(await realpath(target.src_path));
|
|
157
|
-
//
|
|
161
|
+
// A member can inherit edition, lint policy, dependencies and
|
|
158
162
|
// profiles from a workspace above its package directory. Those manifests
|
|
159
163
|
// are not descendants of the source roots returned by Cargo metadata.
|
|
160
164
|
for (let ancestor = dirname(directory); !ancestors.has(ancestor); ancestor = dirname(ancestor)) {
|
|
@@ -37,7 +37,6 @@ export interface CargoPackageTestInputsOptions {
|
|
|
37
37
|
/** The cargo workspace root holding the top-level `Cargo.toml`. */
|
|
38
38
|
absoluteProjectRoot: string;
|
|
39
39
|
memberDir: string;
|
|
40
|
-
inputRoot?: string;
|
|
41
40
|
/** Shared across every call of one graph computation; see {@link createCargoInputsCache}. */
|
|
42
41
|
cache?: CargoInputsCache;
|
|
43
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cargo-workspace.d.ts","sourceRoot":"","sources":["../src/cargo-workspace.ts"],"names":[],"mappings":"AAIA,OAAO,EAAsB,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAE/D,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,+BAAgC,SAAQ,qBAAqB;IAC5E,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,0BAA0B,CAAC,mBAAmB,EAAE,MAAM,GAAG,qBAAqB,EAAE,CAkF/F;AA0ED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,SAAS,qBAAqB,EAAE,EAC1C,QAAQ,EAAE,SAAS,qBAAqB,EAAE,GACzC,+BAA+B,EAAE,CAgBnC;AAED;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,uBAAuB,CAAC;AAE/D,MAAM,WAAW,6BAA6B;IAC5C,oEAAoE;IACpE,aAAa,EAAE,MAAM,CAAC;IACtB,mEAAmE;IACnE,mBAAmB,EAAE,MAAM,CAAC;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,
|
|
1
|
+
{"version":3,"file":"cargo-workspace.d.ts","sourceRoot":"","sources":["../src/cargo-workspace.ts"],"names":[],"mappings":"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"}
|
package/dist/cargo-workspace.js
CHANGED
|
@@ -174,7 +174,7 @@ export function createCargoInputsCache() {
|
|
|
174
174
|
}
|
|
175
175
|
export function cargoPackageTestInputs(options) {
|
|
176
176
|
const cache = options.cache ?? createCargoInputsCache();
|
|
177
|
-
const key = `${options.absoluteProjectRoot}\0${options.memberDir}
|
|
177
|
+
const key = `${options.absoluteProjectRoot}\0${options.memberDir}`;
|
|
178
178
|
const cached = cache.results.get(key);
|
|
179
179
|
if (cached !== undefined)
|
|
180
180
|
return cached;
|
|
@@ -182,7 +182,14 @@ export function cargoPackageTestInputs(options) {
|
|
|
182
182
|
cache.results.set(key, derived);
|
|
183
183
|
return derived;
|
|
184
184
|
}
|
|
185
|
-
async function deriveCargoPackageTestInputs({ workspaceRoot, absoluteProjectRoot, memberDir
|
|
185
|
+
async function deriveCargoPackageTestInputs({ workspaceRoot, absoluteProjectRoot, memberDir }, cache) {
|
|
186
|
+
// Every fileset is anchored at `{workspaceRoot}`, never `{projectRoot}`: Nx
|
|
187
|
+
// hashes a `{projectRoot}` glob against only the files its project OWNS, and
|
|
188
|
+
// a nested Nx project owns the crates under it. A repository-root cargo
|
|
189
|
+
// workspace whose members live in `packages/*` would then hash none of its
|
|
190
|
+
// members' sources, and its archive would cache-hit against edited crates
|
|
191
|
+
// while every per-crate runner reran on the stale binaries.
|
|
192
|
+
const inputRoot = posix.join('{workspaceRoot}', relative(workspaceRoot, absoluteProjectRoot).split(sep).join('/'));
|
|
186
193
|
const loadManifest = (path) => {
|
|
187
194
|
const normalized = resolve(path);
|
|
188
195
|
const cached = cache.manifests.get(normalized);
|
package/dist/ensure-built.d.ts
CHANGED
|
@@ -99,13 +99,14 @@ export declare function describeMiss(reason: MissReason): string;
|
|
|
99
99
|
*/
|
|
100
100
|
export declare function firstCacheMiss(tasks: readonly Task[], cachedCodeByHash: ReadonlyMap<string, number>): MissReason | null;
|
|
101
101
|
/**
|
|
102
|
-
*
|
|
102
|
+
* The entries the daemon does not vouch for.
|
|
103
103
|
*
|
|
104
|
-
* `
|
|
105
|
-
* ragged array
|
|
106
|
-
* positive one, and being wrong here means exec'ing a binary
|
|
104
|
+
* `verdicts[index]` is the daemon's verdict for `entries[index]`. A short or
|
|
105
|
+
* ragged array leaves the remainder unvouched rather than cleared: a missing
|
|
106
|
+
* verdict is not a positive one, and being wrong here means exec'ing a binary
|
|
107
|
+
* that was deleted.
|
|
107
108
|
*/
|
|
108
|
-
export declare function
|
|
109
|
+
export declare function unvouched<Entry>(entries: readonly Entry[], verdicts: readonly boolean[]): Entry[];
|
|
109
110
|
/**
|
|
110
111
|
* Make sure an Nx target's outputs are on disk, doing as little as possible
|
|
111
112
|
* when they already are.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ensure-built.d.ts","sourceRoot":"","sources":["../src/ensure-built.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ensure-built.d.ts","sourceRoot":"","sources":["../src/ensure-built.ts"],"names":[],"mappings":"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"}
|
package/dist/ensure-built.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import { existsSync } from 'node:fs';
|
|
3
|
+
import { closeSync, existsSync, lstatSync, openSync, readdirSync, readlinkSync, readSync } from 'node:fs';
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
|
-
import { join, resolve } from 'node:path';
|
|
5
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
6
6
|
function createWorkspaceNxRequire(workspaceRoot) {
|
|
7
7
|
const requireFromWorkspace = createRequire(join(workspaceRoot, 'package.json'));
|
|
8
8
|
return function requireNx(specifier) {
|
|
@@ -74,19 +74,15 @@ export function firstCacheMiss(tasks, cachedCodeByHash) {
|
|
|
74
74
|
return null;
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* The entries the daemon does not vouch for.
|
|
78
78
|
*
|
|
79
|
-
* `
|
|
80
|
-
* ragged array
|
|
81
|
-
* positive one, and being wrong here means exec'ing a binary
|
|
79
|
+
* `verdicts[index]` is the daemon's verdict for `entries[index]`. A short or
|
|
80
|
+
* ragged array leaves the remainder unvouched rather than cleared: a missing
|
|
81
|
+
* verdict is not a positive one, and being wrong here means exec'ing a binary
|
|
82
|
+
* that was deleted.
|
|
82
83
|
*/
|
|
83
|
-
export function
|
|
84
|
-
|
|
85
|
-
if (matches[index] !== true) {
|
|
86
|
-
return { kind: 'stale-outputs', taskId: tasks[index].id };
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return null;
|
|
84
|
+
export function unvouched(entries, verdicts) {
|
|
85
|
+
return entries.filter((_, index) => verdicts[index] !== true);
|
|
90
86
|
}
|
|
91
87
|
/**
|
|
92
88
|
* Make sure an Nx target's outputs are on disk, doing as little as possible
|
|
@@ -213,7 +209,7 @@ async function ensureBuiltInWorkspace(workspaceRoot, selector, onMiss) {
|
|
|
213
209
|
reason = { kind: 'stale-inputs', taskId: selectorTaskId };
|
|
214
210
|
}
|
|
215
211
|
else {
|
|
216
|
-
reason = await probe(nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx);
|
|
212
|
+
reason = await probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx);
|
|
217
213
|
}
|
|
218
214
|
performance.measure('ensureBuilt:probe', 'ensureBuilt:probe:start');
|
|
219
215
|
const outcome = reason === null
|
|
@@ -309,13 +305,14 @@ async function refreshWorkspaceContext(workspaceRoot, tasks, requireNx) {
|
|
|
309
305
|
return inputsChanged;
|
|
310
306
|
}
|
|
311
307
|
/** `null` when the target is already built; otherwise the first reason it is not. */
|
|
312
|
-
async function probe(nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx) {
|
|
308
|
+
async function probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx) {
|
|
313
309
|
const { daemonClient } = requireNx('nx/src/daemon/client/client');
|
|
314
310
|
const { DaemonBasedTaskHasher } = requireNx('nx/src/hasher/task-hasher');
|
|
315
311
|
const { getTaskDetails, hashTasks } = requireNx('nx/src/hasher/hash-task');
|
|
316
312
|
const { getTaskSpecificEnv } = requireNx('nx/src/tasks-runner/task-env');
|
|
317
313
|
const { getCache } = requireNx('nx/src/tasks-runner/cache');
|
|
318
314
|
const { getRunnerOptions } = requireNx('nx/src/tasks-runner/run-command');
|
|
315
|
+
const { getExecutorNameForTask } = requireNx('nx/src/tasks-runner/utils');
|
|
319
316
|
// `isCloudDefault: false` because these options are only read here by the
|
|
320
317
|
// hasher, which looks at `selectivelyHashTsConfig`; the cloud credentials the
|
|
321
318
|
// flag would add belong to the cloud runner, and the run path calls Nx's own
|
|
@@ -341,20 +338,28 @@ async function probe(nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx)
|
|
|
341
338
|
}
|
|
342
339
|
await hashTasks(hasher, projectGraph, taskGraph, perTaskEnvs, getTaskDetails(), tasks);
|
|
343
340
|
performance.measure('ensureBuilt:hash', 'ensureBuilt:hash:start');
|
|
341
|
+
// An `nx:noop` task has no command: Nx completes it without spawning
|
|
342
|
+
// anything, and normalizes a command-less target that only names dependencies
|
|
343
|
+
// to one. A cache record would vouch for no work — the tasks it aggregates are
|
|
344
|
+
// in this graph and answer for themselves — so none is required. Demanding one
|
|
345
|
+
// made every call through an uncacheable aggregate hand the whole graph to Nx,
|
|
346
|
+
// which replays each dependency's cached log. Outputs a noop declares are
|
|
347
|
+
// still verified below, with every other task's.
|
|
348
|
+
const recordedTasks = tasks.filter((task) => getExecutorNameForTask(task, projectGraph) !== 'nx:noop');
|
|
344
349
|
// Nx's own factory, but deliberately never `init()`ed: that is what makes
|
|
345
350
|
// this a local-only, side-effect-free question. `init()` attaches the remote
|
|
346
351
|
// cache — a network round-trip, and a download is precisely the work this
|
|
347
352
|
// probe exists to detect — and asserts that the cache directory matches the
|
|
348
|
-
// database. Neither matters here:
|
|
349
|
-
//
|
|
353
|
+
// database. Neither matters here: the directory is read only to compare
|
|
354
|
+
// outputs against, and an artifact missing from it is a miss.
|
|
350
355
|
performance.mark('ensureBuilt:cache:start');
|
|
351
356
|
const cache = getCache(runnerOptions);
|
|
352
|
-
const cachedResults = await cache.getBatch(
|
|
357
|
+
const cachedResults = await cache.getBatch(recordedTasks.filter((task) => task.cache && task.hash));
|
|
353
358
|
const cachedCodeByHash = new Map();
|
|
354
359
|
for (const [hash, result] of cachedResults) {
|
|
355
360
|
cachedCodeByHash.set(hash, result.code);
|
|
356
361
|
}
|
|
357
|
-
const cacheMiss = firstCacheMiss(
|
|
362
|
+
const cacheMiss = firstCacheMiss(recordedTasks, cachedCodeByHash);
|
|
358
363
|
performance.measure('ensureBuilt:cache', 'ensureBuilt:cache:start');
|
|
359
364
|
if (cacheMiss) {
|
|
360
365
|
return cacheMiss;
|
|
@@ -362,22 +367,214 @@ async function probe(nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx)
|
|
|
362
367
|
// A cache record only proves the task once succeeded with these inputs. The
|
|
363
368
|
// artifact this facility is about — the binary that is about to be exec'd —
|
|
364
369
|
// lives in the working tree, where anything may have deleted or rewritten it
|
|
365
|
-
// since.
|
|
366
|
-
//
|
|
367
|
-
const
|
|
368
|
-
const outputEntries = [];
|
|
370
|
+
// since. The daemon answers that cheaply from the output hashes it recorded
|
|
371
|
+
// when Nx last wrote them.
|
|
372
|
+
const claims = [];
|
|
369
373
|
for (const task of tasks) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
continue;
|
|
374
|
+
if (task.outputs.length > 0 && task.hash !== undefined) {
|
|
375
|
+
claims.push({ taskId: task.id, outputs: task.outputs, hash: task.hash });
|
|
373
376
|
}
|
|
374
|
-
withOutputs.push(task);
|
|
375
|
-
outputEntries.push({ outputs: task.outputs, hash });
|
|
376
377
|
}
|
|
377
378
|
performance.mark('ensureBuilt:outputs:start');
|
|
378
|
-
const
|
|
379
|
+
const verdicts = await daemonClient.outputsHashesMatchBatch(claims.map(({ outputs, hash }) => ({ outputs, hash })));
|
|
379
380
|
performance.measure('ensureBuilt:outputs', 'ensureBuilt:outputs:start');
|
|
380
|
-
|
|
381
|
+
const doubted = unvouched(claims, verdicts);
|
|
382
|
+
if (doubted.length === 0) {
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
// Its records are lossy, though, and a lost record is not a changed output.
|
|
386
|
+
// They live in memory, so a restart drops every one. They are kept per
|
|
387
|
+
// collapsed directory (Nx tracks at most three paths per level), so a write
|
|
388
|
+
// anywhere under `packages/` voids a task whose outputs span four projects.
|
|
389
|
+
// And a write the daemon processes more than 2 s after a record erases it,
|
|
390
|
+
// which a daemon busy hashing does to a restore's own writes — so each
|
|
391
|
+
// restore guarantees the next one. What settles the question is what a hit
|
|
392
|
+
// would restore: Nx's own local artifact for this exact hash. A working tree
|
|
393
|
+
// that already holds every entry of it is what the restore would leave.
|
|
394
|
+
// Anything else — no artifact, a difference, an error while reading — stays
|
|
395
|
+
// a miss.
|
|
396
|
+
performance.mark('ensureBuilt:artifacts:start');
|
|
397
|
+
const { expandOutputs } = requireNx('nx/src/native');
|
|
398
|
+
const comparison = {
|
|
399
|
+
expandOutputs,
|
|
400
|
+
left: Buffer.allocUnsafe(COMPARE_CHUNK_BYTES),
|
|
401
|
+
right: Buffer.allocUnsafe(COMPARE_CHUNK_BYTES),
|
|
402
|
+
observed: [],
|
|
403
|
+
realDirectories: new Set(),
|
|
404
|
+
};
|
|
405
|
+
for (const claim of doubted) {
|
|
406
|
+
// `recordedTasks` excludes `nx:noop`, so a noop's declared outputs have no
|
|
407
|
+
// artifact here and stay a miss.
|
|
408
|
+
const artifact = cachedResults.get(claim.hash);
|
|
409
|
+
if (artifact === undefined || !outputsMatchArtifact(comparison, workspaceRoot, artifact.outputsPath, claim)) {
|
|
410
|
+
return { kind: 'stale-outputs', taskId: claim.taskId };
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
// A write that landed while the bytes were being compared would otherwise be
|
|
414
|
+
// recorded as current.
|
|
415
|
+
const movedBeforeRecord = firstMovedClaim(comparison.observed);
|
|
416
|
+
if (movedBeforeRecord !== null) {
|
|
417
|
+
return { kind: 'stale-outputs', taskId: movedBeforeRecord };
|
|
418
|
+
}
|
|
419
|
+
// Re-arm the daemon the way Nx's runner does after restoring outputs, so the
|
|
420
|
+
// next call is back on the cheap path.
|
|
421
|
+
await daemonClient.recordOutputsHashBatch(doubted.map(({ outputs, hash }) => ({ outputs, hash })));
|
|
422
|
+
const movedDuringRecord = firstMovedClaim(comparison.observed);
|
|
423
|
+
performance.measure('ensureBuilt:artifacts', 'ensureBuilt:artifacts:start');
|
|
424
|
+
return movedDuringRecord === null ? null : { kind: 'stale-outputs', taskId: movedDuringRecord };
|
|
425
|
+
}
|
|
426
|
+
/** Read size for byte comparison: large enough to stream a binary quickly, small enough never to load one whole. */
|
|
427
|
+
const COMPARE_CHUNK_BYTES = 1 << 20;
|
|
428
|
+
/**
|
|
429
|
+
* Whether restoring `claim` from the artifact would leave the working tree as
|
|
430
|
+
* it is.
|
|
431
|
+
*
|
|
432
|
+
* The entries are the ones Nx's restore copies: `expandOutputs` over the
|
|
433
|
+
* artifact root with the task's outputs, globs and negations included. That
|
|
434
|
+
* walk is bounded by the artifact, which holds nothing but outputs, and it
|
|
435
|
+
* needs no reading of the pattern here. A restore replaces each entry whole
|
|
436
|
+
* and touches nothing else, so a working-tree file that matches a glob but is
|
|
437
|
+
* absent from the artifact survives it and is no difference. An output path
|
|
438
|
+
* Nx would refuse to restore (absolute, or climbing out with `..`), an
|
|
439
|
+
* artifact holding no entry at all, and system errors while reading are all
|
|
440
|
+
* misses.
|
|
441
|
+
*/
|
|
442
|
+
function outputsMatchArtifact(comparison, workspaceRoot, artifactRoot, claim) {
|
|
443
|
+
if (claim.outputs.some((output) => isAbsolute(output) || output.split('/').includes('..'))) {
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
446
|
+
try {
|
|
447
|
+
const entries = comparison.expandOutputs(artifactRoot, claim.outputs);
|
|
448
|
+
return (entries.length > 0 &&
|
|
449
|
+
entries.every((entry) => throughRealDirectories(comparison.realDirectories, workspaceRoot, entry) &&
|
|
450
|
+
sameTree(comparison, claim.taskId, join(workspaceRoot, entry), join(artifactRoot, entry))));
|
|
451
|
+
}
|
|
452
|
+
catch (error) {
|
|
453
|
+
if (isSystemError(error)) {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
throw error;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Whether every directory between the workspace root and `entry` is a real
|
|
461
|
+
* directory. A restore realizes a symlinked parent as a directory, so reading
|
|
462
|
+
* an entry through one would compare bytes the restore does not leave there —
|
|
463
|
+
* and would read the filesystem behind a link.
|
|
464
|
+
*/
|
|
465
|
+
function throughRealDirectories(realDirectories, workspaceRoot, entry) {
|
|
466
|
+
let directory = workspaceRoot;
|
|
467
|
+
const segments = entry.split('/');
|
|
468
|
+
for (const segment of segments.slice(0, -1)) {
|
|
469
|
+
directory = join(directory, segment);
|
|
470
|
+
if (realDirectories.has(directory)) {
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
if (lstatSync(directory, { throwIfNoEntry: false })?.isDirectory() !== true) {
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
realDirectories.add(directory);
|
|
477
|
+
}
|
|
478
|
+
return true;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Whether `actual` is `expected` as a restore would recreate it: same node
|
|
482
|
+
* type; a symlink by its text, never followed, because the link is what Nx
|
|
483
|
+
* stores and restores; a file by permission bits and bytes; a directory by its
|
|
484
|
+
* entry names and each entry in turn. Every working-tree node compared is
|
|
485
|
+
* observed, so a write during the comparison can be caught afterwards.
|
|
486
|
+
*/
|
|
487
|
+
function sameTree(comparison, taskId, actual, expected) {
|
|
488
|
+
const actualStats = lstatSync(actual, { bigint: true, throwIfNoEntry: false });
|
|
489
|
+
const expectedStats = lstatSync(expected, { bigint: true, throwIfNoEntry: false });
|
|
490
|
+
if (actualStats === undefined || expectedStats === undefined) {
|
|
491
|
+
return false;
|
|
492
|
+
}
|
|
493
|
+
comparison.observed.push({ taskId, path: actual, stats: actualStats });
|
|
494
|
+
if (expectedStats.isSymbolicLink()) {
|
|
495
|
+
return actualStats.isSymbolicLink() && readlinkSync(actual) === readlinkSync(expected);
|
|
496
|
+
}
|
|
497
|
+
if (expectedStats.isFile()) {
|
|
498
|
+
return (actualStats.isFile() &&
|
|
499
|
+
actualStats.size === expectedStats.size &&
|
|
500
|
+
(actualStats.mode & 4095n) === (expectedStats.mode & 4095n) &&
|
|
501
|
+
sameBytes(comparison, actual, expected, Number(expectedStats.size)));
|
|
502
|
+
}
|
|
503
|
+
if (expectedStats.isDirectory()) {
|
|
504
|
+
if (!actualStats.isDirectory()) {
|
|
505
|
+
return false;
|
|
506
|
+
}
|
|
507
|
+
const names = readdirSync(actual).sort();
|
|
508
|
+
const expectedNames = readdirSync(expected).sort();
|
|
509
|
+
if (names.length !== expectedNames.length) {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
for (let index = 0; index < names.length; index += 1) {
|
|
513
|
+
if (names[index] !== expectedNames[index]) {
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return names.every((name) => sameTree(comparison, taskId, join(actual, name), join(expected, name)));
|
|
518
|
+
}
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
/** Byte equality of two files already known to be `size` bytes, streamed through the comparison's buffers. */
|
|
522
|
+
function sameBytes(comparison, actual, expected, size) {
|
|
523
|
+
const actualFd = openSync(actual, 'r');
|
|
524
|
+
try {
|
|
525
|
+
const expectedFd = openSync(expected, 'r');
|
|
526
|
+
try {
|
|
527
|
+
for (let offset = 0; offset < size; offset += COMPARE_CHUNK_BYTES) {
|
|
528
|
+
const length = Math.min(COMPARE_CHUNK_BYTES, size - offset);
|
|
529
|
+
// A short read means the file changed length since it was sized.
|
|
530
|
+
if (readSync(actualFd, comparison.left, 0, length, offset) !== length ||
|
|
531
|
+
readSync(expectedFd, comparison.right, 0, length, offset) !== length ||
|
|
532
|
+
comparison.left.compare(comparison.right, 0, length, 0, length) !== 0) {
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return true;
|
|
537
|
+
}
|
|
538
|
+
finally {
|
|
539
|
+
closeSync(expectedFd);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
finally {
|
|
543
|
+
closeSync(actualFd);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* The task owning the first observed node that is no longer the node it was
|
|
548
|
+
* compared as: replaced (device, inode), rewritten (size, mtime) or otherwise
|
|
549
|
+
* touched (mode, ctime).
|
|
550
|
+
*/
|
|
551
|
+
function firstMovedClaim(observed) {
|
|
552
|
+
for (const { taskId, path, stats } of observed) {
|
|
553
|
+
let current;
|
|
554
|
+
try {
|
|
555
|
+
current = lstatSync(path, { bigint: true, throwIfNoEntry: false });
|
|
556
|
+
}
|
|
557
|
+
catch (error) {
|
|
558
|
+
if (isSystemError(error)) {
|
|
559
|
+
return taskId;
|
|
560
|
+
}
|
|
561
|
+
throw error;
|
|
562
|
+
}
|
|
563
|
+
if (current === undefined ||
|
|
564
|
+
current.dev !== stats.dev ||
|
|
565
|
+
current.ino !== stats.ino ||
|
|
566
|
+
current.mode !== stats.mode ||
|
|
567
|
+
current.size !== stats.size ||
|
|
568
|
+
current.mtimeNs !== stats.mtimeNs ||
|
|
569
|
+
current.ctimeNs !== stats.ctimeNs) {
|
|
570
|
+
return taskId;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return null;
|
|
574
|
+
}
|
|
575
|
+
/** An operating-system or native-binding failure, as opposed to a programming error. */
|
|
576
|
+
function isSystemError(error) {
|
|
577
|
+
return error instanceof Error && 'code' in error && typeof error.code === 'string';
|
|
381
578
|
}
|
|
382
579
|
async function runTarget(nxJson, nxArgs, overrides, selector, reason, requireNx) {
|
|
383
580
|
const { runCommandForTasks } = requireNx('nx/src/tasks-runner/run-command');
|