@smoothbricks/nx-plugin 0.4.27 → 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 +363 -125
- 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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
|
+
import { chmodSync, lstatSync, writeFileSync } from 'node:fs';
|
|
3
4
|
import {
|
|
4
5
|
chmod,
|
|
5
6
|
mkdir,
|
|
@@ -16,14 +17,16 @@ import {
|
|
|
16
17
|
import { tmpdir } from 'node:os';
|
|
17
18
|
import { join } from 'node:path';
|
|
18
19
|
import type { ProjectGraph } from 'nx/src/config/project-graph';
|
|
19
|
-
import { WorkspaceContext } from 'nx/src/native';
|
|
20
|
+
import { expandOutputs, WorkspaceContext } from 'nx/src/native';
|
|
20
21
|
import { workspaceDataDirectoryForWorkspace } from 'nx/src/utils/cache-directory';
|
|
21
22
|
import type { readModulePackageJsonWithoutFallbacks } from 'nx/src/utils/package-json';
|
|
22
23
|
import typia from 'typia';
|
|
23
24
|
import {
|
|
24
25
|
type GraphWitness,
|
|
25
26
|
graphInstallationIdentity,
|
|
27
|
+
movedNodes,
|
|
26
28
|
type NodeWitness,
|
|
29
|
+
nodeStamp,
|
|
27
30
|
nodesUnchanged,
|
|
28
31
|
readGraphWitness,
|
|
29
32
|
reusableGraph,
|
|
@@ -219,7 +222,8 @@ describe('installed graph input identity', () => {
|
|
|
219
222
|
const { nx, plugin, dependency, resolver } = await packages();
|
|
220
223
|
const output = join(plugin, 'dist', 'index.js');
|
|
221
224
|
await utimes(output, 1_600_000_000, 1_600_000_000);
|
|
222
|
-
const identity = () =>
|
|
225
|
+
const identity = () =>
|
|
226
|
+
graphInstallationIdentity(root, { plugins: ['@smoothbricks/nx-plugin'] }, resolver, expandOutputs, null);
|
|
223
227
|
const original = identity();
|
|
224
228
|
expect(original).not.toBeNull();
|
|
225
229
|
expect(identity()).toBe(original);
|
|
@@ -263,7 +267,8 @@ describe('installed graph input identity', () => {
|
|
|
263
267
|
const output = join(dependency, 'dist', 'payload.bin');
|
|
264
268
|
const bytes = Buffer.alloc(2 * 64 * 1024 + 17, 0x61);
|
|
265
269
|
await writeFile(output, bytes);
|
|
266
|
-
const identity = () =>
|
|
270
|
+
const identity = () =>
|
|
271
|
+
graphInstallationIdentity(root, { plugins: ['@smoothbricks/nx-plugin'] }, resolver, expandOutputs, null);
|
|
267
272
|
const original = parsed(identity());
|
|
268
273
|
expect(original.files.find(({ path }) => path === output)?.sha256).toBe(
|
|
269
274
|
createHash('sha256').update(bytes).digest('hex'),
|
|
@@ -287,7 +292,8 @@ describe('installed graph input identity', () => {
|
|
|
287
292
|
const published = join(root, 'published-build-volume');
|
|
288
293
|
await rename(join(plugin, 'dist'), published);
|
|
289
294
|
await symlink(published, join(plugin, 'dist'), 'dir');
|
|
290
|
-
const identity = () =>
|
|
295
|
+
const identity = () =>
|
|
296
|
+
graphInstallationIdentity(root, { plugins: ['@smoothbricks/nx-plugin'] }, resolver, expandOutputs, null);
|
|
291
297
|
const original = identity();
|
|
292
298
|
expect(original).not.toBeNull();
|
|
293
299
|
expect(identity()).toBe(original);
|
|
@@ -307,38 +313,216 @@ describe('installed graph input identity', () => {
|
|
|
307
313
|
const alternative = join(root, 'alternative-dependency');
|
|
308
314
|
await mkdir(alternative);
|
|
309
315
|
await writeFile(join(alternative, 'package.json'), '{"name":"owned","version":"1"}');
|
|
310
|
-
const original = graphInstallationIdentity(
|
|
316
|
+
const original = graphInstallationIdentity(
|
|
317
|
+
root,
|
|
318
|
+
{ plugins: ['@smoothbricks/nx-plugin'] },
|
|
319
|
+
resolver,
|
|
320
|
+
expandOutputs,
|
|
321
|
+
null,
|
|
322
|
+
);
|
|
311
323
|
const changed: typeof resolver = (name, from) => {
|
|
312
324
|
const result = resolver(name, from);
|
|
313
325
|
return name === 'alias' ? { ...result, path: join(alternative, 'package.json') } : result;
|
|
314
326
|
};
|
|
315
|
-
expect(
|
|
327
|
+
expect(
|
|
328
|
+
graphInstallationIdentity(root, { plugins: ['@smoothbricks/nx-plugin'] }, changed, expandOutputs, null),
|
|
329
|
+
).not.toBe(original);
|
|
316
330
|
expect(dependency).not.toBe(alternative);
|
|
317
331
|
});
|
|
318
332
|
|
|
333
|
+
it('binds an installed dependency exposing only public subpaths, without inventing a main entry', async () => {
|
|
334
|
+
const { plugin, dependency, resolver } = await packages();
|
|
335
|
+
await mkdir(join(plugin, 'node_modules'), { recursive: true });
|
|
336
|
+
await symlink(dependency, join(plugin, 'node_modules/alias'), 'dir');
|
|
337
|
+
await writeFile(
|
|
338
|
+
join(dependency, 'package.json'),
|
|
339
|
+
JSON.stringify({ name: 'owned', version: '1', exports: { './data': './data.json' } }),
|
|
340
|
+
);
|
|
341
|
+
await writeFile(join(dependency, 'data.json'), '{"value":1}');
|
|
342
|
+
const subpaths: typeof resolver = (name, paths) => {
|
|
343
|
+
if (name === 'alias')
|
|
344
|
+
throw Object.assign(new Error('No exports main defined'), { code: 'ERR_PACKAGE_PATH_NOT_EXPORTED' });
|
|
345
|
+
return resolver(name, paths);
|
|
346
|
+
};
|
|
347
|
+
const identity = () =>
|
|
348
|
+
graphInstallationIdentity(root, { plugins: ['@smoothbricks/nx-plugin'] }, subpaths, expandOutputs, null);
|
|
349
|
+
const original = identity();
|
|
350
|
+
expect(original).not.toBeNull();
|
|
351
|
+
await writeFile(join(dependency, 'data.json'), '{"value":2}');
|
|
352
|
+
expect(identity()).not.toBe(original);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it('uses package-root anchored publication patterns and Nx exclusions without dropping directory members', async () => {
|
|
356
|
+
const { plugin, resolver } = await packages();
|
|
357
|
+
const excluded = join(plugin, 'dist', 'state.tsbuildinfo');
|
|
358
|
+
await writeFile(excluded, 'before');
|
|
359
|
+
const anchored: typeof resolver = (name, paths) => {
|
|
360
|
+
const resolved = resolver(name, paths);
|
|
361
|
+
return { ...resolved, packageJson: { ...resolved.packageJson, files: ['/dist', '!**/*.tsbuildinfo'] } };
|
|
362
|
+
};
|
|
363
|
+
const identity = () =>
|
|
364
|
+
graphInstallationIdentity(root, { plugins: ['@smoothbricks/nx-plugin'] }, anchored, expandOutputs, null);
|
|
365
|
+
const original = identity();
|
|
366
|
+
expect(original).not.toBeNull();
|
|
367
|
+
await writeFile(excluded, 'after');
|
|
368
|
+
expect(identity()).toBe(original);
|
|
369
|
+
await writeFile(join(plugin, 'dist', 'index.js'), 'exports.value = 2;');
|
|
370
|
+
expect(identity()).not.toBe(original);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it('does not bind an unpublished cache marker but names a public marker changed during census', async () => {
|
|
374
|
+
const { plugin, resolver } = await packages();
|
|
375
|
+
await mkdir(join(plugin, '.cache'));
|
|
376
|
+
const privateMarker = join(plugin, '.cache', 'marker');
|
|
377
|
+
const publicMarker = join(plugin, 'dist', 'index.js');
|
|
378
|
+
await writeFile(privateMarker, 'before');
|
|
379
|
+
const during = (marker: string) => {
|
|
380
|
+
let changed = false;
|
|
381
|
+
let detail = '';
|
|
382
|
+
const mutate: typeof resolver = (name, paths) => {
|
|
383
|
+
const resolved = resolver(name, paths);
|
|
384
|
+
if (name === 'alias' && !changed) {
|
|
385
|
+
writeFileSync(marker, 'after');
|
|
386
|
+
changed = true;
|
|
387
|
+
}
|
|
388
|
+
return resolved;
|
|
389
|
+
};
|
|
390
|
+
const proof = graphInstallationIdentity(
|
|
391
|
+
root,
|
|
392
|
+
{ plugins: ['@smoothbricks/nx-plugin'] },
|
|
393
|
+
mutate,
|
|
394
|
+
expandOutputs,
|
|
395
|
+
null,
|
|
396
|
+
(reason) => {
|
|
397
|
+
detail = reason;
|
|
398
|
+
},
|
|
399
|
+
);
|
|
400
|
+
return { proof, changed, detail };
|
|
401
|
+
};
|
|
402
|
+
const unrelated = during(privateMarker);
|
|
403
|
+
expect(unrelated.changed).toBe(true);
|
|
404
|
+
expect(unrelated.proof).not.toBeNull();
|
|
405
|
+
expect(unrelated.detail).toBe('');
|
|
406
|
+
const changed = during(publicMarker);
|
|
407
|
+
expect(changed.changed).toBe(true);
|
|
408
|
+
expect(changed.proof).toBeNull();
|
|
409
|
+
expect(changed.detail).toContain(publicMarker);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it('retains the full tree without a publication declaration and names its changed marker', async () => {
|
|
413
|
+
const { plugin, resolver } = await packages();
|
|
414
|
+
await mkdir(join(plugin, '.cache'));
|
|
415
|
+
const marker = join(plugin, '.cache', 'marker');
|
|
416
|
+
await writeFile(marker, 'before');
|
|
417
|
+
let changed = false;
|
|
418
|
+
let detail = '';
|
|
419
|
+
const undeclared: typeof resolver = (name, paths) => {
|
|
420
|
+
const resolved = resolver(name, paths);
|
|
421
|
+
if (name === 'alias' && !changed) {
|
|
422
|
+
writeFileSync(marker, 'after');
|
|
423
|
+
changed = true;
|
|
424
|
+
}
|
|
425
|
+
const { files, ...packageJson } = resolved.packageJson;
|
|
426
|
+
expect(files).toEqual(['dist']);
|
|
427
|
+
return { ...resolved, packageJson };
|
|
428
|
+
};
|
|
429
|
+
expect(
|
|
430
|
+
graphInstallationIdentity(
|
|
431
|
+
root,
|
|
432
|
+
{ plugins: ['@smoothbricks/nx-plugin'] },
|
|
433
|
+
undeclared,
|
|
434
|
+
expandOutputs,
|
|
435
|
+
null,
|
|
436
|
+
(reason) => {
|
|
437
|
+
detail = reason;
|
|
438
|
+
},
|
|
439
|
+
),
|
|
440
|
+
).toBeNull();
|
|
441
|
+
expect(changed).toBe(true);
|
|
442
|
+
expect(detail).toContain(marker);
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
it("re-hashes a public file whose ctime alone moved during census, as Bun's bin linking moves a shared store file", async () => {
|
|
446
|
+
const { plugin, resolver } = await packages();
|
|
447
|
+
const output = join(plugin, 'dist/index.js');
|
|
448
|
+
const mode = (await stat(output)).mode & 0o7777;
|
|
449
|
+
let rechmodded = false;
|
|
450
|
+
let detail = '';
|
|
451
|
+
// Any checkout's install that links a bin re-chmods its store target to the mode it already has.
|
|
452
|
+
const sameMode: typeof resolver = (name, paths) => {
|
|
453
|
+
const resolved = resolver(name, paths);
|
|
454
|
+
if (name === 'alias' && !rechmodded) {
|
|
455
|
+
chmodSync(output, mode);
|
|
456
|
+
rechmodded = true;
|
|
457
|
+
}
|
|
458
|
+
return resolved;
|
|
459
|
+
};
|
|
460
|
+
const proof = graphInstallationIdentity(
|
|
461
|
+
root,
|
|
462
|
+
{ plugins: ['@smoothbricks/nx-plugin'] },
|
|
463
|
+
sameMode,
|
|
464
|
+
expandOutputs,
|
|
465
|
+
null,
|
|
466
|
+
(reason) => {
|
|
467
|
+
detail = reason;
|
|
468
|
+
},
|
|
469
|
+
);
|
|
470
|
+
expect(rechmodded).toBe(true);
|
|
471
|
+
expect(detail).toBe('');
|
|
472
|
+
// Bound, with the bytes it read: the identity carries the stamps of that census, not a later one's.
|
|
473
|
+
expect(parsed(proof).files.find(({ path }) => path === output)?.sha256).toBe(
|
|
474
|
+
createHash('sha256').update('exports.value = 1;').digest('hex'),
|
|
475
|
+
);
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it('names every moved node, and re-reads only one whose ctime alone moved', async () => {
|
|
479
|
+
const file = join(root, 'stamped');
|
|
480
|
+
await writeFile(file, 'before');
|
|
481
|
+
const witness = (): NodeWitness[] => [{ path: file, stamp: nodeStamp(lstatSync(file, { bigint: true })) }];
|
|
482
|
+
const chmodded = witness();
|
|
483
|
+
chmodSync(file, (await stat(file)).mode & 0o7777);
|
|
484
|
+
expect(movedNodes(chmodded)).toBe(file);
|
|
485
|
+
expect(movedNodes(chmodded, () => true)).toBeNull();
|
|
486
|
+
const written = witness();
|
|
487
|
+
await writeFile(file, 'after!');
|
|
488
|
+
expect(movedNodes(written, () => true)).toBe(file);
|
|
489
|
+
await rm(file);
|
|
490
|
+
expect(movedNodes(written)).toBe(`${file} (ENOENT)`);
|
|
491
|
+
});
|
|
492
|
+
|
|
319
493
|
it('fails loudly for unreadable required module bytes rather than publishing an installation witness', async () => {
|
|
320
494
|
const { plugin, resolver } = await packages();
|
|
321
495
|
const output = join(plugin, 'dist/index.js');
|
|
322
496
|
await chmod(output, 0);
|
|
323
497
|
try {
|
|
324
|
-
expect(() =>
|
|
498
|
+
expect(() =>
|
|
499
|
+
graphInstallationIdentity(root, { plugins: ['@smoothbricks/nx-plugin'] }, resolver, expandOutputs, null),
|
|
500
|
+
).toThrow();
|
|
325
501
|
} finally {
|
|
326
502
|
await chmod(output, 0o600);
|
|
327
503
|
}
|
|
328
504
|
});
|
|
329
505
|
it('does not invent an input contract for unknown plugins or unresolved required dependencies', async () => {
|
|
330
506
|
const { resolver } = await packages();
|
|
331
|
-
expect(graphInstallationIdentity(root, { plugins: ['opaque-plugin'] }, resolver)).toBeNull();
|
|
507
|
+
expect(graphInstallationIdentity(root, { plugins: ['opaque-plugin'] }, resolver, expandOutputs, null)).toBeNull();
|
|
332
508
|
expect(
|
|
333
|
-
graphInstallationIdentity(
|
|
334
|
-
|
|
335
|
-
|
|
509
|
+
graphInstallationIdentity(
|
|
510
|
+
root,
|
|
511
|
+
{},
|
|
512
|
+
() => {
|
|
513
|
+
throw Object.assign(new Error('missing'), { code: 'MODULE_NOT_FOUND' });
|
|
514
|
+
},
|
|
515
|
+
expandOutputs,
|
|
516
|
+
null,
|
|
517
|
+
),
|
|
336
518
|
).toBeNull();
|
|
337
519
|
});
|
|
338
520
|
|
|
339
521
|
it('refuses an unproved directory link instead of overlooking external plugin files', async () => {
|
|
340
522
|
const { plugin, dependency, resolver } = await packages();
|
|
341
|
-
await symlink(dependency, join(plugin, 'external'), 'dir');
|
|
342
|
-
expect(
|
|
523
|
+
await symlink(dependency, join(plugin, 'dist/external'), 'dir');
|
|
524
|
+
expect(
|
|
525
|
+
graphInstallationIdentity(root, { plugins: ['@smoothbricks/nx-plugin'] }, resolver, expandOutputs, null),
|
|
526
|
+
).toBeNull();
|
|
343
527
|
});
|
|
344
528
|
});
|
|
@@ -12,12 +12,19 @@ import {
|
|
|
12
12
|
rmSync,
|
|
13
13
|
writeFileSync,
|
|
14
14
|
} from 'node:fs';
|
|
15
|
-
import {
|
|
15
|
+
import { createRequire } from 'node:module';
|
|
16
|
+
import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
16
17
|
import type { NxJsonConfiguration } from 'nx/src/config/nx-json';
|
|
17
18
|
import type { ProjectGraph } from 'nx/src/config/project-graph';
|
|
18
|
-
import type { FileData, WorkspaceContext } from 'nx/src/native';
|
|
19
|
-
import type { readModulePackageJsonWithoutFallbacks } from 'nx/src/utils/package-json';
|
|
19
|
+
import type { expandOutputs, FileData, WorkspaceContext } from 'nx/src/native';
|
|
20
|
+
import type { PackageJson, readModulePackageJsonWithoutFallbacks } from 'nx/src/utils/package-json';
|
|
20
21
|
import typia from 'typia';
|
|
22
|
+
import type { GraphInputContractProof } from './graph-input-contract.js';
|
|
23
|
+
|
|
24
|
+
interface InstalledPackageManifest {
|
|
25
|
+
readonly path: string;
|
|
26
|
+
readonly packageJson: PackageJson;
|
|
27
|
+
}
|
|
21
28
|
|
|
22
29
|
/** Identity of a previously read node, not a timestamp freshness threshold. */
|
|
23
30
|
export function nodeStamp(stats: BigIntStats): string {
|
|
@@ -112,6 +119,34 @@ export function nodesUnchanged(nodes: readonly NodeWitness[]): boolean {
|
|
|
112
119
|
return true;
|
|
113
120
|
}
|
|
114
121
|
|
|
122
|
+
/**
|
|
123
|
+
* The witnessed nodes whose stamp is no longer the one read, named for a refusal (the first eight in witness order, a
|
|
124
|
+
* gone one with its error code, and how many more), or null when none moved. A node whose device, inode, mode, size
|
|
125
|
+
* and mtime are unchanged and only its ctime moved (a same-mode chmod, which Bun's bin linking does to a shared store
|
|
126
|
+
* file on any checkout's install) asks for a comparison, not a verdict: `same` re-reads it, and one it finds as
|
|
127
|
+
* recorded has not changed. Without `same` every move counts.
|
|
128
|
+
*/
|
|
129
|
+
export function movedNodes(
|
|
130
|
+
nodes: readonly NodeWitness[],
|
|
131
|
+
same: (path: string) => boolean = () => false,
|
|
132
|
+
): string | null {
|
|
133
|
+
const moved: string[] = [];
|
|
134
|
+
for (const node of nodes) {
|
|
135
|
+
try {
|
|
136
|
+
const stamp = nodeStamp(lstatSync(node.path, { bigint: true }));
|
|
137
|
+
if (stamp === node.stamp) continue;
|
|
138
|
+
// nodeStamp ends with the ctime: everything before it is the identity a same-mode chmod keeps.
|
|
139
|
+
const kept = stamp.slice(0, stamp.lastIndexOf(':')) === node.stamp.slice(0, node.stamp.lastIndexOf(':'));
|
|
140
|
+
if (!kept || !same(node.path)) moved.push(node.path);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (!systemError(error)) throw error;
|
|
143
|
+
moved.push(`${node.path} (${error.code})`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (moved.length === 0) return null;
|
|
147
|
+
return `${moved.slice(0, 8).join(', ')}${moved.length > 8 ? ` and ${moved.length - 8} more` : ''}`;
|
|
148
|
+
}
|
|
149
|
+
|
|
115
150
|
/** Membership and content are exact. Outputs do not exempt manifests or
|
|
116
151
|
* newly created/deleted files; this graph witness has no output exclusions.
|
|
117
152
|
*/
|
|
@@ -139,6 +174,15 @@ export function reusableGraph(
|
|
|
139
174
|
: null;
|
|
140
175
|
}
|
|
141
176
|
|
|
177
|
+
/** What {@link graphInstallationIdentity} binds: resolution edges `[from, name, physical manifest]`, node stamps and
|
|
178
|
+
* file hashes, read once.
|
|
179
|
+
*/
|
|
180
|
+
export interface GraphInstallationCensus {
|
|
181
|
+
readonly resolutions: readonly (readonly [string, string, string | null])[];
|
|
182
|
+
readonly nodes: readonly NodeWitness[];
|
|
183
|
+
readonly files: readonly { readonly path: string; readonly sha256: string }[];
|
|
184
|
+
}
|
|
185
|
+
|
|
142
186
|
/** Plugins with opaque external graph inputs cannot borrow this proof.
|
|
143
187
|
* For the repository plugin and Nx, bind the entire owned module/file tree
|
|
144
188
|
* and its dependency/optional/peer resolution closure, including each alias,
|
|
@@ -150,16 +194,63 @@ export function graphInstallationIdentity(
|
|
|
150
194
|
workspaceRoot: string,
|
|
151
195
|
nxJson: NxJsonConfiguration,
|
|
152
196
|
resolvePackage: typeof readModulePackageJsonWithoutFallbacks,
|
|
197
|
+
expand: typeof expandOutputs,
|
|
198
|
+
localInputs: GraphInputContractProof | null,
|
|
199
|
+
onUnproved?: (detail: string) => void,
|
|
153
200
|
): string | null {
|
|
201
|
+
const census = graphInstallationCensus(workspaceRoot, nxJson, resolvePackage, expand, localInputs, onUnproved);
|
|
202
|
+
if (census === null) return null;
|
|
203
|
+
try {
|
|
204
|
+
// A file whose ctime alone moved is re-hashed: Bun's bin linking on any checkout's install re-chmods a shared
|
|
205
|
+
// store file to the mode it already has (movedNodes).
|
|
206
|
+
const hashes = new Map(census.files.map(({ path, sha256 }) => [path, sha256]));
|
|
207
|
+
const moved = movedNodes(
|
|
208
|
+
census.nodes,
|
|
209
|
+
(path) => hashes.get(path) === createHash('sha256').update(readFileSync(path)).digest('hex'),
|
|
210
|
+
);
|
|
211
|
+
if (moved !== null) {
|
|
212
|
+
onUnproved?.(`Installed module node changed during inspection: ${moved}`);
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
} catch (error) {
|
|
216
|
+
if (systemError(error) && ['EACCES', 'EPERM', 'EIO'].includes(error.code)) throw error;
|
|
217
|
+
if (error instanceof Error) {
|
|
218
|
+
onUnproved?.(error.message);
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
return JSON.stringify({ ...census, localInputs: localInputs?.identity ?? null });
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** One read of the installation closure {@link graphInstallationIdentity} binds, without its final check that no node
|
|
227
|
+
* moved while it was read: what a caller that needs the closure, not a proof of it, reads. `null`, with `onUnproved`
|
|
228
|
+
* told why, for a closure that cannot be read.
|
|
229
|
+
*/
|
|
230
|
+
export function graphInstallationCensus(
|
|
231
|
+
workspaceRoot: string,
|
|
232
|
+
nxJson: NxJsonConfiguration,
|
|
233
|
+
resolvePackage: typeof readModulePackageJsonWithoutFallbacks,
|
|
234
|
+
expand: typeof expandOutputs,
|
|
235
|
+
localInputs: GraphInputContractProof | null,
|
|
236
|
+
onUnproved?: (detail: string) => void,
|
|
237
|
+
): GraphInstallationCensus | null {
|
|
154
238
|
const plugins = (nxJson.plugins ?? []).map((plugin) => (typeof plugin === 'string' ? plugin : plugin.plugin));
|
|
155
|
-
|
|
239
|
+
const unproved = plugins.filter(
|
|
240
|
+
(plugin) => plugin !== '@smoothbricks/nx-plugin' && !localInputs?.plugins.includes(plugin),
|
|
241
|
+
);
|
|
242
|
+
if (unproved.length > 0) {
|
|
243
|
+
onUnproved?.(`Unproved configured graph plugins: ${unproved.join(', ')}`);
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
156
246
|
const nodes: NodeWitness[] = [];
|
|
157
247
|
const files: { path: string; sha256: string }[] = [];
|
|
158
248
|
const buffer = Buffer.allocUnsafe(64 * 1024);
|
|
159
249
|
const resolutions: [string, string, string | null][] = [];
|
|
160
250
|
const visited = new Set<string>();
|
|
161
251
|
const declaredDirectoryLinks = new Set<string>();
|
|
162
|
-
|
|
252
|
+
const expandedRoots = new Set<string>();
|
|
253
|
+
function walk(path: string, selected?: ReadonlySet<string>): void {
|
|
163
254
|
const stats = lstatSync(path, { bigint: true });
|
|
164
255
|
nodes.push({ path, stamp: nodeStamp(stats) });
|
|
165
256
|
if (stats.isSymbolicLink()) {
|
|
@@ -169,8 +260,16 @@ export function graphInstallationIdentity(
|
|
|
169
260
|
}
|
|
170
261
|
walk(physical);
|
|
171
262
|
} else if (stats.isDirectory()) {
|
|
263
|
+
const visible = expandedRoots.has(path) ? undefined : selected;
|
|
172
264
|
for (const name of readdirSync(path).sort()) {
|
|
173
|
-
|
|
265
|
+
const child = join(path, name);
|
|
266
|
+
if (
|
|
267
|
+
name !== 'node_modules' &&
|
|
268
|
+
name !== '.git' &&
|
|
269
|
+
name !== '.nx' &&
|
|
270
|
+
(visible === undefined || visible.has(child))
|
|
271
|
+
)
|
|
272
|
+
walk(child, visible);
|
|
174
273
|
}
|
|
175
274
|
} else if (!stats.isFile()) {
|
|
176
275
|
throw new Error(`Unproved graph package node: ${path}`);
|
|
@@ -187,10 +286,29 @@ export function graphInstallationIdentity(
|
|
|
187
286
|
files.push({ path, sha256: hash.digest('hex') });
|
|
188
287
|
}
|
|
189
288
|
}
|
|
289
|
+
function installedManifest(name: string, from: string): InstalledPackageManifest {
|
|
290
|
+
try {
|
|
291
|
+
return resolvePackage(name, [from]);
|
|
292
|
+
} catch (original) {
|
|
293
|
+
if (systemError(original) && ['EACCES', 'EPERM', 'EIO'].includes(original.code)) throw original;
|
|
294
|
+
// A package may expose only subpaths: its dependency declaration still owns its installed manifest and files.
|
|
295
|
+
for (const directory of createRequire(join(from, 'package.json')).resolve.paths(name) ?? []) {
|
|
296
|
+
const path = join(directory, name, 'package.json');
|
|
297
|
+
try {
|
|
298
|
+
const packageJson = typia.json.assertParse<PackageJson>(readFileSync(path, 'utf8'));
|
|
299
|
+
return { path, packageJson };
|
|
300
|
+
} catch (error) {
|
|
301
|
+
if (systemError(error) && ['ENOENT', 'ENOTDIR'].includes(error.code)) continue;
|
|
302
|
+
throw error;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
throw original;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
190
308
|
function visit(name: string, from: string, optional: boolean): void {
|
|
191
|
-
let resolved:
|
|
309
|
+
let resolved: InstalledPackageManifest;
|
|
192
310
|
try {
|
|
193
|
-
resolved =
|
|
311
|
+
resolved = installedManifest(name, from);
|
|
194
312
|
} catch (error) {
|
|
195
313
|
if (optional && systemError(error) && error.code === 'MODULE_NOT_FOUND') {
|
|
196
314
|
resolutions.push([from, name, null]);
|
|
@@ -204,10 +322,59 @@ export function graphInstallationIdentity(
|
|
|
204
322
|
visited.add(physical);
|
|
205
323
|
const packageRoot = dirname(physical);
|
|
206
324
|
const manifest = resolved.packageJson;
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
325
|
+
// Explicit publication owns this tree; unknown declarations keep the conservative full census.
|
|
326
|
+
if (manifest.files !== undefined && manifest.files.length > 0) {
|
|
327
|
+
const patterns = manifest.files.map((pattern) => {
|
|
328
|
+
const negative = pattern.startsWith('!');
|
|
329
|
+
const relativePattern = (negative ? pattern.slice(1) : pattern).replace(/^\/+/u, '') || '.';
|
|
330
|
+
return negative ? `!${relativePattern}` : relativePattern;
|
|
331
|
+
});
|
|
332
|
+
const declared = new Set<string>();
|
|
333
|
+
const literal = (pattern: string) => !/[*?[\]{}]/u.test(pattern);
|
|
334
|
+
const validate = (entry: string) => {
|
|
335
|
+
if (isAbsolute(entry) || entry.split(/[\\/]/u).includes('..'))
|
|
336
|
+
throw new Error(`Published graph package path escapes its owner: ${entry}`);
|
|
337
|
+
};
|
|
338
|
+
const addDeclaration = (entry: string) => {
|
|
339
|
+
validate(entry);
|
|
340
|
+
if (literal(entry)) {
|
|
341
|
+
const absolute = resolve(packageRoot, entry);
|
|
342
|
+
declared.add(absolute);
|
|
343
|
+
declaredDirectoryLinks.add(absolute);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
for (const pattern of patterns) {
|
|
347
|
+
validate(pattern.startsWith('!') ? pattern.slice(1) : pattern);
|
|
348
|
+
if (!pattern.startsWith('!')) addDeclaration(pattern);
|
|
349
|
+
}
|
|
350
|
+
const exported = (value: unknown): void => {
|
|
351
|
+
if (typeof value === 'string') {
|
|
352
|
+
if (value.startsWith('./')) {
|
|
353
|
+
patterns.push(value);
|
|
354
|
+
addDeclaration(value);
|
|
355
|
+
}
|
|
356
|
+
} else if (Array.isArray(value)) {
|
|
357
|
+
for (const entry of value) exported(entry);
|
|
358
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
359
|
+
for (const entry of Object.values(value)) exported(entry);
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
exported(manifest.exports);
|
|
363
|
+
const selected = new Set<string>([packageRoot]);
|
|
364
|
+
const select = (entry: string) => {
|
|
365
|
+
validate(entry);
|
|
366
|
+
for (let path = resolve(packageRoot, entry); path !== packageRoot; path = dirname(path)) selected.add(path);
|
|
367
|
+
};
|
|
368
|
+
select('package.json');
|
|
369
|
+
for (const path of declared) select(relative(packageRoot, path));
|
|
370
|
+
for (const path of expand(packageRoot, patterns)) {
|
|
371
|
+
select(path);
|
|
372
|
+
expandedRoots.add(resolve(packageRoot, path));
|
|
373
|
+
}
|
|
374
|
+
walk(packageRoot, selected);
|
|
375
|
+
} else {
|
|
376
|
+
walk(packageRoot);
|
|
377
|
+
}
|
|
211
378
|
const dependencies = { ...manifest.peerDependencies, ...manifest.dependencies, ...manifest.optionalDependencies };
|
|
212
379
|
for (const dependency of Object.keys(dependencies).sort()) {
|
|
213
380
|
visit(
|
|
@@ -219,14 +386,19 @@ export function graphInstallationIdentity(
|
|
|
219
386
|
}
|
|
220
387
|
}
|
|
221
388
|
try {
|
|
222
|
-
for (const name of ['nx', ...plugins
|
|
389
|
+
for (const name of ['nx', ...plugins.filter((plugin) => plugin === '@smoothbricks/nx-plugin')])
|
|
390
|
+
visit(name, workspaceRoot, false);
|
|
391
|
+
for (const input of localInputs?.packages ?? []) visit(input.name, input.from, false);
|
|
223
392
|
visit('typescript', workspaceRoot, true);
|
|
224
|
-
return
|
|
393
|
+
return { resolutions, nodes, files };
|
|
225
394
|
} catch (error) {
|
|
226
395
|
if (systemError(error) && ['EACCES', 'EPERM', 'EIO'].includes(error.code)) throw error;
|
|
227
396
|
// Installation uncertainty disables only graph reuse. Nx's authoritative
|
|
228
397
|
// RPC remains responsible for diagnosing invalid plugin installations.
|
|
229
|
-
if (error instanceof Error)
|
|
398
|
+
if (error instanceof Error) {
|
|
399
|
+
onUnproved?.(error.message);
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
230
402
|
throw error;
|
|
231
403
|
}
|
|
232
404
|
}
|