-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
build:package-types: Run silently to reduce user confusion #61530
Conversation
Follows up on #61501. The original PR, #61501, modified the `build:package-types` script to log a help message to developers if the `tsc --build` call failed. This message suggested a fix (to run `npm run clean:package-types`). This works, but due to the way that NPM logs the execution of successive NPM scripts, the code that conditionally outputs the help message is, itself, always output. This is not only noisy, but could mislead developers into following the help message's instruction unnecessarily. This commit fixes the problem by wrapping the original NPM script in a new script, which is then called with NPM's `--silent` flag. The console output now looks like this: > [email protected] build:packages > npm run build:package-types && node ./bin/packages/build.js > [email protected] build:package-types > npm run --silent build:package-types:verbose
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. |
Size Change: 0 B Total Size: 1.74 MB ℹ️ View Unchanged
|
package.json
Outdated
@@ -268,7 +268,8 @@ | |||
"scripts": { | |||
"build": "npm run build:packages && wp-scripts build", | |||
"build:analyze-bundles": "npm run build -- --webpack-bundle-analyzer", | |||
"build:package-types": "node ./bin/packages/validate-typescript-version.js && ( tsc --build || ( echo 'tsc failed. Try cleaning up first: `npm run clean:package-types`'; exit 1 ) ) && node ./bin/packages/check-build-type-declaration-files.js", | |||
"build:package-types": "npm run --silent build:package-types:verbose", | |||
"build:package-types:verbose": "node ./bin/packages/validate-typescript-version.js && ( tsc --build || ( echo 'tsc failed. Try cleaning up first: `npm run clean:package-types`'; exit 1 ) ) && node ./bin/packages/check-build-type-declaration-files.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need two scripts, can we just keep one by default have an option to make it verbose or silent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, printing the failure could go in another script:
tsc --build || npm run print-typescript-clean-suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need two scripts, can we just keep one by default have an option to make it verbose or silent?
If you don't have an issue with the delegation of responsibilities, I could keep just one script and modify the flags at the caller:
- "build:packages": "npm run build:package-types && node ./bin/packages/build.js",
+ "build:packages": "npm run --silent build:package-types && node ./bin/packages/build.js",
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -270,7 +270,7 @@ | |||
"build:analyze-bundles": "npm run build -- --webpack-bundle-analyzer", | |||
"build:package-types": "node ./bin/packages/validate-typescript-version.js && ( tsc --build || ( echo 'tsc failed. Try cleaning up first: `npm run clean:package-types`'; exit 1 ) ) && node ./bin/packages/check-build-type-declaration-files.js", | |||
"prebuild:packages": "npm run clean:packages && lerna run build", | |||
"build:packages": "npm run build:package-types && node ./bin/packages/build.js", | |||
"build:packages": "npm run --silent build:package-types && node ./bin/packages/build.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it also suppress the error if it happens? Could we run something like --loglevel error
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevin940726: As far as I can tell, it only suppresses NPM errors. For instance, npm run --silent foobar
yields
npm error Missing script: "foobar"
npm error
npm error To see a list of scripts, run:
npm error npm run
npm error A complete log of this run can be found in: /Users/…/.npm/_logs/….log
It's not great but it's good enough for the problem. The thing is that I find it hard to justify spending any more time on this, especially since testing requires checking out a commit predating the type changes, clearing all type data, rebuilding everything, then jumping back to trunk and testing the script — and doing this for the different scenarios. The proper way to do it would be the way I initially drafted it: with a standalone script that lives in bin/
and orchestrates everything. I can write it by heart and I'm 95% this will work:
# bin/build-package-types
#########################
#!/bin/sh
# Exit if any command fails.
set -e
# Change to the expected directory.
cd "$(dirname "$0")"
cd ..
echo "Validating TypeScript version..."
node ./bin/packages/validate-typescript-version.js
echo "Building (`tsc --build`)..."
if ! tsc --build; then
echo 'tsc failed. Try cleaning up first: `npm run clean:package-types`'
exit 1
fi
echo "Checking build type declaration files..."
node ./bin/packages/check-build-type-declaration-files.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with a standalone script that lives in
bin/
and orchestrates everything.
Sorry I think I missed the convo. Why did we move away from this approach?
Follows up on #61501.
The original PR, #61501, modified the
build:package-types
script to log a help message to developers if thetsc --build
call failed. This message suggested a fix (to runnpm run clean:package-types
).This works, but due to the way that NPM logs the execution of successive NPM scripts, the code that conditionally outputs the help message is, itself, always output. This is not only noisy, but could mislead developers into following the help message's instruction unnecessarily.
This PR fixes the problem by requiring the caller script (
build:packages
) to use NPM's--silent
flag. The console output now looks like this: