@smoothbricks/nx-plugin 0.0.0-bootstrap.0 → 0.2.0
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 +93 -2
- package/dist/bounded-test-policy.d.ts +32 -0
- package/dist/bounded-test-policy.d.ts.map +1 -0
- package/dist/bounded-test-policy.js +184 -0
- package/dist/executors/bounded-exec/executor.d.ts +15 -0
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -0
- package/dist/executors/bounded-exec/executor.js +179 -0
- package/dist/executors/bounded-exec/schema.d.ts +11 -0
- package/dist/executors/bounded-exec/schema.d.ts.map +1 -0
- package/dist/executors/bounded-exec/schema.js +1 -0
- package/dist/generators/bounded-test-targets/generator.d.ts +7 -0
- package/dist/generators/bounded-test-targets/generator.d.ts.map +1 -0
- package/dist/generators/bounded-test-targets/generator.js +40 -0
- package/dist/generators/bun-test-tracing/generator.d.ts +10 -0
- package/dist/generators/bun-test-tracing/generator.d.ts.map +1 -0
- package/dist/generators/bun-test-tracing/generator.js +247 -0
- package/dist/generators/create-package/generator.d.ts +4 -0
- package/dist/generators/create-package/generator.d.ts.map +1 -0
- package/dist/generators/create-package/generator.js +204 -0
- package/dist/generators/make-public/generator.d.ts +4 -0
- package/dist/generators/make-public/generator.d.ts.map +1 -0
- package/dist/generators/make-public/generator.js +55 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +197 -0
- package/dist/package-target-policy.d.ts +31 -0
- package/dist/package-target-policy.d.ts.map +1 -0
- package/dist/package-target-policy.js +930 -0
- package/dist/release-config-policy.d.ts +32 -0
- package/dist/release-config-policy.d.ts.map +1 -0
- package/dist/release-config-policy.js +225 -0
- package/dist/typecheck-test-policy.d.ts +56 -0
- package/dist/typecheck-test-policy.d.ts.map +1 -0
- package/dist/typecheck-test-policy.js +640 -0
- package/dist/version-actions.cjs +78 -0
- package/dist/version-actions.d.cts +6 -0
- package/dist/version-actions.d.cts.map +1 -0
- package/dist/workspace-config-policy.d.ts +33 -0
- package/dist/workspace-config-policy.d.ts.map +1 -0
- package/dist/workspace-config-policy.js +334 -0
- package/executors.json +9 -0
- package/generators.json +24 -0
- package/loader.js +16 -0
- package/package.json +89 -4
- package/src/bounded-test-policy.test.ts +257 -0
- package/src/bounded-test-policy.ts +257 -0
- package/src/bun-bootstrap.test.ts +52 -0
- package/src/executors/bounded-exec/executor.test.ts +258 -0
- package/src/executors/bounded-exec/executor.ts +228 -0
- package/src/executors/bounded-exec/schema.json +68 -0
- package/src/executors/bounded-exec/schema.ts +10 -0
- package/src/generators/bounded-test-targets/generator.test.ts +136 -0
- package/src/generators/bounded-test-targets/generator.ts +67 -0
- package/src/generators/bounded-test-targets/schema.d.ts +3 -0
- package/src/generators/bounded-test-targets/schema.json +14 -0
- package/src/generators/bun-test-tracing/generator.test.ts +243 -0
- package/src/generators/bun-test-tracing/generator.ts +348 -0
- package/src/generators/bun-test-tracing/schema.d.ts +8 -0
- package/src/generators/bun-test-tracing/schema.json +28 -0
- package/src/generators/create-package/generator.test.ts +206 -0
- package/src/generators/create-package/generator.ts +251 -0
- package/src/generators/create-package/schema.d.ts +5 -0
- package/src/generators/create-package/schema.json +24 -0
- package/src/generators/make-public/generator.test.ts +137 -0
- package/src/generators/make-public/generator.ts +83 -0
- package/src/generators/make-public/schema.d.ts +3 -0
- package/src/generators/make-public/schema.json +13 -0
- package/src/index.test.ts +200 -0
- package/src/index.ts +242 -0
- package/src/package-target-policy.test.ts +778 -0
- package/src/package-target-policy.ts +1127 -0
- package/src/release-config-policy.test.ts +280 -0
- package/src/release-config-policy.ts +258 -0
- package/src/typecheck-test-policy.test.ts +797 -0
- package/src/typecheck-test-policy.ts +752 -0
- package/src/version-actions.cts +94 -0
- package/src/workspace-config-policy.test.ts +376 -0
- package/src/workspace-config-policy.ts +390 -0
|
@@ -0,0 +1,778 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from 'bun:test';
|
|
2
|
+
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
|
|
6
|
+
import { addProjectConfiguration, readJson, type Tree } from 'nx/src/devkit-exports.js';
|
|
7
|
+
import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports.js';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
applyPackageTargetPolicy,
|
|
11
|
+
applyPackageTargetPolicyTree,
|
|
12
|
+
applyPackageTargets,
|
|
13
|
+
checkPackageTargetPolicy,
|
|
14
|
+
checkPackageTargetPolicyTree,
|
|
15
|
+
checkPackageTargets,
|
|
16
|
+
nxRunAlias,
|
|
17
|
+
packageNxProjectName,
|
|
18
|
+
type ResolvedProjectTargets,
|
|
19
|
+
} from './package-target-policy.js';
|
|
20
|
+
|
|
21
|
+
describe('package target policy', () => {
|
|
22
|
+
it('rejects colon-style package Nx targets', async () => {
|
|
23
|
+
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-pkg-target-'));
|
|
24
|
+
try {
|
|
25
|
+
await writeJson(join(root, 'package.json'), {
|
|
26
|
+
name: '@scope/root',
|
|
27
|
+
private: true,
|
|
28
|
+
workspaces: ['packages/*'],
|
|
29
|
+
});
|
|
30
|
+
await writeJson(join(root, 'packages/app/package.json'), {
|
|
31
|
+
name: '@scope/app',
|
|
32
|
+
nx: {
|
|
33
|
+
name: 'app',
|
|
34
|
+
targets: {
|
|
35
|
+
'build:ts': {
|
|
36
|
+
executor: 'nx:run-commands',
|
|
37
|
+
options: { command: 'tsc --build tsconfig.lib.json', cwd: '{projectRoot}' },
|
|
38
|
+
},
|
|
39
|
+
'lint:fix': {
|
|
40
|
+
executor: 'nx:run-commands',
|
|
41
|
+
options: { command: 'biome check --apply', cwd: '{projectRoot}' },
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const issues = checkPackageTargetPolicy(root);
|
|
48
|
+
expect(issues.length).toBeGreaterThanOrEqual(2);
|
|
49
|
+
expect(issues.some((i) => i.message.includes('build:ts') && i.message.includes('colon target names'))).toBe(true);
|
|
50
|
+
expect(issues.some((i) => i.message.includes('lint:fix') && i.message.includes('colon target names'))).toBe(true);
|
|
51
|
+
} finally {
|
|
52
|
+
await rm(root, { recursive: true, force: true });
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('migrates colon build targets to tool-output names', async () => {
|
|
57
|
+
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-pkg-target-'));
|
|
58
|
+
try {
|
|
59
|
+
await writeJson(join(root, 'package.json'), {
|
|
60
|
+
name: '@scope/root',
|
|
61
|
+
private: true,
|
|
62
|
+
workspaces: ['packages/*'],
|
|
63
|
+
});
|
|
64
|
+
await writeJson(join(root, 'packages/lib/package.json'), {
|
|
65
|
+
name: '@scope/lib',
|
|
66
|
+
dependencies: { '@scope/other': 'workspace:*' },
|
|
67
|
+
scripts: {
|
|
68
|
+
'build:ts': 'nx run lib:build:ts',
|
|
69
|
+
},
|
|
70
|
+
nx: {
|
|
71
|
+
name: 'lib',
|
|
72
|
+
targets: {
|
|
73
|
+
'build:ts': {
|
|
74
|
+
executor: 'nx:run-commands',
|
|
75
|
+
options: { command: 'tsc --build tsconfig.lib.json', cwd: '{projectRoot}' },
|
|
76
|
+
},
|
|
77
|
+
build: {
|
|
78
|
+
executor: 'nx:noop',
|
|
79
|
+
dependsOn: ['^build', 'build:ts'],
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
await writeJson(join(root, 'packages/other/package.json'), {
|
|
85
|
+
name: '@scope/other',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
expect(applyPackageTargetPolicy(root)).toBe(true);
|
|
89
|
+
|
|
90
|
+
const lib = JSON.parse(await readFile(join(root, 'packages/lib/package.json'), 'utf8'));
|
|
91
|
+
const targets = lib.nx.targets;
|
|
92
|
+
// build:ts should be renamed to tsc-js
|
|
93
|
+
expect(targets['build:ts']).toBeUndefined();
|
|
94
|
+
expect(targets['tsc-js']).toBeDefined();
|
|
95
|
+
expect(targets['tsc-js'].options.command).toBe('tsc --build tsconfig.lib.json');
|
|
96
|
+
// dependsOn in build target should be updated
|
|
97
|
+
expect(targets.build.dependsOn).toContain('tsc-js');
|
|
98
|
+
expect(targets.build.dependsOn).not.toContain('build:ts');
|
|
99
|
+
// scripts should be updated
|
|
100
|
+
expect(lib.scripts['build:ts']).toBe('nx run lib:tsc-js');
|
|
101
|
+
} finally {
|
|
102
|
+
await rm(root, { recursive: true, force: true });
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('removes noop aggregate build targets matching resolved plugin output', async () => {
|
|
107
|
+
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-pkg-target-'));
|
|
108
|
+
try {
|
|
109
|
+
await writeJson(join(root, 'package.json'), {
|
|
110
|
+
name: '@scope/root',
|
|
111
|
+
private: true,
|
|
112
|
+
workspaces: ['packages/*'],
|
|
113
|
+
});
|
|
114
|
+
await writeJson(join(root, 'packages/lib/package.json'), {
|
|
115
|
+
name: '@scope/lib',
|
|
116
|
+
nx: {
|
|
117
|
+
name: 'lib',
|
|
118
|
+
targets: {
|
|
119
|
+
build: {
|
|
120
|
+
executor: 'nx:noop',
|
|
121
|
+
dependsOn: ['^build', '*-js'],
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const resolvedTargetsByProject = new Map<string, ResolvedProjectTargets>([
|
|
128
|
+
[
|
|
129
|
+
'lib',
|
|
130
|
+
{
|
|
131
|
+
targets: new Set(['build', 'tsc-js']),
|
|
132
|
+
buildDependsOn: ['^build', '*-js'],
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
]);
|
|
136
|
+
|
|
137
|
+
expect(applyPackageTargetPolicy(root, { resolvedTargetsByProject })).toBe(true);
|
|
138
|
+
|
|
139
|
+
const lib = JSON.parse(await readFile(join(root, 'packages/lib/package.json'), 'utf8'));
|
|
140
|
+
expect(lib.nx.targets.build).toBeUndefined();
|
|
141
|
+
} finally {
|
|
142
|
+
await rm(root, { recursive: true, force: true });
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('keeps non-noop build targets even when dependsOn matches', async () => {
|
|
147
|
+
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-pkg-target-'));
|
|
148
|
+
try {
|
|
149
|
+
await writeJson(join(root, 'package.json'), {
|
|
150
|
+
name: '@scope/root',
|
|
151
|
+
private: true,
|
|
152
|
+
workspaces: ['packages/*'],
|
|
153
|
+
});
|
|
154
|
+
await writeJson(join(root, 'packages/lib/package.json'), {
|
|
155
|
+
name: '@scope/lib',
|
|
156
|
+
nx: {
|
|
157
|
+
name: 'lib',
|
|
158
|
+
targets: {
|
|
159
|
+
build: {
|
|
160
|
+
executor: 'nx:run-commands',
|
|
161
|
+
dependsOn: ['^build', '*-js'],
|
|
162
|
+
options: { command: 'echo build', cwd: '{projectRoot}' },
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const resolvedTargetsByProject = new Map<string, ResolvedProjectTargets>([
|
|
169
|
+
[
|
|
170
|
+
'lib',
|
|
171
|
+
{
|
|
172
|
+
targets: new Set(['build', 'tsc-js']),
|
|
173
|
+
buildDependsOn: ['^build', '*-js'],
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
]);
|
|
177
|
+
|
|
178
|
+
expect(applyPackageTargetPolicy(root, { resolvedTargetsByProject })).toBe(false);
|
|
179
|
+
|
|
180
|
+
const lib = JSON.parse(await readFile(join(root, 'packages/lib/package.json'), 'utf8'));
|
|
181
|
+
expect(lib.nx.targets.build).toBeDefined();
|
|
182
|
+
expect(lib.nx.targets.build.options.command).toBe('echo build');
|
|
183
|
+
} finally {
|
|
184
|
+
await rm(root, { recursive: true, force: true });
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('rewrites safe scripts into Nx aliases', async () => {
|
|
189
|
+
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-pkg-target-'));
|
|
190
|
+
try {
|
|
191
|
+
await writeJson(join(root, 'package.json'), {
|
|
192
|
+
name: '@scope/root',
|
|
193
|
+
private: true,
|
|
194
|
+
workspaces: ['packages/*'],
|
|
195
|
+
});
|
|
196
|
+
await writeJson(join(root, 'packages/web/package.json'), {
|
|
197
|
+
name: '@scope/web',
|
|
198
|
+
dependencies: { '@scope/lib': 'workspace:*' },
|
|
199
|
+
scripts: {
|
|
200
|
+
dev: 'astro dev',
|
|
201
|
+
build: 'astro build',
|
|
202
|
+
},
|
|
203
|
+
nx: { name: 'web' },
|
|
204
|
+
});
|
|
205
|
+
await writeJson(join(root, 'packages/lib/package.json'), {
|
|
206
|
+
name: '@scope/lib',
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
expect(applyPackageTargetPolicy(root)).toBe(true);
|
|
210
|
+
|
|
211
|
+
const web = JSON.parse(await readFile(join(root, 'packages/web/package.json'), 'utf8'));
|
|
212
|
+
// dev script should become an Nx alias with streaming flags
|
|
213
|
+
expect(web.scripts.dev).toBe('nx run web:dev --tui=false --outputStyle=stream');
|
|
214
|
+
// build script should become an Nx alias without streaming flags
|
|
215
|
+
expect(web.scripts.build).toBe('nx run web:build');
|
|
216
|
+
// nx.targets.dev should be created with continuous flag
|
|
217
|
+
expect(web.nx.targets.dev.continuous).toBe(true);
|
|
218
|
+
expect(web.nx.targets.dev.executor).toBe('nx:run-commands');
|
|
219
|
+
expect(web.nx.targets.dev.options.command).toBe('astro dev');
|
|
220
|
+
// nx.targets.build should be created
|
|
221
|
+
expect(web.nx.targets.build.executor).toBe('nx:run-commands');
|
|
222
|
+
expect(web.nx.targets.build.options.command).toBe('astro build');
|
|
223
|
+
} finally {
|
|
224
|
+
await rm(root, { recursive: true, force: true });
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('rejects recursive script commands', async () => {
|
|
229
|
+
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-pkg-target-'));
|
|
230
|
+
try {
|
|
231
|
+
await writeJson(join(root, 'package.json'), {
|
|
232
|
+
name: '@scope/root',
|
|
233
|
+
private: true,
|
|
234
|
+
workspaces: ['packages/*'],
|
|
235
|
+
});
|
|
236
|
+
await writeJson(join(root, 'packages/app/package.json'), {
|
|
237
|
+
name: '@scope/app',
|
|
238
|
+
dependencies: { '@scope/lib': 'workspace:*' },
|
|
239
|
+
scripts: {
|
|
240
|
+
dev: 'nx run app:dev --tui=false --outputStyle=stream',
|
|
241
|
+
},
|
|
242
|
+
nx: {
|
|
243
|
+
name: 'app',
|
|
244
|
+
targets: {
|
|
245
|
+
dev: {
|
|
246
|
+
executor: 'nx:run-commands',
|
|
247
|
+
dependsOn: ['^build'],
|
|
248
|
+
continuous: true,
|
|
249
|
+
options: { command: 'bun run dev', cwd: '{projectRoot}' },
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
await writeJson(join(root, 'packages/lib/package.json'), {
|
|
255
|
+
name: '@scope/lib',
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
const issues = checkPackageTargetPolicy(root);
|
|
259
|
+
expect(issues.some((i) => i.message.includes('options.command must not call scripts.dev'))).toBe(true);
|
|
260
|
+
} finally {
|
|
261
|
+
await rm(root, { recursive: true, force: true });
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('moves env assignments into target options', async () => {
|
|
266
|
+
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-pkg-target-'));
|
|
267
|
+
try {
|
|
268
|
+
await writeJson(join(root, 'package.json'), {
|
|
269
|
+
name: '@scope/root',
|
|
270
|
+
private: true,
|
|
271
|
+
workspaces: ['packages/*'],
|
|
272
|
+
});
|
|
273
|
+
await writeJson(join(root, 'packages/web/package.json'), {
|
|
274
|
+
name: '@scope/web',
|
|
275
|
+
dependencies: { '@scope/lib': 'workspace:*' },
|
|
276
|
+
scripts: {
|
|
277
|
+
dev: "NODE_OPTIONS='--max-old-space-size=4096' astro dev",
|
|
278
|
+
},
|
|
279
|
+
nx: { name: 'web' },
|
|
280
|
+
});
|
|
281
|
+
await writeJson(join(root, 'packages/lib/package.json'), {
|
|
282
|
+
name: '@scope/lib',
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
expect(applyPackageTargetPolicy(root)).toBe(true);
|
|
286
|
+
|
|
287
|
+
const web = JSON.parse(await readFile(join(root, 'packages/web/package.json'), 'utf8'));
|
|
288
|
+
expect(web.nx.targets.dev.options.command).toBe('astro dev');
|
|
289
|
+
expect(web.nx.targets.dev.options.env).toEqual({ NODE_OPTIONS: '--max-old-space-size=4096' });
|
|
290
|
+
} finally {
|
|
291
|
+
await rm(root, { recursive: true, force: true });
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it('validates build.zig has steps', async () => {
|
|
296
|
+
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-pkg-target-'));
|
|
297
|
+
try {
|
|
298
|
+
await writeJson(join(root, 'package.json'), {
|
|
299
|
+
name: '@scope/root',
|
|
300
|
+
private: true,
|
|
301
|
+
workspaces: ['packages/*'],
|
|
302
|
+
});
|
|
303
|
+
const pkgDir = join(root, 'packages/wasm');
|
|
304
|
+
await mkdir(pkgDir, { recursive: true });
|
|
305
|
+
await writeJson(join(pkgDir, 'package.json'), {
|
|
306
|
+
name: '@scope/wasm',
|
|
307
|
+
nx: { name: 'wasm' },
|
|
308
|
+
});
|
|
309
|
+
// build.zig without b.step(...)
|
|
310
|
+
await writeFile(join(pkgDir, 'build.zig'), 'const std = @import("std");\n');
|
|
311
|
+
|
|
312
|
+
const issues = checkPackageTargetPolicy(root);
|
|
313
|
+
expect(issues.some((i) => i.message.includes('build.zig must define at least one b.step'))).toBe(true);
|
|
314
|
+
} finally {
|
|
315
|
+
await rm(root, { recursive: true, force: true });
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it('requires test entrypoint when test files exist', async () => {
|
|
320
|
+
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-pkg-target-'));
|
|
321
|
+
try {
|
|
322
|
+
await writeJson(join(root, 'package.json'), {
|
|
323
|
+
name: '@scope/root',
|
|
324
|
+
private: true,
|
|
325
|
+
workspaces: ['packages/*'],
|
|
326
|
+
});
|
|
327
|
+
const pkgDir = join(root, 'packages/lib');
|
|
328
|
+
const srcDir = join(pkgDir, 'src');
|
|
329
|
+
await mkdir(srcDir, { recursive: true });
|
|
330
|
+
await writeJson(join(pkgDir, 'package.json'), {
|
|
331
|
+
name: '@scope/lib',
|
|
332
|
+
nx: { name: 'lib' },
|
|
333
|
+
});
|
|
334
|
+
// Create a test file without a scripts.test entry
|
|
335
|
+
await writeFile(join(srcDir, 'example.test.ts'), 'import { test } from "bun:test";\n');
|
|
336
|
+
|
|
337
|
+
const issues = checkPackageTargetPolicy(root);
|
|
338
|
+
expect(issues.some((i) => i.message.includes('test files require scripts.test or nx.targets.test'))).toBe(true);
|
|
339
|
+
} finally {
|
|
340
|
+
await rm(root, { recursive: true, force: true });
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it('accepts wildcard aggregate build dependencies', async () => {
|
|
345
|
+
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-pkg-target-'));
|
|
346
|
+
try {
|
|
347
|
+
await writeJson(join(root, 'package.json'), {
|
|
348
|
+
name: '@scope/root',
|
|
349
|
+
private: true,
|
|
350
|
+
workspaces: ['packages/*'],
|
|
351
|
+
});
|
|
352
|
+
await writeJson(join(root, 'packages/lib/package.json'), {
|
|
353
|
+
name: '@scope/lib',
|
|
354
|
+
nx: {
|
|
355
|
+
name: 'lib',
|
|
356
|
+
targets: {
|
|
357
|
+
build: {
|
|
358
|
+
executor: 'nx:noop',
|
|
359
|
+
dependsOn: ['^build', '*-js', '*-wasm'],
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
const issues = checkPackageTargetPolicy(root);
|
|
366
|
+
// No issue about missing targets for wildcard dependencies
|
|
367
|
+
const buildIssues = issues.filter((i) => i.message.includes('dependsOn references missing target'));
|
|
368
|
+
expect(buildIssues).toEqual([]);
|
|
369
|
+
} finally {
|
|
370
|
+
await rm(root, { recursive: true, force: true });
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
describe('per-package checkPackageTargets', () => {
|
|
376
|
+
it('detects colon target names', () => {
|
|
377
|
+
const pkg = {
|
|
378
|
+
nx: {
|
|
379
|
+
name: 'lib',
|
|
380
|
+
targets: {
|
|
381
|
+
'build:ts': { executor: 'nx:run-commands', options: { command: 'tsc' } },
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
};
|
|
385
|
+
const issues = checkPackageTargets(pkg, 'packages/lib');
|
|
386
|
+
expect(issues.some((i) => i.message.includes('build:ts') && i.message.includes('colon'))).toBe(true);
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
describe('per-package applyPackageTargets', () => {
|
|
391
|
+
it('migrates colon targets and rewrites scripts', () => {
|
|
392
|
+
const pkg: Record<string, unknown> = {
|
|
393
|
+
name: '@scope/lib',
|
|
394
|
+
dependencies: { '@scope/other': 'workspace:*' },
|
|
395
|
+
scripts: {
|
|
396
|
+
'build:ts': 'nx run lib:build:ts',
|
|
397
|
+
},
|
|
398
|
+
nx: {
|
|
399
|
+
name: 'lib',
|
|
400
|
+
targets: {
|
|
401
|
+
'build:ts': {
|
|
402
|
+
executor: 'nx:run-commands',
|
|
403
|
+
options: { command: 'tsc --build tsconfig.lib.json', cwd: '{projectRoot}' },
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
};
|
|
408
|
+
const workspaceNames = new Set(['@scope/lib', '@scope/other']);
|
|
409
|
+
expect(applyPackageTargets(pkg, 'packages/lib', workspaceNames)).toBe(true);
|
|
410
|
+
const targets = (pkg.nx as Record<string, unknown>).targets as Record<string, unknown>;
|
|
411
|
+
expect(targets['build:ts']).toBeUndefined();
|
|
412
|
+
expect(targets['tsc-js']).toBeDefined();
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
describe('nxRunAlias', () => {
|
|
417
|
+
it('generates streaming flags for continuous targets', () => {
|
|
418
|
+
expect(nxRunAlias('app', 'dev', true)).toBe('nx run app:dev --tui=false --outputStyle=stream');
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
it('generates plain alias for non-continuous targets', () => {
|
|
422
|
+
expect(nxRunAlias('app', 'build', false)).toBe('nx run app:build');
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it('delegates test targets to boundedTestScriptAlias', () => {
|
|
426
|
+
expect(nxRunAlias('app', 'test', false)).toBe('nx run app:test --tui=false --outputStyle=stream');
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
describe('packageNxProjectName', () => {
|
|
431
|
+
it('returns nx.name when present', () => {
|
|
432
|
+
expect(packageNxProjectName({ nx: { name: 'my-lib' } })).toBe('my-lib');
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it('falls back to package name', () => {
|
|
436
|
+
expect(packageNxProjectName({ name: '@scope/my-lib' })).toBe('@scope/my-lib');
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it('returns null for anonymous packages', () => {
|
|
440
|
+
expect(packageNxProjectName({})).toBeNull();
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
// ---------------------------------------------------------------------------
|
|
445
|
+
// Tree-based tests
|
|
446
|
+
// ---------------------------------------------------------------------------
|
|
447
|
+
|
|
448
|
+
function addProject(tree: Tree, name: string, root: string, options: { keepProjectJson?: boolean } = {}): void {
|
|
449
|
+
addProjectConfiguration(tree, name, {
|
|
450
|
+
root,
|
|
451
|
+
sourceRoot: `${root}/src`,
|
|
452
|
+
projectType: 'library',
|
|
453
|
+
targets: {},
|
|
454
|
+
});
|
|
455
|
+
if (!options.keepProjectJson && tree.exists(`${root}/project.json`)) {
|
|
456
|
+
tree.delete(`${root}/project.json`);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function writeJsonFile(tree: Tree, filePath: string, value: unknown): void {
|
|
461
|
+
tree.write(filePath, `${JSON.stringify(value, null, 2)}\n`);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
describe('checkPackageTargetPolicyTree', () => {
|
|
465
|
+
let tree: Tree;
|
|
466
|
+
|
|
467
|
+
beforeEach(() => {
|
|
468
|
+
tree = createTreeWithEmptyWorkspace();
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
it('detects colon-style Nx targets', () => {
|
|
472
|
+
addProject(tree, 'app', 'packages/app');
|
|
473
|
+
writeJsonFile(tree, 'packages/app/package.json', {
|
|
474
|
+
name: '@scope/app',
|
|
475
|
+
nx: {
|
|
476
|
+
name: 'app',
|
|
477
|
+
targets: {
|
|
478
|
+
'build:ts': {
|
|
479
|
+
executor: 'nx:run-commands',
|
|
480
|
+
options: { command: 'tsc --build tsconfig.lib.json', cwd: '{projectRoot}' },
|
|
481
|
+
},
|
|
482
|
+
'lint:fix': {
|
|
483
|
+
executor: 'nx:run-commands',
|
|
484
|
+
options: { command: 'biome check --apply', cwd: '{projectRoot}' },
|
|
485
|
+
},
|
|
486
|
+
},
|
|
487
|
+
},
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
const issues = checkPackageTargetPolicyTree(tree);
|
|
491
|
+
expect(issues.length).toBeGreaterThanOrEqual(2);
|
|
492
|
+
expect(issues.some((i) => i.message.includes('build:ts') && i.message.includes('colon target names'))).toBe(true);
|
|
493
|
+
expect(issues.some((i) => i.message.includes('lint:fix') && i.message.includes('colon target names'))).toBe(true);
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
it('validates build.zig has steps', () => {
|
|
497
|
+
addProject(tree, 'wasm', 'packages/wasm');
|
|
498
|
+
writeJsonFile(tree, 'packages/wasm/package.json', {
|
|
499
|
+
name: '@scope/wasm',
|
|
500
|
+
nx: { name: 'wasm' },
|
|
501
|
+
});
|
|
502
|
+
tree.write('packages/wasm/build.zig', 'const std = @import("std");\n');
|
|
503
|
+
|
|
504
|
+
const issues = checkPackageTargetPolicyTree(tree);
|
|
505
|
+
expect(issues.some((i) => i.message.includes('build.zig must define at least one b.step'))).toBe(true);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
it('passes build.zig with valid steps', () => {
|
|
509
|
+
addProject(tree, 'wasm', 'packages/wasm');
|
|
510
|
+
writeJsonFile(tree, 'packages/wasm/package.json', {
|
|
511
|
+
name: '@scope/wasm',
|
|
512
|
+
nx: { name: 'wasm' },
|
|
513
|
+
});
|
|
514
|
+
tree.write('packages/wasm/build.zig', 'const step = b.step("wasm", "Build wasm");\n');
|
|
515
|
+
|
|
516
|
+
const issues = checkPackageTargetPolicyTree(tree);
|
|
517
|
+
expect(issues.filter((i) => i.message.includes('build.zig'))).toEqual([]);
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
it('requires test entrypoint when test files exist', () => {
|
|
521
|
+
addProject(tree, 'lib', 'packages/lib');
|
|
522
|
+
writeJsonFile(tree, 'packages/lib/package.json', {
|
|
523
|
+
name: '@scope/lib',
|
|
524
|
+
nx: { name: 'lib' },
|
|
525
|
+
});
|
|
526
|
+
tree.write('packages/lib/src/example.test.ts', 'import { test } from "bun:test";\n');
|
|
527
|
+
|
|
528
|
+
const issues = checkPackageTargetPolicyTree(tree);
|
|
529
|
+
expect(issues.some((i) => i.message.includes('test files require scripts.test or nx.targets.test'))).toBe(true);
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
it('accepts packages with test entrypoint', () => {
|
|
533
|
+
addProject(tree, 'lib', 'packages/lib');
|
|
534
|
+
writeJsonFile(tree, 'packages/lib/package.json', {
|
|
535
|
+
name: '@scope/lib',
|
|
536
|
+
scripts: { test: 'bun test' },
|
|
537
|
+
nx: { name: 'lib' },
|
|
538
|
+
});
|
|
539
|
+
tree.write('packages/lib/src/example.test.ts', 'import { test } from "bun:test";\n');
|
|
540
|
+
|
|
541
|
+
const issues = checkPackageTargetPolicyTree(tree);
|
|
542
|
+
expect(issues.filter((i) => i.message.includes('test files require'))).toEqual([]);
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
it('accepts wildcard aggregate build dependencies', () => {
|
|
546
|
+
addProject(tree, 'lib', 'packages/lib');
|
|
547
|
+
writeJsonFile(tree, 'packages/lib/package.json', {
|
|
548
|
+
name: '@scope/lib',
|
|
549
|
+
nx: {
|
|
550
|
+
name: 'lib',
|
|
551
|
+
targets: {
|
|
552
|
+
build: {
|
|
553
|
+
executor: 'nx:noop',
|
|
554
|
+
dependsOn: ['^build', '*-js', '*-wasm'],
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
const issues = checkPackageTargetPolicyTree(tree);
|
|
561
|
+
const buildIssues = issues.filter((i) => i.message.includes('dependsOn references missing target'));
|
|
562
|
+
expect(buildIssues).toEqual([]);
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it('rejects recursive script commands', () => {
|
|
566
|
+
addProject(tree, 'app', 'packages/app');
|
|
567
|
+
addProject(tree, 'lib', 'packages/lib');
|
|
568
|
+
writeJsonFile(tree, 'packages/app/package.json', {
|
|
569
|
+
name: '@scope/app',
|
|
570
|
+
dependencies: { '@scope/lib': 'workspace:*' },
|
|
571
|
+
scripts: {
|
|
572
|
+
dev: 'nx run app:dev --tui=false --outputStyle=stream',
|
|
573
|
+
},
|
|
574
|
+
nx: {
|
|
575
|
+
name: 'app',
|
|
576
|
+
targets: {
|
|
577
|
+
dev: {
|
|
578
|
+
executor: 'nx:run-commands',
|
|
579
|
+
dependsOn: ['^build'],
|
|
580
|
+
continuous: true,
|
|
581
|
+
options: { command: 'bun run dev', cwd: '{projectRoot}' },
|
|
582
|
+
},
|
|
583
|
+
},
|
|
584
|
+
},
|
|
585
|
+
});
|
|
586
|
+
writeJsonFile(tree, 'packages/lib/package.json', {
|
|
587
|
+
name: '@scope/lib',
|
|
588
|
+
nx: { name: 'lib' },
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
const issues = checkPackageTargetPolicyTree(tree);
|
|
592
|
+
expect(issues.some((i) => i.message.includes('options.command must not call scripts.dev'))).toBe(true);
|
|
593
|
+
});
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
describe('applyPackageTargetPolicyTree', () => {
|
|
597
|
+
let tree: Tree;
|
|
598
|
+
|
|
599
|
+
beforeEach(() => {
|
|
600
|
+
tree = createTreeWithEmptyWorkspace();
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
it('migrates colon build targets to tool-output names', () => {
|
|
604
|
+
addProject(tree, 'lib', 'packages/lib');
|
|
605
|
+
addProject(tree, 'other', 'packages/other');
|
|
606
|
+
writeJsonFile(tree, 'packages/lib/package.json', {
|
|
607
|
+
name: '@scope/lib',
|
|
608
|
+
dependencies: { '@scope/other': 'workspace:*' },
|
|
609
|
+
scripts: {
|
|
610
|
+
'build:ts': 'nx run lib:build:ts',
|
|
611
|
+
},
|
|
612
|
+
nx: {
|
|
613
|
+
name: 'lib',
|
|
614
|
+
targets: {
|
|
615
|
+
'build:ts': {
|
|
616
|
+
executor: 'nx:run-commands',
|
|
617
|
+
options: { command: 'tsc --build tsconfig.lib.json', cwd: '{projectRoot}' },
|
|
618
|
+
},
|
|
619
|
+
build: {
|
|
620
|
+
executor: 'nx:noop',
|
|
621
|
+
dependsOn: ['^build', 'build:ts'],
|
|
622
|
+
},
|
|
623
|
+
},
|
|
624
|
+
},
|
|
625
|
+
});
|
|
626
|
+
writeJsonFile(tree, 'packages/other/package.json', {
|
|
627
|
+
name: '@scope/other',
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
expect(applyPackageTargetPolicyTree(tree)).toBe(true);
|
|
631
|
+
|
|
632
|
+
const lib = readJson(tree, 'packages/lib/package.json');
|
|
633
|
+
const targets = lib.nx.targets;
|
|
634
|
+
expect(targets['build:ts']).toBeUndefined();
|
|
635
|
+
expect(targets['tsc-js']).toBeDefined();
|
|
636
|
+
expect(targets['tsc-js'].options.command).toBe('tsc --build tsconfig.lib.json');
|
|
637
|
+
expect(targets.build.dependsOn).toContain('tsc-js');
|
|
638
|
+
expect(targets.build.dependsOn).not.toContain('build:ts');
|
|
639
|
+
expect(lib.scripts['build:ts']).toBe('nx run lib:tsc-js');
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
it('removes noop aggregate build targets matching resolved plugin output', () => {
|
|
643
|
+
addProject(tree, 'lib', 'packages/lib');
|
|
644
|
+
writeJsonFile(tree, 'packages/lib/package.json', {
|
|
645
|
+
name: '@scope/lib',
|
|
646
|
+
nx: {
|
|
647
|
+
name: 'lib',
|
|
648
|
+
targets: {
|
|
649
|
+
build: {
|
|
650
|
+
executor: 'nx:noop',
|
|
651
|
+
dependsOn: ['^build', '*-js'],
|
|
652
|
+
},
|
|
653
|
+
},
|
|
654
|
+
},
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
const resolvedTargetsByProject = new Map<string, ResolvedProjectTargets>([
|
|
658
|
+
[
|
|
659
|
+
'lib',
|
|
660
|
+
{
|
|
661
|
+
targets: new Set(['build', 'tsc-js']),
|
|
662
|
+
buildDependsOn: ['^build', '*-js'],
|
|
663
|
+
},
|
|
664
|
+
],
|
|
665
|
+
]);
|
|
666
|
+
|
|
667
|
+
expect(applyPackageTargetPolicyTree(tree, { resolvedTargetsByProject })).toBe(true);
|
|
668
|
+
|
|
669
|
+
const lib = readJson(tree, 'packages/lib/package.json');
|
|
670
|
+
expect(lib.nx.targets.build).toBeUndefined();
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
it('keeps non-noop build targets even when dependsOn matches', () => {
|
|
674
|
+
addProject(tree, 'lib', 'packages/lib');
|
|
675
|
+
writeJsonFile(tree, 'packages/lib/package.json', {
|
|
676
|
+
name: '@scope/lib',
|
|
677
|
+
nx: {
|
|
678
|
+
name: 'lib',
|
|
679
|
+
targets: {
|
|
680
|
+
build: {
|
|
681
|
+
executor: 'nx:run-commands',
|
|
682
|
+
dependsOn: ['^build', '*-js'],
|
|
683
|
+
options: { command: 'echo build', cwd: '{projectRoot}' },
|
|
684
|
+
},
|
|
685
|
+
},
|
|
686
|
+
},
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
const resolvedTargetsByProject = new Map<string, ResolvedProjectTargets>([
|
|
690
|
+
[
|
|
691
|
+
'lib',
|
|
692
|
+
{
|
|
693
|
+
targets: new Set(['build', 'tsc-js']),
|
|
694
|
+
buildDependsOn: ['^build', '*-js'],
|
|
695
|
+
},
|
|
696
|
+
],
|
|
697
|
+
]);
|
|
698
|
+
|
|
699
|
+
expect(applyPackageTargetPolicyTree(tree, { resolvedTargetsByProject })).toBe(false);
|
|
700
|
+
|
|
701
|
+
const lib = readJson(tree, 'packages/lib/package.json');
|
|
702
|
+
expect(lib.nx.targets.build).toBeDefined();
|
|
703
|
+
expect(lib.nx.targets.build.options.command).toBe('echo build');
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
it('rewrites safe scripts into Nx aliases', () => {
|
|
707
|
+
addProject(tree, 'web', 'packages/web');
|
|
708
|
+
addProject(tree, 'lib', 'packages/lib');
|
|
709
|
+
writeJsonFile(tree, 'packages/web/package.json', {
|
|
710
|
+
name: '@scope/web',
|
|
711
|
+
dependencies: { '@scope/lib': 'workspace:*' },
|
|
712
|
+
scripts: {
|
|
713
|
+
dev: 'astro dev',
|
|
714
|
+
build: 'astro build',
|
|
715
|
+
},
|
|
716
|
+
nx: { name: 'web' },
|
|
717
|
+
});
|
|
718
|
+
writeJsonFile(tree, 'packages/lib/package.json', {
|
|
719
|
+
name: '@scope/lib',
|
|
720
|
+
nx: { name: 'lib' },
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
expect(applyPackageTargetPolicyTree(tree)).toBe(true);
|
|
724
|
+
|
|
725
|
+
const web = readJson(tree, 'packages/web/package.json');
|
|
726
|
+
expect(web.scripts.dev).toBe('nx run web:dev --tui=false --outputStyle=stream');
|
|
727
|
+
expect(web.scripts.build).toBe('nx run web:build');
|
|
728
|
+
expect(web.nx.targets.dev.continuous).toBe(true);
|
|
729
|
+
expect(web.nx.targets.dev.executor).toBe('nx:run-commands');
|
|
730
|
+
expect(web.nx.targets.dev.options.command).toBe('astro dev');
|
|
731
|
+
expect(web.nx.targets.build.executor).toBe('nx:run-commands');
|
|
732
|
+
expect(web.nx.targets.build.options.command).toBe('astro build');
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
it('moves env assignments into target options', () => {
|
|
736
|
+
addProject(tree, 'web', 'packages/web');
|
|
737
|
+
addProject(tree, 'lib', 'packages/lib');
|
|
738
|
+
writeJsonFile(tree, 'packages/web/package.json', {
|
|
739
|
+
name: '@scope/web',
|
|
740
|
+
dependencies: { '@scope/lib': 'workspace:*' },
|
|
741
|
+
scripts: {
|
|
742
|
+
dev: "NODE_OPTIONS='--max-old-space-size=4096' astro dev",
|
|
743
|
+
},
|
|
744
|
+
nx: { name: 'web' },
|
|
745
|
+
});
|
|
746
|
+
writeJsonFile(tree, 'packages/lib/package.json', {
|
|
747
|
+
name: '@scope/lib',
|
|
748
|
+
nx: { name: 'lib' },
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
expect(applyPackageTargetPolicyTree(tree)).toBe(true);
|
|
752
|
+
|
|
753
|
+
const web = readJson(tree, 'packages/web/package.json');
|
|
754
|
+
expect(web.nx.targets.dev.options.command).toBe('astro dev');
|
|
755
|
+
expect(web.nx.targets.dev.options.env).toEqual({ NODE_OPTIONS: '--max-old-space-size=4096' });
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
it('returns false when no changes needed', () => {
|
|
759
|
+
addProject(tree, 'lib', 'packages/lib');
|
|
760
|
+
writeJsonFile(tree, 'packages/lib/package.json', {
|
|
761
|
+
name: '@scope/lib',
|
|
762
|
+
nx: { name: 'lib' },
|
|
763
|
+
});
|
|
764
|
+
|
|
765
|
+
expect(applyPackageTargetPolicyTree(tree)).toBe(false);
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
it('skips projects without package.json', () => {
|
|
769
|
+
addProject(tree, 'native', 'packages/native', { keepProjectJson: true });
|
|
770
|
+
// No package.json written — should not throw
|
|
771
|
+
expect(applyPackageTargetPolicyTree(tree)).toBe(false);
|
|
772
|
+
});
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
async function writeJson(path: string, value: unknown): Promise<void> {
|
|
776
|
+
await mkdir(dirname(path), { recursive: true });
|
|
777
|
+
await writeFile(path, `${JSON.stringify(value, null, 2)}\n`);
|
|
778
|
+
}
|