@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.
@@ -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
- if (isCrossProjectTargetDependency(dependency, projectNames)) {
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');