When creating a new dev container, restart it if previously started (#5314)
* When creating a new dev container, restart it if previously started * Adding a changeset
This commit is contained in:
parent
c44d5dd8bc
commit
f6add3924d
4 changed files with 48 additions and 8 deletions
5
.changeset/selfish-mangos-drum.md
Normal file
5
.changeset/selfish-mangos-drum.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes regression with config file restarts
|
|
@ -1,3 +1,3 @@
|
|||
export { createContainer, runInContainer, startContainer } from './container.js';
|
||||
export { createContainer, runInContainer, startContainer, isStarted } from './container.js';
|
||||
export { default } from './dev.js';
|
||||
export { createContainerWithAutomaticRestart } from './restart.js';
|
||||
|
|
|
@ -8,10 +8,10 @@ import { createContainer, isStarted, startContainer } from './container.js';
|
|||
|
||||
async function createRestartedContainer(
|
||||
container: Container,
|
||||
settings: AstroSettings
|
||||
settings: AstroSettings,
|
||||
needsStart: boolean
|
||||
): Promise<Container> {
|
||||
const { logging, fs, resolvedRoot, configFlag, configFlagPath } = container;
|
||||
const needsStart = isStarted(container);
|
||||
const newContainer = await createContainer({
|
||||
isRestart: true,
|
||||
logging,
|
||||
|
@ -78,10 +78,10 @@ export async function restartContainer({
|
|||
const { logging, close, resolvedRoot, settings: existingSettings } = container;
|
||||
container.restartInFlight = true;
|
||||
|
||||
//console.clear(); // TODO move this
|
||||
if (beforeRestart) {
|
||||
beforeRestart();
|
||||
}
|
||||
const needsStart = isStarted(container);
|
||||
try {
|
||||
const newConfig = await openConfig({
|
||||
cwd: resolvedRoot,
|
||||
|
@ -96,7 +96,7 @@ export async function restartContainer({
|
|||
const settings = createSettings(astroConfig, resolvedRoot);
|
||||
await close();
|
||||
return {
|
||||
container: await createRestartedContainer(container, settings),
|
||||
container: await createRestartedContainer(container, settings, needsStart),
|
||||
error: null,
|
||||
};
|
||||
} catch (_err) {
|
||||
|
@ -105,7 +105,7 @@ export async function restartContainer({
|
|||
await close();
|
||||
info(logging, 'astro', 'Continuing with previous valid configuration\n');
|
||||
return {
|
||||
container: await createRestartedContainer(container, existingSettings),
|
||||
container: await createRestartedContainer(container, existingSettings, needsStart),
|
||||
error,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@ import * as cheerio from 'cheerio';
|
|||
|
||||
import {
|
||||
createContainerWithAutomaticRestart,
|
||||
runInContainer,
|
||||
isStarted,
|
||||
startContainer,
|
||||
} from '../../../dist/core/dev/index.js';
|
||||
import { createFs, createRequestAndResponse } from '../test-utils.js';
|
||||
import { createFs, createRequestAndResponse, triggerFSEvent } from '../test-utils.js';
|
||||
|
||||
const root = new URL('../../fixtures/alias/', import.meta.url);
|
||||
|
||||
|
@ -74,4 +75,38 @@ describe('dev container restarts', () => {
|
|||
await restart.container.close();
|
||||
}
|
||||
});
|
||||
|
||||
it('Restarts the container if previously started', async () => {
|
||||
const fs = createFs(
|
||||
{
|
||||
'/src/pages/index.astro': `
|
||||
<html>
|
||||
<head><title>Test</title></head>
|
||||
<body>
|
||||
<h1>Test</h1>
|
||||
</body>
|
||||
</html>
|
||||
`,
|
||||
'/astro.config.mjs': ``,
|
||||
},
|
||||
root
|
||||
);
|
||||
|
||||
let restart = await createContainerWithAutomaticRestart({
|
||||
params: { fs, root },
|
||||
});
|
||||
await startContainer(restart.container);
|
||||
expect(isStarted(restart.container)).to.equal(true);
|
||||
|
||||
try {
|
||||
// Trigger a change
|
||||
let restartComplete = restart.restarted();
|
||||
triggerFSEvent(restart.container, fs, '/astro.config.mjs', 'change');
|
||||
await restartComplete;
|
||||
|
||||
expect(isStarted(restart.container)).to.equal(true);
|
||||
} finally {
|
||||
await restart.container.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue