@smoothbricks/nx-plugin 0.2.5 → 0.3.1
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 +44 -3
- package/dist/generators/create-package/generator.js +29 -2
- package/dist/generators/make-public/generator.js +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +192 -5
- package/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +4 -2
- package/dist/version-actions.cjs +8 -3
- package/dist/version-actions.d.cts.map +1 -1
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +8 -34
- package/package.json +3 -3
- package/src/bounded-test-policy.ts +46 -3
- package/src/generators/create-package/generator.ts +37 -9
- package/src/generators/make-public/generator.ts +5 -1
- package/src/index.test.ts +180 -9
- package/src/index.ts +210 -5
- package/src/package-target-policy.test.ts +9 -1
- package/src/release-config-policy.test.ts +22 -11
- package/src/typecheck-test-policy.test.ts +85 -38
- package/src/typecheck-test-policy.ts +6 -2
- package/src/version-actions.cts +12 -5
- package/src/workspace-config-policy.test.ts +37 -57
- package/src/workspace-config-policy.ts +11 -40
|
@@ -101,19 +101,19 @@ describe('checkTypecheckTestConfig', () => {
|
|
|
101
101
|
it('reports missing noEmit', () => {
|
|
102
102
|
const issues = checkTypecheckTestConfig({ compilerOptions: { composite: false } }, 'packages/app');
|
|
103
103
|
expect(issues.length).toBe(1);
|
|
104
|
-
expect(issues[0]
|
|
104
|
+
expect(issues[0]?.message).toContain('noEmit must be true');
|
|
105
105
|
});
|
|
106
106
|
|
|
107
107
|
it('reports composite = true', () => {
|
|
108
108
|
const issues = checkTypecheckTestConfig({ compilerOptions: { noEmit: true, composite: true } }, 'packages/app');
|
|
109
109
|
expect(issues.length).toBe(1);
|
|
110
|
-
expect(issues[0]
|
|
110
|
+
expect(issues[0]?.message).toContain('composite');
|
|
111
111
|
});
|
|
112
112
|
|
|
113
113
|
it('reports declaration = true', () => {
|
|
114
114
|
const issues = checkTypecheckTestConfig({ compilerOptions: { noEmit: true, declaration: true } }, 'packages/app');
|
|
115
115
|
expect(issues.length).toBe(1);
|
|
116
|
-
expect(issues[0]
|
|
116
|
+
expect(issues[0]?.message).toContain('declaration = true');
|
|
117
117
|
});
|
|
118
118
|
|
|
119
119
|
it('reports declarationMap = true', () => {
|
|
@@ -122,13 +122,13 @@ describe('checkTypecheckTestConfig', () => {
|
|
|
122
122
|
'packages/app',
|
|
123
123
|
);
|
|
124
124
|
expect(issues.length).toBe(1);
|
|
125
|
-
expect(issues[0]
|
|
125
|
+
expect(issues[0]?.message).toContain('declarationMap');
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
it('reports dist-test outDir', () => {
|
|
129
129
|
const issues = checkTypecheckTestConfig({ compilerOptions: { noEmit: true, outDir: 'dist-test' } }, 'packages/app');
|
|
130
130
|
expect(issues.length).toBe(1);
|
|
131
|
-
expect(issues[0]
|
|
131
|
+
expect(issues[0]?.message).toContain('dist-test');
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
it('reports dist-test tsBuildInfoFile', () => {
|
|
@@ -137,7 +137,7 @@ describe('checkTypecheckTestConfig', () => {
|
|
|
137
137
|
'packages/app',
|
|
138
138
|
);
|
|
139
139
|
expect(issues.length).toBe(1);
|
|
140
|
-
expect(issues[0]
|
|
140
|
+
expect(issues[0]?.message).toContain('dist-test');
|
|
141
141
|
});
|
|
142
142
|
|
|
143
143
|
it('returns empty for null input', () => {
|
|
@@ -147,8 +147,8 @@ describe('checkTypecheckTestConfig', () => {
|
|
|
147
147
|
|
|
148
148
|
it('uses packagePath in issue path', () => {
|
|
149
149
|
const issues = checkTypecheckTestConfig({ compilerOptions: {} }, 'packages/mylib');
|
|
150
|
-
expect(issues[0]
|
|
151
|
-
expect(issues[0]
|
|
150
|
+
expect(issues[0]?.path).toContain('packages/mylib');
|
|
151
|
+
expect(issues[0]?.path).toContain('tsconfig.test.json');
|
|
152
152
|
});
|
|
153
153
|
});
|
|
154
154
|
|
|
@@ -164,7 +164,7 @@ describe('checkTsconfigTestReference', () => {
|
|
|
164
164
|
'packages/app',
|
|
165
165
|
);
|
|
166
166
|
expect(issues.length).toBe(1);
|
|
167
|
-
expect(issues[0]
|
|
167
|
+
expect(issues[0]?.message).toContain('must not reference ./tsconfig.test.json');
|
|
168
168
|
});
|
|
169
169
|
|
|
170
170
|
it('returns empty for null input', () => {
|
|
@@ -183,7 +183,7 @@ describe('applyTypecheckTestDefaults', () => {
|
|
|
183
183
|
expect(changed).toBe(true);
|
|
184
184
|
expect(tsconfigTest.extends).toBe('../../tsconfig.base.json');
|
|
185
185
|
|
|
186
|
-
const compilerOptions = tsconfigTest.compilerOptions
|
|
186
|
+
const compilerOptions = expectRecord(tsconfigTest.compilerOptions);
|
|
187
187
|
expect(compilerOptions.noEmit).toBe(true);
|
|
188
188
|
expect(compilerOptions.composite).toBe(false);
|
|
189
189
|
expect(compilerOptions.declaration).toBe(false);
|
|
@@ -191,11 +191,11 @@ describe('applyTypecheckTestDefaults', () => {
|
|
|
191
191
|
expect(compilerOptions.emitDeclarationOnly).toBe(false);
|
|
192
192
|
expect(compilerOptions.types).toContain('bun');
|
|
193
193
|
|
|
194
|
-
const include = tsconfigTest.include
|
|
194
|
+
const include = expectStringArray(tsconfigTest.include);
|
|
195
195
|
expect(include).toContain('src/**/*.test.ts');
|
|
196
196
|
expect(include).toContain('src/**/*.spec.ts');
|
|
197
197
|
|
|
198
|
-
const references = tsconfigTest.references
|
|
198
|
+
const references = expectReferences(tsconfigTest.references);
|
|
199
199
|
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
200
200
|
});
|
|
201
201
|
|
|
@@ -216,7 +216,7 @@ describe('applyTypecheckTestDefaults', () => {
|
|
|
216
216
|
libCompilerOptions: { baseUrl: '.', module: 'esnext', jsx: 'react-jsx' },
|
|
217
217
|
referencePaths: [],
|
|
218
218
|
});
|
|
219
|
-
const compilerOptions = tsconfigTest.compilerOptions
|
|
219
|
+
const compilerOptions = expectRecord(tsconfigTest.compilerOptions);
|
|
220
220
|
expect(compilerOptions.baseUrl).toBe('.');
|
|
221
221
|
expect(compilerOptions.module).toBe('esnext');
|
|
222
222
|
expect(compilerOptions.jsx).toBe('react-jsx');
|
|
@@ -228,7 +228,7 @@ describe('applyTypecheckTestDefaults', () => {
|
|
|
228
228
|
testRunners: new Set(['vitest'] as const),
|
|
229
229
|
referencePaths: [],
|
|
230
230
|
});
|
|
231
|
-
const compilerOptions = tsconfigTest.compilerOptions
|
|
231
|
+
const compilerOptions = expectRecord(tsconfigTest.compilerOptions);
|
|
232
232
|
expect(compilerOptions.types).toBeUndefined();
|
|
233
233
|
});
|
|
234
234
|
|
|
@@ -241,7 +241,7 @@ describe('applyTypecheckTestDefaults', () => {
|
|
|
241
241
|
referencePaths: [],
|
|
242
242
|
});
|
|
243
243
|
expect(changed).toBe(true);
|
|
244
|
-
const compilerOptions = tsconfigTest.compilerOptions
|
|
244
|
+
const compilerOptions = expectRecord(tsconfigTest.compilerOptions);
|
|
245
245
|
expect('outDir' in compilerOptions).toBe(false);
|
|
246
246
|
expect('tsBuildInfoFile' in compilerOptions).toBe(false);
|
|
247
247
|
});
|
|
@@ -250,6 +250,7 @@ describe('applyTypecheckTestDefaults', () => {
|
|
|
250
250
|
const tsconfigTest: Record<string, unknown> = {};
|
|
251
251
|
const opts = {
|
|
252
252
|
testRunners: new Set(['bun'] as const),
|
|
253
|
+
libCompilerOptions: { lib: ['es2024', 'webworker'] },
|
|
253
254
|
referencePaths: ['./tsconfig.lib.json'],
|
|
254
255
|
};
|
|
255
256
|
applyTypecheckTestDefaults(tsconfigTest, opts);
|
|
@@ -304,18 +305,18 @@ describe('typecheck test policy (Tree)', () => {
|
|
|
304
305
|
expect(changed).toBe(true);
|
|
305
306
|
|
|
306
307
|
const tsconfig = readJson<Record<string, unknown>>(tree, 'packages/app/tsconfig.test.json');
|
|
307
|
-
const compilerOptions = tsconfig.compilerOptions
|
|
308
|
+
const compilerOptions = expectRecord(tsconfig.compilerOptions);
|
|
308
309
|
expect(compilerOptions.noEmit).toBe(true);
|
|
309
310
|
expect(compilerOptions.composite).toBe(false);
|
|
310
311
|
expect(compilerOptions.types).toContain('bun');
|
|
311
312
|
expect(compilerOptions.baseUrl).toBe('.');
|
|
312
313
|
expect(tsconfig.extends).toBe('../../tsconfig.base.json');
|
|
313
314
|
|
|
314
|
-
const include = tsconfig.include
|
|
315
|
+
const include = expectStringArray(tsconfig.include);
|
|
315
316
|
expect(include).toContain('src/**/*.test.ts');
|
|
316
317
|
expect(include).toContain('src/**/*.spec.ts');
|
|
317
318
|
|
|
318
|
-
const references = tsconfig.references
|
|
319
|
+
const references = expectReferences(tsconfig.references);
|
|
319
320
|
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
320
321
|
});
|
|
321
322
|
|
|
@@ -422,7 +423,7 @@ describe('typecheck test policy (Tree)', () => {
|
|
|
422
423
|
expect(changed).toBe(true);
|
|
423
424
|
|
|
424
425
|
const tsconfig = readJson<Record<string, unknown>>(tree, 'packages/app/tsconfig.json');
|
|
425
|
-
const references = tsconfig.references
|
|
426
|
+
const references = expectReferences(tsconfig.references);
|
|
426
427
|
expect(references).toEqual([{ path: './tsconfig.lib.json' }]);
|
|
427
428
|
});
|
|
428
429
|
|
|
@@ -479,7 +480,7 @@ describe('typecheck test policy (Tree)', () => {
|
|
|
479
480
|
expect(applyTypecheckTestPolicyTree(tree)).toBe(true);
|
|
480
481
|
|
|
481
482
|
const tsconfig = readJson<Record<string, unknown>>(tree, 'packages/app/tsconfig.test.json');
|
|
482
|
-
const references = tsconfig.references
|
|
483
|
+
const references = expectReferences(tsconfig.references);
|
|
483
484
|
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
484
485
|
expect(references).toContainEqual({ path: '../lib/tsconfig.lib.json' });
|
|
485
486
|
});
|
|
@@ -502,14 +503,14 @@ describe('typecheck test policy', () => {
|
|
|
502
503
|
// check should report missing tsconfig.test.json
|
|
503
504
|
const issues = checkTypecheckTestPolicy(root);
|
|
504
505
|
expect(issues.length).toBe(1);
|
|
505
|
-
expect(issues[0]
|
|
506
|
-
expect(issues[0]
|
|
506
|
+
expect(issues[0]?.message).toContain('bun test');
|
|
507
|
+
expect(issues[0]?.message).toContain('tsconfig.test.json');
|
|
507
508
|
|
|
508
509
|
// apply should create it
|
|
509
510
|
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
510
511
|
|
|
511
|
-
const tsconfig = (await readJsonFs(join(root, 'packages/app/tsconfig.test.json')))
|
|
512
|
-
const compilerOptions = tsconfig.compilerOptions
|
|
512
|
+
const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/app/tsconfig.test.json')));
|
|
513
|
+
const compilerOptions = expectRecord(tsconfig.compilerOptions);
|
|
513
514
|
expect(compilerOptions.noEmit).toBe(true);
|
|
514
515
|
expect(compilerOptions.composite).toBe(false);
|
|
515
516
|
expect(compilerOptions.declaration).toBe(false);
|
|
@@ -518,7 +519,7 @@ describe('typecheck test policy', () => {
|
|
|
518
519
|
expect(compilerOptions.types).toContain('bun');
|
|
519
520
|
expect(tsconfig.extends).toBe('../../tsconfig.base.json');
|
|
520
521
|
|
|
521
|
-
const include = tsconfig.include
|
|
522
|
+
const include = expectStringArray(tsconfig.include);
|
|
522
523
|
expect(include).toContain('src/**/*.test.ts');
|
|
523
524
|
expect(include).toContain('src/**/*.spec.ts');
|
|
524
525
|
expect(include).toContain('src/**/__tests__/**/*.ts');
|
|
@@ -545,8 +546,8 @@ describe('typecheck test policy', () => {
|
|
|
545
546
|
|
|
546
547
|
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
547
548
|
|
|
548
|
-
const tsconfig = (await readJsonFs(join(root, 'packages/web/tsconfig.test.json')))
|
|
549
|
-
const compilerOptions = tsconfig.compilerOptions
|
|
549
|
+
const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/web/tsconfig.test.json')));
|
|
550
|
+
const compilerOptions = expectRecord(tsconfig.compilerOptions);
|
|
550
551
|
expect(compilerOptions.noEmit).toBe(true);
|
|
551
552
|
// vitest should NOT add bun types
|
|
552
553
|
expect(compilerOptions.types).toBeUndefined();
|
|
@@ -574,12 +575,12 @@ describe('typecheck test policy', () => {
|
|
|
574
575
|
|
|
575
576
|
const issues = checkTypecheckTestPolicy(root);
|
|
576
577
|
expect(issues.length).toBe(1);
|
|
577
|
-
expect(issues[0]
|
|
578
|
+
expect(issues[0]?.message).toContain('bun test');
|
|
578
579
|
|
|
579
580
|
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
580
581
|
|
|
581
|
-
const tsconfig = (await readJsonFs(join(root, 'packages/lib/tsconfig.test.json')))
|
|
582
|
-
const compilerOptions = tsconfig.compilerOptions
|
|
582
|
+
const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/lib/tsconfig.test.json')));
|
|
583
|
+
const compilerOptions = expectRecord(tsconfig.compilerOptions);
|
|
583
584
|
expect(compilerOptions.noEmit).toBe(true);
|
|
584
585
|
expect(compilerOptions.types).toContain('bun');
|
|
585
586
|
} finally {
|
|
@@ -650,8 +651,8 @@ describe('typecheck test policy', () => {
|
|
|
650
651
|
// apply should remove it
|
|
651
652
|
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
652
653
|
|
|
653
|
-
const tsconfig = (await readJsonFs(join(root, 'packages/app/tsconfig.json')))
|
|
654
|
-
const references = tsconfig.references
|
|
654
|
+
const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/app/tsconfig.json')));
|
|
655
|
+
const references = expectReferences(tsconfig.references);
|
|
655
656
|
expect(references).toEqual([{ path: './tsconfig.lib.json' }]);
|
|
656
657
|
} finally {
|
|
657
658
|
await rm(root, { recursive: true, force: true });
|
|
@@ -679,8 +680,8 @@ describe('typecheck test policy', () => {
|
|
|
679
680
|
|
|
680
681
|
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
681
682
|
|
|
682
|
-
const tsconfig = (await readJsonFs(join(root, 'packages/app/tsconfig.test.json')))
|
|
683
|
-
const compilerOptions = tsconfig.compilerOptions
|
|
683
|
+
const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/app/tsconfig.test.json')));
|
|
684
|
+
const compilerOptions = expectRecord(tsconfig.compilerOptions);
|
|
684
685
|
expect(compilerOptions.baseUrl).toBe('.');
|
|
685
686
|
expect(compilerOptions.module).toBe('esnext');
|
|
686
687
|
expect(compilerOptions.moduleResolution).toBe('bundler');
|
|
@@ -690,7 +691,7 @@ describe('typecheck test policy', () => {
|
|
|
690
691
|
expect(tsconfig.extends).toBe('../../tsconfig.base.json');
|
|
691
692
|
|
|
692
693
|
// references should include ./tsconfig.lib.json
|
|
693
|
-
const references = tsconfig.references
|
|
694
|
+
const references = expectReferences(tsconfig.references);
|
|
694
695
|
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
695
696
|
} finally {
|
|
696
697
|
await rm(root, { recursive: true, force: true });
|
|
@@ -720,8 +721,8 @@ describe('typecheck test policy', () => {
|
|
|
720
721
|
|
|
721
722
|
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
722
723
|
|
|
723
|
-
const tsconfig = (await readJsonFs(join(root, 'packages/app/tsconfig.test.json')))
|
|
724
|
-
const references = tsconfig.references
|
|
724
|
+
const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/app/tsconfig.test.json')));
|
|
725
|
+
const references = expectReferences(tsconfig.references);
|
|
725
726
|
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
726
727
|
expect(references).toContainEqual({ path: '../lib/tsconfig.lib.json' });
|
|
727
728
|
} finally {
|
|
@@ -789,9 +790,55 @@ describe('typecheck test policy', () => {
|
|
|
789
790
|
|
|
790
791
|
const issues = checkTypecheckTestPolicy(root);
|
|
791
792
|
expect(issues.length).toBe(1);
|
|
792
|
-
expect(issues[0]
|
|
793
|
+
expect(issues[0]?.message).toContain('bun test');
|
|
793
794
|
} finally {
|
|
794
795
|
await rm(root, { recursive: true, force: true });
|
|
795
796
|
}
|
|
796
797
|
});
|
|
797
798
|
});
|
|
799
|
+
|
|
800
|
+
interface TypeScriptReference {
|
|
801
|
+
path: string;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
function expectRecord(value: unknown): Record<string, unknown> {
|
|
805
|
+
if (!isRecord(value)) {
|
|
806
|
+
throw new Error('expected object');
|
|
807
|
+
}
|
|
808
|
+
return value;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
812
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
function expectStringArray(value: unknown): string[] {
|
|
816
|
+
if (!Array.isArray(value)) {
|
|
817
|
+
throw new Error('expected array');
|
|
818
|
+
}
|
|
819
|
+
const values: unknown[] = value;
|
|
820
|
+
if (!values.every((entry): entry is string => typeof entry === 'string')) {
|
|
821
|
+
throw new Error('expected string array');
|
|
822
|
+
}
|
|
823
|
+
return values;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
function expectReferences(value: unknown): TypeScriptReference[] {
|
|
827
|
+
if (!Array.isArray(value)) {
|
|
828
|
+
throw new Error('expected array');
|
|
829
|
+
}
|
|
830
|
+
const values: unknown[] = value;
|
|
831
|
+
if (
|
|
832
|
+
!values.every(
|
|
833
|
+
(entry): entry is TypeScriptReference =>
|
|
834
|
+
entry !== null &&
|
|
835
|
+
typeof entry === 'object' &&
|
|
836
|
+
!Array.isArray(entry) &&
|
|
837
|
+
'path' in entry &&
|
|
838
|
+
typeof entry.path === 'string',
|
|
839
|
+
)
|
|
840
|
+
) {
|
|
841
|
+
throw new Error('expected TypeScript references');
|
|
842
|
+
}
|
|
843
|
+
return values;
|
|
844
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join, relative } from 'node:path';
|
|
3
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
3
4
|
import type { Tree } from 'nx/src/devkit-exports.js';
|
|
4
5
|
import { getProjects, readJson, readProjectConfiguration, updateJson, writeJson } from 'nx/src/devkit-exports.js';
|
|
5
6
|
|
|
@@ -86,7 +87,7 @@ export function checkTypecheckTestConfig(
|
|
|
86
87
|
const tsconfigTestPath = join(packagePath, 'tsconfig.test.json');
|
|
87
88
|
const compilerOptions = recordProperty(tsconfigTest, 'compilerOptions');
|
|
88
89
|
|
|
89
|
-
if (
|
|
90
|
+
if (compilerOptions?.noEmit !== true) {
|
|
90
91
|
issues.push({
|
|
91
92
|
path: tsconfigTestPath,
|
|
92
93
|
message: 'compilerOptions.noEmit must be true',
|
|
@@ -169,7 +170,10 @@ export function applyTypecheckTestDefaults(
|
|
|
169
170
|
// Copy relevant compiler options from lib tsconfig
|
|
170
171
|
if (options.libCompilerOptions) {
|
|
171
172
|
for (const key of ['baseUrl', 'module', 'moduleResolution', 'jsx', 'lib']) {
|
|
172
|
-
if (
|
|
173
|
+
if (
|
|
174
|
+
Object.hasOwn(options.libCompilerOptions, key) &&
|
|
175
|
+
!isDeepStrictEqual(compilerOptions[key], options.libCompilerOptions[key])
|
|
176
|
+
) {
|
|
173
177
|
compilerOptions[key] = options.libCompilerOptions[key];
|
|
174
178
|
changed = true;
|
|
175
179
|
}
|
package/src/version-actions.cts
CHANGED
|
@@ -68,7 +68,7 @@ function syncBunLockfileVersions(root: string): number {
|
|
|
68
68
|
}
|
|
69
69
|
lockfile = lockfile.replace(pattern, `$1${targetVersion}$3`);
|
|
70
70
|
console.log(
|
|
71
|
-
`fix: ${relativePath}: ${lockVersion} -> ${targetVersion}${targetVersion !== pkg.version ? ` (latest stable tag; package.json has ${pkg.version})` : ''}
|
|
71
|
+
`fix: ${relativePath}: ${lockVersion} -> ${targetVersion}${targetVersion !== pkg.version ? ` (latest stable tag; package.json has ${pkg.version})` : ''}`,
|
|
72
72
|
);
|
|
73
73
|
updated++;
|
|
74
74
|
}
|
|
@@ -76,7 +76,7 @@ function syncBunLockfileVersions(root: string): number {
|
|
|
76
76
|
writeFileSync(lockfilePath, lockfile);
|
|
77
77
|
}
|
|
78
78
|
console.log(
|
|
79
|
-
updated > 0 ? `Updated ${updated} workspace version(s) in bun.lock` : 'All workspace versions already in sync.'
|
|
79
|
+
updated > 0 ? `Updated ${updated} workspace version(s) in bun.lock` : 'All workspace versions already in sync.',
|
|
80
80
|
);
|
|
81
81
|
return updated;
|
|
82
82
|
}
|
|
@@ -98,15 +98,22 @@ function workspacePackages(root: string): WorkspacePackage[] {
|
|
|
98
98
|
if (!existsSync(packageJsonPath)) {
|
|
99
99
|
return null;
|
|
100
100
|
}
|
|
101
|
-
const
|
|
102
|
-
if (typeof
|
|
103
|
-
|
|
101
|
+
const parsed: unknown = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
|
|
102
|
+
if (!isRecord(parsed) || typeof parsed.name !== 'string' || typeof parsed.version !== 'string') {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const json = parsed;
|
|
106
|
+
const nx = isRecord(json.nx) ? json.nx : null;
|
|
104
107
|
const projectName = (nx ? (typeof nx.name === 'string' ? nx.name : null) : null) ?? json.name;
|
|
105
108
|
return { path, name: json.name, projectName, version: json.version };
|
|
106
109
|
})
|
|
107
110
|
.filter((pkg): pkg is WorkspacePackage => pkg !== null);
|
|
108
111
|
}
|
|
109
112
|
|
|
113
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
114
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
115
|
+
}
|
|
116
|
+
|
|
110
117
|
function escapeRegex(value: string): string {
|
|
111
118
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
112
119
|
}
|
|
@@ -21,21 +21,7 @@ import {
|
|
|
21
21
|
|
|
22
22
|
function validNxJson(): Record<string, unknown> {
|
|
23
23
|
return {
|
|
24
|
-
plugins: [
|
|
25
|
-
{
|
|
26
|
-
plugin: '@nx/js/typescript',
|
|
27
|
-
options: {
|
|
28
|
-
typecheck: { targetName: 'typecheck' },
|
|
29
|
-
build: {
|
|
30
|
-
targetName: 'tsc-js',
|
|
31
|
-
configName: 'tsconfig.lib.json',
|
|
32
|
-
buildDepsName: 'build-deps',
|
|
33
|
-
watchDepsName: 'watch-deps',
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
'@smoothbricks/nx-plugin',
|
|
38
|
-
],
|
|
24
|
+
plugins: ['@smoothbricks/nx-plugin'],
|
|
39
25
|
targetDefaults: validTargetDefaults(),
|
|
40
26
|
namedInputs: validNamedInputs(),
|
|
41
27
|
};
|
|
@@ -63,21 +49,7 @@ function validNamedInputs(): Record<string, unknown> {
|
|
|
63
49
|
}
|
|
64
50
|
|
|
65
51
|
function validPlugins(): unknown[] {
|
|
66
|
-
return [
|
|
67
|
-
{
|
|
68
|
-
plugin: '@nx/js/typescript',
|
|
69
|
-
options: {
|
|
70
|
-
typecheck: { targetName: 'typecheck' },
|
|
71
|
-
build: {
|
|
72
|
-
targetName: 'tsc-js',
|
|
73
|
-
configName: 'tsconfig.lib.json',
|
|
74
|
-
buildDepsName: 'build-deps',
|
|
75
|
-
watchDepsName: 'watch-deps',
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
'@smoothbricks/nx-plugin',
|
|
80
|
-
];
|
|
52
|
+
return ['@smoothbricks/nx-plugin'];
|
|
81
53
|
}
|
|
82
54
|
|
|
83
55
|
// ---------------------------------------------------------------------------
|
|
@@ -103,8 +75,7 @@ describe('pure core: checkWorkspaceConfig', () => {
|
|
|
103
75
|
targetDefaults: validTargetDefaults(),
|
|
104
76
|
namedInputs: validNamedInputs(),
|
|
105
77
|
});
|
|
106
|
-
expect(issues.length).toBe(
|
|
107
|
-
expect(issues.some((i) => i.message.includes('Official Nx owns TypeScript library inference'))).toBe(true);
|
|
78
|
+
expect(issues.length).toBe(1);
|
|
108
79
|
expect(issues.some((i) => i.message.includes('plugins must include @smoothbricks/nx-plugin'))).toBe(true);
|
|
109
80
|
});
|
|
110
81
|
|
|
@@ -120,16 +91,13 @@ describe('pure core: checkWorkspaceConfig', () => {
|
|
|
120
91
|
expect(issues.some((i) => i.message.includes('must not use colon target names'))).toBe(true);
|
|
121
92
|
});
|
|
122
93
|
|
|
123
|
-
it('detects
|
|
94
|
+
it('detects native TypeScript inference', () => {
|
|
124
95
|
const issues = checkWorkspaceConfig({
|
|
125
|
-
plugins: [
|
|
126
|
-
{ plugin: '@nx/js/typescript', options: { build: { targetName: 'build' } } },
|
|
127
|
-
'@smoothbricks/nx-plugin',
|
|
128
|
-
],
|
|
96
|
+
plugins: ['@nx/js/typescript', '@smoothbricks/nx-plugin'],
|
|
129
97
|
targetDefaults: validTargetDefaults(),
|
|
130
98
|
namedInputs: validNamedInputs(),
|
|
131
99
|
});
|
|
132
|
-
expect(issues.some((
|
|
100
|
+
expect(issues.some((issue) => issue.message.includes('plugins must not configure @nx/js/typescript'))).toBe(true);
|
|
133
101
|
});
|
|
134
102
|
|
|
135
103
|
it('detects imprecise production inputs', () => {
|
|
@@ -183,10 +151,8 @@ describe('pure core: applyWorkspaceConfig', () => {
|
|
|
183
151
|
namedInputs: validNamedInputs(),
|
|
184
152
|
};
|
|
185
153
|
expect(applyWorkspaceConfig(nxJson)).toBe(true);
|
|
186
|
-
const pluginNames = (nxJson.plugins
|
|
187
|
-
|
|
188
|
-
);
|
|
189
|
-
expect(pluginNames).toContain('@nx/js/typescript');
|
|
154
|
+
const pluginNames = readPluginNames(nxJson.plugins);
|
|
155
|
+
expect(pluginNames).not.toContain('@nx/js/typescript');
|
|
190
156
|
expect(pluginNames).toContain('@smoothbricks/nx-plugin');
|
|
191
157
|
});
|
|
192
158
|
|
|
@@ -199,7 +165,7 @@ describe('pure core: applyWorkspaceConfig', () => {
|
|
|
199
165
|
},
|
|
200
166
|
};
|
|
201
167
|
expect(applyWorkspaceConfig(nxJson)).toBe(true);
|
|
202
|
-
expect((nxJson.targetDefaults
|
|
168
|
+
expect(expectRecord(nxJson.targetDefaults)['build:wasm']).toBeUndefined();
|
|
203
169
|
});
|
|
204
170
|
|
|
205
171
|
it('fixes imprecise production inputs', () => {
|
|
@@ -212,7 +178,7 @@ describe('pure core: applyWorkspaceConfig', () => {
|
|
|
212
178
|
},
|
|
213
179
|
};
|
|
214
180
|
expect(applyWorkspaceConfig(nxJson)).toBe(true);
|
|
215
|
-
const namedInputs = nxJson.namedInputs
|
|
181
|
+
const namedInputs = expectRecord(nxJson.namedInputs);
|
|
216
182
|
expect(namedInputs.production).toEqual([
|
|
217
183
|
'{projectRoot}/src/**/*',
|
|
218
184
|
'{projectRoot}/package.json',
|
|
@@ -258,8 +224,7 @@ describe('Tree: checkWorkspaceConfigTree', () => {
|
|
|
258
224
|
});
|
|
259
225
|
|
|
260
226
|
const issues = checkWorkspaceConfigTree(tree);
|
|
261
|
-
expect(issues.length).toBe(
|
|
262
|
-
expect(issues.some((i) => i.message.includes('Official Nx owns TypeScript library inference'))).toBe(true);
|
|
227
|
+
expect(issues.length).toBe(1);
|
|
263
228
|
expect(issues.some((i) => i.message.includes('plugins must include @smoothbricks/nx-plugin'))).toBe(true);
|
|
264
229
|
});
|
|
265
230
|
|
|
@@ -289,10 +254,8 @@ describe('Tree: applyWorkspaceConfigTree', () => {
|
|
|
289
254
|
expect(applyWorkspaceConfigTree(tree)).toBe(true);
|
|
290
255
|
|
|
291
256
|
const nxJson = readJson(tree, 'nx.json');
|
|
292
|
-
const pluginNames = (nxJson.plugins
|
|
293
|
-
|
|
294
|
-
);
|
|
295
|
-
expect(pluginNames).toContain('@nx/js/typescript');
|
|
257
|
+
const pluginNames = readPluginNames(nxJson.plugins);
|
|
258
|
+
expect(pluginNames).not.toContain('@nx/js/typescript');
|
|
296
259
|
expect(pluginNames).toContain('@smoothbricks/nx-plugin');
|
|
297
260
|
|
|
298
261
|
// Tree version now passes check
|
|
@@ -317,11 +280,11 @@ describe('Tree: applyWorkspaceConfigTree', () => {
|
|
|
317
280
|
expect(applyWorkspaceConfigTree(tree)).toBe(true);
|
|
318
281
|
|
|
319
282
|
const nxJson = readJson(tree, 'nx.json');
|
|
320
|
-
expect((nxJson.targetDefaults
|
|
283
|
+
expect(expectRecord(nxJson.targetDefaults).build).toEqual({
|
|
321
284
|
cache: true,
|
|
322
285
|
outputs: ['{projectRoot}/dist'],
|
|
323
286
|
});
|
|
324
|
-
expect((nxJson.targetDefaults
|
|
287
|
+
expect(expectRecord(nxJson.targetDefaults).clean).toEqual({
|
|
325
288
|
executor: '@smoothbricks/nx-plugin:clean-outputs',
|
|
326
289
|
cache: false,
|
|
327
290
|
});
|
|
@@ -349,11 +312,9 @@ describe('filesystem: checkWorkspaceConfigPolicy / applyWorkspaceConfigPolicy',
|
|
|
349
312
|
|
|
350
313
|
expect(applyWorkspaceConfigPolicy(root)).toBe(true);
|
|
351
314
|
|
|
352
|
-
const nxJson = JSON.parse(await readFile(join(root, 'nx.json'), 'utf8'));
|
|
353
|
-
const pluginNames = (nxJson.plugins
|
|
354
|
-
|
|
355
|
-
);
|
|
356
|
-
expect(pluginNames).toContain('@nx/js/typescript');
|
|
315
|
+
const nxJson = expectRecord(JSON.parse(await readFile(join(root, 'nx.json'), 'utf8')));
|
|
316
|
+
const pluginNames = readPluginNames(nxJson.plugins);
|
|
317
|
+
expect(pluginNames).not.toContain('@nx/js/typescript');
|
|
357
318
|
expect(pluginNames).toContain('@smoothbricks/nx-plugin');
|
|
358
319
|
|
|
359
320
|
// No issues after fix
|
|
@@ -386,3 +347,22 @@ async function writeJsonFile(path: string, value: unknown): Promise<void> {
|
|
|
386
347
|
await mkdir(dirname(path), { recursive: true });
|
|
387
348
|
await writeFile(path, `${JSON.stringify(value, null, 2)}\n`);
|
|
388
349
|
}
|
|
350
|
+
|
|
351
|
+
function expectRecord(value: unknown): Record<string, unknown> {
|
|
352
|
+
if (!isRecord(value)) {
|
|
353
|
+
throw new Error('expected object');
|
|
354
|
+
}
|
|
355
|
+
return value;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
359
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function readPluginNames(value: unknown): unknown[] {
|
|
363
|
+
if (!Array.isArray(value)) {
|
|
364
|
+
throw new Error('expected plugins array');
|
|
365
|
+
}
|
|
366
|
+
const plugins: unknown[] = value;
|
|
367
|
+
return plugins.map((plugin) => (typeof plugin === 'string' ? plugin : expectRecord(plugin).plugin));
|
|
368
|
+
}
|
|
@@ -66,20 +66,12 @@ export function checkWorkspaceConfig(nxJson: Record<string, unknown>): NxPolicyI
|
|
|
66
66
|
|
|
67
67
|
// Plugin configuration
|
|
68
68
|
const plugins = Array.isArray(nxJson.plugins) ? nxJson.plugins : [];
|
|
69
|
-
|
|
70
|
-
if (!nxJsPlugin) {
|
|
69
|
+
if (plugins.some(isNxJsTypescriptPlugin)) {
|
|
71
70
|
issues.push({
|
|
72
71
|
path: 'nx.json',
|
|
73
72
|
message:
|
|
74
|
-
`plugins must configure ${nxJsTypescriptPlugin}. ` +
|
|
75
|
-
'
|
|
76
|
-
});
|
|
77
|
-
} else if (nxJsBuildTargetName(nxJsPlugin) !== 'tsc-js') {
|
|
78
|
-
issues.push({
|
|
79
|
-
path: 'nx.json',
|
|
80
|
-
message:
|
|
81
|
-
`${nxJsTypescriptPlugin} build.targetName must be tsc-js. ` +
|
|
82
|
-
'TypeScript library output is a concrete tool-output target; build is reserved for aggregate targets that depend on concrete build work.',
|
|
73
|
+
`plugins must not configure ${nxJsTypescriptPlugin}. ` +
|
|
74
|
+
'Smoo owns transformer-aware TypeScript targets; Nx native inference only supports tsc/tsgo.',
|
|
83
75
|
});
|
|
84
76
|
}
|
|
85
77
|
if (!plugins.includes(smoothBricksNxPlugin) && !plugins.some(isSmoothBricksNxPluginRecord)) {
|
|
@@ -104,10 +96,8 @@ export function applyWorkspaceConfig(nxJson: Record<string, unknown>): boolean {
|
|
|
104
96
|
changed = applyCleanTargetDefault(nxJson) || changed;
|
|
105
97
|
changed = applyNamedInputDefaults(nxJson) || changed;
|
|
106
98
|
const currentPlugins = Array.isArray(nxJson.plugins) ? nxJson.plugins : [];
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
smoothBricksNxPlugin,
|
|
110
|
-
);
|
|
99
|
+
const pluginsWithoutNxTypeScript = currentPlugins.filter((plugin) => !isNxJsTypescriptPlugin(plugin));
|
|
100
|
+
const nextPlugins = upsertNxPlugin(pluginsWithoutNxTypeScript, smoothBricksNxPlugin);
|
|
111
101
|
if (JSON.stringify(currentPlugins) !== JSON.stringify(nextPlugins)) {
|
|
112
102
|
nxJson.plugins = nextPlugins;
|
|
113
103
|
changed = true;
|
|
@@ -181,7 +171,7 @@ function validateBuildTargetDefault(
|
|
|
181
171
|
): void {
|
|
182
172
|
const targetDefaults = recordProperty(nxJson, 'targetDefaults');
|
|
183
173
|
const build = targetDefaults ? recordProperty(targetDefaults, 'build') : null;
|
|
184
|
-
if (
|
|
174
|
+
if (build?.cache !== true) {
|
|
185
175
|
issues.push({ path: nxJsonPath, message: 'targetDefaults.build.cache must be true' });
|
|
186
176
|
}
|
|
187
177
|
const outputs = build?.outputs;
|
|
@@ -200,7 +190,7 @@ function validateCleanTargetDefault(
|
|
|
200
190
|
if (!clean || clean.executor !== cleanOutputsExecutor) {
|
|
201
191
|
issues.push({ path: nxJsonPath, message: `targetDefaults.clean.executor must be ${cleanOutputsExecutor}` });
|
|
202
192
|
}
|
|
203
|
-
if (
|
|
193
|
+
if (clean?.cache !== false) {
|
|
204
194
|
issues.push({ path: nxJsonPath, message: 'targetDefaults.clean.cache must be false' });
|
|
205
195
|
}
|
|
206
196
|
}
|
|
@@ -311,21 +301,6 @@ function isPreciseProductionNamedInput(production: unknown[]): boolean {
|
|
|
311
301
|
return hasPositiveProjectInput;
|
|
312
302
|
}
|
|
313
303
|
|
|
314
|
-
function expectedNxJsTypescriptPlugin(): Record<string, unknown> {
|
|
315
|
-
return {
|
|
316
|
-
plugin: nxJsTypescriptPlugin,
|
|
317
|
-
options: {
|
|
318
|
-
typecheck: { targetName: 'typecheck' },
|
|
319
|
-
build: {
|
|
320
|
-
targetName: 'tsc-js',
|
|
321
|
-
configName: 'tsconfig.lib.json',
|
|
322
|
-
buildDepsName: 'build-deps',
|
|
323
|
-
watchDepsName: 'watch-deps',
|
|
324
|
-
},
|
|
325
|
-
},
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
|
|
329
304
|
function upsertNxPlugin(plugins: readonly unknown[], plugin: string | Record<string, unknown>): unknown[] {
|
|
330
305
|
const pluginName = typeof plugin === 'string' ? plugin : stringProperty(plugin, 'plugin');
|
|
331
306
|
const next = plugins.filter((entry) => nxPluginName(entry) !== pluginName);
|
|
@@ -340,20 +315,16 @@ function nxPluginName(value: unknown): string | null {
|
|
|
340
315
|
return isRecord(value) ? stringProperty(value, 'plugin') : null;
|
|
341
316
|
}
|
|
342
317
|
|
|
343
|
-
function isNxJsTypescriptPlugin(value: unknown):
|
|
344
|
-
return
|
|
318
|
+
function isNxJsTypescriptPlugin(value: unknown): boolean {
|
|
319
|
+
return (
|
|
320
|
+
value === nxJsTypescriptPlugin || (isRecord(value) && stringProperty(value, 'plugin') === nxJsTypescriptPlugin)
|
|
321
|
+
);
|
|
345
322
|
}
|
|
346
323
|
|
|
347
324
|
function isSmoothBricksNxPluginRecord(value: unknown): boolean {
|
|
348
325
|
return isRecord(value) && stringProperty(value, 'plugin') === smoothBricksNxPlugin;
|
|
349
326
|
}
|
|
350
327
|
|
|
351
|
-
function nxJsBuildTargetName(plugin: Record<string, unknown>): string | null {
|
|
352
|
-
const options = recordProperty(plugin, 'options');
|
|
353
|
-
const build = options ? recordProperty(options, 'build') : null;
|
|
354
|
-
return build ? stringProperty(build, 'targetName') : null;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
328
|
function readJsonObject(path: string): Record<string, unknown> | null {
|
|
358
329
|
if (!existsSync(path)) {
|
|
359
330
|
return null;
|