Skip to content

Commit

Permalink
fix: throw when SHOW_CONFIG_FOR is not a regular file
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jul 2, 2020
1 parent a42949a commit edbe64d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/babel-core/src/config/files/configuration.js
Expand Up @@ -305,10 +305,13 @@ export function* resolveShowConfigPath(
const targetPath = process.env.BABEL_SHOW_CONFIG_FOR;
if (targetPath != null) {
const absolutePath = path.resolve(dirname, targetPath);
if (yield* fs.exists(absolutePath)) {
return absolutePath;
const stats = yield* fs.stat(absolutePath);
if (!stats.isFile()) {
throw new Error(
`${absolutePath}: BABEL_SHOW_CONFIG_FOR must refers to a regular file, directory is not supported.`,
);
}
throw new Error(`${absolutePath}: The show config path does not exist.`);
return absolutePath;
}
return null;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/babel-core/src/gensync-utils/fs.js
Expand Up @@ -19,3 +19,8 @@ export const exists = gensync<[string], boolean>({
},
errback: (path, cb) => fs.access(path, undefined, err => cb(null, !err)),
});

export const stat = gensync<[string], *>({
sync: fs.statSync,
errback: fs.stat,
});

0 comments on commit edbe64d

Please sign in to comment.