Skip to content

fix(cli): create output directory if it doesn't exist#1445

Open
lamine2000 wants to merge 1 commit into
OpenFn:mainfrom
lamine2000:fix/output-path-mkdir-859
Open

fix(cli): create output directory if it doesn't exist#1445
lamine2000 wants to merge 1 commit into
OpenFn:mainfrom
lamine2000:fix/output-path-mkdir-859

Conversation

@lamine2000
Copy link
Copy Markdown

@lamine2000 lamine2000 commented Jun 5, 2026

Summary

Fixes #859. The compile and collections get commands threw ENOENT when --output-path pointed to a directory that hadn't been created yet, forcing users to manually mkdir before running the CLI.

  • compile/handler.ts: added await mkdir(dirname(outputPath), { recursive: true }) before writeFile
  • collections/handler.ts: same fix in the get command's output branch

The execute command's serialize-output.ts already had this pattern — this PR brings the other two commands in line with it.

Test plan

  • openfn compile job.js -o new/nested/dir/out.js — should create new/nested/dir/ and write the file
  • openfn collections get myCollection myKey -o new/nested/dir/out.json — same
  • Both commands still work normally when the output directory already exists

Closes #859

@josephjclark
Copy link
Copy Markdown
Collaborator

Thanks @lamine2000 . There's a failing test here that needs resolving. Also this branch includes your other work. Please rebase against main so that this PR is nice and clean. Thank you!

The compile and collections commands threw ENOENT when --output-path
pointed to a directory that hadn't been created yet. Add
mkdir({ recursive: true }) before writeFile in both handlers, matching
the pattern already used in the execute command's serialize-output.ts.

Fixes OpenFn#859
@lamine2000 lamine2000 force-pushed the fix/output-path-mkdir-859 branch from e34452a to 5686653 Compare June 6, 2026 09:16
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.

CLI: don't throw if output path doesn't exist

2 participants