astro 1.5.1 → 1.5.3
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.d.ts +1 -2
- package/dist/core/add/index.js +6 -1
- package/dist/core/build/common.js +2 -1
- package/dist/core/build/generate.js +0 -18
- package/dist/core/build/static-build.js +1 -1
- package/dist/core/build/vite-plugin-css.js +0 -23
- package/dist/core/compile/compile.js +7 -23
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/index.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render/dev/index.js +0 -8
- package/dist/core/render/util.d.ts +0 -5
- package/dist/core/render/util.js +1 -47
- package/dist/core/util.d.ts +5 -1
- package/dist/core/util.js +10 -0
- package/dist/jsx/babel.js +3 -17
- package/dist/runtime/server/index.d.ts +0 -2
- package/dist/runtime/server/index.js +0 -2
- package/dist/vite-plugin-astro-postprocess/index.js +1 -24
- package/dist/vite-plugin-astro-server/index.js +12 -0
- package/dist/vite-plugin-markdown-legacy/index.js +0 -3
- package/package.json +2 -2
- package/dist/runtime/server/metadata.d.ts +0 -29
- package/dist/runtime/server/metadata.js +0 -66
package/dist/@types/astro.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { SerializedSSRManifest } from '../core/app/types';
|
|
|
10
10
|
import type { PageBuildData } from '../core/build/types';
|
|
11
11
|
import type { AstroConfigSchema } from '../core/config';
|
|
12
12
|
import type { AstroCookies } from '../core/cookies';
|
|
13
|
-
import type { AstroComponentFactory
|
|
13
|
+
import type { AstroComponentFactory } from '../runtime/server';
|
|
14
14
|
export type { MarkdownHeading, MarkdownMetadata, MarkdownRenderingResult, RehypePlugins, RemarkPlugins, ShikiConfig, } from '@astrojs/markdown-remark';
|
|
15
15
|
export type { SSRManifest } from '../core/app/types';
|
|
16
16
|
export interface AstroBuiltinProps {
|
|
@@ -889,7 +889,6 @@ export interface AstroSettings {
|
|
|
889
889
|
export declare type AsyncRendererComponentFn<U> = (Component: any, props: any, slots: Record<string, string>, metadata?: AstroComponentMetadata) => Promise<U>;
|
|
890
890
|
/** Generic interface for a component (Astro, Svelte, React, etc.) */
|
|
891
891
|
export interface ComponentInstance {
|
|
892
|
-
$$metadata: Metadata;
|
|
893
892
|
default: AstroComponentFactory;
|
|
894
893
|
css?: string[];
|
|
895
894
|
getStaticPaths?: (options: GetStaticPathsOptions) => GetStaticPathsResult;
|
package/dist/core/add/index.js
CHANGED
|
@@ -545,6 +545,7 @@ async function validateIntegrations(integrations) {
|
|
|
545
545
|
try {
|
|
546
546
|
const integrationEntries = await Promise.all(
|
|
547
547
|
integrations.map(async (integration) => {
|
|
548
|
+
var _a;
|
|
548
549
|
const parsed = parseIntegrationName(integration);
|
|
549
550
|
if (!parsed) {
|
|
550
551
|
throw new Error(`${bold(integration)} does not appear to be a valid package name!`);
|
|
@@ -594,8 +595,12 @@ async function validateIntegrations(integrations) {
|
|
|
594
595
|
[pkgJson["name"], `^${pkgJson["version"]}`]
|
|
595
596
|
];
|
|
596
597
|
if (pkgJson["peerDependencies"]) {
|
|
598
|
+
const meta = pkgJson["peerDependenciesMeta"] || {};
|
|
597
599
|
for (const peer in pkgJson["peerDependencies"]) {
|
|
598
|
-
|
|
600
|
+
const optional = ((_a = meta[peer]) == null ? void 0 : _a.optional) || false;
|
|
601
|
+
if (!optional) {
|
|
602
|
+
dependencies.push([peer, pkgJson["peerDependencies"][peer]]);
|
|
603
|
+
}
|
|
599
604
|
}
|
|
600
605
|
}
|
|
601
606
|
let integrationType;
|
|
@@ -20,7 +20,8 @@ function getOutFolder(astroConfig, pathname, routeType) {
|
|
|
20
20
|
return new URL("." + appendForwardSlash(pathname), outRoot);
|
|
21
21
|
}
|
|
22
22
|
case "file": {
|
|
23
|
-
|
|
23
|
+
const d = pathname === "" ? pathname : npath.dirname(pathname);
|
|
24
|
+
return new URL("." + appendForwardSlash(d), outRoot);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
}
|
|
@@ -22,24 +22,6 @@ import { getOutputFilename } from "../util.js";
|
|
|
22
22
|
import { getOutDirWithinCwd, getOutFile, getOutFolder } from "./common.js";
|
|
23
23
|
import { eachPageData, getPageDataByComponent, sortedCSS } from "./internal.js";
|
|
24
24
|
import { getTimeStat } from "./util.js";
|
|
25
|
-
const MAX_CONCURRENT_RENDERS = 1;
|
|
26
|
-
function* throttle(max, inPaths) {
|
|
27
|
-
let tmp = [];
|
|
28
|
-
let i = 0;
|
|
29
|
-
for (let path of inPaths) {
|
|
30
|
-
tmp.push(path);
|
|
31
|
-
if (i === max) {
|
|
32
|
-
yield tmp;
|
|
33
|
-
tmp.length = 0;
|
|
34
|
-
i = 0;
|
|
35
|
-
} else {
|
|
36
|
-
i++;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (tmp.length) {
|
|
40
|
-
yield tmp;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
25
|
function shouldSkipDraft(pageModule, settings) {
|
|
44
26
|
var _a;
|
|
45
27
|
return !settings.config.markdown.drafts && "frontmatter" in pageModule && ((_a = pageModule.frontmatter) == null ? void 0 : _a.draft) === true;
|
|
@@ -218,7 +218,7 @@ async function cleanSsrOutput(opts) {
|
|
|
218
218
|
const url = new URL(filename, out);
|
|
219
219
|
const folder = await fs.promises.readdir(url);
|
|
220
220
|
if (!folder.length) {
|
|
221
|
-
await fs.promises.
|
|
221
|
+
await fs.promises.rm(url, { recursive: true, force: true });
|
|
222
222
|
}
|
|
223
223
|
})
|
|
224
224
|
);
|
|
@@ -161,29 +161,6 @@ function rollupPluginAstroBuildCSS(options) {
|
|
|
161
161
|
});
|
|
162
162
|
output.source = minifiedCSS;
|
|
163
163
|
}
|
|
164
|
-
} else if (output.type === "chunk") {
|
|
165
|
-
for (const [imp, bindings] of Object.entries(output.importedBindings)) {
|
|
166
|
-
if (imp.startsWith("chunks/") && !bundle[imp] && output.code.includes(imp)) {
|
|
167
|
-
const depChunk = {
|
|
168
|
-
type: "chunk",
|
|
169
|
-
fileName: imp,
|
|
170
|
-
name: imp,
|
|
171
|
-
facadeModuleId: imp,
|
|
172
|
-
code: `/* Pure CSS chunk ${imp} */ ${bindings.map((b) => `export const ${b} = {};`).join("")}`,
|
|
173
|
-
dynamicImports: [],
|
|
174
|
-
implicitlyLoadedBefore: [],
|
|
175
|
-
importedBindings: {},
|
|
176
|
-
imports: [],
|
|
177
|
-
referencedFiles: [],
|
|
178
|
-
exports: Array.from(bindings),
|
|
179
|
-
isDynamicEntry: false,
|
|
180
|
-
isEntry: false,
|
|
181
|
-
isImplicitEntry: false,
|
|
182
|
-
modules: {}
|
|
183
|
-
};
|
|
184
|
-
bundle[imp] = depChunk;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
164
|
}
|
|
188
165
|
}
|
|
189
166
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import path from "path";
|
|
2
1
|
import { transform } from "@astrojs/compiler";
|
|
3
2
|
import { AstroErrorCodes } from "../errors.js";
|
|
4
|
-
import { prependForwardSlash
|
|
5
|
-
import { AggregateError,
|
|
3
|
+
import { prependForwardSlash } from "../path.js";
|
|
4
|
+
import { AggregateError, resolvePath, viteID } from "../util.js";
|
|
6
5
|
import { createStylePreprocessor } from "./style.js";
|
|
7
6
|
const configCache = /* @__PURE__ */ new WeakMap();
|
|
8
7
|
async function compile({
|
|
@@ -15,7 +14,7 @@ async function compile({
|
|
|
15
14
|
let cssDeps = /* @__PURE__ */ new Set();
|
|
16
15
|
let cssTransformErrors = [];
|
|
17
16
|
const transformResult = await transform(source, {
|
|
18
|
-
pathname:
|
|
17
|
+
pathname: filename,
|
|
19
18
|
projectRoot: config.root.toString(),
|
|
20
19
|
site: (_a = config.site) == null ? void 0 : _a.toString(),
|
|
21
20
|
sourcefile: filename,
|
|
@@ -24,7 +23,10 @@ async function compile({
|
|
|
24
23
|
viteID(new URL("../../runtime/server/index.js", import.meta.url))
|
|
25
24
|
)}`,
|
|
26
25
|
experimentalStaticExtraction: true,
|
|
27
|
-
preprocessStyle: createStylePreprocessor(transformStyle, cssDeps, cssTransformErrors)
|
|
26
|
+
preprocessStyle: createStylePreprocessor(transformStyle, cssDeps, cssTransformErrors),
|
|
27
|
+
async resolvePath(specifier) {
|
|
28
|
+
return resolvePath(specifier, filename);
|
|
29
|
+
}
|
|
28
30
|
}).catch((err) => {
|
|
29
31
|
err.code = err.code || AstroErrorCodes.UnknownCompilerError;
|
|
30
32
|
throw err;
|
|
@@ -54,24 +56,6 @@ async function compile({
|
|
|
54
56
|
value: source
|
|
55
57
|
}
|
|
56
58
|
});
|
|
57
|
-
for (const c of compileResult.clientOnlyComponents) {
|
|
58
|
-
c.resolvedPath = removeLeadingForwardSlashWindows(c.resolvedPath);
|
|
59
|
-
if (c.specifier.endsWith(".jsx") && !c.resolvedPath.endsWith(".jsx")) {
|
|
60
|
-
c.resolvedPath += ".jsx";
|
|
61
|
-
}
|
|
62
|
-
if (path.isAbsolute(c.resolvedPath)) {
|
|
63
|
-
c.resolvedPath = resolveJsToTs(c.resolvedPath);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
for (const c of compileResult.hydratedComponents) {
|
|
67
|
-
c.resolvedPath = removeLeadingForwardSlashWindows(c.resolvedPath);
|
|
68
|
-
if (c.specifier.endsWith(".jsx") && !c.resolvedPath.endsWith(".jsx")) {
|
|
69
|
-
c.resolvedPath += ".jsx";
|
|
70
|
-
}
|
|
71
|
-
if (path.isAbsolute(c.resolvedPath)) {
|
|
72
|
-
c.resolvedPath = resolveJsToTs(c.resolvedPath);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
59
|
return compileResult;
|
|
76
60
|
}
|
|
77
61
|
function isCached(config, filename) {
|
package/dist/core/constants.js
CHANGED
package/dist/core/dev/index.js
CHANGED
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function serverStart({
|
|
|
47
47
|
site,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "1.5.
|
|
50
|
+
const version = "1.5.3";
|
|
51
51
|
const rootPath = site ? site.pathname : "/";
|
|
52
52
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
53
53
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -250,7 +250,7 @@ function printHelp({
|
|
|
250
250
|
message.push(
|
|
251
251
|
linebreak(),
|
|
252
252
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
253
|
-
`v${"1.5.
|
|
253
|
+
`v${"1.5.3"}`
|
|
254
254
|
)} ${headline}`
|
|
255
255
|
);
|
|
256
256
|
}
|
|
@@ -3,7 +3,6 @@ import { PAGE_SCRIPT_ID } from "../../../vite-plugin-scripts/index.js";
|
|
|
3
3
|
import { isPage, resolveIdToUrl } from "../../util.js";
|
|
4
4
|
import { createRenderContext, renderPage as coreRenderPage } from "../index.js";
|
|
5
5
|
import { filterFoundRenderers, loadRenderer } from "../renderer.js";
|
|
6
|
-
import { collectMdMetadata } from "../util.js";
|
|
7
6
|
import { getStylesForURL } from "./css.js";
|
|
8
7
|
import { getScriptsForURL } from "./scripts.js";
|
|
9
8
|
import { createDevelopmentEnvironment } from "./environment.js";
|
|
@@ -18,13 +17,6 @@ async function preload({
|
|
|
18
17
|
}) {
|
|
19
18
|
const renderers = await loadRenderers(env.viteServer, env.settings);
|
|
20
19
|
const mod = await env.viteServer.ssrLoadModule(fileURLToPath(filePath));
|
|
21
|
-
if (env.viteServer.config.mode === "development" || !(mod == null ? void 0 : mod.$$metadata)) {
|
|
22
|
-
return [renderers, mod];
|
|
23
|
-
}
|
|
24
|
-
const modGraph = await env.viteServer.moduleGraph.getModuleByUrl(fileURLToPath(filePath));
|
|
25
|
-
if (modGraph) {
|
|
26
|
-
await collectMdMetadata(mod.$$metadata, modGraph, env.viteServer);
|
|
27
|
-
}
|
|
28
20
|
return [renderers, mod];
|
|
29
21
|
}
|
|
30
22
|
async function getScriptsAndStyles({ env, filePath }) {
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import type { ModuleNode, ViteDevServer } from 'vite';
|
|
2
|
-
import type { Metadata } from '../../runtime/server/metadata.js';
|
|
3
|
-
/** Check if a URL is already valid */
|
|
4
|
-
export declare function isValidURL(url: string): boolean;
|
|
5
1
|
export declare const STYLE_EXTENSIONS: Set<string>;
|
|
6
2
|
export declare const isCSSRequest: (request: string) => boolean;
|
|
7
|
-
export declare function collectMdMetadata(metadata: Metadata, modGraph: ModuleNode, viteServer: ViteDevServer): Promise<void>;
|
package/dist/core/render/util.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
function isValidURL(url) {
|
|
2
|
-
try {
|
|
3
|
-
new URL(url);
|
|
4
|
-
return true;
|
|
5
|
-
} catch (e) {
|
|
6
|
-
}
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
1
|
const STYLE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
10
2
|
".css",
|
|
11
3
|
".pcss",
|
|
@@ -16,49 +8,11 @@ const STYLE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
16
8
|
".stylus",
|
|
17
9
|
".less"
|
|
18
10
|
]);
|
|
19
|
-
const MARKDOWN_IMPORT_FLAG = "?mdImport";
|
|
20
11
|
const cssRe = new RegExp(
|
|
21
12
|
`\\.(${Array.from(STYLE_EXTENSIONS).map((s) => s.slice(1)).join("|")})($|\\?)`
|
|
22
13
|
);
|
|
23
14
|
const isCSSRequest = (request) => cssRe.test(request);
|
|
24
|
-
const seenMdMetadata = /* @__PURE__ */ new Set();
|
|
25
|
-
async function collectMdMetadata(metadata, modGraph, viteServer) {
|
|
26
|
-
const importedModules = [...(modGraph == null ? void 0 : modGraph.importedModules) ?? []];
|
|
27
|
-
await Promise.all(
|
|
28
|
-
importedModules.map(async (importedModule) => {
|
|
29
|
-
var _a, _b;
|
|
30
|
-
if (!importedModule.id || seenMdMetadata.has(importedModule.id))
|
|
31
|
-
return;
|
|
32
|
-
seenMdMetadata.add(importedModule.id);
|
|
33
|
-
await collectMdMetadata(metadata, importedModule, viteServer);
|
|
34
|
-
if (!((_a = importedModule == null ? void 0 : importedModule.id) == null ? void 0 : _a.endsWith(MARKDOWN_IMPORT_FLAG)))
|
|
35
|
-
return;
|
|
36
|
-
const mdSSRMod = await viteServer.ssrLoadModule(importedModule.id);
|
|
37
|
-
const mdMetadata = await ((_b = mdSSRMod.$$loadMetadata) == null ? void 0 : _b.call(mdSSRMod));
|
|
38
|
-
if (!mdMetadata)
|
|
39
|
-
return;
|
|
40
|
-
for (let mdMod of mdMetadata.modules) {
|
|
41
|
-
mdMod.specifier = mdMetadata.resolvePath(mdMod.specifier);
|
|
42
|
-
metadata.modules.push(mdMod);
|
|
43
|
-
}
|
|
44
|
-
for (let mdHoisted of mdMetadata.hoisted) {
|
|
45
|
-
metadata.hoisted.push(mdHoisted);
|
|
46
|
-
}
|
|
47
|
-
for (let mdHydrated of mdMetadata.hydratedComponents) {
|
|
48
|
-
metadata.hydratedComponents.push(mdHydrated);
|
|
49
|
-
}
|
|
50
|
-
for (let mdClientOnly of mdMetadata.clientOnlyComponents) {
|
|
51
|
-
metadata.clientOnlyComponents.push(mdClientOnly);
|
|
52
|
-
}
|
|
53
|
-
for (let mdHydrationDirective of mdMetadata.hydrationDirectives) {
|
|
54
|
-
metadata.hydrationDirectives.add(mdHydrationDirective);
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
15
|
export {
|
|
60
16
|
STYLE_EXTENSIONS,
|
|
61
|
-
|
|
62
|
-
isCSSRequest,
|
|
63
|
-
isValidURL
|
|
17
|
+
isCSSRequest
|
|
64
18
|
};
|
package/dist/core/util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ErrorPayload, ViteDevServer } from 'vite';
|
|
2
2
|
import type { AstroConfig, AstroSettings, RouteType } from '../@types/astro';
|
|
3
3
|
/** Returns true if argument is an object of any prototype/class (but not null). */
|
|
4
4
|
export declare function isObject(value: unknown): value is Record<string, any>;
|
|
@@ -45,4 +45,8 @@ export declare function getLocalAddress(serverAddress: string, host: string | bo
|
|
|
45
45
|
*/
|
|
46
46
|
export declare function resolveIdToUrl(viteServer: ViteDevServer, id: string): Promise<string>;
|
|
47
47
|
export declare function resolveJsToTs(filePath: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Resolve the hydration paths so that it can be imported in the client
|
|
50
|
+
*/
|
|
51
|
+
export declare function resolvePath(specifier: string, importer: string): string;
|
|
48
52
|
export declare const AggregateError: any;
|
package/dist/core/util.js
CHANGED
|
@@ -4,6 +4,7 @@ import path from "path";
|
|
|
4
4
|
import resolve from "resolve";
|
|
5
5
|
import slash from "slash";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
7
|
+
import { normalizePath } from "vite";
|
|
7
8
|
import { prependForwardSlash, removeTrailingForwardSlash } from "./path.js";
|
|
8
9
|
function isObject(value) {
|
|
9
10
|
return typeof value === "object" && value != null;
|
|
@@ -169,6 +170,14 @@ function resolveJsToTs(filePath) {
|
|
|
169
170
|
}
|
|
170
171
|
return filePath;
|
|
171
172
|
}
|
|
173
|
+
function resolvePath(specifier, importer) {
|
|
174
|
+
if (specifier.startsWith(".")) {
|
|
175
|
+
const absoluteSpecifier = path.resolve(path.dirname(importer), specifier);
|
|
176
|
+
return resolveJsToTs(normalizePath(absoluteSpecifier));
|
|
177
|
+
} else {
|
|
178
|
+
return specifier;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
172
181
|
const AggregateError = typeof globalThis.AggregateError !== "undefined" ? globalThis.AggregateError : class extends Error {
|
|
173
182
|
constructor(errors, message) {
|
|
174
183
|
super(message);
|
|
@@ -196,6 +205,7 @@ export {
|
|
|
196
205
|
resolveIdToUrl,
|
|
197
206
|
resolveJsToTs,
|
|
198
207
|
resolvePages,
|
|
208
|
+
resolvePath,
|
|
199
209
|
unwrapId,
|
|
200
210
|
viteID
|
|
201
211
|
};
|
package/dist/jsx/babel.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import * as t from "@babel/types";
|
|
2
|
-
import
|
|
3
|
-
import { normalizePath } from "vite";
|
|
4
|
-
import { resolveJsToTs } from "../core/util.js";
|
|
2
|
+
import { resolvePath } from "../core/util.js";
|
|
5
3
|
import { HydrationDirectiveProps } from "../runtime/server/hydration.js";
|
|
6
4
|
const ClientOnlyPlaceholder = "astro-client-only";
|
|
7
5
|
function isComponent(tagName) {
|
|
@@ -194,13 +192,7 @@ function astroJSX() {
|
|
|
194
192
|
}
|
|
195
193
|
const meta = path.getData("import");
|
|
196
194
|
if (meta) {
|
|
197
|
-
|
|
198
|
-
if (meta.path.startsWith(".")) {
|
|
199
|
-
resolvedPath = normalizePath(npath.resolve(npath.dirname(state.filename), meta.path));
|
|
200
|
-
resolvedPath = resolveJsToTs(resolvedPath);
|
|
201
|
-
} else {
|
|
202
|
-
resolvedPath = meta.path;
|
|
203
|
-
}
|
|
195
|
+
const resolvedPath = resolvePath(meta.path, state.filename);
|
|
204
196
|
if (isClientOnly) {
|
|
205
197
|
state.file.metadata.astro.clientOnlyComponents.push({
|
|
206
198
|
exportName: meta.name,
|
|
@@ -270,13 +262,7 @@ function astroJSX() {
|
|
|
270
262
|
}
|
|
271
263
|
}
|
|
272
264
|
}
|
|
273
|
-
|
|
274
|
-
if (meta.path.startsWith(".")) {
|
|
275
|
-
resolvedPath = normalizePath(npath.resolve(npath.dirname(state.filename), meta.path));
|
|
276
|
-
resolvedPath = resolveJsToTs(resolvedPath);
|
|
277
|
-
} else {
|
|
278
|
-
resolvedPath = meta.path;
|
|
279
|
-
}
|
|
265
|
+
const resolvedPath = resolvePath(meta.path, state.filename);
|
|
280
266
|
if (isClientOnly) {
|
|
281
267
|
state.file.metadata.astro.clientOnlyComponents.push({
|
|
282
268
|
exportName: meta.name,
|
|
@@ -2,8 +2,6 @@ export { createAstro } from './astro-global.js';
|
|
|
2
2
|
export { renderEndpoint } from './endpoint.js';
|
|
3
3
|
export { escapeHTML, HTMLBytes, HTMLString, markHTMLString, unescapeHTML } from './escape.js';
|
|
4
4
|
export { renderJSX } from './jsx.js';
|
|
5
|
-
export type { Metadata } from './metadata';
|
|
6
|
-
export { createMetadata } from './metadata.js';
|
|
7
5
|
export { addAttribute, defineScriptVars, Fragment, maybeRenderHead, renderAstroComponent, renderComponent, Renderer as Renderer, renderHead, renderHTMLElement, renderPage, renderSlot, renderTemplate as render, renderTemplate, renderToString, stringifyChunk, voidElementNames, } from './render/index.js';
|
|
8
6
|
export type { AstroComponentFactory, RenderInstruction } from './render/index.js';
|
|
9
7
|
import type { AstroComponentFactory } from './render/index.js';
|
|
@@ -2,7 +2,6 @@ import { createAstro } from "./astro-global.js";
|
|
|
2
2
|
import { renderEndpoint } from "./endpoint.js";
|
|
3
3
|
import { escapeHTML, HTMLBytes, HTMLString, markHTMLString, unescapeHTML } from "./escape.js";
|
|
4
4
|
import { renderJSX } from "./jsx.js";
|
|
5
|
-
import { createMetadata } from "./metadata.js";
|
|
6
5
|
import {
|
|
7
6
|
addAttribute,
|
|
8
7
|
defineScriptVars,
|
|
@@ -89,7 +88,6 @@ export {
|
|
|
89
88
|
addAttribute,
|
|
90
89
|
createAstro,
|
|
91
90
|
createComponent,
|
|
92
|
-
createMetadata,
|
|
93
91
|
defineScriptVars,
|
|
94
92
|
defineStyleVars,
|
|
95
93
|
escapeHTML,
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { parse as babelParser } from "@babel/parser";
|
|
2
|
-
import npath from "path";
|
|
3
2
|
import { parse, print, types, visit } from "recast";
|
|
4
|
-
import { removeLeadingForwardSlashWindows } from "../core/path.js";
|
|
5
|
-
import { resolveJsToTs } from "../core/util.js";
|
|
6
3
|
const ASTRO_GLOB_REGEX = /Astro2?\s*\.\s*glob\s*\(/;
|
|
7
|
-
const CLIENT_COMPONENT_PATH_REGEX = /['"]client:component-path['"]:/;
|
|
8
|
-
const validAstroGlobalNames = /* @__PURE__ */ new Set(["Astro", "Astro2"]);
|
|
9
4
|
function astro(_opts) {
|
|
10
5
|
return {
|
|
11
6
|
name: "astro:postprocess",
|
|
@@ -13,7 +8,7 @@ function astro(_opts) {
|
|
|
13
8
|
if (!id.endsWith(".astro") && !id.endsWith(".md")) {
|
|
14
9
|
return null;
|
|
15
10
|
}
|
|
16
|
-
if (!ASTRO_GLOB_REGEX.test(code)
|
|
11
|
+
if (!ASTRO_GLOB_REGEX.test(code)) {
|
|
17
12
|
return null;
|
|
18
13
|
}
|
|
19
14
|
const ast = parse(code, {
|
|
@@ -49,24 +44,6 @@ function astro(_opts) {
|
|
|
49
44
|
}
|
|
50
45
|
);
|
|
51
46
|
return false;
|
|
52
|
-
},
|
|
53
|
-
visitObjectProperty: function(path) {
|
|
54
|
-
if (!types.namedTypes.StringLiteral.check(path.node.key) || path.node.key.value !== "client:component-path" || !types.namedTypes.StringLiteral.check(path.node.value)) {
|
|
55
|
-
this.traverse(path);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const valuePath = path.get("value");
|
|
59
|
-
let value = valuePath.value.value;
|
|
60
|
-
value = removeLeadingForwardSlashWindows(value);
|
|
61
|
-
if (code.includes(npath.basename(value) + ".jsx")) {
|
|
62
|
-
value += ".jsx";
|
|
63
|
-
}
|
|
64
|
-
value = resolveJsToTs(value);
|
|
65
|
-
valuePath.replace({
|
|
66
|
-
type: "StringLiteral",
|
|
67
|
-
value
|
|
68
|
-
});
|
|
69
|
-
return false;
|
|
70
47
|
}
|
|
71
48
|
});
|
|
72
49
|
const result = print(ast);
|
|
@@ -212,6 +212,16 @@ async function handleRequest(env, manifest, req, res) {
|
|
|
212
212
|
handle500Response(viteServer, origin, req, res, errorWithMetadata);
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
+
function isRedirect(statusCode) {
|
|
216
|
+
return statusCode >= 300 && statusCode < 400;
|
|
217
|
+
}
|
|
218
|
+
function throwIfRedirectNotAllowed(response, config) {
|
|
219
|
+
if (config.output !== "server" && isRedirect(response.status)) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
`Redirects are only available when using output: 'server'. Update your Astro config if you need SSR features.`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
215
225
|
async function handleRoute(matchedRoute, url, pathname, body, origin, env, manifest, req, res) {
|
|
216
226
|
const { logging, settings } = env;
|
|
217
227
|
if (!matchedRoute) {
|
|
@@ -264,6 +274,7 @@ async function handleRoute(matchedRoute, url, pathname, body, origin, env, manif
|
|
|
264
274
|
res
|
|
265
275
|
);
|
|
266
276
|
}
|
|
277
|
+
throwIfRedirectNotAllowed(result.response, config);
|
|
267
278
|
await writeWebResponse(res, result.response);
|
|
268
279
|
} else {
|
|
269
280
|
let contentType = "text/plain";
|
|
@@ -283,6 +294,7 @@ async function handleRoute(matchedRoute, url, pathname, body, origin, env, manif
|
|
|
283
294
|
}
|
|
284
295
|
} else {
|
|
285
296
|
const result = await renderPage(options);
|
|
297
|
+
throwIfRedirectNotAllowed(result, config);
|
|
286
298
|
return await writeSSRResult(result, res);
|
|
287
299
|
}
|
|
288
300
|
}
|
|
@@ -86,9 +86,6 @@ function markdown({ settings }) {
|
|
|
86
86
|
export async function compiledContent() {
|
|
87
87
|
return load().then((m) => m.compiledContent());
|
|
88
88
|
}
|
|
89
|
-
export function $$loadMetadata() {
|
|
90
|
-
return load().then((m) => m.$$metadata);
|
|
91
|
-
}
|
|
92
89
|
|
|
93
90
|
// Deferred
|
|
94
91
|
export default async function load() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3",
|
|
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",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"vendor"
|
|
86
86
|
],
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@astrojs/compiler": "^0.
|
|
88
|
+
"@astrojs/compiler": "^0.28.0",
|
|
89
89
|
"@astrojs/language-server": "^0.26.2",
|
|
90
90
|
"@astrojs/markdown-remark": "^1.1.3",
|
|
91
91
|
"@astrojs/telemetry": "^1.0.1",
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
interface ModuleInfo {
|
|
2
|
-
module: Record<string, any>;
|
|
3
|
-
specifier: string;
|
|
4
|
-
}
|
|
5
|
-
interface CreateMetadataOptions {
|
|
6
|
-
modules: ModuleInfo[];
|
|
7
|
-
hydratedComponents: any[];
|
|
8
|
-
clientOnlyComponents: any[];
|
|
9
|
-
hydrationDirectives: Set<string>;
|
|
10
|
-
hoisted: any[];
|
|
11
|
-
}
|
|
12
|
-
export declare class Metadata {
|
|
13
|
-
filePath: string;
|
|
14
|
-
modules: ModuleInfo[];
|
|
15
|
-
hoisted: any[];
|
|
16
|
-
hydratedComponents: any[];
|
|
17
|
-
clientOnlyComponents: any[];
|
|
18
|
-
hydrationDirectives: Set<string>;
|
|
19
|
-
private mockURL;
|
|
20
|
-
private metadataCache;
|
|
21
|
-
constructor(filePathname: string, opts: CreateMetadataOptions);
|
|
22
|
-
resolvePath(specifier: string): string;
|
|
23
|
-
getPath(Component: any): string | null;
|
|
24
|
-
getExport(Component: any): string | null;
|
|
25
|
-
private getComponentMetadata;
|
|
26
|
-
private findComponentMetadata;
|
|
27
|
-
}
|
|
28
|
-
export declare function createMetadata(filePathname: string, options: CreateMetadataOptions): Metadata;
|
|
29
|
-
export {};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { removeLeadingForwardSlashWindows } from "../../core/path.js";
|
|
2
|
-
class Metadata {
|
|
3
|
-
constructor(filePathname, opts) {
|
|
4
|
-
this.modules = opts.modules;
|
|
5
|
-
this.hoisted = opts.hoisted;
|
|
6
|
-
this.hydratedComponents = opts.hydratedComponents;
|
|
7
|
-
this.clientOnlyComponents = opts.clientOnlyComponents;
|
|
8
|
-
this.hydrationDirectives = opts.hydrationDirectives;
|
|
9
|
-
this.filePath = removeLeadingForwardSlashWindows(filePathname);
|
|
10
|
-
this.mockURL = new URL(filePathname, "http://example.com");
|
|
11
|
-
this.metadataCache = /* @__PURE__ */ new Map();
|
|
12
|
-
}
|
|
13
|
-
resolvePath(specifier) {
|
|
14
|
-
if (specifier.startsWith(".")) {
|
|
15
|
-
const url = new URL(specifier, this.mockURL);
|
|
16
|
-
return removeLeadingForwardSlashWindows(decodeURI(url.pathname));
|
|
17
|
-
} else {
|
|
18
|
-
return specifier;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
getPath(Component) {
|
|
22
|
-
const metadata = this.getComponentMetadata(Component);
|
|
23
|
-
return (metadata == null ? void 0 : metadata.componentUrl) || null;
|
|
24
|
-
}
|
|
25
|
-
getExport(Component) {
|
|
26
|
-
const metadata = this.getComponentMetadata(Component);
|
|
27
|
-
return (metadata == null ? void 0 : metadata.componentExport) || null;
|
|
28
|
-
}
|
|
29
|
-
getComponentMetadata(Component) {
|
|
30
|
-
if (this.metadataCache.has(Component)) {
|
|
31
|
-
return this.metadataCache.get(Component);
|
|
32
|
-
}
|
|
33
|
-
const metadata = this.findComponentMetadata(Component);
|
|
34
|
-
this.metadataCache.set(Component, metadata);
|
|
35
|
-
return metadata;
|
|
36
|
-
}
|
|
37
|
-
findComponentMetadata(Component) {
|
|
38
|
-
const isCustomElement = typeof Component === "string";
|
|
39
|
-
for (const { module, specifier } of this.modules) {
|
|
40
|
-
const id = this.resolvePath(specifier);
|
|
41
|
-
for (const [key, value] of Object.entries(module)) {
|
|
42
|
-
if (isCustomElement) {
|
|
43
|
-
if (key === "tagName" && Component === value) {
|
|
44
|
-
return {
|
|
45
|
-
componentExport: key,
|
|
46
|
-
componentUrl: id
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
} else if (Component === value) {
|
|
50
|
-
return {
|
|
51
|
-
componentExport: key,
|
|
52
|
-
componentUrl: id
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function createMetadata(filePathname, options) {
|
|
61
|
-
return new Metadata(filePathname, options);
|
|
62
|
-
}
|
|
63
|
-
export {
|
|
64
|
-
Metadata,
|
|
65
|
-
createMetadata
|
|
66
|
-
};
|