This repository was archived by the owner on Mar 3, 2023. It is now read-only.
support ES6 default require for packages #21112
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the change
In short:
This allows loading the packages that are Es module and export their function wrapped in a default object. This is the case for any package that uses Babel 6, Babel 7, or other modern compilers for transpiling their package.
This will also allow us to use babel 7 in Atom's babel transpiler as in #20965
Longer:
The behavior of ES6 is to use
exports.default = ....for exporting something as default.This is equal to using
module.exports = ....ormodule.exports = {...}.In ES6 requiring the modules that exported like need explicitly calling
.default_requirefunction in this pull request checks ifdefaultproperty exists and returns what it is inside it instead of returning the useless module itself (which will not have the activate function for the package)._requirefunction checks this phenomenon and adds support for it. Many compilers or bundlers use_interopDefaultwhich serves the same purpose.Drawbacks
This function is written pretty conservatively and has no drawbacks.
In Atom, all the packages can only export their functions either named or wrapped in an object. There is no real useful default export that can be called directly. So the mixed situation does not happen, and we can safely merge this PR.
Verification
The CI passes
Release Notes