Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lodash: Remove completely from @wordpress/create-block package #43362

Merged
merged 1 commit into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package-lock.json

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

30 changes: 17 additions & 13 deletions packages/create-block/lib/check-system-requirements.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
const inquirer = require( 'inquirer' );
const checkSync = require( 'check-node-version' );
const tools = require( 'check-node-version/tools' );
const { forEach } = require( 'lodash' );
const { promisify } = require( 'util' );

/**
Expand All @@ -21,13 +20,15 @@ async function checkSystemRequirements( engines ) {
log.error( 'Minimum system requirements not met!' );
log.info( '' );

forEach( result.versions, ( { isSatisfied, wanted }, name ) => {
if ( ! isSatisfied ) {
log.error(
`Error: Wanted ${ name } version ${ wanted.raw } (${ wanted.range })`
);
Object.entries( result.versions ).forEach(
( [ name, { isSatisfied, wanted } ] ) => {
if ( ! isSatisfied ) {
log.error(
`Error: Wanted ${ name } version ${ wanted.raw } (${ wanted.range })`
);
}
}
} );
);

log.info( '' );
log.error( 'The program may not complete correctly if you continue.' );
Expand All @@ -46,13 +47,16 @@ async function checkSystemRequirements( engines ) {
log.error( 'Cancelled.' );
log.info( '' );

forEach( result.versions, ( { isSatisfied, wanted }, name ) => {
if ( ! isSatisfied ) {
log.info(
tools[ name ].getInstallInstructions( wanted.raw )
);
Object.entries( result.versions ).forEach(
( [ name, { isSatisfied, wanted } ] ) => {
if ( ! isSatisfied ) {
log.info(
tools[ name ].getInstallInstructions( wanted.raw )
);
}
}
} );
);

process.exit( 1 );
}
}
Expand Down
8 changes: 3 additions & 5 deletions packages/create-block/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
const inquirer = require( 'inquirer' );
const { capitalCase } = require( 'change-case' );
const program = require( 'commander' );
const { pickBy } = require( 'lodash' );

/**
* Internal dependencies
Expand Down Expand Up @@ -77,17 +76,16 @@ program
try {
const pluginTemplate = await getPluginTemplate( templateName );
const defaultValues = getDefaultValues( pluginTemplate );
const optionsValues = pickBy(
{
const optionsValues = Object.fromEntries(
Object.entries( {
plugin,
category,
description,
namespace,
title,
wpScripts,
wpEnv,
},
( value ) => value !== undefined
} ).filter( ( [ , value ] ) => value !== undefined )
);

if ( slug ) {
Expand Down
8 changes: 3 additions & 5 deletions packages/create-block/lib/init-block.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
const { omitBy } = require( 'lodash' );
const { dirname, join } = require( 'path' );
const makeDir = require( 'make-dir' );
const { writeFile } = require( 'fs' ).promises;
Expand Down Expand Up @@ -41,8 +40,8 @@ async function initBlockJSON( {
await writeFile(
outputFile,
JSON.stringify(
omitBy(
{
Object.fromEntries(
Object.entries( {
$schema,
apiVersion,
name: namespace + '/' + slug,
Expand All @@ -57,8 +56,7 @@ async function initBlockJSON( {
editorScript,
editorStyle,
style,
},
( value ) => ! value
} ).filter( ( [ , value ] ) => !! value )
),
null,
'\t'
Expand Down
8 changes: 3 additions & 5 deletions packages/create-block/lib/init-package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
const { command } = require( 'execa' );
const { isEmpty, omitBy } = require( 'lodash' );
const npmPackageArg = require( 'npm-package-arg' );
const { join } = require( 'path' );
const writePkg = require( 'write-pkg' );
Expand Down Expand Up @@ -32,8 +31,8 @@ module.exports = async ( {

await writePkg(
cwd,
omitBy(
{
Object.fromEntries(
Object.entries( {
name: slug,
version,
description,
Expand All @@ -54,8 +53,7 @@ module.exports = async ( {
...( wpEnv && { env: 'wp-env' } ),
...customScripts,
},
},
isEmpty
} ).filter( ( [ , value ] ) => !! value )
)
);

Expand Down
7 changes: 1 addition & 6 deletions packages/create-block/lib/prompts.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
const { isEmpty } = require( 'lodash' );

/**
* Capitalizes the first letter in a string.
*
Expand Down Expand Up @@ -66,7 +61,7 @@ const dashicon = {
message:
'The dashicon to make it easier to identify your block (optional):',
validate( input ) {
if ( ! isEmpty( input ) && ! /^[a-z][a-z0-9\-]*$/.test( input ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was _.isEmpty being used on a string? So odd.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added 3 years ago and back then using Lodash was just fine for anything 🤷 .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it was about the length then you could leave it up to the regular expression that requires a starting letter. I don't remember what input can resolve to, but I guess it might be better to check if the input is a string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I've tried setting a dashicon to both 5 and an empty string and it always worked well, seems like it's always a string:

Screenshot 2022-08-18 at 16 02 32

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you for confirming.

if ( input.length && ! /^[a-z][a-z0-9\-]*$/.test( input ) ) {
return 'Invalid dashicon name specified. Visit https://developer.wordpress.org/resource/dashicons/ to discover available names.';
}

Expand Down
1 change: 0 additions & 1 deletion packages/create-block/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"execa": "^4.0.2",
"fast-glob": "^3.2.7",
"inquirer": "^7.1.0",
"lodash": "^4.17.21",
"make-dir": "^3.0.0",
"mustache": "^4.0.0",
"npm-package-arg": "^8.1.5",
Expand Down