Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc49386c

Browse files
authored
feat(tsconfig-loader): extends config from node_modules without './node_modules' prefix (#106)
1 parentf289c99 commitc49386c

File tree

2 files changed

+58
-6
lines changed

2 files changed

+58
-6
lines changed

‎src/tsconfig-loader.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,22 @@ export function loadTsconfig(
120120
){
121121
extendedConfig+=".json";
122122
}
123-
124123
constcurrentDir=path.dirname(configFilePath);
124+
letextendedConfigPath=path.join(currentDir,extendedConfig);
125+
if(
126+
extendedConfig.indexOf("/")!==-1&&
127+
extendedConfig.indexOf(".")!==-1&&
128+
!existsSync(extendedConfigPath)
129+
){
130+
extendedConfigPath=path.join(
131+
currentDir,
132+
"node_modules",
133+
extendedConfig
134+
);
135+
}
136+
125137
constbase=
126-
loadTsconfig(
127-
path.join(currentDir,extendedConfig),
128-
existsSync,
129-
readFileSync
130-
)||{};
138+
loadTsconfig(extendedConfigPath,existsSync,readFileSync)||{};
131139

132140
// baseUrl should be interpreted as relative to the base tsconfig,
133141
// but we need to update it so it is relative to the original tsconfig being loaded

‎test/tsconfig-loader-tests.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,50 @@ describe("loadConfig", () => {
168168
});
169169
});
170170

171+
it("It should load a config with extends from node_modules and overwrite all options",()=>{
172+
constfirstConfig={
173+
extends:"my-package/base-config.json",
174+
compilerOptions:{baseUrl:"kalle",paths:{foo:["bar2"]}}
175+
};
176+
constfirstConfigPath=join("/root","dir1","tsconfig.json");
177+
constbaseConfig={
178+
compilerOptions:{
179+
baseUrl:"olle",
180+
paths:{foo:["bar1"]},
181+
strict:true
182+
}
183+
};
184+
constbaseConfigPath=join(
185+
"/root",
186+
"dir1",
187+
"node_modules",
188+
"my-package",
189+
"base-config.json"
190+
);
191+
constres=loadTsconfig(
192+
join("/root","dir1","tsconfig.json"),
193+
path=>path===firstConfigPath||path===baseConfigPath,
194+
path=>{
195+
if(path===firstConfigPath){
196+
returnJSON.stringify(firstConfig);
197+
}
198+
if(path===baseConfigPath){
199+
returnJSON.stringify(baseConfig);
200+
}
201+
return"";
202+
}
203+
);
204+
205+
assert.deepEqual(res,{
206+
extends:"my-package/base-config.json",
207+
compilerOptions:{
208+
baseUrl:"kalle",
209+
paths:{foo:["bar2"]},
210+
strict:true
211+
}
212+
});
213+
});
214+
171215
it("Should use baseUrl relative to location of extended tsconfig",()=>{
172216
constfirstConfig={compilerOptions:{baseUrl:"."}};
173217
constfirstConfigPath=join("/root","first-config.json");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp