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 import.meta.url inside web workers #4186

Merged
merged 4 commits into from Jul 24, 2021
Merged

Fix import.meta.url inside web workers #4186

merged 4 commits into from Jul 24, 2021

Conversation

@ceifa
Copy link
Contributor

@ceifa ceifa commented Jul 23, 2021

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes
  • no

Breaking Changes?

  • yes
  • no

Description

If I compile a library that uses import.meta.url internally using UMD, it will break if I try to use it inside web workers, that happens because today rollup compile import.meta.url to use nodejs require or browser document API, but both is unavailable inside web workers. This PR adds a check for it and try to use location.href, if available.

@codecov
Copy link

@codecov codecov bot commented Jul 23, 2021

Codecov Report

Merging #4186 (1e0b62b) into master (959f040) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4186   +/-   ##
=======================================
  Coverage   98.34%   98.34%           
=======================================
  Files         202      202           
  Lines        7230     7232    +2     
  Branches     2114     2116    +2     
=======================================
+ Hits         7110     7112    +2     
  Misses         58       58           
  Partials       62       62           
Impacted Files Coverage Δ
src/ast/nodes/MetaProperty.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 959f040...1e0b62b. Read the comment docs.

@guybedford
Copy link
Contributor

@guybedford guybedford commented Jul 23, 2021

Thanks for the PR.

How about we flip the order and make it if (typeof document === 'undefined' ? typeof location !== 'undefined' ? location.href : ...?

@ceifa
Copy link
Contributor Author

@ceifa ceifa commented Jul 23, 2021

How about we flip the order and make it if (typeof document === 'undefined' ? typeof location !== 'undefined' ? location.href : ...?

Thanks for reviewing! Just pushed this suggestion. :)

@guybedford guybedford merged commit 2a29db9 into rollup:master Jul 24, 2021
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants