Skip to content

Commit 5390e4b

Browse files
committed
Just get the compiler options
1 parent 0f8f7d8 commit 5390e4b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

dash/extract-meta.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ const reservedPatterns = args[1]
2121
? args[1].split('|').map(part => new RegExp(part))
2222
: [];
2323

24-
let tsconfig = {};
25-
2624
function help() {
2725
console.error('usage: ');
2826
console.error(
@@ -36,8 +34,15 @@ if (!src.length) {
3634
process.exit(1);
3735
}
3836

39-
if (fs.existsSync('tsconfig.json')) {
40-
tsconfig = ts.getParsedCommandLineOfConfigFile('tsconfig.json', { esModuleInterop: true }, ts.sys);
37+
function getTsConfigCompilerOptions() {
38+
// Since extract-meta can be run on JavaScript sources, if trying to get the
39+
// config doesn't work, we can fall back gracefully.
40+
try {
41+
const tsconfig = ts.getParsedCommandLineOfConfigFile('tsconfig.json', { esModuleInterop: true }, ts.sys);
42+
return tsconfig?.options ?? {};
43+
} catch {
44+
return {};
45+
}
4146
}
4247

4348
let failedBuild = false;
@@ -187,7 +192,7 @@ function gatherComponents(sources, components = {}) {
187192
return components;
188193
}
189194

190-
const program = ts.createProgram(filepaths, tsconfig);
195+
const program = ts.createProgram(filepaths, getTsConfigCompilerOptions());
191196
const checker = program.getTypeChecker();
192197

193198
const coerceValue = t => {

0 commit comments

Comments
 (0)