Skip to content

Commit

Permalink
Move config check utilities back to @wordpress/scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Apr 20, 2020
1 parent 2a39496 commit ba42a81
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 73 deletions.
3 changes: 0 additions & 3 deletions packages/scripts-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ npm install @wordpress/scripts-utils --save-dev
- `getArgFromCLI`
- `getArgsFromCLI`
- `getFileArgsFromCLI`
- `hasBabelConfig`
- `hasArgInCLI`
- `hasFileArgInCLI`
- `hasJestConfig`
- `hasPackageProp`
- `hasPrettierConfig`
- `hasProjectFile`

**Note**: This package requires `node` 10.0.0 or later. It is not compatible with older versions.
Expand Down
52 changes: 0 additions & 52 deletions packages/scripts-utils/lib/config.js

This file was deleted.

8 changes: 0 additions & 8 deletions packages/scripts-utils/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ const {
hasArgInCLI,
hasFileArgInCLI,
} = require( './cli' );
const {
hasBabelConfig,
hasJestConfig,
hasPrettierConfig,
} = require( './config' );
const { fromProjectRoot, hasProjectFile } = require( './file' );
const { hasPackageProp } = require( './package' );

Expand All @@ -21,11 +16,8 @@ module.exports = {
getArgFromCLI,
getArgsFromCLI,
getFileArgsFromCLI,
hasBabelConfig,
hasArgInCLI,
hasFileArgInCLI,
hasJestConfig,
hasPackageProp,
hasPrettierConfig,
hasProjectFile,
};
4 changes: 2 additions & 2 deletions packages/scripts/config/jest-e2e.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
const path = require( 'path' );

/**
* WordPress dependencies
* Internal dependencies
*/
const { hasBabelConfig } = require( '@wordpress/scripts-utils' );
const { hasBabelConfig } = require( '../utils' );

const jestE2EConfig = {
preset: 'jest-puppeteer',
Expand Down
6 changes: 5 additions & 1 deletion packages/scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ const path = require( 'path' );
* WordPress dependencies
*/
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
const { hasBabelConfig } = require( '@wordpress/scripts-utils' );

/**
* Internal dependencies
*/
const { hasBabelConfig } = require( '../utils' );

const isProduction = process.env.NODE_ENV === 'production';
const mode = isProduction ? 'production' : 'development';
Expand Down
3 changes: 1 addition & 2 deletions packages/scripts/scripts/format-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ const {
getArgFromCLI,
getFileArgsFromCLI,
hasArgInCLI,
hasPrettierConfig,
hasProjectFile,
} = require( '@wordpress/scripts-utils' );

/**
* Internal dependencies
*/
const { fromConfigRoot } = require( '../utils' );
const { fromConfigRoot, hasPrettierConfig } = require( '../utils' );

// Check if the project has wp-prettier installed and if the project has a Prettier config
function checkPrettier() {
Expand Down
3 changes: 1 addition & 2 deletions packages/scripts/scripts/test-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ const {
getArgsFromCLI,
hasArgInCLI,
hasProjectFile,
hasJestConfig,
} = require( '@wordpress/scripts-utils' );

/**
* Internal dependencies
*/
const { fromConfigRoot } = require( '../utils' );
const { fromConfigRoot, hasJestConfig } = require( '../utils' );

const result = spawn( 'node', [ require.resolve( 'puppeteer/install' ) ], {
stdio: 'inherit',
Expand Down
4 changes: 2 additions & 2 deletions packages/scripts/scripts/test-unit-jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ const jest = require( 'jest' );
/**
* WordPress dependencies
*/
const { getArgsFromCLI, hasJestConfig } = require( '@wordpress/scripts-utils' );
const { getArgsFromCLI } = require( '@wordpress/scripts-utils' );

/**
* Internal dependencies
*/
const { fromConfigRoot } = require( '../utils' );
const { fromConfigRoot, hasJestConfig } = require( '../utils' );

const config = ! hasJestConfig()
? [
Expand Down
44 changes: 44 additions & 0 deletions packages/scripts/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
getFileArgsFromCLI,
hasArgInCLI,
hasFileArgInCLI,
hasPackageProp,
hasProjectFile,
} = require( '@wordpress/scripts-utils' );

Expand All @@ -19,6 +20,46 @@ const {
*/
const { fromConfigRoot } = require( '../utils' );

/**
* @see https://babeljs.io/docs/en/config-files#configuration-file-types
*/
const hasBabelConfig = () =>
hasProjectFile( '.babelrc' ) ||
hasProjectFile( '.babelrc.cjs' ) ||
hasProjectFile( '.babelrc.js' ) ||
hasProjectFile( '.babelrc.json' ) ||
hasProjectFile( '.babelrc.mjs' ) ||
hasProjectFile( 'babel.config.cjs' ) ||
hasProjectFile( 'babel.config.js' ) ||
hasProjectFile( 'babel.config.json' ) ||
hasProjectFile( 'babel.config.mjs' ) ||
hasPackageProp( 'babel' );

/**
* @see https://jestjs.io/docs/en/configuration
*/
const hasJestConfig = () =>
hasArgInCLI( '-c' ) ||
hasArgInCLI( '--config' ) ||
hasProjectFile( 'jest.config.cjs' ) ||
hasProjectFile( 'jest.config.js' ) ||
hasProjectFile( 'jest.config.json' ) ||
hasProjectFile( 'jest.config.mjs' ) ||
hasPackageProp( 'jest' );

/**
* @see https://prettier.io/docs/en/configuration.html
*/
const hasPrettierConfig = () =>
hasProjectFile( '.prettierrc' ) ||
hasProjectFile( '.prettierrc.js' ) ||
hasProjectFile( '.prettierrc.json' ) ||
hasProjectFile( '.prettierrc.toml' ) ||
hasProjectFile( '.prettierrc.yaml' ) ||
hasProjectFile( '.prettierrc.yml' ) ||
hasProjectFile( 'prettier.config.js' ) ||
hasPackageProp( 'prettier' );

const hasWebpackConfig = () =>
hasArgInCLI( '--config' ) ||
hasProjectFile( 'webpack.config.js' ) ||
Expand Down Expand Up @@ -84,4 +125,7 @@ const getWebpackArgs = ( additionalArgs = [] ) => {

module.exports = {
getWebpackArgs,
hasBabelConfig,
hasJestConfig,
hasPrettierConfig,
};
10 changes: 9 additions & 1 deletion packages/scripts/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
* Internal dependencies
*/
const { spawnScript } = require( './cli' );
const { getWebpackArgs } = require( './config' );
const {
getWebpackArgs,
hasBabelConfig,
hasJestConfig,
hasPrettierConfig,
} = require( './config' );
const {
buildWordPress,
downloadWordPressZip,
Expand All @@ -17,6 +22,9 @@ module.exports = {
downloadWordPressZip,
fromConfigRoot,
getWebpackArgs,
hasBabelConfig,
hasJestConfig,
hasPrettierConfig,
mergeYAMLConfigs,
spawnScript,
};

0 comments on commit ba42a81

Please sign in to comment.