@smoothbricks/nx-plugin 0.3.6 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -3
- package/dist/version-actions.cjs +75 -2
- package/dist/version-actions.d.cts +10 -3
- package/dist/version-actions.d.cts.map +1 -1
- package/dist/workspace-config-policy.js +21 -3
- package/package.json +40 -2
- package/src/bounded-test-policy.ts +9 -2
- package/src/index.test.ts +5 -3
- package/src/index.ts +13 -3
- package/src/version-actions.cts +105 -7
- package/src/version-actions.test.ts +80 -0
- package/src/workspace-config-policy.test.ts +62 -0
- package/src/workspace-config-policy.ts +25 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bounded-test-policy.d.ts","sourceRoot":"","sources":["../src/bounded-test-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAErG,eAAO,MAAM,qBAAqB,yCAAyC,CAAC;AAC5E,eAAO,MAAM,uBAAuB,SAAU,CAAC;AAC/C,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAKjD,eAAO,MAAM,gCAAgC,QAAS,CAAC;AAEvD,MAAM,WAAW,4BAA4B;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,EAAE,CAAC,EAAE;QACH,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;KACnD,CAAC;CACH;AAED,MAAM,WAAW,4BAA4B;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACnD;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mCAAmC;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,4BAA4B,CAAC;IAC3C,eAAe,CAAC,EAAE,sBAAsB,CAAC;CAC1C;AAED,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,4BAA4B,EACzC,OAAO,EAAE,mCAAmC,GAC3C,IAAI,CAuBN;AAED,wBAAgB,qCAAqC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA8BrH;AAED,wBAAgB,qCAAqC,CACnD,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,0BAA+B,GACvC,sBAAsB,EAAE,CA4B1B;AAED,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,4BAA4B,EACzC,OAAO,EAAE,mCAAmC,GAC3C,OAAO,
|
|
1
|
+
{"version":3,"file":"bounded-test-policy.d.ts","sourceRoot":"","sources":["../src/bounded-test-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAErG,eAAO,MAAM,qBAAqB,yCAAyC,CAAC;AAC5E,eAAO,MAAM,uBAAuB,SAAU,CAAC;AAC/C,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAKjD,eAAO,MAAM,gCAAgC,QAAS,CAAC;AAEvD,MAAM,WAAW,4BAA4B;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,EAAE,CAAC,EAAE;QACH,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;KACnD,CAAC;CACH;AAED,MAAM,WAAW,4BAA4B;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACnD;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,mCAAmC;IAClD,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,4BAA4B,CAAC;IAC3C,eAAe,CAAC,EAAE,sBAAsB,CAAC;CAC1C;AAED,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,4BAA4B,EACzC,OAAO,EAAE,mCAAmC,GAC3C,IAAI,CAuBN;AAED,wBAAgB,qCAAqC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA8BrH;AAED,wBAAgB,qCAAqC,CACnD,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,0BAA+B,GACvC,sBAAsB,EAAE,CA4B1B;AAED,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,4BAA4B,EACzC,OAAO,EAAE,mCAAmC,GAC3C,OAAO,CAqBT;AAwFD,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAElE;AAED,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,4BAA4B,EACzC,cAAc,SAAa,EAC3B,WAAW,CAAC,EAAE,4BAA4B,GACzC,MAAM,CAER;AA+CD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAmC,GAAG,MAAM,CAa9G"}
|
|
@@ -93,7 +93,10 @@ export function checkBoundedTestTargetPolicy(packageJson, options) {
|
|
|
93
93
|
if (!isRecord(testTarget)) {
|
|
94
94
|
return false;
|
|
95
95
|
}
|
|
96
|
-
|
|
96
|
+
// `<root>/src` is equally bounded: bun-test targets run from src/ so bun's
|
|
97
|
+
// test-discovery scan never walks generated trees (a Rust package's cargo
|
|
98
|
+
// target/ directory alone costs tens of seconds per run).
|
|
99
|
+
if (isBoundedExecutionTarget(testTarget.executor, testTarget.options, new Set(['{projectRoot}', '{projectRoot}/src']))) {
|
|
97
100
|
return packageJson.scripts?.test === boundedTestScriptAlias(options.projectName);
|
|
98
101
|
}
|
|
99
102
|
if (!isNoopAggregateTarget(testTarget)) {
|
|
@@ -134,7 +137,7 @@ function resolvedAggregateTestIsBounded(project) {
|
|
|
134
137
|
}
|
|
135
138
|
const visiting = new Set();
|
|
136
139
|
const verified = new Map();
|
|
137
|
-
const allowedCwds = new Set(['{projectRoot}',
|
|
140
|
+
const allowedCwds = new Set(['{projectRoot}', '{projectRoot}/src'].concat(project.root ? [project.root, `${project.root}/src`] : []));
|
|
138
141
|
const visit = (targetName) => {
|
|
139
142
|
const cached = verified.get(targetName);
|
|
140
143
|
if (cached !== undefined) {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AAgHlC,eAAO,MAAM,aAAa,EAAE,aA4B3B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,11 @@ const CARGO_INPUTS = [
|
|
|
25
25
|
'{projectRoot}/**/Cargo.toml',
|
|
26
26
|
'{projectRoot}/**/Cargo.lock',
|
|
27
27
|
'{projectRoot}/**/.cargo/config.toml',
|
|
28
|
+
// Shell scripts a `.cargo/config.toml` points at — linker, runner, and rustc wrappers — decide
|
|
29
|
+
// what the compiler produces as surely as the config naming them does. Tracking the config
|
|
30
|
+
// without its shims caches an artifact against a toolchain that has since changed. Only `*.sh`
|
|
31
|
+
// is swept: `scripts/` also holds project tooling that has nothing to do with a cargo build.
|
|
32
|
+
'{projectRoot}/scripts/*.sh',
|
|
28
33
|
'!{projectRoot}/**/target/**',
|
|
29
34
|
];
|
|
30
35
|
const CARGO_OUTPUT_INPUTS = [...CARGO_INPUTS, '{projectRoot}/package.json', '{workspaceRoot}/bun.lock'];
|
|
@@ -463,14 +468,19 @@ function createNapiTargets(projectRoot, config) {
|
|
|
463
468
|
return targets;
|
|
464
469
|
}
|
|
465
470
|
function createNapiTestTarget(projectRoot, hasDedicatedBunfig) {
|
|
466
|
-
const configFlag = hasDedicatedBunfig ? ' --config
|
|
471
|
+
const configFlag = hasDedicatedBunfig ? ' --config=../bunfig.napi-test.toml' : ' --config=../bunfig.toml';
|
|
467
472
|
return {
|
|
468
473
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
469
474
|
cache: true,
|
|
470
475
|
dependsOn: ['cargo-test', 'cargo-napi', 'tsc-js', '^build', 'build'],
|
|
471
476
|
options: {
|
|
472
|
-
|
|
473
|
-
cwd
|
|
477
|
+
// cwd is src/, not the package root: `bun test <arg>` treats the arg as
|
|
478
|
+
// a FILTER and scans the whole cwd tree for test files, and a Rust
|
|
479
|
+
// package's cargo target/ directory turns that scan into tens of
|
|
480
|
+
// seconds. bun only auto-loads bunfig from the cwd, so the package
|
|
481
|
+
// config is passed explicitly.
|
|
482
|
+
command: `bun test${configFlag} --timeout=30000 native.test.ts`,
|
|
483
|
+
cwd: `${projectRoot}/src`,
|
|
474
484
|
timeoutMs: 120000,
|
|
475
485
|
killAfterMs: 10000,
|
|
476
486
|
},
|
package/dist/version-actions.cjs
CHANGED
|
@@ -3,6 +3,10 @@ const node_fs_1 = require("node:fs");
|
|
|
3
3
|
const node_path_1 = require("node:path");
|
|
4
4
|
const nxJsVersionActions = require('@nx/js/src/release/version-actions');
|
|
5
5
|
const baseVersionActions = nxJsVersionActions.default ?? nxJsVersionActions;
|
|
6
|
+
// The manifest sections that survive `npm publish` as a consumer's problem. A devDependency is
|
|
7
|
+
// build-time only: it never reaches an installer, so a new version of it changes nothing about
|
|
8
|
+
// the published artifact and is no reason to cut a release.
|
|
9
|
+
const PUBLISHED_DEPENDENCY_FIELDS = ['dependencies', 'peerDependencies', 'optionalDependencies'];
|
|
6
10
|
const afterAllProjectsVersioned = async (cwd, options) => {
|
|
7
11
|
const result = await nxJsVersionActions.afterAllProjectsVersioned(cwd, options);
|
|
8
12
|
// Temporary Bun workaround. Delete this hook together with the CLI lockfile
|
|
@@ -28,7 +32,76 @@ const afterAllProjectsVersioned = async (cwd, options) => {
|
|
|
28
32
|
deletedFiles: result.deletedFiles,
|
|
29
33
|
};
|
|
30
34
|
};
|
|
31
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Version only the dependents a release can actually reach.
|
|
37
|
+
*
|
|
38
|
+
* Nx expands a bump to every reverse edge of the project graph, and that graph cannot answer the
|
|
39
|
+
* question that matters: `@nx/js` merges `dependencies`, `devDependencies`, `peerDependencies`,
|
|
40
|
+
* and `optionalDependencies` into one edge set before the graph is built, so a package that only
|
|
41
|
+
* uses another for its own tests is indistinguishable from one that ships it. Left alone, a fix
|
|
42
|
+
* to a test-only library republishes every package that tests with it — and on macOS that means
|
|
43
|
+
* rebuilding and re-testing native binaries nothing in the release actually changed.
|
|
44
|
+
*
|
|
45
|
+
* `readDependencies` is Nx's sanctioned override for exactly this: `ReleaseGraph`'s reverse-edge
|
|
46
|
+
* map is built from its return value alone, so dropping the dev-only edges here removes those
|
|
47
|
+
* packages from the release, from the platform builds, and from the version data the CLI reads
|
|
48
|
+
* back. Specifier rewriting is unaffected: `updateProjectDependencies` reads the project graph
|
|
49
|
+
* directly, so a package that is versioned on its own merit still gets accurate devDependency
|
|
50
|
+
* pins.
|
|
51
|
+
*/
|
|
52
|
+
class SmoothbricksVersionActions extends baseVersionActions {
|
|
53
|
+
// Nx reads this off the exported module, not off an instance (`loaded.afterAllProjectsVersioned`).
|
|
54
|
+
static afterAllProjectsVersioned = afterAllProjectsVersioned;
|
|
55
|
+
/**
|
|
56
|
+
* The policy itself: keep an edge only when the source manifest declares the target in a
|
|
57
|
+
* section that survives publication.
|
|
58
|
+
*
|
|
59
|
+
* `packageNameOf` returns `null` for anything that is not a workspace project with a readable
|
|
60
|
+
* name — an external `npm:` node, most commonly. Those are kept exactly as the project graph
|
|
61
|
+
* reported them: they are not release projects, so they expand nothing, and keeping them makes
|
|
62
|
+
* this override strictly subtractive on the set that matters.
|
|
63
|
+
*/
|
|
64
|
+
static publishedDependencies(dependencies, manifest, packageNameOf) {
|
|
65
|
+
return dependencies.filter((dependency) => {
|
|
66
|
+
const packageName = packageNameOf(dependency.target);
|
|
67
|
+
if (packageName === null) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
return PUBLISHED_DEPENDENCY_FIELDS.some((field) => {
|
|
71
|
+
const section = manifest[field];
|
|
72
|
+
return isRecord(section) && packageName in section;
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async readDependencies(tree, projectGraph) {
|
|
77
|
+
const dependencies = await super.readDependencies(tree, projectGraph);
|
|
78
|
+
const manifest = readManifest(tree, this.projectGraphNode);
|
|
79
|
+
if (!manifest) {
|
|
80
|
+
return dependencies;
|
|
81
|
+
}
|
|
82
|
+
return SmoothbricksVersionActions.publishedDependencies(dependencies, manifest, (projectName) => {
|
|
83
|
+
const node = projectGraph.nodes[projectName];
|
|
84
|
+
const packageName = node ? readManifest(tree, node)?.name : undefined;
|
|
85
|
+
return typeof packageName === 'string' ? packageName : null;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Exported as a typed value, not as the class declaration. `export =` of a class publishes every
|
|
90
|
+
// static as an ESM named import TypeScript can see but Node's CJS lexer cannot, which crashes an
|
|
91
|
+
// `import { publishedDependencies }` at runtime; a const has no members to publish.
|
|
92
|
+
const versionActions = SmoothbricksVersionActions;
|
|
93
|
+
/**
|
|
94
|
+
* Read a project's `package.json` from the version tree, which carries writes earlier projects in
|
|
95
|
+
* this run have already staged.
|
|
96
|
+
*/
|
|
97
|
+
function readManifest(tree, node) {
|
|
98
|
+
const contents = tree.read((0, node_path_1.join)(node.data.root, 'package.json'), 'utf-8');
|
|
99
|
+
if (contents === null) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
const parsed = JSON.parse(contents);
|
|
103
|
+
return isRecord(parsed) ? parsed : null;
|
|
104
|
+
}
|
|
32
105
|
function syncBunLockfileVersionsToPackageJson(root) {
|
|
33
106
|
const lockfilePath = (0, node_path_1.join)(root, 'bun.lock');
|
|
34
107
|
if (!(0, node_fs_1.existsSync)(lockfilePath)) {
|
|
@@ -90,4 +163,4 @@ function isRecord(value) {
|
|
|
90
163
|
function escapeRegex(value) {
|
|
91
164
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
92
165
|
}
|
|
93
|
-
module.exports =
|
|
166
|
+
module.exports = versionActions;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import type
|
|
2
|
-
|
|
1
|
+
import type JsVersionActions from '@nx/js/src/release/version-actions';
|
|
2
|
+
import type { AfterAllProjectsVersioned } from 'nx/release';
|
|
3
|
+
import type { ProjectGraphDependency } from 'nx/src/config/project-graph';
|
|
4
|
+
type JsVersionActionsClass = typeof JsVersionActions & {
|
|
3
5
|
afterAllProjectsVersioned: AfterAllProjectsVersioned;
|
|
4
6
|
};
|
|
5
|
-
|
|
7
|
+
/** The exported shape: the base class plus the statics this module adds. */
|
|
8
|
+
type SmoothbricksVersionActionsClass = JsVersionActionsClass & {
|
|
9
|
+
publishedDependencies(dependencies: readonly ProjectGraphDependency[], manifest: Record<string, unknown>, packageNameOf: (projectName: string) => string | null): ProjectGraphDependency[];
|
|
10
|
+
};
|
|
11
|
+
declare const versionActions: SmoothbricksVersionActionsClass;
|
|
12
|
+
export = versionActions;
|
|
6
13
|
//# sourceMappingURL=version-actions.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-actions.d.cts","sourceRoot":"","sources":["../src/version-actions.cts"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"version-actions.d.cts","sourceRoot":"","sources":["../src/version-actions.cts"],"names":[],"mappings":"AAEA,OAAO,KAAK,gBAAgB,MAAM,oCAAoC,CAAC;AACvE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EAAgB,sBAAsB,EAA2B,MAAM,6BAA6B,CAAC;AAMjH,KAAK,qBAAqB,GAAG,OAAO,gBAAgB,GAAG;IACrD,yBAAyB,EAAE,yBAAyB,CAAC;CACtD,CAAC;AAEF,4EAA4E;AAC5E,KAAK,+BAA+B,GAAG,qBAAqB,GAAG;IAC7D,qBAAqB,CACnB,YAAY,EAAE,SAAS,sBAAsB,EAAE,EAC/C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,aAAa,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GACpD,sBAAsB,EAAE,CAAC;CAC7B,CAAC;AAwGF,QAAA,MAAM,cAAc,EAAE,+BAA4D,CAAC;SAE1E,cAAc"}
|
|
@@ -157,10 +157,24 @@ function validateBuildTargetDefault(nxJson, nxJsonPath, issues) {
|
|
|
157
157
|
issues.push({ path: nxJsonPath, message: 'targetDefaults.build.cache must be true' });
|
|
158
158
|
}
|
|
159
159
|
const outputs = build?.outputs;
|
|
160
|
-
if (!
|
|
161
|
-
issues.push({
|
|
160
|
+
if (!isValidBuildOutputs(outputs)) {
|
|
161
|
+
issues.push({
|
|
162
|
+
path: nxJsonPath,
|
|
163
|
+
message: 'targetDefaults.build.outputs must contain "{projectRoot}/dist" and only "{projectRoot}/dist-<suffix>" siblings (e.g. "{projectRoot}/dist-node")',
|
|
164
|
+
});
|
|
162
165
|
}
|
|
163
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Build outputs must include the canonical dist tree; additional project-root
|
|
169
|
+
* dist siblings (dist-node, dist-test, …) are legitimate secondary outputs a
|
|
170
|
+
* repo may aggregate into `build` — the policy pins outputs under the project
|
|
171
|
+
* root's dist family, not the exact array.
|
|
172
|
+
*/
|
|
173
|
+
function isValidBuildOutputs(outputs) {
|
|
174
|
+
return (Array.isArray(outputs) &&
|
|
175
|
+
outputs.includes('{projectRoot}/dist') &&
|
|
176
|
+
outputs.every((output) => typeof output === 'string' && /^\{projectRoot\}\/dist(-[\w.-]+)?$/.test(output)));
|
|
177
|
+
}
|
|
164
178
|
function validateCleanTargetDefault(nxJson, nxJsonPath, issues) {
|
|
165
179
|
const targetDefaults = recordProperty(nxJson, 'targetDefaults');
|
|
166
180
|
const clean = targetDefaults ? recordProperty(targetDefaults, 'clean') : null;
|
|
@@ -211,7 +225,11 @@ function applyBuildTargetDefault(nxJson) {
|
|
|
211
225
|
const targetDefaults = getOrCreateRecord(nxJson, 'targetDefaults');
|
|
212
226
|
const build = getOrCreateRecord(targetDefaults, 'build');
|
|
213
227
|
let changed = setBooleanProperty(build, 'cache', true);
|
|
214
|
-
|
|
228
|
+
// Reset only invalid outputs: valid extra dist siblings (dist-node, …) are a
|
|
229
|
+
// repo decision the fixer must not clobber.
|
|
230
|
+
if (!isValidBuildOutputs(build.outputs)) {
|
|
231
|
+
changed = setStringArrayProperty(build, 'outputs', ['{projectRoot}/dist']) || changed;
|
|
232
|
+
}
|
|
215
233
|
return changed;
|
|
216
234
|
}
|
|
217
235
|
function applyCleanTargetDefault(nxJson) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smoothbricks/nx-plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./loader.js",
|
|
@@ -84,7 +84,45 @@
|
|
|
84
84
|
],
|
|
85
85
|
"license": "MIT",
|
|
86
86
|
"publishConfig": {
|
|
87
|
-
"access": "public"
|
|
87
|
+
"access": "public",
|
|
88
|
+
"exports": {
|
|
89
|
+
"./package.json": "./package.json",
|
|
90
|
+
".": {
|
|
91
|
+
"types": "./dist/index.d.ts",
|
|
92
|
+
"import": "./loader.js",
|
|
93
|
+
"default": "./loader.js"
|
|
94
|
+
},
|
|
95
|
+
"./version-actions": {
|
|
96
|
+
"types": "./dist/version-actions.d.cts",
|
|
97
|
+
"require": "./dist/version-actions.cjs",
|
|
98
|
+
"default": "./dist/version-actions.cjs"
|
|
99
|
+
},
|
|
100
|
+
"./bounded-test-policy": {
|
|
101
|
+
"types": "./dist/bounded-test-policy.d.ts",
|
|
102
|
+
"import": "./dist/bounded-test-policy.js",
|
|
103
|
+
"default": "./dist/bounded-test-policy.js"
|
|
104
|
+
},
|
|
105
|
+
"./workspace-config-policy": {
|
|
106
|
+
"types": "./dist/workspace-config-policy.d.ts",
|
|
107
|
+
"import": "./dist/workspace-config-policy.js",
|
|
108
|
+
"default": "./dist/workspace-config-policy.js"
|
|
109
|
+
},
|
|
110
|
+
"./release-config-policy": {
|
|
111
|
+
"types": "./dist/release-config-policy.d.ts",
|
|
112
|
+
"import": "./dist/release-config-policy.js",
|
|
113
|
+
"default": "./dist/release-config-policy.js"
|
|
114
|
+
},
|
|
115
|
+
"./package-target-policy": {
|
|
116
|
+
"types": "./dist/package-target-policy.d.ts",
|
|
117
|
+
"import": "./dist/package-target-policy.js",
|
|
118
|
+
"default": "./dist/package-target-policy.js"
|
|
119
|
+
},
|
|
120
|
+
"./typecheck-test-policy": {
|
|
121
|
+
"types": "./dist/typecheck-test-policy.d.ts",
|
|
122
|
+
"import": "./dist/typecheck-test-policy.js",
|
|
123
|
+
"default": "./dist/typecheck-test-policy.js"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
88
126
|
},
|
|
89
127
|
"repository": {
|
|
90
128
|
"type": "git",
|
|
@@ -139,7 +139,12 @@ export function checkBoundedTestTargetPolicy(
|
|
|
139
139
|
if (!isRecord(testTarget)) {
|
|
140
140
|
return false;
|
|
141
141
|
}
|
|
142
|
-
|
|
142
|
+
// `<root>/src` is equally bounded: bun-test targets run from src/ so bun's
|
|
143
|
+
// test-discovery scan never walks generated trees (a Rust package's cargo
|
|
144
|
+
// target/ directory alone costs tens of seconds per run).
|
|
145
|
+
if (
|
|
146
|
+
isBoundedExecutionTarget(testTarget.executor, testTarget.options, new Set(['{projectRoot}', '{projectRoot}/src']))
|
|
147
|
+
) {
|
|
143
148
|
return packageJson.scripts?.test === boundedTestScriptAlias(options.projectName);
|
|
144
149
|
}
|
|
145
150
|
if (!isNoopAggregateTarget(testTarget)) {
|
|
@@ -185,7 +190,9 @@ function resolvedAggregateTestIsBounded(project: ResolvedProjectTargets | undefi
|
|
|
185
190
|
}
|
|
186
191
|
const visiting = new Set<string>();
|
|
187
192
|
const verified = new Map<string, boolean>();
|
|
188
|
-
const allowedCwds = new Set(
|
|
193
|
+
const allowedCwds = new Set(
|
|
194
|
+
['{projectRoot}', '{projectRoot}/src'].concat(project.root ? [project.root, `${project.root}/src`] : []),
|
|
195
|
+
);
|
|
189
196
|
|
|
190
197
|
const visit = (targetName: string): boolean => {
|
|
191
198
|
const cached = verified.get(targetName);
|
package/src/index.test.ts
CHANGED
|
@@ -261,6 +261,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
261
261
|
'{projectRoot}/**/Cargo.toml',
|
|
262
262
|
'{projectRoot}/**/Cargo.lock',
|
|
263
263
|
'{projectRoot}/**/.cargo/config.toml',
|
|
264
|
+
'{projectRoot}/scripts/*.sh',
|
|
264
265
|
'!{projectRoot}/**/target/**',
|
|
265
266
|
]);
|
|
266
267
|
expect(targets['cargo-lint']?.options).toMatchObject({
|
|
@@ -313,6 +314,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
313
314
|
'{projectRoot}/**/Cargo.toml',
|
|
314
315
|
'{projectRoot}/**/Cargo.lock',
|
|
315
316
|
'{projectRoot}/**/.cargo/config.toml',
|
|
317
|
+
'{projectRoot}/scripts/*.sh',
|
|
316
318
|
'!{projectRoot}/**/target/**',
|
|
317
319
|
'{projectRoot}/package.json',
|
|
318
320
|
'{workspaceRoot}/bun.lock',
|
|
@@ -405,8 +407,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
405
407
|
cache: true,
|
|
406
408
|
dependsOn: ['cargo-test', 'cargo-napi', 'tsc-js', '^build', 'build'],
|
|
407
409
|
options: {
|
|
408
|
-
command: 'bun test --timeout=30000
|
|
409
|
-
cwd: 'packages/cowshed',
|
|
410
|
+
command: 'bun test --config=../bunfig.toml --timeout=30000 native.test.ts',
|
|
411
|
+
cwd: 'packages/cowshed/src',
|
|
410
412
|
timeoutMs: 120000,
|
|
411
413
|
killAfterMs: 10000,
|
|
412
414
|
},
|
|
@@ -414,7 +416,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
414
416
|
await workspace.write('packages/cowshed/bunfig.napi-test.toml', '[test]\n');
|
|
415
417
|
const targetsWithDedicatedBunfig = await inferProjectTargets(workspace, 'packages/cowshed/package.json');
|
|
416
418
|
expect(targetsWithDedicatedBunfig['napi-test']?.options?.command).toBe(
|
|
417
|
-
'bun --config
|
|
419
|
+
'bun test --config=../bunfig.napi-test.toml --timeout=30000 native.test.ts',
|
|
418
420
|
);
|
|
419
421
|
} finally {
|
|
420
422
|
await workspace.cleanup();
|
package/src/index.ts
CHANGED
|
@@ -34,6 +34,11 @@ const CARGO_INPUTS = [
|
|
|
34
34
|
'{projectRoot}/**/Cargo.toml',
|
|
35
35
|
'{projectRoot}/**/Cargo.lock',
|
|
36
36
|
'{projectRoot}/**/.cargo/config.toml',
|
|
37
|
+
// Shell scripts a `.cargo/config.toml` points at — linker, runner, and rustc wrappers — decide
|
|
38
|
+
// what the compiler produces as surely as the config naming them does. Tracking the config
|
|
39
|
+
// without its shims caches an artifact against a toolchain that has since changed. Only `*.sh`
|
|
40
|
+
// is swept: `scripts/` also holds project tooling that has nothing to do with a cargo build.
|
|
41
|
+
'{projectRoot}/scripts/*.sh',
|
|
37
42
|
'!{projectRoot}/**/target/**',
|
|
38
43
|
];
|
|
39
44
|
const CARGO_OUTPUT_INPUTS = [...CARGO_INPUTS, '{projectRoot}/package.json', '{workspaceRoot}/bun.lock'];
|
|
@@ -568,14 +573,19 @@ function createNapiTargets(projectRoot: string, config: ResolvedNapiConfig): Rec
|
|
|
568
573
|
}
|
|
569
574
|
|
|
570
575
|
function createNapiTestTarget(projectRoot: string, hasDedicatedBunfig: boolean): TargetConfiguration {
|
|
571
|
-
const configFlag = hasDedicatedBunfig ? ' --config
|
|
576
|
+
const configFlag = hasDedicatedBunfig ? ' --config=../bunfig.napi-test.toml' : ' --config=../bunfig.toml';
|
|
572
577
|
return {
|
|
573
578
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
574
579
|
cache: true,
|
|
575
580
|
dependsOn: ['cargo-test', 'cargo-napi', 'tsc-js', '^build', 'build'],
|
|
576
581
|
options: {
|
|
577
|
-
|
|
578
|
-
cwd
|
|
582
|
+
// cwd is src/, not the package root: `bun test <arg>` treats the arg as
|
|
583
|
+
// a FILTER and scans the whole cwd tree for test files, and a Rust
|
|
584
|
+
// package's cargo target/ directory turns that scan into tens of
|
|
585
|
+
// seconds. bun only auto-loads bunfig from the cwd, so the package
|
|
586
|
+
// config is passed explicitly.
|
|
587
|
+
command: `bun test${configFlag} --timeout=30000 native.test.ts`,
|
|
588
|
+
cwd: `${projectRoot}/src`,
|
|
579
589
|
timeoutMs: 120000,
|
|
580
590
|
killAfterMs: 10000,
|
|
581
591
|
},
|
package/src/version-actions.cts
CHANGED
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import type
|
|
3
|
+
import type JsVersionActions from '@nx/js/src/release/version-actions';
|
|
4
|
+
import type { AfterAllProjectsVersioned } from 'nx/release';
|
|
5
|
+
import type { ProjectGraph, ProjectGraphDependency, ProjectGraphProjectNode } from 'nx/src/config/project-graph';
|
|
6
|
+
import type { Tree } from 'nx/src/generators/tree';
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
// The runtime `require` is what Nx's own loader does with this path, and the concrete
|
|
9
|
+
// `JsVersionActions` type is what makes subclassing it typecheck: `nx/release` only exports the
|
|
10
|
+
// abstract `VersionActions`, whose members this class does not reimplement.
|
|
11
|
+
type JsVersionActionsClass = typeof JsVersionActions & {
|
|
7
12
|
afterAllProjectsVersioned: AfterAllProjectsVersioned;
|
|
8
13
|
};
|
|
9
14
|
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
/** The exported shape: the base class plus the statics this module adds. */
|
|
16
|
+
type SmoothbricksVersionActionsClass = JsVersionActionsClass & {
|
|
17
|
+
publishedDependencies(
|
|
18
|
+
dependencies: readonly ProjectGraphDependency[],
|
|
19
|
+
manifest: Record<string, unknown>,
|
|
20
|
+
packageNameOf: (projectName: string) => string | null,
|
|
21
|
+
): ProjectGraphDependency[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const nxJsVersionActions = require('@nx/js/src/release/version-actions') as JsVersionActionsClass & {
|
|
25
|
+
default?: JsVersionActionsClass;
|
|
26
|
+
};
|
|
27
|
+
const baseVersionActions: JsVersionActionsClass = nxJsVersionActions.default ?? nxJsVersionActions;
|
|
28
|
+
|
|
29
|
+
// The manifest sections that survive `npm publish` as a consumer's problem. A devDependency is
|
|
30
|
+
// build-time only: it never reaches an installer, so a new version of it changes nothing about
|
|
31
|
+
// the published artifact and is no reason to cut a release.
|
|
32
|
+
const PUBLISHED_DEPENDENCY_FIELDS = ['dependencies', 'peerDependencies', 'optionalDependencies'] as const;
|
|
12
33
|
|
|
13
34
|
const afterAllProjectsVersioned: AfterAllProjectsVersioned = async (cwd, options) => {
|
|
14
35
|
const result = await nxJsVersionActions.afterAllProjectsVersioned(cwd, options);
|
|
@@ -38,9 +59,86 @@ const afterAllProjectsVersioned: AfterAllProjectsVersioned = async (cwd, options
|
|
|
38
59
|
};
|
|
39
60
|
};
|
|
40
61
|
|
|
41
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Version only the dependents a release can actually reach.
|
|
64
|
+
*
|
|
65
|
+
* Nx expands a bump to every reverse edge of the project graph, and that graph cannot answer the
|
|
66
|
+
* question that matters: `@nx/js` merges `dependencies`, `devDependencies`, `peerDependencies`,
|
|
67
|
+
* and `optionalDependencies` into one edge set before the graph is built, so a package that only
|
|
68
|
+
* uses another for its own tests is indistinguishable from one that ships it. Left alone, a fix
|
|
69
|
+
* to a test-only library republishes every package that tests with it — and on macOS that means
|
|
70
|
+
* rebuilding and re-testing native binaries nothing in the release actually changed.
|
|
71
|
+
*
|
|
72
|
+
* `readDependencies` is Nx's sanctioned override for exactly this: `ReleaseGraph`'s reverse-edge
|
|
73
|
+
* map is built from its return value alone, so dropping the dev-only edges here removes those
|
|
74
|
+
* packages from the release, from the platform builds, and from the version data the CLI reads
|
|
75
|
+
* back. Specifier rewriting is unaffected: `updateProjectDependencies` reads the project graph
|
|
76
|
+
* directly, so a package that is versioned on its own merit still gets accurate devDependency
|
|
77
|
+
* pins.
|
|
78
|
+
*/
|
|
79
|
+
class SmoothbricksVersionActions extends baseVersionActions {
|
|
80
|
+
// Nx reads this off the exported module, not off an instance (`loaded.afterAllProjectsVersioned`).
|
|
81
|
+
static override afterAllProjectsVersioned: AfterAllProjectsVersioned = afterAllProjectsVersioned;
|
|
42
82
|
|
|
43
|
-
|
|
83
|
+
/**
|
|
84
|
+
* The policy itself: keep an edge only when the source manifest declares the target in a
|
|
85
|
+
* section that survives publication.
|
|
86
|
+
*
|
|
87
|
+
* `packageNameOf` returns `null` for anything that is not a workspace project with a readable
|
|
88
|
+
* name — an external `npm:` node, most commonly. Those are kept exactly as the project graph
|
|
89
|
+
* reported them: they are not release projects, so they expand nothing, and keeping them makes
|
|
90
|
+
* this override strictly subtractive on the set that matters.
|
|
91
|
+
*/
|
|
92
|
+
static publishedDependencies(
|
|
93
|
+
dependencies: readonly ProjectGraphDependency[],
|
|
94
|
+
manifest: Record<string, unknown>,
|
|
95
|
+
packageNameOf: (projectName: string) => string | null,
|
|
96
|
+
): ProjectGraphDependency[] {
|
|
97
|
+
return dependencies.filter((dependency) => {
|
|
98
|
+
const packageName = packageNameOf(dependency.target);
|
|
99
|
+
if (packageName === null) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
return PUBLISHED_DEPENDENCY_FIELDS.some((field) => {
|
|
103
|
+
const section = manifest[field];
|
|
104
|
+
return isRecord(section) && packageName in section;
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
override async readDependencies(tree: Tree, projectGraph: ProjectGraph): Promise<ProjectGraphDependency[]> {
|
|
110
|
+
const dependencies = await super.readDependencies(tree, projectGraph);
|
|
111
|
+
const manifest = readManifest(tree, this.projectGraphNode);
|
|
112
|
+
if (!manifest) {
|
|
113
|
+
return dependencies;
|
|
114
|
+
}
|
|
115
|
+
return SmoothbricksVersionActions.publishedDependencies(dependencies, manifest, (projectName) => {
|
|
116
|
+
const node = projectGraph.nodes[projectName];
|
|
117
|
+
const packageName = node ? readManifest(tree, node)?.name : undefined;
|
|
118
|
+
return typeof packageName === 'string' ? packageName : null;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Exported as a typed value, not as the class declaration. `export =` of a class publishes every
|
|
124
|
+
// static as an ESM named import TypeScript can see but Node's CJS lexer cannot, which crashes an
|
|
125
|
+
// `import { publishedDependencies }` at runtime; a const has no members to publish.
|
|
126
|
+
const versionActions: SmoothbricksVersionActionsClass = SmoothbricksVersionActions;
|
|
127
|
+
|
|
128
|
+
export = versionActions;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Read a project's `package.json` from the version tree, which carries writes earlier projects in
|
|
132
|
+
* this run have already staged.
|
|
133
|
+
*/
|
|
134
|
+
function readManifest(tree: Tree, node: ProjectGraphProjectNode): Record<string, unknown> | null {
|
|
135
|
+
const contents = tree.read(join(node.data.root, 'package.json'), 'utf-8');
|
|
136
|
+
if (contents === null) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
const parsed: unknown = JSON.parse(contents);
|
|
140
|
+
return isRecord(parsed) ? parsed : null;
|
|
141
|
+
}
|
|
44
142
|
|
|
45
143
|
function syncBunLockfileVersionsToPackageJson(root: string): number {
|
|
46
144
|
const lockfilePath = join(root, 'bun.lock');
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
// The published entry point is what `nx.json` names in `release.version.versionActions`, so it is
|
|
3
|
+
// the artifact whose behaviour the release depends on.
|
|
4
|
+
import SmoothbricksVersionActions from '@smoothbricks/nx-plugin/version-actions';
|
|
5
|
+
import type { ProjectGraphDependency } from 'nx/src/config/project-graph';
|
|
6
|
+
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Helpers
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
function edge(target: string): ProjectGraphDependency {
|
|
12
|
+
return { source: 'consumer', target, type: 'static' };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Every fixture project's Nx name is its unscoped package name. */
|
|
16
|
+
function packageNameOf(projectName: string): string | null {
|
|
17
|
+
return projectName.startsWith('npm:') ? null : `@smoothbricks/${projectName}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// publishedDependencies
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
describe('publishedDependencies', () => {
|
|
25
|
+
it('keeps every section an installer resolves', () => {
|
|
26
|
+
const manifest = {
|
|
27
|
+
dependencies: { '@smoothbricks/runtime': 'workspace:*' },
|
|
28
|
+
peerDependencies: { '@smoothbricks/host': '^1.0.0' },
|
|
29
|
+
optionalDependencies: { '@smoothbricks/native': 'workspace:*' },
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const kept = SmoothbricksVersionActions.publishedDependencies(
|
|
33
|
+
[edge('runtime'), edge('host'), edge('native')],
|
|
34
|
+
manifest,
|
|
35
|
+
packageNameOf,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
expect(kept.map((dependency) => dependency.target)).toEqual(['runtime', 'host', 'native']);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('drops a dev-only edge, because a devDependency bump changes nothing an installer sees', () => {
|
|
42
|
+
const manifest = {
|
|
43
|
+
dependencies: { typia: '13.2.0' },
|
|
44
|
+
devDependencies: { '@smoothbricks/lmao': 'workspace:*' },
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
expect(SmoothbricksVersionActions.publishedDependencies([edge('lmao')], manifest, packageNameOf)).toEqual([]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('keeps a package declared in both, because the published section is what ships', () => {
|
|
51
|
+
const manifest = {
|
|
52
|
+
dependencies: { '@smoothbricks/lmao': 'workspace:*' },
|
|
53
|
+
devDependencies: { '@smoothbricks/lmao': 'workspace:*' },
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
expect(
|
|
57
|
+
SmoothbricksVersionActions.publishedDependencies([edge('lmao')], manifest, packageNameOf).map(
|
|
58
|
+
(dependency) => dependency.target,
|
|
59
|
+
),
|
|
60
|
+
).toEqual(['lmao']);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('keeps an edge whose target has no resolvable package name', () => {
|
|
64
|
+
expect(
|
|
65
|
+
SmoothbricksVersionActions.publishedDependencies([edge('npm:typia')], {}, packageNameOf).map(
|
|
66
|
+
(dependency) => dependency.target,
|
|
67
|
+
),
|
|
68
|
+
).toEqual(['npm:typia']);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('drops every workspace edge of a manifest with no published sections', () => {
|
|
72
|
+
expect(
|
|
73
|
+
SmoothbricksVersionActions.publishedDependencies(
|
|
74
|
+
[edge('lmao'), edge('validation')],
|
|
75
|
+
{ devDependencies: { '@smoothbricks/lmao': 'workspace:*', '@smoothbricks/validation': 'workspace:*' } },
|
|
76
|
+
packageNameOf,
|
|
77
|
+
),
|
|
78
|
+
).toEqual([]);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -165,6 +165,42 @@ describe('pure core: checkWorkspaceConfig', () => {
|
|
|
165
165
|
expect(issues.some((i) => i.message.includes('build.outputs'))).toBe(true);
|
|
166
166
|
});
|
|
167
167
|
|
|
168
|
+
it('accepts additional project-root dist siblings in build outputs', () => {
|
|
169
|
+
const issues = checkWorkspaceConfig({
|
|
170
|
+
plugins: validPlugins(),
|
|
171
|
+
targetDefaults: {
|
|
172
|
+
...validTargetDefaults(),
|
|
173
|
+
build: { cache: true, outputs: ['{projectRoot}/dist', '{projectRoot}/dist-node'] },
|
|
174
|
+
},
|
|
175
|
+
namedInputs: validNamedInputs(),
|
|
176
|
+
});
|
|
177
|
+
expect(issues.some((i) => i.message.includes('build.outputs'))).toBe(false);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('rejects build outputs missing the canonical dist tree', () => {
|
|
181
|
+
const issues = checkWorkspaceConfig({
|
|
182
|
+
plugins: validPlugins(),
|
|
183
|
+
targetDefaults: {
|
|
184
|
+
...validTargetDefaults(),
|
|
185
|
+
build: { cache: true, outputs: ['{projectRoot}/dist-node'] },
|
|
186
|
+
},
|
|
187
|
+
namedInputs: validNamedInputs(),
|
|
188
|
+
});
|
|
189
|
+
expect(issues.some((i) => i.message.includes('build.outputs'))).toBe(true);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('rejects build outputs outside the project-root dist family', () => {
|
|
193
|
+
const issues = checkWorkspaceConfig({
|
|
194
|
+
plugins: validPlugins(),
|
|
195
|
+
targetDefaults: {
|
|
196
|
+
...validTargetDefaults(),
|
|
197
|
+
build: { cache: true, outputs: ['{projectRoot}/dist', '{workspaceRoot}/out'] },
|
|
198
|
+
},
|
|
199
|
+
namedInputs: validNamedInputs(),
|
|
200
|
+
});
|
|
201
|
+
expect(issues.some((i) => i.message.includes('build.outputs'))).toBe(true);
|
|
202
|
+
});
|
|
203
|
+
|
|
168
204
|
it('detects missing sharedGlobals', () => {
|
|
169
205
|
const issues = checkWorkspaceConfig({
|
|
170
206
|
plugins: validPlugins(),
|
|
@@ -184,6 +220,32 @@ describe('pure core: applyWorkspaceConfig', () => {
|
|
|
184
220
|
expect(applyWorkspaceConfig(nxJson)).toBe(false);
|
|
185
221
|
});
|
|
186
222
|
|
|
223
|
+
it('preserves valid extra dist siblings in build outputs', () => {
|
|
224
|
+
const nxJson = {
|
|
225
|
+
...validNxJson(),
|
|
226
|
+
targetDefaults: {
|
|
227
|
+
...validTargetDefaults(),
|
|
228
|
+
build: { cache: true, outputs: ['{projectRoot}/dist', '{projectRoot}/dist-node'] },
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
expect(applyWorkspaceConfig(nxJson)).toBe(false);
|
|
232
|
+
const build = expectRecord(expectRecord(nxJson.targetDefaults).build);
|
|
233
|
+
expect(build.outputs).toEqual(['{projectRoot}/dist', '{projectRoot}/dist-node']);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('resets invalid build outputs to the canonical dist tree', () => {
|
|
237
|
+
const nxJson = {
|
|
238
|
+
...validNxJson(),
|
|
239
|
+
targetDefaults: {
|
|
240
|
+
...validTargetDefaults(),
|
|
241
|
+
build: { cache: true, outputs: ['{workspaceRoot}/out'] },
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
expect(applyWorkspaceConfig(nxJson)).toBe(true);
|
|
245
|
+
const build = expectRecord(expectRecord(nxJson.targetDefaults).build);
|
|
246
|
+
expect(build.outputs).toEqual(['{projectRoot}/dist']);
|
|
247
|
+
});
|
|
248
|
+
|
|
187
249
|
it('fixes missing plugins', () => {
|
|
188
250
|
const nxJson: Record<string, unknown> = {
|
|
189
251
|
plugins: [],
|
|
@@ -187,11 +187,29 @@ function validateBuildTargetDefault(
|
|
|
187
187
|
issues.push({ path: nxJsonPath, message: 'targetDefaults.build.cache must be true' });
|
|
188
188
|
}
|
|
189
189
|
const outputs = build?.outputs;
|
|
190
|
-
if (!
|
|
191
|
-
issues.push({
|
|
190
|
+
if (!isValidBuildOutputs(outputs)) {
|
|
191
|
+
issues.push({
|
|
192
|
+
path: nxJsonPath,
|
|
193
|
+
message:
|
|
194
|
+
'targetDefaults.build.outputs must contain "{projectRoot}/dist" and only "{projectRoot}/dist-<suffix>" siblings (e.g. "{projectRoot}/dist-node")',
|
|
195
|
+
});
|
|
192
196
|
}
|
|
193
197
|
}
|
|
194
198
|
|
|
199
|
+
/**
|
|
200
|
+
* Build outputs must include the canonical dist tree; additional project-root
|
|
201
|
+
* dist siblings (dist-node, dist-test, …) are legitimate secondary outputs a
|
|
202
|
+
* repo may aggregate into `build` — the policy pins outputs under the project
|
|
203
|
+
* root's dist family, not the exact array.
|
|
204
|
+
*/
|
|
205
|
+
function isValidBuildOutputs(outputs: unknown): outputs is string[] {
|
|
206
|
+
return (
|
|
207
|
+
Array.isArray(outputs) &&
|
|
208
|
+
outputs.includes('{projectRoot}/dist') &&
|
|
209
|
+
outputs.every((output) => typeof output === 'string' && /^\{projectRoot\}\/dist(-[\w.-]+)?$/.test(output))
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
195
213
|
function validateCleanTargetDefault(
|
|
196
214
|
nxJson: Record<string, unknown>,
|
|
197
215
|
nxJsonPath: string,
|
|
@@ -253,7 +271,11 @@ function applyBuildTargetDefault(nxJson: Record<string, unknown>): boolean {
|
|
|
253
271
|
const targetDefaults = getOrCreateRecord(nxJson, 'targetDefaults');
|
|
254
272
|
const build = getOrCreateRecord(targetDefaults, 'build');
|
|
255
273
|
let changed = setBooleanProperty(build, 'cache', true);
|
|
256
|
-
|
|
274
|
+
// Reset only invalid outputs: valid extra dist siblings (dist-node, …) are a
|
|
275
|
+
// repo decision the fixer must not clobber.
|
|
276
|
+
if (!isValidBuildOutputs(build.outputs)) {
|
|
277
|
+
changed = setStringArrayProperty(build, 'outputs', ['{projectRoot}/dist']) || changed;
|
|
278
|
+
}
|
|
257
279
|
return changed;
|
|
258
280
|
}
|
|
259
281
|
|