Skip to content

Commit

Permalink
fix: fix a problem with resolving swc configs
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed Nov 17, 2021
1 parent c791d88 commit 677c928
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/transpiler/swc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ export interface GetSwcConfigOptions {

export type SwcConfigFactory = (filename: string) => Options | undefined;

function readConfig(config: TypescriptPluginSwcOptions["swcConfig"] = `.swcrc`, cwd: string, fileSystem: TS.System): SwcConfig {
if (typeof config === "string") {
function readConfig(config: TypescriptPluginSwcOptions["swcConfig"], cwd: string, fileSystem: TS.System): SwcConfig {
if (config == null) {
const absoluteConfig = path.normalize(path.join(cwd, `.swcrc`));
if (!fileSystem.fileExists(absoluteConfig)) {
return {};
}
return JSON.parse(fileSystem.readFile(absoluteConfig)!);
} else if (typeof config === "string") {
const absoluteConfig = path.normalize(path.isAbsolute(config) ? config : path.join(cwd, config));
if (!fileSystem.fileExists(absoluteConfig)) {
throw new ReferenceError(`Could not find swc config at path: ${config}`);
Expand Down

0 comments on commit 677c928

Please sign in to comment.