-
Notifications
You must be signed in to change notification settings - Fork 179
Build .mjs files (ES modules) alongside CommonJS #209
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
Changes from 7 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 |
---|---|---|
@@ -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 |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
|
||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
import { StarWarsSchema } from './starWarsSchema.js'; | ||
import { StarWarsSchema } from './starWarsSchema'; | ||
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 If you have time maybe it worth to split such changes into separate PR. |
||
import { graphql } from 'graphql'; | ||
|
||
// 80+ char lines are useful in describe/it, so ignore in this file. | ||
|
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,37 @@ | ||
/** | ||
* 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 a number of issues with importing Buffer | ||
* across Webpack, Node and Flow. | ||
* | ||
* 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. | ||
* | ||
* Flow (tested with 0.69.0) knows about global.Buffer but not about | ||
* require('buffer').Buffer. | ||
* https://github.com/facebook/flow/issues/3723 | ||
*/ | ||
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 |
||
|
||
// $FlowFixMe because of the above. | ||
export const Buffer: typeof global.Buffer = NodeBuffer.Buffer; |
Uh oh!
There was an error while loading. Please reload this page.
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.
This should be
"main": "lib",
so the.mjs
files can be resolved automatically in an ESM environment.