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] Better esm config file support #4123
Conversation
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via npm install lohfu/rollup#better-esm-config-file-support or load it into the REPL: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not completely sure about this one, even for a major release. Maybe we actually make this much simpler and say we always use dynamic import()
. This would work for CommonJS just as well as ESM, and then we just always add the interop check, i.e. roughly
const configFileExport = supportsNativeESM()
? getDefaultFromCjs(await import(pathToFileURL(fileName).href)).default)
: extension === '.cjs'
? getDefaultFromCjs(require(fileName))
: await getDefaultFromTranspiledConfigFile(fileName, commandOptions.silent)
That way, we do not rely on an additional package but directly use Node's algorithm to detect ESM/CommonJS. Thoughts?
cli/run/loadConfigFile.ts
Outdated
const major = parseInt(version[1], 10); | ||
const minor = parseInt(version[2], 10); | ||
|
||
return major >= 14 || (major === 13 && minor >= 2) || (major === 12 && minor >= 17); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is definitely a reasonable improvement that I would merge even without a major release.
Codecov Report
@@ Coverage Diff @@
## release-3.0.0 #4123 +/- ##
=================================================
- Coverage 98.87% 98.87% -0.01%
=================================================
Files 211 211
Lines 7391 7388 -3
Branches 2105 2103 -2
=================================================
- Hits 7308 7305 -3
Misses 27 27
Partials 56 56
Continue to review full report at Codecov.
|
As we are now finally starting work on a new major version, I revisited this PR, rebased it onto the release branch and applied some simplifications:
|
Also, the relevant documentation will need to be reworked to better reflect the new logic. |
…eprecated features (#4552) * Remove all active deprecations * Make all inactive deprecations active * Try to make test more stable * Update CLI help screen
* Initial new hashing idea * Simplify external import path generation 197 broken tests left * Use correct file names in chunk info 197 broken tests left * Implement first draft for hashing algorithm 189 broken tests left * Remove active deprecations this.emitAsset this.emitChunk this.getAssetFileName this.getChunkFileName import.meta.ROLLUP_ASSET_URL_ import.meta.ROLLUP_CHUNK_URL_ * Reduce render parameters * Always scan all chunks for hashes * Fix asset emission and remaining tests * Reintroduce augmentChunkHash and get OutputChunk by converting RenderedChunk * Provide chunk graph in renderChunk * Handle hash collisions * Remove deprecated hacky asset emission * Allow to configure hash sizes per file * Update documentation * Extend tests * Minor improvements * Improve documentation about hashing * Replace hash in sourcemap file * Provide ChunkInfo in banner/footer/intro/outro * Extract hashing logic * Clean up hashing logic * Add ExternalChunk wrapper * Store inputBase on Chunk * Store snippets on Chunk * Align chunk interfaces * Reduce this. property access * Move dynamicImportFunction warning to options normalization * Restructure rendering logic * Do not run on Node 10 * Update documentation * Try to fix Windows tests * Improve coverage * Remove graph background colors
* fix: run output plugins last * Add test Co-authored-by: Lukas Taegert-Atkinson <lukas.taegert-atkinson@tngtech.com>
* Convert scripts to ESM, update dependencies * Fix lint issue
93d57da
to
5dcadfb
Compare
I updated the documentation now, mostly removing some sections and recommending to use |
48ce34d
to
11ee71f
Compare
13b0ef8
to
46910f4
Compare
46910f4
to
d196046
Compare
This issue has been resolved via #4574 as part of rollup@3.0.0-3. Note that this is a pre-release, so to test it, you need to install Rollup via |
This issue has been resolved via #4574 as part of rollup@3.0.0-4. Note that this is a pre-release, so to test it, you need to install Rollup via |
This issue has been resolved via #4574 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 |
This issue has been resolved via #4574 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 |
This issue has been resolved via #4574 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 |
This issue has been resolved via #4574 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 |
This issue has been resolved via #4574 as part of rollup@3.0.0. You can test it via |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
#4055
Description
.js
config files untranspiled withimport()
ifpackage.json
has"type": "module"
Only checking if major version is above 13 leads to both false negatives and false positives. ESM is supported in ^12.17, ^13.2 and >=14. Thus, version 12.17 has support and 13.0 does not.
Rollup goes against specification when not loading
.js
config files as ESM despite"type": "module"
being set inpackage.json
. This actually causes imports of.cjs
files to fail with:Changing the extension of the Rollup file to
.mjs
resolves the issue.Although this PR is a breaking change, it makes Rollup handle ESM config files the same way Node handles them natively. It will only make builds with
"type": "module"
and a.js
Rollup config file with invalid ESM syntax fail. Moreover, projects with"type": "module"
will already have spent time converting.js
files (including config) to ESM or changing their extension to.cjs
. If the Rollup config is not valid ESM, it's most likely because they forgot to check it or made a mistake.