From dd9f4544330be4aa32beb96c13a9ad9268c7e573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Mon, 20 Apr 2020 21:57:07 +0200 Subject: [PATCH] Chore: Move camelCaseDash to the package where it is consumed (#21736) --- .../test/util.js | 20 +++++++++++++++ .../util.js | 3 +-- packages/scripts/utils/index.js | 2 -- packages/scripts/utils/string.js | 19 -------------- packages/scripts/utils/test/string.js | 25 ------------------- webpack.config.js | 4 ++- 6 files changed, 24 insertions(+), 49 deletions(-) delete mode 100644 packages/scripts/utils/string.js delete mode 100644 packages/scripts/utils/test/string.js diff --git a/packages/dependency-extraction-webpack-plugin/test/util.js b/packages/dependency-extraction-webpack-plugin/test/util.js index 65bd0110ff105..8c33eb5f25b37 100644 --- a/packages/dependency-extraction-webpack-plugin/test/util.js +++ b/packages/dependency-extraction-webpack-plugin/test/util.js @@ -2,10 +2,30 @@ * Internal dependencies */ const { + camelCaseDash, defaultRequestToExternal, defaultRequestToHandle, } = require( '../util' ); +describe( 'camelCaseDash', () => { + test( 'does not change a single word', () => { + expect( camelCaseDash( 'blocks' ) ).toBe( 'blocks' ); + expect( camelCaseDash( 'dom' ) ).toBe( 'dom' ); + } ); + + test( 'does not capitalize letters following numbers', () => { + expect( camelCaseDash( 'a11y' ) ).toBe( 'a11y' ); + expect( camelCaseDash( 'i18n' ) ).toBe( 'i18n' ); + } ); + + test( 'converts dashes into camel case', () => { + expect( camelCaseDash( 'api-fetch' ) ).toBe( 'apiFetch' ); + expect( camelCaseDash( 'list-reusable-blocks' ) ).toBe( + 'listReusableBlocks' + ); + } ); +} ); + describe( 'defaultRequestToExternal', () => { test( 'Returns undefined on unrecognized request', () => { expect( defaultRequestToExternal( 'unknown-request' ) ).toBeUndefined(); diff --git a/packages/dependency-extraction-webpack-plugin/util.js b/packages/dependency-extraction-webpack-plugin/util.js index e515f752094c6..b869df904787d 100644 --- a/packages/dependency-extraction-webpack-plugin/util.js +++ b/packages/dependency-extraction-webpack-plugin/util.js @@ -79,8 +79,6 @@ function defaultRequestToHandle( request ) { * converting to uppercase, where Lodash will also capitalize letters * following numbers. * - * Temporarily duplicated from @wordpress/scripts/utils. - * * @param {string} string Input dash-delimited string. * * @return {string} Camel-cased string. @@ -92,6 +90,7 @@ function camelCaseDash( string ) { } module.exports = { + camelCaseDash, defaultRequestToExternal, defaultRequestToHandle, }; diff --git a/packages/scripts/utils/index.js b/packages/scripts/utils/index.js index 0629a0e21bcab..2c4957c1d8192 100644 --- a/packages/scripts/utils/index.js +++ b/packages/scripts/utils/index.js @@ -22,11 +22,9 @@ const { } = require( './env' ); const { fromProjectRoot, fromConfigRoot, hasProjectFile } = require( './file' ); const { hasPackageProp } = require( './package' ); -const { camelCaseDash } = require( './string' ); module.exports = { buildWordPress, - camelCaseDash, fromProjectRoot, fromConfigRoot, getArgFromCLI, diff --git a/packages/scripts/utils/string.js b/packages/scripts/utils/string.js deleted file mode 100644 index f44be223dec80..0000000000000 --- a/packages/scripts/utils/string.js +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Given a string, returns a new string with dash separators converted to - * camelCase equivalent. This is not as aggressive as `_.camelCase` in - * converting to uppercase, where Lodash will also capitalize letters - * following numbers. - * - * @param {string} string Input dash-delimited string. - * - * @return {string} Camel-cased string. - */ -function camelCaseDash( string ) { - return string.replace( /-([a-z])/g, ( match, letter ) => - letter.toUpperCase() - ); -} - -module.exports = { - camelCaseDash, -}; diff --git a/packages/scripts/utils/test/string.js b/packages/scripts/utils/test/string.js deleted file mode 100644 index aa0f441186fa1..0000000000000 --- a/packages/scripts/utils/test/string.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Internal dependencies - */ -import { camelCaseDash } from '../string'; - -describe( 'string', () => { - describe( 'camelCaseDash', () => { - test( 'does not change a single word', () => { - expect( camelCaseDash( 'blocks' ) ).toBe( 'blocks' ); - expect( camelCaseDash( 'dom' ) ).toBe( 'dom' ); - } ); - - test( 'does not capitalize letters following numbers', () => { - expect( camelCaseDash( 'a11y' ) ).toBe( 'a11y' ); - expect( camelCaseDash( 'i18n' ) ).toBe( 'i18n' ); - } ); - - test( 'converts dashes into camel case', () => { - expect( camelCaseDash( 'api-fetch' ) ).toBe( 'apiFetch' ); - expect( camelCaseDash( 'list-reusable-blocks' ) ).toBe( - 'listReusableBlocks' - ); - } ); - } ); -} ); diff --git a/webpack.config.js b/webpack.config.js index 7ee728167aeb9..340728cfe103a 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -13,7 +13,9 @@ const { basename, sep } = require( 'path' ); const CustomTemplatedPathPlugin = require( '@wordpress/custom-templated-path-webpack-plugin' ); const LibraryExportDefaultPlugin = require( '@wordpress/library-export-default-webpack-plugin' ); const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' ); -const { camelCaseDash } = require( '@wordpress/scripts/utils' ); +const { + camelCaseDash, +} = require( '@wordpress/dependency-extraction-webpack-plugin/util' ); /** * Internal dependencies