astro 1.2.3 → 1.2.5
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 +3 -0
- package/dist/core/app/index.js +16 -1
- package/dist/core/build/common.d.ts +6 -0
- package/dist/core/build/common.js +10 -0
- package/dist/core/build/generate.js +3 -3
- package/dist/core/build/static-build.js +9 -3
- package/dist/core/build/vite-plugin-ssr.js +1 -1
- package/dist/core/config.js +13 -0
- package/dist/core/dev/index.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/util.js +1 -1
- package/dist/runtime/server/astro-global.js +1 -1
- package/dist/runtime/server/astro-island.js +4 -1
- package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt.js +1 -1
- package/dist/runtime/server/endpoint.d.ts +1 -1
- package/dist/runtime/server/endpoint.js +7 -3
- package/dist/runtime/server/hydration.js +4 -1
- package/dist/runtime/server/jsx.js +1 -0
- package/dist/vite-plugin-astro/index.js +2 -2
- package/dist/vite-plugin-astro-server/index.js +146 -104
- package/dist/vite-plugin-config-alias/index.js +7 -12
- package/dist/vite-plugin-jsx/index.js +5 -0
- package/dist/vite-style-transform/style-transform.d.ts +1 -1
- package/dist/vite-style-transform/style-transform.js +0 -4
- package/dist/vite-style-transform/transform-with-vite.js +3 -1
- package/package.json +3 -3
package/dist/@types/astro.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import type { MarkdownHeading, MarkdownMetadata, MarkdownRenderingResult, RehypePlugins, RemarkPlugins, RemarkRehype, ShikiConfig } from '@astrojs/markdown-remark';
|
|
4
4
|
import type * as babel from '@babel/core';
|
|
5
5
|
import type { AddressInfo } from 'net';
|
|
6
|
+
import type { TsConfigJson } from 'tsconfig-resolver';
|
|
6
7
|
import type * as vite from 'vite';
|
|
7
8
|
import { z } from 'zod';
|
|
8
9
|
import type { SerializedSSRManifest } from '../core/app/types';
|
|
@@ -803,6 +804,8 @@ export interface InjectedRoute {
|
|
|
803
804
|
export interface AstroConfig extends z.output<typeof AstroConfigSchema> {
|
|
804
805
|
integrations: AstroIntegration[];
|
|
805
806
|
_ctx: {
|
|
807
|
+
tsConfig: TsConfigJson | undefined;
|
|
808
|
+
tsConfigPath: string | undefined;
|
|
806
809
|
pageExtensions: string[];
|
|
807
810
|
injectedRoutes: InjectedRoute[];
|
|
808
811
|
adapter: AstroAdapter | undefined;
|
package/dist/core/app/index.js
CHANGED
|
@@ -156,7 +156,15 @@ renderPage_fn = async function(request, routeData, mod, status = 200) {
|
|
|
156
156
|
throw new Error(`Unable to resolve [${specifier}]`);
|
|
157
157
|
}
|
|
158
158
|
const bundlePath = manifest.entryModules[specifier];
|
|
159
|
-
|
|
159
|
+
switch (true) {
|
|
160
|
+
case bundlePath.startsWith("data:"):
|
|
161
|
+
case bundlePath.length === 0: {
|
|
162
|
+
return bundlePath;
|
|
163
|
+
}
|
|
164
|
+
default: {
|
|
165
|
+
return prependForwardSlash(joinPaths(manifest.base, bundlePath));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
160
168
|
},
|
|
161
169
|
route: routeData,
|
|
162
170
|
routeCache: __privateGet(this, _routeCache),
|
|
@@ -190,6 +198,13 @@ callEndpoint_fn = async function(request, routeData, mod, status = 200) {
|
|
|
190
198
|
status
|
|
191
199
|
});
|
|
192
200
|
if (result.type === "response") {
|
|
201
|
+
if (result.response.headers.get("X-Astro-Response") === "Not-Found") {
|
|
202
|
+
const fourOhFourRequest = new Request(new URL("/404", request.url));
|
|
203
|
+
const fourOhFourRouteData = this.match(fourOhFourRequest);
|
|
204
|
+
if (fourOhFourRouteData) {
|
|
205
|
+
return this.render(fourOhFourRequest, fourOhFourRouteData);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
193
208
|
return result.response;
|
|
194
209
|
} else {
|
|
195
210
|
const body = result.body;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { AstroConfig, RouteType } from '../../@types/astro';
|
|
2
2
|
export declare function getOutFolder(astroConfig: AstroConfig, pathname: string, routeType: RouteType): URL;
|
|
3
3
|
export declare function getOutFile(astroConfig: AstroConfig, outFolder: URL, pathname: string, routeType: RouteType): URL;
|
|
4
|
+
/**
|
|
5
|
+
* Ensures the `outDir` is within `process.cwd()`. If not it will fallback to `<cwd>/.astro`.
|
|
6
|
+
* This is used for static `ssrBuild` so the output can access node_modules when we import
|
|
7
|
+
* the output files. A hardcoded fallback dir is fine as it would be cleaned up after build.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getOutDirWithinCwd(outDir: URL): URL;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import npath from "path";
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from "url";
|
|
2
3
|
import { appendForwardSlash } from "../../core/path.js";
|
|
3
4
|
const STATUS_CODE_PAGES = /* @__PURE__ */ new Set(["/404", "/500"]);
|
|
5
|
+
const FALLBACK_OUT_DIR_NAME = "./.astro/";
|
|
4
6
|
function getOutRoot(astroConfig) {
|
|
5
7
|
return new URL("./", astroConfig.outDir);
|
|
6
8
|
}
|
|
@@ -43,7 +45,15 @@ function getOutFile(astroConfig, outFolder, pathname, routeType) {
|
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
}
|
|
48
|
+
function getOutDirWithinCwd(outDir) {
|
|
49
|
+
if (fileURLToPath(outDir).startsWith(process.cwd())) {
|
|
50
|
+
return outDir;
|
|
51
|
+
} else {
|
|
52
|
+
return new URL(FALLBACK_OUT_DIR_NAME, pathToFileURL(process.cwd() + npath.sep));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
46
55
|
export {
|
|
56
|
+
getOutDirWithinCwd,
|
|
47
57
|
getOutFile,
|
|
48
58
|
getOutFolder
|
|
49
59
|
};
|
|
@@ -18,7 +18,7 @@ import { createLinkStylesheetElementSet, createModuleScriptsSet } from "../rende
|
|
|
18
18
|
import { createRequest } from "../request.js";
|
|
19
19
|
import { matchRoute } from "../routing/match.js";
|
|
20
20
|
import { getOutputFilename } from "../util.js";
|
|
21
|
-
import { getOutFile, getOutFolder } from "./common.js";
|
|
21
|
+
import { getOutDirWithinCwd, getOutFile, getOutFolder } from "./common.js";
|
|
22
22
|
import { eachPageData, getPageDataByComponent, sortedCSS } from "./internal.js";
|
|
23
23
|
import { getTimeStat } from "./util.js";
|
|
24
24
|
const MAX_CONCURRENT_RENDERS = 1;
|
|
@@ -65,7 +65,7 @@ async function generatePages(opts, internals) {
|
|
|
65
65
|
${bgGreen(black(" generating static routes "))}`);
|
|
66
66
|
const ssr = opts.astroConfig.output === "server";
|
|
67
67
|
const serverEntry = opts.buildConfig.serverEntry;
|
|
68
|
-
const outFolder = ssr ? opts.buildConfig.server : opts.astroConfig.outDir;
|
|
68
|
+
const outFolder = ssr ? opts.buildConfig.server : getOutDirWithinCwd(opts.astroConfig.outDir);
|
|
69
69
|
const ssrEntryURL = new URL("./" + serverEntry + `?time=${Date.now()}`, outFolder);
|
|
70
70
|
const ssrEntry = await import(ssrEntryURL.toString());
|
|
71
71
|
const builtPaths = /* @__PURE__ */ new Set();
|
|
@@ -246,7 +246,7 @@ async function generatePath(pathname, opts, gopts) {
|
|
|
246
246
|
const hashedFilePath = internals.entrySpecifierToBundleMap.get(specifier);
|
|
247
247
|
if (typeof hashedFilePath !== "string") {
|
|
248
248
|
if (specifier === BEFORE_HYDRATION_SCRIPT_ID) {
|
|
249
|
-
return "
|
|
249
|
+
return "";
|
|
250
250
|
}
|
|
251
251
|
throw new Error(`Cannot find the built path for ${specifier}`);
|
|
252
252
|
}
|
|
@@ -9,6 +9,7 @@ import { emptyDir, isModeServerWithNoAdapter, removeDir } from "../../core/util.
|
|
|
9
9
|
import { runHookBuildSetup } from "../../integrations/index.js";
|
|
10
10
|
import { PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
11
11
|
import { info } from "../logger/core.js";
|
|
12
|
+
import { getOutDirWithinCwd } from "./common.js";
|
|
12
13
|
import { generatePages } from "./generate.js";
|
|
13
14
|
import { trackPageData } from "./internal.js";
|
|
14
15
|
import { getTimeStat } from "./util.js";
|
|
@@ -78,7 +79,7 @@ async function ssrBuild(opts, internals, input) {
|
|
|
78
79
|
var _a, _b, _c;
|
|
79
80
|
const { astroConfig, viteConfig } = opts;
|
|
80
81
|
const ssr = astroConfig.output === "server";
|
|
81
|
-
const out = ssr ? opts.buildConfig.server : astroConfig.outDir;
|
|
82
|
+
const out = ssr ? opts.buildConfig.server : getOutDirWithinCwd(astroConfig.outDir);
|
|
82
83
|
const viteBuildConfig = {
|
|
83
84
|
...viteConfig,
|
|
84
85
|
logLevel: opts.viteConfig.logLevel ?? "error",
|
|
@@ -195,12 +196,17 @@ ${bgGreen(black(" building client "))}`);
|
|
|
195
196
|
return buildResult;
|
|
196
197
|
}
|
|
197
198
|
async function cleanSsrOutput(opts) {
|
|
199
|
+
const out = getOutDirWithinCwd(opts.astroConfig.outDir);
|
|
200
|
+
if (out.toString() !== opts.astroConfig.outDir.toString()) {
|
|
201
|
+
await fs.promises.rm(out, { recursive: true });
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
198
204
|
const files = await glob("**/*.mjs", {
|
|
199
|
-
cwd: fileURLToPath(
|
|
205
|
+
cwd: fileURLToPath(out)
|
|
200
206
|
});
|
|
201
207
|
await Promise.all(
|
|
202
208
|
files.map(async (filename) => {
|
|
203
|
-
const url = new URL(filename,
|
|
209
|
+
const url = new URL(filename, out);
|
|
204
210
|
await fs.promises.rm(url);
|
|
205
211
|
})
|
|
206
212
|
);
|
|
@@ -119,7 +119,7 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
if (!(BEFORE_HYDRATION_SCRIPT_ID in entryModules)) {
|
|
122
|
-
entryModules[BEFORE_HYDRATION_SCRIPT_ID] = "
|
|
122
|
+
entryModules[BEFORE_HYDRATION_SCRIPT_ID] = "";
|
|
123
123
|
}
|
|
124
124
|
const ssrManifest = {
|
|
125
125
|
adapterName: opts.astroConfig._ctx.adapter.name,
|
package/dist/core/config.js
CHANGED
|
@@ -5,6 +5,7 @@ import * as colors from "kleur/colors";
|
|
|
5
5
|
import path from "path";
|
|
6
6
|
import postcssrc from "postcss-load-config";
|
|
7
7
|
import { BUNDLED_THEMES } from "shiki";
|
|
8
|
+
import * as tsr from "tsconfig-resolver";
|
|
8
9
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
9
10
|
import * as vite from "vite";
|
|
10
11
|
import { mergeConfig as mergeViteConfig } from "vite";
|
|
@@ -203,10 +204,13 @@ See https://astro.build/config for more information.`
|
|
|
203
204
|
)
|
|
204
205
|
}).optional().default({})
|
|
205
206
|
});
|
|
207
|
+
const tsconfig = loadTSConfig(root);
|
|
206
208
|
const result = {
|
|
207
209
|
...await AstroConfigRelativeSchema.parseAsync(userConfig),
|
|
208
210
|
_ctx: {
|
|
209
211
|
pageExtensions: [".astro", ".md", ".html"],
|
|
212
|
+
tsConfig: tsconfig == null ? void 0 : tsconfig.config,
|
|
213
|
+
tsConfigPath: tsconfig == null ? void 0 : tsconfig.path,
|
|
210
214
|
scripts: [],
|
|
211
215
|
renderers: [jsxRenderer],
|
|
212
216
|
injectedRoutes: [],
|
|
@@ -346,6 +350,15 @@ async function tryLoadConfig(configOptions, flags, root) {
|
|
|
346
350
|
await finallyCleanup();
|
|
347
351
|
}
|
|
348
352
|
}
|
|
353
|
+
function loadTSConfig(cwd) {
|
|
354
|
+
for (const searchName of ["tsconfig.json", "jsconfig.json"]) {
|
|
355
|
+
const config = tsr.tsconfigResolverSync({ cwd, searchName });
|
|
356
|
+
if (config.exists) {
|
|
357
|
+
return config;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return void 0;
|
|
361
|
+
}
|
|
349
362
|
async function loadConfig(configOptions) {
|
|
350
363
|
const root = resolveRoot(configOptions.cwd);
|
|
351
364
|
const flags = resolveFlags(configOptions.flags || {});
|
package/dist/core/dev/index.js
CHANGED
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function devStart({
|
|
|
47
47
|
site,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "1.2.
|
|
50
|
+
const version = "1.2.5";
|
|
51
51
|
const rootPath = site ? site.pathname : "/";
|
|
52
52
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
53
53
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -226,7 +226,7 @@ function printHelp({
|
|
|
226
226
|
message.push(
|
|
227
227
|
linebreak(),
|
|
228
228
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
229
|
-
`v${"1.2.
|
|
229
|
+
`v${"1.2.5"}`
|
|
230
230
|
)} ${headline}`
|
|
231
231
|
);
|
|
232
232
|
}
|
package/dist/core/util.js
CHANGED
|
@@ -5,7 +5,7 @@ import resolve from "resolve";
|
|
|
5
5
|
import slash from "slash";
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
7
7
|
import { prependForwardSlash, removeTrailingForwardSlash } from "./path.js";
|
|
8
|
-
const ASTRO_VERSION = "1.2.
|
|
8
|
+
const ASTRO_VERSION = "1.2.5";
|
|
9
9
|
function isObject(value) {
|
|
10
10
|
return typeof value === "object" && value != null;
|
|
11
11
|
}
|
|
@@ -63,7 +63,10 @@ var _a;
|
|
|
63
63
|
}
|
|
64
64
|
async childrenConnectedCallback() {
|
|
65
65
|
window.addEventListener("astro:hydrate", this.hydrate);
|
|
66
|
-
|
|
66
|
+
let beforeHydrationUrl = this.getAttribute("before-hydration-url");
|
|
67
|
+
if (beforeHydrationUrl) {
|
|
68
|
+
await import(beforeHydrationUrl);
|
|
69
|
+
}
|
|
67
70
|
this.start();
|
|
68
71
|
}
|
|
69
72
|
start() {
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* Do not edit this directly, but instead edit that file and rerun the prebuild
|
|
4
4
|
* to generate this file.
|
|
5
5
|
*/
|
|
6
|
-
declare const _default: "var l;{const c={0:t=>t,1:t=>JSON.parse(t,o),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,o)),5:t=>new Set(JSON.parse(t,o)),6:t=>BigInt(t),7:t=>new URL(t)},o=(t,
|
|
6
|
+
declare const _default: "var l;{const c={0:t=>t,1:t=>JSON.parse(t,o),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,o)),5:t=>new Set(JSON.parse(t,o)),6:t=>BigInt(t),7:t=>new URL(t)},o=(t,s)=>{if(t===\"\"||!Array.isArray(s))return s;const[e,n]=s;return e in c?c[e](n):void 0};customElements.get(\"astro-island\")||customElements.define(\"astro-island\",(l=class extends HTMLElement{constructor(){super(...arguments);this.hydrate=()=>{if(!this.hydrator||this.parentElement&&this.parentElement.closest(\"astro-island[ssr]\"))return;const s=this.querySelectorAll(\"astro-slot\"),e={},n=this.querySelectorAll(\"template[data-astro-template]\");for(const r of n){const i=r.closest(this.tagName);!i||!i.isSameNode(this)||(e[r.getAttribute(\"data-astro-template\")||\"default\"]=r.innerHTML,r.remove())}for(const r of s){const i=r.closest(this.tagName);!i||!i.isSameNode(this)||(e[r.getAttribute(\"name\")||\"default\"]=r.innerHTML)}const a=this.hasAttribute(\"props\")?JSON.parse(this.getAttribute(\"props\"),o):{};this.hydrator(this)(this.Component,a,e,{client:this.getAttribute(\"client\")}),this.removeAttribute(\"ssr\"),window.removeEventListener(\"astro:hydrate\",this.hydrate),window.dispatchEvent(new CustomEvent(\"astro:hydrate\"))}}connectedCallback(){!this.hasAttribute(\"await-children\")||this.firstChild?this.childrenConnectedCallback():new MutationObserver((s,e)=>{e.disconnect(),this.childrenConnectedCallback()}).observe(this,{childList:!0})}async childrenConnectedCallback(){window.addEventListener(\"astro:hydrate\",this.hydrate);let s=this.getAttribute(\"before-hydration-url\");s&&await import(s),this.start()}start(){const s=JSON.parse(this.getAttribute(\"opts\")),e=this.getAttribute(\"client\");if(Astro[e]===void 0){window.addEventListener(`astro:${e}`,()=>this.start(),{once:!0});return}Astro[e](async()=>{const n=this.getAttribute(\"renderer-url\"),[a,{default:r}]=await Promise.all([import(this.getAttribute(\"component-url\")),n?import(n):()=>()=>{}]),i=this.getAttribute(\"component-export\")||\"default\";if(!i.includes(\".\"))this.Component=a[i];else{this.Component=a;for(const d of i.split(\".\"))this.Component=this.Component[d]}return this.hydrator=r,this.hydrate},s,this)}attributeChangedCallback(){this.hydrator&&this.hydrate()}},l.observedAttributes=[\"props\"],l))}";
|
|
7
7
|
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var astro_island_prebuilt_default = `var l;{const c={0:t=>t,1:t=>JSON.parse(t,o),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,o)),5:t=>new Set(JSON.parse(t,o)),6:t=>BigInt(t),7:t=>new URL(t)},o=(t,
|
|
1
|
+
var astro_island_prebuilt_default = `var l;{const c={0:t=>t,1:t=>JSON.parse(t,o),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,o)),5:t=>new Set(JSON.parse(t,o)),6:t=>BigInt(t),7:t=>new URL(t)},o=(t,s)=>{if(t===""||!Array.isArray(s))return s;const[e,n]=s;return e in c?c[e](n):void 0};customElements.get("astro-island")||customElements.define("astro-island",(l=class extends HTMLElement{constructor(){super(...arguments);this.hydrate=()=>{if(!this.hydrator||this.parentElement&&this.parentElement.closest("astro-island[ssr]"))return;const s=this.querySelectorAll("astro-slot"),e={},n=this.querySelectorAll("template[data-astro-template]");for(const r of n){const i=r.closest(this.tagName);!i||!i.isSameNode(this)||(e[r.getAttribute("data-astro-template")||"default"]=r.innerHTML,r.remove())}for(const r of s){const i=r.closest(this.tagName);!i||!i.isSameNode(this)||(e[r.getAttribute("name")||"default"]=r.innerHTML)}const a=this.hasAttribute("props")?JSON.parse(this.getAttribute("props"),o):{};this.hydrator(this)(this.Component,a,e,{client:this.getAttribute("client")}),this.removeAttribute("ssr"),window.removeEventListener("astro:hydrate",this.hydrate),window.dispatchEvent(new CustomEvent("astro:hydrate"))}}connectedCallback(){!this.hasAttribute("await-children")||this.firstChild?this.childrenConnectedCallback():new MutationObserver((s,e)=>{e.disconnect(),this.childrenConnectedCallback()}).observe(this,{childList:!0})}async childrenConnectedCallback(){window.addEventListener("astro:hydrate",this.hydrate);let s=this.getAttribute("before-hydration-url");s&&await import(s),this.start()}start(){const s=JSON.parse(this.getAttribute("opts")),e=this.getAttribute("client");if(Astro[e]===void 0){window.addEventListener(\`astro:\${e}\`,()=>this.start(),{once:!0});return}Astro[e](async()=>{const n=this.getAttribute("renderer-url"),[a,{default:r}]=await Promise.all([import(this.getAttribute("component-url")),n?import(n):()=>()=>{}]),i=this.getAttribute("component-export")||"default";if(!i.includes("."))this.Component=a[i];else{this.Component=a;for(const d of i.split("."))this.Component=this.Component[d]}return this.hydrator=r,this.hydrate},s,this)}attributeChangedCallback(){this.hydrator&&this.hydrate()}},l.observedAttributes=["props"],l))}`;
|
|
2
2
|
export {
|
|
3
3
|
astro_island_prebuilt_default as default
|
|
4
4
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { EndpointHandler, Params } from '../../@types/astro';
|
|
2
2
|
/** Renders an endpoint request to completion, returning the body. */
|
|
3
|
-
export declare function renderEndpoint(mod: EndpointHandler, request: Request, params: Params): Promise<import("../../@types/astro").EndpointOutput
|
|
3
|
+
export declare function renderEndpoint(mod: EndpointHandler, request: Request, params: Params): Promise<Response | import("../../@types/astro").EndpointOutput>;
|
|
@@ -15,9 +15,13 @@ async function renderEndpoint(mod, request, params) {
|
|
|
15
15
|
const chosenMethod = (_a = request.method) == null ? void 0 : _a.toLowerCase();
|
|
16
16
|
const handler = getHandlerFromModule(mod, chosenMethod);
|
|
17
17
|
if (!handler || typeof handler !== "function") {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
let response = new Response(null, {
|
|
19
|
+
status: 404,
|
|
20
|
+
headers: {
|
|
21
|
+
"X-Astro-Response": "Not-Found"
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return response;
|
|
21
25
|
}
|
|
22
26
|
if (handler.length > 1) {
|
|
23
27
|
console.warn(`
|
|
@@ -93,7 +93,10 @@ async function generateHydrateScript(scriptOptions, metadata) {
|
|
|
93
93
|
}
|
|
94
94
|
island.props["ssr"] = "";
|
|
95
95
|
island.props["client"] = hydrate;
|
|
96
|
-
|
|
96
|
+
let beforeHydrationUrl = await result.resolve("astro:scripts/before-hydration.js");
|
|
97
|
+
if (beforeHydrationUrl.length) {
|
|
98
|
+
island.props["before-hydration-url"] = beforeHydrationUrl;
|
|
99
|
+
}
|
|
97
100
|
island.props["opts"] = escapeHTML(
|
|
98
101
|
JSON.stringify({
|
|
99
102
|
name: metadata.displayName,
|
|
@@ -283,10 +283,10 @@ ${source}
|
|
|
283
283
|
filename: context.file,
|
|
284
284
|
moduleId: context.file,
|
|
285
285
|
source: await context.read(),
|
|
286
|
-
transformStyle: createTransformStyles(styleTransformer, context.file, true
|
|
286
|
+
transformStyle: createTransformStyles(styleTransformer, context.file, true)
|
|
287
287
|
};
|
|
288
288
|
const compile = () => cachedCompilation(compileProps);
|
|
289
|
-
return handleHotUpdate
|
|
289
|
+
return handleHotUpdate(context, {
|
|
290
290
|
config,
|
|
291
291
|
logging,
|
|
292
292
|
compile
|
|
@@ -16,13 +16,6 @@ import { createRequest } from "../core/request.js";
|
|
|
16
16
|
import { createRouteManifest, matchAllRoutes } from "../core/routing/index.js";
|
|
17
17
|
import { resolvePages } from "../core/util.js";
|
|
18
18
|
import notFoundTemplate, { subpathNotUsedTemplate } from "../template/4xx.js";
|
|
19
|
-
function truncateString(str, n) {
|
|
20
|
-
if (str.length > n) {
|
|
21
|
-
return str.substring(0, n) + "…";
|
|
22
|
-
} else {
|
|
23
|
-
return str;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
19
|
function writeHtmlResponse(res, statusCode, html) {
|
|
27
20
|
res.writeHead(statusCode, {
|
|
28
21
|
"Content-Type": "text/html; charset=utf-8",
|
|
@@ -130,9 +123,53 @@ function baseMiddleware(config, logging) {
|
|
|
130
123
|
next();
|
|
131
124
|
};
|
|
132
125
|
}
|
|
126
|
+
async function matchRoute(pathname, routeCache, viteServer, logging, manifest, config) {
|
|
127
|
+
const matches = matchAllRoutes(pathname, manifest);
|
|
128
|
+
for await (const maybeRoute of matches) {
|
|
129
|
+
const filePath = new URL(`./${maybeRoute.component}`, config.root);
|
|
130
|
+
const preloadedComponent = await preload({ astroConfig: config, filePath, viteServer });
|
|
131
|
+
const [, mod] = preloadedComponent;
|
|
132
|
+
const paramsAndPropsRes = await getParamsAndProps({
|
|
133
|
+
mod,
|
|
134
|
+
route: maybeRoute,
|
|
135
|
+
routeCache,
|
|
136
|
+
pathname,
|
|
137
|
+
logging,
|
|
138
|
+
ssr: config.output === "server"
|
|
139
|
+
});
|
|
140
|
+
if (paramsAndPropsRes !== GetParamsAndPropsError.NoMatchingStaticPath) {
|
|
141
|
+
return {
|
|
142
|
+
route: maybeRoute,
|
|
143
|
+
filePath,
|
|
144
|
+
preloadedComponent,
|
|
145
|
+
mod
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (matches.length) {
|
|
150
|
+
warn(
|
|
151
|
+
logging,
|
|
152
|
+
"getStaticPaths",
|
|
153
|
+
`Route pattern matched, but no matching static path found. (${pathname})`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
log404(logging, pathname);
|
|
157
|
+
const custom404 = getCustom404Route(config, manifest);
|
|
158
|
+
if (custom404) {
|
|
159
|
+
const filePath = new URL(`./${custom404.component}`, config.root);
|
|
160
|
+
const preloadedComponent = await preload({ astroConfig: config, filePath, viteServer });
|
|
161
|
+
const [, mod] = preloadedComponent;
|
|
162
|
+
return {
|
|
163
|
+
route: custom404,
|
|
164
|
+
filePath,
|
|
165
|
+
preloadedComponent,
|
|
166
|
+
mod
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
return void 0;
|
|
170
|
+
}
|
|
133
171
|
async function handleRequest(routeCache, viteServer, logging, manifest, config, req, res) {
|
|
134
172
|
var _a;
|
|
135
|
-
const reqStart = performance.now();
|
|
136
173
|
const origin = `${viteServer.config.server.https ? "https" : "http"}://${req.headers.host}`;
|
|
137
174
|
const buildingToSSR = config.output === "server";
|
|
138
175
|
const url = new URL(origin + ((_a = req.url) == null ? void 0 : _a.replace(/(index)?\.html$/, "")));
|
|
@@ -148,112 +185,38 @@ async function handleRequest(routeCache, viteServer, logging, manifest, config,
|
|
|
148
185
|
if (!(req.method === "GET" || req.method === "HEAD")) {
|
|
149
186
|
let bytes = [];
|
|
150
187
|
await new Promise((resolve) => {
|
|
151
|
-
req.
|
|
152
|
-
|
|
188
|
+
req.on("data", (part) => {
|
|
189
|
+
bytes.push(part);
|
|
190
|
+
});
|
|
153
191
|
req.on("end", resolve);
|
|
154
192
|
});
|
|
155
|
-
body =
|
|
156
|
-
}
|
|
157
|
-
const request = createRequest({
|
|
158
|
-
url,
|
|
159
|
-
headers: buildingToSSR ? req.headers : new Headers(),
|
|
160
|
-
method: req.method,
|
|
161
|
-
body,
|
|
162
|
-
logging,
|
|
163
|
-
ssr: buildingToSSR,
|
|
164
|
-
clientAddress: buildingToSSR ? req.socket.remoteAddress : void 0
|
|
165
|
-
});
|
|
166
|
-
async function matchRoute() {
|
|
167
|
-
const matches = matchAllRoutes(pathname, manifest);
|
|
168
|
-
for await (const maybeRoute of matches) {
|
|
169
|
-
const filePath2 = new URL(`./${maybeRoute.component}`, config.root);
|
|
170
|
-
const preloadedComponent = await preload({ astroConfig: config, filePath: filePath2, viteServer });
|
|
171
|
-
const [, mod] = preloadedComponent;
|
|
172
|
-
const paramsAndPropsRes = await getParamsAndProps({
|
|
173
|
-
mod,
|
|
174
|
-
route: maybeRoute,
|
|
175
|
-
routeCache,
|
|
176
|
-
pathname,
|
|
177
|
-
logging,
|
|
178
|
-
ssr: config.output === "server"
|
|
179
|
-
});
|
|
180
|
-
if (paramsAndPropsRes !== GetParamsAndPropsError.NoMatchingStaticPath) {
|
|
181
|
-
return {
|
|
182
|
-
route: maybeRoute,
|
|
183
|
-
filePath: filePath2,
|
|
184
|
-
preloadedComponent,
|
|
185
|
-
mod
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
if (matches.length) {
|
|
190
|
-
warn(
|
|
191
|
-
logging,
|
|
192
|
-
"getStaticPaths",
|
|
193
|
-
`Route pattern matched, but no matching static path found. (${pathname})`
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
log404(logging, pathname);
|
|
197
|
-
const custom404 = getCustom404Route(config, manifest);
|
|
198
|
-
if (custom404) {
|
|
199
|
-
const filePath2 = new URL(`./${custom404.component}`, config.root);
|
|
200
|
-
const preloadedComponent = await preload({ astroConfig: config, filePath: filePath2, viteServer });
|
|
201
|
-
const [, mod] = preloadedComponent;
|
|
202
|
-
return {
|
|
203
|
-
route: custom404,
|
|
204
|
-
filePath: filePath2,
|
|
205
|
-
preloadedComponent,
|
|
206
|
-
mod
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
return void 0;
|
|
193
|
+
body = Buffer.concat(bytes);
|
|
210
194
|
}
|
|
211
195
|
let filePath;
|
|
212
196
|
try {
|
|
213
|
-
const matchedRoute = await matchRoute(
|
|
214
|
-
if (!matchedRoute) {
|
|
215
|
-
return handle404Response(origin, config, req, res);
|
|
216
|
-
}
|
|
217
|
-
const { route, preloadedComponent, mod } = matchedRoute;
|
|
218
|
-
filePath = matchedRoute.filePath;
|
|
219
|
-
const paramsAndPropsRes = await getParamsAndProps({
|
|
220
|
-
mod,
|
|
221
|
-
route,
|
|
222
|
-
routeCache,
|
|
197
|
+
const matchedRoute = await matchRoute(
|
|
223
198
|
pathname,
|
|
199
|
+
routeCache,
|
|
200
|
+
viteServer,
|
|
224
201
|
logging,
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
origin,
|
|
202
|
+
manifest,
|
|
203
|
+
config
|
|
204
|
+
);
|
|
205
|
+
filePath = matchedRoute == null ? void 0 : matchedRoute.filePath;
|
|
206
|
+
return await handleRoute(
|
|
207
|
+
matchedRoute,
|
|
208
|
+
url,
|
|
233
209
|
pathname,
|
|
234
|
-
|
|
210
|
+
body,
|
|
211
|
+
origin,
|
|
235
212
|
routeCache,
|
|
236
213
|
viteServer,
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
} else {
|
|
244
|
-
let contentType = "text/plain";
|
|
245
|
-
const filepath = route.pathname || route.segments.map((segment) => segment.map((p) => p.content).join("")).join("/");
|
|
246
|
-
const computedMimeType = mime.getType(filepath);
|
|
247
|
-
if (computedMimeType) {
|
|
248
|
-
contentType = computedMimeType;
|
|
249
|
-
}
|
|
250
|
-
res.writeHead(200, { "Content-Type": `${contentType};charset=utf-8` });
|
|
251
|
-
res.end(result.body);
|
|
252
|
-
}
|
|
253
|
-
} else {
|
|
254
|
-
const result = await ssr(preloadedComponent, options);
|
|
255
|
-
return await writeSSRResult(result, res);
|
|
256
|
-
}
|
|
214
|
+
manifest,
|
|
215
|
+
logging,
|
|
216
|
+
config,
|
|
217
|
+
req,
|
|
218
|
+
res
|
|
219
|
+
);
|
|
257
220
|
} catch (_err) {
|
|
258
221
|
const err = fixViteErrorMessage(_err, viteServer, filePath);
|
|
259
222
|
const errorWithMetadata = collectErrorMetadata(err);
|
|
@@ -261,6 +224,85 @@ async function handleRequest(routeCache, viteServer, logging, manifest, config,
|
|
|
261
224
|
handle500Response(viteServer, origin, req, res, errorWithMetadata);
|
|
262
225
|
}
|
|
263
226
|
}
|
|
227
|
+
async function handleRoute(matchedRoute, url, pathname, body, origin, routeCache, viteServer, manifest, logging, config, req, res) {
|
|
228
|
+
if (!matchedRoute) {
|
|
229
|
+
return handle404Response(origin, config, req, res);
|
|
230
|
+
}
|
|
231
|
+
const filePath = matchedRoute.filePath;
|
|
232
|
+
const { route, preloadedComponent, mod } = matchedRoute;
|
|
233
|
+
const buildingToSSR = config.output === "server";
|
|
234
|
+
const request = createRequest({
|
|
235
|
+
url,
|
|
236
|
+
headers: buildingToSSR ? req.headers : new Headers(),
|
|
237
|
+
method: req.method,
|
|
238
|
+
body,
|
|
239
|
+
logging,
|
|
240
|
+
ssr: buildingToSSR,
|
|
241
|
+
clientAddress: buildingToSSR ? req.socket.remoteAddress : void 0
|
|
242
|
+
});
|
|
243
|
+
const paramsAndPropsRes = await getParamsAndProps({
|
|
244
|
+
mod,
|
|
245
|
+
route,
|
|
246
|
+
routeCache,
|
|
247
|
+
pathname,
|
|
248
|
+
logging,
|
|
249
|
+
ssr: config.output === "server"
|
|
250
|
+
});
|
|
251
|
+
const options = {
|
|
252
|
+
astroConfig: config,
|
|
253
|
+
filePath,
|
|
254
|
+
logging,
|
|
255
|
+
mode: "development",
|
|
256
|
+
origin,
|
|
257
|
+
pathname,
|
|
258
|
+
route,
|
|
259
|
+
routeCache,
|
|
260
|
+
viteServer,
|
|
261
|
+
request
|
|
262
|
+
};
|
|
263
|
+
if (route.type === "endpoint") {
|
|
264
|
+
const result = await callEndpoint(options);
|
|
265
|
+
if (result.type === "response") {
|
|
266
|
+
if (result.response.headers.get("X-Astro-Response") === "Not-Found") {
|
|
267
|
+
const fourOhFourRoute = await matchRoute(
|
|
268
|
+
"/404",
|
|
269
|
+
routeCache,
|
|
270
|
+
viteServer,
|
|
271
|
+
logging,
|
|
272
|
+
manifest,
|
|
273
|
+
config
|
|
274
|
+
);
|
|
275
|
+
return handleRoute(
|
|
276
|
+
fourOhFourRoute,
|
|
277
|
+
new URL("/404", url),
|
|
278
|
+
"/404",
|
|
279
|
+
body,
|
|
280
|
+
origin,
|
|
281
|
+
routeCache,
|
|
282
|
+
viteServer,
|
|
283
|
+
manifest,
|
|
284
|
+
logging,
|
|
285
|
+
config,
|
|
286
|
+
req,
|
|
287
|
+
res
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
await writeWebResponse(res, result.response);
|
|
291
|
+
} else {
|
|
292
|
+
let contentType = "text/plain";
|
|
293
|
+
const filepath = route.pathname || route.segments.map((segment) => segment.map((p) => p.content).join("")).join("/");
|
|
294
|
+
const computedMimeType = mime.getType(filepath);
|
|
295
|
+
if (computedMimeType) {
|
|
296
|
+
contentType = computedMimeType;
|
|
297
|
+
}
|
|
298
|
+
res.writeHead(200, { "Content-Type": `${contentType};charset=utf-8` });
|
|
299
|
+
res.end(result.body);
|
|
300
|
+
}
|
|
301
|
+
} else {
|
|
302
|
+
const result = await ssr(preloadedComponent, options);
|
|
303
|
+
return await writeSSRResult(result, res);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
264
306
|
function createPlugin({ config, logging }) {
|
|
265
307
|
return {
|
|
266
308
|
name: "astro:server",
|
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
|
-
import * as tsr from "tsconfig-resolver";
|
|
3
|
-
import * as url from "url";
|
|
4
2
|
const normalize = (pathname) => String(pathname).split(path.sep).join(path.posix.sep);
|
|
5
|
-
const
|
|
6
|
-
const config =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const getConfigAlias = (cwd) => {
|
|
10
|
-
const config = getExistingConfig("tsconfig.json", cwd) || getExistingConfig("jsconfig.json", cwd);
|
|
11
|
-
if (!config)
|
|
3
|
+
const getConfigAlias = (astroConfig) => {
|
|
4
|
+
const config = astroConfig._ctx.tsConfig;
|
|
5
|
+
const configPath = astroConfig._ctx.tsConfigPath;
|
|
6
|
+
if (!config || !configPath)
|
|
12
7
|
return null;
|
|
13
|
-
const compilerOptions = Object(config.
|
|
8
|
+
const compilerOptions = Object(config.compilerOptions);
|
|
14
9
|
if (!compilerOptions.baseUrl)
|
|
15
10
|
return null;
|
|
16
11
|
const baseUrl = path.posix.resolve(
|
|
17
|
-
path.posix.dirname(normalize(
|
|
12
|
+
path.posix.dirname(normalize(configPath).replace(/^\/?/, "/")),
|
|
18
13
|
normalize(compilerOptions.baseUrl)
|
|
19
14
|
);
|
|
20
15
|
const aliases = [];
|
|
@@ -42,7 +37,7 @@ const getConfigAlias = (cwd) => {
|
|
|
42
37
|
function configAliasVitePlugin({
|
|
43
38
|
config: astroConfig
|
|
44
39
|
}) {
|
|
45
|
-
const configAlias = getConfigAlias(astroConfig
|
|
40
|
+
const configAlias = getConfigAlias(astroConfig);
|
|
46
41
|
if (!configAlias)
|
|
47
42
|
return {};
|
|
48
43
|
return {
|
|
@@ -124,6 +124,7 @@ function jsx({ config, logging }) {
|
|
|
124
124
|
defaultJSXRendererEntry = [...jsxRenderersIntegrationOnly.entries()][0];
|
|
125
125
|
},
|
|
126
126
|
async transform(code, id, opts) {
|
|
127
|
+
var _a;
|
|
127
128
|
const ssr = Boolean(opts == null ? void 0 : opts.ssr);
|
|
128
129
|
if (!JSX_EXTENSIONS.has(path.extname(id))) {
|
|
129
130
|
return null;
|
|
@@ -163,6 +164,10 @@ function jsx({ config, logging }) {
|
|
|
163
164
|
if (!importSource && IMPORT_KEYWORD_REGEX.test(code)) {
|
|
164
165
|
importSource = await detectImportSourceFromImports(code, id, jsxRenderers);
|
|
165
166
|
}
|
|
167
|
+
if (!importSource) {
|
|
168
|
+
const compilerOptions = (_a = config._ctx.tsConfig) == null ? void 0 : _a.compilerOptions;
|
|
169
|
+
importSource = compilerOptions == null ? void 0 : compilerOptions.jsxImportSource;
|
|
170
|
+
}
|
|
166
171
|
if (!importSource && defaultJSXRendererEntry) {
|
|
167
172
|
const [defaultRendererName] = defaultJSXRendererEntry;
|
|
168
173
|
error(
|
|
@@ -7,4 +7,4 @@ export declare type ViteStyleTransformer = {
|
|
|
7
7
|
transformStyleWithVite: TransformStyleWithVite;
|
|
8
8
|
};
|
|
9
9
|
export declare function createViteStyleTransformer(viteConfig: vite.ResolvedConfig): ViteStyleTransformer;
|
|
10
|
-
export declare function createTransformStyles(viteStyleTransformer: ViteStyleTransformer, filename: string, ssr: boolean, pluginContext
|
|
10
|
+
export declare function createTransformStyles(viteStyleTransformer: ViteStyleTransformer, filename: string, ssr: boolean, pluginContext?: PluginContext): TransformStyle;
|
|
@@ -14,10 +14,6 @@ function getNormalizedIDForPostCSS(filename) {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
function createTransformStyles(viteStyleTransformer, filename, ssr, pluginContext) {
|
|
17
|
-
if (!pluginContext.addWatchFile) {
|
|
18
|
-
pluginContext.addWatchFile = () => {
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
17
|
const normalizedID = getNormalizedIDForPostCSS(filename);
|
|
22
18
|
return async function(styleSource, lang) {
|
|
23
19
|
const result = await viteStyleTransformer.transformStyleWithVite.call(pluginContext, {
|
|
@@ -12,7 +12,9 @@ function createTransformStyleWithViteFn(viteConfig) {
|
|
|
12
12
|
}
|
|
13
13
|
const styleId = `${id}?astro&type=style&lang${lang}`;
|
|
14
14
|
viteDevServer == null ? void 0 : viteDevServer.moduleGraph.ensureEntryFromUrl(styleId, ssr, false);
|
|
15
|
-
const
|
|
15
|
+
const ctx = this ?? { addWatchFile: () => {
|
|
16
|
+
} };
|
|
17
|
+
const transformResult = await transformCss.call(ctx, source, styleId, ssr);
|
|
16
18
|
const { code, map } = transformResult;
|
|
17
19
|
const deps = /* @__PURE__ */ new Set();
|
|
18
20
|
const mod = viteDevServer == null ? void 0 : viteDevServer.moduleGraph.getModuleById(styleId);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
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",
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
"recast": "^0.20.5",
|
|
126
126
|
"rehype": "^12.0.1",
|
|
127
127
|
"resolve": "^1.22.0",
|
|
128
|
-
"rollup": "~2.
|
|
128
|
+
"rollup": "~2.78.0",
|
|
129
129
|
"semver": "^7.3.7",
|
|
130
130
|
"shiki": "^0.11.1",
|
|
131
131
|
"sirv": "^2.0.2",
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
"tsconfig-resolver": "^3.0.1",
|
|
137
137
|
"unist-util-visit": "^4.1.0",
|
|
138
138
|
"vfile": "^5.3.2",
|
|
139
|
-
"vite": "3.0
|
|
139
|
+
"vite": "3.1.0",
|
|
140
140
|
"yargs-parser": "^21.0.1",
|
|
141
141
|
"zod": "^3.17.3"
|
|
142
142
|
},
|