-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Simplify or remove several package.json scripts #38931
Conversation
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Webpack Runtime (~2055 bytes added 📈 [gzipped])
Webpack runtime for loading modules. It is included in the HTML page as an inline script. Is downloaded and parsed every time the app is loaded. App Entrypoints (~94353 bytes removed 📉 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Sections (~685619 bytes added 📈 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~488489 bytes removed 📉 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
Technically, #38576 did not cause a regression. This initial code change was necessary to address changes to memory constraints for wp-desktop that were introduced by Node 12. This change wasn’t an issue until the conversion of the Calypso client into a lerna package. Regardless - I think it’s worth calling out the language used here. We shouldn’t encourage a culture of finger-pointing. Not saying this was anyone’s intention, but such phrasing could easily be construed this way. We all work together on the same team. Moving forward, we should all (myself included) be mindful of the language we use when solving these issues as they come up. |
Hi @nsakaimbo 👋 I apologize for not being careful about the phrasing I used. I wanted to call your attention to the part of the diff where your review would be valuable, not to assign blame to you or anyone else. I agree that would be unproductive and pointless. I still believe that #38576 introduced a change into the
runs the
fails to run the script at all, as it passes the
|
Splitting that out into its own script sounds good to me! It should help contain changes too, as I believe newer
That's actually one of my favourite and most often used tools in bringing down bundle sizes, so thank you for fixing that! 🙂 |
package.json
Outdated
"build-client-evergreen": "cross-env-shell BROWSERSLIST_ENV=evergreen NODE_PATH=$NODE_PATH:server:client:. node $NODE_ARGS ./node_modules/webpack/bin/webpack.js --config client/webpack.config.js --display errors-only", | ||
"build-client-fallback": "cross-env-shell BROWSERSLIST_ENV=defaults node $NODE_ARGS ./node_modules/webpack/bin/webpack.js --config client/webpack.config.js --display errors-only", | ||
"postbuild-client-fallback": "npm run validate-fallback-es5", | ||
"build-client-evergreen": "cross-env-shell BROWSERSLIST_ENV=evergreen node $NODE_ARGS ./node_modules/webpack/bin/webpack.js --config client/webpack.config.js --display errors-only", | ||
"build-client-both": "CONCURRENT_BUILDS=2 concurrently -c cyan -n \"fallback ,evergreen\" \"npm run build-client-fallback\" \"npm run build-client-evergreen\"", | ||
"build-client-if-prod": "node -e \"process.env.CALYPSO_ENV === 'production' && process.exit(1)\" || cross-env-shell NODE_ARGS=${NODE_ARGS:---max_old_space_size=8192} npm run build-client-both", |
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.
I know this code was already here, but why do some scripts (like this one) extend NODE_ARGS
, while others (like preanalyze-bundles
and prewhybundled
) rewrite it?
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.
why do some scripts extend
NODE_ARGS
, while others rewrite it?
That's a good point and I'm cleaning up NODE_ARGS
in 42fb4f6 and further consolidating the build scripts in 1d99184
After these changes, the scripts set and use the NODE_ARGS
variable only at the place where node
is actually spawned to run webpack or the server bundle -- build-client-do
and start-bundle-do
, respectively.
No other tasks set max_old_space_size
now. The default value is OK for everyone, and there's also a way (used by wp-desktop
) to override it by setting the NODE_ARGS
environment variable.
The build-client-do
consolidation works as follows: instead of two NPM tasks:
"build-client-fallback": "cross-env-shell BROWSERSLIST_ENV=fallback node bin/webpack [lot of webpack and node arguments]"
"build-client-evergreen": "cross-env-shell BROWSERSLIST_ENV=evergreen node bin/webpack [lot of webpack and node arguments]"
there are three and duplication is removed:
"build-client-do": "node bin/webpack [lot of webpack and node arguments]"
"build-client-fallback": "cross-env-shell BROWSERSLIST_ENV=fallback npm run build-client-do"
"build-client-evergreen": "cross-env-shell BROWSERSLIST_ENV=evergreen npm run build-client-do"
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.
That's a great solution, thank you! 👍
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.
I'd like to try out the NODE_OPTIONS
environment variable, too. It's supported directly by Node.js, and was added only in 8.x, which is not that ancient. We probably started setting max_old_space_size
at a time when NODE_OPTIONS
wasn't available yet.
"clean": "npm run -s clean:build && npm run -s clean:devdocs && npm run -s clean:public && npm run -s clean:packages", | ||
"clean:build": "npx rimraf build server/bundler/*.json .babel-cache", | ||
"clean:devdocs": "npx rimraf server/devdocs/search-index.js", | ||
"clean": "run-s -s clean:*", |
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.
Very nice 👍
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.
run-p
might be even faster for those of us with SSDs
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.
I considered run-p
, too, but was afraid of race conditions like npx rimraf
doing the download and install two times in parallel.
@jsnajdr Thanks for handling my feedback in a constructive and positive way. I figured it would be better to err on the side of being transparent about any potential misunderstandings, and glad to hear we're on the same page. 😄 I appreciate the breakdown of the underlying issue - I was definitely unaware this change inadvertently borked the |
Finishes the removal started in #27979.
… invoked Updates the paths of generated files to remove (`server/` to `client/server/`), use `run-s` to run all `clean:*` scripts at once.
Makes lines in `package.json` shorter 🙂
`node NODE_ARGS=...` is an error that fails the script invocation: ``` Error: Cannot find module '/Users/jsnajdr/src/wp-desktop/calypso/NODE_ARGS=--max_old_space_size=8192' ``` We want to invoke `node` with `$NODE_ARGS` arguments and supply a default.
…ypso It was needed only to `require` two specific files (webpack config for webpack dev server and search index for devdocs). Updated the webpack `externals` definition to remove that need.
…ross-env and a *-do subtask
5bd0639
to
1d99184
Compare
@nsakaimbo As far as I know, the
Yes, that should be possible with one caveat: you'll need to update externals definitions in the webpack config: https://github.com/Automattic/wp-desktop/blob/develop/webpack.shared.js#L76-L78 so that they are mapped to paths relative to the current working directory when running the server bundle. See the changes that this PR does to the The |
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.
LGTM! Thank you for fixing these issues!
package.json
Outdated
@@ -86,8 +87,9 @@ | |||
"start": "npm run -s build", | |||
"poststart": "run-p -s start-build-if-web start-build-if-desktop build-packages:watch", | |||
"reformat-files": "./node_modules/.bin/prettier --ignore-path .eslintignore --write \"**/*.{js,jsx,json,ts,tsx}\"", | |||
"start-build-fallback": "cross-env-shell BROWSERSLIST_ENV=defaults NODE_PATH=$NODE_PATH:server:client:. node NODE_ARGS=${NODE_ARGS:---max_old_space_size=8192} build/bundle.js", | |||
"start-build-evergreen": "cross-env-shell BROWSERSLIST_ENV=evergreen NODE_PATH=$NODE_PATH:server:client:. node $NODE_ARGS --max_old_space_size=8192 build/bundle.js", | |||
"start-build-do": "cross-env-shell node ${NODE_ARGS:---max_old_space_size=8192} build/bundle.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.
i had no idea this syntax was possible ${NODE_ARGS:---max_old_space_size=8192}
is that a cross-env-shell thing or a npm scripts
thing?
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.
I think it may be missing NODE_ARGS=
beforehand, judging by the other lines.
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.
It's a bash syntax for fancy parameter expansion and setting default values. See the "Default Values" section in https://devhints.io/bash#parameter-expansions
cross-env-shell
does some transforms to the bash-like command line that make it compatible with Windows cmd.exe. But it won't understand the ${FOO:-val}
syntax and this will be one of many things broken in Windows build.
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.
I removed cross-env-shell
from this particular script, as it doesn't set any environment variables.
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.
I think it may be missing
NODE_ARGS=
beforehand, judging by the other lines.
NODE_ARGS=
is needed only if the caller wants to add some Node.js command line options, or override the default value of max_old_space_size
. Currently, the only place that does this is the wp-desktop
build.
@@ -111,8 +113,8 @@ | |||
"typecheck": "tsc --noEmit", | |||
"update-deps": "npx rimraf package-lock.json && npm run -s distclean && npm i && replace --silent 'http://' 'https://' . --recursive --include='package-lock.json' && touch -m node_modules", | |||
"validate-fallback-es5": "npx eslint --parser-options=ecmaVersion:5 --no-eslintrc --no-ignore ./public/fallback/*.js", | |||
"prewhybundled": "cross-env-shell CALYPSO_ENV=production EMIT_STATS=withreasons NODE_ARGS=--max_old_space_size=8192 npm run -s build-client", | |||
"whybundled": "whybundled stats.json", | |||
"prewhybundled": "cross-env-shell CALYPSO_ENV=production EMIT_STATS=withreasons npm run -s build-client-evergreen", |
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.
is there a way to skip this if we already have a client/stats.json
?
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.
Not easily, this is not Makefile
🤣
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.
couple little nits, but this is good progress! LGTM
@@ -111,8 +113,8 @@ | |||
"typecheck": "tsc --noEmit", | |||
"update-deps": "npx rimraf package-lock.json && npm run -s distclean && npm i && replace --silent 'http://' 'https://' . --recursive --include='package-lock.json' && touch -m node_modules", | |||
"validate-fallback-es5": "npx eslint --parser-options=ecmaVersion:5 --no-eslintrc --no-ignore ./public/fallback/*.js", | |||
"prewhybundled": "cross-env-shell CALYPSO_ENV=production EMIT_STATS=withreasons NODE_ARGS=--max_old_space_size=8192 npm run -s build-client", | |||
"whybundled": "whybundled stats.json", | |||
"prewhybundled": "cross-env-shell CALYPSO_ENV=production EMIT_STATS=withreasons npm run -s build-client-evergreen", |
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.
I don't think we need to worry about x-platform support here, we can do something like the following:
[[ -f client/stats.json ]] && echo '`client/stats.json exists, skipping generation. To rebuild, remove the stats.json file.' || CALYPSO_ENV=production EMIT_STATS=withreasons npm run -s build-client-evergreen
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 bear in mind that the stats file may already exist but not be the one we want, e.g. if npm run analyze-bundles
was previously run (that one doesn't contain reasons). If we're going to do this, we should rename the file to stats-with-reasons.json
to make it very clear this is the one we want.
Also, not sure how we should handle staleness. Presumably the developer will be able to tell that it took no time at all and thus it was an existing, possibly stale file?
Bunch of simplifications of the npm scripts in
package.json
. Followup to #38190 that fixes plenty of things.Eliminate the need for setting NODE_PATH when building or running Calypso
It was needed only to
require
two specific files (webpack config for webpack dev server and search index for devdocs). Updated the webpackexternals
definition to remove that need.Fix the NODE_ARGS argument in the start-build scripts
node NODE_ARGS=...
is an error that fails the script invocation:We want to invoke
node
with$NODE_ARGS
arguments and supply a default.Cc @nsakaimbo who introduced the regression in #38576.
Validate fallback build in a separate
post*
scriptMakes lines in
package.json
shorter 🙂 Cc @sgomesUpdate path to stats.json file in
whybundled
scriptThe (rarely used)
npm run whybundled
didn't have a correct path tostats.json
(insideclient/
since the monorepo-ization)Update clean scripts
Updates the paths of generated files to remove (
server/
toclient/server/
), usesrun-s
to run allclean:*
scripts at once.Remove the analyze-css NPM script
Finishes the removal started in #27979.