Skip to content

Commit

Permalink
fix: load the tsconfig extends with the specific extension name (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenPt authored Feb 4, 2025
1 parent f396e5f commit 2bbc458
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
},
"devDependencies": {
"@eggjs/tsconfig": "^1.0.0",
"@tsconfig/node14": "^14.1.2",
"@types/commander": "^2.12.2",
"@types/del": "^3.0.0",
"@types/globby": "^6.1.0",
Expand Down
10 changes: 6 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,13 @@ export function loadTsConfig(tsconfigPath: string): ts.CompilerOptions {
path.resolve(tsconfigDirName, extendPattern),
path.resolve(tsconfigDirName, `${extendPattern}.json`),
];

if (!path.extname(tsConfig.extends) && !extendPattern.startsWith('.') && !extendPattern.startsWith('/')) {
const isExtendFromNodeModules = !extendPattern.startsWith('.') && !extendPattern.startsWith('/');
if (isExtendFromNodeModules) {
const DEFAULT_TS_CONFIG_FILE_NAME = 'tsconfig.json';
const extendTsConfigPath = !path.extname(extendPattern) ? DEFAULT_TS_CONFIG_FILE_NAME : '';
maybeRealExtendPath.push(
path.resolve(tsconfigDirName, 'node_modules', extendPattern, 'tsconfig.json'),
path.resolve(process.cwd(), 'node_modules', extendPattern, 'tsconfig.json'),
path.resolve(tsconfigDirName, 'node_modules', extendPattern, extendTsConfigPath),
path.resolve(process.cwd(), 'node_modules', extendPattern, extendTsConfigPath),
);
}

Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/test-tsconfig/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@tsconfig/node14/tsconfig.json"
}
5 changes: 5 additions & 0 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,10 @@ describe('utils.test.ts', () => {
const tsConfig2 = utils.loadTsConfig(path.resolve(__dirname, './fixtures/test-tsconfig/tsconfig.json'));
assert(tsConfig2);
assert(tsConfig2.skipLibCheck);

const tsConfig3 = utils.loadTsConfig(path.resolve(__dirname, './fixtures/test-tsconfig/tsconfig.node.json'));
assert(tsConfig3);
assert(tsConfig3.strict);
assert(tsConfig3.skipLibCheck);
});
});

0 comments on commit 2bbc458

Please sign in to comment.