Update woocommerce admin scripts to align more with turborepo (#33982)

* Update woocommerce admin scripts to align more with monorepo

* Add changelog

* Add dev script back in

* Add install-if-deps-outdated back into build script

* Remove --force from dev script and add WC_ADMIN_PHASE to turbo cache key

* Remove install-if-deps-outdated from build

* Add composer install step to pr unit tests workflow

* Remove old install scripts, that are not needed anymore

* Make sure client changes are part of the cache hit

* Add composer install to code coverage and code sniff as well

* Add composer_no_dev input to install-build workflow

* Add sass dependency to woocommerce/admin/client turbo cache
This commit is contained in:
louwie17 2022-07-22 08:32:03 -03:00 committed by GitHub
parent c425b94a28
commit 383c96f0ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 38 additions and 68 deletions

View File

@ -5,6 +5,10 @@ inputs:
required: false required: false
description: The directory to target. description: The directory to target.
default: ./ default: ./
composer_no_dev:
required: false
description: COMPOSER_NO_DEV option.
default: 1
runs: runs:
using: "composite" using: "composite"
@ -17,7 +21,7 @@ runs:
- name: Install dependencies - name: Install dependencies
shell: bash shell: bash
working-directory: ${{ inputs.working_directory }} working-directory: ${{ inputs.working_directory }}
run: COMPOSER_NO_DEV=1 pnpm install run: COMPOSER_NO_DEV=${{ inputs.composer_no_dev }} pnpm install
- name: Run build - name: Run build
shell: bash shell: bash

View File

@ -46,7 +46,9 @@ jobs:
- name: Install and Build - name: Install and Build
uses: ./.github/actions/install-build uses: ./.github/actions/install-build
with:
composer_no_dev: 0
- name: Build Admin feature config - name: Build Admin feature config
run: | run: |
pnpm build:feature-config --filter=woocommerce pnpm build:feature-config --filter=woocommerce

View File

@ -35,6 +35,8 @@ jobs:
- name: Install and Build - name: Install and Build
uses: ./.github/actions/install-build uses: ./.github/actions/install-build
with:
composer_no_dev: 0
- name: Run code sniffer - name: Run code sniffer
uses: thenabeel/action-phpcs@v8 uses: thenabeel/action-phpcs@v8

View File

@ -57,6 +57,8 @@ jobs:
- name: Install and Build - name: Install and Build
uses: ./.github/actions/install-build uses: ./.github/actions/install-build
with:
composer_no_dev: 0
- name: Build Admin feature config - name: Build Admin feature config
run: | run: |

View File

@ -1,37 +0,0 @@
#!/usr/bin/env node
/**
* Performs an `pnpm install`. Since that's a costly operation,
* it will only perform it if needed, that is, if the packages
* installed at `node_modules` aren't in sync over what
* `package-lock.json` has. For that, modification times of both
* files will be compared. If the package-lock is newer, it means that
* the packages at node_modules may be outdated. That will happen,
* for example, when switching branches.
*/
const fs = require( 'fs' );
const spawnSync = require( 'child_process' ).spawnSync;
const needsInstall = () => {
try {
const shrinkwrapTime = fs.statSync( 'pnpm-lock.yaml' ).mtime;
const nodeModulesTime = fs.statSync( 'node_modules' ).mtime;
return shrinkwrapTime - nodeModulesTime > 1000; // In Windows, directory mtime has less precision than file mtime
} catch ( e ) {
return true;
}
};
if ( needsInstall() ) {
const installResult = spawnSync( 'pnpm', [ 'install' ], {
shell: true,
stdio: 'inherit',
} ).status;
if ( installResult ) {
process.exit( installResult );
}
fs.utimesSync( 'node_modules', new Date(), new Date() );
}

View File

@ -1,13 +0,0 @@
const spawnSync = require( 'child_process' ).spawnSync;
const fs = require( 'fs' );
if ( ! fs.existsSync( 'node_modules' ) ) {
console.log( 'No "node_modules" present, installing dependencies...' );
const installResult = spawnSync( 'pnpm', [ 'install' ], {
shell: true,
stdio: 'inherit',
} ).status;
if ( installResult ) {
process.exit( installResult );
}
}

View File

@ -10,18 +10,16 @@
}, },
"scripts": { "scripts": {
"analyze": "cross-env NODE_ENV=production ANALYZE=true webpack", "analyze": "cross-env NODE_ENV=production ANALYZE=true webpack",
"build": "node ./node_modules/require-turbo && pnpm run install-if-deps-outdated && pnpm run clean && WC_ADMIN_PHASE=core pnpm run build:packages && WC_ADMIN_PHASE=core pnpm run build:feature-config && cross-env NODE_ENV=production WC_ADMIN_PHASE=core webpack", "build": "node ./node_modules/require-turbo && pnpm run clean && WC_ADMIN_PHASE=core pnpm run build:feature-config && cross-env NODE_ENV=production WC_ADMIN_PHASE=core webpack",
"build:feature-config": "php ../woocommerce/bin/generate-feature-config.php", "build:feature-config": "php ../woocommerce/bin/generate-feature-config.php",
"build:packages": "cross-env NODE_ENV=production pnpm -w exec turbo run build --filter='./packages/js/*'", "build:packages": "cross-env NODE_ENV=production pnpm -w exec turbo run build --filter='./packages/js/*'",
"clean": "rimraf ../woocommerce/assets/client/admin/* && pnpm run:packages -- clean --parallel", "clean": "rimraf ../woocommerce/assets/client/admin/*",
"client:watch": "cross-env WC_ADMIN_PHASE=development pnpm run build:feature-config && cross-env WC_ADMIN_PHASE=development webpack --watch", "client:watch": "cross-env WC_ADMIN_PHASE=development pnpm run build:feature-config && cross-env WC_ADMIN_PHASE=development webpack --watch",
"create-hook-reference": "node ./bin/hook-reference/index.js", "create-hook-reference": "node ./bin/hook-reference/index.js",
"create-wc-extension": "node ./bin/starter-pack/starter-pack.js", "create-wc-extension": "node ./bin/starter-pack/starter-pack.js",
"dev": "pnpm run -s install-if-deps-outdated && cross-env WC_ADMIN_PHASE=development pnpm run build:feature-config && cross-env WC_ADMIN_PHASE=development pnpm run build:packages && cross-env WC_ADMIN_PHASE=development webpack", "dev": "cross-env WC_ADMIN_PHASE=development pnpm run build:feature-config && cross-env WC_ADMIN_PHASE=development pnpm -w exec turbo run build --filter='./packages/js/*' && cross-env WC_ADMIN_PHASE=development webpack",
"example": "webpack --config docs/examples/extensions/examples.config.js --watch", "example": "webpack --config docs/examples/extensions/examples.config.js --watch",
"preinstall": "npx only-allow pnpm", "preinstall": "npx only-allow pnpm",
"install-if-deps-outdated": "node bin/install-if-deps-outdated.js",
"install-if-no-packages": "node bin/install-if-no-packages.js",
"lint": "node ./node_modules/require-turbo && pnpm run lint:js && pnpm run lint:css", "lint": "node ./node_modules/require-turbo && pnpm run lint:js && pnpm run lint:css",
"lint:fix": "pnpm lint:js-fix && pnpm lint:css-fix", "lint:fix": "pnpm lint:js-fix && pnpm lint:css-fix",
"lint:css": "stylelint '**/*.scss'", "lint:css": "stylelint '**/*.scss'",
@ -33,21 +31,13 @@
"prepack": "pnpm install && pnpm run lint && pnpm run test && cross-env WC_ADMIN_PHASE=core pnpm run build", "prepack": "pnpm install && pnpm run lint && pnpm run test && cross-env WC_ADMIN_PHASE=core pnpm run build",
"packages:fix:textdomain": "node ./bin/package-update-textdomain.js", "packages:fix:textdomain": "node ./bin/package-update-textdomain.js",
"packages:watch": "cross-env WC_ADMIN_PHASE=development pnpm run:packages -- start --parallel", "packages:watch": "cross-env WC_ADMIN_PHASE=development pnpm run:packages -- start --parallel",
"pre-release": "./bin/pre-release.sh",
"publish-packages:check": "pnpm run build:packages && pnpm publish --dry-run --filter ../../packages/js/ --publish-branch main --report-summary && cat ../../pnpm-publish-summary.json && rimraf ../../pnpm-publish-summary.json",
"publish-packages:dev": "pnpm run build:packages && pnpm publish --filter ../../packages/js/ --publish-branch main --tag next",
"publish-packages:prod": "pnpm run build:packages && pnpm publish --filter ../../packages/js/ --publish-branch main",
"reformat-files": "wp-scripts format-js -- --ignore-path .eslintignore",
"run:packages": "pnpm run --filter ../../packages/js/", "run:packages": "pnpm run --filter ../../packages/js/",
"start": "pnpm run install-if-deps-outdated && cross-env WC_ADMIN_PHASE=development pnpm run build:packages && cross-env WC_ADMIN_PHASE=development pnpm run build:feature-config && concurrently \"cross-env WC_ADMIN_PHASE=development webpack --watch\" \"cross-env WC_ADMIN_PHASE=development pnpm run:packages -- start --parallel\"", "start": "cross-env WC_ADMIN_PHASE=development pnpm -w exec turbo run build --filter='./packages/js/*' && cross-env WC_ADMIN_PHASE=development pnpm run build:feature-config && concurrently \"cross-env WC_ADMIN_PHASE=development webpack --watch\" \"cross-env WC_ADMIN_PHASE=development pnpm packages:watch\"",
"start:package": "pnpm run:packages -- start --parallel",
"pretest": "pnpm run -s install-if-no-packages",
"test": "node ./node_modules/require-turbo && pnpm run test:client", "test": "node ./node_modules/require-turbo && pnpm run test:client",
"test-staged": "pnpm run test:client -- --bail --findRelatedTests", "test-staged": "pnpm run test:client -- --bail --findRelatedTests",
"test:client": "jest --config client/jest.config.js", "test:client": "jest --config client/jest.config.js",
"test:debug": "node --inspect-brk ./node_modules/.bin/jest --config client/jest.config.js --watch --runInBand --no-cache", "test:debug": "node --inspect-brk ./node_modules/.bin/jest --config client/jest.config.js --watch --runInBand --no-cache",
"test:help": "wp-scripts test-unit-js --help", "test:help": "wp-scripts test-unit-js --help",
"test:packages": "pnpm -w exec turbo run test --filter='./packages/js/*'",
"test:update-snapshots": "pnpm run test:client -- --updateSnapshot && pnpm run --filter @woocommerce/components test:update-snapshots", "test:update-snapshots": "pnpm run test:client -- --updateSnapshot && pnpm run --filter @woocommerce/components test:update-snapshots",
"test:watch": "pnpm run test:client -- --watch", "test:watch": "pnpm run test:client -- --watch",
"ts:check": "tsc --build ./tsconfig.json --pretty", "ts:check": "tsc --build ./tsconfig.json --pretty",

View File

@ -0,0 +1,4 @@
Significance: patch
Type: dev
Update package.json scripts within woocommerce/client/admin plugin. #33982

View File

@ -10,7 +10,7 @@
}, },
"build": { "build": {
"dependsOn": [ "^build" ], "dependsOn": [ "^build", "$WC_ADMIN_PHASE" ],
"inputs": [ "inputs": [
"src/*.js", "src/*.js",
"src/**/*.js", "src/**/*.js",
@ -47,7 +47,23 @@
"includes/**/*.php" "includes/**/*.php"
] ]
}, },
"woocommerce/client/admin#build": {
"dependsOn": [ "^build", "$WC_ADMIN_PHASE" ],
"outputs": [],
"inputs": [
"client/*.js",
"client/**/*.js",
"client/*.jsx",
"client/**/*.jsx",
"client/*.ts",
"client/**/*.ts",
"client/*.tsx",
"client/**/*.tsx",
"client/*.scss",
"client/**/*.scss"
]
},
"test": { "test": {
"dependsOn": [ "build" ], "dependsOn": [ "build" ],
"inputs": [ "inputs": [