Skip to content

Commit

Permalink
fix: Handle module paths pointing to a directory
Browse files Browse the repository at this point in the history
  • Loading branch information
palant committed Oct 29, 2024
1 parent 1dbd3f3 commit f6d9559
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ export function readScript(filepath)

export function saveScript(ast, filepath)
{
ensureParentDirExists(filepath);

let stat = fs.statSync(filepath, {throwIfNoEntry: false});
if (stat && stat.isDirectory())
{
saveScript(ast, path.join(filepath, "index.js"));
return;
}

let code = astToCode(ast, {
format: {
indent: {
Expand All @@ -64,6 +73,5 @@ export function saveScript(ast, filepath)
comment: true
});

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

0 comments on commit f6d9559

Please sign in to comment.