@smoothbricks/nx-plugin 0.3.6 → 0.3.7
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.js +8 -3
- 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 +3 -3
- package/src/index.ts +8 -3
- 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,IA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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.js
CHANGED
|
@@ -463,14 +463,19 @@ function createNapiTargets(projectRoot, config) {
|
|
|
463
463
|
return targets;
|
|
464
464
|
}
|
|
465
465
|
function createNapiTestTarget(projectRoot, hasDedicatedBunfig) {
|
|
466
|
-
const configFlag = hasDedicatedBunfig ? ' --config
|
|
466
|
+
const configFlag = hasDedicatedBunfig ? ' --config=../bunfig.napi-test.toml' : ' --config=../bunfig.toml';
|
|
467
467
|
return {
|
|
468
468
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
469
469
|
cache: true,
|
|
470
470
|
dependsOn: ['cargo-test', 'cargo-napi', 'tsc-js', '^build', 'build'],
|
|
471
471
|
options: {
|
|
472
|
-
|
|
473
|
-
cwd
|
|
472
|
+
// cwd is src/, not the package root: `bun test <arg>` treats the arg as
|
|
473
|
+
// a FILTER and scans the whole cwd tree for test files, and a Rust
|
|
474
|
+
// package's cargo target/ directory turns that scan into tens of
|
|
475
|
+
// seconds. bun only auto-loads bunfig from the cwd, so the package
|
|
476
|
+
// config is passed explicitly.
|
|
477
|
+
command: `bun test${configFlag} --timeout=30000 native.test.ts`,
|
|
478
|
+
cwd: `${projectRoot}/src`,
|
|
474
479
|
timeoutMs: 120000,
|
|
475
480
|
killAfterMs: 10000,
|
|
476
481
|
},
|
|
@@ -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.7",
|
|
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
|
@@ -405,8 +405,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
405
405
|
cache: true,
|
|
406
406
|
dependsOn: ['cargo-test', 'cargo-napi', 'tsc-js', '^build', 'build'],
|
|
407
407
|
options: {
|
|
408
|
-
command: 'bun test --timeout=30000
|
|
409
|
-
cwd: 'packages/cowshed',
|
|
408
|
+
command: 'bun test --config=../bunfig.toml --timeout=30000 native.test.ts',
|
|
409
|
+
cwd: 'packages/cowshed/src',
|
|
410
410
|
timeoutMs: 120000,
|
|
411
411
|
killAfterMs: 10000,
|
|
412
412
|
},
|
|
@@ -414,7 +414,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
414
414
|
await workspace.write('packages/cowshed/bunfig.napi-test.toml', '[test]\n');
|
|
415
415
|
const targetsWithDedicatedBunfig = await inferProjectTargets(workspace, 'packages/cowshed/package.json');
|
|
416
416
|
expect(targetsWithDedicatedBunfig['napi-test']?.options?.command).toBe(
|
|
417
|
-
'bun --config
|
|
417
|
+
'bun test --config=../bunfig.napi-test.toml --timeout=30000 native.test.ts',
|
|
418
418
|
);
|
|
419
419
|
} finally {
|
|
420
420
|
await workspace.cleanup();
|
package/src/index.ts
CHANGED
|
@@ -568,14 +568,19 @@ function createNapiTargets(projectRoot: string, config: ResolvedNapiConfig): Rec
|
|
|
568
568
|
}
|
|
569
569
|
|
|
570
570
|
function createNapiTestTarget(projectRoot: string, hasDedicatedBunfig: boolean): TargetConfiguration {
|
|
571
|
-
const configFlag = hasDedicatedBunfig ? ' --config
|
|
571
|
+
const configFlag = hasDedicatedBunfig ? ' --config=../bunfig.napi-test.toml' : ' --config=../bunfig.toml';
|
|
572
572
|
return {
|
|
573
573
|
executor: '@smoothbricks/nx-plugin:bounded-exec',
|
|
574
574
|
cache: true,
|
|
575
575
|
dependsOn: ['cargo-test', 'cargo-napi', 'tsc-js', '^build', 'build'],
|
|
576
576
|
options: {
|
|
577
|
-
|
|
578
|
-
cwd
|
|
577
|
+
// cwd is src/, not the package root: `bun test <arg>` treats the arg as
|
|
578
|
+
// a FILTER and scans the whole cwd tree for test files, and a Rust
|
|
579
|
+
// package's cargo target/ directory turns that scan into tens of
|
|
580
|
+
// seconds. bun only auto-loads bunfig from the cwd, so the package
|
|
581
|
+
// config is passed explicitly.
|
|
582
|
+
command: `bun test${configFlag} --timeout=30000 native.test.ts`,
|
|
583
|
+
cwd: `${projectRoot}/src`,
|
|
579
584
|
timeoutMs: 120000,
|
|
580
585
|
killAfterMs: 10000,
|
|
581
586
|
},
|
|
@@ -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
|
|