-
Notifications
You must be signed in to change notification settings - Fork 182
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
Build .mjs files (ES modules) alongside CommonJS #209
Changes from all commits
465e1e8
f14c55a
1dfedb4
675edfc
d19581f
e00547e
efdb7dd
608c2a1
f5a1b7d
d699ee4
93befaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ | |
[options] | ||
|
||
[version] | ||
^0.69.0 | ||
^0.73.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* Determines whether to transform modules to commonjs based on an | ||
* environment variable. Module import/export statements are not transformed | ||
* if the `BABEL_MODULES` env variable is set. | ||
*/ | ||
module.exports = process.env.BABEL_MODULES ? | ||
() => ({}) : | ||
require('babel-plugin-transform-es2015-modules-commonjs'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
* @flow | ||
*/ | ||
|
||
import { Buffer } from './buffer'; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I understand facebook/flow#3723 was merged and will be available in the next release. import Buffer from 'buffer'; and everything will work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, sadly no. We'd be able to simplify buffer.js#L28-L37 to export const Buffer = NodeBuffer.Buffer; (which should now typecheck) but we'd still have Node's actual implementation to deal with. Under |
||
export type Base64String = string; | ||
|
||
export function base64(i: string): Base64String { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
/** | ||
* This file exists to work around an issue with importing Buffer across | ||
* Webpack and Node. | ||
* | ||
* Webpack (tested with 4.5.0) doesn't currently support use of Node globals, | ||
* such as Buffer, in ES modules. | ||
* See https://github.com/webpack/webpack/issues/7032 | ||
* | ||
* Hence we want to import it explicitly e.g. | ||
* | ||
* import { Buffer } from 'buffer'; | ||
* | ||
* But Node (tested with version 9.11.1 and --experimental-modules) only has | ||
* Buffer as a property of the default export, not as a separate named export. | ||
*/ | ||
|
||
import NodeBuffer from 'buffer'; | ||
|
||
/** | ||
* An alias for Node's Buffer class. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @motiz88 Flow |
||
|
||
export const Buffer = NodeBuffer.Buffer; |
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.
@motiz88 If you have time maybe it worth to split such changes into separate PR.
I think it would be easy to find someone from Facebook willing to merge such simple change
+ it will make the main PR smaller