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 initial ModuleInfo.meta mutable and maintain object identity #4328

Merged
merged 3 commits into from Jan 4, 2022

Conversation

lukastaegert
Copy link
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

Technically it is a breaking change, but its effects are very subtle and will likely not be noticed considering how meta properties are merged at the moment, so I would consider it as non-breaking.

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

This PR changes two things:

  • When a module is loaded for the first time and no "meta" object is specified, it is initialized with a mutable object. Previously, it used to be a frozen empty object.
  • When meta is updated via a hook, it is now mutated. Previously for each hook, a shallow copy was created and merged with the updated properties. Thus it is always the same object for a module.

There is also now a test that ensures that the meta object (and moduleInfo) of a module is directly accessible after calling this.load even if the promise is not awaited. I actually need this for my current commonjs PR.

@patak-dev, @antfu, @marvinhagemeister not sure if this is supported by Vite/WMR or if this would pose any problems for you?

@github-actions
Copy link

github-actions bot commented Dec 29, 2021

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#mutable-meta

or load it into the REPL:
https://rollupjs.org/repl/?pr=4328

@codecov
Copy link

codecov bot commented Dec 29, 2021

Codecov Report

Merging #4328 (f5392ea) into master (a54b798) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4328   +/-   ##
=======================================
  Coverage   98.44%   98.44%           
=======================================
  Files         205      205           
  Lines        7322     7322           
  Branches     2085     2085           
=======================================
  Hits         7208     7208           
  Misses         55       55           
  Partials       59       59           
Impacted Files Coverage Δ
src/Module.ts 100.00% <100.00%> (ø)
src/ModuleLoader.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 a54b798...f5392ea. Read the comment docs.

@lukastaegert lukastaegert merged commit 2fea0d7 into master Jan 4, 2022
@lukastaegert lukastaegert deleted the mutable-meta branch January 4, 2022 06:35
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

1 participant