Skip to content

fix: create the parent directory of --lua-output-file#67

Merged
Unisay merged 1 commit into
mainfrom
issue-61/mkdir-output-parent
Jun 14, 2026
Merged

fix: create the parent directory of --lua-output-file#67
Unisay merged 1 commit into
mainfrom
issue-61/mkdir-output-parent

Conversation

@Unisay

@Unisay Unisay commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Closes #61.

pslua opened the output file with withFile ... WriteMode, which does not create the parent directory. Passing --lua-output-file dist/X.lua when dist/ is absent (a gitignored output dir, say) aborted with withFile: does not exist. Every fork's build script had to work around it with mkdir -p.

This adds a small helper, Language.PureScript.Backend.Output.withOutputFile, that runs ensureDir on 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.lua into directories that did not exist.

Once this is released, forks can drop their mkdir -p dist lines (tracked in the assert fork, #59).

@Unisay Unisay self-assigned this Jun 14, 2026
@Unisay Unisay requested a review from Copilot June 14, 2026 13:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.withOutputFile to create the parent directory before opening a file for writing.
  • Route Lua chunk output plus optional IR and Lua AST dumps in exe/Main.hs through withOutputFile.
  • 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.

@Unisay Unisay merged commit 116c3af into main Jun 14, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pslua does not create the parent directory of --lua-output-file

2 participants