Skip to content

Commit

Permalink
Stop using Babel tranpiliation for two packages
Browse files Browse the repository at this point in the history
babel-plugin-import-jsx-pragma and postcss-themes
  • Loading branch information
gziolo committed Jan 28, 2019
1 parent e7f5447 commit ff6a5da
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 72 deletions.
13 changes: 3 additions & 10 deletions bin/packages/get-babel-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -37,7 +30,7 @@ const babelConfigs = {
{
plugins,
presets: map(
babelDefaultConfig.presets,
presets,
( preset ) => overrideOptions( preset, '@babel/preset-env', {
modules: 'commonjs',
} )
Expand All @@ -55,7 +48,7 @@ const babelConfigs = {
} )
),
presets: map(
babelDefaultConfig.presets,
presets,
( preset ) => overrideOptions( preset, '@babel/preset-env', {
modules: false,
} )
Expand Down
38 changes: 2 additions & 36 deletions bin/packages/get-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down
7 changes: 2 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,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\"",
Expand Down
6 changes: 6 additions & 0 deletions packages/babel-plugin-import-jsx-pragma/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.0.0 (Unreleased)

### Breaking change

- Stop using Babel transpilation internally and set node 8 as a minimal version required.

## 1.1.0 (2018-09-05)

### New Feature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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( {}, state.opts, DEFAULT_OPTIONS );
}

return state._options;
Expand Down Expand Up @@ -99,4 +96,4 @@ export default function( babel ) {
},
},
};
}
};
12 changes: 5 additions & 7 deletions packages/babel-plugin-import-jsx-pragma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.0.0"
},
"main": "index.js",
"peerDependencies": {
"@babel/core": "^7.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-import-jsx-pragma/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {} ) {
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-preset-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"engines": {
"node": ">=8"
},
"files": [
"index.js"
],
"main": "index.js",
"dependencies": {
"@babel/core": "^7.0.0",
Expand All @@ -30,6 +33,7 @@
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/runtime": "^7.0.0",
"@wordpress/babel-plugin-import-jsx-pragma": "file:../babel-plugin-import-jsx-pragma",
"@wordpress/browserslist-config": "file:../browserslist-config",
"babel-core": "^7.0.0-bridge.0"
},
Expand Down
5 changes: 5 additions & 0 deletions packages/postcss-themes/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 2.0.0 (Unreleased)

### Breaking change

- Stop using Babel transpilation internally and set node 8 as a minimal version required.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* External dependencies
*/
const postcss = require( 'postcss' );

module.exports = postcss.plugin( 'postcss-themes', function( options ) {
Expand Down
9 changes: 5 additions & 4 deletions packages/postcss-themes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.0.0",
"autoprefixer": "^9.4.5",
"postcss": "^7.0.13",
"postcss-color-function": "^4.0.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-themes/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import postcss from 'postcss';
/**
* Internal dependencies
*/
import plugin from '../src';
import plugin from '../';

/**
* Module constants
Expand Down

0 comments on commit ff6a5da

Please sign in to comment.