-
Notifications
You must be signed in to change notification settings - Fork 56
fix: fix error when bundling multiple outputs #16
Conversation
This fixes an error that occurs when multiple outputs are specified for bundling. Reason: - jest-worker was not cleaned up properly Fixes #5
@@ -15,13 +15,18 @@ function terser(userOptions = {}) { | |||
}) | |||
); | |||
|
|||
let numOfBundles = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use plugin context instead of closure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing out plugin context. I didn't know it exists.
However, trying it out (basically attaching numOfBundles
to this
), makes the test hang, because an async operation is not cleaned up properly (worker is not cleaned up properly).
Could you please point me in the right direction or implement it yourself?
The only docs I've found on the context api is this: https://rollupjs.org/guide/en#context
However, it does not mention use of custom data.
I am also just curious why using context api is better than closure?
I am thankful for any clarification. 😊
let numOfBundles = 0; | |
return { | |
name: "terser", | |
renderStart() { | |
if (!this.worker) { | |
this.worker = new Worker(require.resolve("./transform.js"), { | |
numWorkers: userOptions.numWorkers | |
}); | |
this.numOfBundles = 0; | |
} | |
this.numOfBundles++; | |
}, | |
renderChunk(code) { | |
return this.worker.transform(code, minifierOptions).catch(error => { | |
const { message, line, col: column } = error; | |
console.error( | |
codeFrameColumns(code, { start: { line, column } }, { message }) | |
); | |
throw error; | |
}); | |
}, | |
generateBundle() { | |
this.numOfBundles--; | |
// we only want to end worker on the last bundle | |
if (this.numOfBundles == 0) { | |
this.worker.end(); | |
} | |
}, | |
renderError() { | |
this.numOfBundles--; | |
// we only want to end worker on the last bundle | |
if (this.numOfBundles == 0) { | |
this.worker.end(); | |
} | |
} | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context exists per build run. Closure exists for all usages. For example if plugin instance is used for a few builds we may get unexpected results.
const t = terser()
[
{
plugins: [t]
},
{
plugins: [t]
}
]
Also worker instance is already used in this way.
@TrySound Please tell me what I should do, so that this can be merged (see also comment above). |
Close in favour of #19 |
This fixes an error that occurs when multiple outputs are specified
for bundling.
Reason:
Fixes #5