From a278c7ae6f2e93cabfe56fc16eb8b82b904ffb3a Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Wed, 16 Nov 2022 08:34:19 -0500 Subject: [PATCH] Restart dev server on package.json changes (#5412) * Restart dev server on package.json changes * Adding a changeset * update vitefu * lockfile updated --- .changeset/olive-walls-hunt.md | 5 +++ packages/astro/package.json | 4 +-- packages/astro/src/core/config/settings.ts | 11 +++++-- packages/astro/test/units/dev/restart.test.js | 33 +++++++++++++++++++ packages/integrations/solid/package.json | 2 +- pnpm-lock.yaml | 27 ++++++++++----- 6 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 .changeset/olive-walls-hunt.md diff --git a/.changeset/olive-walls-hunt.md b/.changeset/olive-walls-hunt.md new file mode 100644 index 000000000..b28eee851 --- /dev/null +++ b/.changeset/olive-walls-hunt.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Restart dev server on package.json changes diff --git a/packages/astro/package.json b/packages/astro/package.json index 13a82395d..b28eecb87 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -157,8 +157,8 @@ "typescript": "*", "unist-util-visit": "^4.1.0", "vfile": "^5.3.2", - "vite": "~3.2.1", - "vitefu": "^0.2.0", + "vite": "~3.2.4", + "vitefu": "^0.2.1", "yargs-parser": "^21.0.1", "zod": "^3.17.3" }, diff --git a/packages/astro/src/core/config/settings.ts b/packages/astro/src/core/config/settings.ts index b5dccae53..e598dfd6a 100644 --- a/packages/astro/src/core/config/settings.ts +++ b/packages/astro/src/core/config/settings.ts @@ -1,7 +1,7 @@ import type { AstroConfig, AstroSettings, AstroUserConfig } from '../../@types/astro'; import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../constants.js'; -import { fileURLToPath } from 'url'; +import { fileURLToPath, pathToFileURL } from 'url'; import jsxRenderer from '../../jsx/renderer.js'; import { createDefaultDevConfig } from './config.js'; import { loadTSConfig } from './tsconfig.js'; @@ -24,9 +24,16 @@ export function createBaseSettings(config: AstroConfig): AstroSettings { export function createSettings(config: AstroConfig, cwd?: string): AstroSettings { const tsconfig = loadTSConfig(cwd); const settings = createBaseSettings(config); + + const watchFiles = tsconfig?.exists ? [tsconfig.path, ...tsconfig.extendedPaths] : []; + + if(cwd) { + watchFiles.push(fileURLToPath(new URL('./package.json', pathToFileURL(cwd)))); + } + settings.tsConfig = tsconfig?.config; settings.tsConfigPath = tsconfig?.path; - settings.watchFiles = tsconfig?.exists ? [tsconfig.path, ...tsconfig.extendedPaths] : []; + settings.watchFiles = watchFiles; return settings; } diff --git a/packages/astro/test/units/dev/restart.test.js b/packages/astro/test/units/dev/restart.test.js index 96c60c608..740ee4976 100644 --- a/packages/astro/test/units/dev/restart.test.js +++ b/packages/astro/test/units/dev/restart.test.js @@ -1,5 +1,6 @@ import { expect } from 'chai'; import * as cheerio from 'cheerio'; +import { fileURLToPath } from 'url'; import { createContainerWithAutomaticRestart, @@ -147,4 +148,36 @@ describe('dev container restarts', () => { await restart.container.close(); } }); + + it('Is able to restart project on package.json changes', async () => { + const fs = createFs( + { + '/src/pages/index.astro': ``, + }, + root + ); + + const { astroConfig } = await openConfig({ + cwd: root, + flags: {}, + cmd: 'dev', + logging: defaultLogging, + }); + const settings = createSettings(astroConfig, fileURLToPath(root)); + + let restart = await createContainerWithAutomaticRestart({ + params: { fs, root, settings }, + }); + await startContainer(restart.container); + expect(isStarted(restart.container)).to.equal(true); + + try { + let restartComplete = restart.restarted(); + fs.writeFileSync('/package.json', `{}`); + triggerFSEvent(restart.container, fs, '/package.json', 'change'); + await restartComplete; + } finally { + await restart.container.close(); + } + }); }); diff --git a/packages/integrations/solid/package.json b/packages/integrations/solid/package.json index 441f87586..94f654e82 100644 --- a/packages/integrations/solid/package.json +++ b/packages/integrations/solid/package.json @@ -33,7 +33,7 @@ }, "dependencies": { "babel-preset-solid": "^1.4.2", - "vitefu": "^0.2.0" + "vitefu": "^0.2.1" }, "devDependencies": { "astro": "workspace:*", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 36f28279d..8b55fa8cd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -464,8 +464,8 @@ importers: unified: ^10.1.2 unist-util-visit: ^4.1.0 vfile: ^5.3.2 - vite: ~3.2.1 - vitefu: ^0.2.0 + vite: ~3.2.4 + vitefu: ^0.2.1 yargs-parser: ^21.0.1 zod: ^3.17.3 dependencies: @@ -526,8 +526,8 @@ importers: typescript: 4.8.4 unist-util-visit: 4.1.1 vfile: 5.3.5 - vite: 3.2.3_sass@1.56.1 - vitefu: 0.2.1_vite@3.2.3 + vite: 3.2.4_sass@1.56.1 + vitefu: 0.2.1_vite@3.2.4 yargs-parser: 21.1.1 zod: 3.19.1 devDependencies: @@ -3133,7 +3133,7 @@ importers: astro-scripts: workspace:* babel-preset-solid: ^1.4.2 solid-js: ^1.5.1 - vitefu: ^0.2.0 + vitefu: ^0.2.1 dependencies: babel-preset-solid: 1.6.2 vitefu: 0.2.1 @@ -18119,8 +18119,8 @@ packages: fsevents: 2.3.2 dev: false - /vite/3.2.3_sass@1.56.1: - resolution: {integrity: sha512-h8jl1TZ76eGs3o2dIBSsvXDLb1m/Ec1iej8ZMdz+PsaFUsftZeWe2CZOI3qogEsMNaywc17gu0q6cQDzh/weCQ==} + /vite/3.2.4_sass@1.56.1: + resolution: {integrity: sha512-Z2X6SRAffOUYTa+sLy3NQ7nlHFU100xwanq1WDwqaiFiCe+25zdxP1TfCS5ojPV2oDDcXudHIoPnI1Z/66B7Yw==} engines: {node: ^14.18.0 || >=16.0.0} hasBin: true peerDependencies: @@ -18170,7 +18170,18 @@ packages: vite: optional: true dependencies: - vite: 3.2.3_sass@1.56.1 + vite: 3.2.3 + dev: false + + /vitefu/0.2.1_vite@3.2.4: + resolution: {integrity: sha512-clkvXTAeUf+XQKm3bhWUhT4pye+3acm6YCTGaWhxxIvZZ/QjnA3JA8Zud+z/mO5y5XYvJJhevs5Sjkv/FI8nRw==} + peerDependencies: + vite: ^3.0.0 + peerDependenciesMeta: + vite: + optional: true + dependencies: + vite: 3.2.4_sass@1.56.1 dev: false /vitest/0.20.3: