@smoothbricks/nx-plugin 0.6.2 → 0.7.0
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 +417 -171
- package/dist/.build-inputs.json +39 -28
- package/dist/bin/smoo-nx-go-test-build.d.ts +3 -0
- package/dist/bin/smoo-nx-go-test-build.d.ts.map +1 -0
- package/dist/bin/smoo-nx-go-test-build.js +79 -0
- package/dist/bin/smoo-nx-go-test-run.d.ts +3 -0
- package/dist/bin/smoo-nx-go-test-run.d.ts.map +1 -0
- package/dist/bin/smoo-nx-go-test-run.js +129 -0
- package/dist/bin/smoo-nx-publish.d.ts +3 -0
- package/dist/bin/smoo-nx-publish.d.ts.map +1 -0
- package/dist/bin/smoo-nx-publish.js +3 -0
- package/dist/bounded-test-policy.d.ts +1 -1
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +9 -8
- package/dist/cargo-retention-hook.d.ts +6 -2
- package/dist/cargo-retention-hook.d.ts.map +1 -1
- package/dist/cargo-retention-hook.js +13 -7
- package/dist/cargo-workspace.d.ts +10 -20
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +12 -22
- package/dist/cross-check-policy.d.ts +2 -2
- package/dist/cross-check-policy.js +2 -2
- package/dist/deploy-policy.d.ts +6 -0
- package/dist/deploy-policy.d.ts.map +1 -1
- package/dist/deploy-policy.js +11 -0
- package/dist/eslint-file-set.d.ts +4 -1
- package/dist/eslint-file-set.d.ts.map +1 -1
- package/dist/eslint-sources.d.ts +25 -0
- package/dist/eslint-sources.d.ts.map +1 -0
- package/dist/eslint-sources.js +99 -0
- package/dist/executors/all-verdicts/executor.d.ts +2 -1
- package/dist/executors/all-verdicts/executor.d.ts.map +1 -1
- package/dist/executors/all-verdicts/executor.js +48 -2
- package/dist/executors/all-verdicts/schema.d.ts +13 -0
- package/dist/executors/all-verdicts/schema.d.ts.map +1 -1
- package/dist/executors/all-verdicts/schema.js +7 -0
- package/dist/executors/bounded-exec/bounds.d.ts +57 -8
- package/dist/executors/bounded-exec/bounds.d.ts.map +1 -1
- package/dist/executors/bounded-exec/bounds.js +100 -11
- package/dist/executors/bounded-exec/executor.d.ts +2 -1
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +289 -34
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts +2 -0
- package/dist/executors/bounded-exec/hang-diagnostics.d.ts.map +1 -1
- package/dist/executors/bounded-exec/hang-diagnostics.js +2 -2
- package/dist/executors/bounded-exec/mbx-pool.d.ts +56 -10
- package/dist/executors/bounded-exec/mbx-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/mbx-pool.js +145 -11
- package/dist/executors/bounded-exec/mbx-queue.d.ts +30 -0
- package/dist/executors/bounded-exec/mbx-queue.d.ts.map +1 -0
- package/dist/executors/bounded-exec/mbx-queue.js +229 -0
- package/dist/executors/bounded-exec/progress.d.ts +9 -2
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
- package/dist/executors/bounded-exec/progress.js +151 -25
- package/dist/executors/bounded-exec/runner-sizing.d.ts +40 -2
- package/dist/executors/bounded-exec/runner-sizing.d.ts.map +1 -1
- package/dist/executors/bounded-exec/runner-sizing.js +55 -4
- package/dist/executors/bounded-exec/runtime-pin.js +1 -1
- package/dist/executors/bounded-exec/test-result-writer.d.ts +30 -0
- package/dist/executors/bounded-exec/test-result-writer.d.ts.map +1 -0
- package/dist/executors/bounded-exec/test-result-writer.js +126 -0
- package/dist/executors/bounded-exec/test-results.d.ts +33 -0
- package/dist/executors/bounded-exec/test-results.d.ts.map +1 -0
- package/dist/executors/bounded-exec/test-results.js +33 -0
- package/dist/executors/bounded-exec/verdict.d.ts +26 -2
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +108 -4
- package/dist/executors/wrangler-deploy/deploy-hash.d.ts +10 -0
- package/dist/executors/wrangler-deploy/deploy-hash.d.ts.map +1 -0
- package/dist/executors/wrangler-deploy/deploy-hash.js +14 -0
- package/dist/executors/wrangler-deploy/executor.d.ts +24 -0
- package/dist/executors/wrangler-deploy/executor.d.ts.map +1 -0
- package/dist/executors/wrangler-deploy/executor.js +43 -0
- package/dist/executors/wrangler-deploy/hasher.d.ts +27 -0
- package/dist/executors/wrangler-deploy/hasher.d.ts.map +1 -0
- package/dist/executors/wrangler-deploy/hasher.js +90 -0
- package/dist/executors/wrangler-deploy/schema.d.ts +5 -0
- package/dist/executors/wrangler-deploy/schema.d.ts.map +1 -0
- package/dist/go-tests.d.ts +30 -0
- package/dist/go-tests.d.ts.map +1 -0
- package/dist/go-tests.js +43 -0
- package/dist/index.d.ts +12 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +338 -295
- package/dist/managed-files/files.d.ts.map +1 -1
- package/dist/managed-files/files.js +5 -0
- package/dist/nx-publish.d.ts +24 -0
- package/dist/nx-publish.d.ts.map +1 -0
- package/dist/nx-publish.js +150 -0
- package/dist/process-group.js +2 -2
- package/dist/runtime-input-policy.d.ts +17 -3
- package/dist/runtime-input-policy.d.ts.map +1 -1
- package/dist/runtime-input-policy.js +4 -4
- package/dist/test-timings.d.ts +23 -4
- package/dist/test-timings.d.ts.map +1 -1
- package/dist/test-timings.js +72 -12
- package/dist/tool-bins.d.ts +6 -8
- package/dist/tool-bins.d.ts.map +1 -1
- package/dist/tool-bins.js +7 -5
- package/dist/version-actions.cjs +10 -11
- package/dist/version-actions.d.cts.map +1 -1
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +17 -22
- package/dist/workspace-index.d.ts +7 -0
- package/dist/workspace-index.d.ts.map +1 -1
- package/dist/workspace-index.js +11 -0
- package/dist/workspace-manifest.js +3 -3
- package/executors.json +7 -6
- package/managed/raw/patches/nx@23.2.1.patch +118 -24
- package/managed/raw/patches/ttsc@0.34.1.patch +139 -0
- package/managed/raw/tooling/devenv +1 -2
- package/managed/raw/tooling/direnv/developer-links.ts +124 -51
- package/managed/raw/tooling/direnv/devenv.smoo.nix +34 -15
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +20 -10
- package/managed/raw/tooling/direnv/installed-bun-links.ts +7 -6
- package/managed/raw/tooling/direnv/setup-environment.ts +49 -24
- package/managed/raw/tooling/direnv/ttsc-env.sh +8 -6
- package/managed/raw/tooling/git-hooks/pinned-revisions-served.ts +252 -0
- package/managed/raw/tooling/git-hooks/pre-push.sh +34 -32
- package/managed/templates/github/actions/cache-node-modules/action.yml +1 -1
- package/managed/templates/github/actions/cache-ttsc-plugins/action.yml +12 -11
- package/package.json +277 -11
- package/runtime/nx-publish/.build-inputs.json +11 -0
- package/runtime/nx-publish/cache_adapter.js +45 -0
- package/runtime/nx-publish/nx_publish.js +60 -0
- package/runtime-input.sh +62 -26
- package/src/bin/smoo-nx-go-test-build.ts +83 -0
- package/src/bin/smoo-nx-go-test-run.ts +140 -0
- package/src/bin/smoo-nx-publish.ts +4 -0
- package/src/bounded-test-policy.ts +9 -8
- package/src/cargo-retention-hook.ts +16 -10
- package/src/cargo-workspace.ts +12 -24
- package/src/cross-check-policy.ts +2 -2
- package/src/deploy-policy.ts +11 -0
- package/src/eslint-file-set.ts +4 -1
- package/src/eslint-sources.ts +134 -0
- package/src/executors/all-verdicts/executor.ts +58 -3
- package/src/executors/all-verdicts/schema.json +4 -0
- package/src/executors/all-verdicts/schema.ts +14 -0
- package/src/executors/bounded-exec/bounds.ts +132 -15
- package/src/executors/bounded-exec/executor.ts +329 -34
- package/src/executors/bounded-exec/hang-diagnostics.ts +3 -2
- package/src/executors/bounded-exec/mbx-pool.ts +158 -17
- package/src/executors/bounded-exec/mbx-queue.ts +170 -0
- package/src/executors/bounded-exec/progress.ts +171 -18
- package/src/executors/bounded-exec/runner-sizing.ts +73 -7
- package/src/executors/bounded-exec/runtime-pin.ts +1 -1
- package/src/executors/bounded-exec/test-result-writer.ts +152 -0
- package/src/executors/bounded-exec/test-results.ts +39 -0
- package/src/executors/bounded-exec/verdict.ts +115 -5
- package/src/executors/wrangler-deploy/deploy-hash.ts +15 -0
- package/src/executors/wrangler-deploy/executor.ts +63 -0
- package/src/executors/wrangler-deploy/hasher.ts +111 -0
- package/src/executors/wrangler-deploy/schema.json +16 -0
- package/src/executors/wrangler-deploy/schema.ts +4 -0
- package/src/go-tests.ts +67 -0
- package/src/index.ts +368 -323
- package/src/managed-files/files.ts +5 -0
- package/src/nx-publish.ts +157 -0
- package/src/process-group.ts +2 -2
- package/src/runtime-input-policy.ts +4 -4
- package/src/test-timings.ts +72 -14
- package/src/tool-bins.ts +13 -9
- package/src/version-actions.cts +10 -11
- package/src/workspace-config-policy.ts +20 -29
- package/src/workspace-index.ts +12 -0
- package/src/workspace-manifest.ts +3 -3
- package/test-timings.json +131 -125
- package/dist/executors/clean-outputs/executor.d.ts +0 -26
- package/dist/executors/clean-outputs/executor.d.ts.map +0 -1
- package/dist/executors/clean-outputs/executor.js +0 -83
- package/dist/executors/clean-outputs/schema.d.ts +0 -4
- package/dist/executors/clean-outputs/schema.d.ts.map +0 -1
- package/src/executors/clean-outputs/executor.ts +0 -131
- package/src/executors/clean-outputs/schema.json +0 -15
- package/src/executors/clean-outputs/schema.ts +0 -3
- /package/dist/executors/{clean-outputs → wrangler-deploy}/schema.js +0 -0
package/dist/index.js
CHANGED
|
@@ -3,34 +3,33 @@ import { readdir, readFile } from 'node:fs/promises';
|
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
4
|
import { dirname, isAbsolute, join, posix, relative, resolve, sep } from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import {
|
|
6
|
+
import { NEXTEST_BINARIES_BUILD_ARGS, NEXTEST_BINARIES_METADATA, NEXTEST_BUILD_KEY, NEXTEST_CARGO_METADATA, } from '@smoothbricks/nextest-extract';
|
|
7
7
|
import { readJsonFile, } from 'nx/src/devkit-exports.js';
|
|
8
8
|
import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
|
|
9
9
|
import { parse as parseToml } from 'smol-toml';
|
|
10
|
-
import { parseJsonConfigFileContent, readConfigFile, sys as typescriptSys } from 'typescript';
|
|
11
10
|
import { BOUNDED_TEST_IDLE_TIMEOUT_MS, BOUNDED_TEST_KILL_AFTER_MS } from './bounded-test-policy.js';
|
|
12
11
|
import { refuseOverlappingOutputs } from './build-state-output-policy.js';
|
|
13
12
|
import { bunLockDependencies, bunLockInput, bunLockNode } from './bun-lock-scope.js';
|
|
14
13
|
import { CARGO_CLOSURE_INPUT, CARGO_LOCK_NODE_PREFIX, cargoClosureInputs, cargoLockNode, cargoLockNodeName, indexedCargoManifests, isCargoLockInput, resolveCargoClosureSource, } from './cargo-closure-input.js';
|
|
15
14
|
import { CARGO_PRODUCER_METADATA, postTasksExecution as postCargoRetention } from './cargo-retention-hook.js';
|
|
16
15
|
import { CARGO_TOOLCHAIN_NAMED_INPUT, cargoRuntimeInput, cargoToolchainInputs } from './cargo-toolchain-policy.js';
|
|
17
|
-
import { attributeCargoWorkspacePackages,
|
|
16
|
+
import { attributeCargoWorkspacePackages, CARGO_TEST_BUILD_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoTestGroupTargetName, cargoTestPackageTargetName, createCargoInputsCache, EXTERNAL_RUST_CRATES_INPUT, exceptionalTestFilter, listCargoCrossTestTargets, listCargoWorkspacePackages, NEXTEST_REPO_CONFIG_PATH, nextestToolConfigArg, PLUGIN_NEXTEST_CONFIG_PATH, requireExternalRustCratesInput, serialTestGroups, } from './cargo-workspace.js';
|
|
18
17
|
import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_FETCH_COMMAND, CARGO_FETCH_TARGET, CARGO_LINT_CLIPPY_COMMAND, cargoCrossTestArchiveFile, cargoCrossTestArchiveTargetName, cargoCrossTestTargetName, cargoFrozen, runsFrozenCargo, } from './cross-check-policy.js';
|
|
19
18
|
import { eslintConfigClosure } from './eslint-config-closure.js';
|
|
20
|
-
import {
|
|
19
|
+
import { ESLINT_SOURCES_GLOB, eslintSources } from './eslint-sources.js';
|
|
20
|
+
import { ALL_VERDICTS_EXECUTOR, ESLINT_SOURCES_TOKEN, } from './executors/all-verdicts/schema.js';
|
|
21
21
|
import { closeRunCpuPool, serveRunCpuPool } from './executors/bounded-exec/run-cpu-pool.js';
|
|
22
22
|
import { ffiPathProblem } from './executors/scriptc-native/ffi-paths.js';
|
|
23
23
|
import { hashVersionlessCrateManifests } from './manifest-hash.js';
|
|
24
24
|
import { NEXTEST_TIMINGS_PATH, namedTestsFilter, readNextestTimings, timedShardMembers } from './nextest-timings.js';
|
|
25
25
|
import { postTasksExecution as postProducerReceipts, preTasksExecution as preProducerReceipts, } from './producer-receipts.js';
|
|
26
26
|
import { runtimeInput, shellWord } from './runtime-input.js';
|
|
27
|
-
import { isNonSourceDirectory } from './source-directories.js';
|
|
28
27
|
import { inferredTaskKind, refuseBuildTestDependencies } from './task-graph-policy.js';
|
|
29
28
|
import { postTasksExecution as postTaskResults, preTasksExecution as preTaskResults } from './task-results.js';
|
|
30
|
-
import { SHARD_TIMINGS_EXECUTOR, SHARD_TIMINGS_TARGET, timingsShardedSuite } from './test-timings.js';
|
|
29
|
+
import { SHARD_TIMINGS_EXECUTOR, SHARD_TIMINGS_TARGET, timingsShardedSuite, timingsSuiteInputs, } from './test-timings.js';
|
|
31
30
|
import { assertUpstreamBasePrecondition } from './test-walk-policy.js';
|
|
32
31
|
import { nativeToolCommand, nativeToolDependsOn, resolveNativeTools } from './tool-bins.js';
|
|
33
|
-
import { isBuildOutputTargetName, isTestNamespaceTargetName, isTestRunnerTargetName,
|
|
32
|
+
import { isBuildOutputTargetName, isTestNamespaceTargetName, isTestRunnerTargetName, RELEASE_CONFIGURATION, } from './workspace-config-policy.js';
|
|
34
33
|
import { globIndexedFiles } from './workspace-index.js';
|
|
35
34
|
/** Makes a version live and proves it answers; never cached. */
|
|
36
35
|
export const DEPLOY_TARGET = 'deploy';
|
|
@@ -268,20 +267,19 @@ const ESLINT_CONFIG_FILES = [
|
|
|
268
267
|
'eslint.config.mts',
|
|
269
268
|
'eslint.config.cts',
|
|
270
269
|
];
|
|
271
|
-
/** Every JavaScript and TypeScript module kind ESLint is handed. */
|
|
272
|
-
const ESLINT_SOURCES_GLOB = '**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}';
|
|
273
270
|
/**
|
|
274
271
|
* The ESLint sources and config closure of Nx's workspace file index, listed
|
|
275
272
|
* once per graph computation; `null` when no workspace ESLint config enables ESLint.
|
|
276
273
|
*
|
|
277
|
-
* The
|
|
278
|
-
* inputs
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
274
|
+
* The lists the graph records for a project (its lint target's metadata, and
|
|
275
|
+
* the inputs that name its program files) are drawn from the index, not from a
|
|
276
|
+
* walk of the tree. A walk also listed gitignored generated modules a build had
|
|
277
|
+
* left on disk, so every such task's key depended on whether a build had run in
|
|
278
|
+
* that checkout: one workspace's graph listed them and a fresh fork's did not,
|
|
279
|
+
* which alone re-keyed 197 of 510 gate tasks. Drawing them from the index makes
|
|
280
|
+
* the plugin and the hasher agree on one file set. What the lint command runs
|
|
281
|
+
* on is in no graph: the executor reads it when the command runs
|
|
282
|
+
* (eslint-sources.ts).
|
|
285
283
|
*
|
|
286
284
|
* The configs key every lint target with exactly the workspace files they
|
|
287
285
|
* load (eslint-config-closure.ts): a glob over the directory holding a
|
|
@@ -298,66 +296,26 @@ async function eslintWorkspace(workspaceRoot) {
|
|
|
298
296
|
configImports: eslintConfigClosure(workspaceRoot, configs, indexed),
|
|
299
297
|
};
|
|
300
298
|
}
|
|
301
|
-
/**
|
|
302
|
-
* Read a tsconfig with this plugin's own TypeScript. `@nx/js`'s readTsConfig does an
|
|
303
|
-
* undeclared `require('typescript')` resolved from its own location: where that lands on the
|
|
304
|
-
* TypeScript 7 native package (whose entry exports only its version), `sys` is undefined and
|
|
305
|
-
* graph construction dies reading `sys.readFile`. The plugin declares TypeScript 6, whose
|
|
306
|
-
* `sys` this uses, so the resolution is the one this package's manifest promises.
|
|
307
|
-
*/
|
|
308
|
-
function readTestTsConfig(testConfig) {
|
|
309
|
-
const readResult = readConfigFile(testConfig, typescriptSys.readFile);
|
|
310
|
-
return parseJsonConfigFileContent(readResult.config, typescriptSys, dirname(testConfig));
|
|
311
|
-
}
|
|
312
299
|
function projectLintCommands(projectRoot, workspaceRoot, eslint) {
|
|
313
300
|
const commands = [];
|
|
314
301
|
const inputs = [];
|
|
315
302
|
let eslintFileSet = null;
|
|
316
|
-
const absoluteProjectRoot = join(workspaceRoot, projectRoot);
|
|
317
303
|
const quote = (path) => `'${path.replaceAll("'", "'\"'\"'")}'`;
|
|
318
304
|
if (BIOME_CONFIG_FILES.some((name) => existsSync(join(workspaceRoot, name)))) {
|
|
319
305
|
commands.push(`biome check --files-ignore-unknown=true ${quote(projectRoot)}`);
|
|
320
306
|
}
|
|
321
307
|
if (eslint !== null) {
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
const testConfig = join(absoluteProjectRoot, 'tsconfig.test.json');
|
|
331
|
-
if (existsSync(testConfig)) {
|
|
332
|
-
// A test program can live anywhere the declaration selects, not just src.
|
|
333
|
-
// Use the compiler's file set and the existing declaration-chain hasher,
|
|
334
|
-
// so inherited includes and files outside this project keep their keys.
|
|
335
|
-
const program = readTestTsConfig(testConfig);
|
|
336
|
-
const errors = program.errors.filter(({ code }) => code !== 18003);
|
|
337
|
-
if (errors.length > 0) {
|
|
338
|
-
throw new Error(`${testConfig}: ${errors.map(({ code, messageText }) => `TS${code}: ${JSON.stringify(messageText)}`).join('; ')}`);
|
|
339
|
-
}
|
|
340
|
-
inputs.push('{projectRoot}/tsconfig.test.json');
|
|
341
|
-
for (const file of program.fileNames) {
|
|
342
|
-
const path = relative(workspaceRoot, file).split(sep).join('/');
|
|
343
|
-
if (path === '..' || path.startsWith('../') || isAbsolute(path)) {
|
|
344
|
-
throw new Error(`${testConfig}: test source ${file} is outside the workspace and cannot be hashed`);
|
|
345
|
-
}
|
|
346
|
-
// Only a module Nx indexes is linted and keyed. An ignored one is build
|
|
347
|
-
// output that a fresh checkout lacks; a JSON file is not ESLint's.
|
|
348
|
-
if (!eslint.sources.has(path) || path.split('/').some(isNonSourceDirectory))
|
|
349
|
-
continue;
|
|
350
|
-
sourceFiles.add(path);
|
|
351
|
-
inputs.push(`{workspaceRoot}/${path}`);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
if (sourceFiles.size > 0) {
|
|
355
|
-
const files = [...sourceFiles].sort();
|
|
356
|
-
eslintFileSet = { command: `eslint ${files.map(quote).join(' ')}`, files };
|
|
308
|
+
const sources = eslintSources(workspaceRoot, projectRoot, eslint.sources);
|
|
309
|
+
inputs.push(...sources.inputs);
|
|
310
|
+
// The command names no file: a graph the daemon serves past a deletion or an addition would hand ESLint a pattern
|
|
311
|
+
// no file matches, or leave a new file unlinted. The all-verdicts executor resolves the token when it runs, and the
|
|
312
|
+
// list beside the command is the file set this graph resolved, for the inspectors that read it.
|
|
313
|
+
if (sources.files.length > 0) {
|
|
314
|
+
eslintFileSet = { command: `eslint ${ESLINT_SOURCES_TOKEN}`, files: sources.files };
|
|
357
315
|
commands.push(eslintFileSet.command);
|
|
358
316
|
}
|
|
359
317
|
}
|
|
360
|
-
return { commands, inputs
|
|
318
|
+
return { commands, inputs, eslintFileSet };
|
|
361
319
|
}
|
|
362
320
|
/** A host's directory under a package's `dist/bin`, as `@smoothbricks/cowshed`'s launcher names it. */
|
|
363
321
|
const EXECUTABLE_PLATFORM_DIRECTORY = {
|
|
@@ -429,15 +387,30 @@ const CARGO_OUTPUT_INPUTS = CARGO_INPUTS;
|
|
|
429
387
|
/** The lockfiles of crates no resolved Cargo workspace claims, which have no lock-scope node. */
|
|
430
388
|
const UNRESOLVED_CARGO_LOCK_INPUT = '{projectRoot}/**/Cargo.lock';
|
|
431
389
|
/**
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
*
|
|
390
|
+
* The files `cargo-fetch` reads: the manifests and the lock that name the crates, and the Cargo configuration that says
|
|
391
|
+
* where they come from. With the registry's state (cargoFetchedInput) they are its key. Unnamed, Nx plans every file of
|
|
392
|
+
* the project, which for a repository-root project includes its symlinked managed files, and a receipt binds no
|
|
393
|
+
* symlink. That workspace's members belong to other projects, so its globs start at the repository root.
|
|
436
394
|
*/
|
|
437
395
|
function cargoFetchInputs(projectRoot) {
|
|
438
396
|
const base = projectRoot === '.' ? '{workspaceRoot}' : '{projectRoot}';
|
|
439
397
|
return [`${base}/**/Cargo.toml`, `${base}/**/Cargo.lock`, `${base}/**/.cargo/config.toml`, `!${base}/**/target/**`];
|
|
440
398
|
}
|
|
399
|
+
/** The locked fetch of one manifest, relative to the project it runs in. */
|
|
400
|
+
function cargoFetchCommand(manifestPath) {
|
|
401
|
+
return manifestPath === 'Cargo.toml' ? CARGO_FETCH_COMMAND : `${CARGO_FETCH_COMMAND} --manifest-path ${manifestPath}`;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Whether the registry holds every manifest's locked graph, as the runtime input that brings CARGO_HOME into
|
|
405
|
+
* `cargo-fetch`'s key: the download lands outside the workspace, so no output can stand for it. `fetched` when an
|
|
406
|
+
* offline fetch of each manifest succeeds, which asks no network and fails on any crate the registry lacks. A registry
|
|
407
|
+
* that lacks one gives a value of its own run (the shell's pid and the time), which no cached run matches, so the fetch
|
|
408
|
+
* runs; a registry that holds them all keys an unchanged lock to its cached run.
|
|
409
|
+
*/
|
|
410
|
+
function cargoFetchedInput(projectRoot, manifests) {
|
|
411
|
+
const offline = manifests.map((manifest) => `${cargoFetchCommand(manifest)} --offline --quiet`).join(' && ');
|
|
412
|
+
return cargoRuntimeInput(projectRoot, `if { ${offline}; } >/dev/null 2>&1; then echo fetched; else echo "unfetched $$ $(date +%s)"; fi`);
|
|
413
|
+
}
|
|
441
414
|
/** A full cargo-mutants sweep's wall-clock backstop: a sweep takes hours, and a hung one must still end. */
|
|
442
415
|
const MUTATION_TIMEOUT_MS = 6 * 60 * 60 * 1000;
|
|
443
416
|
// The toolchain half of a cargo task's identity lives in its own module
|
|
@@ -448,11 +421,21 @@ const MUTATION_TIMEOUT_MS = 6 * 60 * 60 * 1000;
|
|
|
448
421
|
function fileHashInput(path) {
|
|
449
422
|
return runtimeInput(`bun -e 'console.log(new Bun.CryptoHasher("sha256").update(require("node:fs").readFileSync(process.argv[1])).digest("hex"))' ${shellWord(path)}`);
|
|
450
423
|
}
|
|
424
|
+
/**
|
|
425
|
+
* The bytes of a file that arrives from elsewhere, as a runtime input: their SHA-256, streamed, or `absent`. A task
|
|
426
|
+
* that needs the file fails without it, and Nx caches no failure, so no cached run is keyed on `absent`.
|
|
427
|
+
*/
|
|
428
|
+
export function arrivedFileHashInput(path) {
|
|
429
|
+
const hash = 'const file = Bun.file(process.argv[1]); const hash = new Bun.CryptoHasher("sha256"); ' +
|
|
430
|
+
'if (!(await file.exists())) console.log("absent"); ' +
|
|
431
|
+
'else { for await (const chunk of file.stream()) hash.update(chunk); console.log(hash.digest("hex")); }';
|
|
432
|
+
return runtimeInput(`bun -e ${shellWord(hash)} ${shellWord(path)}`);
|
|
433
|
+
}
|
|
451
434
|
/**
|
|
452
435
|
* One shell command that runs `steps` in order and stops at the first failure.
|
|
453
436
|
*
|
|
454
|
-
* For a step that CONSUMES what an earlier step produces — the
|
|
455
|
-
* its directory, `wasm-bindgen` reads the `.wasm` that `cargo build` writes.
|
|
437
|
+
* For a step that CONSUMES what an earlier step produces — the test build's
|
|
438
|
+
* metadata needs its directory, `wasm-bindgen` reads the `.wasm` that `cargo build` writes.
|
|
456
439
|
* The order lives in the command because that is the only place a
|
|
457
440
|
* producer-consumer pair inside one task can state it: `nx:run-commands`'
|
|
458
441
|
* `commands` array is a set of independent commands that Nx runs side by side.
|
|
@@ -596,69 +579,98 @@ function createCargoWasmTarget(projectRoot, config, repoRooted, cargoTargetDirec
|
|
|
596
579
|
};
|
|
597
580
|
}
|
|
598
581
|
/**
|
|
599
|
-
* The workspace's test binaries, compiled once and
|
|
600
|
-
* per-crate runners execute from.
|
|
582
|
+
* The workspace's test binaries, compiled once and run where they were built.
|
|
601
583
|
*
|
|
602
584
|
* This is the only cargo BUILD in the test graph. Before it, every per-crate
|
|
603
585
|
* target ran `nextest run --workspace -E 'package(X)'`, which is a workspace
|
|
604
586
|
* build with a filter: 32 such tasks on one repository each re-entered cargo,
|
|
605
587
|
* re-resolved features and chained behind one another so the flocked `target/`
|
|
606
|
-
* had a single writer.
|
|
607
|
-
* entirely — the runners execute
|
|
608
|
-
*
|
|
588
|
+
* had a single writer. Running from a reused build removes the build from the
|
|
589
|
+
* run entirely — the runners execute the binaries this build left in Cargo's
|
|
590
|
+
* target directory and never write its build tree — which is what lets the
|
|
591
|
+
* runners fan out.
|
|
609
592
|
*
|
|
610
593
|
* It is also the step that keeps compilation out of the bounded test window: a
|
|
611
594
|
* cold workspace can take many minutes to compile while still making progress,
|
|
612
595
|
* which is not a property of the tests, and the runners start after it. It is
|
|
613
596
|
* test work, so no `build` depends on it (a build never consumes test binaries)
|
|
614
|
-
* and each target that executes them names the edge itself.
|
|
615
|
-
* uncached `cargo test --no-run` warm-up: it compiled the same dev units a
|
|
616
|
-
* second time, queued on the same `target/` lock.
|
|
597
|
+
* and each target that executes them names the edge itself.
|
|
617
598
|
*
|
|
618
|
-
* Cached because it produces
|
|
619
|
-
*
|
|
620
|
-
*
|
|
599
|
+
* Cached because it produces VALUES: nextest's reuse-build metadata, the
|
|
600
|
+
* binaries `cargo nextest list --list-type binaries-only` built (an mbx-cached
|
|
601
|
+
* build) and the `cargo metadata` of the workspace they belong to, which is
|
|
602
|
+
* what `nextest run --binaries-metadata … --cargo-metadata …` reads. The
|
|
603
|
+
* binaries themselves stay in Cargo's target directory, where every build of
|
|
604
|
+
* the workspace keeps its warmth: never in an Nx output, which would restore a
|
|
605
|
+
* multi-GB tree per hit, and never in an archive, which a same-platform run
|
|
606
|
+
* would only unpack again (measured: 290 binaries, 678 MB, 4.6s quiet and 21s
|
|
607
|
+
* in a gate, per archive). A binary's path is cargo's `-C metadata` hash, which
|
|
608
|
+
* ignores source content, so the metadata says which binaries, never which
|
|
609
|
+
* bytes: the build's task hash is its third output, the key, and its last step
|
|
610
|
+
* records that key in the target directory it built. A checkout whose build was
|
|
611
|
+
* a cache hit holds another key, or none, and possibly binaries of an older
|
|
612
|
+
* tree at the very paths the metadata names; each runner's fixture rebuilds
|
|
613
|
+
* there first ({@link nextestRunnerFixture}). The key is also what makes a
|
|
614
|
+
* dependent that hashes this target's outputs see a source change the metadata
|
|
615
|
+
* alone would hide. Only a cross lane, whose binaries are built on one platform
|
|
616
|
+
* and run on another, moves them as an archive
|
|
617
|
+
* ({@link createCargoCrossTestTargets}). `--workspace` matches the clippy
|
|
618
|
+
* selection exactly, so both gates unify features the same way.
|
|
621
619
|
*
|
|
622
620
|
* Tests compile the dev profile only, so no test target carries a
|
|
623
621
|
* RELEASE_CONFIGURATION: Nx forwards a run's configuration down every
|
|
624
622
|
* `dependsOn` edge to each target that has it, and a release configuration
|
|
625
623
|
* must never turn the test binaries into release ones nobody runs.
|
|
626
624
|
*
|
|
627
|
-
* The directory and the
|
|
628
|
-
*
|
|
629
|
-
*
|
|
630
|
-
*
|
|
631
|
-
* an output, so a cache hit restores the key with the archive it names.
|
|
625
|
+
* The directory and the metadata are ONE command: a shell redirect does not
|
|
626
|
+
* create its parent, so the build consumes what the `mkdir` produced. Outside
|
|
627
|
+
* Nx there is no task hash, and a build no task names is refused here rather
|
|
628
|
+
* than by every runner.
|
|
632
629
|
*/
|
|
633
|
-
|
|
634
|
-
|
|
630
|
+
function createCargoTestBuildTarget(projectRoot, toolConfig, nativeTools) {
|
|
631
|
+
const helper = nativeToolCommand(nativeTools, projectRoot, 'nextest-extract', 'smoo-nx-nextest-binaries');
|
|
635
632
|
return {
|
|
636
633
|
executor: 'nx:run-commands',
|
|
637
634
|
metadata: CARGO_PRODUCER_METADATA,
|
|
638
635
|
cache: true,
|
|
639
636
|
inputs: CARGO_INPUTS,
|
|
640
|
-
outputs: [
|
|
637
|
+
outputs: [
|
|
638
|
+
`{projectRoot}/${NEXTEST_BINARIES_METADATA}`,
|
|
639
|
+
`{projectRoot}/${NEXTEST_CARGO_METADATA}`,
|
|
640
|
+
`{projectRoot}/${NEXTEST_BUILD_KEY}`,
|
|
641
|
+
],
|
|
642
|
+
dependsOn: nativeToolDependsOn(nativeTools, 'nextest-extract'),
|
|
641
643
|
options: {
|
|
642
644
|
command: sequence([
|
|
643
|
-
`mkdir -p ${posix.dirname(
|
|
644
|
-
|
|
645
|
-
|
|
645
|
+
`mkdir -p ${posix.dirname(NEXTEST_BINARIES_METADATA)}`,
|
|
646
|
+
`${nextestBinariesBuild(toolConfig)} > ${NEXTEST_BINARIES_METADATA}`,
|
|
647
|
+
`${cargoFrozen('metadata --format-version 1 --all-features')} > ${NEXTEST_CARGO_METADATA}`,
|
|
646
648
|
'test -n "$NX_TASK_HASH"',
|
|
647
|
-
`printf '%s\\n' "$NX_TASK_HASH" > ${
|
|
649
|
+
`printf '%s\\n' "$NX_TASK_HASH" > ${NEXTEST_BUILD_KEY}`,
|
|
650
|
+
`${helper} record ${NEXTEST_BUILD_KEY}`,
|
|
648
651
|
]),
|
|
649
652
|
cwd: projectRoot,
|
|
650
653
|
},
|
|
651
654
|
};
|
|
652
655
|
}
|
|
656
|
+
/**
|
|
657
|
+
* The build of the workspace's test binaries, printing nextest's binaries metadata: the command of
|
|
658
|
+
* `cargo-test-build` and of every runner's fixture, so the binaries a fixture materializes are the
|
|
659
|
+
* ones the metadata names.
|
|
660
|
+
*/
|
|
661
|
+
function nextestBinariesBuild(toolConfig) {
|
|
662
|
+
return cargoFrozen(`${NEXTEST_BINARIES_BUILD_ARGS.join(' ')} ${toolConfig}`);
|
|
663
|
+
}
|
|
653
664
|
/**
|
|
654
665
|
* One foreign triple's test archive, and the target that EXECUTES it.
|
|
655
666
|
*
|
|
656
|
-
*
|
|
657
|
-
*
|
|
658
|
-
*
|
|
659
|
-
*
|
|
660
|
-
*
|
|
661
|
-
*
|
|
667
|
+
* The one place a test archive exists: binaries built on one platform and run
|
|
668
|
+
* on another travel as a file, while a same-platform run executes
|
|
669
|
+
* `cargo-test-build`'s binaries where they were built. Same tool config
|
|
670
|
+
* layering and `--workspace-remap .` on the run as the in-place runners;
|
|
671
|
+
* `--target <triple>` and an archive file per triple, because those archives
|
|
672
|
+
* coexist as declared Nx outputs and one path for two triples would let a
|
|
673
|
+
* restored cache serve the wrong machine's binaries.
|
|
662
674
|
*
|
|
663
675
|
* `cargo-nextest` where every other cargo target spells `cargo --frozen`, and
|
|
664
676
|
* that is measured, not stylistic: cargo overwrites `CARGO` with its own path
|
|
@@ -672,13 +684,14 @@ function createCargoTestArchiveTarget(projectRoot, toolConfig) {
|
|
|
672
684
|
* inputs itself: both are otherwise attached by matching the
|
|
673
685
|
* `cargo --frozen` prefix in a command, and this command does not carry it.
|
|
674
686
|
*
|
|
675
|
-
* The RUNNER declares no dependency on the archive
|
|
676
|
-
*
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
*
|
|
680
|
-
*
|
|
681
|
-
*
|
|
687
|
+
* The RUNNER declares no dependency on the archive. That is the whole point of
|
|
688
|
+
* splitting the pair: it runs on a machine where the triple is native and the
|
|
689
|
+
* archive arrived as a file, so a dependency edge would ask that machine to
|
|
690
|
+
* cross-build what it was sent. It is cached on the archive's own bytes, the
|
|
691
|
+
* binaries it runs, never on the sources: a key of sources would vouch for
|
|
692
|
+
* binaries this machine did not build. It is also the one cargo target that
|
|
693
|
+
* needs no cargo: `nextest run --archive-file` extracts prebuilt binaries and
|
|
694
|
+
* never invokes cargo (measured, zero invocations).
|
|
682
695
|
*/
|
|
683
696
|
function createCargoCrossTestTargets(projectRoot, toolConfig, crossTarget, archiveInputs, pluginInstalled) {
|
|
684
697
|
const { target: triple, cargo } = crossTarget;
|
|
@@ -689,6 +702,9 @@ function createCargoCrossTestTargets(projectRoot, toolConfig, crossTarget, archi
|
|
|
689
702
|
`--archive-file ${archiveFile} --user-config-file none ${toolConfig}`,
|
|
690
703
|
]);
|
|
691
704
|
const archiveExecutor = 'nx:run-commands';
|
|
705
|
+
const runExecutor = '@smoothbricks/nx-plugin:bounded-exec';
|
|
706
|
+
const runCommand = `cargo-nextest nextest run --archive-file ${archiveFile} --workspace-remap . ` +
|
|
707
|
+
`--no-tests=pass --user-config-file none ${toolConfig}`;
|
|
692
708
|
return {
|
|
693
709
|
[cargoCrossTestArchiveTargetName(triple)]: {
|
|
694
710
|
executor: archiveExecutor,
|
|
@@ -731,14 +747,22 @@ function createCargoCrossTestTargets(projectRoot, toolConfig, crossTarget, archi
|
|
|
731
747
|
},
|
|
732
748
|
},
|
|
733
749
|
[cargoCrossTestTargetName(triple)]: {
|
|
734
|
-
executor:
|
|
735
|
-
cache:
|
|
736
|
-
|
|
750
|
+
executor: runExecutor,
|
|
751
|
+
cache: true,
|
|
752
|
+
// The archive's toolchain, npm and lock keys, as `cargo-test-build`'s: they decided the bytes it runs.
|
|
753
|
+
inputs: [
|
|
754
|
+
arrivedFileHashInput(posix.join(projectRoot, archiveFile)),
|
|
755
|
+
`{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`,
|
|
756
|
+
fileHashInput(PLUGIN_NEXTEST_CONFIG_PATH),
|
|
757
|
+
...cargoToolchainInputs(),
|
|
758
|
+
cargoRuntimeInput(projectRoot, 'cargo-nextest nextest --version'),
|
|
759
|
+
{ externalDependencies: cargoCommandNpmPackages({ executor: runExecutor }, runCommand, pluginInstalled) },
|
|
760
|
+
{ externalDependencies: [cargoLockNodeName(projectRoot)] },
|
|
761
|
+
],
|
|
737
762
|
outputs: [],
|
|
738
763
|
dependsOn: [],
|
|
739
764
|
options: {
|
|
740
|
-
command:
|
|
741
|
-
`--no-tests=pass --user-config-file none ${toolConfig}`,
|
|
765
|
+
command: runCommand,
|
|
742
766
|
cwd: projectRoot,
|
|
743
767
|
idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
|
|
744
768
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
@@ -752,7 +776,7 @@ function createCargoTestTarget(projectRoot) {
|
|
|
752
776
|
metadata: CARGO_PRODUCER_METADATA,
|
|
753
777
|
cache: true,
|
|
754
778
|
inputs: CARGO_INPUTS,
|
|
755
|
-
dependsOn: [
|
|
779
|
+
dependsOn: [CARGO_TEST_BUILD_TARGET],
|
|
756
780
|
options: {
|
|
757
781
|
command: cargoFrozen('test --workspace'),
|
|
758
782
|
cwd: projectRoot,
|
|
@@ -812,8 +836,8 @@ export function pluginInstalledIn(workspaceRoot, loadedFromNodeModules = PLUGIN_
|
|
|
812
836
|
/**
|
|
813
837
|
* The npm packages a cached cargo target runs, for its `externalDependencies`.
|
|
814
838
|
* Cargo runs none. A target this plugin's executor runs, or whose command reads
|
|
815
|
-
* the installed plugin's files (the nextest tool config, the
|
|
816
|
-
*
|
|
839
|
+
* the installed plugin's files (the nextest tool config, the test-binaries
|
|
840
|
+
* helper), runs the plugin. Without the input Nx keys every task whose
|
|
817
841
|
* executor is not an `@nx/` one on every package in the lockfile, so a
|
|
818
842
|
* lockfile-only commit re-ran every cargo verdict.
|
|
819
843
|
*/
|
|
@@ -930,8 +954,9 @@ function isBuildOutputPackageJson(packageJsonPath) {
|
|
|
930
954
|
* hint and the opt-in producer completion receipts. Each sees the same options and run context; neither reads the
|
|
931
955
|
* other's output. The hint is recorded first so a producer-receipt bug cannot cost the controller its evidence. The
|
|
932
956
|
* pair also serves a run that inherits no CPU pool its own, which every task inherits (`run-cpu-pool.ts`), and closes
|
|
933
|
-
* it when the run ends. Last, once every task has finished, the post hook
|
|
934
|
-
* superseded Cargo unit generations of each Cargo workspace the run built into
|
|
957
|
+
* it when the run ends. Last, once every task has finished, the post hook starts the reclaim of the
|
|
958
|
+
* superseded Cargo unit generations of each Cargo workspace the run built into, in a process of its own, never on
|
|
959
|
+
* Nx's thread (`@smoothbricks/cargo-retain`).
|
|
935
960
|
*/
|
|
936
961
|
export const preTasksExecution = async (options, context) => {
|
|
937
962
|
// Before any task is hashed: a workspace that declares the test-walk check
|
|
@@ -1181,7 +1206,7 @@ function scriptcPlatformTargets(packageJson, packageJsonPath, projectRoot, libTs
|
|
|
1181
1206
|
*/
|
|
1182
1207
|
const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml'];
|
|
1183
1208
|
/**
|
|
1184
|
-
* ONE target that deploys whichever stage it is handed, never a configuration
|
|
1209
|
+
* ONE target that deploys whichever stage it is handed (`--stage`), never a configuration
|
|
1185
1210
|
* per stage. Pull-request stages are `prN` for unbounded N, so an enumerated
|
|
1186
1211
|
* `configurations` map cannot describe the surface that actually exists, and a
|
|
1187
1212
|
* project carrying both spellings would have two ways to say one thing.
|
|
@@ -1190,15 +1215,17 @@ const WRANGLER_CONFIG_FILES = ['wrangler.jsonc', 'wrangler.json', 'wrangler.toml
|
|
|
1190
1215
|
* statement that CI deploys this project on every stage, and only the repository
|
|
1191
1216
|
* can make it. A plugin that tagged what it inferred would enrol every private
|
|
1192
1217
|
* wrangler project in CI deploys by writing the policy it is supposed to read.
|
|
1193
|
-
*
|
|
1194
|
-
* `{args.stage}` rather than `forwardAllArgs`: run-commands'
|
|
1195
|
-
* `interpolateArgsIntoCommand` returns as soon as it sees `{args.` and never
|
|
1196
|
-
* appends forwarded arguments, so `nx run web:deploy --stage=pr42` yields
|
|
1197
|
-
* exactly one `--stage`, for an arbitrary preview stage no map could enumerate.
|
|
1198
|
-
* An omitted stage interpolates to empty and `deploy-stage`'s required
|
|
1199
|
-
* `--stage` refuses it, which is the failure we want at the boundary.
|
|
1200
1218
|
*/
|
|
1201
|
-
const
|
|
1219
|
+
const WRANGLER_DEPLOY_EXECUTOR = '@smoothbricks/nx-plugin:wrangler-deploy';
|
|
1220
|
+
/**
|
|
1221
|
+
* What a deploy uploads: the project's files and its build half's output. Nx keys the
|
|
1222
|
+
* `--stage` override with them, so the hash is the artifact and the stage.
|
|
1223
|
+
*/
|
|
1224
|
+
const WRANGLER_DEPLOY_INPUTS = [
|
|
1225
|
+
'default',
|
|
1226
|
+
'^default',
|
|
1227
|
+
{ dependentTasksOutputFiles: '**/*', transitive: false },
|
|
1228
|
+
];
|
|
1202
1229
|
async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform, nativeTools, cargoWorkspaces, eslint, versionless) {
|
|
1203
1230
|
const projectRoot = dirname(packageJsonPath);
|
|
1204
1231
|
const absoluteProjectRoot = join(workspaceRoot, projectRoot);
|
|
@@ -1259,9 +1286,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1259
1286
|
const declaredTargets = packageJson.nx?.targets ?? {};
|
|
1260
1287
|
const cargoWasmConfig = await resolveCargoWasmConfig(absoluteProjectRoot, packageJsonPath, workspaceRoot, repoRootPackages);
|
|
1261
1288
|
const inferCargoWasm = cargoWasmConfig !== null && !('cargo-wasm' in declaredTargets);
|
|
1262
|
-
const
|
|
1263
|
-
const hasOrdinaryBuildOutputTarget = hasLibTsconfig || napiConfig !== null || cargoWasmConfig !== null || packageLocalBuildOutputs.ordinary;
|
|
1264
|
-
const hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
|
|
1289
|
+
const hasOrdinaryBuildOutputTarget = hasLibTsconfig || napiConfig !== null || cargoWasmConfig !== null || declaresPackageLocalBuildOutput(packageJson);
|
|
1265
1290
|
const isDeployableWranglerProject = packageJson.private === true && WRANGLER_CONFIG_FILES.some((file) => existsSync(join(absoluteProjectRoot, file)));
|
|
1266
1291
|
if (hasLibTsconfig) {
|
|
1267
1292
|
const executableOutputs = packageBinOutputs(packageJson, packageJsonPath);
|
|
@@ -1386,9 +1411,9 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1386
1411
|
// result — duplicating the very edges the spread exists to add.
|
|
1387
1412
|
//
|
|
1388
1413
|
// `dependsOn` REPLACES rather than unions. These lists state what each target
|
|
1389
|
-
// consumes — the fetched registry, the
|
|
1414
|
+
// consumes — the fetched registry, the test build, the debug addon — and a
|
|
1390
1415
|
// package that must re-route one (build its artifact ahead of the test run,
|
|
1391
|
-
// or drop `cargo-test-
|
|
1416
|
+
// or drop `cargo-test-build` because it compiles differently) can only say
|
|
1392
1417
|
// so by replacing the list; a union would make every inferred edge
|
|
1393
1418
|
// unremovable and a corrected order unrepresentable.
|
|
1394
1419
|
// Additive intent already has a spelling (`"..."` above), so a plugin-local
|
|
@@ -1417,29 +1442,30 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1417
1442
|
// as the outputs of the targets a repository adds to `dependsOn`. Hashing
|
|
1418
1443
|
// those outputs here means a repository never has to restate `inputs` to
|
|
1419
1444
|
// add them - and a restated `inputs` REPLACES this union with the root
|
|
1420
|
-
// project's `default`, which owns no crate file, so the
|
|
1445
|
+
// project's `default`, which owns no crate file, so the test build then
|
|
1421
1446
|
// cache-hits against edited crates while every per-crate test reruns on
|
|
1422
1447
|
// the stale binary. That verdict is wrong, not merely slow.
|
|
1423
1448
|
const workspaceCargoInputs = [
|
|
1424
1449
|
...(workspaceInputs.length > 0 ? workspaceInputs : CARGO_INPUTS),
|
|
1425
1450
|
{ dependentTasksOutputFiles: '**/*', transitive: false },
|
|
1426
1451
|
];
|
|
1427
|
-
targets[
|
|
1428
|
-
// `
|
|
1429
|
-
//
|
|
1430
|
-
targets[
|
|
1452
|
+
targets[CARGO_TEST_BUILD_TARGET] = createCargoTestBuildTarget(cargoWorkspaceRoot, nextestToolConfigArg(cargoWorkspaceRoot), nativeTools);
|
|
1453
|
+
// The build's `cargo nextest list` loads the repository's nextest config and
|
|
1454
|
+
// refuses an invalid one, so that file keys the build as well as every run.
|
|
1455
|
+
targets[CARGO_TEST_BUILD_TARGET].inputs = [...workspaceCargoInputs, `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`];
|
|
1431
1456
|
// One archive per declared foreign triple, from the same inputs and the
|
|
1432
|
-
// same repository nextest config
|
|
1433
|
-
//
|
|
1434
|
-
// the host
|
|
1457
|
+
// same repository nextest config, whose `archive.include` decides what an
|
|
1458
|
+
// archive CONTAINS: it is the workspace's test binaries for another
|
|
1459
|
+
// machine, so a change that invalidates the host build must invalidate
|
|
1460
|
+
// every cross archive.
|
|
1435
1461
|
for (const crossTarget of listCargoCrossTestTargets(join(workspaceRoot, cargoWorkspaceRoot))) {
|
|
1436
1462
|
Object.assign(targets, createCargoCrossTestTargets(cargoWorkspaceRoot, nextestToolConfigArg(cargoWorkspaceRoot), crossTarget, [...workspaceCargoInputs, `{projectRoot}/${NEXTEST_REPO_CONFIG_PATH}`], pluginInstalledIn(workspaceRoot)));
|
|
1437
1463
|
}
|
|
1438
1464
|
// A serial group's filter can span members, so no single crate owns it. The root
|
|
1439
|
-
// owns each group's runner beside the
|
|
1465
|
+
// owns each group's runner beside the test build it executes, and gives it the inputs
|
|
1440
1466
|
// of exactly the members its filter can select from (`filterScope`): a group scoped
|
|
1441
1467
|
// to its packages reruns only when their sources or local dependencies change,
|
|
1442
|
-
// and an unscoped one hashes every member, as the
|
|
1468
|
+
// and an unscoped one hashes every member, as the test build itself does.
|
|
1443
1469
|
for (const group of cargoWorkspace.serialGroups) {
|
|
1444
1470
|
targets[cargoTestGroupTargetName(group.group)] = cargoTestGroupTarget(cargoWorkspace, nativeTools, await cargoTestRunnerInputs(workspaceRoot, cargoWorkspace, serialGroupMemberDirs(cargoWorkspace, group)), group);
|
|
1445
1471
|
}
|
|
@@ -1457,11 +1483,11 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1457
1483
|
// of its closure; a target dir per crate compiled every shared dependency
|
|
1458
1484
|
// once per crate (49 closures, 11 GiB on one repository) and no per-crate
|
|
1459
1485
|
// cache hit ever repaid that. The workspace inputs are exactly the union of
|
|
1460
|
-
// every crate's, so the verdict caches on the same key set the
|
|
1486
|
+
// every crate's, so the verdict caches on the same key set the test build
|
|
1461
1487
|
// does. Non-root packages depend on this target. Its target dir is its own
|
|
1462
1488
|
// (CARGO_LINT_CLIPPY_COMMAND, ./cross-check-policy.ts): Cargo flocks one
|
|
1463
1489
|
// directory per invocation, and a workspace clippy holding the dev build's
|
|
1464
|
-
// `target/` queued the
|
|
1490
|
+
// `target/` queued the test build and every dev build behind it.
|
|
1465
1491
|
targets['cargo-lint'] = {
|
|
1466
1492
|
executor: 'nx:run-commands',
|
|
1467
1493
|
metadata: CARGO_PRODUCER_METADATA,
|
|
@@ -1512,7 +1538,8 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1512
1538
|
cwd: cargoWorkspaceRoot,
|
|
1513
1539
|
},
|
|
1514
1540
|
};
|
|
1515
|
-
// Mutation runs are minutes-to-hours
|
|
1541
|
+
// Mutation runs are minutes-to-hours and never part of build/lint. Cached on the code and toolchain they mutate
|
|
1542
|
+
// and on cargo-mutants' configuration, with the report as the output: an unchanged tree mutates nothing new.
|
|
1516
1543
|
// CI runs these per-PR via `cargo mutants --in-diff` (see mutants.toml docs).
|
|
1517
1544
|
// bounded-exec sizes cargo-mutants' own jobserver to its CPU grant (its `cargo-mutants` runner kind), which
|
|
1518
1545
|
// otherwise starts one task per core whatever else runs on the host. It reports no test bounded-exec can read as
|
|
@@ -1520,29 +1547,19 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1520
1547
|
targets.mutation = {
|
|
1521
1548
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
1522
1549
|
metadata: CARGO_PRODUCER_METADATA,
|
|
1523
|
-
cache:
|
|
1550
|
+
cache: true,
|
|
1551
|
+
inputs: [...workspaceCargoInputs, '{projectRoot}/**/.cargo/mutants.toml'],
|
|
1552
|
+
outputs: [`{workspaceRoot}/${posix.join(cargoWorkspaceRoot, 'mutants.out')}`],
|
|
1524
1553
|
options: { command: cargoFrozen('mutants --workspace'), cwd: cargoWorkspaceRoot, timeoutMs: MUTATION_TIMEOUT_MS },
|
|
1525
1554
|
};
|
|
1555
|
+
// Cached on the code and toolchain it measures: a rerun with unchanged inputs measures nothing new.
|
|
1526
1556
|
targets.bench = {
|
|
1527
1557
|
executor: 'nx:run-commands',
|
|
1528
1558
|
metadata: CARGO_PRODUCER_METADATA,
|
|
1529
|
-
cache:
|
|
1559
|
+
cache: true,
|
|
1560
|
+
inputs: workspaceCargoInputs,
|
|
1530
1561
|
options: { command: cargoFrozen('bench --workspace'), cwd: cargoWorkspaceRoot },
|
|
1531
1562
|
};
|
|
1532
|
-
// A read-only preview of the retention pass the plugin's postTasksExecution
|
|
1533
|
-
// schedules after runs that built (@smoothbricks/cargo-retain): the superseded unit
|
|
1534
|
-
// generations it would reclaim and why everything else stays. Never cached:
|
|
1535
|
-
// the verdict is about this machine's disk, not the commit.
|
|
1536
|
-
const retainTool = nativeToolDependsOn(nativeTools, 'cargo-retain');
|
|
1537
|
-
targets['cargo-retention'] = {
|
|
1538
|
-
executor: 'nx:run-commands',
|
|
1539
|
-
cache: false,
|
|
1540
|
-
...(retainTool.length > 0 ? { dependsOn: retainTool } : {}),
|
|
1541
|
-
options: {
|
|
1542
|
-
command: nativeToolCommand(nativeTools, cargoWorkspaceRoot, 'cargo-retain', 'smoo-nx-cargo-retain'),
|
|
1543
|
-
cwd: cargoWorkspaceRoot,
|
|
1544
|
-
},
|
|
1545
|
-
};
|
|
1546
1563
|
}
|
|
1547
1564
|
if (cargoWorkspace) {
|
|
1548
1565
|
const packageTargetNames = await addCargoTestTargets(targets, projectName, projectRoot, workspaceRoot, cargoWorkspace, nativeTools);
|
|
@@ -1627,19 +1644,16 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1627
1644
|
if (frozenCargoManifests.size > 0) {
|
|
1628
1645
|
targets[CARGO_FETCH_TARGET] = {
|
|
1629
1646
|
executor: 'nx:run-commands',
|
|
1630
|
-
// The download lands in CARGO_HOME, outside the workspace
|
|
1631
|
-
//
|
|
1632
|
-
//
|
|
1633
|
-
cache:
|
|
1634
|
-
inputs: cargoFetchInputs(projectRoot),
|
|
1647
|
+
// The download lands in CARGO_HOME, outside the workspace, so nothing is
|
|
1648
|
+
// a workspace output; the registry's state reaches the key instead
|
|
1649
|
+
// (cargoFetchedInput), and a hit never stands for a crate it lacks.
|
|
1650
|
+
cache: true,
|
|
1651
|
+
inputs: [...cargoFetchInputs(projectRoot), cargoFetchedInput(projectRoot, [...frozenCargoManifests].sort())],
|
|
1652
|
+
outputs: [],
|
|
1635
1653
|
options: {
|
|
1636
1654
|
// One fetch per manifest, independent of the others: Cargo's own
|
|
1637
1655
|
// package-cache lock arbitrates the CARGO_HOME they share.
|
|
1638
|
-
commands: [...frozenCargoManifests]
|
|
1639
|
-
.sort()
|
|
1640
|
-
.map((manifestPath) => manifestPath === 'Cargo.toml'
|
|
1641
|
-
? CARGO_FETCH_COMMAND
|
|
1642
|
-
: `${CARGO_FETCH_COMMAND} --manifest-path ${manifestPath}`),
|
|
1656
|
+
commands: [...frozenCargoManifests].sort().map(cargoFetchCommand),
|
|
1643
1657
|
cwd: projectRoot,
|
|
1644
1658
|
},
|
|
1645
1659
|
};
|
|
@@ -1672,7 +1686,8 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1672
1686
|
// lock-scope node of the directory it runs in) unless its inputs already do.
|
|
1673
1687
|
for (const [name, target] of Object.entries(targets)) {
|
|
1674
1688
|
const text = targetCommandText(target);
|
|
1675
|
-
|
|
1689
|
+
// `cargo-fetch` runs cargo unfrozen, as the one task that may reach the network, and is keyed like the rest.
|
|
1690
|
+
if (!runsFrozenCargo(text) && name !== CARGO_FETCH_TARGET)
|
|
1676
1691
|
continue;
|
|
1677
1692
|
target.outputs ??= [];
|
|
1678
1693
|
if (!target.cache)
|
|
@@ -1682,7 +1697,9 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1682
1697
|
? ` && cargo clippy -V${name === CARGO_CROSS_LINT_TARGET ? '' : ' && cargo fmt --version'}`
|
|
1683
1698
|
: text.includes('nextest ')
|
|
1684
1699
|
? ' && cargo nextest --version'
|
|
1685
|
-
: ''
|
|
1700
|
+
: text.includes('mutants ')
|
|
1701
|
+
? ' && cargo mutants --version'
|
|
1702
|
+
: '';
|
|
1686
1703
|
const inputs = target.inputs ?? CARGO_INPUTS;
|
|
1687
1704
|
const namesPackages = inputs.some((input) => typeof input === 'object' && 'externalDependencies' in input && !isCargoLockInput(input));
|
|
1688
1705
|
const namesLock = inputs.some((input) => input === CARGO_CLOSURE_INPUT || isCargoLockInput(input));
|
|
@@ -1706,7 +1723,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1706
1723
|
if (napiDebug && cargoWorkspace) {
|
|
1707
1724
|
// A crate whose project also builds the debug cdylib runs its tests after
|
|
1708
1725
|
// that build: the tests dlopen what `napi-debug` writes into `target/debug`,
|
|
1709
|
-
// and
|
|
1726
|
+
// and a test binary run in place loads it from this tree.
|
|
1710
1727
|
const runners = [
|
|
1711
1728
|
...cargoPackagePlans.flatMap((plan) => plan.pieces.map((piece) => piece.targetName)),
|
|
1712
1729
|
// The root owns the serial groups' runners, so they take its build as its pieces do.
|
|
@@ -1760,37 +1777,39 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1760
1777
|
};
|
|
1761
1778
|
}
|
|
1762
1779
|
}
|
|
1763
|
-
// A deploy is
|
|
1780
|
+
// A deploy is cached only while its stage serves what it would deploy; the build half beside it
|
|
1781
|
+
// always is.
|
|
1764
1782
|
//
|
|
1765
1783
|
// Nx's cache answers "did this exact input set already produce an output". A deploy's real
|
|
1766
|
-
// question is "is this exact version live", and the two agree only until someone rolls back
|
|
1767
|
-
//
|
|
1768
|
-
//
|
|
1769
|
-
// `
|
|
1770
|
-
//
|
|
1771
|
-
//
|
|
1772
|
-
//
|
|
1773
|
-
//
|
|
1774
|
-
//
|
|
1784
|
+
// question is "is this exact version live", and the two agree only until someone rolls back:
|
|
1785
|
+
// the workspace is then unchanged, so the hash is unchanged. No input repairs that. A `runtime`
|
|
1786
|
+
// input cannot even learn WHICH STAGE is being deployed (Nx hashes runtime inputs with the env
|
|
1787
|
+
// from `getTaskSpecificEnv`, which excludes the task coordinates, and input strings never
|
|
1788
|
+
// interpolate `{args.*}`), and hashing the live tag in would never converge, because the
|
|
1789
|
+
// deployed version is tagged with the hash. An executor's custom hasher is the one Nx API that
|
|
1790
|
+
// sees `task.overrides`, so `wrangler-deploy`'s asks the question: it hashes the artifact and the
|
|
1791
|
+
// stage, answers that hash only while the stage serves the version tagged with it, and otherwise
|
|
1792
|
+
// adds a nonce, so the run misses and deploys (executors/wrangler-deploy/hasher.ts). The run
|
|
1793
|
+
// still tags the artifact's version, so the next hash, with that version live, is the artifact's
|
|
1794
|
+
// own: `deploy-stage` finds it live and changes nothing, and Nx caches that answer.
|
|
1775
1795
|
//
|
|
1776
|
-
// So the target is split along the line the question
|
|
1777
|
-
// file-derived — build the artifact and whatever the build registers
|
|
1778
|
-
//
|
|
1779
|
-
//
|
|
1780
|
-
//
|
|
1781
|
-
//
|
|
1782
|
-
// dependent has to re-check liveness, not inherit someone else's cache hit.
|
|
1796
|
+
// So the target is split along the line the question falls on. `deploy-build` is purely
|
|
1797
|
+
// file-derived — build the artifact and whatever the build registers. `deploy` checks live state
|
|
1798
|
+
// on every run, in its hasher, and a cache hit replays only a deploy that would change nothing.
|
|
1799
|
+
// That is what lets ordering be an ordinary `dependsOn: ["<other>:deploy"]` edge at any depth,
|
|
1800
|
+
// and it is why such an edge must point at `deploy` and not at `deploy-build`: a dependent has
|
|
1801
|
+
// to re-check liveness, not inherit someone else's build.
|
|
1783
1802
|
//
|
|
1784
1803
|
// Both are bases for a package-local declaration to land on, per the merge rules above: a
|
|
1785
1804
|
// declaration naming `cache`, `inputs` or `dependsOn` REPLACES what is set here and inherits
|
|
1786
1805
|
// everything it does not name, while Nx's `"..."` token expands to the inferred list at its
|
|
1787
1806
|
// position. So a project adding a cross-project edge writes
|
|
1788
|
-
// `"dependsOn": ["...", "backend:deploy"]` and keeps both the edge below and this
|
|
1807
|
+
// `"dependsOn": ["...", "backend:deploy"]` and keeps both the edge below and this executor —
|
|
1789
1808
|
// measured, not assumed, against an inferred base.
|
|
1790
1809
|
//
|
|
1791
1810
|
// `deploy` is INFERRED for a private wrangler project rather than patched onto a hand-written
|
|
1792
|
-
// one. The
|
|
1793
|
-
// the same `nx:run-commands` wrapper around
|
|
1811
|
+
// one. The executor is a constant of the convention, not of the project: every consumer wrote
|
|
1812
|
+
// the same `nx:run-commands` wrapper around `smoo wrangler deploy-stage`. `private: true` is the second half of the
|
|
1794
1813
|
// detection: a PUBLISHED package's wrangler manifest documents a binding for its consumers,
|
|
1795
1814
|
// so inferring a deploy from it would put a live `wrangler deploy` of someone's documentation
|
|
1796
1815
|
// one `nx run-many -t deploy` away. A published package that really is deployed declares
|
|
@@ -1811,11 +1830,12 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1811
1830
|
? 'build'
|
|
1812
1831
|
: null;
|
|
1813
1832
|
targets[DEPLOY_TARGET] = {
|
|
1814
|
-
executor:
|
|
1815
|
-
cache:
|
|
1833
|
+
executor: WRANGLER_DEPLOY_EXECUTOR,
|
|
1834
|
+
cache: true,
|
|
1835
|
+
inputs: WRANGLER_DEPLOY_INPUTS,
|
|
1816
1836
|
outputs: [],
|
|
1817
1837
|
...(fileDerivedHalf === null ? {} : { dependsOn: [fileDerivedHalf] }),
|
|
1818
|
-
options: {
|
|
1838
|
+
options: {},
|
|
1819
1839
|
};
|
|
1820
1840
|
}
|
|
1821
1841
|
// Empty `outputs`, deliberately and explicitly: this aggregate runs no
|
|
@@ -1848,43 +1868,10 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1848
1868
|
],
|
|
1849
1869
|
};
|
|
1850
1870
|
}
|
|
1851
|
-
// Every cargo build directory this project's own commands write. `clean`
|
|
1852
|
-
// cannot learn them from `outputs`: a clippy or nextest target dir is a
|
|
1853
|
-
// multi-GB build tree that must never enter the Nx cache, so the targets
|
|
1854
|
-
// deliberately declare `outputs: []`. Reading `--target-dir` back off the
|
|
1855
|
-
// commands means the list cannot drift from what actually gets written, and a
|
|
1856
|
-
// directory is named relative to the command's own cwd, not the project root.
|
|
1857
|
-
// The workspace's default `target/` is not listed: every dev build shares it.
|
|
1858
|
-
const cargoBuildDirs = [
|
|
1859
|
-
...new Set(Object.entries(targets).flatMap(([name, target]) => {
|
|
1860
|
-
const cwd = target.options?.cwd;
|
|
1861
|
-
const base = typeof cwd === 'string' ? cwd : projectRoot;
|
|
1862
|
-
const dirs = [...targetCommandText(target).matchAll(/--target-dir\s+(\S+)/g)].flatMap((match) => match[1] === undefined ? [] : [match[1]]);
|
|
1863
|
-
if (name === CARGO_TEST_ARCHIVE_TARGET) {
|
|
1864
|
-
dirs.push(posix.dirname(CARGO_TEST_ARCHIVE_FILE));
|
|
1865
|
-
}
|
|
1866
|
-
return dirs.map((dir) => `{workspaceRoot}/${posix.normalize(posix.join(base, dir))}`);
|
|
1867
|
-
})),
|
|
1868
|
-
].sort();
|
|
1869
|
-
if (hasAnyBuildOutputTarget || cargoBuildDirs.length > 0) {
|
|
1870
|
-
const declaredBuild = declaredTargets.build;
|
|
1871
|
-
const declaredBuildOutputs = isRecord(declaredBuild) && Array.isArray(declaredBuild.outputs)
|
|
1872
|
-
? declaredBuild.outputs.filter((output) => typeof output === 'string')
|
|
1873
|
-
: null;
|
|
1874
|
-
targets.clean = {
|
|
1875
|
-
executor: '@smoothbricks/nx-plugin:clean-outputs',
|
|
1876
|
-
cache: false,
|
|
1877
|
-
// Naming any output REPLACES the executor's default, so the build outputs
|
|
1878
|
-
// it would have used are restated here rather than lost.
|
|
1879
|
-
...(cargoBuildDirs.length > 0
|
|
1880
|
-
? { options: { outputs: [...(declaredBuildOutputs ?? ['{projectRoot}/dist']), ...cargoBuildDirs] } }
|
|
1881
|
-
: {}),
|
|
1882
|
-
};
|
|
1883
|
-
}
|
|
1884
1871
|
if (targets['typecheck-tests']) {
|
|
1885
1872
|
if (hasLibTsconfig) {
|
|
1886
|
-
// Test configs may resolve the package's own `./index.js` through dist
|
|
1887
|
-
//
|
|
1873
|
+
// Test configs may resolve the package's own `./index.js` through dist, so the
|
|
1874
|
+
// current-project declaration output is rebuilt first, not only the
|
|
1888
1875
|
// dependency-project outputs reached through typecheck.
|
|
1889
1876
|
targets['typecheck-tests'].dependsOn = ['tsc-js', 'typecheck'];
|
|
1890
1877
|
}
|
|
@@ -1895,8 +1882,8 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1895
1882
|
// A Bun suite that `--shard` splits and a `--timings` manifest balances gets a
|
|
1896
1883
|
// check, which `lint` depends on, that the manifest names every file the
|
|
1897
1884
|
// shards run: Bun charges an unnamed file the median, and unnamed files
|
|
1898
|
-
// cluster into one shard.
|
|
1899
|
-
//
|
|
1885
|
+
// cluster into one shard. Cached on the manifests, the bunfig and the names
|
|
1886
|
+
// Bun's discovery would find, which include gitignored files no file input keys.
|
|
1900
1887
|
const sharded = timingsShardedSuite(projectRoot, declaredTargets);
|
|
1901
1888
|
if (!sharded.ok) {
|
|
1902
1889
|
throw new Error(`${packageJsonPath}: ${sharded.error}`);
|
|
@@ -1904,7 +1891,11 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1904
1891
|
if (sharded.suite !== null) {
|
|
1905
1892
|
targets[SHARD_TIMINGS_TARGET] = {
|
|
1906
1893
|
executor: SHARD_TIMINGS_EXECUTOR,
|
|
1907
|
-
cache:
|
|
1894
|
+
cache: true,
|
|
1895
|
+
inputs: [
|
|
1896
|
+
...timingsSuiteInputs(sharded.suite),
|
|
1897
|
+
{ externalDependencies: pluginInstalledIn(workspaceRoot) ? [PLUGIN_PACKAGE] : [] },
|
|
1898
|
+
],
|
|
1908
1899
|
outputs: [],
|
|
1909
1900
|
options: { cwd: sharded.suite.cwd, args: sharded.suite.args },
|
|
1910
1901
|
};
|
|
@@ -1933,11 +1924,54 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1933
1924
|
],
|
|
1934
1925
|
...(lintCommands.length > 0
|
|
1935
1926
|
? {
|
|
1936
|
-
options: {
|
|
1927
|
+
options: {
|
|
1928
|
+
commands: lintCommands,
|
|
1929
|
+
cwd: '.',
|
|
1930
|
+
...(eslintFileSet === null ? {} : { eslintProjectRoot: projectRoot }),
|
|
1931
|
+
},
|
|
1937
1932
|
}
|
|
1938
1933
|
: {}),
|
|
1939
1934
|
};
|
|
1940
1935
|
}
|
|
1936
|
+
// The process-lineage entry has no full API-generator dependency: the generator check itself is bounded work.
|
|
1937
|
+
const lineageProducer = nativeToolDependsOn(nativeTools, 'cowshed', 'lineage-js');
|
|
1938
|
+
if (lineageProducer.length > 0 && packageJson.name === '@smoothbricks/nx-plugin') {
|
|
1939
|
+
for (const name of ['tsc-js', 'typecheck', 'typecheck-tests']) {
|
|
1940
|
+
const target = targets[name];
|
|
1941
|
+
if (target === undefined)
|
|
1942
|
+
continue;
|
|
1943
|
+
target.dependsOn = [...(target.dependsOn ?? []), ...lineageProducer];
|
|
1944
|
+
target.inputs = [
|
|
1945
|
+
...(target.inputs ?? ['production']),
|
|
1946
|
+
{ dependentTasksOutputFiles: '**/dist/lineage/**/*', transitive: false },
|
|
1947
|
+
];
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
// Runtime observers need the local addon, not the package aggregate (which can deliberately build only JS).
|
|
1951
|
+
// Declarations retain these prerequisites and output inputs with Nx's ordinary "..." merge token.
|
|
1952
|
+
// The canonical release-check instead judges prebuilt shipping artifacts and must remain dependency-free.
|
|
1953
|
+
const observerProducers = [...nativeToolDependsOn(nativeTools, 'cowshed'), ...lineageProducer];
|
|
1954
|
+
if (observerProducers.length > 0) {
|
|
1955
|
+
for (const name of new Set([...Object.keys(targets), ...Object.keys(declaredTargets)])) {
|
|
1956
|
+
const declared = declaredTargets[name];
|
|
1957
|
+
const executor = isRecord(declared) && declared.executor !== undefined ? declared.executor : targets[name]?.executor;
|
|
1958
|
+
if (executor !== '@smoothbricks/nx-plugin:bounded-exec' || name === 'release-check')
|
|
1959
|
+
continue;
|
|
1960
|
+
// Nx discards an incompatible executor's inferred configuration; only the observer prerequisites belong below it.
|
|
1961
|
+
if (targets[name]?.executor !== undefined && targets[name]?.executor !== executor) {
|
|
1962
|
+
targets[name] = {};
|
|
1963
|
+
}
|
|
1964
|
+
targets[name] ??= {};
|
|
1965
|
+
const target = targets[name];
|
|
1966
|
+
target.dependsOn = [...(target.dependsOn ?? []), ...observerProducers];
|
|
1967
|
+
const inputs = target.inputs ?? (isRecord(declared) && Array.isArray(declared.inputs) ? [] : ['default', '^production']);
|
|
1968
|
+
target.inputs = [
|
|
1969
|
+
...inputs,
|
|
1970
|
+
{ dependentTasksOutputFiles: '**/*.node', transitive: true },
|
|
1971
|
+
{ dependentTasksOutputFiles: '**/dist/lineage/**/*.js', transitive: true },
|
|
1972
|
+
];
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1941
1975
|
// Publish each inferred target's semantic kind (`inferredTaskKind`) as metadata. Nx merges metadata beneath a
|
|
1942
1976
|
// declaration, so the final graph still says which tasks are build and which are test work after a package rewrites
|
|
1943
1977
|
// one. Fresh objects: `CARGO_PRODUCER_METADATA` is shared by every producer.
|
|
@@ -1963,7 +1997,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
1963
1997
|
[VERSIONLESS_PRODUCTION_INPUT]: ['production', ...versionlessProjectInputs],
|
|
1964
1998
|
[VERSIONLESS_DEFAULT_INPUT]: ['default', ...versionlessProjectInputs],
|
|
1965
1999
|
}),
|
|
1966
|
-
...(Object.keys(targets).some((name) => name.startsWith('cargo-') || name.startsWith('napi-'))
|
|
2000
|
+
...([...Object.keys(targets), ...Object.keys(declaredTargets)].some((name) => name.startsWith('cargo-') || name.startsWith('napi-'))
|
|
1967
2001
|
? { [CARGO_TOOLCHAIN_NAMED_INPUT]: cargoToolchainInputs() }
|
|
1968
2002
|
: {}),
|
|
1969
2003
|
};
|
|
@@ -2409,13 +2443,9 @@ function parseEnvPrefixedCommand(command) {
|
|
|
2409
2443
|
function isRecord(value) {
|
|
2410
2444
|
return value !== null && typeof value === 'object';
|
|
2411
2445
|
}
|
|
2412
|
-
function
|
|
2446
|
+
function declaresPackageLocalBuildOutput(packageJson) {
|
|
2413
2447
|
const targets = packageJson.nx?.targets;
|
|
2414
|
-
|
|
2415
|
-
return {
|
|
2416
|
-
ordinary: targetNames.some(isBuildOutputTargetName),
|
|
2417
|
-
platform: targetNames.some((targetName) => PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1)))),
|
|
2418
|
-
};
|
|
2448
|
+
return isRecord(targets) && Object.keys(targets).some(isBuildOutputTargetName);
|
|
2419
2449
|
}
|
|
2420
2450
|
function cargoTargetDependency(currentProjectName, target) {
|
|
2421
2451
|
return target.projectName === currentProjectName
|
|
@@ -2536,7 +2566,7 @@ async function resolveCargoWorkspaces(packageJsonPaths, workspaceRoot, hostPlatf
|
|
|
2536
2566
|
* own time bound never delays an ordinary shard.
|
|
2537
2567
|
*
|
|
2538
2568
|
* Every piece EXECUTES, it never builds: it runs the binaries
|
|
2539
|
-
* `cargo-test-
|
|
2569
|
+
* `cargo-test-build` compiled once for the whole workspace. That is what
|
|
2540
2570
|
* removed the two costs the old shape could not avoid. `nextest run --workspace
|
|
2541
2571
|
* -E 'package(X)'` re-entered cargo once per crate, and the `-p X` form
|
|
2542
2572
|
* re-resolved that crate's features so cargo rebuilt the divergent half inside
|
|
@@ -2546,37 +2576,32 @@ async function resolveCargoWorkspaces(packageJsonPaths, workspaceRoot, hostPlatf
|
|
|
2546
2576
|
* it, so the filterset is the only selector left, and it selects the same tests
|
|
2547
2577
|
* it always did.
|
|
2548
2578
|
*
|
|
2549
|
-
* The
|
|
2550
|
-
*
|
|
2551
|
-
*
|
|
2552
|
-
*
|
|
2553
|
-
*
|
|
2554
|
-
*
|
|
2555
|
-
*
|
|
2556
|
-
*
|
|
2557
|
-
*
|
|
2558
|
-
*
|
|
2559
|
-
*
|
|
2560
|
-
*
|
|
2561
|
-
*
|
|
2562
|
-
*
|
|
2563
|
-
* than the archived copy of it — the same toolchain, because the archive's hash
|
|
2564
|
-
* covers the toolchain pin. The extraction lives in Cargo's own target
|
|
2565
|
-
* directory (`<target_directory>/nextest-extracted`), never in an Nx output: it
|
|
2566
|
-
* is a multi-GB tree for a cached verdict that has no outputs, rebuilt from the
|
|
2567
|
-
* archive like the rest of the build tree, and a checkout that keeps its build
|
|
2568
|
-
* state off its source tree keeps the extraction there with it.
|
|
2579
|
+
* The binaries run where the build left them, never copied. An archive makes
|
|
2580
|
+
* a same-platform run pay for a copy of every binary in the workspace before
|
|
2581
|
+
* its first test (measured: 290 binaries, 678 MB, 4.6s on a quiet host and 21s
|
|
2582
|
+
* in a gate, per archive), which only a cross lane needs
|
|
2583
|
+
* (createCargoCrossTestTargets). A run reads the build's reuse-build metadata,
|
|
2584
|
+
* the build's declared Nx outputs, and remaps the build's target directory onto
|
|
2585
|
+
* this checkout's, which `smoo-nx-nextest-binaries target-dir` reads from
|
|
2586
|
+
* Cargo, so a `build.target-dir` is honoured as every build honours it. The
|
|
2587
|
+
* binaries are not Nx outputs, so a checkout whose build was a cache hit can
|
|
2588
|
+
* hold the metadata without them, or with binaries of an older tree at the very
|
|
2589
|
+
* paths it names: the runner's fixture (nextestRunnerFixture) compares the key
|
|
2590
|
+
* the target directory records with the build's and stats each binary, and
|
|
2591
|
+
* otherwise rebuilds with the build's own command through mbx, in the runner's
|
|
2592
|
+
* build interval and never in its progress-bounded test window.
|
|
2569
2593
|
*
|
|
2570
|
-
* `--workspace-remap .` is not cosmetic.
|
|
2571
|
-
* of the tree that produced it; without the remap,
|
|
2572
|
-
* every test the producing tree's
|
|
2573
|
-
*
|
|
2574
|
-
* exists. With it, the runner's
|
|
2575
|
-
*
|
|
2576
|
-
* nextest also re-points
|
|
2577
|
-
*
|
|
2578
|
-
* time: a test that spawns
|
|
2579
|
-
* path and must read the
|
|
2594
|
+
* `--workspace-remap .` is not cosmetic. Reuse-build metadata records the
|
|
2595
|
+
* ABSOLUTE paths of the tree that produced it; without the remap, metadata
|
|
2596
|
+
* restored from another checkout hands every test the producing tree's
|
|
2597
|
+
* `CARGO_MANIFEST_DIR` — measured on a moved tree, tests then read another
|
|
2598
|
+
* checkout's fixtures, or a path that no longer exists. With it, the runner's
|
|
2599
|
+
* own cargo workspace root wins, so the metadata is relocatable and one cache
|
|
2600
|
+
* entry serves every checkout of the same commit. nextest also re-points
|
|
2601
|
+
* `CARGO_BIN_EXE_<name>`/`NEXTEST_BIN_EXE_<name>` at the remapped binaries at
|
|
2602
|
+
* RUNTIME (measured), but `env!` reads them at COMPILE time: a test that spawns
|
|
2603
|
+
* `env!("CARGO_BIN_EXE_x")` holds the producing tree's path and must read the
|
|
2604
|
+
* runtime variable instead to survive relocation.
|
|
2580
2605
|
*
|
|
2581
2606
|
* nextest.toml singles some tests out with an override: a raised `slow-timeout`
|
|
2582
2607
|
* marks a test whose cost is not the suite's. Those are lifted OUT of the hash
|
|
@@ -2597,8 +2622,8 @@ async function resolveCargoWorkspaces(packageJsonPaths, workspaceRoot, hostPlatf
|
|
|
2597
2622
|
* making valid empty crates and shards fail execution.
|
|
2598
2623
|
*
|
|
2599
2624
|
* Pieces fan out rather than chain: a reused-build run writes nothing to cargo's
|
|
2600
|
-
* `target/`, so no piece waits on another.
|
|
2601
|
-
*
|
|
2625
|
+
* `target/`, so no piece waits on another. Only a fixture that finds another
|
|
2626
|
+
* build in place builds, once for the checkout's runners, under a lock of its own.
|
|
2602
2627
|
*/
|
|
2603
2628
|
async function addCargoTestTargets(targets, currentProjectName, projectRoot, workspaceRoot, workspace, nativeTools) {
|
|
2604
2629
|
const targetNames = [];
|
|
@@ -2607,13 +2632,13 @@ async function addCargoTestTargets(targets, currentProjectName, projectRoot, wor
|
|
|
2607
2632
|
continue;
|
|
2608
2633
|
}
|
|
2609
2634
|
const inputs = await cargoTestRunnerInputs(workspaceRoot, workspace, [plan.package.dir]);
|
|
2610
|
-
const
|
|
2635
|
+
const build = cargoTargetDependency(currentProjectName, {
|
|
2611
2636
|
projectName: workspace.rootProjectName,
|
|
2612
|
-
targetName:
|
|
2637
|
+
targetName: CARGO_TEST_BUILD_TARGET,
|
|
2613
2638
|
});
|
|
2614
2639
|
for (const piece of plan.pieces) {
|
|
2615
2640
|
targetNames.push(piece.targetName);
|
|
2616
|
-
targets[piece.targetName] = cargoTestRunnerTarget(workspace, nativeTools,
|
|
2641
|
+
targets[piece.targetName] = cargoTestRunnerTarget(workspace, nativeTools, build, inputs, piece);
|
|
2617
2642
|
}
|
|
2618
2643
|
}
|
|
2619
2644
|
return targetNames;
|
|
@@ -2650,7 +2675,7 @@ function serialGroupMemberDirs(workspace, group) {
|
|
|
2650
2675
|
* manifests, not unrelated sibling sources.
|
|
2651
2676
|
*
|
|
2652
2677
|
* The repository's own nextest config layers OVER the plugin's tool config, so it
|
|
2653
|
-
* decides timeouts, groups and
|
|
2678
|
+
* decides timeouts, groups and setup scripts: a cached verdict that ignored it
|
|
2654
2679
|
* would survive the change that invalidates it.
|
|
2655
2680
|
*/
|
|
2656
2681
|
async function cargoTestRunnerInputs(workspaceRoot, workspace, memberDirs) {
|
|
@@ -2662,8 +2687,8 @@ async function cargoTestRunnerInputs(workspaceRoot, workspace, memberDirs) {
|
|
|
2662
2687
|
cache: workspace.inputsCache,
|
|
2663
2688
|
cargo: workspace.closureSource.cargo,
|
|
2664
2689
|
})));
|
|
2665
|
-
// The
|
|
2666
|
-
//
|
|
2690
|
+
// The test build unifies every built package's manifest into every test binary, and a runner's key does not follow
|
|
2691
|
+
// the build's outputs, so each runner names them all: the ones Nx holds as files, the rest through the repository's
|
|
2667
2692
|
// runtime hash of external sources.
|
|
2668
2693
|
const manifests = [];
|
|
2669
2694
|
const external = new Map();
|
|
@@ -2696,30 +2721,46 @@ async function cargoTestRunnerInputs(workspaceRoot, workspace, memberDirs) {
|
|
|
2696
2721
|
];
|
|
2697
2722
|
}
|
|
2698
2723
|
/**
|
|
2699
|
-
*
|
|
2700
|
-
*
|
|
2701
|
-
*
|
|
2724
|
+
* A runner's fixture budget: the build interval in which it rebuilds what the target directory lacks. It is a build's
|
|
2725
|
+
* budget, not a test's: on a host whose mbx store lacks the units, the fixture compiles the whole workspace's
|
|
2726
|
+
* tests, which a cold hosted runner takes tens of minutes to do while still making progress.
|
|
2727
|
+
*/
|
|
2728
|
+
const NEXTEST_BINARIES_FIXTURE_TIMEOUT_MS = 3_600_000;
|
|
2729
|
+
/**
|
|
2730
|
+
* The fixture every runner of the workspace runs before its tests: the binaries live outside Nx outputs, so it checks
|
|
2731
|
+
* that the target directory holds the build whose key the metadata came with, and every binary the metadata names,
|
|
2732
|
+
* and otherwise rebuilds with the build's own command. It reports its own duration and mbx's hits and misses apart
|
|
2733
|
+
* from the run's, and names the crates loudly when mbx had to compile (smoo-nx-nextest-binaries).
|
|
2734
|
+
*/
|
|
2735
|
+
function nextestRunnerFixture(workspace, nativeTools) {
|
|
2736
|
+
const helper = nativeToolCommand(nativeTools, workspace.projectRoot, 'nextest-extract', 'smoo-nx-nextest-binaries');
|
|
2737
|
+
return `${helper} ensure ${NEXTEST_BINARIES_METADATA} ${NEXTEST_BUILD_KEY} -- ${nextestBinariesBuild(nextestToolConfigArg(workspace.projectRoot))}`;
|
|
2738
|
+
}
|
|
2739
|
+
/**
|
|
2740
|
+
* One `nextest run` over a filterset against the workspace's test build. Every runner of the
|
|
2741
|
+
* workspace builds its command here, so the reuse-build, the remap, the tool config and the cwd
|
|
2742
|
+
* cannot drift between the per-crate pieces and the serial groups.
|
|
2702
2743
|
*/
|
|
2703
2744
|
function nextestRunnerCommand(workspace, nativeTools, selector, flags) {
|
|
2704
2745
|
const toolConfig = nextestToolConfigArg(workspace.projectRoot);
|
|
2705
2746
|
// Relative to the runner's cwd, so the hashed command is the same in every checkout.
|
|
2706
|
-
const
|
|
2707
|
-
const
|
|
2708
|
-
`--
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
/** One per-crate piece: a bounded run of its partition of the archive's tests. */
|
|
2714
|
-
function cargoTestRunnerTarget(workspace, nativeTools, archive, inputs, piece) {
|
|
2747
|
+
const helper = nativeToolCommand(nativeTools, workspace.projectRoot, 'nextest-extract', 'smoo-nx-nextest-binaries');
|
|
2748
|
+
const reuseBuild = `--binaries-metadata ${NEXTEST_BINARIES_METADATA} --cargo-metadata ${NEXTEST_CARGO_METADATA} ` +
|
|
2749
|
+
`--target-dir-remap "$(${helper} target-dir)"`;
|
|
2750
|
+
return cargoFrozen(`nextest run ${reuseBuild} --workspace-remap . -E ${shellWord(selector)}${flags} --user-config-file none ${toolConfig}`);
|
|
2751
|
+
}
|
|
2752
|
+
/** One per-crate piece: a bounded run of its partition of the test build's tests. */
|
|
2753
|
+
function cargoTestRunnerTarget(workspace, nativeTools, build, inputs, piece) {
|
|
2715
2754
|
return {
|
|
2716
2755
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
2717
2756
|
cache: true,
|
|
2718
2757
|
inputs,
|
|
2719
|
-
dependsOn: [
|
|
2758
|
+
dependsOn: [build, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
|
|
2720
2759
|
options: {
|
|
2721
2760
|
command: nextestRunnerCommand(workspace, nativeTools, piece.selector, `${piece.extra} --no-fail-fast --no-tests=pass`),
|
|
2722
2761
|
cwd: workspace.projectRoot,
|
|
2762
|
+
fixtureCommand: nextestRunnerFixture(workspace, nativeTools),
|
|
2763
|
+
fixtureTimeoutMs: NEXTEST_BINARIES_FIXTURE_TIMEOUT_MS,
|
|
2723
2764
|
idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
|
|
2724
2765
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
2725
2766
|
},
|
|
@@ -2738,10 +2779,12 @@ function cargoTestGroupTarget(workspace, nativeTools, inputs, group) {
|
|
|
2738
2779
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
2739
2780
|
cache: true,
|
|
2740
2781
|
inputs: [...inputs, fileHashInput(PLUGIN_NEXTEST_CODE_BOUND)],
|
|
2741
|
-
dependsOn: [
|
|
2782
|
+
dependsOn: [CARGO_TEST_BUILD_TARGET, ...nativeToolDependsOn(nativeTools, 'nextest-extract')],
|
|
2742
2783
|
options: {
|
|
2743
2784
|
command: nextestRunnerCommand(workspace, nativeTools, group.filter, ' --no-fail-fast --no-tests=fail'),
|
|
2744
2785
|
cwd: workspace.projectRoot,
|
|
2786
|
+
fixtureCommand: nextestRunnerFixture(workspace, nativeTools),
|
|
2787
|
+
fixtureTimeoutMs: NEXTEST_BINARIES_FIXTURE_TIMEOUT_MS,
|
|
2745
2788
|
idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS,
|
|
2746
2789
|
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
2747
2790
|
parallelism: 1,
|