Skip to content

Commit

Permalink
fix(babel-preset-gatsby-package): remove node-env check as it's alway… (
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet authored and GatsbyJS Bot committed Jan 9, 2020
1 parent 4ae7f4f commit bafa160
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 93 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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`],
},
}

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

0 comments on commit bafa160

Please sign in to comment.