@smoothbricks/nx-plugin 0.4.14 → 0.4.15
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 +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -23
- package/dist/package-target-policy.d.ts +0 -1
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +50 -23
- package/dist/workspace-config-policy.d.ts +21 -0
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +27 -0
- package/package.json +1 -1
- package/src/index.test.ts +7 -7
- package/src/index.ts +7 -26
- package/src/package-target-policy.test.ts +4 -28
- package/src/package-target-policy.ts +55 -31
- package/src/workspace-config-policy.ts +33 -0
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ with `tsconfig.lib.json` receives transformer-aware `tsc-js` and native `typeche
|
|
|
10
10
|
`@smoothbricks/nx-plugin` also owns inferred targets Nx does not provide here:
|
|
11
11
|
|
|
12
12
|
- `typecheck-tests` and `typecheck-tests:watch` from `tsconfig.test.json`
|
|
13
|
-
- `test
|
|
13
|
+
- `test-watch` from explicit `test` commands for Bun and Vitest packages
|
|
14
14
|
- Cargo workspace targets from a neighboring workspace-root `Cargo.toml`
|
|
15
15
|
- aggregate `build` and `lint` targets
|
|
16
16
|
- an uncached `deploy` for a PRIVATE project with a wrangler manifest, running
|
|
@@ -171,7 +171,7 @@ Concrete targets come from concrete files:
|
|
|
171
171
|
- `typecheck-tests` is inferred from `tsconfig.test.json` and runs `tsc -p tsconfig.test.json --noEmit`. It first
|
|
172
172
|
rebuilds the current package's `tsc-js` output (or its non-TypeScript `build`) so self-imports resolve after `clean`.
|
|
173
173
|
- `typecheck-tests:watch` is inferred from `tsconfig.test.json` and runs the same typecheck in watch mode.
|
|
174
|
-
- `test
|
|
174
|
+
- `test-watch` is inferred when the package already defines an explicit Bun or Vitest `test` command. The plugin derives
|
|
175
175
|
the corresponding watch command and makes it depend on `typecheck-tests`.
|
|
176
176
|
- A workspace-root `Cargo.toml` provides `cargo-test`, `test`, `cargo-lint`, `mutation`, and `bench`.
|
|
177
177
|
`cargo-test-compile` warms one workspace `cargo test --no-run`. `cargo-test-archive` runs one
|
|
@@ -257,7 +257,7 @@ target such as `nx run pkg:cargo-wasm`.
|
|
|
257
257
|
There is no Nx `lint:fix` target; repository formatting is handled by the root `lint:fix` script.
|
|
258
258
|
|
|
259
259
|
`typecheck-tests` and `typecheck-tests:watch` are inferred only when `tsconfig.test.json` exists. Test typechecking must
|
|
260
|
-
not emit `dist-test`. `test
|
|
260
|
+
not emit `dist-test`. `test-watch` is continuous and depends on `typecheck-tests` before entering Bun or Vitest watch
|
|
261
261
|
mode. Smoo validation creates/requires this config for test runners that do not typecheck test files by default.
|
|
262
262
|
|
|
263
263
|
`tsconfig.test.json` is not a TypeScript build-mode project. It should reference library tsconfigs it needs to typecheck
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAKL,yBAAyB,EAa1B,MAAM,sBAAsB,CAAC;AAiB9B,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAErC,gEAAgE;AAChE,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAKL,yBAAyB,EAa1B,MAAM,sBAAsB,CAAC;AAiB9B,OAAO,EAAE,yBAAyB,EAAE,CAAC;AAErC,gEAAgE;AAChE,eAAO,MAAM,aAAa,WAAW,CAAC;AACtC,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,iBAAiB,CAAC;AA2GlD,KAAK,gBAAgB,GAAG,OAAO,GAAG,KAAK,CAAC;AACxC,KAAK,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1C,UAAU,YAAY;IACpB,YAAY,EAAE,gBAAgB,CAAC;IAC/B,YAAY,EAAE,gBAAgB,CAAC;CAChC;AAmID,UAAU,oBAAqB,SAAQ,YAAY;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB;AA0CD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,oBAAoB,GAAG,MAAM,CAEhF;AAuWD,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,aAAa,CAEvG;AAED,eAAO,MAAM,aAAa,EAAE,aAG3B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -12,13 +12,12 @@ import { attributeCargoWorkspacePackages, CARGO_TEST_ARCHIVE_FILE, CARGO_TEST_AR
|
|
|
12
12
|
import { CARGO_CROSS_LINT_COMMAND, CARGO_CROSS_LINT_TARGET, CARGO_FETCH_COMMAND, CARGO_FETCH_TARGET, CARGO_FROZEN_PREFIX, CARGO_LINT_CLIPPY_COMMAND, cargoCrossTestArchiveFile, cargoCrossTestArchiveTargetName, cargoCrossTestTargetName, cargoFrozen, } from './cross-check-policy.js';
|
|
13
13
|
import { hashVersionlessCrateManifests } from './manifest-hash.js';
|
|
14
14
|
import { isNonSourceDirectory } from './source-directories.js';
|
|
15
|
-
import { PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
15
|
+
import { isBuildOutputTargetName, isTestRunnerTargetName, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
16
16
|
export { CARGO_TEST_COMPILE_TARGET };
|
|
17
17
|
/** Makes a version live and proves it answers; never cached. */
|
|
18
18
|
export const DEPLOY_TARGET = 'deploy';
|
|
19
19
|
/** The purely file-derived half a deploy needs built first; cached. */
|
|
20
20
|
export const DEPLOY_BUILD_TARGET = 'deploy-build';
|
|
21
|
-
const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|android|native|napi|bun|wasm)$/;
|
|
22
21
|
/** The workspace-wide manifests a release rewrites: the version of every member, and the lockfile mirror of it. */
|
|
23
22
|
const RELEASE_REWRITTEN_WORKSPACE_INPUTS = ['{workspaceRoot}/package.json', '{workspaceRoot}/bun.lock'];
|
|
24
23
|
const TYPESCRIPT_TOOLCHAIN_INPUTS = [
|
|
@@ -148,32 +147,17 @@ function hostPlatformTargetNames(targetNames, hostPlatform) {
|
|
|
148
147
|
* its name ends in a family: `*-js`, `*-web`, `*-html`, `*-css`, `*-android`,
|
|
149
148
|
* `*-native`, `*-napi`, `*-bun`, `*-wasm`.
|
|
150
149
|
*
|
|
151
|
-
* Two spellings of the same collision. A per-crate cargo test runner is
|
|
152
|
-
* `cargo-test-<crate>`, so any crate whose name ends in a family put its RUNNER
|
|
153
|
-
* in the aggregate; the runners are one serialized chain, so a single such
|
|
154
|
-
* crate made `build` pull an entire cargo test suite. A bun suite named
|
|
155
|
-
* `test-bun` is the collision without the prefix — a runner reading as
|
|
156
|
-
* "tool=test, output=bun", swept into `build` by suffix alone. That one forced
|
|
157
|
-
* a consumer to hand-declare `build` purely to replace the inferred list.
|
|
158
|
-
*
|
|
159
150
|
* So the rule is the CLASS, not one namespace: a target that RUNS tests is
|
|
160
151
|
* never a build output, however it is spelled. Expanding the families here
|
|
161
|
-
* rather than delegating to Nx's matcher is what makes that expressible
|
|
152
|
+
* rather than delegating to Nx's matcher is what makes that expressible, and
|
|
153
|
+
* `package-target-policy` reads the same two predicates to decide whether a
|
|
154
|
+
* hand-declared aggregate is naming an edge this list already produces.
|
|
162
155
|
*/
|
|
163
156
|
function buildOutputTargetNames(targetNames) {
|
|
164
157
|
return [...new Set(targetNames)]
|
|
165
|
-
.filter((name) =>
|
|
158
|
+
.filter((name) => isBuildOutputTargetName(name) && !isTestRunnerTargetName(name))
|
|
166
159
|
.sort();
|
|
167
160
|
}
|
|
168
|
-
/**
|
|
169
|
-
* A target whose job is to RUN tests. `test`, anything under `test-`/`test:`,
|
|
170
|
-
* and the plugin's own `cargo-test-<crate>` namespace. Deliberately name-based:
|
|
171
|
-
* the aggregate is assembled from declared AND inferred target names, and a
|
|
172
|
-
* declaration carries no marker saying "this executes rather than emits".
|
|
173
|
-
*/
|
|
174
|
-
function isTestRunnerTargetName(name) {
|
|
175
|
-
return (name === 'test' || name.startsWith('test-') || name.startsWith('test:') || name.startsWith(`${CARGO_TEST_TARGET}-`));
|
|
176
|
-
}
|
|
177
161
|
//#region smoo!n/rust-output-target-inference
|
|
178
162
|
// Cargo workspace inference: a package.json sitting next to a Cargo.toml that
|
|
179
163
|
// declares [workspace] gets direct cargo-test/test targets, cargo-lint feeding
|
|
@@ -761,7 +745,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot, hostPlatform
|
|
|
761
745
|
};
|
|
762
746
|
const inferredTestWatchCommand = inferTestWatchCommand(packageJson);
|
|
763
747
|
if (inferredTestWatchCommand) {
|
|
764
|
-
targets['test
|
|
748
|
+
targets['test-watch'] = {
|
|
765
749
|
executor: 'nx:run-commands',
|
|
766
750
|
continuous: true,
|
|
767
751
|
dependsOn: ['typecheck-tests'],
|
|
@@ -1715,7 +1699,7 @@ function classifyPackageLocalBuildOutputs(packageJson) {
|
|
|
1715
1699
|
const targets = packageJson.nx?.targets;
|
|
1716
1700
|
const targetNames = isRecord(targets) ? Object.keys(targets) : [];
|
|
1717
1701
|
return {
|
|
1718
|
-
ordinary: targetNames.some(
|
|
1702
|
+
ordinary: targetNames.some(isBuildOutputTargetName),
|
|
1719
1703
|
platform: targetNames.some((targetName) => PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1)))),
|
|
1720
1704
|
};
|
|
1721
1705
|
}
|
|
@@ -5,7 +5,6 @@ export type { NxPolicyIssue };
|
|
|
5
5
|
export interface ResolvedProjectTargets {
|
|
6
6
|
root?: string;
|
|
7
7
|
targets: ReadonlySet<string>;
|
|
8
|
-
buildDependsOn?: readonly string[];
|
|
9
8
|
targetDependencies?: ReadonlyMap<string, readonly string[]>;
|
|
10
9
|
targetExecutors?: ReadonlyMap<string, string>;
|
|
11
10
|
targetOptions?: ReadonlyMap<string, Readonly<Record<string, unknown>>>;
|
|
@@ -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;AAIxF,OAAO,
|
|
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;AAIxF,OAAO,EAML,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,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;AAoND,wBAAgB,UAAU,CACxB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,OAAO,EACnB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,MAAM,CAMR;AAgoBD;;;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"}
|
|
@@ -3,7 +3,7 @@ import { join } from 'node:path';
|
|
|
3
3
|
import { getProjects, readJson, updateJson } from 'nx/src/devkit-exports.js';
|
|
4
4
|
import { boundedTestScriptAlias } from './bounded-test-policy.js';
|
|
5
5
|
import { isNonSourceDirectory } from './source-directories.js';
|
|
6
|
-
import { BUILD_OUTPUT_DEPENDENCIES, LINUX_PLATFORM_TARGET_GLOBS, MACOS_PLATFORM_TARGET_GLOBS, } from './workspace-config-policy.js';
|
|
6
|
+
import { BUILD_OUTPUT_DEPENDENCIES, isBuildOutputTargetName, isTestRunnerTargetName, LINUX_PLATFORM_TARGET_GLOBS, MACOS_PLATFORM_TARGET_GLOBS, } from './workspace-config-policy.js';
|
|
7
7
|
export { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
8
8
|
const workspaceDependencyFields = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
|
|
9
9
|
function isRecord(value) {
|
|
@@ -126,12 +126,6 @@ function resolvedProjectTargetNames(resolvedProject) {
|
|
|
126
126
|
}
|
|
127
127
|
return isResolvedProjectTargets(resolvedProject) ? resolvedProject.targets : resolvedProject;
|
|
128
128
|
}
|
|
129
|
-
function resolvedProjectBuildDependsOn(resolvedProject) {
|
|
130
|
-
if (!isResolvedProjectTargets(resolvedProject)) {
|
|
131
|
-
return undefined;
|
|
132
|
-
}
|
|
133
|
-
return resolvedProject.buildDependsOn;
|
|
134
|
-
}
|
|
135
129
|
function resolvedProjectTargetExecutor(resolvedProject, targetName) {
|
|
136
130
|
return isResolvedProjectTargets(resolvedProject) ? resolvedProject.targetExecutors?.get(targetName) : undefined;
|
|
137
131
|
}
|
|
@@ -198,34 +192,67 @@ function isNoopTarget(target) {
|
|
|
198
192
|
const options = recordProperty(target, 'options');
|
|
199
193
|
return !options || stringProperty(options, 'command') === null;
|
|
200
194
|
}
|
|
201
|
-
|
|
202
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Properties the inferred aggregate already sets to exactly these values. A
|
|
197
|
+
* declaration carrying anything else — `inputs`, `outputs`, `cache: false`, a
|
|
198
|
+
* `configurations` block — is CHANGING the aggregate, not restating it.
|
|
199
|
+
*/
|
|
200
|
+
const inferredNoopBuildProperties = { executor: true, cache: true, dependsOn: true };
|
|
201
|
+
/**
|
|
202
|
+
* Can the build-aggregate inference produce this edge on its own?
|
|
203
|
+
*
|
|
204
|
+
* The inferred aggregate is `^build` plus the project's own build-output
|
|
205
|
+
* targets — `isBuildOutputTargetName`, test runners excluded — and
|
|
206
|
+
* `BUILD_OUTPUT_DEPENDENCIES` is the glob spelling of that same list. Anything
|
|
207
|
+
* else is an edge only the declaration carries: a project-local target outside
|
|
208
|
+
* the families (`build-cli`), or a `project:target` edge to a sibling target
|
|
209
|
+
* that is not named `build`, which `^build` never visits.
|
|
210
|
+
*/
|
|
211
|
+
function isInferredBuildDependency(dependency, resolvedTargets) {
|
|
212
|
+
if (typeof dependency !== 'string') {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
if (dependency === '^build' || isBuildOutputDependencyPattern(dependency)) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
return isBuildOutputTargetName(dependency) && !isTestRunnerTargetName(dependency) && resolvedTargets.has(dependency);
|
|
219
|
+
}
|
|
220
|
+
function isRedundantBuildDeclaration(build, resolvedTargets) {
|
|
221
|
+
if (!Object.keys(build).every((key) => inferredNoopBuildProperties[key] === true)) {
|
|
203
222
|
return false;
|
|
204
223
|
}
|
|
205
|
-
|
|
206
|
-
if (target.dependsOn.length !== expected.size) {
|
|
224
|
+
if ('cache' in build && build.cache !== true) {
|
|
207
225
|
return false;
|
|
208
226
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
});
|
|
227
|
+
// An empty list is a deliberate cut — "this aggregate waits for nothing" —
|
|
228
|
+
// and restoring the inferred edges by deleting it is a behaviour change.
|
|
229
|
+
return (Array.isArray(build.dependsOn) &&
|
|
230
|
+
build.dependsOn.length > 0 &&
|
|
231
|
+
build.dependsOn.every((dependency) => isInferredBuildDependency(dependency, resolvedTargets)));
|
|
215
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* A hand-declared `build` is deleted only when inference provably rebuilds it.
|
|
235
|
+
*
|
|
236
|
+
* Deliberately NOT decided against the resolved project graph. Nx replaces a
|
|
237
|
+
* named property of an inferred target with the declared one, so the resolved
|
|
238
|
+
* `build.dependsOn` IS the declaration: comparing them answered "redundant"
|
|
239
|
+
* for every noop aggregate anyone ever wrote. AxE's `containium` lost seven
|
|
240
|
+
* edges that way — four of them targets no inference can reach — and a clean
|
|
241
|
+
* checkout then built it without its producers. The question this has to
|
|
242
|
+
* answer is what inference yields WITHOUT the declaration, so the test is
|
|
243
|
+
* structural: every declared edge must be one the aggregate already collects.
|
|
244
|
+
*/
|
|
216
245
|
function removeRedundantNoopBuildTarget(pkg, resolvedProject) {
|
|
217
246
|
const resolvedTargets = resolvedProjectTargetNames(resolvedProject);
|
|
218
|
-
|
|
219
|
-
|
|
247
|
+
// No build-output target in the project, no inferred aggregate to fall back
|
|
248
|
+
// on: deleting the declaration would leave it with no `build` at all.
|
|
249
|
+
if (!resolvedTargets?.has('build') || ![...resolvedTargets].some(isBuildOutputTargetName)) {
|
|
220
250
|
return false;
|
|
221
251
|
}
|
|
222
252
|
const nx = recordProperty(pkg, 'nx');
|
|
223
253
|
const targets = nx ? recordProperty(nx, 'targets') : null;
|
|
224
254
|
const build = targets ? recordProperty(targets, 'build') : null;
|
|
225
|
-
if (!targets ||
|
|
226
|
-
!build ||
|
|
227
|
-
!isNoopTarget(build) ||
|
|
228
|
-
!targetDependenciesMatchResolvedBuild(build, resolvedBuildDependsOn)) {
|
|
255
|
+
if (!targets || !build || !isNoopTarget(build) || !isRedundantBuildDeclaration(build, resolvedTargets)) {
|
|
229
256
|
return false;
|
|
230
257
|
}
|
|
231
258
|
delete targets.build;
|
|
@@ -7,6 +7,27 @@ export declare const BUILD_OUTPUT_DEPENDENCIES: readonly ['*-js', '*-web', '*-ht
|
|
|
7
7
|
export declare const MACOS_PLATFORM_TARGET_GLOBS: readonly ['*-macos', '*-ios'];
|
|
8
8
|
export declare const LINUX_PLATFORM_TARGET_GLOBS: readonly ['*-linux'];
|
|
9
9
|
export declare const PLATFORM_TARGET_GLOBS: readonly ["*-macos", "*-ios", "*-linux"];
|
|
10
|
+
/**
|
|
11
|
+
* The glob list above, spelled as a target name: a target whose name ends in a
|
|
12
|
+
* reserved family suffix EMITS that kind of artifact. Inference collects
|
|
13
|
+
* exactly these names into the `nx:noop` build aggregate, which makes this the
|
|
14
|
+
* same rule that decides whether a hand-declared aggregate names an edge
|
|
15
|
+
* inference could have produced on its own — one definition, two readers, so
|
|
16
|
+
* the removal policy cannot drift away from what it judges redundant.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isBuildOutputTargetName(name: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* A target whose job is to RUN tests. `test`, anything under `test-`/`test:`,
|
|
21
|
+
* and the plugin's own `cargo-test-<crate>` namespace. Deliberately name-based:
|
|
22
|
+
* the aggregate is assembled from declared AND inferred target names, and a
|
|
23
|
+
* declaration carries no marker saying "this executes rather than emits".
|
|
24
|
+
*
|
|
25
|
+
* A runner collides with the families by construction whenever its name ends in
|
|
26
|
+
* one: a crate named `…-js` puts `cargo-test-<crate>` in the family, and a bun
|
|
27
|
+
* suite named `test-bun` reads as "tool=test, output=bun". Both would drag a
|
|
28
|
+
* test suite into `build`, so the rule is the CLASS, not one namespace.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isTestRunnerTargetName(name: string): boolean;
|
|
10
31
|
/**
|
|
11
32
|
* Check workspace config policy on an in-memory nx.json object.
|
|
12
33
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-config-policy.d.ts","sourceRoot":"","sources":["../src/workspace-config-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"workspace-config-policy.d.ts","sourceRoot":"","sources":["../src/workspace-config-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAKrD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,yBAAyB,YACpC,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,WAAW,EACX,UAAU,EACV,QAAQ,EACR,OAAO,EACP,QAAQ,CACA,CAAC;AAEX,eAAO,MAAM,2BAA2B,YAAI,SAAS,EAAE,OAAO,CAAU,CAAC;AACzE,eAAO,MAAM,2BAA2B,YAAI,SAAS,CAAU,CAAC;AAChE,eAAO,MAAM,qBAAqB,0CAA4E,CAAC;AAI/G;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAI5D;AAgBD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,EAAE,CA4DrF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAe7E;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,EAAE,CAKpE;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAU5D;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAYxE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAWhE"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { readJson, updateJson } from 'nx/src/devkit-exports.js';
|
|
4
|
+
import { CARGO_TEST_TARGET } from './cargo-workspace.js';
|
|
4
5
|
export const BUILD_OUTPUT_DEPENDENCIES = [
|
|
5
6
|
'*-js',
|
|
6
7
|
'*-web',
|
|
@@ -15,6 +16,32 @@ export const BUILD_OUTPUT_DEPENDENCIES = [
|
|
|
15
16
|
export const MACOS_PLATFORM_TARGET_GLOBS = ['*-macos', '*-ios'];
|
|
16
17
|
export const LINUX_PLATFORM_TARGET_GLOBS = ['*-linux'];
|
|
17
18
|
export const PLATFORM_TARGET_GLOBS = [...MACOS_PLATFORM_TARGET_GLOBS, ...LINUX_PLATFORM_TARGET_GLOBS];
|
|
19
|
+
const buildOutputTargetSuffixes = BUILD_OUTPUT_DEPENDENCIES.map((glob) => glob.slice(1));
|
|
20
|
+
/**
|
|
21
|
+
* The glob list above, spelled as a target name: a target whose name ends in a
|
|
22
|
+
* reserved family suffix EMITS that kind of artifact. Inference collects
|
|
23
|
+
* exactly these names into the `nx:noop` build aggregate, which makes this the
|
|
24
|
+
* same rule that decides whether a hand-declared aggregate names an edge
|
|
25
|
+
* inference could have produced on its own — one definition, two readers, so
|
|
26
|
+
* the removal policy cannot drift away from what it judges redundant.
|
|
27
|
+
*/
|
|
28
|
+
export function isBuildOutputTargetName(name) {
|
|
29
|
+
return buildOutputTargetSuffixes.some((suffix) => name.endsWith(suffix));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A target whose job is to RUN tests. `test`, anything under `test-`/`test:`,
|
|
33
|
+
* and the plugin's own `cargo-test-<crate>` namespace. Deliberately name-based:
|
|
34
|
+
* the aggregate is assembled from declared AND inferred target names, and a
|
|
35
|
+
* declaration carries no marker saying "this executes rather than emits".
|
|
36
|
+
*
|
|
37
|
+
* A runner collides with the families by construction whenever its name ends in
|
|
38
|
+
* one: a crate named `…-js` puts `cargo-test-<crate>` in the family, and a bun
|
|
39
|
+
* suite named `test-bun` reads as "tool=test, output=bun". Both would drag a
|
|
40
|
+
* test suite into `build`, so the rule is the CLASS, not one namespace.
|
|
41
|
+
*/
|
|
42
|
+
export function isTestRunnerTargetName(name) {
|
|
43
|
+
return (name === 'test' || name.startsWith('test-') || name.startsWith('test:') || name.startsWith(`${CARGO_TEST_TARGET}-`));
|
|
44
|
+
}
|
|
18
45
|
const nxJsTypescriptPlugin = '@nx/js/typescript';
|
|
19
46
|
const smoothBricksNxPlugin = '@smoothbricks/nx-plugin';
|
|
20
47
|
const cleanOutputsExecutor = '@smoothbricks/nx-plugin:clean-outputs';
|
package/package.json
CHANGED
package/src/index.test.ts
CHANGED
|
@@ -250,10 +250,10 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
250
250
|
cwd: 'packages/example',
|
|
251
251
|
});
|
|
252
252
|
|
|
253
|
-
expect(targets['test
|
|
254
|
-
expect(targets['test
|
|
255
|
-
expect(targets['test
|
|
256
|
-
expect(targets['test
|
|
253
|
+
expect(targets['test-watch']?.executor).toBe('nx:run-commands');
|
|
254
|
+
expect(targets['test-watch']?.continuous).toBe(true);
|
|
255
|
+
expect(targets['test-watch']?.dependsOn).toEqual(['typecheck-tests']);
|
|
256
|
+
expect(targets['test-watch']?.options).toMatchObject({
|
|
257
257
|
command: 'bun test --watch --pass-with-no-tests',
|
|
258
258
|
cwd: 'packages/example',
|
|
259
259
|
});
|
|
@@ -437,8 +437,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
437
437
|
|
|
438
438
|
const targets = await inferProjectTargets(workspace, 'packages/example/package.json');
|
|
439
439
|
|
|
440
|
-
expect(targets['test
|
|
441
|
-
expect(targets['test
|
|
440
|
+
expect(targets['test-watch']?.continuous).toBe(true);
|
|
441
|
+
expect(targets['test-watch']?.options).toMatchObject({
|
|
442
442
|
command: 'vitest --coverage',
|
|
443
443
|
cwd: 'packages/example',
|
|
444
444
|
});
|
|
@@ -480,7 +480,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
480
480
|
// sweep it into `build`, which is a serialized test suite behind
|
|
481
481
|
// every consumer's build.
|
|
482
482
|
'test-bun': { executor: 'nx:run-commands' },
|
|
483
|
-
'test
|
|
483
|
+
'test-watch': { executor: 'nx:run-commands' },
|
|
484
484
|
// A real emitter in the same family, to prove the exclusion is
|
|
485
485
|
// the test-runner class and not the family itself.
|
|
486
486
|
'bundle-bun': { executor: 'nx:run-commands' },
|
package/src/index.ts
CHANGED
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
} from './cross-check-policy.js';
|
|
50
50
|
import { hashVersionlessCrateManifests } from './manifest-hash.js';
|
|
51
51
|
import { isNonSourceDirectory } from './source-directories.js';
|
|
52
|
-
import { PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
52
|
+
import { isBuildOutputTargetName, isTestRunnerTargetName, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
53
53
|
|
|
54
54
|
export { CARGO_TEST_COMPILE_TARGET };
|
|
55
55
|
|
|
@@ -58,7 +58,6 @@ export const DEPLOY_TARGET = 'deploy';
|
|
|
58
58
|
/** The purely file-derived half a deploy needs built first; cached. */
|
|
59
59
|
export const DEPLOY_BUILD_TARGET = 'deploy-build';
|
|
60
60
|
|
|
61
|
-
const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|android|native|napi|bun|wasm)$/;
|
|
62
61
|
/** The workspace-wide manifests a release rewrites: the version of every member, and the lockfile mirror of it. */
|
|
63
62
|
const RELEASE_REWRITTEN_WORKSPACE_INPUTS = ['{workspaceRoot}/package.json', '{workspaceRoot}/bun.lock'];
|
|
64
63
|
const TYPESCRIPT_TOOLCHAIN_INPUTS = [
|
|
@@ -204,36 +203,18 @@ function hostPlatformTargetNames(targetNames: Iterable<string>, hostPlatform: Na
|
|
|
204
203
|
* its name ends in a family: `*-js`, `*-web`, `*-html`, `*-css`, `*-android`,
|
|
205
204
|
* `*-native`, `*-napi`, `*-bun`, `*-wasm`.
|
|
206
205
|
*
|
|
207
|
-
* Two spellings of the same collision. A per-crate cargo test runner is
|
|
208
|
-
* `cargo-test-<crate>`, so any crate whose name ends in a family put its RUNNER
|
|
209
|
-
* in the aggregate; the runners are one serialized chain, so a single such
|
|
210
|
-
* crate made `build` pull an entire cargo test suite. A bun suite named
|
|
211
|
-
* `test-bun` is the collision without the prefix — a runner reading as
|
|
212
|
-
* "tool=test, output=bun", swept into `build` by suffix alone. That one forced
|
|
213
|
-
* a consumer to hand-declare `build` purely to replace the inferred list.
|
|
214
|
-
*
|
|
215
206
|
* So the rule is the CLASS, not one namespace: a target that RUNS tests is
|
|
216
207
|
* never a build output, however it is spelled. Expanding the families here
|
|
217
|
-
* rather than delegating to Nx's matcher is what makes that expressible
|
|
208
|
+
* rather than delegating to Nx's matcher is what makes that expressible, and
|
|
209
|
+
* `package-target-policy` reads the same two predicates to decide whether a
|
|
210
|
+
* hand-declared aggregate is naming an edge this list already produces.
|
|
218
211
|
*/
|
|
219
212
|
function buildOutputTargetNames(targetNames: Iterable<string>): string[] {
|
|
220
213
|
return [...new Set(targetNames)]
|
|
221
|
-
.filter((name) =>
|
|
214
|
+
.filter((name) => isBuildOutputTargetName(name) && !isTestRunnerTargetName(name))
|
|
222
215
|
.sort();
|
|
223
216
|
}
|
|
224
217
|
|
|
225
|
-
/**
|
|
226
|
-
* A target whose job is to RUN tests. `test`, anything under `test-`/`test:`,
|
|
227
|
-
* and the plugin's own `cargo-test-<crate>` namespace. Deliberately name-based:
|
|
228
|
-
* the aggregate is assembled from declared AND inferred target names, and a
|
|
229
|
-
* declaration carries no marker saying "this executes rather than emits".
|
|
230
|
-
*/
|
|
231
|
-
function isTestRunnerTargetName(name: string): boolean {
|
|
232
|
-
return (
|
|
233
|
-
name === 'test' || name.startsWith('test-') || name.startsWith('test:') || name.startsWith(`${CARGO_TEST_TARGET}-`)
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
218
|
//#region smoo!n/rust-output-target-inference
|
|
238
219
|
// Cargo workspace inference: a package.json sitting next to a Cargo.toml that
|
|
239
220
|
// declares [workspace] gets direct cargo-test/test targets, cargo-lint feeding
|
|
@@ -954,7 +935,7 @@ async function createProjectTargets(
|
|
|
954
935
|
};
|
|
955
936
|
const inferredTestWatchCommand = inferTestWatchCommand(packageJson);
|
|
956
937
|
if (inferredTestWatchCommand) {
|
|
957
|
-
targets['test
|
|
938
|
+
targets['test-watch'] = {
|
|
958
939
|
executor: 'nx:run-commands',
|
|
959
940
|
continuous: true,
|
|
960
941
|
dependsOn: ['typecheck-tests'],
|
|
@@ -2041,7 +2022,7 @@ function classifyPackageLocalBuildOutputs(packageJson: PackageJson): { ordinary:
|
|
|
2041
2022
|
const targets = packageJson.nx?.targets;
|
|
2042
2023
|
const targetNames = isRecord(targets) ? Object.keys(targets) : [];
|
|
2043
2024
|
return {
|
|
2044
|
-
ordinary: targetNames.some(
|
|
2025
|
+
ordinary: targetNames.some(isBuildOutputTargetName),
|
|
2045
2026
|
platform: targetNames.some((targetName) =>
|
|
2046
2027
|
PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1))),
|
|
2047
2028
|
),
|
|
@@ -175,13 +175,7 @@ describe('package target policy', () => {
|
|
|
175
175
|
});
|
|
176
176
|
|
|
177
177
|
const resolvedTargetsByProject = new Map<string, ResolvedProjectTargets>([
|
|
178
|
-
[
|
|
179
|
-
'lib',
|
|
180
|
-
{
|
|
181
|
-
targets: new Set(['build', 'tsc-js']),
|
|
182
|
-
buildDependsOn: ['^build', '*-js'],
|
|
183
|
-
},
|
|
184
|
-
],
|
|
178
|
+
['lib', { targets: new Set(['build', 'tsc-js']) }],
|
|
185
179
|
]);
|
|
186
180
|
|
|
187
181
|
expect(applyPackageTargetPolicy(root, { resolvedTargetsByProject })).toBe(true);
|
|
@@ -216,13 +210,7 @@ describe('package target policy', () => {
|
|
|
216
210
|
});
|
|
217
211
|
|
|
218
212
|
const resolvedTargetsByProject = new Map<string, ResolvedProjectTargets>([
|
|
219
|
-
[
|
|
220
|
-
'lib',
|
|
221
|
-
{
|
|
222
|
-
targets: new Set(['build', 'tsc-js']),
|
|
223
|
-
buildDependsOn: ['^build', '*-js'],
|
|
224
|
-
},
|
|
225
|
-
],
|
|
213
|
+
['lib', { targets: new Set(['build', 'tsc-js']) }],
|
|
226
214
|
]);
|
|
227
215
|
|
|
228
216
|
expect(applyPackageTargetPolicy(root, { resolvedTargetsByProject })).toBe(false);
|
|
@@ -911,13 +899,7 @@ describe('applyPackageTargetPolicyTree', () => {
|
|
|
911
899
|
});
|
|
912
900
|
|
|
913
901
|
const resolvedTargetsByProject = new Map<string, ResolvedProjectTargets>([
|
|
914
|
-
[
|
|
915
|
-
'lib',
|
|
916
|
-
{
|
|
917
|
-
targets: new Set(['build', 'tsc-js']),
|
|
918
|
-
buildDependsOn: ['^build', '*-js'],
|
|
919
|
-
},
|
|
920
|
-
],
|
|
902
|
+
['lib', { targets: new Set(['build', 'tsc-js']) }],
|
|
921
903
|
]);
|
|
922
904
|
|
|
923
905
|
expect(applyPackageTargetPolicyTree(tree, { resolvedTargetsByProject })).toBe(true);
|
|
@@ -943,13 +925,7 @@ describe('applyPackageTargetPolicyTree', () => {
|
|
|
943
925
|
});
|
|
944
926
|
|
|
945
927
|
const resolvedTargetsByProject = new Map<string, ResolvedProjectTargets>([
|
|
946
|
-
[
|
|
947
|
-
'lib',
|
|
948
|
-
{
|
|
949
|
-
targets: new Set(['build', 'tsc-js']),
|
|
950
|
-
buildDependsOn: ['^build', '*-js'],
|
|
951
|
-
},
|
|
952
|
-
],
|
|
928
|
+
['lib', { targets: new Set(['build', 'tsc-js']) }],
|
|
953
929
|
]);
|
|
954
930
|
|
|
955
931
|
expect(applyPackageTargetPolicyTree(tree, { resolvedTargetsByProject })).toBe(false);
|
|
@@ -7,6 +7,8 @@ import { boundedTestScriptAlias } from './bounded-test-policy.js';
|
|
|
7
7
|
import { isNonSourceDirectory } from './source-directories.js';
|
|
8
8
|
import {
|
|
9
9
|
BUILD_OUTPUT_DEPENDENCIES,
|
|
10
|
+
isBuildOutputTargetName,
|
|
11
|
+
isTestRunnerTargetName,
|
|
10
12
|
LINUX_PLATFORM_TARGET_GLOBS,
|
|
11
13
|
MACOS_PLATFORM_TARGET_GLOBS,
|
|
12
14
|
type NxPolicyIssue,
|
|
@@ -18,7 +20,6 @@ export type { NxPolicyIssue };
|
|
|
18
20
|
export interface ResolvedProjectTargets {
|
|
19
21
|
root?: string;
|
|
20
22
|
targets: ReadonlySet<string>;
|
|
21
|
-
buildDependsOn?: readonly string[];
|
|
22
23
|
targetDependencies?: ReadonlyMap<string, readonly string[]>;
|
|
23
24
|
targetExecutors?: ReadonlyMap<string, string>;
|
|
24
25
|
targetOptions?: ReadonlyMap<string, Readonly<Record<string, unknown>>>;
|
|
@@ -190,15 +191,6 @@ function resolvedProjectTargetNames(
|
|
|
190
191
|
return isResolvedProjectTargets(resolvedProject) ? resolvedProject.targets : resolvedProject;
|
|
191
192
|
}
|
|
192
193
|
|
|
193
|
-
function resolvedProjectBuildDependsOn(
|
|
194
|
-
resolvedProject?: ReadonlySet<string> | ResolvedProjectTargets,
|
|
195
|
-
): readonly string[] | undefined {
|
|
196
|
-
if (!isResolvedProjectTargets(resolvedProject)) {
|
|
197
|
-
return undefined;
|
|
198
|
-
}
|
|
199
|
-
return resolvedProject.buildDependsOn;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
194
|
function resolvedProjectTargetExecutor(
|
|
203
195
|
resolvedProject: ReadonlySet<string> | ResolvedProjectTargets | undefined,
|
|
204
196
|
targetName: string,
|
|
@@ -286,43 +278,75 @@ function isNoopTarget(target: Record<string, unknown>): boolean {
|
|
|
286
278
|
return !options || stringProperty(options, 'command') === null;
|
|
287
279
|
}
|
|
288
280
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
281
|
+
/**
|
|
282
|
+
* Properties the inferred aggregate already sets to exactly these values. A
|
|
283
|
+
* declaration carrying anything else — `inputs`, `outputs`, `cache: false`, a
|
|
284
|
+
* `configurations` block — is CHANGING the aggregate, not restating it.
|
|
285
|
+
*/
|
|
286
|
+
const inferredNoopBuildProperties: Record<string, true> = { executor: true, cache: true, dependsOn: true };
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Can the build-aggregate inference produce this edge on its own?
|
|
290
|
+
*
|
|
291
|
+
* The inferred aggregate is `^build` plus the project's own build-output
|
|
292
|
+
* targets — `isBuildOutputTargetName`, test runners excluded — and
|
|
293
|
+
* `BUILD_OUTPUT_DEPENDENCIES` is the glob spelling of that same list. Anything
|
|
294
|
+
* else is an edge only the declaration carries: a project-local target outside
|
|
295
|
+
* the families (`build-cli`), or a `project:target` edge to a sibling target
|
|
296
|
+
* that is not named `build`, which `^build` never visits.
|
|
297
|
+
*/
|
|
298
|
+
function isInferredBuildDependency(dependency: unknown, resolvedTargets: ReadonlySet<string>): boolean {
|
|
299
|
+
if (typeof dependency !== 'string') {
|
|
294
300
|
return false;
|
|
295
301
|
}
|
|
296
|
-
|
|
297
|
-
|
|
302
|
+
if (dependency === '^build' || isBuildOutputDependencyPattern(dependency)) {
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
return isBuildOutputTargetName(dependency) && !isTestRunnerTargetName(dependency) && resolvedTargets.has(dependency);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function isRedundantBuildDeclaration(build: Record<string, unknown>, resolvedTargets: ReadonlySet<string>): boolean {
|
|
309
|
+
if (!Object.keys(build).every((key) => inferredNoopBuildProperties[key] === true)) {
|
|
298
310
|
return false;
|
|
299
311
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
312
|
+
if ('cache' in build && build.cache !== true) {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
// An empty list is a deliberate cut — "this aggregate waits for nothing" —
|
|
316
|
+
// and restoring the inferred edges by deleting it is a behaviour change.
|
|
317
|
+
return (
|
|
318
|
+
Array.isArray(build.dependsOn) &&
|
|
319
|
+
build.dependsOn.length > 0 &&
|
|
320
|
+
build.dependsOn.every((dependency) => isInferredBuildDependency(dependency, resolvedTargets))
|
|
321
|
+
);
|
|
306
322
|
}
|
|
307
323
|
|
|
324
|
+
/**
|
|
325
|
+
* A hand-declared `build` is deleted only when inference provably rebuilds it.
|
|
326
|
+
*
|
|
327
|
+
* Deliberately NOT decided against the resolved project graph. Nx replaces a
|
|
328
|
+
* named property of an inferred target with the declared one, so the resolved
|
|
329
|
+
* `build.dependsOn` IS the declaration: comparing them answered "redundant"
|
|
330
|
+
* for every noop aggregate anyone ever wrote. AxE's `containium` lost seven
|
|
331
|
+
* edges that way — four of them targets no inference can reach — and a clean
|
|
332
|
+
* checkout then built it without its producers. The question this has to
|
|
333
|
+
* answer is what inference yields WITHOUT the declaration, so the test is
|
|
334
|
+
* structural: every declared edge must be one the aggregate already collects.
|
|
335
|
+
*/
|
|
308
336
|
function removeRedundantNoopBuildTarget(
|
|
309
337
|
pkg: Record<string, unknown>,
|
|
310
338
|
resolvedProject?: ReadonlySet<string> | ResolvedProjectTargets,
|
|
311
339
|
): boolean {
|
|
312
340
|
const resolvedTargets = resolvedProjectTargetNames(resolvedProject);
|
|
313
|
-
|
|
314
|
-
|
|
341
|
+
// No build-output target in the project, no inferred aggregate to fall back
|
|
342
|
+
// on: deleting the declaration would leave it with no `build` at all.
|
|
343
|
+
if (!resolvedTargets?.has('build') || ![...resolvedTargets].some(isBuildOutputTargetName)) {
|
|
315
344
|
return false;
|
|
316
345
|
}
|
|
317
346
|
const nx = recordProperty(pkg, 'nx');
|
|
318
347
|
const targets = nx ? recordProperty(nx, 'targets') : null;
|
|
319
348
|
const build = targets ? recordProperty(targets, 'build') : null;
|
|
320
|
-
if (
|
|
321
|
-
!targets ||
|
|
322
|
-
!build ||
|
|
323
|
-
!isNoopTarget(build) ||
|
|
324
|
-
!targetDependenciesMatchResolvedBuild(build, resolvedBuildDependsOn)
|
|
325
|
-
) {
|
|
349
|
+
if (!targets || !build || !isNoopTarget(build) || !isRedundantBuildDeclaration(build, resolvedTargets)) {
|
|
326
350
|
return false;
|
|
327
351
|
}
|
|
328
352
|
delete targets.build;
|
|
@@ -3,6 +3,8 @@ import { join } from 'node:path';
|
|
|
3
3
|
import type { Tree } from 'nx/src/devkit-exports.js';
|
|
4
4
|
import { readJson, updateJson } from 'nx/src/devkit-exports.js';
|
|
5
5
|
|
|
6
|
+
import { CARGO_TEST_TARGET } from './cargo-workspace.js';
|
|
7
|
+
|
|
6
8
|
export interface NxPolicyIssue {
|
|
7
9
|
path: string;
|
|
8
10
|
message: string;
|
|
@@ -24,6 +26,37 @@ export const MACOS_PLATFORM_TARGET_GLOBS = ['*-macos', '*-ios'] as const;
|
|
|
24
26
|
export const LINUX_PLATFORM_TARGET_GLOBS = ['*-linux'] as const;
|
|
25
27
|
export const PLATFORM_TARGET_GLOBS = [...MACOS_PLATFORM_TARGET_GLOBS, ...LINUX_PLATFORM_TARGET_GLOBS] as const;
|
|
26
28
|
|
|
29
|
+
const buildOutputTargetSuffixes = BUILD_OUTPUT_DEPENDENCIES.map((glob) => glob.slice(1));
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The glob list above, spelled as a target name: a target whose name ends in a
|
|
33
|
+
* reserved family suffix EMITS that kind of artifact. Inference collects
|
|
34
|
+
* exactly these names into the `nx:noop` build aggregate, which makes this the
|
|
35
|
+
* same rule that decides whether a hand-declared aggregate names an edge
|
|
36
|
+
* inference could have produced on its own — one definition, two readers, so
|
|
37
|
+
* the removal policy cannot drift away from what it judges redundant.
|
|
38
|
+
*/
|
|
39
|
+
export function isBuildOutputTargetName(name: string): boolean {
|
|
40
|
+
return buildOutputTargetSuffixes.some((suffix) => name.endsWith(suffix));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A target whose job is to RUN tests. `test`, anything under `test-`/`test:`,
|
|
45
|
+
* and the plugin's own `cargo-test-<crate>` namespace. Deliberately name-based:
|
|
46
|
+
* the aggregate is assembled from declared AND inferred target names, and a
|
|
47
|
+
* declaration carries no marker saying "this executes rather than emits".
|
|
48
|
+
*
|
|
49
|
+
* A runner collides with the families by construction whenever its name ends in
|
|
50
|
+
* one: a crate named `…-js` puts `cargo-test-<crate>` in the family, and a bun
|
|
51
|
+
* suite named `test-bun` reads as "tool=test, output=bun". Both would drag a
|
|
52
|
+
* test suite into `build`, so the rule is the CLASS, not one namespace.
|
|
53
|
+
*/
|
|
54
|
+
export function isTestRunnerTargetName(name: string): boolean {
|
|
55
|
+
return (
|
|
56
|
+
name === 'test' || name.startsWith('test-') || name.startsWith('test:') || name.startsWith(`${CARGO_TEST_TARGET}-`)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
27
60
|
const nxJsTypescriptPlugin = '@nx/js/typescript';
|
|
28
61
|
const smoothBricksNxPlugin = '@smoothbricks/nx-plugin';
|
|
29
62
|
const cleanOutputsExecutor = '@smoothbricks/nx-plugin:clean-outputs';
|