@smoothbricks/nx-plugin 0.4.16 → 0.4.18
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 +12 -11
- package/dist/ensure-built.d.ts +7 -4
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +77 -17
- package/dist/executors/typescript-emit/executor.d.ts +1 -1
- package/dist/executors/typescript-emit/executor.d.ts.map +1 -1
- package/dist/executors/typescript-emit/executor.js +3 -8
- package/dist/index.js +10 -8
- package/dist/managed-files/files.d.ts +6 -0
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +11 -0
- package/executors.json +1 -1
- package/managed/raw/patches/ttsc@0.30.4.patch +2255 -0
- package/managed/raw/tooling/direnv/devenv.smoo.nix +14 -1
- package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +3 -4
- package/managed/templates/github/actions/setup-devenv/action.yml +11 -7
- package/package.json +5 -5
- package/src/ensure-built.test.ts +41 -5
- package/src/ensure-built.ts +127 -43
- package/src/executors/typescript-emit/executor.test.ts +64 -115
- package/src/executors/typescript-emit/executor.ts +4 -9
- package/src/executors/typescript-emit/schema.json +1 -1
- package/src/index.test.ts +4 -4
- package/src/index.ts +9 -8
- package/src/managed-files/files.ts +12 -0
- package/src/managed-files/github-host-cache-isolation.test.ts +60 -0
|
@@ -17,12 +17,25 @@
|
|
|
17
17
|
lib,
|
|
18
18
|
pkgs,
|
|
19
19
|
...
|
|
20
|
-
}:
|
|
20
|
+
}: let
|
|
21
|
+
# ttsc's native-plugin patch compiles microsoft/typescript-go with one
|
|
22
|
+
# corrected file. `go list -m` only fills `.Dir` after the module is already
|
|
23
|
+
# in GOMODCACHE, which CI does not restore (and GOPROXY is often off under
|
|
24
|
+
# nix). Pin the commit ttsc 0.30.4's patch requires so the tree is in the
|
|
25
|
+
# devenv closure and TTSC_TYPESCRIPT_GO_DIR names it.
|
|
26
|
+
typescriptGo = pkgs.fetchFromGitHub {
|
|
27
|
+
owner = "microsoft";
|
|
28
|
+
repo = "typescript-go";
|
|
29
|
+
rev = "56ab4af42157";
|
|
30
|
+
hash = "sha256-ebjX+1+9axEqsnZXCRZSumA38gPNdmoz98tMt2oftN4=";
|
|
31
|
+
};
|
|
32
|
+
in {
|
|
21
33
|
env = lib.mkMerge [
|
|
22
34
|
{
|
|
23
35
|
# Nx otherwise defaults to three workers. Scale to the cores available in each
|
|
24
36
|
# developer shell or CI runner; explicit --parallel flags still take precedence.
|
|
25
37
|
NX_PARALLEL = "100%";
|
|
38
|
+
TTSC_TYPESCRIPT_GO_DIR = "${typescriptGo}";
|
|
26
39
|
}
|
|
27
40
|
# Playwright's downloaded Ubuntu browser has no runtime closure on NixOS
|
|
28
41
|
# (CI reached the executable, then failed loading libglib-2.0.so.0). Use
|
|
@@ -2,7 +2,8 @@ name: Cache ttsc plugins
|
|
|
2
2
|
description: >
|
|
3
3
|
Restore/save compiled ttsc native plugin binaries (typia, etc.). These are content-keyed under TTSC_CACHE_DIR/plugins
|
|
4
4
|
and skip the multi-minute `go build` when the cache key matches. The Go object cache (go-build/) is NOT cached — it is
|
|
5
|
-
multi-GB and only helps when the plugin key misses.
|
|
5
|
+
multi-GB and only helps when the plugin key misses. Do not use restore-keys: a prefix hit restores plugins built for a
|
|
6
|
+
different lock/patch, then ttsc still compiles any missing plugin against a cold GOMODCACHE.
|
|
6
7
|
|
|
7
8
|
runs:
|
|
8
9
|
using: composite
|
|
@@ -14,6 +15,4 @@ runs:
|
|
|
14
15
|
# workspace; devenv sets TTSC_CACHE_DIR to <repo>/.cache/ttsc.
|
|
15
16
|
path: .cache/ttsc/plugins
|
|
16
17
|
# prettier-ignore
|
|
17
|
-
key: ${{ runner.os }}-${{ runner.arch }}-ttsc-plugins-v1-${{ hashFiles('bun.lock', 'package.json', 'patches/ttsc@*.patch', 'tooling/direnv/devenv.lock') }}
|
|
18
|
-
restore-keys: |
|
|
19
|
-
${{ runner.os }}-${{ runner.arch }}-ttsc-plugins-v1-
|
|
18
|
+
key: ${{ runner.os }}-${{ runner.arch }}-ttsc-plugins-v1-${{ hashFiles('bun.lock', 'package.json', 'patches/ttsc@*.patch', 'tooling/direnv/devenv.lock', 'tooling/direnv/devenv.smoo.nix') }}
|
|
@@ -73,8 +73,10 @@ runs:
|
|
|
73
73
|
# and that DB lives in workspace-data. Since CI and Publish sit in
|
|
74
74
|
# different concurrency groups they run simultaneously on one host, so a
|
|
75
75
|
# repository-wide tree let one workflow rewrite the other's graph state
|
|
76
|
-
# mid-read
|
|
77
|
-
#
|
|
76
|
+
# mid-read. CI concurrency is per workflow/ref, not workflow alone:
|
|
77
|
+
# separate PRs and jobs must never share mutable graph or eval state.
|
|
78
|
+
# Hash the exact identity (not a lossy path slug); keep cache artifacts
|
|
79
|
+
# and their metadata DB together, warm across runs of the same ref/job.
|
|
78
80
|
- name: 📂 Locate the Nx cache on the shared bind
|
|
79
81
|
if: steps.runner-kind.outputs.host == 'true'
|
|
80
82
|
shell: bash
|
|
@@ -83,7 +85,8 @@ runs:
|
|
|
83
85
|
NX_CACHE_LANE: ${{ github.workflow }}
|
|
84
86
|
run: |
|
|
85
87
|
lane=$(printf '%s' "$NX_CACHE_LANE" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9._-' '-')
|
|
86
|
-
|
|
88
|
+
scope=$(printf '%s\0%s\0%s\0%s\0%s' "$GITHUB_WORKFLOW" "$GITHUB_REF" "$GITHUB_JOB" "$RUNNER_OS" "$RUNNER_ARCH" | git hash-object --stdin)
|
|
89
|
+
NX_CACHE_ROOT="/var/cache/ci/nx/$NX_CACHE_REPO/${lane:-default}/$scope"
|
|
87
90
|
mkdir -p "$NX_CACHE_ROOT/cache" "$NX_CACHE_ROOT/workspace-data"
|
|
88
91
|
{
|
|
89
92
|
echo "NX_CACHE_DIRECTORY=$NX_CACHE_ROOT/cache"
|
|
@@ -99,8 +102,8 @@ runs:
|
|
|
99
102
|
# .devenv (eval SQLite, gc roots, profile) and .direnv survive the job, so
|
|
100
103
|
# the next job on this host evaluates nothing and downloads nothing. The
|
|
101
104
|
# Actions cache segment below is the ephemeral runners' substitute for this.
|
|
102
|
-
# Scoped per job
|
|
103
|
-
# eval-cache.db
|
|
105
|
+
# Scoped per workflow/ref/job/platform like Nx: separate PR runs and
|
|
106
|
+
# jobs can overlap, and one eval-cache.db must have only one writer.
|
|
104
107
|
#
|
|
105
108
|
# The eval cache keys on canonical absolute paths, and act's host executor
|
|
106
109
|
# checks out under <cache>/<random 8 chars>/hostexecutor - a new path every
|
|
@@ -123,12 +126,13 @@ runs:
|
|
|
123
126
|
DEVENV_STATE_JOB: ${{ github.job }}
|
|
124
127
|
run: |
|
|
125
128
|
lane=$(printf '%s' "$DEVENV_STATE_LANE" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9._-' '-')
|
|
126
|
-
|
|
129
|
+
scope=$(printf '%s\0%s\0%s\0%s\0%s' "$GITHUB_WORKFLOW" "$GITHUB_REF" "$GITHUB_JOB" "$RUNNER_OS" "$RUNNER_ARCH" | git hash-object --stdin)
|
|
130
|
+
root="/var/cache/ci/devenv/$DEVENV_STATE_REPO/${lane:-default}/$DEVENV_STATE_JOB/$scope"
|
|
127
131
|
mkdir -p "$root/.devenv" "$root/.direnv"
|
|
128
132
|
rm -rf tooling/direnv/.devenv tooling/direnv/.direnv
|
|
129
133
|
ln -s "$root/.devenv" tooling/direnv/.devenv
|
|
130
134
|
ln -s "$root/.direnv" tooling/direnv/.direnv
|
|
131
|
-
stable="/work/$DEVENV_STATE_REPO/${lane:-default}/$DEVENV_STATE_JOB"
|
|
135
|
+
stable="/work/$DEVENV_STATE_REPO/${lane:-default}/$DEVENV_STATE_JOB/$scope"
|
|
132
136
|
if mkdir -p "$stable" && sudo mount --bind "$GITHUB_WORKSPACE" "$stable"; then
|
|
133
137
|
echo "DEVENV_WORKDIR=$stable" >> "$GITHUB_ENV"
|
|
134
138
|
echo "devenv state: $root (workspace bind-mounted at $stable)"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smoothbricks/nx-plugin",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./loader.js",
|
|
@@ -189,15 +189,15 @@
|
|
|
189
189
|
"dependencies": {
|
|
190
190
|
"@nx/js": "latest",
|
|
191
191
|
"nx": "latest",
|
|
192
|
-
"prettier": "^3.
|
|
192
|
+
"prettier": "^3.9.8",
|
|
193
193
|
"smol-toml": "^1.6.1",
|
|
194
194
|
"tslib": "^2.8.1",
|
|
195
|
-
"typia": "14.0.
|
|
195
|
+
"typia": "14.0.6",
|
|
196
196
|
"yaml": "^2.9.0"
|
|
197
197
|
},
|
|
198
198
|
"devDependencies": {
|
|
199
|
-
"@smoothbricks/lmao": "0.4.
|
|
200
|
-
"@smoothbricks/validation": "0.1.
|
|
199
|
+
"@smoothbricks/lmao": "0.4.1",
|
|
200
|
+
"@smoothbricks/validation": "0.1.10",
|
|
201
201
|
"fast-check": "^4.4.0"
|
|
202
202
|
}
|
|
203
203
|
}
|
package/src/ensure-built.test.ts
CHANGED
|
@@ -123,6 +123,7 @@ describe('describeMiss', () => {
|
|
|
123
123
|
describeMiss({ kind: 'not-cached', taskId: 'app:build' }),
|
|
124
124
|
describeMiss({ kind: 'cached-failure', taskId: 'app:build', code: 7 }),
|
|
125
125
|
describeMiss({ kind: 'stale-outputs', taskId: 'app:build' }),
|
|
126
|
+
describeMiss({ kind: 'stale-inputs', taskId: 'app:build' }),
|
|
126
127
|
describeMiss({ kind: 'cache-disabled', taskId: 'app:build' }),
|
|
127
128
|
describeMiss({ kind: 'no-daemon', taskId: 'app:build' }),
|
|
128
129
|
];
|
|
@@ -275,6 +276,9 @@ describe('smoo-nx-exec', () => {
|
|
|
275
276
|
let workspace = '';
|
|
276
277
|
const report = () => join(workspace, 'report');
|
|
277
278
|
const marker = () => join(workspace, 'packages', 'app', 'dist', 'marker.txt');
|
|
279
|
+
// Outside the workspace: a log inside it would be an undeclared output the
|
|
280
|
+
// snapshot diff rightly reports as a changed input.
|
|
281
|
+
const builds = () => `${workspace}-lib-builds.log`;
|
|
278
282
|
|
|
279
283
|
beforeAll(async () => {
|
|
280
284
|
// Realpath because macOS puts the temp directory behind a /private
|
|
@@ -300,14 +304,20 @@ describe('smoo-nx-exec', () => {
|
|
|
300
304
|
build: {
|
|
301
305
|
executor: 'nx:run-commands',
|
|
302
306
|
cache: true,
|
|
303
|
-
inputs: ['{projectRoot}/source
|
|
307
|
+
inputs: ['{projectRoot}/source*.txt'],
|
|
304
308
|
outputs: ['{projectRoot}/dist'],
|
|
305
|
-
options: {
|
|
309
|
+
options: {
|
|
310
|
+
command: `mkdir -p dist && cat source*.txt > dist/lib.txt && cat dist/lib.txt >> ${builds()}`,
|
|
311
|
+
cwd: '{projectRoot}',
|
|
312
|
+
},
|
|
306
313
|
},
|
|
307
314
|
},
|
|
308
315
|
}),
|
|
309
316
|
);
|
|
310
|
-
|
|
317
|
+
// Digit-suffixed so `source*.txt` expands in the same order under every
|
|
318
|
+
// locale: en_US.UTF-8 collation ignores punctuation at the first level and
|
|
319
|
+
// would put `source2.txt` before `source.txt`.
|
|
320
|
+
await writeFile(join(workspace, 'packages', 'lib', 'source1.txt'), 'lib\n');
|
|
311
321
|
await writeFile(
|
|
312
322
|
join(workspace, 'packages', 'app', 'project.json'),
|
|
313
323
|
JSON.stringify({
|
|
@@ -323,7 +333,10 @@ describe('smoo-nx-exec', () => {
|
|
|
323
333
|
inputs: ['{projectRoot}/source.txt', { dependentTasksOutputFiles: '**/*' }],
|
|
324
334
|
outputs: ['{projectRoot}/dist'],
|
|
325
335
|
dependsOn: ['^build'],
|
|
326
|
-
options: {
|
|
336
|
+
options: {
|
|
337
|
+
command: 'mkdir -p dist && cat source.txt ../lib/dist/lib.txt > dist/marker.txt',
|
|
338
|
+
cwd: '{projectRoot}',
|
|
339
|
+
},
|
|
327
340
|
},
|
|
328
341
|
broken: {
|
|
329
342
|
executor: 'nx:run-commands',
|
|
@@ -349,6 +362,7 @@ describe('smoo-nx-exec', () => {
|
|
|
349
362
|
if (workspace) {
|
|
350
363
|
await nx(workspace, ['daemon', '--stop']);
|
|
351
364
|
await rm(workspace, { recursive: true, force: true });
|
|
365
|
+
await rm(builds(), { force: true });
|
|
352
366
|
}
|
|
353
367
|
});
|
|
354
368
|
|
|
@@ -437,10 +451,13 @@ describe('smoo-nx-exec', () => {
|
|
|
437
451
|
});
|
|
438
452
|
|
|
439
453
|
it('runs again when a dependency\u0027s own inputs change', async () => {
|
|
440
|
-
await
|
|
454
|
+
const before = await readFile(builds(), 'utf-8');
|
|
455
|
+
await writeFile(join(workspace, 'packages', 'lib', 'source1.txt'), 'lib changed\n');
|
|
441
456
|
const changed = await runBin(workspace, ['app:build', '--', './report']);
|
|
442
457
|
expect(changed.code).toBe(0);
|
|
443
458
|
expect(await readFile(join(workspace, 'packages', 'lib', 'dist', 'lib.txt'), 'utf-8')).toBe('lib changed\n');
|
|
459
|
+
expect(await readFile(marker(), 'utf-8')).toBe('built\nlib changed\n');
|
|
460
|
+
expect(await readFile(builds(), 'utf-8')).toBe(`${before}lib changed\n`);
|
|
444
461
|
|
|
445
462
|
// And the graph settles back to silence, which is only reachable if the
|
|
446
463
|
// dependent-outputs task was hashed too.
|
|
@@ -448,6 +465,25 @@ describe('smoo-nx-exec', () => {
|
|
|
448
465
|
expect(settled.code).toBe(0);
|
|
449
466
|
expect(settled.stderr).toBe('');
|
|
450
467
|
expect(settled.stdout.split('\n')[0]).toBe(MARKER);
|
|
468
|
+
expect(await readFile(builds(), 'utf-8')).toBe(`${before}lib changed\n`);
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
it('runs again when a dependency input is added or deleted', async () => {
|
|
472
|
+
const addedSource = join(workspace, 'packages', 'lib', 'source2.txt');
|
|
473
|
+
await writeFile(addedSource, 'added\n');
|
|
474
|
+
const added = await runBin(workspace, ['app:build', '--', './report']);
|
|
475
|
+
expect(added.code).toBe(0);
|
|
476
|
+
expect(await readFile(marker(), 'utf-8')).toBe('built\nlib changed\nadded\n');
|
|
477
|
+
|
|
478
|
+
await rm(addedSource);
|
|
479
|
+
const removed = await runBin(workspace, ['app:build', '--', './report']);
|
|
480
|
+
expect(removed.code).toBe(0);
|
|
481
|
+
expect(await readFile(marker(), 'utf-8')).toBe('built\nlib changed\n');
|
|
482
|
+
|
|
483
|
+
const settled = await runBin(workspace, ['app:build', '--', './report']);
|
|
484
|
+
expect(settled.code).toBe(0);
|
|
485
|
+
expect(settled.stderr).toBe('');
|
|
486
|
+
expect(settled.stdout.split('\n')[0]).toBe(MARKER);
|
|
451
487
|
});
|
|
452
488
|
|
|
453
489
|
it('forwards a failing target\u0027s exit code and never execs', async () => {
|
package/src/ensure-built.ts
CHANGED
|
@@ -4,27 +4,45 @@ import { existsSync } from 'node:fs';
|
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
5
|
import { join, resolve } from 'node:path';
|
|
6
6
|
|
|
7
|
+
import type * as NxConfiguration from 'nx/src/config/nx-json';
|
|
7
8
|
import type { NxJsonConfiguration } from 'nx/src/config/nx-json';
|
|
8
9
|
import type { ProjectGraph, ProjectGraphProjectNode } from 'nx/src/config/project-graph';
|
|
9
|
-
import type { Task } from 'nx/src/config/task-graph';
|
|
10
|
+
import type { Task, TaskGraph } from 'nx/src/config/task-graph';
|
|
11
|
+
import type * as NxDaemonClient from 'nx/src/daemon/client/client';
|
|
12
|
+
import type * as NxHashTask from 'nx/src/hasher/hash-task';
|
|
13
|
+
import type * as NxTaskHasher from 'nx/src/hasher/task-hasher';
|
|
14
|
+
import type * as NxNative from 'nx/src/native';
|
|
15
|
+
import type * as NxExecutionHooks from 'nx/src/project-graph/plugins/tasks-execution-hooks';
|
|
16
|
+
import type * as NxProjectGraph from 'nx/src/project-graph/project-graph';
|
|
17
|
+
import type * as NxCache from 'nx/src/tasks-runner/cache';
|
|
18
|
+
import type * as NxCreateTaskGraph from 'nx/src/tasks-runner/create-task-graph';
|
|
10
19
|
import type { TaskResults } from 'nx/src/tasks-runner/life-cycle';
|
|
20
|
+
import type * as NxRunCommand from 'nx/src/tasks-runner/run-command';
|
|
21
|
+
import type * as NxTaskEnv from 'nx/src/tasks-runner/task-env';
|
|
22
|
+
import type * as NxCacheDirectory from 'nx/src/utils/cache-directory';
|
|
23
|
+
import type * as NxCommandLineUtils from 'nx/src/utils/command-line-utils';
|
|
11
24
|
import type { NxArgs } from 'nx/src/utils/command-line-utils';
|
|
25
|
+
import type * as NxExitCodes from 'nx/src/utils/exit-codes';
|
|
26
|
+
import type * as NxPerfLogging from 'nx/src/utils/perf-logging';
|
|
27
|
+
import type * as NxWorkspaceRoot from 'nx/src/utils/workspace-root';
|
|
12
28
|
|
|
13
29
|
interface NxRuntimeModules {
|
|
14
|
-
readonly 'nx/src/config/nx-json': typeof
|
|
15
|
-
readonly 'nx/src/daemon/client/client': typeof
|
|
16
|
-
readonly 'nx/src/hasher/hash-task': typeof
|
|
17
|
-
readonly 'nx/src/hasher/task-hasher': typeof
|
|
18
|
-
readonly 'nx/src/
|
|
19
|
-
readonly 'nx/src/project-graph/
|
|
20
|
-
readonly 'nx/src/
|
|
21
|
-
readonly 'nx/src/tasks-runner/
|
|
22
|
-
readonly 'nx/src/tasks-runner/
|
|
23
|
-
readonly 'nx/src/tasks-runner/
|
|
24
|
-
readonly 'nx/src/
|
|
25
|
-
readonly 'nx/src/utils/
|
|
26
|
-
readonly 'nx/src/utils/
|
|
27
|
-
readonly 'nx/src/utils/
|
|
30
|
+
readonly 'nx/src/config/nx-json': typeof NxConfiguration;
|
|
31
|
+
readonly 'nx/src/daemon/client/client': typeof NxDaemonClient;
|
|
32
|
+
readonly 'nx/src/hasher/hash-task': typeof NxHashTask;
|
|
33
|
+
readonly 'nx/src/hasher/task-hasher': typeof NxTaskHasher;
|
|
34
|
+
readonly 'nx/src/native': typeof NxNative;
|
|
35
|
+
readonly 'nx/src/project-graph/plugins/tasks-execution-hooks': typeof NxExecutionHooks;
|
|
36
|
+
readonly 'nx/src/project-graph/project-graph': typeof NxProjectGraph;
|
|
37
|
+
readonly 'nx/src/tasks-runner/cache': typeof NxCache;
|
|
38
|
+
readonly 'nx/src/tasks-runner/create-task-graph': typeof NxCreateTaskGraph;
|
|
39
|
+
readonly 'nx/src/tasks-runner/run-command': typeof NxRunCommand;
|
|
40
|
+
readonly 'nx/src/tasks-runner/task-env': typeof NxTaskEnv;
|
|
41
|
+
readonly 'nx/src/utils/cache-directory': typeof NxCacheDirectory;
|
|
42
|
+
readonly 'nx/src/utils/command-line-utils': typeof NxCommandLineUtils;
|
|
43
|
+
readonly 'nx/src/utils/exit-codes': typeof NxExitCodes;
|
|
44
|
+
readonly 'nx/src/utils/perf-logging': typeof NxPerfLogging;
|
|
45
|
+
readonly 'nx/src/utils/workspace-root': typeof NxWorkspaceRoot;
|
|
28
46
|
}
|
|
29
47
|
|
|
30
48
|
type WorkspaceNxRequire = <Specifier extends keyof NxRuntimeModules>(
|
|
@@ -66,6 +84,7 @@ export type MissReason =
|
|
|
66
84
|
| { readonly kind: 'not-cached'; readonly taskId: string }
|
|
67
85
|
| { readonly kind: 'cached-failure'; readonly taskId: string; readonly code: number }
|
|
68
86
|
| { readonly kind: 'stale-outputs'; readonly taskId: string }
|
|
87
|
+
| { readonly kind: 'stale-inputs'; readonly taskId: string }
|
|
69
88
|
| { readonly kind: 'cache-disabled'; readonly taskId: string }
|
|
70
89
|
| { readonly kind: 'no-daemon'; readonly taskId: string };
|
|
71
90
|
|
|
@@ -141,6 +160,8 @@ export function describeMiss(reason: MissReason): string {
|
|
|
141
160
|
return `${reason.taskId} last failed with exit code ${reason.code}`;
|
|
142
161
|
case 'stale-outputs':
|
|
143
162
|
return `${reason.taskId} outputs are missing or modified on disk`;
|
|
163
|
+
case 'stale-inputs':
|
|
164
|
+
return `${reason.taskId} inputs changed since the Nx daemon last looked`;
|
|
144
165
|
case 'cache-disabled':
|
|
145
166
|
return `the Nx cache is disabled, so ${reason.taskId} must run`;
|
|
146
167
|
case 'no-daemon':
|
|
@@ -202,10 +223,10 @@ export function firstStaleOutputs(tasks: readonly Task[], matches: readonly bool
|
|
|
202
223
|
* when they already are.
|
|
203
224
|
*
|
|
204
225
|
* "Already built" is the hot path, because a checkout-local CLI wrapper pays it
|
|
205
|
-
* on every invocation. So it never spawns the `nx` CLI:
|
|
206
|
-
* task hashes and
|
|
207
|
-
*
|
|
208
|
-
*
|
|
226
|
+
* on every invocation. So it never spawns the `nx` CLI: a native filesystem
|
|
227
|
+
* snapshot refreshes the daemon's inputs, the task hashes and on-disk output
|
|
228
|
+
* verification are daemon round-trips, and the cache lookup is a local SQLite
|
|
229
|
+
* read. Nx's task runner is only invoked once something needs running.
|
|
209
230
|
*
|
|
210
231
|
* With the daemon disabled there is no probe to make — hashing would have to
|
|
211
232
|
* build the project graph in this process, and no service holds the recorded
|
|
@@ -284,6 +305,7 @@ async function ensureBuiltInWorkspace(
|
|
|
284
305
|
const { readNxJson } = requireNx('nx/src/config/nx-json');
|
|
285
306
|
const { splitArgsIntoNxArgsAndOverrides } = requireNx('nx/src/utils/command-line-utils');
|
|
286
307
|
const { setEnvVarsBasedOnArgs } = requireNx('nx/src/tasks-runner/run-command');
|
|
308
|
+
const { createTaskGraph } = requireNx('nx/src/tasks-runner/create-task-graph');
|
|
287
309
|
const hooks = requireNx('nx/src/project-graph/plugins/tasks-execution-hooks');
|
|
288
310
|
|
|
289
311
|
const nxJson = readNxJson();
|
|
@@ -303,6 +325,23 @@ async function ensureBuiltInWorkspace(
|
|
|
303
325
|
// the probe keys differently from the CLI.
|
|
304
326
|
setEnvVarsBasedOnArgs(nxArgs, loadDotEnvFiles);
|
|
305
327
|
|
|
328
|
+
performance.mark('ensureBuilt:graph:start');
|
|
329
|
+
const { projectGraph } = await daemonClient.getProjectGraphAndSourceMaps();
|
|
330
|
+
requireProject(projectGraph, selector.project);
|
|
331
|
+
const taskGraph = createTaskGraph(
|
|
332
|
+
projectGraph,
|
|
333
|
+
{},
|
|
334
|
+
[selector.project],
|
|
335
|
+
[selector.target],
|
|
336
|
+
selector.configuration,
|
|
337
|
+
overrides,
|
|
338
|
+
false,
|
|
339
|
+
);
|
|
340
|
+
const tasks = Object.values(taskGraph.tasks);
|
|
341
|
+
performance.measure('ensureBuilt:graph', 'ensureBuilt:graph:start');
|
|
342
|
+
|
|
343
|
+
const inputsChanged = await refreshWorkspaceContext(workspaceRoot, tasks, requireNx);
|
|
344
|
+
|
|
306
345
|
const runId = randomUUID();
|
|
307
346
|
const startTime = Date.now();
|
|
308
347
|
// Plugin `preTasksExecution` hooks inject environment variables, and declared
|
|
@@ -318,14 +357,16 @@ async function ensureBuiltInWorkspace(
|
|
|
318
357
|
|
|
319
358
|
performance.mark('ensureBuilt:probe:start');
|
|
320
359
|
let reason: MissReason | null;
|
|
360
|
+
const selectorTaskId =
|
|
361
|
+
selector.configuration === undefined
|
|
362
|
+
? `${selector.project}:${selector.target}`
|
|
363
|
+
: `${selector.project}:${selector.target}:${selector.configuration}`;
|
|
321
364
|
if (process.env.NX_SKIP_NX_CACHE === 'true' || process.env.NX_DISABLE_NX_CACHE === 'true') {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
: `${selector.project}:${selector.target}:${selector.configuration}`;
|
|
326
|
-
reason = { kind: 'cache-disabled', taskId };
|
|
365
|
+
reason = { kind: 'cache-disabled', taskId: selectorTaskId };
|
|
366
|
+
} else if (inputsChanged) {
|
|
367
|
+
reason = { kind: 'stale-inputs', taskId: selectorTaskId };
|
|
327
368
|
} else {
|
|
328
|
-
reason = await probe(nxJson, nxArgs,
|
|
369
|
+
reason = await probe(nxJson, nxArgs, projectGraph, taskGraph, tasks, requireNx);
|
|
329
370
|
}
|
|
330
371
|
performance.measure('ensureBuilt:probe', 'ensureBuilt:probe:start');
|
|
331
372
|
const outcome =
|
|
@@ -371,37 +412,80 @@ function bindWorkspaceRoot(workspaceRoot: string, requireNx: WorkspaceNxRequire)
|
|
|
371
412
|
}
|
|
372
413
|
}
|
|
373
414
|
|
|
415
|
+
/**
|
|
416
|
+
* The daemon drains delivered watcher events before serving its graph, but an
|
|
417
|
+
* OS event can still be in flight after a write has completed. Its graph and
|
|
418
|
+
* hashes can then agree with each other while both describe yesterday's files.
|
|
419
|
+
* Take Nx's native, ignore-aware disk snapshot and compare it with the
|
|
420
|
+
* daemon's file table; its metadata cache reuses unchanged file hashes.
|
|
421
|
+
*
|
|
422
|
+
* Any difference is handed to the daemon so its next graph is current, but
|
|
423
|
+
* that only schedules a recomputation, and a probe meanwhile would hash
|
|
424
|
+
* against the file map it already has. So the caller does not probe: if any
|
|
425
|
+
* differing path is not a declared output of a task in the graph, this
|
|
426
|
+
* returns true and the target is run, which lets Nx's own runner wait for the
|
|
427
|
+
* recomputation. Output paths are exempt because a build's own writes are the
|
|
428
|
+
* commonest thing to reach here before the watcher does, and treating them as
|
|
429
|
+
* a miss would make every hit after a build replay the cached log.
|
|
430
|
+
*/
|
|
431
|
+
async function refreshWorkspaceContext(
|
|
432
|
+
workspaceRoot: string,
|
|
433
|
+
tasks: Task[],
|
|
434
|
+
requireNx: WorkspaceNxRequire,
|
|
435
|
+
): Promise<boolean> {
|
|
436
|
+
const { daemonClient } = requireNx('nx/src/daemon/client/client');
|
|
437
|
+
const { WorkspaceContext, matchOutputPaths } = requireNx('nx/src/native');
|
|
438
|
+
const { workspaceDataDirectoryForWorkspace } = requireNx('nx/src/utils/cache-directory');
|
|
439
|
+
performance.mark('ensureBuilt:inputs:start');
|
|
440
|
+
const previousFiles = await daemonClient.getWorkspaceContextFileData();
|
|
441
|
+
const previousHashes = new Map<string, string>();
|
|
442
|
+
for (const { file, hash } of previousFiles) {
|
|
443
|
+
previousHashes.set(file, hash);
|
|
444
|
+
}
|
|
445
|
+
// A context is a snapshot, not a watcher. Do not reuse one across calls.
|
|
446
|
+
const context = new WorkspaceContext(workspaceRoot, workspaceDataDirectoryForWorkspace(workspaceRoot));
|
|
447
|
+
const createdFiles: string[] = [];
|
|
448
|
+
const updatedFiles: string[] = [];
|
|
449
|
+
for (const { file, hash } of context.allFileData()) {
|
|
450
|
+
const previousHash = previousHashes.get(file);
|
|
451
|
+
if (previousHash === undefined) {
|
|
452
|
+
createdFiles.push(file);
|
|
453
|
+
} else if (previousHash !== hash) {
|
|
454
|
+
updatedFiles.push(file);
|
|
455
|
+
}
|
|
456
|
+
previousHashes.delete(file);
|
|
457
|
+
}
|
|
458
|
+
const deletedFiles = [...previousHashes.keys()];
|
|
459
|
+
const changed = [...createdFiles, ...updatedFiles, ...deletedFiles];
|
|
460
|
+
let inputsChanged = false;
|
|
461
|
+
if (changed.length > 0) {
|
|
462
|
+
await daemonClient.updateWorkspaceContext(createdFiles, updatedFiles, deletedFiles);
|
|
463
|
+
// The same matcher the task runner uses to collect outputs, over the union
|
|
464
|
+
// of every task's declared outputs. A negation declared by one task then
|
|
465
|
+
// also excludes another task's output, which errs toward a miss.
|
|
466
|
+
const outputs = tasks.flatMap((task) => task.outputs);
|
|
467
|
+
inputsChanged = matchOutputPaths(outputs, changed).includes(false);
|
|
468
|
+
}
|
|
469
|
+
performance.measure('ensureBuilt:inputs', 'ensureBuilt:inputs:start');
|
|
470
|
+
return inputsChanged;
|
|
471
|
+
}
|
|
472
|
+
|
|
374
473
|
/** `null` when the target is already built; otherwise the first reason it is not. */
|
|
375
474
|
async function probe(
|
|
376
475
|
nxJson: NxJsonConfiguration,
|
|
377
476
|
nxArgs: NxArgs,
|
|
378
|
-
|
|
379
|
-
|
|
477
|
+
projectGraph: ProjectGraph,
|
|
478
|
+
taskGraph: TaskGraph,
|
|
479
|
+
tasks: Task[],
|
|
380
480
|
requireNx: WorkspaceNxRequire,
|
|
381
481
|
): Promise<MissReason | null> {
|
|
382
482
|
const { daemonClient } = requireNx('nx/src/daemon/client/client');
|
|
383
|
-
const { createTaskGraph } = requireNx('nx/src/tasks-runner/create-task-graph');
|
|
384
483
|
const { DaemonBasedTaskHasher } = requireNx('nx/src/hasher/task-hasher');
|
|
385
484
|
const { getTaskDetails, hashTasks } = requireNx('nx/src/hasher/hash-task');
|
|
386
485
|
const { getTaskSpecificEnv } = requireNx('nx/src/tasks-runner/task-env');
|
|
387
486
|
const { getCache } = requireNx('nx/src/tasks-runner/cache');
|
|
388
487
|
const { getRunnerOptions } = requireNx('nx/src/tasks-runner/run-command');
|
|
389
488
|
|
|
390
|
-
performance.mark('ensureBuilt:graph:start');
|
|
391
|
-
const { projectGraph } = await daemonClient.getProjectGraphAndSourceMaps();
|
|
392
|
-
requireProject(projectGraph, selector.project);
|
|
393
|
-
const taskGraph = createTaskGraph(
|
|
394
|
-
projectGraph,
|
|
395
|
-
{},
|
|
396
|
-
[selector.project],
|
|
397
|
-
[selector.target],
|
|
398
|
-
selector.configuration,
|
|
399
|
-
overrides,
|
|
400
|
-
false,
|
|
401
|
-
);
|
|
402
|
-
const tasks = Object.values(taskGraph.tasks);
|
|
403
|
-
performance.measure('ensureBuilt:graph', 'ensureBuilt:graph:start');
|
|
404
|
-
|
|
405
489
|
// `isCloudDefault: false` because these options are only read here by the
|
|
406
490
|
// hasher, which looks at `selectivelyHashTsConfig`; the cloud credentials the
|
|
407
491
|
// flag would add belong to the cloud runner, and the run path calls Nx's own
|