-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hmr script #50
hmr script #50
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some negative things here. we should pair on this
watch-and-repack.sh
Outdated
|
||
# Reload webpack | ||
reload_webpack() { | ||
(cd "$PRAX_REPO_PATH" && pkill -f "webpack-dev-server") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkill is not directory constrained. in scripts you should only kill by known pid or job control.
it should be possible to signal webpack to reload without killing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally was trying to reload webpack, but changes only seemed to propagate when webpack was killed and then reloaded with pnpm dev
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkill uses pattern matching under the hood, so not being directory constrained isn't really relevant here. It's true that it will terminate any process matching the pattern regardless of the current directory, so if there are multiple webpack dev server instances running, pkill -f "pnpm run dev"
will terminate all of them.
I used a unique pattern,webpack-prax-dev-server
which only terminates webpack in prax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
webpack should have a way to output a pid, or a way to instruct it to reload modules. and if that isn't feasible it should be wrapped in something that can. pkill is the wrong approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
webpack has a built-in hot module replacement dev feature (https://webpack.js.org/guides/hot-module-replacement/), and we may be able to configure webpack.config.ts
to use HMR, but it seems tricky.
I instead modified the relevant function to use kill over pkill for a specific pid running on a specified port, which prevents spawning the extraneous webpack processes above.
reload_webpack() {
# Find the PID of the actively running webpack process
WEBPACK_PID=$(lsof -t -i:5175)
if [ -n "$WEBPACK_PID" ]; then
kill -9 $WEBPACK_PID
fi
(cd "$PRAX_REPO_PATH" && pnpm run dev &)
}
Actually, sorry see this is still in progress, my bad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still think there is a better way to acquire webpack pid but approving
references #59
watch-and-repack.sh
script simulates hot module replacement (HMR) by usingfswatch
to detect changes in thepenumbra-zone/web
repository. I think the script can be configured to optionally use the watch capabilities oftsc
. When changes are detected, the script performs the following actions in sequence:1. triggers
pack-public.sh
and repacks the packages.2. installs the tarballs as dependencies in prax.
3. reloads webpack.
this process was tricky to set up because
fswatch
was initially continuously triggering the repack process because the repack itself was causing changes that fswatch picked up, leading to an infinite loop.to use the prax dev script
(0) enable script permissions in
penumbra-zone/web
withchmod +x pack-public.sh
and inprax-wallet/web
withchmod +x watch-and-repack.sh
.(1) set the environment variables
PENUMBRA_ZONE_WEB_PATH
andPRAX_REPO_PATH
with relative paths.(2) remove npm dependencies from
prax-wallet/apps/extension/package.json
and any other local packages, e.g.(3) execute
pnpm install
.(4) execute
pnpm run watch-and-repack
, and it will wait for changes inpenumbra-zone/web
before starting the execution process.demo
hmr.mov