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

feat(ESModules): importing for esm modules #3998

Merged
merged 3 commits into from
Apr 16, 2020

Conversation

duncte123
Copy link
Contributor

@duncte123 duncte123 commented Mar 26, 2020

Please describe the changes this PR makes and why it should be merged:
This PR fixes #3992 by adding special exports for esm modules.
The exports in the package.json have been inspired by eris with modifications to work with discord.js

I've built a script that automatically can build the discord.mjs file if needed, the script is as follows:

const { writeFileSync } = require('fs');
const Discord = require('discord.js');
const discordExports = Object.keys(Discord);

const template = `import Discord from "../src/index.js";

export default Discord;

export const {
  ${discordExports.join(",\n  ")}
} = Discord;
`;

writeFileSync("./esm/discord.mjs", template);

Status

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

Semantic versioning classification:

  • This PR changes the library's interface (methods or parameters added)
    • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)
  • This PR only includes non-code changes, like changes to documentation, README, etc.

@ghost
Copy link

ghost commented Mar 26, 2020

Node.js fully provides support for ECMAScript modules as they provide limited interoperability between them and the existing module format, namely, CommonJS.

Due to the increasing popularity of ECMAScript modules, it is utterly reasonable to allow support for ECMAScript modules. One drawback of the change is that it blocks 'subpath imports' if paths are not represented in the exports field. This, however, can be utilized using the subpath, which is already defined in the exports field, ./esm.

import submodule from 'discord.js/esm';

esm/discord.mjs Outdated Show resolved Hide resolved
@iCrawl
Copy link
Member

iCrawl commented Mar 27, 2020

I'd argue this is more feat (feature), than a fix here.

I assume this is absolutely needed to get modules to work in Node.js?
Pardon my ignorance on that topic.

@iCrawl iCrawl changed the title fix: importing for esm modules feat(ESModules): importing for esm modules Mar 27, 2020
@duncte123
Copy link
Contributor Author

duncte123 commented Mar 27, 2020

I'd argue this is more feat (feature), than a fix here.

I assume this is absolutely needed to get modules to work in Node.js?
Pardon my ignorance on that topic.

Yes this change is required to get modules working in node.js that is why I labeled it as a fix, documentation can be found on this page https://nodejs.org/api/esm.html

A workaround is achievable by using the esm package but that is unnecessary bloat added to a project.

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.

Incompatible with node ECMAScript Modules
3 participants