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
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { bold, cyan, dim, red, yellow, reset } from "kleur/colors";
|
|
2
|
+
import stringWidth from "string-width";
|
|
3
|
+
import debugPackage from "debug";
|
|
4
|
+
import { format as utilFormat } from "util";
|
|
5
|
+
import * as readline from "readline";
|
|
6
|
+
import { Writable } from "stream";
|
|
7
|
+
import { info, warn, error, dateTimeFormat } from "./core.js";
|
|
8
|
+
let lastMessage;
|
|
9
|
+
let lastMessageCount = 1;
|
|
10
|
+
const nodeLogDestination = new Writable({
|
|
11
|
+
objectMode: true,
|
|
12
|
+
write(event, _, callback) {
|
|
13
|
+
let dest = process.stderr;
|
|
14
|
+
if (levels[event.level] < levels["error"]) {
|
|
15
|
+
dest = process.stdout;
|
|
16
|
+
}
|
|
17
|
+
function getPrefix() {
|
|
18
|
+
let prefix = "";
|
|
19
|
+
let type = event.type;
|
|
20
|
+
if (type) {
|
|
21
|
+
prefix += dim(dateTimeFormat.format(new Date()) + " ");
|
|
22
|
+
if (event.level === "info") {
|
|
23
|
+
type = bold(cyan(`[${type}]`));
|
|
24
|
+
} else if (event.level === "warn") {
|
|
25
|
+
type = bold(yellow(`[${type}]`));
|
|
26
|
+
} else if (event.level === "error") {
|
|
27
|
+
type = bold(red(`[${type}]`));
|
|
28
|
+
}
|
|
29
|
+
prefix += `${type} `;
|
|
30
|
+
}
|
|
31
|
+
return reset(prefix);
|
|
32
|
+
}
|
|
33
|
+
let message = utilFormat(...event.args);
|
|
34
|
+
if (message === lastMessage) {
|
|
35
|
+
lastMessageCount++;
|
|
36
|
+
if (levels[event.level] < levels["error"]) {
|
|
37
|
+
let lines = 1;
|
|
38
|
+
let len = stringWidth(`${getPrefix()}${message}`);
|
|
39
|
+
let cols = dest.columns;
|
|
40
|
+
if (len > cols) {
|
|
41
|
+
lines = Math.ceil(len / cols);
|
|
42
|
+
}
|
|
43
|
+
for (let i = 0; i < lines; i++) {
|
|
44
|
+
readline.clearLine(dest, 0);
|
|
45
|
+
readline.cursorTo(dest, 0);
|
|
46
|
+
readline.moveCursor(dest, 0, -1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
message = `${message} ${yellow(`(x${lastMessageCount})`)}`;
|
|
50
|
+
} else {
|
|
51
|
+
lastMessage = message;
|
|
52
|
+
lastMessageCount = 1;
|
|
53
|
+
}
|
|
54
|
+
dest.write(getPrefix());
|
|
55
|
+
dest.write(message);
|
|
56
|
+
dest.write("\n");
|
|
57
|
+
callback();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const nodeLogOptions = {
|
|
61
|
+
dest: nodeLogDestination,
|
|
62
|
+
level: "info"
|
|
63
|
+
};
|
|
64
|
+
const levels = {
|
|
65
|
+
debug: 20,
|
|
66
|
+
info: 30,
|
|
67
|
+
warn: 40,
|
|
68
|
+
error: 50,
|
|
69
|
+
silent: 90
|
|
70
|
+
};
|
|
71
|
+
const debuggers = {};
|
|
72
|
+
function debug(type, ...messages) {
|
|
73
|
+
const namespace = `astro:${type}`;
|
|
74
|
+
debuggers[namespace] = debuggers[namespace] || debugPackage(namespace);
|
|
75
|
+
return debuggers[namespace](...messages);
|
|
76
|
+
}
|
|
77
|
+
globalThis._astroGlobalDebug = debug;
|
|
78
|
+
const logger = {
|
|
79
|
+
info: info.bind(null, nodeLogOptions),
|
|
80
|
+
warn: warn.bind(null, nodeLogOptions),
|
|
81
|
+
error: error.bind(null, nodeLogOptions)
|
|
82
|
+
};
|
|
83
|
+
function enableVerboseLogging() {
|
|
84
|
+
debug("cli", '--verbose flag enabled! Enabling: DEBUG="*,-babel"');
|
|
85
|
+
debug("cli", 'Tip: Set the DEBUG env variable directly for more control. Example: "DEBUG=astro:*,vite:* astro build".');
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
debug,
|
|
89
|
+
enableVerboseLogging,
|
|
90
|
+
levels,
|
|
91
|
+
logger,
|
|
92
|
+
nodeLogDestination,
|
|
93
|
+
nodeLogOptions
|
|
94
|
+
};
|
package/dist/core/messages.js
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
bold,
|
|
3
|
+
dim,
|
|
4
|
+
red,
|
|
5
|
+
green,
|
|
6
|
+
underline,
|
|
7
|
+
yellow,
|
|
8
|
+
bgYellow,
|
|
9
|
+
cyan,
|
|
10
|
+
bgGreen,
|
|
11
|
+
black,
|
|
12
|
+
bgRed,
|
|
13
|
+
bgWhite
|
|
14
|
+
} from "kleur/colors";
|
|
4
15
|
import os from "os";
|
|
16
|
+
import { collectErrorMetadata, cleanErrorStack } from "./errors.js";
|
|
17
|
+
import { emoji, getLocalAddress, padMultilineString } from "./util.js";
|
|
5
18
|
const PREFIX_PADDING = 6;
|
|
6
|
-
function req({
|
|
19
|
+
function req({
|
|
20
|
+
url,
|
|
21
|
+
statusCode,
|
|
22
|
+
reqTime
|
|
23
|
+
}) {
|
|
7
24
|
let color = dim;
|
|
8
25
|
if (statusCode >= 500)
|
|
9
26
|
color = red;
|
|
@@ -13,13 +30,13 @@ function req({ url, statusCode, reqTime }) {
|
|
|
13
30
|
color = dim;
|
|
14
31
|
else if (statusCode >= 200)
|
|
15
32
|
color = green;
|
|
16
|
-
return `${bold(color(
|
|
33
|
+
return `${bold(color(`${statusCode}`.padStart(PREFIX_PADDING)))} ${url.padStart(40)} ${reqTime ? dim(Math.round(reqTime) + "ms") : ""}`.trim();
|
|
17
34
|
}
|
|
18
35
|
function reload({ file }) {
|
|
19
|
-
return `${green(
|
|
36
|
+
return `${green("reload".padStart(PREFIX_PADDING))} ${file}`;
|
|
20
37
|
}
|
|
21
38
|
function hmr({ file }) {
|
|
22
|
-
return `${green(
|
|
39
|
+
return `${green("update".padStart(PREFIX_PADDING))} ${file}`;
|
|
23
40
|
}
|
|
24
41
|
function devStart({
|
|
25
42
|
startupTime,
|
|
@@ -28,19 +45,22 @@ function devStart({
|
|
|
28
45
|
https,
|
|
29
46
|
site
|
|
30
47
|
}) {
|
|
31
|
-
const version = "0.
|
|
48
|
+
const version = "0.26.1";
|
|
32
49
|
const rootPath = site ? site.pathname : "/";
|
|
33
50
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
34
51
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
35
52
|
const { address: networkAddress, port } = devServerAddressInfo;
|
|
36
|
-
const localAddress = getLocalAddress(networkAddress, config);
|
|
37
|
-
const networkLogging = getNetworkLogging(config);
|
|
53
|
+
const localAddress = getLocalAddress(networkAddress, config.server.host);
|
|
54
|
+
const networkLogging = getNetworkLogging(config.server.host);
|
|
38
55
|
const toDisplayUrl = (hostname) => `${https ? "https" : "http"}://${hostname}:${port}${rootPath}`;
|
|
39
56
|
let addresses = [];
|
|
40
57
|
if (networkLogging === "none") {
|
|
41
58
|
addresses = [`${localPrefix}${bold(cyan(toDisplayUrl(localAddress)))}`];
|
|
42
59
|
} else if (networkLogging === "host-to-expose") {
|
|
43
|
-
addresses = [
|
|
60
|
+
addresses = [
|
|
61
|
+
`${localPrefix}${bold(cyan(toDisplayUrl(localAddress)))}`,
|
|
62
|
+
`${networkPrefix}${dim("use --host to expose")}`
|
|
63
|
+
];
|
|
44
64
|
} else {
|
|
45
65
|
addresses = Object.values(os.networkInterfaces()).flatMap((networkInterface) => networkInterface ?? []).filter((networkInterface) => (networkInterface == null ? void 0 : networkInterface.address) && (networkInterface == null ? void 0 : networkInterface.family) === "IPv4").map(({ address }) => {
|
|
46
66
|
if (address.includes("127.0.0.1")) {
|
|
@@ -51,7 +71,12 @@ function devStart({
|
|
|
51
71
|
}
|
|
52
72
|
}).sort((msg) => msg.startsWith(localPrefix) ? -1 : 1);
|
|
53
73
|
}
|
|
54
|
-
const messages = [
|
|
74
|
+
const messages = [
|
|
75
|
+
`${emoji("\u{1F680} ", "")}${bgGreen(black(` astro `))} ${green(`v${version}`)} ${dim(`started in ${Math.round(startupTime)}ms`)}`,
|
|
76
|
+
"",
|
|
77
|
+
...addresses,
|
|
78
|
+
""
|
|
79
|
+
];
|
|
55
80
|
return messages.map((msg) => ` ${msg}`).join("\n");
|
|
56
81
|
}
|
|
57
82
|
function prerelease({ currentVersion }) {
|
|
@@ -66,35 +91,59 @@ function success(message, tip) {
|
|
|
66
91
|
const headline = green(message);
|
|
67
92
|
const footer = tip ? `
|
|
68
93
|
\u25B6 ${tip}` : void 0;
|
|
69
|
-
return ["", badge
|
|
94
|
+
return ["", `${badge} ${headline}`, footer].filter((v) => v !== void 0).map((msg) => ` ${msg}`).join("\n");
|
|
70
95
|
}
|
|
71
96
|
function failure(message, tip) {
|
|
72
97
|
const badge = bgRed(black(` error `));
|
|
73
98
|
const headline = red(message);
|
|
74
99
|
const footer = tip ? `
|
|
75
100
|
\u25B6 ${tip}` : void 0;
|
|
76
|
-
return ["", badge
|
|
101
|
+
return ["", `${badge} ${headline}`, footer].filter((v) => v !== void 0).map((msg) => ` ${msg}`).join("\n");
|
|
77
102
|
}
|
|
78
103
|
function cancelled(message, tip) {
|
|
79
104
|
const badge = bgYellow(black(` cancelled `));
|
|
80
105
|
const headline = yellow(message);
|
|
81
106
|
const footer = tip ? `
|
|
82
107
|
\u25B6 ${tip}` : void 0;
|
|
83
|
-
return ["", badge
|
|
108
|
+
return ["", `${badge} ${headline}`, footer].filter((v) => v !== void 0).map((msg) => ` ${msg}`).join("\n");
|
|
84
109
|
}
|
|
85
110
|
function portInUse({ port }) {
|
|
86
111
|
return `Port ${port} in use. Trying a new one\u2026`;
|
|
87
112
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
113
|
+
const LOCAL_IP_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1"]);
|
|
114
|
+
function getNetworkLogging(host) {
|
|
115
|
+
if (host === false) {
|
|
116
|
+
return "host-to-expose";
|
|
117
|
+
} else if (typeof host === "string" && LOCAL_IP_HOSTS.has(host)) {
|
|
118
|
+
return "none";
|
|
119
|
+
} else {
|
|
120
|
+
return "visible";
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function formatConfigErrorMessage(err) {
|
|
124
|
+
const errorList = err.issues.map((issue) => ` ! ${bold(issue.path.join("."))} ${red(issue.message + ".")}`);
|
|
125
|
+
return `${red("[config]")} Astro found issue(s) with your configuration:
|
|
126
|
+
${errorList.join("\n")}`;
|
|
127
|
+
}
|
|
128
|
+
function formatErrorMessage(_err, args = []) {
|
|
129
|
+
const err = collectErrorMetadata(_err);
|
|
130
|
+
args.push(`${bgRed(black(` error `))}${red(bold(padMultilineString(err.message)))}`);
|
|
131
|
+
if (err.id) {
|
|
132
|
+
args.push(` ${bold("File:")}`);
|
|
133
|
+
args.push(red(` ${err.id}`));
|
|
134
|
+
}
|
|
135
|
+
if (err.frame) {
|
|
136
|
+
args.push(` ${bold("Code:")}`);
|
|
137
|
+
args.push(red(padMultilineString(err.frame, 4)));
|
|
138
|
+
}
|
|
139
|
+
if (args.length === 1 && err.stack) {
|
|
140
|
+
args.push(dim(cleanErrorStack(err.stack)));
|
|
141
|
+
} else if (err.stack) {
|
|
142
|
+
args.push(` ${bold("Stacktrace:")}`);
|
|
143
|
+
args.push(dim(cleanErrorStack(err.stack)));
|
|
144
|
+
args.push(``);
|
|
145
|
+
}
|
|
146
|
+
return args.join("\n");
|
|
98
147
|
}
|
|
99
148
|
function printHelp({
|
|
100
149
|
commandName,
|
|
@@ -112,7 +161,7 @@ function printHelp({
|
|
|
112
161
|
});
|
|
113
162
|
let raw = "";
|
|
114
163
|
for (const row of rows) {
|
|
115
|
-
raw += `${opts.prefix}${bold(
|
|
164
|
+
raw += `${opts.prefix}${bold(`${row[0]}`.padStart(opts.padding - opts.prefix.length))}`;
|
|
116
165
|
if (split)
|
|
117
166
|
raw += "\n ";
|
|
118
167
|
raw += dim(row[1]) + "\n";
|
|
@@ -121,7 +170,7 @@ function printHelp({
|
|
|
121
170
|
};
|
|
122
171
|
let message = [];
|
|
123
172
|
if (headline) {
|
|
124
|
-
message.push(linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green(`v${"0.
|
|
173
|
+
message.push(linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green(`v${"0.26.1"}`)} ${headline}`);
|
|
125
174
|
}
|
|
126
175
|
if (usage) {
|
|
127
176
|
message.push(linebreak(), ` ${green(commandName)} ${bold(usage)}`);
|
|
@@ -137,8 +186,10 @@ function printHelp({
|
|
|
137
186
|
export {
|
|
138
187
|
cancelled,
|
|
139
188
|
devStart,
|
|
140
|
-
err,
|
|
141
189
|
failure,
|
|
190
|
+
formatConfigErrorMessage,
|
|
191
|
+
formatErrorMessage,
|
|
192
|
+
getNetworkLogging,
|
|
142
193
|
hmr,
|
|
143
194
|
portInUse,
|
|
144
195
|
prerelease,
|
|
@@ -3,16 +3,16 @@ import sirv from "sirv";
|
|
|
3
3
|
import { performance } from "perf_hooks";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
5
|
import * as msg from "../messages.js";
|
|
6
|
-
import { error, info } from "../logger.js";
|
|
6
|
+
import { error, info } from "../logger/core.js";
|
|
7
7
|
import { subpathNotUsedTemplate, notFoundTemplate } from "../../template/4xx.js";
|
|
8
8
|
import { getResolvedHostForHttpServer } from "./util.js";
|
|
9
9
|
const HAS_FILE_EXTENSION_REGEXP = /^.*\.[^\\]+$/;
|
|
10
10
|
async function preview(config, { logging }) {
|
|
11
11
|
const startServerTime = performance.now();
|
|
12
12
|
const defaultOrigin = "http://localhost";
|
|
13
|
-
const trailingSlash = config.
|
|
14
|
-
let baseURL = new URL(config.
|
|
15
|
-
const staticFileServer = sirv(fileURLToPath(config.
|
|
13
|
+
const trailingSlash = config.trailingSlash;
|
|
14
|
+
let baseURL = new URL(config.base, new URL(config.site || "/", defaultOrigin));
|
|
15
|
+
const staticFileServer = sirv(fileURLToPath(config.outDir), {
|
|
16
16
|
dev: true,
|
|
17
17
|
etag: true,
|
|
18
18
|
maxAge: 0
|
|
@@ -34,10 +34,10 @@ async function preview(config, { logging }) {
|
|
|
34
34
|
}
|
|
35
35
|
switch (true) {
|
|
36
36
|
case (hasTrailingSlash && trailingSlash == "never" && !isRoot):
|
|
37
|
-
sendError('Not Found (
|
|
37
|
+
sendError('Not Found (trailingSlash is set to "never")');
|
|
38
38
|
return;
|
|
39
39
|
case (!hasTrailingSlash && trailingSlash == "always" && !isRoot && !HAS_FILE_EXTENSION_REGEXP.test(pathname)):
|
|
40
|
-
sendError('Not Found (
|
|
40
|
+
sendError('Not Found (trailingSlash is set to "always")');
|
|
41
41
|
return;
|
|
42
42
|
default: {
|
|
43
43
|
req.url = "/" + ((_a = req.url) == null ? void 0 : _a.replace(baseURL.pathname, ""));
|
|
@@ -46,8 +46,8 @@ async function preview(config, { logging }) {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
|
-
let { port } = config.
|
|
50
|
-
const host = getResolvedHostForHttpServer(config);
|
|
49
|
+
let { port } = config.server;
|
|
50
|
+
const host = getResolvedHostForHttpServer(config.server.host);
|
|
51
51
|
let httpServer;
|
|
52
52
|
function startServer(timerStart) {
|
|
53
53
|
let showedPortTakenMsg = false;
|
|
@@ -57,7 +57,13 @@ async function preview(config, { logging }) {
|
|
|
57
57
|
httpServer = server.listen(port, host, async () => {
|
|
58
58
|
if (!showedListenMsg) {
|
|
59
59
|
const devServerAddressInfo = server.address();
|
|
60
|
-
info(logging, null, msg.devStart({
|
|
60
|
+
info(logging, null, msg.devStart({
|
|
61
|
+
startupTime: performance.now() - timerStart,
|
|
62
|
+
config,
|
|
63
|
+
devServerAddressInfo,
|
|
64
|
+
https: false,
|
|
65
|
+
site: baseURL
|
|
66
|
+
}));
|
|
61
67
|
}
|
|
62
68
|
showedListenMsg = true;
|
|
63
69
|
resolve();
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
function getResolvedHostForHttpServer(
|
|
2
|
-
|
|
3
|
-
if (host === false && hostname === "localhost") {
|
|
1
|
+
function getResolvedHostForHttpServer(host) {
|
|
2
|
+
if (host === false) {
|
|
4
3
|
return "127.0.0.1";
|
|
5
4
|
} else if (host === true) {
|
|
6
5
|
return void 0;
|
|
7
|
-
} else if (typeof host === "string") {
|
|
8
|
-
return host;
|
|
9
6
|
} else {
|
|
10
|
-
return
|
|
7
|
+
return host;
|
|
11
8
|
}
|
|
12
9
|
}
|
|
13
10
|
export {
|
package/dist/core/render/core.js
CHANGED
|
@@ -15,7 +15,7 @@ var __spreadValues = (a, b) => {
|
|
|
15
15
|
return a;
|
|
16
16
|
};
|
|
17
17
|
import { renderHead, renderPage } from "../../runtime/server/index.js";
|
|
18
|
-
import { getParams } from "../routing/
|
|
18
|
+
import { getParams } from "../routing/params.js";
|
|
19
19
|
import { createResult } from "./result.js";
|
|
20
20
|
import { findPathItemByKey, callGetStaticPaths } from "./route-cache.js";
|
|
21
21
|
var GetParamsAndPropsError = /* @__PURE__ */ ((GetParamsAndPropsError2) => {
|
|
@@ -49,7 +49,23 @@ async function getParamsAndProps(opts) {
|
|
|
49
49
|
return [params, pageProps];
|
|
50
50
|
}
|
|
51
51
|
async function render(opts) {
|
|
52
|
-
const {
|
|
52
|
+
const {
|
|
53
|
+
legacyBuild,
|
|
54
|
+
links,
|
|
55
|
+
logging,
|
|
56
|
+
origin,
|
|
57
|
+
markdownRender,
|
|
58
|
+
mod,
|
|
59
|
+
pathname,
|
|
60
|
+
scripts,
|
|
61
|
+
renderers,
|
|
62
|
+
request,
|
|
63
|
+
resolve,
|
|
64
|
+
route,
|
|
65
|
+
routeCache,
|
|
66
|
+
site,
|
|
67
|
+
ssr
|
|
68
|
+
} = opts;
|
|
53
69
|
const paramsAndPropsRes = await getParamsAndProps({
|
|
54
70
|
logging,
|
|
55
71
|
mod,
|
|
@@ -77,11 +93,10 @@ async function render(opts) {
|
|
|
77
93
|
pathname,
|
|
78
94
|
resolve,
|
|
79
95
|
renderers,
|
|
96
|
+
request,
|
|
80
97
|
site,
|
|
81
98
|
scripts,
|
|
82
|
-
ssr
|
|
83
|
-
method,
|
|
84
|
-
headers
|
|
99
|
+
ssr
|
|
85
100
|
});
|
|
86
101
|
let page = await renderPage(result, Component, pageProps, null);
|
|
87
102
|
if (page.type === "response") {
|
|
@@ -92,7 +107,7 @@ async function render(opts) {
|
|
|
92
107
|
html = await renderHead(result) + html;
|
|
93
108
|
}
|
|
94
109
|
html = html.replace("<!--astro:head:injected-->", "");
|
|
95
|
-
if (
|
|
110
|
+
if (!/<!doctype html/i.test(html)) {
|
|
96
111
|
html = "<!DOCTYPE html>\n" + html;
|
|
97
112
|
}
|
|
98
113
|
return {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { unwrapId, viteID } from "../../util.js";
|
|
3
|
-
|
|
4
|
-
const cssRe = new RegExp(`\\.(${Array.from(STYLE_EXTENSIONS).map((s) => s.slice(1)).join("|")})($|\\?)`);
|
|
5
|
-
const isCSSRequest = (request) => cssRe.test(request);
|
|
3
|
+
import { STYLE_EXTENSIONS } from "../util.js";
|
|
6
4
|
function getStylesForURL(filePath, viteServer) {
|
|
7
5
|
const importedCssUrls = /* @__PURE__ */ new Set();
|
|
8
6
|
function crawlCSS(_id, isFile, scanned = /* @__PURE__ */ new Set()) {
|
|
@@ -10,6 +8,9 @@ function getStylesForURL(filePath, viteServer) {
|
|
|
10
8
|
const importedModules = /* @__PURE__ */ new Set();
|
|
11
9
|
const moduleEntriesForId = isFile ? viteServer.moduleGraph.getModulesByFile(id) ?? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([viteServer.moduleGraph.getModuleById(id)]);
|
|
12
10
|
for (const entry of moduleEntriesForId) {
|
|
11
|
+
if (!entry) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
13
14
|
if (id === entry.id) {
|
|
14
15
|
scanned.add(id);
|
|
15
16
|
for (const importedModule of entry.importedModules) {
|
|
@@ -32,7 +33,5 @@ function getStylesForURL(filePath, viteServer) {
|
|
|
32
33
|
return importedCssUrls;
|
|
33
34
|
}
|
|
34
35
|
export {
|
|
35
|
-
|
|
36
|
-
getStylesForURL,
|
|
37
|
-
isCSSRequest
|
|
36
|
+
getStylesForURL
|
|
38
37
|
};
|
|
@@ -17,14 +17,15 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import astroRemark from "@astrojs/markdown-remark";
|
|
20
21
|
import { fileURLToPath } from "url";
|
|
21
22
|
import { render as coreRender } from "../core.js";
|
|
22
23
|
import { prependForwardSlash } from "../../../core/path.js";
|
|
23
24
|
import { createModuleScriptElementWithSrcSet } from "../ssr-element.js";
|
|
24
25
|
import { getStylesForURL } from "./css.js";
|
|
25
|
-
import { errorHandler } from "./error.js";
|
|
26
26
|
import { getHmrScript } from "./hmr.js";
|
|
27
27
|
import { injectTags } from "./html.js";
|
|
28
|
+
import { isBuildingToSSR } from "../../util.js";
|
|
28
29
|
const svelteStylesRE = /svelte\?svelte&type=style/;
|
|
29
30
|
async function loadRenderer(viteServer, renderer) {
|
|
30
31
|
var _a;
|
|
@@ -35,22 +36,40 @@ async function loadRenderer(viteServer, renderer) {
|
|
|
35
36
|
async function loadRenderers(viteServer, astroConfig) {
|
|
36
37
|
return Promise.all(astroConfig._ctx.renderers.map((r) => loadRenderer(viteServer, r)));
|
|
37
38
|
}
|
|
38
|
-
async function preload({
|
|
39
|
+
async function preload({
|
|
40
|
+
astroConfig,
|
|
41
|
+
filePath,
|
|
42
|
+
viteServer
|
|
43
|
+
}) {
|
|
39
44
|
const renderers = await loadRenderers(viteServer, astroConfig);
|
|
40
45
|
const mod = await viteServer.ssrLoadModule(fileURLToPath(filePath));
|
|
41
46
|
return [renderers, mod];
|
|
42
47
|
}
|
|
43
48
|
async function render(renderers, mod, ssrOpts) {
|
|
44
|
-
const {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
const {
|
|
50
|
+
astroConfig,
|
|
51
|
+
filePath,
|
|
52
|
+
logging,
|
|
53
|
+
mode,
|
|
54
|
+
origin,
|
|
55
|
+
pathname,
|
|
56
|
+
request,
|
|
57
|
+
route,
|
|
58
|
+
routeCache,
|
|
59
|
+
viteServer
|
|
60
|
+
} = ssrOpts;
|
|
61
|
+
const isLegacyBuild = false;
|
|
62
|
+
const scripts = createModuleScriptElementWithSrcSet(!isLegacyBuild && mod.hasOwnProperty("$$metadata") ? Array.from(mod.$$metadata.hoistedScriptPaths()) : []);
|
|
63
|
+
if (mod.hasOwnProperty("$$metadata") && mode === "development" && !isLegacyBuild) {
|
|
48
64
|
scripts.add({
|
|
49
65
|
props: { type: "module", src: "/@vite/client" },
|
|
50
66
|
children: ""
|
|
51
67
|
});
|
|
52
68
|
scripts.add({
|
|
53
|
-
props: {
|
|
69
|
+
props: {
|
|
70
|
+
type: "module",
|
|
71
|
+
src: new URL("../../../runtime/client/hmr.js", import.meta.url).pathname
|
|
72
|
+
},
|
|
54
73
|
children: ""
|
|
55
74
|
});
|
|
56
75
|
}
|
|
@@ -63,7 +82,7 @@ async function render(renderers, mod, ssrOpts) {
|
|
|
63
82
|
}
|
|
64
83
|
}
|
|
65
84
|
let links = /* @__PURE__ */ new Set();
|
|
66
|
-
if (!
|
|
85
|
+
if (!isLegacyBuild) {
|
|
67
86
|
[...getStylesForURL(filePath, viteServer)].forEach((href) => {
|
|
68
87
|
if (mode === "development" && svelteStylesRE.test(href)) {
|
|
69
88
|
scripts.add({
|
|
@@ -83,41 +102,36 @@ async function render(renderers, mod, ssrOpts) {
|
|
|
83
102
|
});
|
|
84
103
|
}
|
|
85
104
|
let content = await coreRender({
|
|
86
|
-
legacyBuild:
|
|
105
|
+
legacyBuild: isLegacyBuild,
|
|
87
106
|
links,
|
|
88
107
|
logging,
|
|
89
|
-
markdownRender: astroConfig.
|
|
108
|
+
markdownRender: [astroRemark, astroConfig.markdown],
|
|
90
109
|
mod,
|
|
91
110
|
origin,
|
|
92
111
|
pathname,
|
|
93
112
|
scripts,
|
|
94
113
|
async resolve(s) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return "/@id" + prependForwardSlash(resolvedUrl);
|
|
102
|
-
}
|
|
103
|
-
return "/@fs" + prependForwardSlash(resolvedPath);
|
|
104
|
-
} else {
|
|
105
|
-
return s;
|
|
114
|
+
const [resolvedUrl, resolvedPath] = await viteServer.moduleGraph.resolveUrl(s);
|
|
115
|
+
if (resolvedPath.includes("node_modules/.vite")) {
|
|
116
|
+
return resolvedPath.replace(/.*?node_modules\/\.vite/, "/node_modules/.vite");
|
|
117
|
+
}
|
|
118
|
+
if (!resolvedUrl.startsWith(".") && !resolvedUrl.startsWith("/")) {
|
|
119
|
+
return "/@id" + prependForwardSlash(resolvedUrl);
|
|
106
120
|
}
|
|
121
|
+
return "/@fs" + prependForwardSlash(resolvedPath);
|
|
107
122
|
},
|
|
108
123
|
renderers,
|
|
124
|
+
request,
|
|
109
125
|
route,
|
|
110
126
|
routeCache,
|
|
111
|
-
site: astroConfig.
|
|
112
|
-
ssr: astroConfig
|
|
113
|
-
method,
|
|
114
|
-
headers
|
|
127
|
+
site: astroConfig.site ? new URL(astroConfig.base, astroConfig.site).toString() : void 0,
|
|
128
|
+
ssr: isBuildingToSSR(astroConfig)
|
|
115
129
|
});
|
|
116
130
|
if ((route == null ? void 0 : route.type) === "endpoint" || content.type === "response") {
|
|
117
131
|
return content;
|
|
118
132
|
}
|
|
119
133
|
const tags = [];
|
|
120
|
-
if (mode === "development" &&
|
|
134
|
+
if (mode === "development" && isLegacyBuild) {
|
|
121
135
|
tags.push({
|
|
122
136
|
tag: "script",
|
|
123
137
|
attrs: { type: "module" },
|
|
@@ -125,7 +139,7 @@ async function render(renderers, mod, ssrOpts) {
|
|
|
125
139
|
injectTo: "head"
|
|
126
140
|
});
|
|
127
141
|
}
|
|
128
|
-
if (
|
|
142
|
+
if (isLegacyBuild) {
|
|
129
143
|
[...getStylesForURL(filePath, viteServer)].forEach((href) => {
|
|
130
144
|
if (mode === "development" && svelteStylesRE.test(href)) {
|
|
131
145
|
tags.push({
|
|
@@ -147,10 +161,6 @@ async function render(renderers, mod, ssrOpts) {
|
|
|
147
161
|
});
|
|
148
162
|
}
|
|
149
163
|
let html = injectTags(content.html, tags);
|
|
150
|
-
if (mode === "development" && astroConfig.buildOptions.legacyBuild) {
|
|
151
|
-
const relativeURL = filePath.href.replace(astroConfig.projectRoot.href, "/");
|
|
152
|
-
html = await viteServer.transformIndexHtml(relativeURL, html, pathname);
|
|
153
|
-
}
|
|
154
164
|
if (!/<!doctype html/i.test(html)) {
|
|
155
165
|
html = "<!DOCTYPE html>\n" + content;
|
|
156
166
|
}
|
|
@@ -160,13 +170,8 @@ async function render(renderers, mod, ssrOpts) {
|
|
|
160
170
|
};
|
|
161
171
|
}
|
|
162
172
|
async function ssr(preloadedComponent, ssrOpts) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return await render(renderers, mod, ssrOpts);
|
|
166
|
-
} catch (e) {
|
|
167
|
-
await errorHandler(e, { viteServer: ssrOpts.viteServer, filePath: ssrOpts.filePath });
|
|
168
|
-
throw e;
|
|
169
|
-
}
|
|
173
|
+
const [renderers, mod] = preloadedComponent;
|
|
174
|
+
return await render(renderers, mod, ssrOpts);
|
|
170
175
|
}
|
|
171
176
|
export {
|
|
172
177
|
loadRenderers,
|
|
@@ -55,7 +55,9 @@ Rename your file to \`[...page].astro\` or customize the param name via the \`pa
|
|
|
55
55
|
url: {
|
|
56
56
|
current: routeMatch.generate(__spreadValues({}, params)),
|
|
57
57
|
next: pageNum === lastPage ? void 0 : routeMatch.generate(__spreadProps(__spreadValues({}, params), { page: String(pageNum + 1) })),
|
|
58
|
-
prev: pageNum === 1 ? void 0 : routeMatch.generate(__spreadProps(__spreadValues({}, params), {
|
|
58
|
+
prev: pageNum === 1 ? void 0 : routeMatch.generate(__spreadProps(__spreadValues({}, params), {
|
|
59
|
+
page: !includesFirstPageNumber && pageNum - 1 === 1 ? void 0 : String(pageNum - 1)
|
|
60
|
+
}))
|
|
59
61
|
}
|
|
60
62
|
}
|
|
61
63
|
})
|