🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
39
node_modules/astro/dist/core/dev/container.d.ts
generated
vendored
Normal file
39
node_modules/astro/dist/core/dev/container.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
import type * as http from 'node:http';
|
||||
import type { AddressInfo } from 'node:net';
|
||||
import type { AstroSettings, AstroUserConfig } from '../../@types/astro';
|
||||
import nodeFs from 'node:fs';
|
||||
import * as vite from 'vite';
|
||||
import type { LogOptions } from '../logger/core.js';
|
||||
export interface Container {
|
||||
fs: typeof nodeFs;
|
||||
logging: LogOptions;
|
||||
settings: AstroSettings;
|
||||
viteConfig: vite.InlineConfig;
|
||||
viteServer: vite.ViteDevServer;
|
||||
resolvedRoot: string;
|
||||
configFlag: string | undefined;
|
||||
configFlagPath: string | undefined;
|
||||
restartInFlight: boolean;
|
||||
handle: (req: http.IncomingMessage, res: http.ServerResponse) => void;
|
||||
close: () => Promise<void>;
|
||||
}
|
||||
export interface CreateContainerParams {
|
||||
isRestart?: boolean;
|
||||
logging?: LogOptions;
|
||||
userConfig?: AstroUserConfig;
|
||||
settings?: AstroSettings;
|
||||
fs?: typeof nodeFs;
|
||||
root?: string | URL;
|
||||
configFlag?: string;
|
||||
configFlagPath?: string;
|
||||
}
|
||||
export declare function createContainer(params?: CreateContainerParams): Promise<Container>;
|
||||
export declare function startContainer({ settings, viteServer, logging, }: Container): Promise<AddressInfo>;
|
||||
export declare function isStarted(container: Container): boolean;
|
||||
/**
|
||||
* Only used in tests
|
||||
*/
|
||||
export declare function runInContainer(params: CreateContainerParams, callback: (container: Container) => Promise<void> | void): Promise<void>;
|
105
node_modules/astro/dist/core/dev/container.js
generated
vendored
Normal file
105
node_modules/astro/dist/core/dev/container.js
generated
vendored
Normal file
|
@ -0,0 +1,105 @@
|
|||
import nodeFs from "node:fs";
|
||||
import * as vite from "vite";
|
||||
import {
|
||||
runHookConfigDone,
|
||||
runHookConfigSetup,
|
||||
runHookServerDone,
|
||||
runHookServerStart
|
||||
} from "../../integrations/index.js";
|
||||
import { createDefaultDevSettings, resolveRoot } from "../config/index.js";
|
||||
import { createVite } from "../create-vite.js";
|
||||
import { nodeLogDestination } from "../logger/node.js";
|
||||
import { appendForwardSlash } from "../path.js";
|
||||
import { apply as applyPolyfill } from "../polyfill.js";
|
||||
const defaultLogging = {
|
||||
dest: nodeLogDestination,
|
||||
level: "error"
|
||||
};
|
||||
async function createContainer(params = {}) {
|
||||
let {
|
||||
isRestart = false,
|
||||
logging = defaultLogging,
|
||||
settings = await createDefaultDevSettings(params.userConfig, params.root),
|
||||
fs = nodeFs
|
||||
} = params;
|
||||
applyPolyfill();
|
||||
settings = await runHookConfigSetup({
|
||||
settings,
|
||||
command: "dev",
|
||||
logging,
|
||||
isRestart
|
||||
});
|
||||
const { host, headers, open } = settings.config.server;
|
||||
const rendererClientEntries = settings.renderers.map((r) => r.clientEntrypoint).filter(Boolean);
|
||||
const viteConfig = await createVite(
|
||||
{
|
||||
mode: "development",
|
||||
server: { host, headers, open },
|
||||
optimizeDeps: {
|
||||
include: rendererClientEntries
|
||||
}
|
||||
},
|
||||
{ settings, logging, mode: "dev", command: "dev", fs }
|
||||
);
|
||||
await runHookConfigDone({ settings, logging });
|
||||
const viteServer = await vite.createServer(viteConfig);
|
||||
const container = {
|
||||
configFlag: params.configFlag,
|
||||
configFlagPath: params.configFlagPath,
|
||||
fs,
|
||||
logging,
|
||||
resolvedRoot: appendForwardSlash(resolveRoot(params.root)),
|
||||
restartInFlight: false,
|
||||
settings,
|
||||
viteConfig,
|
||||
viteServer,
|
||||
handle(req, res) {
|
||||
viteServer.middlewares.handle(req, res, Function.prototype);
|
||||
},
|
||||
// TODO deprecate and remove
|
||||
close() {
|
||||
return closeContainer(container);
|
||||
}
|
||||
};
|
||||
return container;
|
||||
}
|
||||
async function closeContainer({ viteServer, settings, logging }) {
|
||||
await viteServer.close();
|
||||
await runHookServerDone({
|
||||
config: settings.config,
|
||||
logging
|
||||
});
|
||||
}
|
||||
async function startContainer({
|
||||
settings,
|
||||
viteServer,
|
||||
logging
|
||||
}) {
|
||||
const { port } = settings.config.server;
|
||||
await viteServer.listen(port);
|
||||
const devServerAddressInfo = viteServer.httpServer.address();
|
||||
await runHookServerStart({
|
||||
config: settings.config,
|
||||
address: devServerAddressInfo,
|
||||
logging
|
||||
});
|
||||
return devServerAddressInfo;
|
||||
}
|
||||
function isStarted(container) {
|
||||
var _a;
|
||||
return !!((_a = container.viteServer.httpServer) == null ? void 0 : _a.listening);
|
||||
}
|
||||
async function runInContainer(params, callback) {
|
||||
const container = await createContainer(params);
|
||||
try {
|
||||
await callback(container);
|
||||
} finally {
|
||||
await container.close();
|
||||
}
|
||||
}
|
||||
export {
|
||||
createContainer,
|
||||
isStarted,
|
||||
runInContainer,
|
||||
startContainer
|
||||
};
|
24
node_modules/astro/dist/core/dev/dev.d.ts
generated
vendored
Normal file
24
node_modules/astro/dist/core/dev/dev.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
import type http from 'node:http';
|
||||
import type { AddressInfo } from 'node:net';
|
||||
import type * as vite from 'vite';
|
||||
import type yargs from 'yargs-parser';
|
||||
import type { AstroSettings } from '../../@types/astro';
|
||||
import { type LogOptions } from '../logger/core.js';
|
||||
export interface DevOptions {
|
||||
configFlag: string | undefined;
|
||||
configFlagPath: string | undefined;
|
||||
flags?: yargs.Arguments;
|
||||
logging: LogOptions;
|
||||
handleConfigError: (error: Error) => void;
|
||||
isRestart?: boolean;
|
||||
}
|
||||
export interface DevServer {
|
||||
address: AddressInfo;
|
||||
handle: (req: http.IncomingMessage, res: http.ServerResponse<http.IncomingMessage>) => void;
|
||||
watcher: vite.FSWatcher;
|
||||
stop(): Promise<void>;
|
||||
}
|
||||
/** `astro dev` */
|
||||
export default function dev(settings: AstroSettings, options: DevOptions): Promise<DevServer | undefined>;
|
80
node_modules/astro/dist/core/dev/dev.js
generated
vendored
Normal file
80
node_modules/astro/dist/core/dev/dev.js
generated
vendored
Normal file
|
@ -0,0 +1,80 @@
|
|||
import { cyan } from "kleur/colors";
|
||||
import { performance } from "perf_hooks";
|
||||
import { attachContentServerListeners } from "../../content/index.js";
|
||||
import { telemetry } from "../../events/index.js";
|
||||
import { info, warn } from "../logger/core.js";
|
||||
import * as msg from "../messages.js";
|
||||
import { printHelp } from "../messages.js";
|
||||
import { startContainer } from "./container.js";
|
||||
import { createContainerWithAutomaticRestart } from "./restart.js";
|
||||
async function dev(settings, options) {
|
||||
var _a, _b, _c, _d, _e;
|
||||
if (((_a = options.flags) == null ? void 0 : _a.help) || ((_b = options.flags) == null ? void 0 : _b.h)) {
|
||||
printHelp({
|
||||
commandName: "astro dev",
|
||||
usage: "[...flags]",
|
||||
tables: {
|
||||
Flags: [
|
||||
["--port", `Specify which port to run on. Defaults to 3000.`],
|
||||
["--host", `Listen on all addresses, including LAN and public addresses.`],
|
||||
["--host <custom-address>", `Expose on a network IP address at <custom-address>`],
|
||||
["--open", "Automatically open the app in the browser on server start"],
|
||||
["--help (-h)", "See all available flags."]
|
||||
]
|
||||
},
|
||||
description: `Check ${cyan(
|
||||
"https://docs.astro.build/en/reference/cli-reference/#astro-dev"
|
||||
)} for more information.`
|
||||
});
|
||||
return;
|
||||
}
|
||||
const devStart = performance.now();
|
||||
await telemetry.record([]);
|
||||
const restart = await createContainerWithAutomaticRestart({
|
||||
flags: options.flags ?? {},
|
||||
handleConfigError: options.handleConfigError,
|
||||
// eslint-disable-next-line no-console
|
||||
beforeRestart: () => console.clear(),
|
||||
params: {
|
||||
settings,
|
||||
root: (_c = options.flags) == null ? void 0 : _c.root,
|
||||
logging: options.logging,
|
||||
isRestart: options.isRestart
|
||||
}
|
||||
});
|
||||
const devServerAddressInfo = await startContainer(restart.container);
|
||||
info(
|
||||
options.logging,
|
||||
null,
|
||||
msg.serverStart({
|
||||
startupTime: performance.now() - devStart,
|
||||
resolvedUrls: restart.container.viteServer.resolvedUrls || { local: [], network: [] },
|
||||
host: settings.config.server.host,
|
||||
base: settings.config.base,
|
||||
isRestart: options.isRestart
|
||||
})
|
||||
);
|
||||
const currentVersion = "2.8.5";
|
||||
if (currentVersion.includes("-")) {
|
||||
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
||||
}
|
||||
if (((_e = (_d = restart.container.viteConfig.server) == null ? void 0 : _d.fs) == null ? void 0 : _e.strict) === false) {
|
||||
warn(options.logging, null, msg.fsStrictWarning());
|
||||
}
|
||||
await attachContentServerListeners(restart.container);
|
||||
return {
|
||||
address: devServerAddressInfo,
|
||||
get watcher() {
|
||||
return restart.container.viteServer.watcher;
|
||||
},
|
||||
handle(req, res) {
|
||||
return restart.container.handle(req, res);
|
||||
},
|
||||
async stop() {
|
||||
await restart.container.close();
|
||||
}
|
||||
};
|
||||
}
|
||||
export {
|
||||
dev as default
|
||||
};
|
3
node_modules/astro/dist/core/dev/index.d.ts
generated
vendored
Normal file
3
node_modules/astro/dist/core/dev/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
export { createContainer, isStarted, runInContainer, startContainer } from './container.js';
|
||||
export { default } from './dev.js';
|
||||
export { createContainerWithAutomaticRestart } from './restart.js';
|
11
node_modules/astro/dist/core/dev/index.js
generated
vendored
Normal file
11
node_modules/astro/dist/core/dev/index.js
generated
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
import { createContainer, isStarted, runInContainer, startContainer } from "./container.js";
|
||||
import { default as default2 } from "./dev.js";
|
||||
import { createContainerWithAutomaticRestart } from "./restart.js";
|
||||
export {
|
||||
createContainer,
|
||||
createContainerWithAutomaticRestart,
|
||||
default2 as default,
|
||||
isStarted,
|
||||
runInContainer,
|
||||
startContainer
|
||||
};
|
25
node_modules/astro/dist/core/dev/restart.d.ts
generated
vendored
Normal file
25
node_modules/astro/dist/core/dev/restart.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
import type { Container, CreateContainerParams } from './container';
|
||||
export declare function shouldRestartContainer({ settings, configFlag, configFlagPath, restartInFlight }: Container, changedFile: string): boolean;
|
||||
interface RestartContainerParams {
|
||||
container: Container;
|
||||
flags: any;
|
||||
logMsg: string;
|
||||
handleConfigError: (err: Error) => Promise<void> | void;
|
||||
beforeRestart?: () => void;
|
||||
}
|
||||
export declare function restartContainer({ container, flags, logMsg, handleConfigError, beforeRestart, }: RestartContainerParams): Promise<{
|
||||
container: Container;
|
||||
error: Error | null;
|
||||
}>;
|
||||
export interface CreateContainerWithAutomaticRestart {
|
||||
flags: any;
|
||||
params: CreateContainerParams;
|
||||
handleConfigError?: (error: Error) => void | Promise<void>;
|
||||
beforeRestart?: () => void;
|
||||
}
|
||||
interface Restart {
|
||||
container: Container;
|
||||
restarted: () => Promise<Error | null>;
|
||||
}
|
||||
export declare function createContainerWithAutomaticRestart({ flags, handleConfigError, beforeRestart, params, }: CreateContainerWithAutomaticRestart): Promise<Restart>;
|
||||
export {};
|
146
node_modules/astro/dist/core/dev/restart.js
generated
vendored
Normal file
146
node_modules/astro/dist/core/dev/restart.js
generated
vendored
Normal file
|
@ -0,0 +1,146 @@
|
|||
import * as vite from "vite";
|
||||
import { createSettings, openConfig } from "../config/index.js";
|
||||
import { createSafeError } from "../errors/index.js";
|
||||
import { info } from "../logger/core.js";
|
||||
import { createContainer, isStarted, startContainer } from "./container.js";
|
||||
async function createRestartedContainer(container, settings, needsStart) {
|
||||
const { logging, fs, resolvedRoot, configFlag, configFlagPath } = container;
|
||||
const newContainer = await createContainer({
|
||||
isRestart: true,
|
||||
logging,
|
||||
settings,
|
||||
fs,
|
||||
root: resolvedRoot,
|
||||
configFlag,
|
||||
configFlagPath
|
||||
});
|
||||
if (needsStart) {
|
||||
await startContainer(newContainer);
|
||||
}
|
||||
return newContainer;
|
||||
}
|
||||
function shouldRestartContainer({ settings, configFlag, configFlagPath, restartInFlight }, changedFile) {
|
||||
if (restartInFlight)
|
||||
return false;
|
||||
let shouldRestart = false;
|
||||
if (configFlag) {
|
||||
if (!!configFlagPath) {
|
||||
shouldRestart = vite.normalizePath(configFlagPath) === vite.normalizePath(changedFile);
|
||||
}
|
||||
} else {
|
||||
const exp = new RegExp(`.*astro.config.((mjs)|(cjs)|(js)|(ts))$`);
|
||||
const normalizedChangedFile = vite.normalizePath(changedFile);
|
||||
shouldRestart = exp.test(normalizedChangedFile);
|
||||
}
|
||||
if (!shouldRestart && settings.watchFiles.length > 0) {
|
||||
shouldRestart = settings.watchFiles.some(
|
||||
(path) => vite.normalizePath(path) === vite.normalizePath(changedFile)
|
||||
);
|
||||
}
|
||||
return shouldRestart;
|
||||
}
|
||||
async function restartContainer({
|
||||
container,
|
||||
flags,
|
||||
logMsg,
|
||||
handleConfigError,
|
||||
beforeRestart
|
||||
}) {
|
||||
const { logging, close, resolvedRoot, settings: existingSettings } = container;
|
||||
container.restartInFlight = true;
|
||||
if (beforeRestart) {
|
||||
beforeRestart();
|
||||
}
|
||||
const needsStart = isStarted(container);
|
||||
try {
|
||||
const newConfig = await openConfig({
|
||||
cwd: resolvedRoot,
|
||||
flags,
|
||||
cmd: "dev",
|
||||
isRestart: true,
|
||||
fsMod: container.fs
|
||||
});
|
||||
info(logging, "astro", logMsg + "\n");
|
||||
let astroConfig = newConfig.astroConfig;
|
||||
const settings = createSettings(astroConfig, resolvedRoot);
|
||||
await close();
|
||||
return {
|
||||
container: await createRestartedContainer(container, settings, needsStart),
|
||||
error: null
|
||||
};
|
||||
} catch (_err) {
|
||||
const error = createSafeError(_err);
|
||||
await handleConfigError(error);
|
||||
await close();
|
||||
info(logging, "astro", "Continuing with previous valid configuration\n");
|
||||
return {
|
||||
container: await createRestartedContainer(container, existingSettings, needsStart),
|
||||
error
|
||||
};
|
||||
}
|
||||
}
|
||||
async function createContainerWithAutomaticRestart({
|
||||
flags,
|
||||
handleConfigError = () => {
|
||||
},
|
||||
beforeRestart,
|
||||
params
|
||||
}) {
|
||||
const initialContainer = await createContainer(params);
|
||||
let resolveRestart;
|
||||
let restartComplete = new Promise((resolve) => {
|
||||
resolveRestart = resolve;
|
||||
});
|
||||
let restart = {
|
||||
container: initialContainer,
|
||||
restarted() {
|
||||
return restartComplete;
|
||||
}
|
||||
};
|
||||
async function handleServerRestart(logMsg) {
|
||||
const container = restart.container;
|
||||
const { container: newContainer, error } = await restartContainer({
|
||||
beforeRestart,
|
||||
container,
|
||||
flags,
|
||||
logMsg,
|
||||
async handleConfigError(err) {
|
||||
await handleConfigError(err);
|
||||
container.viteServer.ws.send({
|
||||
type: "error",
|
||||
err: {
|
||||
message: err.message,
|
||||
stack: err.stack || ""
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
restart.container = newContainer;
|
||||
addWatches();
|
||||
resolveRestart(error);
|
||||
restartComplete = new Promise((resolve) => {
|
||||
resolveRestart = resolve;
|
||||
});
|
||||
}
|
||||
function handleChangeRestart(logMsg) {
|
||||
return async function(changedFile) {
|
||||
if (shouldRestartContainer(restart.container, changedFile)) {
|
||||
handleServerRestart(logMsg);
|
||||
}
|
||||
};
|
||||
}
|
||||
function addWatches() {
|
||||
const watcher = restart.container.viteServer.watcher;
|
||||
watcher.on("change", handleChangeRestart("Configuration updated. Restarting..."));
|
||||
watcher.on("unlink", handleChangeRestart("Configuration removed. Restarting..."));
|
||||
watcher.on("add", handleChangeRestart("Configuration added. Restarting..."));
|
||||
restart.container.viteServer.restart = () => handleServerRestart("Restarting...");
|
||||
}
|
||||
addWatches();
|
||||
return restart;
|
||||
}
|
||||
export {
|
||||
createContainerWithAutomaticRestart,
|
||||
restartContainer,
|
||||
shouldRestartContainer
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue