Skip to content

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

Merged
lukastaegert merged 5 commits into
release-3.0.0from
esm-load-config
Aug 30, 2022
Merged

[v3.0] Always try to load config files via Node if possible#4621
lukastaegert merged 5 commits into
release-3.0.0from
esm-load-config

Conversation

@lukastaegert

@lukastaegert lukastaegert commented Aug 26, 2022

Copy link
Copy Markdown
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?

  • 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

github-actions Bot commented Aug 26, 2022

Copy link
Copy Markdown

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

codecov Bot commented Aug 26, 2022

Copy link
Copy Markdown

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 merged commit e0bdf9c into release-3.0.0 Aug 30, 2022
@lukastaegert
lukastaegert deleted the esm-load-config branch August 30, 2022 12:10
@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
Copy Markdown
Collaborator

This PR has been released as part of [email protected]. Note that this is a pre-release, so to test it, you need to install Rollup via npm install [email protected] 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
Copy Markdown
Collaborator

This PR has been released as part of [email protected]. Note that this is a pre-release, so to test it, you need to install Rollup via npm install [email protected] 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
Copy Markdown
Collaborator

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

@rollup-bot

Copy link
Copy Markdown
Collaborator

This PR has been released as part of [email protected]. Note that this is a pre-release, so to test it, you need to install Rollup via npm install [email protected] 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
Copy Markdown
Collaborator

This PR has been released as part of [email protected]. 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

None yet

Development

Successfully merging this pull request may close these issues.

Rollup cant parse plugin that dependend on ES package Error TRANSPILED_ESM_CONFIG provides insufficient information

2 participants