@smoothbricks/nx-plugin 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +44 -3
- package/dist/generators/create-package/generator.js +29 -2
- package/dist/generators/make-public/generator.js +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +83 -22
- package/dist/package-target-policy.d.ts +3 -2
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +63 -20
- package/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +4 -2
- package/dist/version-actions.cjs +8 -3
- package/dist/version-actions.d.cts.map +1 -1
- package/dist/workspace-config-policy.d.ts +4 -1
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +11 -35
- package/package.json +3 -3
- package/src/bounded-test-policy.ts +46 -3
- package/src/generators/create-package/generator.ts +37 -9
- package/src/generators/make-public/generator.ts +5 -1
- package/src/index.test.ts +70 -18
- package/src/index.ts +87 -23
- package/src/package-target-policy.test.ts +71 -1
- package/src/package-target-policy.ts +85 -23
- package/src/release-config-policy.test.ts +22 -11
- package/src/typecheck-test-policy.test.ts +85 -38
- package/src/typecheck-test-policy.ts +6 -2
- package/src/version-actions.cts +12 -5
- package/src/workspace-config-policy.test.ts +60 -57
- package/src/workspace-config-policy.ts +16 -42
|
@@ -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
|
|
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
|
});
|
|
@@ -704,6 +708,68 @@ describe('checkPackageTargetPolicyTree', () => {
|
|
|
704
708
|
expect(buildIssues).toEqual([]);
|
|
705
709
|
});
|
|
706
710
|
|
|
711
|
+
it('accepts platform-only target families without an ordinary build aggregate', () => {
|
|
712
|
+
addProject(tree, 'native', 'packages/native');
|
|
713
|
+
writeJsonFile(tree, 'packages/native/package.json', {
|
|
714
|
+
name: '@scope/native',
|
|
715
|
+
nx: { name: 'native' },
|
|
716
|
+
});
|
|
717
|
+
const resolvedTargetsByProject = new Map<string, ResolvedProjectTargets>([
|
|
718
|
+
[
|
|
719
|
+
'native',
|
|
720
|
+
{
|
|
721
|
+
targets: new Set(['bundle-ios', 'prepare-macos', 'bundle-linux']),
|
|
722
|
+
targetDependencies: new Map([
|
|
723
|
+
['bundle-ios', ['prepare-macos', '^build']],
|
|
724
|
+
['prepare-macos', []],
|
|
725
|
+
['bundle-linux', ['^build']],
|
|
726
|
+
]),
|
|
727
|
+
},
|
|
728
|
+
],
|
|
729
|
+
]);
|
|
730
|
+
|
|
731
|
+
expect(checkPackageTargetPolicyTree(tree, { resolvedTargetsByProject })).toEqual([]);
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
it('rejects cross-family dependencies in resolved platform target closures', () => {
|
|
735
|
+
addProject(tree, 'native', 'packages/native');
|
|
736
|
+
writeJsonFile(tree, 'packages/native/package.json', {
|
|
737
|
+
name: '@scope/native',
|
|
738
|
+
nx: { name: 'native' },
|
|
739
|
+
});
|
|
740
|
+
const resolvedTargetsByProject = new Map<string, ResolvedProjectTargets>([
|
|
741
|
+
[
|
|
742
|
+
'native',
|
|
743
|
+
{
|
|
744
|
+
targets: new Set(['bundle-ios', 'prepare-macos', 'compile-js', 'bundle-linux']),
|
|
745
|
+
targetDependencies: new Map([
|
|
746
|
+
['bundle-ios', ['prepare-macos', '^build']],
|
|
747
|
+
['prepare-macos', ['compile-js']],
|
|
748
|
+
['bundle-linux', ['bundle-ios']],
|
|
749
|
+
]),
|
|
750
|
+
},
|
|
751
|
+
],
|
|
752
|
+
]);
|
|
753
|
+
|
|
754
|
+
const issues = checkPackageTargetPolicyTree(tree, { resolvedTargetsByProject });
|
|
755
|
+
|
|
756
|
+
expect(
|
|
757
|
+
issues.some(
|
|
758
|
+
(issue) =>
|
|
759
|
+
issue.message.includes('platform target bundle-ios dependency closure') &&
|
|
760
|
+
issue.message.includes('non-macos sibling target compile-js'),
|
|
761
|
+
),
|
|
762
|
+
).toBe(true);
|
|
763
|
+
expect(
|
|
764
|
+
issues.some(
|
|
765
|
+
(issue) =>
|
|
766
|
+
issue.message.includes('platform target bundle-linux dependency closure') &&
|
|
767
|
+
issue.message.includes('non-linux sibling target bundle-ios'),
|
|
768
|
+
),
|
|
769
|
+
).toBe(true);
|
|
770
|
+
expect(issues.some((issue) => issue.message.includes('non-macos sibling target prepare-macos'))).toBe(false);
|
|
771
|
+
});
|
|
772
|
+
|
|
707
773
|
it('rejects recursive script commands', () => {
|
|
708
774
|
addProject(tree, 'app', 'packages/app');
|
|
709
775
|
addProject(tree, 'lib', 'packages/lib');
|
|
@@ -918,3 +984,7 @@ async function writeJson(path: string, value: unknown): Promise<void> {
|
|
|
918
984
|
await mkdir(dirname(path), { recursive: true });
|
|
919
985
|
await writeFile(path, `${JSON.stringify(value, null, 2)}\n`);
|
|
920
986
|
}
|
|
987
|
+
|
|
988
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
989
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
990
|
+
}
|
|
@@ -4,13 +4,20 @@ import { join } from 'node:path';
|
|
|
4
4
|
import { getProjects, readJson, type Tree, updateJson } from 'nx/src/devkit-exports.js';
|
|
5
5
|
|
|
6
6
|
import { boundedTestScriptAlias } from './bounded-test-policy.js';
|
|
7
|
-
import
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
BUILD_OUTPUT_DEPENDENCIES,
|
|
9
|
+
LINUX_PLATFORM_TARGET_GLOBS,
|
|
10
|
+
MACOS_PLATFORM_TARGET_GLOBS,
|
|
11
|
+
type NxPolicyIssue,
|
|
12
|
+
} from './workspace-config-policy.js';
|
|
13
|
+
|
|
14
|
+
export { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
9
15
|
export type { NxPolicyIssue };
|
|
10
16
|
|
|
11
17
|
export interface ResolvedProjectTargets {
|
|
12
18
|
targets: ReadonlySet<string>;
|
|
13
19
|
buildDependsOn?: readonly string[];
|
|
20
|
+
targetDependencies?: ReadonlyMap<string, readonly string[]>;
|
|
14
21
|
targetExecutors?: ReadonlyMap<string, string>;
|
|
15
22
|
targetScripts?: ReadonlyMap<string, string>;
|
|
16
23
|
}
|
|
@@ -19,19 +26,6 @@ export interface PackageTargetPolicyOptions {
|
|
|
19
26
|
resolvedTargetsByProject?: ReadonlyMap<string, ReadonlySet<string> | ResolvedProjectTargets>;
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
export const BUILD_OUTPUT_DEPENDENCIES = [
|
|
23
|
-
'*-js',
|
|
24
|
-
'*-web',
|
|
25
|
-
'*-html',
|
|
26
|
-
'*-css',
|
|
27
|
-
'*-ios',
|
|
28
|
-
'*-android',
|
|
29
|
-
'*-native',
|
|
30
|
-
'*-napi',
|
|
31
|
-
'*-bun',
|
|
32
|
-
'*-wasm',
|
|
33
|
-
];
|
|
34
|
-
|
|
35
29
|
const workspaceDependencyFields = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
|
|
36
30
|
|
|
37
31
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
@@ -230,7 +224,7 @@ function targetExistsInResolvedProject(
|
|
|
230
224
|
}
|
|
231
225
|
|
|
232
226
|
function isBuildOutputDependencyPattern(dependency: string): boolean {
|
|
233
|
-
return BUILD_OUTPUT_DEPENDENCIES.
|
|
227
|
+
return BUILD_OUTPUT_DEPENDENCIES.some((pattern) => pattern === dependency);
|
|
234
228
|
}
|
|
235
229
|
|
|
236
230
|
function expectedTargetDependencies(targetName: string): string[] {
|
|
@@ -606,14 +600,14 @@ function validateBuildZigPolicy(root: string, packagePath: string): NxPolicyIssu
|
|
|
606
600
|
function validateExplicitNxTargets(
|
|
607
601
|
pkg: Record<string, unknown>,
|
|
608
602
|
packagePath: string,
|
|
609
|
-
|
|
603
|
+
resolvedProject?: ReadonlySet<string> | ResolvedProjectTargets,
|
|
610
604
|
): NxPolicyIssue[] {
|
|
605
|
+
const issues = validatePlatformTargetDependencies(packagePath, resolvedProject);
|
|
611
606
|
const nx = recordProperty(pkg, 'nx');
|
|
612
607
|
const targets = nx ? recordProperty(nx, 'targets') : null;
|
|
613
608
|
if (!targets) {
|
|
614
|
-
return
|
|
609
|
+
return issues;
|
|
615
610
|
}
|
|
616
|
-
const issues: NxPolicyIssue[] = [];
|
|
617
611
|
for (const [targetName, rawTarget] of Object.entries(targets)) {
|
|
618
612
|
if (targetName.includes(':')) {
|
|
619
613
|
issues.push({
|
|
@@ -626,7 +620,76 @@ function validateExplicitNxTargets(
|
|
|
626
620
|
if (!isRecord(rawTarget)) {
|
|
627
621
|
continue;
|
|
628
622
|
}
|
|
629
|
-
issues.push(
|
|
623
|
+
issues.push(
|
|
624
|
+
...validateTargetDependencies(
|
|
625
|
+
rawTarget,
|
|
626
|
+
`${packagePath}: nx.targets.${targetName}`,
|
|
627
|
+
resolvedProjectTargetNames(resolvedProject),
|
|
628
|
+
),
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
return issues;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
type PlatformTargetFamily = 'macos' | 'linux';
|
|
635
|
+
|
|
636
|
+
function platformTargetFamily(targetName: string): PlatformTargetFamily | null {
|
|
637
|
+
if (MACOS_PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1)))) {
|
|
638
|
+
return 'macos';
|
|
639
|
+
}
|
|
640
|
+
if (LINUX_PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1)))) {
|
|
641
|
+
return 'linux';
|
|
642
|
+
}
|
|
643
|
+
return null;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
function matchingResolvedTargets(dependency: string, targets: ReadonlySet<string>): string[] {
|
|
647
|
+
if (!dependency.startsWith('*')) {
|
|
648
|
+
return targets.has(dependency) ? [dependency] : [];
|
|
649
|
+
}
|
|
650
|
+
const suffix = dependency.slice(1);
|
|
651
|
+
return [...targets].filter((targetName) => targetName.endsWith(suffix));
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
function validatePlatformTargetDependencies(
|
|
655
|
+
packagePath: string,
|
|
656
|
+
resolvedProject?: ReadonlySet<string> | ResolvedProjectTargets,
|
|
657
|
+
): NxPolicyIssue[] {
|
|
658
|
+
if (!isResolvedProjectTargets(resolvedProject) || !resolvedProject.targetDependencies) {
|
|
659
|
+
return [];
|
|
660
|
+
}
|
|
661
|
+
const issues: NxPolicyIssue[] = [];
|
|
662
|
+
for (const platformTarget of resolvedProject.targets) {
|
|
663
|
+
const family = platformTargetFamily(platformTarget);
|
|
664
|
+
if (!family) {
|
|
665
|
+
continue;
|
|
666
|
+
}
|
|
667
|
+
const visited = new Set<string>();
|
|
668
|
+
const pending = [platformTarget];
|
|
669
|
+
while (pending.length > 0) {
|
|
670
|
+
const targetName = pending.pop();
|
|
671
|
+
if (!targetName || visited.has(targetName)) {
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
visited.add(targetName);
|
|
675
|
+
for (const dependency of resolvedProject.targetDependencies.get(targetName) ?? []) {
|
|
676
|
+
if (dependency.startsWith('^')) {
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
for (const resolvedDependency of matchingResolvedTargets(dependency, resolvedProject.targets)) {
|
|
680
|
+
if (platformTargetFamily(resolvedDependency) !== family) {
|
|
681
|
+
issues.push({
|
|
682
|
+
path: packagePath,
|
|
683
|
+
message:
|
|
684
|
+
`${packagePath}: platform target ${platformTarget} dependency closure references ` +
|
|
685
|
+
`non-${family} sibling target ${resolvedDependency} via ${targetName}`,
|
|
686
|
+
});
|
|
687
|
+
continue;
|
|
688
|
+
}
|
|
689
|
+
pending.push(resolvedDependency);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
630
693
|
}
|
|
631
694
|
return issues;
|
|
632
695
|
}
|
|
@@ -933,7 +996,7 @@ export function checkPackageTargetPolicyTree(tree: Tree, options: PackageTargetP
|
|
|
933
996
|
const resolvedProject = options.resolvedTargetsByProject?.get(projectName);
|
|
934
997
|
const resolvedTargets = resolvedProjectTargetNames(resolvedProject);
|
|
935
998
|
|
|
936
|
-
issues.push(...validateExplicitNxTargets(pkg, packagePath,
|
|
999
|
+
issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject));
|
|
937
1000
|
issues.push(...validateTestEntrypointPresenceTree(tree, packagePath, pkg));
|
|
938
1001
|
issues.push(...validateBuildZigPolicyTree(tree, packagePath));
|
|
939
1002
|
issues.push(...validatePackageScriptPolicy(pkg, packagePath, workspaceNames, { resolvedTargets }));
|
|
@@ -1156,9 +1219,8 @@ export function checkPackageTargetPolicy(root: string, options: PackageTargetPol
|
|
|
1156
1219
|
const packagePath = packagePathFromJsonPath(root, packageJsonPath);
|
|
1157
1220
|
const projectName = packageNxProjectName(pkg);
|
|
1158
1221
|
const resolvedProject = projectName ? options.resolvedTargetsByProject?.get(projectName) : undefined;
|
|
1159
|
-
const resolvedTargets = resolvedProjectTargetNames(resolvedProject);
|
|
1160
1222
|
|
|
1161
|
-
issues.push(...validateExplicitNxTargets(pkg, packagePath,
|
|
1223
|
+
issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject));
|
|
1162
1224
|
issues.push(...validateTestEntrypointPresence(root, packagePath, pkg));
|
|
1163
1225
|
issues.push(...validateBuildZigPolicy(root, packagePath));
|
|
1164
1226
|
issues.push(...validatePackageScriptPolicy(pkg, packagePath, workspaceNames, { resolvedTargets: resolvedProject }));
|
|
@@ -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
|
|
125
|
+
const release = expectRecord(nxJson.release);
|
|
126
126
|
expect(release.projectsRelationship).toBe('independent');
|
|
127
|
-
const version = release.version
|
|
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
|
|
133
|
+
const releaseTag = expectRecord(release.releaseTag);
|
|
134
134
|
expect(releaseTag.pattern).toBe(SMOO_NX_RELEASE_TAG_PATTERN);
|
|
135
|
-
const changelog = release.changelog
|
|
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
|
|
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
|
|
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
|
|
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
|
|
198
|
+
const release = expectRecord(nxJson.release);
|
|
199
199
|
expect(release.projectsRelationship).toBe('independent');
|
|
200
|
-
const version = release.version
|
|
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
|
|
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
|
|
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]
|
|
104
|
+
expect(issues[0]?.message).toContain('noEmit must be true');
|
|
105
105
|
});
|
|
106
106
|
|
|
107
107
|
it('reports composite = true', () => {
|
|
108
108
|
const issues = checkTypecheckTestConfig({ compilerOptions: { noEmit: true, composite: true } }, 'packages/app');
|
|
109
109
|
expect(issues.length).toBe(1);
|
|
110
|
-
expect(issues[0]
|
|
110
|
+
expect(issues[0]?.message).toContain('composite');
|
|
111
111
|
});
|
|
112
112
|
|
|
113
113
|
it('reports declaration = true', () => {
|
|
114
114
|
const issues = checkTypecheckTestConfig({ compilerOptions: { noEmit: true, declaration: true } }, 'packages/app');
|
|
115
115
|
expect(issues.length).toBe(1);
|
|
116
|
-
expect(issues[0]
|
|
116
|
+
expect(issues[0]?.message).toContain('declaration = true');
|
|
117
117
|
});
|
|
118
118
|
|
|
119
119
|
it('reports declarationMap = true', () => {
|
|
@@ -122,13 +122,13 @@ describe('checkTypecheckTestConfig', () => {
|
|
|
122
122
|
'packages/app',
|
|
123
123
|
);
|
|
124
124
|
expect(issues.length).toBe(1);
|
|
125
|
-
expect(issues[0]
|
|
125
|
+
expect(issues[0]?.message).toContain('declarationMap');
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
it('reports dist-test outDir', () => {
|
|
129
129
|
const issues = checkTypecheckTestConfig({ compilerOptions: { noEmit: true, outDir: 'dist-test' } }, 'packages/app');
|
|
130
130
|
expect(issues.length).toBe(1);
|
|
131
|
-
expect(issues[0]
|
|
131
|
+
expect(issues[0]?.message).toContain('dist-test');
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
it('reports dist-test tsBuildInfoFile', () => {
|
|
@@ -137,7 +137,7 @@ describe('checkTypecheckTestConfig', () => {
|
|
|
137
137
|
'packages/app',
|
|
138
138
|
);
|
|
139
139
|
expect(issues.length).toBe(1);
|
|
140
|
-
expect(issues[0]
|
|
140
|
+
expect(issues[0]?.message).toContain('dist-test');
|
|
141
141
|
});
|
|
142
142
|
|
|
143
143
|
it('returns empty for null input', () => {
|
|
@@ -147,8 +147,8 @@ describe('checkTypecheckTestConfig', () => {
|
|
|
147
147
|
|
|
148
148
|
it('uses packagePath in issue path', () => {
|
|
149
149
|
const issues = checkTypecheckTestConfig({ compilerOptions: {} }, 'packages/mylib');
|
|
150
|
-
expect(issues[0]
|
|
151
|
-
expect(issues[0]
|
|
150
|
+
expect(issues[0]?.path).toContain('packages/mylib');
|
|
151
|
+
expect(issues[0]?.path).toContain('tsconfig.test.json');
|
|
152
152
|
});
|
|
153
153
|
});
|
|
154
154
|
|
|
@@ -164,7 +164,7 @@ describe('checkTsconfigTestReference', () => {
|
|
|
164
164
|
'packages/app',
|
|
165
165
|
);
|
|
166
166
|
expect(issues.length).toBe(1);
|
|
167
|
-
expect(issues[0]
|
|
167
|
+
expect(issues[0]?.message).toContain('must not reference ./tsconfig.test.json');
|
|
168
168
|
});
|
|
169
169
|
|
|
170
170
|
it('returns empty for null input', () => {
|
|
@@ -183,7 +183,7 @@ describe('applyTypecheckTestDefaults', () => {
|
|
|
183
183
|
expect(changed).toBe(true);
|
|
184
184
|
expect(tsconfigTest.extends).toBe('../../tsconfig.base.json');
|
|
185
185
|
|
|
186
|
-
const compilerOptions = tsconfigTest.compilerOptions
|
|
186
|
+
const compilerOptions = expectRecord(tsconfigTest.compilerOptions);
|
|
187
187
|
expect(compilerOptions.noEmit).toBe(true);
|
|
188
188
|
expect(compilerOptions.composite).toBe(false);
|
|
189
189
|
expect(compilerOptions.declaration).toBe(false);
|
|
@@ -191,11 +191,11 @@ describe('applyTypecheckTestDefaults', () => {
|
|
|
191
191
|
expect(compilerOptions.emitDeclarationOnly).toBe(false);
|
|
192
192
|
expect(compilerOptions.types).toContain('bun');
|
|
193
193
|
|
|
194
|
-
const include = tsconfigTest.include
|
|
194
|
+
const include = expectStringArray(tsconfigTest.include);
|
|
195
195
|
expect(include).toContain('src/**/*.test.ts');
|
|
196
196
|
expect(include).toContain('src/**/*.spec.ts');
|
|
197
197
|
|
|
198
|
-
const references = tsconfigTest.references
|
|
198
|
+
const references = expectReferences(tsconfigTest.references);
|
|
199
199
|
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
200
200
|
});
|
|
201
201
|
|
|
@@ -216,7 +216,7 @@ describe('applyTypecheckTestDefaults', () => {
|
|
|
216
216
|
libCompilerOptions: { baseUrl: '.', module: 'esnext', jsx: 'react-jsx' },
|
|
217
217
|
referencePaths: [],
|
|
218
218
|
});
|
|
219
|
-
const compilerOptions = tsconfigTest.compilerOptions
|
|
219
|
+
const compilerOptions = expectRecord(tsconfigTest.compilerOptions);
|
|
220
220
|
expect(compilerOptions.baseUrl).toBe('.');
|
|
221
221
|
expect(compilerOptions.module).toBe('esnext');
|
|
222
222
|
expect(compilerOptions.jsx).toBe('react-jsx');
|
|
@@ -228,7 +228,7 @@ describe('applyTypecheckTestDefaults', () => {
|
|
|
228
228
|
testRunners: new Set(['vitest'] as const),
|
|
229
229
|
referencePaths: [],
|
|
230
230
|
});
|
|
231
|
-
const compilerOptions = tsconfigTest.compilerOptions
|
|
231
|
+
const compilerOptions = expectRecord(tsconfigTest.compilerOptions);
|
|
232
232
|
expect(compilerOptions.types).toBeUndefined();
|
|
233
233
|
});
|
|
234
234
|
|
|
@@ -241,7 +241,7 @@ describe('applyTypecheckTestDefaults', () => {
|
|
|
241
241
|
referencePaths: [],
|
|
242
242
|
});
|
|
243
243
|
expect(changed).toBe(true);
|
|
244
|
-
const compilerOptions = tsconfigTest.compilerOptions
|
|
244
|
+
const compilerOptions = expectRecord(tsconfigTest.compilerOptions);
|
|
245
245
|
expect('outDir' in compilerOptions).toBe(false);
|
|
246
246
|
expect('tsBuildInfoFile' in compilerOptions).toBe(false);
|
|
247
247
|
});
|
|
@@ -250,6 +250,7 @@ describe('applyTypecheckTestDefaults', () => {
|
|
|
250
250
|
const tsconfigTest: Record<string, unknown> = {};
|
|
251
251
|
const opts = {
|
|
252
252
|
testRunners: new Set(['bun'] as const),
|
|
253
|
+
libCompilerOptions: { lib: ['es2024', 'webworker'] },
|
|
253
254
|
referencePaths: ['./tsconfig.lib.json'],
|
|
254
255
|
};
|
|
255
256
|
applyTypecheckTestDefaults(tsconfigTest, opts);
|
|
@@ -304,18 +305,18 @@ describe('typecheck test policy (Tree)', () => {
|
|
|
304
305
|
expect(changed).toBe(true);
|
|
305
306
|
|
|
306
307
|
const tsconfig = readJson<Record<string, unknown>>(tree, 'packages/app/tsconfig.test.json');
|
|
307
|
-
const compilerOptions = tsconfig.compilerOptions
|
|
308
|
+
const compilerOptions = expectRecord(tsconfig.compilerOptions);
|
|
308
309
|
expect(compilerOptions.noEmit).toBe(true);
|
|
309
310
|
expect(compilerOptions.composite).toBe(false);
|
|
310
311
|
expect(compilerOptions.types).toContain('bun');
|
|
311
312
|
expect(compilerOptions.baseUrl).toBe('.');
|
|
312
313
|
expect(tsconfig.extends).toBe('../../tsconfig.base.json');
|
|
313
314
|
|
|
314
|
-
const include = tsconfig.include
|
|
315
|
+
const include = expectStringArray(tsconfig.include);
|
|
315
316
|
expect(include).toContain('src/**/*.test.ts');
|
|
316
317
|
expect(include).toContain('src/**/*.spec.ts');
|
|
317
318
|
|
|
318
|
-
const references = tsconfig.references
|
|
319
|
+
const references = expectReferences(tsconfig.references);
|
|
319
320
|
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
320
321
|
});
|
|
321
322
|
|
|
@@ -422,7 +423,7 @@ describe('typecheck test policy (Tree)', () => {
|
|
|
422
423
|
expect(changed).toBe(true);
|
|
423
424
|
|
|
424
425
|
const tsconfig = readJson<Record<string, unknown>>(tree, 'packages/app/tsconfig.json');
|
|
425
|
-
const references = tsconfig.references
|
|
426
|
+
const references = expectReferences(tsconfig.references);
|
|
426
427
|
expect(references).toEqual([{ path: './tsconfig.lib.json' }]);
|
|
427
428
|
});
|
|
428
429
|
|
|
@@ -479,7 +480,7 @@ describe('typecheck test policy (Tree)', () => {
|
|
|
479
480
|
expect(applyTypecheckTestPolicyTree(tree)).toBe(true);
|
|
480
481
|
|
|
481
482
|
const tsconfig = readJson<Record<string, unknown>>(tree, 'packages/app/tsconfig.test.json');
|
|
482
|
-
const references = tsconfig.references
|
|
483
|
+
const references = expectReferences(tsconfig.references);
|
|
483
484
|
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
484
485
|
expect(references).toContainEqual({ path: '../lib/tsconfig.lib.json' });
|
|
485
486
|
});
|
|
@@ -502,14 +503,14 @@ describe('typecheck test policy', () => {
|
|
|
502
503
|
// check should report missing tsconfig.test.json
|
|
503
504
|
const issues = checkTypecheckTestPolicy(root);
|
|
504
505
|
expect(issues.length).toBe(1);
|
|
505
|
-
expect(issues[0]
|
|
506
|
-
expect(issues[0]
|
|
506
|
+
expect(issues[0]?.message).toContain('bun test');
|
|
507
|
+
expect(issues[0]?.message).toContain('tsconfig.test.json');
|
|
507
508
|
|
|
508
509
|
// apply should create it
|
|
509
510
|
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
510
511
|
|
|
511
|
-
const tsconfig = (await readJsonFs(join(root, 'packages/app/tsconfig.test.json')))
|
|
512
|
-
const compilerOptions = tsconfig.compilerOptions
|
|
512
|
+
const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/app/tsconfig.test.json')));
|
|
513
|
+
const compilerOptions = expectRecord(tsconfig.compilerOptions);
|
|
513
514
|
expect(compilerOptions.noEmit).toBe(true);
|
|
514
515
|
expect(compilerOptions.composite).toBe(false);
|
|
515
516
|
expect(compilerOptions.declaration).toBe(false);
|
|
@@ -518,7 +519,7 @@ describe('typecheck test policy', () => {
|
|
|
518
519
|
expect(compilerOptions.types).toContain('bun');
|
|
519
520
|
expect(tsconfig.extends).toBe('../../tsconfig.base.json');
|
|
520
521
|
|
|
521
|
-
const include = tsconfig.include
|
|
522
|
+
const include = expectStringArray(tsconfig.include);
|
|
522
523
|
expect(include).toContain('src/**/*.test.ts');
|
|
523
524
|
expect(include).toContain('src/**/*.spec.ts');
|
|
524
525
|
expect(include).toContain('src/**/__tests__/**/*.ts');
|
|
@@ -545,8 +546,8 @@ describe('typecheck test policy', () => {
|
|
|
545
546
|
|
|
546
547
|
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
547
548
|
|
|
548
|
-
const tsconfig = (await readJsonFs(join(root, 'packages/web/tsconfig.test.json')))
|
|
549
|
-
const compilerOptions = tsconfig.compilerOptions
|
|
549
|
+
const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/web/tsconfig.test.json')));
|
|
550
|
+
const compilerOptions = expectRecord(tsconfig.compilerOptions);
|
|
550
551
|
expect(compilerOptions.noEmit).toBe(true);
|
|
551
552
|
// vitest should NOT add bun types
|
|
552
553
|
expect(compilerOptions.types).toBeUndefined();
|
|
@@ -574,12 +575,12 @@ describe('typecheck test policy', () => {
|
|
|
574
575
|
|
|
575
576
|
const issues = checkTypecheckTestPolicy(root);
|
|
576
577
|
expect(issues.length).toBe(1);
|
|
577
|
-
expect(issues[0]
|
|
578
|
+
expect(issues[0]?.message).toContain('bun test');
|
|
578
579
|
|
|
579
580
|
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
580
581
|
|
|
581
|
-
const tsconfig = (await readJsonFs(join(root, 'packages/lib/tsconfig.test.json')))
|
|
582
|
-
const compilerOptions = tsconfig.compilerOptions
|
|
582
|
+
const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/lib/tsconfig.test.json')));
|
|
583
|
+
const compilerOptions = expectRecord(tsconfig.compilerOptions);
|
|
583
584
|
expect(compilerOptions.noEmit).toBe(true);
|
|
584
585
|
expect(compilerOptions.types).toContain('bun');
|
|
585
586
|
} finally {
|
|
@@ -650,8 +651,8 @@ describe('typecheck test policy', () => {
|
|
|
650
651
|
// apply should remove it
|
|
651
652
|
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
652
653
|
|
|
653
|
-
const tsconfig = (await readJsonFs(join(root, 'packages/app/tsconfig.json')))
|
|
654
|
-
const references = tsconfig.references
|
|
654
|
+
const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/app/tsconfig.json')));
|
|
655
|
+
const references = expectReferences(tsconfig.references);
|
|
655
656
|
expect(references).toEqual([{ path: './tsconfig.lib.json' }]);
|
|
656
657
|
} finally {
|
|
657
658
|
await rm(root, { recursive: true, force: true });
|
|
@@ -679,8 +680,8 @@ describe('typecheck test policy', () => {
|
|
|
679
680
|
|
|
680
681
|
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
681
682
|
|
|
682
|
-
const tsconfig = (await readJsonFs(join(root, 'packages/app/tsconfig.test.json')))
|
|
683
|
-
const compilerOptions = tsconfig.compilerOptions
|
|
683
|
+
const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/app/tsconfig.test.json')));
|
|
684
|
+
const compilerOptions = expectRecord(tsconfig.compilerOptions);
|
|
684
685
|
expect(compilerOptions.baseUrl).toBe('.');
|
|
685
686
|
expect(compilerOptions.module).toBe('esnext');
|
|
686
687
|
expect(compilerOptions.moduleResolution).toBe('bundler');
|
|
@@ -690,7 +691,7 @@ describe('typecheck test policy', () => {
|
|
|
690
691
|
expect(tsconfig.extends).toBe('../../tsconfig.base.json');
|
|
691
692
|
|
|
692
693
|
// references should include ./tsconfig.lib.json
|
|
693
|
-
const references = tsconfig.references
|
|
694
|
+
const references = expectReferences(tsconfig.references);
|
|
694
695
|
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
695
696
|
} finally {
|
|
696
697
|
await rm(root, { recursive: true, force: true });
|
|
@@ -720,8 +721,8 @@ describe('typecheck test policy', () => {
|
|
|
720
721
|
|
|
721
722
|
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
722
723
|
|
|
723
|
-
const tsconfig = (await readJsonFs(join(root, 'packages/app/tsconfig.test.json')))
|
|
724
|
-
const references = tsconfig.references
|
|
724
|
+
const tsconfig = expectRecord(await readJsonFs(join(root, 'packages/app/tsconfig.test.json')));
|
|
725
|
+
const references = expectReferences(tsconfig.references);
|
|
725
726
|
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
726
727
|
expect(references).toContainEqual({ path: '../lib/tsconfig.lib.json' });
|
|
727
728
|
} finally {
|
|
@@ -789,9 +790,55 @@ describe('typecheck test policy', () => {
|
|
|
789
790
|
|
|
790
791
|
const issues = checkTypecheckTestPolicy(root);
|
|
791
792
|
expect(issues.length).toBe(1);
|
|
792
|
-
expect(issues[0]
|
|
793
|
+
expect(issues[0]?.message).toContain('bun test');
|
|
793
794
|
} finally {
|
|
794
795
|
await rm(root, { recursive: true, force: true });
|
|
795
796
|
}
|
|
796
797
|
});
|
|
797
798
|
});
|
|
799
|
+
|
|
800
|
+
interface TypeScriptReference {
|
|
801
|
+
path: string;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
function expectRecord(value: unknown): Record<string, unknown> {
|
|
805
|
+
if (!isRecord(value)) {
|
|
806
|
+
throw new Error('expected object');
|
|
807
|
+
}
|
|
808
|
+
return value;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
812
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
function expectStringArray(value: unknown): string[] {
|
|
816
|
+
if (!Array.isArray(value)) {
|
|
817
|
+
throw new Error('expected array');
|
|
818
|
+
}
|
|
819
|
+
const values: unknown[] = value;
|
|
820
|
+
if (!values.every((entry): entry is string => typeof entry === 'string')) {
|
|
821
|
+
throw new Error('expected string array');
|
|
822
|
+
}
|
|
823
|
+
return values;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
function expectReferences(value: unknown): TypeScriptReference[] {
|
|
827
|
+
if (!Array.isArray(value)) {
|
|
828
|
+
throw new Error('expected array');
|
|
829
|
+
}
|
|
830
|
+
const values: unknown[] = value;
|
|
831
|
+
if (
|
|
832
|
+
!values.every(
|
|
833
|
+
(entry): entry is TypeScriptReference =>
|
|
834
|
+
entry !== null &&
|
|
835
|
+
typeof entry === 'object' &&
|
|
836
|
+
!Array.isArray(entry) &&
|
|
837
|
+
'path' in entry &&
|
|
838
|
+
typeof entry.path === 'string',
|
|
839
|
+
)
|
|
840
|
+
) {
|
|
841
|
+
throw new Error('expected TypeScript references');
|
|
842
|
+
}
|
|
843
|
+
return values;
|
|
844
|
+
}
|