@smoothbricks/nx-plugin 0.4.25 → 0.4.27
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 +1078 -98
- 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 +16 -85
- 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 +16 -17
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +37 -44
- 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 +50 -8
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +691 -71
- 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 +108 -12
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +299 -18
- 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 +213 -12
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +624 -177
- 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 +435 -230
- package/dist/managed-assets.d.ts +6 -0
- package/dist/managed-assets.d.ts.map +1 -1
- 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.js +3 -2
- 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 -1
- package/dist/workspace-manifest.d.ts.map +1 -1
- package/executors.json +5 -0
- package/loader.js +13 -11
- package/managed/raw/envrc +33 -62
- 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 +607 -17
- package/managed/raw/tooling/direnv/devenv.smoo.nix +314 -92
- 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 +1009 -118
- 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 -75
- package/package.json +75 -13
- package/runtime-input.sh +81 -0
- package/src/__tests__/counted-cargo-process.ts +286 -0
- package/src/__tests__/counted-cargo.ts +730 -0
- package/src/__tests__/fixture-cargo-home.ts +36 -0
- package/src/__tests__/fixture-nx-env.ts +157 -2
- 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 +17 -86
- 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 -22
- 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 +432 -62
- package/src/cargo-closure-input.ts +51 -57
- package/src/cargo-dev-profile.ts +137 -0
- package/src/cargo-resolve-cache.test.ts +1044 -0
- package/src/cargo-source-hash.test.ts +203 -93
- package/src/cargo-source-hash.ts +762 -75
- package/src/cargo-toolchain-policy.ts +6 -0
- package/src/cargo-workspace.test.ts +320 -0
- package/src/cargo-workspace.ts +344 -18
- 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 +1043 -483
- package/src/ensure-built.ts +870 -197
- 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 +1070 -360
- package/src/index.ts +524 -255
- package/src/linked-snapshots.nx.test.ts +172 -0
- package/src/managed-assets.ts +12 -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 +3 -2
- 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 +495 -0
- package/src/nx-cache-bound.test.ts +109 -0
- 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 +112 -0
- 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 +99 -0
- 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 +181 -0
- 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 -1
- package/test-timings.json +85 -28
- package/managed/raw/tooling/direnv/inherited-devenv.ts +0 -615
- package/managed/raw/tooling/direnv/shared-caches.sh +0 -53
- package/src/__tests__/in-process-nx-index.ts +0 -9
package/src/ensure-built.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import { randomUUID } from 'node:crypto';
|
|
1
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
3
|
import type { BigIntStats } from 'node:fs';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
closeSync,
|
|
6
|
+
existsSync,
|
|
7
|
+
lstatSync,
|
|
8
|
+
openSync,
|
|
9
|
+
readdirSync,
|
|
10
|
+
readlinkSync,
|
|
11
|
+
readSync,
|
|
12
|
+
realpathSync,
|
|
13
|
+
statSync,
|
|
14
|
+
} from 'node:fs';
|
|
5
15
|
import { createRequire } from 'node:module';
|
|
6
|
-
import { isAbsolute, join, resolve } from 'node:path';
|
|
7
|
-
|
|
16
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
17
|
+
import { inspect } from 'node:util';
|
|
8
18
|
import type * as NxConfiguration from 'nx/src/config/nx-json';
|
|
9
19
|
import type { NxJsonConfiguration } from 'nx/src/config/nx-json';
|
|
10
20
|
import type { ProjectGraph, ProjectGraphProjectNode } from 'nx/src/config/project-graph';
|
|
@@ -13,7 +23,9 @@ import type * as NxDaemonClient from 'nx/src/daemon/client/client';
|
|
|
13
23
|
import type * as NxHashTask from 'nx/src/hasher/hash-task';
|
|
14
24
|
import type * as NxTaskHasher from 'nx/src/hasher/task-hasher';
|
|
15
25
|
import type * as NxNative from 'nx/src/native';
|
|
26
|
+
import type * as NxTransformObjects from 'nx/src/native/transform-objects';
|
|
16
27
|
import type * as NxExecutionHooks from 'nx/src/project-graph/plugins/tasks-execution-hooks';
|
|
28
|
+
import type * as NxProjectRootMappings from 'nx/src/project-graph/utils/find-project-for-path';
|
|
17
29
|
import type * as NxCache from 'nx/src/tasks-runner/cache';
|
|
18
30
|
import type * as NxCreateTaskGraph from 'nx/src/tasks-runner/create-task-graph';
|
|
19
31
|
import type { TaskResults } from 'nx/src/tasks-runner/life-cycle';
|
|
@@ -23,8 +35,24 @@ import type * as NxTasksRunnerUtils from 'nx/src/tasks-runner/utils';
|
|
|
23
35
|
import type * as NxCacheDirectory from 'nx/src/utils/cache-directory';
|
|
24
36
|
import type * as NxCommandLineUtils from 'nx/src/utils/command-line-utils';
|
|
25
37
|
import type { NxArgs } from 'nx/src/utils/command-line-utils';
|
|
38
|
+
import type * as NxPackageJson from 'nx/src/utils/package-json';
|
|
26
39
|
import type * as NxPerfLogging from 'nx/src/utils/perf-logging';
|
|
27
40
|
import type * as NxWorkspaceRoot from 'nx/src/utils/workspace-root';
|
|
41
|
+
import { boundedReceiptRuntimes, type ProviderInputProof, providerReceipt } from './ensure-built-receipt.js';
|
|
42
|
+
import {
|
|
43
|
+
type ArtifactWitness,
|
|
44
|
+
type GraphWitness,
|
|
45
|
+
graphInstallationIdentity,
|
|
46
|
+
nodeStamp,
|
|
47
|
+
nodesUnchanged,
|
|
48
|
+
readArtifactWitness,
|
|
49
|
+
readGraphWitness,
|
|
50
|
+
reusableGraph,
|
|
51
|
+
snapshotsEqual,
|
|
52
|
+
workspaceSnapshot,
|
|
53
|
+
writeWitness,
|
|
54
|
+
} from './ensure-built-witness.js';
|
|
55
|
+
import { managedAssetsRoot } from './managed-assets.js';
|
|
28
56
|
|
|
29
57
|
interface NxRuntimeModules {
|
|
30
58
|
readonly 'nx/src/config/nx-json': typeof NxConfiguration;
|
|
@@ -32,6 +60,9 @@ interface NxRuntimeModules {
|
|
|
32
60
|
readonly 'nx/src/hasher/hash-task': typeof NxHashTask;
|
|
33
61
|
readonly 'nx/src/hasher/task-hasher': typeof NxTaskHasher;
|
|
34
62
|
readonly 'nx/src/native': typeof NxNative;
|
|
63
|
+
readonly 'nx/src/native/transform-objects': typeof NxTransformObjects;
|
|
64
|
+
readonly 'nx/src/project-graph/utils/find-project-for-path': typeof NxProjectRootMappings;
|
|
65
|
+
readonly 'nx/src/utils/package-json': typeof NxPackageJson;
|
|
35
66
|
readonly 'nx/src/project-graph/plugins/tasks-execution-hooks': typeof NxExecutionHooks;
|
|
36
67
|
readonly 'nx/src/tasks-runner/cache': typeof NxCache;
|
|
37
68
|
readonly 'nx/src/tasks-runner/create-task-graph': typeof NxCreateTaskGraph;
|
|
@@ -83,10 +114,29 @@ export type MissReason =
|
|
|
83
114
|
| { readonly kind: 'not-cached'; readonly taskId: string }
|
|
84
115
|
| { readonly kind: 'cached-failure'; readonly taskId: string; readonly code: number }
|
|
85
116
|
| { readonly kind: 'stale-outputs'; readonly taskId: string }
|
|
86
|
-
| { readonly kind: 'stale-inputs'; readonly taskId: string }
|
|
87
117
|
| { readonly kind: 'cache-disabled'; readonly taskId: string }
|
|
88
118
|
| { readonly kind: 'no-daemon'; readonly taskId: string };
|
|
89
119
|
|
|
120
|
+
/** The provider's socket owner refused before any task or daemon client was started. */
|
|
121
|
+
export interface WorkspaceSocketFailure {
|
|
122
|
+
readonly kind: 'workspace-socket';
|
|
123
|
+
readonly taskId: string;
|
|
124
|
+
readonly workspaceRoot: string;
|
|
125
|
+
readonly detail: string;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface EnsureBuiltFailure {
|
|
129
|
+
readonly disposition: 'failed';
|
|
130
|
+
readonly reason: MissReason | WorkspaceSocketFailure;
|
|
131
|
+
readonly exitCode: number;
|
|
132
|
+
readonly signal: NodeJS.Signals | null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** A precise socket-owner refusal; its task has not run. */
|
|
136
|
+
export interface WorkspaceSocketRefusal extends EnsureBuiltFailure {
|
|
137
|
+
readonly reason: WorkspaceSocketFailure;
|
|
138
|
+
}
|
|
139
|
+
|
|
90
140
|
/**
|
|
91
141
|
* `hit` means nothing ran: every task in the graph was a recorded success and
|
|
92
142
|
* every recorded output is still byte-identical on disk, so the artifacts are
|
|
@@ -98,19 +148,14 @@ export type MissReason =
|
|
|
98
148
|
* order to decide whether to stay quiet. A run writes only to stderr: stdout
|
|
99
149
|
* belongs to whatever the caller goes on to run.
|
|
100
150
|
*
|
|
101
|
-
* `failed` is an operational outcome, not an exception: the
|
|
102
|
-
* not succeed. A caller re-raises `signal` when there
|
|
103
|
-
* `exitCode` otherwise, so a Ctrl-C
|
|
151
|
+
* `failed` is an operational outcome, not an exception: the provider's socket
|
|
152
|
+
* binding or the target did not succeed. A caller re-raises `signal` when there
|
|
153
|
+
* is one and exits with `exitCode` otherwise, so a Ctrl-C stays a Ctrl-C.
|
|
104
154
|
*/
|
|
105
155
|
export type EnsureBuiltResult =
|
|
106
156
|
| { readonly disposition: 'hit' }
|
|
107
157
|
| { readonly disposition: 'built'; readonly reason: MissReason }
|
|
108
|
-
|
|
|
109
|
-
readonly disposition: 'failed';
|
|
110
|
-
readonly reason: MissReason;
|
|
111
|
-
readonly exitCode: number;
|
|
112
|
-
readonly signal: NodeJS.Signals | null;
|
|
113
|
-
};
|
|
158
|
+
| EnsureBuiltFailure;
|
|
114
159
|
|
|
115
160
|
export interface EnsureBuiltOptions {
|
|
116
161
|
/** `project:target` or `project:target:configuration`. */
|
|
@@ -130,6 +175,48 @@ export interface EnsureBuiltOptions {
|
|
|
130
175
|
readonly onMiss?: 'stream';
|
|
131
176
|
}
|
|
132
177
|
|
|
178
|
+
export type EnsureBuiltOutputReceipt =
|
|
179
|
+
| { readonly path: string; readonly type: 'file'; readonly mode: number; readonly sha256: string }
|
|
180
|
+
| { readonly path: string; readonly type: 'symlink'; readonly mode: number; readonly linkText: string }
|
|
181
|
+
| {
|
|
182
|
+
readonly path: string;
|
|
183
|
+
readonly type: 'directory';
|
|
184
|
+
readonly mode: number;
|
|
185
|
+
readonly entries: readonly string[];
|
|
186
|
+
readonly sha256: string;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/** Git provenance covers file inputs only; runtime/env identity remains Nx's current task hash. */
|
|
190
|
+
export interface EnsureBuiltReceipt {
|
|
191
|
+
readonly workspaceRoot: string;
|
|
192
|
+
readonly head: string;
|
|
193
|
+
readonly headTree: string;
|
|
194
|
+
readonly fileInputProvenance: 'exact-file-inputs' | 'conservative-provider-source';
|
|
195
|
+
readonly runtimeEnvironmentProvenance: 'nx-task-hash-only';
|
|
196
|
+
readonly tasks: readonly {
|
|
197
|
+
readonly id: string;
|
|
198
|
+
readonly hash: string;
|
|
199
|
+
readonly outputs: readonly EnsureBuiltOutputReceipt[];
|
|
200
|
+
}[];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export interface EnsureBuiltProbeFailure {
|
|
204
|
+
readonly disposition: 'failed';
|
|
205
|
+
readonly reason: {
|
|
206
|
+
readonly kind: 'provider-proof';
|
|
207
|
+
readonly taskId: string;
|
|
208
|
+
readonly workspaceRoot: string;
|
|
209
|
+
readonly detail: string;
|
|
210
|
+
};
|
|
211
|
+
readonly exitCode: 1;
|
|
212
|
+
readonly signal: null;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export type EnsureBuiltProbeResult =
|
|
216
|
+
| { readonly disposition: 'hit'; readonly receipt: EnsureBuiltReceipt }
|
|
217
|
+
| { readonly disposition: 'miss'; readonly reason: MissReason }
|
|
218
|
+
| EnsureBuiltProbeFailure
|
|
219
|
+
| WorkspaceSocketRefusal;
|
|
133
220
|
/** A full hit carries no payload, so it is the same value every time. */
|
|
134
221
|
const HIT: EnsureBuiltResult = Object.freeze({ disposition: 'hit' });
|
|
135
222
|
|
|
@@ -160,8 +247,6 @@ export function describeMiss(reason: MissReason): string {
|
|
|
160
247
|
return `${reason.taskId} last failed with exit code ${reason.code}`;
|
|
161
248
|
case 'stale-outputs':
|
|
162
249
|
return `${reason.taskId} outputs are missing or modified on disk`;
|
|
163
|
-
case 'stale-inputs':
|
|
164
|
-
return `${reason.taskId} inputs changed since the Nx daemon last looked`;
|
|
165
250
|
case 'cache-disabled':
|
|
166
251
|
return `the Nx cache is disabled, so ${reason.taskId} must run`;
|
|
167
252
|
case 'no-daemon':
|
|
@@ -169,6 +254,87 @@ export function describeMiss(reason: MissReason): string {
|
|
|
169
254
|
}
|
|
170
255
|
}
|
|
171
256
|
|
|
257
|
+
/** A `smoo-nx-exec` command line: the target, the workspace root it names, and the binary to exec with its arguments. */
|
|
258
|
+
export interface ExecInvocation {
|
|
259
|
+
readonly target: string;
|
|
260
|
+
/** As given; absent when the wrapper is to find the root at or above the caller's directory. */
|
|
261
|
+
readonly workspaceRoot: string | undefined;
|
|
262
|
+
/** Empty when there is nothing to exec, only the target to make current. */
|
|
263
|
+
readonly command: readonly string[];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** A command line read as an invocation, or the usage mistake it makes. */
|
|
267
|
+
export type ExecArguments =
|
|
268
|
+
| { readonly ok: true; readonly invocation: ExecInvocation }
|
|
269
|
+
| { readonly ok: false; readonly usage: string };
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Read `smoo-nx-exec <project:target[:configuration]> [--workspace-root <dir>]
|
|
273
|
+
* [-- <binary> [args...]]`. A flag may be spelled `--flag value` or
|
|
274
|
+
* `--flag=value`. Without `--` there is nothing to exec: the wrapper builds
|
|
275
|
+
* what is stale and exits, so a caller that only needs the target current pays
|
|
276
|
+
* the probe, not an Nx CLI start that replays every cached task's log.
|
|
277
|
+
*/
|
|
278
|
+
export function parseExecArguments(argv: readonly string[]): ExecArguments {
|
|
279
|
+
const separator = argv.indexOf('--');
|
|
280
|
+
const command = separator === -1 ? [] : argv.slice(separator + 1);
|
|
281
|
+
if (separator !== -1 && command.length === 0) {
|
|
282
|
+
return { ok: false, usage: 'no binary given after `--`' };
|
|
283
|
+
}
|
|
284
|
+
let target: string | undefined;
|
|
285
|
+
let workspaceRoot: string | undefined;
|
|
286
|
+
// Only leading `--` forms are split at `=`: a value may legitimately contain one.
|
|
287
|
+
const tokens = (separator === -1 ? argv : argv.slice(0, separator)).flatMap((arg) => {
|
|
288
|
+
const equals = arg.startsWith('--') ? arg.indexOf('=') : -1;
|
|
289
|
+
return equals === -1 ? [arg] : [arg.slice(0, equals), arg.slice(equals + 1)];
|
|
290
|
+
});
|
|
291
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
292
|
+
const token = tokens[index];
|
|
293
|
+
if (token === '--workspace-root') {
|
|
294
|
+
index += 1;
|
|
295
|
+
if (index === tokens.length) {
|
|
296
|
+
return { ok: false, usage: '--workspace-root needs a directory' };
|
|
297
|
+
}
|
|
298
|
+
workspaceRoot = tokens[index];
|
|
299
|
+
} else if (token.startsWith('-')) {
|
|
300
|
+
return { ok: false, usage: `unknown flag ${token}` };
|
|
301
|
+
} else if (target !== undefined) {
|
|
302
|
+
return { ok: false, usage: `more than one target given: ${target} and ${token}` };
|
|
303
|
+
} else {
|
|
304
|
+
target = token;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (target === undefined) {
|
|
308
|
+
return { ok: false, usage: 'no project:target given' };
|
|
309
|
+
}
|
|
310
|
+
if (parseTargetSelector(target) === null) {
|
|
311
|
+
return { ok: false, usage: `'${target}' is not a project:target[:configuration] selector` };
|
|
312
|
+
}
|
|
313
|
+
// `execve` does no PATH lookup, so a bare name would fail as a missing file in
|
|
314
|
+
// the current directory. Say which mistake was made instead.
|
|
315
|
+
if (command.length > 0 && !command[0].includes('/')) {
|
|
316
|
+
return { ok: false, usage: `'${command[0]}' must be a path to the binary, not a name to look up on PATH` };
|
|
317
|
+
}
|
|
318
|
+
return { ok: true, invocation: { target, workspaceRoot, command } };
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* The message of whatever `ensureBuilt` rejected with. Nx rejects with plain
|
|
323
|
+
* objects as well as errors (its daemon client's `{ stack, message }`), and
|
|
324
|
+
* `String()` of one is `[object Object]`.
|
|
325
|
+
*/
|
|
326
|
+
export function describeError(error: unknown): string {
|
|
327
|
+
if (error instanceof Error) {
|
|
328
|
+
return error.message;
|
|
329
|
+
}
|
|
330
|
+
if (typeof error === 'object' && error !== null && 'message' in error && typeof error.message === 'string') {
|
|
331
|
+
return error.message;
|
|
332
|
+
}
|
|
333
|
+
return typeof error === 'string'
|
|
334
|
+
? error
|
|
335
|
+
: inspect(error, { breakLength: Number.POSITIVE_INFINITY, colors: false, depth: 5 });
|
|
336
|
+
}
|
|
337
|
+
|
|
172
338
|
/**
|
|
173
339
|
* First reason the task set cannot be replayed, considering only recorded
|
|
174
340
|
* results — no filesystem access. `null` means every task is a recorded
|
|
@@ -230,99 +396,327 @@ export function unvouched<Entry>(entries: readonly Entry[], verdicts: readonly b
|
|
|
230
396
|
* the workspace's own `nx` CLI unconditionally.
|
|
231
397
|
*/
|
|
232
398
|
export async function ensureBuilt(options: EnsureBuiltOptions): Promise<EnsureBuiltResult> {
|
|
399
|
+
return withWorkspaceBinding(options, ensureBuiltInWorkspace);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** Read current producer evidence without running tasks or writing producer outputs. */
|
|
403
|
+
export async function probeBuilt(options: Pick<EnsureBuiltOptions, 'target' | 'cwd'>): Promise<EnsureBuiltProbeResult> {
|
|
404
|
+
return withWorkspaceBinding(options, probeBuiltInWorkspace);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
async function withWorkspaceBinding<Result>(
|
|
408
|
+
options: Pick<EnsureBuiltOptions, 'target' | 'cwd'>,
|
|
409
|
+
operation: (workspaceRoot: string, selector: TargetSelector) => Promise<Result>,
|
|
410
|
+
): Promise<Result | WorkspaceSocketRefusal> {
|
|
233
411
|
const selector = parseTargetSelector(options.target);
|
|
234
412
|
if (!selector) {
|
|
235
413
|
throw new Error(`ensureBuilt: '${options.target}' is not a project:target[:configuration] selector`);
|
|
236
414
|
}
|
|
237
|
-
//
|
|
238
|
-
// caller meant.
|
|
415
|
+
// Resolve before chdir so a relative cwd still means what the caller meant.
|
|
239
416
|
const workspaceRoot = resolve(options.cwd);
|
|
240
417
|
const callerCwd = process.cwd();
|
|
241
418
|
const callerEnv = { ...process.env };
|
|
419
|
+
const callerOwnsRoot = callerOwnsWorkspace(callerEnv, callerCwd, workspaceRoot);
|
|
242
420
|
try {
|
|
243
|
-
//
|
|
244
|
-
// cache. Everything below — plugin hooks, `runtime` inputs, and the hasher,
|
|
245
|
-
// which keys against `process.cwd()` — has to see the same directory or the
|
|
246
|
-
// probe keys differently from the CLI and never hits.
|
|
421
|
+
// Nx's hooks, runtime inputs and hasher see the provider's own workspace.
|
|
247
422
|
process.chdir(workspaceRoot);
|
|
248
|
-
|
|
423
|
+
const environment = workspaceEnvironment(callerEnv, workspaceRoot, callerOwnsRoot);
|
|
424
|
+
if (!callerOwnsRoot) {
|
|
425
|
+
const binding = bindWorkspaceSocketDirectory(workspaceRoot, selectorTaskId(selector), environment);
|
|
426
|
+
if (binding !== undefined) {
|
|
427
|
+
if (typeof binding !== 'string') {
|
|
428
|
+
process.stderr.write(`ensureBuilt: ${binding.reason.workspaceRoot}: ${binding.reason.detail}\n`);
|
|
429
|
+
return binding;
|
|
430
|
+
}
|
|
431
|
+
environment.NX_SOCKET_DIR = binding;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
assignEnvironment(process.env, environment);
|
|
435
|
+
return await operation(workspaceRoot, selector);
|
|
249
436
|
} finally {
|
|
250
|
-
//
|
|
251
|
-
//
|
|
252
|
-
// — would inherit NX_WORKSPACE_ROOT_PATH, the stream/prefix flags, and
|
|
253
|
-
// whatever a plugin's preTasksExecution hook injected. The wrapper this
|
|
254
|
-
// replaces got that isolation for free by running Nx in a child.
|
|
437
|
+
// Never lend this provider's cwd, Nx binding or hook-injected environment
|
|
438
|
+
// to the caller or whatever it executes after this operation.
|
|
255
439
|
process.chdir(callerCwd);
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
440
|
+
assignEnvironment(process.env, callerEnv);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Nx's own overrides for where one workspace keeps its daemon socket, daemon
|
|
446
|
+
* record, task database and cache. Each names the state of a single
|
|
447
|
+
* workspace, and Nx takes it literally: a daemon spawned for another root
|
|
448
|
+
* with `NX_SOCKET_DIR` inherited listens on, and on stop deletes, the socket
|
|
449
|
+
* directory of the workspace that exported it; with
|
|
450
|
+
* `NX_WORKSPACE_DATA_DIRECTORY` it reads and overwrites that workspace's
|
|
451
|
+
* daemon record and task database; and the cache has to move with the
|
|
452
|
+
* database or a hit names artifacts the run never wrote.
|
|
453
|
+
*/
|
|
454
|
+
const WORKSPACE_STATE_ENV_KEYS = [
|
|
455
|
+
'NX_SOCKET_DIR',
|
|
456
|
+
'NX_DAEMON_SOCKET_DIR',
|
|
457
|
+
'NX_WORKSPACE_DATA_DIRECTORY',
|
|
458
|
+
'NX_CACHE_DIRECTORY',
|
|
459
|
+
] as const;
|
|
460
|
+
|
|
461
|
+
/** A socket binding refusal is the existing failed outcome, including the owner's real exit. */
|
|
462
|
+
function workspaceSocketRefusal(
|
|
463
|
+
workspaceRoot: string,
|
|
464
|
+
taskId: string,
|
|
465
|
+
detail: string,
|
|
466
|
+
exitCode: number,
|
|
467
|
+
signal: NodeJS.Signals | null,
|
|
468
|
+
): WorkspaceSocketRefusal {
|
|
469
|
+
return {
|
|
470
|
+
disposition: 'failed',
|
|
471
|
+
reason: { kind: 'workspace-socket', taskId, workspaceRoot, detail },
|
|
472
|
+
exitCode,
|
|
473
|
+
signal,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* A foreign-root call inside a managed shell asks the same packaged socket
|
|
479
|
+
* owner that shell uses. The owner reads the provider's binding or derives a
|
|
480
|
+
* namespace from its canonical checkout spelling under DEVENV_RUNTIME.
|
|
481
|
+
* Outside a managed shell Nx keeps its normal defaults. No caller socket is reused.
|
|
482
|
+
*/
|
|
483
|
+
function bindWorkspaceSocketDirectory(
|
|
484
|
+
workspaceRoot: string,
|
|
485
|
+
taskId: string,
|
|
486
|
+
environment: Readonly<NodeJS.ProcessEnv>,
|
|
487
|
+
): string | WorkspaceSocketRefusal | undefined {
|
|
488
|
+
const runtime = environment.DEVENV_RUNTIME;
|
|
489
|
+
if (runtime === undefined || runtime === '') return undefined;
|
|
490
|
+
if (!isAbsolute(runtime))
|
|
491
|
+
return workspaceSocketRefusal(
|
|
492
|
+
workspaceRoot,
|
|
493
|
+
taskId,
|
|
494
|
+
'DEVENV_RUNTIME must name the managed shell runtime directory',
|
|
495
|
+
1,
|
|
496
|
+
null,
|
|
497
|
+
);
|
|
498
|
+
const script = join(managedAssetsRoot, 'raw/tooling/direnv/nx-socket-dir.sh');
|
|
499
|
+
const result = spawnSync('/bin/sh', ['-c', '. "$1" && printf %s "$NX_SOCKET_DIR"', 'sh', script], {
|
|
500
|
+
cwd: workspaceRoot,
|
|
501
|
+
env: { ...environment, PWD: workspaceRoot },
|
|
502
|
+
encoding: 'utf8',
|
|
503
|
+
});
|
|
504
|
+
if (result.error !== undefined)
|
|
505
|
+
return workspaceSocketRefusal(
|
|
506
|
+
workspaceRoot,
|
|
507
|
+
taskId,
|
|
508
|
+
`socket owner could not start: ${result.error.message}; stdout: ${result.stdout}; stderr: ${result.stderr}`,
|
|
509
|
+
1,
|
|
510
|
+
null,
|
|
511
|
+
);
|
|
512
|
+
if (result.status !== 0) {
|
|
513
|
+
return workspaceSocketRefusal(
|
|
514
|
+
workspaceRoot,
|
|
515
|
+
taskId,
|
|
516
|
+
`socket owner ended ${result.signal === null ? `with exit ${result.status}` : `by ${result.signal}`}: ${result.stderr}; stdout: ${result.stdout}`,
|
|
517
|
+
result.status ?? 1,
|
|
518
|
+
result.signal,
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
const directory = result.stdout;
|
|
522
|
+
if (directory === '' || !isAbsolute(directory))
|
|
523
|
+
return workspaceSocketRefusal(
|
|
524
|
+
workspaceRoot,
|
|
525
|
+
taskId,
|
|
526
|
+
`socket owner returned no absolute directory: ${directory}; stderr: ${result.stderr}`,
|
|
527
|
+
1,
|
|
528
|
+
null,
|
|
529
|
+
);
|
|
530
|
+
try {
|
|
531
|
+
if (!statSync(directory).isDirectory())
|
|
532
|
+
return workspaceSocketRefusal(
|
|
533
|
+
workspaceRoot,
|
|
534
|
+
taskId,
|
|
535
|
+
`socket owner returned a non-directory: ${directory}; stderr: ${result.stderr}`,
|
|
536
|
+
1,
|
|
537
|
+
null,
|
|
538
|
+
);
|
|
539
|
+
} catch (error) {
|
|
540
|
+
return workspaceSocketRefusal(
|
|
541
|
+
workspaceRoot,
|
|
542
|
+
taskId,
|
|
543
|
+
`socket owner returned an unavailable directory ${directory}: ${error instanceof Error ? error.message : String(error)}; stderr: ${result.stderr}`,
|
|
544
|
+
1,
|
|
545
|
+
null,
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
if (result.stderr !== '') process.stderr.write(result.stderr);
|
|
549
|
+
return directory;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* The nearest directory at or above `from` holding an `nx.json`, or null.
|
|
554
|
+
* The marker this wrapper roots a workspace at when `--workspace-root` is
|
|
555
|
+
* not given.
|
|
556
|
+
*/
|
|
557
|
+
export function findNxWorkspaceRoot(from: string): string | null {
|
|
558
|
+
let directory = from;
|
|
559
|
+
for (;;) {
|
|
560
|
+
if (existsSync(join(directory, 'nx.json'))) {
|
|
561
|
+
return directory;
|
|
260
562
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
563
|
+
const parent = dirname(directory);
|
|
564
|
+
if (parent === directory) {
|
|
565
|
+
return null;
|
|
265
566
|
}
|
|
567
|
+
directory = parent;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
function isSameDirectory(left: string, right: string): boolean {
|
|
572
|
+
try {
|
|
573
|
+
return realpathSync(left) === realpathSync(right);
|
|
574
|
+
} catch {
|
|
575
|
+
// A path that cannot be resolved cannot be shown to be the same
|
|
576
|
+
// workspace, and "not the same" is the isolating answer.
|
|
577
|
+
return false;
|
|
266
578
|
}
|
|
267
579
|
}
|
|
268
580
|
|
|
269
|
-
|
|
581
|
+
/**
|
|
582
|
+
* Whether the environment a caller was launched with belongs to
|
|
583
|
+
* `workspaceRoot`. The caller's workspace is the one its own Nx would bind:
|
|
584
|
+
* `NX_WORKSPACE_ROOT_PATH` when set (relative to where it stands), else the
|
|
585
|
+
* nearest `nx.json` at or above where it stands — none, when it stands in no
|
|
586
|
+
* workspace.
|
|
587
|
+
*/
|
|
588
|
+
export function callerOwnsWorkspace(
|
|
589
|
+
callerEnv: Readonly<NodeJS.ProcessEnv>,
|
|
590
|
+
callerCwd: string,
|
|
270
591
|
workspaceRoot: string,
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
592
|
+
): boolean {
|
|
593
|
+
const callerRoot = callerEnv.NX_WORKSPACE_ROOT_PATH
|
|
594
|
+
? resolve(callerCwd, callerEnv.NX_WORKSPACE_ROOT_PATH)
|
|
595
|
+
: findNxWorkspaceRoot(callerCwd);
|
|
596
|
+
return callerRoot !== null && isSameDirectory(callerRoot, workspaceRoot);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* The environment every Nx this call starts runs under — the daemon client
|
|
601
|
+
* loaded below and the `nx` CLI a miss spawns: the caller's, pointed at
|
|
602
|
+
* `workspaceRoot`, with that workspace's state locations. A caller that was set
|
|
603
|
+
* up for this same root keeps its overrides: they are the owner's cache and
|
|
604
|
+
* sandbox boundary. A caller set up for another root, or for none, passes none
|
|
605
|
+
* of them on, so Nx falls back to the per-root defaults. Nothing is reset or
|
|
606
|
+
* bypassed: the root's own daemon and cache are used as they stand. Every one of
|
|
607
|
+
* them answers from the root's installed Nx (`NX_USE_LOCAL=true`): a daemon
|
|
608
|
+
* otherwise installs `nx@latest` to answer Nx Console's status, and a client
|
|
609
|
+
* without the variable recomputes the daemon's graph.
|
|
610
|
+
*/
|
|
611
|
+
export function workspaceEnvironment(
|
|
612
|
+
callerEnv: Readonly<NodeJS.ProcessEnv>,
|
|
613
|
+
workspaceRoot: string,
|
|
614
|
+
callerOwnsRoot: boolean,
|
|
615
|
+
): NodeJS.ProcessEnv {
|
|
616
|
+
const env: NodeJS.ProcessEnv = { ...callerEnv, NX_WORKSPACE_ROOT_PATH: workspaceRoot, NX_USE_LOCAL: 'true' };
|
|
617
|
+
if (!callerOwnsRoot) {
|
|
618
|
+
for (const key of WORKSPACE_STATE_ENV_KEYS) {
|
|
619
|
+
delete env[key];
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return env;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Make `target` hold exactly the variables of `env`: each one missing from
|
|
627
|
+
* `env` removed, each one different set. Nx reads its configuration from
|
|
628
|
+
* `process.env` in this process, so that is where an environment is put in
|
|
629
|
+
* place, and where the caller's is put back.
|
|
630
|
+
*/
|
|
631
|
+
export function assignEnvironment(target: NodeJS.ProcessEnv, env: Readonly<NodeJS.ProcessEnv>): void {
|
|
632
|
+
for (const key of Object.keys(target)) {
|
|
633
|
+
if (env[key] === undefined) {
|
|
634
|
+
delete target[key];
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
for (const [key, value] of Object.entries(env)) {
|
|
638
|
+
if (value !== undefined && target[key] !== value) {
|
|
639
|
+
target[key] = value;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* An outer Nx task exports its own cache-bypass setting to the process it
|
|
646
|
+
* launches. That setting describes the outer task, not the nested target:
|
|
647
|
+
* inheriting it makes the inner runner refuse cache writes forever. Outside an
|
|
648
|
+
* Nx task child, however, the same variables are the caller's explicit request
|
|
649
|
+
* to force this target to rebuild and remain authoritative.
|
|
650
|
+
*/
|
|
651
|
+
export function withoutOuterTaskCacheBypass(env: Readonly<NodeJS.ProcessEnv>): NodeJS.ProcessEnv {
|
|
652
|
+
const nested = { ...env };
|
|
653
|
+
if (nested.NX_TASK_TARGET_PROJECT !== undefined || nested.NX_TASK_TARGET_TARGET !== undefined) {
|
|
654
|
+
delete nested.NX_SKIP_NX_CACHE;
|
|
655
|
+
delete nested.NX_DISABLE_NX_CACHE;
|
|
656
|
+
}
|
|
657
|
+
return nested;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* A caller-requested cache bypass is the only miss known before hashing.
|
|
662
|
+
* Workspace changes first refresh the authoritative graph; the probe then
|
|
663
|
+
* decides whether these current inputs have matching artifacts.
|
|
664
|
+
*/
|
|
665
|
+
export function missBeforeProbe(env: Readonly<NodeJS.ProcessEnv>, taskId: string): MissReason | null {
|
|
666
|
+
if (env.NX_SKIP_NX_CACHE === 'true' || env.NX_DISABLE_NX_CACHE === 'true') {
|
|
667
|
+
return { kind: 'cache-disabled', taskId };
|
|
668
|
+
}
|
|
669
|
+
return null;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
interface ReadyWorkspaceProbe {
|
|
673
|
+
readonly kind: 'ready';
|
|
674
|
+
readonly nxJson: NxJsonConfiguration;
|
|
675
|
+
readonly nxArgs: NxArgs;
|
|
676
|
+
readonly projectGraph: ProjectGraph;
|
|
677
|
+
readonly taskGraph: TaskGraph;
|
|
678
|
+
readonly tasks: Task[];
|
|
679
|
+
readonly requireNx: WorkspaceNxRequire;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
type PreparedWorkspaceProbe =
|
|
683
|
+
| ReadyWorkspaceProbe
|
|
684
|
+
| { readonly kind: 'no-daemon'; readonly reason: Extract<MissReason, { kind: 'no-daemon' }> };
|
|
685
|
+
|
|
686
|
+
async function prepareWorkspaceProbe(workspaceRoot: string, selector: TargetSelector): Promise<PreparedWorkspaceProbe> {
|
|
687
|
+
const taskId = selectorTaskId(selector);
|
|
688
|
+
// This explicit fallback path loads no Nx. The build operation may run the
|
|
689
|
+
// checkout-local CLI; the read-only operation can only report the miss.
|
|
277
690
|
if (process.env.NX_DAEMON === 'false') {
|
|
278
|
-
return
|
|
691
|
+
return { kind: 'no-daemon', reason: { kind: 'no-daemon', taskId } };
|
|
279
692
|
}
|
|
280
|
-
//
|
|
281
|
-
// the workspace's running daemon. Resolve every runtime module from the
|
|
282
|
-
// target checkout rather than this package's own dependency: a reusable
|
|
283
|
-
// wrapper must keep using the daemon after the workspace takes an Nx patch.
|
|
693
|
+
// Runtime modules always belong to the provider's installed Nx version.
|
|
284
694
|
const requireNx = createWorkspaceNxRequire(workspaceRoot);
|
|
285
695
|
bindWorkspaceRoot(workspaceRoot, requireNx);
|
|
286
696
|
const { daemonClient } = requireNx('nx/src/daemon/client/client');
|
|
287
697
|
if (!daemonClient.enabled()) {
|
|
288
|
-
return
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// An outer Nx task exports its own cache-bypass setting to the process it
|
|
292
|
-
// launches. That setting describes the outer task, not the nested target:
|
|
293
|
-
// inheriting it makes the inner runner refuse cache writes forever. Outside
|
|
294
|
-
// an Nx task child, however, the same variables are the caller's explicit
|
|
295
|
-
// request to force this target to rebuild and must remain authoritative.
|
|
296
|
-
if (process.env.NX_TASK_TARGET_PROJECT !== undefined || process.env.NX_TASK_TARGET_TARGET !== undefined) {
|
|
297
|
-
delete process.env.NX_SKIP_NX_CACHE;
|
|
298
|
-
delete process.env.NX_DISABLE_NX_CACHE;
|
|
698
|
+
return { kind: 'no-daemon', reason: { kind: 'no-daemon', taskId } };
|
|
299
699
|
}
|
|
700
|
+
assignEnvironment(process.env, withoutOuterTaskCacheBypass(process.env));
|
|
300
701
|
|
|
301
702
|
const { readNxJson } = requireNx('nx/src/config/nx-json');
|
|
302
703
|
const { splitArgsIntoNxArgsAndOverrides } = requireNx('nx/src/utils/command-line-utils');
|
|
303
704
|
const { setEnvVarsBasedOnArgs } = requireNx('nx/src/tasks-runner/run-command');
|
|
304
705
|
const { createTaskGraph } = requireNx('nx/src/tasks-runner/create-task-graph');
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
const nxJson = readNxJson();
|
|
308
|
-
// Reproduce `nx run <selector> --outputStyle=<style>` exactly. Task hashes
|
|
309
|
-
// are derived from these arguments, so anything hand-rolled here instead of
|
|
310
|
-
// routed through Nx's own argument normalization would key the cache
|
|
311
|
-
// differently from the CLI and turn every probe into a miss.
|
|
706
|
+
let nxJson = readNxJson();
|
|
707
|
+
// Both operations key exactly like nx run <selector> --outputStyle=stream.
|
|
312
708
|
const { nxArgs, overrides } = splitArgsIntoNxArgsAndOverrides(
|
|
313
|
-
{ targets: [selector.target], configuration: selector.configuration, outputStyle:
|
|
709
|
+
{ targets: [selector.target], configuration: selector.configuration, outputStyle: 'stream' },
|
|
314
710
|
'run-one',
|
|
315
711
|
{ printWarnings: false },
|
|
316
712
|
nxJson,
|
|
317
713
|
);
|
|
318
714
|
const loadDotEnvFiles = process.env.NX_LOAD_DOT_ENV_FILES !== 'false';
|
|
319
|
-
// Sets NX_LOAD_DOT_ENV_FILES and the stream/prefix flags, which the hasher
|
|
320
|
-
// reads through each task's environment. It has to happen before hashing or
|
|
321
|
-
// the probe keys differently from the CLI.
|
|
322
715
|
setEnvVarsBasedOnArgs(nxArgs, loadDotEnvFiles);
|
|
323
716
|
|
|
324
717
|
performance.mark('ensureBuilt:graph:start');
|
|
325
|
-
const
|
|
718
|
+
const projectGraph = await currentProjectGraph(workspaceRoot, nxJson, requireNx);
|
|
719
|
+
nxJson = readNxJson();
|
|
326
720
|
requireProject(projectGraph, selector.project);
|
|
327
721
|
const taskGraph = createTaskGraph(
|
|
328
722
|
projectGraph,
|
|
@@ -335,40 +729,32 @@ async function ensureBuiltInWorkspace(
|
|
|
335
729
|
);
|
|
336
730
|
const tasks = Object.values(taskGraph.tasks);
|
|
337
731
|
performance.measure('ensureBuilt:graph', 'ensureBuilt:graph:start');
|
|
732
|
+
return { kind: 'ready', nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx };
|
|
733
|
+
}
|
|
338
734
|
|
|
339
|
-
|
|
340
|
-
|
|
735
|
+
async function withTaskHooks<Result>(
|
|
736
|
+
workspaceRoot: string,
|
|
737
|
+
selector: TargetSelector,
|
|
738
|
+
prepared: ReadyWorkspaceProbe,
|
|
739
|
+
operation: (workspaceRoot: string, selector: TargetSelector, prepared: ReadyWorkspaceProbe) => Promise<Result>,
|
|
740
|
+
): Promise<Result> {
|
|
741
|
+
const hooks = prepared.requireNx('nx/src/project-graph/plugins/tasks-execution-hooks');
|
|
341
742
|
const runId = randomUUID();
|
|
342
743
|
const startTime = Date.now();
|
|
343
|
-
//
|
|
344
|
-
// `env` inputs hash against them. Skipping the hook would not merely cost
|
|
345
|
-
// hits: the run below would then execute with a different environment than
|
|
346
|
-
// the CLI does, record a hash the CLI never looks up, and thrash the cache.
|
|
744
|
+
// Hook-injected env participates in hashing for both real operations.
|
|
347
745
|
await hooks.runPreTasksExecution({
|
|
348
746
|
id: runId,
|
|
349
747
|
workspaceRoot,
|
|
350
|
-
nxJsonConfiguration: nxJson,
|
|
748
|
+
nxJsonConfiguration: prepared.nxJson,
|
|
351
749
|
argv: process.argv,
|
|
352
750
|
});
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
let reason: MissReason | null;
|
|
356
|
-
if (process.env.NX_SKIP_NX_CACHE === 'true' || process.env.NX_DISABLE_NX_CACHE === 'true') {
|
|
357
|
-
reason = { kind: 'cache-disabled', taskId: selectorTaskId(selector) };
|
|
358
|
-
} else if (inputsChanged) {
|
|
359
|
-
reason = { kind: 'stale-inputs', taskId: selectorTaskId(selector) };
|
|
360
|
-
} else {
|
|
361
|
-
reason = await probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx);
|
|
362
|
-
}
|
|
363
|
-
performance.measure('ensureBuilt:probe', 'ensureBuilt:probe:start');
|
|
364
|
-
// The CLI runs the hooks around its own run, under its own id. This process
|
|
365
|
-
// ran none of the tasks, so it reports none for the id it opened.
|
|
366
|
-
const result = reason === null ? HIT : await runViaCli(workspaceRoot, selector, reason);
|
|
751
|
+
const result = await operation(workspaceRoot, selector, prepared);
|
|
752
|
+
// Any runner owns its own hook id; this process executed no tasks.
|
|
367
753
|
await hooks.runPostTasksExecution({
|
|
368
754
|
id: runId,
|
|
369
755
|
taskResults: NO_TASK_RESULTS,
|
|
370
756
|
workspaceRoot,
|
|
371
|
-
nxJsonConfiguration: nxJson,
|
|
757
|
+
nxJsonConfiguration: prepared.nxJson,
|
|
372
758
|
argv: process.argv,
|
|
373
759
|
startTime,
|
|
374
760
|
endTime: Date.now(),
|
|
@@ -376,7 +762,192 @@ async function ensureBuiltInWorkspace(
|
|
|
376
762
|
return result;
|
|
377
763
|
}
|
|
378
764
|
|
|
379
|
-
function
|
|
765
|
+
async function ensureBuiltInWorkspace(workspaceRoot: string, selector: TargetSelector): Promise<EnsureBuiltResult> {
|
|
766
|
+
const prepared = await prepareWorkspaceProbe(workspaceRoot, selector);
|
|
767
|
+
if (prepared.kind === 'no-daemon') return runViaCli(workspaceRoot, selector, prepared.reason);
|
|
768
|
+
return withTaskHooks(workspaceRoot, selector, prepared, buildPreparedTarget);
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
async function buildPreparedTarget(
|
|
772
|
+
workspaceRoot: string,
|
|
773
|
+
selector: TargetSelector,
|
|
774
|
+
prepared: ReadyWorkspaceProbe,
|
|
775
|
+
): Promise<EnsureBuiltResult> {
|
|
776
|
+
const { nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx } = prepared;
|
|
777
|
+
performance.mark('ensureBuilt:probe:start');
|
|
778
|
+
const reason =
|
|
779
|
+
missBeforeProbe(process.env, selectorTaskId(selector)) ??
|
|
780
|
+
(await probe(workspaceRoot, nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx));
|
|
781
|
+
performance.measure('ensureBuilt:probe', 'ensureBuilt:probe:start');
|
|
782
|
+
return reason === null ? HIT : runViaCli(workspaceRoot, selector, reason);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
async function probeBuiltInWorkspace(workspaceRoot: string, selector: TargetSelector): Promise<EnsureBuiltProbeResult> {
|
|
786
|
+
const prepared = await prepareWorkspaceProbe(workspaceRoot, selector);
|
|
787
|
+
if (prepared.kind === 'no-daemon') return { disposition: 'miss', reason: prepared.reason };
|
|
788
|
+
const probeSource = captureProbeSource(workspaceRoot, prepared.requireNx);
|
|
789
|
+
return withTaskHooks(workspaceRoot, selector, prepared, async (root, selected, current) => {
|
|
790
|
+
const { nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx } = current;
|
|
791
|
+
const taskId = selectorTaskId(selected);
|
|
792
|
+
performance.mark('ensureBuilt:probe:start');
|
|
793
|
+
const reason =
|
|
794
|
+
missBeforeProbe(process.env, taskId) ??
|
|
795
|
+
(await probe(root, nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx, true));
|
|
796
|
+
performance.measure('ensureBuilt:probe', 'ensureBuilt:probe:start');
|
|
797
|
+
if (reason !== null) return { disposition: 'miss', reason } satisfies EnsureBuiltProbeResult;
|
|
798
|
+
let result = providerReceipt(
|
|
799
|
+
root,
|
|
800
|
+
taskId,
|
|
801
|
+
tasks,
|
|
802
|
+
providerInputProof(root, nxJson, projectGraph, taskGraph, requireNx),
|
|
803
|
+
requireNx('nx/src/native').expandOutputs,
|
|
804
|
+
);
|
|
805
|
+
if (result.disposition === 'hit') {
|
|
806
|
+
const after = captureProbeSource(root, requireNx);
|
|
807
|
+
if (!snapshotsEqual(probeSource, after) || !nodesUnchanged(probeSource.nodes)) {
|
|
808
|
+
result = {
|
|
809
|
+
disposition: 'failed',
|
|
810
|
+
reason: {
|
|
811
|
+
kind: 'provider-proof',
|
|
812
|
+
taskId,
|
|
813
|
+
workspaceRoot: root,
|
|
814
|
+
detail: 'Provider source nodes or membership moved across Nx hashing/receipt capture',
|
|
815
|
+
},
|
|
816
|
+
exitCode: 1,
|
|
817
|
+
signal: null,
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
if (result.disposition === 'failed') {
|
|
822
|
+
process.stderr.write(`probeBuilt: ${result.reason.workspaceRoot}: ${result.reason.detail}\n`);
|
|
823
|
+
}
|
|
824
|
+
return result;
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
function captureProbeSource(
|
|
829
|
+
workspaceRoot: string,
|
|
830
|
+
requireNx: WorkspaceNxRequire,
|
|
831
|
+
): ReturnType<typeof workspaceSnapshot> {
|
|
832
|
+
const { WorkspaceContext } = requireNx('nx/src/native');
|
|
833
|
+
const { workspaceDataDirectoryForWorkspace } = requireNx('nx/src/utils/cache-directory');
|
|
834
|
+
const data = workspaceDataDirectoryForWorkspace(workspaceRoot);
|
|
835
|
+
const previous = readGraphWitness(join(data, 'ensure-built-graph.json'));
|
|
836
|
+
return workspaceSnapshot(workspaceRoot, new WorkspaceContext(workspaceRoot, data), previous?.snapshot);
|
|
837
|
+
}
|
|
838
|
+
/** Nx's native plan is the FILE selection oracle, not a second glob planner.
|
|
839
|
+
* Config identities skipped by the inspector are included explicitly. A
|
|
840
|
+
* runtime identity is bounded only by the owning toolchain recipe + a declared
|
|
841
|
+
* pin; opaque commands and unavailable native proof categorically refuse.
|
|
842
|
+
*/
|
|
843
|
+
function providerInputProof(
|
|
844
|
+
workspaceRoot: string,
|
|
845
|
+
nxJson: NxJsonConfiguration,
|
|
846
|
+
projectGraph: ProjectGraph,
|
|
847
|
+
taskGraph: TaskGraph,
|
|
848
|
+
requireNx: WorkspaceNxRequire,
|
|
849
|
+
): ProviderInputProof {
|
|
850
|
+
const { WorkspaceContext, HashPlanInspector, HashPlanner, transferProjectGraph } = requireNx('nx/src/native');
|
|
851
|
+
const { transformProjectGraphForRust } = requireNx('nx/src/native/transform-objects');
|
|
852
|
+
const { createProjectRootMappings } = requireNx('nx/src/project-graph/utils/find-project-for-path');
|
|
853
|
+
const { workspaceDataDirectoryForWorkspace } = requireNx('nx/src/utils/cache-directory');
|
|
854
|
+
const context = new WorkspaceContext(workspaceRoot, workspaceDataDirectoryForWorkspace(workspaceRoot));
|
|
855
|
+
const { externalReferences } = context.getWorkspaceFiles(
|
|
856
|
+
Object.fromEntries(createProjectRootMappings(projectGraph.nodes)),
|
|
857
|
+
);
|
|
858
|
+
if (externalReferences === undefined) {
|
|
859
|
+
return {
|
|
860
|
+
kind: 'conservative-provider-source',
|
|
861
|
+
files: [],
|
|
862
|
+
inputs: {},
|
|
863
|
+
runtimeSource: { kind: 'opaque', detail: 'Nx supplied no native file-input proof' },
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
const planner = new HashPlanner(nxJson, transferProjectGraph(transformProjectGraphForRust(projectGraph)));
|
|
867
|
+
const inspector = new HashPlanInspector(
|
|
868
|
+
externalReferences.allWorkspaceFiles,
|
|
869
|
+
externalReferences.projectFiles,
|
|
870
|
+
workspaceRoot,
|
|
871
|
+
);
|
|
872
|
+
const inputs = inspector.inspectInputs(planner.getPlansReference(Object.keys(taskGraph.tasks), taskGraph));
|
|
873
|
+
const files = new Set<string>();
|
|
874
|
+
const directories = new Set<string>();
|
|
875
|
+
const projects = new Set<string>();
|
|
876
|
+
function includeProject(name: string): void {
|
|
877
|
+
if (projects.has(name)) return;
|
|
878
|
+
projects.add(name);
|
|
879
|
+
const node = projectGraph.nodes[name];
|
|
880
|
+
if (node === undefined) return;
|
|
881
|
+
directories.add(node.data.root);
|
|
882
|
+
for (const file of ['project.json', 'package.json']) {
|
|
883
|
+
const path = join(node.data.root, file);
|
|
884
|
+
if (existsSync(join(workspaceRoot, path))) files.add(path);
|
|
885
|
+
}
|
|
886
|
+
for (const dependency of projectGraph.dependencies[name] ?? []) includeProject(dependency.target);
|
|
887
|
+
}
|
|
888
|
+
let conservative = false;
|
|
889
|
+
const projectConfigs = Object.fromEntries(
|
|
890
|
+
Object.entries(projectGraph.nodes).map(([name, node]) => [name, node.data]),
|
|
891
|
+
);
|
|
892
|
+
const { getCustomHasher } = requireNx('nx/src/tasks-runner/utils');
|
|
893
|
+
for (const task of Object.values(taskGraph.tasks)) {
|
|
894
|
+
const input = inputs[task.id];
|
|
895
|
+
if (input === undefined || getCustomHasher(task, projectConfigs) !== null) {
|
|
896
|
+
return {
|
|
897
|
+
kind: 'conservative-provider-source',
|
|
898
|
+
files: [...files],
|
|
899
|
+
inputs,
|
|
900
|
+
runtimeSource: { kind: 'opaque', detail: `No complete native FILE/runtime plan for ${task.id}` },
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
for (const file of input.files) files.add(file);
|
|
904
|
+
if (input.runtime.length > 0 || input.environment.length > 0) conservative = true;
|
|
905
|
+
const node = projectGraph.nodes[task.target.project];
|
|
906
|
+
if (node === undefined) throw new Error(`Lost project for receipt ${task.id}`);
|
|
907
|
+
includeProject(node.name);
|
|
908
|
+
const target = node.data.targets?.[task.target.target];
|
|
909
|
+
const options = {
|
|
910
|
+
...target?.options,
|
|
911
|
+
...(task.target.configuration === undefined ? {} : target?.configurations?.[task.target.configuration]),
|
|
912
|
+
...task.overrides,
|
|
913
|
+
};
|
|
914
|
+
if (typeof options.cwd === 'string') {
|
|
915
|
+
directories.add(options.cwd);
|
|
916
|
+
directories.add(options.cwd.replaceAll('{projectRoot}', node.data.root).replaceAll('{workspaceRoot}', '.'));
|
|
917
|
+
}
|
|
918
|
+
for (const name of ['project.json', 'package.json']) {
|
|
919
|
+
const path = join(node.data.root, name);
|
|
920
|
+
if (existsSync(join(workspaceRoot, path))) files.add(path);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
for (const path of [
|
|
924
|
+
'nx.json',
|
|
925
|
+
'package.json',
|
|
926
|
+
'bun.lock',
|
|
927
|
+
'bun.lockb',
|
|
928
|
+
'package-lock.json',
|
|
929
|
+
'pnpm-lock.yaml',
|
|
930
|
+
'yarn.lock',
|
|
931
|
+
'tsconfig.json',
|
|
932
|
+
'tsconfig.base.json',
|
|
933
|
+
]) {
|
|
934
|
+
if (existsSync(join(workspaceRoot, path))) files.add(path);
|
|
935
|
+
}
|
|
936
|
+
const installation = graphInstallationIdentity(
|
|
937
|
+
workspaceRoot,
|
|
938
|
+
nxJson,
|
|
939
|
+
requireNx('nx/src/utils/package-json').readModulePackageJson,
|
|
940
|
+
);
|
|
941
|
+
const runtimeSource = boundedReceiptRuntimes(inputs, [...directories], [...files], installation !== null);
|
|
942
|
+
return {
|
|
943
|
+
kind: conservative ? 'conservative-provider-source' : 'exact-file-inputs',
|
|
944
|
+
files: [...files],
|
|
945
|
+
inputs,
|
|
946
|
+
runtimeSource,
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
/** The id Nx gives the task `selector` names, and the one a miss runs. */
|
|
950
|
+
export function selectorTaskId(selector: TargetSelector): string {
|
|
380
951
|
return selector.configuration === undefined
|
|
381
952
|
? `${selector.project}:${selector.target}`
|
|
382
953
|
: `${selector.project}:${selector.target}:${selector.configuration}`;
|
|
@@ -388,10 +959,10 @@ function selectorTaskId(selector: TargetSelector): string {
|
|
|
388
959
|
* a module-level singleton that reads `nx.json` from that root. So the root has
|
|
389
960
|
* to be bound before the first Nx module loads, which is why this module
|
|
390
961
|
* imports Nx dynamically throughout. A static import at the top of the file
|
|
391
|
-
* would bind the caller's launch directory instead.
|
|
962
|
+
* would bind the caller's launch directory instead. `ensureBuilt` has already
|
|
963
|
+
* set `NX_WORKSPACE_ROOT_PATH`; this loads Nx and checks it took.
|
|
392
964
|
*/
|
|
393
965
|
function bindWorkspaceRoot(workspaceRoot: string, requireNx: WorkspaceNxRequire): void {
|
|
394
|
-
process.env.NX_WORKSPACE_ROOT_PATH = workspaceRoot;
|
|
395
966
|
if (process.env.NX_PERF_LOGGING === 'true') {
|
|
396
967
|
// Installs Nx's PerformanceObserver, which reports every `performance
|
|
397
968
|
// .measure` this module and Nx itself record. Loading it unconditionally
|
|
@@ -409,62 +980,88 @@ function bindWorkspaceRoot(workspaceRoot: string, requireNx: WorkspaceNxRequire)
|
|
|
409
980
|
}
|
|
410
981
|
}
|
|
411
982
|
|
|
412
|
-
/**
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
* Take Nx's native, ignore-aware disk snapshot and compare it with the
|
|
417
|
-
* daemon's file table; its metadata cache reuses unchanged file hashes.
|
|
418
|
-
*
|
|
419
|
-
* Any difference is handed to the daemon so its next graph is current, but
|
|
420
|
-
* that only schedules a recomputation, and a probe meanwhile would hash
|
|
421
|
-
* against the file map it already has. So the caller does not probe: if any
|
|
422
|
-
* differing path is not a declared output of a task in the graph, this
|
|
423
|
-
* returns true and the target is run, which lets Nx's own runner wait for the
|
|
424
|
-
* recomputation. Output paths are exempt because a build's own writes are the
|
|
425
|
-
* commonest thing to reach here before the watcher does, and treating them as
|
|
426
|
-
* a miss would make every hit after a build replay the cached log.
|
|
983
|
+
/** An exact graph-input witness skips graph transfer, never task hashing.
|
|
984
|
+
* Reconcile disk with the daemon BEFORE asking for a graph; publish evidence
|
|
985
|
+
* only when the filesystem and plugin installation stay identical across the
|
|
986
|
+
* awaited authoritative generation. No disk-cache age or existence is proof.
|
|
427
987
|
*/
|
|
428
|
-
async function
|
|
988
|
+
async function currentProjectGraph(
|
|
429
989
|
workspaceRoot: string,
|
|
430
|
-
|
|
990
|
+
nxJson: NxJsonConfiguration,
|
|
431
991
|
requireNx: WorkspaceNxRequire,
|
|
432
|
-
): Promise<
|
|
992
|
+
): Promise<ProjectGraph> {
|
|
433
993
|
const { daemonClient } = requireNx('nx/src/daemon/client/client');
|
|
434
|
-
const { WorkspaceContext
|
|
994
|
+
const { WorkspaceContext } = requireNx('nx/src/native');
|
|
435
995
|
const { workspaceDataDirectoryForWorkspace } = requireNx('nx/src/utils/cache-directory');
|
|
996
|
+
const packageResolution = requireNx('nx/src/utils/package-json');
|
|
997
|
+
const data = workspaceDataDirectoryForWorkspace(workspaceRoot);
|
|
998
|
+
const witnessPath = join(data, 'ensure-built-graph.json');
|
|
999
|
+
const witness = readGraphWitness(witnessPath);
|
|
1000
|
+
const environment = createHash('sha256')
|
|
1001
|
+
.update(JSON.stringify(Object.entries(process.env).sort(([left], [right]) => left.localeCompare(right))))
|
|
1002
|
+
.digest('hex');
|
|
436
1003
|
performance.mark('ensureBuilt:inputs:start');
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
1004
|
+
// The daemon's file-table RPC is retained even on reuse: task hashing must
|
|
1005
|
+
// see writes the watcher has not delivered, independently of graph reuse.
|
|
1006
|
+
const daemonFiles = await daemonClient.getWorkspaceContextFileData();
|
|
1007
|
+
const before = workspaceSnapshot(workspaceRoot, new WorkspaceContext(workspaceRoot, data), witness?.snapshot);
|
|
1008
|
+
const { created, updated, deleted } = workspaceFileChanges(daemonFiles, before.files);
|
|
1009
|
+
if (created.length + updated.length + deleted.length > 0) {
|
|
1010
|
+
await daemonClient.updateWorkspaceContext(created, updated, deleted);
|
|
441
1011
|
}
|
|
442
|
-
|
|
443
|
-
const
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
1012
|
+
performance.measure('ensureBuilt:inputs', 'ensureBuilt:inputs:start');
|
|
1013
|
+
const installation = graphInstallationIdentity(workspaceRoot, nxJson, packageResolution.readModulePackageJson);
|
|
1014
|
+
const cached = nodesUnchanged(before.nodes)
|
|
1015
|
+
? reusableGraph(witness, workspaceRoot, environment, installation, before)
|
|
1016
|
+
: null;
|
|
1017
|
+
if (cached !== null) return cached;
|
|
1018
|
+
const { projectGraph } = await daemonClient.getProjectGraphAndSourceMaps();
|
|
1019
|
+
const after = workspaceSnapshot(workspaceRoot, new WorkspaceContext(workspaceRoot, data), before);
|
|
1020
|
+
const finalInstallation = graphInstallationIdentity(workspaceRoot, nxJson, packageResolution.readModulePackageJson);
|
|
1021
|
+
const stableGeneration = snapshotsEqual(before, after) && nodesUnchanged(before.nodes);
|
|
1022
|
+
if (installation !== null && installation === finalInstallation && stableGeneration) {
|
|
1023
|
+
const next: GraphWitness = { version: 1, workspaceRoot, environment, installation, snapshot: after, projectGraph };
|
|
1024
|
+
writeWitness(witnessPath, next);
|
|
1025
|
+
}
|
|
1026
|
+
// A write during the await cannot authorize a saved graph. Feed the final
|
|
1027
|
+
// snapshot to Nx and await its successor before current task hashing.
|
|
1028
|
+
if (!stableGeneration) {
|
|
1029
|
+
const currentDaemonFiles = await daemonClient.getWorkspaceContextFileData();
|
|
1030
|
+
const changes = workspaceFileChanges(currentDaemonFiles, after.files);
|
|
1031
|
+
await daemonClient.updateWorkspaceContext(changes.created, changes.updated, changes.deleted);
|
|
1032
|
+
return (await daemonClient.getProjectGraphAndSourceMaps()).projectGraph;
|
|
1033
|
+
}
|
|
1034
|
+
return projectGraph;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
/** How the files on disk differ from the daemon's file table, by workspace-relative path. */
|
|
1038
|
+
export interface WorkspaceFileChanges {
|
|
1039
|
+
readonly created: string[];
|
|
1040
|
+
readonly updated: string[];
|
|
1041
|
+
readonly deleted: string[];
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
/** Compare the daemon's file table with a snapshot of the disk, both as Nx lists them: path and content hash. */
|
|
1045
|
+
export function workspaceFileChanges(
|
|
1046
|
+
daemonFiles: readonly NxNative.FileData[],
|
|
1047
|
+
diskFiles: readonly NxNative.FileData[],
|
|
1048
|
+
): WorkspaceFileChanges {
|
|
1049
|
+
const daemonHashes = new Map<string, string>();
|
|
1050
|
+
for (const { file, hash } of daemonFiles) {
|
|
1051
|
+
daemonHashes.set(file, hash);
|
|
1052
|
+
}
|
|
1053
|
+
const created: string[] = [];
|
|
1054
|
+
const updated: string[] = [];
|
|
1055
|
+
for (const { file, hash } of diskFiles) {
|
|
1056
|
+
const daemonHash = daemonHashes.get(file);
|
|
1057
|
+
if (daemonHash === undefined) {
|
|
1058
|
+
created.push(file);
|
|
1059
|
+
} else if (daemonHash !== hash) {
|
|
1060
|
+
updated.push(file);
|
|
452
1061
|
}
|
|
453
|
-
|
|
454
|
-
}
|
|
455
|
-
const deletedFiles = [...previousHashes.keys()];
|
|
456
|
-
const changed = [...createdFiles, ...updatedFiles, ...deletedFiles];
|
|
457
|
-
let inputsChanged = false;
|
|
458
|
-
if (changed.length > 0) {
|
|
459
|
-
await daemonClient.updateWorkspaceContext(createdFiles, updatedFiles, deletedFiles);
|
|
460
|
-
// The same matcher the task runner uses to collect outputs, over the union
|
|
461
|
-
// of every task's declared outputs. A negation declared by one task then
|
|
462
|
-
// also excludes another task's output, which errs toward a miss.
|
|
463
|
-
const outputs = tasks.flatMap((task) => task.outputs);
|
|
464
|
-
inputsChanged = matchOutputPaths(outputs, changed).includes(false);
|
|
1062
|
+
daemonHashes.delete(file);
|
|
465
1063
|
}
|
|
466
|
-
|
|
467
|
-
return inputsChanged;
|
|
1064
|
+
return { created, updated, deleted: [...daemonHashes.keys()] };
|
|
468
1065
|
}
|
|
469
1066
|
|
|
470
1067
|
/** `null` when the target is already built; otherwise the first reason it is not. */
|
|
@@ -476,6 +1073,7 @@ async function probe(
|
|
|
476
1073
|
taskGraph: TaskGraph,
|
|
477
1074
|
tasks: Task[],
|
|
478
1075
|
requireNx: WorkspaceNxRequire,
|
|
1076
|
+
verifyAllArtifacts = false,
|
|
479
1077
|
): Promise<MissReason | null> {
|
|
480
1078
|
const { daemonClient } = requireNx('nx/src/daemon/client/client');
|
|
481
1079
|
const { DaemonBasedTaskHasher } = requireNx('nx/src/hasher/task-hasher');
|
|
@@ -484,6 +1082,7 @@ async function probe(
|
|
|
484
1082
|
const { getCache } = requireNx('nx/src/tasks-runner/cache');
|
|
485
1083
|
const { getRunnerOptions } = requireNx('nx/src/tasks-runner/run-command');
|
|
486
1084
|
const { getExecutorNameForTask } = requireNx('nx/src/tasks-runner/utils');
|
|
1085
|
+
const { expandOutputs } = requireNx('nx/src/native');
|
|
487
1086
|
|
|
488
1087
|
// `isCloudDefault: false` because these options are only read here by the
|
|
489
1088
|
// hasher, which looks at `selectivelyHashTsConfig`; the cloud credentials the
|
|
@@ -511,14 +1110,7 @@ async function probe(
|
|
|
511
1110
|
await hashTasks(hasher, projectGraph, taskGraph, perTaskEnvs, getTaskDetails(), tasks);
|
|
512
1111
|
performance.measure('ensureBuilt:hash', 'ensureBuilt:hash:start');
|
|
513
1112
|
|
|
514
|
-
|
|
515
|
-
// anything, and normalizes a command-less target that only names dependencies
|
|
516
|
-
// to one. A cache record would vouch for no work — the tasks it aggregates are
|
|
517
|
-
// in this graph and answer for themselves — so none is required. Demanding one
|
|
518
|
-
// made every call through an uncacheable aggregate hand the whole graph to Nx,
|
|
519
|
-
// which replays each dependency's cached log. Outputs a noop declares are
|
|
520
|
-
// still verified below, with every other task's.
|
|
521
|
-
const recordedTasks = tasks.filter((task) => getExecutorNameForTask(task, projectGraph) !== 'nx:noop');
|
|
1113
|
+
const recorded = recordedTasks(tasks, (task) => getExecutorNameForTask(task, projectGraph));
|
|
522
1114
|
|
|
523
1115
|
// Nx's own factory, but deliberately never `init()`ed: that is what makes
|
|
524
1116
|
// this a local-only, side-effect-free question. `init()` attaches the remote
|
|
@@ -528,12 +1120,12 @@ async function probe(
|
|
|
528
1120
|
// outputs against, and an artifact missing from it is a miss.
|
|
529
1121
|
performance.mark('ensureBuilt:cache:start');
|
|
530
1122
|
const cache = getCache(runnerOptions);
|
|
531
|
-
const cachedResults = await cache.getBatch(
|
|
1123
|
+
const cachedResults = await cache.getBatch(recorded.filter((task) => task.cache && task.hash));
|
|
532
1124
|
const cachedCodeByHash = new Map<string, number>();
|
|
533
1125
|
for (const [hash, result] of cachedResults) {
|
|
534
1126
|
cachedCodeByHash.set(hash, result.code);
|
|
535
1127
|
}
|
|
536
|
-
const cacheMiss = firstCacheMiss(
|
|
1128
|
+
const cacheMiss = firstCacheMiss(recorded, cachedCodeByHash);
|
|
537
1129
|
performance.measure('ensureBuilt:cache', 'ensureBuilt:cache:start');
|
|
538
1130
|
if (cacheMiss) {
|
|
539
1131
|
return cacheMiss;
|
|
@@ -544,16 +1136,11 @@ async function probe(
|
|
|
544
1136
|
// lives in the working tree, where anything may have deleted or rewritten it
|
|
545
1137
|
// since. The daemon answers that cheaply from the output hashes it recorded
|
|
546
1138
|
// when Nx last wrote them.
|
|
547
|
-
const claims
|
|
548
|
-
for (const task of tasks) {
|
|
549
|
-
if (task.outputs.length > 0 && task.hash !== undefined) {
|
|
550
|
-
claims.push({ taskId: task.id, outputs: task.outputs, hash: task.hash });
|
|
551
|
-
}
|
|
552
|
-
}
|
|
1139
|
+
const claims = outputClaims(tasks);
|
|
553
1140
|
performance.mark('ensureBuilt:outputs:start');
|
|
554
1141
|
const verdicts = await daemonClient.outputsHashesMatchBatch(claims.map(({ outputs, hash }) => ({ outputs, hash })));
|
|
555
1142
|
performance.measure('ensureBuilt:outputs', 'ensureBuilt:outputs:start');
|
|
556
|
-
const doubted = unvouched(claims, verdicts);
|
|
1143
|
+
const doubted = verifyAllArtifacts ? claims : unvouched(claims, verdicts);
|
|
557
1144
|
if (doubted.length === 0) {
|
|
558
1145
|
return null;
|
|
559
1146
|
}
|
|
@@ -565,12 +1152,96 @@ async function probe(
|
|
|
565
1152
|
// And a write the daemon processes more than 2 s after a record erases it,
|
|
566
1153
|
// which a daemon busy hashing does to a restore's own writes — so each
|
|
567
1154
|
// restore guarantees the next one. What settles the question is what a hit
|
|
568
|
-
// would restore: Nx's own local artifact for this exact hash.
|
|
569
|
-
// that already holds every entry of it is what the restore would leave.
|
|
570
|
-
// Anything else — no artifact, a difference, an error while reading — stays
|
|
571
|
-
// a miss.
|
|
1155
|
+
// would restore: Nx's own local artifact for this exact hash.
|
|
572
1156
|
performance.mark('ensureBuilt:artifacts:start');
|
|
573
|
-
|
|
1157
|
+
// `recorded` excludes `nx:noop`, so a noop's declared outputs have no
|
|
1158
|
+
// artifact here and stay a miss.
|
|
1159
|
+
const { workspaceDataDirectoryForWorkspace } = requireNx('nx/src/utils/cache-directory');
|
|
1160
|
+
const verdict = compareWithArtifacts(
|
|
1161
|
+
workspaceRoot,
|
|
1162
|
+
doubted,
|
|
1163
|
+
cachedResults,
|
|
1164
|
+
expandOutputs,
|
|
1165
|
+
join(workspaceDataDirectoryForWorkspace(workspaceRoot), 'ensure-built-outputs.json'),
|
|
1166
|
+
);
|
|
1167
|
+
if (verdict.kind === 'stale-outputs') {
|
|
1168
|
+
return verdict;
|
|
1169
|
+
}
|
|
1170
|
+
// Re-arm the daemon the way Nx's runner does after restoring outputs, so the
|
|
1171
|
+
// next call is back on the cheap path.
|
|
1172
|
+
await daemonClient.recordOutputsHashBatch(doubted.map(({ outputs, hash }) => ({ outputs, hash })));
|
|
1173
|
+
const movedDuringRecord = firstMovedClaim(verdict.observed);
|
|
1174
|
+
performance.measure('ensureBuilt:artifacts', 'ensureBuilt:artifacts:start');
|
|
1175
|
+
return movedDuringRecord === null ? null : { kind: 'stale-outputs', taskId: movedDuringRecord };
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
/**
|
|
1179
|
+
* The tasks a cache record must answer for. An `nx:noop` task has no command:
|
|
1180
|
+
* Nx completes it without spawning anything, and normalizes a command-less
|
|
1181
|
+
* target that only names dependencies to one. A cache record would vouch for
|
|
1182
|
+
* no work — the tasks it aggregates are in this graph and answer for
|
|
1183
|
+
* themselves — so none is required. Demanding one made every call through an
|
|
1184
|
+
* uncacheable aggregate hand the whole graph to Nx, which replays each
|
|
1185
|
+
* dependency's cached log. Outputs a noop declares are still verified, with
|
|
1186
|
+
* every other task's. `executorOf` is Nx's `getExecutorNameForTask` over the
|
|
1187
|
+
* project graph.
|
|
1188
|
+
*/
|
|
1189
|
+
export function recordedTasks(tasks: readonly Task[], executorOf: (task: Task) => string): Task[] {
|
|
1190
|
+
return tasks.filter((task) => executorOf(task) !== 'nx:noop');
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
/** What the working tree must hold: the declared outputs of every hashed task that declares any. */
|
|
1194
|
+
export function outputClaims(tasks: readonly Task[]): OutputClaim[] {
|
|
1195
|
+
const claims: OutputClaim[] = [];
|
|
1196
|
+
for (const task of tasks) {
|
|
1197
|
+
if (task.outputs.length > 0 && task.hash !== undefined) {
|
|
1198
|
+
claims.push({ taskId: task.id, outputs: task.outputs, hash: task.hash });
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
return claims;
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
/**
|
|
1205
|
+
* Whether restoring every claim from its cache artifact would leave the
|
|
1206
|
+
* working tree as it is. `artifacts` maps a hash to its artifact as Nx's local
|
|
1207
|
+
* cache lists it (`getBatch`). A working tree that already holds every entry of
|
|
1208
|
+
* each artifact is what the restore would leave: `restorable`, with each node
|
|
1209
|
+
* compared, so a write after the comparison can still be caught. Anything else
|
|
1210
|
+
* — no artifact, a difference, an error while reading, a write while comparing
|
|
1211
|
+
* — is the first claim it happened to.
|
|
1212
|
+
*/
|
|
1213
|
+
export function compareWithArtifacts(
|
|
1214
|
+
workspaceRoot: string,
|
|
1215
|
+
claims: readonly OutputClaim[],
|
|
1216
|
+
artifacts: ReadonlyMap<string, { readonly outputsPath: string }>,
|
|
1217
|
+
expandOutputs: typeof NxNative.expandOutputs,
|
|
1218
|
+
witnessPath?: string,
|
|
1219
|
+
): ArtifactVerdict {
|
|
1220
|
+
const binding = JSON.stringify(claims.map((claim) => [claim, artifacts.get(claim.hash)?.outputsPath]));
|
|
1221
|
+
const witness = witnessPath === undefined ? null : readArtifactWitness(witnessPath);
|
|
1222
|
+
if (
|
|
1223
|
+
witness !== null &&
|
|
1224
|
+
witness.version === 1 &&
|
|
1225
|
+
witness.workspaceRoot === workspaceRoot &&
|
|
1226
|
+
witness.claims === binding &&
|
|
1227
|
+
witness.nodes.length > 0 &&
|
|
1228
|
+
nodesUnchanged(witness.nodes)
|
|
1229
|
+
) {
|
|
1230
|
+
try {
|
|
1231
|
+
const observed = witness.nodes.map(({ taskId, path }) => ({
|
|
1232
|
+
taskId,
|
|
1233
|
+
path,
|
|
1234
|
+
stats: lstatSync(path, { bigint: true }),
|
|
1235
|
+
}));
|
|
1236
|
+
// Recheck both node trees after collecting live stats. A read race
|
|
1237
|
+
// invalidates optional evidence and returns to the full comparison.
|
|
1238
|
+
if (observed.every((node, index) => nodeStamp(node.stats) === witness.nodes[index].stamp)) {
|
|
1239
|
+
return { kind: 'restorable', observed };
|
|
1240
|
+
}
|
|
1241
|
+
} catch (error) {
|
|
1242
|
+
if (!isSystemError(error)) throw error;
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
574
1245
|
const comparison: ArtifactComparison = {
|
|
575
1246
|
expandOutputs,
|
|
576
1247
|
left: Buffer.allocUnsafe(COMPARE_CHUNK_BYTES),
|
|
@@ -578,37 +1249,40 @@ async function probe(
|
|
|
578
1249
|
observed: [],
|
|
579
1250
|
realDirectories: new Set(),
|
|
580
1251
|
};
|
|
581
|
-
for (const claim of
|
|
582
|
-
|
|
583
|
-
// artifact here and stay a miss.
|
|
584
|
-
const artifact = cachedResults.get(claim.hash);
|
|
1252
|
+
for (const claim of claims) {
|
|
1253
|
+
const artifact = artifacts.get(claim.hash);
|
|
585
1254
|
if (artifact === undefined || !outputsMatchArtifact(comparison, workspaceRoot, artifact.outputsPath, claim)) {
|
|
586
1255
|
return { kind: 'stale-outputs', taskId: claim.taskId };
|
|
587
1256
|
}
|
|
588
1257
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
1258
|
+
const moved = firstMovedClaim(comparison.observed);
|
|
1259
|
+
if (moved !== null) return { kind: 'stale-outputs', taskId: moved };
|
|
1260
|
+
if (witnessPath !== undefined) {
|
|
1261
|
+
const next: ArtifactWitness = {
|
|
1262
|
+
version: 1,
|
|
1263
|
+
workspaceRoot,
|
|
1264
|
+
claims: binding,
|
|
1265
|
+
nodes: comparison.observed.map(({ taskId, path, stats }) => ({ taskId, path, stamp: nodeStamp(stats) })),
|
|
1266
|
+
};
|
|
1267
|
+
writeWitness(witnessPath, next);
|
|
594
1268
|
}
|
|
595
|
-
|
|
596
|
-
// next call is back on the cheap path.
|
|
597
|
-
await daemonClient.recordOutputsHashBatch(doubted.map(({ outputs, hash }) => ({ outputs, hash })));
|
|
598
|
-
const movedDuringRecord = firstMovedClaim(comparison.observed);
|
|
599
|
-
performance.measure('ensureBuilt:artifacts', 'ensureBuilt:artifacts:start');
|
|
600
|
-
return movedDuringRecord === null ? null : { kind: 'stale-outputs', taskId: movedDuringRecord };
|
|
1269
|
+
return { kind: 'restorable', observed: comparison.observed };
|
|
601
1270
|
}
|
|
602
1271
|
|
|
1272
|
+
/** What comparing the working tree with the cache artifacts found: the first stale claim, or every node compared. */
|
|
1273
|
+
export type ArtifactVerdict =
|
|
1274
|
+
| { readonly kind: 'stale-outputs'; readonly taskId: string }
|
|
1275
|
+
| { readonly kind: 'restorable'; readonly observed: readonly ObservedNode[] };
|
|
1276
|
+
|
|
603
1277
|
/** A task's declared outputs, resolved to workspace-relative paths, and the hash they were cached under. */
|
|
604
|
-
interface OutputClaim {
|
|
1278
|
+
export interface OutputClaim {
|
|
605
1279
|
readonly taskId: string;
|
|
606
1280
|
readonly outputs: string[];
|
|
607
1281
|
readonly hash: string;
|
|
608
1282
|
}
|
|
609
1283
|
|
|
610
|
-
/** A working-tree node as
|
|
611
|
-
interface ObservedNode {
|
|
1284
|
+
/** A working-tree or cache node as compared, so a later write or replacement can be noticed. */
|
|
1285
|
+
export interface ObservedNode {
|
|
612
1286
|
readonly taskId: string;
|
|
613
1287
|
readonly path: string;
|
|
614
1288
|
readonly stats: BigIntStats;
|
|
@@ -655,7 +1329,8 @@ function outputsMatchArtifact(
|
|
|
655
1329
|
entries.length > 0 &&
|
|
656
1330
|
entries.every(
|
|
657
1331
|
(entry) =>
|
|
658
|
-
throughRealDirectories(comparison.
|
|
1332
|
+
throughRealDirectories(comparison, claim.taskId, workspaceRoot, entry) &&
|
|
1333
|
+
throughRealDirectories(comparison, claim.taskId, artifactRoot, entry) &&
|
|
659
1334
|
sameTree(comparison, claim.taskId, join(workspaceRoot, entry), join(artifactRoot, entry)),
|
|
660
1335
|
)
|
|
661
1336
|
);
|
|
@@ -673,18 +1348,15 @@ function outputsMatchArtifact(
|
|
|
673
1348
|
* an entry through one would compare bytes the restore does not leave there —
|
|
674
1349
|
* and would read the filesystem behind a link.
|
|
675
1350
|
*/
|
|
676
|
-
function throughRealDirectories(
|
|
677
|
-
let directory =
|
|
678
|
-
const
|
|
679
|
-
for (const segment of segments.slice(0, -1)) {
|
|
1351
|
+
function throughRealDirectories(comparison: ArtifactComparison, taskId: string, root: string, entry: string): boolean {
|
|
1352
|
+
let directory = root;
|
|
1353
|
+
for (const segment of ['', ...entry.split('/').slice(0, -1)]) {
|
|
680
1354
|
directory = join(directory, segment);
|
|
681
|
-
if (realDirectories.has(directory))
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
}
|
|
687
|
-
realDirectories.add(directory);
|
|
1355
|
+
if (comparison.realDirectories.has(directory)) continue;
|
|
1356
|
+
const stats = lstatSync(directory, { bigint: true, throwIfNoEntry: false });
|
|
1357
|
+
if (stats?.isDirectory() !== true) return false;
|
|
1358
|
+
comparison.observed.push({ taskId, path: directory, stats });
|
|
1359
|
+
comparison.realDirectories.add(directory);
|
|
688
1360
|
}
|
|
689
1361
|
return true;
|
|
690
1362
|
}
|
|
@@ -703,6 +1375,7 @@ function sameTree(comparison: ArtifactComparison, taskId: string, actual: string
|
|
|
703
1375
|
return false;
|
|
704
1376
|
}
|
|
705
1377
|
comparison.observed.push({ taskId, path: actual, stats: actualStats });
|
|
1378
|
+
comparison.observed.push({ taskId, path: expected, stats: expectedStats });
|
|
706
1379
|
if (expectedStats.isSymbolicLink()) {
|
|
707
1380
|
return actualStats.isSymbolicLink() && readlinkSync(actual) === readlinkSync(expected);
|
|
708
1381
|
}
|
|
@@ -764,7 +1437,7 @@ function sameBytes(comparison: ArtifactComparison, actual: string, expected: str
|
|
|
764
1437
|
* compared as: replaced (device, inode), rewritten (size, mtime) or otherwise
|
|
765
1438
|
* touched (mode, ctime).
|
|
766
1439
|
*/
|
|
767
|
-
function firstMovedClaim(observed: readonly ObservedNode[]): string | null {
|
|
1440
|
+
export function firstMovedClaim(observed: readonly ObservedNode[]): string | null {
|
|
768
1441
|
for (const { taskId, path, stats } of observed) {
|
|
769
1442
|
let current: BigIntStats | undefined;
|
|
770
1443
|
try {
|