astro 0.25.3 → 0.26.1
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/astro.js +12 -4
- package/dist/cli/check.js +4 -4
- package/dist/cli/index.js +21 -32
- package/dist/core/add/index.js +36 -20
- package/dist/core/app/index.js +17 -11
- package/dist/core/build/common.js +4 -5
- package/dist/core/build/generate.js +69 -73
- package/dist/core/build/index.js +90 -77
- package/dist/core/build/page-data.js +10 -9
- package/dist/core/build/static-build.js +41 -24
- package/dist/core/build/vite-plugin-hoisted-scripts.js +1 -1
- package/dist/core/build/vite-plugin-ssr.js +5 -2
- package/dist/core/config.js +89 -79
- package/dist/core/create-vite.js +17 -8
- package/dist/core/dev/index.js +22 -9
- 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 +79 -28
- package/dist/core/preview/index.js +15 -9
- package/dist/core/preview/util.js +3 -6
- package/dist/core/render/core.js +21 -6
- package/dist/core/render/dev/css.js +5 -6
- package/dist/core/render/dev/index.js +43 -38
- package/dist/core/render/paginate.js +3 -1
- package/dist/core/render/pretty-feed.js +103 -0
- package/dist/core/render/result.js +33 -15
- package/dist/core/render/route-cache.js +12 -3
- package/dist/core/render/rss.js +5 -4
- package/dist/core/render/ssr-element.js +1 -1
- package/dist/core/render/util.js +35 -0
- package/dist/core/request.js +33 -0
- package/dist/core/routing/manifest/create.js +8 -6
- package/dist/core/routing/validation.js +1 -1
- package/dist/core/util.js +57 -125
- package/dist/integrations/index.js +38 -6
- package/dist/runtime/server/index.js +51 -41
- package/dist/template/4xx.js +8 -2
- package/dist/template/5xx.js +8 -1
- package/dist/types/@types/astro.d.ts +290 -232
- 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/page-data.d.ts +1 -1
- 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 +5 -3
- 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 +5 -7
- 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 +2 -2
- 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 +11 -5
- package/dist/types/runtime/server/index.d.ts +1 -2
- package/dist/types/template/4xx.d.ts +1 -1
- package/dist/types/template/5xx.d.ts +1 -1
- 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/styles.d.ts +1 -1
- package/dist/types/vite-plugin-astro-server/index.d.ts +1 -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-env/index.d.ts +1 -1
- package/dist/types/vite-plugin-integrations-container/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 +41 -13
- package/dist/vite-plugin-astro/styles.js +8 -2
- package/dist/vite-plugin-astro-postprocess/index.js +35 -34
- package/dist/vite-plugin-astro-server/index.js +66 -25
- package/dist/vite-plugin-build-css/index.js +6 -2
- package/dist/vite-plugin-build-html/index.js +43 -23
- package/dist/vite-plugin-config-alias/index.js +4 -2
- package/dist/vite-plugin-env/index.js +8 -3
- package/dist/vite-plugin-integrations-container/index.js +3 -1
- package/dist/vite-plugin-jsx/index.js +22 -4
- package/dist/vite-plugin-markdown/index.js +93 -18
- package/env.d.ts +1 -1
- package/package.json +13 -9
- package/dist/core/build/scan-based-build.js +0 -62
- 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
package/astro.js
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
const CI_INSTRUCTIONS = {
|
|
11
11
|
NETLIFY: 'https://docs.netlify.com/configure-builds/manage-dependencies/#node-js-and-javascript',
|
|
12
|
-
GITHUB_ACTIONS:
|
|
12
|
+
GITHUB_ACTIONS:
|
|
13
|
+
'https://docs.github.com/en/actions/guides/building-and-testing-nodejs#specifying-the-nodejs-version',
|
|
13
14
|
VERCEL: 'https://vercel.com/docs/runtimes#official-runtimes/node-js/node-js-version',
|
|
14
15
|
};
|
|
15
16
|
|
|
@@ -17,7 +18,10 @@ const CI_INSTRUCTIONS = {
|
|
|
17
18
|
async function main() {
|
|
18
19
|
// Check for ESM support.
|
|
19
20
|
// Load the "supports-esm" package in an way that works in both ESM & CJS.
|
|
20
|
-
let supportsESM =
|
|
21
|
+
let supportsESM =
|
|
22
|
+
typeof require !== 'undefined'
|
|
23
|
+
? require('supports-esm')
|
|
24
|
+
: (await import('supports-esm')).default;
|
|
21
25
|
|
|
22
26
|
// Check for CJS->ESM named export support.
|
|
23
27
|
// "path-to-regexp" is a real-world package that we depend on, that only
|
|
@@ -79,7 +83,9 @@ Please upgrade Node.js to a supported version: "${engines}"\n`);
|
|
|
79
83
|
break;
|
|
80
84
|
}
|
|
81
85
|
}
|
|
82
|
-
console.log(
|
|
86
|
+
console.log(
|
|
87
|
+
`${ci.name} CI Environment Detected!\nAdditional steps may be needed to set your Node.js version:`
|
|
88
|
+
);
|
|
83
89
|
console.log(`Documentation: https://docs.astro.build/guides/deploy`);
|
|
84
90
|
if (CI_INSTRUCTIONS[platform]) {
|
|
85
91
|
console.log(`${ci.name} Documentation: ${CI_INSTRUCTIONS[platform]}`);
|
|
@@ -90,4 +96,6 @@ Please upgrade Node.js to a supported version: "${engines}"\n`);
|
|
|
90
96
|
process.exit(1);
|
|
91
97
|
}
|
|
92
98
|
|
|
93
|
-
main()
|
|
99
|
+
main()
|
|
100
|
+
.then(() => process.exit(0))
|
|
101
|
+
.catch(() => process.exit(1));
|
package/dist/cli/check.js
CHANGED
|
@@ -42,13 +42,13 @@ function offsetAt({ line, character }, text) {
|
|
|
42
42
|
}
|
|
43
43
|
return i;
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function generateString(str, len) {
|
|
46
46
|
return Array.from({ length: len }, () => str).join("");
|
|
47
47
|
}
|
|
48
48
|
async function run() {
|
|
49
49
|
}
|
|
50
50
|
async function check(astroConfig) {
|
|
51
|
-
const root = astroConfig.
|
|
51
|
+
const root = astroConfig.root;
|
|
52
52
|
let checker = new AstroCheck(root.toString());
|
|
53
53
|
await openAllDocuments(root, [], checker);
|
|
54
54
|
let diagnostics = await checker.getDiagnostics();
|
|
@@ -67,8 +67,8 @@ async function check(astroConfig) {
|
|
|
67
67
|
const lineNumStr = d.range.start.line.toString();
|
|
68
68
|
const lineNumLen = lineNumStr.length;
|
|
69
69
|
console.error(`${bgWhite(black(lineNumStr))} ${str}`);
|
|
70
|
-
let tildes =
|
|
71
|
-
let spaces =
|
|
70
|
+
let tildes = generateString("~", d.range.end.character - d.range.start.character);
|
|
71
|
+
let spaces = generateString(" ", d.range.start.character + lineNumLen - 1);
|
|
72
72
|
console.error(` ${spaces}${bold(red(tildes))}
|
|
73
73
|
`);
|
|
74
74
|
result.errors++;
|
package/dist/cli/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { enableVerboseLogging } from "../core/logger.js";
|
|
2
1
|
import * as colors from "kleur/colors";
|
|
3
2
|
import yargs from "yargs-parser";
|
|
4
3
|
import { z } from "zod";
|
|
5
|
-
import {
|
|
4
|
+
import { nodeLogDestination, enableVerboseLogging } from "../core/logger/node.js";
|
|
6
5
|
import build from "../core/build/index.js";
|
|
7
6
|
import add from "../core/add/index.js";
|
|
8
7
|
import devServer from "../core/dev/index.js";
|
|
9
8
|
import preview from "../core/preview/index.js";
|
|
10
9
|
import { check } from "./check.js";
|
|
11
|
-
import {
|
|
12
|
-
import { printHelp } from "../core/messages.js";
|
|
10
|
+
import { loadConfig } from "../core/config.js";
|
|
11
|
+
import { printHelp, formatErrorMessage, formatConfigErrorMessage } from "../core/messages.js";
|
|
12
|
+
import { createSafeError } from "../core/util.js";
|
|
13
13
|
function printAstroHelp() {
|
|
14
14
|
printHelp({
|
|
15
15
|
commandName: "astro",
|
|
@@ -26,10 +26,9 @@ function printAstroHelp() {
|
|
|
26
26
|
flags: [
|
|
27
27
|
["--host [optional IP]", "Expose server on network"],
|
|
28
28
|
["--config <path>", "Specify the path to the Astro config file."],
|
|
29
|
-
["--
|
|
30
|
-
["--no-sitemap", "Disable sitemap generation (build only)."],
|
|
29
|
+
["--root <path>", "Specify the path to the project root folder."],
|
|
31
30
|
["--legacy-build", "Use the build strategy prior to 0.24.0"],
|
|
32
|
-
["--experimental-ssr", "Enable SSR compilation."],
|
|
31
|
+
["--experimental-ssr", "Enable SSR compilation fot 3rd-party adapters."],
|
|
33
32
|
["--drafts", "Include markdown draft pages in the build."],
|
|
34
33
|
["--verbose", "Enable verbose logging"],
|
|
35
34
|
["--silent", "Disable logging"]
|
|
@@ -37,7 +36,7 @@ function printAstroHelp() {
|
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
38
|
async function printVersion() {
|
|
40
|
-
const version = "0.
|
|
39
|
+
const version = "0.26.1";
|
|
41
40
|
console.log();
|
|
42
41
|
console.log(` ${colors.bgGreen(colors.black(` astro `))} ${colors.green(`v${version}`)}`);
|
|
43
42
|
}
|
|
@@ -58,7 +57,7 @@ function resolveCommand(flags) {
|
|
|
58
57
|
async function cli(args) {
|
|
59
58
|
const flags = yargs(args);
|
|
60
59
|
const cmd = resolveCommand(flags);
|
|
61
|
-
const
|
|
60
|
+
const root = flags.root;
|
|
62
61
|
switch (cmd) {
|
|
63
62
|
case "help":
|
|
64
63
|
printAstroHelp();
|
|
@@ -68,7 +67,7 @@ async function cli(args) {
|
|
|
68
67
|
return process.exit(0);
|
|
69
68
|
}
|
|
70
69
|
let logging = {
|
|
71
|
-
dest:
|
|
70
|
+
dest: nodeLogDestination,
|
|
72
71
|
level: "info"
|
|
73
72
|
};
|
|
74
73
|
if (flags.verbose) {
|
|
@@ -79,40 +78,34 @@ async function cli(args) {
|
|
|
79
78
|
}
|
|
80
79
|
let config;
|
|
81
80
|
try {
|
|
82
|
-
config = await loadConfig({ cwd:
|
|
81
|
+
config = await loadConfig({ cwd: root, flags, cmd });
|
|
83
82
|
} catch (err) {
|
|
84
|
-
throwAndExit(err);
|
|
85
|
-
return;
|
|
83
|
+
return throwAndExit(err);
|
|
86
84
|
}
|
|
87
85
|
switch (cmd) {
|
|
88
86
|
case "add": {
|
|
89
87
|
try {
|
|
90
88
|
const packages = flags._.slice(3);
|
|
91
|
-
await add(packages, { cwd:
|
|
92
|
-
process.exit(0);
|
|
89
|
+
return await add(packages, { cwd: root, flags, logging });
|
|
93
90
|
} catch (err) {
|
|
94
|
-
throwAndExit(err);
|
|
91
|
+
return throwAndExit(err);
|
|
95
92
|
}
|
|
96
|
-
return;
|
|
97
93
|
}
|
|
98
94
|
case "dev": {
|
|
99
95
|
try {
|
|
100
96
|
await devServer(config, { logging });
|
|
101
|
-
await new Promise(() => {
|
|
97
|
+
return await new Promise(() => {
|
|
102
98
|
});
|
|
103
99
|
} catch (err) {
|
|
104
|
-
throwAndExit(err);
|
|
100
|
+
return throwAndExit(err);
|
|
105
101
|
}
|
|
106
|
-
return;
|
|
107
102
|
}
|
|
108
103
|
case "build": {
|
|
109
104
|
try {
|
|
110
|
-
await build(config, { logging });
|
|
111
|
-
process.exit(0);
|
|
105
|
+
return await build(config, { logging });
|
|
112
106
|
} catch (err) {
|
|
113
|
-
throwAndExit(err);
|
|
107
|
+
return throwAndExit(err);
|
|
114
108
|
}
|
|
115
|
-
return;
|
|
116
109
|
}
|
|
117
110
|
case "check": {
|
|
118
111
|
const ret = await check(config);
|
|
@@ -120,11 +113,10 @@ async function cli(args) {
|
|
|
120
113
|
}
|
|
121
114
|
case "preview": {
|
|
122
115
|
try {
|
|
123
|
-
await preview(config, { logging });
|
|
116
|
+
return await preview(config, { logging });
|
|
124
117
|
} catch (err) {
|
|
125
|
-
throwAndExit(err);
|
|
118
|
+
return throwAndExit(err);
|
|
126
119
|
}
|
|
127
|
-
return;
|
|
128
120
|
}
|
|
129
121
|
default: {
|
|
130
122
|
throw new Error(`Error running ${cmd}`);
|
|
@@ -133,12 +125,9 @@ async function cli(args) {
|
|
|
133
125
|
}
|
|
134
126
|
function throwAndExit(err) {
|
|
135
127
|
if (err instanceof z.ZodError) {
|
|
136
|
-
console.error(
|
|
137
|
-
} else if (err.stack) {
|
|
138
|
-
const [mainMsg, ...stackMsg] = err.stack.split("\n");
|
|
139
|
-
console.error(colors.red(mainMsg) + "\n" + colors.dim(stackMsg.join("\n")));
|
|
128
|
+
console.error(formatConfigErrorMessage(err));
|
|
140
129
|
} else {
|
|
141
|
-
console.error(
|
|
130
|
+
console.error(formatErrorMessage(createSafeError(err)));
|
|
142
131
|
}
|
|
143
132
|
process.exit(1);
|
|
144
133
|
}
|
package/dist/core/add/index.js
CHANGED
|
@@ -9,11 +9,11 @@ import preferredPM from "preferred-pm";
|
|
|
9
9
|
import ora from "ora";
|
|
10
10
|
import { resolveConfigURL } from "../config.js";
|
|
11
11
|
import { apply as applyPolyfill } from "../polyfill.js";
|
|
12
|
-
import { error, info, debug } from "../logger.js";
|
|
12
|
+
import { error, info, debug } from "../logger/core.js";
|
|
13
13
|
import { printHelp } from "../messages.js";
|
|
14
14
|
import * as msg from "../messages.js";
|
|
15
15
|
import * as CONSTS from "./consts.js";
|
|
16
|
-
import { dim,
|
|
16
|
+
import { dim, cyan, green, magenta, bold } from "kleur/colors";
|
|
17
17
|
import { parseNpmName } from "../util.js";
|
|
18
18
|
import { wrapDefaultExport } from "./wrapper.js";
|
|
19
19
|
import { ensureImport } from "./imports.js";
|
|
@@ -54,18 +54,11 @@ async function add(names, { cwd, flags, logging }) {
|
|
|
54
54
|
choices: CONSTS.FIRST_PARTY_ADDONS
|
|
55
55
|
}
|
|
56
56
|
]);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (selected.length === 0) {
|
|
63
|
-
error(logging, null, `
|
|
64
|
-
${red("No integrations specified!")}
|
|
65
|
-
${dim("Try running")} astro add again.`);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
names = selected;
|
|
57
|
+
names = [...response.frameworks ?? [], ...response.addons ?? []];
|
|
58
|
+
}
|
|
59
|
+
if (names.length === 0) {
|
|
60
|
+
error(logging, null, `No integrations specified.`);
|
|
61
|
+
return;
|
|
69
62
|
}
|
|
70
63
|
names = names.map((name) => CONSTS.ALIASES.has(name) ? CONSTS.ALIASES.get(name) : name);
|
|
71
64
|
if (configURL) {
|
|
@@ -127,7 +120,11 @@ ${dim("Try running")} astro add again.`);
|
|
|
127
120
|
case UpdateResult.updated: {
|
|
128
121
|
const len = integrations.length;
|
|
129
122
|
if (integrations.find((integration) => integration.id === "tailwind")) {
|
|
130
|
-
const possibleConfigFiles = [
|
|
123
|
+
const possibleConfigFiles = [
|
|
124
|
+
"./tailwind.config.cjs",
|
|
125
|
+
"./tailwind.config.mjs",
|
|
126
|
+
"./tailwind.config.js"
|
|
127
|
+
].map((p) => fileURLToPath(new URL(p, configURL)));
|
|
131
128
|
let alreadyConfigured = false;
|
|
132
129
|
for (const possibleConfigPath of possibleConfigFiles) {
|
|
133
130
|
if (existsSync(possibleConfigPath)) {
|
|
@@ -228,7 +225,12 @@ var UpdateResult = /* @__PURE__ */ ((UpdateResult2) => {
|
|
|
228
225
|
UpdateResult2[UpdateResult2["failure"] = 3] = "failure";
|
|
229
226
|
return UpdateResult2;
|
|
230
227
|
})(UpdateResult || {});
|
|
231
|
-
async function updateAstroConfig({
|
|
228
|
+
async function updateAstroConfig({
|
|
229
|
+
configURL,
|
|
230
|
+
ast,
|
|
231
|
+
flags,
|
|
232
|
+
logging
|
|
233
|
+
}) {
|
|
232
234
|
const input = await fs.readFile(fileURLToPath(configURL), { encoding: "utf-8" });
|
|
233
235
|
let output = await generate(ast);
|
|
234
236
|
const comment = "// https://astro.build/config";
|
|
@@ -260,7 +262,12 @@ ${defaultExport}`);
|
|
|
260
262
|
diffed = diffed.replace(newContent, coloredOutput);
|
|
261
263
|
}
|
|
262
264
|
const message = `
|
|
263
|
-
${boxen(diffed, {
|
|
265
|
+
${boxen(diffed, {
|
|
266
|
+
margin: 0.5,
|
|
267
|
+
padding: 0.5,
|
|
268
|
+
borderStyle: "round",
|
|
269
|
+
title: configURL.pathname.split("/").pop()
|
|
270
|
+
})}
|
|
264
271
|
`;
|
|
265
272
|
info(logging, null, `
|
|
266
273
|
${magenta("Astro will make the following changes to your config file:")}
|
|
@@ -273,7 +280,10 @@ ${message}`);
|
|
|
273
280
|
return 2 /* cancelled */;
|
|
274
281
|
}
|
|
275
282
|
}
|
|
276
|
-
async function getInstallIntegrationsCommand({
|
|
283
|
+
async function getInstallIntegrationsCommand({
|
|
284
|
+
integrations,
|
|
285
|
+
cwd = process.cwd()
|
|
286
|
+
}) {
|
|
277
287
|
const pm = await preferredPM(cwd);
|
|
278
288
|
debug("add", `package manager: ${JSON.stringify(pm)}`);
|
|
279
289
|
if (!pm)
|
|
@@ -303,7 +313,11 @@ async function tryToInstallIntegrations({
|
|
|
303
313
|
} else {
|
|
304
314
|
const coloredOutput = `${bold(installCommand.pm)} ${installCommand.command} ${installCommand.flags.join(" ")} ${cyan(installCommand.dependencies.join(" "))}`;
|
|
305
315
|
const message = `
|
|
306
|
-
${boxen(coloredOutput, {
|
|
316
|
+
${boxen(coloredOutput, {
|
|
317
|
+
margin: 0.5,
|
|
318
|
+
padding: 0.5,
|
|
319
|
+
borderStyle: "round"
|
|
320
|
+
})}
|
|
307
321
|
`;
|
|
308
322
|
info(logging, null, `
|
|
309
323
|
${magenta("Astro will run the following command:")}
|
|
@@ -345,7 +359,9 @@ async function validateIntegrations(integrations) {
|
|
|
345
359
|
}
|
|
346
360
|
return res.json();
|
|
347
361
|
});
|
|
348
|
-
let dependencies = [
|
|
362
|
+
let dependencies = [
|
|
363
|
+
[result["name"], `^${result["version"]}`]
|
|
364
|
+
];
|
|
349
365
|
if (result["peerDependencies"]) {
|
|
350
366
|
for (const peer in result["peerDependencies"]) {
|
|
351
367
|
dependencies.push([peer, result["peerDependencies"][peer]]);
|
package/dist/core/app/index.js
CHANGED
|
@@ -20,15 +20,18 @@ var __privateMethod = (obj, member, method) => {
|
|
|
20
20
|
__accessCheck(obj, member, "access private method");
|
|
21
21
|
return method;
|
|
22
22
|
};
|
|
23
|
-
var _manifest, _manifestData, _routeDataToRouteInfo, _routeCache, _encoder, _renderPage, renderPage_fn, _callEndpoint, callEndpoint_fn;
|
|
23
|
+
var _manifest, _manifestData, _routeDataToRouteInfo, _routeCache, _encoder, _logging, _renderPage, renderPage_fn, _callEndpoint, callEndpoint_fn;
|
|
24
24
|
import mime from "mime";
|
|
25
|
-
import {
|
|
25
|
+
import { consoleLogDestination } from "../logger/console.js";
|
|
26
26
|
import { deserializeManifest } from "./common.js";
|
|
27
27
|
import { matchRoute } from "../routing/match.js";
|
|
28
28
|
import { render } from "../render/core.js";
|
|
29
29
|
import { call as callEndpoint } from "../endpoint/index.js";
|
|
30
30
|
import { RouteCache } from "../render/route-cache.js";
|
|
31
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
createLinkStylesheetElementSet,
|
|
33
|
+
createModuleScriptElementWithSrcSet
|
|
34
|
+
} from "../render/ssr-element.js";
|
|
32
35
|
import { prependForwardSlash } from "../path.js";
|
|
33
36
|
class App {
|
|
34
37
|
constructor(manifest) {
|
|
@@ -39,12 +42,16 @@ class App {
|
|
|
39
42
|
__privateAdd(this, _routeDataToRouteInfo, void 0);
|
|
40
43
|
__privateAdd(this, _routeCache, void 0);
|
|
41
44
|
__privateAdd(this, _encoder, new TextEncoder());
|
|
45
|
+
__privateAdd(this, _logging, {
|
|
46
|
+
dest: consoleLogDestination,
|
|
47
|
+
level: "info"
|
|
48
|
+
});
|
|
42
49
|
__privateSet(this, _manifest, manifest);
|
|
43
50
|
__privateSet(this, _manifestData, {
|
|
44
51
|
routes: manifest.routes.map((route) => route.routeData)
|
|
45
52
|
});
|
|
46
53
|
__privateSet(this, _routeDataToRouteInfo, new Map(manifest.routes.map((route) => [route.routeData, route])));
|
|
47
|
-
__privateSet(this, _routeCache, new RouteCache(
|
|
54
|
+
__privateSet(this, _routeCache, new RouteCache(__privateGet(this, _logging)));
|
|
48
55
|
}
|
|
49
56
|
match(request) {
|
|
50
57
|
const url = new URL(request.url);
|
|
@@ -75,6 +82,7 @@ _manifestData = new WeakMap();
|
|
|
75
82
|
_routeDataToRouteInfo = new WeakMap();
|
|
76
83
|
_routeCache = new WeakMap();
|
|
77
84
|
_encoder = new WeakMap();
|
|
85
|
+
_logging = new WeakMap();
|
|
78
86
|
_renderPage = new WeakSet();
|
|
79
87
|
renderPage_fn = async function(request, routeData, mod) {
|
|
80
88
|
const url = new URL(request.url);
|
|
@@ -86,7 +94,7 @@ renderPage_fn = async function(request, routeData, mod) {
|
|
|
86
94
|
const result = await render({
|
|
87
95
|
legacyBuild: false,
|
|
88
96
|
links,
|
|
89
|
-
logging:
|
|
97
|
+
logging: __privateGet(this, _logging),
|
|
90
98
|
markdownRender: manifest.markdown.render,
|
|
91
99
|
mod,
|
|
92
100
|
origin: url.origin,
|
|
@@ -104,8 +112,7 @@ renderPage_fn = async function(request, routeData, mod) {
|
|
|
104
112
|
routeCache: __privateGet(this, _routeCache),
|
|
105
113
|
site: __privateGet(this, _manifest).site,
|
|
106
114
|
ssr: true,
|
|
107
|
-
|
|
108
|
-
headers: request.headers
|
|
115
|
+
request
|
|
109
116
|
});
|
|
110
117
|
if (result.type === "response") {
|
|
111
118
|
return result.response;
|
|
@@ -121,15 +128,14 @@ renderPage_fn = async function(request, routeData, mod) {
|
|
|
121
128
|
});
|
|
122
129
|
};
|
|
123
130
|
_callEndpoint = new WeakSet();
|
|
124
|
-
callEndpoint_fn = async function(request,
|
|
131
|
+
callEndpoint_fn = async function(request, _routeData, mod) {
|
|
125
132
|
const url = new URL(request.url);
|
|
126
133
|
const handler = mod;
|
|
127
134
|
const result = await callEndpoint(handler, {
|
|
128
|
-
|
|
129
|
-
logging: defaultLogOptions,
|
|
130
|
-
method: request.method,
|
|
135
|
+
logging: __privateGet(this, _logging),
|
|
131
136
|
origin: url.origin,
|
|
132
137
|
pathname: url.pathname,
|
|
138
|
+
request,
|
|
133
139
|
routeCache: __privateGet(this, _routeCache),
|
|
134
140
|
ssr: true
|
|
135
141
|
});
|
|
@@ -2,7 +2,7 @@ import npath from "path";
|
|
|
2
2
|
import { appendForwardSlash } from "../../core/path.js";
|
|
3
3
|
const STATUS_CODE_PAGES = /* @__PURE__ */ new Set(["/404", "/500"]);
|
|
4
4
|
function getOutRoot(astroConfig) {
|
|
5
|
-
return new URL("./", astroConfig.
|
|
5
|
+
return new URL("./", astroConfig.outDir);
|
|
6
6
|
}
|
|
7
7
|
function getOutFolder(astroConfig, pathname, routeType) {
|
|
8
8
|
const outRoot = getOutRoot(astroConfig);
|
|
@@ -10,7 +10,7 @@ function getOutFolder(astroConfig, pathname, routeType) {
|
|
|
10
10
|
case "endpoint":
|
|
11
11
|
return new URL("." + appendForwardSlash(npath.dirname(pathname)), outRoot);
|
|
12
12
|
case "page":
|
|
13
|
-
switch (astroConfig.
|
|
13
|
+
switch (astroConfig.build.format) {
|
|
14
14
|
case "directory": {
|
|
15
15
|
if (STATUS_CODE_PAGES.has(pathname)) {
|
|
16
16
|
return new URL("." + appendForwardSlash(npath.dirname(pathname)), outRoot);
|
|
@@ -28,7 +28,7 @@ function getOutFile(astroConfig, outFolder, pathname, routeType) {
|
|
|
28
28
|
case "endpoint":
|
|
29
29
|
return new URL(npath.basename(pathname), outFolder);
|
|
30
30
|
case "page":
|
|
31
|
-
switch (astroConfig.
|
|
31
|
+
switch (astroConfig.build.format) {
|
|
32
32
|
case "directory": {
|
|
33
33
|
if (STATUS_CODE_PAGES.has(pathname)) {
|
|
34
34
|
const baseName = npath.basename(pathname);
|
|
@@ -45,6 +45,5 @@ function getOutFile(astroConfig, outFolder, pathname, routeType) {
|
|
|
45
45
|
}
|
|
46
46
|
export {
|
|
47
47
|
getOutFile,
|
|
48
|
-
getOutFolder
|
|
49
|
-
getOutRoot
|
|
48
|
+
getOutFolder
|
|
50
49
|
};
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
+
import astroRemark from "@astrojs/markdown-remark";
|
|
1
2
|
import fs from "fs";
|
|
3
|
+
import { bgGreen, black, cyan, dim, green, magenta } from "kleur/colors";
|
|
2
4
|
import npath from "path";
|
|
3
5
|
import { fileURLToPath } from "url";
|
|
4
|
-
import { debug,
|
|
6
|
+
import { debug, info } from "../logger/core.js";
|
|
5
7
|
import { prependForwardSlash } from "../../core/path.js";
|
|
6
8
|
import { BEFORE_HYDRATION_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
7
9
|
import { call as callEndpoint } from "../endpoint/index.js";
|
|
8
10
|
import { render } from "../render/core.js";
|
|
9
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
createLinkStylesheetElementSet,
|
|
13
|
+
createModuleScriptElementWithSrcSet
|
|
14
|
+
} from "../render/ssr-element.js";
|
|
15
|
+
import { getOutputFilename, isBuildingToSSR } from "../util.js";
|
|
10
16
|
import { getOutFile, getOutFolder } from "./common.js";
|
|
11
|
-
import {
|
|
12
|
-
import { bgMagenta, black, cyan, dim, magenta } from "kleur/colors";
|
|
17
|
+
import { eachPageData, getPageDataByComponent } from "./internal.js";
|
|
13
18
|
import { getTimeStat } from "./util.js";
|
|
19
|
+
import { createRequest } from "../request.js";
|
|
14
20
|
const MAX_CONCURRENT_RENDERS = 1;
|
|
15
21
|
function* throttle(max, inPaths) {
|
|
16
22
|
let tmp = [];
|
|
@@ -30,7 +36,7 @@ function* throttle(max, inPaths) {
|
|
|
30
36
|
}
|
|
31
37
|
}
|
|
32
38
|
function rootRelativeFacadeId(facadeId, astroConfig) {
|
|
33
|
-
return facadeId.slice(fileURLToPath(astroConfig.
|
|
39
|
+
return facadeId.slice(fileURLToPath(astroConfig.root).length);
|
|
34
40
|
}
|
|
35
41
|
function chunkIsPage(astroConfig, output, internals) {
|
|
36
42
|
if (output.type !== "chunk") {
|
|
@@ -44,18 +50,19 @@ function chunkIsPage(astroConfig, output, internals) {
|
|
|
44
50
|
return false;
|
|
45
51
|
}
|
|
46
52
|
async function generatePages(result, opts, internals, facadeIdToPageDataMap) {
|
|
47
|
-
|
|
53
|
+
const timer = performance.now();
|
|
48
54
|
info(opts.logging, null, `
|
|
49
|
-
${
|
|
50
|
-
|
|
51
|
-
const ssr = !!((_a = opts.astroConfig._ctx.adapter) == null ? void 0 : _a.serverEntrypoint);
|
|
55
|
+
${bgGreen(black(" generating static routes "))}`);
|
|
56
|
+
const ssr = isBuildingToSSR(opts.astroConfig);
|
|
52
57
|
const serverEntry = opts.buildConfig.serverEntry;
|
|
53
|
-
const outFolder = ssr ? opts.buildConfig.server : opts.astroConfig.
|
|
58
|
+
const outFolder = ssr ? opts.buildConfig.server : opts.astroConfig.outDir;
|
|
54
59
|
const ssrEntryURL = new URL("./" + serverEntry + `?time=${Date.now()}`, outFolder);
|
|
55
60
|
const ssrEntry = await import(ssrEntryURL.toString());
|
|
56
61
|
for (const pageData of eachPageData(internals)) {
|
|
57
62
|
await generatePage(opts, internals, pageData, ssrEntry);
|
|
58
63
|
}
|
|
64
|
+
info(opts.logging, null, dim(`Completed in ${getTimeStat(timer, performance.now())}.
|
|
65
|
+
`));
|
|
59
66
|
}
|
|
60
67
|
async function generatePage(opts, internals, pageData, ssrEntry) {
|
|
61
68
|
let timeStart = performance.now();
|
|
@@ -75,24 +82,17 @@ async function generatePage(opts, internals, pageData, ssrEntry) {
|
|
|
75
82
|
mod: pageModule,
|
|
76
83
|
renderers
|
|
77
84
|
};
|
|
78
|
-
const icon = pageData.route.type === "page" ?
|
|
85
|
+
const icon = pageData.route.type === "page" ? green("\u25B6") : magenta("\u03BB");
|
|
79
86
|
info(opts.logging, null, `${icon} ${pageData.route.component}`);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
renderPromises.push(generatePath(path, opts, generationOptions));
|
|
84
|
-
}
|
|
85
|
-
await Promise.all(renderPromises);
|
|
87
|
+
for (let i = 0; i < pageData.paths.length; i++) {
|
|
88
|
+
const path = pageData.paths[i];
|
|
89
|
+
await generatePath(path, opts, generationOptions);
|
|
86
90
|
const timeEnd = performance.now();
|
|
87
91
|
const timeChange = getTimeStat(timeStart, timeEnd);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
shouldLogTimeChange = false;
|
|
93
|
-
}
|
|
94
|
-
timeStart = performance.now();
|
|
95
|
-
renderPromises.length = 0;
|
|
92
|
+
const timeIncrease = `(+${timeChange})`;
|
|
93
|
+
const filePath = getOutputFilename(opts.astroConfig, path);
|
|
94
|
+
const lineIcon = i === pageData.paths.length - 1 ? "\u2514\u2500" : "\u251C\u2500";
|
|
95
|
+
info(opts.logging, null, ` ${cyan(lineIcon)} ${dim(filePath)} ${dim(timeIncrease)}`);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
function addPageName(pathname, opts) {
|
|
@@ -105,7 +105,7 @@ async function generatePath(pathname, opts, gopts) {
|
|
|
105
105
|
addPageName(pathname, opts);
|
|
106
106
|
}
|
|
107
107
|
debug("build", `Generating: ${pathname}`);
|
|
108
|
-
const site = astroConfig.
|
|
108
|
+
const site = astroConfig.site;
|
|
109
109
|
const links = createLinkStylesheetElementSet(linkIds.reverse(), site);
|
|
110
110
|
const scripts = createModuleScriptElementWithSrcSet(hoistedId ? [hoistedId] : [], site);
|
|
111
111
|
for (const script of astroConfig._ctx.scripts) {
|
|
@@ -116,57 +116,53 @@ async function generatePath(pathname, opts, gopts) {
|
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
throw new Error(`Cannot find the built path for ${specifier}`);
|
|
119
|
+
const url = new URL(origin + pathname);
|
|
120
|
+
const options = {
|
|
121
|
+
legacyBuild: false,
|
|
122
|
+
links,
|
|
123
|
+
logging,
|
|
124
|
+
markdownRender: [astroRemark, astroConfig.markdown],
|
|
125
|
+
mod,
|
|
126
|
+
origin,
|
|
127
|
+
pathname,
|
|
128
|
+
scripts,
|
|
129
|
+
renderers,
|
|
130
|
+
async resolve(specifier) {
|
|
131
|
+
const hashedFilePath = internals.entrySpecifierToBundleMap.get(specifier);
|
|
132
|
+
if (typeof hashedFilePath !== "string") {
|
|
133
|
+
if (specifier === BEFORE_HYDRATION_SCRIPT_ID) {
|
|
134
|
+
return "data:text/javascript;charset=utf-8,//[no before-hydration script]";
|
|
137
135
|
}
|
|
138
|
-
|
|
139
|
-
const fullyRelativePath = relPath[0] === "." ? relPath : "./" + relPath;
|
|
140
|
-
return fullyRelativePath;
|
|
141
|
-
},
|
|
142
|
-
method: "GET",
|
|
143
|
-
headers: new Headers(),
|
|
144
|
-
route: pageData.route,
|
|
145
|
-
routeCache,
|
|
146
|
-
site: astroConfig.buildOptions.site,
|
|
147
|
-
ssr: opts.astroConfig.buildOptions.experimentalSsr
|
|
148
|
-
};
|
|
149
|
-
let body;
|
|
150
|
-
if (pageData.route.type === "endpoint") {
|
|
151
|
-
const result = await callEndpoint(mod, options);
|
|
152
|
-
if (result.type === "response") {
|
|
153
|
-
throw new Error(`Returning a Response from an endpoint is not supported in SSG mode.`);
|
|
154
|
-
}
|
|
155
|
-
body = result.body;
|
|
156
|
-
} else {
|
|
157
|
-
const result = await render(options);
|
|
158
|
-
if (result.type !== "html") {
|
|
159
|
-
return;
|
|
136
|
+
throw new Error(`Cannot find the built path for ${specifier}`);
|
|
160
137
|
}
|
|
161
|
-
|
|
138
|
+
const relPath = npath.posix.relative(pathname, "/" + hashedFilePath);
|
|
139
|
+
const fullyRelativePath = relPath[0] === "." ? relPath : "./" + relPath;
|
|
140
|
+
return fullyRelativePath;
|
|
141
|
+
},
|
|
142
|
+
request: createRequest({ url, headers: new Headers(), logging }),
|
|
143
|
+
route: pageData.route,
|
|
144
|
+
routeCache,
|
|
145
|
+
site: astroConfig.site ? new URL(astroConfig.base, astroConfig.site).toString() : astroConfig.site,
|
|
146
|
+
ssr: isBuildingToSSR(opts.astroConfig)
|
|
147
|
+
};
|
|
148
|
+
let body;
|
|
149
|
+
if (pageData.route.type === "endpoint") {
|
|
150
|
+
const result = await callEndpoint(mod, options);
|
|
151
|
+
if (result.type === "response") {
|
|
152
|
+
throw new Error(`Returning a Response from an endpoint is not supported in SSG mode.`);
|
|
153
|
+
}
|
|
154
|
+
body = result.body;
|
|
155
|
+
} else {
|
|
156
|
+
const result = await render(options);
|
|
157
|
+
if (result.type !== "html") {
|
|
158
|
+
return;
|
|
162
159
|
}
|
|
163
|
-
|
|
164
|
-
const outFile = getOutFile(astroConfig, outFolder, pathname, pageData.route.type);
|
|
165
|
-
await fs.promises.mkdir(outFolder, { recursive: true });
|
|
166
|
-
await fs.promises.writeFile(outFile, body, "utf-8");
|
|
167
|
-
} catch (err) {
|
|
168
|
-
error(opts.logging, "build", `Error rendering:`, err);
|
|
160
|
+
body = result.html;
|
|
169
161
|
}
|
|
162
|
+
const outFolder = getOutFolder(astroConfig, pathname, pageData.route.type);
|
|
163
|
+
const outFile = getOutFile(astroConfig, outFolder, pathname, pageData.route.type);
|
|
164
|
+
await fs.promises.mkdir(outFolder, { recursive: true });
|
|
165
|
+
await fs.promises.writeFile(outFile, body, "utf-8");
|
|
170
166
|
}
|
|
171
167
|
export {
|
|
172
168
|
chunkIsPage,
|