@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/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
- '{workspaceRoot}/package.json',
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 one namespace collides by construction: a
91
- * per-crate cargo test runner is named `cargo-test-<crate>`, so any crate whose
92
- * name ends in an output family — `*-napi`, `*-wasm`, `*-native`, `*-js` — put
93
- * its RUNNER in the aggregate. The runners are one serialized chain, so a
94
- * single such crate made `build` pull an entire cargo test suite. Expanding the
95
- * families here instead of delegating to Nx's matcher keeps the plugin's own
96
- * `cargo-test-` namespace out of the aggregate however a crate is named.
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.startsWith(`${CARGO_TEST_TARGET}-`))
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,46 @@ function packageBinOutputs(packageJson, packageJsonPath) {
410
616
  }
411
617
  return [...outputs];
412
618
  }
413
- async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform, cargoWorkspaces) {
619
+ /**
620
+ * The deployment manifests wrangler itself looks for, in its own precedence
621
+ * order. Finding one is HALF the detection: a published library ships one to
622
+ * document a Durable Object binding for its consumers, and that manifest is
623
+ * structurally indistinguishable from a deployable worker's — same `name`,
624
+ * `main` and `compatibility_date`. So presence alone cannot mean deployable,
625
+ * and the other half is `private: true` below.
626
+ *
627
+ * Deploy POLICY is deliberately NOT read from the manifest. `smoo.wrangler.stages`
628
+ * belongs to the CLI, which reads it to decide which secrets a stage requires; a
629
+ * second copy in the graph would disagree the first time a stage was added. And
630
+ * which stages CI actually runs is the four-way tag vocabulary in the CLI's
631
+ * `deploy-tags.ts` — every stage, staging only, excluded, production-on-push —
632
+ * that a flag here could express exactly one of. So a private wrangler project
633
+ * gets the target, and the tags alone decide what CI deploys.
634
+ *
635
+ * A worker deployed by some other mechanism declares its own `options.command`,
636
+ * which replaces this one; the tag is what CI reads either way.
637
+ */
638
+ const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml'];
639
+ /**
640
+ * ONE target that deploys whichever stage it is handed, never a configuration
641
+ * per stage. Pull-request stages are `prN` for unbounded N, so an enumerated
642
+ * `configurations` map cannot describe the surface that actually exists, and a
643
+ * project carrying both spellings would have two ways to say one thing.
644
+ *
645
+ * No `stage-deploy-target` tag either, deliberately: that tag is the repository's
646
+ * statement that CI deploys this project on every stage, and only the repository
647
+ * can make it. A plugin that tagged what it inferred would enrol every private
648
+ * wrangler project in CI deploys by writing the policy it is supposed to read.
649
+ *
650
+ * `{args.stage}` rather than `forwardAllArgs`: run-commands'
651
+ * `interpolateArgsIntoCommand` returns as soon as it sees `{args.` and never
652
+ * appends forwarded arguments, so `nx run web:deploy --stage=pr42` yields
653
+ * exactly one `--stage`, for an arbitrary preview stage no map could enumerate.
654
+ * An omitted stage interpolates to empty and `deploy-stage`'s required
655
+ * `--stage` refuses it, which is the failure we want at the boundary.
656
+ */
657
+ const WRANGLER_DEPLOY_COMMAND = 'smoo wrangler deploy-stage --stage {args.stage}';
658
+ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform, cargoWorkspaces, versionless) {
414
659
  const projectRoot = dirname(packageJsonPath);
415
660
  const absoluteProjectRoot = join(workspaceRoot, projectRoot);
416
661
  const packageJson = await readPackageJson(join(workspaceRoot, packageJsonPath));
@@ -431,6 +676,20 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
431
676
  const isCargoProject = cargoWorkspace !== undefined;
432
677
  const repoRootPackages = cargoWorkspace?.projectRoot === '.' ? cargoPackagePlans.map((plan) => plan.package) : [];
433
678
  const isRepoRootedCargoProject = cargoWorkspace?.projectRoot === '.';
679
+ // What a check that only READS the manifests hashes instead of their raw
680
+ // bytes. Each piece degrades to today's input on its own: an Nx without
681
+ // `json` inputs gets no treatment at all; crate manifests this process
682
+ // cannot read stay raw; no workspace-wide named input leaves the
683
+ // transitive half `^production`.
684
+ const hasCrateManifests = isCargoProject || existsSync(cargoTomlPath);
685
+ const crateInputs = versionless !== null && hasCrateManifests ? await versionlessCrateInputs(projectRoot, workspaceRoot) : [];
686
+ const versionlessProjectInputs = versionless === null ? [] : [...VERSIONLESS_PACKAGE_INPUTS, ...crateInputs];
687
+ const checkInputs = versionless === null ? TYPESCRIPT_TOOLCHAIN_INPUTS : VERSIONLESS_TOOLCHAIN_INPUTS;
688
+ const selfProduction = versionless === null ? 'production' : VERSIONLESS_PRODUCTION_INPUT;
689
+ const selfDefault = versionless === null ? 'default' : VERSIONLESS_DEFAULT_INPUT;
690
+ const dependencyProduction = versionless?.transitive === true
691
+ ? { input: VERSIONLESS_PRODUCTION_INPUT, dependencies: true }
692
+ : '^production';
434
693
  const napiConfig = resolveNapiConfig(packageJson, packageJsonPath, absoluteProjectRoot, isCargoWorkspace, repoRootPackages);
435
694
  const declaredTargets = packageJson.nx?.targets ?? {};
436
695
  const cargoWasmConfig = await resolveCargoWasmConfig(absoluteProjectRoot, packageJsonPath, workspaceRoot, repoRootPackages);
@@ -438,6 +697,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
438
697
  const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
439
698
  const hasOrdinaryBuildOutputTarget = hasLibTsconfig || napiConfig !== null || cargoWasmConfig !== null || packageLocalBuildOutputs.ordinary;
440
699
  const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
700
+ const isDeployableWranglerProject = packageJson.private === true && WRANGLER_CONFIG_FILES.some((file) => existsSync(join(absoluteProjectRoot, file)));
441
701
  if (hasLibTsconfig) {
442
702
  const executableOutputs = packageBinOutputs(packageJson, packageJsonPath);
443
703
  // Dependency packages may publish bundled entries that raw tsc does not produce.
@@ -463,7 +723,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
463
723
  targets.typecheck = {
464
724
  executor: 'nx:run-commands',
465
725
  cache: true,
466
- inputs: ['production', '^production', ...TYPESCRIPT_TOOLCHAIN_INPUTS, '{projectRoot}/tsconfig.lib.json'],
726
+ inputs: [selfProduction, dependencyProduction, ...checkInputs, '{projectRoot}/tsconfig.lib.json'],
467
727
  outputs: [],
468
728
  dependsOn: ['^*-js', ...(cargoWasmConfig ? ['cargo-wasm'] : [])],
469
729
  options: {
@@ -477,7 +737,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
477
737
  targets['typecheck-tests'] = {
478
738
  executor: 'nx:run-commands',
479
739
  cache: true,
480
- inputs: ['default', '^production', ...TYPESCRIPT_TOOLCHAIN_INPUTS, '{projectRoot}/tsconfig.test.json'],
740
+ inputs: [selfDefault, dependencyProduction, ...checkInputs, '{projectRoot}/tsconfig.test.json'],
481
741
  dependsOn: ['typecheck'],
482
742
  options: {
483
743
  command: 'tsc -p tsconfig.test.json --noEmit',
@@ -596,6 +856,13 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
596
856
  // `archive.include` lives in the repository's nextest config, so that file
597
857
  // decides what the archive CONTAINS, not merely how a run behaves.
598
858
  targets[CARGO_TEST_ARCHIVE_TARGET].inputs = [...workspaceCargoInputs, `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`];
859
+ // One archive per declared foreign triple, from the same inputs and the
860
+ // same repository nextest config: an archive is the workspace's test
861
+ // binaries whichever machine they are for, so a change that invalidates
862
+ // the host archive must invalidate every cross one.
863
+ for (const crossTarget of listCargoCrossTestTargets(join(workspaceRoot, cargoWorkspaceRoot))) {
864
+ Object.assign(targets, createCargoCrossTestTargets(cargoWorkspaceRoot, nextestToolConfigArg(workspaceRoot, cargoWorkspaceRoot, PLUGIN_NEXTEST_CONFIG), crossTarget, [...workspaceCargoInputs, `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`]));
865
+ }
599
866
  const aggregateDependencies = cargoWorkspace.packages.flatMap((plan) => plan.pieces.map((piece) => cargoTargetDependency(projectName, {
600
867
  projectName: plan.package.projectName,
601
868
  targetName: piece.targetName,
@@ -926,17 +1193,40 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
926
1193
  // dependent has to re-check liveness, not inherit someone else's cache hit.
927
1194
  //
928
1195
  // 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, so a project
930
- // adding a cross-project edge writes `"dependsOn": ["...", "backend:deploy"]` to keep the
931
- // `deploy-build` edge this adds.
1196
+ // declaration naming `cache`, `inputs` or `dependsOn` REPLACES what is set here and inherits
1197
+ // everything it does not name, while Nx's `"..."` token expands to the inferred list at its
1198
+ // position. So a project adding a cross-project edge writes
1199
+ // `"dependsOn": ["...", "backend:deploy"]` and keeps both the edge below and this command —
1200
+ // measured, not assumed, against an inferred base.
1201
+ //
1202
+ // `deploy` is INFERRED for a private wrangler project rather than patched onto a hand-written
1203
+ // one. The command is a constant of the convention, not of the project: every consumer wrote
1204
+ // the same `nx:run-commands` wrapper around it. `private: true` is the second half of the
1205
+ // detection: a PUBLISHED package's wrangler manifest documents a binding for its consumers,
1206
+ // so inferring a deploy from it would put a live `wrangler deploy` of someone's documentation
1207
+ // one `nx run-many -t deploy` away. A published package that really is deployed declares
1208
+ // `deploy` itself. `deploy-build` stays declaration-driven in the other direction, because
1209
+ // only the project knows what building it means — the plugin supplies its POLICY (cache
1210
+ // honestly) and nothing else.
932
1211
  if (DEPLOY_BUILD_TARGET in declaredTargets) {
933
1212
  targets[DEPLOY_BUILD_TARGET] = { cache: true };
934
1213
  }
935
- if (DEPLOY_TARGET in declaredTargets) {
1214
+ if (isDeployableWranglerProject) {
1215
+ // Naming only an edge that exists is tidiness, not a guard: Nx tolerates a `dependsOn` on a
1216
+ // target the project lacks — measured, the task just runs alone — and a wrangler worker can
1217
+ // legitimately have no build at all, since wrangler bundles its own TypeScript. Pointing at a
1218
+ // target that is not there would only make `nx graph` claim a prerequisite nothing satisfies.
1219
+ const fileDerivedHalf = DEPLOY_BUILD_TARGET in declaredTargets
1220
+ ? DEPLOY_BUILD_TARGET
1221
+ : hasOrdinaryBuildOutputTarget || 'build' in declaredTargets
1222
+ ? 'build'
1223
+ : null;
936
1224
  targets[DEPLOY_TARGET] = {
1225
+ executor: 'nx:run-commands',
937
1226
  cache: false,
938
1227
  outputs: [],
939
- ...(DEPLOY_BUILD_TARGET in declaredTargets ? { dependsOn: [DEPLOY_BUILD_TARGET] } : {}),
1228
+ ...(fileDerivedHalf === null ? {} : { dependsOn: [fileDerivedHalf] }),
1229
+ options: { command: WRANGLER_DEPLOY_COMMAND, cwd: projectRoot },
940
1230
  };
941
1231
  }
942
1232
  // No `outputs`, deliberately: this aggregate runs no command, so every file
@@ -1020,8 +1310,8 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1020
1310
  dependsOn: validationTargets,
1021
1311
  outputs: [],
1022
1312
  inputs: [
1023
- 'default',
1024
- ...TYPESCRIPT_TOOLCHAIN_INPUTS,
1313
+ selfDefault,
1314
+ ...checkInputs,
1025
1315
  ...[...BIOME_CONFIG_FILES, ...ESLINT_CONFIG_FILES].flatMap((name) => [
1026
1316
  `{workspaceRoot}/${name}`,
1027
1317
  `{projectRoot}/${name}`,
@@ -1037,7 +1327,26 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
1037
1327
  }
1038
1328
  return {
1039
1329
  projects: {
1040
- [projectRoot]: { name: projectName, targets },
1330
+ [projectRoot]: {
1331
+ name: projectName,
1332
+ targets,
1333
+ // A named input is what `{ input, dependencies: true }` resolves in
1334
+ // each DEPENDENCY's own context, so the dependency half needs one to
1335
+ // exist per project. A `json` path interpolates `{projectRoot}` per
1336
+ // project, but a `runtime` command does NOT — it reaches the shell
1337
+ // literally — so a crate digest can only name its own root from here.
1338
+ // Nx resolves a named input from the project first and nx.json second,
1339
+ // so a workspace-wide definition still covers projects this plugin
1340
+ // never inferred.
1341
+ ...(versionless === null
1342
+ ? {}
1343
+ : {
1344
+ namedInputs: {
1345
+ [VERSIONLESS_PRODUCTION_INPUT]: ['production', ...versionlessProjectInputs],
1346
+ [VERSIONLESS_DEFAULT_INPUT]: ['default', ...versionlessProjectInputs],
1347
+ },
1348
+ }),
1349
+ },
1041
1350
  },
1042
1351
  };
1043
1352
  }
@@ -1329,6 +1638,7 @@ async function readPackageJson(packageJsonPath) {
1329
1638
  ...('bin' in parsed ? { bin: parsed.bin } : {}),
1330
1639
  ...(typeof parsed.name === 'string' ? { name: parsed.name } : {}),
1331
1640
  ...(isRecord(parsed.napi) ? { napi: parsed.napi } : {}),
1641
+ ...(typeof parsed.private === 'boolean' ? { private: parsed.private } : {}),
1332
1642
  ...(isRecord(parsed.scripts) ? { scripts: parsed.scripts } : {}),
1333
1643
  ...(rawNx
1334
1644
  ? {
@@ -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"}