maxmilton / esbuild-minify-templates

Minify template literal strings as part of an esbuild powered build process.
MIT License
13 stars 1 forks source link

`writeFiles` fails when target file is under a directory that doesn't exist #92

Closed ykrasik closed 2 years ago

ykrasik commented 2 years ago

Hi, great lib!

There's an issue where writeFiles will fail if the directory of the output file doesn't exist. For example, if buildResult.outputFiles.path=src/index.js, and src doesn't exist, it will fail at runtime.

The solution is to call fs.promises.mkdir(..., { recursive: true }) before writing the files.

maxmilton commented 2 years ago

Thanks for bringing this up!

For some reason I was under the impression that esbuild throws an error when the output directory doesn't exist so I was matching that behaviour... but a quick experiment proved me wrong! Builds using esbuild CLI and programmatically both create the output directories as needed.

Added a fix for this. I've got a few other things I'd like changed so once those are in I'll create a new release.

maxmilton commented 2 years ago

Included in the now published https://github.com/maxmilton/esbuild-minify-templates/releases/tag/v0.6.0

ykrasik commented 2 years ago

Awesome, thank you!