[dev] pnpm install: speedup postinstall hooks a bit (#51538)
In this PR, we aim to improve the speed of ppm installs by making changes in ppm configuration and post-install hooks. The main principle behind the changes is to leverage the identified parallelization potential.
This commit is contained in:
parent
59aa209761
commit
bca89cb14f
7
.npmrc
7
.npmrc
|
@ -1,5 +1,12 @@
|
||||||
; adding this as npm 7 automatically installs peer dependencies but pnpm does not
|
; adding this as npm 7 automatically installs peer dependencies but pnpm does not
|
||||||
auto-install-peers=true
|
auto-install-peers=true
|
||||||
strict-peer-dependencies=false
|
strict-peer-dependencies=false
|
||||||
|
|
||||||
; See https://github.com/pnpm/pnpm/pull/8363 (we adding the setting now, to not miss when migrating to pnpm 9.7+)
|
; See https://github.com/pnpm/pnpm/pull/8363 (we adding the setting now, to not miss when migrating to pnpm 9.7+)
|
||||||
manage-package-manager-versions=true
|
manage-package-manager-versions=true
|
||||||
|
|
||||||
|
; pnpm installation speed tweaks
|
||||||
|
; https://pnpm.io/npmrc#modules-cache-max-age, 20160 is for two weeks in minutes
|
||||||
|
modules-cache-max-age=20160
|
||||||
|
; https://pnpm.io/npmrc#child-concurrency, default 5
|
||||||
|
child-concurrency=8
|
||||||
|
|
|
@ -26,8 +26,7 @@
|
||||||
"clean": "rimraf -g '**/node_modules' '**/.wireit' && pnpm store prune",
|
"clean": "rimraf -g '**/node_modules' '**/.wireit' && pnpm store prune",
|
||||||
"buildclean": "git clean --force -d -X ./packages ./plugins ./tools",
|
"buildclean": "git clean --force -d -X ./packages ./plugins ./tools",
|
||||||
"preinstall": "npx only-allow pnpm",
|
"preinstall": "npx only-allow pnpm",
|
||||||
"postinstall": "pnpm git:update-hooks",
|
"postinstall": "husky",
|
||||||
"git:update-hooks": "if test -d .git; then rm -rf .git/hooks && mkdir -p .git/hooks && husky install; else husky install; fi",
|
|
||||||
"sync-dependencies": "pnpm exec syncpack -- fix-mismatches",
|
"sync-dependencies": "pnpm exec syncpack -- fix-mismatches",
|
||||||
"utils": "./tools/monorepo-utils/bin/run"
|
"utils": "./tools/monorepo-utils/bin/run"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
const wpTextdomain = require( 'wp-textdomain' );
|
|
||||||
|
|
||||||
const dirs = process.argv.slice( 2 );
|
|
||||||
|
|
||||||
for ( dir of dirs ) {
|
|
||||||
let path = dir + '/**/*.php';
|
|
||||||
console.log("Processing: " + dir);
|
|
||||||
wpTextdomain( path, {
|
|
||||||
domain: 'woocommerce',
|
|
||||||
fix: true,
|
|
||||||
missingDomain: true,
|
|
||||||
variableDomain: true,
|
|
||||||
keywords: [
|
|
||||||
'__:1,2d',
|
|
||||||
'_e:1,2d',
|
|
||||||
'_x:1,2c,3d',
|
|
||||||
'esc_html__:1,2d',
|
|
||||||
'esc_html_e:1,2d',
|
|
||||||
'esc_html_x:1,2c,3d',
|
|
||||||
'esc_attr__:1,2d',
|
|
||||||
'esc_attr_e:1,2d',
|
|
||||||
'esc_attr_x:1,2c,3d',
|
|
||||||
'_ex:1,2c,3d',
|
|
||||||
'_n:1,2,4d',
|
|
||||||
'_nx:1,2,4c,5d',
|
|
||||||
'_n_noop:1,2,3d',
|
|
||||||
'_nx_noop:1,2,3c,4d',
|
|
||||||
'wp_set_script_translations:1,2d,3',
|
|
||||||
],
|
|
||||||
} );
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# Output colorized strings
|
|
||||||
#
|
|
||||||
# Color codes:
|
|
||||||
# 0 - black
|
|
||||||
# 1 - red
|
|
||||||
# 2 - green
|
|
||||||
# 3 - yellow
|
|
||||||
# 4 - blue
|
|
||||||
# 5 - magenta
|
|
||||||
# 6 - cian
|
|
||||||
# 7 - white
|
|
||||||
output() {
|
|
||||||
echo "$(tput setaf "$1")$2$(tput sgr0)"
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ ! -d "packages/" ]; then
|
|
||||||
output 1 "./packages doesn't exist!"
|
|
||||||
output 1 "run \"composer install\" before proceed."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Autoloader optimization is forced to prevent OOM fatal errors in JetPack Autoloader.
|
|
||||||
# We running the optimization in background to speedup build process, with dev-environments in mind.
|
|
||||||
# Building zips enforcing the optimization during the install process, so we are good around building releases as well.
|
|
||||||
output 3 "Updating autoloader classmaps..."
|
|
||||||
composer dump-autoload --optimize --quiet &
|
|
||||||
output 2 "Done"
|
|
||||||
|
|
||||||
if [ -z "$SKIP_UPDATE_TEXTDOMAINS" ]; then
|
|
||||||
# Convert textdomains
|
|
||||||
output 3 "Updating package PHP textdomains..."
|
|
||||||
|
|
||||||
# Replace text domains within packages with woocommerce
|
|
||||||
pnpm packages:fix:textdomain
|
|
||||||
output 2 "Done!"
|
|
||||||
|
|
||||||
# output 3 "Updating package JS textdomains..."
|
|
||||||
# find ./packages/woocommerce-blocks \( -iname '*.js' -o -iname '*.json' \) -exec sed -i.bak -e "s/'woo-gutenberg-products-block'/'woocommerce'/g" -e "s/\"woo-gutenberg-products-block\"/\"woocommerce\"/g" {} \;
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Cleanup backup files
|
|
||||||
find ./packages -name "*.bak" -type f -delete
|
|
||||||
output 2 "Done!"
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Required for dev and build environments: generate optimized autoloaders, safe to run in background.
|
||||||
|
composer dump-autoload --optimize --quiet &
|
||||||
|
# Required for dev environments: install tooling dependencies, if it failing we'll notice it in CI/locally.
|
||||||
|
composer bin all install --ansi &
|
|
@ -0,0 +1,6 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Required for dev and build environments: generate optimized autoloaders, safe to run in background.
|
||||||
|
composer dump-autoload --optimize --quiet &
|
||||||
|
# Required for dev environments: update tooling dependencies, not suitable to run in background.
|
||||||
|
composer bin all update --ansi
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: dev
|
||||||
|
|
||||||
|
Tweaks for better pnpm install performance.
|
|
@ -96,12 +96,10 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"post-install-cmd": [
|
"post-install-cmd": [
|
||||||
"@composer bin all install --ansi",
|
"sh ./bin/post-install.sh"
|
||||||
"sh ./bin/package-update.sh"
|
|
||||||
],
|
],
|
||||||
"post-update-cmd": [
|
"post-update-cmd": [
|
||||||
"@composer bin all update --ansi",
|
"sh ./bin/post-update.sh"
|
||||||
"sh ./bin/package-update.sh"
|
|
||||||
],
|
],
|
||||||
"test": [
|
"test": [
|
||||||
"phpunit"
|
"phpunit"
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
"build": "pnpm --if-present --workspace-concurrency=Infinity --stream --filter=\"$npm_package_name...\" '/^build:project:.*$/'",
|
"build": "pnpm --if-present --workspace-concurrency=Infinity --stream --filter=\"$npm_package_name...\" '/^build:project:.*$/'",
|
||||||
"build:project": "pnpm --if-present '/^build:project:.*$/'",
|
"build:project": "pnpm --if-present '/^build:project:.*$/'",
|
||||||
"build:project:copy-assets": "wireit",
|
"build:project:copy-assets": "wireit",
|
||||||
|
"build:project:actualize-translation-domains": "node ./bin/package-update-textdomain.js",
|
||||||
"build:zip": "./bin/build-zip.sh",
|
"build:zip": "./bin/build-zip.sh",
|
||||||
"changelog": "XDEBUG_MODE=off composer install --quiet && composer exec -- changelogger",
|
"changelog": "XDEBUG_MODE=off composer install --quiet && composer exec -- changelogger",
|
||||||
"docker:down": "pnpm exec wc-e2e docker:down",
|
"docker:down": "pnpm exec wc-e2e docker:down",
|
||||||
|
@ -48,7 +49,6 @@
|
||||||
"lint:php:fix": "composer run-script phpcbf",
|
"lint:php:fix": "composer run-script phpcbf",
|
||||||
"make:collection": "pnpm exec wc-api-tests make:collection",
|
"make:collection": "pnpm exec wc-api-tests make:collection",
|
||||||
"makepot": "composer run-script makepot",
|
"makepot": "composer run-script makepot",
|
||||||
"packages:fix:textdomain": "node ./bin/package-update-textdomain.js",
|
|
||||||
"test": "pnpm test:unit",
|
"test": "pnpm test:unit",
|
||||||
"test:api": "pnpm test:e2e:default --project=api --workers 4",
|
"test:api": "pnpm test:e2e:default --project=api --workers 4",
|
||||||
"test:e2e": "pnpm test:e2e:default --project=ui",
|
"test:e2e": "pnpm test:e2e:default --project=ui",
|
||||||
|
|
|
@ -39,12 +39,6 @@ Edit `composer.json` in the root directory and add the package and package versi
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
Next, if your package contains user translatable strings you'll need to edit `bin/package-update.sh` and instruct it to change your package textdomain to the `woocommerce` textdomain. For example:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
find ./packages/woocommerce-example-package -iname '*.php' -exec sed -i.bak -e "s/, 'woocommerce-example-package'/, 'woocommerce'/g" {} \;
|
|
||||||
```
|
|
||||||
|
|
||||||
Finally, you will need to tell core to load your package. Edit `src/Packages.php` and add your package to the list of packages there:
|
Finally, you will need to tell core to load your package. Edit `src/Packages.php` and add your package to the list of packages there:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
|
Loading…
Reference in New Issue