use unique temp entry files for bundles
This commit is contained in:
@@ -91,35 +91,27 @@ globalThis.__readability = { Readability, isProbablyReaderable }
|
|||||||
|
|
||||||
async function buildBundle(config: BundleConfig): Promise<void> {
|
async function buildBundle(config: BundleConfig): Promise<void> {
|
||||||
const startTime = Date.now()
|
const startTime = Date.now()
|
||||||
const entrypoint =
|
const entryPathConfig: { entryPath: string; cleanupEntry: boolean } = (() => {
|
||||||
config.type === 'source' ? path.join(srcDir, config.entry) : `virtual:${config.name}`
|
if (config.type === 'source') {
|
||||||
const plugins =
|
return {
|
||||||
config.type === 'source'
|
entryPath: path.join(srcDir, config.entry),
|
||||||
? []
|
cleanupEntry: false,
|
||||||
: [
|
}
|
||||||
{
|
}
|
||||||
name: `virtual-${config.name}`,
|
|
||||||
setup(build) {
|
// Create temporary entry file for wrapper bundles
|
||||||
const filter = new RegExp(`^virtual:${config.name}$`)
|
const entrySuffix = `${process.pid}-${Date.now()}`
|
||||||
build.onResolve({ filter }, (args) => {
|
const entryPath = path.join(distDir, `_${config.name}-entry-${entrySuffix}.js`)
|
||||||
return {
|
fs.writeFileSync(entryPath, config.code)
|
||||||
path: args.path,
|
return {
|
||||||
namespace: 'virtual',
|
entryPath,
|
||||||
}
|
cleanupEntry: true,
|
||||||
})
|
}
|
||||||
build.onLoad({ filter, namespace: 'virtual' }, () => {
|
})()
|
||||||
return {
|
const { entryPath, cleanupEntry } = entryPathConfig
|
||||||
contents: config.code,
|
|
||||||
loader: 'js',
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
const result = await Bun.build({
|
const result = await Bun.build({
|
||||||
entrypoints: [entrypoint],
|
entrypoints: [entryPath],
|
||||||
plugins,
|
|
||||||
target: 'browser',
|
target: 'browser',
|
||||||
format: 'iife',
|
format: 'iife',
|
||||||
define: {
|
define: {
|
||||||
@@ -127,6 +119,11 @@ async function buildBundle(config: BundleConfig): Promise<void> {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Cleanup temporary entry file
|
||||||
|
if (cleanupEntry && fs.existsSync(entryPath)) {
|
||||||
|
fs.unlinkSync(entryPath)
|
||||||
|
}
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
console.error(`Bundle errors for ${config.name}:`, result.logs)
|
console.error(`Bundle errors for ${config.name}:`, result.logs)
|
||||||
throw new Error(`Failed to bundle ${config.name}`)
|
throw new Error(`Failed to bundle ${config.name}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user