From 48d3e4e957f07cde1e1546ac69388fa45f6a8c6d Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 27 Sep 2024 12:28:49 +0100 Subject: [PATCH] Restart dev server on lockfile change --- .changeset/good-geese-run.md | 5 ++++ packages/astro/src/core/config/settings.ts | 10 +++++++- packages/astro/test/units/dev/restart.test.js | 25 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 .changeset/good-geese-run.md diff --git a/.changeset/good-geese-run.md b/.changeset/good-geese-run.md new file mode 100644 index 0000000000..98a2ebf7e6 --- /dev/null +++ b/.changeset/good-geese-run.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Restart dev server on lockfile change diff --git a/packages/astro/src/core/config/settings.ts b/packages/astro/src/core/config/settings.ts index e333d6b061..2a681e2833 100644 --- a/packages/astro/src/core/config/settings.ts +++ b/packages/astro/src/core/config/settings.ts @@ -121,7 +121,15 @@ export async function createSettings(config: AstroConfig, cwd?: string): Promise let watchFiles = []; if (cwd) { - 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']; + + for(const file of packageFiles) { + const rel = `./${file}`; + const url = new URL(rel, pathToFileURL(cwd)); + watchFiles.push(fileURLToPath(url)); + } } if (typeof tsconfig !== 'string') { diff --git a/packages/astro/test/units/dev/restart.test.js b/packages/astro/test/units/dev/restart.test.js index 339b95fc1a..0975b82080 100644 --- a/packages/astro/test/units/dev/restart.test.js +++ b/packages/astro/test/units/dev/restart.test.js @@ -171,6 +171,31 @@ describe('dev container restarts', () => { } }); + it('Is able to restart project on lockfile changes', async () => { + const fs = createFs( + { + '/src/pages/index.astro': ``, + }, + root, + ); + + const restart = await createContainerWithAutomaticRestart({ + fs, + inlineConfig: { root: fileURLToPath(root), logLevel: 'silent' }, + }); + await startContainer(restart.container); + assert.equal(isStarted(restart.container), true); + + try { + let restartComplete = restart.restarted(); + fs.writeFileSync('/pnpm-lock.yaml', `{}`); + triggerFSEvent(restart.container, fs, '/pnpm-lock.yaml', 'change'); + await restartComplete; + } finally { + await restart.container.close(); + } + }); + it('Is able to restart on viteServer.restart API call', async () => { const fs = createFs( {