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

[v3.0] Always try to load config files via Node if possible #4621

Merged
merged 5 commits into from Aug 30, 2022

Conversation

lukastaegert
Copy link
Member

@lukastaegert lukastaegert commented Aug 26, 2022

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

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

Breaking Changes?

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

List any relevant issue numbers:

Description

As it turns out, bundling a config to CommonJS will not allow users to directly import ESM-only plugins. The solution here is to

  • Load the config via Node's native mechanism if there is no --configPlugin
  • Provide a helpful error message if this fails
  • Add a timestamp parameter when loading in watch mode to allow reloading the config
  • If a --configPlugin is used, we bundle to ESM instead of CJS to fix a similar issue with TypeScript configs. To allow loading the bundled config, we temporarily write it to disk with a timestamp in the name and extension .mjs and delete it again after loading.
  • Add a new option --bundleConfigAsCjs to force bundling the config to CommonJS instead, even if no --configPlugin is used. We use the .cjs extension instead in this case. This also serves as a compatibility mode to e.g. run ESM configs that depend on things like __dirname.

@github-actions
Copy link

github-actions bot commented Aug 26, 2022

Thank you for your contribution! ❤️

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

npm install rollup/rollup#esm-load-config

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

@codecov
Copy link

codecov bot commented Aug 26, 2022

Codecov Report

Merging #4621 (51096cc) into release-3.0.0 (eac06ac) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@                Coverage Diff                @@
##           release-3.0.0    #4621      +/-   ##
=================================================
+ Coverage          98.97%   98.99%   +0.01%     
=================================================
  Files                211      211              
  Lines               7428     7439      +11     
  Branches            2101     2105       +4     
=================================================
+ Hits                7352     7364      +12     
  Misses                23       23              
+ Partials              53       52       -1     
Impacted Files Coverage Δ
src/utils/options/mergeOptions.ts 100.00% <ø> (ø)
cli/run/loadConfigFile.ts 96.61% <100.00%> (+2.61%) ⬆️
src/utils/error.ts 99.46% <100.00%> (+<0.01%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@lukastaegert lukastaegert force-pushed the esm-load-config branch 2 times, most recently from 6d8c3a4 to 06587f3 Compare August 27, 2022 05:06
@lukastaegert lukastaegert added this to In progress in Release 3.0.0 via automation Aug 30, 2022
@lukastaegert lukastaegert moved this from In progress to Ready for merge in Release 3.0.0 Aug 30, 2022
@lukastaegert lukastaegert merged commit e0bdf9c into release-3.0.0 Aug 30, 2022
@lukastaegert lukastaegert deleted the esm-load-config branch August 30, 2022 12:10
Release 3.0.0 automation moved this from Ready for merge to Done Aug 30, 2022
@lukastaegert lukastaegert mentioned this pull request Aug 30, 2022
9 tasks
lukastaegert added a commit that referenced this pull request Aug 31, 2022
* Support ES modules in bundles config files

* Always try to load config files directly if possible

* Fix build

* Fix test

* Debug test
@rollup-bot
Copy link
Collaborator

This PR has been released as part of rollup@3.0.0-5. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-5 or npm install rollup@beta. It will likely become part of a regular release later.

lukastaegert added a commit that referenced this pull request Sep 6, 2022
* Support ES modules in bundles config files

* Always try to load config files directly if possible

* Fix build

* Fix test

* Debug test
@rollup-bot
Copy link
Collaborator

This PR has been released as part of rollup@3.0.0-6. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-6 or npm install rollup@beta. It will likely become part of a regular release later.

lukastaegert added a commit that referenced this pull request Sep 22, 2022
* Support ES modules in bundles config files

* Always try to load config files directly if possible

* Fix build

* Fix test

* Debug test
@rollup-bot
Copy link
Collaborator

This PR has been released as part of rollup@3.0.0-7. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-7 or npm install rollup@beta. It will likely become part of a regular release later.

@rollup-bot
Copy link
Collaborator

This PR has been released as part of rollup@3.0.0-8. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-8 or npm install rollup@beta. It will likely become part of a regular release later.

lukastaegert added a commit that referenced this pull request Oct 11, 2022
* Support ES modules in bundles config files

* Always try to load config files directly if possible

* Fix build

* Fix test

* Debug test
@rollup-bot
Copy link
Collaborator

This PR has been released as part of rollup@3.0.0. You can test it via npm install rollup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Release 3.0.0
  
Done
2 participants