Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions bin/postinstall-packages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env node
/* eslint-disable no-console */

Check failure on line 2 in bin/postinstall-packages.js

View workflow job for this annotation

GitHub Actions / JS/TS Code Quality

Requires 'eslint-enable' directive for 'no-console'.

const { execSync } = require( 'child_process' );

/**
* Build workspace packages after install when dev tooling is available.
*
* Skips builds for production installs that omit devDependencies (e.g. pnpm install --prod).
*/
function hasTypeScript() {
try {
require.resolve( 'typescript' );
return true;
} catch ( err ) {
return false;
}
}

if ( ! hasTypeScript() ) {
process.exit( 0 );
}

execSync( 'pnpm run build:tsc && pnpm run build:types', {
stdio: 'inherit',
} );
40 changes: 0 additions & 40 deletions nx.json

This file was deleted.

20 changes: 9 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@
"@code-atlantic/eslint-plugin": "^1.3.1",
"@code-atlantic/stylelint-config": "^1.3.0",
"@jest/globals": "^29.7.0",
"@nx/playwright": "20.8.4",
"@nx/storybook": "20.3.3",
"@playwright/test": "^1.50.1",
"@popup-maker/custom-templated-path-webpack-plugin": "file:./packages/custom-templated-path-webpack-plugin",
"@popup-maker/dependency-extraction-webpack-plugin": "file:./packages/dependency-extraction-webpack-plugin",
Expand All @@ -90,7 +88,6 @@
"lint-staged": "^15.2.11",
"mini-css-extract-plugin": "^2.9.2",
"minimist": "^1.2.8",
"nx": "20.8.4",
"path": "^0.12.7",
"prettier": "npm:wp-prettier@3.0.3",
"react": "^18.3.1",
Expand All @@ -103,10 +100,11 @@
},
"scripts": {
"preinstall": "npx -y only-allow pnpm",
"postinstall": "node bin/postinstall-packages.js",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the postinstall helper exists and inspect its TS-availability guard
fd -t f 'postinstall-packages.js' bin
echo '--- contents ---'
fd -t f 'postinstall-packages.js' bin --exec cat {}

Repository: PopupMaker/Popup-Maker

Length of output: 649


Fix postinstall failure handling when TypeScript is present but the build fails

bin/postinstall-packages.js correctly skips the build when typescript is missing (require.resolve('typescript') + process.exit(0)), but when TypeScript exists it runs execSync('pnpm run build:tsc && pnpm run build:types') with no try/catch—so a failing build:tsc/build:types will still fail the postinstall step and can break pnpm install.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` at line 103, The postinstall script calls execSync('pnpm run
build:tsc && pnpm run build:types') in bin/postinstall-packages.js without
protecting failures, so a failing build aborts pnpm install; wrap that execSync
call in a try/catch around the code path that runs when
require.resolve('typescript') succeeds, and in the catch log the error (use
console.error or the existing logger) and exit with code 0 (or otherwise
return/continue) so postinstall does not fail the install when build:tsc or
build:types errors; keep the existing behavior for the
require.resolve('typescript') absent case.

"build": "wp-scripts build --config webpack.config.js --config webpack.old.config.js",
"build:production": "NODE_ENV=production npm run build",
"build:tsc": "nx run-many --target=build:tsc",
"build:types": "nx run-many --target=build:types",
"build:tsc": "pnpm -r --sort --if-present run build:tsc",
"build:types": "pnpm -r --sort --if-present run build:types",
"check-engines": "wp-scripts check-engines",
"validate:dep-tree": "node bin/validate-dep-tree.js packages",
"validate:dep-tree:fix": "node bin/validate-dep-tree.js packages --fix",
Expand All @@ -123,12 +121,12 @@
"lint:md:docs": "wp-scripts lint-md-docs",
"lint:md:js": "wp-scripts lint-md-js",
"lint:pkg-json": "wp-scripts lint-pkg-json",
"packages:clean": "nx run-many --target=clean",
"packages:build:tsc": "nx run-many --target=build:tsc",
"packages:build:types": "nx run-many --target=build:types",
"packages:format": "nx run-many --target=format",
"packages:lint": "nx run-many --target=lint",
"packages-update": "wp-scripts packages-update && npx nx run-many --target=packages-update",
"packages:clean": "pnpm -r --if-present run clean",
"packages:build:tsc": "pnpm -r --sort --if-present run build:tsc",
"packages:build:types": "pnpm -r --sort --if-present run build:types",
"packages:format": "pnpm -r --parallel --if-present run format",
"packages:lint": "pnpm -r --parallel --if-present run lint",
"packages-update": "wp-scripts packages-update && pnpm -r --if-present run packages-update",
"postpackages-update": "npm run build",
"plugin-zip": "wp-scripts plugin-zip",
"start": "wp-scripts start --config webpack.config.js --config webpack.old.config.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"react": "^18.3.1"
},
"scripts": {
"prepublishOnly": "pnpm run build:tsc && pnpm run build:types",
"prepack": "pnpm run build:tsc && pnpm run build:types",
"build:tsc": "tsc",
"build:types": "tsc --build",
"watch:tsc": "tsc -w",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"lodash": "^4.18.1"
},
"scripts": {
"prepublishOnly": "pnpm run build:tsc && pnpm run build:types",
"prepack": "pnpm run build:tsc && pnpm run build:types",
"build:tsc": "tsc",
"build:types": "tsc --build",
"watch:tsc": "tsc -w",
Expand Down
2 changes: 1 addition & 1 deletion packages/cta-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@types/testing-library__jest-dom": "^6.0.0"
},
"scripts": {
"prepublishOnly": "pnpm run build:tsc && pnpm run build:types",
"prepack": "pnpm run build:tsc && pnpm run build:types",
"build:tsc": "tsc",
"build:types": "tsc --build",
"watch:tsc": "tsc -w",
Expand Down
2 changes: 1 addition & 1 deletion packages/cta-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"react": "^18.3.1"
},
"scripts": {
"prepublishOnly": "pnpm run build:tsc && pnpm run build:types",
"prepack": "pnpm run build:tsc && pnpm run build:types",
"build:tsc": "tsc",
"build:types": "tsc --build",
"watch:tsc": "tsc -w",
Expand Down
2 changes: 1 addition & 1 deletion packages/data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@wordpress/notices": "^5.29.0"
},
"scripts": {
"prepublishOnly": "pnpm run build:tsc && pnpm run build:types",
"prepack": "pnpm run build:tsc && pnpm run build:types",
"build:tsc": "tsc",
"build:types": "tsc --build",
"watch:tsc": "tsc -w",
Expand Down
2 changes: 1 addition & 1 deletion packages/fields/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"classnames": "^2.5.1"
},
"scripts": {
"prepublishOnly": "pnpm run build:tsc && pnpm run build:types",
"prepack": "pnpm run build:tsc && pnpm run build:types",
"build:tsc": "tsc",
"build:types": "tsc --build",
"watch:tsc": "tsc -w",
Expand Down
2 changes: 1 addition & 1 deletion packages/i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@wordpress/i18n": "^6.2.0"
},
"scripts": {
"prepublishOnly": "pnpm run build:tsc && pnpm run build:types",
"prepack": "pnpm run build:tsc && pnpm run build:types",
"build:tsc": "tsc",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore the per-package publish build hook

Removing prepublishOnly means a direct pnpm publish/pnpm -r publish from a clean checkout no longer builds this package before packing it; pnpm's publish lifecycle still includes prepublishOnly, and this package's main, types, and files all expect ignored build/build-types artifacts to exist. The custom bin/bump-and-publish-packages.js path builds first, but any other publish path can now ship a tarball with missing entrypoints.

Useful? React with 👍 / 👎.

"build:types": "tsc --build",
"watch:tsc": "tsc -w",
Expand Down
2 changes: 1 addition & 1 deletion packages/layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@types/wordpress__element": "^2.14.1"
},
"scripts": {
"prepublishOnly": "pnpm run build:tsc && pnpm run build:types",
"prepack": "pnpm run build:tsc && pnpm run build:types",
"build:tsc": "tsc",
"build:types": "tsc --build",
"watch:tsc": "tsc -w",
Expand Down
2 changes: 1 addition & 1 deletion packages/registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@wordpress/element": "^6.29.0"
},
"scripts": {
"prepublishOnly": "pnpm run build:tsc && pnpm run build:types",
"prepack": "pnpm run build:tsc && pnpm run build:types",
"build:tsc": "tsc",
"build:types": "tsc --build",
"watch:tsc": "tsc -w",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"wpScript": true,
"sideEffects": false,
"scripts": {
"prepublishOnly": "pnpm run build:tsc && pnpm run build:types",
"prepack": "pnpm run build:tsc && pnpm run build:types",
"build:tsc": "tsc",
"build:types": "tsc --build",
"watch:tsc": "tsc -w",
Expand Down
2 changes: 1 addition & 1 deletion packages/use-query-params/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"react-router": "^6.0.0 || ^7.0.0"
},
"scripts": {
"prepublishOnly": "pnpm run build:tsc && pnpm run build:types",
"prepack": "pnpm run build:tsc && pnpm run build:types",
"build:tsc": "tsc",
"build:types": "tsc --build",
"watch:tsc": "tsc -w",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"dependencies": {},
"peerDependencies": {},
"scripts": {
"prepublishOnly": "pnpm run build:tsc && pnpm run build:types",
"prepack": "pnpm run build:tsc && pnpm run build:types",
"build:tsc": "tsc",
"build:types": "tsc --build",
"watch:tsc": "tsc -w",
Expand Down
Loading
Loading