From 6ce31dbbaaf6864847bafa9c2bdfc44f3e6f1b63 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Mon, 28 Jan 2019 14:06:33 +0100 Subject: [PATCH 1/3] Include custome JSX pragma support in Babel preset --- babel.config.js | 10 ---------- packages/babel-preset-default/CHANGELOG.md | 1 + packages/babel-preset-default/index.js | 8 ++++++++ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/babel.config.js b/babel.config.js index 6a903eff6c1d94..4dc16df8337b23 100644 --- a/babel.config.js +++ b/babel.config.js @@ -3,16 +3,6 @@ module.exports = function( api ) { return { presets: [ '@wordpress/babel-preset-default' ], - plugins: [ - [ - '@wordpress/babel-plugin-import-jsx-pragma', - { - scopeVariable: 'createElement', - source: '@wordpress/element', - isDefault: false, - }, - ], - ], env: { production: { plugins: [ diff --git a/packages/babel-preset-default/CHANGELOG.md b/packages/babel-preset-default/CHANGELOG.md index 40e47005778e40..d548b55f22a037 100644 --- a/packages/babel-preset-default/CHANGELOG.md +++ b/packages/babel-preset-default/CHANGELOG.md @@ -2,6 +2,7 @@ ## Breaking Change +- Plugin updated to include `@wordpress/babel-plugin-import-jsx-pragma` plugin integration. - Removed `babel-core` dependency acting as Babel 7 bridge ([#13922](https://github.com/WordPress/gutenberg/pull/13922). Ensure all references to `babel-core` are replaced with `@babel/core` . ## 3.0.0 (2018-09-30) diff --git a/packages/babel-preset-default/index.js b/packages/babel-preset-default/index.js index a2bfedebe1b370..44a0392cd82cb2 100644 --- a/packages/babel-preset-default/index.js +++ b/packages/babel-preset-default/index.js @@ -15,6 +15,14 @@ module.exports = function( api ) { ].filter( Boolean ), plugins: [ '@babel/plugin-proposal-object-rest-spread', + [ + '@wordpress/babel-plugin-import-jsx-pragma', + { + scopeVariable: 'createElement', + source: '@wordpress/element', + isDefault: false, + }, + ], [ '@babel/plugin-transform-react-jsx', { pragma: 'createElement', } ], From 8e4910f82df06866ffb1a40f722757adccf31a1b Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Mon, 28 Jan 2019 15:01:43 +0100 Subject: [PATCH 2/3] Stop using Babel tranpiliation for two packages babel-plugin-import-jsx-pragma and postcss-themes --- bin/packages/get-babel-config.js | 13 ++----- bin/packages/get-packages.js | 38 +------------------ package-lock.json | 7 +--- package.json | 4 +- .../CHANGELOG.md | 1 + .../{src => }/index.js | 9 ++--- .../package.json | 12 +++--- .../test/index.js | 2 +- packages/babel-preset-default/CHANGELOG.md | 2 +- packages/babel-preset-default/package.json | 4 ++ packages/postcss-themes/CHANGELOG.md | 5 +++ packages/postcss-themes/{src => }/index.js | 3 ++ packages/postcss-themes/package.json | 9 +++-- packages/postcss-themes/test/index.js | 2 +- 14 files changed, 38 insertions(+), 73 deletions(-) rename packages/babel-plugin-import-jsx-pragma/{src => }/index.js (96%) create mode 100644 packages/postcss-themes/CHANGELOG.md rename packages/postcss-themes/{src => }/index.js (98%) diff --git a/bin/packages/get-babel-config.js b/bin/packages/get-babel-config.js index e79bc306d07c4c..b2646da46955c2 100644 --- a/bin/packages/get-babel-config.js +++ b/bin/packages/get-babel-config.js @@ -10,14 +10,7 @@ const babel = require( '@babel/core' ); const { options: babelDefaultConfig } = babel.loadPartialConfig( { configFile: '@wordpress/babel-preset-default', } ); -const plugins = babelDefaultConfig.plugins; -if ( ! process.env.SKIP_JSX_PRAGMA_TRANSFORM ) { - plugins.push( [ '@wordpress/babel-plugin-import-jsx-pragma', { - scopeVariable: 'createElement', - source: '@wordpress/element', - isDefault: false, - } ] ); -} +const { plugins, presets } = babelDefaultConfig; const overrideOptions = ( target, targetName, options ) => { if ( get( target, [ 'file', 'request' ] ) === targetName ) { @@ -37,7 +30,7 @@ const babelConfigs = { { plugins, presets: map( - babelDefaultConfig.presets, + presets, ( preset ) => overrideOptions( preset, '@babel/preset-env', { modules: 'commonjs', } ) @@ -55,7 +48,7 @@ const babelConfigs = { } ) ), presets: map( - babelDefaultConfig.presets, + presets, ( preset ) => overrideOptions( preset, '@babel/preset-env', { modules: false, } ) diff --git a/bin/packages/get-packages.js b/bin/packages/get-packages.js index 30093a22abba60..ed271db0434f23 100644 --- a/bin/packages/get-packages.js +++ b/bin/packages/get-packages.js @@ -3,7 +3,7 @@ */ const fs = require( 'fs' ); const path = require( 'path' ); -const { overEvery, compact, includes, negate } = require( 'lodash' ); +const { overEvery } = require( 'lodash' ); /** * Absolute path to packages directory. @@ -12,36 +12,6 @@ const { overEvery, compact, includes, negate } = require( 'lodash' ); */ const PACKAGES_DIR = path.resolve( __dirname, '../../packages' ); -const { - /** - * Comma-separated string of packages to include in build. - * - * @type {string} - */ - INCLUDE_PACKAGES, - - /** - * Comma-separated string of packages to exclude from build. - * - * @type {string} - */ - EXCLUDE_PACKAGES, -} = process.env; - -/** - * Given a comma-separated string, returns a filter function which returns true - * if the item is contained within as a comma-separated entry. - * - * @param {Function} filterFn Filter function to call with item to test. - * @param {string} list Comma-separated list of items. - * - * @return {Function} Filter function. - */ -const createCommaSeparatedFilter = ( filterFn, list ) => { - const listItems = list.split( ',' ); - return ( item ) => filterFn( listItems, item ); -}; - /** * Returns true if the given base file name for a file within the packages * directory is itself a directory. @@ -62,11 +32,7 @@ function isDirectory( file ) { * * @return {boolean} Whether to include file in build. */ -const filterPackages = overEvery( compact( [ - isDirectory, - INCLUDE_PACKAGES && createCommaSeparatedFilter( includes, INCLUDE_PACKAGES ), - EXCLUDE_PACKAGES && createCommaSeparatedFilter( negate( includes ), EXCLUDE_PACKAGES ), -] ) ); +const filterPackages = overEvery( isDirectory ); /** * Returns the absolute path of all WordPress packages diff --git a/package-lock.json b/package-lock.json index 4c9b3ccb412e83..064963872225fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2496,10 +2496,7 @@ }, "@wordpress/babel-plugin-import-jsx-pragma": { "version": "file:packages/babel-plugin-import-jsx-pragma", - "dev": true, - "requires": { - "@babel/runtime": "^7.3.1" - } + "dev": true }, "@wordpress/babel-plugin-makepot": { "version": "file:packages/babel-plugin-makepot", @@ -2521,6 +2518,7 @@ "@babel/plugin-transform-runtime": "^7.2.0", "@babel/preset-env": "^7.3.1", "@babel/runtime": "^7.3.1", + "@wordpress/babel-plugin-import-jsx-pragma": "file:packages/babel-plugin-import-jsx-pragma", "@wordpress/browserslist-config": "file:packages/browserslist-config" } }, @@ -2975,7 +2973,6 @@ "version": "file:packages/postcss-themes", "dev": true, "requires": { - "@babel/runtime": "^7.3.1", "autoprefixer": "^9.4.5", "postcss": "^7.0.13", "postcss-color-function": "^4.0.1" diff --git a/package.json b/package.json index 63f478e6c6fa33..eb1b308d87f2a1 100644 --- a/package.json +++ b/package.json @@ -150,8 +150,8 @@ "scripts": { "prebuild": "npm run check-engines", "clean:packages": "rimraf ./packages/*/build ./packages/*/build-module ./packages/*/build-style", - "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", + "prebuild:packages": "npm run clean:packages && lerna run build", + "build:packages": "node ./bin/packages/build.js", "build": "npm run build:packages && wp-scripts build", "check-engines": "wp-scripts check-engines", "check-licenses": "concurrently \"wp-scripts check-licenses --prod --gpl2\" \"wp-scripts check-licenses --dev\"", diff --git a/packages/babel-plugin-import-jsx-pragma/CHANGELOG.md b/packages/babel-plugin-import-jsx-pragma/CHANGELOG.md index ffa68f4404f0d4..32ad201bf1884e 100644 --- a/packages/babel-plugin-import-jsx-pragma/CHANGELOG.md +++ b/packages/babel-plugin-import-jsx-pragma/CHANGELOG.md @@ -3,6 +3,7 @@ ### Breaking Change - Plugin skips now adding import JSX pragma when the scope variable is defined for all JSX elements ([#13809](https://github.com/WordPress/gutenberg/pull/13809)). +- Stop using Babel transpilation internally and set node 8 as a minimal version required ([#13540](https://github.com/WordPress/gutenberg/pull/13540)). ## 1.1.0 (2018-09-05) diff --git a/packages/babel-plugin-import-jsx-pragma/src/index.js b/packages/babel-plugin-import-jsx-pragma/index.js similarity index 96% rename from packages/babel-plugin-import-jsx-pragma/src/index.js rename to packages/babel-plugin-import-jsx-pragma/index.js index 68e94e1ffc37d6..d431b6823aea35 100644 --- a/packages/babel-plugin-import-jsx-pragma/src/index.js +++ b/packages/babel-plugin-import-jsx-pragma/index.js @@ -26,15 +26,12 @@ const DEFAULT_OPTIONS = { * * @return {Object} Babel transform plugin. */ -export default function( babel ) { +module.exports = function( babel ) { const { types: t } = babel; function getOptions( state ) { if ( ! state._options ) { - state._options = { - ...DEFAULT_OPTIONS, - ...state.opts, - }; + state._options = Object.assign( {}, DEFAULT_OPTIONS, state.opts ); } return state._options; @@ -106,4 +103,4 @@ export default function( babel ) { }, }, }; -} +}; diff --git a/packages/babel-plugin-import-jsx-pragma/package.json b/packages/babel-plugin-import-jsx-pragma/package.json index 7dac8d0786bfb5..1adcaa57b9caa2 100644 --- a/packages/babel-plugin-import-jsx-pragma/package.json +++ b/packages/babel-plugin-import-jsx-pragma/package.json @@ -19,15 +19,13 @@ "bugs": { "url": "https://github.com/WordPress/gutenberg/issues" }, + "engines": { + "node": ">=8" + }, "files": [ - "build", - "build-module" + "index.js" ], - "main": "build/index.js", - "module": "build-module/index.js", - "dependencies": { - "@babel/runtime": "^7.3.1" - }, + "main": "index.js", "peerDependencies": { "@babel/core": "^7.0.0" }, diff --git a/packages/babel-plugin-import-jsx-pragma/test/index.js b/packages/babel-plugin-import-jsx-pragma/test/index.js index d70cf2313c540a..a10207a5d55634 100644 --- a/packages/babel-plugin-import-jsx-pragma/test/index.js +++ b/packages/babel-plugin-import-jsx-pragma/test/index.js @@ -6,7 +6,7 @@ import { transformSync } from '@babel/core'; /** * Internal dependencies */ -import plugin from '../src'; +import plugin from '../'; describe( 'babel-plugin-import-jsx-pragma', () => { function getTransformedCode( source, options = {} ) { diff --git a/packages/babel-preset-default/CHANGELOG.md b/packages/babel-preset-default/CHANGELOG.md index d548b55f22a037..3fe7a9f29b1009 100644 --- a/packages/babel-preset-default/CHANGELOG.md +++ b/packages/babel-preset-default/CHANGELOG.md @@ -2,8 +2,8 @@ ## Breaking Change -- Plugin updated to include `@wordpress/babel-plugin-import-jsx-pragma` plugin integration. - Removed `babel-core` dependency acting as Babel 7 bridge ([#13922](https://github.com/WordPress/gutenberg/pull/13922). Ensure all references to `babel-core` are replaced with `@babel/core` . +- Preset updated to include `@wordpress/babel-plugin-import-jsx-pragma` plugin integration ([#13540](https://github.com/WordPress/gutenberg/pull/13540)). ## 3.0.0 (2018-09-30) diff --git a/packages/babel-preset-default/package.json b/packages/babel-preset-default/package.json index de20169a475b62..3bb9cd8fdd80b9 100644 --- a/packages/babel-preset-default/package.json +++ b/packages/babel-preset-default/package.json @@ -21,6 +21,9 @@ "engines": { "node": ">=8" }, + "files": [ + "index.js" + ], "main": "index.js", "dependencies": { "@babel/core": "^7.2.2", @@ -30,6 +33,7 @@ "@babel/plugin-transform-runtime": "^7.2.0", "@babel/preset-env": "^7.3.1", "@babel/runtime": "^7.3.1", + "@wordpress/babel-plugin-import-jsx-pragma": "file:../babel-plugin-import-jsx-pragma", "@wordpress/browserslist-config": "file:../browserslist-config" }, "peerDependencies": { diff --git a/packages/postcss-themes/CHANGELOG.md b/packages/postcss-themes/CHANGELOG.md new file mode 100644 index 00000000000000..23a814422fd86b --- /dev/null +++ b/packages/postcss-themes/CHANGELOG.md @@ -0,0 +1,5 @@ +## 2.0.0 (Unreleased) + +### Breaking change + +- Stop using Babel transpilation internally and set node 8 as a minimal version required ([#13540](https://github.com/WordPress/gutenberg/pull/13540)). diff --git a/packages/postcss-themes/src/index.js b/packages/postcss-themes/index.js similarity index 98% rename from packages/postcss-themes/src/index.js rename to packages/postcss-themes/index.js index 5018a0dd39a4e6..9c7dd80c645013 100644 --- a/packages/postcss-themes/src/index.js +++ b/packages/postcss-themes/index.js @@ -1,3 +1,6 @@ +/** + * External dependencies + */ const postcss = require( 'postcss' ); module.exports = postcss.plugin( 'postcss-themes', function( options ) { diff --git a/packages/postcss-themes/package.json b/packages/postcss-themes/package.json index 0836e71badf9a0..4f5f233ac4eb66 100644 --- a/packages/postcss-themes/package.json +++ b/packages/postcss-themes/package.json @@ -20,13 +20,14 @@ "bugs": { "url": "https://github.com/WordPress/gutenberg/issues" }, + "engines": { + "node": ">=8" + }, "files": [ - "build", - "build-module" + "index.js" ], - "main": "build/index.js", + "main": "index.js", "dependencies": { - "@babel/runtime": "^7.3.1", "autoprefixer": "^9.4.5", "postcss": "^7.0.13", "postcss-color-function": "^4.0.1" diff --git a/packages/postcss-themes/test/index.js b/packages/postcss-themes/test/index.js index 9a670ba55a5884..45a058d6e2a31a 100644 --- a/packages/postcss-themes/test/index.js +++ b/packages/postcss-themes/test/index.js @@ -6,7 +6,7 @@ import postcss from 'postcss'; /** * Internal dependencies */ -import plugin from '../src'; +import plugin from '../'; /** * Module constants From 78208c67e4e6e8fd695983396ca6507a0f957940 Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Mon, 25 Feb 2019 10:06:36 +0100 Subject: [PATCH 3/3] Add engines field to node based packages --- packages/babel-plugin-makepot/package.json | 3 +++ packages/custom-templated-path-webpack-plugin/package.json | 3 +++ packages/e2e-test-utils/package.json | 3 +++ packages/e2e-tests/package.json | 3 +++ packages/jest-console/package.json | 3 +++ packages/jest-preset-default/package.json | 3 +++ packages/jest-puppeteer-axe/package.json | 3 +++ packages/library-export-default-webpack-plugin/package.json | 3 +++ packages/npm-package-json-lint-config/package.json | 3 +++ 9 files changed, 27 insertions(+) diff --git a/packages/babel-plugin-makepot/package.json b/packages/babel-plugin-makepot/package.json index 1dfd50b4c9984f..587ad24e1d5892 100644 --- a/packages/babel-plugin-makepot/package.json +++ b/packages/babel-plugin-makepot/package.json @@ -18,6 +18,9 @@ "bugs": { "url": "https://github.com/WordPress/gutenberg/issues" }, + "engines": { + "node": ">=8" + }, "files": [ "build", "build-module" diff --git a/packages/custom-templated-path-webpack-plugin/package.json b/packages/custom-templated-path-webpack-plugin/package.json index 4f41dc79fb0641..351b337f649182 100644 --- a/packages/custom-templated-path-webpack-plugin/package.json +++ b/packages/custom-templated-path-webpack-plugin/package.json @@ -17,6 +17,9 @@ "bugs": { "url": "https://github.com/WordPress/gutenberg/issues" }, + "engines": { + "node": ">=8" + }, "files": [ "build", "build-module" diff --git a/packages/e2e-test-utils/package.json b/packages/e2e-test-utils/package.json index ca3e6b12d913f5..2e471f32af53d1 100644 --- a/packages/e2e-test-utils/package.json +++ b/packages/e2e-test-utils/package.json @@ -17,6 +17,9 @@ "bugs": { "url": "https://github.com/WordPress/gutenberg/issues" }, + "engines": { + "node": ">=8" + }, "files": [ "build", "build-module" diff --git a/packages/e2e-tests/package.json b/packages/e2e-tests/package.json index a79a08fb53e165..84d52fa65232c1 100644 --- a/packages/e2e-tests/package.json +++ b/packages/e2e-tests/package.json @@ -17,6 +17,9 @@ "bugs": { "url": "https://github.com/WordPress/gutenberg/issues" }, + "engines": { + "node": ">=8" + }, "dependencies": { "@wordpress/e2e-test-utils": "file:../e2e-test-utils", "@wordpress/jest-console": "file:../jest-console", diff --git a/packages/jest-console/package.json b/packages/jest-console/package.json index ae0f3902fa50f7..3e46312d733653 100644 --- a/packages/jest-console/package.json +++ b/packages/jest-console/package.json @@ -18,6 +18,9 @@ "bugs": { "url": "https://github.com/WordPress/gutenberg/issues" }, + "engines": { + "node": ">=8" + }, "files": [ "build", "build-module" diff --git a/packages/jest-preset-default/package.json b/packages/jest-preset-default/package.json index fbabe4c53bc690..45276f99e6f700 100644 --- a/packages/jest-preset-default/package.json +++ b/packages/jest-preset-default/package.json @@ -20,6 +20,9 @@ "bugs": { "url": "https://github.com/WordPress/gutenberg/issues" }, + "engines": { + "node": ">=8" + }, "files": [ "scripts", "jest-preset.json" diff --git a/packages/jest-puppeteer-axe/package.json b/packages/jest-puppeteer-axe/package.json index 2c73930c9bca0e..441a6ce07eb5ef 100644 --- a/packages/jest-puppeteer-axe/package.json +++ b/packages/jest-puppeteer-axe/package.json @@ -19,6 +19,9 @@ "bugs": { "url": "https://github.com/WordPress/gutenberg/issues" }, + "engines": { + "node": ">=8" + }, "files": [ "build", "build-module" diff --git a/packages/library-export-default-webpack-plugin/package.json b/packages/library-export-default-webpack-plugin/package.json index 7222df5a7b4ff1..de2a8b72b8f4a4 100644 --- a/packages/library-export-default-webpack-plugin/package.json +++ b/packages/library-export-default-webpack-plugin/package.json @@ -17,6 +17,9 @@ "bugs": { "url": "https://github.com/WordPress/gutenberg/issues" }, + "engines": { + "node": ">=8" + }, "files": [ "build", "build-module" diff --git a/packages/npm-package-json-lint-config/package.json b/packages/npm-package-json-lint-config/package.json index 6fdb45fd6c6127..be21fd747be1a9 100644 --- a/packages/npm-package-json-lint-config/package.json +++ b/packages/npm-package-json-lint-config/package.json @@ -17,6 +17,9 @@ "bugs": { "url": "https://github.com/WordPress/gutenberg/issues" }, + "engines": { + "node": ">=8" + }, "main": "index.js", "peerDependencies": { "npm-package-json-lint": ">=3.3.1"