@smoothbricks/nx-plugin 0.3.11 → 0.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +10 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +455 -95
- 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 +79 -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 +531 -99
- package/src/index.ts +527 -104
- 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
|
@@ -103,6 +103,56 @@ describe('package target policy', () => {
|
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
+
it('preserves cross-project dependsOn references in apply and check', async () => {
|
|
107
|
+
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-pkg-target-'));
|
|
108
|
+
try {
|
|
109
|
+
await writeJson(join(root, 'package.json'), {
|
|
110
|
+
name: '@scope/root',
|
|
111
|
+
private: true,
|
|
112
|
+
workspaces: ['packages/*'],
|
|
113
|
+
});
|
|
114
|
+
await writeJson(join(root, 'packages/lib/package.json'), {
|
|
115
|
+
name: '@scope/lib',
|
|
116
|
+
dependencies: { '@scope/schema': 'workspace:*' },
|
|
117
|
+
nx: {
|
|
118
|
+
name: 'lib',
|
|
119
|
+
targets: {
|
|
120
|
+
// `wire-schema:build` is Nx's project:target syntax pointing at a real
|
|
121
|
+
// sibling project; only its suffix collides with this project's own
|
|
122
|
+
// `build`, which is exactly what the legacy colon-name migration used
|
|
123
|
+
// to swallow.
|
|
124
|
+
build: {
|
|
125
|
+
executor: 'nx:run-commands',
|
|
126
|
+
options: { command: 'tsc --build tsconfig.lib.json', cwd: '{projectRoot}' },
|
|
127
|
+
dependsOn: ['^build', 'wire-schema:build'],
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
await writeJson(join(root, 'packages/schema/package.json'), {
|
|
133
|
+
name: '@scope/schema',
|
|
134
|
+
nx: {
|
|
135
|
+
name: 'wire-schema',
|
|
136
|
+
targets: {
|
|
137
|
+
build: {
|
|
138
|
+
executor: 'nx:run-commands',
|
|
139
|
+
options: { command: 'bun run emit.ts', cwd: '{projectRoot}' },
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
applyPackageTargetPolicy(root);
|
|
146
|
+
|
|
147
|
+
const lib = JSON.parse(await readFile(join(root, 'packages/lib/package.json'), 'utf8'));
|
|
148
|
+
expect(lib.nx.targets.build.dependsOn).toEqual(['^build', 'wire-schema:build']);
|
|
149
|
+
const issues = checkPackageTargetPolicy(root);
|
|
150
|
+
expect(issues.filter((issue) => issue.message.includes('wire-schema:build'))).toEqual([]);
|
|
151
|
+
} finally {
|
|
152
|
+
await rm(root, { recursive: true, force: true });
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
106
156
|
it('removes noop aggregate build targets matching resolved plugin output', async () => {
|
|
107
157
|
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-pkg-target-'));
|
|
108
158
|
try {
|
|
@@ -229,6 +229,38 @@ function isBuildOutputDependencyPattern(dependency: string): boolean {
|
|
|
229
229
|
return BUILD_OUTPUT_DEPENDENCIES.some((pattern) => pattern === dependency);
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
+
/**
|
|
233
|
+
* `project:target` in dependsOn is Nx's cross-project dependency syntax. When
|
|
234
|
+
* the prefix names a real workspace project, the entry references that
|
|
235
|
+
* project's target — it is not a legacy colon-named local target, so neither
|
|
236
|
+
* migration nor validation may touch it.
|
|
237
|
+
*/
|
|
238
|
+
function isCrossProjectTargetDependency(dependency: string, projectNames?: ReadonlySet<string>): boolean {
|
|
239
|
+
const split = dependency.lastIndexOf(':');
|
|
240
|
+
return split > 0 && projectNames?.has(dependency.slice(0, split)) === true;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function projectNamesFromOptions(options: PackageTargetPolicyOptions): ReadonlySet<string> | undefined {
|
|
244
|
+
return options.resolvedTargetsByProject ? new Set(options.resolvedTargetsByProject.keys()) : undefined;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* The resolved-target map alone can be absent (unit-scale callers), so the
|
|
249
|
+
* workspace's declared package project names back it up: a dependsOn prefix is
|
|
250
|
+
* cross-project if either source knows the name.
|
|
251
|
+
*/
|
|
252
|
+
function collectWorkspaceProjectNames(root: string, options: PackageTargetPolicyOptions): ReadonlySet<string> {
|
|
253
|
+
const names = new Set(projectNamesFromOptions(options) ?? []);
|
|
254
|
+
for (const packageJsonPath of listWorkspacePackageJsonPaths(root)) {
|
|
255
|
+
const pkg = readJsonObject(packageJsonPath);
|
|
256
|
+
const projectName = pkg ? packageNxProjectName(pkg) : null;
|
|
257
|
+
if (projectName) {
|
|
258
|
+
names.add(projectName);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return names;
|
|
262
|
+
}
|
|
263
|
+
|
|
232
264
|
function expectedTargetDependencies(targetName: string): string[] {
|
|
233
265
|
if (targetName === 'preview') return ['build'];
|
|
234
266
|
if (targetName.endsWith('-js')) return ['^*-js'];
|
|
@@ -587,6 +619,7 @@ function validateExplicitNxTargets(
|
|
|
587
619
|
pkg: Record<string, unknown>,
|
|
588
620
|
packagePath: string,
|
|
589
621
|
resolvedProject?: ReadonlySet<string> | ResolvedProjectTargets,
|
|
622
|
+
projectNames?: ReadonlySet<string>,
|
|
590
623
|
): NxPolicyIssue[] {
|
|
591
624
|
const issues = validatePlatformTargetDependencies(packagePath, resolvedProject);
|
|
592
625
|
const nx = recordProperty(pkg, 'nx');
|
|
@@ -611,6 +644,7 @@ function validateExplicitNxTargets(
|
|
|
611
644
|
rawTarget,
|
|
612
645
|
`${packagePath}: nx.targets.${targetName}`,
|
|
613
646
|
resolvedProjectTargetNames(resolvedProject),
|
|
647
|
+
projectNames,
|
|
614
648
|
),
|
|
615
649
|
);
|
|
616
650
|
}
|
|
@@ -684,6 +718,7 @@ function validateTargetDependencies(
|
|
|
684
718
|
target: Record<string, unknown>,
|
|
685
719
|
label: string,
|
|
686
720
|
resolvedTargets?: ReadonlySet<string>,
|
|
721
|
+
projectNames?: ReadonlySet<string>,
|
|
687
722
|
): NxPolicyIssue[] {
|
|
688
723
|
if (!Array.isArray(target.dependsOn)) {
|
|
689
724
|
return [];
|
|
@@ -693,6 +728,9 @@ function validateTargetDependencies(
|
|
|
693
728
|
if (typeof dependency !== 'string') {
|
|
694
729
|
continue;
|
|
695
730
|
}
|
|
731
|
+
if (isCrossProjectTargetDependency(dependency, projectNames)) {
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
696
734
|
if (dependency.includes(':')) {
|
|
697
735
|
issues.push({
|
|
698
736
|
path: label.split(':')[0]?.trim() ?? label,
|
|
@@ -959,8 +997,10 @@ function validateTestEntrypointPresenceTree(
|
|
|
959
997
|
export function checkPackageTargetPolicyTree(tree: Tree, options: PackageTargetPolicyOptions = {}): NxPolicyIssue[] {
|
|
960
998
|
const issues: NxPolicyIssue[] = [];
|
|
961
999
|
const workspaceNames = collectWorkspaceNamesTree(tree);
|
|
1000
|
+
const projects = getProjects(tree);
|
|
1001
|
+
const projectNames = new Set([...(projectNamesFromOptions(options) ?? []), ...projects.keys()]);
|
|
962
1002
|
|
|
963
|
-
for (const [projectName, config] of
|
|
1003
|
+
for (const [projectName, config] of projects) {
|
|
964
1004
|
const pkgPath = `${config.root}/package.json`;
|
|
965
1005
|
if (!tree.exists(pkgPath)) {
|
|
966
1006
|
continue;
|
|
@@ -970,7 +1010,7 @@ export function checkPackageTargetPolicyTree(tree: Tree, options: PackageTargetP
|
|
|
970
1010
|
const resolvedProject = options.resolvedTargetsByProject?.get(projectName);
|
|
971
1011
|
const resolvedTargets = resolvedProjectTargetNames(resolvedProject);
|
|
972
1012
|
|
|
973
|
-
issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject));
|
|
1013
|
+
issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject, projectNames));
|
|
974
1014
|
issues.push(...validateTestEntrypointPresenceTree(tree, packagePath, pkg));
|
|
975
1015
|
issues.push(...validatePackageScriptPolicy(pkg, packagePath, workspaceNames, { resolvedTargets }));
|
|
976
1016
|
}
|
|
@@ -986,8 +1026,10 @@ export function checkPackageTargetPolicyTree(tree: Tree, options: PackageTargetP
|
|
|
986
1026
|
export function applyPackageTargetPolicyTree(tree: Tree, options: PackageTargetPolicyOptions = {}): boolean {
|
|
987
1027
|
let changed = false;
|
|
988
1028
|
const workspaceNames = collectWorkspaceNamesTree(tree);
|
|
1029
|
+
const projects = getProjects(tree);
|
|
1030
|
+
const projectNames = new Set([...(projectNamesFromOptions(options) ?? []), ...projects.keys()]);
|
|
989
1031
|
|
|
990
|
-
for (const [projectName, config] of
|
|
1032
|
+
for (const [projectName, config] of projects) {
|
|
991
1033
|
const pkgPath = `${config.root}/package.json`;
|
|
992
1034
|
if (!tree.exists(pkgPath)) {
|
|
993
1035
|
continue;
|
|
@@ -998,7 +1040,7 @@ export function applyPackageTargetPolicyTree(tree: Tree, options: PackageTargetP
|
|
|
998
1040
|
|
|
999
1041
|
updateJson(tree, pkgPath, (pkg: Record<string, unknown>) => {
|
|
1000
1042
|
let packageChanged = migratePackageColonTargets(pkg, resolvedTargets);
|
|
1001
|
-
packageChanged = rewriteColonTargetDependenciesInPackage(pkg, resolvedTargets) || packageChanged;
|
|
1043
|
+
packageChanged = rewriteColonTargetDependenciesInPackage(pkg, resolvedTargets, projectNames) || packageChanged;
|
|
1002
1044
|
packageChanged = removePackageColonTargets(pkg) || packageChanged;
|
|
1003
1045
|
packageChanged = removeRedundantNoopBuildTarget(pkg, resolvedProject) || packageChanged;
|
|
1004
1046
|
packageChanged =
|
|
@@ -1032,6 +1074,7 @@ function removePackageColonTargets(pkg: Record<string, unknown>): boolean {
|
|
|
1032
1074
|
function rewriteColonTargetDependenciesInPackage(
|
|
1033
1075
|
pkg: Record<string, unknown>,
|
|
1034
1076
|
resolvedTargets?: ReadonlySet<string>,
|
|
1077
|
+
projectNames?: ReadonlySet<string>,
|
|
1035
1078
|
): boolean {
|
|
1036
1079
|
const nx = recordProperty(pkg, 'nx');
|
|
1037
1080
|
const targets = nx ? recordProperty(nx, 'targets') : null;
|
|
@@ -1049,6 +1092,9 @@ function rewriteColonTargetDependenciesInPackage(
|
|
|
1049
1092
|
if (typeof dependency !== 'string' || !dependency.includes(':')) {
|
|
1050
1093
|
return dependency;
|
|
1051
1094
|
}
|
|
1095
|
+
if (isCrossProjectTargetDependency(dependency, projectNames)) {
|
|
1096
|
+
return dependency;
|
|
1097
|
+
}
|
|
1052
1098
|
const next = scriptAliases.get(dependency) ?? replacementTargetName(dependency, null, resolvedTargets);
|
|
1053
1099
|
if (!next) {
|
|
1054
1100
|
return dependency;
|
|
@@ -1163,18 +1209,19 @@ export function checkPackageTargets(
|
|
|
1163
1209
|
pkg: Record<string, unknown>,
|
|
1164
1210
|
packagePath: string,
|
|
1165
1211
|
resolvedTargets?: ReadonlySet<string>,
|
|
1212
|
+
projectNames?: ReadonlySet<string>,
|
|
1166
1213
|
): NxPolicyIssue[] {
|
|
1167
|
-
return [...validateExplicitNxTargets(pkg, packagePath, resolvedTargets)];
|
|
1214
|
+
return [...validateExplicitNxTargets(pkg, packagePath, resolvedTargets, projectNames)];
|
|
1168
1215
|
}
|
|
1169
1216
|
|
|
1170
1217
|
export function applyPackageTargets(
|
|
1171
1218
|
pkg: Record<string, unknown>,
|
|
1172
1219
|
packagePath: string,
|
|
1173
1220
|
workspaceNames: ReadonlySet<string>,
|
|
1174
|
-
options: { resolvedTargets?: ReadonlySet<string> } = {},
|
|
1221
|
+
options: { resolvedTargets?: ReadonlySet<string>; projectNames?: ReadonlySet<string> } = {},
|
|
1175
1222
|
): boolean {
|
|
1176
1223
|
let changed = migratePackageColonTargets(pkg, options.resolvedTargets);
|
|
1177
|
-
changed = rewriteColonTargetDependenciesInPackage(pkg, options.resolvedTargets) || changed;
|
|
1224
|
+
changed = rewriteColonTargetDependenciesInPackage(pkg, options.resolvedTargets, options.projectNames) || changed;
|
|
1178
1225
|
changed = removePackageColonTargets(pkg) || changed;
|
|
1179
1226
|
changed = applyPackageScriptPolicyForPkg(pkg, packagePath, workspaceNames, options) || changed;
|
|
1180
1227
|
return changed;
|
|
@@ -1183,6 +1230,7 @@ export function applyPackageTargets(
|
|
|
1183
1230
|
export function checkPackageTargetPolicy(root: string, options: PackageTargetPolicyOptions = {}): NxPolicyIssue[] {
|
|
1184
1231
|
const issues: NxPolicyIssue[] = [];
|
|
1185
1232
|
const workspaceNames = getWorkspacePackageNames(root);
|
|
1233
|
+
const projectNames = collectWorkspaceProjectNames(root, options);
|
|
1186
1234
|
|
|
1187
1235
|
for (const packageJsonPath of listWorkspacePackageJsonPaths(root)) {
|
|
1188
1236
|
const pkg = readJsonObject(packageJsonPath);
|
|
@@ -1193,7 +1241,7 @@ export function checkPackageTargetPolicy(root: string, options: PackageTargetPol
|
|
|
1193
1241
|
const projectName = packageNxProjectName(pkg);
|
|
1194
1242
|
const resolvedProject = projectName ? options.resolvedTargetsByProject?.get(projectName) : undefined;
|
|
1195
1243
|
|
|
1196
|
-
issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject));
|
|
1244
|
+
issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject, projectNames));
|
|
1197
1245
|
issues.push(...validateTestEntrypointPresence(root, packagePath, pkg));
|
|
1198
1246
|
issues.push(...validatePackageScriptPolicy(pkg, packagePath, workspaceNames, { resolvedTargets: resolvedProject }));
|
|
1199
1247
|
}
|
|
@@ -1204,6 +1252,7 @@ export function checkPackageTargetPolicy(root: string, options: PackageTargetPol
|
|
|
1204
1252
|
export function applyPackageTargetPolicy(root: string, options: PackageTargetPolicyOptions = {}): boolean {
|
|
1205
1253
|
let changed = false;
|
|
1206
1254
|
const workspaceNames = getWorkspacePackageNames(root);
|
|
1255
|
+
const projectNames = collectWorkspaceProjectNames(root, options);
|
|
1207
1256
|
|
|
1208
1257
|
for (const packageJsonPath of listWorkspacePackageJsonPaths(root)) {
|
|
1209
1258
|
const pkg = readJsonObject(packageJsonPath);
|
|
@@ -1216,7 +1265,7 @@ export function applyPackageTargetPolicy(root: string, options: PackageTargetPol
|
|
|
1216
1265
|
const resolvedTargets = resolvedProjectTargetNames(resolvedProject);
|
|
1217
1266
|
|
|
1218
1267
|
let packageChanged = migratePackageColonTargets(pkg, resolvedTargets);
|
|
1219
|
-
packageChanged = rewriteColonTargetDependenciesInPackage(pkg, resolvedTargets) || packageChanged;
|
|
1268
|
+
packageChanged = rewriteColonTargetDependenciesInPackage(pkg, resolvedTargets, projectNames) || packageChanged;
|
|
1220
1269
|
packageChanged = removePackageColonTargets(pkg) || packageChanged;
|
|
1221
1270
|
packageChanged = removeRedundantNoopBuildTarget(pkg, resolvedProject) || packageChanged;
|
|
1222
1271
|
packageChanged =
|
|
@@ -33,7 +33,7 @@ function validNxJson(): Record<string, unknown> {
|
|
|
33
33
|
|
|
34
34
|
function validTargetDefaults(): Record<string, unknown> {
|
|
35
35
|
return {
|
|
36
|
-
build: { cache: true
|
|
36
|
+
build: { cache: true },
|
|
37
37
|
clean: { executor: '@smoothbricks/nx-plugin:clean-outputs', cache: false },
|
|
38
38
|
};
|
|
39
39
|
}
|
|
@@ -162,43 +162,31 @@ describe('pure core: checkWorkspaceConfig', () => {
|
|
|
162
162
|
namedInputs: validNamedInputs(),
|
|
163
163
|
});
|
|
164
164
|
expect(issues.some((i) => i.message.includes('build.cache must be true'))).toBe(true);
|
|
165
|
-
expect(issues.some((i) => i.message.includes('build.outputs'))).toBe(true);
|
|
166
|
-
});
|
|
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
165
|
expect(issues.some((i) => i.message.includes('build.outputs'))).toBe(false);
|
|
178
166
|
});
|
|
179
167
|
|
|
180
|
-
it('rejects build outputs
|
|
168
|
+
it('rejects a build outputs default that would clobber the inferred aggregate', () => {
|
|
181
169
|
const issues = checkWorkspaceConfig({
|
|
182
170
|
plugins: validPlugins(),
|
|
183
171
|
targetDefaults: {
|
|
184
172
|
...validTargetDefaults(),
|
|
185
|
-
build: { cache: true, outputs: ['{projectRoot}/dist
|
|
173
|
+
build: { cache: true, outputs: ['{projectRoot}/dist'] },
|
|
186
174
|
},
|
|
187
175
|
namedInputs: validNamedInputs(),
|
|
188
176
|
});
|
|
189
|
-
expect(issues.some((i) => i.message.includes('build.outputs'))).toBe(true);
|
|
177
|
+
expect(issues.some((i) => i.message.includes('targetDefaults.build.outputs must not be set'))).toBe(true);
|
|
190
178
|
});
|
|
191
179
|
|
|
192
|
-
it('rejects build
|
|
180
|
+
it('rejects a build dependsOn default that would clobber the inferred aggregate', () => {
|
|
193
181
|
const issues = checkWorkspaceConfig({
|
|
194
182
|
plugins: validPlugins(),
|
|
195
183
|
targetDefaults: {
|
|
196
184
|
...validTargetDefaults(),
|
|
197
|
-
build: { cache: true,
|
|
185
|
+
build: { cache: true, dependsOn: ['^build'] },
|
|
198
186
|
},
|
|
199
187
|
namedInputs: validNamedInputs(),
|
|
200
188
|
});
|
|
201
|
-
expect(issues.some((i) => i.message.includes('build.
|
|
189
|
+
expect(issues.some((i) => i.message.includes('targetDefaults.build.dependsOn must not be set'))).toBe(true);
|
|
202
190
|
});
|
|
203
191
|
|
|
204
192
|
it('detects missing sharedGlobals', () => {
|
|
@@ -220,7 +208,7 @@ describe('pure core: applyWorkspaceConfig', () => {
|
|
|
220
208
|
expect(applyWorkspaceConfig(nxJson)).toBe(false);
|
|
221
209
|
});
|
|
222
210
|
|
|
223
|
-
it('
|
|
211
|
+
it('strips a build outputs default so the inferred aggregate claims nothing', () => {
|
|
224
212
|
const nxJson = {
|
|
225
213
|
...validNxJson(),
|
|
226
214
|
targetDefaults: {
|
|
@@ -228,22 +216,22 @@ describe('pure core: applyWorkspaceConfig', () => {
|
|
|
228
216
|
build: { cache: true, outputs: ['{projectRoot}/dist', '{projectRoot}/dist-node'] },
|
|
229
217
|
},
|
|
230
218
|
};
|
|
231
|
-
expect(applyWorkspaceConfig(nxJson)).toBe(
|
|
219
|
+
expect(applyWorkspaceConfig(nxJson)).toBe(true);
|
|
232
220
|
const build = expectRecord(expectRecord(nxJson.targetDefaults).build);
|
|
233
|
-
expect(build
|
|
221
|
+
expect(build).toEqual({ cache: true });
|
|
234
222
|
});
|
|
235
223
|
|
|
236
|
-
it('
|
|
224
|
+
it('strips a build dependsOn default so the inferred host-aware edge survives', () => {
|
|
237
225
|
const nxJson = {
|
|
238
226
|
...validNxJson(),
|
|
239
227
|
targetDefaults: {
|
|
240
228
|
...validTargetDefaults(),
|
|
241
|
-
build: { cache: true,
|
|
229
|
+
build: { cache: true, dependsOn: ['^build'] },
|
|
242
230
|
},
|
|
243
231
|
};
|
|
244
232
|
expect(applyWorkspaceConfig(nxJson)).toBe(true);
|
|
245
233
|
const build = expectRecord(expectRecord(nxJson.targetDefaults).build);
|
|
246
|
-
expect(build
|
|
234
|
+
expect(build).toEqual({ cache: true });
|
|
247
235
|
});
|
|
248
236
|
|
|
249
237
|
it('fixes missing plugins', () => {
|
|
@@ -391,17 +379,14 @@ describe('Tree: applyWorkspaceConfigTree', () => {
|
|
|
391
379
|
const tree = createTreeWithEmptyWorkspace();
|
|
392
380
|
writeJson(tree, 'nx.json', {
|
|
393
381
|
plugins: validPlugins(),
|
|
394
|
-
targetDefaults: { build: { cache: false } },
|
|
382
|
+
targetDefaults: { build: { cache: false, outputs: ['{projectRoot}/dist'] } },
|
|
395
383
|
namedInputs: validNamedInputs(),
|
|
396
384
|
});
|
|
397
385
|
|
|
398
386
|
expect(applyWorkspaceConfigTree(tree)).toBe(true);
|
|
399
387
|
|
|
400
388
|
const nxJson = readJson(tree, 'nx.json');
|
|
401
|
-
expect(expectRecord(nxJson.targetDefaults).build).toEqual({
|
|
402
|
-
cache: true,
|
|
403
|
-
outputs: ['{projectRoot}/dist'],
|
|
404
|
-
});
|
|
389
|
+
expect(expectRecord(nxJson.targetDefaults).build).toEqual({ cache: true });
|
|
405
390
|
expect(expectRecord(nxJson.targetDefaults).clean).toEqual({
|
|
406
391
|
executor: '@smoothbricks/nx-plugin:clean-outputs',
|
|
407
392
|
cache: false,
|
|
@@ -186,40 +186,36 @@ function validateBuildTargetDefault(
|
|
|
186
186
|
if (build?.cache !== true) {
|
|
187
187
|
issues.push({ path: nxJsonPath, message: 'targetDefaults.build.cache must be true' });
|
|
188
188
|
}
|
|
189
|
-
// dependsOn
|
|
190
|
-
//
|
|
191
|
-
//
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
189
|
+
// dependsOn and outputs are both owned by the inference plugin, and Nx gives
|
|
190
|
+
// targetDefaults precedence over inferred values, so anything set here lands
|
|
191
|
+
// on every project regardless of what inference knows about that project.
|
|
192
|
+
//
|
|
193
|
+
// dependsOn: the inferred aggregate carries the output families PLUS this
|
|
194
|
+
// host's platform-suffixed binary targets; a static list here would clobber
|
|
195
|
+
// the host-aware edge.
|
|
196
|
+
//
|
|
197
|
+
// outputs: `build` is an `nx:noop` aggregate that runs no command and writes
|
|
198
|
+
// no file — every artifact under dist belongs to the concrete target that
|
|
199
|
+
// emitted it. A workspace-wide `{projectRoot}/dist` makes the aggregate claim
|
|
200
|
+
// its children's trees, which caches those bytes a second time under the
|
|
201
|
+
// aggregate's hash and, worse, makes `github-ci nx-run-many
|
|
202
|
+
// --collect-outputs` attribute to `build` every file that happens to sit
|
|
203
|
+
// under dist: artifacts of platform targets the collect deliberately
|
|
204
|
+
// excluded, and stale artifacts of a target that did not run at all. The
|
|
205
|
+
// publish workflow then applies two collected trees that both claim the same
|
|
206
|
+
// platform binary and `apply-outputs` rejects the overlap. A project whose
|
|
207
|
+
// `build` genuinely emits files declares its own outputs in package.json,
|
|
208
|
+
// where the claim is scoped to the project that can honour it.
|
|
209
|
+
for (const property of ['dependsOn', 'outputs'] as const) {
|
|
210
|
+
if (build !== null && property in build) {
|
|
211
|
+
issues.push({
|
|
212
|
+
path: nxJsonPath,
|
|
213
|
+
message: `targetDefaults.build.${property} must not be set; @smoothbricks/nx-plugin infers the build aggregate`,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
206
216
|
}
|
|
207
217
|
}
|
|
208
218
|
|
|
209
|
-
/**
|
|
210
|
-
* Build outputs must include the canonical dist tree; additional project-root
|
|
211
|
-
* dist siblings (dist-node, dist-test, …) are legitimate secondary outputs a
|
|
212
|
-
* repo may aggregate into `build` — the policy pins outputs under the project
|
|
213
|
-
* root's dist family, not the exact array.
|
|
214
|
-
*/
|
|
215
|
-
function isValidBuildOutputs(outputs: unknown): outputs is string[] {
|
|
216
|
-
return (
|
|
217
|
-
Array.isArray(outputs) &&
|
|
218
|
-
outputs.includes('{projectRoot}/dist') &&
|
|
219
|
-
outputs.every((output) => typeof output === 'string' && /^\{projectRoot\}\/dist(-[\w.-]+)?$/.test(output))
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
219
|
function validateCleanTargetDefault(
|
|
224
220
|
nxJson: Record<string, unknown>,
|
|
225
221
|
nxJsonPath: string,
|
|
@@ -281,14 +277,11 @@ function applyBuildTargetDefault(nxJson: Record<string, unknown>): boolean {
|
|
|
281
277
|
const targetDefaults = getOrCreateRecord(nxJson, 'targetDefaults');
|
|
282
278
|
const build = getOrCreateRecord(targetDefaults, 'build');
|
|
283
279
|
let changed = setBooleanProperty(build, 'cache', true);
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
if ('dependsOn' in build) {
|
|
290
|
-
delete build.dependsOn;
|
|
291
|
-
changed = true;
|
|
280
|
+
for (const property of ['dependsOn', 'outputs'] as const) {
|
|
281
|
+
if (property in build) {
|
|
282
|
+
delete build[property];
|
|
283
|
+
changed = true;
|
|
284
|
+
}
|
|
292
285
|
}
|
|
293
286
|
return changed;
|
|
294
287
|
}
|