astro 4.4.2 → 4.4.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/content/vite-plugin-content-virtual-mod.d.ts +2 -1
- package/dist/content/vite-plugin-content-virtual-mod.js +14 -4
- package/dist/core/build/plugins/plugin-content.js +2 -1
- package/dist/core/compile/compile.d.ts +9 -3
- package/dist/core/compile/compile.js +5 -3
- package/dist/core/compile/style.d.ts +2 -1
- package/dist/core/compile/style.js +7 -5
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +13 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/transitions/vite-plugin-transitions.js +7 -0
- package/dist/vite-plugin-astro/hmr.d.ts +1 -4
- package/dist/vite-plugin-astro/hmr.js +11 -20
- package/dist/vite-plugin-astro/index.js +13 -33
- package/dist/vite-plugin-astro/types.d.ts +2 -1
- package/dist/vite-plugin-astro/utils.d.ts +2 -0
- package/dist/vite-plugin-astro/utils.js +17 -1
- package/dist/vite-plugin-astro-server/response.js +1 -2
- package/package.json +1 -1
|
@@ -8,12 +8,13 @@ interface AstroContentVirtualModPluginParams {
|
|
|
8
8
|
fs: typeof nodeFs;
|
|
9
9
|
}
|
|
10
10
|
export declare function astroContentVirtualModPlugin({ settings, fs, }: AstroContentVirtualModPluginParams): Plugin;
|
|
11
|
-
export declare function generateContentEntryFile({ settings, lookupMap, IS_DEV, IS_SERVER, }: {
|
|
11
|
+
export declare function generateContentEntryFile({ settings, lookupMap, IS_DEV, IS_SERVER, isClient, }: {
|
|
12
12
|
settings: AstroSettings;
|
|
13
13
|
fs: typeof nodeFs;
|
|
14
14
|
lookupMap: ContentLookupMap;
|
|
15
15
|
IS_DEV: boolean;
|
|
16
16
|
IS_SERVER: boolean;
|
|
17
|
+
isClient: boolean;
|
|
17
18
|
}): Promise<string>;
|
|
18
19
|
/**
|
|
19
20
|
* Generate a map from a collection + slug to the local file path.
|
|
@@ -51,13 +51,21 @@ function astroContentVirtualModPlugin({
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
|
-
async load(id) {
|
|
54
|
+
async load(id, args) {
|
|
55
55
|
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
56
56
|
const lookupMap = await generateLookupMap({
|
|
57
57
|
settings,
|
|
58
58
|
fs
|
|
59
59
|
});
|
|
60
|
-
const
|
|
60
|
+
const isClient = !args?.ssr;
|
|
61
|
+
const code = await generateContentEntryFile({
|
|
62
|
+
settings,
|
|
63
|
+
fs,
|
|
64
|
+
lookupMap,
|
|
65
|
+
IS_DEV,
|
|
66
|
+
IS_SERVER,
|
|
67
|
+
isClient
|
|
68
|
+
});
|
|
61
69
|
return {
|
|
62
70
|
code,
|
|
63
71
|
meta: {
|
|
@@ -89,7 +97,8 @@ async function generateContentEntryFile({
|
|
|
89
97
|
settings,
|
|
90
98
|
lookupMap,
|
|
91
99
|
IS_DEV,
|
|
92
|
-
IS_SERVER
|
|
100
|
+
IS_SERVER,
|
|
101
|
+
isClient
|
|
93
102
|
}) {
|
|
94
103
|
const contentPaths = getContentPaths(settings.config);
|
|
95
104
|
const relContentDir = rootRelativePath(settings.config.root, contentPaths.contentDir);
|
|
@@ -122,7 +131,8 @@ async function generateContentEntryFile({
|
|
|
122
131
|
dataEntryGlobResult = getStringifiedCollectionFromLookup("data", relContentDir, lookupMap);
|
|
123
132
|
renderEntryGlobResult = getStringifiedCollectionFromLookup("render", relContentDir, lookupMap);
|
|
124
133
|
}
|
|
125
|
-
|
|
134
|
+
let virtualModContents = nodeFs.readFileSync(contentPaths.virtualModTemplate, "utf-8").replace("@@CONTENT_DIR@@", relContentDir).replace("'@@CONTENT_ENTRY_GLOB_PATH@@'", contentEntryGlobResult).replace("'@@DATA_ENTRY_GLOB_PATH@@'", dataEntryGlobResult).replace("'@@RENDER_ENTRY_GLOB_PATH@@'", renderEntryGlobResult).replace("/* @@LOOKUP_MAP_ASSIGNMENT@@ */", `lookupMap = ${JSON.stringify(lookupMap)};`) + (isClient ? `
|
|
135
|
+
console.warn('astro:content is only supported running server-side. Using it in the browser will lead to bloated bundles and slow down page load. In the future it will not be supported.');` : "");
|
|
126
136
|
return virtualModContents;
|
|
127
137
|
}
|
|
128
138
|
function getStringifiedCollectionFromLookup(wantedType, relContentDir, lookupMap) {
|
|
@@ -9,8 +9,14 @@ export interface CompileProps {
|
|
|
9
9
|
filename: string;
|
|
10
10
|
source: string;
|
|
11
11
|
}
|
|
12
|
-
export interface
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export interface CompileCssResult {
|
|
13
|
+
code: string;
|
|
14
|
+
/**
|
|
15
|
+
* The dependencies of the transformed CSS (Normalized paths)
|
|
16
|
+
*/
|
|
17
|
+
dependencies?: string[];
|
|
18
|
+
}
|
|
19
|
+
export interface CompileResult extends Omit<TransformResult, 'css'> {
|
|
20
|
+
css: CompileCssResult[];
|
|
15
21
|
}
|
|
16
22
|
export declare function compile({ astroConfig, viteConfig, preferences, filename, source, }: CompileProps): Promise<CompileResult>;
|
|
@@ -12,7 +12,7 @@ async function compile({
|
|
|
12
12
|
filename,
|
|
13
13
|
source
|
|
14
14
|
}) {
|
|
15
|
-
const cssDeps =
|
|
15
|
+
const cssDeps = [];
|
|
16
16
|
const cssTransformErrors = [];
|
|
17
17
|
let transformResult;
|
|
18
18
|
try {
|
|
@@ -50,8 +50,10 @@ async function compile({
|
|
|
50
50
|
handleCompileResultErrors(transformResult, cssTransformErrors);
|
|
51
51
|
return {
|
|
52
52
|
...transformResult,
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
css: transformResult.css.map((code, i) => ({
|
|
54
|
+
code,
|
|
55
|
+
dependencies: cssDeps[i]
|
|
56
|
+
}))
|
|
55
57
|
};
|
|
56
58
|
}
|
|
57
59
|
function handleCompileResultErrors(result, cssTransformErrors) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { TransformOptions } from '@astrojs/compiler';
|
|
2
2
|
import { type ResolvedConfig } from 'vite';
|
|
3
|
+
import type { CompileCssResult } from './compile.js';
|
|
3
4
|
export declare function createStylePreprocessor({ filename, viteConfig, cssDeps, cssTransformErrors, }: {
|
|
4
5
|
filename: string;
|
|
5
6
|
viteConfig: ResolvedConfig;
|
|
6
|
-
cssDeps:
|
|
7
|
+
cssDeps: CompileCssResult['dependencies'][];
|
|
7
8
|
cssTransformErrors: Error[];
|
|
8
9
|
}): TransformOptions['preprocessStyle'];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import { preprocessCSS } from "vite";
|
|
2
|
+
import { normalizePath, preprocessCSS } from "vite";
|
|
3
3
|
import { AstroErrorData, CSSError, positionAt } from "../errors/index.js";
|
|
4
4
|
function createStylePreprocessor({
|
|
5
5
|
filename,
|
|
@@ -7,14 +7,16 @@ function createStylePreprocessor({
|
|
|
7
7
|
cssDeps,
|
|
8
8
|
cssTransformErrors
|
|
9
9
|
}) {
|
|
10
|
+
let processedStylesCount = 0;
|
|
10
11
|
return async (content, attrs) => {
|
|
12
|
+
const index = processedStylesCount++;
|
|
11
13
|
const lang = `.${attrs?.lang || "css"}`.toLowerCase();
|
|
12
|
-
const id = `${filename}?astro&type=style&lang${lang}`;
|
|
14
|
+
const id = `${filename}?astro&type=style&index=${index}&lang${lang}`;
|
|
13
15
|
try {
|
|
14
16
|
const result = await preprocessCSS(content, id, viteConfig);
|
|
15
|
-
result.deps
|
|
16
|
-
cssDeps.
|
|
17
|
-
}
|
|
17
|
+
if (result.deps) {
|
|
18
|
+
cssDeps[index] = [...result.deps].map((dep) => normalizePath(dep));
|
|
19
|
+
}
|
|
18
20
|
let map;
|
|
19
21
|
if (result.map) {
|
|
20
22
|
if (typeof result.map === "string") {
|
package/dist/core/constants.js
CHANGED
package/dist/core/create-vite.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import nodeFs from "node:fs";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
|
+
import glob from "fast-glob";
|
|
3
4
|
import * as vite from "vite";
|
|
4
5
|
import { crawlFrameworkPkgs } from "vitefu";
|
|
5
6
|
import astroAssetsPlugin from "../assets/vite-plugin-assets.js";
|
|
@@ -74,6 +75,7 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
});
|
|
78
|
+
const srcDirPattern = glob.convertPathToPattern(fileURLToPath(settings.config.srcDir));
|
|
77
79
|
const commonConfig = {
|
|
78
80
|
// Tell Vite not to combine config from vite.config.js with our provided inline config
|
|
79
81
|
configFile: false,
|
|
@@ -84,7 +86,17 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
|
|
|
84
86
|
customLogger: createViteLogger(logger, settings.config.vite.logLevel),
|
|
85
87
|
appType: "custom",
|
|
86
88
|
optimizeDeps: {
|
|
87
|
-
|
|
89
|
+
// Scan all files within `srcDir` except for known server-code (e.g endpoints)
|
|
90
|
+
entries: [
|
|
91
|
+
`${srcDirPattern}!(pages)/**/*`,
|
|
92
|
+
// All files except for pages
|
|
93
|
+
`${srcDirPattern}pages/**/!(*.js|*.mjs|*.ts|*.mts)`,
|
|
94
|
+
// All pages except for endpoints
|
|
95
|
+
`${srcDirPattern}pages/**/_*.{js,mjs,ts,mts}`,
|
|
96
|
+
// Remaining JS/TS files prefixed with `_` (not endpoints)
|
|
97
|
+
`${srcDirPattern}pages/**/_*/**/*.{js,mjs,ts,mts}`
|
|
98
|
+
// Remaining JS/TS files within directories prefixed with `_` (not endpoints)
|
|
99
|
+
],
|
|
88
100
|
exclude: ["astro", "node-fetch"]
|
|
89
101
|
},
|
|
90
102
|
plugins: [
|
package/dist/core/dev/dev.js
CHANGED
|
@@ -23,7 +23,7 @@ async function dev(inlineConfig) {
|
|
|
23
23
|
base: restart.container.settings.config.base
|
|
24
24
|
})
|
|
25
25
|
);
|
|
26
|
-
const currentVersion = "4.4.
|
|
26
|
+
const currentVersion = "4.4.3";
|
|
27
27
|
if (currentVersion.includes("-")) {
|
|
28
28
|
logger.warn("SKIP_FORMAT", msg.prerelease({ currentVersion }));
|
|
29
29
|
}
|
package/dist/core/messages.js
CHANGED
|
@@ -36,7 +36,7 @@ function serverStart({
|
|
|
36
36
|
host,
|
|
37
37
|
base
|
|
38
38
|
}) {
|
|
39
|
-
const version = "4.4.
|
|
39
|
+
const version = "4.4.3";
|
|
40
40
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
41
41
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
42
42
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -261,7 +261,7 @@ function printHelp({
|
|
|
261
261
|
message.push(
|
|
262
262
|
linebreak(),
|
|
263
263
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
264
|
-
`v${"4.4.
|
|
264
|
+
`v${"4.4.3"}`
|
|
265
265
|
)} ${headline}`
|
|
266
266
|
);
|
|
267
267
|
}
|
|
@@ -5,6 +5,13 @@ const resolvedVirtualClientModuleId = "\0" + virtualClientModuleId;
|
|
|
5
5
|
function astroTransitions({ settings }) {
|
|
6
6
|
return {
|
|
7
7
|
name: "astro:transitions",
|
|
8
|
+
config() {
|
|
9
|
+
return {
|
|
10
|
+
optimizeDeps: {
|
|
11
|
+
include: ["astro > cssesc"]
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
},
|
|
8
15
|
async resolveId(id) {
|
|
9
16
|
if (id === virtualModuleId) {
|
|
10
17
|
return resolvedVirtualModuleId;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import type { HmrContext } from 'vite';
|
|
2
2
|
import type { Logger } from '../core/logger/core.js';
|
|
3
|
-
import type { CompileAstroResult } from './compile.js';
|
|
4
3
|
import type { CompileMetadata } from './types.js';
|
|
5
4
|
export interface HandleHotUpdateOptions {
|
|
6
5
|
logger: Logger;
|
|
7
|
-
compile: (code: string, filename: string) => Promise<CompileAstroResult>;
|
|
8
|
-
astroFileToCssAstroDeps: Map<string, Set<string>>;
|
|
9
6
|
astroFileToCompileMetadata: Map<string, CompileMetadata>;
|
|
10
7
|
}
|
|
11
|
-
export declare function handleHotUpdate(ctx: HmrContext, { logger,
|
|
8
|
+
export declare function handleHotUpdate(ctx: HmrContext, { logger, astroFileToCompileMetadata }: HandleHotUpdateOptions): Promise<import("vite").ModuleNode[] | undefined>;
|
|
12
9
|
export declare function isStyleOnlyChanged(oldCode: string, newCode: string): boolean;
|
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { appendForwardSlash } from "@astrojs/internal-helpers/path";
|
|
3
1
|
import { frontmatterRE } from "./utils.js";
|
|
4
|
-
async function handleHotUpdate(ctx, { logger,
|
|
2
|
+
async function handleHotUpdate(ctx, { logger, astroFileToCompileMetadata }) {
|
|
3
|
+
for (const [astroFile, compileData] of astroFileToCompileMetadata) {
|
|
4
|
+
const isUpdatedFileCssDep = compileData.css.some((css) => css.dependencies?.includes(ctx.file));
|
|
5
|
+
if (isUpdatedFileCssDep) {
|
|
6
|
+
astroFileToCompileMetadata.delete(astroFile);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
5
9
|
const oldCode = astroFileToCompileMetadata.get(ctx.file)?.originalCode;
|
|
10
|
+
if (oldCode == null)
|
|
11
|
+
return;
|
|
6
12
|
const newCode = await ctx.read();
|
|
7
|
-
if (
|
|
13
|
+
if (isStyleOnlyChanged(oldCode, newCode)) {
|
|
8
14
|
logger.debug("watch", "style-only change");
|
|
9
|
-
|
|
15
|
+
astroFileToCompileMetadata.delete(ctx.file);
|
|
10
16
|
return ctx.modules.filter((mod) => mod.id?.includes("astro&type=style"));
|
|
11
17
|
}
|
|
12
|
-
for (const [astroFile, cssAstroDeps] of astroFileToCssAstroDeps) {
|
|
13
|
-
if (cssAstroDeps.has(ctx.file)) {
|
|
14
|
-
logger.info("watch", getShortName(ctx.file, ctx.server.config.root));
|
|
15
|
-
const parentModules = ctx.server.moduleGraph.getModulesByFile(astroFile);
|
|
16
|
-
if (parentModules) {
|
|
17
|
-
for (const mod of parentModules) {
|
|
18
|
-
ctx.server.moduleGraph.invalidateModule(mod);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
ctx.server.hot.send({ type: "full-reload", path: "*" });
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
18
|
}
|
|
25
19
|
const scriptRE = /<script(?:\s.*?)?>.*?<\/script>/gs;
|
|
26
20
|
const styleRE = /<style(?:\s.*?)?>.*?<\/style>/gs;
|
|
@@ -58,9 +52,6 @@ function isArrayEqual(a, b) {
|
|
|
58
52
|
}
|
|
59
53
|
return true;
|
|
60
54
|
}
|
|
61
|
-
function getShortName(file, root) {
|
|
62
|
-
return file.startsWith(appendForwardSlash(root)) ? path.posix.relative(root, file) : file;
|
|
63
|
-
}
|
|
64
55
|
export {
|
|
65
56
|
handleHotUpdate,
|
|
66
57
|
isStyleOnlyChanged
|
|
@@ -3,13 +3,13 @@ import { normalizeFilename } from "../vite-plugin-utils/index.js";
|
|
|
3
3
|
import { compileAstro } from "./compile.js";
|
|
4
4
|
import { handleHotUpdate } from "./hmr.js";
|
|
5
5
|
import { parseAstroRequest } from "./query.js";
|
|
6
|
+
import { loadId } from "./utils.js";
|
|
6
7
|
import { getAstroMetadata } from "./metadata.js";
|
|
7
8
|
const astroFileToCompileMetadataWeakMap = /* @__PURE__ */ new WeakMap();
|
|
8
9
|
function astro({ settings, logger }) {
|
|
9
10
|
const { config } = settings;
|
|
10
11
|
let server;
|
|
11
12
|
let compile;
|
|
12
|
-
let astroFileToCssAstroDeps = /* @__PURE__ */ new Map();
|
|
13
13
|
let astroFileToCompileMetadata = /* @__PURE__ */ new Map();
|
|
14
14
|
const srcRootWeb = config.srcDir.pathname.slice(config.root.pathname.length - 1);
|
|
15
15
|
const isBrowserPath = (path) => path.startsWith(srcRootWeb) && srcRootWeb !== "/";
|
|
@@ -39,7 +39,6 @@ function astro({ settings, logger }) {
|
|
|
39
39
|
});
|
|
40
40
|
},
|
|
41
41
|
buildStart() {
|
|
42
|
-
astroFileToCssAstroDeps = /* @__PURE__ */ new Map();
|
|
43
42
|
astroFileToCompileMetadata = /* @__PURE__ */ new Map();
|
|
44
43
|
if (astroFileToCompileMetadataWeakMap.has(config)) {
|
|
45
44
|
astroFileToCompileMetadata = astroFileToCompileMetadataWeakMap.get(config);
|
|
@@ -54,7 +53,13 @@ function astro({ settings, logger }) {
|
|
|
54
53
|
return null;
|
|
55
54
|
}
|
|
56
55
|
const filename = normalizePath(normalizeFilename(parsedId.filename, config.root));
|
|
57
|
-
|
|
56
|
+
let compileMetadata = astroFileToCompileMetadata.get(filename);
|
|
57
|
+
if (!compileMetadata && server) {
|
|
58
|
+
const code = await loadId(server.pluginContainer, filename);
|
|
59
|
+
if (code != null)
|
|
60
|
+
await compile(code, filename);
|
|
61
|
+
compileMetadata = astroFileToCompileMetadata.get(filename);
|
|
62
|
+
}
|
|
58
63
|
if (!compileMetadata) {
|
|
59
64
|
throw new Error(
|
|
60
65
|
`No cached compile metadata found for "${id}". The main Astro module "${filename}" should have compiled and filled the metadata first, before its virtual modules can be requested.`
|
|
@@ -65,11 +70,12 @@ function astro({ settings, logger }) {
|
|
|
65
70
|
if (typeof query.index === "undefined") {
|
|
66
71
|
throw new Error(`Requests for Astro CSS must include an index.`);
|
|
67
72
|
}
|
|
68
|
-
const
|
|
69
|
-
if (!
|
|
73
|
+
const result = compileMetadata.css[query.index];
|
|
74
|
+
if (!result) {
|
|
70
75
|
throw new Error(`No Astro CSS at index ${query.index}`);
|
|
71
76
|
}
|
|
72
|
-
|
|
77
|
+
result.dependencies?.forEach((dep) => this.addWatchFile(dep));
|
|
78
|
+
return { code: result.code };
|
|
73
79
|
}
|
|
74
80
|
case "script": {
|
|
75
81
|
if (typeof query.index === "undefined") {
|
|
@@ -130,25 +136,6 @@ File: ${id}`
|
|
|
130
136
|
}
|
|
131
137
|
const filename = normalizePath(parsedId.filename);
|
|
132
138
|
const transformResult = await compile(source, filename);
|
|
133
|
-
const astroDeps = /* @__PURE__ */ new Set();
|
|
134
|
-
for (const dep of transformResult.cssDeps) {
|
|
135
|
-
if (dep.endsWith(".astro")) {
|
|
136
|
-
astroDeps.add(dep);
|
|
137
|
-
}
|
|
138
|
-
this.addWatchFile(dep);
|
|
139
|
-
}
|
|
140
|
-
astroFileToCssAstroDeps.set(id, astroDeps);
|
|
141
|
-
if (server) {
|
|
142
|
-
const mods = server.moduleGraph.getModulesByFile(filename);
|
|
143
|
-
if (mods) {
|
|
144
|
-
const seen = new Set(mods);
|
|
145
|
-
for (const mod of mods) {
|
|
146
|
-
if (mod.url.includes("?astro")) {
|
|
147
|
-
server.moduleGraph.invalidateModule(mod, seen);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
139
|
const astroMetadata = {
|
|
153
140
|
clientOnlyComponents: transformResult.clientOnlyComponents,
|
|
154
141
|
hydratedComponents: transformResult.hydratedComponents,
|
|
@@ -171,14 +158,7 @@ File: ${id}`
|
|
|
171
158
|
};
|
|
172
159
|
},
|
|
173
160
|
async handleHotUpdate(ctx) {
|
|
174
|
-
|
|
175
|
-
return;
|
|
176
|
-
return handleHotUpdate(ctx, {
|
|
177
|
-
logger,
|
|
178
|
-
compile,
|
|
179
|
-
astroFileToCssAstroDeps,
|
|
180
|
-
astroFileToCompileMetadata
|
|
181
|
-
});
|
|
161
|
+
return handleHotUpdate(ctx, { logger, astroFileToCompileMetadata });
|
|
182
162
|
}
|
|
183
163
|
};
|
|
184
164
|
const normalPlugin = {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { HoistedScript, TransformResult } from '@astrojs/compiler';
|
|
2
2
|
import type { PropagationHint } from '../@types/astro.js';
|
|
3
|
+
import type { CompileCssResult } from '../core/compile/compile.js';
|
|
3
4
|
export interface PageOptions {
|
|
4
5
|
prerender?: boolean;
|
|
5
6
|
}
|
|
@@ -17,7 +18,7 @@ export interface CompileMetadata {
|
|
|
17
18
|
/** Used for HMR to compare code changes */
|
|
18
19
|
originalCode: string;
|
|
19
20
|
/** For Astro CSS virtual module */
|
|
20
|
-
css:
|
|
21
|
+
css: CompileCssResult[];
|
|
21
22
|
/** For Astro hoisted scripts virtual module */
|
|
22
23
|
scripts: HoistedScript[];
|
|
23
24
|
}
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
1
2
|
const frontmatterRE = /^---(.*?)^---/ms;
|
|
3
|
+
async function loadId(pluginContainer, id) {
|
|
4
|
+
const result = await pluginContainer.load(id, { ssr: true });
|
|
5
|
+
if (result) {
|
|
6
|
+
if (typeof result === "string") {
|
|
7
|
+
return result;
|
|
8
|
+
} else {
|
|
9
|
+
return result.code;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
return await fs.readFile(id, "utf-8");
|
|
14
|
+
} catch {
|
|
15
|
+
}
|
|
16
|
+
}
|
|
2
17
|
export {
|
|
3
|
-
frontmatterRE
|
|
18
|
+
frontmatterRE,
|
|
19
|
+
loadId
|
|
4
20
|
};
|
|
@@ -61,8 +61,7 @@ async function writeWebResponse(res, webResponse) {
|
|
|
61
61
|
} else {
|
|
62
62
|
const reader = body.getReader();
|
|
63
63
|
res.on("close", () => {
|
|
64
|
-
reader.cancel().catch((
|
|
65
|
-
console.error("An unexpected error occurred in the middle of the stream.", error);
|
|
64
|
+
reader.cancel().catch(() => {
|
|
66
65
|
});
|
|
67
66
|
});
|
|
68
67
|
while (true) {
|