Skip to content

Commit

Permalink
fix: esbuild emitFile should mkdir subdirectories too (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
edemaine authored Feb 22, 2024
1 parent 3ef83de commit b73e16a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/esbuild/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ export function createBuildContext(initialOptions: BuildOptions): UnpluginBuildC
throw new Error('unplugin/esbuild: addWatchFile outside supported hooks (resolveId, load, transform)')
},
emitFile(emittedFile) {
// Ensure output directory exists for this.emitFile
if (initialOptions.outdir && !fs.existsSync(initialOptions.outdir))
fs.mkdirSync(initialOptions.outdir, { recursive: true })

const outFileName = emittedFile.fileName || emittedFile.name
if (initialOptions.outdir && emittedFile.source && outFileName)
fs.writeFileSync(path.resolve(initialOptions.outdir, outFileName), emittedFile.source)
if (initialOptions.outdir && emittedFile.source && outFileName) {
const outPath = path.resolve(initialOptions.outdir, outFileName)
// Ensure output directory exists for this.emitFile
const outDir = path.dirname(outPath)
if (!fs.existsSync(outDir))
fs.mkdirSync(outDir, { recursive: true })
fs.writeFileSync(outPath, emittedFile.source)
}
},
getWatchFiles() {
return watchFiles
Expand Down

0 comments on commit b73e16a

Please sign in to comment.