Create Block: Migrate Inquirer.js dependency to the new API#67877
Create Block: Migrate Inquirer.js dependency to the new API#67877
Conversation
|
Size Change: 0 B Total Size: 1.84 MB ℹ️ View Unchanged
|
|
Flaky tests detected in 29683d7. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12410450664
|
ce6eb21 to
3b146d7
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
ryanwelcher
left a comment
There was a problem hiding this comment.
Code changes LGTM. I've testing in both interactive and quick mode and everything seems to work as expected.
There was a problem hiding this comment.
I have confirmed that it works correctly on a Windows host OS.
One concern is that an error occurs when I cancel the prompt. In my environment, this occurs on both a Windows host OS and an Ubuntu OS:
$ npx wp-create-block
Let's customize your WordPress plugin with blocks:
? The template variant to use for this block: (Use arrow keys)
❯ static
dynamic
/home/t-hamano/projects/gutenberg/node_modules/@inquirer/core/dist/commonjs/lib/create-prompt.js:84
reject(new errors_js_1.ExitPromptError(`User force closed the prompt with ${code} ${signal}`));
^
ExitPromptError: User force closed the prompt with 0 null
at /home/t-hamano/projects/gutenberg/node_modules/@inquirer/core/dist/commonjs/lib/create-prompt.js:84:20
at Emitter.emit (/home/t-hamano/projects/gutenberg/node_modules/@inquirer/core/node_modules/signal-exit/dist/cjs/index.js:71:19)
at #processEmit (/home/t-hamano/projects/gutenberg/node_modules/@inquirer/core/node_modules/signal-exit/dist/cjs/index.js:240:27)
at #process.emit (/home/t-hamano/projects/gutenberg/node_modules/@inquirer/core/node_modules/signal-exit/dist/cjs/index.js:191:37)
at process.callbackTrampoline (node:internal/async_hooks:130:17)
This error doesn't seem to occur on trunk 🤔
Update: This might be a problem with the library.
3b146d7 to
db0658e
Compare
| const blockPrompts = getPrompts( | ||
| pluginTemplate, | ||
| const blockAnswers = await runPrompts( | ||
| projectTemplate, |
There was a problem hiding this comment.
I changed the name from pluginTemplate to projectTemplate as I realized that the name became confusing after we introduced the concept of scaffolding a block without a plugin. This part is used to scaffold only the block. Consequently, the name getPluginTemplate became getProjectTemplate. It's also a step towards the potential introduction of the template for a theme that needs dev tools for JavaScript and CSS.
| if ( ! configurePlugin ) { | ||
| return {}; | ||
| } | ||
| ! plugin && 'textdomain', |
There was a problem hiding this comment.
In my testing, the textdomain prompt only makes sense when --no-plugin option is selected. Otherwise, it should be equal to the plugin slug name.
6a1e4d9 to
f5c8e69
Compare
t-hamano
left a comment
There was a problem hiding this comment.
LGTM! I have confirmed that ctrl+c works on both Windows OS and Linux.
There was a problem hiding this comment.
Wait, we may also need to update the env command.
$ npm run wp-env destroy
> gutenberg@19.9.0 wp-env
> wp-env destroy
ℹ WARNING! This will remove Docker containers, volumes, networks, and images associated with the WordPress instance.
✖ inquirer.prompt is not a function
TypeError: inquirer.prompt is not a function
at destroy (/home/t-hamano/projects/gutenberg/packages/env/lib/commands/destroy.js:43:39)
|
@t-hamano, for consistency, I updated all occurrences so it's handled the same way. That also covers:
Consequently, the Gutenberg repository uses only |
t-hamano
left a comment
There was a problem hiding this comment.
Thanks for the update. I have tested again and everything seems to be working as expected.
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>


What?
Prerequisite for the work started by @eduwass:
Why?
Let's ensure that the new custom prompts support for Create Block uses the latest API to avoid the lockdown on the legacy version of the
inquirerlibrary.How?
Replaces usage of
inquirerwith the recommended@inquirer/prompts.Testing Instructions
Everything should work as before. The best way to test is to run locally the following commands:
create-block-demo.mov