forked from inexorabletash/text-encoding
-
Notifications
You must be signed in to change notification settings - Fork 6
Add support for node ESModules with --experimental-modules flag #2
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arv
approved these changes
Nov 20, 2017
Owner
arv
left a comment
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.
Nice. LGTM
Owner
|
I'll have to do another push to npm later when I'm in front of my laptop. |
Author
|
@arv thanks so much! I believe our next release is after thanksgiving, maybe even early next week, so no rush. |
Owner
|
I just pushed to npm (1.0.2). |
wesm
pushed a commit
to apache/arrow
that referenced
this pull request
Nov 21, 2017
…les support Updates the `text-encoding-utf-8` dependency to version 1.0.2, [which now supports](arv/text-encoding-utf-8#2) ESModules in node >= v8.6.0 via the `--experimental-modules` flag. We currently support ESModules in node in the main `apache-arrow` package, but need our dependencies to also expose ESModule forms as well. I have also issued a [PR to flatbuffers](google/flatbuffers#4504) to add ESModules support, and are using a temporary [fork of flatbuffers](https://github.com/trxcllnt/flatbuffers-esm) in my github until that PR is merged. This PR enables the following workflow: ```js // file - index.mjs // run via `node --experimental-modules index.mjs` import util from 'util'; import * as fs from 'fs'; import { Table } from 'apache-arrow'; (async () => { const buffer = await util.promisify(fs.readFile)('simple.arrow'); console.log(Table.from([buffer]).toString()); /* foo, bar, baz 1, 1, aa null, null, null 3, null, null 4, 4, bbb 5, 5, cccc */ })(); ``` Author: Paul Taylor <[email protected]> Closes #1338 from trxcllnt/update-text-encoding-utf8 and squashes the following commits: fbecde5 [Paul Taylor] synthesize an mjs file for tslib on postinstall 4b050c9 [Paul Taylor] update text-encoding-utf-8 dependency with node ESModules support
kou
pushed a commit
to apache/arrow-js
that referenced
this pull request
May 14, 2025
…les support Updates the `text-encoding-utf-8` dependency to version 1.0.2, [which now supports](arv/text-encoding-utf-8#2) ESModules in node >= v8.6.0 via the `--experimental-modules` flag. We currently support ESModules in node in the main `apache-arrow` package, but need our dependencies to also expose ESModule forms as well. I have also issued a [PR to flatbuffers](google/flatbuffers#4504) to add ESModules support, and are using a temporary [fork of flatbuffers](https://github.com/trxcllnt/flatbuffers-esm) in my github until that PR is merged. This PR enables the following workflow: ```js // file - index.mjs // run via `node --experimental-modules index.mjs` import util from 'util'; import * as fs from 'fs'; import { Table } from 'apache-arrow'; (async () => { const buffer = await util.promisify(fs.readFile)('simple.arrow'); console.log(Table.from([buffer]).toString()); /* foo, bar, baz 1, 1, aa null, null, null 3, null, null 4, 4, bbb 5, 5, cccc */ })(); ``` Author: Paul Taylor <[email protected]> Closes #1338 from trxcllnt/update-text-encoding-utf8 and squashes the following commits: fbecde59 [Paul Taylor] synthesize an mjs file for tslib on postinstall 4b050c95 [Paul Taylor] update text-encoding-utf-8 dependency with node ESModules support
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 using
text-encoding-utf-8with node's new--experimental-modulesflag for ESModules support:lib/encoding.cjs.jstolib/encoding.lib.jssrc/encoding.jsfile tolib/encoding.lib.mjspackage.json,lib/encoding.lib.js->lib/encoding.libPoints 2 and 3 are necessary because node will automatically select the "mjs" file when run with
--experimental-modules, but only if the "main" export doesn't specify a file extension. If no "mjs" file exists, node imports the CJS form and synthesizes a default export from themodule.exportsobject, leading to the following behavior:For context: we are using this polyfill in the Apache Arrow JS project (and really appreciate your efforts), and are now supporting ESModules in our library. Let me know if there's anything else I can help to get this PR merged and a new version published soon. Thanks!