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
|
@@ -1,6 +1,19 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
1
2
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
2
3
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3
4
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
4
17
|
var __objRest = (source, exclude) => {
|
|
5
18
|
var target = {};
|
|
6
19
|
for (var prop in source)
|
|
@@ -13,41 +26,99 @@ var __objRest = (source, exclude) => {
|
|
|
13
26
|
}
|
|
14
27
|
return target;
|
|
15
28
|
};
|
|
29
|
+
import astroRemark from "@astrojs/markdown-remark";
|
|
16
30
|
import { transform } from "@astrojs/compiler";
|
|
17
31
|
import ancestor from "common-ancestor-path";
|
|
18
32
|
import esbuild from "esbuild";
|
|
19
33
|
import fs from "fs";
|
|
34
|
+
import matter from "gray-matter";
|
|
35
|
+
import { fileURLToPath } from "url";
|
|
20
36
|
import { PAGE_SSR_SCRIPT_ID } from "../vite-plugin-scripts/index.js";
|
|
37
|
+
import { virtualModuleId as pagesVirtualModuleId } from "../core/build/vite-plugin-pages.js";
|
|
38
|
+
import { appendForwardSlash } from "../core/path.js";
|
|
39
|
+
import { resolvePages } from "../core/util.js";
|
|
40
|
+
const VIRTUAL_MODULE_ID_PREFIX = "astro:markdown";
|
|
41
|
+
const VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID_PREFIX;
|
|
21
42
|
function markdown({ config }) {
|
|
22
43
|
function normalizeFilename(filename) {
|
|
23
44
|
if (filename.startsWith("/@fs")) {
|
|
24
45
|
filename = filename.slice("/@fs".length);
|
|
25
|
-
} else if (filename.startsWith("/") && !ancestor(filename, config.
|
|
26
|
-
filename = new URL("." + filename, config.
|
|
46
|
+
} else if (filename.startsWith("/") && !ancestor(filename, config.root.pathname)) {
|
|
47
|
+
filename = new URL("." + filename, config.root).pathname;
|
|
27
48
|
}
|
|
28
49
|
return filename;
|
|
29
50
|
}
|
|
51
|
+
const fakeRootImporter = fileURLToPath(new URL("index.html", config.root));
|
|
52
|
+
function isRootImport(importer) {
|
|
53
|
+
if (!importer) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
if (importer === fakeRootImporter) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
if (importer === "\0" + pagesVirtualModuleId) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
30
64
|
return {
|
|
31
65
|
name: "astro:markdown",
|
|
32
66
|
enforce: "pre",
|
|
67
|
+
async resolveId(id, importer, options) {
|
|
68
|
+
if (id.startsWith(VIRTUAL_MODULE_ID)) {
|
|
69
|
+
return id;
|
|
70
|
+
}
|
|
71
|
+
if (id.endsWith(".md?content")) {
|
|
72
|
+
const resolvedId = await this.resolve(id, importer, __spreadValues({ skipSelf: true }, options));
|
|
73
|
+
return resolvedId == null ? void 0 : resolvedId.id.replace("?content", "");
|
|
74
|
+
}
|
|
75
|
+
if (id.endsWith(".md") && !isRootImport(importer)) {
|
|
76
|
+
const resolvedId = await this.resolve(id, importer, __spreadValues({ skipSelf: true }, options));
|
|
77
|
+
if (resolvedId) {
|
|
78
|
+
return VIRTUAL_MODULE_ID + resolvedId.id;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return void 0;
|
|
82
|
+
},
|
|
33
83
|
async load(id) {
|
|
84
|
+
if (id.startsWith(VIRTUAL_MODULE_ID)) {
|
|
85
|
+
const sitePathname = config.site ? appendForwardSlash(new URL(config.base, config.site).pathname) : "/";
|
|
86
|
+
const fileId = id.substring(VIRTUAL_MODULE_ID.length);
|
|
87
|
+
const fileUrl = fileId.includes("/pages/") ? fileId.replace(/^.*\/pages\//, sitePathname).replace(/(\/index)?\.md$/, "") : void 0;
|
|
88
|
+
const source = await fs.promises.readFile(fileId, "utf8");
|
|
89
|
+
const { data: frontmatter } = matter(source);
|
|
90
|
+
return {
|
|
91
|
+
code: `
|
|
92
|
+
// Static
|
|
93
|
+
export const frontmatter = ${JSON.stringify(frontmatter)};
|
|
94
|
+
export const file = ${JSON.stringify(fileId)};
|
|
95
|
+
export const url = ${JSON.stringify(fileUrl)};
|
|
96
|
+
|
|
97
|
+
// Deferred
|
|
98
|
+
export default async function load() {
|
|
99
|
+
return (await import(${JSON.stringify(fileId + "?content")}));
|
|
100
|
+
};
|
|
101
|
+
export function Content(...args) {
|
|
102
|
+
return load().then((m) => m.default(...args))
|
|
103
|
+
}
|
|
104
|
+
Content.isAstroComponentFactory = true;
|
|
105
|
+
export function getHeaders() {
|
|
106
|
+
return load().then((m) => m.metadata.headers)
|
|
107
|
+
};`,
|
|
108
|
+
map: null
|
|
109
|
+
};
|
|
110
|
+
}
|
|
34
111
|
if (id.endsWith(".md")) {
|
|
35
112
|
const source = await fs.promises.readFile(id, "utf8");
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (Array.isArray(render)) {
|
|
39
|
-
renderOpts = render[1];
|
|
40
|
-
render = render[0];
|
|
41
|
-
}
|
|
42
|
-
if (typeof render === "string") {
|
|
43
|
-
({ default: render } = await import(render));
|
|
44
|
-
}
|
|
45
|
-
let renderResult = await render(source, renderOpts);
|
|
46
|
-
let { frontmatter, metadata, code: astroResult } = renderResult;
|
|
113
|
+
const render = astroRemark;
|
|
114
|
+
const renderOpts = config.markdown;
|
|
47
115
|
const filename = normalizeFilename(id);
|
|
48
116
|
const fileUrl = new URL(`file://${filename}`);
|
|
49
|
-
const isPage = fileUrl.pathname.startsWith(config.
|
|
117
|
+
const isPage = fileUrl.pathname.startsWith(resolvePages(config).pathname);
|
|
50
118
|
const hasInjectedScript = isPage && config._ctx.scripts.some((s) => s.stage === "page-ssr");
|
|
119
|
+
const { data: frontmatter, content: markdownContent } = matter(source);
|
|
120
|
+
let renderResult = await render(markdownContent, renderOpts);
|
|
121
|
+
let { code: astroResult, metadata } = renderResult;
|
|
51
122
|
const _a = frontmatter, { layout = "", components = "", setup = "" } = _a, content = __objRest(_a, ["layout", "components", "setup"]);
|
|
52
123
|
content.astro = metadata;
|
|
53
124
|
const prelude = `---
|
|
@@ -72,9 +143,9 @@ ${astroResult}
|
|
|
72
143
|
${astroResult}`;
|
|
73
144
|
}
|
|
74
145
|
let { code: tsResult } = await transform(astroResult, {
|
|
75
|
-
pathname: fileUrl.pathname.substr(config.
|
|
76
|
-
projectRoot: config.
|
|
77
|
-
site: config.
|
|
146
|
+
pathname: fileUrl.pathname.substr(config.root.pathname.length - 1),
|
|
147
|
+
projectRoot: config.root.toString(),
|
|
148
|
+
site: config.site ? new URL(config.base, config.site).toString() : void 0,
|
|
78
149
|
sourcefile: id,
|
|
79
150
|
sourcemap: "inline",
|
|
80
151
|
internalURL: `/@fs${new URL("../runtime/server/index.js", import.meta.url).pathname}`
|
|
@@ -83,7 +154,7 @@ ${astroResult}`;
|
|
|
83
154
|
export const metadata = ${JSON.stringify(metadata)};
|
|
84
155
|
export const frontmatter = ${JSON.stringify(content)};
|
|
85
156
|
${tsResult}`;
|
|
86
|
-
const { code
|
|
157
|
+
const { code } = await esbuild.transform(tsResult, { loader: "ts", sourcemap: false, sourcefile: id });
|
|
87
158
|
return {
|
|
88
159
|
code,
|
|
89
160
|
map: null
|
|
File without changes
|
package/env.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="vite/client" />
|
|
2
2
|
|
|
3
|
-
type Astro = import('
|
|
3
|
+
type Astro = import('astro').AstroGlobal;
|
|
4
4
|
|
|
5
5
|
// We duplicate the description here because editors won't show the JSDoc comment from the imported type (but will for its properties, ex: Astro.request will show the AstroGlobal.request description)
|
|
6
6
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "withastro",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"vendor"
|
|
65
65
|
],
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@astrojs/compiler": "^0.
|
|
68
|
-
"@astrojs/language-server": "^0.13.
|
|
69
|
-
"@astrojs/markdown-remark": "^0.
|
|
67
|
+
"@astrojs/compiler": "^0.14.1",
|
|
68
|
+
"@astrojs/language-server": "^0.13.3",
|
|
69
|
+
"@astrojs/markdown-remark": "^0.8.0",
|
|
70
70
|
"@astrojs/prism": "0.4.1",
|
|
71
71
|
"@astrojs/webapi": "^0.11.0",
|
|
72
72
|
"@babel/core": "^7.17.8",
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"@proload/core": "^0.2.2",
|
|
77
77
|
"@proload/plugin-tsm": "^0.1.1",
|
|
78
78
|
"@web/parse5-utils": "^1.3.0",
|
|
79
|
+
"ast-types": "^0.14.2",
|
|
79
80
|
"boxen": "^6.2.1",
|
|
80
81
|
"ci-info": "^3.3.0",
|
|
81
82
|
"common-ancestor-path": "^1.0.1",
|
|
@@ -88,7 +89,7 @@
|
|
|
88
89
|
"execa": "^6.1.0",
|
|
89
90
|
"fast-glob": "^3.2.11",
|
|
90
91
|
"fast-xml-parser": "^4.0.7",
|
|
91
|
-
"html-entities": "^2.3.
|
|
92
|
+
"html-entities": "^2.3.3",
|
|
92
93
|
"html-escaper": "^3.0.3",
|
|
93
94
|
"htmlparser2": "^7.2.0",
|
|
94
95
|
"kleur": "^4.1.4",
|
|
@@ -97,12 +98,14 @@
|
|
|
97
98
|
"mime": "^3.0.0",
|
|
98
99
|
"ora": "^6.1.0",
|
|
99
100
|
"parse5": "^6.0.1",
|
|
101
|
+
"path-browserify": "^1.0.1",
|
|
100
102
|
"path-to-regexp": "^6.2.0",
|
|
101
103
|
"postcss": "^8.4.12",
|
|
102
|
-
"postcss-load-config": "^3.1.
|
|
104
|
+
"postcss-load-config": "^3.1.4",
|
|
103
105
|
"preferred-pm": "^3.0.3",
|
|
104
106
|
"prismjs": "^1.27.0",
|
|
105
107
|
"prompts": "^2.4.2",
|
|
108
|
+
"recast": "^0.20.5",
|
|
106
109
|
"rehype-slug": "^5.0.1",
|
|
107
110
|
"resolve": "^1.22.0",
|
|
108
111
|
"rollup": "^2.70.1",
|
|
@@ -118,9 +121,9 @@
|
|
|
118
121
|
"strip-ansi": "^7.0.1",
|
|
119
122
|
"supports-esm": "^1.0.0",
|
|
120
123
|
"tsconfig-resolver": "^3.0.1",
|
|
121
|
-
"vite": "^2.
|
|
124
|
+
"vite": "^2.9.1",
|
|
122
125
|
"yargs-parser": "^21.0.1",
|
|
123
|
-
"zod": "^3.14.
|
|
126
|
+
"zod": "^3.14.3"
|
|
124
127
|
},
|
|
125
128
|
"devDependencies": {
|
|
126
129
|
"@babel/types": "^7.17.0",
|
|
@@ -137,6 +140,7 @@
|
|
|
137
140
|
"@types/mime": "^2.0.3",
|
|
138
141
|
"@types/mocha": "^9.1.0",
|
|
139
142
|
"@types/parse5": "^6.0.3",
|
|
143
|
+
"@types/path-browserify": "^1.0.0",
|
|
140
144
|
"@types/prettier": "^2.4.4",
|
|
141
145
|
"@types/resolve": "^1.20.1",
|
|
142
146
|
"@types/rimraf": "^3.0.2",
|
|
@@ -146,7 +150,7 @@
|
|
|
146
150
|
"chai": "^4.3.6",
|
|
147
151
|
"cheerio": "^1.0.0-rc.10",
|
|
148
152
|
"mocha": "^9.2.2",
|
|
149
|
-
"sass": "^1.49.
|
|
153
|
+
"sass": "^1.49.11"
|
|
150
154
|
},
|
|
151
155
|
"engines": {
|
|
152
156
|
"node": "^14.15.0 || >=16.0.0",
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath } from "url";
|
|
2
|
-
import * as vite from "vite";
|
|
3
|
-
import { createBuildInternals } from "../../core/build/internal.js";
|
|
4
|
-
import { rollupPluginAstroScanHTML } from "../../vite-plugin-build-html/index.js";
|
|
5
|
-
import { rollupPluginAstroBuildCSS } from "../../vite-plugin-build-css/index.js";
|
|
6
|
-
function entryIsType(type) {
|
|
7
|
-
return function withPage([_, pageData]) {
|
|
8
|
-
return pageData.route.type === type;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
function reduceEntries(acc, [key, value]) {
|
|
12
|
-
acc[key] = value;
|
|
13
|
-
return acc;
|
|
14
|
-
}
|
|
15
|
-
function routesOfType(type, allPages) {
|
|
16
|
-
return Object.entries(allPages).filter(entryIsType(type)).reduce(reduceEntries, {});
|
|
17
|
-
}
|
|
18
|
-
async function build(opts) {
|
|
19
|
-
const { allPages, astroConfig, logging, origin, pageNames, routeCache, viteConfig, viteServer } = opts;
|
|
20
|
-
const internals = createBuildInternals();
|
|
21
|
-
return await vite.build({
|
|
22
|
-
logLevel: "warn",
|
|
23
|
-
mode: "production",
|
|
24
|
-
build: {
|
|
25
|
-
emptyOutDir: true,
|
|
26
|
-
minify: "esbuild",
|
|
27
|
-
outDir: fileURLToPath(astroConfig.dist),
|
|
28
|
-
rollupOptions: {
|
|
29
|
-
input: [],
|
|
30
|
-
output: {
|
|
31
|
-
format: "esm"
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
target: "es2020"
|
|
35
|
-
},
|
|
36
|
-
plugins: [
|
|
37
|
-
rollupPluginAstroScanHTML({
|
|
38
|
-
astroConfig,
|
|
39
|
-
internals,
|
|
40
|
-
logging,
|
|
41
|
-
origin,
|
|
42
|
-
allPages: routesOfType("page", allPages),
|
|
43
|
-
pageNames,
|
|
44
|
-
routeCache,
|
|
45
|
-
viteServer
|
|
46
|
-
}),
|
|
47
|
-
rollupPluginAstroBuildCSS({
|
|
48
|
-
internals
|
|
49
|
-
}),
|
|
50
|
-
...viteConfig.plugins || []
|
|
51
|
-
],
|
|
52
|
-
publicDir: viteConfig.publicDir,
|
|
53
|
-
root: viteConfig.root,
|
|
54
|
-
envPrefix: "PUBLIC_",
|
|
55
|
-
server: viteConfig.server,
|
|
56
|
-
base: astroConfig.buildOptions.site ? new URL(astroConfig.buildOptions.site).pathname : "/"
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
export {
|
|
60
|
-
build
|
|
61
|
-
};
|
package/dist/core/dev/util.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
const localIps = /* @__PURE__ */ new Set(["localhost", "127.0.0.1"]);
|
|
2
|
-
function pad(input, minLength, dir) {
|
|
3
|
-
let output = input;
|
|
4
|
-
while (output.length < minLength) {
|
|
5
|
-
output = dir === "left" ? " " + output : output + " ";
|
|
6
|
-
}
|
|
7
|
-
return output;
|
|
8
|
-
}
|
|
9
|
-
function emoji(char, fallback) {
|
|
10
|
-
return process.platform !== "win32" ? char : fallback;
|
|
11
|
-
}
|
|
12
|
-
function getResolvedHostForVite(config) {
|
|
13
|
-
if (config.devOptions.host === false && config.devOptions.hostname !== "localhost") {
|
|
14
|
-
return config.devOptions.hostname;
|
|
15
|
-
} else {
|
|
16
|
-
return config.devOptions.host;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function getLocalAddress(serverAddress, config) {
|
|
20
|
-
const host = getResolvedHostForVite(config);
|
|
21
|
-
if (typeof host === "boolean" || host === "localhost") {
|
|
22
|
-
return "localhost";
|
|
23
|
-
} else {
|
|
24
|
-
return serverAddress;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function getNetworkLogging(config) {
|
|
28
|
-
const host = getResolvedHostForVite(config);
|
|
29
|
-
if (host === false) {
|
|
30
|
-
return "host-to-expose";
|
|
31
|
-
} else if (typeof host === "string" && localIps.has(host)) {
|
|
32
|
-
return "none";
|
|
33
|
-
} else {
|
|
34
|
-
return "visible";
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export {
|
|
38
|
-
emoji,
|
|
39
|
-
getLocalAddress,
|
|
40
|
-
getNetworkLogging,
|
|
41
|
-
getResolvedHostForVite,
|
|
42
|
-
localIps,
|
|
43
|
-
pad
|
|
44
|
-
};
|
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 {};
|