Skip to content

Commit

Permalink
chore(gatsby): officially stop supporting Node 6 (#14842)
Browse files Browse the repository at this point in the history
* ci: remove node6 unit test running

* refactor(gatsby-cli): fail on Node 6

* feat(babel-preset-gatsby-package): nodeVersion is supported option

* chore: update documentation and lockfile

* chore: remove the workflow too ya dingus

* chore: use engines in gatsby-cli

* chore: fix pkg engines

* chore: migrate off of engines

* chore(*): add engines to all packages

* chore: does this work

* chore: add new lines
  • Loading branch information
DSchau authored Jun 20, 2019
1 parent 1616ae7 commit 30045f6
Show file tree
Hide file tree
Showing 105 changed files with 403 additions and 32 deletions.
10 changes: 0 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ jobs:
- <<: *persist_cache
- run: yarn lint

unit_tests_node6:
executor:
name: node
image: "6"
<<: *test_template

unit_tests_node8:
executor:
name: node
Expand Down Expand Up @@ -216,10 +210,6 @@ workflows:
jobs:
- bootstrap
- lint
- unit_tests_node6:
<<: *ignore_docs
requires:
- bootstrap
- unit_tests_node8:
<<: *ignore_docs
requires:
Expand Down
3 changes: 3 additions & 0 deletions packages/babel-plugin-remove-graphql-queries/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
"build": "babel src --out-dir . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__"
},
"engines": {
"node": ">=8.0.0"
}
}
6 changes: 6 additions & 0 deletions packages/babel-preset-gatsby-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ Defines if [`@babel/preset-env`](https://babeljs.io/docs/en/babel-preset-env) is
`boolean`, defaults to `false`.

Outputs the targets/plugins used and the version specified in [plugin data version](https://github.com/babel/babel/blob/master/packages/babel-preset-env/data/plugins.json) to `console.log`.

### `nodeVersion`

`string`, defaults to `8.0`

Allows the Node.js version target to be modified per [`@babel/preset-env` documentation](https://babeljs.io/docs/en/babel-preset-env#targetsnode)
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Array [
"modules": "commonjs",
"shippedProposals": true,
"targets": Object {
"node": 6,
"node": "8.0",
},
"useBuiltIns": "entry",
},
Expand Down
26 changes: 18 additions & 8 deletions packages/babel-preset-gatsby-package/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ const preset = require(`../`)

jest.mock(`../resolver`, () => jest.fn(moduleName => moduleName))

beforeEach(() => {
delete process.env.BABEL_ENV
})

describe(`babel-preset-gatsby-package`, () => {
describe(`in node mode`, () => {
it(`specifies the proper plugins`, () => {
Expand All @@ -18,6 +22,19 @@ describe(`babel-preset-gatsby-package`, () => {
const { presets } = preset(null, { debug: true })
expect(presets).toMatchSnapshot()
})

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

const nodeVersion = `6.0`
const { presets } = preset(null, {
nodeVersion
})

const [_, opts] = presets.find(preset => [].concat(preset).includes('@babel/preset-env'))

expect(opts.targets.node).toBe(nodeVersion)
})
})

describe(`in browser mode`, () => {
Expand All @@ -38,17 +55,10 @@ describe(`babel-preset-gatsby-package`, () => {
})

describe(`in production mode`, () => {
let env

beforeAll(() => {
env = process.env.BABEL_ENV
beforeEach(() => {
process.env.BABEL_ENV = `production`
})

afterAll(() => {
process.env.BABEL_ENV = env
})

it(`specifies proper presets for node mode`, () => {
const { presets } = preset(null)
expect(presets).toMatchSnapshot()
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-preset-gatsby-package/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const r = require(`./resolver`)

function preset(context, options = {}) {
const { browser = false, debug = false } = options
const { browser = false, debug = false, nodeVersion = `8.0` } = options
const { NODE_ENV, BABEL_ENV } = process.env

const PRODUCTION = (BABEL_ENV || NODE_ENV) === `production`
Expand All @@ -17,7 +17,7 @@ function preset(context, options = {}) {

const nodeConfig = {
targets: {
node: PRODUCTION ? 6.0 : `current`,
node: PRODUCTION ? nodeVersion : `current`,
},
}

Expand Down
5 changes: 4 additions & 1 deletion packages/babel-preset-gatsby-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
"@babel/preset-react": "^7.0.0"
},
"license": "MIT",
"main": "index.js"
"main": "index.js",
"engines": {
"node": ">=8.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/babel-preset-gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
"@babel/cli": "^7.0.0",
"babel-preset-gatsby-package": "^0.1.4",
"cross-env": "^5.1.4"
},
"engines": {
"node": ">=8.0.0"
}
}
4 changes: 3 additions & 1 deletion packages/gatsby-cli/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"presets": [
["babel-preset-gatsby-package"]
["babel-preset-gatsby-package", {
"nodeVersion": "6.0"
}]
]
}
2 changes: 1 addition & 1 deletion packages/gatsby-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"prompts": "^2.1.0",
"react": "^16.8.4",
"resolve-cwd": "^2.0.0",
"semver": "^6.0.0",
"semver": "^6.1.1",
"source-map": "0.5.7",
"stack-trace": "^0.0.10",
"strip-ansi": "^5.2.0",
Expand Down
74 changes: 74 additions & 0 deletions packages/gatsby-cli/src/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
jest.mock(`../reporter`, () => {
return {
panic: jest.fn(),
log: jest.fn(),
stripIndent: jest.fn(str => str),
}
})
jest.mock(`../create-cli`)

const getCLI = () => {
jest.resetModules()

const reporter = require(`../reporter`)
const createCLI = require(`../create-cli`)

require(`../`)

return {
reporter,
createCLI,
}
}

let __process__
beforeAll(() => {
__process__ = global.process
})

beforeEach(() => {
global.process = __process__
})

const setup = version => {
if (version) {
Object.defineProperty(__process__, `version`, {
get: () => version,
})
}

return getCLI()
}

describe(`error handling`, () => {
it(`panics on Node < 8.0.0`, () => {
const { reporter } = setup(`v6.0.0`)

expect(reporter.panic).toHaveBeenCalledTimes(1)
})

it(`shows error with link to more info`, () => {
const { reporter } = setup(`v6.0.0`)

expect(reporter.panic).toHaveBeenCalledWith(
expect.stringContaining(`https://gatsby.dev/upgrading-node-js`)
)
})
})

describe(`normal behavior`, () => {
it(`does not panic on Node >= 8.0.0`, () => {
;[`8.0.0`, `8.9.0`, `10.0.0`, `11.0.0`, `12.0.0`].forEach(version => {
const { reporter } = setup(version)

expect(reporter.panic).not.toHaveBeenCalled()
})
})

it(`invokes createCLI`, () => {
const { createCLI } = setup()

expect(createCLI).toHaveBeenCalledTimes(1)
expect(createCLI).toHaveBeenCalledWith(process.argv)
})
})
14 changes: 8 additions & 6 deletions packages/gatsby-cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
// babel-preset-env doesn't find this import if you
// use require() with backtick strings so use the es6 syntax
import "@babel/polyfill"
const semver = require(`semver`)

const createCli = require(`./create-cli`)
const report = require(`./reporter`)

const version = process.version
const verDigit = Number(version.match(/\d+/)[0])

const pkg = require(`../package.json`)
const updateNotifier = require(`update-notifier`)
// Check if update is available
updateNotifier({ pkg }).notify()

if (verDigit < 6) {
const MIN_NODE_VERSION = `>=8.0.0`

if (!semver.satisfies(process.version, MIN_NODE_VERSION)) {
report.panic(
`Gatsby 1.0+ requires node.js v6 or higher (you have ${version}). \n` +
`Upgrade node to the latest stable release.`
report.stripIndent(`
Gatsby requires Node.js v8 or higher (you have ${process.version}).
Upgrade Node to the latest stable release: https://gatsby.dev/upgrading-node-js
`)
)
}

Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby-codemods/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@
"babel-preset-gatsby-package": "^0.1.4",
"cross-env": "^5.0.5",
"jscodeshift": "^0.5.1"
},
"engines": {
"node": ">=8.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/gatsby-cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@
"build": "babel src --out-dir . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__"
},
"engines": {
"node": ">=8.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/gatsby-dev-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@
"prepare": "cross-env NODE_ENV=production npm run build",
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "babel -w src --out-dir dist --ignore \"**/__tests__\""
},
"engines": {
"node": ">=8.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/gatsby-graphiql-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@
"style-loader": "^0.21.0",
"webpack-cli": "^3.3.2",
"whatwg-fetch": "^3.0.0"
},
"engines": {
"node": ">=8.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-canonical-urls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@
"build": "babel src --out-dir . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__"
},
"engines": {
"node": ">=8.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-catch-links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@
"build": "babel src --out-dir . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__"
},
"engines": {
"node": ">=8.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-coffeescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@
"build": "babel src --out-dir . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__"
},
"engines": {
"node": ">=8.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-create-client-paths/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@
"build": "babel src --out-dir . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__"
},
"engines": {
"node": ">=8.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-cxs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@
"build": "babel src --out-dir . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__"
},
"engines": {
"node": ">=8.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-emotion/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@
"build": "babel src --out-dir . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__"
},
"engines": {
"node": ">=8.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-facebook-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@
"build": "babel src --out-dir . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__"
},
"engines": {
"node": ">=8.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-feed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@
"build": "babel src --out-dir . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__"
},
"engines": {
"node": ">=8.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-flow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@
"@babel/core": "^7.0.0",
"babel-preset-gatsby-package": "^0.1.4",
"cross-env": "^5.0.5"
},
"engines": {
"node": ">=8.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-fullstory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@
},
"peerDependencies": {
"gatsby": "^2.0.0"
},
"engines": {
"node": ">=8.0.0"
}
}
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-glamor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@
"build": "babel src --out-dir . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__"
},
"engines": {
"node": ">=8.0.0"
}
}
Loading

0 comments on commit 30045f6

Please sign in to comment.