Skip to content

Commit c912910

Browse files
authored
fix: plugin crash when import does not exist
This prevents the VSCode plugin from crashing when an imported css/scss/etc... file does not exist.
1 parent d722951 commit c912910

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/helpers/getDtsSnapshot.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@ export const getDtsSnapshot = (
1515
compilerOptions: tsModule.CompilerOptions,
1616
directory: string,
1717
): tsModule.IScriptSnapshot => {
18-
const css = readFileSync(fileName, 'utf-8');
19-
const cssExports = getCssExports({
20-
css,
21-
fileName,
22-
logger,
23-
options,
24-
processor,
25-
compilerOptions,
26-
directory,
27-
});
28-
const dts = createDtsExports({ cssExports, fileName, logger, options });
29-
return ts.ScriptSnapshot.fromString(dts);
18+
try {
19+
const css = readFileSync(fileName, 'utf-8');
20+
const cssExports = getCssExports({
21+
css,
22+
fileName,
23+
logger,
24+
options,
25+
processor,
26+
compilerOptions,
27+
directory,
28+
});
29+
const dts = createDtsExports({ cssExports, fileName, logger, options });
30+
return ts.ScriptSnapshot.fromString(dts);
31+
}
32+
catch (e) {
33+
logger.error(e);
34+
}
3035
};

0 commit comments

Comments
 (0)