Skip to content

Commit fad888a

Browse files
authored
Add extendedSourceFiles in CMKConfig (#265)
* fix comment * add `extendedSourceFiles` in `CMKConfig` * remove test - A test fails on Windows. - The test expects `extendedSourceFiles` to return in 8.3 filename format but instead receives full filenames. - On the other hand, this test examines internal behavior of the TypeScript Compiler API. - This test should be removed.
1 parent c1232f3 commit fad888a

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

.changeset/khaki-pillows-change.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@css-modules-kit/core': minor
3+
---
4+
5+
feat: add `extendedSourceFiles` in `CMKConfig`

packages/core/src/config.test.ts

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@ describe('readConfigFile', () => {
1818
});
1919
test('returns the default options even if tsconfig is empty', async () => {
2020
const iff = await createIFF({ 'tsconfig.json': '{}' });
21-
expect(readConfigFile(iff.rootDir)).toStrictEqual<CMKConfig>(
22-
expect.objectContaining({
23-
includes: [iff.join('**/*')],
24-
excludes: [],
25-
dtsOutDir: iff.join('generated'),
26-
arbitraryExtensions: false,
27-
namedExports: false,
28-
prioritizeNamedImports: false,
29-
keyframes: true,
30-
compilerOptions: expect.any(Object),
31-
wildcardDirectories: [{ fileName: iff.rootDir, recursive: true }],
32-
}),
33-
);
21+
expect(readConfigFile(iff.rootDir)).toStrictEqual<CMKConfig>({
22+
includes: [iff.join('**/*')],
23+
excludes: [],
24+
dtsOutDir: iff.join('generated'),
25+
arbitraryExtensions: false,
26+
namedExports: false,
27+
prioritizeNamedImports: false,
28+
keyframes: true,
29+
basePath: iff.rootDir,
30+
configFileName: iff.paths['tsconfig.json'],
31+
compilerOptions: expect.any(Object),
32+
wildcardDirectories: [{ fileName: iff.rootDir, recursive: true }],
33+
extendedSourceFiles: [],
34+
diagnostics: [],
35+
});
3436
});
3537
test('default option values are overridden by config file values', async () => {
3638
const iff = await createIFF({
@@ -101,6 +103,7 @@ describe('readConfigFile', () => {
101103
module: ts.ModuleKind.ESNext,
102104
}),
103105
wildcardDirectories: [{ fileName: iff.join('src'), recursive: true }],
106+
extendedSourceFiles: [iff.join('tsconfig.base.json')],
104107
}),
105108
);
106109
});
@@ -134,6 +137,7 @@ describe('readConfigFile', () => {
134137
module: ts.ModuleKind.ES2015,
135138
}),
136139
wildcardDirectories: [{ fileName: iff.join('src2'), recursive: true }],
140+
extendedSourceFiles: [iff.join('tsconfig.base.json')],
137141
}),
138142
);
139143
});
@@ -161,6 +165,7 @@ describe('readConfigFile', () => {
161165
module: ts.ModuleKind.ESNext,
162166
}),
163167
wildcardDirectories: [{ fileName: iff.join('src'), recursive: true }],
168+
extendedSourceFiles: [iff.join('tsconfig.base2.json'), iff.join('tsconfig.base1.json')],
164169
}),
165170
);
166171
});
@@ -185,21 +190,6 @@ describe('readConfigFile', () => {
185190
});
186191
expect(readConfigFile(iff.rootDir).dtsOutDir).toBe(iff.join('generated2'));
187192
});
188-
test('inherits from a package', async () => {
189-
const iff = await createIFF({
190-
'node_modules/some-pkg/tsconfig.json': dedent`
191-
{
192-
"cmkOptions": { "dtsOutDir": "generated/cmk" }
193-
}
194-
`,
195-
'tsconfig.json': dedent`
196-
{
197-
"extends": "some-pkg/tsconfig.json"
198-
}
199-
`,
200-
});
201-
expect(readConfigFile(iff.rootDir).dtsOutDir).toBe(iff.join('generated/cmk'));
202-
});
203193
test('inherits from multiple files', async () => {
204194
const iff = await createIFF({
205195
'tsconfig.base1.json': dedent`
@@ -222,6 +212,7 @@ describe('readConfigFile', () => {
222212
expect.objectContaining({
223213
dtsOutDir: iff.join('generated/cmk'),
224214
arbitraryExtensions: true,
215+
extendedSourceFiles: [iff.join('tsconfig.base1.json'), iff.join('tsconfig.base2.json')],
225216
}),
226217
);
227218
});

packages/core/src/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export interface CMKConfig {
6060
compilerOptions: ts.CompilerOptions;
6161
/** The directories to watch when watch mode is enabled. */
6262
wildcardDirectories: { fileName: string; recursive: boolean }[];
63+
/** The tsconfig files inherited by `configFileName`. */
64+
extendedSourceFiles: string[];
6365
/** The diagnostics that occurred while reading the config file. */
6466
diagnostics: Diagnostic[];
6567
}
@@ -246,7 +248,7 @@ export function readConfigFile(project: string): CMKConfig {
246248

247249
const basePath = dirname(configFileName);
248250
return {
249-
// If `include` is not specified, fallback to the default include spec
251+
// If `include` is not specified, fallback to the default include spec.
250252
// ref: https://github.com/microsoft/TypeScript/blob/caf1aee269d1660b4d2a8b555c2d602c97cb28d7/src/compiler/commandLineParser.ts#L3102
251253
includes: (parsedTsConfig.config.includes ?? [DEFAULT_INCLUDE_SPEC]).map((i) => join(basePath, i)),
252254
excludes: (parsedTsConfig.config.excludes ?? []).map((e) => join(basePath, e)),
@@ -259,6 +261,7 @@ export function readConfigFile(project: string): CMKConfig {
259261
configFileName,
260262
compilerOptions: parsedTsConfig.compilerOptions,
261263
wildcardDirectories: parsedTsConfig.wildcardDirectories,
264+
extendedSourceFiles: parsedTsConfig.extendedSourceFiles ?? [],
262265
diagnostics: parsedTsConfig.diagnostics,
263266
};
264267
}

packages/core/src/test/faker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function fakeConfig(args?: Partial<CMKConfig>): CMKConfig {
1616
compilerOptions: {},
1717
wildcardDirectories: [{ fileName: '/app', recursive: true }],
1818
diagnostics: [],
19+
extendedSourceFiles: [],
1920
...args,
2021
};
2122
}

0 commit comments

Comments
 (0)