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
|
@@ -17,31 +17,53 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import {
|
|
21
|
+
createElement,
|
|
22
|
+
createScript,
|
|
23
|
+
getAttribute,
|
|
24
|
+
hasAttribute,
|
|
25
|
+
insertBefore,
|
|
26
|
+
remove,
|
|
27
|
+
setAttribute
|
|
28
|
+
} from "@web/parse5-utils";
|
|
29
|
+
import { promises as fs } from "fs";
|
|
20
30
|
import parse5 from "parse5";
|
|
21
|
-
import srcsetParse from "srcset-parse";
|
|
22
31
|
import * as npath from "path";
|
|
23
|
-
import
|
|
24
|
-
import {
|
|
25
|
-
import { addRollupInput } from "./add-rollup-input.js";
|
|
26
|
-
import { findAssets, findExternalScripts, findInlineScripts, findInlineStyles, getTextContent, getAttributes } from "./extract-assets.js";
|
|
27
|
-
import { isBuildableImage, isBuildableLink, isHoistedScript, isInSrcDirectory, hasSrcSet } from "./util.js";
|
|
32
|
+
import srcsetParse from "srcset-parse";
|
|
33
|
+
import { prependDotSlash } from "../core/path.js";
|
|
28
34
|
import { render as ssrRender } from "../core/render/dev/index.js";
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
35
|
+
import { getOutputFilename } from "../core/util.js";
|
|
36
|
+
import { getAstroPageStyleId, getAstroStyleId } from "../vite-plugin-build-css/index.js";
|
|
37
|
+
import { addRollupInput } from "./add-rollup-input.js";
|
|
38
|
+
import {
|
|
39
|
+
findAssets,
|
|
40
|
+
findExternalScripts,
|
|
41
|
+
findInlineScripts,
|
|
42
|
+
findInlineStyles,
|
|
43
|
+
getAttributes,
|
|
44
|
+
getTextContent
|
|
45
|
+
} from "./extract-assets.js";
|
|
46
|
+
import {
|
|
47
|
+
hasSrcSet,
|
|
48
|
+
isBuildableImage,
|
|
49
|
+
isBuildableLink,
|
|
50
|
+
isHoistedScript,
|
|
51
|
+
isInSrcDirectory
|
|
52
|
+
} from "./util.js";
|
|
53
|
+
import { createRequest } from "../core/request.js";
|
|
31
54
|
const matchSrcset = srcsetParse.default;
|
|
32
55
|
const PLUGIN_NAME = "@astro/rollup-plugin-build";
|
|
33
56
|
const ASTRO_PAGE_PREFIX = "@astro-page";
|
|
34
57
|
const ASTRO_SCRIPT_PREFIX = "@astro-script";
|
|
35
58
|
const ASTRO_EMPTY = "@astro-empty";
|
|
36
|
-
const STATUS_CODE_REGEXP = /^[0-9]{3}$/;
|
|
37
59
|
function relativePath(from, to) {
|
|
38
60
|
const rel = npath.posix.relative(from, to);
|
|
39
61
|
return prependDotSlash(rel);
|
|
40
62
|
}
|
|
41
63
|
function rollupPluginAstroScanHTML(options) {
|
|
42
64
|
const { astroConfig, internals, logging, origin, allPages, routeCache, viteServer, pageNames } = options;
|
|
43
|
-
const srcRoot = astroConfig.
|
|
44
|
-
const srcRootWeb = srcRoot.substr(astroConfig.
|
|
65
|
+
const srcRoot = astroConfig.srcDir.pathname;
|
|
66
|
+
const srcRootWeb = srcRoot.substr(astroConfig.root.pathname.length - 1);
|
|
45
67
|
const renderedPageMap = /* @__PURE__ */ new Map();
|
|
46
68
|
const astroScriptMap = /* @__PURE__ */ new Map();
|
|
47
69
|
const astroPageMap = /* @__PURE__ */ new Map();
|
|
@@ -65,10 +87,13 @@ function rollupPluginAstroScanHTML(options) {
|
|
|
65
87
|
const id = ASTRO_PAGE_PREFIX + pathname;
|
|
66
88
|
const response = await ssrRender(renderers, mod, {
|
|
67
89
|
astroConfig,
|
|
68
|
-
filePath: new URL(`./${component}`, astroConfig.
|
|
90
|
+
filePath: new URL(`./${component}`, astroConfig.root),
|
|
69
91
|
logging,
|
|
70
|
-
|
|
71
|
-
|
|
92
|
+
request: createRequest({
|
|
93
|
+
url: new URL(origin + pathname),
|
|
94
|
+
headers: new Headers(),
|
|
95
|
+
logging
|
|
96
|
+
}),
|
|
72
97
|
mode: "production",
|
|
73
98
|
origin,
|
|
74
99
|
pathname,
|
|
@@ -131,7 +156,7 @@ function rollupPluginAstroScanHTML(options) {
|
|
|
131
156
|
if ((src == null ? void 0 : src.startsWith(srcRoot)) && !astroAssetMap.has(src)) {
|
|
132
157
|
astroAssetMap.set(src, fs.readFile(new URL(`file://${src}`)));
|
|
133
158
|
} else if ((src == null ? void 0 : src.startsWith(srcRootWeb)) && !astroAssetMap.has(src)) {
|
|
134
|
-
const resolved = new URL("." + src, astroConfig.
|
|
159
|
+
const resolved = new URL("." + src, astroConfig.root);
|
|
135
160
|
astroAssetMap.set(src, fs.readFile(resolved));
|
|
136
161
|
}
|
|
137
162
|
}
|
|
@@ -141,7 +166,7 @@ function rollupPluginAstroScanHTML(options) {
|
|
|
141
166
|
if (url.startsWith(srcRoot) && !astroAssetMap.has(url)) {
|
|
142
167
|
astroAssetMap.set(url, fs.readFile(new URL(`file://${url}`)));
|
|
143
168
|
} else if (url.startsWith(srcRootWeb) && !astroAssetMap.has(url)) {
|
|
144
|
-
const resolved = new URL("." + url, astroConfig.
|
|
169
|
+
const resolved = new URL("." + url, astroConfig.root);
|
|
145
170
|
astroAssetMap.set(url, fs.readFile(resolved));
|
|
146
171
|
}
|
|
147
172
|
}
|
|
@@ -313,7 +338,7 @@ function rollupPluginAstroScanHTML(options) {
|
|
|
313
338
|
} else if (isInSrcDirectory(script, "src", srcRoot, srcRootWeb)) {
|
|
314
339
|
let src = getAttribute(script, "src");
|
|
315
340
|
if (src == null ? void 0 : src.startsWith(srcRootWeb)) {
|
|
316
|
-
src = new URL("." + src, astroConfig.
|
|
341
|
+
src = new URL("." + src, astroConfig.root).pathname;
|
|
317
342
|
}
|
|
318
343
|
if (src && (facadeIdMap.has(src) || facadeIdMap.has(src.substr(1)))) {
|
|
319
344
|
const assetRootPath = "/" + (facadeIdMap.get(src) || facadeIdMap.get(src.substr(1)));
|
|
@@ -386,12 +411,7 @@ function rollupPluginAstroScanHTML(options) {
|
|
|
386
411
|
}
|
|
387
412
|
const outHTML = parse5.serialize(document);
|
|
388
413
|
const name = pathname.substr(1);
|
|
389
|
-
|
|
390
|
-
if (astroConfig.buildOptions.pageUrlFormat === "file" || STATUS_CODE_REGEXP.test(name)) {
|
|
391
|
-
outPath = `${removeEndingForwardSlash(name || "index")}.html`;
|
|
392
|
-
} else {
|
|
393
|
-
outPath = npath.posix.join(name, "index.html");
|
|
394
|
-
}
|
|
414
|
+
const outPath = getOutputFilename(astroConfig, name);
|
|
395
415
|
this.emitFile({
|
|
396
416
|
fileName: outPath,
|
|
397
417
|
source: outHTML,
|
|
@@ -47,7 +47,7 @@ const getConfigAlias = (cwd) => {
|
|
|
47
47
|
return aliases;
|
|
48
48
|
};
|
|
49
49
|
function configAliasVitePlugin(astroConfig) {
|
|
50
|
-
const configAlias = getConfigAlias(astroConfig.
|
|
50
|
+
const configAlias = getConfigAlias(astroConfig.root && url.fileURLToPath(astroConfig.root));
|
|
51
51
|
if (!configAlias)
|
|
52
52
|
return {};
|
|
53
53
|
return {
|
|
@@ -60,7 +60,9 @@ function configAliasVitePlugin(astroConfig) {
|
|
|
60
60
|
for (const alias of configAlias) {
|
|
61
61
|
if (alias.find.test(sourceId)) {
|
|
62
62
|
const aliasedSourceId = sourceId.replace(alias.find, alias.replacement);
|
|
63
|
-
const resolvedAliasedId = await this.resolve(aliasedSourceId, importer, __spreadValues({
|
|
63
|
+
const resolvedAliasedId = await this.resolve(aliasedSourceId, importer, __spreadValues({
|
|
64
|
+
skipSelf: true
|
|
65
|
+
}, options));
|
|
64
66
|
if (resolvedAliasedId)
|
|
65
67
|
return resolvedAliasedId;
|
|
66
68
|
}
|
|
@@ -6,7 +6,7 @@ function getPrivateEnv(viteConfig, astroConfig) {
|
|
|
6
6
|
if (viteConfig.envPrefix) {
|
|
7
7
|
envPrefixes = Array.isArray(viteConfig.envPrefix) ? viteConfig.envPrefix : [viteConfig.envPrefix];
|
|
8
8
|
}
|
|
9
|
-
const fullEnv = loadEnv(viteConfig.mode, viteConfig.envDir ?? fileURLToPath(astroConfig.
|
|
9
|
+
const fullEnv = loadEnv(viteConfig.mode, viteConfig.envDir ?? fileURLToPath(astroConfig.root), "");
|
|
10
10
|
const privateKeys = Object.keys(fullEnv).filter((key) => {
|
|
11
11
|
if (typeof process.env[key] !== "undefined")
|
|
12
12
|
return false;
|
|
@@ -30,7 +30,9 @@ function getReferencedPrivateKeys(source, privateEnv) {
|
|
|
30
30
|
}
|
|
31
31
|
return references;
|
|
32
32
|
}
|
|
33
|
-
function envVitePlugin({
|
|
33
|
+
function envVitePlugin({
|
|
34
|
+
config: astroConfig
|
|
35
|
+
}) {
|
|
34
36
|
let privateEnv;
|
|
35
37
|
let config;
|
|
36
38
|
let replacements;
|
|
@@ -52,7 +54,10 @@ function envVitePlugin({ config: astroConfig }) {
|
|
|
52
54
|
if (typeof privateEnv === "undefined") {
|
|
53
55
|
privateEnv = getPrivateEnv(config, astroConfig);
|
|
54
56
|
if (privateEnv) {
|
|
55
|
-
const entries = Object.entries(privateEnv).map(([key, value]) => [
|
|
57
|
+
const entries = Object.entries(privateEnv).map(([key, value]) => [
|
|
58
|
+
`import.meta.env.${key}`,
|
|
59
|
+
value
|
|
60
|
+
]);
|
|
56
61
|
replacements = Object.fromEntries(entries);
|
|
57
62
|
replacements = Object.assign(replacements, {
|
|
58
63
|
"import.meta.env": `({})`
|
|
@@ -3,7 +3,7 @@ import esbuild from "esbuild";
|
|
|
3
3
|
import * as colors from "kleur/colors";
|
|
4
4
|
import * as eslexer from "es-module-lexer";
|
|
5
5
|
import path from "path";
|
|
6
|
-
import { error } from "../core/logger.js";
|
|
6
|
+
import { error } from "../core/logger/core.js";
|
|
7
7
|
import { parseNpmName } from "../core/util.js";
|
|
8
8
|
const JSX_RENDERER_CACHE = /* @__PURE__ */ new WeakMap();
|
|
9
9
|
const JSX_EXTENSIONS = /* @__PURE__ */ new Set([".jsx", ".tsx"]);
|
|
@@ -20,7 +20,13 @@ function collectJSXRenderers(renderers) {
|
|
|
20
20
|
const renderersWithJSXSupport = renderers.filter((r) => r.jsxImportSource);
|
|
21
21
|
return new Map(renderersWithJSXSupport.map((r) => [r.jsxImportSource, r]));
|
|
22
22
|
}
|
|
23
|
-
async function transformJSX({
|
|
23
|
+
async function transformJSX({
|
|
24
|
+
code,
|
|
25
|
+
mode,
|
|
26
|
+
id,
|
|
27
|
+
ssr,
|
|
28
|
+
renderer
|
|
29
|
+
}) {
|
|
24
30
|
const { jsxTransformOptions } = renderer;
|
|
25
31
|
const options = await jsxTransformOptions({ mode, ssr });
|
|
26
32
|
const plugins = [...options.plugins || []];
|
|
@@ -76,7 +82,13 @@ Unable to resolve a JSX renderer! Did you forget to include one? Add a JSX integ
|
|
|
76
82
|
sourcefile: id,
|
|
77
83
|
sourcemap: "inline"
|
|
78
84
|
});
|
|
79
|
-
return transformJSX({
|
|
85
|
+
return transformJSX({
|
|
86
|
+
code: jsxCode,
|
|
87
|
+
id,
|
|
88
|
+
renderer: [...jsxRenderers.values()][0],
|
|
89
|
+
mode,
|
|
90
|
+
ssr
|
|
91
|
+
});
|
|
80
92
|
}
|
|
81
93
|
const { code: jsCode } = await esbuild.transform(code + PREVENT_UNUSED_IMPORTS, {
|
|
82
94
|
loader: getEsbuildLoader(path.extname(id)),
|
|
@@ -125,7 +137,13 @@ Unable to resolve a JSX renderer! Did you forget to include one? Add a JSX integ
|
|
|
125
137
|
sourcefile: id,
|
|
126
138
|
sourcemap: "inline"
|
|
127
139
|
});
|
|
128
|
-
return await transformJSX({
|
|
140
|
+
return await transformJSX({
|
|
141
|
+
code: jsxCode,
|
|
142
|
+
id,
|
|
143
|
+
renderer: jsxRenderers.get(importSource),
|
|
144
|
+
mode,
|
|
145
|
+
ssr
|
|
146
|
+
});
|
|
129
147
|
}
|
|
130
148
|
const defaultRenderer = [...jsxRenderers.keys()][0];
|
|
131
149
|
error(logging, "renderer", `${colors.yellow(id)}
|
|
@@ -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,11 @@ ${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, {
|
|
158
|
+
loader: "ts",
|
|
159
|
+
sourcemap: false,
|
|
160
|
+
sourcefile: id
|
|
161
|
+
});
|
|
87
162
|
return {
|
|
88
163
|
code,
|
|
89
164
|
map: null
|
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.1",
|
|
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.1",
|
|
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,62 +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
|
-
legacy: true
|
|
50
|
-
}),
|
|
51
|
-
...viteConfig.plugins || []
|
|
52
|
-
],
|
|
53
|
-
publicDir: viteConfig.publicDir,
|
|
54
|
-
root: viteConfig.root,
|
|
55
|
-
envPrefix: "PUBLIC_",
|
|
56
|
-
server: viteConfig.server,
|
|
57
|
-
base: astroConfig.buildOptions.site ? new URL(astroConfig.buildOptions.site).pathname : "/"
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
export {
|
|
61
|
-
build
|
|
62
|
-
};
|
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
|
-
};
|