diff --git a/package-lock.json b/package-lock.json index ccaaa56b7d2e5f..973163b96c9b2f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,11 +13,7 @@ "packages/*", "routes/*", "storybook", - "test/e2e", - "test/integration", - "test/performance", - "test/storybook-playwright", - "test/unit", + "test/*", "tools/*", "widgets/*" ], @@ -38,9 +34,7 @@ "lint-staged": "^16.4.0", "npm-run-all": "^4.1.5", "patch-package": "^8.0.0", - "rimraf": "^5.0.10", "syncpack": "^15.3.1", - "typescript": "npm:@typescript/typescript6@^6.0.2", "wait-on": "^8.0.1" }, "engines": { @@ -13524,7 +13518,6 @@ "version": "6.0.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", - "dev": true, "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", @@ -40842,7 +40835,6 @@ "version": "6.0.2", "resolved": "https://registry.npmjs.org/@typescript/typescript6/-/typescript6-6.0.2.tgz", "integrity": "sha512-mbCddXd+jm7hfx7w2YU64/Av4/NqqeG3GoRZgxPcgoTxYjhrcfJRw9ULch71SS4G+Q3bOXFhRvPqjguN0Hyp5w==", - "dev": true, "license": "Apache-2.0", "dependencies": { "@typescript/old": "npm:typescript@^6" @@ -45778,7 +45770,8 @@ "@types/eslint": "^9", "@types/estree": "^1.0.8", "@typescript-eslint/parser": "^8.57.1", - "eslint": "^10.0.0" + "eslint": "^10.0.0", + "typescript": "npm:@typescript/typescript6@^6.0.2" }, "engines": { "node": ">=18.12.0", @@ -48878,6 +48871,7 @@ "storybook": "^10.4.3", "storybook-addon-tag-badges": "^3.0.4", "terser": "^5.37.0", + "typescript": "npm:@typescript/typescript6@^6.0.2", "vite": "^7.3.2" } }, @@ -48940,7 +48934,8 @@ "@wordpress/rich-text": "file:../../packages/rich-text", "ajv": "^8.17.1", "fast-glob": "^3.2.7", - "react": "^18.3.1" + "react": "^18.3.1", + "rimraf": "^5.0.10" } }, "test/performance": { @@ -49018,6 +49013,7 @@ "magic-string": "^0.30.21", "react": "^18.3.1", "react-dom": "^18.3.1", + "rimraf": "^5.0.10", "source-map": "^0.6.1" } }, @@ -49036,7 +49032,8 @@ "fast-glob": "^3.2.7", "glob": "^7.1.2", "json2md": "^2.0.1", - "react-docgen-typescript": "^2.4.0" + "react-docgen-typescript": "^2.4.0", + "typescript": "npm:@typescript/typescript6@^6.0.2" } }, "tools/eslint": { @@ -49062,6 +49059,7 @@ "glob": "^7.1.2", "globals": "^16.0.0", "react": "^18.3.1", + "typescript": "npm:@typescript/typescript6@^6.0.2", "typescript-eslint": "^8.57.1" } }, diff --git a/package.json b/package.json index 7b0688675b3c1d..19cad614572c67 100644 --- a/package.json +++ b/package.json @@ -81,9 +81,7 @@ "lint-staged": "^16.4.0", "npm-run-all": "^4.1.5", "patch-package": "^8.0.0", - "rimraf": "^5.0.10", "syncpack": "^15.3.1", - "typescript": "npm:@typescript/typescript6@^6.0.2", "wait-on": "^8.0.1" }, "overrides": { @@ -92,8 +90,8 @@ "scripts": { "build": "npm run --workspace @wordpress/build-scripts build:all --", "build:plugin-zip": "bash ./bin/build-plugin-zip.sh", - "clean:package-types": "tsc --build --clean && rimraf --glob \"./packages/*/build-types\"", - "clean:packages": "rimraf --glob \"./packages/*/{build,build-module,build-wp,build-style}\" \"./build\"", + "clean:package-types": "npm run --workspace @wordpress/build-scripts clean:package-types --", + "clean:packages": "npm run --workspace @wordpress/build-scripts clean:packages --", "dev": "npm run --workspace @wordpress/build-scripts dev --", "distclean": "git clean --force -d -X", "docs:api-ref": "npm run --workspace @wordpress/docs-tools docs:api-ref --", @@ -105,7 +103,7 @@ "docs:gen": "npm run --workspace @wordpress/docs-tools docs:gen --", "docs:theme-ref": "npm run --workspace @wordpress/docs-tools docs:theme-ref --", "env": "wp-env", - "fixtures:clean": "rimraf --glob \"test/integration/fixtures/blocks/*.{json,serialized.html}\"", + "fixtures:clean": "npm run --workspace @wordpress/integration-tests fixtures:clean --", "fixtures:generate": "cross-env GENERATE_MISSING_FIXTURES=y npm run test:unit -- test/integration/full-content/ && npm run format test/integration/fixtures/blocks/*.json", "fixtures:regenerate": "npm-run-all fixtures:clean fixtures:generate", "format": "wp-scripts format", @@ -182,11 +180,7 @@ "packages/*", "routes/*", "storybook", - "test/e2e", - "test/integration", - "test/performance", - "test/storybook-playwright", - "test/unit", + "test/*", "tools/*", "widgets/*" ] diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index e64622c6799639..2e5318ac681030 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -66,7 +66,8 @@ "@types/eslint": "^9", "@types/estree": "^1.0.8", "@typescript-eslint/parser": "^8.57.1", - "eslint": "^10.0.0" + "eslint": "^10.0.0", + "typescript": "npm:@typescript/typescript6@^6.0.2" }, "peerDependencies": { "@babel/core": ">=7", diff --git a/storybook/package.json b/storybook/package.json index 26dd219277c06c..c0336fa715fe0c 100644 --- a/storybook/package.json +++ b/storybook/package.json @@ -65,6 +65,7 @@ "storybook": "^10.4.3", "storybook-addon-tag-badges": "^3.0.4", "terser": "^5.37.0", + "typescript": "npm:@typescript/typescript6@^6.0.2", "vite": "^7.3.2" }, "publishConfig": { diff --git a/test/integration/package.json b/test/integration/package.json index 059a3ccfa0a60f..fc9d61eeea0b47 100644 --- a/test/integration/package.json +++ b/test/integration/package.json @@ -36,9 +36,13 @@ "@wordpress/rich-text": "file:../../packages/rich-text", "ajv": "^8.17.1", "fast-glob": "^3.2.7", - "react": "^18.3.1" + "react": "^18.3.1", + "rimraf": "^5.0.10" }, "publishConfig": { "access": "public" + }, + "scripts": { + "fixtures:clean": "rimraf --glob \"fixtures/blocks/*.{json,serialized.html}\"" } } diff --git a/tools/build-scripts/build.mjs b/tools/build-scripts/build.mjs index d8a6724b6fb1c6..a345935a96f5cd 100644 --- a/tools/build-scripts/build.mjs +++ b/tools/build-scripts/build.mjs @@ -117,7 +117,11 @@ async function build() { } console.log( '\n🧹 Cleaning packages...' ); - await exec( 'npm', [ 'run', 'clean:packages' ], { silent: true } ); + await exec( + 'node', + [ path.join( __dirname, 'clean.mjs' ), '--packages' ], + { silent: true } + ); console.log( '\n📦 Building workspaces...' ); await exec( diff --git a/tools/build-scripts/clean.mjs b/tools/build-scripts/clean.mjs new file mode 100644 index 00000000000000..51227fb0bd1865 --- /dev/null +++ b/tools/build-scripts/clean.mjs @@ -0,0 +1,60 @@ +#!/usr/bin/env node + +/** + * External dependencies + */ +import spawn from 'cross-spawn'; +import path from 'path'; +import { rimraf } from 'rimraf'; +import { fileURLToPath } from 'url'; +import { parseArgs } from 'util'; + +const __dirname = path.dirname( fileURLToPath( import.meta.url ) ); +const ROOT_DIR = path.resolve( __dirname, '../..' ); + +const { values } = parseArgs( { + options: { + packages: { type: 'boolean', default: false }, + types: { type: 'boolean', default: false }, + }, + strict: false, +} ); + +if ( ! values.packages && ! values.types ) { + console.error( 'Usage: node ./clean.mjs [--packages] [--types]' ); + process.exit( 1 ); +} + +/** + * Remove paths matching the given globs, resolved from the repository root. + * + * @param {string[]} patterns Glob patterns. + * @return {Promise} Promise that resolves once the paths are removed. + */ +function remove( patterns ) { + return rimraf( patterns, { glob: { cwd: ROOT_DIR, absolute: true } } ); +} + +if ( values.types ) { + /* + * TypeScript tracks its own output through `.tsbuildinfo` files, so it has to + * remove those itself before the emitted directories are deleted. + */ + const { status } = spawn.sync( 'tsc', [ '--build', '--clean' ], { + cwd: ROOT_DIR, + stdio: 'inherit', + } ); + + if ( status !== 0 ) { + process.exit( status ?? 1 ); + } + + await remove( [ 'packages/*/build-types' ] ); +} + +if ( values.packages ) { + await remove( [ + 'packages/*/{build,build-module,build-wp,build-style}', + 'build', + ] ); +} diff --git a/tools/build-scripts/dev.mjs b/tools/build-scripts/dev.mjs index 9c1b8ceaef803d..1971c04e5c15fe 100644 --- a/tools/build-scripts/dev.mjs +++ b/tools/build-scripts/dev.mjs @@ -156,7 +156,11 @@ async function dev() { } console.log( '\n🧹 Cleaning packages...' ); - await exec( 'npm', [ 'run', 'clean:packages' ], { silent: true } ); + await exec( + 'node', + [ path.join( __dirname, 'clean.mjs' ), '--packages' ], + { silent: true } + ); console.log( '\n📦 Building workspaces...' ); await exec( diff --git a/tools/build-scripts/package.json b/tools/build-scripts/package.json index 46d2a8a39c35df..ba1a15b63b51b7 100644 --- a/tools/build-scripts/package.json +++ b/tools/build-scripts/package.json @@ -37,6 +37,7 @@ "magic-string": "^0.30.21", "react": "^18.3.1", "react-dom": "^18.3.1", + "rimraf": "^5.0.10", "source-map": "^0.6.1" }, "publishConfig": { @@ -44,6 +45,8 @@ }, "scripts": { "build:all": "node ./build.mjs", + "clean:package-types": "node ./clean.mjs --types", + "clean:packages": "node ./clean.mjs --packages", "dev": "node ./dev.mjs", "build-vendors": "node ./packages/build-vendors.mjs", "generate-worker-placeholders": "node ./packages/generate-worker-placeholders.mjs", diff --git a/tools/docs/package.json b/tools/docs/package.json index 8c97b1706b7791..e750a62d109e03 100644 --- a/tools/docs/package.json +++ b/tools/docs/package.json @@ -30,7 +30,8 @@ "fast-glob": "^3.2.7", "glob": "^7.1.2", "json2md": "^2.0.1", - "react-docgen-typescript": "^2.4.0" + "react-docgen-typescript": "^2.4.0", + "typescript": "npm:@typescript/typescript6@^6.0.2" }, "publishConfig": { "access": "public" diff --git a/tools/eslint/package.json b/tools/eslint/package.json index 237a85d986e99a..e5c23a06a41bd6 100644 --- a/tools/eslint/package.json +++ b/tools/eslint/package.json @@ -43,6 +43,7 @@ "glob": "^7.1.2", "globals": "^16.0.0", "react": "^18.3.1", + "typescript": "npm:@typescript/typescript6@^6.0.2", "typescript-eslint": "^8.57.1" }, "publishConfig": {