Conversation
🦋 Changeset detectedLatest commit: 8f28ecc The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
- Use the same function names as in TypeScript - To prevent the function from being redefined every time `readConfigFile` is executed
- Users can also specify a path for `cmkOptions.dtsOutDir`. They would likely expect `${configDir}` to be supported there as well.
| const result = readConfigFile(iff.join('app')); | ||
| expect(result.includes).toEqual([iff.join('src')]); | ||
| expect(result.excludes).toEqual([iff.join('dist')]); | ||
| expect(result.dtsOutDir).toBe(iff.join('generated')); |
There was a problem hiding this comment.
Currently, this test fails. There seems to be a bug. I’ll fix it later, so I’ll leave it as is in this pull request.
FAIL unit packages/core/src/config.test.ts > readConfigFile > inheritance > resolves relative paths against the defining tsconfig directory
AssertionError: expected '/var/folders/1b/v674402d0n1d90hz22pbz…' to be '/var/folders/1b/v674402d0n1d90hz22pbz…' // Object.is equality
Expected: "/var/folders/1b/v674402d0n1d90hz22pbz_tr0000gn/T/css-modules-kit/12/da8a9946-a88c-4612-920f-a8e84e4a23eb/generated"
Received: "/var/folders/1b/v674402d0n1d90hz22pbz_tr0000gn/T/css-modules-kit/12/da8a9946-a88c-4612-920f-a8e84e4a23eb/app/generated"
❯ packages/core/src/config.test.ts:292:32
290| expect(result.includes).toEqual([iff.join('src')]);
291| expect(result.excludes).toEqual([iff.join('dist')]);
292| expect(result.dtsOutDir).toBe(iff.join('generated'));
| ^
293| });
294| });
❯ node_modules/.pnpm/@voidzero-dev+vite-plus-test@0.1.16_@types+node@25.5.2_esbuild@0.27.7_tsx@4.21.0_typesc_d9d6de7afd15cc08c9d54a997cfe644c/node_modules/@voidzero-dev/vite-plus-test/dist/@vitest/runner/chunk-artifact.js:1893:22
There was a problem hiding this comment.
The JSON content is passed through convertToJson(), which reads from getTsconfigRootOptionsMap() via parseOwnConfigOfJsonSourceFile(). Only options that are declared to be paths (look for isFilePath: true and .isFilePath in commandLineParser.ts) get the special treatment.
I tried this hack, to no avail:
const tsConfigSourceFile = ts.readJsonConfigFile(fileName, path => {
const originalContent = ts.sys.readFile(path);
let parsed: unknown;
try {
parsed = JSON.parse(originalContent ?? '');
} catch {
return originalContent;
}
if (typeof parsed === 'object' && parsed !== null && 'cmkOptions' in parsed) {
let compilerOptions: { cmkOptions?: any };
if ('compilerOptions' in parsed) {
if (typeof parsed.compilerOptions !== 'object' || parsed.compilerOptions === null) {
console.log('compo2')
return originalContent;
}
compilerOptions = parsed.compilerOptions;
} else {
compilerOptions = {};
Object.assign(parsed, { compilerOptions });
}
compilerOptions!.cmkOptions = parsed.cmkOptions;
}
return JSON.stringify(parsed, null, ' ');
});
if ('optionsDeclaration' in ts && ts.optionsDeclaration instanceof Array) {
ts.optionsDeclaration.push({
name: 'cmkOptions',
type: 'object',
elementOptions: new Map(Object.entries({
'dtsOutDir': {
name: 'dtsOutDir',
type: 'string',
isFilePath: true
}
}))
});
} All subcomponents of _tsconfigRootOptions, compilerOptions included, are built at import time, so it was too late.
mizdra
left a comment
There was a problem hiding this comment.
LGTM! Thank you for contributing!
Resolves #368.
Included and excluded paths using
${configDir}are now resolved correctly. The variable, recognized only if placed at the very start, is case-insensitively replaced with./; the path is then joined with the base directory's path as usual.