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/dist/core/logger.js
DELETED
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { bold, cyan, dim, red, yellow, reset } from "kleur/colors";
|
|
2
|
-
import { performance } from "perf_hooks";
|
|
3
|
-
import { Writable } from "stream";
|
|
4
|
-
import stringWidth from "string-width";
|
|
5
|
-
import * as readline from "readline";
|
|
6
|
-
import debugPackage from "debug";
|
|
7
|
-
import { format as utilFormat } from "util";
|
|
8
|
-
import { isBuildingToSSR } from "./util.js";
|
|
9
|
-
function getLoggerLocale() {
|
|
10
|
-
const defaultLocale = "en-US";
|
|
11
|
-
if (process.env.LANG) {
|
|
12
|
-
const extractedLocale = process.env.LANG.split(".")[0].replace(/_/g, "-");
|
|
13
|
-
if (extractedLocale.length < 2)
|
|
14
|
-
return defaultLocale;
|
|
15
|
-
else
|
|
16
|
-
return extractedLocale.substring(0, 5);
|
|
17
|
-
} else
|
|
18
|
-
return defaultLocale;
|
|
19
|
-
}
|
|
20
|
-
const dt = new Intl.DateTimeFormat(getLoggerLocale(), {
|
|
21
|
-
hour: "2-digit",
|
|
22
|
-
minute: "2-digit",
|
|
23
|
-
second: "2-digit"
|
|
24
|
-
});
|
|
25
|
-
let lastMessage;
|
|
26
|
-
let lastMessageCount = 1;
|
|
27
|
-
const defaultLogDestination = new Writable({
|
|
28
|
-
objectMode: true,
|
|
29
|
-
write(event, _, callback) {
|
|
30
|
-
let dest = process.stderr;
|
|
31
|
-
if (levels[event.level] < levels["error"]) {
|
|
32
|
-
dest = process.stdout;
|
|
33
|
-
}
|
|
34
|
-
function getPrefix() {
|
|
35
|
-
let prefix = "";
|
|
36
|
-
let type = event.type;
|
|
37
|
-
if (type) {
|
|
38
|
-
prefix += dim(dt.format(new Date()) + " ");
|
|
39
|
-
if (event.level === "info") {
|
|
40
|
-
type = bold(cyan(`[${type}]`));
|
|
41
|
-
} else if (event.level === "warn") {
|
|
42
|
-
type = bold(yellow(`[${type}]`));
|
|
43
|
-
} else if (event.level === "error") {
|
|
44
|
-
type = bold(red(`[${type}]`));
|
|
45
|
-
}
|
|
46
|
-
prefix += `${type} `;
|
|
47
|
-
}
|
|
48
|
-
return reset(prefix);
|
|
49
|
-
}
|
|
50
|
-
let message = utilFormat(...event.args);
|
|
51
|
-
if (message === lastMessage) {
|
|
52
|
-
lastMessageCount++;
|
|
53
|
-
if (levels[event.level] < levels["error"]) {
|
|
54
|
-
let lines = 1;
|
|
55
|
-
let len = stringWidth(`${getPrefix()}${message}`);
|
|
56
|
-
let cols = dest.columns;
|
|
57
|
-
if (len > cols) {
|
|
58
|
-
lines = Math.ceil(len / cols);
|
|
59
|
-
}
|
|
60
|
-
for (let i = 0; i < lines; i++) {
|
|
61
|
-
readline.clearLine(dest, 0);
|
|
62
|
-
readline.cursorTo(dest, 0);
|
|
63
|
-
readline.moveCursor(dest, 0, -1);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
message = `${message} ${yellow(`(x${lastMessageCount})`)}`;
|
|
67
|
-
} else {
|
|
68
|
-
lastMessage = message;
|
|
69
|
-
lastMessageCount = 1;
|
|
70
|
-
}
|
|
71
|
-
dest.write(getPrefix());
|
|
72
|
-
dest.write(message);
|
|
73
|
-
dest.write("\n");
|
|
74
|
-
callback();
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
const defaultLogOptions = {
|
|
78
|
-
dest: defaultLogDestination,
|
|
79
|
-
level: "info"
|
|
80
|
-
};
|
|
81
|
-
const levels = {
|
|
82
|
-
debug: 20,
|
|
83
|
-
info: 30,
|
|
84
|
-
warn: 40,
|
|
85
|
-
error: 50,
|
|
86
|
-
silent: 90
|
|
87
|
-
};
|
|
88
|
-
function enableVerboseLogging() {
|
|
89
|
-
debugPackage.enable("*,-babel");
|
|
90
|
-
debug("cli", '--verbose flag enabled! Enabling: DEBUG="*,-babel"');
|
|
91
|
-
debug("cli", 'Tip: Set the DEBUG env variable directly for more control. Example: "DEBUG=astro:*,vite:* astro build".');
|
|
92
|
-
}
|
|
93
|
-
function log(opts = {}, level, type, ...args) {
|
|
94
|
-
const logLevel = opts.level ?? defaultLogOptions.level;
|
|
95
|
-
const dest = opts.dest ?? defaultLogOptions.dest;
|
|
96
|
-
const event = {
|
|
97
|
-
type,
|
|
98
|
-
level,
|
|
99
|
-
args,
|
|
100
|
-
message: ""
|
|
101
|
-
};
|
|
102
|
-
if (levels[logLevel] > levels[level]) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
dest.write(event);
|
|
106
|
-
}
|
|
107
|
-
const debuggers = {};
|
|
108
|
-
function debug(type, ...messages) {
|
|
109
|
-
const namespace = `astro:${type}`;
|
|
110
|
-
debuggers[namespace] = debuggers[namespace] || debugPackage(namespace);
|
|
111
|
-
return debuggers[namespace](...messages);
|
|
112
|
-
}
|
|
113
|
-
function info(opts, type, ...messages) {
|
|
114
|
-
return log(opts, "info", type, ...messages);
|
|
115
|
-
}
|
|
116
|
-
function warn(opts, type, ...messages) {
|
|
117
|
-
return log(opts, "warn", type, ...messages);
|
|
118
|
-
}
|
|
119
|
-
function error(opts, type, ...messages) {
|
|
120
|
-
return log(opts, "error", type, ...messages);
|
|
121
|
-
}
|
|
122
|
-
function table(opts, columns) {
|
|
123
|
-
return function logTable(logFn, ...input) {
|
|
124
|
-
const messages = columns.map((len, i) => padStr(input[i].toString(), len));
|
|
125
|
-
logFn(opts, null, ...messages);
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
const logger = {
|
|
129
|
-
info: info.bind(null, defaultLogOptions),
|
|
130
|
-
warn: warn.bind(null, defaultLogOptions),
|
|
131
|
-
error: error.bind(null, defaultLogOptions)
|
|
132
|
-
};
|
|
133
|
-
function padStr(str, len) {
|
|
134
|
-
const strLen = stringWidth(str);
|
|
135
|
-
if (strLen > len) {
|
|
136
|
-
return str.substring(0, len - 3) + "...";
|
|
137
|
-
}
|
|
138
|
-
const spaces = Array.from({ length: len - strLen }, () => " ").join("");
|
|
139
|
-
return str + spaces;
|
|
140
|
-
}
|
|
141
|
-
let defaultLogLevel;
|
|
142
|
-
if (process.argv.includes("--verbose")) {
|
|
143
|
-
defaultLogLevel = "debug";
|
|
144
|
-
} else if (process.argv.includes("--silent")) {
|
|
145
|
-
defaultLogLevel = "silent";
|
|
146
|
-
} else {
|
|
147
|
-
defaultLogLevel = "info";
|
|
148
|
-
}
|
|
149
|
-
function timerMessage(message, startTime = performance.now()) {
|
|
150
|
-
let timeDiff = performance.now() - startTime;
|
|
151
|
-
let timeDisplay = timeDiff < 750 ? `${Math.round(timeDiff)}ms` : `${(timeDiff / 1e3).toFixed(1)}s`;
|
|
152
|
-
return `${message} ${dim(timeDisplay)}`;
|
|
153
|
-
}
|
|
154
|
-
function warnIfUsingExperimentalSSR(opts, config) {
|
|
155
|
-
if (isBuildingToSSR(config)) {
|
|
156
|
-
warn(opts, "warning", bold(`Warning:`), ` SSR support is still experimental and subject to API changes. If using in production pin your dependencies to prevent accidental breakage.`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
export {
|
|
160
|
-
debug,
|
|
161
|
-
defaultLogDestination,
|
|
162
|
-
defaultLogLevel,
|
|
163
|
-
defaultLogOptions,
|
|
164
|
-
enableVerboseLogging,
|
|
165
|
-
error,
|
|
166
|
-
info,
|
|
167
|
-
levels,
|
|
168
|
-
log,
|
|
169
|
-
logger,
|
|
170
|
-
table,
|
|
171
|
-
timerMessage,
|
|
172
|
-
warn,
|
|
173
|
-
warnIfUsingExperimentalSSR
|
|
174
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import eol from "eol";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import { codeFrame } from "../../util.js";
|
|
4
|
-
async function errorHandler(e, { viteServer, filePath }) {
|
|
5
|
-
if (e.stack) {
|
|
6
|
-
e.stack = eol.lf(e.stack);
|
|
7
|
-
}
|
|
8
|
-
if (e instanceof Error) {
|
|
9
|
-
viteServer.ssrFixStacktrace(e);
|
|
10
|
-
}
|
|
11
|
-
if (Array.isArray(e.errors)) {
|
|
12
|
-
const { location, pluginName, text } = e.errors[0];
|
|
13
|
-
const err = e;
|
|
14
|
-
if (location)
|
|
15
|
-
err.loc = { file: location.file, line: location.line, column: location.column };
|
|
16
|
-
let src = err.pluginCode;
|
|
17
|
-
if (!src && err.id && fs.existsSync(err.id))
|
|
18
|
-
src = await fs.promises.readFile(err.id, "utf8");
|
|
19
|
-
if (!src)
|
|
20
|
-
src = await fs.promises.readFile(filePath, "utf8");
|
|
21
|
-
err.frame = codeFrame(src, err.loc);
|
|
22
|
-
err.id = location == null ? void 0 : location.file;
|
|
23
|
-
err.message = `${location == null ? void 0 : location.file}: ${text}
|
|
24
|
-
${err.frame}
|
|
25
|
-
`;
|
|
26
|
-
if (pluginName)
|
|
27
|
-
err.plugin = pluginName;
|
|
28
|
-
throw err;
|
|
29
|
-
}
|
|
30
|
-
throw e;
|
|
31
|
-
}
|
|
32
|
-
export {
|
|
33
|
-
errorHandler
|
|
34
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { canonicalURL as utilCanonicalURL } from "../util.js";
|
|
2
|
-
function createRequest(method, pathname, headers, origin, site, ssr) {
|
|
3
|
-
const url = new URL("." + pathname, new URL(origin));
|
|
4
|
-
const canonicalURL = utilCanonicalURL("." + pathname, site ?? url.origin);
|
|
5
|
-
const request = {
|
|
6
|
-
url,
|
|
7
|
-
canonicalURL,
|
|
8
|
-
params: {},
|
|
9
|
-
headers,
|
|
10
|
-
method
|
|
11
|
-
};
|
|
12
|
-
if (!ssr) {
|
|
13
|
-
request.headers = new Headers();
|
|
14
|
-
request.url = new URL(request.url);
|
|
15
|
-
for (const [key] of request.url.searchParams) {
|
|
16
|
-
request.url.searchParams.delete(key);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return request;
|
|
20
|
-
}
|
|
21
|
-
export {
|
|
22
|
-
createRequest
|
|
23
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const STATUS_CODE_PAGE_REGEXP = /\/[0-9]{3}\/?$/;
|
|
2
|
-
function generateSitemap(pages, filter) {
|
|
3
|
-
let urls = [...pages].filter((url) => !STATUS_CODE_PAGE_REGEXP.test(url));
|
|
4
|
-
if (filter) {
|
|
5
|
-
urls = urls.filter((url) => filter(url));
|
|
6
|
-
}
|
|
7
|
-
urls.sort((a, b) => a.localeCompare(b, "en", { numeric: true }));
|
|
8
|
-
let sitemap = `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">`;
|
|
9
|
-
for (const url of urls) {
|
|
10
|
-
sitemap += `<url><loc>${url}</loc></url>`;
|
|
11
|
-
}
|
|
12
|
-
sitemap += `</urlset>
|
|
13
|
-
`;
|
|
14
|
-
return sitemap;
|
|
15
|
-
}
|
|
16
|
-
export {
|
|
17
|
-
generateSitemap
|
|
18
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ViteDevServer } from 'vite';
|
|
2
|
-
import type { RollupOutput, RollupWatcher } from 'rollup';
|
|
3
|
-
import type { AstroConfig } from '../../@types/astro';
|
|
4
|
-
import type { AllPagesData } from './types';
|
|
5
|
-
import type { LogOptions } from '../logger';
|
|
6
|
-
import type { ViteConfigWithSSR } from '../create-vite.js';
|
|
7
|
-
import { RouteCache } from '../render/route-cache.js';
|
|
8
|
-
export interface ScanBasedBuildOptions {
|
|
9
|
-
allPages: AllPagesData;
|
|
10
|
-
astroConfig: AstroConfig;
|
|
11
|
-
logging: LogOptions;
|
|
12
|
-
origin: string;
|
|
13
|
-
pageNames: string[];
|
|
14
|
-
routeCache: RouteCache;
|
|
15
|
-
viteConfig: ViteConfigWithSSR;
|
|
16
|
-
viteServer: ViteDevServer;
|
|
17
|
-
}
|
|
18
|
-
export declare function build(opts: ScanBasedBuildOptions): Promise<RollupOutput | RollupOutput[] | RollupWatcher>;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { AstroConfig } from '../../@types/astro';
|
|
2
|
-
export declare const localIps: Set<string>;
|
|
3
|
-
/** Pad string () */
|
|
4
|
-
export declare function pad(input: string, minLength: number, dir?: 'left' | 'right'): string;
|
|
5
|
-
export declare function emoji(char: string, fallback: string): string;
|
|
6
|
-
export declare function getResolvedHostForVite(config: AstroConfig): string | boolean;
|
|
7
|
-
export declare function getLocalAddress(serverAddress: string, config: AstroConfig): string;
|
|
8
|
-
export declare type NetworkLogging = 'none' | 'host-to-expose' | 'visible';
|
|
9
|
-
export declare function getNetworkLogging(config: AstroConfig): NetworkLogging;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Params } from '../../@types/astro';
|
|
2
|
-
declare type Site = string | undefined;
|
|
3
|
-
export interface AstroRequest {
|
|
4
|
-
/** get the current page URL */
|
|
5
|
-
url: URL;
|
|
6
|
-
/** get the current canonical URL */
|
|
7
|
-
canonicalURL: URL;
|
|
8
|
-
/** get page params (dynamic pages only) */
|
|
9
|
-
params: Params;
|
|
10
|
-
headers: Headers;
|
|
11
|
-
method: string;
|
|
12
|
-
}
|
|
13
|
-
export declare type AstroRequestSSR = AstroRequest;
|
|
14
|
-
export declare function createRequest(method: string, pathname: string, headers: Headers, origin: string, site: Site, ssr: boolean): AstroRequest;
|
|
15
|
-
export {};
|