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:
parent
7191ed1c7c
commit
a278c7ae6f
6 changed files with 69 additions and 13 deletions
5
.changeset/olive-walls-hunt.md
Normal file
5
.changeset/olive-walls-hunt.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Restart dev server on package.json changes
|
|
@ -157,8 +157,8 @@
|
||||||
"typescript": "*",
|
"typescript": "*",
|
||||||
"unist-util-visit": "^4.1.0",
|
"unist-util-visit": "^4.1.0",
|
||||||
"vfile": "^5.3.2",
|
"vfile": "^5.3.2",
|
||||||
"vite": "~3.2.1",
|
"vite": "~3.2.4",
|
||||||
"vitefu": "^0.2.0",
|
"vitefu": "^0.2.1",
|
||||||
"yargs-parser": "^21.0.1",
|
"yargs-parser": "^21.0.1",
|
||||||
"zod": "^3.17.3"
|
"zod": "^3.17.3"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import type { AstroConfig, AstroSettings, AstroUserConfig } from '../../@types/astro';
|
import type { AstroConfig, AstroSettings, AstroUserConfig } from '../../@types/astro';
|
||||||
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../constants.js';
|
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../constants.js';
|
||||||
|
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath, pathToFileURL } from 'url';
|
||||||
import jsxRenderer from '../../jsx/renderer.js';
|
import jsxRenderer from '../../jsx/renderer.js';
|
||||||
import { createDefaultDevConfig } from './config.js';
|
import { createDefaultDevConfig } from './config.js';
|
||||||
import { loadTSConfig } from './tsconfig.js';
|
import { loadTSConfig } from './tsconfig.js';
|
||||||
|
@ -24,9 +24,16 @@ export function createBaseSettings(config: AstroConfig): AstroSettings {
|
||||||
export function createSettings(config: AstroConfig, cwd?: string): AstroSettings {
|
export function createSettings(config: AstroConfig, cwd?: string): AstroSettings {
|
||||||
const tsconfig = loadTSConfig(cwd);
|
const tsconfig = loadTSConfig(cwd);
|
||||||
const settings = createBaseSettings(config);
|
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.tsConfig = tsconfig?.config;
|
||||||
settings.tsConfigPath = tsconfig?.path;
|
settings.tsConfigPath = tsconfig?.path;
|
||||||
settings.watchFiles = tsconfig?.exists ? [tsconfig.path, ...tsconfig.extendedPaths] : [];
|
settings.watchFiles = watchFiles;
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import * as cheerio from 'cheerio';
|
import * as cheerio from 'cheerio';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createContainerWithAutomaticRestart,
|
createContainerWithAutomaticRestart,
|
||||||
|
@ -147,4 +148,36 @@ describe('dev container restarts', () => {
|
||||||
await restart.container.close();
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-preset-solid": "^1.4.2",
|
"babel-preset-solid": "^1.4.2",
|
||||||
"vitefu": "^0.2.0"
|
"vitefu": "^0.2.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"astro": "workspace:*",
|
"astro": "workspace:*",
|
||||||
|
|
|
@ -464,8 +464,8 @@ importers:
|
||||||
unified: ^10.1.2
|
unified: ^10.1.2
|
||||||
unist-util-visit: ^4.1.0
|
unist-util-visit: ^4.1.0
|
||||||
vfile: ^5.3.2
|
vfile: ^5.3.2
|
||||||
vite: ~3.2.1
|
vite: ~3.2.4
|
||||||
vitefu: ^0.2.0
|
vitefu: ^0.2.1
|
||||||
yargs-parser: ^21.0.1
|
yargs-parser: ^21.0.1
|
||||||
zod: ^3.17.3
|
zod: ^3.17.3
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -526,8 +526,8 @@ importers:
|
||||||
typescript: 4.8.4
|
typescript: 4.8.4
|
||||||
unist-util-visit: 4.1.1
|
unist-util-visit: 4.1.1
|
||||||
vfile: 5.3.5
|
vfile: 5.3.5
|
||||||
vite: 3.2.3_sass@1.56.1
|
vite: 3.2.4_sass@1.56.1
|
||||||
vitefu: 0.2.1_vite@3.2.3
|
vitefu: 0.2.1_vite@3.2.4
|
||||||
yargs-parser: 21.1.1
|
yargs-parser: 21.1.1
|
||||||
zod: 3.19.1
|
zod: 3.19.1
|
||||||
devDependencies:
|
devDependencies:
|
||||||
|
@ -3133,7 +3133,7 @@ importers:
|
||||||
astro-scripts: workspace:*
|
astro-scripts: workspace:*
|
||||||
babel-preset-solid: ^1.4.2
|
babel-preset-solid: ^1.4.2
|
||||||
solid-js: ^1.5.1
|
solid-js: ^1.5.1
|
||||||
vitefu: ^0.2.0
|
vitefu: ^0.2.1
|
||||||
dependencies:
|
dependencies:
|
||||||
babel-preset-solid: 1.6.2
|
babel-preset-solid: 1.6.2
|
||||||
vitefu: 0.2.1
|
vitefu: 0.2.1
|
||||||
|
@ -18119,8 +18119,8 @@ packages:
|
||||||
fsevents: 2.3.2
|
fsevents: 2.3.2
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/vite/3.2.3_sass@1.56.1:
|
/vite/3.2.4_sass@1.56.1:
|
||||||
resolution: {integrity: sha512-h8jl1TZ76eGs3o2dIBSsvXDLb1m/Ec1iej8ZMdz+PsaFUsftZeWe2CZOI3qogEsMNaywc17gu0q6cQDzh/weCQ==}
|
resolution: {integrity: sha512-Z2X6SRAffOUYTa+sLy3NQ7nlHFU100xwanq1WDwqaiFiCe+25zdxP1TfCS5ojPV2oDDcXudHIoPnI1Z/66B7Yw==}
|
||||||
engines: {node: ^14.18.0 || >=16.0.0}
|
engines: {node: ^14.18.0 || >=16.0.0}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
|
@ -18170,7 +18170,18 @@ packages:
|
||||||
vite:
|
vite:
|
||||||
optional: true
|
optional: true
|
||||||
dependencies:
|
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
|
dev: false
|
||||||
|
|
||||||
/vitest/0.20.3:
|
/vitest/0.20.3:
|
||||||
|
|
Loading…
Reference in a new issue