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

Fix SW packaging in web extensions #8424

Merged
merged 2 commits into from Oct 24, 2022

Conversation

olistic
Copy link
Contributor

@olistic olistic commented Aug 28, 2022

↪️ Pull Request

This PR fixes the packaging of Service Workers using ES Modules in the webextension config.

The JS transform does not support ES Modules for service workers:

context: 'service-worker',
sourceType: dep.source_type === 'Module' ? 'module' : 'script',
outputFormat: 'global', // TODO: module service worker support

Instead, it sets outputFormat to global (docs). For that reason, the type=module is removed when packaging the extension.

Related issue: #1747.

🚨 Test instructions

Here's a repo in which builds fail with 2.7.0 but pass with this PR:

https://github.com/olistic/parcel-webextension-repro

✔️ PR Todo

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs

@louisgv
Copy link
Contributor

louisgv commented Oct 3, 2022

@olistic how would we implement real module support when it comes to importing code into background sw? Or is that not necessary since parcel would be the "bundler" anyhow :-?... Just thinking outloud, since this PR is more of a hack to get over real-import and bundle them all into the output file (instead of using importScript/proper module import (?))

@olistic
Copy link
Contributor Author

olistic commented Oct 6, 2022

@olistic how would we implement real module support when it comes to importing code into background sw? Or is that not necessary since parcel would be the "bundler" anyhow :-?... Just thinking outloud, since this PR is more of a hack to get over real-import and bundle them all into the output file (instead of using importScript/proper module import (?))

Right now it's not necessary since Parcel is bundling the SW code anyhow, and since it leaves the type=module in the manifest, it's failing as what Parcel outputs isn't actually a module.

@louisgv
Copy link
Contributor

louisgv commented Oct 6, 2022

it's failing as what Parcel outputs isn't actually a module.

Yeah, so the way to actually fix that is to fix the js transformer to output service worker module... tbh I'm not sure how useful it will be, since bgsw are loaded in the background anyhow.

BTW, thanks for the patch - I incorporated it into my fork of this packager. (used in plasmo: https://github.com/PlasmoHQ/plasmo/)

@devongovett devongovett merged commit 59610c1 into parcel-bundler:v2 Oct 24, 2022
@olistic olistic deleted the fix-webextension-sw branch October 25, 2022 21:37
@olistic
Copy link
Contributor Author

olistic commented Oct 25, 2022

@devongovett Thanks for merging. Any idea when this will be released?

@devongovett
Copy link
Member

Working on testing and preparing a release soon (next few weeks hopefully). In the meantime, you could try out the nightly releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants