@smoothbricks/nx-plugin 0.4.0 → 0.4.2
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 +80 -20
- package/dist/bin/smoo-nx-cargo-hash.d.ts +3 -0
- package/dist/bin/smoo-nx-cargo-hash.d.ts.map +1 -0
- package/dist/bin/smoo-nx-cargo-hash.js +16 -0
- package/dist/cargo-source-hash.d.ts +12 -0
- package/dist/cargo-source-hash.d.ts.map +1 -0
- package/dist/cargo-source-hash.js +208 -0
- package/dist/cargo-workspace.d.ts +22 -20
- package/dist/cargo-workspace.d.ts.map +1 -1
- package/dist/cargo-workspace.js +268 -58
- package/dist/cross-check-policy.d.ts +5 -10
- package/dist/cross-check-policy.d.ts.map +1 -1
- package/dist/cross-check-policy.js +7 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +344 -191
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +2 -1
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +54 -0
- package/package.json +9 -3
- package/src/bin/smoo-nx-cargo-hash.ts +18 -0
- package/src/cargo-source-hash.test.ts +51 -0
- package/src/cargo-source-hash.ts +138 -0
- package/src/cargo-workspace.test.ts +236 -90
- package/src/cargo-workspace.ts +337 -64
- package/src/cross-check-policy.test.ts +37 -7
- package/src/cross-check-policy.ts +9 -21
- package/src/ensure-built.test.ts +8 -3
- package/src/index.test.ts +340 -49
- package/src/index.ts +383 -224
- package/src/package-target-policy.test.ts +13 -0
- package/src/package-target-policy.ts +2 -1
- package/src/workspace-config-policy.test.ts +48 -0
- package/src/workspace-config-policy.ts +60 -0
|
@@ -546,6 +546,19 @@ describe('per-package checkPackageTargets', () => {
|
|
|
546
546
|
const issues = checkPackageTargets(pkg, 'packages/lib');
|
|
547
547
|
expect(issues.some((i) => i.message.includes('build:ts') && i.message.includes('colon'))).toBe(true);
|
|
548
548
|
});
|
|
549
|
+
|
|
550
|
+
it('accepts the Nx inferred-target merge marker', () => {
|
|
551
|
+
const pkg = {
|
|
552
|
+
nx: {
|
|
553
|
+
name: 'lib',
|
|
554
|
+
targets: {
|
|
555
|
+
build: { dependsOn: ['...', 'rust-dist'] },
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
expect(checkPackageTargets(pkg, 'packages/lib', new Set(['build', 'rust-dist']))).toEqual([]);
|
|
561
|
+
});
|
|
549
562
|
});
|
|
550
563
|
|
|
551
564
|
describe('per-package applyPackageTargets', () => {
|
|
@@ -728,7 +728,8 @@ function validateTargetDependencies(
|
|
|
728
728
|
if (typeof dependency !== 'string') {
|
|
729
729
|
continue;
|
|
730
730
|
}
|
|
731
|
-
|
|
731
|
+
// Nx expands "..." to the inferred target's existing dependencies before merging explicit entries.
|
|
732
|
+
if (dependency === '...' || isCrossProjectTargetDependency(dependency, projectNames)) {
|
|
732
733
|
continue;
|
|
733
734
|
}
|
|
734
735
|
if (dependency.includes(':')) {
|
|
@@ -189,6 +189,18 @@ describe('pure core: checkWorkspaceConfig', () => {
|
|
|
189
189
|
expect(issues.some((i) => i.message.includes('targetDefaults.build.dependsOn must not be set'))).toBe(true);
|
|
190
190
|
});
|
|
191
191
|
|
|
192
|
+
it('rejects a test dependsOn default that would clobber inferred cargo-test', () => {
|
|
193
|
+
const issues = checkWorkspaceConfig({
|
|
194
|
+
plugins: validPlugins(),
|
|
195
|
+
targetDefaults: {
|
|
196
|
+
...validTargetDefaults(),
|
|
197
|
+
test: { cache: true, dependsOn: ['^build', 'build'] },
|
|
198
|
+
},
|
|
199
|
+
namedInputs: validNamedInputs(),
|
|
200
|
+
});
|
|
201
|
+
expect(issues.some((i) => i.message.includes('targetDefaults.test.dependsOn must not be set'))).toBe(true);
|
|
202
|
+
});
|
|
203
|
+
|
|
192
204
|
it('detects missing sharedGlobals', () => {
|
|
193
205
|
const issues = checkWorkspaceConfig({
|
|
194
206
|
plugins: validPlugins(),
|
|
@@ -203,6 +215,29 @@ describe('pure core: checkWorkspaceConfig', () => {
|
|
|
203
215
|
});
|
|
204
216
|
|
|
205
217
|
describe('pure core: applyWorkspaceConfig', () => {
|
|
218
|
+
it('removes workspace-wide lint commands while preserving shared cache policy', () => {
|
|
219
|
+
const nxJson = {
|
|
220
|
+
...validNxJson(),
|
|
221
|
+
targetDefaults: {
|
|
222
|
+
...validTargetDefaults(),
|
|
223
|
+
lint: {
|
|
224
|
+
cache: true,
|
|
225
|
+
executor: 'nx:run-commands',
|
|
226
|
+
dependsOn: ['typecheck-tests', 'cargo-lint'],
|
|
227
|
+
inputs: ['default'],
|
|
228
|
+
outputs: ['dist'],
|
|
229
|
+
options: { command: 'eslint packages/*/src' },
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
expect(checkWorkspaceConfig(nxJson).some((issue) => issue.message.includes('targetDefaults.lint.'))).toBe(true);
|
|
234
|
+
expect(applyWorkspaceConfig(nxJson)).toBe(true);
|
|
235
|
+
expect(nxJson.targetDefaults.lint).toMatchObject({ cache: true });
|
|
236
|
+
expect(Object.keys(nxJson.targetDefaults.lint)).toEqual(['cache']);
|
|
237
|
+
expect(checkWorkspaceConfig(nxJson)).toEqual([]);
|
|
238
|
+
expect(applyWorkspaceConfig(nxJson)).toBe(false);
|
|
239
|
+
});
|
|
240
|
+
|
|
206
241
|
it('returns false for already-valid config', () => {
|
|
207
242
|
const nxJson = validNxJson();
|
|
208
243
|
expect(applyWorkspaceConfig(nxJson)).toBe(false);
|
|
@@ -234,6 +269,19 @@ describe('pure core: applyWorkspaceConfig', () => {
|
|
|
234
269
|
expect(build).toEqual({ cache: true });
|
|
235
270
|
});
|
|
236
271
|
|
|
272
|
+
it('strips a test dependsOn default so inferred cargo-test survives', () => {
|
|
273
|
+
const nxJson = {
|
|
274
|
+
...validNxJson(),
|
|
275
|
+
targetDefaults: {
|
|
276
|
+
...validTargetDefaults(),
|
|
277
|
+
test: { cache: true, dependsOn: ['^build', 'build'] },
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
expect(applyWorkspaceConfig(nxJson)).toBe(true);
|
|
281
|
+
const test = expectRecord(expectRecord(nxJson.targetDefaults).test);
|
|
282
|
+
expect(test).toEqual({ cache: true });
|
|
283
|
+
});
|
|
284
|
+
|
|
237
285
|
it('fixes missing plugins', () => {
|
|
238
286
|
const nxJson: Record<string, unknown> = {
|
|
239
287
|
plugins: [],
|
|
@@ -70,6 +70,11 @@ export function checkWorkspaceConfig(nxJson: Record<string, unknown>): NxPolicyI
|
|
|
70
70
|
// Build target default
|
|
71
71
|
validateBuildTargetDefault(nxJson, 'nx.json', issues);
|
|
72
72
|
|
|
73
|
+
// Test target default: dependsOn is inferred per project (cargo-test vs ^build/build)
|
|
74
|
+
validateTestTargetDefault(nxJson, 'nx.json', issues);
|
|
75
|
+
|
|
76
|
+
validateLintTargetDefault(nxJson, 'nx.json', issues);
|
|
77
|
+
|
|
73
78
|
// Clean target default
|
|
74
79
|
validateCleanTargetDefault(nxJson, 'nx.json', issues);
|
|
75
80
|
|
|
@@ -105,6 +110,8 @@ export function checkWorkspaceConfig(nxJson: Record<string, unknown>): NxPolicyI
|
|
|
105
110
|
export function applyWorkspaceConfig(nxJson: Record<string, unknown>): boolean {
|
|
106
111
|
let changed = removeDisallowedTargetDefaults(nxJson);
|
|
107
112
|
changed = applyBuildTargetDefault(nxJson) || changed;
|
|
113
|
+
changed = applyTestTargetDefault(nxJson) || changed;
|
|
114
|
+
changed = applyLintTargetDefault(nxJson) || changed;
|
|
108
115
|
changed = applyCleanTargetDefault(nxJson) || changed;
|
|
109
116
|
changed = applyNamedInputDefaults(nxJson) || changed;
|
|
110
117
|
const currentPlugins = Array.isArray(nxJson.plugins) ? nxJson.plugins : [];
|
|
@@ -286,6 +293,59 @@ function applyBuildTargetDefault(nxJson: Record<string, unknown>): boolean {
|
|
|
286
293
|
return changed;
|
|
287
294
|
}
|
|
288
295
|
|
|
296
|
+
function validateTestTargetDefault(nxJson: Record<string, unknown>, nxJsonPath: string, issues: NxPolicyIssue[]): void {
|
|
297
|
+
const targetDefaults = recordProperty(nxJson, 'targetDefaults');
|
|
298
|
+
const test = targetDefaults ? recordProperty(targetDefaults, 'test') : null;
|
|
299
|
+
// Same clobber as targetDefaults.build.dependsOn: Nx replaces an inferred
|
|
300
|
+
// list rather than merging, so a workspace-wide [^build, build] unwires
|
|
301
|
+
// cargo-test from every Rust test aggregate. Cache stays allowed.
|
|
302
|
+
if (test !== null && 'dependsOn' in test) {
|
|
303
|
+
issues.push({
|
|
304
|
+
path: nxJsonPath,
|
|
305
|
+
message: 'targetDefaults.test.dependsOn must not be set; @smoothbricks/nx-plugin infers the test aggregate',
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function applyTestTargetDefault(nxJson: Record<string, unknown>): boolean {
|
|
311
|
+
const targetDefaults = recordProperty(nxJson, 'targetDefaults');
|
|
312
|
+
const test = targetDefaults ? recordProperty(targetDefaults, 'test') : null;
|
|
313
|
+
if (test === null || !('dependsOn' in test)) {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
delete test.dependsOn;
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const inferredLintProperties = ['executor', 'options', 'dependsOn', 'outputs', 'inputs'] as const;
|
|
321
|
+
|
|
322
|
+
function validateLintTargetDefault(nxJson: Record<string, unknown>, nxJsonPath: string, issues: NxPolicyIssue[]): void {
|
|
323
|
+
const defaults = recordProperty(nxJson, 'targetDefaults');
|
|
324
|
+
const lint = defaults ? recordProperty(defaults, 'lint') : null;
|
|
325
|
+
for (const property of inferredLintProperties) {
|
|
326
|
+
if (lint !== null && property in lint) {
|
|
327
|
+
issues.push({
|
|
328
|
+
path: nxJsonPath,
|
|
329
|
+
message: `targetDefaults.lint.${property} must not be set; @smoothbricks/nx-plugin infers lint from project sources`,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function applyLintTargetDefault(nxJson: Record<string, unknown>): boolean {
|
|
336
|
+
const defaults = recordProperty(nxJson, 'targetDefaults');
|
|
337
|
+
const lint = defaults ? recordProperty(defaults, 'lint') : null;
|
|
338
|
+
if (lint === null) return false;
|
|
339
|
+
let changed = false;
|
|
340
|
+
for (const property of inferredLintProperties) {
|
|
341
|
+
if (property in lint) {
|
|
342
|
+
delete lint[property];
|
|
343
|
+
changed = true;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return changed;
|
|
347
|
+
}
|
|
348
|
+
|
|
289
349
|
function applyCleanTargetDefault(nxJson: Record<string, unknown>): boolean {
|
|
290
350
|
const targetDefaults = getOrCreateRecord(nxJson, 'targetDefaults');
|
|
291
351
|
const clean = getOrCreateRecord(targetDefaults, 'clean');
|