@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/dist/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
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,12 +18,66 @@ export const DEPLOY_TARGET = 'deploy';
|
|
|
16
18
|
/** The purely file-derived half a deploy needs built first; cached. */
|
|
17
19
|
export const DEPLOY_BUILD_TARGET = 'deploy-build';
|
|
18
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'];
|
|
19
23
|
const TYPESCRIPT_TOOLCHAIN_INPUTS = [
|
|
20
|
-
|
|
21
|
-
'{workspaceRoot}/bun.lock',
|
|
24
|
+
...RELEASE_REWRITTEN_WORKSPACE_INPUTS,
|
|
22
25
|
'{workspaceRoot}/patches/**/*',
|
|
23
26
|
'{workspaceRoot}/tsconfig.base.json',
|
|
24
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];
|
|
25
81
|
const BIOME_CONFIG_FILES = ['biome.json', 'biome.jsonc'];
|
|
26
82
|
const ESLINT_CONFIG_FILES = [
|
|
27
83
|
'eslint.config.js',
|
|
@@ -87,19 +143,36 @@ function hostPlatformTargetNames(targetNames, hostPlatform) {
|
|
|
87
143
|
/**
|
|
88
144
|
* The reserved suffixes name targets that EMIT an artifact, and the `build`
|
|
89
145
|
* aggregate is a list of those. Handing Nx the raw `*-<family>` globs let it
|
|
90
|
-
* match on suffix alone, and
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
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.
|
|
97
161
|
*/
|
|
98
162
|
function buildOutputTargetNames(targetNames) {
|
|
99
163
|
return [...new Set(targetNames)]
|
|
100
|
-
.filter((name) => BUILD_OUTPUT_TARGET_PATTERN.test(name) && !name
|
|
164
|
+
.filter((name) => BUILD_OUTPUT_TARGET_PATTERN.test(name) && !isTestRunnerTargetName(name))
|
|
101
165
|
.sort();
|
|
102
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
|
+
}
|
|
103
176
|
//#region smoo!n/rust-output-target-inference
|
|
104
177
|
// Cargo workspace inference: a package.json sitting next to a Cargo.toml that
|
|
105
178
|
// declares [workspace] gets direct cargo-test/test targets, cargo-lint feeding
|
|
@@ -314,6 +387,98 @@ function createCargoTestArchiveTarget(projectRoot, toolConfig) {
|
|
|
314
387
|
},
|
|
315
388
|
};
|
|
316
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
|
+
}
|
|
317
482
|
function createCargoTestTarget(projectRoot) {
|
|
318
483
|
return {
|
|
319
484
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
@@ -332,6 +497,46 @@ function createCargoTestTarget(projectRoot) {
|
|
|
332
497
|
};
|
|
333
498
|
}
|
|
334
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
|
+
}
|
|
335
540
|
function createNodesHandler(hostPlatform) {
|
|
336
541
|
return async (projectConfigurationFiles, _options, context) => {
|
|
337
542
|
const results = [];
|
|
@@ -343,6 +548,7 @@ function createNodesHandler(hostPlatform) {
|
|
|
343
548
|
catch (error) {
|
|
344
549
|
throw new AggregateCreateNodesError([[null, error instanceof Error ? error : new Error(String(error))]], results);
|
|
345
550
|
}
|
|
551
|
+
const versionless = versionlessManifestPolicy(context);
|
|
346
552
|
await Promise.all(projectConfigurationFiles.map(async (packageJsonPath) => {
|
|
347
553
|
try {
|
|
348
554
|
if (isManagedPackageJsonSource(packageJsonPath) || isBuildOutputPackageJson(packageJsonPath)) {
|
|
@@ -357,7 +563,7 @@ function createNodesHandler(hostPlatform) {
|
|
|
357
563
|
}
|
|
358
564
|
results.push([
|
|
359
565
|
packageJsonPath,
|
|
360
|
-
await createProjectTargets(packageJsonPath, context.workspaceRoot, hostPlatform, cargoWorkspaces),
|
|
566
|
+
await createProjectTargets(packageJsonPath, context.workspaceRoot, hostPlatform, cargoWorkspaces, versionless),
|
|
361
567
|
]);
|
|
362
568
|
}
|
|
363
569
|
catch (error) {
|
|
@@ -410,7 +616,45 @@ function packageBinOutputs(packageJson, packageJsonPath) {
|
|
|
410
616
|
}
|
|
411
617
|
return [...outputs];
|
|
412
618
|
}
|
|
413
|
-
|
|
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) {
|
|
414
658
|
const projectRoot = dirname(packageJsonPath);
|
|
415
659
|
const absoluteProjectRoot = join(workspaceRoot, projectRoot);
|
|
416
660
|
const packageJson = await readPackageJson(join(workspaceRoot, packageJsonPath));
|
|
@@ -431,6 +675,20 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
431
675
|
const isCargoProject = cargoWorkspace !== undefined;
|
|
432
676
|
const repoRootPackages = cargoWorkspace?.projectRoot === '.' ? cargoPackagePlans.map((plan) => plan.package) : [];
|
|
433
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';
|
|
434
692
|
const napiConfig = resolveNapiConfig(packageJson, packageJsonPath, absoluteProjectRoot, isCargoWorkspace, repoRootPackages);
|
|
435
693
|
const declaredTargets = packageJson.nx?.targets ?? {};
|
|
436
694
|
const cargoWasmConfig = await resolveCargoWasmConfig(absoluteProjectRoot, packageJsonPath, workspaceRoot, repoRootPackages);
|
|
@@ -438,6 +696,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
438
696
|
const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
|
|
439
697
|
const hasOrdinaryBuildOutputTarget = hasLibTsconfig || napiConfig !== null || cargoWasmConfig !== null || packageLocalBuildOutputs.ordinary;
|
|
440
698
|
const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
|
|
699
|
+
const isWranglerProject = WRANGLER_CONFIG_FILES.some((file) => existsSync(join(absoluteProjectRoot, file)));
|
|
441
700
|
if (hasLibTsconfig) {
|
|
442
701
|
const executableOutputs = packageBinOutputs(packageJson, packageJsonPath);
|
|
443
702
|
// Dependency packages may publish bundled entries that raw tsc does not produce.
|
|
@@ -463,7 +722,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
463
722
|
targets.typecheck = {
|
|
464
723
|
executor: 'nx:run-commands',
|
|
465
724
|
cache: true,
|
|
466
|
-
inputs: [
|
|
725
|
+
inputs: [selfProduction, dependencyProduction, ...checkInputs, '{projectRoot}/tsconfig.lib.json'],
|
|
467
726
|
outputs: [],
|
|
468
727
|
dependsOn: ['^*-js', ...(cargoWasmConfig ? ['cargo-wasm'] : [])],
|
|
469
728
|
options: {
|
|
@@ -477,7 +736,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
477
736
|
targets['typecheck-tests'] = {
|
|
478
737
|
executor: 'nx:run-commands',
|
|
479
738
|
cache: true,
|
|
480
|
-
inputs: [
|
|
739
|
+
inputs: [selfDefault, dependencyProduction, ...checkInputs, '{projectRoot}/tsconfig.test.json'],
|
|
481
740
|
dependsOn: ['typecheck'],
|
|
482
741
|
options: {
|
|
483
742
|
command: 'tsc -p tsconfig.test.json --noEmit',
|
|
@@ -596,6 +855,13 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
596
855
|
// `archive.include` lives in the repository's nextest config, so that file
|
|
597
856
|
// decides what the archive CONTAINS, not merely how a run behaves.
|
|
598
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
|
+
}
|
|
599
865
|
const aggregateDependencies = cargoWorkspace.packages.flatMap((plan) => plan.pieces.map((piece) => cargoTargetDependency(projectName, {
|
|
600
866
|
projectName: plan.package.projectName,
|
|
601
867
|
targetName: piece.targetName,
|
|
@@ -926,17 +1192,37 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
926
1192
|
// dependent has to re-check liveness, not inherit someone else's cache hit.
|
|
927
1193
|
//
|
|
928
1194
|
// Both are bases for a package-local declaration to land on, per the merge rules above: a
|
|
929
|
-
// declaration naming `cache`, `inputs` or `dependsOn` REPLACES what is set here
|
|
930
|
-
//
|
|
931
|
-
//
|
|
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.
|
|
932
1207
|
if (DEPLOY_BUILD_TARGET in declaredTargets) {
|
|
933
1208
|
targets[DEPLOY_BUILD_TARGET] = { cache: true };
|
|
934
1209
|
}
|
|
935
|
-
if (
|
|
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;
|
|
936
1220
|
targets[DEPLOY_TARGET] = {
|
|
1221
|
+
executor: 'nx:run-commands',
|
|
937
1222
|
cache: false,
|
|
938
1223
|
outputs: [],
|
|
939
|
-
...(
|
|
1224
|
+
...(fileDerivedHalf === null ? {} : { dependsOn: [fileDerivedHalf] }),
|
|
1225
|
+
options: { command: WRANGLER_DEPLOY_COMMAND, cwd: projectRoot },
|
|
940
1226
|
};
|
|
941
1227
|
}
|
|
942
1228
|
// No `outputs`, deliberately: this aggregate runs no command, so every file
|
|
@@ -1020,8 +1306,8 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1020
1306
|
dependsOn: validationTargets,
|
|
1021
1307
|
outputs: [],
|
|
1022
1308
|
inputs: [
|
|
1023
|
-
|
|
1024
|
-
...
|
|
1309
|
+
selfDefault,
|
|
1310
|
+
...checkInputs,
|
|
1025
1311
|
...[...BIOME_CONFIG_FILES, ...ESLINT_CONFIG_FILES].flatMap((name) => [
|
|
1026
1312
|
`{workspaceRoot}/${name}`,
|
|
1027
1313
|
`{projectRoot}/${name}`,
|
|
@@ -1037,7 +1323,26 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1037
1323
|
}
|
|
1038
1324
|
return {
|
|
1039
1325
|
projects: {
|
|
1040
|
-
[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
|
+
},
|
|
1041
1346
|
},
|
|
1042
1347
|
};
|
|
1043
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"}
|