@smoothbricks/nx-plugin 0.7.17 → 0.7.19
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 +315 -114
- package/dist/.build-inputs.json +47 -38
- package/dist/built-output-packages.js +1 -1
- package/dist/bun-lock-scope.d.ts +128 -20
- package/dist/bun-lock-scope.d.ts.map +1 -1
- package/dist/bun-lock-scope.js +267 -44
- package/dist/cargo-closure-input.d.ts +8 -6
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +15 -12
- package/dist/cargo-source-hash.d.ts +26 -25
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +84 -105
- package/dist/cargo-toolchain-paths.d.ts +2 -2
- package/dist/cargo-toolchain-paths.js +2 -2
- package/dist/cargo-workspace.d.ts +20 -2
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +43 -22
- package/dist/ensure-built-receipt.d.ts +3 -2
- package/dist/ensure-built-receipt.d.ts.map +1 -1
- package/dist/ensure-built-receipt.js +3 -2
- package/dist/eslint-config-closure.d.ts +8 -3
- package/dist/eslint-config-closure.d.ts.map +1 -1
- package/dist/eslint-config-closure.js +24 -5
- package/dist/executors/bounded-exec/admission-queue.d.ts +3 -1
- package/dist/executors/bounded-exec/admission-queue.d.ts.map +1 -1
- package/dist/executors/bounded-exec/admission-queue.js +9 -10
- package/dist/executors/bounded-exec/awake-clock.d.ts +5 -0
- package/dist/executors/bounded-exec/awake-clock.d.ts.map +1 -0
- package/dist/executors/bounded-exec/awake-clock.js +22 -0
- package/dist/executors/bounded-exec/bounds.d.ts +19 -6
- package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
- package/dist/executors/bounded-exec/bounds.js +22 -15
- package/dist/executors/bounded-exec/case-gate.d.ts +114 -0
- package/dist/executors/bounded-exec/case-gate.d.ts.map +1 -0
- package/dist/executors/bounded-exec/case-gate.js +342 -0
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts +1 -0
- package/dist/executors/bounded-exec/cpu-pool-thread.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool-thread.js +2 -2
- package/dist/executors/bounded-exec/cpu-pool.d.ts +28 -1
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +102 -16
- package/dist/executors/bounded-exec/cpu-rise.d.ts +73 -0
- package/dist/executors/bounded-exec/cpu-rise.d.ts.map +1 -0
- package/dist/executors/bounded-exec/cpu-rise.js +111 -0
- package/dist/executors/bounded-exec/endpoint-life.d.ts +146 -0
- package/dist/executors/bounded-exec/endpoint-life.d.ts.map +1 -0
- package/dist/executors/bounded-exec/endpoint-life.js +228 -0
- package/dist/executors/bounded-exec/executor.d.ts +1 -1
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +256 -86
- package/dist/executors/bounded-exec/gateway-lease.d.ts +1 -1
- package/dist/executors/bounded-exec/gateway-lease.d.ts.map +1 -1
- package/dist/executors/bounded-exec/gateway-lease.js +8 -1
- package/dist/executors/bounded-exec/go-run-summary.d.ts +51 -0
- package/dist/executors/bounded-exec/go-run-summary.d.ts.map +1 -0
- package/dist/executors/bounded-exec/go-run-summary.js +98 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts +11 -3
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
- package/dist/executors/bounded-exec/hang-diagnostics.js +125 -47
- package/dist/executors/bounded-exec/lease-wait.d.ts +1 -0
- package/dist/executors/bounded-exec/lease-wait.d.ts.map +1 -1
- package/dist/executors/bounded-exec/lease-wait.js +1 -0
- package/dist/executors/bounded-exec/mbx-pool.d.ts +42 -7
- package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/mbx-pool.js +45 -8
- package/dist/executors/bounded-exec/mbx-reservations.d.ts +12 -6
- package/dist/executors/bounded-exec/mbx-reservations.d.ts.map +1 -1
- package/dist/executors/bounded-exec/mbx-reservations.js +190 -284
- package/dist/executors/bounded-exec/parent-grant.d.ts +2 -0
- package/dist/executors/bounded-exec/parent-grant.d.ts.map +1 -1
- package/dist/executors/bounded-exec/parent-grant.js +1 -0
- package/dist/executors/bounded-exec/pool-admission.d.ts +29 -3
- package/dist/executors/bounded-exec/pool-admission.d.ts.map +1 -1
- package/dist/executors/bounded-exec/pool-admission.js +47 -1
- package/dist/executors/bounded-exec/progress-channel.d.ts +38 -0
- package/dist/executors/bounded-exec/progress-channel.d.ts.map +1 -0
- package/dist/executors/bounded-exec/progress-channel.js +113 -0
- package/dist/executors/bounded-exec/progress.d.ts +5 -1
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
- package/dist/executors/bounded-exec/progress.js +31 -1
- package/dist/executors/bounded-exec/ram-temp.d.ts +24 -1
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
- package/dist/executors/bounded-exec/ram-temp.js +123 -16
- package/dist/executors/bounded-exec/reservation-connection.d.ts +90 -0
- package/dist/executors/bounded-exec/reservation-connection.d.ts.map +1 -0
- package/dist/executors/bounded-exec/reservation-connection.js +248 -0
- package/dist/executors/bounded-exec/run-cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/run-cpu-pool.js +3 -0
- package/dist/executors/bounded-exec/runner-sizing.d.ts +9 -5
- package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
- package/dist/executors/bounded-exec/runner-sizing.js +13 -9
- package/dist/executors/bounded-exec/schema.d.ts +7 -2
- package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
- package/dist/executors/bounded-exec/schema.js +17 -1
- package/dist/executors/bounded-exec/suite-minimum.d.ts +21 -0
- package/dist/executors/bounded-exec/suite-minimum.d.ts.map +1 -0
- package/dist/executors/bounded-exec/suite-minimum.js +85 -0
- package/dist/executors/bounded-exec/test-result-writer.d.ts +2 -0
- package/dist/executors/bounded-exec/test-result-writer.d.ts.map +1 -1
- package/dist/executors/bounded-exec/test-result-writer.js +1 -0
- package/dist/executors/bounded-exec/test-results.d.ts +5 -0
- package/dist/executors/bounded-exec/test-results.d.ts.map +1 -1
- package/dist/executors/bounded-exec/test-results.js +2 -2
- package/dist/executors/bounded-exec/verdict.d.ts +39 -10
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +60 -14
- package/dist/executors/cargo-zigbuild/executor.d.ts +10 -8
- package/dist/executors/cargo-zigbuild/executor.d.ts.map +1 -1
- package/dist/executors/cargo-zigbuild/executor.js +32 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +294 -152
- package/dist/managed-files/ci-workflow.d.ts +4 -1
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +9 -14
- package/dist/managed-files/files.d.ts +3 -3
- package/dist/managed-files/files.js +3 -3
- package/dist/managed-files/generator.d.ts +5 -1
- package/dist/managed-files/generator.d.ts.map +1 -1
- package/dist/managed-files/generator.js +22 -7
- package/dist/managed-files/render-memo.d.ts +13 -0
- package/dist/managed-files/render-memo.d.ts.map +1 -0
- package/dist/managed-files/render-memo.js +94 -0
- package/dist/task-results.js +2 -1
- package/dist/test-program.d.ts +11 -6
- package/dist/test-program.d.ts.map +1 -1
- package/dist/test-program.js +39 -35
- package/dist/tool-bins.d.ts +12 -0
- package/dist/tool-bins.d.ts.map +1 -1
- package/dist/tool-bins.js +31 -6
- package/dist/typecheck-test-policy.d.ts +10 -1
- package/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +40 -24
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +135 -42
- package/dist/workspace-index.d.ts +14 -1
- package/dist/workspace-index.d.ts.map +1 -1
- package/dist/workspace-index.js +36 -4
- package/executors.json +2 -0
- package/managed/raw/envrc +24 -0
- package/managed/raw/patches/nx@24.0.3.patch +1851 -221
- package/managed/raw/patches/ttsc@0.37.1.patch +1055 -0
- package/managed/raw/tooling/direnv/developer-links.ts +122 -14
- package/managed/raw/tooling/direnv/devenv.smoo.nix +20 -19
- package/managed/templates/github/actions/save-nix-devenv/action.yml +19 -1
- package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
- package/package.json +68 -11
- package/runtime/nx-publish/.build-inputs.json +2 -2
- package/runtime/nx-publish/cache_adapter.js +293 -3
- package/runtime/nx-publish/nx_publish.js +36 -14
- package/src/built-output-packages.ts +1 -1
- package/src/bun-lock-scope.ts +293 -40
- package/src/cargo-closure-input.ts +20 -12
- package/src/cargo-source-hash.ts +119 -145
- package/src/cargo-toolchain-paths.ts +2 -2
- package/src/cargo-workspace.ts +59 -21
- package/src/ensure-built-receipt.ts +3 -2
- package/src/eslint-config-closure.ts +27 -6
- package/src/executors/bounded-exec/admission-queue.ts +11 -10
- package/src/executors/bounded-exec/awake-clock.ts +20 -0
- package/src/executors/bounded-exec/bounds.ts +41 -19
- package/src/executors/bounded-exec/case-gate.ts +365 -0
- package/src/executors/bounded-exec/cpu-pool-thread.ts +3 -3
- package/src/executors/bounded-exec/cpu-pool.ts +139 -12
- package/src/executors/bounded-exec/cpu-rise.ts +156 -0
- package/src/executors/bounded-exec/endpoint-life.ts +279 -0
- package/src/executors/bounded-exec/executor.ts +341 -123
- package/src/executors/bounded-exec/gateway-lease.ts +6 -0
- package/src/executors/bounded-exec/go-run-summary.ts +137 -0
- package/src/executors/bounded-exec/hang-diagnostics.ts +150 -50
- package/src/executors/bounded-exec/lease-wait.ts +1 -0
- package/src/executors/bounded-exec/mbx-pool.ts +57 -9
- package/src/executors/bounded-exec/mbx-reservations.ts +216 -183
- package/src/executors/bounded-exec/parent-grant.ts +3 -0
- package/src/executors/bounded-exec/pool-admission.ts +59 -2
- package/src/executors/bounded-exec/progress-channel.ts +129 -0
- package/src/executors/bounded-exec/progress.ts +39 -3
- package/src/executors/bounded-exec/ram-temp.ts +137 -17
- package/src/executors/bounded-exec/reservation-connection.ts +221 -0
- package/src/executors/bounded-exec/run-cpu-pool.ts +2 -0
- package/src/executors/bounded-exec/runner-sizing.ts +13 -8
- package/src/executors/bounded-exec/schema.json +1 -1
- package/src/executors/bounded-exec/schema.ts +21 -2
- package/src/executors/bounded-exec/suite-minimum.ts +81 -0
- package/src/executors/bounded-exec/test-result-writer.ts +3 -0
- package/src/executors/bounded-exec/test-results.ts +5 -0
- package/src/executors/bounded-exec/verdict.ts +83 -22
- package/src/executors/cargo-zigbuild/executor.ts +30 -19
- package/src/index.ts +357 -166
- package/src/managed-files/ci-workflow.ts +13 -17
- package/src/managed-files/files.ts +3 -3
- package/src/managed-files/generator.ts +21 -6
- package/src/managed-files/render-memo.ts +135 -0
- package/src/test-program.ts +36 -41
- package/src/tool-bins.ts +35 -6
- package/src/typecheck-test-policy.ts +49 -24
- package/src/workspace-config-policy.ts +161 -43
- package/src/workspace-index.ts +40 -5
- package/test-timings.json +157 -141
- package/managed/raw/patches/ttsc@0.36.3.patch +0 -1660
package/src/cargo-source-hash.ts
CHANGED
|
@@ -14,112 +14,30 @@ import {
|
|
|
14
14
|
import { lstat, mkdir, readdir, readFile, readlink, realpath, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
15
15
|
import { createRequire } from 'node:module';
|
|
16
16
|
import { homedir } from 'node:os';
|
|
17
|
-
import { delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
17
|
+
import { basename, delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
18
18
|
import type { Readable } from 'node:stream';
|
|
19
|
+
import {
|
|
20
|
+
buildClosure,
|
|
21
|
+
type CargoClosure,
|
|
22
|
+
type CargoEdge,
|
|
23
|
+
type CargoMetadata,
|
|
24
|
+
cargoEdges,
|
|
25
|
+
localPackagesUnder,
|
|
26
|
+
type PinnedCargoPackage,
|
|
27
|
+
parseCargoMetadata,
|
|
28
|
+
pinnedPackages,
|
|
29
|
+
} from '@smoothbricks/build-inputs/cargo-closure';
|
|
19
30
|
import { CARGO_ANCESTOR_INPUTS } from '@smoothbricks/cargo-retain/cargo-ancestor-inputs';
|
|
20
|
-
import native from 'nx/src/native/index.js';
|
|
31
|
+
import native, { type FileData } from 'nx/src/native/index.js';
|
|
21
32
|
import { workspaceDataDirectoryForWorkspace } from 'nx/src/utils/cache-directory.js';
|
|
22
33
|
import { CARGO_TOOLCHAIN_PIN_INPUTS } from './cargo-toolchain-policy.js';
|
|
23
34
|
import { describeTeardown, killProcessGroupNow, TEARDOWN_PATIENCE } from './process-group.js';
|
|
24
35
|
import { rustTokens } from './rust-tokens.js';
|
|
25
36
|
|
|
26
|
-
const { IS_WASM, WorkspaceContext } = native;
|
|
37
|
+
const { IS_WASM, WorkspaceContext, hashArray } = native;
|
|
27
38
|
|
|
28
39
|
const cargoResolveEvents = channel('@smoothbricks/nx-plugin:cargo-resolve');
|
|
29
40
|
|
|
30
|
-
/** The fields of `cargo metadata --format-version 1` this module reads. */
|
|
31
|
-
interface CargoMetadata {
|
|
32
|
-
packages: {
|
|
33
|
-
id: string;
|
|
34
|
-
name: string;
|
|
35
|
-
version: string;
|
|
36
|
-
source: string | null;
|
|
37
|
-
manifest_path: string;
|
|
38
|
-
targets: { src_path: string }[];
|
|
39
|
-
/** Added by the cache after Cargo identifies each local package's governing workspace. */
|
|
40
|
-
governing_manifest_path?: string;
|
|
41
|
-
}[];
|
|
42
|
-
resolve: { nodes: { id: string; deps: { pkg: string; dep_kinds: { kind: CargoDependencyKind }[] }[] }[] } | null;
|
|
43
|
-
workspace_members: string[];
|
|
44
|
-
workspace_root: string;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Narrowed field by field, not by typia: graph inference imports this module,
|
|
49
|
-
* and a workspace that loads the plugin from its sources runs them without
|
|
50
|
-
* typia's compile-time transform.
|
|
51
|
-
*/
|
|
52
|
-
function parseCargoMetadata(json: string): CargoMetadata {
|
|
53
|
-
const member = (value: unknown, key: string): unknown =>
|
|
54
|
-
typeof value === 'object' && value !== null && key in value ? Reflect.get(value, key) : undefined;
|
|
55
|
-
const text = (value: unknown, field: string): string => {
|
|
56
|
-
if (typeof value !== 'string') throw new Error(`cargo metadata reported no valid ${field}`);
|
|
57
|
-
return value;
|
|
58
|
-
};
|
|
59
|
-
const list = (value: unknown, field: string): unknown[] => {
|
|
60
|
-
if (!Array.isArray(value)) throw new Error(`cargo metadata reported no valid ${field}`);
|
|
61
|
-
return value;
|
|
62
|
-
};
|
|
63
|
-
const document: unknown = JSON.parse(json);
|
|
64
|
-
const resolveGraph = member(document, 'resolve');
|
|
65
|
-
return {
|
|
66
|
-
packages: list(member(document, 'packages'), 'packages').map((pkg) => ({
|
|
67
|
-
id: text(member(pkg, 'id'), 'package id'),
|
|
68
|
-
name: text(member(pkg, 'name'), 'package name'),
|
|
69
|
-
version: text(member(pkg, 'version'), 'package version'),
|
|
70
|
-
source: member(pkg, 'source') === null ? null : text(member(pkg, 'source'), 'package source'),
|
|
71
|
-
manifest_path: text(member(pkg, 'manifest_path'), 'package manifest_path'),
|
|
72
|
-
targets: list(member(pkg, 'targets'), 'package targets').map((target) => ({
|
|
73
|
-
src_path: text(member(target, 'src_path'), 'target src_path'),
|
|
74
|
-
})),
|
|
75
|
-
...(member(pkg, 'governing_manifest_path') === undefined
|
|
76
|
-
? {}
|
|
77
|
-
: { governing_manifest_path: text(member(pkg, 'governing_manifest_path'), 'governing manifest') }),
|
|
78
|
-
})),
|
|
79
|
-
resolve:
|
|
80
|
-
resolveGraph === null
|
|
81
|
-
? null
|
|
82
|
-
: {
|
|
83
|
-
nodes: list(member(resolveGraph, 'nodes'), 'resolve').map((node) => ({
|
|
84
|
-
id: text(member(node, 'id'), 'resolve node id'),
|
|
85
|
-
deps: list(member(node, 'deps'), 'resolve node deps').map((dependency) => ({
|
|
86
|
-
pkg: text(member(dependency, 'pkg'), 'resolve edge'),
|
|
87
|
-
dep_kinds: dependencyKinds(member(dependency, 'dep_kinds')),
|
|
88
|
-
})),
|
|
89
|
-
})),
|
|
90
|
-
},
|
|
91
|
-
workspace_members: list(member(document, 'workspace_members'), 'workspace_members').map((id) =>
|
|
92
|
-
text(id, 'workspace member'),
|
|
93
|
-
),
|
|
94
|
-
workspace_root: text(member(document, 'workspace_root'), 'workspace_root'),
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** How a package declares a dependency: `[dependencies]` (null), `[dev-dependencies]` or `[build-dependencies]`. */
|
|
99
|
-
type CargoDependencyKind = null | 'dev' | 'build';
|
|
100
|
-
|
|
101
|
-
/** A resolve edge's `dep_kinds`. An edge Cargo reports with no kind is refused: read as dev-only, it would drop a dependency. */
|
|
102
|
-
function dependencyKinds(value: unknown): { kind: CargoDependencyKind }[] {
|
|
103
|
-
if (!Array.isArray(value) || value.length === 0)
|
|
104
|
-
throw new Error('cargo metadata reported no valid resolve edge kinds');
|
|
105
|
-
return value.map((entry: unknown) => {
|
|
106
|
-
const kind = typeof entry === 'object' && entry !== null ? Reflect.get(entry, 'kind') : undefined;
|
|
107
|
-
if (kind !== null && kind !== 'dev' && kind !== 'build')
|
|
108
|
-
throw new Error('cargo metadata reported no valid resolve edge kind');
|
|
109
|
-
return { kind };
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** One resolved dependency of a package: the package it resolved to, and whether every declaration of it is a dev one. */
|
|
114
|
-
export interface CargoEdge {
|
|
115
|
-
readonly pkg: string;
|
|
116
|
-
/** Cargo builds this dependency for the dependent's tests, examples and benches only. */
|
|
117
|
-
readonly devOnly: boolean;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** Every package Cargo builds for a selection, by package id, each with the dependencies Cargo builds for it. */
|
|
121
|
-
export type CargoClosure = ReadonlyMap<string, readonly string[]>;
|
|
122
|
-
|
|
123
41
|
/** A mutable (path) package in Cargo's locked resolve. Every path is canonical. */
|
|
124
42
|
export interface LocalCargoPackage {
|
|
125
43
|
readonly id: string;
|
|
@@ -139,11 +57,8 @@ export interface CargoResolve {
|
|
|
139
57
|
/** The workspace's own members: `root`'s manifest governs each of them. */
|
|
140
58
|
readonly members: ReadonlySet<string>;
|
|
141
59
|
readonly local: readonly LocalCargoPackage[];
|
|
142
|
-
/**
|
|
143
|
-
|
|
144
|
-
* dependency names the locked commit that the id alone does not.
|
|
145
|
-
*/
|
|
146
|
-
readonly locked: ReadonlyMap<string, string>;
|
|
60
|
+
/** Every package Cargo.lock pins (registry, git, alternate registry), by package id. */
|
|
61
|
+
readonly pinned: ReadonlyMap<string, PinnedCargoPackage>;
|
|
147
62
|
/** Every dependency edge by package id, or null when Cargo reported no resolution. */
|
|
148
63
|
readonly edges: ReadonlyMap<string, readonly CargoEdge[]> | null;
|
|
149
64
|
}
|
|
@@ -534,16 +449,8 @@ function cargoFromMetadata(metadata: CargoMetadata): CargoResolve {
|
|
|
534
449
|
governingManifest: pkg.governing_manifest_path,
|
|
535
450
|
};
|
|
536
451
|
}),
|
|
537
|
-
|
|
538
|
-
edges:
|
|
539
|
-
metadata.resolve === null
|
|
540
|
-
? null
|
|
541
|
-
: new Map(
|
|
542
|
-
metadata.resolve.nodes.map((node) => [
|
|
543
|
-
node.id,
|
|
544
|
-
node.deps.map((dep) => ({ pkg: dep.pkg, devOnly: dep.dep_kinds.every(({ kind }) => kind === 'dev') })),
|
|
545
|
-
]),
|
|
546
|
-
),
|
|
452
|
+
pinned: pinnedPackages(metadata),
|
|
453
|
+
edges: cargoEdges(metadata),
|
|
547
454
|
};
|
|
548
455
|
}
|
|
549
456
|
|
|
@@ -1025,7 +932,7 @@ export async function hashCargoPathInputs(
|
|
|
1025
932
|
const scan = scans.get(input.file);
|
|
1026
933
|
if (scan !== undefined) {
|
|
1027
934
|
scans.delete(input.file);
|
|
1028
|
-
collectCompiledInputs(input.file, bytes.toString('utf8'), scan.found);
|
|
935
|
+
collectCompiledInputs(input.file, includeSpellings(bytes.toString('utf8')), scan.found);
|
|
1029
936
|
}
|
|
1030
937
|
hash.update(input.key);
|
|
1031
938
|
hash.update('\0');
|
|
@@ -1046,7 +953,7 @@ export async function hashCargoPathInputs(
|
|
|
1046
953
|
if (!scans.delete(source)) continue;
|
|
1047
954
|
// Discovery also visits ignored sources. They have no scheduled identity;
|
|
1048
955
|
// if an include alias later names one, preserve the old read-then-hash path.
|
|
1049
|
-
collectCompiledInputs(source, readFileSync(source, 'utf8'), scan.found);
|
|
956
|
+
collectCompiledInputs(source, includeSpellings(readFileSync(source, 'utf8')), scan.found);
|
|
1050
957
|
}
|
|
1051
958
|
for (const input of [...scan.found.values()].sort((left, right) =>
|
|
1052
959
|
left.file < right.file ? -1 : left.file > right.file ? 1 : 0,
|
|
@@ -1073,34 +980,11 @@ export async function hashCargoPathInputs(
|
|
|
1073
980
|
*/
|
|
1074
981
|
export async function dependencyClosure(cargo: CargoResolve, directory: string): Promise<CargoClosure> {
|
|
1075
982
|
const base = await realpath(directory);
|
|
1076
|
-
const selected = cargo.local
|
|
1077
|
-
.filter((pkg) => pkg.directory === base || pkg.directory.startsWith(`${base}${sep}`))
|
|
1078
|
-
.map((pkg) => pkg.id);
|
|
983
|
+
const selected = localPackagesUnder(cargo.local, base).map((pkg) => pkg.id);
|
|
1079
984
|
if (selected.length === 0) throw new Error(`no local Cargo package lies under ${directory}`);
|
|
1080
985
|
return buildClosure(cargo, selected);
|
|
1081
986
|
}
|
|
1082
987
|
|
|
1083
|
-
/**
|
|
1084
|
-
* The packages Cargo compiles to build, test or run the `selected` ones, each with the dependencies Cargo builds for
|
|
1085
|
-
* it. A selected package's targets reach every dependency kind: its library and binaries the normal ones, its build
|
|
1086
|
-
* script the build ones, its tests, examples and benches the dev ones. Below the selection Cargo builds a package for
|
|
1087
|
-
* its library and build script alone, so a dependency's own dev-dependencies never compile into a selected package's
|
|
1088
|
-
* binaries and are not part of what it builds.
|
|
1089
|
-
*/
|
|
1090
|
-
export function buildClosure(cargo: CargoResolve, selected: readonly string[]): CargoClosure {
|
|
1091
|
-
if (cargo.edges === null) throw new Error('cargo metadata reported no dependency resolution');
|
|
1092
|
-
const roots = new Set(selected);
|
|
1093
|
-
const reached = new Map<string, readonly string[]>();
|
|
1094
|
-
const pending = [...selected];
|
|
1095
|
-
for (let id = pending.pop(); id !== undefined; id = pending.pop()) {
|
|
1096
|
-
if (reached.has(id)) continue;
|
|
1097
|
-
const built = (cargo.edges.get(id) ?? []).filter((edge) => roots.has(id) || !edge.devOnly).map((edge) => edge.pkg);
|
|
1098
|
-
reached.set(id, built);
|
|
1099
|
-
pending.push(...built);
|
|
1100
|
-
}
|
|
1101
|
-
return reached;
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
988
|
/**
|
|
1105
989
|
* Whether git ignores a path beneath one of the package directories. A
|
|
1106
990
|
* package whose own directory is ignored (an installed dependency, say) keeps
|
|
@@ -1231,8 +1115,13 @@ function* compiledSourceFiles(root: string): Generator<string> {
|
|
|
1231
1115
|
}
|
|
1232
1116
|
}
|
|
1233
1117
|
|
|
1234
|
-
|
|
1235
|
-
|
|
1118
|
+
/** What a source with no include spells. */
|
|
1119
|
+
const NO_SPELLINGS: readonly string[] = [];
|
|
1120
|
+
|
|
1121
|
+
/** The paths a Rust source's text spells as literal include_str!/include_bytes! arguments. */
|
|
1122
|
+
function includeSpellings(text: string): readonly string[] {
|
|
1123
|
+
if (!text.includes('include_')) return NO_SPELLINGS;
|
|
1124
|
+
const spellings: string[] = [];
|
|
1236
1125
|
const tokens = rustTokens(text);
|
|
1237
1126
|
for (let index = 0; index < tokens.length; index += 1) {
|
|
1238
1127
|
if (tokens[index]?.text !== 'include_str' && tokens[index]?.text !== 'include_bytes') continue;
|
|
@@ -1244,7 +1133,18 @@ function collectCompiledInputs(source: string, text: string, found: Map<string,
|
|
|
1244
1133
|
// must reference path-sized storage, not a view into the decoded source.
|
|
1245
1134
|
const literal = Buffer.from(tokens[index + 3]?.text ?? '', 'utf8').toString('utf8');
|
|
1246
1135
|
const path = INCLUDE_STRING.exec(literal)?.[1] ?? INCLUDE_RAW_STRING.exec(literal)?.[2];
|
|
1247
|
-
if (path
|
|
1136
|
+
if (path !== undefined && path !== '') spellings.push(path);
|
|
1137
|
+
}
|
|
1138
|
+
return spellings;
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
/** Records each existing file `source` spells, keeping the smallest declaring source and spelling per file. */
|
|
1142
|
+
function collectCompiledInputs(
|
|
1143
|
+
source: string,
|
|
1144
|
+
spellings: readonly string[],
|
|
1145
|
+
found: Map<string, CompiledCargoInput>,
|
|
1146
|
+
): void {
|
|
1147
|
+
for (const path of spellings) {
|
|
1248
1148
|
const file = resolve(dirname(source), path);
|
|
1249
1149
|
if (statSync(file, { throwIfNoEntry: false })?.isFile()) {
|
|
1250
1150
|
const prior = found.get(file);
|
|
@@ -1256,15 +1156,89 @@ function collectCompiledInputs(source: string, text: string, found: Map<string,
|
|
|
1256
1156
|
}
|
|
1257
1157
|
|
|
1258
1158
|
/**
|
|
1259
|
-
*
|
|
1260
|
-
*
|
|
1261
|
-
*
|
|
1159
|
+
* The Rust sources and Cargo packages of Nx's workspace file index (.gitignore and .nxignore applied, as for every
|
|
1160
|
+
* fileset input), canonical and absolute. A graph computation takes a package's sources and nested packages from
|
|
1161
|
+
* here, so it lists no directory and probes no path for a manifest.
|
|
1162
|
+
*/
|
|
1163
|
+
export interface CargoSourceIndex {
|
|
1164
|
+
/** Every `Cargo.toml` in the index, relative to the workspace root. */
|
|
1165
|
+
readonly manifests: ReadonlySet<string>;
|
|
1166
|
+
/** Every directory holding an indexed `Cargo.toml`. */
|
|
1167
|
+
readonly packageDirectories: ReadonlySet<string>;
|
|
1168
|
+
/** Nx's content hash of every indexed `.rs` file. */
|
|
1169
|
+
readonly rustSources: ReadonlyMap<string, string>;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
/** {@link CargoSourceIndex} of Nx's file data (workspace-relative paths and content hashes) under the canonical `root`. */
|
|
1173
|
+
export function cargoSourceIndex(root: string, files: Iterable<FileData>): CargoSourceIndex {
|
|
1174
|
+
const manifests = new Set<string>();
|
|
1175
|
+
const packageDirectories = new Set<string>();
|
|
1176
|
+
const rustSources = new Map<string, string>();
|
|
1177
|
+
for (const { file, hash } of files) {
|
|
1178
|
+
if (file === 'Cargo.toml' || file.endsWith('/Cargo.toml')) {
|
|
1179
|
+
manifests.add(file);
|
|
1180
|
+
packageDirectories.add(dirname(join(root, file)));
|
|
1181
|
+
} else if (file.endsWith('.rs')) {
|
|
1182
|
+
rustSources.set(join(root, file), hash);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
return { manifests, packageDirectories, rustSources };
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
/**
|
|
1189
|
+
* The include spellings of every Rust source text scanned, by Nx's content hash of that text: a source whose hash is
|
|
1190
|
+
* unchanged is not read again. An entry is kept only when the text read hashes to that hash, so a write Nx's index has
|
|
1191
|
+
* not seen yet is scanned but never remembered under the hash of the bytes it replaced. Entries leave when no index
|
|
1192
|
+
* holds their hash any longer ({@link retainIncludeScans}); nothing expires by time.
|
|
1193
|
+
*/
|
|
1194
|
+
const includeScans = new Map<string, readonly string[]>();
|
|
1195
|
+
|
|
1196
|
+
/** Forgets the scan of every source text `index` no longer holds. */
|
|
1197
|
+
export function retainIncludeScans(index: CargoSourceIndex): void {
|
|
1198
|
+
const held = new Set(index.rustSources.values());
|
|
1199
|
+
for (const hash of includeScans.keys()) if (!held.has(hash)) includeScans.delete(hash);
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
function includeSpellingsOf(source: string, hash: string): readonly string[] {
|
|
1203
|
+
const known = includeScans.get(hash);
|
|
1204
|
+
if (known !== undefined) return known;
|
|
1205
|
+
const text = readFileSync(source, 'utf8');
|
|
1206
|
+
const spellings = includeSpellings(text);
|
|
1207
|
+
if (hashArray([text]) === hash) includeScans.set(hash, spellings);
|
|
1208
|
+
return spellings;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
const SCAN_SKIPPED: ReadonlySet<string> = new Set(HASH_SKIPPED_DIRECTORIES);
|
|
1212
|
+
|
|
1213
|
+
/** The indexed Rust sources of the package at `root`, with their hashes: none beneath a nested package or a skipped directory. */
|
|
1214
|
+
function* packageRustSources(root: string, index: CargoSourceIndex): Generator<readonly [string, string]> {
|
|
1215
|
+
const prefix = `${root}${sep}`;
|
|
1216
|
+
sources: for (const [source, hash] of index.rustSources) {
|
|
1217
|
+
if (!source.startsWith(prefix)) continue;
|
|
1218
|
+
for (let directory = dirname(source); directory !== root; directory = dirname(directory)) {
|
|
1219
|
+
if (index.packageDirectories.has(directory) || SCAN_SKIPPED.has(basename(directory))) continue sources;
|
|
1220
|
+
}
|
|
1221
|
+
yield [source, hash];
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
* Existing literal include_str!/include_bytes! files read by this package's Rust sources, as Nx's file index holds
|
|
1227
|
+
* them: a generated (ignored) source is its producer's output and keys a consumer through its dependency outputs.
|
|
1228
|
+
* One graph owns the memo; runtime hashing consumes the same discovery alongside source bytes. Nested packages own
|
|
1229
|
+
* their sources separately. Computed paths remain explicit inputs.
|
|
1262
1230
|
*/
|
|
1263
|
-
export function compiledInFiles(
|
|
1231
|
+
export function compiledInFiles(
|
|
1232
|
+
root: string,
|
|
1233
|
+
index: CargoSourceIndex,
|
|
1234
|
+
cache: Map<string, CompiledCargoInput[]>,
|
|
1235
|
+
): CompiledCargoInput[] {
|
|
1264
1236
|
const cached = cache.get(root);
|
|
1265
1237
|
if (cached !== undefined) return cached;
|
|
1266
1238
|
const found = new Map<string, CompiledCargoInput>();
|
|
1267
|
-
for (const source of
|
|
1239
|
+
for (const [source, hash] of packageRustSources(root, index)) {
|
|
1240
|
+
collectCompiledInputs(source, includeSpellingsOf(source, hash), found);
|
|
1241
|
+
}
|
|
1268
1242
|
const files = [...found.values()].sort((left, right) =>
|
|
1269
1243
|
left.file < right.file ? -1 : left.file > right.file ? 1 : 0,
|
|
1270
1244
|
);
|
|
@@ -19,8 +19,8 @@ import { delimiter, join } from 'node:path';
|
|
|
19
19
|
* wrapper's object, and one entry covers all three.
|
|
20
20
|
*
|
|
21
21
|
* rustc and cargo are not here on purpose. Cargo keys units on the output of `rustc -vV`, never on rustc's path, and the
|
|
22
|
-
* version recipe beside this one hashes it.
|
|
23
|
-
*
|
|
22
|
+
* version recipe beside this one hashes it. Shells of one host may carry different rust-std targets, so a rustc path
|
|
23
|
+
* would split one target's key between them.
|
|
24
24
|
*
|
|
25
25
|
* Only a path in the Nix store counts. A store object is named by the hash of everything it was built from, so one
|
|
26
26
|
* shell gives one object on every machine of a platform. A path elsewhere belongs to the machine and takes no part.
|
package/src/cargo-workspace.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { readFile, realpath } from 'node:fs/promises';
|
|
3
|
-
import { dirname, isAbsolute, join, posix, relative, resolve, sep } from 'node:path';
|
|
3
|
+
import { basename, dirname, isAbsolute, join, posix, relative, resolve, sep } from 'node:path';
|
|
4
|
+
import { buildClosure } from '@smoothbricks/build-inputs/cargo-closure';
|
|
4
5
|
import { readNxJson } from 'nx/src/config/nx-json.js';
|
|
5
6
|
import { parse as parseToml, type TomlTable } from 'smol-toml';
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
import {
|
|
8
|
+
type CargoResolve,
|
|
9
|
+
type CargoSourceIndex,
|
|
10
|
+
type CompiledCargoInput,
|
|
11
|
+
compiledInFiles,
|
|
12
|
+
} from './cargo-source-hash.js';
|
|
8
13
|
|
|
9
14
|
export interface CargoWorkspacePackage {
|
|
10
15
|
name: string;
|
|
@@ -225,6 +230,8 @@ export interface CargoPackageTestInputsOptions {
|
|
|
225
230
|
memberDir: string;
|
|
226
231
|
/** Cargo's locked resolve of that workspace, which decides the crates the member's tests build. */
|
|
227
232
|
cargo: CargoResolve;
|
|
233
|
+
/** Nx's indexed Cargo sources, where the crates' Rust sources and nested packages are found. */
|
|
234
|
+
sources: CargoSourceIndex;
|
|
228
235
|
/** Shared across every call of one graph computation; see {@link createCargoInputsCache}. */
|
|
229
236
|
cache?: CargoInputsCache;
|
|
230
237
|
}
|
|
@@ -236,7 +243,9 @@ export interface CargoPackageTestInputsOptions {
|
|
|
236
243
|
* three targets over ~45 crates that was ~135 derivations and the dominant
|
|
237
244
|
* cost of loading the graph. The cache lives exactly as long as one
|
|
238
245
|
* `createNodes` call — Nx recomputes the graph when a manifest changes, so
|
|
239
|
-
* nothing here can go stale across runs.
|
|
246
|
+
* nothing here can go stale across runs. What outlives the call is keyed by
|
|
247
|
+
* content, not by time: a Rust source's include scan by Nx's hash of it
|
|
248
|
+
* (`compiledInFiles`), so a recomputation reads only the sources that changed.
|
|
240
249
|
*/
|
|
241
250
|
export interface CargoInputsCache {
|
|
242
251
|
readonly manifests: Map<string, Promise<TomlTable>>;
|
|
@@ -249,6 +258,33 @@ export function createCargoInputsCache(): CargoInputsCache {
|
|
|
249
258
|
return { manifests: new Map(), nestedCrateDirs: new Map(), compiledInFiles: new Map(), results: new Map() };
|
|
250
259
|
}
|
|
251
260
|
|
|
261
|
+
/** A producer output a Cargo target hashes: the files one producer edge writes under one closure file set. */
|
|
262
|
+
export interface CargoProducerOutputInput {
|
|
263
|
+
readonly dependentTasksOutputFiles: string;
|
|
264
|
+
readonly transitive: false;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* The outputs of a Cargo target's producers its compile can read: one `dependentTasksOutputFiles` per file set of its
|
|
269
|
+
* closure (`cargoPackageTestInputs`, or the generic fallback rooted at `projectRoot`). A producer that writes a
|
|
270
|
+
* generated crate source, a compiled-in file or a manifest keys the target; one that writes anywhere else, such as a
|
|
271
|
+
* TypeScript package's `dist`, does not. Nx matches the glob against each output file's workspace-relative path (the
|
|
272
|
+
* same `matchGlobPaths` its `--check` uses), so the `{workspaceRoot}/` anchor is dropped. An exclusion or a named input
|
|
273
|
+
* has no output form, and a producer writes into no build directory the exclusions name.
|
|
274
|
+
*/
|
|
275
|
+
export function cargoProducerOutputInputs(
|
|
276
|
+
inputs: readonly (string | object)[],
|
|
277
|
+
projectRoot: string,
|
|
278
|
+
): CargoProducerOutputInput[] {
|
|
279
|
+
const globs = inputs.flatMap((input) => {
|
|
280
|
+
if (typeof input !== 'string') return [];
|
|
281
|
+
if (input.startsWith('{workspaceRoot}/')) return [input.slice('{workspaceRoot}/'.length)];
|
|
282
|
+
if (input.startsWith('{projectRoot}/')) return [posix.join(projectRoot, input.slice('{projectRoot}/'.length))];
|
|
283
|
+
return [];
|
|
284
|
+
});
|
|
285
|
+
return [...new Set(globs)].map((glob) => ({ dependentTasksOutputFiles: glob, transitive: false }));
|
|
286
|
+
}
|
|
287
|
+
|
|
252
288
|
export function cargoPackageTestInputs(options: CargoPackageTestInputsOptions): Promise<string[]> {
|
|
253
289
|
const cache = options.cache ?? createCargoInputsCache();
|
|
254
290
|
const key = `${options.absoluteProjectRoot}\0${options.memberDir}`;
|
|
@@ -260,7 +296,7 @@ export function cargoPackageTestInputs(options: CargoPackageTestInputsOptions):
|
|
|
260
296
|
}
|
|
261
297
|
|
|
262
298
|
async function deriveCargoPackageTestInputs(
|
|
263
|
-
{ workspaceRoot, absoluteProjectRoot, memberDir, cargo }: CargoPackageTestInputsOptions,
|
|
299
|
+
{ workspaceRoot, absoluteProjectRoot, memberDir, cargo, sources }: CargoPackageTestInputsOptions,
|
|
264
300
|
cache: CargoInputsCache,
|
|
265
301
|
): Promise<string[]> {
|
|
266
302
|
// Every fileset is anchored at `{workspaceRoot}`, never `{projectRoot}`: Nx
|
|
@@ -328,14 +364,14 @@ async function deriveCargoPackageTestInputs(
|
|
|
328
364
|
// Cargo packages can compile include_bytes!, headers, schemas and build.rs,
|
|
329
365
|
// not only Rust sources. Nested packages are separate source owners.
|
|
330
366
|
inputs.add(`${inputPath(absoluteDir)}/**/*`);
|
|
331
|
-
for (const child of nestedCrateDirs(absoluteDir, cache)) {
|
|
367
|
+
for (const child of nestedCrateDirs(absoluteDir, sources, cache)) {
|
|
332
368
|
const childDir = relative(cargoRoot, child).split(sep).join('/');
|
|
333
369
|
if (!dirs.has(childDir)) exclusions.add(`!${inputPath(child)}/**`);
|
|
334
370
|
}
|
|
335
371
|
// `include_str!("../../../skills/SKILL.md")` compiles a file the package's own
|
|
336
372
|
// fileset does not reach; a target that does not hash it serves a binary
|
|
337
373
|
// built from the file's old bytes.
|
|
338
|
-
for (const { file } of compiledInFiles(absoluteDir, cache.compiledInFiles)) {
|
|
374
|
+
for (const { file } of compiledInFiles(absoluteDir, sources, cache.compiledInFiles)) {
|
|
339
375
|
if (isOutsideRoot(relative(absoluteDir, file))) declaredSources.add(file);
|
|
340
376
|
}
|
|
341
377
|
}
|
|
@@ -415,25 +451,27 @@ export function requireExternalRustCratesInput(
|
|
|
415
451
|
}
|
|
416
452
|
|
|
417
453
|
/** Every directory beneath `root` that holds its own `Cargo.toml`, the walk stopping at each. */
|
|
418
|
-
|
|
454
|
+
/** Directories whose packages are never nested crates of a package: build output, VCS and Nx state, installed packages. */
|
|
455
|
+
const NESTED_CRATE_SKIPPED: ReadonlySet<string> = new Set(['target', '.git', 'node_modules', '.nx']);
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* The packages nested in the package at `root`: the indexed package directories beneath it with no other package,
|
|
459
|
+
* and no skipped directory, in between. Read from Nx's file index, so no directory is listed and no path probed.
|
|
460
|
+
*/
|
|
461
|
+
function nestedCrateDirs(root: string, sources: CargoSourceIndex, cache: CargoInputsCache): string[] {
|
|
419
462
|
const cached = cache.nestedCrateDirs.get(root);
|
|
420
463
|
if (cached !== undefined) return cached;
|
|
464
|
+
const prefix = `${root}${sep}`;
|
|
421
465
|
const found: string[] = [];
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
if (!entry.isDirectory()) continue;
|
|
428
|
-
const child = join(current, entry.name);
|
|
429
|
-
if (['target', '.git', 'node_modules', '.nx'].includes(entry.name)) {
|
|
430
|
-
} else if (existsSync(join(child, 'Cargo.toml'))) {
|
|
431
|
-
found.push(child);
|
|
432
|
-
} else {
|
|
433
|
-
scan.push(child);
|
|
434
|
-
}
|
|
466
|
+
nested: for (const directory of sources.packageDirectories) {
|
|
467
|
+
if (!directory.startsWith(prefix)) continue;
|
|
468
|
+
if (NESTED_CRATE_SKIPPED.has(basename(directory))) continue;
|
|
469
|
+
for (let parent = dirname(directory); parent !== root; parent = dirname(parent)) {
|
|
470
|
+
if (sources.packageDirectories.has(parent) || NESTED_CRATE_SKIPPED.has(basename(parent))) continue nested;
|
|
435
471
|
}
|
|
472
|
+
found.push(directory);
|
|
436
473
|
}
|
|
474
|
+
found.sort();
|
|
437
475
|
cache.nestedCrateDirs.set(root, found);
|
|
438
476
|
return found;
|
|
439
477
|
}
|
|
@@ -50,8 +50,9 @@ export interface ProducerSourceWitness {
|
|
|
50
50
|
readonly outputs: readonly string[];
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
* Git as receipts read it: the checkout and nothing of the operator's home. The producer hooks run in
|
|
54
|
-
*
|
|
53
|
+
* Git as receipts read it: the checkout and nothing of the operator's home. The producer hooks run in the process that
|
|
54
|
+
* runs the tasks (patches/README.md, "A run's task hooks run in its own process"), a host shell's or a sandboxed job's,
|
|
55
|
+
* under whatever HOME that process has; git with the operator's HOME
|
|
55
56
|
* reads the operator's global configuration, the sandbox denies it, and git dies (specs/cowshed/04_sandbox.md, the
|
|
56
57
|
* runtime-input contract). A receipt's tree, HEAD and tracked-file status are read under the repository's own
|
|
57
58
|
* configuration alone, so a host run and a sandboxed run agree on them.
|
|
@@ -16,8 +16,10 @@
|
|
|
16
16
|
* `createRequire(module).resolve` and each `import` with
|
|
17
17
|
* `import.meta.resolve(specifier, module)`.
|
|
18
18
|
*
|
|
19
|
-
* A builtin
|
|
20
|
-
*
|
|
19
|
+
* A builtin adds nothing. A package installed outside the workspace's own
|
|
20
|
+
* files is reported by name with the directory whose module loads it: the
|
|
21
|
+
* lint target keys it by the lock scope that declares it there
|
|
22
|
+
* (bun-lock-scope.ts, `bunLoadScope`). A package
|
|
21
23
|
* that resolves into the workspace's own files (a workspace member linked into
|
|
22
24
|
* `node_modules`) is keyed and walked like a relative module. Every loaded
|
|
23
25
|
* file keys the package.json files that decide how it loads: the nearest one
|
|
@@ -36,6 +38,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
|
36
38
|
import type * as Jiti from 'jiti';
|
|
37
39
|
import ts from 'typescript';
|
|
38
40
|
import typia from 'typia';
|
|
41
|
+
import { type PackageLoad, specifierPackage } from './bun-lock-scope.js';
|
|
39
42
|
|
|
40
43
|
type LoadKind = 'require' | 'import';
|
|
41
44
|
/** One load a module performs: CommonJS `require` and ESM `import` resolve under different conditions. */
|
|
@@ -72,16 +75,18 @@ console.log(JSON.stringify(loads.map(({ kind, specifier, from }) => {
|
|
|
72
75
|
|
|
73
76
|
/**
|
|
74
77
|
* The workspace-relative files `configs` load, transitively, the configs
|
|
75
|
-
* excluded, sorted
|
|
76
|
-
*
|
|
78
|
+
* excluded, sorted, and the installed packages those modules load by name.
|
|
79
|
+
* `indexed` is Nx's workspace file index (at least its JavaScript,
|
|
80
|
+
* TypeScript, JSON and package.json files); a file outside it refuses.
|
|
77
81
|
*/
|
|
78
82
|
export function eslintConfigClosure(
|
|
79
83
|
workspaceRoot: string,
|
|
80
84
|
configs: readonly string[],
|
|
81
85
|
indexed: ReadonlySet<string>,
|
|
82
|
-
): string[] {
|
|
86
|
+
): { readonly files: string[]; readonly packageLoads: PackageLoad[] } {
|
|
83
87
|
const root = realpathSync(workspaceRoot);
|
|
84
88
|
const keyed = new Set<string>();
|
|
89
|
+
const packageLoads = new Map<string, PackageLoad>();
|
|
85
90
|
const jiti = configs.some((config) => TYPESCRIPT_CONFIG.test(config)) ? workspaceJiti(workspaceRoot) : null;
|
|
86
91
|
for (const config of configs) {
|
|
87
92
|
const loader = TYPESCRIPT_CONFIG.test(config) ? jiti : null;
|
|
@@ -103,6 +108,11 @@ export function eslintConfigClosure(
|
|
|
103
108
|
const workspacePath = relative(root, real).split(sep).join('/');
|
|
104
109
|
const installed = workspacePath.split('/').includes('node_modules');
|
|
105
110
|
if (workspacePath.startsWith('../') || isAbsolute(workspacePath) || installed) {
|
|
111
|
+
if (load.bare) {
|
|
112
|
+
const directory = relative(root, dirname(load.from)).split(sep).join('/') || '.';
|
|
113
|
+
const name = specifierPackage(load.specifier);
|
|
114
|
+
packageLoads.set(`${directory}\0${name}`, { directory, name });
|
|
115
|
+
}
|
|
106
116
|
if (load.bare || installed) return;
|
|
107
117
|
throw new Error(
|
|
108
118
|
`${load.importer} imports '${load.specifier}', which resolves outside the workspace to ${real}`,
|
|
@@ -121,7 +131,18 @@ export function eslintConfigClosure(
|
|
|
121
131
|
});
|
|
122
132
|
}
|
|
123
133
|
}
|
|
124
|
-
return
|
|
134
|
+
return {
|
|
135
|
+
files: [...keyed].sort(),
|
|
136
|
+
packageLoads: [...packageLoads.values()].sort((left, right) =>
|
|
137
|
+
left.directory === right.directory
|
|
138
|
+
? left.name < right.name
|
|
139
|
+
? -1
|
|
140
|
+
: 1
|
|
141
|
+
: left.directory < right.directory
|
|
142
|
+
? -1
|
|
143
|
+
: 1,
|
|
144
|
+
),
|
|
145
|
+
};
|
|
125
146
|
}
|
|
126
147
|
|
|
127
148
|
/** The loads `module` performs that resolve to a file; refuses a computed load or an unresolvable specifier kind. */
|
|
@@ -26,6 +26,8 @@ export interface ObservationHost {
|
|
|
26
26
|
step(event: BoundEvent): void;
|
|
27
27
|
/** Whether the command is running a test. */
|
|
28
28
|
testing(): boolean;
|
|
29
|
+
/** Same sleep-excluding clock as the executor's idle bound. */
|
|
30
|
+
awakeNow(): number;
|
|
29
31
|
readonly queueHost: QueueHost | undefined;
|
|
30
32
|
}
|
|
31
33
|
|
|
@@ -41,7 +43,7 @@ export class AdmissionObservation {
|
|
|
41
43
|
* and ends nothing: the bounds decide, and an idle expiry names it.
|
|
42
44
|
*/
|
|
43
45
|
private failure: string | null = null;
|
|
44
|
-
/** When the last successful snapshot completed
|
|
46
|
+
/** When the last successful snapshot completed on the awake clock: credit runs to it and no further. */
|
|
45
47
|
private confirmedAt: number | null = null;
|
|
46
48
|
private readonly abort = new AbortController();
|
|
47
49
|
private timer: NodeJS.Timeout | undefined;
|
|
@@ -64,12 +66,12 @@ export class AdmissionObservation {
|
|
|
64
66
|
queueWait(reserved: boolean): AdmissionQueueWait | null {
|
|
65
67
|
return this.admitted || (this.requests.length === 0 && !reserved)
|
|
66
68
|
? null
|
|
67
|
-
: { waitedMs: admissionWaitMs(this.wait,
|
|
69
|
+
: { waitedMs: admissionWaitMs(this.wait, this.host.awakeNow()), requests: this.requests };
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
/** A reserved leaf's request began to wait on its run's endpoint. */
|
|
71
73
|
waiting(): void {
|
|
72
|
-
this.wait = stepAdmissionWait(this.wait, { kind: 'snapshot', at:
|
|
74
|
+
this.wait = stepAdmissionWait(this.wait, { kind: 'snapshot', at: this.host.awakeNow(), waiting: true });
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
/** Only mbx's activity report says whether a Cargo leaf's compiler or test waits in the pool: poll it. */
|
|
@@ -82,7 +84,7 @@ export class AdmissionObservation {
|
|
|
82
84
|
|
|
83
85
|
/** The run ended: the wait stops counting and no snapshot is taken or credited again. */
|
|
84
86
|
stop(): void {
|
|
85
|
-
this.wait = stepAdmissionWait(this.wait, { kind: 'stop', at:
|
|
87
|
+
this.wait = stepAdmissionWait(this.wait, { kind: 'stop', at: this.host.awakeNow() });
|
|
86
88
|
clearInterval(this.timer);
|
|
87
89
|
this.abort.abort();
|
|
88
90
|
}
|
|
@@ -101,11 +103,11 @@ export class AdmissionObservation {
|
|
|
101
103
|
}
|
|
102
104
|
this.failure = detail;
|
|
103
105
|
this.requests = [];
|
|
104
|
-
this.wait = stepAdmissionWait(this.wait, { kind: 'snapshot', at:
|
|
106
|
+
this.wait = stepAdmissionWait(this.wait, { kind: 'snapshot', at: this.host.awakeNow(), waiting: false });
|
|
105
107
|
// The wait since the last confirmed snapshot is unconfirmed: the idle bound resumes from that snapshot.
|
|
106
108
|
this.host.step({
|
|
107
109
|
kind: 'admission-queue',
|
|
108
|
-
at: this.confirmedAt ??
|
|
110
|
+
at: this.confirmedAt ?? this.host.awakeNow(),
|
|
109
111
|
waiting: false,
|
|
110
112
|
testing: this.host.testing(),
|
|
111
113
|
});
|
|
@@ -129,9 +131,8 @@ export class AdmissionObservation {
|
|
|
129
131
|
}
|
|
130
132
|
this.lastSnapshotDiagnostics = diagnostics;
|
|
131
133
|
const waiting = snapshot.requests.length > 0;
|
|
132
|
-
const observedAt =
|
|
133
|
-
|
|
134
|
-
this.wait = stepAdmissionWait(this.wait, { kind: 'snapshot', at: observedWaitAt, waiting });
|
|
134
|
+
const observedAt = this.host.awakeNow();
|
|
135
|
+
this.wait = stepAdmissionWait(this.wait, { kind: 'snapshot', at: observedAt, waiting });
|
|
135
136
|
this.failure = null;
|
|
136
137
|
this.confirmedAt = observedAt;
|
|
137
138
|
if (waiting) {
|
|
@@ -142,7 +143,7 @@ export class AdmissionObservation {
|
|
|
142
143
|
this.lastDiagnosticAt === null ||
|
|
143
144
|
Date.now() - this.lastDiagnosticAt >= HANG_CAPTURE_MS
|
|
144
145
|
) {
|
|
145
|
-
const waitedMs = admissionWaitMs(this.wait,
|
|
146
|
+
const waitedMs = admissionWaitMs(this.wait, observedAt);
|
|
146
147
|
this.host.tell(`cowshed: mbx ${describeAdmissionQueue({ waitedMs, requests: snapshot.requests })}\n`);
|
|
147
148
|
this.lastDiagnostic = positions;
|
|
148
149
|
this.lastDiagnosticAt = Date.now();
|