astro 0.25.2 → 0.26.0
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/astro.js +0 -0
- package/dist/@types/serialize-javascript.d.js +0 -0
- package/dist/@types/shorthash.d.js +0 -0
- package/dist/adapter-ssg/index.js +0 -0
- package/dist/cli/check.js +4 -4
- package/dist/cli/index.js +21 -32
- package/dist/core/add/babel.js +0 -0
- package/dist/core/add/consts.js +0 -0
- package/dist/core/add/imports.js +0 -0
- package/dist/core/add/index.js +7 -14
- package/dist/core/add/wrapper.js +0 -0
- package/dist/core/app/common.js +0 -0
- package/dist/core/app/index.js +13 -10
- package/dist/core/app/node.js +0 -0
- package/dist/core/app/types.js +0 -0
- package/dist/core/build/add-rollup-input.js +0 -0
- package/dist/core/build/common.js +4 -5
- package/dist/core/build/generate.js +65 -72
- package/dist/core/build/index.js +59 -74
- package/dist/core/build/internal.js +4 -0
- package/dist/core/build/page-data.js +10 -9
- package/dist/core/build/static-build.js +46 -28
- package/dist/core/build/types.d.js +0 -0
- package/dist/core/build/util.js +0 -0
- package/dist/core/build/vite-plugin-hoisted-scripts.js +1 -1
- package/dist/core/build/vite-plugin-internals.js +0 -0
- package/dist/core/build/vite-plugin-pages.js +1 -0
- package/dist/core/build/vite-plugin-ssr.js +4 -2
- package/dist/core/config.js +87 -79
- package/dist/core/create-vite.js +12 -7
- package/dist/core/dev/index.js +8 -7
- package/dist/core/endpoint/dev/index.js +5 -10
- package/dist/core/endpoint/index.js +1 -3
- package/dist/core/errors.js +45 -0
- package/dist/core/logger/console.js +43 -0
- package/dist/core/logger/core.js +103 -0
- package/dist/core/logger/node.js +94 -0
- package/dist/core/messages.js +50 -24
- package/dist/core/path.js +0 -0
- package/dist/core/polyfill.js +0 -0
- package/dist/core/preview/index.js +8 -8
- package/dist/core/preview/util.js +3 -6
- package/dist/core/render/core.js +5 -6
- package/dist/core/render/dev/css.js +5 -6
- package/dist/core/render/dev/hmr.js +0 -0
- package/dist/core/render/dev/html.js +0 -0
- package/dist/core/render/dev/index.js +23 -36
- package/dist/core/render/paginate.js +0 -0
- package/dist/core/render/pretty-feed.js +103 -0
- package/dist/core/render/result.js +33 -15
- package/dist/core/render/route-cache.js +2 -2
- package/dist/core/render/rss.js +5 -4
- package/dist/core/render/script.js +0 -0
- package/dist/core/render/ssr-element.js +1 -1
- package/dist/core/render/util.js +26 -0
- package/dist/core/request.js +27 -0
- package/dist/core/routing/index.js +0 -0
- package/dist/core/routing/manifest/create.js +8 -6
- package/dist/core/routing/manifest/serialization.js +0 -0
- package/dist/core/routing/match.js +0 -0
- package/dist/core/routing/params.js +0 -0
- package/dist/core/routing/validation.js +1 -1
- package/dist/core/util.js +57 -125
- package/dist/integrations/index.js +9 -1
- package/dist/runtime/client/hmr.js +0 -0
- package/dist/runtime/client/idle.js +0 -0
- package/dist/runtime/client/load.js +0 -0
- package/dist/runtime/client/media.js +0 -0
- package/dist/runtime/client/only.js +0 -0
- package/dist/runtime/client/visible.js +0 -0
- package/dist/runtime/server/escape.js +0 -0
- package/dist/runtime/server/hydration.js +0 -0
- package/dist/runtime/server/index.js +42 -36
- package/dist/runtime/server/metadata.js +0 -0
- package/dist/runtime/server/util.js +0 -0
- package/dist/template/4xx.js +1 -1
- package/dist/template/5xx.js +0 -0
- package/dist/template/css.js +0 -0
- package/dist/types/@types/astro.d.ts +291 -233
- package/dist/types/cli/index.d.ts +1 -1
- package/dist/types/core/add/index.d.ts +1 -1
- package/dist/types/core/build/common.d.ts +0 -1
- package/dist/types/core/build/generate.d.ts +1 -1
- package/dist/types/core/build/index.d.ts +1 -1
- package/dist/types/core/build/internal.d.ts +1 -0
- package/dist/types/core/build/page-data.d.ts +1 -1
- package/dist/types/core/build/vite-plugin-pages.d.ts +1 -0
- package/dist/types/core/config.d.ts +125 -116
- package/dist/types/core/create-vite.d.ts +1 -1
- package/dist/types/core/dev/index.d.ts +1 -1
- package/dist/types/core/endpoint/index.d.ts +1 -1
- package/dist/types/core/errors.d.ts +23 -0
- package/dist/types/core/logger/console.d.ts +4 -0
- package/dist/types/core/{logger.d.ts → logger/core.d.ts} +7 -22
- package/dist/types/core/logger/node.d.ts +34 -0
- package/dist/types/core/messages.d.ts +4 -2
- package/dist/types/core/preview/index.d.ts +1 -1
- package/dist/types/core/preview/util.d.ts +1 -2
- package/dist/types/core/render/core.d.ts +2 -3
- package/dist/types/core/render/dev/css.d.ts +0 -2
- package/dist/types/core/render/dev/index.d.ts +4 -6
- package/dist/types/core/render/pretty-feed.d.ts +2 -0
- package/dist/types/core/render/result.d.ts +2 -3
- package/dist/types/core/render/route-cache.d.ts +1 -1
- package/dist/types/core/render/util.d.ts +6 -0
- package/dist/types/core/request.d.ts +14 -0
- package/dist/types/core/routing/manifest/create.d.ts +1 -1
- package/dist/types/core/routing/validation.d.ts +1 -1
- package/dist/types/core/util.d.ts +11 -7
- package/dist/types/integrations/index.d.ts +6 -0
- package/dist/types/runtime/server/index.d.ts +1 -2
- package/dist/types/vite-plugin-astro/hmr.d.ts +1 -1
- package/dist/types/vite-plugin-astro/index.d.ts +1 -1
- package/dist/types/vite-plugin-astro-server/index.d.ts +1 -1
- package/dist/types/vite-plugin-build-css/index.d.ts +2 -1
- package/dist/types/vite-plugin-build-html/extract-assets.d.ts +1 -1
- package/dist/types/vite-plugin-build-html/index.d.ts +3 -3
- package/dist/types/vite-plugin-config-alias/index.d.ts +1 -1
- package/dist/types/vite-plugin-jsx/index.d.ts +1 -1
- package/dist/vite-plugin-astro/compile.js +12 -14
- package/dist/vite-plugin-astro/hmr.js +2 -2
- package/dist/vite-plugin-astro/index.js +21 -8
- package/dist/vite-plugin-astro/query.js +0 -0
- package/dist/vite-plugin-astro/styles.js +1 -1
- package/dist/vite-plugin-astro-postprocess/index.js +31 -34
- package/dist/vite-plugin-astro-server/index.js +50 -22
- package/dist/vite-plugin-build-css/index.js +47 -4
- package/dist/vite-plugin-build-css/resolve.js +0 -0
- package/dist/vite-plugin-build-html/add-rollup-input.js +0 -0
- package/dist/vite-plugin-build-html/extract-assets.js +0 -0
- package/dist/vite-plugin-build-html/index.js +22 -23
- package/dist/vite-plugin-build-html/util.js +0 -0
- package/dist/vite-plugin-config-alias/index.js +1 -1
- package/dist/vite-plugin-env/index.js +1 -1
- package/dist/vite-plugin-integrations-container/index.js +0 -0
- package/dist/vite-plugin-jsx/index.js +1 -1
- package/dist/vite-plugin-markdown/index.js +89 -18
- package/dist/vite-plugin-scripts/index.js +0 -0
- package/env.d.ts +1 -1
- package/package.json +13 -9
- package/dist/core/build/scan-based-build.js +0 -61
- package/dist/core/dev/util.js +0 -44
- package/dist/core/logger.js +0 -174
- package/dist/core/render/dev/error.js +0 -34
- package/dist/core/render/request.js +0 -23
- package/dist/core/render/sitemap.js +0 -18
- package/dist/types/core/build/scan-based-build.d.ts +0 -18
- package/dist/types/core/dev/util.d.ts +0 -9
- package/dist/types/core/render/dev/error.d.ts +0 -7
- package/dist/types/core/render/request.d.ts +0 -15
- package/dist/types/core/render/sitemap.d.ts +0 -2
|
@@ -13,30 +13,28 @@ const configCache = /* @__PURE__ */ new WeakMap();
|
|
|
13
13
|
async function compile(config, filename, source, viteTransform, opts) {
|
|
14
14
|
const filenameURL = new URL(`file://${filename}`);
|
|
15
15
|
const normalizedID = fileURLToPath(filenameURL);
|
|
16
|
-
const pathname = filenameURL.pathname.substr(config.
|
|
16
|
+
const pathname = filenameURL.pathname.substr(config.root.pathname.length - 1);
|
|
17
17
|
let rawCSSDeps = /* @__PURE__ */ new Set();
|
|
18
18
|
let cssTransformError;
|
|
19
19
|
const transformResult = await transform(source, {
|
|
20
20
|
pathname,
|
|
21
|
-
projectRoot: config.
|
|
22
|
-
site: config.
|
|
21
|
+
projectRoot: config.root.toString(),
|
|
22
|
+
site: config.site ? new URL(config.base, config.site).toString() : void 0,
|
|
23
23
|
sourcefile: filename,
|
|
24
24
|
sourcemap: "both",
|
|
25
25
|
internalURL: `/@fs${prependForwardSlash(viteID(new URL("../runtime/server/index.js", import.meta.url)))}`,
|
|
26
|
-
experimentalStaticExtraction:
|
|
26
|
+
experimentalStaticExtraction: true,
|
|
27
27
|
preprocessStyle: async (value, attrs) => {
|
|
28
28
|
const lang = `.${(attrs == null ? void 0 : attrs.lang) || "css"}`.toLowerCase();
|
|
29
29
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
39
|
-
}
|
|
30
|
+
value.replace(/(?:@import)\s(?:url\()?\s?["\'](.*?)["\']\s?\)?(?:[^;]*);?/gi, (match, spec) => {
|
|
31
|
+
rawCSSDeps.add(spec);
|
|
32
|
+
if (lang === ".css") {
|
|
33
|
+
return createImportPlaceholder(spec);
|
|
34
|
+
} else {
|
|
35
|
+
return match;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
40
38
|
const result = await transformWithVite({
|
|
41
39
|
value,
|
|
42
40
|
lang,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { invalidateCompilation, isCached } from "./compile.js";
|
|
2
|
-
import { info } from "../core/logger.js";
|
|
2
|
+
import { info } from "../core/logger/core.js";
|
|
3
3
|
import * as msg from "../core/messages.js";
|
|
4
4
|
async function trackCSSDependencies(opts) {
|
|
5
5
|
const { viteDevServer, filename, deps, id } = opts;
|
|
@@ -46,7 +46,7 @@ async function handleHotUpdate(ctx, config, logging) {
|
|
|
46
46
|
invalidateCompilation(config, file2);
|
|
47
47
|
}
|
|
48
48
|
const mod = ctx.modules.find((m) => m.file === ctx.file);
|
|
49
|
-
const file = ctx.file.replace(config.
|
|
49
|
+
const file = ctx.file.replace(config.root.pathname, "/");
|
|
50
50
|
if (ctx.file.endsWith(".astro")) {
|
|
51
51
|
ctx.server.ws.send({ type: "custom", event: "astro:update", data: { file } });
|
|
52
52
|
}
|
|
@@ -9,25 +9,26 @@ import ancestor from "common-ancestor-path";
|
|
|
9
9
|
import { trackCSSDependencies, handleHotUpdate } from "./hmr.js";
|
|
10
10
|
import { isRelativePath, startsWithForwardSlash } from "../core/path.js";
|
|
11
11
|
import { PAGE_SCRIPT_ID, PAGE_SSR_SCRIPT_ID } from "../vite-plugin-scripts/index.js";
|
|
12
|
+
import { resolvePages } from "../core/util.js";
|
|
12
13
|
const FRONTMATTER_PARSE_REGEXP = /^\-\-\-(.*)^\-\-\-/ms;
|
|
13
14
|
function astro({ config, logging }) {
|
|
14
15
|
function normalizeFilename(filename) {
|
|
15
16
|
if (filename.startsWith("/@fs")) {
|
|
16
17
|
filename = filename.slice("/@fs".length);
|
|
17
|
-
} else if (filename.startsWith("/") && !ancestor(filename, config.
|
|
18
|
-
filename = new URL("." + filename, config.
|
|
18
|
+
} else if (filename.startsWith("/") && !ancestor(filename, config.root.pathname)) {
|
|
19
|
+
filename = new URL("." + filename, config.root).pathname;
|
|
19
20
|
}
|
|
20
21
|
return filename;
|
|
21
22
|
}
|
|
22
23
|
function relativeToRoot(pathname) {
|
|
23
24
|
const arg = startsWithForwardSlash(pathname) ? "." + pathname : pathname;
|
|
24
|
-
const url = new URL(arg, config.
|
|
25
|
+
const url = new URL(arg, config.root);
|
|
25
26
|
return slash(fileURLToPath(url)) + url.search;
|
|
26
27
|
}
|
|
27
28
|
let resolvedConfig;
|
|
28
29
|
let viteTransform;
|
|
29
30
|
let viteDevServer = null;
|
|
30
|
-
const srcRootWeb = config.
|
|
31
|
+
const srcRootWeb = config.srcDir.pathname.slice(config.root.pathname.length - 1);
|
|
31
32
|
const isBrowserPath = (path) => path.startsWith(srcRootWeb);
|
|
32
33
|
return {
|
|
33
34
|
name: "astro:build",
|
|
@@ -60,6 +61,7 @@ function astro({ config, logging }) {
|
|
|
60
61
|
}
|
|
61
62
|
},
|
|
62
63
|
async load(id, opts) {
|
|
64
|
+
var _a;
|
|
63
65
|
const parsedId = parseAstroRequest(id);
|
|
64
66
|
const query = parsedId.query;
|
|
65
67
|
if (!id.endsWith(".astro") && !query.astro) {
|
|
@@ -68,10 +70,10 @@ function astro({ config, logging }) {
|
|
|
68
70
|
const filename = normalizeFilename(parsedId.filename);
|
|
69
71
|
const fileUrl = new URL(`file://${filename}`);
|
|
70
72
|
let source = await fs.promises.readFile(fileUrl, "utf-8");
|
|
71
|
-
const isPage = fileUrl.pathname.startsWith(config.
|
|
73
|
+
const isPage = fileUrl.pathname.startsWith(resolvePages(config).pathname);
|
|
72
74
|
if (isPage && config._ctx.scripts.some((s) => s.stage === "page")) {
|
|
73
75
|
source += `
|
|
74
|
-
<script
|
|
76
|
+
<script src="${PAGE_SCRIPT_ID}" />`;
|
|
75
77
|
}
|
|
76
78
|
if (query.astro) {
|
|
77
79
|
if (query.type === "style") {
|
|
@@ -95,6 +97,17 @@ function astro({ config, logging }) {
|
|
|
95
97
|
if (!hoistedScript) {
|
|
96
98
|
throw new Error(`No hoisted script at index ${query.index}`);
|
|
97
99
|
}
|
|
100
|
+
if (hoistedScript.type === "external") {
|
|
101
|
+
const src = hoistedScript.src;
|
|
102
|
+
if (src.startsWith("/") && !isBrowserPath(src)) {
|
|
103
|
+
const publicDir = config.publicDir.pathname.replace(/\/$/, "").split("/").pop() + "/";
|
|
104
|
+
throw new Error(`
|
|
105
|
+
|
|
106
|
+
<script src="${src}"> references an asset in the "${publicDir}" directory. Please add the "is:inline" directive to keep this asset from being bundled.
|
|
107
|
+
|
|
108
|
+
File: ${filename}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
98
111
|
return {
|
|
99
112
|
code: hoistedScript.type === "inline" ? hoistedScript.code : `import "${hoistedScript.src}";`
|
|
100
113
|
};
|
|
@@ -106,7 +119,7 @@ function astro({ config, logging }) {
|
|
|
106
119
|
loader: "ts",
|
|
107
120
|
sourcemap: "external",
|
|
108
121
|
sourcefile: id,
|
|
109
|
-
define: config.vite.define
|
|
122
|
+
define: (_a = config.vite) == null ? void 0 : _a.define
|
|
110
123
|
});
|
|
111
124
|
let SUFFIX = "";
|
|
112
125
|
if (!resolvedConfig.isProduction) {
|
|
@@ -141,7 +154,7 @@ import "${PAGE_SSR_SCRIPT_ID}";`;
|
|
|
141
154
|
|
|
142
155
|
\`@astrojs/compiler\` encountered an unrecoverable error when compiling the following file.
|
|
143
156
|
|
|
144
|
-
**${id.replace(fileURLToPath(config.
|
|
157
|
+
**${id.replace(fileURLToPath(config.root), "")}**
|
|
145
158
|
\`\`\`astro
|
|
146
159
|
${source}
|
|
147
160
|
\`\`\`
|
|
File without changes
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { parse as babelParser } from "@babel/parser";
|
|
2
|
+
import { parse, print, types, visit } from "recast";
|
|
3
|
+
const ASTRO_GLOB_REGEX = /Astro2?\s*\.\s*glob\s*\(/;
|
|
2
4
|
const validAstroGlobalNames = /* @__PURE__ */ new Set(["Astro", "Astro2"]);
|
|
3
5
|
function astro({ config }) {
|
|
4
6
|
return {
|
|
@@ -7,43 +9,38 @@ function astro({ config }) {
|
|
|
7
9
|
if (!id.endsWith(".astro") && !id.endsWith(".md")) {
|
|
8
10
|
return null;
|
|
9
11
|
}
|
|
10
|
-
if (!
|
|
12
|
+
if (!ASTRO_GLOB_REGEX.test(code)) {
|
|
11
13
|
return null;
|
|
12
14
|
}
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (path.parent.type !== "CallExpression" || path.parent.callee.type !== "MemberExpression" || !validAstroGlobalNames.has(path.parent.callee.object.name) || path.parent.callee.property.name !== "fetchContent") {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const { value } = path.node;
|
|
25
|
-
if (/[a-z]\:\/\//.test(value)) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
path.replaceWith({
|
|
29
|
-
type: "CallExpression",
|
|
30
|
-
callee: {
|
|
31
|
-
type: "MemberExpression",
|
|
32
|
-
object: { type: "MetaProperty", meta: { type: "Identifier", name: "import" }, property: { type: "Identifier", name: "meta" } },
|
|
33
|
-
property: { type: "Identifier", name: "globEager" },
|
|
34
|
-
computed: false
|
|
35
|
-
},
|
|
36
|
-
arguments: [path.node]
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
15
|
+
const ast = parse(code, {
|
|
16
|
+
parser: { parse: babelParser }
|
|
17
|
+
});
|
|
18
|
+
visit(ast, {
|
|
19
|
+
visitCallExpression: function(path) {
|
|
20
|
+
if (!types.namedTypes.MemberExpression.check(path.node.callee) || !types.namedTypes.Identifier.check(path.node.callee.property) || !(path.node.callee.property.name === "glob") || !types.namedTypes.Identifier.check(path.node.callee.object) || !(path.node.callee.object.name === "Astro" || path.node.callee.object.name === "Astro2")) {
|
|
21
|
+
this.traverse(path);
|
|
22
|
+
return;
|
|
41
23
|
}
|
|
42
|
-
|
|
24
|
+
const argsPath = path.get("arguments", 0);
|
|
25
|
+
const args = argsPath.value;
|
|
26
|
+
argsPath.replace({
|
|
27
|
+
type: "CallExpression",
|
|
28
|
+
callee: {
|
|
29
|
+
type: "MemberExpression",
|
|
30
|
+
object: { type: "MetaProperty", meta: { type: "Identifier", name: "import" }, property: { type: "Identifier", name: "meta" } },
|
|
31
|
+
property: { type: "Identifier", name: "glob" },
|
|
32
|
+
computed: false
|
|
33
|
+
},
|
|
34
|
+
arguments: [args]
|
|
35
|
+
}, {
|
|
36
|
+
type: "ArrowFunctionExpression",
|
|
37
|
+
body: args,
|
|
38
|
+
params: []
|
|
39
|
+
});
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
43
42
|
});
|
|
44
|
-
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
43
|
+
const result = print(ast);
|
|
47
44
|
return { code: result.code, map: result.map };
|
|
48
45
|
}
|
|
49
46
|
};
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { info, warn, error } from "../core/logger.js";
|
|
1
|
+
import { info, warn, error } from "../core/logger/core.js";
|
|
2
2
|
import { getParamsAndProps, GetParamsAndPropsError } from "../core/render/core.js";
|
|
3
3
|
import { createRouteManifest, matchRoute } from "../core/routing/index.js";
|
|
4
4
|
import stripAnsi from "strip-ansi";
|
|
5
|
-
import { createSafeError } from "../core/util.js";
|
|
5
|
+
import { createSafeError, resolvePages, isBuildingToSSR } from "../core/util.js";
|
|
6
6
|
import { ssr, preload } from "../core/render/dev/index.js";
|
|
7
7
|
import { call as callEndpoint } from "../core/endpoint/dev/index.js";
|
|
8
8
|
import * as msg from "../core/messages.js";
|
|
9
9
|
import notFoundTemplate, { subpathNotUsedTemplate } from "../template/4xx.js";
|
|
10
10
|
import serverErrorTemplate from "../template/5xx.js";
|
|
11
11
|
import { RouteCache } from "../core/render/route-cache.js";
|
|
12
|
+
import { fixViteErrorMessage } from "../core/errors.js";
|
|
13
|
+
import { createRequest } from "../core/request.js";
|
|
14
|
+
import { Readable } from "stream";
|
|
12
15
|
const BAD_VITE_MIDDLEWARE = ["viteIndexHtmlMiddleware", "vite404Middleware", "viteSpaFallbackMiddleware"];
|
|
13
16
|
function removeViteHttpMiddleware(server) {
|
|
14
17
|
for (let i = server.stack.length - 1; i > 0; i--) {
|
|
@@ -29,13 +32,18 @@ async function writeWebResponse(res, webResponse) {
|
|
|
29
32
|
const { status, headers, body } = webResponse;
|
|
30
33
|
res.writeHead(status, Object.fromEntries(headers.entries()));
|
|
31
34
|
if (body) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
if (body instanceof Readable) {
|
|
36
|
+
body.pipe(res);
|
|
37
|
+
return;
|
|
38
|
+
} else {
|
|
39
|
+
const reader = body.getReader();
|
|
40
|
+
while (true) {
|
|
41
|
+
const { done, value } = await reader.read();
|
|
42
|
+
if (done)
|
|
43
|
+
break;
|
|
44
|
+
if (value) {
|
|
45
|
+
res.write(value);
|
|
46
|
+
}
|
|
39
47
|
}
|
|
40
48
|
}
|
|
41
49
|
}
|
|
@@ -51,7 +59,7 @@ async function writeSSRResult(result, res, statusCode) {
|
|
|
51
59
|
writeHtmlResponse(res, statusCode, html);
|
|
52
60
|
}
|
|
53
61
|
async function handle404Response(origin, config, req, res) {
|
|
54
|
-
const site = config.
|
|
62
|
+
const site = config.site ? new URL(config.base, config.site) : void 0;
|
|
55
63
|
const devRoot = site ? site.pathname : "/";
|
|
56
64
|
const pathname = decodeURI(new URL(origin + req.url).pathname);
|
|
57
65
|
let html = "";
|
|
@@ -76,7 +84,7 @@ async function handle500Response(viteServer, origin, req, res, err) {
|
|
|
76
84
|
writeHtmlResponse(res, 500, transformedHtml);
|
|
77
85
|
}
|
|
78
86
|
function getCustom404Route(config, manifest) {
|
|
79
|
-
const relPages = config.
|
|
87
|
+
const relPages = resolvePages(config).href.replace(config.root.href, "");
|
|
80
88
|
return manifest.routes.find((r) => r.component === relPages + "404.astro");
|
|
81
89
|
}
|
|
82
90
|
function log404(logging, pathname) {
|
|
@@ -84,12 +92,35 @@ function log404(logging, pathname) {
|
|
|
84
92
|
}
|
|
85
93
|
async function handleRequest(routeCache, viteServer, logging, manifest, config, req, res) {
|
|
86
94
|
const reqStart = performance.now();
|
|
87
|
-
const site = config.
|
|
95
|
+
const site = config.site ? new URL(config.base, config.site) : void 0;
|
|
88
96
|
const devRoot = site ? site.pathname : "/";
|
|
89
97
|
const origin = `${viteServer.config.server.https ? "https" : "http"}://${req.headers.host}`;
|
|
98
|
+
const buildingToSSR = isBuildingToSSR(config);
|
|
90
99
|
const url = new URL(origin + req.url);
|
|
91
100
|
const pathname = decodeURI(url.pathname);
|
|
92
101
|
const rootRelativeUrl = pathname.substring(devRoot.length - 1);
|
|
102
|
+
if (!buildingToSSR) {
|
|
103
|
+
for (const [key] of url.searchParams) {
|
|
104
|
+
url.searchParams.delete(key);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
let body = void 0;
|
|
108
|
+
if (!(req.method === "GET" || req.method === "HEAD")) {
|
|
109
|
+
let bytes = [];
|
|
110
|
+
await new Promise((resolve) => {
|
|
111
|
+
req.setEncoding("utf-8");
|
|
112
|
+
req.on("data", (bts) => bytes.push(bts));
|
|
113
|
+
req.on("end", resolve);
|
|
114
|
+
});
|
|
115
|
+
body = new TextEncoder().encode(bytes.join("")).buffer;
|
|
116
|
+
}
|
|
117
|
+
const request = createRequest({
|
|
118
|
+
url,
|
|
119
|
+
headers: buildingToSSR ? req.headers : new Headers(),
|
|
120
|
+
method: req.method,
|
|
121
|
+
body,
|
|
122
|
+
logging
|
|
123
|
+
});
|
|
93
124
|
try {
|
|
94
125
|
if (!pathname.startsWith(devRoot)) {
|
|
95
126
|
log404(logging, pathname);
|
|
@@ -106,7 +137,7 @@ async function handleRequest(routeCache, viteServer, logging, manifest, config,
|
|
|
106
137
|
return handle404Response(origin, config, req, res);
|
|
107
138
|
}
|
|
108
139
|
}
|
|
109
|
-
const filePath = new URL(`./${route.component}`, config.
|
|
140
|
+
const filePath = new URL(`./${route.component}`, config.root);
|
|
110
141
|
const preloadedComponent = await preload({ astroConfig: config, filePath, viteServer });
|
|
111
142
|
const [, mod] = preloadedComponent;
|
|
112
143
|
const paramsAndPropsRes = await getParamsAndProps({
|
|
@@ -115,24 +146,23 @@ async function handleRequest(routeCache, viteServer, logging, manifest, config,
|
|
|
115
146
|
routeCache,
|
|
116
147
|
pathname: rootRelativeUrl,
|
|
117
148
|
logging,
|
|
118
|
-
ssr: config
|
|
149
|
+
ssr: isBuildingToSSR(config)
|
|
119
150
|
});
|
|
120
151
|
if (paramsAndPropsRes === GetParamsAndPropsError.NoMatchingStaticPath) {
|
|
121
152
|
warn(logging, "getStaticPaths", `Route pattern matched, but no matching static path found. (${pathname})`);
|
|
122
153
|
log404(logging, pathname);
|
|
123
154
|
const routeCustom404 = getCustom404Route(config, manifest);
|
|
124
155
|
if (routeCustom404) {
|
|
125
|
-
const filePathCustom404 = new URL(`./${routeCustom404.component}`, config.
|
|
156
|
+
const filePathCustom404 = new URL(`./${routeCustom404.component}`, config.root);
|
|
126
157
|
const preloadedCompCustom404 = await preload({ astroConfig: config, filePath: filePathCustom404, viteServer });
|
|
127
158
|
const result = await ssr(preloadedCompCustom404, {
|
|
128
159
|
astroConfig: config,
|
|
129
160
|
filePath: filePathCustom404,
|
|
130
161
|
logging,
|
|
131
162
|
mode: "development",
|
|
132
|
-
method: "GET",
|
|
133
|
-
headers: new Headers(Object.entries(req.headers)),
|
|
134
163
|
origin,
|
|
135
164
|
pathname: rootRelativeUrl,
|
|
165
|
+
request,
|
|
136
166
|
route: routeCustom404,
|
|
137
167
|
routeCache,
|
|
138
168
|
viteServer
|
|
@@ -152,8 +182,7 @@ async function handleRequest(routeCache, viteServer, logging, manifest, config,
|
|
|
152
182
|
route,
|
|
153
183
|
routeCache,
|
|
154
184
|
viteServer,
|
|
155
|
-
|
|
156
|
-
headers: new Headers(Object.entries(req.headers))
|
|
185
|
+
request
|
|
157
186
|
};
|
|
158
187
|
if (route.type === "endpoint") {
|
|
159
188
|
const result = await callEndpoint(options);
|
|
@@ -169,9 +198,8 @@ async function handleRequest(routeCache, viteServer, logging, manifest, config,
|
|
|
169
198
|
}
|
|
170
199
|
} catch (_err) {
|
|
171
200
|
debugger;
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
error(logging, "error", msg.err(err));
|
|
201
|
+
const err = fixViteErrorMessage(createSafeError(_err), viteServer);
|
|
202
|
+
error(logging, null, msg.formatErrorMessage(err));
|
|
175
203
|
handle500Response(viteServer, origin, req, res, err);
|
|
176
204
|
}
|
|
177
205
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
2
|
import esbuild from "esbuild";
|
|
3
|
-
import { isCSSRequest } from "../core/render/
|
|
4
|
-
import { getPageDatasByChunk } from "../core/build/internal.js";
|
|
3
|
+
import { isCSSRequest } from "../core/render/util.js";
|
|
4
|
+
import { getPageDatasByChunk, getPageDataByViteID, hasPageDataByViteID } from "../core/build/internal.js";
|
|
5
5
|
const PLUGIN_NAME = "@astrojs/rollup-plugin-build-css";
|
|
6
6
|
const ASTRO_STYLE_PREFIX = "@astro-inline-style";
|
|
7
7
|
const ASTRO_PAGE_STYLE_PREFIX = "@astro-page-all-styles";
|
|
@@ -30,8 +30,46 @@ function isPageStyleVirtualModule(id) {
|
|
|
30
30
|
return id.startsWith(ASTRO_PAGE_STYLE_PREFIX);
|
|
31
31
|
}
|
|
32
32
|
function rollupPluginAstroBuildCSS(options) {
|
|
33
|
-
const { internals } = options;
|
|
33
|
+
const { internals, legacy } = options;
|
|
34
34
|
const styleSourceMap = /* @__PURE__ */ new Map();
|
|
35
|
+
function* walkStyles(ctx, id, seen = /* @__PURE__ */ new Set()) {
|
|
36
|
+
seen.add(id);
|
|
37
|
+
if (styleSourceMap.has(id)) {
|
|
38
|
+
yield [id, styleSourceMap.get(id)];
|
|
39
|
+
}
|
|
40
|
+
const info = ctx.getModuleInfo(id);
|
|
41
|
+
if (info) {
|
|
42
|
+
for (const importedId of info.importedIds) {
|
|
43
|
+
if (!seen.has(importedId)) {
|
|
44
|
+
yield* walkStyles(ctx, importedId, seen);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function addStyles() {
|
|
50
|
+
var _a;
|
|
51
|
+
for (const id of this.getModuleIds()) {
|
|
52
|
+
if (hasPageDataByViteID(internals, id)) {
|
|
53
|
+
let pageStyles = "";
|
|
54
|
+
for (const [_styleId, styles] of walkStyles(this, id)) {
|
|
55
|
+
pageStyles += styles;
|
|
56
|
+
}
|
|
57
|
+
if (!pageStyles)
|
|
58
|
+
continue;
|
|
59
|
+
const { code: minifiedCSS } = await esbuild.transform(pageStyles, {
|
|
60
|
+
loader: "css",
|
|
61
|
+
minify: true
|
|
62
|
+
});
|
|
63
|
+
const referenceId = this.emitFile({
|
|
64
|
+
name: "entry.css",
|
|
65
|
+
type: "asset",
|
|
66
|
+
source: minifiedCSS
|
|
67
|
+
});
|
|
68
|
+
const fileName = this.getFileName(referenceId);
|
|
69
|
+
(_a = getPageDataByViteID(internals, id)) == null ? void 0 : _a.css.add(fileName);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
35
73
|
return {
|
|
36
74
|
name: PLUGIN_NAME,
|
|
37
75
|
configResolved(resolvedConfig) {
|
|
@@ -75,6 +113,8 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
75
113
|
return null;
|
|
76
114
|
},
|
|
77
115
|
async renderChunk(_code, chunk) {
|
|
116
|
+
if (!legacy)
|
|
117
|
+
return null;
|
|
78
118
|
let chunkCSS = "";
|
|
79
119
|
let isPureCSS = true;
|
|
80
120
|
for (const [id] of Object.entries(chunk.modules)) {
|
|
@@ -108,13 +148,16 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
108
148
|
}
|
|
109
149
|
return null;
|
|
110
150
|
},
|
|
111
|
-
generateBundle(opts, bundle) {
|
|
151
|
+
async generateBundle(opts, bundle) {
|
|
112
152
|
const hasPureCSSChunks = internals.pureCSSChunks.size;
|
|
113
153
|
const pureChunkFilenames = new Set([...internals.pureCSSChunks].map((chunk) => chunk.fileName));
|
|
114
154
|
const emptyChunkFiles = [...pureChunkFilenames].map((file) => path.basename(file)).join("|").replace(/\./g, "\\.");
|
|
115
155
|
const emptyChunkRE = new RegExp(opts.format === "es" ? `\\bimport\\s*"[^"]*(?:${emptyChunkFiles})";
|
|
116
156
|
?` : `\\brequire\\(\\s*"[^"]*(?:${emptyChunkFiles})"\\);
|
|
117
157
|
?`, "g");
|
|
158
|
+
if (!legacy) {
|
|
159
|
+
await addStyles.call(this);
|
|
160
|
+
}
|
|
118
161
|
for (const [chunkId, chunk] of Object.entries(bundle)) {
|
|
119
162
|
if (chunk.type === "chunk") {
|
|
120
163
|
for (const { css: cssSet } of getPageDatasByChunk(internals, chunk)) {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -17,31 +17,32 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { createElement, createScript, getAttribute, hasAttribute, insertBefore, remove, setAttribute } from "@web/parse5-utils";
|
|
21
|
+
import { promises as fs } from "fs";
|
|
20
22
|
import parse5 from "parse5";
|
|
21
|
-
import srcsetParse from "srcset-parse";
|
|
22
23
|
import * as npath from "path";
|
|
23
|
-
import
|
|
24
|
-
import {
|
|
25
|
-
import { addRollupInput } from "./add-rollup-input.js";
|
|
26
|
-
import { findAssets, findExternalScripts, findInlineScripts, findInlineStyles, getTextContent, getAttributes } from "./extract-assets.js";
|
|
27
|
-
import { isBuildableImage, isBuildableLink, isHoistedScript, isInSrcDirectory, hasSrcSet } from "./util.js";
|
|
24
|
+
import srcsetParse from "srcset-parse";
|
|
25
|
+
import { prependDotSlash } from "../core/path.js";
|
|
28
26
|
import { render as ssrRender } from "../core/render/dev/index.js";
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
27
|
+
import { getOutputFilename } from "../core/util.js";
|
|
28
|
+
import { getAstroPageStyleId, getAstroStyleId } from "../vite-plugin-build-css/index.js";
|
|
29
|
+
import { addRollupInput } from "./add-rollup-input.js";
|
|
30
|
+
import { findAssets, findExternalScripts, findInlineScripts, findInlineStyles, getAttributes, getTextContent } from "./extract-assets.js";
|
|
31
|
+
import { hasSrcSet, isBuildableImage, isBuildableLink, isHoistedScript, isInSrcDirectory } from "./util.js";
|
|
32
|
+
import { createRequest } from "../core/request.js";
|
|
31
33
|
const matchSrcset = srcsetParse.default;
|
|
32
34
|
const PLUGIN_NAME = "@astro/rollup-plugin-build";
|
|
33
35
|
const ASTRO_PAGE_PREFIX = "@astro-page";
|
|
34
36
|
const ASTRO_SCRIPT_PREFIX = "@astro-script";
|
|
35
37
|
const ASTRO_EMPTY = "@astro-empty";
|
|
36
|
-
const STATUS_CODE_REGEXP = /^[0-9]{3}$/;
|
|
37
38
|
function relativePath(from, to) {
|
|
38
39
|
const rel = npath.posix.relative(from, to);
|
|
39
40
|
return prependDotSlash(rel);
|
|
40
41
|
}
|
|
41
42
|
function rollupPluginAstroScanHTML(options) {
|
|
42
43
|
const { astroConfig, internals, logging, origin, allPages, routeCache, viteServer, pageNames } = options;
|
|
43
|
-
const srcRoot = astroConfig.
|
|
44
|
-
const srcRootWeb = srcRoot.substr(astroConfig.
|
|
44
|
+
const srcRoot = astroConfig.srcDir.pathname;
|
|
45
|
+
const srcRootWeb = srcRoot.substr(astroConfig.root.pathname.length - 1);
|
|
45
46
|
const renderedPageMap = /* @__PURE__ */ new Map();
|
|
46
47
|
const astroScriptMap = /* @__PURE__ */ new Map();
|
|
47
48
|
const astroPageMap = /* @__PURE__ */ new Map();
|
|
@@ -65,10 +66,13 @@ function rollupPluginAstroScanHTML(options) {
|
|
|
65
66
|
const id = ASTRO_PAGE_PREFIX + pathname;
|
|
66
67
|
const response = await ssrRender(renderers, mod, {
|
|
67
68
|
astroConfig,
|
|
68
|
-
filePath: new URL(`./${component}`, astroConfig.
|
|
69
|
+
filePath: new URL(`./${component}`, astroConfig.root),
|
|
69
70
|
logging,
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
request: createRequest({
|
|
72
|
+
url: new URL(origin + pathname),
|
|
73
|
+
headers: new Headers(),
|
|
74
|
+
logging
|
|
75
|
+
}),
|
|
72
76
|
mode: "production",
|
|
73
77
|
origin,
|
|
74
78
|
pathname,
|
|
@@ -131,7 +135,7 @@ function rollupPluginAstroScanHTML(options) {
|
|
|
131
135
|
if ((src == null ? void 0 : src.startsWith(srcRoot)) && !astroAssetMap.has(src)) {
|
|
132
136
|
astroAssetMap.set(src, fs.readFile(new URL(`file://${src}`)));
|
|
133
137
|
} else if ((src == null ? void 0 : src.startsWith(srcRootWeb)) && !astroAssetMap.has(src)) {
|
|
134
|
-
const resolved = new URL("." + src, astroConfig.
|
|
138
|
+
const resolved = new URL("." + src, astroConfig.root);
|
|
135
139
|
astroAssetMap.set(src, fs.readFile(resolved));
|
|
136
140
|
}
|
|
137
141
|
}
|
|
@@ -141,7 +145,7 @@ function rollupPluginAstroScanHTML(options) {
|
|
|
141
145
|
if (url.startsWith(srcRoot) && !astroAssetMap.has(url)) {
|
|
142
146
|
astroAssetMap.set(url, fs.readFile(new URL(`file://${url}`)));
|
|
143
147
|
} else if (url.startsWith(srcRootWeb) && !astroAssetMap.has(url)) {
|
|
144
|
-
const resolved = new URL("." + url, astroConfig.
|
|
148
|
+
const resolved = new URL("." + url, astroConfig.root);
|
|
145
149
|
astroAssetMap.set(url, fs.readFile(resolved));
|
|
146
150
|
}
|
|
147
151
|
}
|
|
@@ -313,7 +317,7 @@ function rollupPluginAstroScanHTML(options) {
|
|
|
313
317
|
} else if (isInSrcDirectory(script, "src", srcRoot, srcRootWeb)) {
|
|
314
318
|
let src = getAttribute(script, "src");
|
|
315
319
|
if (src == null ? void 0 : src.startsWith(srcRootWeb)) {
|
|
316
|
-
src = new URL("." + src, astroConfig.
|
|
320
|
+
src = new URL("." + src, astroConfig.root).pathname;
|
|
317
321
|
}
|
|
318
322
|
if (src && (facadeIdMap.has(src) || facadeIdMap.has(src.substr(1)))) {
|
|
319
323
|
const assetRootPath = "/" + (facadeIdMap.get(src) || facadeIdMap.get(src.substr(1)));
|
|
@@ -386,12 +390,7 @@ function rollupPluginAstroScanHTML(options) {
|
|
|
386
390
|
}
|
|
387
391
|
const outHTML = parse5.serialize(document);
|
|
388
392
|
const name = pathname.substr(1);
|
|
389
|
-
|
|
390
|
-
if (astroConfig.buildOptions.pageUrlFormat === "file" || STATUS_CODE_REGEXP.test(name)) {
|
|
391
|
-
outPath = `${removeEndingForwardSlash(name || "index")}.html`;
|
|
392
|
-
} else {
|
|
393
|
-
outPath = npath.posix.join(name, "index.html");
|
|
394
|
-
}
|
|
393
|
+
const outPath = getOutputFilename(astroConfig, name);
|
|
395
394
|
this.emitFile({
|
|
396
395
|
fileName: outPath,
|
|
397
396
|
source: outHTML,
|
|
File without changes
|
|
@@ -47,7 +47,7 @@ const getConfigAlias = (cwd) => {
|
|
|
47
47
|
return aliases;
|
|
48
48
|
};
|
|
49
49
|
function configAliasVitePlugin(astroConfig) {
|
|
50
|
-
const configAlias = getConfigAlias(astroConfig.
|
|
50
|
+
const configAlias = getConfigAlias(astroConfig.root && url.fileURLToPath(astroConfig.root));
|
|
51
51
|
if (!configAlias)
|
|
52
52
|
return {};
|
|
53
53
|
return {
|
|
@@ -6,7 +6,7 @@ function getPrivateEnv(viteConfig, astroConfig) {
|
|
|
6
6
|
if (viteConfig.envPrefix) {
|
|
7
7
|
envPrefixes = Array.isArray(viteConfig.envPrefix) ? viteConfig.envPrefix : [viteConfig.envPrefix];
|
|
8
8
|
}
|
|
9
|
-
const fullEnv = loadEnv(viteConfig.mode, viteConfig.envDir ?? fileURLToPath(astroConfig.
|
|
9
|
+
const fullEnv = loadEnv(viteConfig.mode, viteConfig.envDir ?? fileURLToPath(astroConfig.root), "");
|
|
10
10
|
const privateKeys = Object.keys(fullEnv).filter((key) => {
|
|
11
11
|
if (typeof process.env[key] !== "undefined")
|
|
12
12
|
return false;
|
|
File without changes
|
|
@@ -3,7 +3,7 @@ import esbuild from "esbuild";
|
|
|
3
3
|
import * as colors from "kleur/colors";
|
|
4
4
|
import * as eslexer from "es-module-lexer";
|
|
5
5
|
import path from "path";
|
|
6
|
-
import { error } from "../core/logger.js";
|
|
6
|
+
import { error } from "../core/logger/core.js";
|
|
7
7
|
import { parseNpmName } from "../core/util.js";
|
|
8
8
|
const JSX_RENDERER_CACHE = /* @__PURE__ */ new WeakMap();
|
|
9
9
|
const JSX_EXTENSIONS = /* @__PURE__ */ new Set([".jsx", ".tsx"]);
|