@smoothbricks/nx-plugin 0.3.11 → 0.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -2
- package/dist/bounded-test-policy.d.ts +26 -0
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +194 -0
- package/dist/cargo-workspace.d.ts +67 -0
- package/dist/cargo-workspace.d.ts.map +1 -0
- package/dist/cargo-workspace.js +215 -0
- package/dist/cross-check-policy.d.ts +60 -1
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +65 -1
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +86 -51
- package/dist/executors/bounded-exec/schema.d.ts +13 -0
- package/dist/executors/bounded-exec/schema.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +344 -57
- package/dist/package-target-policy.d.ts +2 -1
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +54 -13
- package/dist/workspace-config-policy.js +32 -35
- package/nextest.toml +42 -0
- package/package.json +2 -1
- package/src/bounded-test-policy.test.ts +304 -0
- package/src/bounded-test-policy.ts +218 -0
- package/src/cargo-workspace.ts +243 -0
- package/src/cross-check-policy.test.ts +24 -0
- package/src/cross-check-policy.ts +80 -1
- package/src/executors/bounded-exec/executor.test.ts +147 -3
- package/src/executors/bounded-exec/executor.ts +103 -53
- package/src/executors/bounded-exec/schema.json +7 -2
- package/src/executors/bounded-exec/schema.ts +13 -0
- package/src/index.test.ts +373 -25
- package/src/index.ts +390 -65
- package/src/package-target-policy.test.ts +50 -0
- package/src/package-target-policy.ts +58 -9
- package/src/workspace-config-policy.test.ts +15 -30
- package/src/workspace-config-policy.ts +32 -39
package/dist/index.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import { readdir, readFile } from 'node:fs/promises';
|
|
3
3
|
import { dirname, join, posix } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
4
5
|
import { readJsonFile, } from 'nx/src/devkit-exports.js';
|
|
5
6
|
import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
|
|
6
7
|
import { parse as parseToml } from 'smol-toml';
|
|
7
|
-
import {
|
|
8
|
+
import { BOUNDED_TEST_KILL_AFTER_MS, BOUNDED_TEST_TIMEOUT_MS } from './bounded-test-policy.js';
|
|
9
|
+
import { CARGO_TEST_COMPILE_TARGET, CARGO_TEST_EXCEPTIONS_SUFFIX, CARGO_TEST_TARGET, cargoPackageTestInputs, cargoTestPackageTargetName, exceptionalTestFilter, listCargoWorkspacePackages, nextestConfigRelPath, } 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';
|
|
8
11
|
import { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
12
|
+
export { CARGO_TEST_COMPILE_TARGET };
|
|
9
13
|
const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|android|native|napi|bun|wasm)$/;
|
|
10
14
|
const TYPESCRIPT_TOOLCHAIN_INPUTS = [
|
|
11
15
|
'{workspaceRoot}/package.json',
|
|
@@ -103,7 +107,7 @@ function createCargoWasmTarget(projectRoot, config) {
|
|
|
103
107
|
outputs: [`{projectRoot}/${config.outputDirectory}`],
|
|
104
108
|
options: {
|
|
105
109
|
commands: [
|
|
106
|
-
`
|
|
110
|
+
cargoFrozen(`build --release --target wasm32-unknown-unknown --target-dir ${cargoTargetDirectory} --manifest-path ${config.manifestPath}`),
|
|
107
111
|
...config.targets.map(({ bindgenTarget, outputName }) => `wasm-bindgen --target ${bindgenTarget} --out-dir ${config.outputDirectory}/${outputName} ${wasmInput}`),
|
|
108
112
|
],
|
|
109
113
|
cwd: projectRoot,
|
|
@@ -111,23 +115,126 @@ function createCargoWasmTarget(projectRoot, config) {
|
|
|
111
115
|
},
|
|
112
116
|
};
|
|
113
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Compilation is excluded from the bounded test window: a cold Cargo
|
|
120
|
+
* workspace can take many minutes to compile while still making progress,
|
|
121
|
+
* which is not a property of the tests. `cargo test --no-run` pays that cost
|
|
122
|
+
* in its own unbounded, cacheable target; the bounded runner then re-invokes
|
|
123
|
+
* cargo against a warm target directory, where only the suites' own runtime
|
|
124
|
+
* counts against the standard bound.
|
|
125
|
+
*
|
|
126
|
+
* Cargo flocks one `target/` per invocation. Nx must not run two cargo
|
|
127
|
+
* writers on that directory at once — that is a mutex, not a deadlock, and
|
|
128
|
+
* the second process sits in "Blocking waiting for file lock" until a
|
|
129
|
+
* timeout. Inference serializes writers that share the default target dir
|
|
130
|
+
* (`napi-debug` after compile, `cargo-test` after `napi-debug`). Clippy uses
|
|
131
|
+
* its own `--target-dir` so lint can overlap tests.
|
|
132
|
+
*/
|
|
133
|
+
function createCargoTestCompileTarget(projectRoot) {
|
|
134
|
+
return {
|
|
135
|
+
executor: 'nx:run-commands',
|
|
136
|
+
cache: true,
|
|
137
|
+
inputs: CARGO_INPUTS,
|
|
138
|
+
options: {
|
|
139
|
+
command: cargoFrozen('test --workspace --no-run'),
|
|
140
|
+
cwd: projectRoot,
|
|
141
|
+
},
|
|
142
|
+
configurations: {
|
|
143
|
+
production: { command: cargoFrozen('test --workspace --release --no-run') },
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
114
147
|
function createCargoTestTarget(projectRoot) {
|
|
115
148
|
return {
|
|
116
149
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
117
150
|
cache: true,
|
|
118
151
|
inputs: CARGO_INPUTS,
|
|
152
|
+
dependsOn: [CARGO_TEST_COMPILE_TARGET],
|
|
119
153
|
options: {
|
|
120
|
-
command: '
|
|
154
|
+
command: cargoFrozen('test --workspace'),
|
|
121
155
|
cwd: projectRoot,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
killAfterMs: 10000,
|
|
156
|
+
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
157
|
+
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
125
158
|
},
|
|
126
159
|
configurations: {
|
|
127
|
-
production: { command: '
|
|
160
|
+
production: { command: cargoFrozen('test --workspace --release') },
|
|
128
161
|
},
|
|
129
162
|
};
|
|
130
163
|
}
|
|
164
|
+
const PLUGIN_NEXTEST_CONFIG = fileURLToPath(new URL('../nextest.toml', import.meta.url));
|
|
165
|
+
/**
|
|
166
|
+
* One bounded target per crate; a crate that declares `smoothbricks.test.shards`
|
|
167
|
+
* gets one per shard plus one for the tests nextest.toml singles out.
|
|
168
|
+
*
|
|
169
|
+
* `--workspace -E 'package(X)'` rather than `--package X`. A filterset selects
|
|
170
|
+
* what RUNS; `--package` also re-resolves FEATURES for that crate alone, which
|
|
171
|
+
* fingerprints differently from the `cargo test --workspace --no-run` that
|
|
172
|
+
* `cargo-test-compile` already paid for, so cargo rebuilds the divergent half
|
|
173
|
+
* inside the bounded window. Measured on a hosted 3-core macOS runner that
|
|
174
|
+
* rebuild was 57.9s of a 120s budget — the tests were killed with 264 still to
|
|
175
|
+
* run while nothing was wrong with them. The two forms select the same tests;
|
|
176
|
+
* only the filterset reuses the compile target's artifacts.
|
|
177
|
+
*
|
|
178
|
+
* nextest.toml singles some tests out with an override, and each such class
|
|
179
|
+
* breaks a shard in its own way — a `test-group` is scoped to one nextest RUN
|
|
180
|
+
* so the hash would dissolve it, and a raised `slow-timeout` marks a test whose
|
|
181
|
+
* cost is not the suite's. Those are lifted OUT of the hash into one target and
|
|
182
|
+
* the shards run the exact complement, so which tests a shard holds stops
|
|
183
|
+
* depending on how the hash happened to fall.
|
|
184
|
+
*
|
|
185
|
+
* The two filtersets are exact complements, so their union is the crate whatever
|
|
186
|
+
* either one matches; an empty exception set (every real-APFS test is
|
|
187
|
+
* `cfg(target_os = "macos")`, so on Linux there are none) costs coverage
|
|
188
|
+
* nothing, which is why that target may pass having run zero tests. It cannot
|
|
189
|
+
* hide a lost test — only a pin that stopped matching, whose members then fall
|
|
190
|
+
* into the shards.
|
|
191
|
+
*
|
|
192
|
+
* Pieces chain rather than fan out, like the crates do: cargo flocks one
|
|
193
|
+
* `target/`, and chaining keeps even the pinned group from overlapping the
|
|
194
|
+
* shards on a machine-wide resource.
|
|
195
|
+
*/
|
|
196
|
+
async function addPerPackageCargoTestTargets(targets, projectRoot, workspaceRoot, absoluteProjectRoot) {
|
|
197
|
+
const packages = listCargoWorkspacePackages(absoluteProjectRoot);
|
|
198
|
+
if (packages.length === 0) {
|
|
199
|
+
return [];
|
|
200
|
+
}
|
|
201
|
+
const configFile = nextestConfigRelPath(workspaceRoot, projectRoot, PLUGIN_NEXTEST_CONFIG);
|
|
202
|
+
const exceptional = exceptionalTestFilter(PLUGIN_NEXTEST_CONFIG);
|
|
203
|
+
const packageTargetNames = [];
|
|
204
|
+
let previous = CARGO_TEST_COMPILE_TARGET;
|
|
205
|
+
for (const pkg of packages) {
|
|
206
|
+
const inputs = await cargoPackageTestInputs(absoluteProjectRoot, pkg.dir);
|
|
207
|
+
const sharded = pkg.testShards > 1;
|
|
208
|
+
const pin = sharded && exceptional !== null ? exceptional : null;
|
|
209
|
+
const addTarget = (piece, selector, extra) => {
|
|
210
|
+
const targetName = cargoTestPackageTargetName(pkg.name, piece);
|
|
211
|
+
packageTargetNames.push(targetName);
|
|
212
|
+
targets[targetName] = {
|
|
213
|
+
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
214
|
+
cache: true,
|
|
215
|
+
inputs,
|
|
216
|
+
dependsOn: [previous],
|
|
217
|
+
options: {
|
|
218
|
+
command: cargoFrozen(`nextest run --workspace -E '${selector}'${extra} --user-config-file none --config-file ${configFile}`),
|
|
219
|
+
cwd: projectRoot,
|
|
220
|
+
timeoutMs: BOUNDED_TEST_TIMEOUT_MS,
|
|
221
|
+
killAfterMs: BOUNDED_TEST_KILL_AFTER_MS,
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
previous = targetName;
|
|
225
|
+
};
|
|
226
|
+
const shardable = pin === null ? `package(${pkg.name})` : `package(${pkg.name}) and not (${pin})`;
|
|
227
|
+
for (let index = 1; index <= pkg.testShards; index += 1) {
|
|
228
|
+
// nextest hashes the test name, so a shard holds the same tests whatever
|
|
229
|
+
// else the filterset selects and whatever tests are added later.
|
|
230
|
+
addTarget(sharded ? `shard${index}` : undefined, shardable, sharded ? ` --partition hash:${index}/${pkg.testShards}` : '');
|
|
231
|
+
}
|
|
232
|
+
if (pin !== null) {
|
|
233
|
+
addTarget(CARGO_TEST_EXCEPTIONS_SUFFIX, `package(${pkg.name}) and (${pin})`, ' --no-tests=pass');
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return packageTargetNames;
|
|
237
|
+
}
|
|
131
238
|
export const createNodesV2 = [
|
|
132
239
|
'**/package.json',
|
|
133
240
|
async (projectConfigurationFiles, _options, context) => {
|
|
@@ -248,32 +355,75 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
|
|
|
248
355
|
targets['cargo-wasm'] = createCargoWasmTarget(projectRoot, cargoWasmConfig);
|
|
249
356
|
}
|
|
250
357
|
if (napiConfig) {
|
|
251
|
-
|
|
252
|
-
Object.assign(targets, napiTargets.targets);
|
|
358
|
+
Object.assign(targets, createNapiTargets(projectRoot, napiConfig));
|
|
253
359
|
if (!('napi-test' in (packageJson.nx?.targets ?? {})) &&
|
|
254
360
|
existsSync(join(absoluteProjectRoot, 'src/native.test.ts'))) {
|
|
255
|
-
targets['napi-test'] = createNapiTestTarget(projectRoot, existsSync(join(absoluteProjectRoot, 'bunfig.napi-test.toml'))
|
|
361
|
+
targets['napi-test'] = createNapiTestTarget(projectRoot, existsSync(join(absoluteProjectRoot, 'bunfig.napi-test.toml')));
|
|
256
362
|
}
|
|
257
363
|
}
|
|
258
364
|
// Member crates get their targets from the workspace-root package.json,
|
|
259
365
|
// never per-crate — one Nx project per Cargo workspace.
|
|
366
|
+
//
|
|
367
|
+
// Every cargo tool target below is inferred unconditionally, INCLUDING when
|
|
368
|
+
// the package already declares that key in `nx.targets`. Nx merges a
|
|
369
|
+
// package-local declaration over an inference plugin's target one layer
|
|
370
|
+
// later — the precedence order is specified plugins → target defaults →
|
|
371
|
+
// default plugins, and the package.json reader is a default plugin — so a
|
|
372
|
+
// declaration only has to name the fields it changes:
|
|
373
|
+
//
|
|
374
|
+
// - `executor`, `cache`, `inputs`, `outputs`, `dependsOn`: the declared
|
|
375
|
+
// value REPLACES the inferred one, and every field the declaration omits
|
|
376
|
+
// is inherited from here.
|
|
377
|
+
// - `options` and `configurations`: merged key by key with declared keys
|
|
378
|
+
// winning, unless the declaration names a different executor — then its
|
|
379
|
+
// options mean something else and replace them wholesale.
|
|
380
|
+
// - `"dependsOn": ["...", "extra"]` expands the inferred list at the
|
|
381
|
+
// token's position. That is how a package ADDS an edge.
|
|
382
|
+
//
|
|
383
|
+
// Skipping inference for a declared key — what this used to do — is what made
|
|
384
|
+
// a one-line addition catastrophic: `nx.targets['cargo-test'] = { dependsOn:
|
|
385
|
+
// [...] }` left nothing to merge onto, and Nx normalizes a bare `dependsOn`
|
|
386
|
+
// to `executor: nx:noop` with empty options. That is the worst kind of green:
|
|
387
|
+
// `cargo-test` reaches its dependencies and runs no test binary.
|
|
388
|
+
// `checkWorkspaceCargoTestReachabilityPolicy` fails that shape, but the fix is
|
|
389
|
+
// to leave a base for the declaration to land on.
|
|
390
|
+
//
|
|
391
|
+
// The overlay is deliberately NOT re-implemented here. Applying it in this
|
|
392
|
+
// plugin as well would expand a `"..."` spread twice — once against the
|
|
393
|
+
// inferred list here, once when Nx merges the same declaration over this
|
|
394
|
+
// result — duplicating the very edges the spread exists to add.
|
|
395
|
+
//
|
|
396
|
+
// `dependsOn` REPLACES rather than unions. These lists are not a bag of
|
|
397
|
+
// independent wishes; they are the serialization chain that keeps two cargo
|
|
398
|
+
// writers off one flocked `target/` (see CARGO_TEST_COMPILE_TARGET), and their
|
|
399
|
+
// ORDER carries the invariant. A package that must re-route the chain — build
|
|
400
|
+
// its artifact ahead of the test run, or drop `cargo-test-compile` because it
|
|
401
|
+
// compiles differently — can only say so by replacing the list; a union would
|
|
402
|
+
// make every inferred edge unremovable and a corrected order unrepresentable.
|
|
403
|
+
// Additive intent already has a spelling (`"..."` above), so a plugin-local
|
|
404
|
+
// additive key would be a second convention beside a working one.
|
|
405
|
+
//
|
|
406
|
+
// The output families (`cargo-wasm`, `napi-*`) and the `test` aggregate stay
|
|
407
|
+
// all-or-nothing, because for those the package decides whether the target
|
|
408
|
+
// EXISTS — a packaging decision for output families, the bounded-test policy's
|
|
409
|
+
// rewrite for `test` — so there is no inferred base to partially override.
|
|
260
410
|
if (isCargoWorkspace) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
}
|
|
411
|
+
targets[CARGO_TEST_COMPILE_TARGET] = createCargoTestCompileTarget(projectRoot);
|
|
412
|
+
const packageTargetNames = await addPerPackageCargoTestTargets(targets, projectRoot, workspaceRoot, absoluteProjectRoot);
|
|
413
|
+
targets[CARGO_TEST_TARGET] =
|
|
414
|
+
packageTargetNames.length > 0
|
|
415
|
+
? { executor: 'nx:noop', cache: true, dependsOn: packageTargetNames }
|
|
416
|
+
: createCargoTestTarget(projectRoot);
|
|
417
|
+
targets['cargo-lint'] = {
|
|
418
|
+
executor: 'nx:run-commands',
|
|
419
|
+
cache: true,
|
|
420
|
+
inputs: CARGO_INPUTS,
|
|
421
|
+
options: {
|
|
422
|
+
commands: ['cargo fmt --all --check', CARGO_LINT_CLIPPY_COMMAND],
|
|
423
|
+
cwd: projectRoot,
|
|
424
|
+
parallel: false,
|
|
425
|
+
},
|
|
426
|
+
};
|
|
277
427
|
validationTargets.push('cargo-lint');
|
|
278
428
|
// The Linux arm of `cargo-lint`, as its own target. Rationale for the name,
|
|
279
429
|
// the command and the absent cross test leg lives in ./cross-check-policy.ts.
|
|
@@ -293,44 +443,157 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
|
|
|
293
443
|
// see, so it would silently skip projects — today's bug in a new costume. An
|
|
294
444
|
// opt-in flag has the same failure mode by construction. Every Rust project is
|
|
295
445
|
// in scope because CI compiles every Rust project on Linux; a project that
|
|
296
|
-
// genuinely cannot cross-compile overrides the target by declaring it
|
|
297
|
-
// a visible edit to its package.json rather
|
|
446
|
+
// genuinely cannot cross-compile overrides the target by declaring it with
|
|
447
|
+
// `executor: nx:noop`, which is a visible edit to its package.json rather
|
|
448
|
+
// than a silent absence.
|
|
298
449
|
//
|
|
299
450
|
// Deliberately NOT pushed to validationTargets: joining the lint aggregate
|
|
300
451
|
// would make `bun run lint` — and CI's own Linux lint, already native — demand
|
|
301
452
|
// the 0.4 GiB cross toolchain that the devenv profile exists to keep opt-in.
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
453
|
+
targets[CARGO_CROSS_LINT_TARGET] = {
|
|
454
|
+
executor: 'nx:run-commands',
|
|
455
|
+
cache: true,
|
|
456
|
+
inputs: CARGO_INPUTS,
|
|
457
|
+
options: {
|
|
458
|
+
command: CARGO_CROSS_LINT_COMMAND,
|
|
459
|
+
cwd: projectRoot,
|
|
460
|
+
},
|
|
461
|
+
};
|
|
462
|
+
if (!targets.test && !('test' in declaredTargets) && typeof packageJson.scripts?.test !== 'string') {
|
|
463
|
+
targets.test = {
|
|
464
|
+
executor: 'nx:noop',
|
|
305
465
|
cache: true,
|
|
306
|
-
|
|
307
|
-
options: {
|
|
308
|
-
command: CARGO_CROSS_LINT_COMMAND,
|
|
309
|
-
cwd: projectRoot,
|
|
310
|
-
},
|
|
466
|
+
dependsOn: [CARGO_TEST_TARGET],
|
|
311
467
|
};
|
|
312
468
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
469
|
+
// Mutation runs are minutes-to-hours: never cached, never part of build/lint.
|
|
470
|
+
// CI runs these per-PR via `cargo mutants --in-diff` (see mutants.toml docs).
|
|
471
|
+
targets.mutation = {
|
|
472
|
+
executor: 'nx:run-commands',
|
|
473
|
+
cache: false,
|
|
474
|
+
options: { command: cargoFrozen('mutants --workspace'), cwd: projectRoot },
|
|
475
|
+
};
|
|
476
|
+
targets.bench = {
|
|
477
|
+
executor: 'nx:run-commands',
|
|
478
|
+
cache: false,
|
|
479
|
+
options: { command: cargoFrozen('bench --workspace'), cwd: projectRoot },
|
|
480
|
+
};
|
|
481
|
+
// Target-dir GC. Cargo never removes superseded artifacts, so a busy
|
|
482
|
+
// workspace grows tens of GB of stale variants no fingerprint references;
|
|
483
|
+
// sweeping by age prunes exactly that junk while the warm current
|
|
484
|
+
// surface — the gated asset — survives untouched. Never cached: the
|
|
485
|
+
// verdict is about this machine's disk, not the commit.
|
|
486
|
+
targets['cargo-sweep'] = {
|
|
487
|
+
executor: 'nx:run-commands',
|
|
488
|
+
cache: false,
|
|
489
|
+
options: { command: 'cargo sweep --time 7', cwd: projectRoot },
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
// Every `cargoFrozen` command needs a registry cache holding the whole locked
|
|
493
|
+
// graph, and offline cargo checks that at RESOLUTION — so a dev-dependency no
|
|
494
|
+
// build ever downloaded takes down `cargo --frozen build` just as surely as
|
|
495
|
+
// `cargo --frozen test`. On an ephemeral runner the only thing that had been
|
|
496
|
+
// populating that cache was a preceding NON-frozen `napi build`, which
|
|
497
|
+
// downloads normal dependencies and never dev-dependencies; a workspace no
|
|
498
|
+
// platform target reaches got nothing at all. `cargo-fetch` states the
|
|
499
|
+
// precondition instead of inheriting it from another target's side effects.
|
|
500
|
+
//
|
|
501
|
+
// Derived from the command text rather than a curated list of target names:
|
|
502
|
+
// the fact that makes a target need this is that it runs frozen cargo, so a
|
|
503
|
+
// frozen target added later is covered without anyone remembering to. The edge
|
|
504
|
+
// goes on EVERY frozen target, not just the head of the serialization chain,
|
|
505
|
+
// so re-routing that chain cannot strip a surviving target's precondition.
|
|
506
|
+
//
|
|
507
|
+
// A package that REPLACES one of these `dependsOn` lists drops the edge with
|
|
508
|
+
// it (see the merge rules above) and gets its cold-cache failure back; `"..."`
|
|
509
|
+
// keeps it.
|
|
510
|
+
const frozenCargoManifests = new Set();
|
|
511
|
+
if (isCargoWorkspace) {
|
|
512
|
+
frozenCargoManifests.add('Cargo.toml');
|
|
513
|
+
}
|
|
514
|
+
if (inferCargoWasm && cargoWasmConfig) {
|
|
515
|
+
// A wasm-bindgen crate can sit in a nested Cargo workspace the project root
|
|
516
|
+
// is not a member of, so its graph is a second fetch, not the same one.
|
|
517
|
+
frozenCargoManifests.add(cargoWasmConfig.manifestPath);
|
|
518
|
+
}
|
|
519
|
+
if (frozenCargoManifests.size > 0) {
|
|
520
|
+
targets[CARGO_FETCH_TARGET] = {
|
|
521
|
+
executor: 'nx:run-commands',
|
|
522
|
+
// The download lands in CARGO_HOME, outside the workspace: a cache hit
|
|
523
|
+
// would skip work a cold registry still needs — same reason
|
|
524
|
+
// napi-toolchain-* is uncached. Nothing here is a workspace output, so
|
|
525
|
+
// there is nothing for Nx to restore in its place.
|
|
526
|
+
cache: false,
|
|
527
|
+
options: {
|
|
528
|
+
commands: [...frozenCargoManifests]
|
|
529
|
+
.sort()
|
|
530
|
+
.map((manifestPath) => manifestPath === 'Cargo.toml'
|
|
531
|
+
? CARGO_FETCH_COMMAND
|
|
532
|
+
: `${CARGO_FETCH_COMMAND} --manifest-path ${manifestPath}`),
|
|
533
|
+
cwd: projectRoot,
|
|
534
|
+
// Two fetches into one CARGO_HOME contend on its package-cache flock;
|
|
535
|
+
// serializing here spends the wait in Nx instead of inside cargo.
|
|
536
|
+
parallel: false,
|
|
537
|
+
},
|
|
538
|
+
};
|
|
539
|
+
for (const [name, target] of Object.entries(targets)) {
|
|
540
|
+
if (name === CARGO_FETCH_TARGET) {
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
const command = target.options?.command;
|
|
544
|
+
const commands = target.options?.commands;
|
|
545
|
+
const text = [
|
|
546
|
+
typeof command === 'string' ? command : '',
|
|
547
|
+
...(Array.isArray(commands) ? commands.filter((entry) => typeof entry === 'string') : []),
|
|
548
|
+
].join('\n');
|
|
549
|
+
if (!text.includes(CARGO_FROZEN_PREFIX)) {
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
const dependsOn = target.dependsOn ?? [];
|
|
553
|
+
if (!dependsOn.includes(CARGO_FETCH_TARGET)) {
|
|
554
|
+
target.dependsOn = [CARGO_FETCH_TARGET, ...dependsOn];
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
// Cargo flocks the package's default `target/`. Writers that share it must
|
|
559
|
+
// not be Nx siblings. Clippy is not in this set: it has its own --target-dir.
|
|
560
|
+
const napiDebug = targets['napi-debug'];
|
|
561
|
+
if (napiDebug && targets[CARGO_TEST_COMPILE_TARGET]) {
|
|
562
|
+
const dependsOn = napiDebug.dependsOn ?? [];
|
|
563
|
+
if (!dependsOn.includes(CARGO_TEST_COMPILE_TARGET)) {
|
|
564
|
+
napiDebug.dependsOn = [...dependsOn, CARGO_TEST_COMPILE_TARGET];
|
|
316
565
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
566
|
+
}
|
|
567
|
+
if (napiDebug) {
|
|
568
|
+
for (const [name, target] of Object.entries(targets)) {
|
|
569
|
+
if (!name.startsWith('cargo-test-') || name === CARGO_TEST_COMPILE_TARGET) {
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
const dependsOn = target.dependsOn ?? [];
|
|
573
|
+
if (dependsOn.includes(CARGO_TEST_COMPILE_TARGET) && !dependsOn.includes('napi-debug')) {
|
|
574
|
+
target.dependsOn = dependsOn.map((dep) => (dep === CARGO_TEST_COMPILE_TARGET ? 'napi-debug' : dep));
|
|
575
|
+
}
|
|
325
576
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
577
|
+
const cargoTest = targets[CARGO_TEST_TARGET];
|
|
578
|
+
if (cargoTest?.options &&
|
|
579
|
+
typeof cargoTest.options.command === 'string' &&
|
|
580
|
+
cargoTest.options.command.startsWith('cargo ')) {
|
|
581
|
+
const dependsOn = cargoTest.dependsOn ?? [];
|
|
582
|
+
if (!dependsOn.includes('napi-debug')) {
|
|
583
|
+
cargoTest.dependsOn = [...dependsOn, 'napi-debug'];
|
|
584
|
+
}
|
|
332
585
|
}
|
|
333
586
|
}
|
|
587
|
+
// No `outputs`, deliberately: this aggregate runs no command, so every file
|
|
588
|
+
// under dist belongs to the concrete target that emitted it. Claiming
|
|
589
|
+
// `{projectRoot}/dist` here would cache the children's bytes a second time
|
|
590
|
+
// under the aggregate's hash, and would make `smoo github-ci nx-run-many
|
|
591
|
+
// --collect-outputs` attribute to `build` whatever sits under dist — including
|
|
592
|
+
// platform-target artifacts the collect excludes on purpose and stale
|
|
593
|
+
// artifacts of targets that never ran. Two collected trees then claim one
|
|
594
|
+
// binary and `apply-outputs` rejects the overlap. `lint` and `test` are
|
|
595
|
+
// aggregates on the same terms. Same reason nx.json must not put `outputs` in
|
|
596
|
+
// targetDefaults.build (see validateBuildTargetDefault).
|
|
334
597
|
if (hasOrdinaryBuildOutputTarget) {
|
|
335
598
|
targets.build = {
|
|
336
599
|
executor: 'nx:noop',
|
|
@@ -513,8 +776,25 @@ function createNapiTargets(projectRoot, config) {
|
|
|
513
776
|
}
|
|
514
777
|
}
|
|
515
778
|
}
|
|
516
|
-
const hostProvider = nativeHostTargetName ?? 'cargo-napi';
|
|
517
779
|
const targets = {};
|
|
780
|
+
// The addon the test suite loads. A dev-profile build shares target/debug
|
|
781
|
+
// with cargo-test's dependency graph, so after the tests compile this is
|
|
782
|
+
// nearly free — where the release platform build it replaces cost minutes
|
|
783
|
+
// and sat alone on the test critical path. The output lives OUTSIDE dist/
|
|
784
|
+
// because packages publish `files: ["dist"]` wholesale: a debug addon under
|
|
785
|
+
// dist/ would ship. native.ts resolves this directory only when the
|
|
786
|
+
// napi-test target sets NAPI_DEBUG_ADDON=1, so production loads never see it.
|
|
787
|
+
targets['napi-debug'] = {
|
|
788
|
+
executor: 'nx:run-commands',
|
|
789
|
+
cache: true,
|
|
790
|
+
dependsOn: ['^build'],
|
|
791
|
+
inputs: NAPI_INPUTS,
|
|
792
|
+
outputs: ['{projectRoot}/.cache/native-debug'],
|
|
793
|
+
options: {
|
|
794
|
+
cwd: projectRoot,
|
|
795
|
+
command: `napi build --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir .cache/native-debug`,
|
|
796
|
+
},
|
|
797
|
+
};
|
|
518
798
|
if (nativeHostTargetName === null) {
|
|
519
799
|
// The platform target for this host triple is the same compilation, so a
|
|
520
800
|
// second cargo-napi invocation only buys a duplicate dependency graph in
|
|
@@ -575,14 +855,18 @@ function createNapiTargets(projectRoot, config) {
|
|
|
575
855
|
},
|
|
576
856
|
};
|
|
577
857
|
}
|
|
578
|
-
return
|
|
858
|
+
return targets;
|
|
579
859
|
}
|
|
580
|
-
function createNapiTestTarget(projectRoot, hasDedicatedBunfig
|
|
860
|
+
function createNapiTestTarget(projectRoot, hasDedicatedBunfig) {
|
|
581
861
|
const configFlag = hasDedicatedBunfig ? ' --config=../bunfig.napi-test.toml' : ' --config=../bunfig.toml';
|
|
582
862
|
return {
|
|
583
863
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
584
864
|
cache: true,
|
|
585
|
-
|
|
865
|
+
// Deliberately NOT `build`: the aggregate drags the host-platform release
|
|
866
|
+
// binaries onto the test critical path, and the tests assert behavior, not
|
|
867
|
+
// optimization level. tsc-js supplies dist/ts for the suite's own imports;
|
|
868
|
+
// napi-debug supplies the addon.
|
|
869
|
+
dependsOn: ['cargo-test', 'napi-debug', 'tsc-js', '^build'],
|
|
586
870
|
options: {
|
|
587
871
|
// cwd is src/, not the package root: `bun test <arg>` treats the arg as a
|
|
588
872
|
// FILTER and scans the whole cwd tree for test files, and a Rust
|
|
@@ -591,6 +875,9 @@ function createNapiTestTarget(projectRoot, hasDedicatedBunfig, hostProvider) {
|
|
|
591
875
|
// config is passed explicitly.
|
|
592
876
|
command: `bun test${configFlag} --timeout=30000 native.test.ts`,
|
|
593
877
|
cwd: `${projectRoot}/src`,
|
|
878
|
+
// Routes the package's native loader to the napi-debug artifact under
|
|
879
|
+
// .cache/native-debug instead of the packaged dist/native tree.
|
|
880
|
+
env: { NAPI_DEBUG_ADDON: '1' },
|
|
594
881
|
timeoutMs: 120000,
|
|
595
882
|
killAfterMs: 10000,
|
|
596
883
|
},
|
|
@@ -27,9 +27,10 @@ export declare function checkPackageTargetPolicyTree(tree: Tree, options?: Packa
|
|
|
27
27
|
* Returns whether anything changed.
|
|
28
28
|
*/
|
|
29
29
|
export declare function applyPackageTargetPolicyTree(tree: Tree, options?: PackageTargetPolicyOptions): boolean;
|
|
30
|
-
export declare function checkPackageTargets(pkg: Record<string, unknown>, packagePath: string, resolvedTargets?: ReadonlySet<string>): NxPolicyIssue[];
|
|
30
|
+
export declare function checkPackageTargets(pkg: Record<string, unknown>, packagePath: string, resolvedTargets?: ReadonlySet<string>, projectNames?: ReadonlySet<string>): NxPolicyIssue[];
|
|
31
31
|
export declare function applyPackageTargets(pkg: Record<string, unknown>, packagePath: string, workspaceNames: ReadonlySet<string>, options?: {
|
|
32
32
|
resolvedTargets?: ReadonlySet<string>;
|
|
33
|
+
projectNames?: ReadonlySet<string>;
|
|
33
34
|
}): boolean;
|
|
34
35
|
export declare function checkPackageTargetPolicy(root: string, options?: PackageTargetPolicyOptions): NxPolicyIssue[];
|
|
35
36
|
export declare function applyPackageTargetPolicy(root: string, options?: PackageTargetPolicyOptions): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-target-policy.d.ts","sourceRoot":"","sources":["../src/package-target-policy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyB,KAAK,IAAI,EAAc,MAAM,0BAA0B,CAAC;AAGxF,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAChG,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7B,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,kBAAkB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;IAC5D,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACvE,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,0BAA0B;IACzC,wBAAwB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,sBAAsB,CAAC,CAAC;CAC9F;AA0HD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAGhF;
|
|
1
|
+
{"version":3,"file":"package-target-policy.d.ts","sourceRoot":"","sources":["../src/package-target-policy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyB,KAAK,IAAI,EAAc,MAAM,0BAA0B,CAAC;AAGxF,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAChG,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7B,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,kBAAkB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;IAC5D,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACvE,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,0BAA0B;IACzC,wBAAwB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,sBAAsB,CAAC,CAAC;CAC9F;AA0HD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAGhF;AA6LD,wBAAgB,UAAU,CACxB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,OAAO,EACnB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,MAAM,CAMR;AA+nBD;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,0BAA+B,GAAG,aAAa,EAAE,CAsBlH;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA8B1G;AAwJD,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,EACrC,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GACjC,aAAa,EAAE,CAEjB;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,EACnC,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAAC,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAO,GAC1F,OAAO,CAMT;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,aAAa,EAAE,CAoBhH;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA8BxG"}
|