bin/dev.mjs: warn on stale webpack watching this checkout#78098
Conversation
`npm run dev` produces output via wp-build / esbuild into build/scripts/. A stale webpack dev server still watching this checkout (e.g. left over from a previous setup) can clobber the non-minified index.js files in build/scripts/ with webpack chunk format, breaking the editor when SCRIPT_DEBUG is enabled. Both symptoms are silent — the file just stops being valid JS. This adds a startup check that runs once before `dev()` and logs a clear warning + offending PIDs if it finds webpack processes whose command line or cwd references this checkout's path. The check is deliberately: - Scoped to ROOT_DIR + '/' so unrelated webpack processes from other projects on the same machine don't trigger false positives. - A console.warn, not process.exit, so a misdetection can't block startup. If the file is silently corrupted later, the SCRIPT_DEBUG user will notice; the warning gives them a place to look first. - Best-effort: a `ps aux` failure is swallowed silently. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: 0 B Total Size: 7.92 MB ℹ️ View Unchanged
|
mikachan
left a comment
There was a problem hiding this comment.
This tests well for me, looks good!
A review from Claude suggested changing the warning that mentions kill -9, but I don't think it necessarily needs changing:
kill -9is unnecessarily harsh. The suggested kill command usesSIGKILL, which doesn't give the webpack process a chance to clean up.kill <pids>(SIGTERM) is almost always sufficient for a dev watcher and is more polite. Consider:kill ${ pids.join(' ') }with a note thatkill -9is available as a fallback if it doesn't stop.
What?
Add a non-fatal startup check to `bin/dev.mjs` that warns if a webpack process is watching this checkout, with the offending PIDs. Best-effort, opt-out by simply not having webpack running.
Why?
`npm run dev` produces output via `wp-build` / esbuild into `build/scripts/`. A stale webpack dev server still watching this checkout (left over from a pre-migration setup, or another package's watcher with overly broad globs) can clobber the non-minified `index.js` files in `build/scripts/` with webpack chunk format. The result is:
This bug bit me while developing #76204 and burned more than a couple of hours figuring out why the bundle on disk wasn't what wp-build said it had emitted. A warning at startup would have caught it immediately.
How?
Adds a single `checkForConflictingProcesses()` function called before `dev()`. It does `ps aux`, filters lines that contain both `webpack` and this repo's path (with a trailing `/` so sibling directories like `/Users/.../gutenberg-fork/` don't false-match), and prints a warning + the matching PIDs + a kill command.
Deliberately:
Testing Instructions
Testing Instructions for Keyboard
N/A — dev tooling only.