Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command-line -t requires from wrong directory #211

Closed
hildjj opened this issue Nov 18, 2021 · 0 comments
Closed

Command-line -t requires from wrong directory #211

hildjj opened this issue Nov 18, 2021 · 0 comments
Assignees
Labels
blocks-release Blocks an imminent release. High Priorty.

Comments

@hildjj
Copy link
Contributor

hildjj commented Nov 18, 2021

In a directory other than <PEGGY_ROOT>/bin, this fails:

touch ast.js
echo '{{ require("./ast.js") }}\nfoo="1"' | peggy -t 1

the eval at the heart of the test routine is relative to the CLI script. I think there's a similar issue when we have {output: "parser"} in the API.

Some combination of vm and require("module").createRequire (when it's available) might be needed. Probably also making __dirname and __filename match the outputFile if it's not "-", and using cwd and a synthetic name when it is "-".

In node 10, createRequire doesn't exist, but the undocumented createRequireFromPath does, as well as new Module(path).require.

I don't know how to fix this for import, but we can probably at least hack in import.meta.url same as __filename.

@hildjj hildjj self-assigned this Nov 18, 2021
@hildjj hildjj added the blocks-release Blocks an imminent release. High Priorty. label Nov 18, 2021
hildjj added a commit to hildjj/peggy that referenced this issue Nov 22, 2021
…utput JS (if one exists) or cwd if reading stdin. Fixes peggyjs#211.
@hildjj hildjj mentioned this issue Nov 22, 2021
@hildjj hildjj closed this as completed in fc23cf4 May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocks-release Blocks an imminent release. High Priorty.
Projects
None yet
Development

No branches or pull requests

1 participant