peggyjs / peggy

Peggy: Parser generator for JavaScript
https://peggyjs.org/
MIT License
906 stars 64 forks source link

`-o dist/my-parser.js` errors if `dist/` doesn't exist #440

Closed jcbhmr closed 6 months ago

jcbhmr commented 11 months ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch peggy@3.0.2 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/peggy/bin/peggy-cli.js b/node_modules/peggy/bin/peggy-cli.js
index b3130a0..0107699 100644
--- a/node_modules/peggy/bin/peggy-cli.js
+++ b/node_modules/peggy/bin/peggy-cli.js
@@ -439,6 +439,7 @@ class PeggyCLI extends Command {
       return Promise.resolve(hasTest ? this.std.out : null);
     }
     return new Promise((resolve, reject) => {
+      fs.mkdirSync(path.dirname(this.outputFile), { recursive: true });
       const outputStream = fs.createWriteStream(this.outputFile);
       outputStream.on("error", reject);
       outputStream.on("open", () => resolve(outputStream));

This issue body was partially generated by patch-package.