@smoothbricks/nx-plugin 0.4.11 → 0.4.13
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 +56 -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 +334 -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 +406 -19
- package/src/index.ts +408 -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,126 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1476
1659
|
}
|
|
1477
1660
|
});
|
|
1478
1661
|
|
|
1479
|
-
it('
|
|
1662
|
+
it('gives a private 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","private":true}\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
|
+
// A cache hit on deploy would mean "we once uploaded this hash", which a rollback falsifies
|
|
1676
|
+
// silently; the step has to run and read live state instead.
|
|
1677
|
+
expect(targets.deploy?.cache).toBe(false);
|
|
1678
|
+
expect(targets.deploy?.outputs).toEqual([]);
|
|
1679
|
+
// No build half of any kind here, so no edge is claimed: wrangler bundles its own
|
|
1680
|
+
// TypeScript, so a worker with neither `build` nor `deploy-build` is legitimate.
|
|
1681
|
+
expect(targets.deploy?.dependsOn).toBeUndefined();
|
|
1682
|
+
} finally {
|
|
1683
|
+
await workspace.cleanup();
|
|
1684
|
+
}
|
|
1685
|
+
});
|
|
1686
|
+
|
|
1687
|
+
it('infers no deploy for a PUBLISHED package whose wrangler manifest documents a binding', async () => {
|
|
1688
|
+
const workspace = await createWorkspace();
|
|
1689
|
+
try {
|
|
1690
|
+
// The shape that regressed a consumer: a library published to npm that ships a wrangler
|
|
1691
|
+
// manifest so consumers can declare the Durable Object binding it implements. Structurally
|
|
1692
|
+
// identical to a worker's, so only the manifest's own `private` flag tells them apart.
|
|
1693
|
+
await workspace.write(
|
|
1694
|
+
'packages/acme-cloudflare/package.json',
|
|
1695
|
+
'{"name":"@acme/cloudflare","nx":{"tags":["npm:private"]}}\n',
|
|
1696
|
+
);
|
|
1697
|
+
await workspace.write(
|
|
1698
|
+
'packages/acme-cloudflare/wrangler.toml',
|
|
1699
|
+
'# Wrangler configuration for @acme/cloudflare Durable Object\nname = "acme-cloudflare"\nmain = "src/index.ts"\ncompatibility_date = "2025-01-01"\n',
|
|
1700
|
+
);
|
|
1701
|
+
const targets = await inferProjectTargets(workspace, 'packages/acme-cloudflare/package.json');
|
|
1702
|
+
|
|
1703
|
+
expect(Object.keys(targets)).not.toContain('deploy');
|
|
1704
|
+
} finally {
|
|
1705
|
+
await workspace.cleanup();
|
|
1706
|
+
}
|
|
1707
|
+
});
|
|
1708
|
+
|
|
1709
|
+
it('points an inferred deploy at the declared deploy-build, and caches that half', async () => {
|
|
1480
1710
|
const workspace = await createWorkspace();
|
|
1481
1711
|
const declared = {
|
|
1482
|
-
deploy: { executor: 'nx:run-commands', options: { command: 'smoo wrangler deploy-stage --stage={args.stage}' } },
|
|
1483
1712
|
'deploy-build': { executor: 'nx:run-commands', options: { command: 'bun tooling/build-site.ts' } },
|
|
1484
1713
|
};
|
|
1485
1714
|
try {
|
|
1486
|
-
await workspace.write(
|
|
1715
|
+
await workspace.write(
|
|
1716
|
+
'packages/site/package.json',
|
|
1717
|
+
JSON.stringify({ name: 'site', private: true, nx: { targets: declared } }),
|
|
1718
|
+
);
|
|
1719
|
+
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
1720
|
+
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
1721
|
+
|
|
1722
|
+
expect(targets.deploy?.dependsOn).toEqual(['deploy-build']);
|
|
1723
|
+
// Only the project knows what building it means, so the plugin supplies the policy for
|
|
1724
|
+
// that half and nothing else.
|
|
1725
|
+
expect(resolveDeclaredOverInferred(targets, declared, 'deploy-build')?.cache).toBe(true);
|
|
1726
|
+
expect(resolveDeclaredOverInferred(targets, declared, 'deploy-build')?.options).toEqual({
|
|
1727
|
+
command: 'bun tooling/build-site.ts',
|
|
1728
|
+
});
|
|
1729
|
+
} finally {
|
|
1730
|
+
await workspace.cleanup();
|
|
1731
|
+
}
|
|
1732
|
+
});
|
|
1733
|
+
|
|
1734
|
+
it('falls back to the aggregate build when a wrangler project emits one', async () => {
|
|
1735
|
+
const workspace = await createWorkspace();
|
|
1736
|
+
try {
|
|
1737
|
+
await workspace.write('packages/site/package.json', '{"name":"site","private":true}\n');
|
|
1738
|
+
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
1739
|
+
// tsconfig.lib.json is what puts an emitting target, and so the `build` aggregate, on a project.
|
|
1740
|
+
await workspace.write('packages/site/tsconfig.lib.json', '{}\n');
|
|
1741
|
+
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
1742
|
+
|
|
1743
|
+
expect(targets.build).toBeDefined();
|
|
1744
|
+
expect(targets.deploy?.dependsOn).toEqual(['build']);
|
|
1745
|
+
} finally {
|
|
1746
|
+
await workspace.cleanup();
|
|
1747
|
+
}
|
|
1748
|
+
});
|
|
1749
|
+
|
|
1750
|
+
it('lets a dependsOn-only declaration add a cross-project edge without restating the command', async () => {
|
|
1751
|
+
const workspace = await createWorkspace();
|
|
1752
|
+
// The whole point of inferring: ordering is expressed in Nx's own vocabulary, and the
|
|
1753
|
+
// consumer never retypes the command, cwd, cache or outputs to get it.
|
|
1754
|
+
const declared: Record<string, TargetConfiguration> = {
|
|
1755
|
+
deploy: { dependsOn: ['...', { projects: ['backend'], target: 'deploy', params: 'forward' }] },
|
|
1756
|
+
};
|
|
1757
|
+
try {
|
|
1758
|
+
await workspace.write(
|
|
1759
|
+
'packages/site/package.json',
|
|
1760
|
+
JSON.stringify({ name: 'site', private: true, nx: { targets: declared } }),
|
|
1761
|
+
);
|
|
1762
|
+
await workspace.write('packages/site/wrangler.toml', 'name = "site"\n');
|
|
1763
|
+
await workspace.write('packages/site/tsconfig.lib.json', '{}\n');
|
|
1487
1764
|
const targets = await inferProjectTargets(workspace, 'packages/site/package.json');
|
|
1488
1765
|
|
|
1489
1766
|
const deploy = resolveDeclaredOverInferred(targets, declared, 'deploy');
|
|
1490
|
-
//
|
|
1491
|
-
//
|
|
1767
|
+
// `...` expands to the inferred list at its position, so the inferred build edge survives
|
|
1768
|
+
// beside the declared one.
|
|
1769
|
+
expect(deploy?.dependsOn).toEqual(['build', { projects: ['backend'], target: 'deploy', params: 'forward' }]);
|
|
1770
|
+
expect(deploy?.options).toEqual({
|
|
1771
|
+
command: 'smoo wrangler deploy-stage --stage {args.stage}',
|
|
1772
|
+
cwd: 'packages/site',
|
|
1773
|
+
});
|
|
1492
1774
|
expect(deploy?.cache).toBe(false);
|
|
1493
|
-
expect(deploy?.
|
|
1494
|
-
expect(resolveDeclaredOverInferred(targets, declared, 'deploy-build')?.cache).toBe(true);
|
|
1775
|
+
expect(deploy?.outputs).toEqual([]);
|
|
1495
1776
|
} finally {
|
|
1496
1777
|
await workspace.cleanup();
|
|
1497
1778
|
}
|
|
1498
1779
|
});
|
|
1499
1780
|
|
|
1500
|
-
it('infers
|
|
1781
|
+
it('infers no deploy for a project with no wrangler manifest', async () => {
|
|
1501
1782
|
const workspace = await createWorkspace();
|
|
1502
1783
|
try {
|
|
1503
1784
|
await workspace.write('packages/lib/package.json', '{"name":"plain-lib"}\n');
|
|
@@ -1510,7 +1791,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1510
1791
|
}
|
|
1511
1792
|
});
|
|
1512
1793
|
|
|
1513
|
-
it('orders a three-project
|
|
1794
|
+
it('orders a three-project chain of INFERRED deploys through one run-many', async () => {
|
|
1514
1795
|
const workspace = await createWorkspace();
|
|
1515
1796
|
const root = workspace.context.workspaceRoot;
|
|
1516
1797
|
const repositoryRoot = fileURLToPath(new URL('../../../', import.meta.url));
|
|
@@ -1524,21 +1805,24 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1524
1805
|
namedInputs: { default: ['{projectRoot}/**/*'] },
|
|
1525
1806
|
}),
|
|
1526
1807
|
);
|
|
1527
|
-
// c is deepest: a's deploy calls into b's, b's calls into c's.
|
|
1528
|
-
//
|
|
1808
|
+
// c is deepest: a's deploy calls into b's, b's calls into c's. No project declares a
|
|
1809
|
+
// deploy target — each only has a wrangler manifest and, where it needs ordering, the
|
|
1810
|
+
// edge. Nothing here says "round one" or "round two", and no project knows the depth.
|
|
1529
1811
|
const chain: Record<string, string[]> = { a: ['b:deploy'], b: ['c:deploy'], c: [] };
|
|
1530
1812
|
for (const [name, dependsOn] of Object.entries(chain)) {
|
|
1813
|
+
await workspace.write(`packages/${name}/wrangler.toml`, `name = "${name}"\n`);
|
|
1531
1814
|
await workspace.write(
|
|
1532
1815
|
`packages/${name}/package.json`,
|
|
1533
1816
|
JSON.stringify({
|
|
1534
1817
|
name,
|
|
1818
|
+
private: true,
|
|
1535
1819
|
nx: {
|
|
1536
1820
|
targets: {
|
|
1537
1821
|
deploy: {
|
|
1538
|
-
executor: 'nx:run-commands',
|
|
1539
1822
|
...(dependsOn.length > 0 ? { dependsOn: ['...', ...dependsOn] } : {}),
|
|
1540
|
-
//
|
|
1541
|
-
//
|
|
1823
|
+
// The real inferred command deploys to Cloudflare. Only `command` is
|
|
1824
|
+
// overridden, so this still proves the rest of the inferred target — the
|
|
1825
|
+
// executor that runs it, and the edges — is what carries the run.
|
|
1542
1826
|
options: {
|
|
1543
1827
|
command: `printf '%s\\n' ${name} >> ${join(root, 'deploy-order.txt')}`,
|
|
1544
1828
|
forwardAllArgs: false,
|
|
@@ -1586,6 +1870,91 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
1586
1870
|
await workspace.cleanup();
|
|
1587
1871
|
}
|
|
1588
1872
|
}, 120_000);
|
|
1873
|
+
|
|
1874
|
+
it('archives a declared foreign triple beside the host archive, and runs it without building', async () => {
|
|
1875
|
+
const workspace = await createWorkspace();
|
|
1876
|
+
try {
|
|
1877
|
+
await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
|
|
1878
|
+
await workspace.write(
|
|
1879
|
+
'packages/ferris/Cargo.toml',
|
|
1880
|
+
'[workspace]\nmembers = ["crates/ferris-core"]\n\n' +
|
|
1881
|
+
'[workspace.metadata.smoothbricks.test]\n' +
|
|
1882
|
+
'cross-targets = [{ target = "aarch64-apple-darwin", cargo = "scripts/cargo-for-nextest.sh" }]\n',
|
|
1883
|
+
);
|
|
1884
|
+
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
1885
|
+
await workspace.write('packages/ferris/scripts/cargo-for-nextest.sh', '#!/bin/sh\nexec cargo "$@"\n');
|
|
1886
|
+
|
|
1887
|
+
const targets = await inferProjectTargets(workspace, 'packages/ferris/package.json');
|
|
1888
|
+
const archive = targets['cargo-cross-test-archive-aarch64-apple-darwin'];
|
|
1889
|
+
const run = targets['cargo-cross-test-aarch64-apple-darwin'];
|
|
1890
|
+
|
|
1891
|
+
// A distinct archive file, declared as this target's output: the host
|
|
1892
|
+
// archive must survive a cross build and each must be cached as itself.
|
|
1893
|
+
expect(archive?.outputs).toEqual(['{projectRoot}/target/nextest/archive-aarch64-apple-darwin.tar.zst']);
|
|
1894
|
+
expect(targets['cargo-test-archive']?.outputs).toEqual(['{projectRoot}/target/nextest/archive.tar.zst']);
|
|
1895
|
+
expect(archive?.cache).toBe(true);
|
|
1896
|
+
// Everything the host archive hashes, plus the declared driver: the
|
|
1897
|
+
// script that decides how the foreign link happens is an input of the
|
|
1898
|
+
// bytes it produces.
|
|
1899
|
+
for (const input of targets['cargo-test-archive']?.inputs ?? []) {
|
|
1900
|
+
expect(archive?.inputs).toContainEqual(input);
|
|
1901
|
+
}
|
|
1902
|
+
expect(archive?.inputs).toContain('{projectRoot}/scripts/cargo-for-nextest.sh');
|
|
1903
|
+
expect(archive?.options?.env).toEqual({ CARGO: 'scripts/cargo-for-nextest.sh' });
|
|
1904
|
+
// The runner needs no driver: it never invokes cargo at all.
|
|
1905
|
+
expect(run?.options?.env).toBeUndefined();
|
|
1906
|
+
expect(archive?.options?.commands?.[0]).toBe('mkdir -p target/nextest');
|
|
1907
|
+
// `cargo-nextest`, not `cargo nextest`: cargo overwrites CARGO for its
|
|
1908
|
+
// subcommands, and CARGO is the only seam a cross cargo driver has.
|
|
1909
|
+
expect(String(archive?.options?.commands?.[1])).toMatch(
|
|
1910
|
+
/^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"$/,
|
|
1911
|
+
);
|
|
1912
|
+
expect(String(archive?.configurations?.production?.commands?.[1])).toContain(
|
|
1913
|
+
'nextest archive --workspace --release --target aarch64-apple-darwin',
|
|
1914
|
+
);
|
|
1915
|
+
// The archive BUILDS, so it needs the locked registry graph; the runner
|
|
1916
|
+
// never touches cargo, so it needs nothing and depends on nothing.
|
|
1917
|
+
expect(archive?.dependsOn).toEqual(['cargo-fetch']);
|
|
1918
|
+
expect(run?.dependsOn).toEqual([]);
|
|
1919
|
+
expect(String(run?.options?.command)).toMatch(
|
|
1920
|
+
/^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"$/,
|
|
1921
|
+
);
|
|
1922
|
+
expect(run?.executor).toBe('@smoothbricks/nx-plugin:bounded-exec');
|
|
1923
|
+
// Not a crate: the per-crate coverage policy reads `cargo-test-<name>`,
|
|
1924
|
+
// so a triple must not land in that namespace, and neither target may
|
|
1925
|
+
// join the test aggregate a host machine runs.
|
|
1926
|
+
expect(packageNameFromCargoTestTarget('cargo-cross-test-archive-aarch64-apple-darwin')).toBeNull();
|
|
1927
|
+
expect(packageNameFromCargoTestTarget('cargo-cross-test-aarch64-apple-darwin')).toBeNull();
|
|
1928
|
+
expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-ferris-core']);
|
|
1929
|
+
expect(targets.build?.dependsOn ?? []).not.toContain('cargo-cross-test-archive-aarch64-apple-darwin');
|
|
1930
|
+
} finally {
|
|
1931
|
+
await workspace.cleanup();
|
|
1932
|
+
}
|
|
1933
|
+
});
|
|
1934
|
+
|
|
1935
|
+
it('refuses a cross-targets declaration that cannot name a target or a file', async () => {
|
|
1936
|
+
const workspace = await createWorkspace();
|
|
1937
|
+
try {
|
|
1938
|
+
await workspace.write('packages/ferris/package.json', '{"name":"ferris"}\n');
|
|
1939
|
+
await workspace.write(
|
|
1940
|
+
'packages/ferris/Cargo.toml',
|
|
1941
|
+
'[workspace]\nmembers = ["crates/ferris-core"]\n\n' +
|
|
1942
|
+
'[workspace.metadata.smoothbricks.test]\ncross-targets = ["aarch64 apple darwin; rm -rf /"]\n',
|
|
1943
|
+
);
|
|
1944
|
+
await workspace.write('packages/ferris/crates/ferris-core/Cargo.toml', '[package]\nname = "ferris-core"\n');
|
|
1945
|
+
|
|
1946
|
+
const failure = await inferProjectTargets(workspace, 'packages/ferris/package.json').then(
|
|
1947
|
+
() => undefined,
|
|
1948
|
+
(error: unknown) => error,
|
|
1949
|
+
);
|
|
1950
|
+
if (!(failure instanceof AggregateCreateNodesError)) {
|
|
1951
|
+
throw new Error(`expected AggregateCreateNodesError, got ${String(failure)}`);
|
|
1952
|
+
}
|
|
1953
|
+
expect(failure.errors[0]?.[1]?.message).toMatch(/cross-targets entries must be target triples like/);
|
|
1954
|
+
} finally {
|
|
1955
|
+
await workspace.cleanup();
|
|
1956
|
+
}
|
|
1957
|
+
});
|
|
1589
1958
|
//#endregion
|
|
1590
1959
|
});
|
|
1591
1960
|
|
|
@@ -1624,6 +1993,24 @@ async function inferProject(
|
|
|
1624
1993
|
return result[0]?.[1].projects?.[dirname(packageJsonPath)];
|
|
1625
1994
|
}
|
|
1626
1995
|
|
|
1996
|
+
/**
|
|
1997
|
+
* Inference against a chosen nx.json. The versionless manifest inputs reach as
|
|
1998
|
+
* far as the workspace's own `namedInputs` allow, so the workspace
|
|
1999
|
+
* configuration is an input to inference and not a constant of the fixture.
|
|
2000
|
+
*/
|
|
2001
|
+
async function inferProjectWithNxJson(
|
|
2002
|
+
workspace: WorkspaceFixture,
|
|
2003
|
+
packageJsonPath: string,
|
|
2004
|
+
nxJsonConfiguration: CreateNodesContextV2['nxJsonConfiguration'],
|
|
2005
|
+
) {
|
|
2006
|
+
const [, infer] = createNodesV2;
|
|
2007
|
+
const result = await infer([packageJsonPath], undefined, {
|
|
2008
|
+
workspaceRoot: workspace.context.workspaceRoot,
|
|
2009
|
+
nxJsonConfiguration,
|
|
2010
|
+
});
|
|
2011
|
+
return result[0]?.[1].projects?.[dirname(packageJsonPath)];
|
|
2012
|
+
}
|
|
2013
|
+
|
|
1627
2014
|
async function inferProjectTargets(
|
|
1628
2015
|
workspace: WorkspaceFixture,
|
|
1629
2016
|
packageJsonPath: string,
|