@smoothbricks/nx-plugin 0.4.26 → 0.4.28
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 +994 -117
- package/dist/bin/smoo-nx-bound-failures.d.ts +3 -0
- package/dist/bin/smoo-nx-bound-failures.d.ts.map +1 -0
- package/dist/bin/smoo-nx-bound-failures.js +31 -0
- package/dist/bin/smoo-nx-cargo-hash.js +28 -3
- package/dist/bin/smoo-nx-exec.js +15 -73
- package/dist/bin/smoo-nx-failures.d.ts +3 -0
- package/dist/bin/smoo-nx-failures.d.ts.map +1 -0
- package/dist/bin/smoo-nx-failures.js +3 -0
- package/dist/bin/smoo-nx-nextest-extract.js +3 -2
- package/dist/bin/smoo-nx-test-walks.d.ts +3 -0
- package/dist/bin/smoo-nx-test-walks.d.ts.map +1 -0
- package/dist/bin/smoo-nx-test-walks.js +34 -0
- package/dist/bounded-test-policy.d.ts +7 -1
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +101 -40
- package/dist/build-state-output-policy.d.ts +25 -0
- package/dist/build-state-output-policy.d.ts.map +1 -0
- package/dist/build-state-output-policy.js +64 -0
- package/dist/cargo-closure-input.d.ts +3 -2
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +16 -15
- package/dist/cargo-dev-profile.d.ts +37 -0
- package/dist/cargo-dev-profile.d.ts.map +1 -0
- package/dist/cargo-dev-profile.js +108 -0
- package/dist/cargo-source-hash.d.ts +43 -6
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +309 -73
- package/dist/cargo-toolchain-policy.d.ts +4 -0
- package/dist/cargo-toolchain-policy.d.ts.map +1 -1
- package/dist/cargo-toolchain-policy.js +5 -0
- package/dist/cargo-workspace.d.ts +101 -5
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +291 -10
- package/dist/cross-check-policy.d.ts +21 -3
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +24 -6
- package/dist/disk-command-policy.d.ts +7 -0
- package/dist/disk-command-policy.d.ts.map +1 -0
- package/dist/disk-command-policy.js +98 -0
- package/dist/ensure-built-receipt.d.ts +25 -0
- package/dist/ensure-built-receipt.d.ts.map +1 -0
- package/dist/ensure-built-receipt.js +261 -0
- package/dist/ensure-built-witness.d.ts +57 -0
- package/dist/ensure-built-witness.d.ts.map +1 -0
- package/dist/ensure-built-witness.js +412 -0
- package/dist/ensure-built.d.ts +207 -12
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +576 -202
- package/dist/eslint-file-set.d.ts +7 -0
- package/dist/eslint-file-set.d.ts.map +1 -0
- package/dist/eslint-file-set.js +12 -0
- package/dist/executors/bounded-exec/cpu-pool.d.ts +63 -0
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-pool.js +379 -0
- package/dist/executors/bounded-exec/cpu-tokens.d.ts +82 -0
- package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-tokens.js +114 -0
- package/dist/executors/bounded-exec/disk-lease.d.ts +61 -0
- package/dist/executors/bounded-exec/disk-lease.d.ts.map +1 -0
- package/dist/executors/bounded-exec/disk-lease.js +91 -0
- package/dist/executors/bounded-exec/executor.d.ts +45 -2
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +447 -52
- package/dist/executors/bounded-exec/gateway-lease.d.ts +52 -0
- package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -0
- package/dist/executors/bounded-exec/gateway-lease.js +143 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts +35 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -0
- package/dist/executors/bounded-exec/hang-diagnostics.js +231 -0
- package/dist/executors/bounded-exec/progress.d.ts +35 -0
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -0
- package/dist/executors/bounded-exec/progress.js +79 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts +3 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp-fixtures.js +12 -0
- package/dist/executors/bounded-exec/ram-temp-held.d.ts +91 -0
- package/dist/executors/bounded-exec/ram-temp-held.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp-held.js +152 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts +223 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -0
- package/dist/executors/bounded-exec/ram-temp.js +1528 -0
- package/dist/executors/bounded-exec/schema.d.ts +29 -11
- package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.d.ts +162 -0
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -0
- package/dist/executors/bounded-exec/verdict.js +318 -0
- package/dist/executors/shard-timings/executor.d.ts +14 -0
- package/dist/executors/shard-timings/executor.d.ts.map +1 -0
- package/dist/executors/shard-timings/executor.js +25 -0
- package/dist/executors/shard-timings/schema.d.ts +4 -0
- package/dist/executors/shard-timings/schema.d.ts.map +1 -0
- package/dist/executors/shard-timings/schema.js +1 -0
- package/dist/failure-summary.d.ts +5 -0
- package/dist/failure-summary.d.ts.map +1 -0
- package/dist/failure-summary.js +118 -0
- package/dist/generators/create-package/generator.d.ts.map +1 -1
- package/dist/generators/create-package/generator.js +6 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +370 -138
- package/dist/managed-files/ci-workflow.d.ts +13 -0
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +44 -13
- package/dist/managed-files/files.d.ts +7 -1
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +62 -8
- package/dist/managed-files/json-edit.d.ts +21 -0
- package/dist/managed-files/json-edit.d.ts.map +1 -0
- package/dist/managed-files/json-edit.js +295 -0
- package/dist/managed-files/managed-format.d.ts +33 -1
- package/dist/managed-files/managed-format.d.ts.map +1 -1
- package/dist/managed-files/managed-format.js +82 -2
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts +7 -0
- package/dist/managed-files/pr-preview-cleanup-workflow.d.ts.map +1 -1
- package/dist/managed-files/pr-preview-cleanup-workflow.js +68 -4
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/managed-files/publish-workflow.js +231 -48
- package/dist/managed-files/tree.d.ts +5 -0
- package/dist/managed-files/tree.d.ts.map +1 -1
- package/dist/managed-files/tree.js +5 -3
- package/dist/manifest-hash.d.ts.map +1 -1
- package/dist/manifest-hash.js +2 -5
- package/dist/nextest-code-bound.d.ts +62 -0
- package/dist/nextest-code-bound.d.ts.map +1 -0
- package/dist/nextest-code-bound.js +154 -0
- package/dist/nextest-extraction.d.ts +24 -8
- package/dist/nextest-extraction.d.ts.map +1 -1
- package/dist/nextest-extraction.js +42 -7
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +3 -5
- package/dist/release-config-policy.d.ts.map +1 -1
- package/dist/release-config-policy.js +3 -5
- package/dist/runtime-input.d.ts +14 -0
- package/dist/runtime-input.d.ts.map +1 -0
- package/dist/runtime-input.js +15 -0
- package/dist/rust-tokens.d.ts +11 -0
- package/dist/rust-tokens.d.ts.map +1 -0
- package/dist/rust-tokens.js +81 -0
- package/dist/task-results.d.ts +6 -0
- package/dist/task-results.d.ts.map +1 -0
- package/dist/task-results.js +61 -0
- package/dist/test-program.d.ts +54 -0
- package/dist/test-program.d.ts.map +1 -0
- package/dist/test-program.js +292 -0
- package/dist/test-timings.d.ts +71 -0
- package/dist/test-timings.d.ts.map +1 -0
- package/dist/test-timings.js +393 -0
- package/dist/test-walk-policy.d.ts +103 -0
- package/dist/test-walk-policy.d.ts.map +1 -0
- package/dist/test-walk-policy.js +657 -0
- package/dist/testing.d.ts +177 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +824 -0
- package/dist/type-guards.d.ts +3 -0
- package/dist/type-guards.d.ts.map +1 -0
- package/dist/type-guards.js +4 -0
- package/dist/typecheck-test-policy.d.ts +8 -5
- package/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +113 -100
- package/dist/workspace-config-policy.d.ts +8 -0
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +175 -63
- package/dist/workspace-index.d.ts +12 -0
- package/dist/workspace-index.d.ts.map +1 -0
- package/dist/workspace-index.js +17 -0
- package/dist/workspace-manifest.d.ts +37 -0
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/executors.json +5 -0
- package/loader.js +13 -11
- package/managed/raw/envrc +33 -67
- package/managed/raw/git-format-staged.yml +30 -35
- package/managed/raw/patches/nx@23.2.1.patch +3484 -0
- package/managed/raw/tooling/direnv/apple-developer.sh +83 -0
- package/managed/raw/tooling/direnv/developer-links.ts +569 -11
- package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -93
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -11
- package/managed/raw/tooling/direnv/linked-snapshots.ts +845 -0
- package/managed/raw/tooling/direnv/nx-socket-dir.sh +82 -0
- package/managed/raw/tooling/direnv/repo-path +14 -2
- package/managed/raw/tooling/direnv/setup-environment.ts +1146 -159
- package/managed/raw/tooling/direnv/toolchain-stamp.ts +45 -3
- package/managed/raw/tooling/direnv/ttsc-env.sh +39 -0
- package/managed/raw/tooling/git-hooks/commit-msg.sh +5 -6
- package/managed/raw/tooling/git-hooks/pre-commit.sh +7 -6
- package/managed/raw/tooling/git-hooks/pre-push.sh +20 -15
- package/managed/templates/github/actions/cache-nix-devenv/action.yml +6 -6
- package/managed/templates/github/actions/cache-node-modules/action.yml +6 -4
- package/managed/templates/github/actions/cache-nx/action.yml +1 -1
- package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +1 -1
- package/managed/templates/github/actions/forgejo-artifact.cjs +99 -0
- package/managed/templates/github/actions/forgejo-download-artifact/action.yml +49 -0
- package/managed/templates/github/actions/forgejo-download-artifact/index.cjs +7 -0
- package/managed/templates/github/actions/forgejo-upload-artifact/action.yml +65 -0
- package/managed/templates/github/actions/forgejo-upload-artifact/index.cjs +7 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +21 -3
- package/managed/templates/github/workflows/managed-files.yml +1 -2
- package/nextest.toml +8 -41
- package/package.json +74 -12
- package/runtime-input.sh +81 -0
- package/src/__tests__/counted-cargo.ts +33 -14
- package/src/__tests__/fixture-nx-env.ts +111 -46
- package/src/__tests__/progress-clock.ts +43 -0
- package/src/__tests__/runtime-input.ts +23 -0
- package/src/bin/smoo-nx-bound-failures.test.ts +127 -0
- package/src/bin/smoo-nx-bound-failures.ts +33 -0
- package/src/bin/smoo-nx-cargo-hash.ts +28 -3
- package/src/bin/smoo-nx-exec.ts +16 -74
- package/src/bin/smoo-nx-failures.ts +4 -0
- package/src/bin/smoo-nx-nextest-extract.ts +3 -2
- package/src/bin/smoo-nx-test-walks.ts +42 -0
- package/src/bounded-test-policy.test.ts +268 -21
- package/src/bounded-test-policy.ts +114 -42
- package/src/build-state-output-policy.test.ts +115 -0
- package/src/build-state-output-policy.ts +90 -0
- package/src/bun-bootstrap.test.ts +57 -3
- package/src/bun-file-packages.test.ts +47 -0
- package/src/cargo-closure-input.test.ts +138 -66
- package/src/cargo-closure-input.ts +17 -15
- package/src/cargo-dev-profile.ts +137 -0
- package/src/cargo-resolve-cache.test.ts +70 -1
- package/src/cargo-source-hash.test.ts +193 -97
- package/src/cargo-source-hash.ts +345 -68
- package/src/cargo-toolchain-policy.ts +6 -0
- package/src/cargo-workspace.test.ts +320 -0
- package/src/cargo-workspace.ts +336 -10
- package/src/cross-check-policy.test.ts +59 -1
- package/src/cross-check-policy.ts +25 -6
- package/src/disk-command-policy.test.ts +61 -0
- package/src/disk-command-policy.ts +107 -0
- package/src/ensure-built-receipt.test.ts +184 -0
- package/src/ensure-built-receipt.ts +263 -0
- package/src/ensure-built-witness.test.ts +344 -0
- package/src/ensure-built-witness.ts +252 -0
- package/src/ensure-built.test.ts +1036 -578
- package/src/ensure-built.ts +820 -224
- package/src/eslint-file-set.ts +9 -0
- package/src/executors/bounded-exec/cpu-pool.test.ts +454 -0
- package/src/executors/bounded-exec/cpu-pool.ts +417 -0
- package/src/executors/bounded-exec/cpu-tokens.test.ts +269 -0
- package/src/executors/bounded-exec/cpu-tokens.ts +177 -0
- package/src/executors/bounded-exec/disk-lease.test.ts +185 -0
- package/src/executors/bounded-exec/disk-lease.ts +139 -0
- package/src/executors/bounded-exec/executor-host.test.ts +778 -0
- package/src/executors/bounded-exec/executor.test.ts +1116 -63
- package/src/executors/bounded-exec/executor.ts +565 -67
- package/src/executors/bounded-exec/gateway-lease.ts +176 -0
- package/src/executors/bounded-exec/hang-diagnostics.test.ts +285 -0
- package/src/executors/bounded-exec/hang-diagnostics.ts +283 -0
- package/src/executors/bounded-exec/progress.test.ts +79 -0
- package/src/executors/bounded-exec/progress.ts +118 -0
- package/src/executors/bounded-exec/ram-temp-fixtures.ts +12 -0
- package/src/executors/bounded-exec/ram-temp-held.test.ts +264 -0
- package/src/executors/bounded-exec/ram-temp-held.ts +242 -0
- package/src/executors/bounded-exec/ram-temp-host.test.ts +605 -0
- package/src/executors/bounded-exec/ram-temp.test.ts +674 -0
- package/src/executors/bounded-exec/ram-temp.ts +1918 -0
- package/src/executors/bounded-exec/schema.json +11 -5
- package/src/executors/bounded-exec/schema.ts +27 -11
- package/src/executors/bounded-exec/verdict.test.ts +440 -0
- package/src/executors/bounded-exec/verdict.ts +433 -0
- package/src/executors/shard-timings/executor.ts +36 -0
- package/src/executors/shard-timings/schema.json +21 -0
- package/src/executors/shard-timings/schema.ts +4 -0
- package/src/failure-summary.ts +119 -0
- package/src/generators/bounded-test-targets/generator.test.ts +4 -4
- package/src/generators/bun-test-tracing/generator.test.ts +2 -2
- package/src/generators/create-package/generator.test.ts +6 -0
- package/src/generators/create-package/generator.ts +6 -2
- package/src/host-controller-wiring.test.ts +31 -0
- package/src/index.test.ts +909 -295
- package/src/index.ts +441 -143
- package/src/linked-snapshots.nx.test.ts +172 -0
- package/src/managed-files/ci-workflow.ts +54 -13
- package/src/managed-files/files.ts +65 -9
- package/src/managed-files/forgejo-artifact.test.ts +395 -0
- package/src/managed-files/generator.test.ts +60 -1
- package/src/managed-files/json-edit.test.ts +216 -0
- package/src/managed-files/json-edit.ts +290 -0
- package/src/managed-files/managed-format-json.test.ts +308 -0
- package/src/managed-files/managed-format.ts +90 -2
- package/src/managed-files/pr-preview-cleanup-workflow.ts +69 -3
- package/src/managed-files/publish-workflow.ts +285 -67
- package/src/managed-files/repo-path.test.ts +129 -0
- package/src/managed-files/trace-db-artifact.test.ts +7 -0
- package/src/managed-files/tree.ts +11 -3
- package/src/manifest-hash.ts +2 -6
- package/src/nextest-code-bound.test.ts +155 -0
- package/src/nextest-code-bound.ts +195 -0
- package/src/nextest-extraction.test.ts +37 -5
- package/src/nextest-extraction.ts +51 -9
- package/src/nextest-partitions.test.ts +427 -82
- package/src/nx-cache-bound.test.ts +5 -10
- package/src/nx-cache-restore-mtime.test.ts +170 -0
- package/src/nx-daemon-claim.test.ts +277 -0
- package/src/nx-daemon-idle-cpu.test.ts +81 -0
- package/src/nx-daemon-idle-policy.test.ts +51 -0
- package/src/nx-daemon-ignore-files.test.ts +210 -0
- package/src/nx-daemon-root-normalization.test.ts +105 -0
- package/src/nx-daemon-validity.test.ts +925 -0
- package/src/nx-dot-input-policy.test.ts +353 -0
- package/src/nx-failure-life-cycles.test.ts +207 -0
- package/src/nx-files-archive-racy.test.ts +97 -0
- package/src/nx-foreign-workspace-env.test.ts +329 -0
- package/src/nx-incomplete-run-summary.test.ts +70 -0
- package/src/nx-plugin-load-errors.test.ts +120 -0
- package/src/nx-project-resolution-cache.test.ts +176 -0
- package/src/nx-raw-inputs.test.ts +166 -0
- package/src/nx-resident-graph-workers.test.ts +7 -16
- package/src/nx-run-information.test.ts +118 -0
- package/src/nx-skipped-task-exit.test.ts +180 -0
- package/src/nx-state-location.test.ts +63 -0
- package/src/nx-store-resolution.test.ts +26 -25
- package/src/nx-task-graph-cycles.test.ts +148 -0
- package/src/nx-task-output-lease.test.ts +414 -0
- package/src/nx-use-local.test.ts +103 -0
- package/src/package-target-policy.ts +3 -6
- package/src/release-config-policy.ts +3 -6
- package/src/runtime-input.test.ts +215 -0
- package/src/runtime-input.ts +17 -0
- package/src/rust-tokens.ts +78 -0
- package/src/serial-group-wiring.test.ts +326 -0
- package/src/task-history-namespace.test.ts +87 -89
- package/src/task-results.test.ts +226 -0
- package/src/task-results.ts +75 -0
- package/src/test-program.test.ts +303 -0
- package/src/test-program.ts +341 -0
- package/src/test-timings.test.ts +240 -0
- package/src/test-timings.ts +311 -0
- package/src/test-walk-policy.test.ts +585 -0
- package/src/test-walk-policy.ts +731 -0
- package/src/testing.test.ts +509 -0
- package/src/testing.ts +922 -0
- package/src/type-guards.ts +4 -0
- package/src/typecheck-test-policy.test.ts +496 -11
- package/src/typecheck-test-policy.ts +137 -103
- package/src/workspace-config-policy.test.ts +212 -13
- package/src/workspace-config-policy.ts +101 -73
- package/src/workspace-index.ts +18 -0
- package/src/workspace-manifest.ts +41 -0
- package/test-timings.json +85 -30
- package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -665
- package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
package/dist/ensure-built.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import { closeSync, existsSync, lstatSync, openSync, readdirSync, readlinkSync, readSync, realpathSync } from 'node:fs';
|
|
1
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
+
import { closeSync, existsSync, lstatSync, openSync, readdirSync, readlinkSync, readSync, realpathSync, statSync, } from 'node:fs';
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
5
|
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
6
|
+
import { inspect } from 'node:util';
|
|
7
|
+
import { boundedReceiptRuntimes, providerReceipt } from './ensure-built-receipt.js';
|
|
8
|
+
import { graphInstallationIdentity, nodeStamp, nodesUnchanged, readArtifactWitness, readGraphWitness, reusableGraph, snapshotsEqual, workspaceSnapshot, writeWitness, } from './ensure-built-witness.js';
|
|
9
|
+
import { managedAssetsRoot } from './managed-assets.js';
|
|
6
10
|
function createWorkspaceNxRequire(workspaceRoot) {
|
|
7
11
|
const requireFromWorkspace = createRequire(join(workspaceRoot, 'package.json'));
|
|
8
12
|
return function requireNx(specifier) {
|
|
@@ -36,14 +40,80 @@ export function describeMiss(reason) {
|
|
|
36
40
|
return `${reason.taskId} last failed with exit code ${reason.code}`;
|
|
37
41
|
case 'stale-outputs':
|
|
38
42
|
return `${reason.taskId} outputs are missing or modified on disk`;
|
|
39
|
-
case 'stale-inputs':
|
|
40
|
-
return `${reason.taskId} inputs changed since the Nx daemon last looked`;
|
|
41
43
|
case 'cache-disabled':
|
|
42
44
|
return `the Nx cache is disabled, so ${reason.taskId} must run`;
|
|
43
45
|
case 'no-daemon':
|
|
44
46
|
return `the Nx daemon is disabled, so ${reason.taskId} cannot be checked without running it`;
|
|
45
47
|
}
|
|
46
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Read `smoo-nx-exec <project:target[:configuration]> [--workspace-root <dir>]
|
|
51
|
+
* [-- <binary> [args...]]`. A flag may be spelled `--flag value` or
|
|
52
|
+
* `--flag=value`. Without `--` there is nothing to exec: the wrapper builds
|
|
53
|
+
* what is stale and exits, so a caller that only needs the target current pays
|
|
54
|
+
* the probe, not an Nx CLI start that replays every cached task's log.
|
|
55
|
+
*/
|
|
56
|
+
export function parseExecArguments(argv) {
|
|
57
|
+
const separator = argv.indexOf('--');
|
|
58
|
+
const command = separator === -1 ? [] : argv.slice(separator + 1);
|
|
59
|
+
if (separator !== -1 && command.length === 0) {
|
|
60
|
+
return { ok: false, usage: 'no binary given after `--`' };
|
|
61
|
+
}
|
|
62
|
+
let target;
|
|
63
|
+
let workspaceRoot;
|
|
64
|
+
// Only leading `--` forms are split at `=`: a value may legitimately contain one.
|
|
65
|
+
const tokens = (separator === -1 ? argv : argv.slice(0, separator)).flatMap((arg) => {
|
|
66
|
+
const equals = arg.startsWith('--') ? arg.indexOf('=') : -1;
|
|
67
|
+
return equals === -1 ? [arg] : [arg.slice(0, equals), arg.slice(equals + 1)];
|
|
68
|
+
});
|
|
69
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
70
|
+
const token = tokens[index];
|
|
71
|
+
if (token === '--workspace-root') {
|
|
72
|
+
index += 1;
|
|
73
|
+
if (index === tokens.length) {
|
|
74
|
+
return { ok: false, usage: '--workspace-root needs a directory' };
|
|
75
|
+
}
|
|
76
|
+
workspaceRoot = tokens[index];
|
|
77
|
+
}
|
|
78
|
+
else if (token.startsWith('-')) {
|
|
79
|
+
return { ok: false, usage: `unknown flag ${token}` };
|
|
80
|
+
}
|
|
81
|
+
else if (target !== undefined) {
|
|
82
|
+
return { ok: false, usage: `more than one target given: ${target} and ${token}` };
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
target = token;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (target === undefined) {
|
|
89
|
+
return { ok: false, usage: 'no project:target given' };
|
|
90
|
+
}
|
|
91
|
+
if (parseTargetSelector(target) === null) {
|
|
92
|
+
return { ok: false, usage: `'${target}' is not a project:target[:configuration] selector` };
|
|
93
|
+
}
|
|
94
|
+
// `execve` does no PATH lookup, so a bare name would fail as a missing file in
|
|
95
|
+
// the current directory. Say which mistake was made instead.
|
|
96
|
+
if (command.length > 0 && !command[0].includes('/')) {
|
|
97
|
+
return { ok: false, usage: `'${command[0]}' must be a path to the binary, not a name to look up on PATH` };
|
|
98
|
+
}
|
|
99
|
+
return { ok: true, invocation: { target, workspaceRoot, command } };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The message of whatever `ensureBuilt` rejected with. Nx rejects with plain
|
|
103
|
+
* objects as well as errors (its daemon client's `{ stack, message }`), and
|
|
104
|
+
* `String()` of one is `[object Object]`.
|
|
105
|
+
*/
|
|
106
|
+
export function describeError(error) {
|
|
107
|
+
if (error instanceof Error) {
|
|
108
|
+
return error.message;
|
|
109
|
+
}
|
|
110
|
+
if (typeof error === 'object' && error !== null && 'message' in error && typeof error.message === 'string') {
|
|
111
|
+
return error.message;
|
|
112
|
+
}
|
|
113
|
+
return typeof error === 'string'
|
|
114
|
+
? error
|
|
115
|
+
: inspect(error, { breakLength: Number.POSITIVE_INFINITY, colors: false, depth: 5 });
|
|
116
|
+
}
|
|
47
117
|
/**
|
|
48
118
|
* First reason the task set cannot be replayed, considering only recorded
|
|
49
119
|
* results — no filesystem access. `null` means every task is a recorded
|
|
@@ -100,49 +170,44 @@ export function unvouched(entries, verdicts) {
|
|
|
100
170
|
* the workspace's own `nx` CLI unconditionally.
|
|
101
171
|
*/
|
|
102
172
|
export async function ensureBuilt(options) {
|
|
173
|
+
return withWorkspaceBinding(options, ensureBuiltInWorkspace);
|
|
174
|
+
}
|
|
175
|
+
/** Read current producer evidence without running tasks or writing producer outputs. */
|
|
176
|
+
export async function probeBuilt(options) {
|
|
177
|
+
return withWorkspaceBinding(options, probeBuiltInWorkspace);
|
|
178
|
+
}
|
|
179
|
+
async function withWorkspaceBinding(options, operation) {
|
|
103
180
|
const selector = parseTargetSelector(options.target);
|
|
104
181
|
if (!selector) {
|
|
105
182
|
throw new Error(`ensureBuilt: '${options.target}' is not a project:target[:configuration] selector`);
|
|
106
183
|
}
|
|
107
|
-
//
|
|
108
|
-
// caller meant.
|
|
184
|
+
// Resolve before chdir so a relative cwd still means what the caller meant.
|
|
109
185
|
const workspaceRoot = resolve(options.cwd);
|
|
110
186
|
const callerCwd = process.cwd();
|
|
111
187
|
const callerEnv = { ...process.env };
|
|
112
|
-
|
|
113
|
-
// workspace asked for, decided before the chdir and the rebinding below. The
|
|
114
|
-
// caller's workspace is the one its own Nx would bind: `NX_WORKSPACE_ROOT_PATH`
|
|
115
|
-
// when set, else the nearest `nx.json` above where it stands (none, when it
|
|
116
|
-
// stands in no workspace).
|
|
117
|
-
const callerRoot = callerEnv.NX_WORKSPACE_ROOT_PATH
|
|
118
|
-
? resolve(callerCwd, callerEnv.NX_WORKSPACE_ROOT_PATH)
|
|
119
|
-
: findNxWorkspaceRoot(callerCwd);
|
|
120
|
-
const callerOwnsRoot = callerRoot !== null && isSameDirectory(callerRoot, workspaceRoot);
|
|
188
|
+
const callerOwnsRoot = callerOwnsWorkspace(callerEnv, callerCwd, workspaceRoot);
|
|
121
189
|
try {
|
|
122
|
-
//
|
|
123
|
-
// cache. Everything below — plugin hooks, `runtime` inputs, and the hasher,
|
|
124
|
-
// which keys against `process.cwd()` — has to see the same directory or the
|
|
125
|
-
// probe keys differently from the CLI and never hits.
|
|
190
|
+
// Nx's hooks, runtime inputs and hasher see the provider's own workspace.
|
|
126
191
|
process.chdir(workspaceRoot);
|
|
127
|
-
|
|
192
|
+
const environment = workspaceEnvironment(callerEnv, workspaceRoot, callerOwnsRoot);
|
|
193
|
+
if (!callerOwnsRoot) {
|
|
194
|
+
const binding = bindWorkspaceSocketDirectory(workspaceRoot, selectorTaskId(selector), environment);
|
|
195
|
+
if (binding !== undefined) {
|
|
196
|
+
if (typeof binding !== 'string') {
|
|
197
|
+
process.stderr.write(`ensureBuilt: ${binding.reason.workspaceRoot}: ${binding.reason.detail}\n`);
|
|
198
|
+
return binding;
|
|
199
|
+
}
|
|
200
|
+
environment.NX_SOCKET_DIR = binding;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
assignEnvironment(process.env, environment);
|
|
204
|
+
return await operation(workspaceRoot, selector);
|
|
128
205
|
}
|
|
129
206
|
finally {
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
// — would inherit NX_WORKSPACE_ROOT_PATH, the stream/prefix flags, and
|
|
133
|
-
// whatever a plugin's preTasksExecution hook injected. The wrapper this
|
|
134
|
-
// replaces got that isolation for free by running Nx in a child.
|
|
207
|
+
// Never lend this provider's cwd, Nx binding or hook-injected environment
|
|
208
|
+
// to the caller or whatever it executes after this operation.
|
|
135
209
|
process.chdir(callerCwd);
|
|
136
|
-
|
|
137
|
-
if (!(key in callerEnv)) {
|
|
138
|
-
delete process.env[key];
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
for (const [key, value] of Object.entries(callerEnv)) {
|
|
142
|
-
if (process.env[key] !== value) {
|
|
143
|
-
process.env[key] = value;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
210
|
+
assignEnvironment(process.env, callerEnv);
|
|
146
211
|
}
|
|
147
212
|
}
|
|
148
213
|
/**
|
|
@@ -161,6 +226,52 @@ const WORKSPACE_STATE_ENV_KEYS = [
|
|
|
161
226
|
'NX_WORKSPACE_DATA_DIRECTORY',
|
|
162
227
|
'NX_CACHE_DIRECTORY',
|
|
163
228
|
];
|
|
229
|
+
/** A socket binding refusal is the existing failed outcome, including the owner's real exit. */
|
|
230
|
+
function workspaceSocketRefusal(workspaceRoot, taskId, detail, exitCode, signal) {
|
|
231
|
+
return {
|
|
232
|
+
disposition: 'failed',
|
|
233
|
+
reason: { kind: 'workspace-socket', taskId, workspaceRoot, detail },
|
|
234
|
+
exitCode,
|
|
235
|
+
signal,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* A foreign-root call inside a managed shell asks the same packaged socket
|
|
240
|
+
* owner that shell uses. The owner reads the provider's binding or derives a
|
|
241
|
+
* namespace from its canonical checkout spelling under DEVENV_RUNTIME.
|
|
242
|
+
* Outside a managed shell Nx keeps its normal defaults. No caller socket is reused.
|
|
243
|
+
*/
|
|
244
|
+
function bindWorkspaceSocketDirectory(workspaceRoot, taskId, environment) {
|
|
245
|
+
const runtime = environment.DEVENV_RUNTIME;
|
|
246
|
+
if (runtime === undefined || runtime === '')
|
|
247
|
+
return undefined;
|
|
248
|
+
if (!isAbsolute(runtime))
|
|
249
|
+
return workspaceSocketRefusal(workspaceRoot, taskId, 'DEVENV_RUNTIME must name the managed shell runtime directory', 1, null);
|
|
250
|
+
const script = join(managedAssetsRoot, 'raw/tooling/direnv/nx-socket-dir.sh');
|
|
251
|
+
const result = spawnSync('/bin/sh', ['-c', '. "$1" && printf %s "$NX_SOCKET_DIR"', 'sh', script], {
|
|
252
|
+
cwd: workspaceRoot,
|
|
253
|
+
env: { ...environment, PWD: workspaceRoot },
|
|
254
|
+
encoding: 'utf8',
|
|
255
|
+
});
|
|
256
|
+
if (result.error !== undefined)
|
|
257
|
+
return workspaceSocketRefusal(workspaceRoot, taskId, `socket owner could not start: ${result.error.message}; stdout: ${result.stdout}; stderr: ${result.stderr}`, 1, null);
|
|
258
|
+
if (result.status !== 0) {
|
|
259
|
+
return workspaceSocketRefusal(workspaceRoot, taskId, `socket owner ended ${result.signal === null ? `with exit ${result.status}` : `by ${result.signal}`}: ${result.stderr}; stdout: ${result.stdout}`, result.status ?? 1, result.signal);
|
|
260
|
+
}
|
|
261
|
+
const directory = result.stdout;
|
|
262
|
+
if (directory === '' || !isAbsolute(directory))
|
|
263
|
+
return workspaceSocketRefusal(workspaceRoot, taskId, `socket owner returned no absolute directory: ${directory}; stderr: ${result.stderr}`, 1, null);
|
|
264
|
+
try {
|
|
265
|
+
if (!statSync(directory).isDirectory())
|
|
266
|
+
return workspaceSocketRefusal(workspaceRoot, taskId, `socket owner returned a non-directory: ${directory}; stderr: ${result.stderr}`, 1, null);
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
return workspaceSocketRefusal(workspaceRoot, taskId, `socket owner returned an unavailable directory ${directory}: ${error instanceof Error ? error.message : String(error)}; stderr: ${result.stderr}`, 1, null);
|
|
270
|
+
}
|
|
271
|
+
if (result.stderr !== '')
|
|
272
|
+
process.stderr.write(result.stderr);
|
|
273
|
+
return directory;
|
|
274
|
+
}
|
|
164
275
|
/**
|
|
165
276
|
* The nearest directory at or above `from` holding an `nx.json`, or null.
|
|
166
277
|
* The marker this wrapper roots a workspace at when `--workspace-root` is
|
|
@@ -190,113 +301,302 @@ function isSameDirectory(left, right) {
|
|
|
190
301
|
}
|
|
191
302
|
}
|
|
192
303
|
/**
|
|
193
|
-
*
|
|
194
|
-
* `
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
* the per-root defaults. Nothing is reset or bypassed: the root's own daemon
|
|
199
|
-
* and cache are used as they stand. `ensureBuilt` restores the caller's
|
|
200
|
-
* environment when it returns.
|
|
304
|
+
* Whether the environment a caller was launched with belongs to
|
|
305
|
+
* `workspaceRoot`. The caller's workspace is the one its own Nx would bind:
|
|
306
|
+
* `NX_WORKSPACE_ROOT_PATH` when set (relative to where it stands), else the
|
|
307
|
+
* nearest `nx.json` at or above where it stands — none, when it stands in no
|
|
308
|
+
* workspace.
|
|
201
309
|
*/
|
|
202
|
-
function
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
310
|
+
export function callerOwnsWorkspace(callerEnv, callerCwd, workspaceRoot) {
|
|
311
|
+
const callerRoot = callerEnv.NX_WORKSPACE_ROOT_PATH
|
|
312
|
+
? resolve(callerCwd, callerEnv.NX_WORKSPACE_ROOT_PATH)
|
|
313
|
+
: findNxWorkspaceRoot(callerCwd);
|
|
314
|
+
return callerRoot !== null && isSameDirectory(callerRoot, workspaceRoot);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* The environment every Nx this call starts runs under — the daemon client
|
|
318
|
+
* loaded below and the `nx` CLI a miss spawns: the caller's, pointed at
|
|
319
|
+
* `workspaceRoot`, with that workspace's state locations. A caller that was set
|
|
320
|
+
* up for this same root keeps its overrides: they are the owner's cache and
|
|
321
|
+
* sandbox boundary. A caller set up for another root, or for none, passes none
|
|
322
|
+
* of them on, so Nx falls back to the per-root defaults. Nothing is reset or
|
|
323
|
+
* bypassed: the root's own daemon and cache are used as they stand. Every one of
|
|
324
|
+
* them answers from the root's installed Nx (`NX_USE_LOCAL=true`): a daemon
|
|
325
|
+
* otherwise installs `nx@latest` to answer Nx Console's status, and a client
|
|
326
|
+
* without the variable recomputes the daemon's graph.
|
|
327
|
+
*/
|
|
328
|
+
export function workspaceEnvironment(callerEnv, workspaceRoot, callerOwnsRoot) {
|
|
329
|
+
const env = { ...callerEnv, NX_WORKSPACE_ROOT_PATH: workspaceRoot, NX_USE_LOCAL: 'true' };
|
|
330
|
+
if (!callerOwnsRoot) {
|
|
331
|
+
for (const key of WORKSPACE_STATE_ENV_KEYS) {
|
|
332
|
+
delete env[key];
|
|
333
|
+
}
|
|
206
334
|
}
|
|
207
|
-
|
|
208
|
-
|
|
335
|
+
return env;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Make `target` hold exactly the variables of `env`: each one missing from
|
|
339
|
+
* `env` removed, each one different set. Nx reads its configuration from
|
|
340
|
+
* `process.env` in this process, so that is where an environment is put in
|
|
341
|
+
* place, and where the caller's is put back.
|
|
342
|
+
*/
|
|
343
|
+
export function assignEnvironment(target, env) {
|
|
344
|
+
for (const key of Object.keys(target)) {
|
|
345
|
+
if (env[key] === undefined) {
|
|
346
|
+
delete target[key];
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
for (const [key, value] of Object.entries(env)) {
|
|
350
|
+
if (value !== undefined && target[key] !== value) {
|
|
351
|
+
target[key] = value;
|
|
352
|
+
}
|
|
209
353
|
}
|
|
210
354
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
355
|
+
/**
|
|
356
|
+
* An outer Nx task exports its own cache-bypass setting to the process it
|
|
357
|
+
* launches. That setting describes the outer task, not the nested target:
|
|
358
|
+
* inheriting it makes the inner runner refuse cache writes forever. Outside an
|
|
359
|
+
* Nx task child, however, the same variables are the caller's explicit request
|
|
360
|
+
* to force this target to rebuild and remain authoritative.
|
|
361
|
+
*/
|
|
362
|
+
export function withoutOuterTaskCacheBypass(env) {
|
|
363
|
+
const nested = { ...env };
|
|
364
|
+
if (nested.NX_TASK_TARGET_PROJECT !== undefined || nested.NX_TASK_TARGET_TARGET !== undefined) {
|
|
365
|
+
delete nested.NX_SKIP_NX_CACHE;
|
|
366
|
+
delete nested.NX_DISABLE_NX_CACHE;
|
|
367
|
+
}
|
|
368
|
+
return nested;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* A caller-requested cache bypass is the only miss known before hashing.
|
|
372
|
+
* Workspace changes first refresh the authoritative graph; the probe then
|
|
373
|
+
* decides whether these current inputs have matching artifacts.
|
|
374
|
+
*/
|
|
375
|
+
export function missBeforeProbe(env, taskId) {
|
|
376
|
+
if (env.NX_SKIP_NX_CACHE === 'true' || env.NX_DISABLE_NX_CACHE === 'true') {
|
|
377
|
+
return { kind: 'cache-disabled', taskId };
|
|
378
|
+
}
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
async function prepareWorkspaceProbe(workspaceRoot, selector) {
|
|
382
|
+
const taskId = selectorTaskId(selector);
|
|
383
|
+
// This explicit fallback path loads no Nx. The build operation may run the
|
|
384
|
+
// checkout-local CLI; the read-only operation can only report the miss.
|
|
216
385
|
if (process.env.NX_DAEMON === 'false') {
|
|
217
|
-
return
|
|
386
|
+
return { kind: 'no-daemon', reason: { kind: 'no-daemon', taskId } };
|
|
218
387
|
}
|
|
219
|
-
//
|
|
220
|
-
// the workspace's running daemon. Resolve every runtime module from the
|
|
221
|
-
// target checkout rather than this package's own dependency: a reusable
|
|
222
|
-
// wrapper must keep using the daemon after the workspace takes an Nx patch.
|
|
388
|
+
// Runtime modules always belong to the provider's installed Nx version.
|
|
223
389
|
const requireNx = createWorkspaceNxRequire(workspaceRoot);
|
|
224
390
|
bindWorkspaceRoot(workspaceRoot, requireNx);
|
|
225
391
|
const { daemonClient } = requireNx('nx/src/daemon/client/client');
|
|
226
392
|
if (!daemonClient.enabled()) {
|
|
227
|
-
return
|
|
228
|
-
}
|
|
229
|
-
// An outer Nx task exports its own cache-bypass setting to the process it
|
|
230
|
-
// launches. That setting describes the outer task, not the nested target:
|
|
231
|
-
// inheriting it makes the inner runner refuse cache writes forever. Outside
|
|
232
|
-
// an Nx task child, however, the same variables are the caller's explicit
|
|
233
|
-
// request to force this target to rebuild and must remain authoritative.
|
|
234
|
-
if (process.env.NX_TASK_TARGET_PROJECT !== undefined || process.env.NX_TASK_TARGET_TARGET !== undefined) {
|
|
235
|
-
delete process.env.NX_SKIP_NX_CACHE;
|
|
236
|
-
delete process.env.NX_DISABLE_NX_CACHE;
|
|
393
|
+
return { kind: 'no-daemon', reason: { kind: 'no-daemon', taskId } };
|
|
237
394
|
}
|
|
395
|
+
assignEnvironment(process.env, withoutOuterTaskCacheBypass(process.env));
|
|
238
396
|
const { readNxJson } = requireNx('nx/src/config/nx-json');
|
|
239
397
|
const { splitArgsIntoNxArgsAndOverrides } = requireNx('nx/src/utils/command-line-utils');
|
|
240
398
|
const { setEnvVarsBasedOnArgs } = requireNx('nx/src/tasks-runner/run-command');
|
|
241
399
|
const { createTaskGraph } = requireNx('nx/src/tasks-runner/create-task-graph');
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
// are derived from these arguments, so anything hand-rolled here instead of
|
|
246
|
-
// routed through Nx's own argument normalization would key the cache
|
|
247
|
-
// differently from the CLI and turn every probe into a miss.
|
|
248
|
-
const { nxArgs, overrides } = splitArgsIntoNxArgsAndOverrides({ targets: [selector.target], configuration: selector.configuration, outputStyle: onMiss }, 'run-one', { printWarnings: false }, nxJson);
|
|
400
|
+
let nxJson = readNxJson();
|
|
401
|
+
// Both operations key exactly like nx run <selector> --outputStyle=stream.
|
|
402
|
+
const { nxArgs, overrides } = splitArgsIntoNxArgsAndOverrides({ targets: [selector.target], configuration: selector.configuration, outputStyle: 'stream' }, 'run-one', { printWarnings: false }, nxJson);
|
|
249
403
|
const loadDotEnvFiles = process.env.NX_LOAD_DOT_ENV_FILES !== 'false';
|
|
250
|
-
// Sets NX_LOAD_DOT_ENV_FILES and the stream/prefix flags, which the hasher
|
|
251
|
-
// reads through each task's environment. It has to happen before hashing or
|
|
252
|
-
// the probe keys differently from the CLI.
|
|
253
404
|
setEnvVarsBasedOnArgs(nxArgs, loadDotEnvFiles);
|
|
254
405
|
performance.mark('ensureBuilt:graph:start');
|
|
255
|
-
const
|
|
406
|
+
const projectGraph = await currentProjectGraph(workspaceRoot, nxJson, requireNx);
|
|
407
|
+
nxJson = readNxJson();
|
|
256
408
|
requireProject(projectGraph, selector.project);
|
|
257
409
|
const taskGraph = createTaskGraph(projectGraph, {}, [selector.project], [selector.target], selector.configuration, overrides, false);
|
|
258
410
|
const tasks = Object.values(taskGraph.tasks);
|
|
259
411
|
performance.measure('ensureBuilt:graph', 'ensureBuilt:graph:start');
|
|
260
|
-
|
|
412
|
+
return { kind: 'ready', nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx };
|
|
413
|
+
}
|
|
414
|
+
async function withTaskHooks(workspaceRoot, selector, prepared, operation) {
|
|
415
|
+
const hooks = prepared.requireNx('nx/src/project-graph/plugins/tasks-execution-hooks');
|
|
261
416
|
const runId = randomUUID();
|
|
262
417
|
const startTime = Date.now();
|
|
263
|
-
//
|
|
264
|
-
// `env` inputs hash against them. Skipping the hook would not merely cost
|
|
265
|
-
// hits: the run below would then execute with a different environment than
|
|
266
|
-
// the CLI does, record a hash the CLI never looks up, and thrash the cache.
|
|
418
|
+
// Hook-injected env participates in hashing for both real operations.
|
|
267
419
|
await hooks.runPreTasksExecution({
|
|
268
420
|
id: runId,
|
|
269
421
|
workspaceRoot,
|
|
270
|
-
nxJsonConfiguration: nxJson,
|
|
422
|
+
nxJsonConfiguration: prepared.nxJson,
|
|
271
423
|
argv: process.argv,
|
|
272
424
|
});
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if (process.env.NX_SKIP_NX_CACHE === 'true' || process.env.NX_DISABLE_NX_CACHE === 'true') {
|
|
276
|
-
reason = { kind: 'cache-disabled', taskId: selectorTaskId(selector) };
|
|
277
|
-
}
|
|
278
|
-
else if (inputsChanged) {
|
|
279
|
-
reason = { kind: 'stale-inputs', taskId: selectorTaskId(selector) };
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
reason = await probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx);
|
|
283
|
-
}
|
|
284
|
-
performance.measure('ensureBuilt:probe', 'ensureBuilt:probe:start');
|
|
285
|
-
// The CLI runs the hooks around its own run, under its own id. This process
|
|
286
|
-
// ran none of the tasks, so it reports none for the id it opened.
|
|
287
|
-
const result = reason === null ? HIT : await runViaCli(workspaceRoot, selector, reason);
|
|
425
|
+
const result = await operation(workspaceRoot, selector, prepared);
|
|
426
|
+
// Any runner owns its own hook id; this process executed no tasks.
|
|
288
427
|
await hooks.runPostTasksExecution({
|
|
289
428
|
id: runId,
|
|
290
429
|
taskResults: NO_TASK_RESULTS,
|
|
291
430
|
workspaceRoot,
|
|
292
|
-
nxJsonConfiguration: nxJson,
|
|
431
|
+
nxJsonConfiguration: prepared.nxJson,
|
|
293
432
|
argv: process.argv,
|
|
294
433
|
startTime,
|
|
295
434
|
endTime: Date.now(),
|
|
296
435
|
});
|
|
297
436
|
return result;
|
|
298
437
|
}
|
|
299
|
-
function
|
|
438
|
+
async function ensureBuiltInWorkspace(workspaceRoot, selector) {
|
|
439
|
+
const prepared = await prepareWorkspaceProbe(workspaceRoot, selector);
|
|
440
|
+
if (prepared.kind === 'no-daemon')
|
|
441
|
+
return runViaCli(workspaceRoot, selector, prepared.reason);
|
|
442
|
+
return withTaskHooks(workspaceRoot, selector, prepared, buildPreparedTarget);
|
|
443
|
+
}
|
|
444
|
+
async function buildPreparedTarget(workspaceRoot, selector, prepared) {
|
|
445
|
+
const { nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx } = prepared;
|
|
446
|
+
performance.mark('ensureBuilt:probe:start');
|
|
447
|
+
const reason = missBeforeProbe(process.env, selectorTaskId(selector)) ??
|
|
448
|
+
(await probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx));
|
|
449
|
+
performance.measure('ensureBuilt:probe', 'ensureBuilt:probe:start');
|
|
450
|
+
return reason === null ? HIT : runViaCli(workspaceRoot, selector, reason);
|
|
451
|
+
}
|
|
452
|
+
async function probeBuiltInWorkspace(workspaceRoot, selector) {
|
|
453
|
+
const prepared = await prepareWorkspaceProbe(workspaceRoot, selector);
|
|
454
|
+
if (prepared.kind === 'no-daemon')
|
|
455
|
+
return { disposition: 'miss', reason: prepared.reason };
|
|
456
|
+
const probeSource = captureProbeSource(workspaceRoot, prepared.requireNx);
|
|
457
|
+
return withTaskHooks(workspaceRoot, selector, prepared, async (root, selected, current) => {
|
|
458
|
+
const { nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx } = current;
|
|
459
|
+
const taskId = selectorTaskId(selected);
|
|
460
|
+
performance.mark('ensureBuilt:probe:start');
|
|
461
|
+
const reason = missBeforeProbe(process.env, taskId) ??
|
|
462
|
+
(await probe(root, nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx, true));
|
|
463
|
+
performance.measure('ensureBuilt:probe', 'ensureBuilt:probe:start');
|
|
464
|
+
if (reason !== null)
|
|
465
|
+
return { disposition: 'miss', reason };
|
|
466
|
+
let result = providerReceipt(root, taskId, tasks, providerInputProof(root, nxJson, projectGraph, taskGraph, requireNx), requireNx('nx/src/native').expandOutputs);
|
|
467
|
+
if (result.disposition === 'hit') {
|
|
468
|
+
const after = captureProbeSource(root, requireNx);
|
|
469
|
+
if (!snapshotsEqual(probeSource, after) || !nodesUnchanged(probeSource.nodes)) {
|
|
470
|
+
result = {
|
|
471
|
+
disposition: 'failed',
|
|
472
|
+
reason: {
|
|
473
|
+
kind: 'provider-proof',
|
|
474
|
+
taskId,
|
|
475
|
+
workspaceRoot: root,
|
|
476
|
+
detail: 'Provider source nodes or membership moved across Nx hashing/receipt capture',
|
|
477
|
+
},
|
|
478
|
+
exitCode: 1,
|
|
479
|
+
signal: null,
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
if (result.disposition === 'failed') {
|
|
484
|
+
process.stderr.write(`probeBuilt: ${result.reason.workspaceRoot}: ${result.reason.detail}\n`);
|
|
485
|
+
}
|
|
486
|
+
return result;
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
function captureProbeSource(workspaceRoot, requireNx) {
|
|
490
|
+
const { WorkspaceContext } = requireNx('nx/src/native');
|
|
491
|
+
const { workspaceDataDirectoryForWorkspace } = requireNx('nx/src/utils/cache-directory');
|
|
492
|
+
const data = workspaceDataDirectoryForWorkspace(workspaceRoot);
|
|
493
|
+
const previous = readGraphWitness(join(data, 'ensure-built-graph.json'));
|
|
494
|
+
return workspaceSnapshot(workspaceRoot, new WorkspaceContext(workspaceRoot, data), previous?.snapshot);
|
|
495
|
+
}
|
|
496
|
+
/** Nx's native plan is the FILE selection oracle, not a second glob planner.
|
|
497
|
+
* Config identities skipped by the inspector are included explicitly. A
|
|
498
|
+
* runtime identity is bounded only by the owning toolchain recipe + a declared
|
|
499
|
+
* pin; opaque commands and unavailable native proof categorically refuse.
|
|
500
|
+
*/
|
|
501
|
+
function providerInputProof(workspaceRoot, nxJson, projectGraph, taskGraph, requireNx) {
|
|
502
|
+
const { WorkspaceContext, HashPlanInspector, HashPlanner, transferProjectGraph } = requireNx('nx/src/native');
|
|
503
|
+
const { transformProjectGraphForRust } = requireNx('nx/src/native/transform-objects');
|
|
504
|
+
const { createProjectRootMappings } = requireNx('nx/src/project-graph/utils/find-project-for-path');
|
|
505
|
+
const { workspaceDataDirectoryForWorkspace } = requireNx('nx/src/utils/cache-directory');
|
|
506
|
+
const context = new WorkspaceContext(workspaceRoot, workspaceDataDirectoryForWorkspace(workspaceRoot));
|
|
507
|
+
const { externalReferences } = context.getWorkspaceFiles(Object.fromEntries(createProjectRootMappings(projectGraph.nodes)));
|
|
508
|
+
if (externalReferences === undefined) {
|
|
509
|
+
return {
|
|
510
|
+
kind: 'conservative-provider-source',
|
|
511
|
+
files: [],
|
|
512
|
+
inputs: {},
|
|
513
|
+
runtimeSource: { kind: 'opaque', detail: 'Nx supplied no native file-input proof' },
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
const planner = new HashPlanner(nxJson, transferProjectGraph(transformProjectGraphForRust(projectGraph)));
|
|
517
|
+
const inspector = new HashPlanInspector(externalReferences.allWorkspaceFiles, externalReferences.projectFiles, workspaceRoot);
|
|
518
|
+
const inputs = inspector.inspectInputs(planner.getPlansReference(Object.keys(taskGraph.tasks), taskGraph));
|
|
519
|
+
const files = new Set();
|
|
520
|
+
const directories = new Set();
|
|
521
|
+
const projects = new Set();
|
|
522
|
+
function includeProject(name) {
|
|
523
|
+
if (projects.has(name))
|
|
524
|
+
return;
|
|
525
|
+
projects.add(name);
|
|
526
|
+
const node = projectGraph.nodes[name];
|
|
527
|
+
if (node === undefined)
|
|
528
|
+
return;
|
|
529
|
+
directories.add(node.data.root);
|
|
530
|
+
for (const file of ['project.json', 'package.json']) {
|
|
531
|
+
const path = join(node.data.root, file);
|
|
532
|
+
if (existsSync(join(workspaceRoot, path)))
|
|
533
|
+
files.add(path);
|
|
534
|
+
}
|
|
535
|
+
for (const dependency of projectGraph.dependencies[name] ?? [])
|
|
536
|
+
includeProject(dependency.target);
|
|
537
|
+
}
|
|
538
|
+
let conservative = false;
|
|
539
|
+
const projectConfigs = Object.fromEntries(Object.entries(projectGraph.nodes).map(([name, node]) => [name, node.data]));
|
|
540
|
+
const { getCustomHasher } = requireNx('nx/src/tasks-runner/utils');
|
|
541
|
+
for (const task of Object.values(taskGraph.tasks)) {
|
|
542
|
+
const input = inputs[task.id];
|
|
543
|
+
if (input === undefined || getCustomHasher(task, projectConfigs) !== null) {
|
|
544
|
+
return {
|
|
545
|
+
kind: 'conservative-provider-source',
|
|
546
|
+
files: [...files],
|
|
547
|
+
inputs,
|
|
548
|
+
runtimeSource: { kind: 'opaque', detail: `No complete native FILE/runtime plan for ${task.id}` },
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
for (const file of input.files)
|
|
552
|
+
files.add(file);
|
|
553
|
+
if (input.runtime.length > 0 || input.environment.length > 0)
|
|
554
|
+
conservative = true;
|
|
555
|
+
const node = projectGraph.nodes[task.target.project];
|
|
556
|
+
if (node === undefined)
|
|
557
|
+
throw new Error(`Lost project for receipt ${task.id}`);
|
|
558
|
+
includeProject(node.name);
|
|
559
|
+
const target = node.data.targets?.[task.target.target];
|
|
560
|
+
const options = {
|
|
561
|
+
...target?.options,
|
|
562
|
+
...(task.target.configuration === undefined ? {} : target?.configurations?.[task.target.configuration]),
|
|
563
|
+
...task.overrides,
|
|
564
|
+
};
|
|
565
|
+
if (typeof options.cwd === 'string') {
|
|
566
|
+
directories.add(options.cwd);
|
|
567
|
+
directories.add(options.cwd.replaceAll('{projectRoot}', node.data.root).replaceAll('{workspaceRoot}', '.'));
|
|
568
|
+
}
|
|
569
|
+
for (const name of ['project.json', 'package.json']) {
|
|
570
|
+
const path = join(node.data.root, name);
|
|
571
|
+
if (existsSync(join(workspaceRoot, path)))
|
|
572
|
+
files.add(path);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
for (const path of [
|
|
576
|
+
'nx.json',
|
|
577
|
+
'package.json',
|
|
578
|
+
'bun.lock',
|
|
579
|
+
'bun.lockb',
|
|
580
|
+
'package-lock.json',
|
|
581
|
+
'pnpm-lock.yaml',
|
|
582
|
+
'yarn.lock',
|
|
583
|
+
'tsconfig.json',
|
|
584
|
+
'tsconfig.base.json',
|
|
585
|
+
]) {
|
|
586
|
+
if (existsSync(join(workspaceRoot, path)))
|
|
587
|
+
files.add(path);
|
|
588
|
+
}
|
|
589
|
+
const installation = graphInstallationIdentity(workspaceRoot, nxJson, requireNx('nx/src/utils/package-json').readModulePackageJson);
|
|
590
|
+
const runtimeSource = boundedReceiptRuntimes(inputs, [...directories], [...files], installation !== null);
|
|
591
|
+
return {
|
|
592
|
+
kind: conservative ? 'conservative-provider-source' : 'exact-file-inputs',
|
|
593
|
+
files: [...files],
|
|
594
|
+
inputs,
|
|
595
|
+
runtimeSource,
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
/** The id Nx gives the task `selector` names, and the one a miss runs. */
|
|
599
|
+
export function selectorTaskId(selector) {
|
|
300
600
|
return selector.configuration === undefined
|
|
301
601
|
? `${selector.project}:${selector.target}`
|
|
302
602
|
: `${selector.project}:${selector.target}:${selector.configuration}`;
|
|
@@ -307,8 +607,8 @@ function selectorTaskId(selector) {
|
|
|
307
607
|
* a module-level singleton that reads `nx.json` from that root. So the root has
|
|
308
608
|
* to be bound before the first Nx module loads, which is why this module
|
|
309
609
|
* imports Nx dynamically throughout. A static import at the top of the file
|
|
310
|
-
* would bind the caller's launch directory instead. `
|
|
311
|
-
*
|
|
610
|
+
* would bind the caller's launch directory instead. `ensureBuilt` has already
|
|
611
|
+
* set `NX_WORKSPACE_ROOT_PATH`; this loads Nx and checks it took.
|
|
312
612
|
*/
|
|
313
613
|
function bindWorkspaceRoot(workspaceRoot, requireNx) {
|
|
314
614
|
if (process.env.NX_PERF_LOGGING === 'true') {
|
|
@@ -325,62 +625,78 @@ function bindWorkspaceRoot(workspaceRoot, requireNx) {
|
|
|
325
625
|
throw new Error(`ensureBuilt: Nx is already bound to workspace root ${boundRoot}, cannot switch to ${workspaceRoot}`);
|
|
326
626
|
}
|
|
327
627
|
}
|
|
328
|
-
/**
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
* Take Nx's native, ignore-aware disk snapshot and compare it with the
|
|
333
|
-
* daemon's file table; its metadata cache reuses unchanged file hashes.
|
|
334
|
-
*
|
|
335
|
-
* Any difference is handed to the daemon so its next graph is current, but
|
|
336
|
-
* that only schedules a recomputation, and a probe meanwhile would hash
|
|
337
|
-
* against the file map it already has. So the caller does not probe: if any
|
|
338
|
-
* differing path is not a declared output of a task in the graph, this
|
|
339
|
-
* returns true and the target is run, which lets Nx's own runner wait for the
|
|
340
|
-
* recomputation. Output paths are exempt because a build's own writes are the
|
|
341
|
-
* commonest thing to reach here before the watcher does, and treating them as
|
|
342
|
-
* a miss would make every hit after a build replay the cached log.
|
|
628
|
+
/** An exact graph-input witness skips graph transfer, never task hashing.
|
|
629
|
+
* Reconcile disk with the daemon BEFORE asking for a graph; publish evidence
|
|
630
|
+
* only when the filesystem and plugin installation stay identical across the
|
|
631
|
+
* awaited authoritative generation. No disk-cache age or existence is proof.
|
|
343
632
|
*/
|
|
344
|
-
async function
|
|
633
|
+
async function currentProjectGraph(workspaceRoot, nxJson, requireNx) {
|
|
345
634
|
const { daemonClient } = requireNx('nx/src/daemon/client/client');
|
|
346
|
-
const { WorkspaceContext
|
|
635
|
+
const { WorkspaceContext } = requireNx('nx/src/native');
|
|
347
636
|
const { workspaceDataDirectoryForWorkspace } = requireNx('nx/src/utils/cache-directory');
|
|
637
|
+
const packageResolution = requireNx('nx/src/utils/package-json');
|
|
638
|
+
const data = workspaceDataDirectoryForWorkspace(workspaceRoot);
|
|
639
|
+
const witnessPath = join(data, 'ensure-built-graph.json');
|
|
640
|
+
const witness = readGraphWitness(witnessPath);
|
|
641
|
+
const environment = createHash('sha256')
|
|
642
|
+
.update(JSON.stringify(Object.entries(process.env).sort(([left], [right]) => left.localeCompare(right))))
|
|
643
|
+
.digest('hex');
|
|
348
644
|
performance.mark('ensureBuilt:inputs:start');
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
const createdFiles = [];
|
|
357
|
-
const updatedFiles = [];
|
|
358
|
-
for (const { file, hash } of context.allFileData()) {
|
|
359
|
-
const previousHash = previousHashes.get(file);
|
|
360
|
-
if (previousHash === undefined) {
|
|
361
|
-
createdFiles.push(file);
|
|
362
|
-
}
|
|
363
|
-
else if (previousHash !== hash) {
|
|
364
|
-
updatedFiles.push(file);
|
|
365
|
-
}
|
|
366
|
-
previousHashes.delete(file);
|
|
367
|
-
}
|
|
368
|
-
const deletedFiles = [...previousHashes.keys()];
|
|
369
|
-
const changed = [...createdFiles, ...updatedFiles, ...deletedFiles];
|
|
370
|
-
let inputsChanged = false;
|
|
371
|
-
if (changed.length > 0) {
|
|
372
|
-
await daemonClient.updateWorkspaceContext(createdFiles, updatedFiles, deletedFiles);
|
|
373
|
-
// The same matcher the task runner uses to collect outputs, over the union
|
|
374
|
-
// of every task's declared outputs. A negation declared by one task then
|
|
375
|
-
// also excludes another task's output, which errs toward a miss.
|
|
376
|
-
const outputs = tasks.flatMap((task) => task.outputs);
|
|
377
|
-
inputsChanged = matchOutputPaths(outputs, changed).includes(false);
|
|
645
|
+
// The daemon's file-table RPC is retained even on reuse: task hashing must
|
|
646
|
+
// see writes the watcher has not delivered, independently of graph reuse.
|
|
647
|
+
const daemonFiles = await daemonClient.getWorkspaceContextFileData();
|
|
648
|
+
const before = workspaceSnapshot(workspaceRoot, new WorkspaceContext(workspaceRoot, data), witness?.snapshot);
|
|
649
|
+
const { created, updated, deleted } = workspaceFileChanges(daemonFiles, before.files);
|
|
650
|
+
if (created.length + updated.length + deleted.length > 0) {
|
|
651
|
+
await daemonClient.updateWorkspaceContext(created, updated, deleted);
|
|
378
652
|
}
|
|
379
653
|
performance.measure('ensureBuilt:inputs', 'ensureBuilt:inputs:start');
|
|
380
|
-
|
|
654
|
+
const installation = graphInstallationIdentity(workspaceRoot, nxJson, packageResolution.readModulePackageJson);
|
|
655
|
+
const cached = nodesUnchanged(before.nodes)
|
|
656
|
+
? reusableGraph(witness, workspaceRoot, environment, installation, before)
|
|
657
|
+
: null;
|
|
658
|
+
if (cached !== null)
|
|
659
|
+
return cached;
|
|
660
|
+
const { projectGraph } = await daemonClient.getProjectGraphAndSourceMaps();
|
|
661
|
+
const after = workspaceSnapshot(workspaceRoot, new WorkspaceContext(workspaceRoot, data), before);
|
|
662
|
+
const finalInstallation = graphInstallationIdentity(workspaceRoot, nxJson, packageResolution.readModulePackageJson);
|
|
663
|
+
const stableGeneration = snapshotsEqual(before, after) && nodesUnchanged(before.nodes);
|
|
664
|
+
if (installation !== null && installation === finalInstallation && stableGeneration) {
|
|
665
|
+
const next = { version: 1, workspaceRoot, environment, installation, snapshot: after, projectGraph };
|
|
666
|
+
writeWitness(witnessPath, next);
|
|
667
|
+
}
|
|
668
|
+
// A write during the await cannot authorize a saved graph. Feed the final
|
|
669
|
+
// snapshot to Nx and await its successor before current task hashing.
|
|
670
|
+
if (!stableGeneration) {
|
|
671
|
+
const currentDaemonFiles = await daemonClient.getWorkspaceContextFileData();
|
|
672
|
+
const changes = workspaceFileChanges(currentDaemonFiles, after.files);
|
|
673
|
+
await daemonClient.updateWorkspaceContext(changes.created, changes.updated, changes.deleted);
|
|
674
|
+
return (await daemonClient.getProjectGraphAndSourceMaps()).projectGraph;
|
|
675
|
+
}
|
|
676
|
+
return projectGraph;
|
|
677
|
+
}
|
|
678
|
+
/** Compare the daemon's file table with a snapshot of the disk, both as Nx lists them: path and content hash. */
|
|
679
|
+
export function workspaceFileChanges(daemonFiles, diskFiles) {
|
|
680
|
+
const daemonHashes = new Map();
|
|
681
|
+
for (const { file, hash } of daemonFiles) {
|
|
682
|
+
daemonHashes.set(file, hash);
|
|
683
|
+
}
|
|
684
|
+
const created = [];
|
|
685
|
+
const updated = [];
|
|
686
|
+
for (const { file, hash } of diskFiles) {
|
|
687
|
+
const daemonHash = daemonHashes.get(file);
|
|
688
|
+
if (daemonHash === undefined) {
|
|
689
|
+
created.push(file);
|
|
690
|
+
}
|
|
691
|
+
else if (daemonHash !== hash) {
|
|
692
|
+
updated.push(file);
|
|
693
|
+
}
|
|
694
|
+
daemonHashes.delete(file);
|
|
695
|
+
}
|
|
696
|
+
return { created, updated, deleted: [...daemonHashes.keys()] };
|
|
381
697
|
}
|
|
382
698
|
/** `null` when the target is already built; otherwise the first reason it is not. */
|
|
383
|
-
async function probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx) {
|
|
699
|
+
async function probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx, verifyAllArtifacts = false) {
|
|
384
700
|
const { daemonClient } = requireNx('nx/src/daemon/client/client');
|
|
385
701
|
const { DaemonBasedTaskHasher } = requireNx('nx/src/hasher/task-hasher');
|
|
386
702
|
const { getTaskDetails, hashTasks } = requireNx('nx/src/hasher/hash-task');
|
|
@@ -388,6 +704,7 @@ async function probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tas
|
|
|
388
704
|
const { getCache } = requireNx('nx/src/tasks-runner/cache');
|
|
389
705
|
const { getRunnerOptions } = requireNx('nx/src/tasks-runner/run-command');
|
|
390
706
|
const { getExecutorNameForTask } = requireNx('nx/src/tasks-runner/utils');
|
|
707
|
+
const { expandOutputs } = requireNx('nx/src/native');
|
|
391
708
|
// `isCloudDefault: false` because these options are only read here by the
|
|
392
709
|
// hasher, which looks at `selectivelyHashTsConfig`; the cloud credentials the
|
|
393
710
|
// flag would add belong to the cloud runner, and the run path calls Nx's own
|
|
@@ -413,14 +730,7 @@ async function probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tas
|
|
|
413
730
|
}
|
|
414
731
|
await hashTasks(hasher, projectGraph, taskGraph, perTaskEnvs, getTaskDetails(), tasks);
|
|
415
732
|
performance.measure('ensureBuilt:hash', 'ensureBuilt:hash:start');
|
|
416
|
-
|
|
417
|
-
// anything, and normalizes a command-less target that only names dependencies
|
|
418
|
-
// to one. A cache record would vouch for no work — the tasks it aggregates are
|
|
419
|
-
// in this graph and answer for themselves — so none is required. Demanding one
|
|
420
|
-
// made every call through an uncacheable aggregate hand the whole graph to Nx,
|
|
421
|
-
// which replays each dependency's cached log. Outputs a noop declares are
|
|
422
|
-
// still verified below, with every other task's.
|
|
423
|
-
const recordedTasks = tasks.filter((task) => getExecutorNameForTask(task, projectGraph) !== 'nx:noop');
|
|
733
|
+
const recorded = recordedTasks(tasks, (task) => getExecutorNameForTask(task, projectGraph));
|
|
424
734
|
// Nx's own factory, but deliberately never `init()`ed: that is what makes
|
|
425
735
|
// this a local-only, side-effect-free question. `init()` attaches the remote
|
|
426
736
|
// cache — a network round-trip, and a download is precisely the work this
|
|
@@ -429,12 +739,12 @@ async function probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tas
|
|
|
429
739
|
// outputs against, and an artifact missing from it is a miss.
|
|
430
740
|
performance.mark('ensureBuilt:cache:start');
|
|
431
741
|
const cache = getCache(runnerOptions);
|
|
432
|
-
const cachedResults = await cache.getBatch(
|
|
742
|
+
const cachedResults = await cache.getBatch(recorded.filter((task) => task.cache && task.hash));
|
|
433
743
|
const cachedCodeByHash = new Map();
|
|
434
744
|
for (const [hash, result] of cachedResults) {
|
|
435
745
|
cachedCodeByHash.set(hash, result.code);
|
|
436
746
|
}
|
|
437
|
-
const cacheMiss = firstCacheMiss(
|
|
747
|
+
const cacheMiss = firstCacheMiss(recorded, cachedCodeByHash);
|
|
438
748
|
performance.measure('ensureBuilt:cache', 'ensureBuilt:cache:start');
|
|
439
749
|
if (cacheMiss) {
|
|
440
750
|
return cacheMiss;
|
|
@@ -444,16 +754,11 @@ async function probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tas
|
|
|
444
754
|
// lives in the working tree, where anything may have deleted or rewritten it
|
|
445
755
|
// since. The daemon answers that cheaply from the output hashes it recorded
|
|
446
756
|
// when Nx last wrote them.
|
|
447
|
-
const claims =
|
|
448
|
-
for (const task of tasks) {
|
|
449
|
-
if (task.outputs.length > 0 && task.hash !== undefined) {
|
|
450
|
-
claims.push({ taskId: task.id, outputs: task.outputs, hash: task.hash });
|
|
451
|
-
}
|
|
452
|
-
}
|
|
757
|
+
const claims = outputClaims(tasks);
|
|
453
758
|
performance.mark('ensureBuilt:outputs:start');
|
|
454
759
|
const verdicts = await daemonClient.outputsHashesMatchBatch(claims.map(({ outputs, hash }) => ({ outputs, hash })));
|
|
455
760
|
performance.measure('ensureBuilt:outputs', 'ensureBuilt:outputs:start');
|
|
456
|
-
const doubted = unvouched(claims, verdicts);
|
|
761
|
+
const doubted = verifyAllArtifacts ? claims : unvouched(claims, verdicts);
|
|
457
762
|
if (doubted.length === 0) {
|
|
458
763
|
return null;
|
|
459
764
|
}
|
|
@@ -464,12 +769,81 @@ async function probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tas
|
|
|
464
769
|
// And a write the daemon processes more than 2 s after a record erases it,
|
|
465
770
|
// which a daemon busy hashing does to a restore's own writes — so each
|
|
466
771
|
// restore guarantees the next one. What settles the question is what a hit
|
|
467
|
-
// would restore: Nx's own local artifact for this exact hash.
|
|
468
|
-
// that already holds every entry of it is what the restore would leave.
|
|
469
|
-
// Anything else — no artifact, a difference, an error while reading — stays
|
|
470
|
-
// a miss.
|
|
772
|
+
// would restore: Nx's own local artifact for this exact hash.
|
|
471
773
|
performance.mark('ensureBuilt:artifacts:start');
|
|
472
|
-
|
|
774
|
+
// `recorded` excludes `nx:noop`, so a noop's declared outputs have no
|
|
775
|
+
// artifact here and stay a miss.
|
|
776
|
+
const { workspaceDataDirectoryForWorkspace } = requireNx('nx/src/utils/cache-directory');
|
|
777
|
+
const verdict = compareWithArtifacts(workspaceRoot, doubted, cachedResults, expandOutputs, join(workspaceDataDirectoryForWorkspace(workspaceRoot), 'ensure-built-outputs.json'));
|
|
778
|
+
if (verdict.kind === 'stale-outputs') {
|
|
779
|
+
return verdict;
|
|
780
|
+
}
|
|
781
|
+
// Re-arm the daemon the way Nx's runner does after restoring outputs, so the
|
|
782
|
+
// next call is back on the cheap path.
|
|
783
|
+
await daemonClient.recordOutputsHashBatch(doubted.map(({ outputs, hash }) => ({ outputs, hash })));
|
|
784
|
+
const movedDuringRecord = firstMovedClaim(verdict.observed);
|
|
785
|
+
performance.measure('ensureBuilt:artifacts', 'ensureBuilt:artifacts:start');
|
|
786
|
+
return movedDuringRecord === null ? null : { kind: 'stale-outputs', taskId: movedDuringRecord };
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* The tasks a cache record must answer for. An `nx:noop` task has no command:
|
|
790
|
+
* Nx completes it without spawning anything, and normalizes a command-less
|
|
791
|
+
* target that only names dependencies to one. A cache record would vouch for
|
|
792
|
+
* no work — the tasks it aggregates are in this graph and answer for
|
|
793
|
+
* themselves — so none is required. Demanding one made every call through an
|
|
794
|
+
* uncacheable aggregate hand the whole graph to Nx, which replays each
|
|
795
|
+
* dependency's cached log. Outputs a noop declares are still verified, with
|
|
796
|
+
* every other task's. `executorOf` is Nx's `getExecutorNameForTask` over the
|
|
797
|
+
* project graph.
|
|
798
|
+
*/
|
|
799
|
+
export function recordedTasks(tasks, executorOf) {
|
|
800
|
+
return tasks.filter((task) => executorOf(task) !== 'nx:noop');
|
|
801
|
+
}
|
|
802
|
+
/** What the working tree must hold: the declared outputs of every hashed task that declares any. */
|
|
803
|
+
export function outputClaims(tasks) {
|
|
804
|
+
const claims = [];
|
|
805
|
+
for (const task of tasks) {
|
|
806
|
+
if (task.outputs.length > 0 && task.hash !== undefined) {
|
|
807
|
+
claims.push({ taskId: task.id, outputs: task.outputs, hash: task.hash });
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
return claims;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Whether restoring every claim from its cache artifact would leave the
|
|
814
|
+
* working tree as it is. `artifacts` maps a hash to its artifact as Nx's local
|
|
815
|
+
* cache lists it (`getBatch`). A working tree that already holds every entry of
|
|
816
|
+
* each artifact is what the restore would leave: `restorable`, with each node
|
|
817
|
+
* compared, so a write after the comparison can still be caught. Anything else
|
|
818
|
+
* — no artifact, a difference, an error while reading, a write while comparing
|
|
819
|
+
* — is the first claim it happened to.
|
|
820
|
+
*/
|
|
821
|
+
export function compareWithArtifacts(workspaceRoot, claims, artifacts, expandOutputs, witnessPath) {
|
|
822
|
+
const binding = JSON.stringify(claims.map((claim) => [claim, artifacts.get(claim.hash)?.outputsPath]));
|
|
823
|
+
const witness = witnessPath === undefined ? null : readArtifactWitness(witnessPath);
|
|
824
|
+
if (witness !== null &&
|
|
825
|
+
witness.version === 1 &&
|
|
826
|
+
witness.workspaceRoot === workspaceRoot &&
|
|
827
|
+
witness.claims === binding &&
|
|
828
|
+
witness.nodes.length > 0 &&
|
|
829
|
+
nodesUnchanged(witness.nodes)) {
|
|
830
|
+
try {
|
|
831
|
+
const observed = witness.nodes.map(({ taskId, path }) => ({
|
|
832
|
+
taskId,
|
|
833
|
+
path,
|
|
834
|
+
stats: lstatSync(path, { bigint: true }),
|
|
835
|
+
}));
|
|
836
|
+
// Recheck both node trees after collecting live stats. A read race
|
|
837
|
+
// invalidates optional evidence and returns to the full comparison.
|
|
838
|
+
if (observed.every((node, index) => nodeStamp(node.stats) === witness.nodes[index].stamp)) {
|
|
839
|
+
return { kind: 'restorable', observed };
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
catch (error) {
|
|
843
|
+
if (!isSystemError(error))
|
|
844
|
+
throw error;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
473
847
|
const comparison = {
|
|
474
848
|
expandOutputs,
|
|
475
849
|
left: Buffer.allocUnsafe(COMPARE_CHUNK_BYTES),
|
|
@@ -477,26 +851,25 @@ async function probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tas
|
|
|
477
851
|
observed: [],
|
|
478
852
|
realDirectories: new Set(),
|
|
479
853
|
};
|
|
480
|
-
for (const claim of
|
|
481
|
-
|
|
482
|
-
// artifact here and stay a miss.
|
|
483
|
-
const artifact = cachedResults.get(claim.hash);
|
|
854
|
+
for (const claim of claims) {
|
|
855
|
+
const artifact = artifacts.get(claim.hash);
|
|
484
856
|
if (artifact === undefined || !outputsMatchArtifact(comparison, workspaceRoot, artifact.outputsPath, claim)) {
|
|
485
857
|
return { kind: 'stale-outputs', taskId: claim.taskId };
|
|
486
858
|
}
|
|
487
859
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
if (
|
|
492
|
-
|
|
860
|
+
const moved = firstMovedClaim(comparison.observed);
|
|
861
|
+
if (moved !== null)
|
|
862
|
+
return { kind: 'stale-outputs', taskId: moved };
|
|
863
|
+
if (witnessPath !== undefined) {
|
|
864
|
+
const next = {
|
|
865
|
+
version: 1,
|
|
866
|
+
workspaceRoot,
|
|
867
|
+
claims: binding,
|
|
868
|
+
nodes: comparison.observed.map(({ taskId, path, stats }) => ({ taskId, path, stamp: nodeStamp(stats) })),
|
|
869
|
+
};
|
|
870
|
+
writeWitness(witnessPath, next);
|
|
493
871
|
}
|
|
494
|
-
|
|
495
|
-
// next call is back on the cheap path.
|
|
496
|
-
await daemonClient.recordOutputsHashBatch(doubted.map(({ outputs, hash }) => ({ outputs, hash })));
|
|
497
|
-
const movedDuringRecord = firstMovedClaim(comparison.observed);
|
|
498
|
-
performance.measure('ensureBuilt:artifacts', 'ensureBuilt:artifacts:start');
|
|
499
|
-
return movedDuringRecord === null ? null : { kind: 'stale-outputs', taskId: movedDuringRecord };
|
|
872
|
+
return { kind: 'restorable', observed: comparison.observed };
|
|
500
873
|
}
|
|
501
874
|
/** Read size for byte comparison: large enough to stream a binary quickly, small enough never to load one whole. */
|
|
502
875
|
const COMPARE_CHUNK_BYTES = 1 << 20;
|
|
@@ -521,7 +894,8 @@ function outputsMatchArtifact(comparison, workspaceRoot, artifactRoot, claim) {
|
|
|
521
894
|
try {
|
|
522
895
|
const entries = comparison.expandOutputs(artifactRoot, claim.outputs);
|
|
523
896
|
return (entries.length > 0 &&
|
|
524
|
-
entries.every((entry) => throughRealDirectories(comparison.
|
|
897
|
+
entries.every((entry) => throughRealDirectories(comparison, claim.taskId, workspaceRoot, entry) &&
|
|
898
|
+
throughRealDirectories(comparison, claim.taskId, artifactRoot, entry) &&
|
|
525
899
|
sameTree(comparison, claim.taskId, join(workspaceRoot, entry), join(artifactRoot, entry))));
|
|
526
900
|
}
|
|
527
901
|
catch (error) {
|
|
@@ -537,18 +911,17 @@ function outputsMatchArtifact(comparison, workspaceRoot, artifactRoot, claim) {
|
|
|
537
911
|
* an entry through one would compare bytes the restore does not leave there —
|
|
538
912
|
* and would read the filesystem behind a link.
|
|
539
913
|
*/
|
|
540
|
-
function throughRealDirectories(
|
|
541
|
-
let directory =
|
|
542
|
-
const
|
|
543
|
-
for (const segment of segments.slice(0, -1)) {
|
|
914
|
+
function throughRealDirectories(comparison, taskId, root, entry) {
|
|
915
|
+
let directory = root;
|
|
916
|
+
for (const segment of ['', ...entry.split('/').slice(0, -1)]) {
|
|
544
917
|
directory = join(directory, segment);
|
|
545
|
-
if (realDirectories.has(directory))
|
|
918
|
+
if (comparison.realDirectories.has(directory))
|
|
546
919
|
continue;
|
|
547
|
-
}
|
|
548
|
-
if (
|
|
920
|
+
const stats = lstatSync(directory, { bigint: true, throwIfNoEntry: false });
|
|
921
|
+
if (stats?.isDirectory() !== true)
|
|
549
922
|
return false;
|
|
550
|
-
}
|
|
551
|
-
realDirectories.add(directory);
|
|
923
|
+
comparison.observed.push({ taskId, path: directory, stats });
|
|
924
|
+
comparison.realDirectories.add(directory);
|
|
552
925
|
}
|
|
553
926
|
return true;
|
|
554
927
|
}
|
|
@@ -566,6 +939,7 @@ function sameTree(comparison, taskId, actual, expected) {
|
|
|
566
939
|
return false;
|
|
567
940
|
}
|
|
568
941
|
comparison.observed.push({ taskId, path: actual, stats: actualStats });
|
|
942
|
+
comparison.observed.push({ taskId, path: expected, stats: expectedStats });
|
|
569
943
|
if (expectedStats.isSymbolicLink()) {
|
|
570
944
|
return actualStats.isSymbolicLink() && readlinkSync(actual) === readlinkSync(expected);
|
|
571
945
|
}
|
|
@@ -623,7 +997,7 @@ function sameBytes(comparison, actual, expected, size) {
|
|
|
623
997
|
* compared as: replaced (device, inode), rewritten (size, mtime) or otherwise
|
|
624
998
|
* touched (mode, ctime).
|
|
625
999
|
*/
|
|
626
|
-
function firstMovedClaim(observed) {
|
|
1000
|
+
export function firstMovedClaim(observed) {
|
|
627
1001
|
for (const { taskId, path, stats } of observed) {
|
|
628
1002
|
let current;
|
|
629
1003
|
try {
|