@smoothbricks/nx-plugin 0.1.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 +35 -8
- 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.map +1 -1
- package/dist/generators/bun-test-tracing/generator.js +5 -4
- 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.map +1 -1
- package/dist/index.js +78 -7
- 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 +15 -0
- package/package.json +45 -11
- 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 +25 -1
- package/src/generators/bun-test-tracing/generator.ts +6 -5
- 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 +85 -18
- package/src/index.ts +99 -8
- 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
- package/src/test-suite-tracer.ts +0 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import type { AfterAllProjectsVersioned, VersionActions } from 'nx/release';
|
|
4
|
+
|
|
5
|
+
type VersionActionsModule = typeof VersionActions & {
|
|
6
|
+
default?: typeof VersionActions & { afterAllProjectsVersioned: AfterAllProjectsVersioned };
|
|
7
|
+
afterAllProjectsVersioned: AfterAllProjectsVersioned;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const nxJsVersionActions = require('@nx/js/src/release/version-actions') as VersionActionsModule;
|
|
11
|
+
const baseVersionActions = nxJsVersionActions.default ?? nxJsVersionActions;
|
|
12
|
+
|
|
13
|
+
const afterAllProjectsVersioned: AfterAllProjectsVersioned = async (cwd, options) => {
|
|
14
|
+
const result = await nxJsVersionActions.afterAllProjectsVersioned(cwd, options);
|
|
15
|
+
|
|
16
|
+
// Temporary Bun workaround. Delete this hook together with the CLI lockfile
|
|
17
|
+
// sync/validation code once supported Bun versions fix all three issues:
|
|
18
|
+
// - https://github.com/oven-sh/bun/issues/18906
|
|
19
|
+
// - https://github.com/oven-sh/bun/issues/20477
|
|
20
|
+
// - https://github.com/oven-sh/bun/issues/20829
|
|
21
|
+
// Nx runs `bun install --lockfile-only`, but Bun currently leaves workspace
|
|
22
|
+
// versions stale in bun.lock. `bun pm pack` then rewrites `workspace:*` using
|
|
23
|
+
// those stale lockfile versions instead of the current package.json versions.
|
|
24
|
+
const updated = syncBunLockfileVersions(cwd);
|
|
25
|
+
if (updated === 0) {
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
changedFiles: Array.from(new Set([...result.changedFiles, 'bun.lock'])),
|
|
31
|
+
deletedFiles: result.deletedFiles,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
baseVersionActions.afterAllProjectsVersioned = afterAllProjectsVersioned;
|
|
36
|
+
|
|
37
|
+
export = baseVersionActions;
|
|
38
|
+
|
|
39
|
+
function syncBunLockfileVersions(root: string): number {
|
|
40
|
+
const lockfilePath = join(root, 'bun.lock');
|
|
41
|
+
if (!existsSync(lockfilePath)) {
|
|
42
|
+
throw new Error('bun.lock not found');
|
|
43
|
+
}
|
|
44
|
+
const packages = workspacePackages(root);
|
|
45
|
+
let lockfile = readFileSync(lockfilePath, 'utf8');
|
|
46
|
+
let updated = 0;
|
|
47
|
+
for (const pkg of packages) {
|
|
48
|
+
const relativePath = pkg.path.replaceAll('\\', '/');
|
|
49
|
+
const escaped = escapeRegex(relativePath);
|
|
50
|
+
const pattern = new RegExp(`("${escaped}":\\s*\\{[^}]*"version":\\s*")([^"]+)(")`);
|
|
51
|
+
const match = lockfile.match(pattern);
|
|
52
|
+
if (!match) {
|
|
53
|
+
console.log(`skip: ${relativePath} (not found in lockfile)`);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const lockVersion = match[2];
|
|
57
|
+
if (lockVersion === pkg.version) {
|
|
58
|
+
console.log(`ok: ${relativePath} = ${pkg.version}`);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
lockfile = lockfile.replace(pattern, `$1${pkg.version}$3`);
|
|
62
|
+
console.log(`fix: ${relativePath}: ${lockVersion} -> ${pkg.version}`);
|
|
63
|
+
updated++;
|
|
64
|
+
}
|
|
65
|
+
if (updated > 0) {
|
|
66
|
+
writeFileSync(lockfilePath, lockfile);
|
|
67
|
+
}
|
|
68
|
+
console.log(
|
|
69
|
+
updated > 0 ? `Updated ${updated} workspace version(s) in bun.lock` : 'All workspace versions already in sync.'
|
|
70
|
+
);
|
|
71
|
+
return updated;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function workspacePackages(root: string): Array<{ path: string; name: string; version: string }> {
|
|
75
|
+
const packagesRoot = join(root, 'packages');
|
|
76
|
+
return readdirSync(packagesRoot, { withFileTypes: true })
|
|
77
|
+
.filter((entry) => entry.isDirectory())
|
|
78
|
+
.map((entry) => {
|
|
79
|
+
const path = `packages/${entry.name}`;
|
|
80
|
+
const packageJsonPath = join(root, path, 'package.json');
|
|
81
|
+
if (!existsSync(packageJsonPath)) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const json = JSON.parse(readFileSync(packageJsonPath, 'utf8')) as Record<string, unknown>;
|
|
85
|
+
return typeof json.name === 'string' && typeof json.version === 'string'
|
|
86
|
+
? { path, name: json.name, version: json.version }
|
|
87
|
+
: null;
|
|
88
|
+
})
|
|
89
|
+
.filter((pkg): pkg is { path: string; name: string; version: string } => pkg !== null);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function escapeRegex(value: string): string {
|
|
93
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
94
|
+
}
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { 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 { readJson, writeJson } from 'nx/src/devkit-exports.js';
|
|
7
|
+
import { createTreeWithEmptyWorkspace } from 'nx/src/devkit-testing-exports.js';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
applyWorkspaceConfig,
|
|
11
|
+
applyWorkspaceConfigPolicy,
|
|
12
|
+
applyWorkspaceConfigTree,
|
|
13
|
+
checkWorkspaceConfig,
|
|
14
|
+
checkWorkspaceConfigPolicy,
|
|
15
|
+
checkWorkspaceConfigTree,
|
|
16
|
+
} from './workspace-config-policy.js';
|
|
17
|
+
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
// Helpers
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
function validNxJson(): Record<string, unknown> {
|
|
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
|
+
],
|
|
39
|
+
targetDefaults: {
|
|
40
|
+
build: { cache: true, outputs: ['{projectRoot}/dist'] },
|
|
41
|
+
},
|
|
42
|
+
namedInputs: validNamedInputs(),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function validNamedInputs(): Record<string, unknown> {
|
|
47
|
+
return {
|
|
48
|
+
default: ['{projectRoot}/**/*', 'sharedGlobals'],
|
|
49
|
+
sharedGlobals: ['{workspaceRoot}/.github/workflows/ci.yml'],
|
|
50
|
+
production: [
|
|
51
|
+
'{projectRoot}/src/**/*',
|
|
52
|
+
'{projectRoot}/package.json',
|
|
53
|
+
'!{projectRoot}/**/__tests__/**',
|
|
54
|
+
'!{projectRoot}/**/*.test.*',
|
|
55
|
+
'!{projectRoot}/**/*.spec.*',
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function validPlugins(): unknown[] {
|
|
61
|
+
return [
|
|
62
|
+
{
|
|
63
|
+
plugin: '@nx/js/typescript',
|
|
64
|
+
options: {
|
|
65
|
+
typecheck: { targetName: 'typecheck' },
|
|
66
|
+
build: {
|
|
67
|
+
targetName: 'tsc-js',
|
|
68
|
+
configName: 'tsconfig.lib.json',
|
|
69
|
+
buildDepsName: 'build-deps',
|
|
70
|
+
watchDepsName: 'watch-deps',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
'@smoothbricks/nx-plugin',
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
// Layer 1: Pure core function tests
|
|
80
|
+
// ---------------------------------------------------------------------------
|
|
81
|
+
|
|
82
|
+
describe('pure core: checkWorkspaceConfig', () => {
|
|
83
|
+
it('returns no issues for valid config', () => {
|
|
84
|
+
const issues = checkWorkspaceConfig(validNxJson());
|
|
85
|
+
expect(issues).toEqual([]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('uses nx.json as path in issues', () => {
|
|
89
|
+
const issues = checkWorkspaceConfig({});
|
|
90
|
+
for (const issue of issues) {
|
|
91
|
+
expect(issue.path).toBe('nx.json');
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('detects missing plugins', () => {
|
|
96
|
+
const issues = checkWorkspaceConfig({
|
|
97
|
+
plugins: [],
|
|
98
|
+
targetDefaults: { build: { cache: true, outputs: ['{projectRoot}/dist'] } },
|
|
99
|
+
namedInputs: validNamedInputs(),
|
|
100
|
+
});
|
|
101
|
+
expect(issues.length).toBe(2);
|
|
102
|
+
expect(issues.some((i) => i.message.includes('Official Nx owns TypeScript library inference'))).toBe(true);
|
|
103
|
+
expect(issues.some((i) => i.message.includes('plugins must include @smoothbricks/nx-plugin'))).toBe(true);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('detects colon target defaults', () => {
|
|
107
|
+
const issues = checkWorkspaceConfig({
|
|
108
|
+
...validNxJson(),
|
|
109
|
+
targetDefaults: {
|
|
110
|
+
build: { cache: true, outputs: ['{projectRoot}/dist'] },
|
|
111
|
+
'build:wasm': { cache: true },
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
expect(issues.some((i) => i.message.includes('build:wasm'))).toBe(true);
|
|
115
|
+
expect(issues.some((i) => i.message.includes('must not use colon target names'))).toBe(true);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('detects wrong tsc-js target name', () => {
|
|
119
|
+
const issues = checkWorkspaceConfig({
|
|
120
|
+
plugins: [
|
|
121
|
+
{ plugin: '@nx/js/typescript', options: { build: { targetName: 'build' } } },
|
|
122
|
+
'@smoothbricks/nx-plugin',
|
|
123
|
+
],
|
|
124
|
+
targetDefaults: { build: { cache: true, outputs: ['{projectRoot}/dist'] } },
|
|
125
|
+
namedInputs: validNamedInputs(),
|
|
126
|
+
});
|
|
127
|
+
expect(issues.some((i) => i.message.includes('build.targetName must be tsc-js'))).toBe(true);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('detects imprecise production inputs', () => {
|
|
131
|
+
const issues = checkWorkspaceConfig({
|
|
132
|
+
plugins: validPlugins(),
|
|
133
|
+
targetDefaults: { build: { cache: true, outputs: ['{projectRoot}/dist'] } },
|
|
134
|
+
namedInputs: {
|
|
135
|
+
...validNamedInputs(),
|
|
136
|
+
production: ['default'],
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
expect(issues.some((i) => i.message.includes('enumerate precise production inputs'))).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('detects missing build cache', () => {
|
|
143
|
+
const issues = checkWorkspaceConfig({
|
|
144
|
+
plugins: validPlugins(),
|
|
145
|
+
targetDefaults: { build: { cache: false } },
|
|
146
|
+
namedInputs: validNamedInputs(),
|
|
147
|
+
});
|
|
148
|
+
expect(issues.some((i) => i.message.includes('build.cache must be true'))).toBe(true);
|
|
149
|
+
expect(issues.some((i) => i.message.includes('build.outputs'))).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('detects missing sharedGlobals', () => {
|
|
153
|
+
const issues = checkWorkspaceConfig({
|
|
154
|
+
plugins: validPlugins(),
|
|
155
|
+
targetDefaults: { build: { cache: true, outputs: ['{projectRoot}/dist'] } },
|
|
156
|
+
namedInputs: {
|
|
157
|
+
...validNamedInputs(),
|
|
158
|
+
sharedGlobals: [],
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
expect(issues.some((i) => i.message.includes('sharedGlobals'))).toBe(true);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe('pure core: applyWorkspaceConfig', () => {
|
|
166
|
+
it('returns false for already-valid config', () => {
|
|
167
|
+
const nxJson = validNxJson();
|
|
168
|
+
expect(applyWorkspaceConfig(nxJson)).toBe(false);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('fixes missing plugins', () => {
|
|
172
|
+
const nxJson: Record<string, unknown> = {
|
|
173
|
+
plugins: [],
|
|
174
|
+
targetDefaults: { build: { cache: true, outputs: ['{projectRoot}/dist'] } },
|
|
175
|
+
namedInputs: validNamedInputs(),
|
|
176
|
+
};
|
|
177
|
+
expect(applyWorkspaceConfig(nxJson)).toBe(true);
|
|
178
|
+
const pluginNames = (nxJson.plugins as unknown[]).map((p: unknown) =>
|
|
179
|
+
typeof p === 'string' ? p : (p as Record<string, unknown>).plugin,
|
|
180
|
+
);
|
|
181
|
+
expect(pluginNames).toContain('@nx/js/typescript');
|
|
182
|
+
expect(pluginNames).toContain('@smoothbricks/nx-plugin');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('removes colon target defaults', () => {
|
|
186
|
+
const nxJson = {
|
|
187
|
+
...validNxJson(),
|
|
188
|
+
targetDefaults: {
|
|
189
|
+
build: { cache: true, outputs: ['{projectRoot}/dist'] },
|
|
190
|
+
'build:wasm': { cache: true },
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
expect(applyWorkspaceConfig(nxJson)).toBe(true);
|
|
194
|
+
expect((nxJson.targetDefaults as Record<string, unknown>)['build:wasm']).toBeUndefined();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('fixes imprecise production inputs', () => {
|
|
198
|
+
const nxJson: Record<string, unknown> = {
|
|
199
|
+
plugins: validPlugins(),
|
|
200
|
+
targetDefaults: { build: { cache: true, outputs: ['{projectRoot}/dist'] } },
|
|
201
|
+
namedInputs: {
|
|
202
|
+
...validNamedInputs(),
|
|
203
|
+
production: ['default', '{projectRoot}/**/*'],
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
expect(applyWorkspaceConfig(nxJson)).toBe(true);
|
|
207
|
+
const namedInputs = nxJson.namedInputs as Record<string, unknown>;
|
|
208
|
+
expect(namedInputs.production).toEqual([
|
|
209
|
+
'{projectRoot}/src/**/*',
|
|
210
|
+
'{projectRoot}/package.json',
|
|
211
|
+
'!{projectRoot}/**/__tests__/**',
|
|
212
|
+
'!{projectRoot}/**/*.test.*',
|
|
213
|
+
'!{projectRoot}/**/*.spec.*',
|
|
214
|
+
]);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('accepts custom precise production inputs unchanged', () => {
|
|
218
|
+
const nxJson: Record<string, unknown> = {
|
|
219
|
+
plugins: validPlugins(),
|
|
220
|
+
targetDefaults: { build: { cache: true, outputs: ['{projectRoot}/dist'] } },
|
|
221
|
+
namedInputs: {
|
|
222
|
+
...validNamedInputs(),
|
|
223
|
+
production: ['{projectRoot}/src/**/*.rs', '{projectRoot}/Cargo.toml', '!{projectRoot}/**/*.test.*'],
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
expect(applyWorkspaceConfig(nxJson)).toBe(false);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// ---------------------------------------------------------------------------
|
|
231
|
+
// Layer 2: Tree-based function tests
|
|
232
|
+
// ---------------------------------------------------------------------------
|
|
233
|
+
|
|
234
|
+
describe('Tree: checkWorkspaceConfigTree', () => {
|
|
235
|
+
it('returns issue when nx.json missing', () => {
|
|
236
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
237
|
+
// createTreeWithEmptyWorkspace creates an nx.json, remove it
|
|
238
|
+
tree.delete('nx.json');
|
|
239
|
+
const issues = checkWorkspaceConfigTree(tree);
|
|
240
|
+
expect(issues).toHaveLength(1);
|
|
241
|
+
expect(issues[0].message).toBe('nx.json not found');
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('detects missing plugins', () => {
|
|
245
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
246
|
+
writeJson(tree, 'nx.json', {
|
|
247
|
+
plugins: [],
|
|
248
|
+
targetDefaults: { build: { cache: true, outputs: ['{projectRoot}/dist'] } },
|
|
249
|
+
namedInputs: validNamedInputs(),
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
const issues = checkWorkspaceConfigTree(tree);
|
|
253
|
+
expect(issues.length).toBe(2);
|
|
254
|
+
expect(issues.some((i) => i.message.includes('Official Nx owns TypeScript library inference'))).toBe(true);
|
|
255
|
+
expect(issues.some((i) => i.message.includes('plugins must include @smoothbricks/nx-plugin'))).toBe(true);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('returns no issues for valid config', () => {
|
|
259
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
260
|
+
writeJson(tree, 'nx.json', validNxJson());
|
|
261
|
+
|
|
262
|
+
expect(checkWorkspaceConfigTree(tree)).toEqual([]);
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
describe('Tree: applyWorkspaceConfigTree', () => {
|
|
267
|
+
it('returns false when nx.json missing', () => {
|
|
268
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
269
|
+
tree.delete('nx.json');
|
|
270
|
+
expect(applyWorkspaceConfigTree(tree)).toBe(false);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('fixes missing plugins and writes back to tree', () => {
|
|
274
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
275
|
+
writeJson(tree, 'nx.json', {
|
|
276
|
+
plugins: [],
|
|
277
|
+
targetDefaults: { build: { cache: true, outputs: ['{projectRoot}/dist'] } },
|
|
278
|
+
namedInputs: validNamedInputs(),
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
expect(applyWorkspaceConfigTree(tree)).toBe(true);
|
|
282
|
+
|
|
283
|
+
const nxJson = readJson(tree, 'nx.json');
|
|
284
|
+
const pluginNames = (nxJson.plugins as unknown[]).map((p: unknown) =>
|
|
285
|
+
typeof p === 'string' ? p : (p as Record<string, unknown>).plugin,
|
|
286
|
+
);
|
|
287
|
+
expect(pluginNames).toContain('@nx/js/typescript');
|
|
288
|
+
expect(pluginNames).toContain('@smoothbricks/nx-plugin');
|
|
289
|
+
|
|
290
|
+
// Tree version now passes check
|
|
291
|
+
expect(checkWorkspaceConfigTree(tree)).toEqual([]);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('returns false when config already valid', () => {
|
|
295
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
296
|
+
writeJson(tree, 'nx.json', validNxJson());
|
|
297
|
+
|
|
298
|
+
expect(applyWorkspaceConfigTree(tree)).toBe(false);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it('fixes build target defaults via tree', () => {
|
|
302
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
303
|
+
writeJson(tree, 'nx.json', {
|
|
304
|
+
plugins: validPlugins(),
|
|
305
|
+
targetDefaults: { build: { cache: false } },
|
|
306
|
+
namedInputs: validNamedInputs(),
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
expect(applyWorkspaceConfigTree(tree)).toBe(true);
|
|
310
|
+
|
|
311
|
+
const nxJson = readJson(tree, 'nx.json');
|
|
312
|
+
expect((nxJson.targetDefaults as Record<string, unknown>).build).toEqual({
|
|
313
|
+
cache: true,
|
|
314
|
+
outputs: ['{projectRoot}/dist'],
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
// ---------------------------------------------------------------------------
|
|
320
|
+
// Layer 3: Filesystem wrapper integration test
|
|
321
|
+
// ---------------------------------------------------------------------------
|
|
322
|
+
|
|
323
|
+
describe('filesystem: checkWorkspaceConfigPolicy / applyWorkspaceConfigPolicy', () => {
|
|
324
|
+
it('round-trips check/apply on real temp directory', async () => {
|
|
325
|
+
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-ws-policy-'));
|
|
326
|
+
try {
|
|
327
|
+
await writeJsonFile(join(root, 'nx.json'), {
|
|
328
|
+
plugins: [],
|
|
329
|
+
targetDefaults: { build: { cache: false } },
|
|
330
|
+
namedInputs: validNamedInputs(),
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
const issues = checkWorkspaceConfigPolicy(root);
|
|
334
|
+
expect(issues.length).toBeGreaterThan(0);
|
|
335
|
+
// Filesystem wrapper uses absolute paths
|
|
336
|
+
expect(issues[0].path).toBe(join(root, 'nx.json'));
|
|
337
|
+
|
|
338
|
+
expect(applyWorkspaceConfigPolicy(root)).toBe(true);
|
|
339
|
+
|
|
340
|
+
const nxJson = JSON.parse(await readFile(join(root, 'nx.json'), 'utf8'));
|
|
341
|
+
const pluginNames = (nxJson.plugins as unknown[]).map((p: unknown) =>
|
|
342
|
+
typeof p === 'string' ? p : (p as Record<string, unknown>).plugin,
|
|
343
|
+
);
|
|
344
|
+
expect(pluginNames).toContain('@nx/js/typescript');
|
|
345
|
+
expect(pluginNames).toContain('@smoothbricks/nx-plugin');
|
|
346
|
+
|
|
347
|
+
// No issues after fix
|
|
348
|
+
expect(checkWorkspaceConfigPolicy(root)).toEqual([]);
|
|
349
|
+
expect(applyWorkspaceConfigPolicy(root)).toBe(false);
|
|
350
|
+
} finally {
|
|
351
|
+
await rm(root, { recursive: true, force: true });
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it('reports issue when nx.json is missing', async () => {
|
|
356
|
+
const root = await mkdtemp(join(tmpdir(), 'smoothbricks-ws-policy-'));
|
|
357
|
+
try {
|
|
358
|
+
const issues = checkWorkspaceConfigPolicy(root);
|
|
359
|
+
expect(issues).toHaveLength(1);
|
|
360
|
+
expect(issues[0].message).toBe('nx.json not found or invalid');
|
|
361
|
+
|
|
362
|
+
expect(applyWorkspaceConfigPolicy(root)).toBe(false);
|
|
363
|
+
} finally {
|
|
364
|
+
await rm(root, { recursive: true, force: true });
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
// ---------------------------------------------------------------------------
|
|
370
|
+
// Test-local file helper (for filesystem integration tests only)
|
|
371
|
+
// ---------------------------------------------------------------------------
|
|
372
|
+
|
|
373
|
+
async function writeJsonFile(path: string, value: unknown): Promise<void> {
|
|
374
|
+
await mkdir(dirname(path), { recursive: true });
|
|
375
|
+
await writeFile(path, `${JSON.stringify(value, null, 2)}\n`);
|
|
376
|
+
}
|