Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Conversation

@aminya
Copy link
Contributor

@aminya aminya commented Jul 25, 2020

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 = .... or module.exports = {...}.

In ES6 requiring the modules that exported like need explicitly calling .default

const x = require(module).default // require(module) is wrong

_require function in this pull request checks if default property 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).

_require function checks this phenomenon and adds support for it. Many compilers or bundlers use _interopDefault which 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

  • Adding support for the packages that export their main functions under an object and are transpiled using modern transpilers (e.g babel 6 or later, etc).

this is not necessary
It does not necessarily need to be an object. It can be a function
Copy link
Contributor

@sadick254 sadick254 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. 👍

@sadick254 sadick254 merged commit bd189eb into atom:master Nov 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants