fix: create the parent directory of --lua-output-file#67
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the pslua CLI’s file output behavior by ensuring the parent directory for --lua-output-file (and related optional outputs) exists before opening output handles, eliminating the need for downstream mkdir -p workarounds.
Changes:
- Add
Language.PureScript.Backend.Output.withOutputFileto create the parent directory before opening a file for writing. - Route Lua chunk output plus optional IR and Lua AST dumps in
exe/Main.hsthroughwithOutputFile. - Add an Hspec unit test that writes to a nested, non-existent path under a temp dir and asserts the file is created.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/Main.hs | Registers the new Output spec in the Hspec test runner. |
| test/Language/PureScript/Backend/Output/Spec.hs | Adds a unit test verifying withOutputFile creates missing parent directories. |
| pslua.cabal | Exposes the new output helper module and includes the new test module in the spec suite. |
| lib/Language/PureScript/Backend/Output.hs | Introduces withOutputFile which ensureDirs the parent and then opens the file in WriteMode. |
| exe/Main.hs | Uses withOutputFile for Lua output, IR dump, and Lua AST dump to avoid failures when output directories don’t exist. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #61.
psluaopened the output file withwithFile ... WriteMode, which does not create the parent directory. Passing--lua-output-file dist/X.luawhendist/is absent (a gitignored output dir, say) aborted withwithFile: does not exist. Every fork's build script had to work around it withmkdir -p.This adds a small helper,
Language.PureScript.Backend.Output.withOutputFile, that runsensureDiron the parent before opening the handle, and routes all three CLI outputs (the Lua chunk, the optional IR dump, the optional Lua AST dump) through it. They share one directory, so the parent is ensured once per run.Test: a unit spec writes to a nested non-existent path under a temp dir and asserts the file appears. End-to-end, the built binary now writes
--lua-output-file /tmp/a/b/c/out.luainto directories that did not exist.Once this is released, forks can drop their
mkdir -p distlines (tracked in the assert fork, #59).