@smoothbricks/nx-plugin 0.7.17 → 0.7.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 +204 -64
- package/dist/.build-inputs.json +24 -21
- 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 +14 -11
- package/dist/cargo-source-hash.d.ts +23 -4
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +80 -14
- package/dist/cargo-workspace.d.ts +20 -2
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +42 -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/bounds.d.ts +12 -1
- package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
- package/dist/executors/bounded-exec/bounds.js +8 -4
- 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/executor.d.ts +1 -1
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +54 -22
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts +8 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
- package/dist/executors/bounded-exec/hang-diagnostics.js +66 -6
- package/dist/executors/bounded-exec/mbx-pool.d.ts +16 -2
- package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/mbx-pool.js +18 -2
- package/dist/executors/bounded-exec/mbx-reservations.d.ts +5 -2
- package/dist/executors/bounded-exec/mbx-reservations.d.ts.map +1 -1
- package/dist/executors/bounded-exec/mbx-reservations.js +5 -3
- 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 +2 -1
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -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/schema.d.ts +5 -0
- 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/verdict.d.ts +13 -6
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +34 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +199 -89
- 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/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-index.d.ts +14 -1
- package/dist/workspace-index.d.ts.map +1 -1
- package/dist/workspace-index.js +36 -4
- package/managed/raw/patches/nx@24.0.3.patch +703 -119
- package/managed/raw/tooling/direnv/developer-links.ts +17 -3
- 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 +3 -2
- package/src/bun-lock-scope.ts +293 -40
- package/src/cargo-closure-input.ts +19 -11
- package/src/cargo-source-hash.ts +103 -13
- package/src/cargo-workspace.ts +59 -20
- package/src/ensure-built-receipt.ts +3 -2
- package/src/eslint-config-closure.ts +27 -6
- package/src/executors/bounded-exec/bounds.ts +13 -4
- package/src/executors/bounded-exec/cpu-rise.ts +156 -0
- package/src/executors/bounded-exec/executor.ts +65 -21
- package/src/executors/bounded-exec/hang-diagnostics.ts +88 -6
- package/src/executors/bounded-exec/mbx-pool.ts +24 -3
- package/src/executors/bounded-exec/mbx-reservations.ts +7 -5
- package/src/executors/bounded-exec/progress-channel.ts +129 -0
- package/src/executors/bounded-exec/progress.ts +2 -1
- package/src/executors/bounded-exec/ram-temp.ts +137 -17
- package/src/executors/bounded-exec/schema.ts +19 -0
- package/src/executors/bounded-exec/verdict.ts +44 -16
- package/src/index.ts +255 -98
- 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-index.ts +40 -5
- package/test-timings.json +6 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import type { FileChange, Tree } from 'nx/src/devkit-exports.js';
|
|
3
|
+
import type { ManagedFile } from './tree.js';
|
|
4
|
+
|
|
5
|
+
/** What a render can ask a Tree. */
|
|
6
|
+
type Question = 'read' | 'exists' | 'isFile' | 'children';
|
|
7
|
+
|
|
8
|
+
/** One question a render asked, and the answer it got: a digest of the bytes for a read. */
|
|
9
|
+
interface Answer {
|
|
10
|
+
readonly question: Question;
|
|
11
|
+
readonly path: string;
|
|
12
|
+
readonly value: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** A render's result, and every answer it was computed from. */
|
|
16
|
+
interface Render {
|
|
17
|
+
readonly key: string;
|
|
18
|
+
readonly answers: readonly Answer[];
|
|
19
|
+
readonly files: readonly ManagedFile[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The last render of each workspace root. Replaced by the next render of that root; never expired by time. */
|
|
23
|
+
const renders = new Map<string, Render>();
|
|
24
|
+
|
|
25
|
+
function readValue(bytes: Buffer | null): string {
|
|
26
|
+
return bytes === null ? 'absent' : createHash('sha256').update(bytes).digest('base64');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function answerOf(tree: Tree, question: Question, path: string): string {
|
|
30
|
+
switch (question) {
|
|
31
|
+
case 'read':
|
|
32
|
+
return readValue(tree.read(path));
|
|
33
|
+
case 'exists':
|
|
34
|
+
return String(tree.exists(path));
|
|
35
|
+
case 'isFile':
|
|
36
|
+
return String(tree.isFile(path));
|
|
37
|
+
case 'children':
|
|
38
|
+
return JSON.stringify(tree.children(path));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A Tree that answers from another and keeps every answer it gave. A render that reads the workspace only through
|
|
44
|
+
* it is a function of those answers and of what its caller keys it on. It refuses every write: a render reads the
|
|
45
|
+
* Tree, and staging alone writes it.
|
|
46
|
+
*/
|
|
47
|
+
class AnsweringTree implements Tree {
|
|
48
|
+
readonly answers = new Map<string, Answer>();
|
|
49
|
+
|
|
50
|
+
constructor(private readonly tree: Tree) {}
|
|
51
|
+
|
|
52
|
+
get root(): string {
|
|
53
|
+
return this.tree.root;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
read(filePath: string): Buffer | null;
|
|
57
|
+
read(filePath: string, encoding: BufferEncoding): string | null;
|
|
58
|
+
read(filePath: string, encoding?: BufferEncoding): Buffer | string | null {
|
|
59
|
+
const bytes = this.tree.read(filePath);
|
|
60
|
+
this.keep('read', filePath, readValue(bytes));
|
|
61
|
+
return bytes === null || encoding === undefined ? bytes : bytes.toString(encoding);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exists(filePath: string): boolean {
|
|
65
|
+
return this.keep('exists', filePath, String(this.tree.exists(filePath))) === 'true';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
isFile(filePath: string): boolean {
|
|
69
|
+
return this.keep('isFile', filePath, String(this.tree.isFile(filePath))) === 'true';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
children(dirPath: string): string[] {
|
|
73
|
+
const children = this.tree.children(dirPath);
|
|
74
|
+
this.keep('children', dirPath, JSON.stringify(children));
|
|
75
|
+
return children;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
listChanges(): FileChange[] {
|
|
79
|
+
return this.tree.listChanges();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
write(filePath: string): never {
|
|
83
|
+
throw readOnly(filePath);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
delete(filePath: string): never {
|
|
87
|
+
throw readOnly(filePath);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
rename(from: string): never {
|
|
91
|
+
throw readOnly(from);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
changePermissions(filePath: string): never {
|
|
95
|
+
throw readOnly(filePath);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private keep(question: Question, path: string, value: string): string {
|
|
99
|
+
this.answers.set(`${question}\0${path}`, { question, path, value });
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function readOnly(path: string): Error {
|
|
105
|
+
return new Error(`${path}: a managed-files render reads the Tree; only staging writes it`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The files `render` gives for `tree`, rendered again only when one of its inputs changed: `key`, which names what the
|
|
110
|
+
* render reads beside the Tree (the context, the source listing), or an answer the Tree gave it. Checking the answers
|
|
111
|
+
* reads each file the last render read, once; the render itself (policy, JSON edits, formatter runs) is skipped.
|
|
112
|
+
*
|
|
113
|
+
* A Tree with pending edits is rendered and nothing is kept: no later Tree shows those edits as they are here.
|
|
114
|
+
* The formatters' own configuration is not an answer: Prettier and Biome read it from disk, and Prettier keeps it for
|
|
115
|
+
* the life of the process, so a daemon already formats with what it first read.
|
|
116
|
+
*/
|
|
117
|
+
export async function renderedOnChange(
|
|
118
|
+
tree: Tree,
|
|
119
|
+
key: string,
|
|
120
|
+
render: (tree: Tree) => Promise<ManagedFile[]>,
|
|
121
|
+
): Promise<readonly ManagedFile[]> {
|
|
122
|
+
if (tree.listChanges().length > 0) return render(tree);
|
|
123
|
+
const last = renders.get(tree.root);
|
|
124
|
+
if (
|
|
125
|
+
last !== undefined &&
|
|
126
|
+
last.key === key &&
|
|
127
|
+
last.answers.every(({ question, path, value }) => answerOf(tree, question, path) === value)
|
|
128
|
+
) {
|
|
129
|
+
return last.files;
|
|
130
|
+
}
|
|
131
|
+
const answering = new AnsweringTree(tree);
|
|
132
|
+
const files = await render(answering);
|
|
133
|
+
renders.set(tree.root, { key, answers: [...answering.answers.values()], files });
|
|
134
|
+
return files;
|
|
135
|
+
}
|
package/src/test-program.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { posix } from 'node:path';
|
|
2
|
-
import type { Tree } from 'nx/src/devkit-exports.js';
|
|
3
2
|
import { isNonSourceDirectory } from './source-directories.js';
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -20,9 +19,6 @@ export interface TestProgram {
|
|
|
20
19
|
readonly readConfig: (path: string) => Record<string, unknown> | null;
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
/** A directory listing the walker can use: an Nx `Tree`, or the disk behind a small adapter. */
|
|
24
|
-
export type ProjectTree = Pick<Tree, 'children' | 'isFile'>;
|
|
25
|
-
|
|
26
22
|
/** Why a test program typechecks none of what it exists to typecheck. */
|
|
27
23
|
export type TestProgramFault =
|
|
28
24
|
| { readonly kind: 'no-tests' }
|
|
@@ -49,51 +45,50 @@ const PACKAGE_CONVENTION_ROOT = 'src';
|
|
|
49
45
|
const TESTS_DIRECTORY = '__tests__';
|
|
50
46
|
|
|
51
47
|
/**
|
|
52
|
-
* The TypeScript sources
|
|
48
|
+
* The files {@link typeScriptSourcesByProject} lists from: the TypeScript sources, and the manifests that make a
|
|
49
|
+
* directory a project of its own.
|
|
50
|
+
*/
|
|
51
|
+
export const SOURCE_LISTING_GLOBS = ['**/*.{ts,tsx,mts,cts}', '**/{package,project}.json'];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The TypeScript sources of each of `projectRoots`, project-relative and sorted, from one listing of the workspace's
|
|
55
|
+
* files (workspace-relative; a file that is neither a source nor a manifest is passed over). One pass over the listing
|
|
56
|
+
* answers every project: no directory is listed and no file is probed.
|
|
53
57
|
*
|
|
54
58
|
* A directory below the project that is a project of its own (its own manifest or Nx project file) is not part of
|
|
55
59
|
* this one: its files are its own tests, found by its own policy pass, and folding them in would count them twice.
|
|
56
60
|
* A directory that merely carries a tsconfig is not that: in a monorepo of Bun programs such a file routes the
|
|
57
61
|
* directory's files to the parent's program (a `tests/tsconfig.json` extending `../tsconfig.test.json`), and
|
|
58
|
-
* nothing typechecks the directory but that program.
|
|
62
|
+
* nothing typechecks the directory but that program. Nothing beneath a build-output or dot directory is a source
|
|
63
|
+
* ({@link isNonSourceDirectory}).
|
|
59
64
|
*/
|
|
60
|
-
export function
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
);
|
|
65
|
+
export function typeScriptSourcesByProject(
|
|
66
|
+
files: Iterable<string>,
|
|
67
|
+
projectRoots: Iterable<string>,
|
|
68
|
+
): ReadonlyMap<string, readonly string[]> {
|
|
69
|
+
const sources = new Map<string, string[]>();
|
|
70
|
+
for (const root of projectRoots) sources.set(root === '' ? '.' : root, []);
|
|
71
|
+
const owners = new Set(sources.keys());
|
|
72
|
+
const listed: string[] = [];
|
|
73
|
+
for (const file of files) {
|
|
74
|
+
const name = posix.basename(file);
|
|
75
|
+
if (PROJECT_FILE.test(name)) owners.add(posix.dirname(file));
|
|
76
|
+
if (TYPESCRIPT_SOURCE.test(name)) listed.push(file);
|
|
77
|
+
}
|
|
78
|
+
for (const file of listed) {
|
|
79
|
+
const owner = ownerOf(file, owners);
|
|
80
|
+
if (owner === null) continue;
|
|
81
|
+
sources.get(owner)?.push(owner === '.' ? file : file.slice(owner.length + 1));
|
|
82
|
+
}
|
|
83
|
+
for (const list of sources.values()) list.sort();
|
|
84
|
+
return sources;
|
|
81
85
|
}
|
|
82
86
|
|
|
83
|
-
/**
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// ELOOP is a link cycle: there is nothing beneath it to list.
|
|
89
|
-
if (
|
|
90
|
-
error instanceof Error &&
|
|
91
|
-
'code' in error &&
|
|
92
|
-
(error.code === 'ENOENT' || error.code === 'ENOTDIR' || error.code === 'ELOOP')
|
|
93
|
-
) {
|
|
94
|
-
return [];
|
|
95
|
-
}
|
|
96
|
-
throw error;
|
|
87
|
+
/** The nearest directory holding a file that is a project, or null when a build-output or dot directory comes first. */
|
|
88
|
+
function ownerOf(file: string, owners: ReadonlySet<string>): string | null {
|
|
89
|
+
for (let directory = posix.dirname(file); ; directory = posix.dirname(directory)) {
|
|
90
|
+
if (owners.has(directory)) return directory;
|
|
91
|
+
if (directory === '.' || isNonSourceDirectory(posix.basename(directory))) return null;
|
|
97
92
|
}
|
|
98
93
|
}
|
|
99
94
|
|
package/src/tool-bins.ts
CHANGED
|
@@ -41,6 +41,11 @@ export interface NativeTools {
|
|
|
41
41
|
readonly target: string;
|
|
42
42
|
/** Each tool package that is a project of this workspace, to its project name. */
|
|
43
43
|
readonly projects: ReadonlyMap<NativeToolPackage, string>;
|
|
44
|
+
/**
|
|
45
|
+
* The Nx project of the plugin itself, when this workspace owns it: the executors it ships are files its own
|
|
46
|
+
* build writes. An installed plugin ships them built, so a consumer has none.
|
|
47
|
+
*/
|
|
48
|
+
readonly plugin: string | undefined;
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
/**
|
|
@@ -54,6 +59,7 @@ export async function resolveNativeTools(
|
|
|
54
59
|
target: string,
|
|
55
60
|
): Promise<NativeTools> {
|
|
56
61
|
const projects = new Map<NativeToolPackage, string>();
|
|
62
|
+
let pluginProject: string | undefined;
|
|
57
63
|
const plugin = await realpath(join(workspaceRoot, PLUGIN_LINK)).catch((error: unknown) => {
|
|
58
64
|
// A workspace whose install has not linked the plugin yet has no tool package of its own either.
|
|
59
65
|
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') return null;
|
|
@@ -61,16 +67,21 @@ export async function resolveNativeTools(
|
|
|
61
67
|
});
|
|
62
68
|
if (plugin !== null) {
|
|
63
69
|
const root = await realpath(workspaceRoot);
|
|
64
|
-
|
|
65
|
-
const manifest = relative(root, join(
|
|
66
|
-
if (!projectManifests.includes(manifest))
|
|
70
|
+
const owned = async (directory: string, package_: string): Promise<string | undefined> => {
|
|
71
|
+
const manifest = relative(root, join(directory, 'package.json')).replaceAll('\\', '/');
|
|
72
|
+
if (!projectManifests.includes(manifest)) return undefined;
|
|
67
73
|
const parsed: unknown = JSON.parse(await readFile(join(root, manifest), 'utf8'));
|
|
68
74
|
const name = projectName(parsed);
|
|
69
|
-
if (name === undefined) throw new Error(`${manifest}:
|
|
70
|
-
|
|
75
|
+
if (name === undefined) throw new Error(`${manifest}: ${package_} names its Nx project in name or nx.name`);
|
|
76
|
+
return name;
|
|
77
|
+
};
|
|
78
|
+
pluginProject = await owned(plugin, 'the plugin package');
|
|
79
|
+
for (const tool of NATIVE_TOOL_PACKAGES) {
|
|
80
|
+
const name = await owned(join(dirname(plugin), tool), 'a tool package');
|
|
81
|
+
if (name !== undefined) projects.set(tool, name);
|
|
71
82
|
}
|
|
72
83
|
}
|
|
73
|
-
return { platform, target, projects };
|
|
84
|
+
return { platform, target, projects, plugin: pluginProject };
|
|
74
85
|
}
|
|
75
86
|
|
|
76
87
|
function projectName(manifest: unknown): string | undefined {
|
|
@@ -110,3 +121,21 @@ export function nativeToolDependsOn(
|
|
|
110
121
|
? []
|
|
111
122
|
: [{ projects: [project], target: target ?? (tool === 'cowshed' ? 'napi-native' : tools.target) }];
|
|
112
123
|
}
|
|
124
|
+
|
|
125
|
+
/** The plugin executors its own build runs: they load from a dist an earlier build left, so none can wait for it. */
|
|
126
|
+
const BOOTSTRAP_EXECUTORS: ReadonlySet<string> = new Set([
|
|
127
|
+
'@smoothbricks/nx-plugin:typescript-emit',
|
|
128
|
+
'@smoothbricks/nx-plugin:scriptc-native',
|
|
129
|
+
]);
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The task that leaves the plugin's executors built, for a target whose `executor` is one of them, only when this
|
|
133
|
+
* workspace owns the plugin's package (an installed plugin ships its executors built). The executor is a file the
|
|
134
|
+
* plugin's own build writes, so a target that starts before that build ends loads the dist a previous build left, which
|
|
135
|
+
* lacks an executor the plugin gained since, or none at all.
|
|
136
|
+
*/
|
|
137
|
+
export function pluginBuildDependsOn(tools: NativeTools | null, executor: unknown): TargetDependency[] {
|
|
138
|
+
if (tools?.plugin === undefined || typeof executor !== 'string') return [];
|
|
139
|
+
if (!executor.startsWith('@smoothbricks/nx-plugin:') || BOOTSTRAP_EXECUTORS.has(executor)) return [];
|
|
140
|
+
return [{ projects: [tools.plugin], target: 'build' }];
|
|
141
|
+
}
|
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import { existsSync, readdirSync, readFileSync
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { dirname, join, posix, relative } from 'node:path';
|
|
3
3
|
import type { Tree } from 'nx/src/devkit-exports.js';
|
|
4
4
|
import { getProjects, parseJson, readJson, readProjectConfiguration } from 'nx/src/devkit-exports.js';
|
|
5
|
+
import { globWithWorkspaceContextSync } from 'nx/src/utils/workspace-context.js';
|
|
5
6
|
import typia from 'typia';
|
|
6
7
|
import { editJsonText } from './managed-files/json-edit.js';
|
|
7
8
|
import { formatJsonWithBiome, jsonFileText } from './managed-files/managed-format.js';
|
|
8
9
|
import type { ManagedFile } from './managed-files/tree.js';
|
|
9
10
|
import {
|
|
10
11
|
includeGlobsFor,
|
|
11
|
-
|
|
12
|
-
type ProjectTree,
|
|
12
|
+
SOURCE_LISTING_GLOBS,
|
|
13
13
|
type TestProgram,
|
|
14
14
|
type TestProgramFault,
|
|
15
15
|
testProgramFault,
|
|
16
|
+
typeScriptSourcesByProject,
|
|
16
17
|
} from './test-program.js';
|
|
17
18
|
import { isRecord } from './type-guards.js';
|
|
18
19
|
import type { NxPolicyIssue } from './workspace-config-policy.js';
|
|
20
|
+
import { freshIndexedFiles } from './workspace-index.js';
|
|
19
21
|
import { workspacePackagePatterns } from './workspace-manifest.js';
|
|
20
22
|
|
|
21
23
|
export type TestRunner = 'bun' | 'vitest';
|
|
@@ -261,8 +263,13 @@ export function removeTsconfigTestReference(projectTsconfig: Record<string, unkn
|
|
|
261
263
|
*/
|
|
262
264
|
export function checkTypecheckTestPolicyTree(tree: Tree): NxPolicyIssue[] {
|
|
263
265
|
const issues: NxPolicyIssue[] = [];
|
|
266
|
+
const projects = getProjects(tree);
|
|
267
|
+
const sources = typeScriptSourcesByProject(
|
|
268
|
+
treeSourceListing(tree),
|
|
269
|
+
[...projects.values()].map((project) => project.root),
|
|
270
|
+
);
|
|
264
271
|
|
|
265
|
-
for (const [projectName, config] of
|
|
272
|
+
for (const [projectName, config] of projects) {
|
|
266
273
|
const pkgPath = `${config.root}/package.json`;
|
|
267
274
|
if (!tree.exists(pkgPath)) continue;
|
|
268
275
|
if (config.root === '.' || config.root === '') continue;
|
|
@@ -289,7 +296,7 @@ export function checkTypecheckTestPolicyTree(tree: Tree): NxPolicyIssue[] {
|
|
|
289
296
|
// Check tsconfig.test.json contents
|
|
290
297
|
const tsconfigTest = readJson<Record<string, unknown>>(tree, tsconfigTestPath);
|
|
291
298
|
issues.push(...checkTypecheckTestConfig(tsconfigTest, config.root));
|
|
292
|
-
const fault = testProgramFault(treeProgram(tree, config.root), tsconfigTest);
|
|
299
|
+
const fault = testProgramFault(treeProgram(tree, config.root, sources), tsconfigTest);
|
|
293
300
|
if (fault !== null) {
|
|
294
301
|
issues.push({ path: tsconfigTestPath, message: testProgramFaultMessage(config.root, testRunners, fault) });
|
|
295
302
|
}
|
|
@@ -308,12 +315,18 @@ export function checkTypecheckTestPolicyTree(tree: Tree): NxPolicyIssue[] {
|
|
|
308
315
|
/**
|
|
309
316
|
* Render test typechecking policy from the caller's Tree. The managed generator
|
|
310
317
|
* owns staging, permission checks, and flushing together with its other files.
|
|
318
|
+
* `listing` is {@link treeSourceListing} of the same Tree: the caller holds it, as the render's memo is keyed on it.
|
|
311
319
|
*/
|
|
312
|
-
export function renderTypecheckTestFiles(tree: Tree): ManagedFile[] {
|
|
320
|
+
export function renderTypecheckTestFiles(tree: Tree, listing: readonly string[]): ManagedFile[] {
|
|
313
321
|
const files: ManagedFile[] = [];
|
|
314
322
|
const workspacePackages = collectWorkspacePackagesTree(tree);
|
|
323
|
+
const projects = getProjects(tree);
|
|
324
|
+
const sources = typeScriptSourcesByProject(
|
|
325
|
+
listing,
|
|
326
|
+
[...projects.values()].map((project) => project.root),
|
|
327
|
+
);
|
|
315
328
|
|
|
316
|
-
for (const [projectName, config] of
|
|
329
|
+
for (const [projectName, config] of projects) {
|
|
317
330
|
const pkgPath = `${config.root}/package.json`;
|
|
318
331
|
if (!tree.exists(pkgPath)) continue;
|
|
319
332
|
if (config.root === '.' || config.root === '') continue;
|
|
@@ -341,7 +354,7 @@ export function renderTypecheckTestFiles(tree: Tree): ManagedFile[] {
|
|
|
341
354
|
// Collect reference paths
|
|
342
355
|
const referencePaths = collectReferencePathsTree(tree, config.root, pkg, workspacePackages);
|
|
343
356
|
|
|
344
|
-
const program = treeProgram(tree, config.root);
|
|
357
|
+
const program = treeProgram(tree, config.root, sources);
|
|
345
358
|
applyTypecheckTestDefaults(tsconfigTest, {
|
|
346
359
|
testRunners,
|
|
347
360
|
testExtends,
|
|
@@ -397,28 +410,34 @@ function renderTsconfig(tree: Tree, target: string, after: Record<string, unknow
|
|
|
397
410
|
return { target, content: edited === current ? current : formatJsonWithBiome(path, edited) };
|
|
398
411
|
}
|
|
399
412
|
|
|
400
|
-
|
|
413
|
+
/**
|
|
414
|
+
* The files a Tree's source listing reads, workspace-relative and sorted: Nx's workspace file index for the Tree's
|
|
415
|
+
* root, with the Tree's pending edits over it, as devkit's own `getProjects` lists project files. The index applies
|
|
416
|
+
* .gitignore and .nxignore, so the listing is what the commit holds, the same in every checkout, and never build
|
|
417
|
+
* output one disk happens to carry; it is read from memory, so no directory is listed and no file probed. A path a
|
|
418
|
+
* pending edit writes is listed whatever its name: the listing passes over what is neither a source nor a manifest.
|
|
419
|
+
*/
|
|
420
|
+
export function treeSourceListing(tree: Tree): string[] {
|
|
421
|
+
const files = new Set(globWithWorkspaceContextSync(tree.root, SOURCE_LISTING_GLOBS));
|
|
422
|
+
for (const change of tree.listChanges()) {
|
|
423
|
+
if (change.type === 'DELETE') files.delete(change.path);
|
|
424
|
+
else files.add(change.path);
|
|
425
|
+
}
|
|
426
|
+
return [...files].sort();
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function treeProgram(tree: Tree, projectRoot: string, sources: ReadonlyMap<string, readonly string[]>): TestProgram {
|
|
401
430
|
return {
|
|
402
431
|
projectRoot,
|
|
403
|
-
files:
|
|
432
|
+
files: sources.get(projectRoot) ?? [],
|
|
404
433
|
readConfig: (path) => (tree.exists(path) ? readJson<Record<string, unknown>>(tree, path) : null),
|
|
405
434
|
};
|
|
406
435
|
}
|
|
407
436
|
|
|
408
|
-
function diskProgram(root: string, projectRoot: string): TestProgram {
|
|
409
|
-
const disk: ProjectTree = {
|
|
410
|
-
children: (directory) => readdirSync(join(root, directory)),
|
|
411
|
-
isFile: (path) => {
|
|
412
|
-
try {
|
|
413
|
-
return statSync(join(root, path)).isFile();
|
|
414
|
-
} catch {
|
|
415
|
-
return false;
|
|
416
|
-
}
|
|
417
|
-
},
|
|
418
|
-
};
|
|
437
|
+
function diskProgram(root: string, projectRoot: string, sources: ReadonlyMap<string, readonly string[]>): TestProgram {
|
|
419
438
|
return {
|
|
420
439
|
projectRoot,
|
|
421
|
-
files:
|
|
440
|
+
files: sources.get(projectRoot) ?? [],
|
|
422
441
|
readConfig: (path) => readJsonObject(join(root, path)),
|
|
423
442
|
};
|
|
424
443
|
}
|
|
@@ -450,7 +469,13 @@ function testProgramFaultMessage(
|
|
|
450
469
|
export function checkTypecheckTestPolicy(root: string): NxPolicyIssue[] {
|
|
451
470
|
const issues: NxPolicyIssue[] = [];
|
|
452
471
|
const workspaceNames = getWorkspacePackageNames(root);
|
|
453
|
-
|
|
472
|
+
const packageJsonPaths = listWorkspacePackageJsonPaths(root);
|
|
473
|
+
// Files as they are on disk now, through the same ignore rules as the Tree listing.
|
|
474
|
+
const sources = typeScriptSourcesByProject(
|
|
475
|
+
freshIndexedFiles(root, SOURCE_LISTING_GLOBS),
|
|
476
|
+
packageJsonPaths.map((path) => relative(root, dirname(path))),
|
|
477
|
+
);
|
|
478
|
+
for (const packageJsonPath of packageJsonPaths) {
|
|
454
479
|
const pkg = readJsonObject(packageJsonPath);
|
|
455
480
|
if (!pkg) {
|
|
456
481
|
continue;
|
|
@@ -483,7 +508,7 @@ export function checkTypecheckTestPolicy(root: string): NxPolicyIssue[] {
|
|
|
483
508
|
if (tsconfig) {
|
|
484
509
|
const absoluteIssues = checkTypecheckTestConfig(tsconfig, join(root, packagePath));
|
|
485
510
|
issues.push(...absoluteIssues);
|
|
486
|
-
const program = diskProgram(root, packagePath);
|
|
511
|
+
const program = diskProgram(root, packagePath, sources);
|
|
487
512
|
const fault = testProgramFault(program, tsconfig);
|
|
488
513
|
if (fault !== null) {
|
|
489
514
|
issues.push({ path: tsconfigTestPath, message: testProgramFaultMessage(packagePath, testRunners, fault) });
|
package/src/workspace-index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import native, { type FileData } from 'nx/src/native/index.js';
|
|
2
3
|
import { workspaceDataDirectoryForWorkspace } from 'nx/src/utils/cache-directory.js';
|
|
3
|
-
import {
|
|
4
|
+
import { getAllFileDataInContext, globWithWorkspaceContext } from 'nx/src/utils/workspace-context.js';
|
|
4
5
|
import { workspaceRoot as daemonWorkspaceRoot } from 'nx/src/utils/workspace-root.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -11,12 +12,15 @@ import { workspaceRoot as daemonWorkspaceRoot } from 'nx/src/utils/workspace-roo
|
|
|
11
12
|
* output happens to be on disk.
|
|
12
13
|
*
|
|
13
14
|
* The daemon serves only its own workspace's index. Any other root, such as a
|
|
14
|
-
* test fixture or a foreign checkout, is
|
|
15
|
+
* test fixture or a foreign checkout, is read from the filesystem now
|
|
16
|
+
* ({@link freshIndexedFiles}), under that root's own data directory: Nx's
|
|
17
|
+
* process context for it would resolve the inherited NX_WORKSPACE_DATA_DIRECTORY,
|
|
18
|
+
* this workspace's, and take its files lock and archive.
|
|
15
19
|
*/
|
|
16
20
|
export async function globIndexedFiles(workspaceRoot: string, globs: string[]): Promise<string[]> {
|
|
17
21
|
return workspaceRoot === daemonWorkspaceRoot
|
|
18
22
|
? globWithWorkspaceContext(workspaceRoot, globs)
|
|
19
|
-
:
|
|
23
|
+
: freshIndexedFiles(workspaceRoot, globs);
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
/**
|
|
@@ -26,5 +30,36 @@ export async function globIndexedFiles(workspaceRoot: string, globs: string[]):
|
|
|
26
30
|
* runs on the files as they are asks here; what describes a graph asks {@link globIndexedFiles}.
|
|
27
31
|
*/
|
|
28
32
|
export function freshIndexedFiles(workspaceRoot: string, globs: string[]): string[] {
|
|
29
|
-
return new native.WorkspaceContext(workspaceRoot,
|
|
33
|
+
return new native.WorkspaceContext(workspaceRoot, indexDataDirectory(workspaceRoot)).glob(globs);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Every file of Nx's workspace file index with Nx's content hash of it, workspace-relative: the hashes Nx's task
|
|
38
|
+
* hasher keys every fileset on, kept current by its watcher, so a caller can tell an unchanged file without reading
|
|
39
|
+
* it. The daemon serves its own workspace; any other root, such as a test fixture, is read from the filesystem now
|
|
40
|
+
* ({@link freshIndexedFileData}), since the daemon's answer would be about another tree.
|
|
41
|
+
*/
|
|
42
|
+
export async function indexedFileData(workspaceRoot: string): Promise<FileData[]> {
|
|
43
|
+
return workspaceRoot === daemonWorkspaceRoot
|
|
44
|
+
? getAllFileDataInContext(workspaceRoot)
|
|
45
|
+
: freshIndexedFileData(workspaceRoot);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Like {@link indexedFileData}, read from the filesystem now, as {@link freshIndexedFiles} lists it. */
|
|
49
|
+
export function freshIndexedFileData(workspaceRoot: string): FileData[] {
|
|
50
|
+
return new native.WorkspaceContext(workspaceRoot, indexDataDirectory(workspaceRoot)).allFileData();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Where a fresh native context of `workspaceRoot` keeps its files lock and archive. Nx's
|
|
55
|
+
* `workspaceDataDirectoryForWorkspace` answers `NX_WORKSPACE_DATA_DIRECTORY` for every root, and that variable names
|
|
56
|
+
* this process's workspace's data (CI points it at a shared directory outside the checkout). A walk of another root
|
|
57
|
+
* there takes this workspace's files lock, and when another process holds it, loads the archive that process writes,
|
|
58
|
+
* this workspace's files, as the other root's (CI's Lint, run 42738719423: the compiled-in fixtures found no crate).
|
|
59
|
+
* Any other root walks under Nx's default for it, inside itself.
|
|
60
|
+
*/
|
|
61
|
+
function indexDataDirectory(workspaceRoot: string): string {
|
|
62
|
+
return workspaceRoot === daemonWorkspaceRoot
|
|
63
|
+
? workspaceDataDirectoryForWorkspace(workspaceRoot)
|
|
64
|
+
: join(workspaceRoot, '.nx', 'workspace-data');
|
|
30
65
|
}
|
package/test-timings.json
CHANGED
|
@@ -8,17 +8,22 @@
|
|
|
8
8
|
"src/executors/bounded-exec/executor.test.ts": 40109,
|
|
9
9
|
"src/executors/bounded-exec/cargo-progress-host.test.ts": 38973,
|
|
10
10
|
"src/nextest-partitions.test.ts": 36611,
|
|
11
|
+
"src/executors/bounded-exec/cpu-rise.test.ts": 34421,
|
|
11
12
|
"src/cargo-resolve-cache.test.ts": 20025,
|
|
12
13
|
"src/executors/bounded-exec/run-cpu-pool.test.ts": 19052,
|
|
13
14
|
"src/linked-snapshots.nx.test.ts": 17026,
|
|
14
15
|
"src/ensure-built-receipt.test.ts": 15880,
|
|
15
16
|
"src/process-group.test.ts": 15352,
|
|
16
17
|
"src/index.test.ts": 15133,
|
|
18
|
+
"src/workspace-index.test.ts": 14351,
|
|
17
19
|
"src/cargo-source-hash.test.ts": 12215,
|
|
20
|
+
"src/cache-key-laws.test.ts": 10728,
|
|
18
21
|
"src/cargo-retention.test.ts": 10686,
|
|
22
|
+
"src/executors/bounded-exec/mbx-reservations-run.test.ts": 10620,
|
|
19
23
|
"src/cargo-closure-input.test.ts": 9328,
|
|
20
24
|
"src/managed-files/repo-path.test.ts": 8962,
|
|
21
25
|
"src/nx-daemon-claim.test.ts": 8359,
|
|
26
|
+
"src/nx-project-config-hash.test.ts": 7610,
|
|
22
27
|
"src/managed-files/forgejo-artifact.test.ts": 7370,
|
|
23
28
|
"src/managed-files/setup-devenv-task-records.test.ts": 6855,
|
|
24
29
|
"src/nx-daemon-idle-policy.test.ts": 6475,
|
|
@@ -67,6 +72,7 @@
|
|
|
67
72
|
"src/executors/all-verdicts/executor.test.ts": 957,
|
|
68
73
|
"src/nextest-code-bound.test.ts": 957,
|
|
69
74
|
"src/nx-files-archive-racy.test.ts": 869,
|
|
75
|
+
"src/nx-bun-builtin-imports.test.ts": 728,
|
|
70
76
|
"src/nx-local-plugin-hook-env.test.ts": 657,
|
|
71
77
|
"src/nx-raw-inputs.test.ts": 622,
|
|
72
78
|
"src/nx-daemon-root-normalization.test.ts": 561,
|