Skip to content
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

Restart on lock file changes #12086

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open

Restart on lock file changes #12086

wants to merge 1 commit into from

Conversation

matthewp
Copy link
Contributor

Changes

  • Adds common package lock files to the list of files to watch for trigger a dev server restart.

Testing

  • New unit test case added

Docs

N/A

Copy link

changeset-bot bot commented Sep 27, 2024

🦋 Changeset detected

Latest commit: 48d3e4e

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@matthewp matthewp changed the base branch from main to next September 27, 2024 11:30
@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Sep 27, 2024
@matthewp matthewp changed the title Restart on lock Restart on lock file changes Sep 27, 2024
@github-actions github-actions bot added the semver: minor Change triggers a `minor` release label Sep 27, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

@florian-lefebvre florian-lefebvre removed the semver: minor Change triggers a `minor` release label Sep 28, 2024
@bluwy
Copy link
Member

bluwy commented Sep 29, 2024

I think there was a conversation about this during the offsite, but I don't quite recall 😅 What is the reason for this again? Restarting the dev server if the lockfile changes doesn't always bring the desired behaviour. For example:

  1. Project imports foo library
  2. Astro dev server starts which imports foo library
  3. Node.js caches its import
  4. User updates foo library while Astro dev server is active
  5. Astro dev server restarts
  6. foo library is still outdated because Node.js caches its import

It'll work for client-only libraries though I believe, but I don't think the same would happen for node/ssr. The better way in this case is to completely manually restart the dev server.

@Princesseuh
Copy link
Member

If we can't make it work, maybe we could at least output a message like "Lockfile changes detected, restart your dev server to see changes" or something similar?

It'd be cool if it actually worked, though.

@bluwy
Copy link
Member

bluwy commented Oct 1, 2024

It could sometimes work though, like adding a new dependency that wasn't cached before, and after a server restart you can start using the dependency. I think Matthew fixed it in Vite to allow this flow to happen. But it's hard to tell usually which case is happening and whether it's safe.

I guess there's the point where we already watch the package.json file (which has the same problems), so it doesn't hurt to watch more lock files, but I feel like we should encourage users to manually restart the server instead of potentially leading them to an odd server state.

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

I agree with @bluwy here. I am not sure what we're fixing because the description of the PR doesn't say anything about it. Regardless, I would encourage users to restart the server to avoid possible side-effects

watchFiles.push(fileURLToPath(new URL('./package.json', pathToFileURL(cwd))));
// We don't official support Bun, Yarn Berry, and Yarn 1 should not be used by anyone.
// Ok to add other obscure package managers.
const packageFiles = ['package.json', 'package-lock.json', 'pnpm-lock.yaml'];
Copy link
Member

Choose a reason for hiding this comment

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

package.json isn't a lock file, is it a mistake?

@matthewp
Copy link
Contributor Author

matthewp commented Oct 1, 2024

Good points, I think what we should actually be doing here is restarting the process, not just restarting the container, because of the cached import issue. To do this I think we'll need to make it so that there's a parent process that can handle the restart.

@bluwy
Copy link
Member

bluwy commented Oct 2, 2024

As a stop gap now, I'm fine with merging this to help with some cases. I was thinking it's worth mentioning that this doesn't fix all the issues with adding/updating packages.

@Fryuni
Copy link
Member

Fryuni commented Oct 2, 2024

To do this I think we'll need to make it so that there's a parent process that can handle the restart.

I think that should be easily doable by forking on the installable astro.js before importing the CLI index. We can then define an exit code ro represent a request for a restart as even use Node's built-in IPC

@bluwy
Copy link
Member

bluwy commented Oct 3, 2024

Refactoring to parent-child process to handle complete restarts feel a bit over board to me and potentially a can of worms. I think it's fine to keep the current flow as you're not editing the package.json or lock files all the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants