Skip to content

Commit

Permalink
refactor: Simplify integration between bundleWorkerEntry() and emitSo…
Browse files Browse the repository at this point in the history
…urcemapForWorkerEntry()
  • Loading branch information
KallynGowdy committed Mar 28, 2022
1 parent 4df4452 commit 72fa5c0
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions packages/vite/src/node/plugins/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,15 @@ export async function bundleWorkerEntry(
},
preserveEntrySignatures: false
})
let code: string
let sourcemap: Rollup.SourceMap | undefined
let buffer: Buffer
let chunk: Rollup.OutputChunk
try {
const {
output: [outputCode, ...outputChunks]
output: [outputChunk, ...outputChunks]
} = await bundle.generate({
format,
sourcemap: config.build.sourcemap
})
code = outputCode.code
sourcemap = outputCode.map

buffer = emitSourcemapForWorkerEntry(
ctx,
config,
id,
query,
code,
sourcemap
)
chunk = outputChunk
outputChunks.forEach((outputChunk) => {
if (outputChunk.type === 'asset') {
ctx.emitFile(outputChunk)
Expand All @@ -69,7 +57,7 @@ export async function bundleWorkerEntry(
} finally {
await bundle.close()
}
return buffer
return emitSourcemapForWorkerEntry(ctx, config, id, query, chunk)
}

export interface EmitResult {
Expand All @@ -81,9 +69,9 @@ function emitSourcemapForWorkerEntry(
config: ResolvedConfig,
id: string,
query: Record<string, string> | null,
code: string,
sourcemap: Rollup.SourceMap | undefined
chunk: Rollup.OutputChunk
): Buffer {
let { code, map: sourcemap } = chunk
if (sourcemap) {
if (config.build.sourcemap === 'inline') {
// Manually add the sourcemap to the code if configured for inline sourcemaps.
Expand Down

0 comments on commit 72fa5c0

Please sign in to comment.