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 { default } from './dev.js';
|
||||||
export { createContainerWithAutomaticRestart } from './restart.js';
|
export { createContainerWithAutomaticRestart } from './restart.js';
|
||||||
|
|
|
@ -8,10 +8,10 @@ import { createContainer, isStarted, startContainer } from './container.js';
|
||||||
|
|
||||||
async function createRestartedContainer(
|
async function createRestartedContainer(
|
||||||
container: Container,
|
container: Container,
|
||||||
settings: AstroSettings
|
settings: AstroSettings,
|
||||||
|
needsStart: boolean
|
||||||
): Promise<Container> {
|
): Promise<Container> {
|
||||||
const { logging, fs, resolvedRoot, configFlag, configFlagPath } = container;
|
const { logging, fs, resolvedRoot, configFlag, configFlagPath } = container;
|
||||||
const needsStart = isStarted(container);
|
|
||||||
const newContainer = await createContainer({
|
const newContainer = await createContainer({
|
||||||
isRestart: true,
|
isRestart: true,
|
||||||
logging,
|
logging,
|
||||||
|
@ -78,10 +78,10 @@ export async function restartContainer({
|
||||||
const { logging, close, resolvedRoot, settings: existingSettings } = container;
|
const { logging, close, resolvedRoot, settings: existingSettings } = container;
|
||||||
container.restartInFlight = true;
|
container.restartInFlight = true;
|
||||||
|
|
||||||
//console.clear(); // TODO move this
|
|
||||||
if (beforeRestart) {
|
if (beforeRestart) {
|
||||||
beforeRestart();
|
beforeRestart();
|
||||||
}
|
}
|
||||||
|
const needsStart = isStarted(container);
|
||||||
try {
|
try {
|
||||||
const newConfig = await openConfig({
|
const newConfig = await openConfig({
|
||||||
cwd: resolvedRoot,
|
cwd: resolvedRoot,
|
||||||
|
@ -96,7 +96,7 @@ export async function restartContainer({
|
||||||
const settings = createSettings(astroConfig, resolvedRoot);
|
const settings = createSettings(astroConfig, resolvedRoot);
|
||||||
await close();
|
await close();
|
||||||
return {
|
return {
|
||||||
container: await createRestartedContainer(container, settings),
|
container: await createRestartedContainer(container, settings, needsStart),
|
||||||
error: null,
|
error: null,
|
||||||
};
|
};
|
||||||
} catch (_err) {
|
} catch (_err) {
|
||||||
|
@ -105,7 +105,7 @@ export async function restartContainer({
|
||||||
await close();
|
await close();
|
||||||
info(logging, 'astro', 'Continuing with previous valid configuration\n');
|
info(logging, 'astro', 'Continuing with previous valid configuration\n');
|
||||||
return {
|
return {
|
||||||
container: await createRestartedContainer(container, existingSettings),
|
container: await createRestartedContainer(container, existingSettings, needsStart),
|
||||||
error,
|
error,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,10 @@ import * as cheerio from 'cheerio';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createContainerWithAutomaticRestart,
|
createContainerWithAutomaticRestart,
|
||||||
runInContainer,
|
isStarted,
|
||||||
|
startContainer,
|
||||||
} from '../../../dist/core/dev/index.js';
|
} 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);
|
const root = new URL('../../fixtures/alias/', import.meta.url);
|
||||||
|
|
||||||
|
@ -74,4 +75,38 @@ describe('dev container restarts', () => {
|
||||||
await restart.container.close();
|
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