@smoothbricks/nx-plugin 0.3.0 → 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 +56 -4
- 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 +36 -5
- package/src/index.ts +57 -4
- 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
|
@@ -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;
|