@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/src/index.test.ts CHANGED
@@ -43,7 +43,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
43
43
  }
44
44
  });
45
45
 
46
- it('infers validation and aggregate build targets without owning TypeScript lib build', async () => {
46
+ it('overrides inferred TypeScript compiler commands with ttsc', async () => {
47
47
  const workspace = await createWorkspace();
48
48
  try {
49
49
  await workspace.write(
@@ -55,7 +55,32 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
55
55
 
56
56
  const targets = await inferProjectTargets(workspace, 'packages/example/package.json');
57
57
 
58
- expect(targets['tsc-js']).toBeUndefined();
58
+ expect(targets['tsc-js']?.options).toMatchObject({
59
+ command: 'ttsc -p tsconfig.lib.json --emit',
60
+ cwd: 'packages/example',
61
+ });
62
+ const toolchainInputs = [
63
+ '{workspaceRoot}/package.json',
64
+ '{workspaceRoot}/bun.lock',
65
+ '{workspaceRoot}/patches/**/*',
66
+ '{workspaceRoot}/tsconfig.base.json',
67
+ ];
68
+ expect(targets['tsc-js']?.inputs).toEqual([
69
+ 'production',
70
+ '^production',
71
+ ...toolchainInputs,
72
+ '{projectRoot}/tsconfig.lib.json',
73
+ ]);
74
+ expect(targets.typecheck?.options).toMatchObject({
75
+ command: 'ttsc -p tsconfig.lib.json --noEmit',
76
+ cwd: 'packages/example',
77
+ });
78
+ expect(targets.typecheck?.inputs).toEqual([
79
+ 'production',
80
+ '^production',
81
+ ...toolchainInputs,
82
+ '{projectRoot}/tsconfig.lib.json',
83
+ ]);
59
84
  expect(targets.build?.executor).toBe('nx:noop');
60
85
  expect(targets.build?.cache).toBe(true);
61
86
  expect(targets.build?.dependsOn).toEqual(buildOutputDependencies);
@@ -66,14 +91,20 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
66
91
  expect(targets['typecheck-tests']?.cache).toBe(true);
67
92
  expect(targets['typecheck-tests']?.dependsOn).toEqual(['typecheck']);
68
93
  expect(targets['typecheck-tests']?.options).toMatchObject({
69
- command: 'tsc --noEmit -p tsconfig.test.json',
94
+ command: 'ttsc -p tsconfig.test.json --noEmit',
70
95
  cwd: 'packages/example',
71
96
  });
97
+ expect(targets['typecheck-tests']?.inputs).toEqual([
98
+ 'default',
99
+ '^production',
100
+ ...toolchainInputs,
101
+ '{projectRoot}/tsconfig.test.json',
102
+ ]);
72
103
 
73
104
  expect(targets['typecheck-tests:watch']?.executor).toBe('nx:run-commands');
74
105
  expect(targets['typecheck-tests:watch']?.continuous).toBe(true);
75
106
  expect(targets['typecheck-tests:watch']?.options).toMatchObject({
76
- command: 'tsc --noEmit -p tsconfig.test.json --watch',
107
+ command: 'ttsc -p tsconfig.test.json --noEmit --watch',
77
108
  cwd: 'packages/example',
78
109
  });
79
110
 
@@ -85,7 +116,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
85
116
  cwd: 'packages/example',
86
117
  });
87
118
 
88
- expect(targets.lint?.executor).toBe('nx:noop');
119
+ expect(targets.lint?.executor).toBeUndefined();
89
120
  expect(targets.lint?.cache).toBe(true);
90
121
  expect(targets.lint?.dependsOn).toEqual(['typecheck-tests']);
91
122
  } finally {
package/src/index.ts CHANGED
@@ -11,6 +11,12 @@ const RESERVED_ZIG_STEPS = new Set(['all', 'clean', 'install', 'test']);
11
11
  const ZIG_STEP_PATTERN = /\bb\.step\(\s*["']([^"']+)["']\s*,/g;
12
12
  const VALID_ZIG_STEP_NAME = /^[A-Za-z0-9_-]+$/;
13
13
  const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|ios|android|native|napi|bun|wasm)$/;
14
+ const TYPESCRIPT_TOOLCHAIN_INPUTS = [
15
+ '{workspaceRoot}/package.json',
16
+ '{workspaceRoot}/bun.lock',
17
+ '{workspaceRoot}/patches/**/*',
18
+ '{workspaceRoot}/tsconfig.base.json',
19
+ ];
14
20
 
15
21
  // Cargo workspace inference: a package.json sitting next to a Cargo.toml that
16
22
  // declares [workspace] gets direct cargo-test/test targets, cargo-lint feeding
@@ -94,13 +100,45 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
94
100
  const hasLibTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.lib.json'));
95
101
  let hasBuildOutputTarget = hasLibTsconfig || hasPackageLocalBuildOutputTarget(packageJson);
96
102
 
103
+ if (hasLibTsconfig) {
104
+ // Official Nx target inference is disabled because its compiler surface only
105
+ // supports tsc/tsgo. Smoo owns the complete transformer-aware ttsc targets.
106
+ targets['tsc-js'] = {
107
+ executor: 'nx:run-commands',
108
+ cache: true,
109
+ inputs: ['production', '^production', ...TYPESCRIPT_TOOLCHAIN_INPUTS, '{projectRoot}/tsconfig.lib.json'],
110
+ outputs: [
111
+ '{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}',
112
+ '{projectRoot}/dist/.build.tsbuildinfo',
113
+ ],
114
+ dependsOn: ['^tsc-js'],
115
+ options: {
116
+ command: 'ttsc -p tsconfig.lib.json --emit',
117
+ cwd: projectRoot,
118
+ },
119
+ };
120
+ targets.typecheck = {
121
+ executor: 'nx:run-commands',
122
+ cache: true,
123
+ inputs: ['production', '^production', ...TYPESCRIPT_TOOLCHAIN_INPUTS, '{projectRoot}/tsconfig.lib.json'],
124
+ outputs: [],
125
+ dependsOn: ['^tsc-js'],
126
+ options: {
127
+ command: 'ttsc -p tsconfig.lib.json --noEmit',
128
+ cwd: projectRoot,
129
+ },
130
+ };
131
+ }
132
+
97
133
  const hasTestTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.test.json'));
98
134
  if (hasTestTsconfig) {
99
135
  targets['typecheck-tests'] = {
100
136
  executor: 'nx:run-commands',
101
137
  cache: true,
138
+ inputs: ['default', '^production', ...TYPESCRIPT_TOOLCHAIN_INPUTS, '{projectRoot}/tsconfig.test.json'],
139
+ dependsOn: ['typecheck'],
102
140
  options: {
103
- command: 'tsc --noEmit -p tsconfig.test.json',
141
+ command: 'ttsc -p tsconfig.test.json --noEmit',
104
142
  cwd: projectRoot,
105
143
  },
106
144
  };
@@ -108,7 +146,7 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
108
146
  executor: 'nx:run-commands',
109
147
  continuous: true,
110
148
  options: {
111
- command: 'tsc --noEmit -p tsconfig.test.json --watch',
149
+ command: 'ttsc -p tsconfig.test.json --noEmit --watch',
112
150
  cwd: projectRoot,
113
151
  },
114
152
  };
@@ -241,7 +279,6 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
241
279
 
242
280
  if (validationTargets.length > 0) {
243
281
  targets.lint = {
244
- executor: 'nx:noop',
245
282
  cache: true,
246
283
  dependsOn: validationTargets,
247
284
  };
@@ -260,7 +297,23 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
260
297
  }
261
298
 
262
299
  async function readPackageJson(packageJsonPath: string): Promise<PackageJson> {
263
- return JSON.parse(await readFile(packageJsonPath, 'utf-8')) as PackageJson;
300
+ const parsed: unknown = JSON.parse(await readFile(packageJsonPath, 'utf-8'));
301
+ if (!isRecord(parsed)) {
302
+ throw new Error(`${packageJsonPath} must contain a JSON object`);
303
+ }
304
+ const rawNx = isRecord(parsed.nx) ? parsed.nx : undefined;
305
+ return {
306
+ ...(typeof parsed.name === 'string' ? { name: parsed.name } : {}),
307
+ ...(isRecord(parsed.scripts) ? { scripts: parsed.scripts } : {}),
308
+ ...(rawNx
309
+ ? {
310
+ nx: {
311
+ ...(typeof rawNx.name === 'string' ? { name: rawNx.name } : {}),
312
+ ...(isRecord(rawNx.targets) ? { targets: rawNx.targets } : {}),
313
+ },
314
+ }
315
+ : {}),
316
+ };
264
317
  }
265
318
 
266
319
  function inferTestWatchCommand(packageJson: PackageJson): string | null {
@@ -542,7 +542,11 @@ describe('per-package applyPackageTargets', () => {
542
542
  };
543
543
  const workspaceNames = new Set(['@scope/lib', '@scope/other']);
544
544
  expect(applyPackageTargets(pkg, 'packages/lib', workspaceNames)).toBe(true);
545
- const targets = (pkg.nx as Record<string, unknown>).targets as Record<string, unknown>;
545
+ const nx = pkg.nx;
546
+ if (!isRecord(nx) || !isRecord(nx.targets)) {
547
+ throw new Error('expected generated Nx targets');
548
+ }
549
+ const targets = nx.targets;
546
550
  expect(targets['build:ts']).toBeUndefined();
547
551
  expect(targets['tsc-js']).toBeDefined();
548
552
  });
@@ -918,3 +922,7 @@ async function writeJson(path: string, value: unknown): Promise<void> {
918
922
  await mkdir(dirname(path), { recursive: true });
919
923
  await writeFile(path, `${JSON.stringify(value, null, 2)}\n`);
920
924
  }
925
+
926
+ function isRecord(value: unknown): value is Record<string, unknown> {
927
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
928
+ }
@@ -122,30 +122,30 @@ describe('pure core: applyReleaseConfig', () => {
122
122
  const nxJson: Record<string, unknown> = {};
123
123
  expect(applyReleaseConfig(nxJson)).toBe(true);
124
124
 
125
- const release = nxJson.release as Record<string, unknown>;
125
+ const release = expectRecord(nxJson.release);
126
126
  expect(release.projectsRelationship).toBe('independent');
127
- const version = release.version as Record<string, unknown>;
127
+ const version = expectRecord(release.version);
128
128
  expect(version.specifierSource).toBe('conventional-commits');
129
129
  expect(version.currentVersionResolver).toBe('git-tag');
130
130
  expect(version.fallbackCurrentVersionResolver).toBe('disk');
131
131
  expect(version.versionActions).toBe(SMOO_NX_VERSION_ACTIONS);
132
132
  expect(version.preVersionCommand).toBeUndefined();
133
- const releaseTag = release.releaseTag as Record<string, unknown>;
133
+ const releaseTag = expectRecord(release.releaseTag);
134
134
  expect(releaseTag.pattern).toBe(SMOO_NX_RELEASE_TAG_PATTERN);
135
- const changelog = release.changelog as Record<string, unknown>;
135
+ const changelog = expectRecord(release.changelog);
136
136
  expect(changelog.automaticFromRef).toBe(true);
137
137
  expect(changelog.workspaceChangelog).toBe(false);
138
- const projectChangelogs = changelog.projectChangelogs as Record<string, unknown>;
138
+ const projectChangelogs = expectRecord(changelog.projectChangelogs);
139
139
  expect(projectChangelogs.createRelease).toBe(false);
140
140
  expect(projectChangelogs.file).toBe(false);
141
- const renderOptions = projectChangelogs.renderOptions as Record<string, unknown>;
141
+ const renderOptions = expectRecord(projectChangelogs.renderOptions);
142
142
  expect(renderOptions.authors).toBe(true);
143
143
  expect(renderOptions.applyUsernameToAuthors).toBe(true);
144
144
  });
145
145
 
146
146
  it('removes preVersionCommand', () => {
147
147
  const nxJson = validReleaseNxJson();
148
- const version = (nxJson.release as Record<string, unknown>).version as Record<string, unknown>;
148
+ const version = expectRecord(expectRecord(nxJson.release).version);
149
149
  version.preVersionCommand = 'nx run-many -t build';
150
150
  expect(applyReleaseConfig(nxJson)).toBe(true);
151
151
  expect(version.preVersionCommand).toBeUndefined();
@@ -195,9 +195,9 @@ describe('Tree: applyReleaseConfigTree', () => {
195
195
  expect(applyReleaseConfigTree(tree)).toBe(true);
196
196
 
197
197
  const nxJson = readJson(tree, 'nx.json');
198
- const release = nxJson.release as Record<string, unknown>;
198
+ const release = expectRecord(nxJson.release);
199
199
  expect(release.projectsRelationship).toBe('independent');
200
- const version = release.version as Record<string, unknown>;
200
+ const version = expectRecord(release.version);
201
201
  expect(version.specifierSource).toBe('conventional-commits');
202
202
 
203
203
  // Tree version now passes check
@@ -214,14 +214,14 @@ describe('Tree: applyReleaseConfigTree', () => {
214
214
  it('removes preVersionCommand via tree', () => {
215
215
  const tree = createTreeWithEmptyWorkspace();
216
216
  const nxJson = validReleaseNxJson();
217
- const version = (nxJson.release as Record<string, unknown>).version as Record<string, unknown>;
217
+ const version = expectRecord(expectRecord(nxJson.release).version);
218
218
  version.preVersionCommand = 'nx run-many -t build';
219
219
  writeJson(tree, 'nx.json', nxJson);
220
220
 
221
221
  expect(applyReleaseConfigTree(tree)).toBe(true);
222
222
 
223
223
  const fixed = readJson(tree, 'nx.json');
224
- const fixedVersion = (fixed.release as Record<string, unknown>).version as Record<string, unknown>;
224
+ const fixedVersion = expectRecord(expectRecord(fixed.release).version);
225
225
  expect(fixedVersion.preVersionCommand).toBeUndefined();
226
226
 
227
227
  expect(checkReleaseConfigTree(tree)).toEqual([]);
@@ -281,3 +281,14 @@ async function writeJsonFile(path: string, value: unknown): Promise<void> {
281
281
  await mkdir(dirname(path), { recursive: true });
282
282
  await writeFile(path, `${JSON.stringify(value, null, 2)}\n`);
283
283
  }
284
+
285
+ function expectRecord(value: unknown): Record<string, unknown> {
286
+ if (!isRecord(value)) {
287
+ throw new Error('expected object');
288
+ }
289
+ return value;
290
+ }
291
+
292
+ function isRecord(value: unknown): value is Record<string, unknown> {
293
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
294
+ }
@@ -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]!.message).toContain('noEmit must be true');
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]!.message).toContain('composite');
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]!.message).toContain('declaration = true');
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]!.message).toContain('declarationMap');
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]!.message).toContain('dist-test');
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]!.message).toContain('dist-test');
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]!.path).toContain('packages/mylib');
151
- expect(issues[0]!.path).toContain('tsconfig.test.json');
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]!.message).toContain('must not reference ./tsconfig.test.json');
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 as Record<string, unknown>;
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 as string[];
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 as Array<{ path: string }>;
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 as Record<string, unknown>;
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 as Record<string, unknown>;
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 as Record<string, unknown>;
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 as Record<string, unknown>;
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 as string[];
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 as Array<{ path: string }>;
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 as Array<{ path: string }>;
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 as Array<{ path: string }>;
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]!.message).toContain('bun test');
506
- expect(issues[0]!.message).toContain('tsconfig.test.json');
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'))) as Record<string, unknown>;
512
- const compilerOptions = tsconfig.compilerOptions as Record<string, unknown>;
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 as string[];
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'))) as Record<string, unknown>;
549
- const compilerOptions = tsconfig.compilerOptions as Record<string, unknown>;
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]!.message).toContain('bun test');
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'))) as Record<string, unknown>;
582
- const compilerOptions = tsconfig.compilerOptions as Record<string, unknown>;
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'))) as Record<string, unknown>;
654
- const references = tsconfig.references as Array<{ path: string }>;
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'))) as Record<string, unknown>;
683
- const compilerOptions = tsconfig.compilerOptions as Record<string, unknown>;
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 as Array<{ path: string }>;
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'))) as Record<string, unknown>;
724
- const references = tsconfig.references as Array<{ path: string }>;
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]!.message).toContain('bun test');
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 (!compilerOptions || compilerOptions.noEmit !== true) {
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 (Object.hasOwn(options.libCompilerOptions, key) && compilerOptions[key] !== options.libCompilerOptions[key]) {
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
  }
@@ -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 json = JSON.parse(readFileSync(packageJsonPath, 'utf8')) as Record<string, unknown>;
102
- if (typeof json.name !== 'string' || typeof json.version !== 'string') return null;
103
- const nx = json.nx != null && typeof json.nx === 'object' ? (json.nx as Record<string, unknown>) : null;
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
  }