astro 1.6.2 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/typed-emitter.d.ts +42 -0
- package/dist/@types/typed-emitter.js +0 -0
- package/dist/cli/index.js +13 -51
- package/dist/core/build/generate.js +10 -6
- package/dist/core/compile/compile.d.ts +3 -3
- package/dist/core/compile/compile.js +15 -10
- package/dist/core/compile/style.d.ts +7 -4
- package/dist/core/compile/style.js +65 -12
- package/dist/core/config/config.d.ts +7 -3
- package/dist/core/config/config.js +15 -12
- package/dist/core/config/index.d.ts +2 -2
- package/dist/core/config/index.js +4 -1
- package/dist/core/config/schema.d.ts +69 -69
- package/dist/core/config/settings.d.ts +3 -1
- package/dist/core/config/settings.js +23 -5
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.d.ts +4 -1
- package/dist/core/create-vite.js +7 -4
- package/dist/core/dev/container.d.ts +36 -0
- package/dist/core/dev/container.js +109 -0
- package/dist/core/dev/dev.d.ts +24 -0
- package/dist/core/dev/dev.js +55 -0
- package/dist/core/dev/index.d.ts +3 -18
- package/dist/core/dev/index.js +8 -81
- package/dist/core/dev/restart.d.ts +25 -0
- package/dist/core/dev/restart.js +143 -0
- package/dist/core/endpoint/index.d.ts +2 -1
- package/dist/core/endpoint/index.js +12 -1
- package/dist/core/errors/dev/vite.d.ts +3 -2
- package/dist/core/errors/dev/vite.js +4 -6
- package/dist/core/messages.js +2 -2
- package/dist/core/module-loader/index.d.ts +3 -0
- package/dist/core/module-loader/index.js +6 -0
- package/dist/core/module-loader/loader.d.ts +42 -0
- package/dist/core/module-loader/loader.js +39 -0
- package/dist/core/module-loader/vite.d.ts +3 -0
- package/dist/core/module-loader/vite.js +62 -0
- package/dist/core/render/dev/css.d.ts +2 -2
- package/dist/core/render/dev/css.js +3 -3
- package/dist/core/render/dev/environment.d.ts +3 -3
- package/dist/core/render/dev/environment.js +3 -3
- package/dist/core/render/dev/index.d.ts +4 -4
- package/dist/core/render/dev/index.js +8 -8
- package/dist/core/render/dev/resolve.d.ts +2 -2
- package/dist/core/render/dev/resolve.js +2 -2
- package/dist/core/render/dev/scripts.d.ts +2 -2
- package/dist/core/render/dev/scripts.js +4 -4
- package/dist/core/render/dev/vite.d.ts +2 -2
- package/dist/core/render/dev/vite.js +5 -5
- package/dist/core/routing/manifest/create.d.ts +10 -3
- package/dist/core/routing/manifest/create.js +7 -6
- package/dist/core/util.d.ts +3 -4
- package/dist/core/util.js +10 -17
- package/dist/vite-plugin-astro/index.js +9 -20
- package/dist/vite-plugin-astro-postprocess/index.js +1 -1
- package/dist/vite-plugin-astro-server/base.d.ts +4 -0
- package/dist/vite-plugin-astro-server/base.js +36 -0
- package/dist/vite-plugin-astro-server/common.d.ts +2 -0
- package/dist/vite-plugin-astro-server/common.js +8 -0
- package/dist/vite-plugin-astro-server/controller.d.ts +26 -0
- package/dist/vite-plugin-astro-server/controller.js +77 -0
- package/dist/vite-plugin-astro-server/index.d.ts +3 -10
- package/dist/vite-plugin-astro-server/index.js +7 -336
- package/dist/vite-plugin-astro-server/plugin.d.ts +11 -0
- package/dist/vite-plugin-astro-server/plugin.js +54 -0
- package/dist/vite-plugin-astro-server/request.d.ts +7 -0
- package/dist/vite-plugin-astro-server/request.js +52 -0
- package/dist/vite-plugin-astro-server/response.d.ts +9 -0
- package/dist/vite-plugin-astro-server/response.js +85 -0
- package/dist/vite-plugin-astro-server/route.d.ts +13 -0
- package/dist/vite-plugin-astro-server/route.js +144 -0
- package/dist/vite-plugin-astro-server/server-state.d.ts +15 -0
- package/dist/vite-plugin-astro-server/server-state.js +42 -0
- package/dist/vite-plugin-jsx/index.js +2 -2
- package/dist/vite-plugin-load-fallback/index.d.ts +9 -0
- package/dist/vite-plugin-load-fallback/index.js +26 -0
- package/dist/vite-plugin-markdown/index.js +1 -1
- package/dist/vite-plugin-markdown-legacy/index.js +8 -24
- package/package.json +4 -2
- package/types.d.ts +1 -1
- package/dist/vite-style-transform/index.d.ts +0 -2
- package/dist/vite-style-transform/index.js +0 -5
- package/dist/vite-style-transform/style-transform.d.ts +0 -10
- package/dist/vite-style-transform/style-transform.js +0 -80
- package/dist/vite-style-transform/transform-with-vite.d.ts +0 -18
- package/dist/vite-style-transform/transform-with-vite.js +0 -33
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolveIdToUrl } from "../../util.js";
|
|
2
|
-
function createResolve(
|
|
2
|
+
function createResolve(loader) {
|
|
3
3
|
return async function(s) {
|
|
4
|
-
const url = await resolveIdToUrl(
|
|
4
|
+
const url = await resolveIdToUrl(loader, s);
|
|
5
5
|
if (url.startsWith("/@fs") && url.endsWith(".jsx")) {
|
|
6
6
|
return url.slice(0, -4);
|
|
7
7
|
} else {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import vite from 'vite';
|
|
2
1
|
import type { SSRElement } from '../../../@types/astro';
|
|
3
|
-
|
|
2
|
+
import type { ModuleLoader } from '../../module-loader/index';
|
|
3
|
+
export declare function getScriptsForURL(filePath: URL, loader: ModuleLoader): Promise<Set<SSRElement>>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { viteID } from "../../util.js";
|
|
2
2
|
import { createModuleScriptElementWithSrc } from "../ssr-element.js";
|
|
3
3
|
import { crawlGraph } from "./vite.js";
|
|
4
|
-
async function getScriptsForURL(filePath,
|
|
4
|
+
async function getScriptsForURL(filePath, loader) {
|
|
5
5
|
const elements = /* @__PURE__ */ new Set();
|
|
6
6
|
const rootID = viteID(filePath);
|
|
7
|
-
const modInfo =
|
|
7
|
+
const modInfo = loader.getModuleInfo(rootID);
|
|
8
8
|
addHoistedScripts(elements, modInfo);
|
|
9
|
-
for await (const moduleNode of crawlGraph(
|
|
9
|
+
for await (const moduleNode of crawlGraph(loader, rootID, true)) {
|
|
10
10
|
const id = moduleNode.id;
|
|
11
11
|
if (id) {
|
|
12
|
-
const info =
|
|
12
|
+
const info = loader.getModuleInfo(id);
|
|
13
13
|
addHoistedScripts(elements, info);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ModuleLoader, ModuleNode } from '../../module-loader/index';
|
|
2
2
|
/** recursively crawl the module graph to get all style files imported by parent id */
|
|
3
|
-
export declare function crawlGraph(
|
|
3
|
+
export declare function crawlGraph(loader: ModuleLoader, _id: string, isRootFile: boolean, scanned?: Set<string>): AsyncGenerator<ModuleNode, void, unknown>;
|
|
@@ -4,10 +4,10 @@ import { unwrapId } from "../../util.js";
|
|
|
4
4
|
import { STYLE_EXTENSIONS } from "../util.js";
|
|
5
5
|
const fileExtensionsToSSR = /* @__PURE__ */ new Set([".astro", ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS]);
|
|
6
6
|
const STRIP_QUERY_PARAMS_REGEX = /\?.*$/;
|
|
7
|
-
async function* crawlGraph(
|
|
7
|
+
async function* crawlGraph(loader, _id, isRootFile, scanned = /* @__PURE__ */ new Set()) {
|
|
8
8
|
const id = unwrapId(_id);
|
|
9
9
|
const importedModules = /* @__PURE__ */ new Set();
|
|
10
|
-
const moduleEntriesForId = isRootFile ?
|
|
10
|
+
const moduleEntriesForId = isRootFile ? loader.getModulesByFile(id) ?? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([loader.getModuleById(id)]);
|
|
11
11
|
for (const entry of moduleEntriesForId) {
|
|
12
12
|
if (!entry) {
|
|
13
13
|
continue;
|
|
@@ -22,10 +22,10 @@ async function* crawlGraph(viteServer, _id, isRootFile, scanned = /* @__PURE__ *
|
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
24
24
|
if (fileExtensionsToSSR.has(npath.extname(importedModulePathname))) {
|
|
25
|
-
const mod =
|
|
25
|
+
const mod = loader.getModuleById(importedModule.id);
|
|
26
26
|
if (!(mod == null ? void 0 : mod.ssrModule)) {
|
|
27
27
|
try {
|
|
28
|
-
await
|
|
28
|
+
await loader.import(importedModule.id);
|
|
29
29
|
} catch {
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -40,7 +40,7 @@ async function* crawlGraph(viteServer, _id, isRootFile, scanned = /* @__PURE__ *
|
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
42
42
|
yield importedModule;
|
|
43
|
-
yield* crawlGraph(
|
|
43
|
+
yield* crawlGraph(loader, importedModule.id, false, scanned);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
export {
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { AstroSettings, ManifestData } from '../../../@types/astro';
|
|
2
3
|
import type { LogOptions } from '../../logger/core';
|
|
3
|
-
|
|
4
|
-
export
|
|
4
|
+
import nodeFs from 'fs';
|
|
5
|
+
export interface CreateRouteManifestParams {
|
|
6
|
+
/** Astro Settings object */
|
|
5
7
|
settings: AstroSettings;
|
|
8
|
+
/** Current working directory */
|
|
6
9
|
cwd?: string;
|
|
7
|
-
|
|
10
|
+
/** fs module, for testing */
|
|
11
|
+
fsMod?: typeof nodeFs;
|
|
12
|
+
}
|
|
13
|
+
/** Create manifest of all static routes */
|
|
14
|
+
export declare function createRouteManifest({ settings, cwd, fsMod }: CreateRouteManifestParams, logging: LogOptions): ManifestData;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import nodeFs from "fs";
|
|
2
2
|
import { createRequire } from "module";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import slash from "slash";
|
|
@@ -132,7 +132,7 @@ function injectedRouteToItem({ config, cwd }, { pattern, entryPoint }) {
|
|
|
132
132
|
routeSuffix: pattern.slice(pattern.indexOf("."), -ext.length)
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
|
-
function createRouteManifest({ settings, cwd }, logging) {
|
|
135
|
+
function createRouteManifest({ settings, cwd, fsMod }, logging) {
|
|
136
136
|
var _a;
|
|
137
137
|
const components = [];
|
|
138
138
|
const routes = [];
|
|
@@ -142,7 +142,8 @@ function createRouteManifest({ settings, cwd }, logging) {
|
|
|
142
142
|
...settings.pageExtensions
|
|
143
143
|
]);
|
|
144
144
|
const validEndpointExtensions = /* @__PURE__ */ new Set([".js", ".ts"]);
|
|
145
|
-
|
|
145
|
+
const localFs = fsMod ?? nodeFs;
|
|
146
|
+
function walk(fs, dir, parentSegments, parentParams) {
|
|
146
147
|
let items = [];
|
|
147
148
|
fs.readdirSync(dir).forEach((basename) => {
|
|
148
149
|
const resolved = path.join(dir, basename);
|
|
@@ -208,7 +209,7 @@ function createRouteManifest({ settings, cwd }, logging) {
|
|
|
208
209
|
const params = parentParams.slice();
|
|
209
210
|
params.push(...item.parts.filter((p) => p.dynamic).map((p) => p.content));
|
|
210
211
|
if (item.isDir) {
|
|
211
|
-
walk(path.join(dir, item.basename), segments, params);
|
|
212
|
+
walk(fsMod ?? fs, path.join(dir, item.basename), segments, params);
|
|
212
213
|
} else {
|
|
213
214
|
components.push(item.file);
|
|
214
215
|
const component = item.file;
|
|
@@ -232,8 +233,8 @@ function createRouteManifest({ settings, cwd }, logging) {
|
|
|
232
233
|
}
|
|
233
234
|
const { config } = settings;
|
|
234
235
|
const pages = resolvePages(config);
|
|
235
|
-
if (
|
|
236
|
-
walk(fileURLToPath(pages), [], []);
|
|
236
|
+
if (localFs.existsSync(pages)) {
|
|
237
|
+
walk(localFs, fileURLToPath(pages), [], []);
|
|
237
238
|
} else if (settings.injectedRoutes.length === 0) {
|
|
238
239
|
const pagesDirRootRelative = pages.href.slice(settings.config.root.href.length);
|
|
239
240
|
warn(logging, "astro", `Missing pages directory: ${pagesDirRootRelative}`);
|
package/dist/core/util.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { ViteDevServer } from 'vite';
|
|
2
1
|
import type { AstroConfig, AstroSettings, RouteType } from '../@types/astro';
|
|
2
|
+
import type { ModuleLoader } from './module-loader';
|
|
3
3
|
/** Returns true if argument is an object of any prototype/class (but not null). */
|
|
4
4
|
export declare function isObject(value: unknown): value is Record<string, any>;
|
|
5
5
|
/** Cross-realm compatible URL */
|
|
6
6
|
export declare function isURL(value: unknown): value is URL;
|
|
7
7
|
/** Check if a file is a markdown file based on its extension */
|
|
8
|
-
export declare function isMarkdownFile(fileId: string, option
|
|
9
|
-
criteria: 'endsWith' | 'includes';
|
|
8
|
+
export declare function isMarkdownFile(fileId: string, option?: {
|
|
10
9
|
suffix?: string;
|
|
11
10
|
}): boolean;
|
|
12
11
|
/** Wraps an object in an array. If an array is passed, ignore it. */
|
|
@@ -44,7 +43,7 @@ export declare function getLocalAddress(serverAddress: string, host: string | bo
|
|
|
44
43
|
* Simulate Vite's resolve and import analysis so we can import the id as an URL
|
|
45
44
|
* through a script tag or a dynamic import as-is.
|
|
46
45
|
*/
|
|
47
|
-
export declare function resolveIdToUrl(
|
|
46
|
+
export declare function resolveIdToUrl(loader: ModuleLoader, id: string): Promise<string>;
|
|
48
47
|
export declare function resolveJsToTs(filePath: string): string;
|
|
49
48
|
/**
|
|
50
49
|
* Resolve the hydration paths so that it can be imported in the client
|
package/dist/core/util.js
CHANGED
|
@@ -13,16 +13,9 @@ function isURL(value) {
|
|
|
13
13
|
return Object.prototype.toString.call(value) === "[object URL]";
|
|
14
14
|
}
|
|
15
15
|
function isMarkdownFile(fileId, option) {
|
|
16
|
-
const _suffix = option.suffix ?? "";
|
|
17
|
-
if (option.criteria === "endsWith") {
|
|
18
|
-
for (let markdownFileExtension of SUPPORTED_MARKDOWN_FILE_EXTENSIONS) {
|
|
19
|
-
if (fileId.endsWith(`${markdownFileExtension}${_suffix}`))
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
16
|
+
const _suffix = (option == null ? void 0 : option.suffix) ?? "";
|
|
24
17
|
for (let markdownFileExtension of SUPPORTED_MARKDOWN_FILE_EXTENSIONS) {
|
|
25
|
-
if (fileId.
|
|
18
|
+
if (fileId.endsWith(`${markdownFileExtension}${_suffix}`))
|
|
26
19
|
return true;
|
|
27
20
|
}
|
|
28
21
|
return false;
|
|
@@ -131,18 +124,18 @@ function getLocalAddress(serverAddress, host) {
|
|
|
131
124
|
return serverAddress;
|
|
132
125
|
}
|
|
133
126
|
}
|
|
134
|
-
async function resolveIdToUrl(
|
|
135
|
-
let
|
|
136
|
-
if (!
|
|
137
|
-
|
|
127
|
+
async function resolveIdToUrl(loader, id) {
|
|
128
|
+
let resultId = await loader.resolveId(id, void 0);
|
|
129
|
+
if (!resultId && id.endsWith(".jsx")) {
|
|
130
|
+
resultId = await loader.resolveId(id.slice(0, -4), void 0);
|
|
138
131
|
}
|
|
139
|
-
if (!
|
|
132
|
+
if (!resultId) {
|
|
140
133
|
return VALID_ID_PREFIX + id;
|
|
141
134
|
}
|
|
142
|
-
if (path.isAbsolute(
|
|
143
|
-
return "/@fs" + prependForwardSlash(
|
|
135
|
+
if (path.isAbsolute(resultId)) {
|
|
136
|
+
return "/@fs" + prependForwardSlash(resultId);
|
|
144
137
|
}
|
|
145
|
-
return VALID_ID_PREFIX +
|
|
138
|
+
return VALID_ID_PREFIX + resultId;
|
|
146
139
|
}
|
|
147
140
|
function resolveJsToTs(filePath) {
|
|
148
141
|
if (filePath.endsWith(".jsx") && !fs.existsSync(filePath)) {
|
|
@@ -6,10 +6,6 @@ import { cachedCompilation, getCachedSource } from "../core/compile/index.js";
|
|
|
6
6
|
import { isRelativePath, prependForwardSlash, startsWithForwardSlash } from "../core/path.js";
|
|
7
7
|
import { viteID } from "../core/util.js";
|
|
8
8
|
import { getFileInfo } from "../vite-plugin-utils/index.js";
|
|
9
|
-
import {
|
|
10
|
-
createTransformStyles,
|
|
11
|
-
createViteStyleTransformer
|
|
12
|
-
} from "../vite-style-transform/index.js";
|
|
13
9
|
import { handleHotUpdate } from "./hmr.js";
|
|
14
10
|
import { parseAstroRequest } from "./query.js";
|
|
15
11
|
const FRONTMATTER_PARSE_REGEXP = /^\-\-\-(.*)^\-\-\-/ms;
|
|
@@ -29,8 +25,6 @@ function astro({ settings, logging }) {
|
|
|
29
25
|
return slash(fileURLToPath(url)) + url.search;
|
|
30
26
|
}
|
|
31
27
|
let resolvedConfig;
|
|
32
|
-
let styleTransformer;
|
|
33
|
-
let viteDevServer;
|
|
34
28
|
const srcRootWeb = config.srcDir.pathname.slice(config.root.pathname.length - 1);
|
|
35
29
|
const isBrowserPath = (path) => path.startsWith(srcRootWeb);
|
|
36
30
|
const isFullFilePath = (path) => path.startsWith(prependForwardSlash(slash(fileURLToPath(config.root))));
|
|
@@ -48,11 +42,6 @@ function astro({ settings, logging }) {
|
|
|
48
42
|
enforce: "pre",
|
|
49
43
|
configResolved(_resolvedConfig) {
|
|
50
44
|
resolvedConfig = _resolvedConfig;
|
|
51
|
-
styleTransformer = createViteStyleTransformer(_resolvedConfig);
|
|
52
|
-
},
|
|
53
|
-
configureServer(server) {
|
|
54
|
-
viteDevServer = server;
|
|
55
|
-
styleTransformer.viteDevServer = server;
|
|
56
45
|
},
|
|
57
46
|
async resolveId(id, from, opts) {
|
|
58
47
|
if (from) {
|
|
@@ -92,10 +81,10 @@ function astro({ settings, logging }) {
|
|
|
92
81
|
return null;
|
|
93
82
|
}
|
|
94
83
|
const compileProps = {
|
|
95
|
-
config,
|
|
84
|
+
astroConfig: config,
|
|
85
|
+
viteConfig: resolvedConfig,
|
|
96
86
|
filename,
|
|
97
|
-
source
|
|
98
|
-
transformStyle: createTransformStyles(styleTransformer, filename, Boolean(opts == null ? void 0 : opts.ssr), this)
|
|
87
|
+
source
|
|
99
88
|
};
|
|
100
89
|
switch (query.type) {
|
|
101
90
|
case "style": {
|
|
@@ -180,10 +169,10 @@ File: ${filename}`
|
|
|
180
169
|
}
|
|
181
170
|
const filename = normalizeFilename(parsedId.filename);
|
|
182
171
|
const compileProps = {
|
|
183
|
-
config,
|
|
172
|
+
astroConfig: config,
|
|
173
|
+
viteConfig: resolvedConfig,
|
|
184
174
|
filename,
|
|
185
|
-
source
|
|
186
|
-
transformStyle: createTransformStyles(styleTransformer, filename, Boolean(opts == null ? void 0 : opts.ssr), this)
|
|
175
|
+
source
|
|
187
176
|
};
|
|
188
177
|
try {
|
|
189
178
|
const transformResult = await cachedCompilation(compileProps);
|
|
@@ -278,10 +267,10 @@ ${source}
|
|
|
278
267
|
if (context.server.config.isProduction)
|
|
279
268
|
return;
|
|
280
269
|
const compileProps = {
|
|
281
|
-
config,
|
|
270
|
+
astroConfig: config,
|
|
271
|
+
viteConfig: resolvedConfig,
|
|
282
272
|
filename: context.file,
|
|
283
|
-
source: await context.read()
|
|
284
|
-
transformStyle: createTransformStyles(styleTransformer, context.file, true)
|
|
273
|
+
source: await context.read()
|
|
285
274
|
};
|
|
286
275
|
const compile = () => cachedCompilation(compileProps);
|
|
287
276
|
return handleHotUpdate(context, {
|
|
@@ -6,7 +6,7 @@ function astro(_opts) {
|
|
|
6
6
|
return {
|
|
7
7
|
name: "astro:postprocess",
|
|
8
8
|
async transform(code, id) {
|
|
9
|
-
if (!id.endsWith(".astro") && !isMarkdownFile(id
|
|
9
|
+
if (!id.endsWith(".astro") && !isMarkdownFile(id)) {
|
|
10
10
|
return null;
|
|
11
11
|
}
|
|
12
12
|
if (!ASTRO_GLOB_REGEX.test(code)) {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import notFoundTemplate, { subpathNotUsedTemplate } from "../template/4xx.js";
|
|
2
|
+
import { log404 } from "./common.js";
|
|
3
|
+
import { writeHtmlResponse } from "./response.js";
|
|
4
|
+
function baseMiddleware(settings, logging) {
|
|
5
|
+
const { config } = settings;
|
|
6
|
+
const site = config.site ? new URL(config.base, config.site) : void 0;
|
|
7
|
+
const devRoot = site ? site.pathname : "/";
|
|
8
|
+
return function devBaseMiddleware(req, res, next) {
|
|
9
|
+
var _a;
|
|
10
|
+
const url = req.url;
|
|
11
|
+
const pathname = decodeURI(new URL(url, "http://vitejs.dev").pathname);
|
|
12
|
+
if (pathname.startsWith(devRoot)) {
|
|
13
|
+
req.url = url.replace(devRoot, "/");
|
|
14
|
+
return next();
|
|
15
|
+
}
|
|
16
|
+
if (pathname === "/" || pathname === "/index.html") {
|
|
17
|
+
log404(logging, pathname);
|
|
18
|
+
const html = subpathNotUsedTemplate(devRoot, pathname);
|
|
19
|
+
return writeHtmlResponse(res, 404, html);
|
|
20
|
+
}
|
|
21
|
+
if ((_a = req.headers.accept) == null ? void 0 : _a.includes("text/html")) {
|
|
22
|
+
log404(logging, pathname);
|
|
23
|
+
const html = notFoundTemplate({
|
|
24
|
+
statusCode: 404,
|
|
25
|
+
title: "Not found",
|
|
26
|
+
tabTitle: "404: Not Found",
|
|
27
|
+
pathname
|
|
28
|
+
});
|
|
29
|
+
return writeHtmlResponse(res, 404, html);
|
|
30
|
+
}
|
|
31
|
+
next();
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
baseMiddleware
|
|
36
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { LoaderEvents, ModuleLoader } from '../core/module-loader/index';
|
|
2
|
+
import type { ServerState } from './server-state';
|
|
3
|
+
declare type ReloadFn = () => void;
|
|
4
|
+
export interface DevServerController {
|
|
5
|
+
state: ServerState;
|
|
6
|
+
onFileChange: LoaderEvents['file-change'];
|
|
7
|
+
onHMRError: LoaderEvents['hmr-error'];
|
|
8
|
+
}
|
|
9
|
+
export declare type CreateControllerParams = {
|
|
10
|
+
loader: ModuleLoader;
|
|
11
|
+
} | {
|
|
12
|
+
reload: ReloadFn;
|
|
13
|
+
};
|
|
14
|
+
export declare function createController(params: CreateControllerParams): DevServerController;
|
|
15
|
+
export declare function createBaseController({ reload }: {
|
|
16
|
+
reload: ReloadFn;
|
|
17
|
+
}): DevServerController;
|
|
18
|
+
export declare function createLoaderController(loader: ModuleLoader): DevServerController;
|
|
19
|
+
export interface RunWithErrorHandlingParams {
|
|
20
|
+
controller: DevServerController;
|
|
21
|
+
pathname: string;
|
|
22
|
+
run: () => Promise<any>;
|
|
23
|
+
onError: (error: unknown) => Error;
|
|
24
|
+
}
|
|
25
|
+
export declare function runWithErrorHandling({ controller: { state }, pathname, run, onError, }: RunWithErrorHandlingParams): Promise<void>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clearRouteError,
|
|
3
|
+
createServerState,
|
|
4
|
+
setRouteError,
|
|
5
|
+
setServerError
|
|
6
|
+
} from "./server-state.js";
|
|
7
|
+
function createController(params) {
|
|
8
|
+
if ("loader" in params) {
|
|
9
|
+
return createLoaderController(params.loader);
|
|
10
|
+
} else {
|
|
11
|
+
return createBaseController(params);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function createBaseController({ reload }) {
|
|
15
|
+
const serverState = createServerState();
|
|
16
|
+
const onFileChange = () => {
|
|
17
|
+
if (serverState.state === "error") {
|
|
18
|
+
reload();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const onHMRError = (payload) => {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
let msg = ((_a = payload == null ? void 0 : payload.err) == null ? void 0 : _a.message) ?? "Unknown error";
|
|
24
|
+
let stack = ((_b = payload == null ? void 0 : payload.err) == null ? void 0 : _b.stack) ?? "Unknown stack";
|
|
25
|
+
let error = new Error(msg);
|
|
26
|
+
Object.defineProperty(error, "stack", {
|
|
27
|
+
value: stack
|
|
28
|
+
});
|
|
29
|
+
setServerError(serverState, error);
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
state: serverState,
|
|
33
|
+
onFileChange,
|
|
34
|
+
onHMRError
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function createLoaderController(loader) {
|
|
38
|
+
const controller = createBaseController({
|
|
39
|
+
reload() {
|
|
40
|
+
loader.clientReload();
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const baseOnFileChange = controller.onFileChange;
|
|
44
|
+
controller.onFileChange = (...args) => {
|
|
45
|
+
if (controller.state.state === "error") {
|
|
46
|
+
loader.eachModule((mod) => {
|
|
47
|
+
if (mod.ssrError) {
|
|
48
|
+
loader.invalidateModule(mod);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
baseOnFileChange(...args);
|
|
53
|
+
};
|
|
54
|
+
loader.events.on("file-change", controller.onFileChange);
|
|
55
|
+
loader.events.on("hmr-error", controller.onHMRError);
|
|
56
|
+
return controller;
|
|
57
|
+
}
|
|
58
|
+
async function runWithErrorHandling({
|
|
59
|
+
controller: { state },
|
|
60
|
+
pathname,
|
|
61
|
+
run,
|
|
62
|
+
onError
|
|
63
|
+
}) {
|
|
64
|
+
try {
|
|
65
|
+
await run();
|
|
66
|
+
clearRouteError(state, pathname);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
const error = onError(err);
|
|
69
|
+
setRouteError(state, pathname, error);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export {
|
|
73
|
+
createBaseController,
|
|
74
|
+
createController,
|
|
75
|
+
createLoaderController,
|
|
76
|
+
runWithErrorHandling
|
|
77
|
+
};
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
interface AstroPluginOptions {
|
|
5
|
-
settings: AstroSettings;
|
|
6
|
-
logging: LogOptions;
|
|
7
|
-
}
|
|
8
|
-
export declare function baseMiddleware(settings: AstroSettings, logging: LogOptions): vite.Connect.NextHandleFunction;
|
|
9
|
-
export default function createPlugin({ settings, logging }: AstroPluginOptions): vite.Plugin;
|
|
10
|
-
export {};
|
|
1
|
+
export { createController, runWithErrorHandling } from './controller.js';
|
|
2
|
+
export { default as vitePluginAstroServer } from './plugin.js';
|
|
3
|
+
export { handleRequest } from './request.js';
|