From dcec25250ad894dab11cff3dcb121e15979f82b6 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Thu, 6 Dec 2018 13:25:01 +0100 Subject: [PATCH 1/4] Scripts: Add check-engines script to the package --- package-lock.json | 1 + package.json | 7 +---- packages/scripts/CHANGELOG.md | 6 ++++ packages/scripts/README.md | 19 +++++++++++++ packages/scripts/package.json | 1 + packages/scripts/scripts/check-engines.js | 34 +++++++++++++++++++++++ 6 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 packages/scripts/scripts/check-engines.js diff --git a/package-lock.json b/package-lock.json index df6980879a3426..a8e836fe694774 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2763,6 +2763,7 @@ "@wordpress/npm-package-json-lint-config": "file:packages/npm-package-json-lint-config", "babel-eslint": "8.0.3", "chalk": "^2.4.1", + "check-node-version": "^3.1.1", "cross-spawn": "^5.1.0", "eslint": "^4.19.1", "jest": "^23.6.0", diff --git a/package.json b/package.json index 541ebbfa9df50d..92b48e7638e7d5 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,6 @@ "WordPress", "editor" ], - "engines": { - "node": ">=8.0.0", - "npm": ">=6.0.0" - }, "dependencies": { "@wordpress/a11y": "file:packages/a11y", "@wordpress/annotations": "file:packages/annotations", @@ -72,7 +68,6 @@ "autoprefixer": "8.2.0", "babel-loader": "8.0.0", "chalk": "2.4.1", - "check-node-version": "3.1.1", "concurrently": "3.5.0", "copy-webpack-plugin": "4.5.2", "core-js": "2.5.7", @@ -145,7 +140,7 @@ "prebuild:packages": "npm run clean:packages && lerna run build && cross-env INCLUDE_PACKAGES=babel-plugin-import-jsx-pragma,postcss-themes,jest-console SKIP_JSX_PRAGMA_TRANSFORM=1 node ./bin/packages/build.js", "build:packages": "cross-env EXCLUDE_PACKAGES=babel-plugin-import-jsx-pragma,jest-console,postcss-themes node ./bin/packages/build.js", "build": "npm run build:packages && cross-env NODE_ENV=production webpack", - "check-engines": "check-node-version --package", + "check-engines": "wp-scripts check-engines", "check-licenses": "concurrently \"wp-scripts check-licenses --prod --gpl2\" \"wp-scripts check-licenses --dev\"", "precheck-local-changes": "npm run docs:build", "check-local-changes": "( git diff -U0 | xargs -0 node bin/process-git-diff ) || ( echo \"There are local uncommitted changes after one or both of 'npm install' or 'npm run docs:build'!\" && exit 1 );", diff --git a/packages/scripts/CHANGELOG.md b/packages/scripts/CHANGELOG.md index c07fe9a2e6d566..8912ef51f1fa77 100644 --- a/packages/scripts/CHANGELOG.md +++ b/packages/scripts/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.5.0 (Unreleased) + +### New Feature + +- Added support for `check-engines` script ([#XXXXX](https://github.com/WordPress/gutenberg/pull/XXXXX)) + ## 2.4.4 (2018-11-20) ## 2.4.3 (2018-11-09) diff --git a/packages/scripts/README.md b/packages/scripts/README.md index 4126cdd34cc9b2..bd94b8cf09197a 100644 --- a/packages/scripts/README.md +++ b/packages/scripts/README.md @@ -19,6 +19,7 @@ _Example:_ ```json { "scripts": { + "check-engines": "wp-scripts check-engines", "lint:pkg-json": "wp-scripts lint-pkg-json .", "test": "wp-scripts test-unit-js" } @@ -27,6 +28,24 @@ _Example:_ ## Available Scripts +### `check-engines` + +Check if the current `node`, `npm` (or `yarn`) versions match the given semver version ranges. If the given version is not satisfied, information about installing the needed version is printed and the program exits with an error code. It uses [check-node-version](https://www.npmjs.com/package/check-node-version) behind the scenes with the default configuration provided. You can specify your own ranges as described in [check-node-version docs](https://www.npmjs.com/package/check-node-version). + +_Example:_ + +```json +{ + "scripts": { + "check-engines": "wp-scripts check-engines" + } +} +``` + +This is how you execute the script with presented setup: +* `npm run check-engines` - checks installed version of `node` and `npm`. + + ### `wp-scripts lint-js` Helps enforce coding style guidelines for your JavaScript files. It uses [eslint](https://eslint.org/) with no rules provided (we plan to add zero config support in the near future). You can specify your own rules as described in [eslint docs](https://eslint.org/docs/rules/). diff --git a/packages/scripts/package.json b/packages/scripts/package.json index fbbbff832e7360..6a0bc5e1986a92 100644 --- a/packages/scripts/package.json +++ b/packages/scripts/package.json @@ -36,6 +36,7 @@ "@wordpress/npm-package-json-lint-config": "file:../npm-package-json-lint-config", "babel-eslint": "8.0.3", "chalk": "^2.4.1", + "check-node-version": "^3.1.1", "cross-spawn": "^5.1.0", "eslint": "^4.19.1", "jest": "^23.6.0", diff --git a/packages/scripts/scripts/check-engines.js b/packages/scripts/scripts/check-engines.js new file mode 100644 index 00000000000000..23b5e390035cba --- /dev/null +++ b/packages/scripts/scripts/check-engines.js @@ -0,0 +1,34 @@ +/** + * External dependencies + */ +const { sync: spawn } = require( 'cross-spawn' ); +const { sync: resolveBin } = require( 'resolve-bin' ); + +/** + * Internal dependencies + */ +const { + getCliArgs, + hasCliArg, +} = require( '../utils' ); + +const args = getCliArgs(); + +const hasConfig = hasCliArg( '--package' ) || + hasCliArg( '--node' ) || + hasCliArg( '--npm' ) || + hasCliArg( '--yarn' ); +const config = ! hasConfig ? + [ + '--node', '>=8.0.0', + '--npm', '>=6.0.0', + ] : + []; + +const result = spawn( + resolveBin( 'check-node-version' ), + [ ...config, ...args ], + { stdio: 'inherit' } +); + +process.exit( result.status ); From fb540b85ca8930ca0b7408b93f8c12eb240cdf88 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Sun, 9 Dec 2018 13:30:24 -0600 Subject: [PATCH 2/4] Update packages/scripts/CHANGELOG.md Co-Authored-By: gziolo --- packages/scripts/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/scripts/CHANGELOG.md b/packages/scripts/CHANGELOG.md index 8912ef51f1fa77..6f2977dc07f901 100644 --- a/packages/scripts/CHANGELOG.md +++ b/packages/scripts/CHANGELOG.md @@ -2,7 +2,7 @@ ### New Feature -- Added support for `check-engines` script ([#XXXXX](https://github.com/WordPress/gutenberg/pull/XXXXX)) +- Added support for `check-engines` script ([#12721](https://github.com/WordPress/gutenberg/pull/12721)) ## 2.4.4 (2018-11-20) From a394e0ac137f73139ee83e6537fa1e02c766e8e8 Mon Sep 17 00:00:00 2001 From: Stephen Edgar Date: Mon, 10 Dec 2018 14:29:32 -0600 Subject: [PATCH 3/4] Update packages/scripts/README.md Co-Authored-By: gziolo --- packages/scripts/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/scripts/README.md b/packages/scripts/README.md index bd94b8cf09197a..04ddf958782e02 100644 --- a/packages/scripts/README.md +++ b/packages/scripts/README.md @@ -30,7 +30,7 @@ _Example:_ ### `check-engines` -Check if the current `node`, `npm` (or `yarn`) versions match the given semver version ranges. If the given version is not satisfied, information about installing the needed version is printed and the program exits with an error code. It uses [check-node-version](https://www.npmjs.com/package/check-node-version) behind the scenes with the default configuration provided. You can specify your own ranges as described in [check-node-version docs](https://www.npmjs.com/package/check-node-version). +Check if the current `node`, `npm` (or `yarn`) versions match the given [semantic version](https://semver.org/) ranges. If the given version is not satisfied, information about installing the needed version is printed and the program exits with an error code. It uses [check-node-version](https://www.npmjs.com/package/check-node-version) behind the scenes with the default configuration provided. You can specify your own ranges as described in [check-node-version docs](https://www.npmjs.com/package/check-node-version). _Example:_ From 55c589746933c5259ba88b7f941d388867762377 Mon Sep 17 00:00:00 2001 From: Stephen Edgar Date: Mon, 10 Dec 2018 14:32:07 -0600 Subject: [PATCH 4/4] Update minimal node version to 10.x Co-Authored-By: gziolo --- packages/scripts/scripts/check-engines.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/scripts/scripts/check-engines.js b/packages/scripts/scripts/check-engines.js index 23b5e390035cba..5440e27ccaffba 100644 --- a/packages/scripts/scripts/check-engines.js +++ b/packages/scripts/scripts/check-engines.js @@ -20,7 +20,7 @@ const hasConfig = hasCliArg( '--package' ) || hasCliArg( '--yarn' ); const config = ! hasConfig ? [ - '--node', '>=8.0.0', + '--node', '>=10.0.0', '--npm', '>=6.0.0', ] : [];