Skip to content

Add support for imported exports #100

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,12 @@ loader.pitch = function(request) {

let key = entries[0].entryModule.nameForCondition();
let contents = compilation.assets[worker.file].source();
let exports = Object.keys(CACHE[key] || {});
let exports = Array.from(
new Set([
...Object.keys(CACHE[key] || {}),
...entries[0].entryModule.buildMeta.providedExports
])
);

// console.log('Workerized exports: ', exports.join(', '));

Expand Down
9 changes: 9 additions & 0 deletions test/src/and-the-other.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function otherOtherFoo() {
return 2;
}

export function anyFoo() {
return 4;
}

export const otherOtherBar = 3;
3 changes: 3 additions & 0 deletions test/src/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.tragedy = function tragedy() {
return 'common';
};
21 changes: 21 additions & 0 deletions test/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,33 @@ describe('worker', () => {

it('should be an instance of Worker', () => {
worker = new Worker();
// eslint-disable-next-line jest/no-jasmine-globals
expect(worker).toEqual(jasmine.any(window.Worker));
});

it('worker.foo()', async () => {
expect(await worker.foo()).toBe(1);
});

it('worker.otherFoo()', async () => {
expect(await worker.otherFoo()).toBe(-1);
});

it('worker.otherOtherFoo()', async () => {
expect(await worker.otherOtherFoo()).toBe(2);
});
it('worker.andTheOtherFoo()', async () => {
expect(await worker.andTheOtherFoo()).toBe(2);
});

it('worker.anyFoo()', async () => {
expect(await worker.anyFoo()).toBe(4);
});

it('worker.tragedy()', async () => {
expect(await worker.tragedy()).toBe('common');
});

it('worker.bar()', async () => {
let out = await worker.bar('a', 'b');
expect(out).toEqual('a [bar:3] b');
Expand Down Expand Up @@ -102,6 +122,7 @@ describe('?import option', () => {

it('should be an instance of Worker', () => {
worker = new ImportWorker();
// eslint-disable-next-line jest/no-jasmine-globals
expect(worker).toEqual(jasmine.any(window.Worker));
});

Expand Down
6 changes: 4 additions & 2 deletions test/src/other.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export function otherFoo() {}
export function otherFoo() {
return -1;
}

export const otherBar = 3;
export const otherBar = 3;
6 changes: 6 additions & 0 deletions test/src/worker.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { otherFoo, otherBar } from './other';

export { otherFoo };
export { otherOtherFoo as andTheOtherFoo } from './and-the-other';
export * from './and-the-other';

export { tragedy } from './common.js';

export function foo() {
return 1;
}

export const value = 3;

export function throwError() {
throw new Error('Error in worker.js');
}
Expand Down