@smoothbricks/nx-plugin 0.7.16 → 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.
Files changed (119) hide show
  1. package/README.md +210 -64
  2. package/dist/.build-inputs.json +28 -23
  3. package/dist/bun-lock-scope.d.ts +128 -20
  4. package/dist/bun-lock-scope.d.ts.map +1 -1
  5. package/dist/bun-lock-scope.js +267 -44
  6. package/dist/cargo-closure-input.d.ts +8 -6
  7. package/dist/cargo-closure-input.d.ts.map +1 -1
  8. package/dist/cargo-closure-input.js +14 -11
  9. package/dist/cargo-source-hash.d.ts +23 -4
  10. package/dist/cargo-source-hash.d.ts.map +1 -1
  11. package/dist/cargo-source-hash.js +80 -14
  12. package/dist/cargo-workspace.d.ts +20 -2
  13. package/dist/cargo-workspace.d.ts.map +1 -1
  14. package/dist/cargo-workspace.js +42 -22
  15. package/dist/compile-environment.d.ts +8 -0
  16. package/dist/compile-environment.d.ts.map +1 -0
  17. package/dist/compile-environment.js +80 -0
  18. package/dist/dependency-manifests.d.ts +13 -0
  19. package/dist/dependency-manifests.d.ts.map +1 -0
  20. package/dist/dependency-manifests.js +20 -0
  21. package/dist/ensure-built-receipt.d.ts +3 -2
  22. package/dist/ensure-built-receipt.d.ts.map +1 -1
  23. package/dist/ensure-built-receipt.js +3 -2
  24. package/dist/eslint-config-closure.d.ts +8 -3
  25. package/dist/eslint-config-closure.d.ts.map +1 -1
  26. package/dist/eslint-config-closure.js +24 -5
  27. package/dist/executors/bounded-exec/bounds.d.ts +12 -1
  28. package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
  29. package/dist/executors/bounded-exec/bounds.js +8 -4
  30. package/dist/executors/bounded-exec/cpu-rise.d.ts +73 -0
  31. package/dist/executors/bounded-exec/cpu-rise.d.ts.map +1 -0
  32. package/dist/executors/bounded-exec/cpu-rise.js +111 -0
  33. package/dist/executors/bounded-exec/executor.d.ts +1 -1
  34. package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
  35. package/dist/executors/bounded-exec/executor.js +54 -22
  36. package/dist/executors/bounded-exec/hang-diagnostics.d.ts +8 -0
  37. package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
  38. package/dist/executors/bounded-exec/hang-diagnostics.js +66 -6
  39. package/dist/executors/bounded-exec/mbx-pool.d.ts +16 -2
  40. package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
  41. package/dist/executors/bounded-exec/mbx-pool.js +18 -2
  42. package/dist/executors/bounded-exec/mbx-reservations.d.ts +5 -2
  43. package/dist/executors/bounded-exec/mbx-reservations.d.ts.map +1 -1
  44. package/dist/executors/bounded-exec/mbx-reservations.js +5 -3
  45. package/dist/executors/bounded-exec/progress-channel.d.ts +38 -0
  46. package/dist/executors/bounded-exec/progress-channel.d.ts.map +1 -0
  47. package/dist/executors/bounded-exec/progress-channel.js +113 -0
  48. package/dist/executors/bounded-exec/progress.d.ts +2 -1
  49. package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
  50. package/dist/executors/bounded-exec/ram-temp.d.ts +24 -1
  51. package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
  52. package/dist/executors/bounded-exec/ram-temp.js +123 -16
  53. package/dist/executors/bounded-exec/schema.d.ts +5 -0
  54. package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
  55. package/dist/executors/bounded-exec/schema.js +17 -1
  56. package/dist/executors/bounded-exec/verdict.d.ts +13 -6
  57. package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
  58. package/dist/executors/bounded-exec/verdict.js +34 -9
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +216 -97
  61. package/dist/managed-files/files.d.ts +3 -3
  62. package/dist/managed-files/files.js +3 -3
  63. package/dist/managed-files/generator.d.ts +5 -1
  64. package/dist/managed-files/generator.d.ts.map +1 -1
  65. package/dist/managed-files/generator.js +22 -7
  66. package/dist/managed-files/render-memo.d.ts +13 -0
  67. package/dist/managed-files/render-memo.d.ts.map +1 -0
  68. package/dist/managed-files/render-memo.js +94 -0
  69. package/dist/test-program.d.ts +11 -6
  70. package/dist/test-program.d.ts.map +1 -1
  71. package/dist/test-program.js +39 -35
  72. package/dist/tool-bins.d.ts +12 -0
  73. package/dist/tool-bins.d.ts.map +1 -1
  74. package/dist/tool-bins.js +31 -6
  75. package/dist/typecheck-route.d.ts +3 -4
  76. package/dist/typecheck-route.d.ts.map +1 -1
  77. package/dist/typecheck-route.js +4 -15
  78. package/dist/typecheck-test-policy.d.ts +10 -1
  79. package/dist/typecheck-test-policy.d.ts.map +1 -1
  80. package/dist/typecheck-test-policy.js +40 -24
  81. package/dist/workspace-index.d.ts +14 -1
  82. package/dist/workspace-index.d.ts.map +1 -1
  83. package/dist/workspace-index.js +36 -4
  84. package/managed/raw/patches/nx@24.0.3.patch +703 -119
  85. package/managed/raw/patches/{ttsc@0.34.1.patch → ttsc@0.36.3.patch} +728 -71
  86. package/managed/raw/tooling/direnv/developer-links.ts +17 -3
  87. package/managed/raw/tooling/direnv/devenv.smoo.nix +1 -1
  88. package/managed/templates/github/actions/save-nix-devenv/action.yml +19 -1
  89. package/managed/templates/github/actions/setup-devenv/action.yml +2 -0
  90. package/package.json +5 -4
  91. package/src/bun-lock-scope.ts +293 -40
  92. package/src/cargo-closure-input.ts +19 -11
  93. package/src/cargo-source-hash.ts +103 -13
  94. package/src/cargo-workspace.ts +59 -20
  95. package/src/compile-environment.ts +35 -0
  96. package/src/dependency-manifests.ts +30 -0
  97. package/src/ensure-built-receipt.ts +3 -2
  98. package/src/eslint-config-closure.ts +27 -6
  99. package/src/executors/bounded-exec/bounds.ts +13 -4
  100. package/src/executors/bounded-exec/cpu-rise.ts +156 -0
  101. package/src/executors/bounded-exec/executor.ts +65 -21
  102. package/src/executors/bounded-exec/hang-diagnostics.ts +88 -6
  103. package/src/executors/bounded-exec/mbx-pool.ts +24 -3
  104. package/src/executors/bounded-exec/mbx-reservations.ts +7 -5
  105. package/src/executors/bounded-exec/progress-channel.ts +129 -0
  106. package/src/executors/bounded-exec/progress.ts +2 -1
  107. package/src/executors/bounded-exec/ram-temp.ts +137 -17
  108. package/src/executors/bounded-exec/schema.ts +19 -0
  109. package/src/executors/bounded-exec/verdict.ts +44 -16
  110. package/src/index.ts +272 -106
  111. package/src/managed-files/files.ts +3 -3
  112. package/src/managed-files/generator.ts +21 -6
  113. package/src/managed-files/render-memo.ts +135 -0
  114. package/src/test-program.ts +36 -41
  115. package/src/tool-bins.ts +35 -6
  116. package/src/typecheck-route.ts +5 -14
  117. package/src/typecheck-test-policy.ts +49 -24
  118. package/src/workspace-index.ts +40 -5
  119. package/test-timings.json +6 -0
@@ -72,9 +72,9 @@ export interface ManagedFileContext {
72
72
 
73
73
  /** Temporary upstream compiler repairs distributed to smoo-managed Bun workspaces. */
74
74
  export const managedTtscPatch = {
75
- version: '0.34.1',
76
- key: 'ttsc@0.34.1',
77
- path: 'patches/ttsc@0.34.1.patch',
75
+ version: '0.36.3',
76
+ key: 'ttsc@0.36.3',
77
+ path: 'patches/ttsc@0.36.3.patch',
78
78
  } as const;
79
79
 
80
80
  /** Maintained Nx 24.0.3 repairs, applied as an ordinary Bun patchedDependency over the registry release. */
@@ -1,10 +1,12 @@
1
+ import { createHash } from 'node:crypto';
1
2
  import { createProjectGraphAsync, getProjects, joinPathFragments, readJson, type Tree } from 'nx/src/devkit-exports.js';
2
- import { renderTypecheckTestFiles } from '../typecheck-test-policy.js';
3
+ import { renderTypecheckTestFiles, treeSourceListing } from '../typecheck-test-policy.js';
3
4
  import type { PackageJson } from '../workspace-manifest.js';
4
5
  import { deriveManagedFileContext, type WorkspaceProjects } from './context.js';
5
6
  import { type ManagedFileContext, renderManagedFiles } from './files.js';
6
7
  import { formatManagedContent } from './managed-format.js';
7
8
  import { inspectManagedPaths } from './paths.js';
9
+ import { renderedOnChange } from './render-memo.js';
8
10
  import { assertNoManagedConflicts, type FileResult, type ManagedPathInfo, stageManagedFiles } from './tree.js';
9
11
 
10
12
  /**
@@ -33,16 +35,29 @@ export async function generateManagedFiles(
33
35
  );
34
36
  }
35
37
 
36
- /** Shared rendering boundary; stage only after every consumer formatter has succeeded. */
38
+ /**
39
+ * Shared rendering boundary; stage only after every consumer formatter has succeeded. The render is a function of the
40
+ * context, the workspace's source listing and what it reads through the Tree, so it runs again only when one of those
41
+ * changed (`renderedOnChange`); staging always compares against the Tree as it is.
42
+ */
37
43
  export async function generateManagedFilesForContext(
38
44
  tree: Tree,
39
45
  context: ManagedFileContext,
40
46
  pathInfo?: ReadonlyMap<string, ManagedPathInfo>,
41
47
  ): Promise<FileResult[]> {
42
- const files = [...renderManagedFiles(context), ...renderTypecheckTestFiles(tree)];
43
- for (const file of files) {
44
- if (file.content !== null) file.content = await formatManagedContent(tree.root, file.target, file.content);
45
- }
48
+ const listing = treeSourceListing(tree);
49
+ const key = createHash('sha256')
50
+ .update(JSON.stringify(context))
51
+ .update('\0')
52
+ .update(listing.join('\0'))
53
+ .digest('hex');
54
+ const files = await renderedOnChange(tree, key, async (reading) => {
55
+ const rendered = [...renderManagedFiles(context), ...renderTypecheckTestFiles(reading, listing)];
56
+ for (const file of rendered) {
57
+ if (file.content !== null) file.content = await formatManagedContent(reading.root, file.target, file.content);
58
+ }
59
+ return rendered;
60
+ });
46
61
  const paths =
47
62
  pathInfo ??
48
63
  inspectManagedPaths(
@@ -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
+ }
@@ -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 of a project, project-relative and sorted.
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 listTypeScriptSources(tree: ProjectTree, projectRoot: string): string[] {
61
- const files: string[] = [];
62
- const walk = (directory: string): void => {
63
- for (const name of childrenOf(tree, directory)) {
64
- const path = posix.join(directory, name);
65
- if (tree.isFile(path)) {
66
- if (TYPESCRIPT_SOURCE.test(name)) files.push(posix.relative(projectRoot, path));
67
- } else if (!isNonSourceDirectory(name) && !isNestedProject(tree, path)) {
68
- walk(path);
69
- }
70
- }
71
- };
72
- walk(projectRoot);
73
- return files.sort();
74
- }
75
-
76
- /** A directory with its own manifest or Nx project file is a project, and its files are that project's. */
77
- function isNestedProject(tree: ProjectTree, directory: string): boolean {
78
- return childrenOf(tree, directory).some(
79
- (name) => PROJECT_FILE.test(name) && tree.isFile(posix.join(directory, name)),
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
- /** A dangling link (a collected build out-link) is neither a file nor a directory; anything else is a real fault. */
84
- function childrenOf(tree: ProjectTree, directory: string): string[] {
85
- try {
86
- return tree.children(directory);
87
- } catch (error) {
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
- for (const tool of NATIVE_TOOL_PACKAGES) {
65
- const manifest = relative(root, join(dirname(plugin), tool, 'package.json')).replaceAll('\\', '/');
66
- if (!projectManifests.includes(manifest)) continue;
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}: a tool package names its Nx project in name or nx.name`);
70
- projects.set(tool, name);
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,7 +1,5 @@
1
- import { existsSync, readFileSync } from 'node:fs';
2
- import { createRequire } from 'node:module';
3
- import { join } from 'node:path';
4
1
  import typia from 'typia';
2
+ import type { DependencyManifest } from './dependency-manifests.js';
5
3
 
6
4
  /**
7
5
  * What a package whose ttsc plugin lowers a dialect declares in its manifest, as `smoo.typecheck`: every project that
@@ -33,21 +31,14 @@ export interface TypecheckRoute {
33
31
  }
34
32
 
35
33
  /**
36
- * The typecheck route of the project whose manifest is `packageJsonPath`, over its direct dependencies (the ones ttsc
37
- * discovers plugins on: `dependencies` and `devDependencies`). Each dependency's manifest is the one Node resolution
38
- * reaches from the project, as ttsc reads it; a dependency that is not installed declares nothing. A manifest that
34
+ * The typecheck route of a project over its direct dependencies' manifests (dependency-manifests.ts). A manifest that
39
35
  * declares `smoo.typecheck` in another shape refuses the inference by its path and the field it got wrong.
40
36
  */
41
- export function typecheckRoute(packageJsonPath: string, dependencies: readonly string[]): TypecheckRoute {
37
+ export function typecheckRoute(manifests: readonly DependencyManifest[]): TypecheckRoute {
42
38
  const declaredBy: string[] = [];
43
39
  const dependsOn: string[] = [];
44
- const lookup = createRequire(packageJsonPath);
45
- for (const name of new Set(dependencies)) {
46
- const manifest = (lookup.resolve.paths(name) ?? [])
47
- .map((root) => join(root, ...name.split('/'), 'package.json'))
48
- .find((candidate) => existsSync(candidate));
49
- if (manifest === undefined) continue;
50
- const checked = validateManifest(JSON.parse(readFileSync(manifest, 'utf-8')));
40
+ for (const { name, path: manifest, json } of manifests) {
41
+ const checked = validateManifest(json);
51
42
  if (!checked.success) {
52
43
  throw new Error(
53
44
  `${manifest}: smoo.typecheck must be { compiler: 'ttsc', dependsOn: ['<project>:<target>', ...] }: ${checked.errors
@@ -1,21 +1,23 @@
1
- import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
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
- listTypeScriptSources,
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 getProjects(tree)) {
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 getProjects(tree)) {
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
- function treeProgram(tree: Tree, projectRoot: string): TestProgram {
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: listTypeScriptSources(tree, projectRoot),
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: listTypeScriptSources(disk, projectRoot),
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
- for (const packageJsonPath of listWorkspacePackageJsonPaths(root)) {
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) });
@@ -1,6 +1,7 @@
1
- import native from 'nx/src/native/index.js';
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 { globWithWorkspaceContext, globWithWorkspaceContextSync } from 'nx/src/utils/workspace-context.js';
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 indexed by this process's context.
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
- : globWithWorkspaceContextSync(workspaceRoot, globs);
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, workspaceDataDirectoryForWorkspace(workspaceRoot)).glob(globs);
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,