Closed ComLock closed 10 months ago
Perhaps use 'writeFileSync' here: https://github.com/jfortunato/esbuild-plugin-manifest/blob/develop/src/index.ts#LL124C14-L124C35
ref https://nodejs.org/api/fs.html#fswritefilesyncfile-data-options
'as' is interesting, but there is no 'ws'? https://nodejs.org/api/fs.html#file-system-flags
Side note: I even add some of my own entries https://github.com/enonic/starter-tsup/blob/6e12022809b5c589d5535021ceb1bec59eaf7a08/tsup/static.ts#L26-L29
I guess it has to stay asyncronous https://esbuild.github.io/plugins/#on-resolve
So a different solution would be to allow setting filename based on a function which has format in it's context...
Made this since it got silent: https://www.npmjs.com/package/@enonic/tsup-plugin-manifest
The format
https://esbuild.github.io/api/#format option for esbuild only allows you to specify 1 format at a time, so specifying format: ['cjs','esm']
wouldn't be valid when using esbuild on its own. (Looks like you got that from tsup)
To support multiple formats like this using esbuild on its own, you can utilize a combination of esbuilds outExtension
option along with esbuild-plugin-manifests append
option, like the example here: https://github.com/jfortunato/esbuild-plugin-manifest#multiple-formats
I'm using
format: ['cjs','esm']
Which executes the manifestPlugin twice and the last result ends up in the file.
I did a hacky workaround by keeping an external obj and returning that: https://github.com/enonic/starter-tsup/blob/c800b77027d9d114c85f894fc286b821a66dcdc5/tsup/static.ts#L54 https://github.com/enonic/starter-tsup/blob/c800b77027d9d114c85f894fc286b821a66dcdc5/tsup/static.ts#L76
Which means the last write to the file contains a "merged" result.
But quite often the file gets corrupt and contains an extra curly end bracket (probably some race condition, no write lock?):
If would be nice if this plugins would make a single "merged" manifest file, or at least have a write lock.