Restart dev server on package.json changes (#5412)

* Restart dev server on package.json changes

* Adding a changeset

* update vitefu

* lockfile updated
This commit is contained in:
Matthew Phillips 2022-11-16 08:34:19 -05:00 committed by GitHub
parent 7191ed1c7c
commit a278c7ae6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 13 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Restart dev server on package.json changes

View file

@ -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"
},

View file

@ -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;
}

View file

@ -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();
}
});
});

View file

@ -33,7 +33,7 @@
},
"dependencies": {
"babel-preset-solid": "^1.4.2",
"vitefu": "^0.2.0"
"vitefu": "^0.2.1"
},
"devDependencies": {
"astro": "workspace:*",

View file

@ -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: