Skip to content

Fix import.meta.url inside web workers#4186

Merged
guybedford merged 4 commits intorollup:masterfrom
ceifa:master
Jul 24, 2021
Merged

Fix import.meta.url inside web workers#4186
guybedford merged 4 commits intorollup:masterfrom
ceifa:master

Conversation

@ceifa
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

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. :)

Comment thread test/form/samples/emit-uint8array-no-buffer/_expected/umd.js Outdated
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.

2 participants