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

fix(babel-preset-gatsby-package): remove node-env check as it's alway… #20509

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -21,9 +21,6 @@ Array [
],
Array [
"@babel/preset-react",
Object {
"development": true,
},
],
"@babel/preset-flow",
]
Expand All @@ -50,9 +47,6 @@ Array [
],
Array [
"@babel/preset-react",
Object {
"development": true,
},
],
"@babel/preset-flow",
]
Expand Down Expand Up @@ -80,16 +74,13 @@ Array [
"modules": "commonjs",
"shippedProposals": true,
"targets": Object {
"node": "current",
"node": "8.0",
},
"useBuiltIns": "entry",
},
],
Array [
"@babel/preset-react",
Object {
"development": true,
},
],
"@babel/preset-flow",
]
Expand All @@ -106,16 +97,13 @@ Array [
"modules": "commonjs",
"shippedProposals": true,
"targets": Object {
"node": "current",
"node": "8.0",
},
"useBuiltIns": "entry",
},
],
Array [
"@babel/preset-react",
Object {
"development": true,
},
],
"@babel/preset-flow",
]
Expand All @@ -131,58 +119,3 @@ Array [
"babel-plugin-dynamic-import-node",
]
`;

exports[`babel-preset-gatsby-package in production mode specifies proper presets for browser mode 1`] = `
Array [
Array [
"@babel/preset-env",
Object {
"debug": false,
"loose": true,
"modules": "commonjs",
"shippedProposals": true,
"targets": Object {
"browsers": Array [
"last 4 versions",
"safari >= 7",
"ie >= 9",
],
},
"useBuiltIns": false,
},
],
Array [
"@babel/preset-react",
Object {
"development": false,
},
],
"@babel/preset-flow",
]
`;

exports[`babel-preset-gatsby-package in production mode specifies proper presets for node mode 1`] = `
Array [
Array [
"@babel/preset-env",
Object {
"corejs": 2,
"debug": false,
"loose": true,
"modules": "commonjs",
"shippedProposals": true,
"targets": Object {
"node": "8.0",
},
"useBuiltIns": "entry",
},
],
Array [
"@babel/preset-react",
Object {
"development": false,
},
],
"@babel/preset-flow",
]
`;
18 changes: 0 additions & 18 deletions packages/babel-preset-gatsby-package/__tests__/index.js
Expand Up @@ -24,8 +24,6 @@ describe(`babel-preset-gatsby-package`, () => {
})

it(`can pass custom nodeVersion target`, () => {
process.env.BABEL_ENV = `production`

const nodeVersion = `6.0`
const { presets } = preset(null, {
nodeVersion,
Expand Down Expand Up @@ -55,20 +53,4 @@ describe(`babel-preset-gatsby-package`, () => {
expect(presets).toMatchSnapshot()
})
})

describe(`in production mode`, () => {
beforeEach(() => {
process.env.BABEL_ENV = `production`
})

it(`specifies proper presets for node mode`, () => {
const { presets } = preset(null)
expect(presets).toMatchSnapshot()
})

it(`specifies proper presets for browser mode`, () => {
const { presets } = preset(null, { browser: true })
expect(presets).toMatchSnapshot()
})
})
})
9 changes: 3 additions & 6 deletions packages/babel-preset-gatsby-package/index.js
Expand Up @@ -4,23 +4,20 @@ function preset(context, options = {}) {
const { browser = false, debug = false, nodeVersion = `8.0` } = options
const { NODE_ENV, BABEL_ENV } = process.env

const IS_PRODUCTION = (BABEL_ENV || NODE_ENV) === `production`
const IS_TEST = (BABEL_ENV || NODE_ENV) === `test`

const browserConfig = {
useBuiltIns: false,
targets: {
browsers: IS_PRODUCTION
? [`last 4 versions`, `safari >= 7`, `ie >= 9`]
: [`last 2 versions`, `not ie <= 11`, `not android 4.4.3`],
browsers: [`last 2 versions`, `not ie <= 11`, `not android 4.4.3`],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this change the client-side JS that's output during a build?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No that's babel-preset-gatsby :)

},
}

const nodeConfig = {
corejs: 2,
useBuiltIns: `entry`,
targets: {
node: IS_PRODUCTION ? nodeVersion : `current`,
node: nodeVersion,
},
}

Expand All @@ -38,7 +35,7 @@ function preset(context, options = {}) {
browser ? browserConfig : nodeConfig
),
],
[r(`@babel/preset-react`), { development: !IS_PRODUCTION }],
[r(`@babel/preset-react`)],
r(`@babel/preset-flow`),
],
plugins: [
Expand Down