@smoothbricks/nx-plugin 0.4.18 → 0.4.19
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/managed-files/managed-content.d.ts +2 -0
- package/dist/managed-files/managed-content.d.ts.map +1 -1
- package/dist/managed-files/managed-content.js +19 -5
- package/dist/typecheck-test-policy.d.ts +2 -0
- package/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +57 -12
- package/package.json +1 -1
- package/src/managed-files/managed-content.test.ts +19 -0
- package/src/managed-files/managed-content.ts +23 -6
- package/src/typecheck-test-policy.test.ts +56 -5
- package/src/typecheck-test-policy.ts +56 -12
|
@@ -29,6 +29,8 @@ export interface InlineLocalBlock {
|
|
|
29
29
|
anchor: string;
|
|
30
30
|
lines: string;
|
|
31
31
|
markerIndent?: string;
|
|
32
|
+
/** The comment prefix the markers were written with; `#` unless stated. */
|
|
33
|
+
markerPrefix?: string;
|
|
32
34
|
/** Distinguishes no lines from one deliberately blank line. */
|
|
33
35
|
empty?: true;
|
|
34
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"managed-content.d.ts","sourceRoot":"","sources":["../../src/managed-files/managed-content.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,qBAAa,sBAAuB,SAAQ,KAAK;CAAG;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,yEAAyE,CAAC;AAE3G,sFAAsF;AACtF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAUzF;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AACvD,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"managed-content.d.ts","sourceRoot":"","sources":["../../src/managed-files/managed-content.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,qBAAa,sBAAuB,SAAQ,KAAK;CAAG;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,yEAAyE,CAAC;AAE3G,sFAAsF;AACtF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAUzF;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AACvD,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAcnD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,IAAI,CAAC;CACd;AAED;;8BAE8B;AAC9B,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,gBAAgB,EAAE,CAAA;CAAE,CA8C/G;AAED;+EAC+E;AAC/E,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAyB7F"}
|
|
@@ -32,6 +32,17 @@ export function splitLocalSection(current) {
|
|
|
32
32
|
*/
|
|
33
33
|
export const INLINE_LOCAL_BEGIN = '# smoo-local-begin';
|
|
34
34
|
export const INLINE_LOCAL_END = '# smoo-local-end';
|
|
35
|
+
/**
|
|
36
|
+
* The markers are line comments, so a managed file whose language does not
|
|
37
|
+
* comment with `#` (a TypeScript setup script) fences its repo-owned block
|
|
38
|
+
* with `//` instead: `// smoo-local-begin`. The prefix a block was written
|
|
39
|
+
* with is the prefix it is re-emitted with.
|
|
40
|
+
*/
|
|
41
|
+
const INLINE_MARKER = /^\s*(#|\/\/) smoo-local-(begin|end)$/;
|
|
42
|
+
function inlineMarker(line) {
|
|
43
|
+
const match = line === undefined ? null : INLINE_MARKER.exec(line);
|
|
44
|
+
return match === null ? undefined : { kind: match[2] === 'begin' ? 'begin' : 'end', prefix: match[1] };
|
|
45
|
+
}
|
|
35
46
|
/** Pull inline local blocks out of a managed section, returning the section
|
|
36
47
|
* with each block (and its markers) removed, plus the extracted blocks in
|
|
37
48
|
* the order they appeared. */
|
|
@@ -42,16 +53,17 @@ export function extractInlineLocalBlocks(managed) {
|
|
|
42
53
|
let i = 0;
|
|
43
54
|
while (i < lines.length) {
|
|
44
55
|
const line = lines[i];
|
|
45
|
-
|
|
56
|
+
const marker = inlineMarker(line);
|
|
57
|
+
if (line !== undefined && marker?.kind === 'begin') {
|
|
46
58
|
const anchor = kept.at(-1);
|
|
47
59
|
if (anchor === undefined) {
|
|
48
60
|
throw new ManagedContentConflict(`${INLINE_LOCAL_BEGIN} on line ${i + 1} has no preceding anchor line`);
|
|
49
61
|
}
|
|
50
62
|
const blockLines = [];
|
|
51
63
|
i += 1;
|
|
52
|
-
while (i < lines.length && lines[i]?.
|
|
64
|
+
while (i < lines.length && inlineMarker(lines[i])?.kind !== 'end') {
|
|
53
65
|
const blockLine = lines[i];
|
|
54
|
-
if (blockLine
|
|
66
|
+
if (inlineMarker(blockLine)?.kind === 'begin') {
|
|
55
67
|
throw new ManagedContentConflict(`${INLINE_LOCAL_BEGIN} on line ${i + 1} is nested`);
|
|
56
68
|
}
|
|
57
69
|
blockLines.push(blockLine);
|
|
@@ -66,11 +78,12 @@ export function extractInlineLocalBlocks(managed) {
|
|
|
66
78
|
lines: blockLines.join('\n'),
|
|
67
79
|
...(blockLines.length === 0 ? { empty: true } : {}),
|
|
68
80
|
...(markerIndent === '' ? {} : { markerIndent }),
|
|
81
|
+
...(marker.prefix === '#' ? {} : { markerPrefix: marker.prefix }),
|
|
69
82
|
});
|
|
70
83
|
i += 1; // skip the END marker line itself
|
|
71
84
|
continue;
|
|
72
85
|
}
|
|
73
|
-
if (line
|
|
86
|
+
if (inlineMarker(line)?.kind === 'end') {
|
|
74
87
|
throw new ManagedContentConflict(`${INLINE_LOCAL_END} on line ${i + 1} has no matching ${INLINE_LOCAL_BEGIN}`);
|
|
75
88
|
}
|
|
76
89
|
kept.push(line);
|
|
@@ -94,8 +107,9 @@ export function reinsertInlineLocalBlocks(content, blocks) {
|
|
|
94
107
|
}
|
|
95
108
|
const index = matches[0];
|
|
96
109
|
const markerIndent = block.markerIndent ?? '';
|
|
110
|
+
const prefix = block.markerPrefix ?? '#';
|
|
97
111
|
const inserted = additions.get(index) ?? [];
|
|
98
|
-
inserted.push(`${markerIndent}${
|
|
112
|
+
inserted.push(`${markerIndent}${prefix} smoo-local-begin`, ...(block.empty ? [] : block.lines.split('\n')), `${markerIndent}${prefix} smoo-local-end`);
|
|
99
113
|
additions.set(index, inserted);
|
|
100
114
|
}
|
|
101
115
|
return lines.flatMap((line, index) => [line, ...(additions.get(index) ?? [])]).join('\n');
|
|
@@ -25,6 +25,8 @@ export declare function applyTypecheckTestDefaults(tsconfigTest: Record<string,
|
|
|
25
25
|
tsconfigLibExtends?: string | string[];
|
|
26
26
|
libCompilerOptions?: Record<string, unknown>;
|
|
27
27
|
referencePaths: string[];
|
|
28
|
+
/** The file did not exist: a fresh program gets the src-test globs. */
|
|
29
|
+
isNew?: boolean;
|
|
28
30
|
}): boolean;
|
|
29
31
|
/**
|
|
30
32
|
* Remove the ./tsconfig.test.json reference from a tsconfig.json object.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typecheck-test-policy.d.ts","sourceRoot":"","sources":["../src/typecheck-test-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAIrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE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|
|
1
1
|
import * as _assertGuard_1 from "typia/lib/internal/_assertGuard";
|
|
2
2
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
3
|
-
import { join, relative } from 'node:path';
|
|
3
|
+
import { dirname, join, relative } from 'node:path';
|
|
4
4
|
import { getProjects, readJson, readProjectConfiguration } from 'nx/src/devkit-exports.js';
|
|
5
5
|
import typia from 'typia';
|
|
6
6
|
import { ManagedContentConflict } from './managed-files/managed-content.js';
|
|
@@ -152,7 +152,11 @@ export function applyTypecheckTestDefaults(tsconfigTest, options) {
|
|
|
152
152
|
changed = setBooleanProperty(compilerOptions, 'declarationMap', false) || changed;
|
|
153
153
|
changed = setBooleanProperty(compilerOptions, 'emitDeclarationOnly', false) || changed;
|
|
154
154
|
changed = setBooleanProperty(compilerOptions, 'noEmit', true) || changed;
|
|
155
|
-
|
|
155
|
+
// `types`, like `include` below, replaces what `extends` provides the
|
|
156
|
+
// moment it is declared: a program inheriting workers + bun types from its
|
|
157
|
+
// tsconfig.json would be left with `["bun"]` alone. Merge only into a
|
|
158
|
+
// declared list or a new file.
|
|
159
|
+
if (options.testRunners.has('bun') && (options.isNew || Object.hasOwn(compilerOptions, 'types'))) {
|
|
156
160
|
changed = mergeStringListProperty(compilerOptions, 'types', ['bun']) || changed;
|
|
157
161
|
}
|
|
158
162
|
if ('outDir' in compilerOptions) {
|
|
@@ -163,14 +167,22 @@ export function applyTypecheckTestDefaults(tsconfigTest, options) {
|
|
|
163
167
|
delete compilerOptions.tsBuildInfoFile;
|
|
164
168
|
changed = true;
|
|
165
169
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
// A test program that declares no `include` inherits one from `extends`
|
|
171
|
+
// (a package keeping its suites in `test/` alongside src, tooling and
|
|
172
|
+
// scripts as one program). Minting `include` there REPLACES the inherited
|
|
173
|
+
// set with globs that match nothing, and a program of zero files passes the
|
|
174
|
+
// gate by compiling nothing. Only a program that already declares `include`,
|
|
175
|
+
// or a new file, gets the src-test globs merged in.
|
|
176
|
+
if (options.isNew || Object.hasOwn(tsconfigTest, 'include')) {
|
|
177
|
+
changed =
|
|
178
|
+
mergeStringListProperty(tsconfigTest, 'include', [
|
|
179
|
+
'src/**/*.test.ts',
|
|
180
|
+
'src/**/*.spec.ts',
|
|
181
|
+
'src/**/__tests__/**/*.ts',
|
|
182
|
+
'src/**/__tests__/**/*.tsx',
|
|
183
|
+
'src/test-suite-tracer.ts',
|
|
184
|
+
]) || changed;
|
|
185
|
+
}
|
|
174
186
|
for (const referencePath of options.referencePaths) {
|
|
175
187
|
changed = addTsconfigReference(tsconfigTest, referencePath) || changed;
|
|
176
188
|
}
|
|
@@ -262,6 +274,7 @@ export function renderTypecheckTestFiles(tree) {
|
|
|
262
274
|
tsconfigLibExtends,
|
|
263
275
|
libCompilerOptions: libCompilerOptions ?? undefined,
|
|
264
276
|
referencePaths,
|
|
277
|
+
isNew,
|
|
265
278
|
});
|
|
266
279
|
files.push(renderTsconfig(tree, tsconfigTestPath, tsconfigTest, changed || isNew));
|
|
267
280
|
// Remove test reference from tsconfig.json
|
|
@@ -425,8 +438,14 @@ function collectWorkspacePackagesTree(tree) {
|
|
|
425
438
|
}
|
|
426
439
|
function collectReferencePathsTree(tree, packageRoot, pkg, workspacePackages) {
|
|
427
440
|
const paths = [];
|
|
441
|
+
// A project reference is only legal to a `composite` program (TS6306); a
|
|
442
|
+
// lib tsconfig that is not composite — an application target's emit
|
|
443
|
+
// program — is included by the test program's own globs instead.
|
|
444
|
+
// `composite` is usually inherited from tsconfig.base.json, so the option is
|
|
445
|
+
// resolved through the `extends` chain, not read off the one file.
|
|
446
|
+
const isComposite = (path) => resolveTsconfigOption(tree, path, 'composite') === true;
|
|
428
447
|
const libTsconfigPath = `${packageRoot}/tsconfig.lib.json`;
|
|
429
|
-
if (
|
|
448
|
+
if (isComposite(libTsconfigPath)) {
|
|
430
449
|
paths.push('./tsconfig.lib.json');
|
|
431
450
|
}
|
|
432
451
|
const packagesByName = new Map(workspacePackages.map((p) => [p.name, p]));
|
|
@@ -439,7 +458,7 @@ function collectReferencePathsTree(tree, packageRoot, pkg, workspacePackages) {
|
|
|
439
458
|
if (!depPkg)
|
|
440
459
|
continue;
|
|
441
460
|
const depTsconfig = `${depPkg.path}/tsconfig.lib.json`;
|
|
442
|
-
if (!
|
|
461
|
+
if (!isComposite(depTsconfig))
|
|
443
462
|
continue;
|
|
444
463
|
const refPath = relative(packageRoot, depTsconfig).replaceAll('\\', '/');
|
|
445
464
|
if (!paths.includes(refPath))
|
|
@@ -662,6 +681,32 @@ function recordProperty(record, key) {
|
|
|
662
681
|
const value = record[key];
|
|
663
682
|
return isRecord(value) ? value : null;
|
|
664
683
|
}
|
|
684
|
+
/**
|
|
685
|
+
* A tsconfig compiler option as TypeScript would see it: the file's own value,
|
|
686
|
+
* else the nearest base in its `extends` chain (an array extends applies
|
|
687
|
+
* left-to-right, so the last base naming the option wins). Bases that are not
|
|
688
|
+
* relative paths (package configs) are outside the tree and contribute nothing.
|
|
689
|
+
*/
|
|
690
|
+
function resolveTsconfigOption(tree, path, option) {
|
|
691
|
+
if (!tree.exists(path))
|
|
692
|
+
return undefined;
|
|
693
|
+
const config = readJson(tree, path);
|
|
694
|
+
const own = recordProperty(config, 'compilerOptions')?.[option];
|
|
695
|
+
if (own !== undefined)
|
|
696
|
+
return own;
|
|
697
|
+
const bases = config.extends;
|
|
698
|
+
const baseList = typeof bases === 'string' ? [bases] : Array.isArray(bases) ? bases : [];
|
|
699
|
+
for (let i = baseList.length - 1; i >= 0; i--) {
|
|
700
|
+
const base = baseList[i];
|
|
701
|
+
if (typeof base !== 'string' || !base.startsWith('.'))
|
|
702
|
+
continue;
|
|
703
|
+
const basePath = join(dirname(path), base.endsWith('.json') ? base : `${base}.json`);
|
|
704
|
+
const inherited = resolveTsconfigOption(tree, basePath, option);
|
|
705
|
+
if (inherited !== undefined)
|
|
706
|
+
return inherited;
|
|
707
|
+
}
|
|
708
|
+
return undefined;
|
|
709
|
+
}
|
|
665
710
|
function getOrCreateRecord(record, key) {
|
|
666
711
|
const value = record[key];
|
|
667
712
|
if (isRecord(value)) {
|
package/package.json
CHANGED
|
@@ -93,6 +93,25 @@ describe('managed-file inline local blocks', () => {
|
|
|
93
93
|
);
|
|
94
94
|
});
|
|
95
95
|
|
|
96
|
+
it('fences a TypeScript managed file with // markers and re-emits the same prefix', () => {
|
|
97
|
+
// setup-environment.ts is a managed TypeScript file; `# smoo-local-begin`
|
|
98
|
+
// is not a comment there. A repo-owned block (the dev-links re-link after
|
|
99
|
+
// install) used `//` fences that the update never recognised and dropped.
|
|
100
|
+
const current = [
|
|
101
|
+
'const a = 1;',
|
|
102
|
+
'// smoo-local-begin',
|
|
103
|
+
'linkDevPackages();',
|
|
104
|
+
'// smoo-local-end',
|
|
105
|
+
'const b = 2;',
|
|
106
|
+
].join('\n');
|
|
107
|
+
const { withoutInline, blocks } = extractInlineLocalBlocks(current);
|
|
108
|
+
expect(withoutInline).toBe(['const a = 1;', 'const b = 2;'].join('\n'));
|
|
109
|
+
expect(blocks).toEqual([{ anchor: 'const a = 1;', lines: 'linkDevPackages();', markerPrefix: '//' }]);
|
|
110
|
+
expect(reinsertInlineLocalBlocks(['const a = 1;', 'const b = 3;'].join('\n'), blocks)).toBe(
|
|
111
|
+
['const a = 1;', '// smoo-local-begin', 'linkDevPackages();', '// smoo-local-end', 'const b = 3;'].join('\n'),
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
|
|
96
115
|
it('preserves marker indentation when refreshing nested configuration', () => {
|
|
97
116
|
const markerIndent = ' ';
|
|
98
117
|
const current = [
|
|
@@ -34,11 +34,25 @@ export function splitLocalSection(current: string): { managed: string; localTail
|
|
|
34
34
|
*/
|
|
35
35
|
export const INLINE_LOCAL_BEGIN = '# smoo-local-begin';
|
|
36
36
|
export const INLINE_LOCAL_END = '# smoo-local-end';
|
|
37
|
+
/**
|
|
38
|
+
* The markers are line comments, so a managed file whose language does not
|
|
39
|
+
* comment with `#` (a TypeScript setup script) fences its repo-owned block
|
|
40
|
+
* with `//` instead: `// smoo-local-begin`. The prefix a block was written
|
|
41
|
+
* with is the prefix it is re-emitted with.
|
|
42
|
+
*/
|
|
43
|
+
const INLINE_MARKER = /^\s*(#|\/\/) smoo-local-(begin|end)$/;
|
|
44
|
+
|
|
45
|
+
function inlineMarker(line: string | undefined): { kind: 'begin' | 'end'; prefix: string } | undefined {
|
|
46
|
+
const match = line === undefined ? null : INLINE_MARKER.exec(line);
|
|
47
|
+
return match === null ? undefined : { kind: match[2] === 'begin' ? 'begin' : 'end', prefix: match[1] };
|
|
48
|
+
}
|
|
37
49
|
|
|
38
50
|
export interface InlineLocalBlock {
|
|
39
51
|
anchor: string;
|
|
40
52
|
lines: string;
|
|
41
53
|
markerIndent?: string;
|
|
54
|
+
/** The comment prefix the markers were written with; `#` unless stated. */
|
|
55
|
+
markerPrefix?: string;
|
|
42
56
|
/** Distinguishes no lines from one deliberately blank line. */
|
|
43
57
|
empty?: true;
|
|
44
58
|
}
|
|
@@ -53,16 +67,17 @@ export function extractInlineLocalBlocks(managed: string): { withoutInline: stri
|
|
|
53
67
|
let i = 0;
|
|
54
68
|
while (i < lines.length) {
|
|
55
69
|
const line = lines[i];
|
|
56
|
-
|
|
70
|
+
const marker = inlineMarker(line);
|
|
71
|
+
if (line !== undefined && marker?.kind === 'begin') {
|
|
57
72
|
const anchor = kept.at(-1);
|
|
58
73
|
if (anchor === undefined) {
|
|
59
74
|
throw new ManagedContentConflict(`${INLINE_LOCAL_BEGIN} on line ${i + 1} has no preceding anchor line`);
|
|
60
75
|
}
|
|
61
76
|
const blockLines: string[] = [];
|
|
62
77
|
i += 1;
|
|
63
|
-
while (i < lines.length && lines[i]?.
|
|
78
|
+
while (i < lines.length && inlineMarker(lines[i])?.kind !== 'end') {
|
|
64
79
|
const blockLine = lines[i];
|
|
65
|
-
if (blockLine
|
|
80
|
+
if (inlineMarker(blockLine)?.kind === 'begin') {
|
|
66
81
|
throw new ManagedContentConflict(`${INLINE_LOCAL_BEGIN} on line ${i + 1} is nested`);
|
|
67
82
|
}
|
|
68
83
|
blockLines.push(blockLine);
|
|
@@ -79,11 +94,12 @@ export function extractInlineLocalBlocks(managed: string): { withoutInline: stri
|
|
|
79
94
|
lines: blockLines.join('\n'),
|
|
80
95
|
...(blockLines.length === 0 ? { empty: true as const } : {}),
|
|
81
96
|
...(markerIndent === '' ? {} : { markerIndent }),
|
|
97
|
+
...(marker.prefix === '#' ? {} : { markerPrefix: marker.prefix }),
|
|
82
98
|
});
|
|
83
99
|
i += 1; // skip the END marker line itself
|
|
84
100
|
continue;
|
|
85
101
|
}
|
|
86
|
-
if (line
|
|
102
|
+
if (inlineMarker(line)?.kind === 'end') {
|
|
87
103
|
throw new ManagedContentConflict(`${INLINE_LOCAL_END} on line ${i + 1} has no matching ${INLINE_LOCAL_BEGIN}`);
|
|
88
104
|
}
|
|
89
105
|
kept.push(line);
|
|
@@ -109,11 +125,12 @@ export function reinsertInlineLocalBlocks(content: string, blocks: InlineLocalBl
|
|
|
109
125
|
}
|
|
110
126
|
const index = matches[0];
|
|
111
127
|
const markerIndent = block.markerIndent ?? '';
|
|
128
|
+
const prefix = block.markerPrefix ?? '#';
|
|
112
129
|
const inserted = additions.get(index) ?? [];
|
|
113
130
|
inserted.push(
|
|
114
|
-
`${markerIndent}${
|
|
131
|
+
`${markerIndent}${prefix} smoo-local-begin`,
|
|
115
132
|
...(block.empty ? [] : block.lines.split('\n')),
|
|
116
|
-
`${markerIndent}${
|
|
133
|
+
`${markerIndent}${prefix} smoo-local-end`,
|
|
117
134
|
);
|
|
118
135
|
additions.set(index, inserted);
|
|
119
136
|
}
|
|
@@ -204,6 +204,7 @@ describe('applyTypecheckTestDefaults', () => {
|
|
|
204
204
|
const changed = applyTypecheckTestDefaults(tsconfigTest, {
|
|
205
205
|
testRunners: new Set(['bun'] as const),
|
|
206
206
|
referencePaths: ['./tsconfig.lib.json'],
|
|
207
|
+
isNew: true,
|
|
207
208
|
});
|
|
208
209
|
expect(changed).toBe(true);
|
|
209
210
|
expect(tsconfigTest.extends).toBe('../../tsconfig.base.json');
|
|
@@ -224,6 +225,22 @@ describe('applyTypecheckTestDefaults', () => {
|
|
|
224
225
|
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
225
226
|
});
|
|
226
227
|
|
|
228
|
+
it('leaves an inherited include alone: minting one narrows the program to nothing', () => {
|
|
229
|
+
// A package keeping its suites in `test/` inherits src + test + tooling
|
|
230
|
+
// from its tsconfig.json. Writing `include` with src-test globs replaced
|
|
231
|
+
// that with a program of zero files, which passed the gate by compiling
|
|
232
|
+
// nothing (the false green the policy exists to prevent).
|
|
233
|
+
const declared: Record<string, unknown> = { extends: './tsconfig.json', compilerOptions: { noEmit: true } };
|
|
234
|
+
applyTypecheckTestDefaults(declared, { testRunners: new Set(['bun'] as const), referencePaths: [] });
|
|
235
|
+
expect(Object.hasOwn(declared, 'include')).toBe(false);
|
|
236
|
+
// Same for `types`: declaring it would drop the workers types the program inherits.
|
|
237
|
+
expect(Object.hasOwn(expectRecord(declared.compilerOptions), 'types')).toBe(false);
|
|
238
|
+
|
|
239
|
+
const explicit: Record<string, unknown> = { extends: './tsconfig.json', include: ['test/**/*.ts'] };
|
|
240
|
+
applyTypecheckTestDefaults(explicit, { testRunners: new Set(['bun'] as const), referencePaths: [] });
|
|
241
|
+
expect(expectStringArray(explicit.include)).toEqual(expect.arrayContaining(['test/**/*.ts', 'src/**/*.test.ts']));
|
|
242
|
+
});
|
|
243
|
+
|
|
227
244
|
it('fills compiler options the test program left out and keeps the ones it declared', () => {
|
|
228
245
|
// A Bun-only test program declaring es2023 says something the library cannot
|
|
229
246
|
// know: its runtime has change-array-by-copy while the library's output ships
|
|
@@ -350,7 +367,7 @@ describe('typecheck test policy (Tree)', () => {
|
|
|
350
367
|
});
|
|
351
368
|
writeJson(tree, 'packages/app/tsconfig.lib.json', {
|
|
352
369
|
extends: '../../tsconfig.base.json',
|
|
353
|
-
compilerOptions: { baseUrl: '.', rootDir: 'src', outDir: 'dist' },
|
|
370
|
+
compilerOptions: { composite: true, baseUrl: '.', rootDir: 'src', outDir: 'dist' },
|
|
354
371
|
});
|
|
355
372
|
|
|
356
373
|
const changed = applyTypecheckTestPolicyTree(tree);
|
|
@@ -372,6 +389,39 @@ describe('typecheck test policy (Tree)', () => {
|
|
|
372
389
|
expect(references).toContainEqual({ path: './tsconfig.lib.json' });
|
|
373
390
|
});
|
|
374
391
|
|
|
392
|
+
it('references only composite lib programs (TS6306 otherwise), resolving composite through extends', () => {
|
|
393
|
+
const tree = createTreeWithEmptyWorkspace();
|
|
394
|
+
writeJson(tree, 'tsconfig.composite.json', { compilerOptions: { composite: true } });
|
|
395
|
+
for (const [name, composite] of [
|
|
396
|
+
['app', 'no'],
|
|
397
|
+
['lib', 'own'],
|
|
398
|
+
['inherits', 'base'],
|
|
399
|
+
] as const) {
|
|
400
|
+
addProjectConfiguration(tree, name, { root: `packages/${name}`, targets: {} });
|
|
401
|
+
if (tree.exists(`packages/${name}/project.json`)) tree.delete(`packages/${name}/project.json`);
|
|
402
|
+
writeJson(tree, `packages/${name}/package.json`, {
|
|
403
|
+
name: `@scope/${name}`,
|
|
404
|
+
scripts: { test: 'bun test' },
|
|
405
|
+
nx: { name },
|
|
406
|
+
...(name === 'app' ? { dependencies: { '@scope/lib': 'workspace:*', '@scope/inherits': 'workspace:*' } } : {}),
|
|
407
|
+
});
|
|
408
|
+
writeJson(tree, `packages/${name}/tsconfig.lib.json`, {
|
|
409
|
+
extends:
|
|
410
|
+
composite === 'base' ? ['../../tsconfig.base.json', '../../tsconfig.composite'] : '../../tsconfig.base.json',
|
|
411
|
+
compilerOptions: { rootDir: 'src', outDir: 'dist', ...(composite === 'own' ? { composite: true } : {}) },
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
applyTypecheckTestPolicyTree(tree);
|
|
416
|
+
const references = expectReferences(
|
|
417
|
+
readJson<Record<string, unknown>>(tree, 'packages/app/tsconfig.test.json').references,
|
|
418
|
+
);
|
|
419
|
+
// The app's own emit program is not composite: its sources are in the
|
|
420
|
+
// test program by glob, not by reference. The composite dependencies are —
|
|
421
|
+
// whether composite is declared on the file or inherited from a base.
|
|
422
|
+
expect(references).toEqual([{ path: '../lib/tsconfig.lib.json' }, { path: '../inherits/tsconfig.lib.json' }]);
|
|
423
|
+
});
|
|
424
|
+
|
|
375
425
|
it('detects bun test in project.json targets', () => {
|
|
376
426
|
const tree = createTreeWithEmptyWorkspace();
|
|
377
427
|
addProjectConfiguration(tree, 'app', {
|
|
@@ -513,7 +563,7 @@ describe('typecheck test policy (Tree)', () => {
|
|
|
513
563
|
writeJson(tree, 'packages/lib/package.json', { name: '@scope/lib' });
|
|
514
564
|
writeJson(tree, 'packages/lib/tsconfig.lib.json', {
|
|
515
565
|
extends: '../../tsconfig.base.json',
|
|
516
|
-
compilerOptions: {},
|
|
566
|
+
compilerOptions: { composite: true },
|
|
517
567
|
});
|
|
518
568
|
|
|
519
569
|
// App that depends on lib
|
|
@@ -526,7 +576,7 @@ describe('typecheck test policy (Tree)', () => {
|
|
|
526
576
|
});
|
|
527
577
|
writeJson(tree, 'packages/app/tsconfig.lib.json', {
|
|
528
578
|
extends: '../../tsconfig.base.json',
|
|
529
|
-
compilerOptions: {},
|
|
579
|
+
compilerOptions: { composite: true },
|
|
530
580
|
});
|
|
531
581
|
|
|
532
582
|
expect(applyTypecheckTestPolicyTree(tree)).toBe(true);
|
|
@@ -758,6 +808,7 @@ describe('typecheck test policy', () => {
|
|
|
758
808
|
await writeJsonFs(join(root, 'packages/app/tsconfig.lib.json'), {
|
|
759
809
|
extends: '../../tsconfig.base.json',
|
|
760
810
|
compilerOptions: {
|
|
811
|
+
composite: true,
|
|
761
812
|
baseUrl: '.',
|
|
762
813
|
module: 'esnext',
|
|
763
814
|
moduleResolution: 'bundler',
|
|
@@ -795,7 +846,7 @@ describe('typecheck test policy', () => {
|
|
|
795
846
|
});
|
|
796
847
|
await writeJsonFs(join(root, 'packages/lib/tsconfig.lib.json'), {
|
|
797
848
|
extends: '../../tsconfig.base.json',
|
|
798
|
-
compilerOptions: {},
|
|
849
|
+
compilerOptions: { composite: true },
|
|
799
850
|
});
|
|
800
851
|
await writeJsonFs(join(root, 'packages/app/package.json'), {
|
|
801
852
|
name: '@scope/app',
|
|
@@ -804,7 +855,7 @@ describe('typecheck test policy', () => {
|
|
|
804
855
|
});
|
|
805
856
|
await writeJsonFs(join(root, 'packages/app/tsconfig.lib.json'), {
|
|
806
857
|
extends: '../../tsconfig.base.json',
|
|
807
|
-
compilerOptions: {},
|
|
858
|
+
compilerOptions: { composite: true },
|
|
808
859
|
});
|
|
809
860
|
|
|
810
861
|
expect(applyTypecheckTestPolicy(root)).toBe(true);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
2
|
-
import { join, relative } from 'node:path';
|
|
2
|
+
import { dirname, join, relative } from 'node:path';
|
|
3
3
|
import type { Tree } from 'nx/src/devkit-exports.js';
|
|
4
4
|
import { getProjects, readJson, readProjectConfiguration } from 'nx/src/devkit-exports.js';
|
|
5
5
|
import typia from 'typia';
|
|
@@ -162,6 +162,8 @@ export function applyTypecheckTestDefaults(
|
|
|
162
162
|
tsconfigLibExtends?: string | string[];
|
|
163
163
|
libCompilerOptions?: Record<string, unknown>;
|
|
164
164
|
referencePaths: string[];
|
|
165
|
+
/** The file did not exist: a fresh program gets the src-test globs. */
|
|
166
|
+
isNew?: boolean;
|
|
165
167
|
},
|
|
166
168
|
): boolean {
|
|
167
169
|
let changed = !Object.hasOwn(tsconfigTest, 'extends');
|
|
@@ -190,7 +192,11 @@ export function applyTypecheckTestDefaults(
|
|
|
190
192
|
changed = setBooleanProperty(compilerOptions, 'emitDeclarationOnly', false) || changed;
|
|
191
193
|
changed = setBooleanProperty(compilerOptions, 'noEmit', true) || changed;
|
|
192
194
|
|
|
193
|
-
|
|
195
|
+
// `types`, like `include` below, replaces what `extends` provides the
|
|
196
|
+
// moment it is declared: a program inheriting workers + bun types from its
|
|
197
|
+
// tsconfig.json would be left with `["bun"]` alone. Merge only into a
|
|
198
|
+
// declared list or a new file.
|
|
199
|
+
if (options.testRunners.has('bun') && (options.isNew || Object.hasOwn(compilerOptions, 'types'))) {
|
|
194
200
|
changed = mergeStringListProperty(compilerOptions, 'types', ['bun']) || changed;
|
|
195
201
|
}
|
|
196
202
|
|
|
@@ -203,14 +209,22 @@ export function applyTypecheckTestDefaults(
|
|
|
203
209
|
changed = true;
|
|
204
210
|
}
|
|
205
211
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
// A test program that declares no `include` inherits one from `extends`
|
|
213
|
+
// (a package keeping its suites in `test/` alongside src, tooling and
|
|
214
|
+
// scripts as one program). Minting `include` there REPLACES the inherited
|
|
215
|
+
// set with globs that match nothing, and a program of zero files passes the
|
|
216
|
+
// gate by compiling nothing. Only a program that already declares `include`,
|
|
217
|
+
// or a new file, gets the src-test globs merged in.
|
|
218
|
+
if (options.isNew || Object.hasOwn(tsconfigTest, 'include')) {
|
|
219
|
+
changed =
|
|
220
|
+
mergeStringListProperty(tsconfigTest, 'include', [
|
|
221
|
+
'src/**/*.test.ts',
|
|
222
|
+
'src/**/*.spec.ts',
|
|
223
|
+
'src/**/__tests__/**/*.ts',
|
|
224
|
+
'src/**/__tests__/**/*.tsx',
|
|
225
|
+
'src/test-suite-tracer.ts',
|
|
226
|
+
]) || changed;
|
|
227
|
+
}
|
|
214
228
|
|
|
215
229
|
for (const referencePath of options.referencePaths) {
|
|
216
230
|
changed = addTsconfigReference(tsconfigTest, referencePath) || changed;
|
|
@@ -316,6 +330,7 @@ export function renderTypecheckTestFiles(tree: Tree): ManagedFile[] {
|
|
|
316
330
|
tsconfigLibExtends,
|
|
317
331
|
libCompilerOptions: libCompilerOptions ?? undefined,
|
|
318
332
|
referencePaths,
|
|
333
|
+
isNew,
|
|
319
334
|
});
|
|
320
335
|
files.push(renderTsconfig(tree, tsconfigTestPath, tsconfigTest, changed || isNew));
|
|
321
336
|
|
|
@@ -506,8 +521,14 @@ function collectReferencePathsTree(
|
|
|
506
521
|
workspacePackages: TreeWorkspacePackage[],
|
|
507
522
|
): string[] {
|
|
508
523
|
const paths: string[] = [];
|
|
524
|
+
// A project reference is only legal to a `composite` program (TS6306); a
|
|
525
|
+
// lib tsconfig that is not composite — an application target's emit
|
|
526
|
+
// program — is included by the test program's own globs instead.
|
|
527
|
+
// `composite` is usually inherited from tsconfig.base.json, so the option is
|
|
528
|
+
// resolved through the `extends` chain, not read off the one file.
|
|
529
|
+
const isComposite = (path: string): boolean => resolveTsconfigOption(tree, path, 'composite') === true;
|
|
509
530
|
const libTsconfigPath = `${packageRoot}/tsconfig.lib.json`;
|
|
510
|
-
if (
|
|
531
|
+
if (isComposite(libTsconfigPath)) {
|
|
511
532
|
paths.push('./tsconfig.lib.json');
|
|
512
533
|
}
|
|
513
534
|
|
|
@@ -519,7 +540,7 @@ function collectReferencePathsTree(
|
|
|
519
540
|
const depPkg = packagesByName.get(depName);
|
|
520
541
|
if (!depPkg) continue;
|
|
521
542
|
const depTsconfig = `${depPkg.path}/tsconfig.lib.json`;
|
|
522
|
-
if (!
|
|
543
|
+
if (!isComposite(depTsconfig)) continue;
|
|
523
544
|
const refPath = relative(packageRoot, depTsconfig).replaceAll('\\', '/');
|
|
524
545
|
if (!paths.includes(refPath)) paths.push(refPath);
|
|
525
546
|
}
|
|
@@ -726,6 +747,29 @@ function recordProperty(record: Record<string, unknown> | null, key: string): Re
|
|
|
726
747
|
return isRecord(value) ? value : null;
|
|
727
748
|
}
|
|
728
749
|
|
|
750
|
+
/**
|
|
751
|
+
* A tsconfig compiler option as TypeScript would see it: the file's own value,
|
|
752
|
+
* else the nearest base in its `extends` chain (an array extends applies
|
|
753
|
+
* left-to-right, so the last base naming the option wins). Bases that are not
|
|
754
|
+
* relative paths (package configs) are outside the tree and contribute nothing.
|
|
755
|
+
*/
|
|
756
|
+
function resolveTsconfigOption(tree: Tree, path: string, option: string): unknown {
|
|
757
|
+
if (!tree.exists(path)) return undefined;
|
|
758
|
+
const config = readJson<Record<string, unknown>>(tree, path);
|
|
759
|
+
const own = recordProperty(config, 'compilerOptions')?.[option];
|
|
760
|
+
if (own !== undefined) return own;
|
|
761
|
+
const bases = config.extends;
|
|
762
|
+
const baseList = typeof bases === 'string' ? [bases] : Array.isArray(bases) ? bases : [];
|
|
763
|
+
for (let i = baseList.length - 1; i >= 0; i--) {
|
|
764
|
+
const base = baseList[i];
|
|
765
|
+
if (typeof base !== 'string' || !base.startsWith('.')) continue;
|
|
766
|
+
const basePath = join(dirname(path), base.endsWith('.json') ? base : `${base}.json`);
|
|
767
|
+
const inherited = resolveTsconfigOption(tree, basePath, option);
|
|
768
|
+
if (inherited !== undefined) return inherited;
|
|
769
|
+
}
|
|
770
|
+
return undefined;
|
|
771
|
+
}
|
|
772
|
+
|
|
729
773
|
function getOrCreateRecord(record: Record<string, unknown>, key: string): Record<string, unknown> {
|
|
730
774
|
const value = record[key];
|
|
731
775
|
if (isRecord(value)) {
|