@smoothbricks/nx-plugin 0.4.11 → 0.4.12
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 +49 -0
- package/dist/cargo-workspace.d.ts +35 -0
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +59 -0
- package/dist/cross-check-policy.d.ts +49 -3
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +61 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +329 -24
- package/dist/manifest-hash.d.ts +39 -0
- package/dist/manifest-hash.d.ts.map +1 -0
- package/dist/manifest-hash.js +343 -0
- package/package.json +1 -1
- package/src/cargo-workspace.ts +83 -0
- package/src/cross-check-policy.test.ts +4 -1
- package/src/cross-check-policy.ts +66 -3
- package/src/index.test.ts +379 -18
- package/src/index.ts +400 -21
- package/src/manifest-hash.test.ts +199 -0
- package/src/manifest-hash.ts +335 -0
package/src/index.test.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
|
|
|
9
9
|
import { createTargetDefaultsResults } from 'nx/src/project-graph/utils/project-configuration/target-defaults.js';
|
|
10
10
|
import { mergeTargetConfigurations } from 'nx/src/project-graph/utils/project-configuration-utils.js';
|
|
11
11
|
import { BOUNDED_TEST_TIMEOUT_MS } from './bounded-test-policy.js';
|
|
12
|
-
import { exceptionalTestFilter } from './cargo-workspace.js';
|
|
12
|
+
import { exceptionalTestFilter, packageNameFromCargoTestTarget } from './cargo-workspace.js';
|
|
13
13
|
import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_LINT_CLIPPY_COMMAND } from './cross-check-policy.js';
|
|
14
14
|
import { createNodesV2, createNodesV2ForPlatform } from './index.js';
|
|
15
15
|
import { applyWorkspaceConfig } from './workspace-config-policy.js';
|
|
@@ -192,6 +192,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
192
192
|
'{workspaceRoot}/patches/**/*',
|
|
193
193
|
'{workspaceRoot}/tsconfig.base.json',
|
|
194
194
|
];
|
|
195
|
+
// An emit is a shipped artifact: it hashes the raw manifests, so a
|
|
196
|
+
// version bump reruns it rather than restoring a stale one.
|
|
195
197
|
expect(targets['tsc-js']?.inputs).toEqual([
|
|
196
198
|
'production',
|
|
197
199
|
'^production',
|
|
@@ -203,10 +205,16 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
203
205
|
command: 'tsc -p tsconfig.lib.json --noEmit',
|
|
204
206
|
cwd: 'packages/example',
|
|
205
207
|
});
|
|
208
|
+
const checkToolchainInputs = [
|
|
209
|
+
'{workspaceRoot}/patches/**/*',
|
|
210
|
+
'{workspaceRoot}/tsconfig.base.json',
|
|
211
|
+
{ json: '{workspaceRoot}/package.json', excludeFields: ['version'] },
|
|
212
|
+
{ json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
|
|
213
|
+
];
|
|
206
214
|
expect(targets.typecheck?.inputs).toEqual([
|
|
207
|
-
'
|
|
215
|
+
'versionlessProduction',
|
|
208
216
|
'^production',
|
|
209
|
-
...
|
|
217
|
+
...checkToolchainInputs,
|
|
210
218
|
'{projectRoot}/tsconfig.lib.json',
|
|
211
219
|
]);
|
|
212
220
|
expect(targets.build?.executor).toBe('nx:noop');
|
|
@@ -229,9 +237,9 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
229
237
|
cwd: 'packages/example',
|
|
230
238
|
});
|
|
231
239
|
expect(targets['typecheck-tests']?.inputs).toEqual([
|
|
232
|
-
'
|
|
240
|
+
'versionlessDefault',
|
|
233
241
|
'^production',
|
|
234
|
-
...
|
|
242
|
+
...checkToolchainInputs,
|
|
235
243
|
'{projectRoot}/tsconfig.test.json',
|
|
236
244
|
]);
|
|
237
245
|
|
|
@@ -257,6 +265,151 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
257
265
|
}
|
|
258
266
|
});
|
|
259
267
|
|
|
268
|
+
it('hashes the manifests without their versions for checks, raw for artifacts', async () => {
|
|
269
|
+
const workspace = await createWorkspace();
|
|
270
|
+
try {
|
|
271
|
+
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
272
|
+
await workspace.write('packages/example/tsconfig.lib.json', '{}\n');
|
|
273
|
+
await workspace.write('packages/example/tsconfig.test.json', '{}\n');
|
|
274
|
+
|
|
275
|
+
const project = await inferProjectWithNxJson(workspace, 'packages/example/package.json', {
|
|
276
|
+
namedInputs: { versionlessProduction: ['production'] },
|
|
277
|
+
});
|
|
278
|
+
const targets = project?.targets ?? {};
|
|
279
|
+
const checkToolchain = [
|
|
280
|
+
'{workspaceRoot}/patches/**/*',
|
|
281
|
+
'{workspaceRoot}/tsconfig.base.json',
|
|
282
|
+
// Hashed by Nx itself: a `json` input costs no process, and neither
|
|
283
|
+
// does the crate digest that replaces the manifests below.
|
|
284
|
+
{ json: '{workspaceRoot}/package.json', excludeFields: ['version'] },
|
|
285
|
+
{ json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
|
|
286
|
+
];
|
|
287
|
+
|
|
288
|
+
// No crate manifest in this project, so no crate digest is declared at
|
|
289
|
+
// all — nothing is hashed that nothing reads.
|
|
290
|
+
expect(project?.namedInputs).toEqual({
|
|
291
|
+
versionlessProduction: [
|
|
292
|
+
'production',
|
|
293
|
+
'!{projectRoot}/package.json',
|
|
294
|
+
{ json: '{projectRoot}/package.json', excludeFields: ['version'] },
|
|
295
|
+
],
|
|
296
|
+
versionlessDefault: [
|
|
297
|
+
'default',
|
|
298
|
+
'!{projectRoot}/package.json',
|
|
299
|
+
{ json: '{projectRoot}/package.json', excludeFields: ['version'] },
|
|
300
|
+
],
|
|
301
|
+
});
|
|
302
|
+
expect(targets.typecheck?.inputs).toEqual([
|
|
303
|
+
'versionlessProduction',
|
|
304
|
+
{ input: 'versionlessProduction', dependencies: true },
|
|
305
|
+
...checkToolchain,
|
|
306
|
+
'{projectRoot}/tsconfig.lib.json',
|
|
307
|
+
]);
|
|
308
|
+
expect(targets['typecheck-tests']?.inputs).toEqual([
|
|
309
|
+
'versionlessDefault',
|
|
310
|
+
{ input: 'versionlessProduction', dependencies: true },
|
|
311
|
+
...checkToolchain,
|
|
312
|
+
'{projectRoot}/tsconfig.test.json',
|
|
313
|
+
]);
|
|
314
|
+
expect(targets.lint?.inputs).toEqual([
|
|
315
|
+
'versionlessDefault',
|
|
316
|
+
...checkToolchain,
|
|
317
|
+
...[
|
|
318
|
+
'biome.json',
|
|
319
|
+
'biome.jsonc',
|
|
320
|
+
'eslint.config.js',
|
|
321
|
+
'eslint.config.mjs',
|
|
322
|
+
'eslint.config.cjs',
|
|
323
|
+
'eslint.config.ts',
|
|
324
|
+
'eslint.config.mts',
|
|
325
|
+
'eslint.config.cts',
|
|
326
|
+
].flatMap((name) => [`{workspaceRoot}/${name}`, `{projectRoot}/${name}`]),
|
|
327
|
+
'{workspaceRoot}/tooling/checks/**/*',
|
|
328
|
+
]);
|
|
329
|
+
|
|
330
|
+
// The guard this whole treatment lives or dies on. A declaration emit is
|
|
331
|
+
// a shipped artifact, and a crate compiled beside it embeds its version
|
|
332
|
+
// through `env!("CARGO_PKG_VERSION")`, so an artifact target that stopped
|
|
333
|
+
// hashing the raw manifests could hit a pre-bump entry and publish a
|
|
334
|
+
// binary reporting the previous version.
|
|
335
|
+
expect(targets['tsc-js']?.inputs).toEqual([
|
|
336
|
+
'production',
|
|
337
|
+
'^production',
|
|
338
|
+
'{workspaceRoot}/package.json',
|
|
339
|
+
'{workspaceRoot}/bun.lock',
|
|
340
|
+
'{workspaceRoot}/patches/**/*',
|
|
341
|
+
'{workspaceRoot}/tsconfig.base.json',
|
|
342
|
+
'{projectRoot}/tsconfig.lib.json',
|
|
343
|
+
]);
|
|
344
|
+
} finally {
|
|
345
|
+
await workspace.cleanup();
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it('hashes crate manifests into a digest, only where crates exist', async () => {
|
|
350
|
+
const workspace = await createWorkspace();
|
|
351
|
+
try {
|
|
352
|
+
const manifest = (version: string) =>
|
|
353
|
+
`[package]\nname = "rust-example"\nversion = "${version}"\n\n[dependencies]\nserde = { version = "1.0.200" }\n`;
|
|
354
|
+
await workspace.write('packages/rust/package.json', '{"name":"rust-example"}\n');
|
|
355
|
+
await workspace.write('packages/rust/tsconfig.lib.json', '{}\n');
|
|
356
|
+
await workspace.write('packages/rust/Cargo.toml', manifest('0.1.0'));
|
|
357
|
+
const production = async () =>
|
|
358
|
+
(await inferProjectWithNxJson(workspace, 'packages/rust/package.json', {}))?.namedInputs?.versionlessProduction;
|
|
359
|
+
|
|
360
|
+
const baseline = await production();
|
|
361
|
+
|
|
362
|
+
// TOML has no `json` input, so this is the one manifest kind the plugin
|
|
363
|
+
// hashes itself. There is no command behind it: the value IS the input,
|
|
364
|
+
// and Nx hashes it through the project configuration.
|
|
365
|
+
expect(baseline).toEqual([
|
|
366
|
+
'production',
|
|
367
|
+
'!{projectRoot}/package.json',
|
|
368
|
+
{ json: '{projectRoot}/package.json', excludeFields: ['version'] },
|
|
369
|
+
'!{projectRoot}/**/Cargo.toml',
|
|
370
|
+
expect.stringMatching(/^\{projectRoot\}\/\.versionless-crate-manifests\/[0-9a-f]{64}$/),
|
|
371
|
+
]);
|
|
372
|
+
|
|
373
|
+
// What the digest exists for: the release moves the crate's own version
|
|
374
|
+
// and nothing else, so the input a check hashes must not move with it.
|
|
375
|
+
await workspace.write('packages/rust/Cargo.toml', manifest('9.9.9'));
|
|
376
|
+
expect(await production()).toEqual(baseline);
|
|
377
|
+
|
|
378
|
+
// And a dependency really changing must still reach the hash, or the
|
|
379
|
+
// exclusion above would be hiding it.
|
|
380
|
+
await workspace.write('packages/rust/Cargo.toml', manifest('0.1.0').replace('1.0.200', '1.0.201'));
|
|
381
|
+
expect(await production()).not.toEqual(baseline);
|
|
382
|
+
} finally {
|
|
383
|
+
await workspace.cleanup();
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it('keeps the dependency half raw until the workspace defines the named input', async () => {
|
|
388
|
+
const workspace = await createWorkspace();
|
|
389
|
+
try {
|
|
390
|
+
await workspace.write('packages/example/package.json', '{"name":"example"}\n');
|
|
391
|
+
await workspace.write('packages/example/tsconfig.lib.json', '{}\n');
|
|
392
|
+
|
|
393
|
+
// `{ input, dependencies: true }` resolves the name in each dependency's
|
|
394
|
+
// own context and Nx throws when one has no definition for it. A
|
|
395
|
+
// project.json project this plugin never inferred has none, so the
|
|
396
|
+
// transitive half waits for the workspace-wide definition that covers it.
|
|
397
|
+
const targets = (await inferProjectWithNxJson(workspace, 'packages/example/package.json', {}))?.targets ?? {};
|
|
398
|
+
|
|
399
|
+
expect(targets.typecheck?.inputs).toEqual([
|
|
400
|
+
'versionlessProduction',
|
|
401
|
+
'^production',
|
|
402
|
+
'{workspaceRoot}/patches/**/*',
|
|
403
|
+
'{workspaceRoot}/tsconfig.base.json',
|
|
404
|
+
{ json: '{workspaceRoot}/package.json', excludeFields: ['version'] },
|
|
405
|
+
{ json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
|
|
406
|
+
'{projectRoot}/tsconfig.lib.json',
|
|
407
|
+
]);
|
|
408
|
+
} finally {
|
|
409
|
+
await workspace.cleanup();
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
|
|
260
413
|
it('rebuilds current library declarations before test typechecking after clean', async () => {
|
|
261
414
|
const workspace = await createWorkspace();
|
|
262
415
|
try {
|
|
@@ -314,6 +467,36 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
314
467
|
}
|
|
315
468
|
});
|
|
316
469
|
|
|
470
|
+
it('keeps a test runner out of the aggregate build however its name ends', async () => {
|
|
471
|
+
const workspace = await createWorkspace();
|
|
472
|
+
try {
|
|
473
|
+
await workspace.write(
|
|
474
|
+
'packages/suites/package.json',
|
|
475
|
+
JSON.stringify({
|
|
476
|
+
name: 'suites',
|
|
477
|
+
nx: {
|
|
478
|
+
targets: {
|
|
479
|
+
// A runner reading as "tool=test, output=bun". Suffix alone would
|
|
480
|
+
// sweep it into `build`, which is a serialized test suite behind
|
|
481
|
+
// every consumer's build.
|
|
482
|
+
'test-bun': { executor: 'nx:run-commands' },
|
|
483
|
+
'test:watch': { executor: 'nx:run-commands' },
|
|
484
|
+
// A real emitter in the same family, to prove the exclusion is
|
|
485
|
+
// the test-runner class and not the family itself.
|
|
486
|
+
'bundle-bun': { executor: 'nx:run-commands' },
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
}),
|
|
490
|
+
);
|
|
491
|
+
|
|
492
|
+
const targets = await inferProjectTargets(workspace, 'packages/suites/package.json');
|
|
493
|
+
|
|
494
|
+
expect(targets.build?.dependsOn).toEqual(['^build', 'bundle-bun']);
|
|
495
|
+
} finally {
|
|
496
|
+
await workspace.cleanup();
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
|
|
317
500
|
it('keeps platform-only output families out of the ordinary aggregate build', async () => {
|
|
318
501
|
const workspace = await createWorkspace();
|
|
319
502
|
try {
|
|
@@ -1476,28 +1659,101 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1476
1659
|
}
|
|
1477
1660
|
});
|
|
1478
1661
|
|
|
1479
|
-
it('
|
|
1662
|
+
it('gives a wrangler project a deploy that runs the stage CLI, uncached, behind its build half', async () => {
|
|
1663
|
+
const workspace = await createWorkspace();
|
|
1664
|
+
try {
|
|
1665
|
+
await workspace.write('packages/site/package.json', '{"name":"site"}\n');
|
|
1666
|
+
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
1667
|
+
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
1668
|
+
|
|
1669
|
+
// One target taking a stage, never a configuration per stage: pull-request stages are
|
|
1670
|
+
// `prN` for unbounded N, so `--configuration` could not name the stage that matters most.
|
|
1671
|
+
expect(targets.deploy?.options).toEqual({
|
|
1672
|
+
command: 'smoo wrangler deploy-stage --stage {args.stage}',
|
|
1673
|
+
cwd: 'packages/site',
|
|
1674
|
+
});
|
|
1675
|
+
// That exact string is load-bearing beyond running: the CLI's `isStageDerivedDeploy`
|
|
1676
|
+
// recognises a stage deploy by it, which is why the plugin emits it instead of asking
|
|
1677
|
+
// every consumer to retype it and drift.
|
|
1678
|
+
// A cache hit on deploy would mean "we once uploaded this hash", which a rollback falsifies
|
|
1679
|
+
// silently; the step has to run and read live state instead.
|
|
1680
|
+
expect(targets.deploy?.cache).toBe(false);
|
|
1681
|
+
expect(targets.deploy?.outputs).toEqual([]);
|
|
1682
|
+
// No build half of any kind here, so no edge is claimed: wrangler bundles its own
|
|
1683
|
+
// TypeScript, so a worker with neither `build` nor `deploy-build` is legitimate.
|
|
1684
|
+
expect(targets.deploy?.dependsOn).toBeUndefined();
|
|
1685
|
+
} finally {
|
|
1686
|
+
await workspace.cleanup();
|
|
1687
|
+
}
|
|
1688
|
+
});
|
|
1689
|
+
|
|
1690
|
+
it('points an inferred deploy at the declared deploy-build, and caches that half', async () => {
|
|
1480
1691
|
const workspace = await createWorkspace();
|
|
1481
1692
|
const declared = {
|
|
1482
|
-
deploy: { executor: 'nx:run-commands', options: { command: 'smoo wrangler deploy-stage --stage={args.stage}' } },
|
|
1483
1693
|
'deploy-build': { executor: 'nx:run-commands', options: { command: 'bun tooling/build-site.ts' } },
|
|
1484
1694
|
};
|
|
1485
1695
|
try {
|
|
1486
1696
|
await workspace.write('packages/site/package.json', JSON.stringify({ name: 'site', nx: { targets: declared } }));
|
|
1697
|
+
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
1698
|
+
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
1699
|
+
|
|
1700
|
+
expect(targets.deploy?.dependsOn).toEqual(['deploy-build']);
|
|
1701
|
+
// Only the project knows what building it means, so the plugin supplies the policy for
|
|
1702
|
+
// that half and nothing else.
|
|
1703
|
+
expect(resolveDeclaredOverInferred(targets, declared, 'deploy-build')?.cache).toBe(true);
|
|
1704
|
+
expect(resolveDeclaredOverInferred(targets, declared, 'deploy-build')?.options).toEqual({
|
|
1705
|
+
command: 'bun tooling/build-site.ts',
|
|
1706
|
+
});
|
|
1707
|
+
} finally {
|
|
1708
|
+
await workspace.cleanup();
|
|
1709
|
+
}
|
|
1710
|
+
});
|
|
1711
|
+
|
|
1712
|
+
it('falls back to the aggregate build when a wrangler project emits one', async () => {
|
|
1713
|
+
const workspace = await createWorkspace();
|
|
1714
|
+
try {
|
|
1715
|
+
await workspace.write('packages/site/package.json', '{"name":"site"}\n');
|
|
1716
|
+
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
1717
|
+
// tsconfig.lib.json is what puts an emitting target, and so the `build` aggregate, on a project.
|
|
1718
|
+
await workspace.write('packages/site/tsconfig.lib.json', '{}\n');
|
|
1719
|
+
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
1720
|
+
|
|
1721
|
+
expect(targets.build).toBeDefined();
|
|
1722
|
+
expect(targets.deploy?.dependsOn).toEqual(['build']);
|
|
1723
|
+
} finally {
|
|
1724
|
+
await workspace.cleanup();
|
|
1725
|
+
}
|
|
1726
|
+
});
|
|
1727
|
+
|
|
1728
|
+
it('lets a dependsOn-only declaration add a cross-project edge without restating the command', async () => {
|
|
1729
|
+
const workspace = await createWorkspace();
|
|
1730
|
+
// The whole point of inferring: ordering is expressed in Nx's own vocabulary, and the
|
|
1731
|
+
// consumer never retypes the command, cwd, cache or outputs to get it.
|
|
1732
|
+
const declared: Record<string, TargetConfiguration> = {
|
|
1733
|
+
deploy: { dependsOn: ['...', { projects: ['backend'], target: 'deploy', params: 'forward' }] },
|
|
1734
|
+
};
|
|
1735
|
+
try {
|
|
1736
|
+
await workspace.write('packages/site/package.json', JSON.stringify({ name: 'site', nx: { targets: declared } }));
|
|
1737
|
+
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
1738
|
+
await workspace.write('packages/site/tsconfig.lib.json', '{}\n');
|
|
1487
1739
|
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
1488
1740
|
|
|
1489
1741
|
const deploy = resolveDeclaredOverInferred(targets, declared, 'deploy');
|
|
1490
|
-
//
|
|
1491
|
-
//
|
|
1742
|
+
// `...` expands to the inferred list at its position, so the inferred build edge survives
|
|
1743
|
+
// beside the declared one.
|
|
1744
|
+
expect(deploy?.dependsOn).toEqual(['build', { projects: ['backend'], target: 'deploy', params: 'forward' }]);
|
|
1745
|
+
expect(deploy?.options).toEqual({
|
|
1746
|
+
command: 'smoo wrangler deploy-stage --stage {args.stage}',
|
|
1747
|
+
cwd: 'packages/site',
|
|
1748
|
+
});
|
|
1492
1749
|
expect(deploy?.cache).toBe(false);
|
|
1493
|
-
expect(deploy?.
|
|
1494
|
-
expect(resolveDeclaredOverInferred(targets, declared, 'deploy-build')?.cache).toBe(true);
|
|
1750
|
+
expect(deploy?.outputs).toEqual([]);
|
|
1495
1751
|
} finally {
|
|
1496
1752
|
await workspace.cleanup();
|
|
1497
1753
|
}
|
|
1498
1754
|
});
|
|
1499
1755
|
|
|
1500
|
-
it('infers
|
|
1756
|
+
it('infers no deploy for a project with no wrangler manifest', async () => {
|
|
1501
1757
|
const workspace = await createWorkspace();
|
|
1502
1758
|
try {
|
|
1503
1759
|
await workspace.write('packages/lib/package.json', '{"name":"plain-lib"}\n');
|
|
@@ -1510,7 +1766,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1510
1766
|
}
|
|
1511
1767
|
});
|
|
1512
1768
|
|
|
1513
|
-
it('orders a three-project
|
|
1769
|
+
it('orders a three-project chain of INFERRED deploys through one run-many', async () => {
|
|
1514
1770
|
const workspace = await createWorkspace();
|
|
1515
1771
|
const root = workspace.context.workspaceRoot;
|
|
1516
1772
|
const repositoryRoot = fileURLToPath(new URL('../../../', import.meta.url));
|
|
@@ -1524,10 +1780,12 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1524
1780
|
namedInputs: { default: ['{projectRoot}/**/*'] },
|
|
1525
1781
|
}),
|
|
1526
1782
|
);
|
|
1527
|
-
// c is deepest: a's deploy calls into b's, b's calls into c's.
|
|
1528
|
-
//
|
|
1783
|
+
// c is deepest: a's deploy calls into b's, b's calls into c's. No project declares a
|
|
1784
|
+
// deploy target — each only has a wrangler manifest and, where it needs ordering, the
|
|
1785
|
+
// edge. Nothing here says "round one" or "round two", and no project knows the depth.
|
|
1529
1786
|
const chain: Record<string, string[]> = { a: ['b:deploy'], b: ['c:deploy'], c: [] };
|
|
1530
1787
|
for (const [name, dependsOn] of Object.entries(chain)) {
|
|
1788
|
+
await workspace.write(`packages/${name}/wrangler.toml`, `name = "${name}"\n`);
|
|
1531
1789
|
await workspace.write(
|
|
1532
1790
|
`packages/${name}/package.json`,
|
|
1533
1791
|
JSON.stringify({
|
|
@@ -1535,10 +1793,10 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1535
1793
|
nx: {
|
|
1536
1794
|
targets: {
|
|
1537
1795
|
deploy: {
|
|
1538
|
-
executor: 'nx:run-commands',
|
|
1539
1796
|
...(dependsOn.length > 0 ? { dependsOn: ['...', ...dependsOn] } : {}),
|
|
1540
|
-
//
|
|
1541
|
-
//
|
|
1797
|
+
// The real inferred command deploys to Cloudflare. Only `command` is
|
|
1798
|
+
// overridden, so this still proves the rest of the inferred target — the
|
|
1799
|
+
// executor that runs it, and the edges — is what carries the run.
|
|
1542
1800
|
options: {
|
|
1543
1801
|
command: `printf '%s\\n' ${name} >> ${join(root, 'deploy-order.txt')}`,
|
|
1544
1802
|
forwardAllArgs: false,
|
|
@@ -1586,6 +1844,91 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1586
1844
|
await workspace.cleanup();
|
|
1587
1845
|
}
|
|
1588
1846
|
}, 120_000);
|
|
1847
|
+
|
|
1848
|
+
it('archives a declared foreign triple beside the host archive, and runs it without building', async () => {
|
|
1849
|
+
const workspace = await createWorkspace();
|
|
1850
|
+
try {
|
|
1851
|
+
await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
|
|
1852
|
+
await workspace.write(
|
|
1853
|
+
'packages/ferris/Cargo.toml',
|
|
1854
|
+
'[workspace]\nmembers = ["crates/ferris-core"]\n\n' +
|
|
1855
|
+
'[workspace.metadata.smoothbricks.test]\n' +
|
|
1856
|
+
'cross-targets = [{ target = "aarch64-apple-darwin", cargo = "scripts/cargo-for-nextest.sh" }]\n',
|
|
1857
|
+
);
|
|
1858
|
+
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
1859
|
+
await workspace.write('packages/ferris/scripts/cargo-for-nextest.sh', '#!/bin/sh\nexec cargo "$@"\n');
|
|
1860
|
+
|
|
1861
|
+
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
1862
|
+
const archive = targets['cargo-cross-test-archive-aarch64-apple-darwin'];
|
|
1863
|
+
const run = targets['cargo-cross-test-aarch64-apple-darwin'];
|
|
1864
|
+
|
|
1865
|
+
// A distinct archive file, declared as this target's output: the host
|
|
1866
|
+
// archive must survive a cross build and each must be cached as itself.
|
|
1867
|
+
expect(archive?.outputs).toEqual(['{projectRoot}/target/nextest/archive-aarch64-apple-darwin.tar.zst']);
|
|
1868
|
+
expect(targets['cargo-test-archive']?.outputs).toEqual(['{projectRoot}/target/nextest/archive.tar.zst']);
|
|
1869
|
+
expect(archive?.cache).toBe(true);
|
|
1870
|
+
// Everything the host archive hashes, plus the declared driver: the
|
|
1871
|
+
// script that decides how the foreign link happens is an input of the
|
|
1872
|
+
// bytes it produces.
|
|
1873
|
+
for (const input of targets['cargo-test-archive']?.inputs ?? []) {
|
|
1874
|
+
expect(archive?.inputs).toContainEqual(input);
|
|
1875
|
+
}
|
|
1876
|
+
expect(archive?.inputs).toContain('{projectRoot}/scripts/cargo-for-nextest.sh');
|
|
1877
|
+
expect(archive?.options?.env).toEqual({ CARGO: 'scripts/cargo-for-nextest.sh' });
|
|
1878
|
+
// The runner needs no driver: it never invokes cargo at all.
|
|
1879
|
+
expect(run?.options?.env).toBeUndefined();
|
|
1880
|
+
expect(archive?.options?.commands?.[0]).toBe('mkdir -p target/nextest');
|
|
1881
|
+
// `cargo-nextest`, not `cargo nextest`: cargo overwrites CARGO for its
|
|
1882
|
+
// subcommands, and CARGO is the only seam a cross cargo driver has.
|
|
1883
|
+
expect(String(archive?.options?.commands?.[1])).toMatch(
|
|
1884
|
+
/^cargo-nextest nextest archive --workspace --target aarch64-apple-darwin --frozen --archive-file target\/nextest\/archive-aarch64-apple-darwin\.tar\.zst --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
|
|
1885
|
+
);
|
|
1886
|
+
expect(String(archive?.configurations?.production?.commands?.[1])).toContain(
|
|
1887
|
+
'nextest archive --workspace --release --target aarch64-apple-darwin',
|
|
1888
|
+
);
|
|
1889
|
+
// The archive BUILDS, so it needs the locked registry graph; the runner
|
|
1890
|
+
// never touches cargo, so it needs nothing and depends on nothing.
|
|
1891
|
+
expect(archive?.dependsOn).toEqual(['cargo-fetch']);
|
|
1892
|
+
expect(run?.dependsOn).toEqual([]);
|
|
1893
|
+
expect(String(run?.options?.command)).toMatch(
|
|
1894
|
+
/^cargo-nextest nextest run --archive-file target\/nextest\/archive-aarch64-apple-darwin\.tar\.zst --workspace-remap \. --no-tests=pass --user-config-file none --tool-config-file "smoo:\$PWD\/.*nextest\.toml"$/,
|
|
1895
|
+
);
|
|
1896
|
+
expect(run?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
|
|
1897
|
+
// Not a crate: the per-crate coverage policy reads `cargo-test-<name>`,
|
|
1898
|
+
// so a triple must not land in that namespace, and neither target may
|
|
1899
|
+
// join the test aggregate a host machine runs.
|
|
1900
|
+
expect(packageNameFromCargoTestTarget('cargo-cross-test-archive-aarch64-apple-darwin')).toBeNull();
|
|
1901
|
+
expect(packageNameFromCargoTestTarget('cargo-cross-test-aarch64-apple-darwin')).toBeNull();
|
|
1902
|
+
expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-ferris-core']);
|
|
1903
|
+
expect(targets.build?.dependsOn ?? []).not.toContain('cargo-cross-test-archive-aarch64-apple-darwin');
|
|
1904
|
+
} finally {
|
|
1905
|
+
await workspace.cleanup();
|
|
1906
|
+
}
|
|
1907
|
+
});
|
|
1908
|
+
|
|
1909
|
+
it('refuses a cross-targets declaration that cannot name a target or a file', async () => {
|
|
1910
|
+
const workspace = await createWorkspace();
|
|
1911
|
+
try {
|
|
1912
|
+
await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
|
|
1913
|
+
await workspace.write(
|
|
1914
|
+
'packages/ferris/Cargo.toml',
|
|
1915
|
+
'[workspace]\nmembers = ["crates/ferris-core"]\n\n' +
|
|
1916
|
+
'[workspace.metadata.smoothbricks.test]\ncross-targets = ["aarch64 apple darwin; rm -rf /"]\n',
|
|
1917
|
+
);
|
|
1918
|
+
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
1919
|
+
|
|
1920
|
+
const failure = await inferProjectTargets(workspace, 'packages/ferris/package.json').then(
|
|
1921
|
+
() => undefined,
|
|
1922
|
+
(error: unknown) => error,
|
|
1923
|
+
);
|
|
1924
|
+
if (!(failure instanceof AggregateCreateNodesError)) {
|
|
1925
|
+
throw new Error(`expected AggregateCreateNodesError, got ${String(failure)}`);
|
|
1926
|
+
}
|
|
1927
|
+
expect(failure.errors[0]?.[1]?.message).toMatch(/cross-targets entries must be target triples like/);
|
|
1928
|
+
} finally {
|
|
1929
|
+
await workspace.cleanup();
|
|
1930
|
+
}
|
|
1931
|
+
});
|
|
1589
1932
|
//#endregion
|
|
1590
1933
|
});
|
|
1591
1934
|
|
|
@@ -1624,6 +1967,24 @@ async function inferProject(
|
|
|
1624
1967
|
return result[0]?.[1].projects?.[dirname(packageJsonPath)];
|
|
1625
1968
|
}
|
|
1626
1969
|
|
|
1970
|
+
/**
|
|
1971
|
+
* Inference against a chosen nx.json. The versionless manifest inputs reach as
|
|
1972
|
+
* far as the workspace's own `namedInputs` allow, so the workspace
|
|
1973
|
+
* configuration is an input to inference and not a constant of the fixture.
|
|
1974
|
+
*/
|
|
1975
|
+
async function inferProjectWithNxJson(
|
|
1976
|
+
workspace: WorkspaceFixture,
|
|
1977
|
+
packageJsonPath: string,
|
|
1978
|
+
nxJsonConfiguration: CreateNodesContextV2['nxJsonConfiguration'],
|
|
1979
|
+
) {
|
|
1980
|
+
const [, infer] = createNodesV2;
|
|
1981
|
+
const result = await infer([packageJsonPath], undefined, {
|
|
1982
|
+
workspaceRoot: workspace.context.workspaceRoot,
|
|
1983
|
+
nxJsonConfiguration,
|
|
1984
|
+
});
|
|
1985
|
+
return result[0]?.[1].projects?.[dirname(packageJsonPath)];
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1627
1988
|
async function inferProjectTargets(
|
|
1628
1989
|
workspace: WorkspaceFixture,
|
|
1629
1990
|
packageJsonPath: string,
|