support node ESModules via --experimental-modules flag #44
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.
This PR adds support for importing
tslibin node running with the--experimental-modulesflag:tslib.es6.jstotslib.mjsjust before publishing to npm (not windows compatible afaik -- wanted to avoid adding anshxdevDependency)"main": "tslib.js"package.json entrySteps 1-2 are necessary because node will automatically select either the "js" or "mjs" file depending on whether it was run with the --experimental-modules flag, but only if the "main" entry doesn't explicitly specify a file extension.
Step 3 ensures the gitignore'd
tslib.mjsfile is included in the assets published to npm.Step 4 ensures the
mjsfile is always in line with thetslib.es6.jsfile, and avoids source code duplication.ESModules in node >= 8.6.0
If you attempt to import a CommonJS module as an ESModule (either by explicitly importing the "js" version, or if there's no explicit extension and no "mjs" file available), node will synthesize a default export from the "module.exports" object, leading to the following error condition:
I believe this PR is the less invasive of two possible approaches, as it shouldn't break anyone who has hard-coded references to
tslib.es6.jsin their builds (e.g. for closure compiler). Alternatively, we could renametslib.es6.js->tslib.mjs(branch).For context: the Apache Arrow JS project is written in TypeScript, and we're targeting full compatibility with node's new --experimental-modules flag.
The last step in our upgrade process is helping ensure our dependencies expose node v8.6.0+ compatible ESModules. Please let me know if there's anything else I can do to help get this PR accepted, and a new version published soon. Thanks!