@smoothbricks/nx-plugin 0.4.10 → 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 +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +363 -19
- 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/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +77 -3
- package/package.json +2 -2
- 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 +478 -6
- package/src/index.ts +436 -16
- package/src/manifest-hash.test.ts +199 -0
- package/src/manifest-hash.ts +335 -0
- package/src/typecheck-test-policy.test.ts +36 -0
- package/src/typecheck-test-policy.ts +77 -3
package/dist/index.js
CHANGED
|
@@ -1,23 +1,83 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import { readdir, readFile } from 'node:fs/promises';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
3
4
|
import { dirname, join, posix, relative } from 'node:path';
|
|
4
5
|
import { fileURLToPath } from 'node:url';
|
|
5
6
|
import { readJsonFile, } from 'nx/src/devkit-exports.js';
|
|
6
7
|
import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
|
|
7
8
|
import { parse as parseToml } from 'smol-toml';
|
|
8
9
|
import { BOUNDED_TEST_KILL_AFTER_MS, BOUNDED_TEST_TIMEOUT_MS } from './bounded-test-policy.js';
|
|
9
|
-
import { attributeCargoWorkspacePackages, CARGO_TEST_ARCHIVE_FILE, CARGO_TEST_ARCHIVE_TARGET, CARGO_TEST_COMPILE_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoTestPackageTargetName, createCargoInputsCache, exceptionalTestFilter, listCargoWorkspacePackages, NEXTEST_REPO_CONFIG_PATH, nextestToolConfigArg, } from './cargo-workspace.js';
|
|
10
|
-
import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_FETCH_COMMAND, CARGO_FETCH_TARGET, CARGO_FROZEN_PREFIX, CARGO_LINT_CLIPPY_COMMAND, cargoFrozen, } from './cross-check-policy.js';
|
|
10
|
+
import { attributeCargoWorkspacePackages, CARGO_TEST_ARCHIVE_FILE, CARGO_TEST_ARCHIVE_TARGET, CARGO_TEST_COMPILE_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoTestPackageTargetName, createCargoInputsCache, exceptionalTestFilter, listCargoCrossTestTargets, listCargoWorkspacePackages, NEXTEST_REPO_CONFIG_PATH, nextestToolConfigArg, } from './cargo-workspace.js';
|
|
11
|
+
import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_FETCH_COMMAND, CARGO_FETCH_TARGET, CARGO_FROZEN_PREFIX, CARGO_LINT_CLIPPY_COMMAND, cargoCrossTestArchiveFile, cargoCrossTestArchiveTargetName, cargoCrossTestTargetName, cargoFrozen, } from './cross-check-policy.js';
|
|
12
|
+
import { hashVersionlessCrateManifests } from './manifest-hash.js';
|
|
11
13
|
import { isNonSourceDirectory } from './source-directories.js';
|
|
12
14
|
import { PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
13
15
|
export { CARGO_TEST_COMPILE_TARGET };
|
|
16
|
+
/** Makes a version live and proves it answers; never cached. */
|
|
17
|
+
export const DEPLOY_TARGET = 'deploy';
|
|
18
|
+
/** The purely file-derived half a deploy needs built first; cached. */
|
|
19
|
+
export const DEPLOY_BUILD_TARGET = 'deploy-build';
|
|
14
20
|
const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|android|native|napi|bun|wasm)$/;
|
|
21
|
+
/** The workspace-wide manifests a release rewrites: the version of every member, and the lockfile mirror of it. */
|
|
22
|
+
const RELEASE_REWRITTEN_WORKSPACE_INPUTS = ['{workspaceRoot}/package.json', '{workspaceRoot}/bun.lock'];
|
|
15
23
|
const TYPESCRIPT_TOOLCHAIN_INPUTS = [
|
|
16
|
-
|
|
17
|
-
'{workspaceRoot}/bun.lock',
|
|
24
|
+
...RELEASE_REWRITTEN_WORKSPACE_INPUTS,
|
|
18
25
|
'{workspaceRoot}/patches/**/*',
|
|
19
26
|
'{workspaceRoot}/tsconfig.base.json',
|
|
20
27
|
];
|
|
28
|
+
/**
|
|
29
|
+
* The same toolchain for a check, with the two release-rewritten files hashed
|
|
30
|
+
* by field instead of by byte.
|
|
31
|
+
*
|
|
32
|
+
* A `json` input is hashed by Nx's own hasher, so this costs no process. The
|
|
33
|
+
* lockfile's `workspaces` section is the mirror of each member's manifest —
|
|
34
|
+
* name, version and dependency specifiers — and every one of those is already
|
|
35
|
+
* hashed from the member's own `package.json`. Dropping that section keeps the
|
|
36
|
+
* resolution table, which is the reason the lockfile is an input at all.
|
|
37
|
+
*/
|
|
38
|
+
const VERSIONLESS_TOOLCHAIN_INPUTS = [
|
|
39
|
+
...TYPESCRIPT_TOOLCHAIN_INPUTS.filter((input) => !RELEASE_REWRITTEN_WORKSPACE_INPUTS.includes(input)),
|
|
40
|
+
{ json: '{workspaceRoot}/package.json', excludeFields: ['version'] },
|
|
41
|
+
{ json: '{workspaceRoot}/bun.lock', excludeFields: ['workspaces'] },
|
|
42
|
+
];
|
|
43
|
+
/**
|
|
44
|
+
* A project's own manifest, hashed without the version a release rewrites.
|
|
45
|
+
*
|
|
46
|
+
* ONLY targets that read source may exclude the raw file. A target that
|
|
47
|
+
* produces a shipped artifact keeps hashing it: Rust embeds its version at
|
|
48
|
+
* compile time through `env!("CARGO_PKG_VERSION")`, so a version-insensitive
|
|
49
|
+
* build hash lets a post-bump `build` hit a pre-bump artifact and ship a
|
|
50
|
+
* binary that reports the previous version. `tsc-js`, `build`, `pack` and
|
|
51
|
+
* every cargo target are therefore left alone.
|
|
52
|
+
*/
|
|
53
|
+
const VERSIONLESS_PACKAGE_INPUTS = [
|
|
54
|
+
'!{projectRoot}/package.json',
|
|
55
|
+
{ json: '{projectRoot}/package.json', excludeFields: ['version'] },
|
|
56
|
+
];
|
|
57
|
+
/**
|
|
58
|
+
* Crate manifests, for the projects that have any.
|
|
59
|
+
*
|
|
60
|
+
* TOML has no `json` input, so this is the one manifest kind the plugin
|
|
61
|
+
* hashes itself — in this process, over bytes it is already reading, during
|
|
62
|
+
* the graph construction that needs the answer.
|
|
63
|
+
*
|
|
64
|
+
* The digest reaches the hash as a literal, with no command behind it. Nx
|
|
65
|
+
* hashes a project's `namedInputs` DEFINITIONS into that project's
|
|
66
|
+
* configuration hash, and that hash is part of every task in the project and
|
|
67
|
+
* of every task that depends on the project — which is exactly the reach the
|
|
68
|
+
* transitive half needs. So the digest is written as an input path that
|
|
69
|
+
* matches no file and is only ever read as a string. It is a positive
|
|
70
|
+
* pattern, never an exclusion: a pattern that matched something unexpected
|
|
71
|
+
* could then only ADD to the hash, never quietly remove a real manifest from
|
|
72
|
+
* it.
|
|
73
|
+
*/
|
|
74
|
+
const VERSIONLESS_CRATE_EXCLUSION = '!{projectRoot}/**/Cargo.toml';
|
|
75
|
+
const VERSIONLESS_CRATE_DIGEST_PREFIX = '{projectRoot}/.versionless-crate-manifests/';
|
|
76
|
+
/** Plugin-owned named inputs: a project's `production`/`default` with the manifest versions ignored. */
|
|
77
|
+
const VERSIONLESS_PRODUCTION_INPUT = 'versionlessProduction';
|
|
78
|
+
const VERSIONLESS_DEFAULT_INPUT = 'versionlessDefault';
|
|
79
|
+
/** `json` inputs with `excludeFields` are Nx 23.2; an older hasher rejects the entry outright. */
|
|
80
|
+
const JSON_INPUT_MINIMUM_NX = [23, 2];
|
|
21
81
|
const BIOME_CONFIG_FILES = ['biome.json', 'biome.jsonc'];
|
|
22
82
|
const ESLINT_CONFIG_FILES = [
|
|
23
83
|
'eslint.config.js',
|
|
@@ -83,19 +143,36 @@ function hostPlatformTargetNames(targetNames, hostPlatform) {
|
|
|
83
143
|
/**
|
|
84
144
|
* The reserved suffixes name targets that EMIT an artifact, and the `build`
|
|
85
145
|
* aggregate is a list of those. Handing Nx the raw `*-<family>` globs let it
|
|
86
|
-
* match on suffix alone, and
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
146
|
+
* match on suffix alone, and a test runner collides by construction whenever
|
|
147
|
+
* its name ends in a family: `*-js`, `*-web`, `*-html`, `*-css`, `*-android`,
|
|
148
|
+
* `*-native`, `*-napi`, `*-bun`, `*-wasm`.
|
|
149
|
+
*
|
|
150
|
+
* Two spellings of the same collision. A per-crate cargo test runner is
|
|
151
|
+
* `cargo-test-<crate>`, so any crate whose name ends in a family put its RUNNER
|
|
152
|
+
* in the aggregate; the runners are one serialized chain, so a single such
|
|
153
|
+
* crate made `build` pull an entire cargo test suite. A bun suite named
|
|
154
|
+
* `test-bun` is the collision without the prefix — a runner reading as
|
|
155
|
+
* "tool=test, output=bun", swept into `build` by suffix alone. That one forced
|
|
156
|
+
* a consumer to hand-declare `build` purely to replace the inferred list.
|
|
157
|
+
*
|
|
158
|
+
* So the rule is the CLASS, not one namespace: a target that RUNS tests is
|
|
159
|
+
* never a build output, however it is spelled. Expanding the families here
|
|
160
|
+
* rather than delegating to Nx's matcher is what makes that expressible.
|
|
93
161
|
*/
|
|
94
162
|
function buildOutputTargetNames(targetNames) {
|
|
95
163
|
return [...new Set(targetNames)]
|
|
96
|
-
.filter((name) => BUILD_OUTPUT_TARGET_PATTERN.test(name) && !name
|
|
164
|
+
.filter((name) => BUILD_OUTPUT_TARGET_PATTERN.test(name) && !isTestRunnerTargetName(name))
|
|
97
165
|
.sort();
|
|
98
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* A target whose job is to RUN tests. `test`, anything under `test-`/`test:`,
|
|
169
|
+
* and the plugin's own `cargo-test-<crate>` namespace. Deliberately name-based:
|
|
170
|
+
* the aggregate is assembled from declared AND inferred target names, and a
|
|
171
|
+
* declaration carries no marker saying "this executes rather than emits".
|
|
172
|
+
*/
|
|
173
|
+
function isTestRunnerTargetName(name) {
|
|
174
|
+
return (name === 'test' || name.startsWith('test-') || name.startsWith('test:') || name.startsWith(`${CARGO_TEST_TARGET}-`));
|
|
175
|
+
}
|
|
99
176
|
//#region smoo!n/rust-output-target-inference
|
|
100
177
|
// Cargo workspace inference: a package.json sitting next to a Cargo.toml that
|
|
101
178
|
// declares [workspace] gets direct cargo-test/test targets, cargo-lint feeding
|
|
@@ -310,6 +387,98 @@ function createCargoTestArchiveTarget(projectRoot, toolConfig) {
|
|
|
310
387
|
},
|
|
311
388
|
};
|
|
312
389
|
}
|
|
390
|
+
/**
|
|
391
|
+
* One foreign triple's test archive, and the target that EXECUTES it.
|
|
392
|
+
*
|
|
393
|
+
* A target-triple VARIANT of `cargo-test-archive`, not a second mechanism: same
|
|
394
|
+
* `nextest archive --workspace`, same tool config layering, same
|
|
395
|
+
* `--workspace-remap .` on the run — only `--target <triple>` and a distinct
|
|
396
|
+
* archive file are added, because both archives coexist as declared Nx outputs
|
|
397
|
+
* and one path for two triples would let a restored cache serve the wrong
|
|
398
|
+
* machine's binaries.
|
|
399
|
+
*
|
|
400
|
+
* `cargo-nextest` where every other cargo target spells `cargo --frozen`, and
|
|
401
|
+
* that is measured, not stylistic: cargo overwrites `CARGO` with its own path
|
|
402
|
+
* for every subcommand it launches, so `cargo nextest` erases the cross cargo
|
|
403
|
+
* driver a repository exports through `CARGO` — the only seam nextest has for
|
|
404
|
+
* one. Invoking `cargo-nextest` directly leaves that driver intact, and
|
|
405
|
+
* `--frozen` moves onto nextest, which forwards it to both inner cargo calls
|
|
406
|
+
* (measured: `metadata … --frozen` and `test --no-run … --frozen`).
|
|
407
|
+
*
|
|
408
|
+
* The archive target therefore states `CARGO_FETCH_TARGET` and the toolchain
|
|
409
|
+
* runtime inputs itself: both are otherwise attached by matching the
|
|
410
|
+
* `cargo --frozen` prefix in a command, and this command does not carry it.
|
|
411
|
+
*
|
|
412
|
+
* The RUNNER declares no dependency on the archive and is not cached. That is
|
|
413
|
+
* the whole point of splitting the pair: it runs on a machine where the triple
|
|
414
|
+
* is native and the archive arrived as a file, so a dependency edge would ask
|
|
415
|
+
* that machine to cross-build what it was sent, and a cache verdict would be
|
|
416
|
+
* keyed on sources whose binaries it did not build. It is also the one cargo
|
|
417
|
+
* target that needs no cargo: `nextest run --archive-file` extracts prebuilt
|
|
418
|
+
* binaries and never invokes cargo (measured, zero invocations).
|
|
419
|
+
*/
|
|
420
|
+
function createCargoCrossTestTargets(projectRoot, toolConfig, crossTarget, archiveInputs) {
|
|
421
|
+
const { target: triple, cargo } = crossTarget;
|
|
422
|
+
const archiveFile = cargoCrossTestArchiveFile(triple);
|
|
423
|
+
const archiveCommand = (profile) => `cargo-nextest nextest archive --workspace${profile} --target ${triple} --frozen ` +
|
|
424
|
+
`--archive-file ${archiveFile} --user-config-file none ${toolConfig}`;
|
|
425
|
+
return {
|
|
426
|
+
[cargoCrossTestArchiveTargetName(triple)]: {
|
|
427
|
+
executor: 'nx:run-commands',
|
|
428
|
+
cache: true,
|
|
429
|
+
// The two runtime inputs every cached cargo target carries, plus the
|
|
430
|
+
// declared driver's own bytes. They are attached elsewhere by matching
|
|
431
|
+
// the `cargo --frozen` prefix in a command, which this one does not
|
|
432
|
+
// spell — and they matter MORE here than anywhere else: the cross
|
|
433
|
+
// environment (SDKROOT, CC_<triple>, ZIG*, and CARGO itself) is what
|
|
434
|
+
// decides whether these bytes are Mach-O at all, so an archive linked
|
|
435
|
+
// against one sysroot must never hash equal to the same sources linked
|
|
436
|
+
// against another.
|
|
437
|
+
inputs: [
|
|
438
|
+
...archiveInputs,
|
|
439
|
+
...(cargo === undefined ? [] : [`{projectRoot}/${cargo}`]),
|
|
440
|
+
cargoRuntimeInput(projectRoot, CARGO_ENVIRONMENT_INPUT.runtime),
|
|
441
|
+
cargoRuntimeInput(projectRoot, 'rustc -vV && cargo -V && cargo nextest --version'),
|
|
442
|
+
],
|
|
443
|
+
outputs: [`{projectRoot}/${archiveFile}`],
|
|
444
|
+
dependsOn: [CARGO_FETCH_TARGET],
|
|
445
|
+
options: {
|
|
446
|
+
commands: [`mkdir -p ${posix.dirname(archiveFile)}`, archiveCommand('')],
|
|
447
|
+
cwd: projectRoot,
|
|
448
|
+
parallel: false,
|
|
449
|
+
// `CARGO` is cargo's own driver variable and the only seam nextest
|
|
450
|
+
// offers: it shells out to `$CARGO metadata` and
|
|
451
|
+
// `$CARGO test --no-run --target <triple>`, so the declared script
|
|
452
|
+
// decides how the foreign link happens without the generated command
|
|
453
|
+
// knowing anything about zig, an SDK, or a sysroot. Target-scoped, so
|
|
454
|
+
// it applies to this archive and to nothing else cargo runs.
|
|
455
|
+
...(cargo === undefined ? {} : { env: { CARGO: cargo } }),
|
|
456
|
+
},
|
|
457
|
+
configurations: {
|
|
458
|
+
production: {
|
|
459
|
+
commands: [`mkdir -p ${posix.dirname(archiveFile)}`, archiveCommand(' --release')],
|
|
460
|
+
},
|
|
461
|
+
},
|
|
462
|
+
},
|
|
463
|
+
[cargoCrossTestTargetName(triple)]: {
|
|
464
|
+
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
465
|
+
cache: false,
|
|
466
|
+
inputs: [],
|
|
467
|
+
outputs: [],
|
|
468
|
+
dependsOn: [],
|
|
469
|
+
options: {
|
|
470
|
+
command: `cargo-nextest nextest run --archive-file ${archiveFile} --workspace-remap . ` +
|
|
471
|
+
`--no-tests=pass --user-config-file none ${toolConfig}`,
|
|
472
|
+
cwd: projectRoot,
|
|
473
|
+
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
474
|
+
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
475
|
+
},
|
|
476
|
+
// The archive already holds the profile it was built with, and nextest
|
|
477
|
+
// rejects `--release` beside `--archive-file`.
|
|
478
|
+
configurations: { production: {} },
|
|
479
|
+
},
|
|
480
|
+
};
|
|
481
|
+
}
|
|
313
482
|
function createCargoTestTarget(projectRoot) {
|
|
314
483
|
return {
|
|
315
484
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
@@ -328,6 +497,46 @@ function createCargoTestTarget(projectRoot) {
|
|
|
328
497
|
};
|
|
329
498
|
}
|
|
330
499
|
const PLUGIN_NEXTEST_CONFIG = fileURLToPath(new URL('../nextest.toml', import.meta.url));
|
|
500
|
+
function versionlessManifestPolicy(context) {
|
|
501
|
+
if (!supportsJsonInputs())
|
|
502
|
+
return null;
|
|
503
|
+
return { transitive: context.nxJsonConfiguration.namedInputs?.[VERSIONLESS_PRODUCTION_INPUT] !== undefined };
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* The crate manifests' exclusion and the digest that stands in for them, or
|
|
507
|
+
* nothing at all when this process cannot read them.
|
|
508
|
+
*
|
|
509
|
+
* Fail-closed, and the only direction that is safe: excluding the manifests
|
|
510
|
+
* with no digest replacing them would stop a real dependency change from
|
|
511
|
+
* invalidating anything, and neither Nx nor this plugin would say a word.
|
|
512
|
+
* Handing back the empty list leaves the raw manifests in the fileset — one
|
|
513
|
+
* cache miss per release, which is what the workspace has today.
|
|
514
|
+
*/
|
|
515
|
+
async function versionlessCrateInputs(projectRoot, workspaceRoot) {
|
|
516
|
+
try {
|
|
517
|
+
const digest = await hashVersionlessCrateManifests(projectRoot, workspaceRoot);
|
|
518
|
+
return [VERSIONLESS_CRATE_EXCLUSION, `${VERSIONLESS_CRATE_DIGEST_PREFIX}${digest}`];
|
|
519
|
+
}
|
|
520
|
+
catch (error) {
|
|
521
|
+
// Out loud: a silent degrade here reads as "the release stopped costing a
|
|
522
|
+
// rebuild", which is the same thing a wrong hash reads as.
|
|
523
|
+
process.stderr.write(`@smoothbricks/nx-plugin: hashing the crate manifests under ${projectRoot} failed (${error instanceof Error ? error.message : String(error)}); hashing them raw instead, so a release invalidates this project's checks.\n`);
|
|
524
|
+
return [];
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Whether the Nx that is RUNNING understands a `json` input. Read from the
|
|
529
|
+
* loaded module rather than the workspace, because that is the hasher which
|
|
530
|
+
* will receive the entry.
|
|
531
|
+
*/
|
|
532
|
+
function supportsJsonInputs() {
|
|
533
|
+
const version = readJsonFile(createRequire(import.meta.url).resolve('nx/package.json')).version;
|
|
534
|
+
if (typeof version !== 'string')
|
|
535
|
+
return false;
|
|
536
|
+
const [major = 0, minor = 0] = version.split('.', 2).map(Number);
|
|
537
|
+
const [minimumMajor, minimumMinor] = JSON_INPUT_MINIMUM_NX;
|
|
538
|
+
return major > minimumMajor || (major === minimumMajor && minor >= minimumMinor);
|
|
539
|
+
}
|
|
331
540
|
function createNodesHandler(hostPlatform) {
|
|
332
541
|
return async (projectConfigurationFiles, _options, context) => {
|
|
333
542
|
const results = [];
|
|
@@ -339,6 +548,7 @@ function createNodesHandler(hostPlatform) {
|
|
|
339
548
|
catch (error) {
|
|
340
549
|
throw new AggregateCreateNodesError([[null, error instanceof Error ? error : new Error(String(error))]], results);
|
|
341
550
|
}
|
|
551
|
+
const versionless = versionlessManifestPolicy(context);
|
|
342
552
|
await Promise.all(projectConfigurationFiles.map(async (packageJsonPath) => {
|
|
343
553
|
try {
|
|
344
554
|
if (isManagedPackageJsonSource(packageJsonPath) || isBuildOutputPackageJson(packageJsonPath)) {
|
|
@@ -353,7 +563,7 @@ function createNodesHandler(hostPlatform) {
|
|
|
353
563
|
}
|
|
354
564
|
results.push([
|
|
355
565
|
packageJsonPath,
|
|
356
|
-
await createProjectTargets(packageJsonPath, context.workspaceRoot, hostPlatform, cargoWorkspaces),
|
|
566
|
+
await createProjectTargets(packageJsonPath, context.workspaceRoot, hostPlatform, cargoWorkspaces, versionless),
|
|
357
567
|
]);
|
|
358
568
|
}
|
|
359
569
|
catch (error) {
|
|
@@ -406,7 +616,45 @@ function packageBinOutputs(packageJson, packageJsonPath) {
|
|
|
406
616
|
}
|
|
407
617
|
return [...outputs];
|
|
408
618
|
}
|
|
409
|
-
|
|
619
|
+
/**
|
|
620
|
+
* The deployment manifests wrangler itself looks for, in its own precedence
|
|
621
|
+
* order. Finding one IS the detection: a project that hands Cloudflare a
|
|
622
|
+
* worker has one of these, and nothing else in a workspace does.
|
|
623
|
+
*
|
|
624
|
+
* Deploy POLICY is deliberately NOT read from the manifest. `smoo.wrangler.stages`
|
|
625
|
+
* belongs to the CLI, which reads it to decide which secrets a stage requires; a
|
|
626
|
+
* second copy in the graph would disagree the first time a stage was added. And
|
|
627
|
+
* which stages CI actually runs is the four-way vocabulary in the CLI's
|
|
628
|
+
* `deploy-tags.ts` — every stage, staging only, excluded, production-on-push —
|
|
629
|
+
* that a flag here could express exactly one of. So every wrangler project gets
|
|
630
|
+
* the target, and CI selection keeps excluding by tag.
|
|
631
|
+
*
|
|
632
|
+
* A worker deployed by some other mechanism declares its own `options.command`,
|
|
633
|
+
* which replaces this one; `isStageDerivedDeploy` then correctly stops matching
|
|
634
|
+
* it, because the `deploy-stage` string went with it.
|
|
635
|
+
*/
|
|
636
|
+
const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml'];
|
|
637
|
+
/**
|
|
638
|
+
* ONE target that deploys whichever stage it is handed, never a configuration
|
|
639
|
+
* per stage. Pull-request stages are `prN` for unbounded N, so an enumerated
|
|
640
|
+
* `configurations` map cannot describe the surface that actually exists, and a
|
|
641
|
+
* project carrying both spellings would have two ways to say one thing.
|
|
642
|
+
*
|
|
643
|
+
* No `stage-deploy-target` tag either, deliberately: the CLI's
|
|
644
|
+
* `isStageDerivedDeploy` recognises a stage deploy by the tag OR by this exact
|
|
645
|
+
* command string, and the inferred target always carries the command. Adding
|
|
646
|
+
* the tag would be a second mechanism answering a question the first already
|
|
647
|
+
* answers, and the two would drift the first time either moved.
|
|
648
|
+
*
|
|
649
|
+
* `{args.stage}` rather than `forwardAllArgs`: run-commands'
|
|
650
|
+
* `interpolateArgsIntoCommand` returns as soon as it sees `{args.` and never
|
|
651
|
+
* appends forwarded arguments, so `nx run web:deploy --stage=pr42` yields
|
|
652
|
+
* exactly one `--stage`, for an arbitrary preview stage no map could enumerate.
|
|
653
|
+
* An omitted stage interpolates to empty and `deploy-stage`'s required
|
|
654
|
+
* `--stage` refuses it, which is the failure we want at the boundary.
|
|
655
|
+
*/
|
|
656
|
+
const WRANGLER_DEPLOY_COMMAND = 'smoo wrangler deploy-stage --stage {args.stage}';
|
|
657
|
+
async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform, cargoWorkspaces, versionless) {
|
|
410
658
|
const projectRoot = dirname(packageJsonPath);
|
|
411
659
|
const absoluteProjectRoot = join(workspaceRoot, projectRoot);
|
|
412
660
|
const packageJson = await readPackageJson(join(workspaceRoot, packageJsonPath));
|
|
@@ -427,6 +675,20 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
427
675
|
const isCargoProject = cargoWorkspace !== undefined;
|
|
428
676
|
const repoRootPackages = cargoWorkspace?.projectRoot === '.' ? cargoPackagePlans.map((plan) => plan.package) : [];
|
|
429
677
|
const isRepoRootedCargoProject = cargoWorkspace?.projectRoot === '.';
|
|
678
|
+
// What a check that only READS the manifests hashes instead of their raw
|
|
679
|
+
// bytes. Each piece degrades to today's input on its own: an Nx without
|
|
680
|
+
// `json` inputs gets no treatment at all; crate manifests this process
|
|
681
|
+
// cannot read stay raw; no workspace-wide named input leaves the
|
|
682
|
+
// transitive half `^production`.
|
|
683
|
+
const hasCrateManifests = isCargoProject || existsSync(cargoTomlPath);
|
|
684
|
+
const crateInputs = versionless !== null && hasCrateManifests ? await versionlessCrateInputs(projectRoot, workspaceRoot) : [];
|
|
685
|
+
const versionlessProjectInputs = versionless === null ? [] : [...VERSIONLESS_PACKAGE_INPUTS, ...crateInputs];
|
|
686
|
+
const checkInputs = versionless === null ? TYPESCRIPT_TOOLCHAIN_INPUTS : VERSIONLESS_TOOLCHAIN_INPUTS;
|
|
687
|
+
const selfProduction = versionless === null ? 'production' : VERSIONLESS_PRODUCTION_INPUT;
|
|
688
|
+
const selfDefault = versionless === null ? 'default' : VERSIONLESS_DEFAULT_INPUT;
|
|
689
|
+
const dependencyProduction = versionless?.transitive === true
|
|
690
|
+
? { input: VERSIONLESS_PRODUCTION_INPUT, dependencies: true }
|
|
691
|
+
: '^production';
|
|
430
692
|
const napiConfig = resolveNapiConfig(packageJson, packageJsonPath, absoluteProjectRoot, isCargoWorkspace, repoRootPackages);
|
|
431
693
|
const declaredTargets = packageJson.nx?.targets ?? {};
|
|
432
694
|
const cargoWasmConfig = await resolveCargoWasmConfig(absoluteProjectRoot, packageJsonPath, workspaceRoot, repoRootPackages);
|
|
@@ -434,6 +696,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
434
696
|
const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
|
|
435
697
|
const hasOrdinaryBuildOutputTarget = hasLibTsconfig || napiConfig !== null || cargoWasmConfig !== null || packageLocalBuildOutputs.ordinary;
|
|
436
698
|
const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
|
|
699
|
+
const isWranglerProject = WRANGLER_CONFIG_FILES.some((file) => existsSync(join(absoluteProjectRoot, file)));
|
|
437
700
|
if (hasLibTsconfig) {
|
|
438
701
|
const executableOutputs = packageBinOutputs(packageJson, packageJsonPath);
|
|
439
702
|
// Dependency packages may publish bundled entries that raw tsc does not produce.
|
|
@@ -459,7 +722,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
459
722
|
targets.typecheck = {
|
|
460
723
|
executor: 'nx:run-commands',
|
|
461
724
|
cache: true,
|
|
462
|
-
inputs: [
|
|
725
|
+
inputs: [selfProduction, dependencyProduction, ...checkInputs, '{projectRoot}/tsconfig.lib.json'],
|
|
463
726
|
outputs: [],
|
|
464
727
|
dependsOn: ['^*-js', ...(cargoWasmConfig ? ['cargo-wasm'] : [])],
|
|
465
728
|
options: {
|
|
@@ -473,7 +736,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
473
736
|
targets['typecheck-tests'] = {
|
|
474
737
|
executor: 'nx:run-commands',
|
|
475
738
|
cache: true,
|
|
476
|
-
inputs: [
|
|
739
|
+
inputs: [selfDefault, dependencyProduction, ...checkInputs, '{projectRoot}/tsconfig.test.json'],
|
|
477
740
|
dependsOn: ['typecheck'],
|
|
478
741
|
options: {
|
|
479
742
|
command: 'tsc -p tsconfig.test.json --noEmit',
|
|
@@ -592,6 +855,13 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
592
855
|
// `archive.include` lives in the repository's nextest config, so that file
|
|
593
856
|
// decides what the archive CONTAINS, not merely how a run behaves.
|
|
594
857
|
targets[CARGO_TEST_ARCHIVE_TARGET].inputs = [...workspaceCargoInputs, `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`];
|
|
858
|
+
// One archive per declared foreign triple, from the same inputs and the
|
|
859
|
+
// same repository nextest config: an archive is the workspace's test
|
|
860
|
+
// binaries whichever machine they are for, so a change that invalidates
|
|
861
|
+
// the host archive must invalidate every cross one.
|
|
862
|
+
for (const crossTarget of listCargoCrossTestTargets(join(workspaceRoot, cargoWorkspaceRoot))) {
|
|
863
|
+
Object.assign(targets, createCargoCrossTestTargets(cargoWorkspaceRoot, nextestToolConfigArg(workspaceRoot, cargoWorkspaceRoot, PLUGIN_NEXTEST_CONFIG), crossTarget, [...workspaceCargoInputs, `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`]));
|
|
864
|
+
}
|
|
595
865
|
const aggregateDependencies = cargoWorkspace.packages.flatMap((plan) => plan.pieces.map((piece) => cargoTargetDependency(projectName, {
|
|
596
866
|
projectName: plan.package.projectName,
|
|
597
867
|
targetName: piece.targetName,
|
|
@@ -900,6 +1170,61 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
900
1170
|
cargoNapi.dependsOn = [...dependsOn, cargoTestCompileDependency];
|
|
901
1171
|
}
|
|
902
1172
|
}
|
|
1173
|
+
// A deploy is never cached; the build half beside it always is.
|
|
1174
|
+
//
|
|
1175
|
+
// Nx's cache answers "did this exact input set already produce an output". A deploy's real
|
|
1176
|
+
// question is "is this exact version live", and the two agree only until someone rolls back.
|
|
1177
|
+
// After a rollback the workspace is unchanged, so the hash is unchanged, so a cached `deploy`
|
|
1178
|
+
// reports success while the previous version keeps serving. No input tuning repairs that: a
|
|
1179
|
+
// `runtime` input cannot even learn WHICH STAGE is being deployed. Nx hashes runtime inputs with
|
|
1180
|
+
// the env from `getTaskSpecificEnv`, which deliberately excludes the task coordinates; input
|
|
1181
|
+
// strings interpolate only `{workspaceRoot}`/`{projectRoot}`, never `{args.*}`; and overrides
|
|
1182
|
+
// are not forwarded to `dependsOn` dependencies, so an auxiliary task cannot carry the stage
|
|
1183
|
+
// either. (An executor's custom hasher is the single Nx API that does see `task.overrides`, if
|
|
1184
|
+
// hash-level participation is ever genuinely wanted.)
|
|
1185
|
+
//
|
|
1186
|
+
// So the target is split along the line the question actually falls on. `deploy-build` is purely
|
|
1187
|
+
// file-derived — build the artifact and whatever the build registers — and caches honestly.
|
|
1188
|
+
// `deploy` reads live state every run and no-ops when live already equals the desired tag, which
|
|
1189
|
+
// costs two Cloudflare calls and makes a redundant deploy provably free rather than assumed
|
|
1190
|
+
// free. That is what lets ordering be an ordinary `dependsOn: ["<other>:deploy"]` edge at any
|
|
1191
|
+
// depth, and it is why such an edge must point at `deploy` and not at `deploy-build`: a
|
|
1192
|
+
// dependent has to re-check liveness, not inherit someone else's cache hit.
|
|
1193
|
+
//
|
|
1194
|
+
// Both are bases for a package-local declaration to land on, per the merge rules above: a
|
|
1195
|
+
// declaration naming `cache`, `inputs` or `dependsOn` REPLACES what is set here and inherits
|
|
1196
|
+
// everything it does not name, while Nx's `"..."` token expands to the inferred list at its
|
|
1197
|
+
// position. So a project adding a cross-project edge writes
|
|
1198
|
+
// `"dependsOn": ["...", "backend:deploy"]` and keeps both the edge below and this command —
|
|
1199
|
+
// measured, not assumed, against an inferred base.
|
|
1200
|
+
//
|
|
1201
|
+
// `deploy` is INFERRED for a wrangler project rather than patched onto a hand-written one. The
|
|
1202
|
+
// command is a constant of the convention, not of the project: every consumer wrote the same
|
|
1203
|
+
// `nx:run-commands` wrapper around it, and one that spells it differently silently stops being
|
|
1204
|
+
// a stage deploy to `isStageDerivedDeploy`, which reads that exact string. `deploy-build` stays
|
|
1205
|
+
// declaration-driven in the other direction, because only the project knows what building it
|
|
1206
|
+
// means — the plugin supplies its POLICY (cache honestly) and nothing else.
|
|
1207
|
+
if (DEPLOY_BUILD_TARGET in declaredTargets) {
|
|
1208
|
+
targets[DEPLOY_BUILD_TARGET] = { cache: true };
|
|
1209
|
+
}
|
|
1210
|
+
if (isWranglerProject) {
|
|
1211
|
+
// Naming only an edge that exists is tidiness, not a guard: Nx tolerates a `dependsOn` on a
|
|
1212
|
+
// target the project lacks — measured, the task just runs alone — and a wrangler worker can
|
|
1213
|
+
// legitimately have no build at all, since wrangler bundles its own TypeScript. Pointing at a
|
|
1214
|
+
// target that is not there would only make `nx graph` claim a prerequisite nothing satisfies.
|
|
1215
|
+
const fileDerivedHalf = DEPLOY_BUILD_TARGET in declaredTargets
|
|
1216
|
+
? DEPLOY_BUILD_TARGET
|
|
1217
|
+
: hasOrdinaryBuildOutputTarget || 'build' in declaredTargets
|
|
1218
|
+
? 'build'
|
|
1219
|
+
: null;
|
|
1220
|
+
targets[DEPLOY_TARGET] = {
|
|
1221
|
+
executor: 'nx:run-commands',
|
|
1222
|
+
cache: false,
|
|
1223
|
+
outputs: [],
|
|
1224
|
+
...(fileDerivedHalf === null ? {} : { dependsOn: [fileDerivedHalf] }),
|
|
1225
|
+
options: { command: WRANGLER_DEPLOY_COMMAND, cwd: projectRoot },
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
903
1228
|
// No `outputs`, deliberately: this aggregate runs no command, so every file
|
|
904
1229
|
// under dist belongs to the concrete target that emitted it. Claiming
|
|
905
1230
|
// `{projectRoot}/dist` here would cache the children's bytes a second time
|
|
@@ -981,8 +1306,8 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
981
1306
|
dependsOn: validationTargets,
|
|
982
1307
|
outputs: [],
|
|
983
1308
|
inputs: [
|
|
984
|
-
|
|
985
|
-
...
|
|
1309
|
+
selfDefault,
|
|
1310
|
+
...checkInputs,
|
|
986
1311
|
...[...BIOME_CONFIG_FILES, ...ESLINT_CONFIG_FILES].flatMap((name) => [
|
|
987
1312
|
`{workspaceRoot}/${name}`,
|
|
988
1313
|
`{projectRoot}/${name}`,
|
|
@@ -998,7 +1323,26 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
998
1323
|
}
|
|
999
1324
|
return {
|
|
1000
1325
|
projects: {
|
|
1001
|
-
[projectRoot]: {
|
|
1326
|
+
[projectRoot]: {
|
|
1327
|
+
name: projectName,
|
|
1328
|
+
targets,
|
|
1329
|
+
// A named input is what `{ input, dependencies: true }` resolves in
|
|
1330
|
+
// each DEPENDENCY's own context, so the dependency half needs one to
|
|
1331
|
+
// exist per project. A `json` path interpolates `{projectRoot}` per
|
|
1332
|
+
// project, but a `runtime` command does NOT — it reaches the shell
|
|
1333
|
+
// literally — so a crate digest can only name its own root from here.
|
|
1334
|
+
// Nx resolves a named input from the project first and nx.json second,
|
|
1335
|
+
// so a workspace-wide definition still covers projects this plugin
|
|
1336
|
+
// never inferred.
|
|
1337
|
+
...(versionless === null
|
|
1338
|
+
? {}
|
|
1339
|
+
: {
|
|
1340
|
+
namedInputs: {
|
|
1341
|
+
[VERSIONLESS_PRODUCTION_INPUT]: ['production', ...versionlessProjectInputs],
|
|
1342
|
+
[VERSIONLESS_DEFAULT_INPUT]: ['default', ...versionlessProjectInputs],
|
|
1343
|
+
},
|
|
1344
|
+
}),
|
|
1345
|
+
},
|
|
1002
1346
|
},
|
|
1003
1347
|
};
|
|
1004
1348
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type Hash } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* Feed one crate manifest to `hash` without the versions the crate declares
|
|
4
|
+
* for itself.
|
|
5
|
+
*
|
|
6
|
+
* A forward scan over the bytes that hands the runs it keeps straight to the
|
|
7
|
+
* hasher as views: the manifest is never parsed into objects, never
|
|
8
|
+
* re-serialised, and never copied. `[package].version` and the
|
|
9
|
+
* `[workspace.package].version` that members inherit are the crate's own and
|
|
10
|
+
* go whole — trailing comment and newline included. A `version` under a
|
|
11
|
+
* dependency table, a `[target.'cfg(…)'.dependencies]` table or an inline
|
|
12
|
+
* table names a DIFFERENT crate and stays: dropping it would let a genuinely
|
|
13
|
+
* different dependency serve a stale result.
|
|
14
|
+
*
|
|
15
|
+
* Some of TOML is out of reach of a line-oriented scan. A multi-line basic or
|
|
16
|
+
* literal string can hold anything at all, a `[package]` header and a
|
|
17
|
+
* `version = "…"` line included, and no scan that has not lexed the whole
|
|
18
|
+
* document can tell that text from the document. So from the first `"""` or
|
|
19
|
+
* `'''`, from an unterminated value, and from any line it cannot classify,
|
|
20
|
+
* this elides nothing more and hashes the rest of the manifest verbatim. That
|
|
21
|
+
* direction is the safe one: hashing too much costs a cache miss on release,
|
|
22
|
+
* hashing too little serves a wrong result.
|
|
23
|
+
*/
|
|
24
|
+
export declare function updateVersionlessCrateManifest(hash: Hash, manifest: Buffer): void;
|
|
25
|
+
/**
|
|
26
|
+
* The digest of every crate manifest under a project, with the versions the
|
|
27
|
+
* crates declare for themselves removed.
|
|
28
|
+
*
|
|
29
|
+
* This is exactly what the validation targets exclude from their filesets.
|
|
30
|
+
* Paths are part of the digest, so moving a crate is a change even when no
|
|
31
|
+
* manifest body differs. A project with no crate manifest never declares this
|
|
32
|
+
* input at all, so the empty digest is not a case that reaches Nx.
|
|
33
|
+
*
|
|
34
|
+
* A crate that pins a workspace sibling by `path` + `version` still carries
|
|
35
|
+
* that sibling's version, so a release does invalidate it. That is the honest
|
|
36
|
+
* answer: the dependency the digest describes really did change.
|
|
37
|
+
*/
|
|
38
|
+
export declare function hashVersionlessCrateManifests(projectRoot: string, workspaceRoot: string): Promise<string>;
|
|
39
|
+
//# sourceMappingURL=manifest-hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest-hash.d.ts","sourceRoot":"","sources":["../src/manifest-hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAoEpD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CA8CjF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,6BAA6B,CAAC,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAgB/G"}
|