Skip to content

Commit f6d9559

Browse files
committed
fix: Handle module paths pointing to a directory
1 parent 1dbd3f3 commit f6d9559

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/io.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ export function readScript(filepath)
5353

5454
export function saveScript(ast, filepath)
5555
{
56+
ensureParentDirExists(filepath);
57+
58+
let stat = fs.statSync(filepath, {throwIfNoEntry: false});
59+
if (stat && stat.isDirectory())
60+
{
61+
saveScript(ast, path.join(filepath, "index.js"));
62+
return;
63+
}
64+
5665
let code = astToCode(ast, {
5766
format: {
5867
indent: {
@@ -64,6 +73,5 @@ export function saveScript(ast, filepath)
6473
comment: true
6574
});
6675

67-
ensureParentDirExists(filepath);
6876
fs.writeFileSync(filepath, code, {encoding: "utf-8"});
6977
}

0 commit comments

Comments
 (0)