@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
|
@@ -0,0 +1,3484 @@
|
|
|
1
|
+
diff --git a/dist/bin/nx.js b/dist/bin/nx.js
|
|
2
|
+
index 5a59f762f2002f61f84d0966c8fb48d48b3bdce2..f190d2b93cc7c1d0f59dcb1e76ef7d3efb01c3f9 100755
|
|
3
|
+
--- a/dist/bin/nx.js
|
|
4
|
+
+++ b/dist/bin/nx.js
|
|
5
|
+
@@ -9,9 +9,15 @@ if (process.env.FORCE_COLOR === '0') {
|
|
6
|
+
process.env.NO_COLOR = '1';
|
|
7
|
+
delete process.env.FORCE_COLOR;
|
|
8
|
+
}
|
|
9
|
+
+// Every command, and the daemon this process starts, answers from this
|
|
10
|
+
+// installed Nx: `nx configure-ai-agents`, `nx init` and `nx migrate` would
|
|
11
|
+
+// otherwise run `nx@latest` from the registry. `NX_USE_LOCAL=false` restores
|
|
12
|
+
+// the latest CLI for one command.
|
|
13
|
+
+process.env.NX_USE_LOCAL ??= 'true';
|
|
14
|
+
// Must be the first import — see enable-compile-cache.ts.
|
|
15
|
+
require("../src/utils/enable-compile-cache");
|
|
16
|
+
const find_workspace_root_1 = require("../src/utils/find-workspace-root");
|
|
17
|
+
+const workspace_root_1 = require("../src/utils/workspace-root");
|
|
18
|
+
const pc = tslib_1.__importStar(require("picocolors"));
|
|
19
|
+
const output_1 = require("../src/utils/output");
|
|
20
|
+
const installation_directory_1 = require("../src/utils/installation-directory");
|
|
21
|
+
@@ -35,6 +41,10 @@ async function main() {
|
|
22
|
+
// user's command line.
|
|
23
|
+
if (process.env.NX_COMPLETE) {
|
|
24
|
+
try {
|
|
25
|
+
+ // A shell set up for another workspace gets no suggestions: they
|
|
26
|
+
+ // would come from that workspace's graph.
|
|
27
|
+
+ if ((0, workspace_root_1.foreignWorkspaceEnvironment)(process.cwd(), process.env) !== null)
|
|
28
|
+
+ return;
|
|
29
|
+
perf_hooks_1.performance.mark('init-local');
|
|
30
|
+
const { tryValueCompletion } = await import('nx/src/command-line/completion/value-completions');
|
|
31
|
+
if (tryValueCompletion())
|
|
32
|
+
@@ -51,6 +61,13 @@ async function main() {
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
+ // Before anything below can reach the daemon, sockets or files of a
|
|
37
|
+
+ // workspace the environment names instead of the current directory's.
|
|
38
|
+
+ const foreign = (0, workspace_root_1.foreignWorkspaceEnvironment)(process.cwd(), process.env);
|
|
39
|
+
+ if (foreign !== null) {
|
|
40
|
+
+ handleForeignWorkspaceEnvironment(foreign);
|
|
41
|
+
+ return;
|
|
42
|
+
+ }
|
|
43
|
+
if (process.argv[2] !== 'report' &&
|
|
44
|
+
process.argv[2] !== '--version' &&
|
|
45
|
+
process.argv[2] !== '--help' &&
|
|
46
|
+
@@ -154,6 +171,23 @@ async function main() {
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
+/**
|
|
51
|
+
+ * Refuse to run: the environment belongs to another workspace than the
|
|
52
|
+
+ * current directory's (see `foreignWorkspaceEnvironment`). `exitCode` rather
|
|
53
|
+
+ * than `process.exit`, so the message is not cut off on a piped stderr.
|
|
54
|
+
+ */
|
|
55
|
+
+function handleForeignWorkspaceEnvironment({ workspace, variables }) {
|
|
56
|
+
+ output_1.output.error({
|
|
57
|
+
+ title: `The environment belongs to another Nx workspace than ${workspace}, the one the current directory is in.`,
|
|
58
|
+
+ bodyLines: [
|
|
59
|
+
+ ...variables.map(({ name, value, workspace: other }) => `${name}=${value} belongs to workspace ${other}`),
|
|
60
|
+
+ '',
|
|
61
|
+
+ `Nx stopped before reaching that workspace's daemon, cache or files. Run the command under ${workspace}'s own environment, for example \`direnv exec ${workspace} nx ...\`, or unset the variables above.`,
|
|
62
|
+
+ 'A cache or data directory several checkouts share on purpose has to lie outside every workspace.',
|
|
63
|
+
+ ],
|
|
64
|
+
+ });
|
|
65
|
+
+ process.exitCode = 1;
|
|
66
|
+
+}
|
|
67
|
+
function handleNoWorkspace(globalNxVersion) {
|
|
68
|
+
output_1.output.log({
|
|
69
|
+
title: `The current directory isn't part of an Nx workspace.`,
|
|
70
|
+
diff --git a/dist/src/command-line/release/version/version-actions.js b/dist/src/command-line/release/version/version-actions.js
|
|
71
|
+
index 006c077033a6e92a8bdcc6c732110736fb465b5a..2ac4a0252c813cec5492b7ac83e2d5160b97bc32 100644
|
|
72
|
+
--- a/dist/src/command-line/release/version/version-actions.js
|
|
73
|
+
+++ b/dist/src/command-line/release/version/version-actions.js
|
|
74
|
+
@@ -5,13 +5,14 @@ exports.resolveVersionActionsForProject = resolveVersionActionsForProject;
|
|
75
|
+
const node_path_1 = require("node:path");
|
|
76
|
+
const register_1 = require("../../../plugins/js/utils/register");
|
|
77
|
+
const utils_1 = require("../../../tasks-runner/utils");
|
|
78
|
+
+const installation_directory_1 = require("../../../utils/installation-directory");
|
|
79
|
+
const workspace_root_1 = require("../../../utils/workspace-root");
|
|
80
|
+
const config_1 = require("../config/config");
|
|
81
|
+
const semver_1 = require("../utils/semver");
|
|
82
|
+
const release_group_processor_1 = require("./release-group-processor");
|
|
83
|
+
function resolveVersionActionsPath(path, projectGraphNode) {
|
|
84
|
+
try {
|
|
85
|
+
- return require.resolve(path);
|
|
86
|
+
+ return (0, installation_directory_1.resolveFromWorkspace)(path);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
try {
|
|
90
|
+
diff --git a/dist/src/daemon/cache.d.ts b/dist/src/daemon/cache.d.ts
|
|
91
|
+
index 65e58a019d7c1f7ba7c8243ad119aa444ec3a499..cb060c6d90352cbaf69d105652617d5a995385ea 100644
|
|
92
|
+
--- a/dist/src/daemon/cache.d.ts
|
|
93
|
+
+++ b/dist/src/daemon/cache.d.ts
|
|
94
|
+
@@ -2,9 +2,29 @@ export interface DaemonProcessJson {
|
|
95
|
+
processId: number;
|
|
96
|
+
socketPath: string;
|
|
97
|
+
nxVersion: string;
|
|
98
|
+
+ /** The root the daemon serves; a record written before the claim existed has none. */
|
|
99
|
+
+ workspaceRoot?: string;
|
|
100
|
+
}
|
|
101
|
+
export declare const serverProcessJsonPath: string;
|
|
102
|
+
export declare function readDaemonProcessJsonCache(): DaemonProcessJson | null;
|
|
103
|
+
export declare function deleteDaemonJsonProcessCache(): void;
|
|
104
|
+
-export declare function writeDaemonJsonProcessCache(daemonJson: DaemonProcessJson): Promise<void>;
|
|
105
|
+
+/**
|
|
106
|
+
+ * What claiming the workspace's daemon record found: the record is now this
|
|
107
|
+
+ * process's, another daemon serves the workspace, or one is starting to (retry).
|
|
108
|
+
+ * `owner` is `null` for a record still being written.
|
|
109
|
+
+ */
|
|
110
|
+
+export type DaemonClaim = {
|
|
111
|
+
+ kind: 'claimed';
|
|
112
|
+
+} | {
|
|
113
|
+
+ kind: 'serving';
|
|
114
|
+
+ owner: DaemonProcessJson;
|
|
115
|
+
+} | {
|
|
116
|
+
+ kind: 'starting';
|
|
117
|
+
+ owner: DaemonProcessJson | null;
|
|
118
|
+
+};
|
|
119
|
+
+/**
|
|
120
|
+
+ * Makes this process the workspace's daemon of record, unless another daemon of
|
|
121
|
+
+ * the same Nx version already serves the same root or is starting to.
|
|
122
|
+
+ */
|
|
123
|
+
+export declare function claimDaemonJsonProcessCache(daemonJson: DaemonProcessJson): Promise<DaemonClaim>;
|
|
124
|
+
export declare function getDaemonProcessIdSync(): number | null;
|
|
125
|
+
diff --git a/dist/src/daemon/cache.js b/dist/src/daemon/cache.js
|
|
126
|
+
index 757fd200dbd83f335c9868987e4135d4b7b580cb..1bf7e571cc66d3483f8b2ebb7b73ad8b43128269 100644
|
|
127
|
+
--- a/dist/src/daemon/cache.js
|
|
128
|
+
+++ b/dist/src/daemon/cache.js
|
|
129
|
+
@@ -3,9 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
130
|
+
exports.serverProcessJsonPath = void 0;
|
|
131
|
+
exports.readDaemonProcessJsonCache = readDaemonProcessJsonCache;
|
|
132
|
+
exports.deleteDaemonJsonProcessCache = deleteDaemonJsonProcessCache;
|
|
133
|
+
-exports.writeDaemonJsonProcessCache = writeDaemonJsonProcessCache;
|
|
134
|
+
+exports.claimDaemonJsonProcessCache = claimDaemonJsonProcessCache;
|
|
135
|
+
exports.getDaemonProcessIdSync = getDaemonProcessIdSync;
|
|
136
|
+
const node_fs_1 = require("node:fs");
|
|
137
|
+
+const node_net_1 = require("node:net");
|
|
138
|
+
const path_1 = require("path");
|
|
139
|
+
const tmp_dir_1 = require("./tmp-dir");
|
|
140
|
+
const fileutils_1 = require("../utils/fileutils");
|
|
141
|
+
@@ -38,9 +39,177 @@ function deleteDaemonJsonProcessCache() {
|
|
142
|
+
}
|
|
143
|
+
catch { }
|
|
144
|
+
}
|
|
145
|
+
-async function writeDaemonJsonProcessCache(daemonJson) {
|
|
146
|
+
- await (0, fileutils_1.writeJsonFileAsync)(exports.serverProcessJsonPath, daemonJson, {
|
|
147
|
+
- appendNewLine: true,
|
|
148
|
+
+/**
|
|
149
|
+
+ * How long a daemon may take from claiming the record to answering on its
|
|
150
|
+
+ * socket: a client waits as long (6000 polls 10 ms apart) for a daemon it starts.
|
|
151
|
+
+ */
|
|
152
|
+
+const DAEMON_STARTUP_GRACE_MS = 60000;
|
|
153
|
+
+/**
|
|
154
|
+
+ * Makes this process the workspace's daemon of record, unless another daemon of
|
|
155
|
+
+ * the same Nx version already serves the same root (`serving`) or is starting to
|
|
156
|
+
+ * (`starting`, retry); `claimed` once the record is this process's. Socket paths
|
|
157
|
+
+ * are not compared: by default each daemon's socket directory hashes its own pid.
|
|
158
|
+
+ *
|
|
159
|
+
+ * Each daemon used to overwrite the record unconditionally, so two clients that
|
|
160
|
+
+ * both found no daemon started two, and the later one displaced the first along
|
|
161
|
+
+ * with every client connected to it. The record is now created exclusively, with
|
|
162
|
+
+ * link(2) from a staged file, so of two daemons racing for a free record exactly
|
|
163
|
+
+ * one wins and no reader sees it half written. A holder starts when it claims,
|
|
164
|
+
+ * so its record's mtime dates its start: a live holder that does not answer is
|
|
165
|
+
+ * starting while its record is younger than the startup grace, and stale after,
|
|
166
|
+
+ * as is one that is dead, of another Nx version or root (a copied workspace),
|
|
167
|
+
+ * from before the claim existed, or unreadable. A stale record is renamed aside
|
|
168
|
+
+ * and replaced; if what was renamed aside is no longer the record judged
|
|
169
|
+
+ * (another daemon claimed it in between), it is put back rather than discarded.
|
|
170
|
+
+ */
|
|
171
|
+
+async function claimDaemonJsonProcessCache(daemonJson) {
|
|
172
|
+
+ const text = `${JSON.stringify(daemonJson, null, 2)}\n`;
|
|
173
|
+
+ const staged = `${exports.serverProcessJsonPath}.${process.pid}`;
|
|
174
|
+
+ const aside = `${exports.serverProcessJsonPath}.replaced.${process.pid}`;
|
|
175
|
+
+ (0, node_fs_1.mkdirSync)((0, path_1.dirname)(exports.serverProcessJsonPath), { recursive: true });
|
|
176
|
+
+ (0, node_fs_1.writeFileSync)(staged, text);
|
|
177
|
+
+ try {
|
|
178
|
+
+ // Each pass either claims, defers, or replaces one judged record; a record
|
|
179
|
+
+ // that changes under every pass is a fight no daemon should win silently.
|
|
180
|
+
+ for (let pass = 0; pass < 8; pass++) {
|
|
181
|
+
+ if (createExclusively(exports.serverProcessJsonPath, staged, text)) {
|
|
182
|
+
+ return { kind: 'claimed' };
|
|
183
|
+
+ }
|
|
184
|
+
+ const judged = readRecordOrNull();
|
|
185
|
+
+ if (judged === null)
|
|
186
|
+
+ continue;
|
|
187
|
+
+ const holder = await judgeHolder(judged, daemonJson);
|
|
188
|
+
+ if (holder !== null)
|
|
189
|
+
+ return holder;
|
|
190
|
+
+ try {
|
|
191
|
+
+ (0, node_fs_1.renameSync)(exports.serverProcessJsonPath, aside);
|
|
192
|
+
+ }
|
|
193
|
+
+ catch (e) {
|
|
194
|
+
+ if (e.code === 'ENOENT')
|
|
195
|
+
+ continue;
|
|
196
|
+
+ throw e;
|
|
197
|
+
+ }
|
|
198
|
+
+ const movedAside = readFileOrNull(aside);
|
|
199
|
+
+ if (movedAside !== null && movedAside !== judged.text) {
|
|
200
|
+
+ // A third daemon claimed the free path first if this finds it
|
|
201
|
+
+ // taken. The claim moved aside is then lost; its daemon finds
|
|
202
|
+
+ // the record is not its own and stops, as a displaced daemon
|
|
203
|
+
+ // always has.
|
|
204
|
+
+ createExclusively(exports.serverProcessJsonPath, aside, movedAside);
|
|
205
|
+
+ }
|
|
206
|
+
+ (0, node_fs_1.rmSync)(aside, { force: true });
|
|
207
|
+
+ }
|
|
208
|
+
+ throw new Error(`The Nx daemon record ${exports.serverProcessJsonPath} changed under every attempt to claim it.`);
|
|
209
|
+
+ }
|
|
210
|
+
+ finally {
|
|
211
|
+
+ (0, node_fs_1.rmSync)(staged, { force: true });
|
|
212
|
+
+ }
|
|
213
|
+
+}
|
|
214
|
+
+/**
|
|
215
|
+
+ * Whether the record judged names a daemon this one must not displace: `null`
|
|
216
|
+
+ * when it is stale.
|
|
217
|
+
+ */
|
|
218
|
+
+async function judgeHolder({ text, mtimeMs }, daemonJson) {
|
|
219
|
+
+ const starting = Date.now() - mtimeMs < DAEMON_STARTUP_GRACE_MS;
|
|
220
|
+
+ const owner = parseDaemonJson(text);
|
|
221
|
+
+ if (owner === null) {
|
|
222
|
+
+ // Only an exclusive create without link(2) shows a record half written.
|
|
223
|
+
+ return starting ? { kind: 'starting', owner: null } : null;
|
|
224
|
+
+ }
|
|
225
|
+
+ if (owner.processId === process.pid ||
|
|
226
|
+
+ owner.nxVersion !== daemonJson.nxVersion ||
|
|
227
|
+
+ owner.workspaceRoot !== daemonJson.workspaceRoot ||
|
|
228
|
+
+ !isProcessAlive(owner.processId)) {
|
|
229
|
+
+ return null;
|
|
230
|
+
+ }
|
|
231
|
+
+ if (await socketAnswers(owner.socketPath)) {
|
|
232
|
+
+ return { kind: 'serving', owner };
|
|
233
|
+
+ }
|
|
234
|
+
+ // A serving daemon exits once its socket is gone, so a live pid that has not
|
|
235
|
+
+ // answered past the grace is not this workspace's daemon: a reused pid.
|
|
236
|
+
+ return starting ? { kind: 'starting', owner } : null;
|
|
237
|
+
+}
|
|
238
|
+
+/**
|
|
239
|
+
+ * Creates `path` holding `text` unless it exists: by link(2) from `source`,
|
|
240
|
+
+ * which holds `text`, or on a filesystem without hard links by an exclusive
|
|
241
|
+
+ * create, whose half-written record a judge takes for one still starting.
|
|
242
|
+
+ */
|
|
243
|
+
+function createExclusively(path, source, text) {
|
|
244
|
+
+ try {
|
|
245
|
+
+ (0, node_fs_1.linkSync)(source, path);
|
|
246
|
+
+ return true;
|
|
247
|
+
+ }
|
|
248
|
+
+ catch (e) {
|
|
249
|
+
+ if (e.code === 'EEXIST')
|
|
250
|
+
+ return false;
|
|
251
|
+
+ if (e.code !== 'EPERM' && e.code !== 'ENOTSUP' && e.code !== 'ENOSYS')
|
|
252
|
+
+ throw e;
|
|
253
|
+
+ }
|
|
254
|
+
+ try {
|
|
255
|
+
+ (0, node_fs_1.writeFileSync)(path, text, { flag: 'wx' });
|
|
256
|
+
+ return true;
|
|
257
|
+
+ }
|
|
258
|
+
+ catch (e) {
|
|
259
|
+
+ if (e.code === 'EEXIST')
|
|
260
|
+
+ return false;
|
|
261
|
+
+ throw e;
|
|
262
|
+
+ }
|
|
263
|
+
+}
|
|
264
|
+
+function readRecordOrNull() {
|
|
265
|
+
+ let fd;
|
|
266
|
+
+ try {
|
|
267
|
+
+ fd = (0, node_fs_1.openSync)(exports.serverProcessJsonPath, 'r');
|
|
268
|
+
+ }
|
|
269
|
+
+ catch (e) {
|
|
270
|
+
+ if (e.code === 'ENOENT')
|
|
271
|
+
+ return null;
|
|
272
|
+
+ throw e;
|
|
273
|
+
+ }
|
|
274
|
+
+ try {
|
|
275
|
+
+ return {
|
|
276
|
+
+ text: (0, node_fs_1.readFileSync)(fd, 'utf-8'),
|
|
277
|
+
+ mtimeMs: (0, node_fs_1.fstatSync)(fd).mtimeMs,
|
|
278
|
+
+ };
|
|
279
|
+
+ }
|
|
280
|
+
+ finally {
|
|
281
|
+
+ (0, node_fs_1.closeSync)(fd);
|
|
282
|
+
+ }
|
|
283
|
+
+}
|
|
284
|
+
+function readFileOrNull(path) {
|
|
285
|
+
+ try {
|
|
286
|
+
+ return (0, node_fs_1.readFileSync)(path, 'utf-8');
|
|
287
|
+
+ }
|
|
288
|
+
+ catch (e) {
|
|
289
|
+
+ if (e.code === 'ENOENT')
|
|
290
|
+
+ return null;
|
|
291
|
+
+ throw e;
|
|
292
|
+
+ }
|
|
293
|
+
+}
|
|
294
|
+
+function parseDaemonJson(text) {
|
|
295
|
+
+ try {
|
|
296
|
+
+ return JSON.parse(text);
|
|
297
|
+
+ }
|
|
298
|
+
+ catch {
|
|
299
|
+
+ return null;
|
|
300
|
+
+ }
|
|
301
|
+
+}
|
|
302
|
+
+/** `kill(pid, 0)` reports EPERM for a live process this user may not signal. */
|
|
303
|
+
+function isProcessAlive(pid) {
|
|
304
|
+
+ try {
|
|
305
|
+
+ process.kill(pid, 0);
|
|
306
|
+
+ return true;
|
|
307
|
+
+ }
|
|
308
|
+
+ catch (e) {
|
|
309
|
+
+ return e.code === 'EPERM';
|
|
310
|
+
+ }
|
|
311
|
+
+}
|
|
312
|
+
+function socketAnswers(socketPath) {
|
|
313
|
+
+ return new Promise((resolve) => {
|
|
314
|
+
+ const socket = (0, node_net_1.connect)(socketPath, () => {
|
|
315
|
+
+ socket.destroy();
|
|
316
|
+
+ resolve(true);
|
|
317
|
+
+ });
|
|
318
|
+
+ socket.once('error', () => resolve(false));
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
// Must be sync for the help output use case
|
|
322
|
+
diff --git a/dist/src/daemon/client/client.d.ts b/dist/src/daemon/client/client.d.ts
|
|
323
|
+
index 9bd7b61bf9ad94c72a198dfe6f15fbcb68dfaac3..c552b4b252c2d0496312ddb6ff481699a6771552 100644
|
|
324
|
+
--- a/dist/src/daemon/client/client.d.ts
|
|
325
|
+
+++ b/dist/src/daemon/client/client.d.ts
|
|
326
|
+
@@ -2,7 +2,7 @@ import { ChildProcess } from 'child_process';
|
|
327
|
+
import { FileData, ProjectGraph } from '../../config/project-graph';
|
|
328
|
+
import { Task, TaskGraph } from '../../config/task-graph';
|
|
329
|
+
import { Hash } from '../../hasher/task-hasher';
|
|
330
|
+
-import { NxWorkspaceFiles, TaskRun, TaskTarget } from '../../native';
|
|
331
|
+
+import { NxWorkspaceFiles } from '../../native';
|
|
332
|
+
import { PostTasksExecutionContext, PreTasksExecutionContext } from '../../project-graph/plugins/public-api';
|
|
333
|
+
import { ConfigurationSourceMaps } from '../../project-graph/utils/project-configuration/source-maps';
|
|
334
|
+
import type { FlushSyncGeneratorChangesResult, SyncGeneratorRunResult } from '../../utils/sync-generators';
|
|
335
|
+
@@ -89,9 +89,6 @@ export declare class DaemonClient {
|
|
336
|
+
getFilesInDirectory(dir: string): Promise<string[]>;
|
|
337
|
+
hashGlob(globs: string[], exclude?: string[]): Promise<string>;
|
|
338
|
+
hashMultiGlob(globGroups: string[][]): Promise<string[]>;
|
|
339
|
+
- getFlakyTasks(hashes: string[]): Promise<string[]>;
|
|
340
|
+
- getEstimatedTaskTimings(targets: TaskTarget[]): Promise<Record<string, number>>;
|
|
341
|
+
- recordTaskRuns(taskRuns: TaskRun[]): Promise<void>;
|
|
342
|
+
getSyncGeneratorChanges(generators: string[]): Promise<SyncGeneratorRunResult[]>;
|
|
343
|
+
flushSyncGeneratorChangesToDisk(generators: string[]): Promise<FlushSyncGeneratorChangesResult>;
|
|
344
|
+
getRegisteredSyncGenerators(): Promise<{
|
|
345
|
+
diff --git a/dist/src/daemon/client/client.js b/dist/src/daemon/client/client.js
|
|
346
|
+
index cebfd6d1f8ddb2c5b93dcb847904aa9ab0553de6..a0389a0c54c40d43cf863b899bf49193d2918332 100644
|
|
347
|
+
--- a/dist/src/daemon/client/client.js
|
|
348
|
+
+++ b/dist/src/daemon/client/client.js
|
|
349
|
+
@@ -40,7 +40,6 @@ const nx_console_1 = require("../message-types/nx-console");
|
|
350
|
+
const register_project_graph_listener_1 = require("../message-types/register-project-graph-listener");
|
|
351
|
+
const run_tasks_execution_hooks_1 = require("../message-types/run-tasks-execution-hooks");
|
|
352
|
+
const streaming_messages_1 = require("../message-types/streaming-messages");
|
|
353
|
+
-const task_history_1 = require("../message-types/task-history");
|
|
354
|
+
const update_workspace_context_1 = require("../message-types/update-workspace-context");
|
|
355
|
+
const tmp_dir_1 = require("../tmp-dir");
|
|
356
|
+
const sandbox_socket_hint_1 = require("../sandbox-socket-hint");
|
|
357
|
+
@@ -668,27 +667,6 @@ class DaemonClient {
|
|
358
|
+
};
|
|
359
|
+
return this.sendToDaemonViaQueue(message);
|
|
360
|
+
}
|
|
361
|
+
- getFlakyTasks(hashes) {
|
|
362
|
+
- const message = {
|
|
363
|
+
- type: task_history_1.GET_FLAKY_TASKS,
|
|
364
|
+
- hashes,
|
|
365
|
+
- };
|
|
366
|
+
- return this.sendToDaemonViaQueue(message);
|
|
367
|
+
- }
|
|
368
|
+
- async getEstimatedTaskTimings(targets) {
|
|
369
|
+
- const message = {
|
|
370
|
+
- type: task_history_1.GET_ESTIMATED_TASK_TIMINGS,
|
|
371
|
+
- targets,
|
|
372
|
+
- };
|
|
373
|
+
- return this.sendToDaemonViaQueue(message);
|
|
374
|
+
- }
|
|
375
|
+
- recordTaskRuns(taskRuns) {
|
|
376
|
+
- const message = {
|
|
377
|
+
- type: task_history_1.RECORD_TASK_RUNS,
|
|
378
|
+
- taskRuns,
|
|
379
|
+
- };
|
|
380
|
+
- return this.sendToDaemonViaQueue(message);
|
|
381
|
+
- }
|
|
382
|
+
getSyncGeneratorChanges(generators) {
|
|
383
|
+
const message = {
|
|
384
|
+
type: get_sync_generator_changes_1.GET_SYNC_GENERATOR_CHANGES,
|
|
385
|
+
@@ -1132,8 +1110,11 @@ class DaemonClient {
|
|
386
|
+
*/
|
|
387
|
+
const { available, refusal: polled } = await this.waitForServerToBeAvailable({ ignoreVersionMismatch: true });
|
|
388
|
+
if (available) {
|
|
389
|
+
- logger_1.clientLogger.log(`[Client] Daemon server started, pid=${backgroundProcess.pid}`);
|
|
390
|
+
- return backgroundProcess.pid;
|
|
391
|
+
+ // The process spawned here exits instead of serving when another daemon
|
|
392
|
+
+ // already serves the workspace; the record names the one that answered.
|
|
393
|
+
+ const daemonPid = (0, cache_1.getDaemonProcessIdSync)() ?? backgroundProcess.pid;
|
|
394
|
+
+ logger_1.clientLogger.log(`[Client] Daemon server available, pid=${daemonPid}`);
|
|
395
|
+
+ return daemonPid;
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
// A permission refusal from either source wins, then the poll's errno,
|
|
399
|
+
diff --git a/dist/src/daemon/message-types/daemon-message.d.ts b/dist/src/daemon/message-types/daemon-message.d.ts
|
|
400
|
+
index 9dd6123ad6d9adb20a07f7db56fc476be78cbcca..0b1ee217729d63a29806cf6c38d0fc5d4a2161a5 100644
|
|
401
|
+
--- a/dist/src/daemon/message-types/daemon-message.d.ts
|
|
402
|
+
+++ b/dist/src/daemon/message-types/daemon-message.d.ts
|
|
403
|
+
@@ -11,6 +11,8 @@ export type DaemonMessage = {
|
|
404
|
+
data?: any;
|
|
405
|
+
};
|
|
406
|
+
export declare function isDaemonMessage(msg: unknown): msg is DaemonMessage;
|
|
407
|
+
+/** Normalize path spelling without removing a POSIX, drive or UNC root. */
|
|
408
|
+
+export declare function normalizeRootString(workspaceRoot: string, platform?: NodeJS.Platform): string;
|
|
409
|
+
/**
|
|
410
|
+
* Any message carrying the sender's workspace root. Structural so the checks
|
|
411
|
+
* below serve the daemon and the plugin worker without either importing the
|
|
412
|
+
@@ -24,7 +26,7 @@ type WorkspaceScopedMessage = {
|
|
413
|
+
/**
|
|
414
|
+
* A message from a different workspace — two sharing an NX_SOCKET_DIR — must not
|
|
415
|
+
* be processed. Roots are normalized first so that a workspace does not look
|
|
416
|
+
- * foreign to itself; see {@link normalizeWorkspaceRoot}.
|
|
417
|
+
+ * foreign to itself; see {@link normalizeRootString}.
|
|
418
|
+
*/
|
|
419
|
+
export declare function isForeignWorkspaceMessage(msg: WorkspaceScopedMessage, receiverWorkspaceRoot: string): boolean;
|
|
420
|
+
/**
|
|
421
|
+
diff --git a/dist/src/daemon/message-types/daemon-message.js b/dist/src/daemon/message-types/daemon-message.js
|
|
422
|
+
index e7a63499d18a3a8896fb117591356c3bb138032a..8d03082ada878fedd70c6245791f4c6979f17801 100644
|
|
423
|
+
--- a/dist/src/daemon/message-types/daemon-message.js
|
|
424
|
+
+++ b/dist/src/daemon/message-types/daemon-message.js
|
|
425
|
+
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
426
|
+
exports.isDaemonMessage = isDaemonMessage;
|
|
427
|
+
exports.isForeignWorkspaceMessage = isForeignWorkspaceMessage;
|
|
428
|
+
exports.assertNotForeignWorkspaceMessage = assertNotForeignWorkspaceMessage;
|
|
429
|
+
+exports.normalizeRootString = normalizeRootString;
|
|
430
|
+
const node_path_1 = require("node:path");
|
|
431
|
+
function isDaemonMessage(msg) {
|
|
432
|
+
return typeof msg === 'object' && msg && 'type' in msg;
|
|
433
|
+
@@ -22,22 +23,29 @@ function isDaemonMessage(msg) {
|
|
434
|
+
* POSIX roots keep their case, where `/repo` and `/REPO` really can be two
|
|
435
|
+
* directories.
|
|
436
|
+
*/
|
|
437
|
+
-function normalizeWorkspaceRoot(workspaceRoot) {
|
|
438
|
+
- return process.platform === 'win32'
|
|
439
|
+
- ? node_path_1.win32.normalize(workspaceRoot).toLowerCase()
|
|
440
|
+
- : node_path_1.posix.normalize(workspaceRoot);
|
|
441
|
+
+function normalizeRootString(workspaceRoot, platform = process.platform) {
|
|
442
|
+
+ const windows = platform === 'win32';
|
|
443
|
+
+ const format = windows ? node_path_1.win32 : node_path_1.posix;
|
|
444
|
+
+ const normalized = format.normalize(workspaceRoot);
|
|
445
|
+
+ const rootLength = format.parse(normalized).root.length;
|
|
446
|
+
+ let end = normalized.length;
|
|
447
|
+
+ while (end > rootLength && (normalized[end - 1] === '/' || (windows && normalized[end - 1] === '\\'))) {
|
|
448
|
+
+ end--;
|
|
449
|
+
+ }
|
|
450
|
+
+ const root = normalized.slice(0, end);
|
|
451
|
+
+ return windows ? root.toLowerCase() : root;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* A message from a different workspace — two sharing an NX_SOCKET_DIR — must not
|
|
455
|
+
* be processed. Roots are normalized first so that a workspace does not look
|
|
456
|
+
- * foreign to itself; see {@link normalizeWorkspaceRoot}.
|
|
457
|
+
+ * foreign to itself; see {@link normalizeRootString}.
|
|
458
|
+
*/
|
|
459
|
+
function isForeignWorkspaceMessage(msg, receiverWorkspaceRoot) {
|
|
460
|
+
if (msg.workspaceRoot === undefined) {
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
- return (normalizeWorkspaceRoot(msg.workspaceRoot) !==
|
|
464
|
+
- normalizeWorkspaceRoot(receiverWorkspaceRoot));
|
|
465
|
+
+ return (normalizeRootString(msg.workspaceRoot) !==
|
|
466
|
+
+ normalizeRootString(receiverWorkspaceRoot));
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Throws on a message this receiver must not act on. The daemon catches it and
|
|
470
|
+
diff --git a/dist/src/daemon/message-types/task-history.d.ts b/dist/src/daemon/message-types/task-history.d.ts
|
|
471
|
+
deleted file mode 100644
|
|
472
|
+
index cc2b606d99db19beb05d85e5ec2f13600712e7bd..0000000000000000000000000000000000000000
|
|
473
|
+
--- a/dist/src/daemon/message-types/task-history.d.ts
|
|
474
|
+
+++ /dev/null
|
|
475
|
+
@@ -1,19 +0,0 @@
|
|
476
|
+
-import type { TaskRun, TaskTarget } from '../../native';
|
|
477
|
+
-export declare const GET_FLAKY_TASKS: 'GET_FLAKY_TASKS';
|
|
478
|
+
-export declare const GET_ESTIMATED_TASK_TIMINGS: 'GET_ESTIMATED_TASK_TIMINGS';
|
|
479
|
+
-export declare const RECORD_TASK_RUNS: 'RECORD_TASK_RUNS';
|
|
480
|
+
-export type HandleGetFlakyTasks = {
|
|
481
|
+
- type: typeof GET_FLAKY_TASKS;
|
|
482
|
+
- hashes: string[];
|
|
483
|
+
-};
|
|
484
|
+
-export type HandleGetEstimatedTaskTimings = {
|
|
485
|
+
- type: typeof GET_ESTIMATED_TASK_TIMINGS;
|
|
486
|
+
- targets: TaskTarget[];
|
|
487
|
+
-};
|
|
488
|
+
-export type HandleRecordTaskRunsMessage = {
|
|
489
|
+
- type: typeof RECORD_TASK_RUNS;
|
|
490
|
+
- taskRuns: TaskRun[];
|
|
491
|
+
-};
|
|
492
|
+
-export declare function isHandleGetFlakyTasksMessage(message: unknown): message is HandleGetFlakyTasks;
|
|
493
|
+
-export declare function isHandleGetEstimatedTaskTimings(message: unknown): message is HandleGetEstimatedTaskTimings;
|
|
494
|
+
-export declare function isHandleWriteTaskRunsToHistoryMessage(message: unknown): message is HandleRecordTaskRunsMessage;
|
|
495
|
+
diff --git a/dist/src/daemon/message-types/task-history.js b/dist/src/daemon/message-types/task-history.js
|
|
496
|
+
deleted file mode 100644
|
|
497
|
+
index 12c1507aec3cf894bc18c680818bf76ec1533cca..0000000000000000000000000000000000000000
|
|
498
|
+
--- a/dist/src/daemon/message-types/task-history.js
|
|
499
|
+
+++ /dev/null
|
|
500
|
+
@@ -1,27 +0,0 @@
|
|
501
|
+
-"use strict";
|
|
502
|
+
-Object.defineProperty(exports, "__esModule", { value: true });
|
|
503
|
+
-exports.RECORD_TASK_RUNS = exports.GET_ESTIMATED_TASK_TIMINGS = exports.GET_FLAKY_TASKS = void 0;
|
|
504
|
+
-exports.isHandleGetFlakyTasksMessage = isHandleGetFlakyTasksMessage;
|
|
505
|
+
-exports.isHandleGetEstimatedTaskTimings = isHandleGetEstimatedTaskTimings;
|
|
506
|
+
-exports.isHandleWriteTaskRunsToHistoryMessage = isHandleWriteTaskRunsToHistoryMessage;
|
|
507
|
+
-exports.GET_FLAKY_TASKS = 'GET_FLAKY_TASKS';
|
|
508
|
+
-exports.GET_ESTIMATED_TASK_TIMINGS = 'GET_ESTIMATED_TASK_TIMINGS';
|
|
509
|
+
-exports.RECORD_TASK_RUNS = 'RECORD_TASK_RUNS';
|
|
510
|
+
-function isHandleGetFlakyTasksMessage(message) {
|
|
511
|
+
- return (typeof message === 'object' &&
|
|
512
|
+
- message !== null &&
|
|
513
|
+
- 'type' in message &&
|
|
514
|
+
- message['type'] === exports.GET_FLAKY_TASKS);
|
|
515
|
+
-}
|
|
516
|
+
-function isHandleGetEstimatedTaskTimings(message) {
|
|
517
|
+
- return (typeof message === 'object' &&
|
|
518
|
+
- message !== null &&
|
|
519
|
+
- 'type' in message &&
|
|
520
|
+
- message['type'] === exports.GET_ESTIMATED_TASK_TIMINGS);
|
|
521
|
+
-}
|
|
522
|
+
-function isHandleWriteTaskRunsToHistoryMessage(message) {
|
|
523
|
+
- return (typeof message === 'object' &&
|
|
524
|
+
- message !== null &&
|
|
525
|
+
- 'type' in message &&
|
|
526
|
+
- message['type'] === exports.RECORD_TASK_RUNS);
|
|
527
|
+
-}
|
|
528
|
+
diff --git a/dist/src/daemon/server/handle-task-history.d.ts b/dist/src/daemon/server/handle-task-history.d.ts
|
|
529
|
+
deleted file mode 100644
|
|
530
|
+
index 70e1f4db2d37af99bfea24cebca2cdf49f71406d..0000000000000000000000000000000000000000
|
|
531
|
+
--- a/dist/src/daemon/server/handle-task-history.d.ts
|
|
532
|
+
+++ /dev/null
|
|
533
|
+
@@ -1,13 +0,0 @@
|
|
534
|
+
-import type { TaskRun, TaskTarget } from '../../native';
|
|
535
|
+
-export declare function handleRecordTaskRuns(taskRuns: TaskRun[]): Promise<{
|
|
536
|
+
- response: string;
|
|
537
|
+
- description: string;
|
|
538
|
+
-}>;
|
|
539
|
+
-export declare function handleGetFlakyTasks(hashes: string[]): Promise<{
|
|
540
|
+
- response: string[];
|
|
541
|
+
- description: string;
|
|
542
|
+
-}>;
|
|
543
|
+
-export declare function handleGetEstimatedTaskTimings(targets: TaskTarget[]): Promise<{
|
|
544
|
+
- response: Record<string, number>;
|
|
545
|
+
- description: string;
|
|
546
|
+
-}>;
|
|
547
|
+
diff --git a/dist/src/daemon/server/handle-task-history.js b/dist/src/daemon/server/handle-task-history.js
|
|
548
|
+
deleted file mode 100644
|
|
549
|
+
index 0051f7f97f0d9c05341f8cbaa7f51eb851051077..0000000000000000000000000000000000000000
|
|
550
|
+
--- a/dist/src/daemon/server/handle-task-history.js
|
|
551
|
+
+++ /dev/null
|
|
552
|
+
@@ -1,30 +0,0 @@
|
|
553
|
+
-"use strict";
|
|
554
|
+
-Object.defineProperty(exports, "__esModule", { value: true });
|
|
555
|
+
-exports.handleRecordTaskRuns = handleRecordTaskRuns;
|
|
556
|
+
-exports.handleGetFlakyTasks = handleGetFlakyTasks;
|
|
557
|
+
-exports.handleGetEstimatedTaskTimings = handleGetEstimatedTaskTimings;
|
|
558
|
+
-const task_history_1 = require("../../utils/task-history");
|
|
559
|
+
-async function handleRecordTaskRuns(taskRuns) {
|
|
560
|
+
- const taskHistory = (0, task_history_1.getTaskHistory)();
|
|
561
|
+
- await taskHistory.recordTaskRuns(taskRuns);
|
|
562
|
+
- return {
|
|
563
|
+
- response: 'true',
|
|
564
|
+
- description: 'handleRecordTaskRuns',
|
|
565
|
+
- };
|
|
566
|
+
-}
|
|
567
|
+
-async function handleGetFlakyTasks(hashes) {
|
|
568
|
+
- const taskHistory = (0, task_history_1.getTaskHistory)();
|
|
569
|
+
- const history = await taskHistory.getFlakyTasks(hashes);
|
|
570
|
+
- return {
|
|
571
|
+
- response: history,
|
|
572
|
+
- description: 'handleGetFlakyTasks',
|
|
573
|
+
- };
|
|
574
|
+
-}
|
|
575
|
+
-async function handleGetEstimatedTaskTimings(targets) {
|
|
576
|
+
- const taskHistory = (0, task_history_1.getTaskHistory)();
|
|
577
|
+
- const history = await taskHistory.getEstimatedTaskTimings(targets);
|
|
578
|
+
- return {
|
|
579
|
+
- response: history,
|
|
580
|
+
- description: 'handleGetEstimatedTaskTimings',
|
|
581
|
+
- };
|
|
582
|
+
-}
|
|
583
|
+
diff --git a/dist/src/daemon/server/latest-nx.js b/dist/src/daemon/server/latest-nx.js
|
|
584
|
+
index ef00ae3212498e75d6bb6371aec4b113970c0c68..06eb2bf7436cc20dad1d646be44ba99064395f3d 100644
|
|
585
|
+
--- a/dist/src/daemon/server/latest-nx.js
|
|
586
|
+
+++ b/dist/src/daemon/server/latest-nx.js
|
|
587
|
+
@@ -20,6 +20,11 @@ let installPromise = null;
|
|
588
|
+
* Guards against concurrent callers by reusing the in-flight promise.
|
|
589
|
+
*/
|
|
590
|
+
async function getLatestNxTmpPath() {
|
|
591
|
+
+ // The daemon never installs `nx@latest` from the registry, whatever the
|
|
592
|
+
+ // environment a client sent it says: it answers Nx Console and AI-agent
|
|
593
|
+
+ // status from the Nx that runs it. Callers resolve `nx/...` from the
|
|
594
|
+
+ // returned directory, which finds this installed package.
|
|
595
|
+
+ return __dirname;
|
|
596
|
+
if (latestNxTmpPath !== null) {
|
|
597
|
+
logger_1.serverLogger.log('[LATEST-NX]: Reusing cached Nx installation from', latestNxTmpPath);
|
|
598
|
+
return latestNxTmpPath;
|
|
599
|
+
diff --git a/dist/src/daemon/server/project-graph-incremental-recomputation.js b/dist/src/daemon/server/project-graph-incremental-recomputation.js
|
|
600
|
+
index c2a2f8f70fe71940e47c97931c5925bac1fbd480..39582a8fc342ae59decd3d4ca25179f2bc478691 100644
|
|
601
|
+
--- a/dist/src/daemon/server/project-graph-incremental-recomputation.js
|
|
602
|
+
+++ b/dist/src/daemon/server/project-graph-incremental-recomputation.js
|
|
603
|
+
@@ -27,6 +27,7 @@ const file_watcher_sockets_1 = require("./file-watching/file-watcher-sockets");
|
|
604
|
+
const project_graph_listener_sockets_1 = require("./project-graph-listener-sockets");
|
|
605
|
+
const watcher_1 = require("./watcher");
|
|
606
|
+
const logger_1 = require("../logger");
|
|
607
|
+
+const restart_checks_1 = require("./restart-checks");
|
|
608
|
+
let cachedSerializedProjectGraphPromise;
|
|
609
|
+
// Maps file path to a version counter that increments on each modification.
|
|
610
|
+
// This lets us detect mid-flight re-modifications when clearing processed files.
|
|
611
|
+
@@ -241,6 +242,11 @@ function scheduleProjectGraphRecomputation(createdFiles, updatedFiles, deletedFi
|
|
612
|
+
: {};
|
|
613
|
+
perf_hooks_1.performance.mark('hash-watched-changes-end');
|
|
614
|
+
perf_hooks_1.performance.measure('hash changed files from watcher', 'hash-watched-changes-start', 'hash-watched-changes-end');
|
|
615
|
+
+ const changedPaths = Object.keys(changedFileHashes);
|
|
616
|
+
+ if ((0, restart_checks_1.restartDaemonIfLockFilesChanged)(changedPaths) ||
|
|
617
|
+
+ (0, restart_checks_1.restartDaemonIfLockFilesChanged)(deletedFiles)) {
|
|
618
|
+
+ return;
|
|
619
|
+
+ }
|
|
620
|
+
for (const [f, hash] of Object.entries(changedFileHashes)) {
|
|
621
|
+
collectedDeletedFiles.delete(f);
|
|
622
|
+
collectedUpdatedFiles.set(f, { version: fileChangeCounter, hash });
|
|
623
|
+
@@ -251,7 +257,7 @@ function scheduleProjectGraphRecomputation(createdFiles, updatedFiles, deletedFi
|
|
624
|
+
}
|
|
625
|
+
// The native watcher already coalesces a burst of events into one batch,
|
|
626
|
+
// so socket + listener notifications dispatch immediately.
|
|
627
|
+
- if (Object.keys(changedFileHashes).length > 0 || deletedFiles.length > 0) {
|
|
628
|
+
+ if (changedPaths.length > 0 || deletedFiles.length > 0) {
|
|
629
|
+
(0, file_change_events_1.notifyFileChangeListeners)({ createdFiles, updatedFiles, deletedFiles });
|
|
630
|
+
(0, file_watcher_sockets_1.notifyFileWatcherSockets)(createdFiles, updatedFiles, deletedFiles);
|
|
631
|
+
// Bump generation synchronously so any in-flight compute fails its
|
|
632
|
+
diff --git a/dist/src/daemon/server/restart-checks.d.ts b/dist/src/daemon/server/restart-checks.d.ts
|
|
633
|
+
new file mode 100644
|
|
634
|
+
index 0000000000000000000000000000000000000000..65660f0d5f7789d64ad26b0a9644f23949e79831
|
|
635
|
+
--- /dev/null
|
|
636
|
+
+++ b/dist/src/daemon/server/restart-checks.d.ts
|
|
637
|
+
@@ -0,0 +1,9 @@
|
|
638
|
+
+import type { Server, Socket } from 'net';
|
|
639
|
+
+import type { WatchEvent } from '../../native';
|
|
640
|
+
+export declare const DAEMON_VALIDITY_SAFETY_INTERVAL_MS = 5000;
|
|
641
|
+
+export declare const relativeServerProcess: string;
|
|
642
|
+
+export declare function registerDaemonForRestartChecks(server: Server, sockets: Iterable<Socket>, socketPath: string): void;
|
|
643
|
+
+export declare function recordLockFileHash(): void;
|
|
644
|
+
+export declare function restartDaemonIfLockFilesChanged(paths: string[]): boolean;
|
|
645
|
+
+export declare function stopDaemonIfReplaced(events: WatchEvent[]): boolean;
|
|
646
|
+
+export declare function stopDaemonIfOutdated(): boolean;
|
|
647
|
+
diff --git a/dist/src/daemon/server/restart-checks.js b/dist/src/daemon/server/restart-checks.js
|
|
648
|
+
new file mode 100644
|
|
649
|
+
index 0000000000000000000000000000000000000000..e45f9d2c918a1d33b6ebb29be76dfb2eecd37b45
|
|
650
|
+
--- /dev/null
|
|
651
|
+
+++ b/dist/src/daemon/server/restart-checks.js
|
|
652
|
+
@@ -0,0 +1,113 @@
|
|
653
|
+
+"use strict";
|
|
654
|
+
+Object.defineProperty(exports, "__esModule", { value: true });
|
|
655
|
+
+exports.relativeServerProcess = exports.DAEMON_VALIDITY_SAFETY_INTERVAL_MS = void 0;
|
|
656
|
+
+exports.registerDaemonForRestartChecks = registerDaemonForRestartChecks;
|
|
657
|
+
+exports.recordLockFileHash = recordLockFileHash;
|
|
658
|
+
+exports.restartDaemonIfLockFilesChanged = restartDaemonIfLockFilesChanged;
|
|
659
|
+
+exports.stopDaemonIfReplaced = stopDaemonIfReplaced;
|
|
660
|
+
+exports.stopDaemonIfOutdated = stopDaemonIfOutdated;
|
|
661
|
+
+const fs_1 = require("fs");
|
|
662
|
+
+const path_1 = require("path");
|
|
663
|
+
+const file_hasher_1 = require("../../hasher/file-hasher");
|
|
664
|
+
+const native_1 = require("../../native");
|
|
665
|
+
+const path_2 = require("../../utils/path");
|
|
666
|
+
+const workspace_root_1 = require("../../utils/workspace-root");
|
|
667
|
+
+const cache_1 = require("../cache");
|
|
668
|
+
+const is_nx_version_mismatch_1 = require("../is-nx-version-mismatch");
|
|
669
|
+
+const logger_1 = require("../logger");
|
|
670
|
+
+const socket_utils_1 = require("../socket-utils");
|
|
671
|
+
+const shutdown_utils_1 = require("./shutdown-utils");
|
|
672
|
+
+// Adapted from nrwl/nx#37113. Kept apart from server.js: importing it starts a server.
|
|
673
|
+
+let daemon;
|
|
674
|
+
+let terminating = false;
|
|
675
|
+
+function registerDaemonForRestartChecks(server, sockets, socketPath) {
|
|
676
|
+
+ daemon = { server, sockets, socketPath };
|
|
677
|
+
+ terminating = false;
|
|
678
|
+
+}
|
|
679
|
+
+exports.DAEMON_VALIDITY_SAFETY_INTERVAL_MS = 5000;
|
|
680
|
+
+exports.relativeServerProcess = (0, path_2.normalizePath)((0, path_1.relative)(workspace_root_1.workspaceRoot, cache_1.serverProcessJsonPath));
|
|
681
|
+
+const LOCK_FILE_NAMES = ['package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lockb', 'bun.lock'];
|
|
682
|
+
+const lockFiles = LOCK_FILE_NAMES.map((name) => (0, path_1.join)(workspace_root_1.workspaceRoot, name));
|
|
683
|
+
+let lockFileHash;
|
|
684
|
+
+function hashLockFiles() {
|
|
685
|
+
+ // Include the names so a missed rename between two lockfile formats is visible.
|
|
686
|
+
+ const hashes = [];
|
|
687
|
+
+ for (let i = 0; i < lockFiles.length; i++) {
|
|
688
|
+
+ if ((0, fs_1.existsSync)(lockFiles[i])) {
|
|
689
|
+
+ hashes.push(LOCK_FILE_NAMES[i], (0, native_1.hashFile)(lockFiles[i]));
|
|
690
|
+
+ }
|
|
691
|
+
+ }
|
|
692
|
+
+ return (0, file_hasher_1.hashArray)(hashes);
|
|
693
|
+
+}
|
|
694
|
+
+function recordLockFileHash() {
|
|
695
|
+
+ lockFileHash = hashLockFiles();
|
|
696
|
+
+}
|
|
697
|
+
+function lockFileHashChanged() {
|
|
698
|
+
+ const newHash = hashLockFiles();
|
|
699
|
+
+ if (lockFileHash !== undefined && newHash !== lockFileHash) {
|
|
700
|
+
+ logger_1.serverLogger.log(`[Server] lock file hash changed! old=${lockFileHash}, new=${newHash}`);
|
|
701
|
+
+ lockFileHash = newHash;
|
|
702
|
+
+ return true;
|
|
703
|
+
+ }
|
|
704
|
+
+ lockFileHash = newHash;
|
|
705
|
+
+ return false;
|
|
706
|
+
+}
|
|
707
|
+
+// Applied paths have been hashed by the native workspace context; same-byte
|
|
708
|
+
+// rewrites were dropped already. No lockfile is read on this watcher path.
|
|
709
|
+
+function restartDaemonIfLockFilesChanged(paths) {
|
|
710
|
+
+ if (!paths.some((path) => LOCK_FILE_NAMES.includes(path))) {
|
|
711
|
+
+ return false;
|
|
712
|
+
+ }
|
|
713
|
+
+ restartDaemon('LOCK_FILES_CHANGED');
|
|
714
|
+
+ return true;
|
|
715
|
+
+}
|
|
716
|
+
+function stopDaemonIfReplaced(events) {
|
|
717
|
+
+ if (terminating) return true;
|
|
718
|
+
+ // Pinned Nx 23.2.1 reports create/update/delete, not upstream's rescan event.
|
|
719
|
+
+ // The safety interval covers missed ownership events on this version.
|
|
720
|
+
+ const replaced = events.some((event) => event.path === exports.relativeServerProcess && isReplaced());
|
|
721
|
+
+ if (replaced) {
|
|
722
|
+
+ stopDaemon('this process is no longer the current daemon (native)');
|
|
723
|
+
+ }
|
|
724
|
+
+ return replaced;
|
|
725
|
+
+}
|
|
726
|
+
+// Once per request, including long-lived sockets, and on the slow safety poll.
|
|
727
|
+
+// The socket guard uses the inode captured at bind, never a client's environment.
|
|
728
|
+
+function stopDaemonIfOutdated() {
|
|
729
|
+
+ if (terminating) return true;
|
|
730
|
+
+ if (isReplaced()) {
|
|
731
|
+
+ stopDaemon('this process is no longer the current daemon (native)');
|
|
732
|
+
+ return true;
|
|
733
|
+
+ }
|
|
734
|
+
+ if ((0, socket_utils_1.ownSocketState)() === 'lost') {
|
|
735
|
+
+ stopDaemon(`its socket ${daemon.socketPath} was removed or replaced, so no client can reach it`);
|
|
736
|
+
+ return true;
|
|
737
|
+
+ }
|
|
738
|
+
+ if ((0, is_nx_version_mismatch_1.isNxVersionMismatch)()) {
|
|
739
|
+
+ logger_1.serverLogger.log('[Server] Daemon outdated: NX_VERSION_CHANGED');
|
|
740
|
+
+ stopDaemon('NX_VERSION_CHANGED');
|
|
741
|
+
+ return true;
|
|
742
|
+
+ }
|
|
743
|
+
+ if (lockFileHashChanged()) {
|
|
744
|
+
+ restartDaemon('LOCK_FILES_CHANGED');
|
|
745
|
+
+ return true;
|
|
746
|
+
+ }
|
|
747
|
+
+ return false;
|
|
748
|
+
+}
|
|
749
|
+
+function isReplaced() {
|
|
750
|
+
+ return (0, cache_1.getDaemonProcessIdSync)() !== process.pid;
|
|
751
|
+
+}
|
|
752
|
+
+function stopDaemon(reason) {
|
|
753
|
+
+ if (!daemon || terminating) return;
|
|
754
|
+
+ terminating = true;
|
|
755
|
+
+ (0, shutdown_utils_1.handleServerProcessTermination)({ server: daemon.server, reason, sockets: daemon.sockets });
|
|
756
|
+
+}
|
|
757
|
+
+function restartDaemon(reason) {
|
|
758
|
+
+ if (!daemon || terminating) return;
|
|
759
|
+
+ // Do not spawn multiple replacements or answer queued requests while the
|
|
760
|
+
+ // asynchronous restart releases ownership and starts the successor.
|
|
761
|
+
+ terminating = true;
|
|
762
|
+
+ logger_1.serverLogger.log(`[Server] Daemon outdated: ${reason}`);
|
|
763
|
+
+ logger_1.serverLogger.log('[Server] Restarting daemon...');
|
|
764
|
+
+ (0, shutdown_utils_1.handleServerProcessTerminationWithRestart)({ server: daemon.server, reason, sockets: daemon.sockets });
|
|
765
|
+
+}
|
|
766
|
+
diff --git a/dist/src/daemon/server/server.js b/dist/src/daemon/server/server.js
|
|
767
|
+
index b1c143e244efd435b28642ed86e999d6c86f7d94..9939d13d2845b63af8dfdfbba08a01d3832fe34d 100644
|
|
768
|
+
--- a/dist/src/daemon/server/server.js
|
|
769
|
+
+++ b/dist/src/daemon/server/server.js
|
|
770
|
+
@@ -7,17 +7,13 @@ const fs_1 = require("fs");
|
|
771
|
+
const permission_errors_1 = require("../../utils/permission-errors");
|
|
772
|
+
const socket_refused_exit_code_1 = require("../../utils/socket-refused-exit-code");
|
|
773
|
+
const net_1 = require("net");
|
|
774
|
+
-const path_1 = require("path");
|
|
775
|
+
const analytics_1 = require("../../analytics");
|
|
776
|
+
-const file_hasher_1 = require("../../hasher/file-hasher");
|
|
777
|
+
-const native_1 = require("../../native");
|
|
778
|
+
const consume_messages_from_socket_1 = require("../../utils/consume-messages-from-socket");
|
|
779
|
+
require("../../utils/perf-logging");
|
|
780
|
+
const versions_1 = require("../../utils/versions");
|
|
781
|
+
const workspace_context_1 = require("../../utils/workspace-context");
|
|
782
|
+
const workspace_root_1 = require("../../utils/workspace-root");
|
|
783
|
+
const cache_1 = require("../cache");
|
|
784
|
+
-const is_nx_version_mismatch_1 = require("../is-nx-version-mismatch");
|
|
785
|
+
const installed_nx_version_1 = require("../../utils/installed-nx-version");
|
|
786
|
+
const logger_1 = require("../logger");
|
|
787
|
+
const configure_ai_agents_1 = require("../message-types/configure-ai-agents");
|
|
788
|
+
@@ -34,7 +30,6 @@ const hash_glob_1 = require("../message-types/hash-glob");
|
|
789
|
+
const nx_console_1 = require("../message-types/nx-console");
|
|
790
|
+
const register_project_graph_listener_1 = require("../message-types/register-project-graph-listener");
|
|
791
|
+
const run_tasks_execution_hooks_1 = require("../message-types/run-tasks-execution-hooks");
|
|
792
|
+
-const task_history_1 = require("../message-types/task-history");
|
|
793
|
+
const update_workspace_context_1 = require("../message-types/update-workspace-context");
|
|
794
|
+
const socket_utils_1 = require("../socket-utils");
|
|
795
|
+
const file_change_events_1 = require("./file-watching/file-change-events");
|
|
796
|
+
@@ -57,7 +52,6 @@ const handle_outputs_tracking_1 = require("./handle-outputs-tracking");
|
|
797
|
+
const handle_process_in_background_1 = require("./handle-process-in-background");
|
|
798
|
+
const handle_request_project_graph_1 = require("./handle-request-project-graph");
|
|
799
|
+
const handle_request_shutdown_1 = require("./handle-request-shutdown");
|
|
800
|
+
-const handle_task_history_1 = require("./handle-task-history");
|
|
801
|
+
const handle_tasks_execution_hooks_1 = require("./handle-tasks-execution-hooks");
|
|
802
|
+
const handle_update_workspace_context_1 = require("./handle-update-workspace-context");
|
|
803
|
+
const handle_outputs_changes_1 = require("./handle-outputs-changes");
|
|
804
|
+
@@ -66,6 +60,7 @@ const project_graph_listener_sockets_1 = require("./project-graph-listener-socke
|
|
805
|
+
const shutdown_utils_1 = require("./shutdown-utils");
|
|
806
|
+
const sync_generators_1 = require("./sync-generators");
|
|
807
|
+
const watcher_1 = require("./watcher");
|
|
808
|
+
+const restart_checks_1 = require("./restart-checks");
|
|
809
|
+
let workspaceWatcherError;
|
|
810
|
+
global.NX_DAEMON = true;
|
|
811
|
+
process.env.NX_DAEMON_PROCESS = 'true';
|
|
812
|
+
@@ -97,6 +92,9 @@ const server = (0, net_1.createServer)(async (socket) => {
|
|
813
|
+
numberOfOpenConnections -= 1;
|
|
814
|
+
exports.openSockets.delete(socket);
|
|
815
|
+
logger_1.serverLogger.log(`Closed a connection. Number of open connections: ${numberOfOpenConnections}`);
|
|
816
|
+
+ if (numberOfOpenConnections === 0) {
|
|
817
|
+
+ (0, shutdown_utils_1.resetInactivityTimeout)(handleInactivityTimeout);
|
|
818
|
+
+ }
|
|
819
|
+
(0, file_watcher_sockets_1.removeRegisteredFileWatcherSocket)(socket);
|
|
820
|
+
(0, project_graph_listener_sockets_1.removeRegisteredProjectGraphListenerSocket)(socket);
|
|
821
|
+
});
|
|
822
|
+
@@ -134,6 +132,11 @@ async function handleMessage(socket, data) {
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
+ // Check every request, including requests on a long-lived connection.
|
|
827
|
+
+ // Shutdown closes this socket; the client reconnects to the next daemon.
|
|
828
|
+
+ if ((0, restart_checks_1.stopDaemonIfOutdated)()) {
|
|
829
|
+
+ return;
|
|
830
|
+
+ }
|
|
831
|
+
if ((0, daemon_message_1.isDaemonMessage)(payload) && payload.env) {
|
|
832
|
+
await (0, handle_client_env_1.handleClientEnv)(payload.env);
|
|
833
|
+
}
|
|
834
|
+
@@ -185,15 +188,6 @@ async function handleMessage(socket, data) {
|
|
835
|
+
else if ((0, hash_glob_1.isHandleHashMultiGlobMessage)(payload)) {
|
|
836
|
+
await handleResult(socket, hash_glob_1.HASH_GLOB, () => (0, handle_hash_glob_1.handleHashMultiGlob)(payload.globGroups), mode);
|
|
837
|
+
}
|
|
838
|
+
- else if ((0, task_history_1.isHandleGetFlakyTasksMessage)(payload)) {
|
|
839
|
+
- await handleResult(socket, task_history_1.GET_FLAKY_TASKS, () => (0, handle_task_history_1.handleGetFlakyTasks)(payload.hashes), mode);
|
|
840
|
+
- }
|
|
841
|
+
- else if ((0, task_history_1.isHandleGetEstimatedTaskTimings)(payload)) {
|
|
842
|
+
- await handleResult(socket, task_history_1.GET_ESTIMATED_TASK_TIMINGS, () => (0, handle_task_history_1.handleGetEstimatedTaskTimings)(payload.targets), mode);
|
|
843
|
+
- }
|
|
844
|
+
- else if ((0, task_history_1.isHandleWriteTaskRunsToHistoryMessage)(payload)) {
|
|
845
|
+
- await handleResult(socket, task_history_1.RECORD_TASK_RUNS, () => (0, handle_task_history_1.handleRecordTaskRuns)(payload.taskRuns), mode);
|
|
846
|
+
- }
|
|
847
|
+
else if ((0, force_shutdown_1.isHandleForceShutdownMessage)(payload)) {
|
|
848
|
+
await handleResult(socket, 'FORCE_SHUTDOWN', () => (0, handle_force_shutdown_1.handleForceShutdown)(server), mode);
|
|
849
|
+
}
|
|
850
|
+
@@ -256,9 +250,10 @@ async function handleResult(socket, type, hrFn, mode) {
|
|
851
|
+
logger_1.serverLogger.log(`Handled ${mode} message ${type}. Handling time: ${doneHandlingMark.getTime() - startMark.getTime()}. Response time: ${endMark.getTime() - doneHandlingMark.getTime()}.`);
|
|
852
|
+
}
|
|
853
|
+
function handleInactivityTimeout() {
|
|
854
|
+
- if ((0, file_watcher_sockets_1.hasRegisteredFileWatcherSockets)() ||
|
|
855
|
+
+ if (numberOfOpenConnections > 0 ||
|
|
856
|
+
+ (0, file_watcher_sockets_1.hasRegisteredFileWatcherSockets)() ||
|
|
857
|
+
(0, project_graph_listener_sockets_1.hasRegisteredProjectGraphListenerSockets)()) {
|
|
858
|
+
- logger_1.serverLogger.log(`There are open file watchers or project graph listeners. Resetting inactivity timer.`);
|
|
859
|
+
+ logger_1.serverLogger.log(`There are open request connections, file watchers or project graph listeners. Resetting inactivity timer.`);
|
|
860
|
+
(0, shutdown_utils_1.resetInactivityTimeout)(handleInactivityTimeout);
|
|
861
|
+
}
|
|
862
|
+
else {
|
|
863
|
+
@@ -287,37 +282,6 @@ function registerProcessTerminationListeners() {
|
|
864
|
+
sockets: exports.openSockets,
|
|
865
|
+
}));
|
|
866
|
+
}
|
|
867
|
+
-let existingLockHash;
|
|
868
|
+
-function daemonIsOutdated() {
|
|
869
|
+
- if ((0, is_nx_version_mismatch_1.isNxVersionMismatch)()) {
|
|
870
|
+
- return 'NX_VERSION_CHANGED';
|
|
871
|
+
- }
|
|
872
|
+
- else if (lockFileHashChanged()) {
|
|
873
|
+
- return 'LOCK_FILES_CHANGED';
|
|
874
|
+
- }
|
|
875
|
+
- return null;
|
|
876
|
+
-}
|
|
877
|
+
-function lockFileHashChanged() {
|
|
878
|
+
- const lockFiles = [
|
|
879
|
+
- (0, path_1.join)(workspace_root_1.workspaceRoot, 'package-lock.json'),
|
|
880
|
+
- (0, path_1.join)(workspace_root_1.workspaceRoot, 'yarn.lock'),
|
|
881
|
+
- (0, path_1.join)(workspace_root_1.workspaceRoot, 'pnpm-lock.yaml'),
|
|
882
|
+
- (0, path_1.join)(workspace_root_1.workspaceRoot, 'bun.lockb'),
|
|
883
|
+
- (0, path_1.join)(workspace_root_1.workspaceRoot, 'bun.lock'),
|
|
884
|
+
- ];
|
|
885
|
+
- const existingFiles = lockFiles.filter((file) => (0, fs_1.existsSync)(file));
|
|
886
|
+
- const lockHashes = existingFiles.map((file) => (0, native_1.hashFile)(file));
|
|
887
|
+
- const newHash = (0, file_hasher_1.hashArray)(lockHashes);
|
|
888
|
+
- if (existingLockHash && newHash != existingLockHash) {
|
|
889
|
+
- logger_1.serverLogger.log(`[Server] lock file hash changed! old=${existingLockHash}, new=${newHash}`);
|
|
890
|
+
- existingLockHash = newHash;
|
|
891
|
+
- return true;
|
|
892
|
+
- }
|
|
893
|
+
- else {
|
|
894
|
+
- existingLockHash = newHash;
|
|
895
|
+
- return false;
|
|
896
|
+
- }
|
|
897
|
+
-}
|
|
898
|
+
/**
|
|
899
|
+
* When applicable files in the workspaces are changed (created, updated, deleted),
|
|
900
|
+
* we need to recompute the cached serialized project graph so that it is readily
|
|
901
|
+
@@ -348,7 +312,43 @@ const handleWorkspaceChanges = async (err, changeEvents) => {
|
|
902
|
+
(0, file_watcher_sockets_1.notifyFileWatcherSocketsOfError)(err);
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
+/**
|
|
906
|
+
+ * Claims the workspace's daemon record: `null` once the record is this
|
|
907
|
+
+ * process's, otherwise the record of the daemon that serves the workspace. A
|
|
908
|
+
+ * holder that is starting is waited for until it answers or its record ages
|
|
909
|
+
+ * past the startup grace, when it is replaced as stale.
|
|
910
|
+
+ */
|
|
911
|
+
+async function claimDaemonOrDefer(socketPath) {
|
|
912
|
+
+ while (true) {
|
|
913
|
+
+ const claim = await (0, cache_1.claimDaemonJsonProcessCache)({
|
|
914
|
+
+ processId: process.pid,
|
|
915
|
+
+ socketPath,
|
|
916
|
+
+ nxVersion: versions_1.nxVersion,
|
|
917
|
+
+ workspaceRoot: workspace_root_1.workspaceRoot,
|
|
918
|
+
+ });
|
|
919
|
+
+ switch (claim.kind) {
|
|
920
|
+
+ case 'claimed':
|
|
921
|
+
+ return null;
|
|
922
|
+
+ case 'serving':
|
|
923
|
+
+ return claim.owner;
|
|
924
|
+
+ case 'starting':
|
|
925
|
+
+ await new Promise((resolve) => setTimeout(resolve, 10));
|
|
926
|
+
+ }
|
|
927
|
+
+ }
|
|
928
|
+
+}
|
|
929
|
+
async function startServer() {
|
|
930
|
+
+ const socketPath = (0, socket_utils_1.getFullOsSocketPath)();
|
|
931
|
+
+ // Claim the workspace before doing anything: a daemon another client started
|
|
932
|
+
+ // for it serves this client too, and a second one used to displace it, cutting
|
|
933
|
+
+ // off every client mid-request.
|
|
934
|
+
+ const owner = await claimDaemonOrDefer(socketPath);
|
|
935
|
+
+ if (owner !== null) {
|
|
936
|
+
+ logger_1.serverLogger.log(`[Server] Daemon ${owner.processId} already serves this workspace on ${owner.socketPath}, so daemon ${process.pid} exits`);
|
|
937
|
+
+ process.exit(0);
|
|
938
|
+
+ }
|
|
939
|
+
+ (0, restart_checks_1.registerDaemonForRestartChecks)(server, exports.openSockets, socketPath);
|
|
940
|
+
+ // Record before watch/scan so a lockfile changed during boot is not lost.
|
|
941
|
+
+ (0, restart_checks_1.recordLockFileHash)();
|
|
942
|
+
// Watch before scan: a file written during boot must be visible to the
|
|
943
|
+
// watcher or the scan below. Scan-first left a blind window where such
|
|
944
|
+
// files stayed invisible to both until an unrelated change arrived.
|
|
945
|
+
@@ -359,54 +359,21 @@ async function startServer() {
|
|
946
|
+
(0, workspace_context_1.setupWorkspaceContext)(workspace_root_1.workspaceRoot);
|
|
947
|
+
// Initialize analytics for daemon process
|
|
948
|
+
await (0, analytics_1.startAnalytics)();
|
|
949
|
+
- const socketPath = (0, socket_utils_1.getFullOsSocketPath)();
|
|
950
|
+
// Log daemon startup information for debugging
|
|
951
|
+
logger_1.serverLogger.log(`New daemon starting from: ${__filename}`);
|
|
952
|
+
logger_1.serverLogger.log(`New daemon __dirname: ${__dirname}`);
|
|
953
|
+
logger_1.serverLogger.log(`New daemon nxVersion: ${versions_1.nxVersion}`);
|
|
954
|
+
logger_1.serverLogger.log(`New daemon getInstalledNxVersion(): ${(0, installed_nx_version_1.getInstalledNxVersion)()}`);
|
|
955
|
+
- // Persist metadata about the background process so that it can be cleaned up later if needed
|
|
956
|
+
- await (0, cache_1.writeDaemonJsonProcessCache)({
|
|
957
|
+
- processId: process.pid,
|
|
958
|
+
- socketPath,
|
|
959
|
+
- nxVersion: versions_1.nxVersion,
|
|
960
|
+
- });
|
|
961
|
+
// See notes in socket-command-line-utils.ts on OS differences regarding clean up of existings connections.
|
|
962
|
+
if (!socket_utils_1.isWindows) {
|
|
963
|
+
(0, socket_utils_1.killSocketOrPath)();
|
|
964
|
+
}
|
|
965
|
+
- logger_1.serverLogger.log(`[Server] Starting outdated check interval (20ms)`);
|
|
966
|
+
+ // Watch events and request boundaries do the normal validity checks.
|
|
967
|
+
+ // Retain a slow safety check for dropped events and unreachable sockets.
|
|
968
|
+
+ logger_1.serverLogger.log(`[Server] Starting validity safety interval (${restart_checks_1.DAEMON_VALIDITY_SAFETY_INTERVAL_MS}ms)`);
|
|
969
|
+
setInterval(() => {
|
|
970
|
+
- if ((0, cache_1.getDaemonProcessIdSync)() !== process.pid) {
|
|
971
|
+
- return (0, shutdown_utils_1.handleServerProcessTermination)({
|
|
972
|
+
- server,
|
|
973
|
+
- reason: 'this process is no longer the current daemon (native)',
|
|
974
|
+
- sockets: exports.openSockets,
|
|
975
|
+
- });
|
|
976
|
+
- }
|
|
977
|
+
- const outdated = daemonIsOutdated();
|
|
978
|
+
- if (outdated) {
|
|
979
|
+
- logger_1.serverLogger.log(`[Server] Daemon outdated: ${outdated}`);
|
|
980
|
+
- if (outdated === 'LOCK_FILES_CHANGED') {
|
|
981
|
+
- // Lock file changes - restart daemon, clients will reconnect
|
|
982
|
+
- logger_1.serverLogger.log('[Server] Restarting daemon...');
|
|
983
|
+
- (0, shutdown_utils_1.handleServerProcessTerminationWithRestart)({
|
|
984
|
+
- server,
|
|
985
|
+
- reason: outdated,
|
|
986
|
+
- sockets: exports.openSockets,
|
|
987
|
+
- });
|
|
988
|
+
- }
|
|
989
|
+
- else {
|
|
990
|
+
- // Version changes or other reasons - just shut down, don't restart
|
|
991
|
+
- logger_1.serverLogger.log('[Server] Shutting down daemon (no restart)...');
|
|
992
|
+
- (0, shutdown_utils_1.handleServerProcessTermination)({
|
|
993
|
+
- server,
|
|
994
|
+
- reason: outdated,
|
|
995
|
+
- sockets: exports.openSockets,
|
|
996
|
+
- });
|
|
997
|
+
- }
|
|
998
|
+
- }
|
|
999
|
+
- }, 20).unref();
|
|
1000
|
+
+ (0, restart_checks_1.stopDaemonIfOutdated)();
|
|
1001
|
+
+ }, restart_checks_1.DAEMON_VALIDITY_SAFETY_INTERVAL_MS).unref();
|
|
1002
|
+
return new Promise(async (resolve, reject) => {
|
|
1003
|
+
// `listen` reports a failed bind asynchronously on the server, which the
|
|
1004
|
+
// try below cannot catch — without this an EACCES became an uncaught
|
|
1005
|
+
@@ -432,8 +399,7 @@ async function startServer() {
|
|
1006
|
+
// Best effort; the 0700 socket directory is the primary control.
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
- // this triggers the storage of the lock file hash
|
|
1010
|
+
- daemonIsOutdated();
|
|
1011
|
+
+ (0, socket_utils_1.recordOwnSocket)(socketPath);
|
|
1012
|
+
if (!(0, shutdown_utils_1.getOutputWatcherInstance)()) {
|
|
1013
|
+
(0, shutdown_utils_1.storeOutputWatcherInstance)(await (0, watcher_1.watchOutputFiles)(server, handle_outputs_changes_1.handleOutputsChanges));
|
|
1014
|
+
}
|
|
1015
|
+
diff --git a/dist/src/daemon/server/shutdown-utils.d.ts b/dist/src/daemon/server/shutdown-utils.d.ts
|
|
1016
|
+
index 698fcf9e061b8e0b37057a6318614dbe6d290b9e..422d244931ceb3a7143fc06e23d113bc0c566092 100644
|
|
1017
|
+
--- a/dist/src/daemon/server/shutdown-utils.d.ts
|
|
1018
|
+
+++ b/dist/src/daemon/server/shutdown-utils.d.ts
|
|
1019
|
+
@@ -1,6 +1,6 @@
|
|
1020
|
+
import type { Server, Socket } from 'net';
|
|
1021
|
+
import type { Watcher } from '../../native';
|
|
1022
|
+
-export declare const SERVER_INACTIVITY_TIMEOUT_MS: 10800000;
|
|
1023
|
+
+export declare const SERVER_INACTIVITY_TIMEOUT_MS: 300000;
|
|
1024
|
+
export declare function storeWatcherInstance(instance: Watcher): void;
|
|
1025
|
+
export declare function getWatcherInstance(): Watcher;
|
|
1026
|
+
export declare function storeOutputWatcherInstance(instance: Watcher): void;
|
|
1027
|
+
diff --git a/dist/src/daemon/server/shutdown-utils.js b/dist/src/daemon/server/shutdown-utils.js
|
|
1028
|
+
index a449f2fb3c864bc9d3d710078418c8a05879aa84..7123ce257437d940409bc683b00ed500f6b10a55 100644
|
|
1029
|
+
--- a/dist/src/daemon/server/shutdown-utils.js
|
|
1030
|
+
+++ b/dist/src/daemon/server/shutdown-utils.js
|
|
1031
|
+
@@ -25,7 +25,7 @@ const path_1 = require("path");
|
|
1032
|
+
const node_fs_1 = require("node:fs");
|
|
1033
|
+
const promises_1 = require("fs/promises");
|
|
1034
|
+
const tmp_dir_1 = require("../tmp-dir");
|
|
1035
|
+
-exports.SERVER_INACTIVITY_TIMEOUT_MS = 10800000; // 10800000 ms = 3 hours
|
|
1036
|
+
+exports.SERVER_INACTIVITY_TIMEOUT_MS = 300000; // 300000 ms = 5 minutes
|
|
1037
|
+
async function startNewDaemonInBackground() {
|
|
1038
|
+
(0, node_fs_1.mkdirSync)(tmp_dir_1.DAEMON_DIR_FOR_CURRENT_WORKSPACE, { recursive: true });
|
|
1039
|
+
if (!(0, node_fs_1.existsSync)(tmp_dir_1.DAEMON_OUTPUT_LOG_FILE)) {
|
|
1040
|
+
@@ -85,15 +85,31 @@ async function handleServerProcessTerminationWithRestart({ server, reason, socke
|
|
1041
|
+
await startNewDaemonInBackground();
|
|
1042
|
+
await performShutdown(server, reason, sockets);
|
|
1043
|
+
}
|
|
1044
|
+
-async function performShutdown(server, reason, sockets) {
|
|
1045
|
+
+/** The shutdown under way: each later reason to stop joins it. */
|
|
1046
|
+
+let shutdown;
|
|
1047
|
+
+function performShutdown(server, reason, sockets) {
|
|
1048
|
+
+ shutdown ??= shutDown(server, reason, sockets);
|
|
1049
|
+
+ return shutdown;
|
|
1050
|
+
+}
|
|
1051
|
+
+async function shutDown(server, reason, sockets) {
|
|
1052
|
+
try {
|
|
1053
|
+
+ // Closing a listening Unix socket unlinks its path. Once another daemon
|
|
1054
|
+
+ // has bound that path, the path is that daemon's socket, and closing this
|
|
1055
|
+
+ // server would cut every client off from it. Such a server is left to end
|
|
1056
|
+
+ // with the process, which leaves the path alone.
|
|
1057
|
+
+ const closesServer = (0, socket_utils_1.ownSocketState)() !== 'lost';
|
|
1058
|
+
await new Promise((res) => {
|
|
1059
|
+
- server.close(() => {
|
|
1060
|
+
- res(null);
|
|
1061
|
+
- });
|
|
1062
|
+
+ if (closesServer) {
|
|
1063
|
+
+ server.close(() => {
|
|
1064
|
+
+ res(null);
|
|
1065
|
+
+ });
|
|
1066
|
+
+ }
|
|
1067
|
+
for (const socket of sockets) {
|
|
1068
|
+
socket.destroy();
|
|
1069
|
+
}
|
|
1070
|
+
+ if (!closesServer) {
|
|
1071
|
+
+ res(null);
|
|
1072
|
+
+ }
|
|
1073
|
+
});
|
|
1074
|
+
if (watcherInstance) {
|
|
1075
|
+
await watcherInstance.stop();
|
|
1076
|
+
diff --git a/dist/src/daemon/server/watcher.js b/dist/src/daemon/server/watcher.js
|
|
1077
|
+
index cbc34a1a9c7650ddd50ee7309a0b487f1837e88a..11d56729bcd092605dd9ed64728232022e942384 100644
|
|
1078
|
+
--- a/dist/src/daemon/server/watcher.js
|
|
1079
|
+
+++ b/dist/src/daemon/server/watcher.js
|
|
1080
|
+
@@ -6,20 +6,102 @@ exports.watchOutputFiles = watchOutputFiles;
|
|
1081
|
+
exports.convertChangeEventsToLogMessage = convertChangeEventsToLogMessage;
|
|
1082
|
+
const workspace_root_1 = require("../../utils/workspace-root");
|
|
1083
|
+
const path_1 = require("path");
|
|
1084
|
+
+const fs_1 = require("fs");
|
|
1085
|
+
const shutdown_utils_1 = require("./shutdown-utils");
|
|
1086
|
+
-const path_2 = require("../../utils/path");
|
|
1087
|
+
-const cache_1 = require("../cache");
|
|
1088
|
+
const server_1 = require("./server");
|
|
1089
|
+
const handle_import_1 = require("../../utils/handle-import");
|
|
1090
|
+
+const workspace_context_1 = require("../../utils/workspace-context");
|
|
1091
|
+
+const cache_directory_1 = require("../../utils/cache-directory");
|
|
1092
|
+
+const restart_checks_1 = require("./restart-checks");
|
|
1093
|
+
// Captured by watchWorkspace so flushPendingWorkspaceChanges can route
|
|
1094
|
+
// force-flushed events through the same handling as the async callback.
|
|
1095
|
+
// Definite-assignment: dispatchWorkspaceChanges only runs after
|
|
1096
|
+
-// watchWorkspace has set both, so reading them as non-nullable is safe.
|
|
1097
|
+
+// watchWorkspace has set all four, so reading them as non-nullable is safe.
|
|
1098
|
+
let activeServer;
|
|
1099
|
+
let workspaceChangesCallback;
|
|
1100
|
+
-function dispatchWorkspaceChanges(events) {
|
|
1101
|
+
+let hashFile;
|
|
1102
|
+
+// The filesystem's own time, in nanoseconds, just before the watcher read
|
|
1103
|
+
+// the ignore files its filter is built from.
|
|
1104
|
+
+let filterReadFrom;
|
|
1105
|
+
+function isIgnoreFile(path) {
|
|
1106
|
+
+ return path.endsWith('.gitignore') || path === '.nxignore';
|
|
1107
|
+
+}
|
|
1108
|
+
+/** The later of a path's ctime and mtime, in the filesystem's nanoseconds. */
|
|
1109
|
+
+function changedAt(path) {
|
|
1110
|
+
+ const stat = (0, fs_1.statSync)(path, { bigint: true });
|
|
1111
|
+
+ return stat.ctimeNs > stat.mtimeNs ? stat.ctimeNs : stat.mtimeNs;
|
|
1112
|
+
+}
|
|
1113
|
+
+/**
|
|
1114
|
+
+ * The filesystem's clock now: the change time of a probe it stamps. File
|
|
1115
|
+
+ * timestamps can lag the system clock by a tick (Linux stamps from a coarse
|
|
1116
|
+
+ * clock) or be truncated to a coarse resolution, so a write made after this
|
|
1117
|
+
+ * point is stamped at or after it only when both come from the same clock.
|
|
1118
|
+
+ */
|
|
1119
|
+
+function filesystemNow() {
|
|
1120
|
+
+ (0, fs_1.mkdirSync)(cache_directory_1.workspaceDataDirectory, { recursive: true });
|
|
1121
|
+
+ const probe = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `.watch-start-${process.pid}`);
|
|
1122
|
+
+ (0, fs_1.writeFileSync)(probe, '');
|
|
1123
|
+
+ try {
|
|
1124
|
+
+ return changedAt(probe);
|
|
1125
|
+
+ }
|
|
1126
|
+
+ finally {
|
|
1127
|
+
+ (0, fs_1.unlinkSync)(probe);
|
|
1128
|
+
+ }
|
|
1129
|
+
+}
|
|
1130
|
+
+/** Whether `path` is unchanged since the filter's read; a path that is gone is not. */
|
|
1131
|
+
+function unchangedSinceFilterRead(path) {
|
|
1132
|
+
+ try {
|
|
1133
|
+
+ return changedAt(path) < filterReadFrom;
|
|
1134
|
+
+ }
|
|
1135
|
+
+ catch (error) {
|
|
1136
|
+
+ if (error.code === 'ENOENT')
|
|
1137
|
+
+ return false;
|
|
1138
|
+
+ throw error;
|
|
1139
|
+
+ }
|
|
1140
|
+
+}
|
|
1141
|
+
+// The ignore files whose bytes the watcher's filter is known to hold: each
|
|
1142
|
+
+// one's content hash, by workspace-relative path. The watcher reads its
|
|
1143
|
+
+// ignore rules once, in watch(), before its event stream starts, and never
|
|
1144
|
+
+// again, so only a change to those bytes makes its rules stale. A watcher
|
|
1145
|
+
+// event alone does not: a rewrite with the same bytes (a checkout, a
|
|
1146
|
+
+// formatter) reports one, and FSEvents reports writes made shortly before
|
|
1147
|
+
+// the stream started, when fseventsd numbered them after its start.
|
|
1148
|
+
+//
|
|
1149
|
+
+// The hashes come from the workspace context, which startServer sets up
|
|
1150
|
+
+// after watch() returned, so the context read each file after the filter
|
|
1151
|
+
+// did. They are the same bytes only if neither the file nor the directory
|
|
1152
|
+
+// entry naming it changed since just before the filter's read: then no
|
|
1153
|
+
+// write, replacement, rename or deletion fell between the two reads. A file
|
|
1154
|
+
+// changed in that gap is left out, as is one the context never held, and
|
|
1155
|
+
+// any event for an ignore file left out stops the daemon, as Nx always did.
|
|
1156
|
+
+// Taken once, in the turn after watchWorkspace returns; a dispatch that
|
|
1157
|
+
+// comes first takes it then.
|
|
1158
|
+
+let ignoreFilesAtStart;
|
|
1159
|
+
+function ignoreFiles() {
|
|
1160
|
+
+ ignoreFilesAtStart ??= (0, workspace_context_1.getAllFileDataInContext)(workspace_root_1.workspaceRoot).then((files) => {
|
|
1161
|
+
+ const read = new Map();
|
|
1162
|
+
+ for (const { file, hash } of files) {
|
|
1163
|
+
+ const path = (0, path_1.join)(workspace_root_1.workspaceRoot, file);
|
|
1164
|
+
+ if (isIgnoreFile(file) &&
|
|
1165
|
+
+ unchangedSinceFilterRead(path) &&
|
|
1166
|
+
+ unchangedSinceFilterRead((0, path_1.dirname)(path))) {
|
|
1167
|
+
+ read.set(file, hash);
|
|
1168
|
+
+ }
|
|
1169
|
+
+ }
|
|
1170
|
+
+ return read;
|
|
1171
|
+
+ });
|
|
1172
|
+
+ return ignoreFilesAtStart;
|
|
1173
|
+
+}
|
|
1174
|
+
+// Every dispatch awaits the snapshot, so batches still reach the callback in
|
|
1175
|
+
+// the order the watcher delivered them.
|
|
1176
|
+
+async function dispatchWorkspaceChanges(events) {
|
|
1177
|
+
+ const filterRead = await ignoreFiles();
|
|
1178
|
+
for (const event of events) {
|
|
1179
|
+
- if (event.path.endsWith('.gitignore') || event.path === '.nxignore') {
|
|
1180
|
+
+ // hashFile answers null for a file that is gone, which no read hash is.
|
|
1181
|
+
+ if (isIgnoreFile(event.path) &&
|
|
1182
|
+
+ (!filterRead.has(event.path) ||
|
|
1183
|
+
+ hashFile((0, path_1.join)(workspace_root_1.workspaceRoot, event.path)) !==
|
|
1184
|
+
+ filterRead.get(event.path))) {
|
|
1185
|
+
// If the ignore files themselves have changed we need to dynamically
|
|
1186
|
+
// update our cached ignoreGlobs
|
|
1187
|
+
(0, shutdown_utils_1.handleServerProcessTermination)({
|
|
1188
|
+
@@ -32,16 +114,20 @@ function dispatchWorkspaceChanges(events) {
|
|
1189
|
+
return workspaceChangesCallback(null, events);
|
|
1190
|
+
}
|
|
1191
|
+
async function watchWorkspace(server, cb) {
|
|
1192
|
+
- const { Watcher } = await (0, handle_import_1.handleImport)('../../native/index.js', __dirname);
|
|
1193
|
+
+ const native = await (0, handle_import_1.handleImport)('../../native/index.js', __dirname);
|
|
1194
|
+
+ const { Watcher } = native;
|
|
1195
|
+
activeServer = server;
|
|
1196
|
+
workspaceChangesCallback = cb;
|
|
1197
|
+
+ hashFile = native.hashFile;
|
|
1198
|
+
+ filterReadFrom = filesystemNow();
|
|
1199
|
+
const watcher = new Watcher(workspace_root_1.workspaceRoot);
|
|
1200
|
+
watcher.watch((err, events) => {
|
|
1201
|
+
if (err) {
|
|
1202
|
+
return cb(err, null);
|
|
1203
|
+
}
|
|
1204
|
+
- dispatchWorkspaceChanges(events);
|
|
1205
|
+
+ dispatchWorkspaceChanges(events).catch((error) => cb(error, null));
|
|
1206
|
+
});
|
|
1207
|
+
+ setImmediate(() => ignoreFiles().catch((error) => cb(error, null)));
|
|
1208
|
+
return watcher;
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
@@ -61,21 +147,13 @@ async function flushPendingWorkspaceChanges() {
|
|
1212
|
+
}
|
|
1213
|
+
async function watchOutputFiles(server, cb) {
|
|
1214
|
+
const { Watcher } = await (0, handle_import_1.handleImport)('../../native/index.js', __dirname);
|
|
1215
|
+
- const relativeServerProcess = (0, path_2.normalizePath)((0, path_1.relative)(workspace_root_1.workspaceRoot, cache_1.serverProcessJsonPath));
|
|
1216
|
+
- const watcher = new Watcher(workspace_root_1.workspaceRoot, [`!${relativeServerProcess}`], false);
|
|
1217
|
+
+ const watcher = new Watcher(workspace_root_1.workspaceRoot, [`!${restart_checks_1.relativeServerProcess}`], false);
|
|
1218
|
+
watcher.watch((err, events) => {
|
|
1219
|
+
if (err) {
|
|
1220
|
+
return cb(err, null);
|
|
1221
|
+
}
|
|
1222
|
+
- for (const event of events) {
|
|
1223
|
+
- if (event.path == relativeServerProcess &&
|
|
1224
|
+
- (0, cache_1.getDaemonProcessIdSync)() !== process.pid) {
|
|
1225
|
+
- return (0, shutdown_utils_1.handleServerProcessTermination)({
|
|
1226
|
+
- server,
|
|
1227
|
+
- reason: 'this process is no longer the current daemon (native)',
|
|
1228
|
+
- sockets: server_1.openSockets,
|
|
1229
|
+
- });
|
|
1230
|
+
- }
|
|
1231
|
+
+ if ((0, restart_checks_1.stopDaemonIfReplaced)(events)) {
|
|
1232
|
+
+ return;
|
|
1233
|
+
}
|
|
1234
|
+
if (events.length !== 0) {
|
|
1235
|
+
cb(null, events);
|
|
1236
|
+
diff --git a/dist/src/daemon/socket-utils.d.ts b/dist/src/daemon/socket-utils.d.ts
|
|
1237
|
+
index 52b621b433beccb8e6590316cfd5baa7c7ec3b80..1c13e49fb4e8e37520ecd6e7a1c00ce251d201e4 100644
|
|
1238
|
+
--- a/dist/src/daemon/socket-utils.d.ts
|
|
1239
|
+
+++ b/dist/src/daemon/socket-utils.d.ts
|
|
1240
|
+
@@ -11,6 +11,21 @@ export declare const getForkedProcessOsSocketPath: (id: string) => string;
|
|
1241
|
+
export declare const getPluginOsSocketPath: (id: string) => string;
|
|
1242
|
+
export declare function getPluginSocketFileName(id: string): string;
|
|
1243
|
+
export declare function killSocketOrPath(): void;
|
|
1244
|
+
+/**
|
|
1245
|
+
+ * Notes which socket file this daemon's server bound at `socketPath`, so that it
|
|
1246
|
+
+ * can tell its own socket from one a later daemon bound at the same path. The
|
|
1247
|
+
+ * path is kept rather than derived again: the daemon takes on each client's
|
|
1248
|
+
+ * environment, `NX_SOCKET_DIR` included, so deriving it later can name another
|
|
1249
|
+
+ * directory.
|
|
1250
|
+
+ */
|
|
1251
|
+
+export declare function recordOwnSocket(socketPath: string): void;
|
|
1252
|
+
+/**
|
|
1253
|
+
+ * Whether the path this daemon bound still names its listening socket: `unbound`
|
|
1254
|
+
+ * before it listens, `ours` while it does, and `lost` once the path is gone or
|
|
1255
|
+
+ * names another daemon's socket. A daemon whose socket is lost is one no client
|
|
1256
|
+
+ * can reach, and closing it would unlink the path, whatever it now names.
|
|
1257
|
+
+ */
|
|
1258
|
+
+export declare function ownSocketState(): 'unbound' | 'ours' | 'lost';
|
|
1259
|
+
export declare function serializeResult(error: Error | null, serializedProjectGraph: string | null, serializedSourceMaps: string | null): string | null;
|
|
1260
|
+
/**
|
|
1261
|
+
* Serialize using `preferred`, falling back to the other format when it throws.
|
|
1262
|
+
diff --git a/dist/src/daemon/socket-utils.js b/dist/src/daemon/socket-utils.js
|
|
1263
|
+
index 66371610921778e1ee3c44055ca6438cc01dc7a9..92b1f00e948ac522fad5a6e6e3e87f41e2c098dc 100644
|
|
1264
|
+
--- a/dist/src/daemon/socket-utils.js
|
|
1265
|
+
+++ b/dist/src/daemon/socket-utils.js
|
|
1266
|
+
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
1267
|
+
exports.getPluginOsSocketPath = exports.getForkedProcessOsSocketPath = exports.getFullOsSocketPath = exports.isWindows = void 0;
|
|
1268
|
+
exports.getPluginSocketFileName = getPluginSocketFileName;
|
|
1269
|
+
exports.killSocketOrPath = killSocketOrPath;
|
|
1270
|
+
+exports.recordOwnSocket = recordOwnSocket;
|
|
1271
|
+
+exports.ownSocketState = ownSocketState;
|
|
1272
|
+
exports.serializeResult = serializeResult;
|
|
1273
|
+
exports.serializeWithFallback = serializeWithFallback;
|
|
1274
|
+
exports.serialize = serialize;
|
|
1275
|
+
@@ -75,6 +77,46 @@ function killSocketOrPath() {
|
|
1276
|
+
}
|
|
1277
|
+
catch { }
|
|
1278
|
+
}
|
|
1279
|
+
+/**
|
|
1280
|
+
+ * The socket this daemon listens on, once it listens: the path it bound and that
|
|
1281
|
+
+ * socket's inode, or `true` for a named pipe, which is not a file another daemon
|
|
1282
|
+
+ * can replace.
|
|
1283
|
+
+ */
|
|
1284
|
+
+let ownSocket;
|
|
1285
|
+
+/**
|
|
1286
|
+
+ * Notes which socket file this daemon's server bound at `socketPath`, so that it
|
|
1287
|
+
+ * can tell its own socket from one a later daemon bound at the same path. The
|
|
1288
|
+
+ * path is kept rather than derived again: the daemon takes on each client's
|
|
1289
|
+
+ * environment, `NX_SOCKET_DIR` included, so deriving it later can name another
|
|
1290
|
+
+ * directory.
|
|
1291
|
+
+ */
|
|
1292
|
+
+function recordOwnSocket(socketPath) {
|
|
1293
|
+
+ ownSocket = exports.isWindows
|
|
1294
|
+
+ ? true
|
|
1295
|
+
+ : { path: socketPath, ino: (0, fs_1.statSync)(socketPath).ino };
|
|
1296
|
+
+}
|
|
1297
|
+
+/**
|
|
1298
|
+
+ * Whether the path this daemon bound still names its listening socket: `unbound`
|
|
1299
|
+
+ * before it listens, `ours` while it does, and `lost` once the path is gone or
|
|
1300
|
+
+ * names another daemon's socket. A daemon whose socket is lost is one no client
|
|
1301
|
+
+ * can reach, and closing it would unlink the path, whatever it now names.
|
|
1302
|
+
+ */
|
|
1303
|
+
+function ownSocketState() {
|
|
1304
|
+
+ if (ownSocket === undefined) {
|
|
1305
|
+
+ return 'unbound';
|
|
1306
|
+
+ }
|
|
1307
|
+
+ if (ownSocket === true) {
|
|
1308
|
+
+ return 'ours';
|
|
1309
|
+
+ }
|
|
1310
|
+
+ try {
|
|
1311
|
+
+ return (0, fs_1.statSync)(ownSocket.path).ino === ownSocket.ino ? 'ours' : 'lost';
|
|
1312
|
+
+ }
|
|
1313
|
+
+ catch (e) {
|
|
1314
|
+
+ if (e.code === 'ENOENT')
|
|
1315
|
+
+ return 'lost';
|
|
1316
|
+
+ throw e;
|
|
1317
|
+
+ }
|
|
1318
|
+
+}
|
|
1319
|
+
// Prepare a serialized project graph result for sending over IPC from the server to the client
|
|
1320
|
+
function serializeResult(error, serializedProjectGraph, serializedSourceMaps) {
|
|
1321
|
+
// We do not want to repeat work `JSON.stringify`ing an object containing the potentially large project graph so merge as strings
|
|
1322
|
+
diff --git a/dist/src/hasher/check-task-files.js b/dist/src/hasher/check-task-files.js
|
|
1323
|
+
index d21213e8de9eba5e1edcde9e7db474ec7266272b..584785648eefa62878cc914a2d91bace5478fccf 100644
|
|
1324
|
+
--- a/dist/src/hasher/check-task-files.js
|
|
1325
|
+
+++ b/dist/src/hasher/check-task-files.js
|
|
1326
|
+
@@ -96,11 +96,13 @@ async function getRawInputs(taskId, { projectGraph, getInspector }) {
|
|
1327
|
+
const inspector = await getInspector();
|
|
1328
|
+
// `null` means "this task is absent from the hash plan" — any other failure
|
|
1329
|
+
// is a real error and propagates to the caller.
|
|
1330
|
+
+ // The raw API returns only this task. Keep its producer graph for planning,
|
|
1331
|
+
+ // but do not resolve dependency plans whose results would be discarded.
|
|
1332
|
+
const planResult = inspector.inspectTaskInputs({
|
|
1333
|
+
project,
|
|
1334
|
+
target,
|
|
1335
|
+
configuration,
|
|
1336
|
+
- });
|
|
1337
|
+
+ }, {}, {}, false, [canonicalTaskId]);
|
|
1338
|
+
const result = planResult[canonicalTaskId] ?? null;
|
|
1339
|
+
hashInputsCache.set(taskId, result);
|
|
1340
|
+
return result;
|
|
1341
|
+
diff --git a/dist/src/hasher/hash-plan-inspector.d.ts b/dist/src/hasher/hash-plan-inspector.d.ts
|
|
1342
|
+
index edb5a7bf425cfd04ad243b0d30a21f1cf6061140..316ca4b91dbf788c9f41d5a2acfbb077590d5db2 100644
|
|
1343
|
+
--- a/dist/src/hasher/hash-plan-inspector.d.ts
|
|
1344
|
+
+++ b/dist/src/hasher/hash-plan-inspector.d.ts
|
|
1345
|
+
@@ -26,8 +26,9 @@ export declare class HashPlanInspector {
|
|
1346
|
+
/**
|
|
1347
|
+
* Like inspectTask() but returns structured HashInputs objects instead of flat strings.
|
|
1348
|
+
* Each input is categorized into files, runtime, environment, depOutputs, or external.
|
|
1349
|
+
+ * A selected task list limits resolution, not the dependency graph used to plan its inputs.
|
|
1350
|
+
*/
|
|
1351
|
+
inspectTaskInputs({ project, target, configuration }: Target, parsedArgs?: {
|
|
1352
|
+
[k: string]: any;
|
|
1353
|
+
- }, extraTargetDependencies?: Record<string, (TargetDependencyConfig | string)[]>, excludeTaskDependencies?: boolean): Record<string, HashInputs>;
|
|
1354
|
+
+ }, extraTargetDependencies?: Record<string, (TargetDependencyConfig | string)[]>, excludeTaskDependencies?: boolean, taskIdsToInspect?: string[]): Record<string, HashInputs>;
|
|
1355
|
+
}
|
|
1356
|
+
diff --git a/dist/src/hasher/hash-plan-inspector.js b/dist/src/hasher/hash-plan-inspector.js
|
|
1357
|
+
index 332accab74919348073538f4198693328bf68193..a56864600a5e7a9f9e40adea9a7bfc9e5803029d 100644
|
|
1358
|
+
--- a/dist/src/hasher/hash-plan-inspector.js
|
|
1359
|
+
+++ b/dist/src/hasher/hash-plan-inspector.js
|
|
1360
|
+
@@ -54,15 +54,16 @@ class HashPlanInspector {
|
|
1361
|
+
/**
|
|
1362
|
+
* Like inspectTask() but returns structured HashInputs objects instead of flat strings.
|
|
1363
|
+
* Each input is categorized into files, runtime, environment, depOutputs, or external.
|
|
1364
|
+
+ * A selected task list limits resolution, not the dependency graph used to plan its inputs.
|
|
1365
|
+
*/
|
|
1366
|
+
- inspectTaskInputs({ project, target, configuration }, parsedArgs = {}, extraTargetDependencies = {}, excludeTaskDependencies = false) {
|
|
1367
|
+
+ inspectTaskInputs({ project, target, configuration }, parsedArgs = {}, extraTargetDependencies = {}, excludeTaskDependencies = false, taskIdsToInspect) {
|
|
1368
|
+
const { nxArgs, overrides } = (0, command_line_utils_1.splitArgsIntoNxArgsAndOverrides)({
|
|
1369
|
+
...parsedArgs,
|
|
1370
|
+
configuration: configuration,
|
|
1371
|
+
targets: [target],
|
|
1372
|
+
}, 'run-one', { printWarnings: false }, this.nxJson);
|
|
1373
|
+
const taskGraph = (0, create_task_graph_1.createTaskGraph)(this.projectGraph, extraTargetDependencies, [project], nxArgs.targets, nxArgs.configuration, overrides, excludeTaskDependencies);
|
|
1374
|
+
- const taskIds = Object.keys(taskGraph.tasks);
|
|
1375
|
+
+ const taskIds = taskIdsToInspect ?? Object.keys(taskGraph.tasks);
|
|
1376
|
+
const plansReference = this.planner.getPlansReference(taskIds, taskGraph);
|
|
1377
|
+
return this.inspector.inspectInputs(plansReference);
|
|
1378
|
+
}
|
|
1379
|
+
diff --git a/dist/src/plugins/js/lock-file/bun-parser.js b/dist/src/plugins/js/lock-file/bun-parser.js
|
|
1380
|
+
index 169563d598af64c8b74d00ab9815dd651650ec9d..0bd5e1f536b1e0e02843396e01b29dcece8293b0 100644
|
|
1381
|
+
--- a/dist/src/plugins/js/lock-file/bun-parser.js
|
|
1382
|
+
+++ b/dist/src/plugins/js/lock-file/bun-parser.js
|
|
1383
|
+
@@ -7,6 +7,7 @@ exports.clearCache = clearCache;
|
|
1384
|
+
exports.getBunTextLockfileNodes = getBunTextLockfileNodes;
|
|
1385
|
+
const node_child_process_1 = require("node:child_process");
|
|
1386
|
+
const node_fs_1 = require("node:fs");
|
|
1387
|
+
+const node_path_1 = require("node:path");
|
|
1388
|
+
const semver_1 = require("semver");
|
|
1389
|
+
const project_graph_1 = require("../../../config/project-graph");
|
|
1390
|
+
const file_hasher_1 = require("../../../hasher/file-hasher");
|
|
1391
|
+
@@ -285,8 +286,7 @@ function buildPackageIndex(lockFile) {
|
|
1392
|
+
...workspace.peerDependencies,
|
|
1393
|
+
};
|
|
1394
|
+
for (const [depName, depVersion] of Object.entries(allDeps)) {
|
|
1395
|
+
- if (depVersion.startsWith('workspace:') ||
|
|
1396
|
+
- depVersion.startsWith('file:')) {
|
|
1397
|
+
+ if (depVersion.startsWith('workspace:')) {
|
|
1398
|
+
workspaceNames.add(depName);
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
@@ -306,8 +306,9 @@ function buildPackageIndex(lockFile) {
|
|
1402
|
+
if (!name || !version) {
|
|
1403
|
+
continue;
|
|
1404
|
+
}
|
|
1405
|
+
- // Track workspace packages from packages section
|
|
1406
|
+
- if (protocol === 'workspace' || protocol === 'file') {
|
|
1407
|
+
+ // File packages belong to a workspace only when their resolved target is an actual workspace path.
|
|
1408
|
+
+ if (protocol === 'workspace' ||
|
|
1409
|
+
+ (protocol === 'file' && workspacePaths.has(node_path_1.posix.normalize(version.slice('file:'.length))))) {
|
|
1410
|
+
workspaceNames.add(name);
|
|
1411
|
+
}
|
|
1412
|
+
// Check if this is a workspace-specific variant (e.g., "@quz/pkg1/lodash")
|
|
1413
|
+
diff --git a/dist/src/plugins/js/project-graph/build-dependencies/build-dependencies.js b/dist/src/plugins/js/project-graph/build-dependencies/build-dependencies.js
|
|
1414
|
+
index 81a6ebea371390c69fc2c3ab3da95d7dbec13a37..5746704ac8457eddfcedfbcd171504f3e36082e1 100644
|
|
1415
|
+
--- a/dist/src/plugins/js/project-graph/build-dependencies/build-dependencies.js
|
|
1416
|
+
+++ b/dist/src/plugins/js/project-graph/build-dependencies/build-dependencies.js
|
|
1417
|
+
@@ -2,6 +2,7 @@
|
|
1418
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1419
|
+
exports.buildExplicitDependencies = buildExplicitDependencies;
|
|
1420
|
+
const explicit_package_json_dependencies_1 = require("./explicit-package-json-dependencies");
|
|
1421
|
+
+const installation_directory_1 = require("../../../../utils/installation-directory");
|
|
1422
|
+
const explicit_project_dependencies_1 = require("./explicit-project-dependencies");
|
|
1423
|
+
const target_project_locator_1 = require("./target-project-locator");
|
|
1424
|
+
function buildExplicitDependencies(jsPluginConfig, ctx) {
|
|
1425
|
+
@@ -24,7 +25,7 @@ function buildExplicitDependencies(jsPluginConfig, ctx) {
|
|
1426
|
+
jsPluginConfig.analyzeSourceFiles === true) {
|
|
1427
|
+
let tsExists = false;
|
|
1428
|
+
try {
|
|
1429
|
+
- require.resolve('typescript');
|
|
1430
|
+
+ (0, installation_directory_1.resolveFromWorkspace)('typescript');
|
|
1431
|
+
tsExists = true;
|
|
1432
|
+
}
|
|
1433
|
+
catch { }
|
|
1434
|
+
diff --git a/dist/src/plugins/js/utils/register.js b/dist/src/plugins/js/utils/register.js
|
|
1435
|
+
index 151dfb805f179c65391587b379033fd53257d909..ae75a76b87d7974a5e1866e5ecbbf758e26533ca 100644
|
|
1436
|
+
--- a/dist/src/plugins/js/utils/register.js
|
|
1437
|
+
+++ b/dist/src/plugins/js/utils/register.js
|
|
1438
|
+
@@ -25,6 +25,7 @@ exports.getTsNodeCompilerOptions = getTsNodeCompilerOptions;
|
|
1439
|
+
const path_1 = require("path");
|
|
1440
|
+
const fs_1 = require("fs");
|
|
1441
|
+
const logger_1 = require("../../../utils/logger");
|
|
1442
|
+
+const installation_directory_1 = require("../../../utils/installation-directory");
|
|
1443
|
+
const workspace_root_1 = require("../../../utils/workspace-root");
|
|
1444
|
+
const typescript_1 = require("./typescript");
|
|
1445
|
+
const swcNodeInstalled = packageIsInstalled('@swc-node/register');
|
|
1446
|
+
@@ -663,7 +664,7 @@ const registered = new Map();
|
|
1447
|
+
function getTranspiler(compilerOptions, tsConfigRaw) {
|
|
1448
|
+
const preferTsNode = process.env.NX_PREFER_TS_NODE === 'true';
|
|
1449
|
+
if (!ts) {
|
|
1450
|
+
- ts = require('typescript');
|
|
1451
|
+
+ ts = require((0, installation_directory_1.resolveFromWorkspace)('typescript'));
|
|
1452
|
+
}
|
|
1453
|
+
compilerOptions.lib = ['es2021'];
|
|
1454
|
+
compilerOptions.module = ts.ModuleKind.CommonJS;
|
|
1455
|
+
@@ -1167,7 +1168,7 @@ function packageIsInstalled(m) {
|
|
1456
|
+
*/
|
|
1457
|
+
function getTsNodeCompilerOptions(compilerOptions) {
|
|
1458
|
+
if (!ts) {
|
|
1459
|
+
- ts = require('typescript');
|
|
1460
|
+
+ ts = require((0, installation_directory_1.resolveFromWorkspace)('typescript'));
|
|
1461
|
+
}
|
|
1462
|
+
const flagMap = {
|
|
1463
|
+
module: 'ModuleKind',
|
|
1464
|
+
diff --git a/dist/src/plugins/js/utils/typescript.js b/dist/src/plugins/js/utils/typescript.js
|
|
1465
|
+
index f756066cc6009478b6e16136d8ba4b5a5614c63c..7b0f3b4b5b270650f2ac0a1c28259e84f1c04811 100644
|
|
1466
|
+
--- a/dist/src/plugins/js/utils/typescript.js
|
|
1467
|
+
+++ b/dist/src/plugins/js/utils/typescript.js
|
|
1468
|
+
@@ -10,6 +10,7 @@ exports.getRootTsConfigCustomConditions = getRootTsConfigCustomConditions;
|
|
1469
|
+
exports.getRootTsConfigResolveExportsConditions = getRootTsConfigResolveExportsConditions;
|
|
1470
|
+
exports.getPluginResolveConditionNodeArgs = getPluginResolveConditionNodeArgs;
|
|
1471
|
+
exports.findNodes = findNodes;
|
|
1472
|
+
+const installation_directory_1 = require("../../../utils/installation-directory");
|
|
1473
|
+
const workspace_root_1 = require("../../../utils/workspace-root");
|
|
1474
|
+
const fs_1 = require("fs");
|
|
1475
|
+
const path_1 = require("path");
|
|
1476
|
+
@@ -17,7 +18,7 @@ const normalizedAppRoot = workspace_root_1.workspaceRoot.replace(/\\/g, '/');
|
|
1477
|
+
let tsModule;
|
|
1478
|
+
function readTsConfig(tsConfigPath, sys) {
|
|
1479
|
+
if (!tsModule) {
|
|
1480
|
+
- tsModule = require('typescript');
|
|
1481
|
+
+ tsModule = require((0, installation_directory_1.resolveFromWorkspace)('typescript'));
|
|
1482
|
+
}
|
|
1483
|
+
sys ??= tsModule.sys;
|
|
1484
|
+
const readResult = tsModule.readConfigFile(tsConfigPath, sys.readFile);
|
|
1485
|
+
@@ -25,7 +26,7 @@ function readTsConfig(tsConfigPath, sys) {
|
|
1486
|
+
}
|
|
1487
|
+
function readTsConfigWithoutFiles(tsConfigPath) {
|
|
1488
|
+
if (!tsModule) {
|
|
1489
|
+
- tsModule = require('typescript');
|
|
1490
|
+
+ tsModule = require((0, installation_directory_1.resolveFromWorkspace)('typescript'));
|
|
1491
|
+
}
|
|
1492
|
+
// We only care about options, so we don't need to scan source files, and thus
|
|
1493
|
+
// `readDirectory` is stubbed for performance.
|
|
1494
|
+
diff --git a/dist/src/project-graph/build-project-graph.js b/dist/src/project-graph/build-project-graph.js
|
|
1495
|
+
index 28c9655c4612dcc85a881816f172dce98642bb0c..ea65f019024da507dd81f4ace12020914a6f97a1 100644
|
|
1496
|
+
--- a/dist/src/project-graph/build-project-graph.js
|
|
1497
|
+
+++ b/dist/src/project-graph/build-project-graph.js
|
|
1498
|
+
@@ -93,7 +93,7 @@ async function buildProjectGraphUsingProjectFileMap(projectRootMap, externalNode
|
|
1499
|
+
try {
|
|
1500
|
+
const context = createContext(projects, nxJson, externalNodes, fileMap, filesToProcess);
|
|
1501
|
+
projectGraph = await buildProjectGraphUsingContext(externalNodes, context, cachedFileData, projectGraphVersion, plugins, sourceMap);
|
|
1502
|
+
- projectFileMapCache = (0, nx_deps_cache_1.createProjectFileMapCache)(nxJson, packageJsonDeps, fileMap, rootTsConfig, externalNodesHash);
|
|
1503
|
+
+ projectFileMapCache = (0, nx_deps_cache_1.createProjectFileMapCache)(nxJson, packageJsonDeps, fileMap, rootTsConfig, externalNodesHash, projects);
|
|
1504
|
+
}
|
|
1505
|
+
catch (e) {
|
|
1506
|
+
// we need to include the workspace validity errors in the final error
|
|
1507
|
+
diff --git a/dist/src/project-graph/nx-deps-cache.d.ts b/dist/src/project-graph/nx-deps-cache.d.ts
|
|
1508
|
+
index 5bc1e76b319294101cc9b038dc6eb0ad01036b13..baf7908aeb206f1c4e26ed0c8578465d8b510776 100644
|
|
1509
|
+
--- a/dist/src/project-graph/nx-deps-cache.d.ts
|
|
1510
|
+
+++ b/dist/src/project-graph/nx-deps-cache.d.ts
|
|
1511
|
+
@@ -11,6 +11,8 @@ export interface FileMapCache {
|
|
1512
|
+
pluginsConfig?: any;
|
|
1513
|
+
fileMap: FileMap;
|
|
1514
|
+
externalNodesHash?: string;
|
|
1515
|
+
+ /** Missing only in caches written before package-resolution invalidation. */
|
|
1516
|
+
+ projectResolution?: string;
|
|
1517
|
+
}
|
|
1518
|
+
export declare const nxProjectGraph: string;
|
|
1519
|
+
export declare const nxFileMap: string;
|
|
1520
|
+
@@ -25,7 +27,7 @@ export declare function createProjectFileMapCache(nxJson: NxJsonConfiguration<'*
|
|
1521
|
+
[p: string]: any;
|
|
1522
|
+
};
|
|
1523
|
+
};
|
|
1524
|
+
-}, externalNodesHash: string): FileMapCache;
|
|
1525
|
+
+}, externalNodesHash: string, projects: Record<string, ProjectConfiguration>): FileMapCache;
|
|
1526
|
+
export declare function writeCache(cache: FileMapCache, projectGraph: ProjectGraph, sourceMaps: ConfigurationSourceMaps, errors: ProjectGraphErrorTypes[]): void;
|
|
1527
|
+
/**
|
|
1528
|
+
* Writes the cache only if the on-disk cache file has been modified since
|
|
1529
|
+
diff --git a/dist/src/project-graph/nx-deps-cache.js b/dist/src/project-graph/nx-deps-cache.js
|
|
1530
|
+
index a880a6620cd7ac46e4bd189bc2034ce58825769a..ef3c99a115e7114ea78da379316a0478e45fbeea 100644
|
|
1531
|
+
--- a/dist/src/project-graph/nx-deps-cache.js
|
|
1532
|
+
+++ b/dist/src/project-graph/nx-deps-cache.js
|
|
1533
|
+
@@ -120,7 +120,7 @@ function readSourceMapsCache() {
|
|
1534
|
+
perf_hooks_1.performance.measure('read cache', 'read source-maps:start', 'read source-maps:end');
|
|
1535
|
+
return data ?? null;
|
|
1536
|
+
}
|
|
1537
|
+
-function createProjectFileMapCache(nxJson, packageJsonDeps, fileMap, tsConfig, externalNodesHash) {
|
|
1538
|
+
+function createProjectFileMapCache(nxJson, packageJsonDeps, fileMap, tsConfig, externalNodesHash, projects) {
|
|
1539
|
+
const nxJsonPlugins = getNxJsonPluginsData(nxJson, packageJsonDeps);
|
|
1540
|
+
const newValue = {
|
|
1541
|
+
version: '6.0',
|
|
1542
|
+
@@ -131,9 +131,29 @@ function createProjectFileMapCache(nxJson, packageJsonDeps, fileMap, tsConfig, e
|
|
1543
|
+
pluginsConfig: nxJson?.pluginsConfig,
|
|
1544
|
+
fileMap,
|
|
1545
|
+
externalNodesHash,
|
|
1546
|
+
+ projectResolution: projectResolutionIdentity(projects),
|
|
1547
|
+
};
|
|
1548
|
+
return newValue;
|
|
1549
|
+
}
|
|
1550
|
+
+// Dependency resolution reads project roots and package metadata, even when
|
|
1551
|
+
+// the importing files have not changed. Do not key unrelated targets or tags.
|
|
1552
|
+
+// Preserve enumeration order: package-name collisions are last-writer-wins
|
|
1553
|
+
+// and wildcard export lookup uses the first matching entry.
|
|
1554
|
+
+function projectResolutionIdentity(projects) {
|
|
1555
|
+
+ return JSON.stringify(Object.keys(projects).map((name) => {
|
|
1556
|
+
+ const project = projects[name];
|
|
1557
|
+
+ const js = project.metadata?.js;
|
|
1558
|
+
+ return [
|
|
1559
|
+
+ name,
|
|
1560
|
+
+ project.root,
|
|
1561
|
+
+ js?.packageName,
|
|
1562
|
+
+ js?.packageVersion,
|
|
1563
|
+
+ js?.packageExports,
|
|
1564
|
+
+ js?.packageMain,
|
|
1565
|
+
+ js?.isInPackageManagerWorkspaces,
|
|
1566
|
+
+ ];
|
|
1567
|
+
+ }));
|
|
1568
|
+
+}
|
|
1569
|
+
/**
|
|
1570
|
+
* Tracks the mtime of the project graph cache file after the last successful
|
|
1571
|
+
* writeCache() call. Used by writeCacheIfStale() to skip redundant writes
|
|
1572
|
+
@@ -230,19 +250,19 @@ function shouldRecomputeWholeGraph(cache, packageJsonDeps, projects, nxJson, tsC
|
|
1573
|
+
if (cache.nxVersion !== versions_1.nxVersion) {
|
|
1574
|
+
return true;
|
|
1575
|
+
}
|
|
1576
|
+
- // we have a cached project that is no longer present
|
|
1577
|
+
- const cachedNodes = Object.keys(cache.fileMap.projectFileMap);
|
|
1578
|
+
- if (cachedNodes.some((p) => projects[p] === undefined)) {
|
|
1579
|
+
+ // Legacy caches have no resolution identity and must be rebuilt once.
|
|
1580
|
+
+ // A new package can resolve an unchanged import just as a renamed one can.
|
|
1581
|
+
+ if (cache.projectResolution !== projectResolutionIdentity(projects)) {
|
|
1582
|
+
return true;
|
|
1583
|
+
}
|
|
1584
|
+
- // a path mapping for an existing project has changed
|
|
1585
|
+
- if (Object.keys(cache.pathMappings).some((t) => {
|
|
1586
|
+
+ // Added aliases can resolve unchanged imports; compare the whole key set.
|
|
1587
|
+
+ const cachedPaths = Object.keys(cache.pathMappings);
|
|
1588
|
+
+ const paths = tsConfig?.compilerOptions?.paths || {};
|
|
1589
|
+
+ if (cachedPaths.length !== Object.keys(paths).length || cachedPaths.some((t) => {
|
|
1590
|
+
const cached = cache.pathMappings && cache.pathMappings[t]
|
|
1591
|
+
? JSON.stringify(cache.pathMappings[t])
|
|
1592
|
+
: undefined;
|
|
1593
|
+
- const notCached = tsConfig?.compilerOptions?.paths && tsConfig?.compilerOptions?.paths[t]
|
|
1594
|
+
- ? JSON.stringify(tsConfig.compilerOptions.paths[t])
|
|
1595
|
+
- : undefined;
|
|
1596
|
+
+ const notCached = paths[t] ? JSON.stringify(paths[t]) : undefined;
|
|
1597
|
+
return cached !== notCached;
|
|
1598
|
+
})) {
|
|
1599
|
+
return true;
|
|
1600
|
+
diff --git a/dist/src/project-graph/plugins/get-plugins.js b/dist/src/project-graph/plugins/get-plugins.js
|
|
1601
|
+
index df153050063fa81b915d3004d3a87cd397f73b19..7d751ed7b895ea88735361b481c9437339ef7ffa 100644
|
|
1602
|
+
--- a/dist/src/project-graph/plugins/get-plugins.js
|
|
1603
|
+
+++ b/dist/src/project-graph/plugins/get-plugins.js
|
|
1604
|
+
@@ -296,7 +296,7 @@ async function loadDefaultNxPlugins(root = workspace_root_1.workspaceRoot) {
|
|
1605
|
+
fn();
|
|
1606
|
+
}
|
|
1607
|
+
const errorMessage = errors
|
|
1608
|
+
- .map((e) => ` - ${e.pluginName}: ${e.error.message}`)
|
|
1609
|
+
+ .map((e) => ` - ${e.pluginName}: ${formatPluginLoadError(e.error).replace(/\n/g, '\n ')}`)
|
|
1610
|
+
.join('\n');
|
|
1611
|
+
throw new AggregateError(errors.map((e) => e.error), `Failed to load ${errors.length} default Nx plugin(s):\n${errorMessage}`);
|
|
1612
|
+
}
|
|
1613
|
+
@@ -361,7 +361,7 @@ async function loadSpecifiedNxPlugins(pluginsConfigurations, root = workspace_ro
|
|
1614
|
+
fn();
|
|
1615
|
+
}
|
|
1616
|
+
const errorMessage = errors
|
|
1617
|
+
- .map((e) => ` - ${e.pluginName}: ${e.error.message}`)
|
|
1618
|
+
+ .map((e) => ` - ${e.pluginName}: ${formatPluginLoadError(e.error).replace(/\n/g, '\n ')}`)
|
|
1619
|
+
.join('\n');
|
|
1620
|
+
throw new AggregateError(errors.map((e) => e.error), `Failed to load ${errors.length} Nx plugin(s):\n${errorMessage}`);
|
|
1621
|
+
}
|
|
1622
|
+
@@ -376,6 +376,32 @@ async function loadSpecifiedNxPlugins(pluginsConfigurations, root = workspace_ro
|
|
1623
|
+
};
|
|
1624
|
+
return plugins;
|
|
1625
|
+
}
|
|
1626
|
+
+// Plugin resolution can wrap configuration errors before a plugin ever runs.
|
|
1627
|
+
+// Keep their causes and aggregate entries in the non-verbose diagnostic too.
|
|
1628
|
+
+function formatPluginLoadError(error, ancestors = new Set()) {
|
|
1629
|
+
+ const isObject = error !== null && typeof error === 'object';
|
|
1630
|
+
+ if (isObject) {
|
|
1631
|
+
+ if (ancestors.has(error)) {
|
|
1632
|
+
+ return '[Circular error]';
|
|
1633
|
+
+ }
|
|
1634
|
+
+ ancestors.add(error);
|
|
1635
|
+
+ }
|
|
1636
|
+
+ let message = Array.isArray(error) ? '' : String(error?.message ?? error);
|
|
1637
|
+
+ if (error?.cause !== undefined) {
|
|
1638
|
+
+ message += `\nCaused by: ${formatPluginLoadError(error.cause, ancestors)}`;
|
|
1639
|
+
+ }
|
|
1640
|
+
+ // AggregateCreateNodesError entries can be [file, error] pairs.
|
|
1641
|
+
+ const nestedErrors = Array.isArray(error) ? error : error?.errors;
|
|
1642
|
+
+ if (Array.isArray(nestedErrors)) {
|
|
1643
|
+
+ for (const nested of nestedErrors) {
|
|
1644
|
+
+ message += `${message ? '\n' : ''}${formatPluginLoadError(nested, ancestors)}`;
|
|
1645
|
+
+ }
|
|
1646
|
+
+ }
|
|
1647
|
+
+ if (isObject) {
|
|
1648
|
+
+ ancestors.delete(error);
|
|
1649
|
+
+ }
|
|
1650
|
+
+ return message;
|
|
1651
|
+
+}
|
|
1652
|
+
function reasonToError(reason) {
|
|
1653
|
+
if (reason instanceof Error) {
|
|
1654
|
+
return reason;
|
|
1655
|
+
@@ -385,6 +411,12 @@ function reasonToError(reason) {
|
|
1656
|
+
if ('stack' in reason) {
|
|
1657
|
+
error.stack = String(reason.stack);
|
|
1658
|
+
}
|
|
1659
|
+
+ if ('cause' in reason) {
|
|
1660
|
+
+ error.cause = reason.cause;
|
|
1661
|
+
+ }
|
|
1662
|
+
+ if ('errors' in reason) {
|
|
1663
|
+
+ error.errors = reason.errors;
|
|
1664
|
+
+ }
|
|
1665
|
+
return error;
|
|
1666
|
+
}
|
|
1667
|
+
return new Error(String(reason));
|
|
1668
|
+
diff --git a/dist/src/project-graph/plugins/isolation/isolated-plugin.js b/dist/src/project-graph/plugins/isolation/isolated-plugin.js
|
|
1669
|
+
index 07648586a78fad6c986f537e042e94e65b0dcc61..d7079a756fda379a7c6898de2b08ff917bf214bb 100644
|
|
1670
|
+
--- a/dist/src/project-graph/plugins/isolation/isolated-plugin.js
|
|
1671
|
+
+++ b/dist/src/project-graph/plugins/isolation/isolated-plugin.js
|
|
1672
|
+
@@ -11,6 +11,7 @@ const crypto_1 = require("crypto");
|
|
1673
|
+
const net_1 = require("net");
|
|
1674
|
+
const path = require("path");
|
|
1675
|
+
const logger_1 = require("../../../daemon/logger");
|
|
1676
|
+
+const is_on_daemon_1 = require("../../../daemon/is-on-daemon");
|
|
1677
|
+
const sandbox_socket_hint_1 = require("../../../daemon/sandbox-socket-hint");
|
|
1678
|
+
const socket_refused_exit_code_1 = require("../../../utils/socket-refused-exit-code");
|
|
1679
|
+
const socket_utils_1 = require("../../../daemon/socket-utils");
|
|
1680
|
+
@@ -210,7 +211,7 @@ class IsolatedPlugin {
|
|
1681
|
+
this.include = loadResult.include;
|
|
1682
|
+
this.exclude = loadResult.exclude;
|
|
1683
|
+
const registeredHooks = hooks(loadResult.createNodesPattern && 'createNodes', loadResult.hasCreateDependencies && 'createDependencies', loadResult.hasCreateMetadata && 'createMetadata', loadResult.hasPreTasksExecution && 'preTasksExecution', loadResult.hasPostTasksExecution && 'postTasksExecution');
|
|
1684
|
+
- this.lifecycle = new plugin_lifecycle_manager_1.PluginLifecycleManager(registeredHooks);
|
|
1685
|
+
+ this.lifecycle = new plugin_lifecycle_manager_1.PluginLifecycleManager(registeredHooks, (0, is_on_daemon_1.isOnDaemon)());
|
|
1686
|
+
const shutdown = (hookName) => this.shutdownIfInactive(hookName);
|
|
1687
|
+
const wrap = (hook, hookFn) => this.lifecycle.wrapHook(hook, async (...args) => {
|
|
1688
|
+
await this.ensureAlive();
|
|
1689
|
+
diff --git a/dist/src/project-graph/plugins/isolation/plugin-lifecycle-manager.d.ts b/dist/src/project-graph/plugins/isolation/plugin-lifecycle-manager.d.ts
|
|
1690
|
+
index 3a6df86646a11f371525fca978edf0fc318bf848..1e73ad21751964e3c6839e44eb43488677a9cec3 100644
|
|
1691
|
+
--- a/dist/src/project-graph/plugins/isolation/plugin-lifecycle-manager.d.ts
|
|
1692
|
+
+++ b/dist/src/project-graph/plugins/isolation/plugin-lifecycle-manager.d.ts
|
|
1693
|
+
@@ -20,6 +20,10 @@ export type Hook = (typeof HOOKS_BY_PHASE)[Phase][number];
|
|
1694
|
+
* Shutdown occurs when:
|
|
1695
|
+
* 1. All phase sessions complete (ref count reaches 0)
|
|
1696
|
+
* 2. No later phases have registered hooks
|
|
1697
|
+
+ * 3. The worker is not resident: a host that recomputes the graph for every
|
|
1698
|
+
+ * file change (the daemon) keeps a worker with graph hooks alive, because
|
|
1699
|
+
+ * the next change calls those hooks again and a restart costs a process
|
|
1700
|
+
+ * spawn plus a plugin load each time
|
|
1701
|
+
*/
|
|
1702
|
+
export declare class PluginLifecycleManager {
|
|
1703
|
+
/** Phases where this plugin has at least one registered hook */
|
|
1704
|
+
@@ -28,7 +32,9 @@ export declare class PluginLifecycleManager {
|
|
1705
|
+
private readonly phaseSessionCount;
|
|
1706
|
+
/** Ordered list of registered phases (derived from HOOKS_BY_PHASE key order, narrowed to registered phases) */
|
|
1707
|
+
private readonly registeredPhaseOrder;
|
|
1708
|
+
- constructor(registeredHooks: Iterable<Hook>);
|
|
1709
|
+
+ /** Whether this worker outlives its phases (see class doc, rule 3) */
|
|
1710
|
+
+ private readonly resident;
|
|
1711
|
+
+ constructor(registeredHooks: Iterable<Hook>, recomputesGraph?: boolean);
|
|
1712
|
+
wrapHook<TArgs extends unknown[], TReturn>(hook: Hook, fn: (...args: TArgs) => Promise<TReturn>, shutdown: () => Promise<void> | void): (...args: TArgs) => Promise<TReturn>;
|
|
1713
|
+
/**
|
|
1714
|
+
* Called when entering a hook. Increments phase session count if this
|
|
1715
|
+
diff --git a/dist/src/project-graph/plugins/isolation/plugin-lifecycle-manager.js b/dist/src/project-graph/plugins/isolation/plugin-lifecycle-manager.js
|
|
1716
|
+
index 3659fdd1955d56e60cc0158d19ac55d59916d78e..92e6700adfc52a380b3e9e37b655fbc9a96f673a 100644
|
|
1717
|
+
--- a/dist/src/project-graph/plugins/isolation/plugin-lifecycle-manager.js
|
|
1718
|
+
+++ b/dist/src/project-graph/plugins/isolation/plugin-lifecycle-manager.js
|
|
1719
|
+
@@ -28,9 +28,13 @@ const PHASE_ORDER = keys(HOOKS_BY_PHASE);
|
|
1720
|
+
* Shutdown occurs when:
|
|
1721
|
+
* 1. All phase sessions complete (ref count reaches 0)
|
|
1722
|
+
* 2. No later phases have registered hooks
|
|
1723
|
+
+ * 3. The worker is not resident: a host that recomputes the graph for every
|
|
1724
|
+
+ * file change (the daemon) keeps a worker with graph hooks alive, because
|
|
1725
|
+
+ * the next change calls those hooks again and a restart costs a process
|
|
1726
|
+
+ * spawn plus a plugin load each time
|
|
1727
|
+
*/
|
|
1728
|
+
class PluginLifecycleManager {
|
|
1729
|
+
- constructor(registeredHooks) {
|
|
1730
|
+
+ constructor(registeredHooks, recomputesGraph = false) {
|
|
1731
|
+
/** Phases where this plugin has at least one registered hook */
|
|
1732
|
+
this.registeredPhases = {};
|
|
1733
|
+
/** Number of active "phase sessions" (callers between first and last hook) */
|
|
1734
|
+
@@ -51,6 +55,8 @@ class PluginLifecycleManager {
|
|
1735
|
+
for (const phase of this.registeredPhaseOrder) {
|
|
1736
|
+
this.phaseSessionCount[phase] = 0;
|
|
1737
|
+
}
|
|
1738
|
+
+ /** Whether this worker outlives its phases (see class doc, rule 3) */
|
|
1739
|
+
+ this.resident = recomputesGraph && this.registeredPhases['graph'] !== undefined;
|
|
1740
|
+
}
|
|
1741
|
+
wrapHook(hook, fn, shutdown) {
|
|
1742
|
+
return async (...args) => {
|
|
1743
|
+
@@ -109,8 +115,8 @@ class PluginLifecycleManager {
|
|
1744
|
+
// Can only shut down if no more active sessions in this phase
|
|
1745
|
+
if (newCount > 0)
|
|
1746
|
+
return false;
|
|
1747
|
+
- // Can only shut down if this is the last registered phase
|
|
1748
|
+
- return this.isLastRegisteredPhase(phase);
|
|
1749
|
+
+ // Can only shut down a non-resident worker after its last registered phase
|
|
1750
|
+
+ return !this.resident && this.isLastRegisteredPhase(phase);
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1753
|
+
* Returns true if the worker should shut down immediately after construction.
|
|
1754
|
+
@@ -173,7 +179,7 @@ class PluginLifecycleManager {
|
|
1755
|
+
if (newCount > 0) {
|
|
1756
|
+
return false;
|
|
1757
|
+
}
|
|
1758
|
+
- return this.isLastRegisteredPhase(phase);
|
|
1759
|
+
+ return !this.resident && this.isLastRegisteredPhase(phase);
|
|
1760
|
+
}
|
|
1761
|
+
/**
|
|
1762
|
+
* Returns the current session count for a phase. Useful for testing.
|
|
1763
|
+
diff --git a/dist/src/tasks-runner/cache.d.ts b/dist/src/tasks-runner/cache.d.ts
|
|
1764
|
+
index 34aa44f81f1df63c5d33e58d8b55d15fcf1d7619..edf41406f465726828fa447bd10d71a49a2ede8a 100644
|
|
1765
|
+
--- a/dist/src/tasks-runner/cache.d.ts
|
|
1766
|
+
+++ b/dist/src/tasks-runner/cache.d.ts
|
|
1767
|
+
@@ -33,6 +33,7 @@ export declare class DbCache {
|
|
1768
|
+
private applyRemoteCacheResults;
|
|
1769
|
+
put(task: Task, terminalOutput: string | null, outputs: string[], code: number): Promise<void>;
|
|
1770
|
+
copyFilesFromCache(_: string, cachedResult: CachedResult, outputs: string[]): Promise<number>;
|
|
1771
|
+
+ private stampRestored;
|
|
1772
|
+
removeOldCacheRecords(): void;
|
|
1773
|
+
temporaryOutputPath(task: Task): string;
|
|
1774
|
+
private getRemoteCache;
|
|
1775
|
+
diff --git a/dist/src/tasks-runner/cache.js b/dist/src/tasks-runner/cache.js
|
|
1776
|
+
index 4a34ba245ca18dc4f4897fb45130e0d9dce94861..c7301119b99aa8d2a6dff507bee8f8652d2be0c4 100644
|
|
1777
|
+
--- a/dist/src/tasks-runner/cache.js
|
|
1778
|
+
+++ b/dist/src/tasks-runner/cache.js
|
|
1779
|
+
@@ -149,7 +149,11 @@ class DbCache {
|
|
1780
|
+
return this.cache.getCacheSize();
|
|
1781
|
+
}
|
|
1782
|
+
applyRemoteCacheResults(hash, res, outputs) {
|
|
1783
|
+
- return this.cache.applyRemoteCacheResults(hash, res, outputs);
|
|
1784
|
+
+ this.cache.applyRemoteCacheResults(hash, res, outputs);
|
|
1785
|
+
+ // The native call restores the outputs itself, under this same condition.
|
|
1786
|
+
+ if (outputs?.length > 0 && res.code === 0) {
|
|
1787
|
+
+ this.stampRestored(res.outputsPath, outputs);
|
|
1788
|
+
+ }
|
|
1789
|
+
}
|
|
1790
|
+
async put(task, terminalOutput, outputs, code) {
|
|
1791
|
+
return tryAndRetry(async () => {
|
|
1792
|
+
@@ -162,7 +166,20 @@ class DbCache {
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1795
|
+
copyFilesFromCache(_, cachedResult, outputs) {
|
|
1796
|
+
- return tryAndRetry(async () => this.cache.copyFilesFromCache(cachedResult, outputs));
|
|
1797
|
+
+ return tryAndRetry(async () => {
|
|
1798
|
+
+ const size = this.cache.copyFilesFromCache(cachedResult, outputs);
|
|
1799
|
+
+ this.stampRestored(cachedResult.outputsPath, outputs);
|
|
1800
|
+
+ return size;
|
|
1801
|
+
+ });
|
|
1802
|
+
+ }
|
|
1803
|
+
+ /**
|
|
1804
|
+
+ * Stamps what the native restore wrote from the cache entry at
|
|
1805
|
+
+ * `outputsPath`. The native restore makes an absolute in-workspace output
|
|
1806
|
+
+ * relative before expanding it in the entry, so this does too.
|
|
1807
|
+
+ */
|
|
1808
|
+
+ stampRestored(outputsPath, outputs) {
|
|
1809
|
+
+ const relativeOutputs = outputs.map((output) => (0, path_1.isAbsolute)(output) ? (0, path_1.relative)(workspace_root_1.workspaceRoot, output) : output);
|
|
1810
|
+
+ stampRestoredOutputs(workspace_root_1.workspaceRoot, outputsPath, (0, native_1.expandOutputs)(outputsPath, relativeOutputs));
|
|
1811
|
+
}
|
|
1812
|
+
removeOldCacheRecords() {
|
|
1813
|
+
return this.cache.removeOldCacheRecords();
|
|
1814
|
+
@@ -416,6 +433,7 @@ class Cache {
|
|
1815
|
+
await this.copy(cached, src);
|
|
1816
|
+
}
|
|
1817
|
+
}));
|
|
1818
|
+
+ stampRestoredOutputs(this.root, cachedResult.outputsPath, expandedOutputs);
|
|
1819
|
+
});
|
|
1820
|
+
}
|
|
1821
|
+
temporaryOutputPath(task) {
|
|
1822
|
+
@@ -516,6 +534,35 @@ class Cache {
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
exports.Cache = Cache;
|
|
1826
|
+
+/**
|
|
1827
|
+
+ * Gives each file a cache restore wrote the time of the restore. The native
|
|
1828
|
+
+ * copy (`std::fs::copy`) clones a file on macOS and keeps its timestamps, so a
|
|
1829
|
+
+ * restored output kept the mtime it had when its cache entry was written:
|
|
1830
|
+
+ * older than anything a tool built from a newer output since. A consumer that
|
|
1831
|
+
+ * judges freshness by mtime (a Cargo build script's `rerun-if-changed`, make,
|
|
1832
|
+
+ * a file watcher) then kept what it built from the newer bytes. Running the
|
|
1833
|
+
+ * task would have written the output now, so the restore stamps it now. Links
|
|
1834
|
+
+ * keep their own times: `utimes` would stamp what they point at.
|
|
1835
|
+
+ */
|
|
1836
|
+
+function stampRestoredOutputs(workspaceRoot, outputsPath, expandedOutputs) {
|
|
1837
|
+
+ const now = new Date();
|
|
1838
|
+
+ const stamp = (path) => {
|
|
1839
|
+
+ const stats = (0, node_fs_1.lstatSync)(path);
|
|
1840
|
+
+ if (stats.isDirectory()) {
|
|
1841
|
+
+ for (const entry of (0, node_fs_1.readdirSync)(path)) {
|
|
1842
|
+
+ stamp((0, path_1.join)(path, entry));
|
|
1843
|
+
+ }
|
|
1844
|
+
+ }
|
|
1845
|
+
+ else if (stats.isFile()) {
|
|
1846
|
+
+ (0, node_fs_1.utimesSync)(path, now, now);
|
|
1847
|
+
+ }
|
|
1848
|
+
+ };
|
|
1849
|
+
+ for (const output of expandedOutputs) {
|
|
1850
|
+
+ if ((0, node_fs_1.existsSync)((0, path_1.join)(outputsPath, output))) {
|
|
1851
|
+
+ stamp((0, path_1.join)(workspaceRoot, output));
|
|
1852
|
+
+ }
|
|
1853
|
+
+ }
|
|
1854
|
+
+}
|
|
1855
|
+
function tryAndRetry(fn) {
|
|
1856
|
+
let attempts = 0;
|
|
1857
|
+
// Generate a random number between 2 and 4 to raise to the power of attempts
|
|
1858
|
+
@@ -549,7 +596,29 @@ function resolveMaxCacheSize(nxJson) {
|
|
1859
|
+
const rawMaxCacheSize = process.env.NX_MAX_CACHE_SIZE ?? nxJson.maxCacheSize;
|
|
1860
|
+
return rawMaxCacheSize !== undefined
|
|
1861
|
+
? parseMaxCacheSize(rawMaxCacheSize)
|
|
1862
|
+
- : (0, native_1.getDefaultMaxCacheSize)(cache_directory_1.cacheDir);
|
|
1863
|
+
+ : defaultMaxCacheSize(cache_directory_1.cacheDir);
|
|
1864
|
+
+}
|
|
1865
|
+
+/**
|
|
1866
|
+
+ * A tenth of the filesystem that holds the cache directory, asked of that one
|
|
1867
|
+
+ * filesystem through its nearest existing ancestor (the directory may not
|
|
1868
|
+
+ * exist yet). The native default lists every mounted disk to find it, which
|
|
1869
|
+
+ * on macOS costs IOKit and CacheDelete round trips per mount on this thread,
|
|
1870
|
+
+ * between hashing and the first task.
|
|
1871
|
+
+ */
|
|
1872
|
+
+function defaultMaxCacheSize(cachePath) {
|
|
1873
|
+
+ for (let directory = cachePath;;) {
|
|
1874
|
+
+ try {
|
|
1875
|
+
+ const { blocks, bsize } = (0, node_fs_1.statfsSync)(directory);
|
|
1876
|
+
+ return Math.floor(blocks * bsize * 0.1);
|
|
1877
|
+
+ }
|
|
1878
|
+
+ catch (error) {
|
|
1879
|
+
+ const parent = (0, path_1.dirname)(directory);
|
|
1880
|
+
+ if (error?.code !== 'ENOENT' || parent === directory) {
|
|
1881
|
+
+ throw error;
|
|
1882
|
+
+ }
|
|
1883
|
+
+ directory = parent;
|
|
1884
|
+
+ }
|
|
1885
|
+
+ }
|
|
1886
|
+
}
|
|
1887
|
+
/**
|
|
1888
|
+
* Converts a string representation of a max cache size to a number.
|
|
1889
|
+
diff --git a/dist/src/tasks-runner/create-task-graph.js b/dist/src/tasks-runner/create-task-graph.js
|
|
1890
|
+
index f0996420e6a01e90f58512e433bd98cdd299d47b..cdb4fdcb687916f6098b8b77c9471da934bf0243 100644
|
|
1891
|
+
--- a/dist/src/tasks-runner/create-task-graph.js
|
|
1892
|
+
+++ b/dist/src/tasks-runner/create-task-graph.js
|
|
1893
|
+
@@ -77,7 +77,33 @@ class ProcessTasks {
|
|
1894
|
+
];
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
- return Object.keys(this.tasks).filter((d) => this.dependencies[d].length === 0 &&
|
|
1898
|
+
+ // Dummy-cycle normalization can disconnect tasks found during expansion.
|
|
1899
|
+
+ const taskIds = Object.keys(this.tasks);
|
|
1900
|
+
+ const pending = Object.keys(initialTasks);
|
|
1901
|
+
+ const reachable = new Set(pending);
|
|
1902
|
+
+ while (pending.length > 0) {
|
|
1903
|
+
+ const taskId = pending.pop();
|
|
1904
|
+
+ for (const dependency of this.dependencies[taskId]) {
|
|
1905
|
+
+ if (!reachable.has(dependency)) {
|
|
1906
|
+
+ reachable.add(dependency);
|
|
1907
|
+
+ pending.push(dependency);
|
|
1908
|
+
+ }
|
|
1909
|
+
+ }
|
|
1910
|
+
+ for (const dependency of this.continuousDependencies[taskId]) {
|
|
1911
|
+
+ if (!reachable.has(dependency)) {
|
|
1912
|
+
+ reachable.add(dependency);
|
|
1913
|
+
+ pending.push(dependency);
|
|
1914
|
+
+ }
|
|
1915
|
+
+ }
|
|
1916
|
+
+ }
|
|
1917
|
+
+ for (const taskId of taskIds) {
|
|
1918
|
+
+ if (!reachable.has(taskId)) {
|
|
1919
|
+
+ delete this.tasks[taskId];
|
|
1920
|
+
+ delete this.dependencies[taskId];
|
|
1921
|
+
+ delete this.continuousDependencies[taskId];
|
|
1922
|
+
+ }
|
|
1923
|
+
+ }
|
|
1924
|
+
+ return taskIds.filter((d) => reachable.has(d) && this.dependencies[d].length === 0 &&
|
|
1925
|
+
this.continuousDependencies[d].length === 0);
|
|
1926
|
+
}
|
|
1927
|
+
processTask(task, projectUsedToDeriveDependencies, configuration, overrides) {
|
|
1928
|
+
diff --git a/dist/src/tasks-runner/default-tasks-runner.js b/dist/src/tasks-runner/default-tasks-runner.js
|
|
1929
|
+
index 713453e37ce42da670e6a37d62e0bab763d7cf37..841eb089b99e0c6029c0d860bf5e0a305fe6ad50 100644
|
|
1930
|
+
--- a/dist/src/tasks-runner/default-tasks-runner.js
|
|
1931
|
+
+++ b/dist/src/tasks-runner/default-tasks-runner.js
|
|
1932
|
+
@@ -54,12 +54,12 @@ class RemoteCacheV2 {
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
exports.RemoteCacheV2 = RemoteCacheV2;
|
|
1936
|
+
-const defaultTasksRunner = async (tasks, options, context) => {
|
|
1937
|
+
+const defaultTasksRunner = async (tasks, options, context, runnerCompletion) => {
|
|
1938
|
+
const { total: threadCount, discrete } = (0, task_orchestrator_1.getThreadPoolSize)(options, context.taskGraph);
|
|
1939
|
+
// Total thread count drives the TUI; the discrete `--parallel` feeds the perf report.
|
|
1940
|
+
await options.lifeCycle.startCommand(threadCount, discrete);
|
|
1941
|
+
try {
|
|
1942
|
+
- return await runAllTasks(options, context);
|
|
1943
|
+
+ return await runAllTasks(options, context, runnerCompletion);
|
|
1944
|
+
}
|
|
1945
|
+
finally {
|
|
1946
|
+
// Hand the TUI exit popup the perf report (multi-task TUI runs); other modes flush it.
|
|
1947
|
+
@@ -67,8 +67,13 @@ const defaultTasksRunner = async (tasks, options, context) => {
|
|
1948
|
+
}
|
|
1949
|
+
};
|
|
1950
|
+
exports.defaultTasksRunner = defaultTasksRunner;
|
|
1951
|
+
-async function runAllTasks(options, context) {
|
|
1952
|
+
+async function runAllTasks(options, context, runnerCompletion) {
|
|
1953
|
+
const orchestrator = new task_orchestrator_1.TaskOrchestrator(context.hasher, context.initiatingProject, context.initiatingTasks, context.projectGraph, context.taskGraph, context.nxJson, options, context.nxArgs?.nxBail, context.daemon, context.nxArgs?.outputStyle);
|
|
1954
|
+
- return orchestrator.run();
|
|
1955
|
+
+ const statuses = await orchestrator.run();
|
|
1956
|
+
+ if (runnerCompletion) {
|
|
1957
|
+
+ runnerCompletion.bailed = orchestrator.bailed;
|
|
1958
|
+
+ runnerCompletion.interrupted = orchestrator.stopRequested;
|
|
1959
|
+
+ }
|
|
1960
|
+
+ return statuses;
|
|
1961
|
+
}
|
|
1962
|
+
exports.default = exports.defaultTasksRunner;
|
|
1963
|
+
diff --git a/dist/src/tasks-runner/life-cycles/performance-life-cycle.js b/dist/src/tasks-runner/life-cycles/performance-life-cycle.js
|
|
1964
|
+
index fa73e9c05acc22a21b26f37df2b52fae4727b23a..8eb555827d52af60c047697f42e8d185235d4bb4 100644
|
|
1965
|
+
--- a/dist/src/tasks-runner/life-cycles/performance-life-cycle.js
|
|
1966
|
+
+++ b/dist/src/tasks-runner/life-cycles/performance-life-cycle.js
|
|
1967
|
+
@@ -12,7 +12,7 @@ const performance_analysis_1 = require("./performance-analysis");
|
|
1968
|
+
* Measures how much wall-clock a run loses to parallelism contention versus its
|
|
1969
|
+
* critical-path floor, and reports it at the end of a run. Added on every run by
|
|
1970
|
+
* `constructLifeCycles`, but only emitted where the report is flushed (the CLI
|
|
1971
|
+
- * `invokeTasksRunner` path) — the programmatic `init-tasks-runner` path collects
|
|
1972
|
+
+ * `runCommandForTasks` path) — the programmatic `init-tasks-runner` path collects
|
|
1973
|
+
* timings but never displays them.
|
|
1974
|
+
*
|
|
1975
|
+
* overhead = runDuration − criticalPathDuration, split by CAUSE off the occupancy
|
|
1976
|
+
diff --git a/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.d.ts b/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.d.ts
|
|
1977
|
+
index b948965217d385e31f5f49895bb09aa5d11afedb..6fff5d5e42ba9ff87f074ccba1045960a5501fe5 100644
|
|
1978
|
+
--- a/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.d.ts
|
|
1979
|
+
+++ b/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.d.ts
|
|
1980
|
+
@@ -30,10 +30,11 @@ export declare class StaticRunManyTerminalOutputLifeCycle implements LifeCycle {
|
|
1981
|
+
startCommand(): void;
|
|
1982
|
+
endCommand(): void;
|
|
1983
|
+
/**
|
|
1984
|
+
- * Tasks with a `skipped` status are never reported through `endTasks`, so
|
|
1985
|
+
- * they are derived by subtracting everything that did complete.
|
|
1986
|
+
+ * The tasks the orchestrator never reported through `endTasks`: those it
|
|
1987
|
+
+ * skipped, which it never reports, and those a run that threw part way
|
|
1988
|
+
+ * through never finished.
|
|
1989
|
+
*/
|
|
1990
|
+
- private skippedTasks;
|
|
1991
|
+
+ private unreportedTasks;
|
|
1992
|
+
/**
|
|
1993
|
+
* Whether this run prints every task's output in full rather than collapsing
|
|
1994
|
+
* the ones that succeeded.
|
|
1995
|
+
@@ -44,11 +45,6 @@ export declare class StaticRunManyTerminalOutputLifeCycle implements LifeCycle {
|
|
1996
|
+
* printing something worth reading is not silently swallowed.
|
|
1997
|
+
*/
|
|
1998
|
+
private hiddenOutputHint;
|
|
1999
|
+
- /**
|
|
2000
|
+
- * Tasks that never produced output worth printing are summarized as counts,
|
|
2001
|
+
- * with their names available behind --verbose.
|
|
2002
|
+
- */
|
|
2003
|
+
- private tasksNotRunSummary;
|
|
2004
|
+
endTasks(taskResults: TaskResult[]): void;
|
|
2005
|
+
printTaskTerminalOutput(task: Task, taskStatus: TaskStatus, terminalOutput: string): void;
|
|
2006
|
+
}
|
|
2007
|
+
diff --git a/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js b/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js
|
|
2008
|
+
index a389729defdaac06c0e710369c27569a98b077e8..e92595278c7e07fd55d724c47e62882cae49e73e 100644
|
|
2009
|
+
--- a/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js
|
|
2010
|
+
+++ b/dist/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.js
|
|
2011
|
+
@@ -59,17 +59,22 @@ class StaticRunManyTerminalOutputLifeCycle {
|
|
2012
|
+
output_1.output.logSingleLine(`No tasks were run`);
|
|
2013
|
+
return;
|
|
2014
|
+
}
|
|
2015
|
+
- // A stopped task was killed mid-flight, so the run did not complete even
|
|
2016
|
+
- // though nothing outright failed. `didCommandComplete` already treats it
|
|
2017
|
+
- // that way; reporting "Successfully ran" here would contradict it.
|
|
2018
|
+
- if (this.failedTasks.length === 0 && this.stoppedTasks.length === 0) {
|
|
2019
|
+
+ // The orchestrator reports every task it finishes through `endTasks`
|
|
2020
|
+
+ // except one it skips, and it skips a task only behind a failed or
|
|
2021
|
+
+ // stopped one. With neither, a task it never reported is one the run
|
|
2022
|
+
+ // ended without finishing: the orchestrator threw part way through, and
|
|
2023
|
+
+ // `endCommand` runs from the runner's `finally`. Only a run that
|
|
2024
|
+
+ // reported every task, none failed or stopped, ran successfully.
|
|
2025
|
+
+ const unreportedTasks = this.unreportedTasks();
|
|
2026
|
+
+ if (this.failedTasks.length === 0 &&
|
|
2027
|
+
+ this.stoppedTasks.length === 0 &&
|
|
2028
|
+
+ unreportedTasks.length === 0) {
|
|
2029
|
+
output_1.output.addVerticalSeparatorWithoutNewLines('green');
|
|
2030
|
+
const bodyLines = this.cachedTasks.length > 0
|
|
2031
|
+
? [
|
|
2032
|
+
output_1.output.dim(`Nx read the output from the cache instead of running the command for ${this.cachedTasks.length} out of ${this.tasks.length} tasks.`),
|
|
2033
|
+
]
|
|
2034
|
+
: [];
|
|
2035
|
+
- bodyLines.push(...this.tasksNotRunSummary());
|
|
2036
|
+
bodyLines.push(...this.hiddenOutputHint());
|
|
2037
|
+
output_1.output.success({
|
|
2038
|
+
title: `Successfully ran ${(0, formatting_utils_1.formatTargetsAndProjects)(this.projectNames, this.args.targets, this.tasks)}`,
|
|
2039
|
+
@@ -79,9 +84,10 @@ class StaticRunManyTerminalOutputLifeCycle {
|
|
2040
|
+
else {
|
|
2041
|
+
output_1.output.addVerticalSeparatorWithoutNewLines('red');
|
|
2042
|
+
const bodyLines = [];
|
|
2043
|
+
- const skippedTasks = this.skippedTasks();
|
|
2044
|
+
- if (skippedTasks.length > 0) {
|
|
2045
|
+
- bodyLines.push(output_1.output.dim('Tasks not run because their dependencies failed or --nx-bail=true:'), '', ...skippedTasks.map((task) => `${output_1.output.dim('-')} ${task.id}`), '');
|
|
2046
|
+
+ if (unreportedTasks.length > 0) {
|
|
2047
|
+
+ bodyLines.push(output_1.output.dim(this.failedTasks.length > 0
|
|
2048
|
+
+ ? 'Tasks not run because their dependencies failed or --nx-bail=true:'
|
|
2049
|
+
+ : 'Tasks the run ended without finishing:'), '', ...unreportedTasks.map((task) => `${output_1.output.dim('-')} ${task.id}`), '');
|
|
2050
|
+
}
|
|
2051
|
+
if (this.stoppedTasks.length > 0) {
|
|
2052
|
+
bodyLines.push(output_1.output.dim('Tasks stopped before they finished:'), '', ...this.stoppedTasks.map((task) => `${output_1.output.dim('-')} ${task.id}`), '');
|
|
2053
|
+
@@ -100,10 +106,11 @@ class StaticRunManyTerminalOutputLifeCycle {
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
/**
|
|
2057
|
+
- * Tasks with a `skipped` status are never reported through `endTasks`, so
|
|
2058
|
+
- * they are derived by subtracting everything that did complete.
|
|
2059
|
+
+ * The tasks the orchestrator never reported through `endTasks`: those it
|
|
2060
|
+
+ * skipped, which it never reports, and those a run that threw part way
|
|
2061
|
+
+ * through never finished.
|
|
2062
|
+
*/
|
|
2063
|
+
- skippedTasks() {
|
|
2064
|
+
+ unreportedTasks() {
|
|
2065
|
+
return this.tasks.filter((t) => !this.allCompletedTasks.has(t.id));
|
|
2066
|
+
}
|
|
2067
|
+
/**
|
|
2068
|
+
@@ -136,28 +143,6 @@ class StaticRunManyTerminalOutputLifeCycle {
|
|
2069
|
+
`${output_1.output.dim(`Output of ${withheld.join(' and ')} ${total === 1 && withheld.length === 1 ? 'was' : 'were'} not shown. Run with`)} --verbose ${output_1.output.dim('or')} --output-style=static ${output_1.output.dim('to see it.')}`,
|
|
2070
|
+
];
|
|
2071
|
+
}
|
|
2072
|
+
- /**
|
|
2073
|
+
- * Tasks that never produced output worth printing are summarized as counts,
|
|
2074
|
+
- * with their names available behind --verbose.
|
|
2075
|
+
- */
|
|
2076
|
+
- tasksNotRunSummary() {
|
|
2077
|
+
- const skippedTasks = this.skippedTasks();
|
|
2078
|
+
- const counts = [];
|
|
2079
|
+
- if (skippedTasks.length > 0) {
|
|
2080
|
+
- counts.push(`${skippedTasks.length} skipped`);
|
|
2081
|
+
- }
|
|
2082
|
+
- if (this.stoppedTasks.length > 0) {
|
|
2083
|
+
- counts.push(`${this.stoppedTasks.length} stopped`);
|
|
2084
|
+
- }
|
|
2085
|
+
- if (counts.length === 0) {
|
|
2086
|
+
- return [];
|
|
2087
|
+
- }
|
|
2088
|
+
- const lines = [output_1.output.dim(counts.join(', '))];
|
|
2089
|
+
- if (this.printsFullOutput) {
|
|
2090
|
+
- lines.push('', ...[...skippedTasks, ...this.stoppedTasks].map((task) => `${output_1.output.dim('-')} ${task.id}`));
|
|
2091
|
+
- }
|
|
2092
|
+
- return lines;
|
|
2093
|
+
- }
|
|
2094
|
+
endTasks(taskResults) {
|
|
2095
|
+
for (let t of taskResults) {
|
|
2096
|
+
this.allCompletedTasks.set(t.task.id, t.task);
|
|
2097
|
+
diff --git a/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.d.ts b/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.d.ts
|
|
2098
|
+
index 5748cbb88fa16e495c206ce8281b25ac8e481082..cc8e908f64e389d00f11414d41b4256ae18c1630 100644
|
|
2099
|
+
--- a/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.d.ts
|
|
2100
|
+
+++ b/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.d.ts
|
|
2101
|
+
@@ -40,15 +40,11 @@ export declare class StaticRunOneTerminalOutputLifeCycle implements LifeCycle {
|
|
2102
|
+
startCommand(): void;
|
|
2103
|
+
endCommand(): void;
|
|
2104
|
+
/**
|
|
2105
|
+
- * Tasks with a `skipped` status are never reported through `endTasks`, so
|
|
2106
|
+
- * they are derived by subtracting everything that did complete.
|
|
2107
|
+
+ * The tasks the orchestrator never reported through `endTasks`: those it
|
|
2108
|
+
+ * skipped, which it never reports, and those a run that threw part way
|
|
2109
|
+
+ * through never finished.
|
|
2110
|
+
*/
|
|
2111
|
+
- private skippedTasks;
|
|
2112
|
+
- /**
|
|
2113
|
+
- * Tasks that never produced output worth printing are summarized as counts,
|
|
2114
|
+
- * with their names available behind --verbose.
|
|
2115
|
+
- */
|
|
2116
|
+
- private tasksNotRunSummary;
|
|
2117
|
+
+ private unreportedTasks;
|
|
2118
|
+
endTasks(taskResults: TaskResult[]): void;
|
|
2119
|
+
printTaskTerminalOutput(task: Task, status: TaskStatus, terminalOutput: string): void;
|
|
2120
|
+
}
|
|
2121
|
+
diff --git a/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.js b/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.js
|
|
2122
|
+
index 4b3ae70c8af939f85e02dc5de8afefc62d6d20d4..88857f50b46fe34ad9e8330aa4e6f3ab1af1d676 100644
|
|
2123
|
+
--- a/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.js
|
|
2124
|
+
+++ b/dist/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.js
|
|
2125
|
+
@@ -69,16 +69,22 @@ class StaticRunOneTerminalOutputLifeCycle {
|
|
2126
|
+
}
|
|
2127
|
+
endCommand() {
|
|
2128
|
+
output_1.output.addNewline();
|
|
2129
|
+
- // A stopped task was killed mid-flight, so the run did not complete even
|
|
2130
|
+
- // though nothing outright failed — matching run-many and didCommandComplete.
|
|
2131
|
+
- if (this.failedTasks.length === 0 && this.stoppedTasks.length === 0) {
|
|
2132
|
+
+ // The orchestrator reports every task it finishes through `endTasks`
|
|
2133
|
+
+ // except one it skips, and it skips a task only behind a failed or
|
|
2134
|
+
+ // stopped one. With neither, a task it never reported is one the run
|
|
2135
|
+
+ // ended without finishing: the orchestrator threw part way through, and
|
|
2136
|
+
+ // `endCommand` runs from the runner's `finally`. Only a run that
|
|
2137
|
+
+ // reported every task, none failed or stopped, ran successfully.
|
|
2138
|
+
+ const unreportedTasks = this.unreportedTasks();
|
|
2139
|
+
+ if (this.failedTasks.length === 0 &&
|
|
2140
|
+
+ this.stoppedTasks.length === 0 &&
|
|
2141
|
+
+ unreportedTasks.length === 0) {
|
|
2142
|
+
output_1.output.addVerticalSeparatorWithoutNewLines('green');
|
|
2143
|
+
const bodyLines = this.cachedTasks.length > 0
|
|
2144
|
+
? [
|
|
2145
|
+
output_1.output.dim(`Nx read the output from the cache instead of running the command for ${this.cachedTasks.length} out of ${this.tasks.length} tasks.`),
|
|
2146
|
+
]
|
|
2147
|
+
: [];
|
|
2148
|
+
- bodyLines.push(...this.tasksNotRunSummary());
|
|
2149
|
+
bodyLines.push(...this.hiddenOutputHint());
|
|
2150
|
+
output_1.output.success({
|
|
2151
|
+
title: `Successfully ran ${(0, formatting_utils_1.formatTargetsAndProjects)(this.projectNames, this.args.targets, this.tasks)}`,
|
|
2152
|
+
@@ -88,9 +94,10 @@ class StaticRunOneTerminalOutputLifeCycle {
|
|
2153
|
+
else {
|
|
2154
|
+
output_1.output.addVerticalSeparatorWithoutNewLines('red');
|
|
2155
|
+
const bodyLines = [];
|
|
2156
|
+
- const skippedTasks = this.skippedTasks();
|
|
2157
|
+
- if (skippedTasks.length > 0) {
|
|
2158
|
+
- bodyLines.push(output_1.output.dim('Tasks not run because their dependencies failed or --nx-bail=true:'), '', ...skippedTasks.map((task) => `${output_1.output.dim('-')} ${task.id}`), '');
|
|
2159
|
+
+ if (unreportedTasks.length > 0) {
|
|
2160
|
+
+ bodyLines.push(output_1.output.dim(this.failedTasks.length > 0
|
|
2161
|
+
+ ? 'Tasks not run because their dependencies failed or --nx-bail=true:'
|
|
2162
|
+
+ : 'Tasks the run ended without finishing:'), '', ...unreportedTasks.map((task) => `${output_1.output.dim('-')} ${task.id}`), '');
|
|
2163
|
+
}
|
|
2164
|
+
if (this.stoppedTasks.length > 0) {
|
|
2165
|
+
bodyLines.push(output_1.output.dim('Tasks stopped before they finished:'), '', ...this.stoppedTasks.map((task) => `${output_1.output.dim('-')} ${task.id}`), '');
|
|
2166
|
+
@@ -110,34 +117,13 @@ class StaticRunOneTerminalOutputLifeCycle {
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
/**
|
|
2170
|
+
- * Tasks with a `skipped` status are never reported through `endTasks`, so
|
|
2171
|
+
- * they are derived by subtracting everything that did complete.
|
|
2172
|
+
+ * The tasks the orchestrator never reported through `endTasks`: those it
|
|
2173
|
+
+ * skipped, which it never reports, and those a run that threw part way
|
|
2174
|
+
+ * through never finished.
|
|
2175
|
+
*/
|
|
2176
|
+
- skippedTasks() {
|
|
2177
|
+
+ unreportedTasks() {
|
|
2178
|
+
return this.tasks.filter((t) => !this.allCompletedTasks.has(t.id));
|
|
2179
|
+
}
|
|
2180
|
+
- /**
|
|
2181
|
+
- * Tasks that never produced output worth printing are summarized as counts,
|
|
2182
|
+
- * with their names available behind --verbose.
|
|
2183
|
+
- */
|
|
2184
|
+
- tasksNotRunSummary() {
|
|
2185
|
+
- const skippedTasks = this.skippedTasks();
|
|
2186
|
+
- const counts = [];
|
|
2187
|
+
- if (skippedTasks.length > 0) {
|
|
2188
|
+
- counts.push(`${skippedTasks.length} skipped`);
|
|
2189
|
+
- }
|
|
2190
|
+
- if (this.stoppedTasks.length > 0) {
|
|
2191
|
+
- counts.push(`${this.stoppedTasks.length} stopped`);
|
|
2192
|
+
- }
|
|
2193
|
+
- if (counts.length === 0) {
|
|
2194
|
+
- return [];
|
|
2195
|
+
- }
|
|
2196
|
+
- const lines = [output_1.output.dim(counts.join(', '))];
|
|
2197
|
+
- if (this.printsFullOutput) {
|
|
2198
|
+
- lines.push('', ...[...skippedTasks, ...this.stoppedTasks].map((task) => `${output_1.output.dim('-')} ${task.id}`));
|
|
2199
|
+
- }
|
|
2200
|
+
- return lines;
|
|
2201
|
+
- }
|
|
2202
|
+
endTasks(taskResults) {
|
|
2203
|
+
for (let t of taskResults) {
|
|
2204
|
+
this.allCompletedTasks.set(t.task.id, t.task);
|
|
2205
|
+
diff --git a/dist/src/tasks-runner/life-cycles/store-run-information-life-cycle.js b/dist/src/tasks-runner/life-cycles/store-run-information-life-cycle.js
|
|
2206
|
+
index 55e70337fe2026cc992620d12bfa37bc99e70cd6..21b08d74572c79e0101df75f9f13a2e4712b85cd 100644
|
|
2207
|
+
--- a/dist/src/tasks-runner/life-cycles/store-run-information-life-cycle.js
|
|
2208
|
+
+++ b/dist/src/tasks-runner/life-cycles/store-run-information-life-cycle.js
|
|
2209
|
+
@@ -22,10 +22,13 @@ class StoreRunInformationLifeCycle {
|
|
2210
|
+
}
|
|
2211
|
+
endTasks(taskResults) {
|
|
2212
|
+
for (let tr of taskResults) {
|
|
2213
|
+
- if (tr.task.startTime) {
|
|
2214
|
+
+ // A worker may fail hashing before startTasks. Record its failure
|
|
2215
|
+
+ // without inventing an execution start or masking the original error.
|
|
2216
|
+
+ this.timings[tr.task.id] ??= { start: undefined, end: undefined };
|
|
2217
|
+
+ if (tr.task.startTime !== undefined) {
|
|
2218
|
+
this.timings[tr.task.id].start = new Date(tr.task.startTime).toISOString();
|
|
2219
|
+
}
|
|
2220
|
+
- if (tr.task.endTime) {
|
|
2221
|
+
+ if (tr.task.endTime !== undefined) {
|
|
2222
|
+
this.timings[tr.task.id].end = new Date(tr.task.endTime).toISOString();
|
|
2223
|
+
}
|
|
2224
|
+
else {
|
|
2225
|
+
diff --git a/dist/src/tasks-runner/life-cycles/task-history-life-cycle-old.js b/dist/src/tasks-runner/life-cycles/task-history-life-cycle-old.js
|
|
2226
|
+
index 18411f17b945ced007a0605a2b371239c205fc43..a1dfabc9a90042140de26c4b8d717a4a179a809e 100644
|
|
2227
|
+
--- a/dist/src/tasks-runner/life-cycles/task-history-life-cycle-old.js
|
|
2228
|
+
+++ b/dist/src/tasks-runner/life-cycles/task-history-life-cycle-old.js
|
|
2229
|
+
@@ -23,10 +23,16 @@ class LegacyTaskHistoryLifeCycle {
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
async endCommand() {
|
|
2233
|
+
- // Build TaskRun objects now — task.hash is guaranteed to be set by this point
|
|
2234
|
+
+ // History contains hashed execution intervals, not pre-start failures.
|
|
2235
|
+
+ // Those failures remain in run information without a fabricated hash/start.
|
|
2236
|
+
const taskRuns = [];
|
|
2237
|
+
const cacheableHashes = new Set();
|
|
2238
|
+
for (const taskResult of this.pendingResults) {
|
|
2239
|
+
+ const start = taskResult.task.startTime ?? this.startTimings[taskResult.task.id];
|
|
2240
|
+
+ delete this.startTimings[taskResult.task.id];
|
|
2241
|
+
+ if (taskResult.task.hash === undefined || start === undefined) {
|
|
2242
|
+
+ continue;
|
|
2243
|
+
+ }
|
|
2244
|
+
if (taskResult.task.cache === true) {
|
|
2245
|
+
cacheableHashes.add(taskResult.task.hash);
|
|
2246
|
+
}
|
|
2247
|
+
@@ -37,7 +43,7 @@ class LegacyTaskHistoryLifeCycle {
|
|
2248
|
+
hash: taskResult.task.hash,
|
|
2249
|
+
code: taskResult.code.toString(),
|
|
2250
|
+
status: taskResult.status,
|
|
2251
|
+
- start: (taskResult.task.startTime ?? this.startTimings[taskResult.task.id]).toString(),
|
|
2252
|
+
+ start: start.toString(),
|
|
2253
|
+
end: (taskResult.task.endTime ?? new Date().getTime()).toString(),
|
|
2254
|
+
});
|
|
2255
|
+
}
|
|
2256
|
+
diff --git a/dist/src/tasks-runner/life-cycles/task-history-life-cycle.js b/dist/src/tasks-runner/life-cycles/task-history-life-cycle.js
|
|
2257
|
+
index 4824a4ad117bec083da7502891f88651dba1b48f..ea27b2edf6dd505db797ca590c0d0d9471a980cf 100644
|
|
2258
|
+
--- a/dist/src/tasks-runner/life-cycles/task-history-life-cycle.js
|
|
2259
|
+
+++ b/dist/src/tasks-runner/life-cycles/task-history-life-cycle.js
|
|
2260
|
+
@@ -48,18 +48,23 @@ class TaskHistoryLifeCycle {
|
|
2261
|
+
if (!this.taskHistory) {
|
|
2262
|
+
return;
|
|
2263
|
+
}
|
|
2264
|
+
- // Build TaskRun objects now — task.hash is guaranteed to be set by this point
|
|
2265
|
+
+ // History contains hashed execution intervals, not pre-start failures.
|
|
2266
|
+
+ // Those failures remain in run information without a fabricated hash/start.
|
|
2267
|
+
for (const { task, code, status } of pendingResults) {
|
|
2268
|
+
+ const start = task.startTime ?? this.startTimings[task.id];
|
|
2269
|
+
+ delete this.startTimings[task.id];
|
|
2270
|
+
+ if (task.hash === undefined || start === undefined) {
|
|
2271
|
+
+ continue;
|
|
2272
|
+
+ }
|
|
2273
|
+
this.taskRuns.set(task.hash, {
|
|
2274
|
+
hash: task.hash,
|
|
2275
|
+
target: task.target,
|
|
2276
|
+
code,
|
|
2277
|
+
status,
|
|
2278
|
+
- start: task.startTime ?? this.startTimings[task.id],
|
|
2279
|
+
+ start,
|
|
2280
|
+
end: task.endTime ?? Date.now(),
|
|
2281
|
+
cacheable: task.cache === true,
|
|
2282
|
+
});
|
|
2283
|
+
- delete this.startTimings[task.id];
|
|
2284
|
+
}
|
|
2285
|
+
const runs = [];
|
|
2286
|
+
// Only check for flaky tasks among cacheable tasks
|
|
2287
|
+
diff --git a/dist/src/tasks-runner/life-cycles/task-profiling-life-cycle.js b/dist/src/tasks-runner/life-cycles/task-profiling-life-cycle.js
|
|
2288
|
+
index d806bce7abd862fca0e73289d04c01d223f4a1e5..bffb669ffb511ec469b9bf62a29726b5c5aedcfe 100644
|
|
2289
|
+
--- a/dist/src/tasks-runner/life-cycles/task-profiling-life-cycle.js
|
|
2290
|
+
+++ b/dist/src/tasks-runner/life-cycles/task-profiling-life-cycle.js
|
|
2291
|
+
@@ -22,10 +22,11 @@ class TaskProfilingLifeCycle {
|
|
2292
|
+
}
|
|
2293
|
+
endTasks(taskResults, metadata) {
|
|
2294
|
+
for (let tr of taskResults) {
|
|
2295
|
+
- if (tr.task.startTime) {
|
|
2296
|
+
+ this.timings[tr.task.id] ??= { perfStart: undefined, perfEnd: undefined };
|
|
2297
|
+
+ if (tr.task.startTime !== undefined) {
|
|
2298
|
+
this.timings[tr.task.id].perfStart = tr.task.startTime;
|
|
2299
|
+
}
|
|
2300
|
+
- if (tr.task.endTime) {
|
|
2301
|
+
+ if (tr.task.endTime !== undefined) {
|
|
2302
|
+
this.timings[tr.task.id].perfEnd = tr.task.endTime;
|
|
2303
|
+
}
|
|
2304
|
+
else {
|
|
2305
|
+
@@ -41,6 +42,10 @@ class TaskProfilingLifeCycle {
|
|
2306
|
+
recordTaskCompletions(tasks, { groupId }) {
|
|
2307
|
+
for (const { task, status } of tasks) {
|
|
2308
|
+
const { perfStart, perfEnd } = this.timings[task.id];
|
|
2309
|
+
+ // A failure before execution has no executed profile interval.
|
|
2310
|
+
+ if (perfStart === undefined) {
|
|
2311
|
+
+ continue;
|
|
2312
|
+
+ }
|
|
2313
|
+
this.profile.push({
|
|
2314
|
+
name: task.id,
|
|
2315
|
+
cat: Object.values(task.target).join(','),
|
|
2316
|
+
diff --git a/dist/src/tasks-runner/life-cycles/task-timings-life-cycle.js b/dist/src/tasks-runner/life-cycles/task-timings-life-cycle.js
|
|
2317
|
+
index ab0d47a6d12a4ce8cb6b140364b1ada923fab95a..894bbfc883a7108a9fdd118691d6e2bcb69a06da 100644
|
|
2318
|
+
--- a/dist/src/tasks-runner/life-cycles/task-timings-life-cycle.js
|
|
2319
|
+
+++ b/dist/src/tasks-runner/life-cycles/task-timings-life-cycle.js
|
|
2320
|
+
@@ -15,10 +15,11 @@ class TaskTimingsLifeCycle {
|
|
2321
|
+
}
|
|
2322
|
+
endTasks(taskResults) {
|
|
2323
|
+
for (let tr of taskResults) {
|
|
2324
|
+
- if (tr.task.startTime) {
|
|
2325
|
+
+ this.timings[tr.task.id] ??= { start: undefined, end: undefined };
|
|
2326
|
+
+ if (tr.task.startTime !== undefined) {
|
|
2327
|
+
this.timings[tr.task.id].start = tr.task.startTime;
|
|
2328
|
+
}
|
|
2329
|
+
- if (tr.task.endTime) {
|
|
2330
|
+
+ if (tr.task.endTime !== undefined) {
|
|
2331
|
+
this.timings[tr.task.id].end = tr.task.endTime;
|
|
2332
|
+
}
|
|
2333
|
+
else {
|
|
2334
|
+
@@ -31,7 +32,7 @@ class TaskTimingsLifeCycle {
|
|
2335
|
+
const timings = {};
|
|
2336
|
+
Object.keys(this.timings).forEach((p) => {
|
|
2337
|
+
const t = this.timings[p];
|
|
2338
|
+
- timings[p] = t.end ? t.end - t.start : null;
|
|
2339
|
+
+ timings[p] = t.start !== undefined && t.end !== undefined ? t.end - t.start : null;
|
|
2340
|
+
});
|
|
2341
|
+
console.log(JSON.stringify(timings, null, 2));
|
|
2342
|
+
}
|
|
2343
|
+
diff --git a/dist/src/tasks-runner/run-command.js b/dist/src/tasks-runner/run-command.js
|
|
2344
|
+
index 4e64afa4fb985191ac8bc0e31a1e380bcecf9427..14723620cb7d8094bff0eb70214442dd39fe9131 100644
|
|
2345
|
+
--- a/dist/src/tasks-runner/run-command.js
|
|
2346
|
+
+++ b/dist/src/tasks-runner/run-command.js
|
|
2347
|
+
@@ -41,6 +41,7 @@ const task_profiling_life_cycle_1 = require("./life-cycles/task-profiling-life-c
|
|
2348
|
+
const performance_life_cycle_1 = require("./life-cycles/performance-life-cycle");
|
|
2349
|
+
const performance_report_1 = require("./life-cycles/performance-report");
|
|
2350
|
+
const task_results_life_cycle_1 = require("./life-cycles/task-results-life-cycle");
|
|
2351
|
+
+const default_tasks_runner_1 = require("./default-tasks-runner");
|
|
2352
|
+
const task_telemetry_life_cycle_1 = require("./life-cycles/task-telemetry-life-cycle");
|
|
2353
|
+
const task_timings_life_cycle_1 = require("./life-cycles/task-timings-life-cycle");
|
|
2354
|
+
const tui_summary_life_cycle_1 = require("./life-cycles/tui-summary-life-cycle");
|
|
2355
|
+
@@ -373,8 +374,9 @@ async function runCommandForTasks(projectsToRun, currentProjectGraph, { nxJson }
|
|
2356
|
+
const initiatingTasks = tasks.filter((t) => projectNameSet.has(t.target.project) &&
|
|
2357
|
+
nxArgs.targets.includes(t.target.target));
|
|
2358
|
+
const { lifeCycle, renderIsDone, printSummary, restoreTerminal } = await getTerminalOutputLifeCycle(initiatingProject, initiatingTasks, projectNames, tasks, taskGraph, nxArgs, nxJson, overrides);
|
|
2359
|
+
+ const runnerCompletion = { bailed: false, interrupted: false };
|
|
2360
|
+
try {
|
|
2361
|
+
- const taskResults = await invokeTasksRunner({
|
|
2362
|
+
+ const { taskResults, skippedTaskIds } = await runTasks({
|
|
2363
|
+
tasks,
|
|
2364
|
+
projectGraph,
|
|
2365
|
+
taskGraph,
|
|
2366
|
+
@@ -384,7 +386,7 @@ async function runCommandForTasks(projectsToRun, currentProjectGraph, { nxJson }
|
|
2367
|
+
loadDotEnvFiles: extraOptions.loadDotEnvFiles,
|
|
2368
|
+
initiatingProject,
|
|
2369
|
+
initiatingTasks,
|
|
2370
|
+
- });
|
|
2371
|
+
+ }, runnerCompletion);
|
|
2372
|
+
await renderIsDone.finally(() => restoreTerminal?.());
|
|
2373
|
+
if (printSummary) {
|
|
2374
|
+
printSummary();
|
|
2375
|
+
@@ -395,7 +397,7 @@ async function runCommandForTasks(projectsToRun, currentProjectGraph, { nxJson }
|
|
2376
|
+
logger_1.logger.log((0, nx_key_1.createNxKeyLicenseeInformation)(nxKey));
|
|
2377
|
+
return {
|
|
2378
|
+
taskResults,
|
|
2379
|
+
- completed: didCommandComplete(tasks, taskResults),
|
|
2380
|
+
+ completed: didCommandComplete(tasks, taskResults, skippedTaskIds, runnerCompletion),
|
|
2381
|
+
};
|
|
2382
|
+
}
|
|
2383
|
+
catch (e) {
|
|
2384
|
+
@@ -424,18 +426,22 @@ async function printConfigureAiAgentsDisclaimer() {
|
|
2385
|
+
// Silently ignore errors
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
-function didCommandComplete(tasks, taskResults) {
|
|
2389
|
+
- if (tasks.length === 0)
|
|
2390
|
+
+function didCommandComplete(tasks, taskResults, skippedTaskIds, runnerCompletion) {
|
|
2391
|
+
+ if (runnerCompletion.interrupted)
|
|
2392
|
+
+ return false;
|
|
2393
|
+
+ const results = Object.values(taskResults);
|
|
2394
|
+
+ // Bail can stop active tasks during cleanup and leaves pending tasks
|
|
2395
|
+
+ // without statuses. Only the orchestrator knows that it bailed, rather
|
|
2396
|
+
+ // than being interrupted by a signal or forced TUI shutdown.
|
|
2397
|
+
+ if (runnerCompletion.bailed && results.some((result) => result.status === 'failure'))
|
|
2398
|
+
return true;
|
|
2399
|
+
+ if (results.some((result) => result.status === 'stopped'))
|
|
2400
|
+
+ return false;
|
|
2401
|
+
for (const task of tasks) {
|
|
2402
|
+
- if (!task.continuous) {
|
|
2403
|
+
- // Discrete task must have a result (was started and finished)
|
|
2404
|
+
- if (!taskResults[task.id])
|
|
2405
|
+
- return false;
|
|
2406
|
+
- }
|
|
2407
|
+
+ if (!task.continuous && !taskResults[task.id] && !skippedTaskIds.has(task.id))
|
|
2408
|
+
+ return false;
|
|
2409
|
+
}
|
|
2410
|
+
- // Any stopped task means the run was interrupted
|
|
2411
|
+
- return !Object.values(taskResults).some((r) => r.status === 'stopped');
|
|
2412
|
+
+ return true;
|
|
2413
|
+
}
|
|
2414
|
+
async function ensureWorkspaceIsInSyncAndGetGraphs(projectGraph, nxJson, projectNames, nxArgs, overrides, extraTargetDependencies, extraOptions) {
|
|
2415
|
+
let taskGraph = createTaskGraphAndRunValidations(projectGraph, extraTargetDependencies ?? {}, projectNames, nxArgs, overrides, extraOptions);
|
|
2416
|
+
@@ -659,7 +665,16 @@ function setEnvVarsBasedOnArgs(nxArgs, loadDotEnvFiles) {
|
|
2417
|
+
process.env.NX_LOAD_DOT_ENV_FILES = 'true';
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
-async function invokeTasksRunner({ tasks, projectGraph, taskGraph, lifeCycle, nxJson, nxArgs, loadDotEnvFiles, initiatingProject, initiatingTasks, }) {
|
|
2421
|
+
+/**
|
|
2422
|
+
+ * Runs the tasks and returns what every life cycle saw end, unchanged from
|
|
2423
|
+
+ * what Nx has always returned: a task the orchestrator skips because a
|
|
2424
|
+
+ * dependency failed reaches no life cycle, so it has no result here, and
|
|
2425
|
+
+ * callers that replay Nx's skip rule over these results keep working.
|
|
2426
|
+
+ */
|
|
2427
|
+
+async function invokeTasksRunner(args) {
|
|
2428
|
+
+ return (await runTasks(args)).taskResults;
|
|
2429
|
+
+}
|
|
2430
|
+
+async function runTasks({ tasks, projectGraph, taskGraph, lifeCycle, nxJson, nxArgs, loadDotEnvFiles, initiatingProject, initiatingTasks, }, runnerCompletion) {
|
|
2431
|
+
setEnvVarsBasedOnArgs(nxArgs, loadDotEnvFiles);
|
|
2432
|
+
// this needs to be done before we start to run the tasks
|
|
2433
|
+
const taskDetails = (0, hash_task_1.getTaskDetails)();
|
|
2434
|
+
@@ -674,10 +689,11 @@ async function invokeTasksRunner({ tasks, projectGraph, taskGraph, lifeCycle, nx
|
|
2435
|
+
...constructLifeCycles(lifeCycle, taskGraph, nxJson, nxArgs.skipNxCache),
|
|
2436
|
+
taskResultsLifecycle,
|
|
2437
|
+
]);
|
|
2438
|
+
- let promiseOrObservable = tasksRunner(tasks, {
|
|
2439
|
+
+ const options = {
|
|
2440
|
+
...runnerOptions,
|
|
2441
|
+
lifeCycle: compositedLifeCycle,
|
|
2442
|
+
- }, {
|
|
2443
|
+
+ };
|
|
2444
|
+
+ const context = {
|
|
2445
|
+
initiatingProject,
|
|
2446
|
+
initiatingTasks,
|
|
2447
|
+
projectGraph,
|
|
2448
|
+
@@ -735,12 +751,24 @@ async function invokeTasksRunner({ tasks, projectGraph, taskGraph, lifeCycle, nx
|
|
2449
|
+
},
|
|
2450
|
+
},
|
|
2451
|
+
daemon: client_1.daemonClient,
|
|
2452
|
+
- });
|
|
2453
|
+
+ };
|
|
2454
|
+
+ // Completion provenance is passed only to Nx's own runner, never to a
|
|
2455
|
+
+ // custom runner or through the public task-results map.
|
|
2456
|
+
+ let promiseOrObservable = tasksRunner === default_tasks_runner_1.defaultTasksRunner
|
|
2457
|
+
+ ? tasksRunner(tasks, options, context, runnerCompletion)
|
|
2458
|
+
+ : tasksRunner(tasks, options, context);
|
|
2459
|
+
if (promiseOrObservable.subscribe) {
|
|
2460
|
+
promiseOrObservable = convertObservableToPromise(promiseOrObservable);
|
|
2461
|
+
}
|
|
2462
|
+
- await promiseOrObservable;
|
|
2463
|
+
- return taskResultsLifecycle.getTaskResults();
|
|
2464
|
+
+ const statuses = await promiseOrObservable;
|
|
2465
|
+
+ // Only the runner's own answer knows the tasks it skipped because a
|
|
2466
|
+
+ // dependency failed; runCommandForTasks needs them to tell an ordinary
|
|
2467
|
+
+ // failure from an interrupted run. A custom runner's answer is typed `any`,
|
|
2468
|
+
+ // so a runner that answers nothing names none.
|
|
2469
|
+
+ const skippedTaskIds = new Set(Object.entries(statuses ?? {})
|
|
2470
|
+
+ .filter(([, status]) => status === 'skipped')
|
|
2471
|
+
+ .map(([taskId]) => taskId));
|
|
2472
|
+
+ return { taskResults: taskResultsLifecycle.getTaskResults(), skippedTaskIds };
|
|
2473
|
+
}
|
|
2474
|
+
function constructLifeCycles(lifeCycle, taskGraph, nxJson, skipNxCache) {
|
|
2475
|
+
const lifeCycles = [];
|
|
2476
|
+
diff --git a/dist/src/tasks-runner/task-graph-utils.d.ts b/dist/src/tasks-runner/task-graph-utils.d.ts
|
|
2477
|
+
index 2ba00c254450c7d3b93e288b1f0bb28361ef8cf3..5f76eee85731e34fbf1edc4ebc0c7593dd2abdbd 100644
|
|
2478
|
+
--- a/dist/src/tasks-runner/task-graph-utils.d.ts
|
|
2479
|
+
+++ b/dist/src/tasks-runner/task-graph-utils.d.ts
|
|
2480
|
+
@@ -10,7 +10,10 @@ export declare function findCycle(graph: {
|
|
2481
|
+
}): string[] | null;
|
|
2482
|
+
/**
|
|
2483
|
+
* This function finds all cycles in the graph.
|
|
2484
|
+
- * @returns a list of unique task ids in all cycles found, or null if no cycle is found.
|
|
2485
|
+
+ * @returns the unique task ids that lie on a cycle (every task of a strongly connected component of more than one
|
|
2486
|
+
+ * task, and every task that depends on itself), or null if there is none. A task that merely leads to a cycle is not
|
|
2487
|
+
+ * on it. The answer is a property of the graph, not of the order of its keys or of the tasks around it: this is what
|
|
2488
|
+
+ * dummy-task flattening reads, and a different answer there gives a task different dependencies.
|
|
2489
|
+
*/
|
|
2490
|
+
export declare function findCycles(graph: {
|
|
2491
|
+
dependencies: Record<string, string[]>;
|
|
2492
|
+
diff --git a/dist/src/tasks-runner/task-graph-utils.js b/dist/src/tasks-runner/task-graph-utils.js
|
|
2493
|
+
index 42dc80a7a3551c9fe0737f39388670e9a7a475dd..99ac4a74f9cec802360f365d7ca8fc344412d53b 100644
|
|
2494
|
+
--- a/dist/src/tasks-runner/task-graph-utils.js
|
|
2495
|
+
+++ b/dist/src/tasks-runner/task-graph-utils.js
|
|
2496
|
+
@@ -42,18 +42,66 @@ function findCycle(graph) {
|
|
2497
|
+
}
|
|
2498
|
+
/**
|
|
2499
|
+
* This function finds all cycles in the graph.
|
|
2500
|
+
- * @returns a list of unique task ids in all cycles found, or null if no cycle is found.
|
|
2501
|
+
+ * @returns the unique task ids that lie on a cycle (every task of a strongly connected component of more than one
|
|
2502
|
+
+ * task, and every task that depends on itself), or null if there is none. A task that merely leads to a cycle is not
|
|
2503
|
+
+ * on it. The answer is a property of the graph, not of the order of its keys or of the tasks around it: this is what
|
|
2504
|
+
+ * dummy-task flattening reads, and a different answer there gives a task different dependencies.
|
|
2505
|
+
*/
|
|
2506
|
+
function findCycles(graph) {
|
|
2507
|
+
- const visited = {};
|
|
2508
|
+
+ const edges = (id) => [
|
|
2509
|
+
+ ...(graph.dependencies[id] ?? []),
|
|
2510
|
+
+ ...(graph.continuousDependencies?.[id] ?? []),
|
|
2511
|
+
+ ];
|
|
2512
|
+
+ // Tarjan's algorithm, iterative so a deep dependency chain cannot overflow the stack.
|
|
2513
|
+
+ const order = new Map();
|
|
2514
|
+
+ const lowest = new Map();
|
|
2515
|
+
+ const open = [];
|
|
2516
|
+
+ const isOpen = new Set();
|
|
2517
|
+
const cycles = new Set();
|
|
2518
|
+
- for (const t of Object.keys(graph.dependencies)) {
|
|
2519
|
+
- visited[t] = false;
|
|
2520
|
+
- }
|
|
2521
|
+
- for (const t of Object.keys(graph.dependencies)) {
|
|
2522
|
+
- const cycle = _findCycle(graph, t, visited, [t]);
|
|
2523
|
+
- if (cycle) {
|
|
2524
|
+
- cycle.forEach((t) => cycles.add(t));
|
|
2525
|
+
+ const enter = (id) => {
|
|
2526
|
+
+ order.set(id, order.size);
|
|
2527
|
+
+ lowest.set(id, order.get(id));
|
|
2528
|
+
+ open.push(id);
|
|
2529
|
+
+ isOpen.add(id);
|
|
2530
|
+
+ return { id, edges: edges(id), next: 0 };
|
|
2531
|
+
+ };
|
|
2532
|
+
+ for (const start of Object.keys(graph.dependencies)) {
|
|
2533
|
+
+ if (order.has(start)) {
|
|
2534
|
+
+ continue;
|
|
2535
|
+
+ }
|
|
2536
|
+
+ const frames = [enter(start)];
|
|
2537
|
+
+ while (frames.length > 0) {
|
|
2538
|
+
+ const frame = frames[frames.length - 1];
|
|
2539
|
+
+ if (frame.next < frame.edges.length) {
|
|
2540
|
+
+ const d = frame.edges[frame.next++];
|
|
2541
|
+
+ if (d === frame.id) {
|
|
2542
|
+
+ cycles.add(d);
|
|
2543
|
+
+ }
|
|
2544
|
+
+ if (!order.has(d)) {
|
|
2545
|
+
+ frames.push(enter(d));
|
|
2546
|
+
+ }
|
|
2547
|
+
+ else if (isOpen.has(d)) {
|
|
2548
|
+
+ lowest.set(frame.id, Math.min(lowest.get(frame.id), order.get(d)));
|
|
2549
|
+
+ }
|
|
2550
|
+
+ continue;
|
|
2551
|
+
+ }
|
|
2552
|
+
+ frames.pop();
|
|
2553
|
+
+ const caller = frames[frames.length - 1];
|
|
2554
|
+
+ if (caller) {
|
|
2555
|
+
+ lowest.set(caller.id, Math.min(lowest.get(caller.id), lowest.get(frame.id)));
|
|
2556
|
+
+ }
|
|
2557
|
+
+ if (lowest.get(frame.id) === order.get(frame.id)) {
|
|
2558
|
+
+ const component = [];
|
|
2559
|
+
+ let member;
|
|
2560
|
+
+ do {
|
|
2561
|
+
+ member = open.pop();
|
|
2562
|
+
+ isOpen.delete(member);
|
|
2563
|
+
+ component.push(member);
|
|
2564
|
+
+ } while (member !== frame.id);
|
|
2565
|
+
+ if (component.length > 1) {
|
|
2566
|
+
+ component.forEach((id) => cycles.add(id));
|
|
2567
|
+
+ }
|
|
2568
|
+
+ }
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
return cycles.size ? cycles : null;
|
|
2572
|
+
diff --git a/dist/src/tasks-runner/task-orchestrator.d.ts b/dist/src/tasks-runner/task-orchestrator.d.ts
|
|
2573
|
+
index 6d3dd021b050be5c74803555b361b6502f9693c7..81e7fa2f866eb22eeabcc8d2802aec5ee7228d57 100644
|
|
2574
|
+
--- a/dist/src/tasks-runner/task-orchestrator.d.ts
|
|
2575
|
+
+++ b/dist/src/tasks-runner/task-orchestrator.d.ts
|
|
2576
|
+
@@ -57,11 +57,14 @@ export declare class TaskOrchestrator {
|
|
2577
|
+
private continuousTaskExitHandled;
|
|
2578
|
+
private cleanupPromise;
|
|
2579
|
+
private signalHandlers;
|
|
2580
|
+
+ private taskOutputLeases;
|
|
2581
|
+
+ private continuousStartupLeases;
|
|
2582
|
+
constructor(hasher: TaskHasher, initiatingProject: string | undefined, initiatingTasks: Task[], projectGraph: ProjectGraph, taskGraph: TaskGraph, nxJson: NxJsonConfiguration, options: NxArgs & DefaultTasksRunnerOptions, bail: boolean, daemon: DaemonClient, outputStyle: string, fullTaskGraph?: TaskGraph);
|
|
2583
|
+
init(): Promise<void>;
|
|
2584
|
+
run(): Promise<{
|
|
2585
|
+
[k: string]: TaskStatus;
|
|
2586
|
+
}>;
|
|
2587
|
+
+ private runTasks;
|
|
2588
|
+
nextBatch(): Batch;
|
|
2589
|
+
/**
|
|
2590
|
+
* Coordinator loop. All batch operations (hashing, cache resolution)
|
|
2591
|
+
@@ -105,12 +108,9 @@ export declare class TaskOrchestrator {
|
|
2592
|
+
* cache fetch + lifecycle to the public method. Returns true if any
|
|
2593
|
+
* tasks were resolved.
|
|
2594
|
+
*
|
|
2595
|
+
- * The coordinator relies on this running unconditionally (when cache
|
|
2596
|
+
- * is enabled): tasks dispatched in step 5 via runTaskDirectly skip
|
|
2597
|
+
- * their own cache lookup on the assumption that this has already
|
|
2598
|
+
- * confirmed them as misses. Excluding cacheMissedHashes preserves that
|
|
2599
|
+
- * invariant — every dispatched hash was queried exactly once — but
|
|
2600
|
+
- * don't add other length-based bails.
|
|
2601
|
+
+ * The coordinator probes a missing key once while it is queued. Output
|
|
2602
|
+
+ * targets recheck after reacquiring their cross-client writer lease: a
|
|
2603
|
+
+ * foreign producer may have completed since the coordinator's lookup.
|
|
2604
|
+
*/
|
|
2605
|
+
private resolveCachedTasksBulk;
|
|
2606
|
+
/**
|
|
2607
|
+
@@ -124,6 +124,7 @@ export declare class TaskOrchestrator {
|
|
2608
|
+
private applyBatchCachedResults;
|
|
2609
|
+
private hashBatchTasks;
|
|
2610
|
+
applyFromCacheOrRunBatch(doNotSkipCache: boolean, batch: Batch, groupId: number): Promise<TaskResult[]>;
|
|
2611
|
+
+ private runBatchUnderOutputLease;
|
|
2612
|
+
private runBatch;
|
|
2613
|
+
/**
|
|
2614
|
+
* Rendering a batch's output must never change the batch's results. A throw
|
|
2615
|
+
@@ -202,12 +203,11 @@ export declare class TaskOrchestrator {
|
|
2616
|
+
* don't actually compete for parallelism.
|
|
2617
|
+
*/
|
|
2618
|
+
resolveCachedTasks(doNotSkipCache: boolean, tasks: Task[], groupId: number): Promise<TaskResult[]>;
|
|
2619
|
+
+ private resolveCachedTasksUnderOutputLease;
|
|
2620
|
+
/**
|
|
2621
|
+
* Fire a discrete-task worker and track it in pendingDiscreteWorkers until
|
|
2622
|
+
- * it settles. Uses runTaskDirectly (not applyFromCacheOrRun*) because
|
|
2623
|
+
- * resolveCachedTasksBulk already confirmed this task is a cache miss —
|
|
2624
|
+
- * another lookup would re-query the DB and (for Nx Cloud users) repeat
|
|
2625
|
+
- * the remote HTTP retrieval.
|
|
2626
|
+
+ * it settles. Output-producing tasks recheck the cache after taking their
|
|
2627
|
+
+ * writer lease; tasks without outputs use the coordinator's confirmed miss.
|
|
2628
|
+
*/
|
|
2629
|
+
private dispatchDiscreteWorker;
|
|
2630
|
+
/**
|
|
2631
|
+
@@ -219,14 +219,16 @@ export declare class TaskOrchestrator {
|
|
2632
|
+
*/
|
|
2633
|
+
private handleDiscreteWorkerFailure;
|
|
2634
|
+
/**
|
|
2635
|
+
- * Spawn and wait on a task's child process, unconditionally — no cache
|
|
2636
|
+
- * lookup. Callers must have already confirmed the task is a cache miss
|
|
2637
|
+
- * (or disabled caching entirely).
|
|
2638
|
+
+ * Own a target's output through cache recheck, execution and capture.
|
|
2639
|
+
+ * Targets without outputs retain the coordinator's confirmed-miss fast path.
|
|
2640
|
+
*/
|
|
2641
|
+
runTaskDirectly(doNotSkipCache: boolean, task: Task, groupId: number): Promise<TaskResult>;
|
|
2642
|
+
+ private runTaskUnderOutputLease;
|
|
2643
|
+
private runTask;
|
|
2644
|
+
private runTaskInForkedProcess;
|
|
2645
|
+
startContinuousTask(task: Task, groupId: number): Promise<RunningTask | SharedRunningTask>;
|
|
2646
|
+
+ private startContinuousTaskUnderStartupLease;
|
|
2647
|
+
+ private startOwnedContinuousTask;
|
|
2648
|
+
private preRunSteps;
|
|
2649
|
+
private postRunSteps;
|
|
2650
|
+
private scheduleNextTasksAndReleaseThreads;
|
|
2651
|
+
diff --git a/dist/src/tasks-runner/task-orchestrator.js b/dist/src/tasks-runner/task-orchestrator.js
|
|
2652
|
+
index 0b446cbce811319a741165e42a0100e0570e0a2f..1fbd5f47637dd6fb1a7e7b073d062069df31384c 100644
|
|
2653
|
+
--- a/dist/src/tasks-runner/task-orchestrator.js
|
|
2654
|
+
+++ b/dist/src/tasks-runner/task-orchestrator.js
|
|
2655
|
+
@@ -29,6 +29,7 @@ const shared_running_task_1 = require("./running-tasks/shared-running-task");
|
|
2656
|
+
const task_env_1 = require("./task-env");
|
|
2657
|
+
const tasks_schedule_1 = require("./tasks-schedule");
|
|
2658
|
+
const utils_1 = require("./utils");
|
|
2659
|
+
+const { TaskOutputLeases } = require("./task-output-lease");
|
|
2660
|
+
/**
|
|
2661
|
+
* Resolve a batch executor's per-task result to a TaskStatus. Prefers an
|
|
2662
|
+
* explicit `status` from the executor; falls back to the `success` boolean
|
|
2663
|
+
@@ -79,11 +80,9 @@ class TaskOrchestrator {
|
|
2664
|
+
// underlying real tasks become the anchors.
|
|
2665
|
+
this.initializingTaskIds = (0, utils_1.expandInitiatingTasksThroughNoop)(this.initiatingTasks, this.taskGraph, this.projectGraph);
|
|
2666
|
+
this.processedTasks = new Map();
|
|
2667
|
+
- // Hashes confirmed absent from the cache this run. A confirmed miss can
|
|
2668
|
+
- // only become a hit when the task itself runs — and then it leaves the
|
|
2669
|
+
- // schedule — so a missed hash never needs re-querying. Without this, a
|
|
2670
|
+
- // miss waiting for a worker slot is re-queried (including the remote
|
|
2671
|
+
- // retrieval) on every coordinator cycle.
|
|
2672
|
+
+ // Probe a queued miss once, not on every coordinator wakeup.
|
|
2673
|
+
+ // Output producers recheck after taking their cross-client lease: a
|
|
2674
|
+
+ // foreign client can populate the key while this worker is queued.
|
|
2675
|
+
this.cacheMissedHashes = new Set();
|
|
2676
|
+
this.completedTasks = new Map();
|
|
2677
|
+
this.waitingForTasks = [];
|
|
2678
|
+
@@ -106,6 +105,9 @@ class TaskOrchestrator {
|
|
2679
|
+
this.continuousTaskExitHandled = new Map();
|
|
2680
|
+
this.cleanupPromise = null;
|
|
2681
|
+
this.signalHandlers = [];
|
|
2682
|
+
+ const leaseParallelism = getThreadPoolSize(this.options, this.taskGraph).total;
|
|
2683
|
+
+ this.taskOutputLeases = new TaskOutputLeases(leaseParallelism, this.taskInvocationTracker, "output");
|
|
2684
|
+
+ this.continuousStartupLeases = new TaskOutputLeases(leaseParallelism, this.taskInvocationTracker, "continuous-startup");
|
|
2685
|
+
}
|
|
2686
|
+
async init() {
|
|
2687
|
+
this.setupSignalHandlers();
|
|
2688
|
+
@@ -125,6 +127,20 @@ class TaskOrchestrator {
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
async run() {
|
|
2692
|
+
+ try {
|
|
2693
|
+
+ return await this.runTasks();
|
|
2694
|
+
+ }
|
|
2695
|
+
+ finally {
|
|
2696
|
+
+ try {
|
|
2697
|
+
+ await this.cleanup();
|
|
2698
|
+
+ await this.dispose();
|
|
2699
|
+
+ }
|
|
2700
|
+
+ finally {
|
|
2701
|
+
+ await Promise.all([this.taskOutputLeases.close(), this.continuousStartupLeases.close()]);
|
|
2702
|
+
+ }
|
|
2703
|
+
+ }
|
|
2704
|
+
+ }
|
|
2705
|
+
+ async runTasks() {
|
|
2706
|
+
await this.init();
|
|
2707
|
+
perf_hooks_1.performance.mark('task-execution:start');
|
|
2708
|
+
const { discrete, continuous, total } = getThreadPoolSize(this.options, this.taskGraph);
|
|
2709
|
+
@@ -159,8 +175,6 @@ class TaskOrchestrator {
|
|
2710
|
+
if (!this.stopRequested) {
|
|
2711
|
+
this.cache.removeOldCacheRecords();
|
|
2712
|
+
}
|
|
2713
|
+
- await this.cleanup();
|
|
2714
|
+
- await this.dispose();
|
|
2715
|
+
// Public API (defaultTasksRunner) returns a plain object keyed by
|
|
2716
|
+
// task id. Internal state is a Map for faster lookup.
|
|
2717
|
+
return Object.fromEntries(this.completedTasks);
|
|
2718
|
+
@@ -413,12 +427,9 @@ class TaskOrchestrator {
|
|
2719
|
+
* cache fetch + lifecycle to the public method. Returns true if any
|
|
2720
|
+
* tasks were resolved.
|
|
2721
|
+
*
|
|
2722
|
+
- * The coordinator relies on this running unconditionally (when cache
|
|
2723
|
+
- * is enabled): tasks dispatched in step 5 via runTaskDirectly skip
|
|
2724
|
+
- * their own cache lookup on the assumption that this has already
|
|
2725
|
+
- * confirmed them as misses. Excluding cacheMissedHashes preserves that
|
|
2726
|
+
- * invariant — every dispatched hash was queried exactly once — but
|
|
2727
|
+
- * don't add other length-based bails.
|
|
2728
|
+
+ * The coordinator probes a missing key once while it is queued. Output
|
|
2729
|
+
+ * targets recheck after reacquiring their cross-client writer lease: a
|
|
2730
|
+
+ * foreign producer may have completed since the coordinator's lookup.
|
|
2731
|
+
*/
|
|
2732
|
+
async resolveCachedTasksBulk() {
|
|
2733
|
+
const { scheduledTasks } = this.tasksSchedule.getAllScheduledTasks();
|
|
2734
|
+
@@ -514,6 +525,13 @@ class TaskOrchestrator {
|
|
2735
|
+
await (0, hash_task_1.hashTasks)(this.hasher, this.projectGraph, this.fullTaskGraph, perTaskEnvs, this.taskDetails, tasks);
|
|
2736
|
+
}
|
|
2737
|
+
async applyFromCacheOrRunBatch(doNotSkipCache, batch, groupId) {
|
|
2738
|
+
+ const tasks = Object.values(batch.taskGraph.tasks);
|
|
2739
|
+
+ return this.taskOutputLeases.withTasks(tasks, async () => {
|
|
2740
|
+
+ for (const task of tasks) this.cacheMissedHashes.delete(task.hash);
|
|
2741
|
+
+ return this.runBatchUnderOutputLease(doNotSkipCache, batch, groupId);
|
|
2742
|
+
+ });
|
|
2743
|
+
+ }
|
|
2744
|
+
+ async runBatchUnderOutputLease(doNotSkipCache, batch, groupId) {
|
|
2745
|
+
const applyFromCacheOrRunBatchStart = perf_hooks_1.performance.mark('TaskOrchestrator-apply-from-cache-or-run-batch:start');
|
|
2746
|
+
const taskEntries = Object.entries(batch.taskGraph.tasks);
|
|
2747
|
+
const tasks = taskEntries.map(([, task]) => task);
|
|
2748
|
+
@@ -571,7 +589,7 @@ class TaskOrchestrator {
|
|
2749
|
+
const tasksCompleted = taskEntries.filter(([taskId]) => this.completedTasks.has(taskId));
|
|
2750
|
+
// Batch is still not done, run it again
|
|
2751
|
+
if (tasksCompleted.length !== taskEntries.length) {
|
|
2752
|
+
- await this.applyFromCacheOrRunBatch(doNotSkipCache, {
|
|
2753
|
+
+ await this.runBatchUnderOutputLease(doNotSkipCache, {
|
|
2754
|
+
id: batch.id,
|
|
2755
|
+
executorName: batch.executorName,
|
|
2756
|
+
taskGraph: (0, utils_1.removeTasksFromTaskGraph)(batch.taskGraph, tasksCompleted.map(([taskId]) => taskId)),
|
|
2757
|
+
@@ -810,6 +828,20 @@ class TaskOrchestrator {
|
|
2758
|
+
* don't actually compete for parallelism.
|
|
2759
|
+
*/
|
|
2760
|
+
async resolveCachedTasks(doNotSkipCache, tasks, groupId) {
|
|
2761
|
+
+ if (!doNotSkipCache || tasks.length === 0) return [];
|
|
2762
|
+
+ // Hold only one independent target while resolving it. Acquiring a set
|
|
2763
|
+
+ // of unrelated cache-hit leases would block disjoint work behind one
|
|
2764
|
+
+ // foreign producer, and partial acquisition in different orders deadlocks.
|
|
2765
|
+
+ const withoutOutputs = tasks.filter((task) => task.outputs.length === 0);
|
|
2766
|
+
+ const results = await Promise.all([
|
|
2767
|
+
+ this.resolveCachedTasksUnderOutputLease(doNotSkipCache, withoutOutputs, groupId),
|
|
2768
|
+
+ ...tasks.filter((task) => task.outputs.length > 0).map((task) =>
|
|
2769
|
+
+ this.taskOutputLeases.withTasks([task], () =>
|
|
2770
|
+
+ this.resolveCachedTasksUnderOutputLease(doNotSkipCache, [task], groupId))),
|
|
2771
|
+
+ ]);
|
|
2772
|
+
+ return results.flat();
|
|
2773
|
+
+ }
|
|
2774
|
+
+ async resolveCachedTasksUnderOutputLease(doNotSkipCache, tasks, groupId) {
|
|
2775
|
+
if (!doNotSkipCache || tasks.length === 0)
|
|
2776
|
+
return [];
|
|
2777
|
+
const cacheableTasks = tasks.filter((t) => t.cache);
|
|
2778
|
+
@@ -836,10 +868,8 @@ class TaskOrchestrator {
|
|
2779
|
+
}
|
|
2780
|
+
/**
|
|
2781
|
+
* Fire a discrete-task worker and track it in pendingDiscreteWorkers until
|
|
2782
|
+
- * it settles. Uses runTaskDirectly (not applyFromCacheOrRun*) because
|
|
2783
|
+
- * resolveCachedTasksBulk already confirmed this task is a cache miss —
|
|
2784
|
+
- * another lookup would re-query the DB and (for Nx Cloud users) repeat
|
|
2785
|
+
- * the remote HTTP retrieval.
|
|
2786
|
+
+ * it settles. Output-producing tasks recheck the cache after taking their
|
|
2787
|
+
+ * writer lease; tasks without outputs use the coordinator's confirmed miss.
|
|
2788
|
+
*/
|
|
2789
|
+
dispatchDiscreteWorker(doNotSkipCache, task, groupId) {
|
|
2790
|
+
const worker = this.runTaskDirectly(doNotSkipCache, task, groupId)
|
|
2791
|
+
@@ -870,11 +900,21 @@ class TaskOrchestrator {
|
|
2792
|
+
await this.postRunSteps([{ task, status: 'failure', terminalOutput }], doNotSkipCache, groupId);
|
|
2793
|
+
}
|
|
2794
|
+
/**
|
|
2795
|
+
- * Spawn and wait on a task's child process, unconditionally — no cache
|
|
2796
|
+
- * lookup. Callers must have already confirmed the task is a cache miss
|
|
2797
|
+
- * (or disabled caching entirely).
|
|
2798
|
+
+ * Own a target's output through cache recheck, execution and capture.
|
|
2799
|
+
+ * Targets without outputs retain the coordinator's confirmed-miss fast path.
|
|
2800
|
+
*/
|
|
2801
|
+
async runTaskDirectly(doNotSkipCache, task, groupId) {
|
|
2802
|
+
+ return this.taskOutputLeases.withTasks([task], async () => {
|
|
2803
|
+
+ if (doNotSkipCache && task.outputs.length > 0) {
|
|
2804
|
+
+ // A foreign client may have populated this key while we waited.
|
|
2805
|
+
+ this.cacheMissedHashes.delete(task.hash);
|
|
2806
|
+
+ const cached = await this.resolveCachedTasksUnderOutputLease(true, [task], groupId);
|
|
2807
|
+
+ if (cached.length > 0) return cached[0];
|
|
2808
|
+
+ }
|
|
2809
|
+
+ return this.runTaskUnderOutputLease(doNotSkipCache, task, groupId);
|
|
2810
|
+
+ });
|
|
2811
|
+
+ }
|
|
2812
|
+
+ async runTaskUnderOutputLease(doNotSkipCache, task, groupId) {
|
|
2813
|
+
// Wait for task to be processed
|
|
2814
|
+
const taskSpecificEnv = await this.processedTasks.get(task.id);
|
|
2815
|
+
await this.preRunSteps([task], { groupId });
|
|
2816
|
+
@@ -1063,6 +1103,10 @@ class TaskOrchestrator {
|
|
2817
|
+
}
|
|
2818
|
+
}
|
|
2819
|
+
async startContinuousTask(task, groupId) {
|
|
2820
|
+
+ return this.continuousStartupLeases.withTasks([task], () =>
|
|
2821
|
+
+ this.startContinuousTaskUnderStartupLease(task, groupId));
|
|
2822
|
+
+ }
|
|
2823
|
+
+ async startContinuousTaskUnderStartupLease(task, groupId) {
|
|
2824
|
+
if (this.runningTasksService &&
|
|
2825
|
+
this.runningTasksService.getRunningTasks([task.id]).length) {
|
|
2826
|
+
await this.preRunSteps([task], { groupId });
|
|
2827
|
+
@@ -1086,6 +1130,16 @@ class TaskOrchestrator {
|
|
2828
|
+
await this.scheduleNextTasksAndReleaseThreads();
|
|
2829
|
+
return runningTask;
|
|
2830
|
+
}
|
|
2831
|
+
+ const release = await this.taskOutputLeases.acquire([task]);
|
|
2832
|
+
+ try {
|
|
2833
|
+
+ return await this.startOwnedContinuousTask(task, groupId, release);
|
|
2834
|
+
+ }
|
|
2835
|
+
+ catch (error) {
|
|
2836
|
+
+ await release();
|
|
2837
|
+
+ throw error;
|
|
2838
|
+
+ }
|
|
2839
|
+
+ }
|
|
2840
|
+
+ async startOwnedContinuousTask(task, groupId, release) {
|
|
2841
|
+
const taskSpecificEnv = await this.processedTasks.get(task.id);
|
|
2842
|
+
await this.preRunSteps([task], { groupId });
|
|
2843
|
+
const pipeOutput = await this.pipeOutputCapture(task);
|
|
2844
|
+
@@ -1105,10 +1159,10 @@ class TaskOrchestrator {
|
|
2845
|
+
groupId,
|
|
2846
|
+
ownsRunningTasksService: true,
|
|
2847
|
+
});
|
|
2848
|
+
- this.continuousTaskExitHandled.set(task.id, new Promise((resolve) => {
|
|
2849
|
+
- childProcess.onExit(async (code) => {
|
|
2850
|
+
- await this.handleContinuousTaskExit(code, task, groupId, true);
|
|
2851
|
+
- resolve();
|
|
2852
|
+
+ this.continuousTaskExitHandled.set(task.id, new Promise((resolve, reject) => {
|
|
2853
|
+
+ childProcess.onExit((code) => {
|
|
2854
|
+
+ this.handleContinuousTaskExit(code, task, groupId, true)
|
|
2855
|
+
+ .finally(release).then(resolve, reject);
|
|
2856
|
+
});
|
|
2857
|
+
}));
|
|
2858
|
+
await this.scheduleNextTasksAndReleaseThreads();
|
|
2859
|
+
@@ -1376,6 +1430,7 @@ class TaskOrchestrator {
|
|
2860
|
+
return this.cleanupPromise;
|
|
2861
|
+
}
|
|
2862
|
+
async performCleanup() {
|
|
2863
|
+
+ await Promise.all([this.taskOutputLeases.cancelPending(), this.continuousStartupLeases.cancelPending()]);
|
|
2864
|
+
// Mark all running tasks for intentional stop
|
|
2865
|
+
const reason = this.stopRequested ? 'interrupted' : 'fulfilled';
|
|
2866
|
+
for (const entry of this.runningContinuousTasks.values()) {
|
|
2867
|
+
diff --git a/dist/src/tasks-runner/task-output-lease.d.ts b/dist/src/tasks-runner/task-output-lease.d.ts
|
|
2868
|
+
new file mode 100644
|
|
2869
|
+
index 0000000000000000000000000000000000000000..ab141ad0de874122b363f2fd1894dcbde6ac52a4
|
|
2870
|
+
--- /dev/null
|
|
2871
|
+
+++ b/dist/src/tasks-runner/task-output-lease.d.ts
|
|
2872
|
+
@@ -0,0 +1,10 @@
|
|
2873
|
+
+import { Task } from '../config/task-graph';
|
|
2874
|
+
+import { TaskInvocationTracker } from '../native';
|
|
2875
|
+
+/** A target's cross-client ownership from cache lookup/restore through execution and cache capture. */
|
|
2876
|
+
+export declare class TaskOutputLeases {
|
|
2877
|
+
+ constructor(parallelism: number, invocationTracker: TaskInvocationTracker | null, purpose: 'output' | 'continuous-startup');
|
|
2878
|
+
+ acquire(tasks: readonly Task[]): Promise<() => Promise<void>>;
|
|
2879
|
+
+ withTasks<T>(tasks: readonly Task[], action: () => Promise<T>): Promise<T>;
|
|
2880
|
+
+ cancelPending(): Promise<void>;
|
|
2881
|
+
+ close(): Promise<void>;
|
|
2882
|
+
+}
|
|
2883
|
+
diff --git a/dist/src/tasks-runner/task-output-lease.js b/dist/src/tasks-runner/task-output-lease.js
|
|
2884
|
+
new file mode 100644
|
|
2885
|
+
index 0000000000000000000000000000000000000000..9f8639b22d29c8a4aca18a0efaec7a264ff2485c
|
|
2886
|
+
--- /dev/null
|
|
2887
|
+
+++ b/dist/src/tasks-runner/task-output-lease.js
|
|
2888
|
+
@@ -0,0 +1,180 @@
|
|
2889
|
+
+"use strict";
|
|
2890
|
+
+const { channel } = require("node:diagnostics_channel");
|
|
2891
|
+
+const { writeFileSync } = require("node:fs");
|
|
2892
|
+
+const { join } = require("node:path");
|
|
2893
|
+
+const { fork } = require("node:child_process");
|
|
2894
|
+
+const { FileLock, hashArray } = require("../native");
|
|
2895
|
+
+const { workspaceDataDirectory } = require("../utils/cache-directory");
|
|
2896
|
+
+const events = channel("nx:task-output-lease");
|
|
2897
|
+
+
|
|
2898
|
+
+// FileLock.lock() is synchronous. Reusable helper processes keep a contended
|
|
2899
|
+
+// lock off the client's event loop. Unlike a worker thread inside a blocking
|
|
2900
|
+
+// native call, a helper can be cancelled immediately by the kernel. Persistent
|
|
2901
|
+
+// lock files are never unlinked or replaced.
|
|
2902
|
+
+if (process.argv[2] === "--nx-task-output-lease-worker") {
|
|
2903
|
+
+ let held = [];
|
|
2904
|
+
+ process.on("disconnect", () => process.exit(0));
|
|
2905
|
+
+ process.on("message", (message) => {
|
|
2906
|
+
+ try {
|
|
2907
|
+
+ if (message.type === "acquire") {
|
|
2908
|
+
+ for (const path of message.paths) {
|
|
2909
|
+
+ const lock = new FileLock(path);
|
|
2910
|
+
+ lock.lock();
|
|
2911
|
+
+ held.push({ lock, path });
|
|
2912
|
+
+ writeFileSync(path, JSON.stringify({ pid: process.pid, clientPid: process.ppid, purpose: message.purpose, targets: message.targets }));
|
|
2913
|
+
+ }
|
|
2914
|
+
+ process.send({ type: "acquired" });
|
|
2915
|
+
+ }
|
|
2916
|
+
+ else if (message.type === "release") {
|
|
2917
|
+
+ for (const { lock, path } of held.reverse()) {
|
|
2918
|
+
+ writeFileSync(path, "");
|
|
2919
|
+
+ lock.unlock();
|
|
2920
|
+
+ }
|
|
2921
|
+
+ held = [];
|
|
2922
|
+
+ process.send({ type: "released" });
|
|
2923
|
+
+ }
|
|
2924
|
+
+ }
|
|
2925
|
+
+ catch (error) {
|
|
2926
|
+
+ for (const { lock } of held.reverse()) {
|
|
2927
|
+
+ lock.unlock();
|
|
2928
|
+
+ }
|
|
2929
|
+
+ held = [];
|
|
2930
|
+
+ process.send({ type: "error", message: error.message, stack: error.stack });
|
|
2931
|
+
+ }
|
|
2932
|
+
+ });
|
|
2933
|
+
+}
|
|
2934
|
+
+else {
|
|
2935
|
+
+ class TaskOutputLeases {
|
|
2936
|
+
+ constructor(parallelism, invocationTracker, purpose) {
|
|
2937
|
+
+ this.purpose = purpose;
|
|
2938
|
+
+ this.invocationTracker = invocationTracker;
|
|
2939
|
+
+ this.parallelism = Math.max(1, parallelism);
|
|
2940
|
+
+ this.workers = new Set();
|
|
2941
|
+
+ this.idle = [];
|
|
2942
|
+
+ this.waiters = [];
|
|
2943
|
+
+ this.stopping = false;
|
|
2944
|
+
+ this.closed = false;
|
|
2945
|
+
+ }
|
|
2946
|
+
+ async acquire(tasks) {
|
|
2947
|
+
+ // Configurations and overrides can publish the same output directory.
|
|
2948
|
+
+ // They share the project's target lease, not a configuration or hash.
|
|
2949
|
+
+ const targets = [...new Set(tasks.filter((task) => task.outputs.length > 0)
|
|
2950
|
+
+ .map((task) => `${task.target.project}:${task.target.target}`))].sort();
|
|
2951
|
+
+ if (targets.length === 0) {
|
|
2952
|
+
+ return async () => {};
|
|
2953
|
+
+ }
|
|
2954
|
+
+ if (this.stopping) {
|
|
2955
|
+
+ throw new Error(`Cannot acquire task output lease after disposal: ${targets.join(", ")}`);
|
|
2956
|
+
+ }
|
|
2957
|
+
+ // Detect an ancestor that owns the same output before blocking.
|
|
2958
|
+
+ // Configurations share a lease even when their full task ids differ.
|
|
2959
|
+
+ if (this.invocationTracker && Number(process.env.NX_INVOCATION_ROOT_PID ?? process.pid) !== process.pid) {
|
|
2960
|
+
+ const chain = this.invocationTracker.getInvocationChain();
|
|
2961
|
+
+ const ancestor = chain.find((record) => record.parentPid !== process.pid &&
|
|
2962
|
+
+ targets.some((target) => record.taskId === target || record.taskId.startsWith(`${target}:`)));
|
|
2963
|
+
+ if (ancestor) {
|
|
2964
|
+
+ throw new Error(`Recursive task output lease: client ${process.pid} cannot acquire ${targets.join(", ")} while ancestor client ${ancestor.parentPid} runs ${ancestor.taskId}; invocation chain: ${chain.map((record) => record.taskId).join(" -> ")}`);
|
|
2965
|
+
+ }
|
|
2966
|
+
+ }
|
|
2967
|
+
+ const paths = targets.map((target) => join(workspaceDataDirectory, "task-output-leases", `${hashArray([this.purpose, target])}.lock`));
|
|
2968
|
+
+ events.publish({ phase: "waiting", purpose: this.purpose, targets, paths, pid: process.pid });
|
|
2969
|
+
+ let entry = this.idle.pop();
|
|
2970
|
+
+ if (!entry && this.workers.size >= this.parallelism) {
|
|
2971
|
+
+ entry = await new Promise((resolve, reject) => this.waiters.push({ resolve, reject }));
|
|
2972
|
+
+ }
|
|
2973
|
+
+ if (!entry) {
|
|
2974
|
+
+ const worker = fork(__filename, ["--nx-task-output-lease-worker"], {
|
|
2975
|
+
+ execPath: process.execPath,
|
|
2976
|
+
+ execArgv: [],
|
|
2977
|
+
+ stdio: ["ignore", "inherit", "inherit", "ipc"],
|
|
2978
|
+
+ });
|
|
2979
|
+
+ entry = { worker, pending: null, failed: null, phase: "idle", exited: null };
|
|
2980
|
+
+ entry.exited = new Promise((resolve) => worker.once("exit", resolve));
|
|
2981
|
+
+ this.workers.add(entry);
|
|
2982
|
+
+ worker.on("message", (message) => {
|
|
2983
|
+
+ const pending = entry.pending;
|
|
2984
|
+
+ entry.pending = null;
|
|
2985
|
+
+ if (message.type === "error") {
|
|
2986
|
+
+ const error = new Error(`Task output lease for ${entry.targets.join(", ")} at ${entry.paths.join(", ")} failed: ${message.message}`);
|
|
2987
|
+
+ error.stack += `\nCaused by lease helper:\n${message.stack}`;
|
|
2988
|
+
+ entry.failed = error;
|
|
2989
|
+
+ pending?.reject(error);
|
|
2990
|
+
+ }
|
|
2991
|
+
+ else {
|
|
2992
|
+
+ pending?.resolve();
|
|
2993
|
+
+ }
|
|
2994
|
+
+ });
|
|
2995
|
+
+ worker.on("error", (cause) => {
|
|
2996
|
+
+ const error = new Error(`Task output lease helper failed for ${entry.targets.join(", ")} at ${entry.paths.join(", ")}`, { cause });
|
|
2997
|
+
+ entry.failed = error;
|
|
2998
|
+
+ entry.pending?.reject(error);
|
|
2999
|
+
+ entry.pending = null;
|
|
3000
|
+
+ });
|
|
3001
|
+
+ worker.on("exit", (code, signal) => {
|
|
3002
|
+
+ entry.failed ??= new Error(`Task output lease worker exited (code ${code}, signal ${signal ?? "none"}) for ${entry.targets.join(", ")} at ${entry.paths.join(", ")}`);
|
|
3003
|
+
+ entry.pending?.reject(entry.failed);
|
|
3004
|
+
+ entry.pending = null;
|
|
3005
|
+
+ this.workers.delete(entry);
|
|
3006
|
+
+ });
|
|
3007
|
+
+ }
|
|
3008
|
+
+ entry.targets = targets;
|
|
3009
|
+
+ entry.paths = paths;
|
|
3010
|
+
+ entry.phase = "acquiring";
|
|
3011
|
+
+ await this.exchange(entry, { type: "acquire", purpose: this.purpose, targets, paths });
|
|
3012
|
+
+ entry.phase = "held";
|
|
3013
|
+
+ events.publish({ phase: "acquired", purpose: this.purpose, targets, paths, pid: process.pid });
|
|
3014
|
+
+ let released = false;
|
|
3015
|
+
+ return async () => {
|
|
3016
|
+
+ if (released || this.closed) return;
|
|
3017
|
+
+ released = true;
|
|
3018
|
+
+ entry.phase = "releasing";
|
|
3019
|
+
+ await this.exchange(entry, { type: "release" });
|
|
3020
|
+
+ entry.phase = "idle";
|
|
3021
|
+
+ events.publish({ phase: "released", purpose: this.purpose, targets, paths, pid: process.pid });
|
|
3022
|
+
+ const waiter = this.waiters.shift();
|
|
3023
|
+
+ if (waiter) waiter.resolve(entry);
|
|
3024
|
+
+ else this.idle.push(entry);
|
|
3025
|
+
+ };
|
|
3026
|
+
+ }
|
|
3027
|
+
+ exchange(entry, message) {
|
|
3028
|
+
+ if (entry.failed) return Promise.reject(entry.failed);
|
|
3029
|
+
+ return new Promise((resolve, reject) => {
|
|
3030
|
+
+ entry.pending = { resolve, reject };
|
|
3031
|
+
+ entry.worker.send(message);
|
|
3032
|
+
+ });
|
|
3033
|
+
+ }
|
|
3034
|
+
+ async withTasks(tasks, action) {
|
|
3035
|
+
+ const release = await this.acquire(tasks);
|
|
3036
|
+
+ try {
|
|
3037
|
+
+ return await action();
|
|
3038
|
+
+ }
|
|
3039
|
+
+ finally {
|
|
3040
|
+
+ await release();
|
|
3041
|
+
+ }
|
|
3042
|
+
+ }
|
|
3043
|
+
+ async cancelPending() {
|
|
3044
|
+
+ this.stopping = true;
|
|
3045
|
+
+ for (const waiter of this.waiters.splice(0)) {
|
|
3046
|
+
+ waiter.reject(new Error("Task output lease acquisition cancelled during runner cleanup"));
|
|
3047
|
+
+ }
|
|
3048
|
+
+ await Promise.all([...this.workers]
|
|
3049
|
+
+ .filter((entry) => entry.phase === "acquiring")
|
|
3050
|
+
+ .map((entry) => {
|
|
3051
|
+
+ // Interrupt the native wait unconditionally. This owned
|
|
3052
|
+
+ // helper holds only kernel leases, never task work.
|
|
3053
|
+
+ entry.worker.kill("SIGKILL");
|
|
3054
|
+
+ return entry.exited;
|
|
3055
|
+
+ }));
|
|
3056
|
+
+ }
|
|
3057
|
+
+ async close() {
|
|
3058
|
+
+ await this.cancelPending();
|
|
3059
|
+
+ this.closed = true;
|
|
3060
|
+
+ await Promise.all([...this.workers].map((entry) => {
|
|
3061
|
+
+ entry.worker.kill("SIGKILL");
|
|
3062
|
+
+ return entry.exited;
|
|
3063
|
+
+ }));
|
|
3064
|
+
+ this.idle.length = 0;
|
|
3065
|
+
+ }
|
|
3066
|
+
+ }
|
|
3067
|
+
+ exports.TaskOutputLeases = TaskOutputLeases;
|
|
3068
|
+
+}
|
|
3069
|
+
diff --git a/dist/src/utils/installation-directory.d.ts b/dist/src/utils/installation-directory.d.ts
|
|
3070
|
+
index dc1784edc9f48944589213847e653720b25990fc..f830bb52acb7f4652e45ea4afb7a24adc4adf7a8 100644
|
|
3071
|
+
--- a/dist/src/utils/installation-directory.d.ts
|
|
3072
|
+
+++ b/dist/src/utils/installation-directory.d.ts
|
|
3073
|
+
@@ -1,2 +1,10 @@
|
|
3074
|
+
export declare function getNxInstallationPath(root?: string): string;
|
|
3075
|
+
export declare function getNxRequirePaths(root?: string): string[];
|
|
3076
|
+
+/**
|
|
3077
|
+
+ * Resolves a package the workspace provides (typescript, a release version
|
|
3078
|
+
+ * actions implementation, ...) from the workspace first, then from this nx
|
|
3079
|
+
+ * installation. A package manager's global or content-addressed store links nx
|
|
3080
|
+
+ * only to its own dependencies, so resolving from nx's location alone cannot
|
|
3081
|
+
+ * see what the workspace installs.
|
|
3082
|
+
+ */
|
|
3083
|
+
+export declare function resolveFromWorkspace(specifier: string, root?: string): string;
|
|
3084
|
+
diff --git a/dist/src/utils/installation-directory.js b/dist/src/utils/installation-directory.js
|
|
3085
|
+
index a6e742172f09e800da486af4716e9747d5ff2304..29f3376dfc5a00f83e90a7a2a7ce1a4eeed1a14e 100644
|
|
3086
|
+
--- a/dist/src/utils/installation-directory.js
|
|
3087
|
+
+++ b/dist/src/utils/installation-directory.js
|
|
3088
|
+
@@ -2,6 +2,7 @@
|
|
3089
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3090
|
+
exports.getNxInstallationPath = getNxInstallationPath;
|
|
3091
|
+
exports.getNxRequirePaths = getNxRequirePaths;
|
|
3092
|
+
+exports.resolveFromWorkspace = resolveFromWorkspace;
|
|
3093
|
+
const path_1 = require("path");
|
|
3094
|
+
const workspace_root_1 = require("./workspace-root");
|
|
3095
|
+
function getNxInstallationPath(root = workspace_root_1.workspaceRoot) {
|
|
3096
|
+
@@ -10,3 +11,15 @@ function getNxInstallationPath(root = workspace_root_1.workspaceRoot) {
|
|
3097
|
+
function getNxRequirePaths(root = workspace_root_1.workspaceRoot) {
|
|
3098
|
+
return [getNxInstallationPath(root), root];
|
|
3099
|
+
}
|
|
3100
|
+
+/**
|
|
3101
|
+
+ * Resolves a package the workspace provides (typescript, a release version
|
|
3102
|
+
+ * actions implementation, ...) from the workspace first, then from this nx
|
|
3103
|
+
+ * installation. A package manager's global or content-addressed store links nx
|
|
3104
|
+
+ * only to its own dependencies, so resolving from nx's location alone cannot
|
|
3105
|
+
+ * see what the workspace installs.
|
|
3106
|
+
+ */
|
|
3107
|
+
+function resolveFromWorkspace(specifier, root = workspace_root_1.workspaceRoot) {
|
|
3108
|
+
+ return require.resolve(specifier, {
|
|
3109
|
+
+ paths: [...getNxRequirePaths(root), __dirname],
|
|
3110
|
+
+ });
|
|
3111
|
+
+}
|
|
3112
|
+
diff --git a/dist/src/utils/installed-nx-version.js b/dist/src/utils/installed-nx-version.js
|
|
3113
|
+
index 7adf7fe48dbde78fa770ad37c5714985d78a7b8c..13e1858e5487a7d308a84cba1f379cde4e1429fa 100644
|
|
3114
|
+
--- a/dist/src/utils/installed-nx-version.js
|
|
3115
|
+
+++ b/dist/src/utils/installed-nx-version.js
|
|
3116
|
+
@@ -6,19 +6,32 @@ exports.getInstalledLegacyNrwlWorkspaceVersion = getInstalledLegacyNrwlWorkspace
|
|
3117
|
+
exports.getInstalledPackageGroup = getInstalledPackageGroup;
|
|
3118
|
+
const tslib_1 = require("tslib");
|
|
3119
|
+
const node_module_1 = tslib_1.__importStar(require("node:module"));
|
|
3120
|
+
+const node_fs_1 = require("node:fs");
|
|
3121
|
+
+const node_path_1 = require("node:path");
|
|
3122
|
+
const fileutils_1 = require("./fileutils");
|
|
3123
|
+
const package_json_1 = require("./package-json");
|
|
3124
|
+
const workspace_root_1 = require("./workspace-root");
|
|
3125
|
+
const installation_directory_1 = require("./installation-directory");
|
|
3126
|
+
/**
|
|
3127
|
+
- * Read the installed `packageName` package.json via the cache-shielded
|
|
3128
|
+
- * resolver. The resolver always reflects the workspace's `node_modules`/PnP
|
|
3129
|
+
- * store rather than whichever copy happens to be loaded in the current process
|
|
3130
|
+
- * (e.g. the temp `nx@latest` install used by the migrate bootstrap). See
|
|
3131
|
+
- * nrwl/nx#35444 and `resolvePackageJsonWithoutCachePollution` below.
|
|
3132
|
+
+ * Read installed metadata through its literal node_modules path first, so a
|
|
3133
|
+
+ * package-link swap is followed by the filesystem rather than Node's cached
|
|
3134
|
+
+ * realpath. Non-node_modules/PnP layouts use the detached resolver below,
|
|
3135
|
+
+ * preserving its protection against self-reference and path-cache pollution.
|
|
3136
|
+
*/
|
|
3137
|
+
function readInstalledPackageJson(packageName) {
|
|
3138
|
+
- const path = resolvePackageJsonWithoutCachePollution(packageName, (0, installation_directory_1.getNxRequirePaths)(workspace_root_1.workspaceRoot));
|
|
3139
|
+
+ const requirePaths = (0, installation_directory_1.getNxRequirePaths)(workspace_root_1.workspaceRoot);
|
|
3140
|
+
+ for (const root of requirePaths) {
|
|
3141
|
+
+ const path = (0, node_path_1.join)(root, 'node_modules', packageName, 'package.json');
|
|
3142
|
+
+ if ((0, node_fs_1.existsSync)(path)) {
|
|
3143
|
+
+ try {
|
|
3144
|
+
+ return (0, fileutils_1.readJsonFile)(path);
|
|
3145
|
+
+ }
|
|
3146
|
+
+ catch {
|
|
3147
|
+
+ return null;
|
|
3148
|
+
+ }
|
|
3149
|
+
+ }
|
|
3150
|
+
+ }
|
|
3151
|
+
+ const path = resolvePackageJsonWithoutCachePollution(packageName, requirePaths);
|
|
3152
|
+
if (!path) {
|
|
3153
|
+
return null;
|
|
3154
|
+
}
|
|
3155
|
+
diff --git a/dist/src/utils/task-history.js b/dist/src/utils/task-history.js
|
|
3156
|
+
index 34dbaa2a5a44e6b7d1f69a516756b30939877bd7..09f95b73572a0d411f26d42aac2cfbf0098311f4 100644
|
|
3157
|
+
--- a/dist/src/utils/task-history.js
|
|
3158
|
+
+++ b/dist/src/utils/task-history.js
|
|
3159
|
+
@@ -2,12 +2,13 @@
|
|
3160
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3161
|
+
exports.TaskHistory = void 0;
|
|
3162
|
+
exports.getTaskHistory = getTaskHistory;
|
|
3163
|
+
-const client_1 = require("../daemon/client/client");
|
|
3164
|
+
-const is_on_daemon_1 = require("../daemon/is-on-daemon");
|
|
3165
|
+
const native_1 = require("../native");
|
|
3166
|
+
const db_connection_1 = require("./db-connection");
|
|
3167
|
+
class TaskHistory {
|
|
3168
|
+
constructor() {
|
|
3169
|
+
+ // TaskDetails records hashes on this process's connection. Keep history on
|
|
3170
|
+
+ // that same connection: a daemon may have frozen a different cache/database
|
|
3171
|
+
+ // namespace before a later client supplied its workspace-data overrides.
|
|
3172
|
+
this.taskHistory = new native_1.NxTaskHistory((0, db_connection_1.getDbConnection)());
|
|
3173
|
+
}
|
|
3174
|
+
/**
|
|
3175
|
+
@@ -16,22 +17,13 @@ class TaskHistory {
|
|
3176
|
+
* @returns a map where key is task id (project:target:configuration), value is average time of historical runs
|
|
3177
|
+
*/
|
|
3178
|
+
async getEstimatedTaskTimings(targets) {
|
|
3179
|
+
- if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
|
|
3180
|
+
- return this.taskHistory.getEstimatedTaskTimings(targets);
|
|
3181
|
+
- }
|
|
3182
|
+
- return await client_1.daemonClient.getEstimatedTaskTimings(targets);
|
|
3183
|
+
+ return this.taskHistory.getEstimatedTaskTimings(targets);
|
|
3184
|
+
}
|
|
3185
|
+
async getFlakyTasks(hashes) {
|
|
3186
|
+
- if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
|
|
3187
|
+
- return this.taskHistory.getFlakyTasks(hashes);
|
|
3188
|
+
- }
|
|
3189
|
+
- return await client_1.daemonClient.getFlakyTasks(hashes);
|
|
3190
|
+
+ return this.taskHistory.getFlakyTasks(hashes);
|
|
3191
|
+
}
|
|
3192
|
+
async recordTaskRuns(taskRuns) {
|
|
3193
|
+
- if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
|
|
3194
|
+
- return this.taskHistory.recordTaskRuns(taskRuns);
|
|
3195
|
+
- }
|
|
3196
|
+
- return client_1.daemonClient.recordTaskRuns(taskRuns);
|
|
3197
|
+
+ return this.taskHistory.recordTaskRuns(taskRuns);
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
exports.TaskHistory = TaskHistory;
|
|
3201
|
+
diff --git a/dist/src/utils/workspace-context.js b/dist/src/utils/workspace-context.js
|
|
3202
|
+
index a887d862c9c431d8cbbc0d44e26fd394b243fb9c..ead0324cffa7dac0a019a756ab9902876c34b593 100644
|
|
3203
|
+
--- a/dist/src/utils/workspace-context.js
|
|
3204
|
+
+++ b/dist/src/utils/workspace-context.js
|
|
3205
|
+
@@ -13,6 +13,9 @@ exports.getAllFileDataInContext = getAllFileDataInContext;
|
|
3206
|
+
exports.getFilesInDirectoryUsingContext = getFilesInDirectoryUsingContext;
|
|
3207
|
+
exports.updateProjectFiles = updateProjectFiles;
|
|
3208
|
+
exports.resetWorkspaceContext = resetWorkspaceContext;
|
|
3209
|
+
+const node_fs_1 = require("node:fs");
|
|
3210
|
+
+const node_os_1 = require("node:os");
|
|
3211
|
+
+const node_path_1 = require("node:path");
|
|
3212
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
3213
|
+
const cache_directory_1 = require("./cache-directory");
|
|
3214
|
+
const is_on_daemon_1 = require("../daemon/is-on-daemon");
|
|
3215
|
+
@@ -22,10 +25,92 @@ let workspaceContext;
|
|
3216
|
+
function setupWorkspaceContext(workspaceRoot) {
|
|
3217
|
+
const { WorkspaceContext } = require('../native');
|
|
3218
|
+
perf_hooks_1.performance.mark('workspace-context');
|
|
3219
|
+
- workspaceContext = new WorkspaceContext(workspaceRoot, (0, cache_directory_1.workspaceDataDirectoryForWorkspace)(workspaceRoot));
|
|
3220
|
+
+ const workspaceDataDirectory = (0, cache_directory_1.workspaceDataDirectoryForWorkspace)(workspaceRoot);
|
|
3221
|
+
+ dropRacyFilesArchive(workspaceDataDirectory);
|
|
3222
|
+
+ workspaceContext = new WorkspaceContext(workspaceRoot, workspaceDataDirectory);
|
|
3223
|
+
perf_hooks_1.performance.mark('workspace-context:end');
|
|
3224
|
+
perf_hooks_1.performance.measure('workspace context init', 'workspace-context', 'workspace-context:end');
|
|
3225
|
+
}
|
|
3226
|
+
+/**
|
|
3227
|
+
+ * Seconds before the archive's write that a file hashed into it can carry: a
|
|
3228
|
+
+ * bound on one hashing pass. The native context walks and hashes the files
|
|
3229
|
+
+ * before it writes the archive; a full pass over 6,370 files measured 288 to
|
|
3230
|
+
+ * 753 ms at load average 70 to 110.
|
|
3231
|
+
+ */
|
|
3232
|
+
+const RACY_ARCHIVE_SECONDS = 10n;
|
|
3233
|
+
+/** Bytes of one archived entry, which holds the file's i64 mtime at +8. */
|
|
3234
|
+
+const ARCHIVE_ENTRY_BYTES = 24;
|
|
3235
|
+
+/**
|
|
3236
|
+
+ * Removes the file-hash archive when it may hold a hash its file no longer
|
|
3237
|
+
+ * has, so the native context hashes every file instead of reusing one.
|
|
3238
|
+
+ *
|
|
3239
|
+
+ * On Unix the native context reuses an archived hash while the file's
|
|
3240
|
+
+ * whole-second `st_mtime` equals the archived one (`selective_files_hash`);
|
|
3241
|
+
+ * neither size nor nanoseconds are compared. A file written again within the
|
|
3242
|
+
+ * second it was hashed in keeps that mtime, so the next context, daemon or
|
|
3243
|
+
+ * not, reuses the old hash: a revert hashes as the edit it reverts and Nx
|
|
3244
|
+
+ * replays the edit's cache entry. Git calls such index entries racily clean,
|
|
3245
|
+
+ * and distrusts every entry whose mtime is not older than the index. Here a
|
|
3246
|
+
+ * racy entry's mtime lies in the seconds its hashing pass ran, which end with
|
|
3247
|
+
+ * the archive's own write; an mtime after that write (a file dated ahead, a
|
|
3248
|
+
+ * clock that differs) is as suspect.
|
|
3249
|
+
+ *
|
|
3250
|
+
+ * The archive is the rkyv form of a map from path to (hash, mtime), in native
|
|
3251
|
+
+ * byte order, as Nx 23.2.1's binary writes it. Its root is its last 12 bytes:
|
|
3252
|
+
+ * the entry count (u32) at end-12 and the entries' position (i32, relative to
|
|
3253
|
+
+ * itself) at end-4. Each entry is ARCHIVE_ENTRY_BYTES long. An archive whose
|
|
3254
|
+
+ * root does not fit is removed; the native reader would reject it anyway. On
|
|
3255
|
+
+ * Windows the native mtime is a FILETIME, not seconds, and this check does
|
|
3256
|
+
+ * nothing.
|
|
3257
|
+
+ */
|
|
3258
|
+
+function dropRacyFilesArchive(workspaceDataDirectory) {
|
|
3259
|
+
+ if (process.platform === 'win32') {
|
|
3260
|
+
+ return;
|
|
3261
|
+
+ }
|
|
3262
|
+
+ const archivePath = (0, node_path_1.join)(workspaceDataDirectory, 'nx_files.nxt');
|
|
3263
|
+
+ let fd;
|
|
3264
|
+
+ try {
|
|
3265
|
+
+ fd = (0, node_fs_1.openSync)(archivePath, 'r');
|
|
3266
|
+
+ }
|
|
3267
|
+
+ catch (error) {
|
|
3268
|
+
+ if (error?.code === 'ENOENT') {
|
|
3269
|
+
+ return;
|
|
3270
|
+
+ }
|
|
3271
|
+
+ throw error;
|
|
3272
|
+
+ }
|
|
3273
|
+
+ let archive;
|
|
3274
|
+
+ let written;
|
|
3275
|
+
+ try {
|
|
3276
|
+
+ archive = (0, node_fs_1.readFileSync)(fd);
|
|
3277
|
+
+ // After the read: the write that left these bytes ended no later.
|
|
3278
|
+
+ written = Math.floor((0, node_fs_1.fstatSync)(fd).mtimeMs / 1000);
|
|
3279
|
+
+ }
|
|
3280
|
+
+ finally {
|
|
3281
|
+
+ (0, node_fs_1.closeSync)(fd);
|
|
3282
|
+
+ }
|
|
3283
|
+
+ const racyFrom = BigInt(written) - RACY_ARCHIVE_SECONDS;
|
|
3284
|
+
+ const littleEndian = (0, node_os_1.endianness)() === 'LE';
|
|
3285
|
+
+ const drop = () => (0, node_fs_1.rmSync)(archivePath, { force: true });
|
|
3286
|
+
+ if (archive.length < 12) {
|
|
3287
|
+
+ drop();
|
|
3288
|
+
+ return;
|
|
3289
|
+
+ }
|
|
3290
|
+
+ const count = littleEndian ? archive.readUInt32LE(archive.length - 12) : archive.readUInt32BE(archive.length - 12);
|
|
3291
|
+
+ const pointer = archive.length - 4;
|
|
3292
|
+
+ const entries = pointer + (littleEndian ? archive.readInt32LE(pointer) : archive.readInt32BE(pointer));
|
|
3293
|
+
+ if (entries < 0 || entries + count * ARCHIVE_ENTRY_BYTES > archive.length - 12) {
|
|
3294
|
+
+ drop();
|
|
3295
|
+
+ return;
|
|
3296
|
+
+ }
|
|
3297
|
+
+ for (let entry = 0; entry < count; entry++) {
|
|
3298
|
+
+ const at = entries + entry * ARCHIVE_ENTRY_BYTES + 8;
|
|
3299
|
+
+ const mtime = littleEndian ? archive.readBigInt64LE(at) : archive.readBigInt64BE(at);
|
|
3300
|
+
+ if (mtime >= racyFrom) {
|
|
3301
|
+
+ drop();
|
|
3302
|
+
+ return;
|
|
3303
|
+
+ }
|
|
3304
|
+
+ }
|
|
3305
|
+
+}
|
|
3306
|
+
async function getNxWorkspaceFilesFromContext(workspaceRoot, projectRootMap, useDaemonProcess = true) {
|
|
3307
|
+
if (!useDaemonProcess || (0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
|
|
3308
|
+
ensureContextAvailable(workspaceRoot);
|
|
3309
|
+
diff --git a/dist/src/utils/workspace-root.d.ts b/dist/src/utils/workspace-root.d.ts
|
|
3310
|
+
index 74bf8f91928de190fda5886163a4b7cbd5add572..8034019f30f243d86a7a74abc42fd4ad5725b5ef 100644
|
|
3311
|
+
--- a/dist/src/utils/workspace-root.d.ts
|
|
3312
|
+
+++ b/dist/src/utils/workspace-root.d.ts
|
|
3313
|
+
@@ -4,3 +4,17 @@
|
|
3314
|
+
export declare let workspaceRoot: string;
|
|
3315
|
+
export declare function setWorkspaceRoot(root: string): void;
|
|
3316
|
+
export declare function workspaceRootInner(dir: string, candidateRoot: string | null): string;
|
|
3317
|
+
+export declare function workspaceRootFromMarkers(dir: string, candidateRoot: string | null): string | null;
|
|
3318
|
+
+/** A variable naming a workspace other than the current directory's. */
|
|
3319
|
+
+export interface ForeignWorkspaceVariable {
|
|
3320
|
+
+ readonly name: string;
|
|
3321
|
+
+ readonly value: string;
|
|
3322
|
+
+ /** The workspace the value names, symlinks resolved. */
|
|
3323
|
+
+ readonly workspace: string;
|
|
3324
|
+
+}
|
|
3325
|
+
+export interface ForeignWorkspaceEnvironment {
|
|
3326
|
+
+ /** The workspace the current directory is in, symlinks resolved. */
|
|
3327
|
+
+ readonly workspace: string;
|
|
3328
|
+
+ readonly variables: readonly ForeignWorkspaceVariable[];
|
|
3329
|
+
+}
|
|
3330
|
+
+export declare function foreignWorkspaceEnvironment(cwd: string, env: NodeJS.ProcessEnv): ForeignWorkspaceEnvironment | null;
|
|
3331
|
+
diff --git a/dist/src/utils/workspace-root.js b/dist/src/utils/workspace-root.js
|
|
3332
|
+
index 74f0682269ede01ee9ee4819e39f38c90a719894..03686ffeeff54286b99386fddeef77d031d3af71 100644
|
|
3333
|
+
--- a/dist/src/utils/workspace-root.js
|
|
3334
|
+
+++ b/dist/src/utils/workspace-root.js
|
|
3335
|
+
@@ -3,7 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3336
|
+
exports.workspaceRoot = void 0;
|
|
3337
|
+
exports.setWorkspaceRoot = setWorkspaceRoot;
|
|
3338
|
+
exports.workspaceRootInner = workspaceRootInner;
|
|
3339
|
+
+exports.workspaceRootFromMarkers = workspaceRootFromMarkers;
|
|
3340
|
+
+exports.foreignWorkspaceEnvironment = foreignWorkspaceEnvironment;
|
|
3341
|
+
const tslib_1 = require("tslib");
|
|
3342
|
+
+const fs_1 = require("fs");
|
|
3343
|
+
const path = tslib_1.__importStar(require("path"));
|
|
3344
|
+
const fileutils_1 = require("./fileutils");
|
|
3345
|
+
/**
|
|
3346
|
+
@@ -17,6 +20,15 @@ function setWorkspaceRoot(root) {
|
|
3347
|
+
function workspaceRootInner(dir, candidateRoot) {
|
|
3348
|
+
if (process.env.NX_WORKSPACE_ROOT_PATH)
|
|
3349
|
+
return process.env.NX_WORKSPACE_ROOT_PATH;
|
|
3350
|
+
+ return workspaceRootFromMarkers(dir, candidateRoot);
|
|
3351
|
+
+}
|
|
3352
|
+
+/**
|
|
3353
|
+
+ * The workspace `dir` is in, by the files on disk alone: the nearest directory
|
|
3354
|
+
+ * at or above `dir` holding `nx.json`, `nx` or `nx.bat`, else the topmost one
|
|
3355
|
+
+ * holding `node_modules/nx`, else `candidateRoot`. `workspaceRootInner` without
|
|
3356
|
+
+ * the `NX_WORKSPACE_ROOT_PATH` override.
|
|
3357
|
+
+ */
|
|
3358
|
+
+function workspaceRootFromMarkers(dir, candidateRoot) {
|
|
3359
|
+
if (path.dirname(dir) === dir)
|
|
3360
|
+
return candidateRoot;
|
|
3361
|
+
const matches = [
|
|
3362
|
+
@@ -32,9 +44,120 @@ function workspaceRootInner(dir, candidateRoot) {
|
|
3363
|
+
// thus located in //packages/my-lib/node_modules/nx/package.json
|
|
3364
|
+
}
|
|
3365
|
+
else if ((0, fileutils_1.fileExists)(path.join(dir, 'node_modules', 'nx', 'package.json'))) {
|
|
3366
|
+
- return workspaceRootInner(path.dirname(dir), dir);
|
|
3367
|
+
+ return workspaceRootFromMarkers(path.dirname(dir), dir);
|
|
3368
|
+
}
|
|
3369
|
+
else {
|
|
3370
|
+
- return workspaceRootInner(path.dirname(dir), candidateRoot);
|
|
3371
|
+
+ return workspaceRootFromMarkers(path.dirname(dir), candidateRoot);
|
|
3372
|
+
+ }
|
|
3373
|
+
+}
|
|
3374
|
+
+/**
|
|
3375
|
+
+ * The variables that relocate one workspace's daemon socket, daemon record,
|
|
3376
|
+
+ * task database and cache, each with the directory Nx resolves a relative
|
|
3377
|
+
+ * value against.
|
|
3378
|
+
+ */
|
|
3379
|
+
+const WORKSPACE_STATE_ENV = [
|
|
3380
|
+
+ ['NX_WORKSPACE_DATA_DIRECTORY', 'root'],
|
|
3381
|
+
+ ['NX_PROJECT_GRAPH_CACHE_DIRECTORY', 'root'],
|
|
3382
|
+
+ ['NX_CACHE_DIRECTORY', 'root'],
|
|
3383
|
+
+ ['NX_SOCKET_DIR', 'cwd'],
|
|
3384
|
+
+ ['NX_DAEMON_SOCKET_DIR', 'cwd'],
|
|
3385
|
+
+];
|
|
3386
|
+
+/**
|
|
3387
|
+
+ * The variables of `env` that name a workspace other than the one `cwd` is in,
|
|
3388
|
+
+ * or null when there are none.
|
|
3389
|
+
+ *
|
|
3390
|
+
+ * A shell keeps the environment of the workspace it was set up for when it
|
|
3391
|
+
+ * moves into another checkout. Nx takes `NX_WORKSPACE_ROOT_PATH` verbatim as
|
|
3392
|
+
+ * its root, and the state variables as the locations of its daemon socket,
|
|
3393
|
+
+ * daemon record, task database and cache, so an `nx` run there acts on the
|
|
3394
|
+
+ * first workspace: `nx daemon --stop` stops that workspace's daemon, and
|
|
3395
|
+
+ * `nx reset` deletes that workspace's cache.
|
|
3396
|
+
+ *
|
|
3397
|
+
+ * Which workspace a variable names:
|
|
3398
|
+
+ * - `cwd`'s workspace is found by the markers alone (`workspaceRootFromMarkers`).
|
|
3399
|
+
+ * A `cwd` inside no workspace has nothing to contradict, so nothing is
|
|
3400
|
+
+ * reported.
|
|
3401
|
+
+ * - `NX_WORKSPACE_ROOT_PATH` names the directory it holds.
|
|
3402
|
+
+ * - A data, cache or socket directory belongs to the workspace whose root
|
|
3403
|
+
+ * contains it, found by the same marker walk from the directory.
|
|
3404
|
+
+ * - A directory outside every workspace, such as a socket directory under
|
|
3405
|
+
+ * /tmp, cannot be attributed by its path and is not reported. Nothing on disk
|
|
3406
|
+
+ * says which workspace owns it short of asking the daemon behind it, and
|
|
3407
|
+
+ * that daemon is what must not be reached.
|
|
3408
|
+
+ * Directories are compared by device and inode (`sameDirectory`), so every path
|
|
3409
|
+
+ * to `cwd`'s own workspace, a symlink, a bind mount or a firmlink, is that
|
|
3410
|
+
+ * workspace.
|
|
3411
|
+
+ */
|
|
3412
|
+
+function foreignWorkspaceEnvironment(cwd, env) {
|
|
3413
|
+
+ const found = workspaceRootFromMarkers(cwd, null);
|
|
3414
|
+
+ if (found === null)
|
|
3415
|
+
+ return null;
|
|
3416
|
+
+ const variables = [];
|
|
3417
|
+
+ const rootPath = env.NX_WORKSPACE_ROOT_PATH;
|
|
3418
|
+
+ if (rootPath) {
|
|
3419
|
+
+ const named = path.resolve(cwd, rootPath);
|
|
3420
|
+
+ if (!sameDirectory(named, found)) {
|
|
3421
|
+
+ variables.push({ name: 'NX_WORKSPACE_ROOT_PATH', value: rootPath, workspace: realLocation(named) });
|
|
3422
|
+
+ }
|
|
3423
|
+
+ }
|
|
3424
|
+
+ const nxRoot = rootPath ? path.resolve(cwd, rootPath) : found;
|
|
3425
|
+
+ for (const [name, base] of WORKSPACE_STATE_ENV) {
|
|
3426
|
+
+ const value = env[name];
|
|
3427
|
+
+ if (!value)
|
|
3428
|
+
+ continue;
|
|
3429
|
+
+ const location = realLocation(path.resolve(base === 'root' ? nxRoot : cwd, value));
|
|
3430
|
+
+ const owner = workspaceRootFromMarkers(location, null);
|
|
3431
|
+
+ if (owner === null)
|
|
3432
|
+
+ continue;
|
|
3433
|
+
+ if (!sameDirectory(owner, found)) {
|
|
3434
|
+
+ variables.push({ name, value, workspace: realLocation(owner) });
|
|
3435
|
+
+ }
|
|
3436
|
+
+ }
|
|
3437
|
+
+ return variables.length === 0 ? null : { workspace: realLocation(found), variables };
|
|
3438
|
+
+}
|
|
3439
|
+
+/**
|
|
3440
|
+
+ * Whether `left` and `right` are one directory: the same device and inode,
|
|
3441
|
+
+ * which every path to a directory shares. Resolving symlinks does not join the
|
|
3442
|
+
+ * paths of a bind mount (CI binds the checkout at `/work/...` and runs steps in
|
|
3443
|
+
+ * the checkout itself) or a firmlink (macOS's `/System/Volumes/Data/Users` and
|
|
3444
|
+
+ * `/Users`): each is a second canonical path to the one directory. Where either
|
|
3445
|
+
+ * cannot be read, or its filesystem reports no inode, the resolved paths decide.
|
|
3446
|
+
+ */
|
|
3447
|
+
+function sameDirectory(left, right) {
|
|
3448
|
+
+ const leftIdentity = directoryIdentity(left);
|
|
3449
|
+
+ const rightIdentity = directoryIdentity(right);
|
|
3450
|
+
+ return leftIdentity !== null && rightIdentity !== null
|
|
3451
|
+
+ ? leftIdentity === rightIdentity
|
|
3452
|
+
+ : realLocation(left) === realLocation(right);
|
|
3453
|
+
+}
|
|
3454
|
+
+function directoryIdentity(location) {
|
|
3455
|
+
+ try {
|
|
3456
|
+
+ const { dev, ino } = fs_1.statSync(location, { bigint: true });
|
|
3457
|
+
+ return ino === 0n ? null : `${dev}:${ino}`;
|
|
3458
|
+
+ }
|
|
3459
|
+
+ catch {
|
|
3460
|
+
+ return null;
|
|
3461
|
+
+ }
|
|
3462
|
+
+}
|
|
3463
|
+
+/**
|
|
3464
|
+
+ * `location` with every symlink resolved. A directory Nx has not created yet
|
|
3465
|
+
+ * resolves through its nearest existing ancestor: what it will be created
|
|
3466
|
+
+ * under is what decides where it lies.
|
|
3467
|
+
+ */
|
|
3468
|
+
+function realLocation(location) {
|
|
3469
|
+
+ const missing = [];
|
|
3470
|
+
+ let existing = location;
|
|
3471
|
+
+ for (;;) {
|
|
3472
|
+
+ try {
|
|
3473
|
+
+ return path.join(fs_1.realpathSync.native(existing), ...missing);
|
|
3474
|
+
+ }
|
|
3475
|
+
+ catch {
|
|
3476
|
+
+ // Unresolvable (missing, or unreadable): resolve its parent instead.
|
|
3477
|
+
+ const parent = path.dirname(existing);
|
|
3478
|
+
+ if (parent === existing)
|
|
3479
|
+
+ return location;
|
|
3480
|
+
+ missing.unshift(path.basename(existing));
|
|
3481
|
+
+ existing = parent;
|
|
3482
|
+
+ }
|
|
3483
|
+
}
|
|
3484
|
+
}
|