@smoothbricks/nx-plugin 0.4.28 → 0.4.29
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 +203 -83
- package/dist/bounded-test-policy.d.ts +10 -3
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +19 -25
- package/dist/cargo-closure-input.d.ts +12 -0
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +29 -7
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +42 -19
- package/dist/ensure-built-receipt.d.ts +34 -6
- package/dist/ensure-built-receipt.d.ts.map +1 -1
- package/dist/ensure-built-receipt.js +265 -159
- package/dist/ensure-built-witness.d.ts +27 -2
- package/dist/ensure-built-witness.d.ts.map +1 -1
- package/dist/ensure-built-witness.js +2176 -15
- package/dist/ensure-built.d.ts +99 -1
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +34 -53
- package/dist/executors/bounded-exec/cpu-pool.d.ts +16 -5
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +43 -19
- package/dist/executors/bounded-exec/executor.d.ts +11 -2
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +139 -39
- package/dist/executors/bounded-exec/ram-temp.d.ts +17 -11
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
- package/dist/executors/bounded-exec/ram-temp.js +27 -13
- package/dist/generators/bun-test-tracing/generator.js +2 -2
- package/dist/graph-input-contract.d.ts +98 -0
- package/dist/graph-input-contract.d.ts.map +1 -0
- package/dist/graph-input-contract.js +624 -0
- package/dist/index.d.ts +12 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -3
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +5 -2
- package/dist/managed-files/publish-workflow.d.ts +11 -1
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/producer-receipts.d.ts +19 -0
- package/dist/producer-receipts.d.ts.map +1 -0
- package/dist/producer-receipts.js +921 -0
- package/dist/testing.d.ts +8 -0
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +58 -0
- package/managed/raw/patches/nx@23.2.1.patch +328 -50
- package/managed/raw/tooling/direnv/developer-links.ts +147 -21
- package/managed/raw/tooling/direnv/devenv.smoo.nix +7 -7
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -5
- package/managed/raw/tooling/direnv/linked-snapshots.ts +206 -40
- package/managed/raw/tooling/direnv/repo-path +15 -2
- package/managed/raw/tooling/direnv/setup-environment.ts +179 -114
- package/managed/templates/github/actions/cache-node-modules/action.yml +9 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +63 -7
- package/nextest.toml +1 -1
- package/package.json +11 -6
- package/src/__tests__/fixture-nx-env.ts +7 -0
- package/src/__tests__/owned-installation.ts +174 -0
- package/src/bin/smoo-nx-bound-failures.test.ts +1 -1
- package/src/bounded-test-policy.test.ts +36 -22
- package/src/bounded-test-policy.ts +19 -27
- package/src/bun-bootstrap.test.ts +1 -1
- package/src/cargo-closure-input.test.ts +60 -11
- package/src/cargo-closure-input.ts +28 -6
- package/src/cargo-resolve-cache.test.ts +140 -25
- package/src/cargo-source-hash.test.ts +78 -3
- package/src/cargo-source-hash.ts +48 -30
- package/src/cross-check-policy.test.ts +2 -2
- package/src/ensure-built-receipt.test.ts +111 -16
- package/src/ensure-built-receipt.ts +251 -149
- package/src/ensure-built-witness.test.ts +197 -13
- package/src/ensure-built-witness.ts +187 -15
- package/src/ensure-built.test.ts +156 -102
- package/src/ensure-built.ts +114 -64
- package/src/executors/bounded-exec/cpu-pool.test.ts +116 -32
- package/src/executors/bounded-exec/cpu-pool.ts +55 -17
- package/src/executors/bounded-exec/cpu-tokens.test.ts +2 -2
- package/src/executors/bounded-exec/executor-host.test.ts +51 -41
- package/src/executors/bounded-exec/executor.test.ts +155 -35
- package/src/executors/bounded-exec/executor.ts +156 -45
- package/src/executors/bounded-exec/progress.test.ts +1 -1
- package/src/executors/bounded-exec/ram-temp-host.test.ts +46 -17
- package/src/executors/bounded-exec/ram-temp.test.ts +65 -3
- package/src/executors/bounded-exec/ram-temp.ts +32 -16
- package/src/executors/bounded-exec/verdict.test.ts +17 -12
- package/src/generators/bounded-test-targets/generator.test.ts +1 -3
- package/src/generators/bun-test-tracing/generator.test.ts +2 -2
- package/src/generators/bun-test-tracing/generator.ts +2 -2
- package/src/graph-input-contract.test.ts +371 -0
- package/src/graph-input-contract.ts +605 -0
- package/src/index.test.ts +3 -3
- package/src/index.ts +24 -3
- package/src/linked-snapshots.nx.test.ts +112 -30
- package/src/managed-files/ci-workflow.ts +5 -2
- package/src/managed-files/publish-workflow.ts +12 -1
- package/src/managed-files/repo-path.test.ts +44 -1
- package/src/managed-files/setup-devenv-free-disk.test.ts +95 -0
- package/src/nextest-code-bound.test.ts +23 -17
- package/src/nextest-partitions.test.ts +7 -1
- package/src/nx-cache-restore-mtime.test.ts +2 -2
- package/src/nx-daemon-claim.test.ts +5 -5
- package/src/nx-daemon-idle-cpu.test.ts +0 -1
- package/src/nx-daemon-idle-policy.test.ts +56 -0
- package/src/nx-daemon-ignore-files.test.ts +2 -2
- package/src/nx-daemon-validity.test.ts +31 -9
- package/src/nx-dot-input-policy.test.ts +5 -5
- package/src/nx-files-archive-racy.test.ts +1 -1
- package/src/nx-incomplete-run-summary.test.ts +1 -1
- package/src/nx-plugin-load-errors.test.ts +2 -2
- package/src/nx-project-graph-errors.test.ts +70 -0
- package/src/nx-skipped-task-exit.test.ts +2 -2
- package/src/nx-store-resolution.test.ts +7 -25
- package/src/nx-task-output-lease.test.ts +3 -3
- package/src/nx-use-local.test.ts +7 -5
- package/src/producer-receipts.test.ts +164 -0
- package/src/producer-receipts.ts +631 -0
- package/src/runtime-input.test.ts +1 -1
- package/src/serial-group-wiring.test.ts +4 -4
- package/src/task-results.test.ts +18 -16
- package/src/test-timings.test.ts +2 -2
- package/src/testing.test.ts +5 -5
- package/src/testing.ts +59 -0
- package/src/typecheck-test-policy.test.ts +1 -1
- package/src/typescript-resolution.test.ts +76 -0
- package/test-timings.json +5 -0
package/src/task-results.test.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { expect, it } from 'bun:test';
|
|
1
|
+
import { afterAll, expect, it } from 'bun:test';
|
|
2
2
|
import { mkdir, readdir, readFile, realpath, stat, symlink, writeFile } from 'node:fs/promises';
|
|
3
|
-
import {
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { join } from 'node:path';
|
|
5
4
|
import { fixtureNxEnv, withNxFixture } from './__tests__/fixture-nx-env.js';
|
|
5
|
+
import { testFileInstallation } from './__tests__/owned-installation.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* The plugin's `preTasksExecution`/`postTasksExecution` hooks, run by a real Nx subprocess in a
|
|
@@ -15,18 +15,20 @@ import { fixtureNxEnv, withNxFixture } from './__tests__/fixture-nx-env.js';
|
|
|
15
15
|
const RECEIPT_ENV = 'COWSHED_NX_TASK_RECEIPT_ID';
|
|
16
16
|
const RECEIPT = '0123456789abcdef0123456789abcdef';
|
|
17
17
|
const CHANGED_RECEIPT = 'fedcba9876543210fedcba9876543210';
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const nxEntry = join(repoRoot, 'node_modules', '.bin', 'nx');
|
|
18
|
+
/** The Nx CLI of a fixture workspace's own installation. */
|
|
19
|
+
const nxEntry = (workspace: string) => join(workspace, 'node_modules', '.bin', 'nx');
|
|
21
20
|
const HINTS = join('.nx', 'cache', '.cowshed-task-results');
|
|
22
21
|
|
|
22
|
+
/** The Nx and the plugin under test, one copy this file's fixtures share; none may write into it. */
|
|
23
|
+
const installation = testFileInstallation('task-results-installation-');
|
|
24
|
+
afterAll(() => installation.retire());
|
|
25
|
+
|
|
23
26
|
/** A fixture workspace: `app:build` caches its copy of `source.txt`; `app:fail` always exits 3. */
|
|
24
27
|
async function writeWorkspace(workspace: string): Promise<void> {
|
|
25
28
|
await mkdir(join(workspace, 'app'), { recursive: true });
|
|
26
29
|
const git = Bun.spawnSync(['git', 'init', '--quiet', workspace]);
|
|
27
30
|
expect(git.exitCode, git.stderr.toString()).toBe(0);
|
|
28
|
-
|
|
29
|
-
await symlink(join(repoRoot, 'node_modules'), join(workspace, 'node_modules'), 'dir');
|
|
31
|
+
await symlink(await installation.nodeModules(), join(workspace, 'node_modules'), 'dir');
|
|
30
32
|
await writeFile(
|
|
31
33
|
join(workspace, 'nx.json'),
|
|
32
34
|
JSON.stringify({ cacheDirectory: '.nx/cache', plugins: ['@smoothbricks/nx-plugin'] }),
|
|
@@ -53,7 +55,7 @@ async function writeWorkspace(workspace: string): Promise<void> {
|
|
|
53
55
|
|
|
54
56
|
/** Runs one target with `nx run` under `env`, returning its exit code, output and argv. */
|
|
55
57
|
async function nx(workspace: string, env: Record<string, string>, target: string) {
|
|
56
|
-
const argv = [process.execPath, nxEntry, 'run', target, '--outputStyle=static'];
|
|
58
|
+
const argv = [process.execPath, nxEntry(workspace), 'run', target, '--outputStyle=static'];
|
|
57
59
|
const child = Bun.spawn(argv, { cwd: workspace, env, stdout: 'pipe', stderr: 'pipe' });
|
|
58
60
|
const [exitCode, stdout, stderr] = await Promise.all([
|
|
59
61
|
child.exited,
|
|
@@ -112,7 +114,7 @@ it('records a task hint only under a controller receipt, and never on an ordinar
|
|
|
112
114
|
version: 1,
|
|
113
115
|
requestId: RECEIPT,
|
|
114
116
|
workspaceRoot: workspace,
|
|
115
|
-
run: { argv: [process.execPath, await realpath(nxEntry), ...hit.argv.slice(2)] },
|
|
117
|
+
run: { argv: [process.execPath, await realpath(nxEntry(workspace)), ...hit.argv.slice(2)] },
|
|
116
118
|
tasks: [{ task: { id: 'app:build', hash: expect.stringMatching(/^\d+$/) }, status: 'local-cache', code: 0 }],
|
|
117
119
|
});
|
|
118
120
|
|
|
@@ -129,13 +131,13 @@ it('records a task hint only under a controller receipt, and never on an ordinar
|
|
|
129
131
|
expect(await readHint(join(hints, CHANGED_RECEIPT))).toMatchObject({
|
|
130
132
|
version: 1,
|
|
131
133
|
requestId: CHANGED_RECEIPT,
|
|
132
|
-
run: { argv: [process.execPath, await realpath(nxEntry), ...changed.argv.slice(2)] },
|
|
134
|
+
run: { argv: [process.execPath, await realpath(nxEntry(workspace)), ...changed.argv.slice(2)] },
|
|
133
135
|
tasks: [{ task: { id: 'app:build', hash: expect.stringMatching(/^\d+$/) }, status: 'success', code: 0 }],
|
|
134
136
|
});
|
|
135
137
|
},
|
|
136
138
|
'.',
|
|
137
139
|
);
|
|
138
|
-
}
|
|
140
|
+
});
|
|
139
141
|
|
|
140
142
|
it('records a failed task as a failure under a receipt, never as a success', async () => {
|
|
141
143
|
await withNxFixture(
|
|
@@ -153,7 +155,7 @@ it('records a failed task as a failure under a receipt, never as a success', asy
|
|
|
153
155
|
},
|
|
154
156
|
'.',
|
|
155
157
|
);
|
|
156
|
-
}
|
|
158
|
+
});
|
|
157
159
|
|
|
158
160
|
it('records hints through a daemon-backed Nx only under a checked receipt', async () => {
|
|
159
161
|
await withNxFixture(
|
|
@@ -179,7 +181,7 @@ it('records hints through a daemon-backed Nx only under a checked receipt', asyn
|
|
|
179
181
|
version: 1,
|
|
180
182
|
requestId: RECEIPT,
|
|
181
183
|
workspaceRoot: workspace,
|
|
182
|
-
run: { argv: [checkedA.argv[0] ?? '', await realpath(nxEntry), ...checkedA.argv.slice(2)] },
|
|
184
|
+
run: { argv: [checkedA.argv[0] ?? '', await realpath(nxEntry(workspace)), ...checkedA.argv.slice(2)] },
|
|
183
185
|
tasks: [
|
|
184
186
|
{
|
|
185
187
|
task: { id: 'app:build', hash: expect.stringMatching(/^\d+$/) },
|
|
@@ -211,7 +213,7 @@ it('records hints through a daemon-backed Nx only under a checked receipt', asyn
|
|
|
211
213
|
version: 1,
|
|
212
214
|
requestId: CHANGED_RECEIPT,
|
|
213
215
|
workspaceRoot: workspace,
|
|
214
|
-
run: { argv: [checkedB.argv[0] ?? '', await realpath(nxEntry), ...checkedB.argv.slice(2)] },
|
|
216
|
+
run: { argv: [checkedB.argv[0] ?? '', await realpath(nxEntry(workspace)), ...checkedB.argv.slice(2)] },
|
|
215
217
|
tasks: [
|
|
216
218
|
{
|
|
217
219
|
task: { id: 'app:build', hash: expect.stringMatching(/^\d+$/) },
|
|
@@ -223,4 +225,4 @@ it('records hints through a daemon-backed Nx only under a checked receipt', asyn
|
|
|
223
225
|
},
|
|
224
226
|
'.',
|
|
225
227
|
);
|
|
226
|
-
}
|
|
228
|
+
});
|
package/src/test-timings.test.ts
CHANGED
|
@@ -15,8 +15,8 @@ import {
|
|
|
15
15
|
} from './test-timings.js';
|
|
16
16
|
|
|
17
17
|
const SHARD = (n: number) =>
|
|
18
|
-
`bun test --timeout=
|
|
19
|
-
const SUITE_ARGS = ['--timeout=
|
|
18
|
+
`bun test --timeout=0 --timings=test-timings.json --shard=${n}/2 --path-ignore-patterns='**/*-host.test.ts'`;
|
|
19
|
+
const SUITE_ARGS = ['--timeout=0', '--timings=test-timings.json', '--path-ignore-patterns=**/*-host.test.ts'];
|
|
20
20
|
|
|
21
21
|
function shardTargets(command: (n: number) => string = SHARD): Record<string, unknown> {
|
|
22
22
|
return {
|
package/src/testing.test.ts
CHANGED
|
@@ -123,7 +123,7 @@ it('stops the Nx daemon of a fixture whose body throws, and deletes its socket a
|
|
|
123
123
|
expect(await pidsWorkingIn(root)).toEqual([]);
|
|
124
124
|
expect(existsSync(root)).toBe(false);
|
|
125
125
|
expect(lstatSync(alias, { throwIfNoEntry: false })).toBeUndefined();
|
|
126
|
-
}
|
|
126
|
+
});
|
|
127
127
|
|
|
128
128
|
it('ends owned Nx processes before daemon publication and after daemon exit', async () => {
|
|
129
129
|
let root = '';
|
|
@@ -196,7 +196,7 @@ it('ends owned Nx processes before daemon publication and after daemon exit', as
|
|
|
196
196
|
}
|
|
197
197
|
});
|
|
198
198
|
expect(await pidsWorkingIn(root)).toEqual([]);
|
|
199
|
-
}
|
|
199
|
+
});
|
|
200
200
|
|
|
201
201
|
it('binds and connects through its short alias without granting the long fixture root a socket namespace', async () => {
|
|
202
202
|
let alias = '';
|
|
@@ -363,7 +363,7 @@ it('starts and connects to a fixture daemon through owned short aliases with a l
|
|
|
363
363
|
expect(daemon.some(({ pid }) => pid === record.processId)).toBe(true);
|
|
364
364
|
expect(await stillRunning(daemon)).not.toEqual([]);
|
|
365
365
|
});
|
|
366
|
-
}
|
|
366
|
+
});
|
|
367
367
|
|
|
368
368
|
/**
|
|
369
369
|
* The alias a killed fixture leaves: what {@link publishFixtureSocketDirectory} makes, planted for a workspace in
|
|
@@ -441,7 +441,7 @@ it("reclaims a dead run's Nx daemon, helper processes and socket aliases, and no
|
|
|
441
441
|
}
|
|
442
442
|
await rm(suiteDirectory, { recursive: true, force: true });
|
|
443
443
|
}
|
|
444
|
-
}
|
|
444
|
+
});
|
|
445
445
|
|
|
446
446
|
it('stops what works in every run it owns when the process is signalled, then dies of the signal', async () => {
|
|
447
447
|
const suite = `signal-regression-${process.pid}`;
|
|
@@ -506,4 +506,4 @@ setInterval(() => {}, 1 << 30);
|
|
|
506
506
|
await rm(suiteDirectory, { recursive: true, force: true });
|
|
507
507
|
await rm(otherParent, { recursive: true, force: true });
|
|
508
508
|
}
|
|
509
|
-
}
|
|
509
|
+
});
|
package/src/testing.ts
CHANGED
|
@@ -202,6 +202,65 @@ export async function pidsWorkingIn(root: string): Promise<number[]> {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Every process of this user started with `TMPDIR` set to `root` or beneath it. Such a process
|
|
207
|
+
* writes there whatever its working directory: a ttsc plugin build copies its Go sources into
|
|
208
|
+
* `$TMPDIR` from a process working in its project, and Node and Bun write their compile cache
|
|
209
|
+
* there on the way out. The environment is the one the process was started with, which is the
|
|
210
|
+
* one its children inherit unless it changed it for them.
|
|
211
|
+
*/
|
|
212
|
+
export async function pidsWithTempIn(root: string): Promise<number[]> {
|
|
213
|
+
// The value as it follows `TMPDIR=`: `root` itself, with or without its trailing slash, or below it.
|
|
214
|
+
const names = (value: string) => value.startsWith(root) && ['', '/', ' '].includes(value.charAt(root.length));
|
|
215
|
+
switch (process.platform) {
|
|
216
|
+
case 'linux': {
|
|
217
|
+
const found: number[] = [];
|
|
218
|
+
for (const pid of (await readdir('/proc')).filter((name) => /^\d+$/.test(name))) {
|
|
219
|
+
const environ = await readFile(`/proc/${pid}/environ`, 'utf8').catch((error: unknown) => {
|
|
220
|
+
// Another user's process, or one that exited since the listing.
|
|
221
|
+
if (errorCode(error) === 'EACCES' || errorCode(error) === 'ENOENT' || errorCode(error) === 'ESRCH') {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
throw error;
|
|
225
|
+
});
|
|
226
|
+
const entry = environ?.split('\0').find((variable) => variable.startsWith('TMPDIR='));
|
|
227
|
+
if (entry !== undefined && names(entry.slice('TMPDIR='.length))) {
|
|
228
|
+
found.push(Number(pid));
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return found;
|
|
232
|
+
}
|
|
233
|
+
case 'darwin': {
|
|
234
|
+
// `ps -E` follows each command line with the environment it was started with, as words
|
|
235
|
+
// separated by spaces, and only for this user's processes. A word `TMPDIR=<root>` is matched
|
|
236
|
+
// with what follows it in that word, so a root containing a space is still found whole. An
|
|
237
|
+
// argument spelled `TMPDIR=<root>` names the same directory and counts too: an `env` that
|
|
238
|
+
// sets it is about to run something there. `/bin/ps` by path: a procps `ps` has no `-E`.
|
|
239
|
+
const { stdout } = await run('/bin/ps', ['-E', '-ww', '-U', String(userInfo().uid), '-o', 'pid=,command='], {
|
|
240
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
241
|
+
});
|
|
242
|
+
const token = ` TMPDIR=${root}`;
|
|
243
|
+
const found: number[] = [];
|
|
244
|
+
for (const line of stdout.split('\n')) {
|
|
245
|
+
const row = /^\s*(\d+) (.*)$/.exec(line);
|
|
246
|
+
if (row === null) {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
const words = ` ${row[2]}`;
|
|
250
|
+
for (let at = words.indexOf(token); at !== -1; at = words.indexOf(token, at + 1)) {
|
|
251
|
+
if (names(words.slice(at + ' TMPDIR='.length))) {
|
|
252
|
+
found.push(Number(row[1]));
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return found;
|
|
258
|
+
}
|
|
259
|
+
default:
|
|
260
|
+
throw new Error(`No TMPDIR scan for ${process.platform}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
205
264
|
/**
|
|
206
265
|
* The Nx daemon `workspace` runs, the daemon first, then every process it
|
|
207
266
|
* started. Empty when the workspace records no daemon or the recorded one is
|
|
@@ -1139,7 +1139,7 @@ async function toolingShapedWorkspace(root: string): Promise<void> {
|
|
|
1139
1139
|
targets: {
|
|
1140
1140
|
test: {
|
|
1141
1141
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
1142
|
-
options: { command: 'bun test --timeout=
|
|
1142
|
+
options: { command: 'bun test --timeout=0 direnv', cwd: '{projectRoot}' },
|
|
1143
1143
|
},
|
|
1144
1144
|
},
|
|
1145
1145
|
},
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { expect, it } from 'bun:test';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { mkdir, realpath, symlink, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { fixtureNxEnv, withNxFixture } from './__tests__/fixture-nx-env.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The project graph must not depend on which `typescript` Bun's isolated linker hoists. A package that requires
|
|
10
|
+
* `typescript` without declaring it (as @nx/js does) gets the copy in node_modules/.bun/node_modules, and beside the
|
|
11
|
+
* `@typescript/native` alias that can be TypeScript 7, whose package exports no compiler API. A publish runner hoisted
|
|
12
|
+
* it once: every project failed with "Cannot read properties of undefined (reading 'readFile')".
|
|
13
|
+
*
|
|
14
|
+
* The preload hoists TypeScript 7 for every undeclared `typescript` request, as that runner did, and leaves declared
|
|
15
|
+
* ones and path-anchored resolutions (Nx's resolveFromWorkspace) alone.
|
|
16
|
+
*/
|
|
17
|
+
const repositoryRoot = join(import.meta.dir, '../../..');
|
|
18
|
+
const nxEntry = join(repositoryRoot, 'node_modules/.bin/nx');
|
|
19
|
+
const require = createRequire(join(repositoryRoot, 'package.json'));
|
|
20
|
+
|
|
21
|
+
const HOIST_TYPESCRIPT_7 = `
|
|
22
|
+
const Module = require('node:module');
|
|
23
|
+
const { existsSync, readFileSync } = require('node:fs');
|
|
24
|
+
const { dirname, join } = require('node:path');
|
|
25
|
+
const native = ${JSON.stringify(require.resolve('@typescript/native'))};
|
|
26
|
+
function declaresTypescript(file) {
|
|
27
|
+
for (let directory = dirname(file); directory !== dirname(directory); directory = dirname(directory)) {
|
|
28
|
+
const manifest = join(directory, 'package.json');
|
|
29
|
+
if (!existsSync(manifest)) continue;
|
|
30
|
+
const json = JSON.parse(readFileSync(manifest, 'utf8'));
|
|
31
|
+
return ['dependencies', 'peerDependencies', 'optionalDependencies'].some((field) => json[field]?.typescript);
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
const resolve = Module._resolveFilename;
|
|
36
|
+
Module._resolveFilename = function (request, parent, isMain, options) {
|
|
37
|
+
if (request === 'typescript' && options?.paths === undefined && parent?.filename && !declaresTypescript(parent.filename)) {
|
|
38
|
+
return native;
|
|
39
|
+
}
|
|
40
|
+
return resolve.call(this, request, parent, isMain, options);
|
|
41
|
+
};
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
for (const isolate of ['false', 'true']) {
|
|
45
|
+
it(`reads a test tsconfig whichever typescript is hoisted (isolated plugins: ${isolate})`, async () => {
|
|
46
|
+
await withNxFixture('nx-typescript-hoist-', async ({ workspace, socketDirectory }) => {
|
|
47
|
+
await symlink(await realpath(join(repositoryRoot, 'node_modules')), join(workspace, 'node_modules'), 'dir');
|
|
48
|
+
await writeFile(join(workspace, 'package.json'), JSON.stringify({ name: 'hoist', private: true }));
|
|
49
|
+
await writeFile(join(workspace, 'nx.json'), JSON.stringify({ plugins: ['@smoothbricks/nx-plugin'] }));
|
|
50
|
+
// An ESLint config makes the plugin read the test program to key lint on its sources.
|
|
51
|
+
await writeFile(join(workspace, 'eslint.config.mjs'), 'export default [];\n');
|
|
52
|
+
await mkdir(join(workspace, 'packages/example/src'), { recursive: true });
|
|
53
|
+
await writeFile(
|
|
54
|
+
join(workspace, 'packages/example/package.json'),
|
|
55
|
+
JSON.stringify({ name: 'example', private: true, scripts: { test: 'bun test' } }),
|
|
56
|
+
);
|
|
57
|
+
await writeFile(join(workspace, 'packages/example/tsconfig.test.json'), '{"include":["src/**/*.test.ts"]}\n');
|
|
58
|
+
await writeFile(join(workspace, 'packages/example/src/a.test.ts'), 'export {};\n');
|
|
59
|
+
const preload = join(workspace, 'hoist-typescript-7.cjs');
|
|
60
|
+
await writeFile(preload, HOIST_TYPESCRIPT_7);
|
|
61
|
+
|
|
62
|
+
const ran = spawnSync('node', [nxEntry, 'show', 'project', 'example', '--json'], {
|
|
63
|
+
cwd: workspace,
|
|
64
|
+
env: {
|
|
65
|
+
...fixtureNxEnv(workspace, socketDirectory),
|
|
66
|
+
NX_ISOLATE_PLUGINS: isolate,
|
|
67
|
+
NODE_OPTIONS: `--require ${preload}`,
|
|
68
|
+
},
|
|
69
|
+
encoding: 'utf8',
|
|
70
|
+
});
|
|
71
|
+
expect(ran.status, `${ran.stdout}${ran.stderr}`).toBe(0);
|
|
72
|
+
// Lint keys the test program's sources, which only reading tsconfig.test.json yields.
|
|
73
|
+
expect(ran.stdout).toContain('{workspaceRoot}/packages/example/src/a.test.ts');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
package/test-timings.json
CHANGED
|
@@ -3,10 +3,14 @@
|
|
|
3
3
|
"files": {
|
|
4
4
|
"src/index.test.ts": 57872,
|
|
5
5
|
"src/nx-daemon-validity.test.ts": 46596,
|
|
6
|
+
"src/nx-project-graph-errors.test.ts": 32787,
|
|
6
7
|
"src/ensure-built.test.ts": 18391,
|
|
8
|
+
"src/graph-input-contract.test.ts": 16550,
|
|
7
9
|
"src/executors/bounded-exec/executor.test.ts": 12975,
|
|
8
10
|
"src/cargo-resolve-cache.test.ts": 11421,
|
|
9
11
|
"src/executors/bounded-exec/ram-temp.test.ts": 10766,
|
|
12
|
+
"src/producer-receipts.test.ts": 10581,
|
|
13
|
+
"src/typescript-resolution.test.ts": 10482,
|
|
10
14
|
"src/executors/napi-cross-toolchain/executor.test.ts": 10474,
|
|
11
15
|
"src/nx-daemon-claim.test.ts": 9477,
|
|
12
16
|
"src/cargo-source-hash.test.ts": 9179,
|
|
@@ -52,6 +56,7 @@
|
|
|
52
56
|
"src/bun-bootstrap.test.ts": 378,
|
|
53
57
|
"src/ensure-built-witness.test.ts": 280,
|
|
54
58
|
"src/test-walk-policy.test.ts": 280,
|
|
59
|
+
"src/managed-files/setup-devenv-free-disk.test.ts": 277,
|
|
55
60
|
"src/package-target-policy.test.ts": 208,
|
|
56
61
|
"src/nextest-extraction.test.ts": 151,
|
|
57
62
|
"src/executors/bounded-exec/cpu-tokens.test.ts": 136,
|