Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the plugin work for SharedWorker #49

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ export default class WorkerPlugin {
for (const type of JS_TYPES) {
factory.hooks.parser.for(`javascript/${type}`).tap(NAME, parser => {
parser.hooks.new.for('imported var').tap(NAME, expr => {
if (expr.callee.name !== 'Worker') return false
if (expr.callee.name !== 'Worker' && expr.callee.name !== 'SharedWorker') return false

const dep = parser.evaluateExpression(expr.arguments[0]);

if (!dep.isString()) {
parser.state.module.warnings.push({
message: 'new Worker() will only be bundled if passed a String.'
message: 'new Worker() and new SharedWorker() will only be bundled if passed a String.'
});
return false;
}
Expand Down Expand Up @@ -95,7 +95,7 @@ export default class WorkerPlugin {
'No instantiations of threads.js workers found.\n' +
'Please check that:\n' +
' 1. You have configured Babel / TypeScript to not transpile ES modules\n' +
' 2. You import `Worker` from `threads` where you use it\n\n' +
' 2. You import `Worker` or `SharedWorker` from `threads` where you use it\n\n' +
'For more details see: https://github.com/andywer/threads-plugin\n'
})
}
Expand Down