astro 1.2.4 → 1.2.6
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 +15 -11
- package/dist/cli/check/index.d.ts +2 -2
- package/dist/cli/check/index.js +2 -2
- package/dist/cli/index.js +28 -9
- package/dist/core/add/index.js +1 -1
- package/dist/core/app/index.js +9 -1
- package/dist/core/build/generate.d.ts +3 -3
- package/dist/core/build/generate.js +28 -28
- package/dist/core/build/index.d.ts +2 -2
- package/dist/core/build/index.js +23 -19
- package/dist/core/build/page-data.d.ts +2 -2
- package/dist/core/build/page-data.js +2 -2
- package/dist/core/build/static-build.js +26 -28
- package/dist/core/build/types.d.ts +2 -2
- package/dist/core/build/vite-plugin-css.d.ts +0 -2
- package/dist/core/build/vite-plugin-css.js +3 -3
- package/dist/core/build/vite-plugin-hoisted-scripts.d.ts +2 -2
- package/dist/core/build/vite-plugin-hoisted-scripts.js +3 -3
- package/dist/core/build/vite-plugin-pages.js +2 -2
- package/dist/core/build/vite-plugin-ssr.js +16 -12
- package/dist/core/config/config.d.ts +41 -0
- package/dist/core/{config.js → config/config.js} +5 -153
- package/dist/core/config/index.d.ts +4 -0
- package/dist/core/config/index.js +18 -0
- package/dist/core/config/schema.d.ts +478 -0
- package/dist/core/config/schema.js +148 -0
- package/dist/core/config/settings.d.ts +8 -0
- package/dist/core/config/settings.js +16 -0
- package/dist/core/config/tsconfig.d.ts +2 -0
- package/dist/core/config/tsconfig.js +13 -0
- package/dist/core/create-vite.d.ts +3 -3
- package/dist/core/create-vite.js +21 -21
- package/dist/core/dev/index.d.ts +2 -2
- package/dist/core/dev/index.js +16 -12
- package/dist/core/endpoint/dev/index.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/preview/index.d.ts +2 -2
- package/dist/core/preview/index.js +9 -9
- package/dist/core/render/dev/index.d.ts +5 -5
- package/dist/core/render/dev/index.js +14 -14
- package/dist/core/render/dev/scripts.d.ts +2 -2
- package/dist/core/render/dev/scripts.js +4 -7
- package/dist/core/routing/manifest/create.d.ts +3 -3
- package/dist/core/routing/manifest/create.js +9 -12
- package/dist/core/util.d.ts +3 -3
- package/dist/core/util.js +9 -9
- package/dist/integrations/index.d.ts +6 -6
- package/dist/integrations/index.js +19 -17
- 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/hydration.js +4 -1
- package/dist/vite-plugin-astro/index.d.ts +3 -3
- package/dist/vite-plugin-astro/index.js +2 -1
- package/dist/vite-plugin-astro-postprocess/index.d.ts +3 -3
- package/dist/vite-plugin-astro-postprocess/index.js +1 -1
- package/dist/vite-plugin-astro-server/index.d.ts +4 -4
- package/dist/vite-plugin-astro-server/index.js +27 -24
- package/dist/vite-plugin-config-alias/index.d.ts +3 -3
- package/dist/vite-plugin-config-alias/index.js +9 -13
- package/dist/vite-plugin-env/index.d.ts +3 -3
- package/dist/vite-plugin-env/index.js +2 -3
- package/dist/vite-plugin-integrations-container/index.d.ts +3 -3
- package/dist/vite-plugin-integrations-container/index.js +2 -2
- package/dist/vite-plugin-jsx/index.d.ts +3 -3
- package/dist/vite-plugin-jsx/index.js +7 -2
- package/dist/vite-plugin-markdown/index.d.ts +3 -3
- package/dist/vite-plugin-markdown/index.js +3 -3
- package/dist/vite-plugin-markdown-legacy/index.d.ts +3 -3
- package/dist/vite-plugin-markdown-legacy/index.js +2 -1
- package/dist/vite-plugin-scripts/index.d.ts +3 -3
- package/dist/vite-plugin-scripts/index.js +5 -5
- package/dist/vite-plugin-scripts/page-ssr.d.ts +3 -3
- package/dist/vite-plugin-scripts/page-ssr.js +7 -5
- package/package.json +1 -1
- package/dist/core/config.d.ts +0 -260
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { bold } from "kleur/colors";
|
|
2
|
-
import { mergeConfig } from "../core/config.js";
|
|
2
|
+
import { mergeConfig } from "../core/config/config.js";
|
|
3
3
|
import { info } from "../core/logger/core.js";
|
|
4
4
|
async function withTakingALongTimeMsg({
|
|
5
5
|
name,
|
|
@@ -15,20 +15,21 @@ async function withTakingALongTimeMsg({
|
|
|
15
15
|
return result;
|
|
16
16
|
}
|
|
17
17
|
async function runHookConfigSetup({
|
|
18
|
-
|
|
18
|
+
settings,
|
|
19
19
|
command,
|
|
20
20
|
logging
|
|
21
21
|
}) {
|
|
22
22
|
var _a;
|
|
23
|
-
if (
|
|
24
|
-
|
|
23
|
+
if (settings.config.adapter) {
|
|
24
|
+
settings.config.integrations.push(settings.config.adapter);
|
|
25
25
|
}
|
|
26
|
-
let updatedConfig = { ...
|
|
27
|
-
|
|
26
|
+
let updatedConfig = { ...settings.config };
|
|
27
|
+
let updatedSettings = { ...settings, config: updatedConfig };
|
|
28
|
+
for (const integration of settings.config.integrations) {
|
|
28
29
|
if ((_a = integration == null ? void 0 : integration.hooks) == null ? void 0 : _a["astro:config:setup"]) {
|
|
29
30
|
let addPageExtension2 = function(...input) {
|
|
30
31
|
const exts = input.flat(Infinity).map((ext) => `.${ext.replace(/^\./, "")}`);
|
|
31
|
-
|
|
32
|
+
updatedSettings.pageExtensions.push(...exts);
|
|
32
33
|
};
|
|
33
34
|
var addPageExtension = addPageExtension2;
|
|
34
35
|
const hooks = {
|
|
@@ -41,16 +42,16 @@ async function runHookConfigSetup({
|
|
|
41
42
|
if (!renderer.serverEntrypoint) {
|
|
42
43
|
throw new Error(`Renderer ${bold(renderer.name)} does not provide a serverEntrypoint.`);
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
+
updatedSettings.renderers.push(renderer);
|
|
45
46
|
},
|
|
46
47
|
injectScript: (stage, content) => {
|
|
47
|
-
|
|
48
|
+
updatedSettings.scripts.push({ stage, content });
|
|
48
49
|
},
|
|
49
50
|
updateConfig: (newConfig) => {
|
|
50
51
|
updatedConfig = mergeConfig(updatedConfig, newConfig);
|
|
51
52
|
},
|
|
52
53
|
injectRoute: (injectRoute) => {
|
|
53
|
-
|
|
54
|
+
updatedSettings.injectedRoutes.push(injectRoute);
|
|
54
55
|
}
|
|
55
56
|
};
|
|
56
57
|
Object.defineProperty(hooks, "addPageExtension", {
|
|
@@ -65,26 +66,27 @@ async function runHookConfigSetup({
|
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
|
-
|
|
69
|
+
updatedSettings.config = updatedConfig;
|
|
70
|
+
return updatedSettings;
|
|
69
71
|
}
|
|
70
72
|
async function runHookConfigDone({
|
|
71
|
-
|
|
73
|
+
settings,
|
|
72
74
|
logging
|
|
73
75
|
}) {
|
|
74
76
|
var _a;
|
|
75
|
-
for (const integration of config.integrations) {
|
|
77
|
+
for (const integration of settings.config.integrations) {
|
|
76
78
|
if ((_a = integration == null ? void 0 : integration.hooks) == null ? void 0 : _a["astro:config:done"]) {
|
|
77
79
|
await withTakingALongTimeMsg({
|
|
78
80
|
name: integration.name,
|
|
79
81
|
hookResult: integration.hooks["astro:config:done"]({
|
|
80
|
-
config,
|
|
82
|
+
config: settings.config,
|
|
81
83
|
setAdapter(adapter) {
|
|
82
|
-
if (
|
|
84
|
+
if (settings.adapter && settings.adapter.name !== adapter.name) {
|
|
83
85
|
throw new Error(
|
|
84
|
-
`Integration "${integration.name}" conflicts with "${
|
|
86
|
+
`Integration "${integration.name}" conflicts with "${settings.adapter.name}". You can only configure one deployment integration.`
|
|
85
87
|
);
|
|
86
88
|
}
|
|
87
|
-
|
|
89
|
+
settings.adapter = adapter;
|
|
88
90
|
}
|
|
89
91
|
}),
|
|
90
92
|
logging
|
|
@@ -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
|
};
|
|
@@ -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,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type * as vite from 'vite';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AstroSettings } from '../@types/astro';
|
|
3
3
|
import type { LogOptions } from '../core/logger/core.js';
|
|
4
4
|
interface AstroPluginOptions {
|
|
5
|
-
|
|
5
|
+
settings: AstroSettings;
|
|
6
6
|
logging: LogOptions;
|
|
7
7
|
}
|
|
8
8
|
/** Transform .astro files for Vite */
|
|
9
|
-
export default function astro({
|
|
9
|
+
export default function astro({ settings, logging }: AstroPluginOptions): vite.Plugin;
|
|
10
10
|
export {};
|
|
@@ -13,7 +13,8 @@ import {
|
|
|
13
13
|
import { handleHotUpdate } from "./hmr.js";
|
|
14
14
|
import { parseAstroRequest } from "./query.js";
|
|
15
15
|
const FRONTMATTER_PARSE_REGEXP = /^\-\-\-(.*)^\-\-\-/ms;
|
|
16
|
-
function astro({
|
|
16
|
+
function astro({ settings, logging }) {
|
|
17
|
+
const { config } = settings;
|
|
17
18
|
function normalizeFilename(filename) {
|
|
18
19
|
if (filename.startsWith("/@fs")) {
|
|
19
20
|
filename = filename.slice("/@fs".length);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AstroSettings } from '../@types/astro';
|
|
3
3
|
interface AstroPluginOptions {
|
|
4
|
-
|
|
4
|
+
settings: AstroSettings;
|
|
5
5
|
}
|
|
6
|
-
export default function astro(
|
|
6
|
+
export default function astro(_opts: AstroPluginOptions): Plugin;
|
|
7
7
|
export {};
|
|
@@ -2,7 +2,7 @@ import { parse as babelParser } from "@babel/parser";
|
|
|
2
2
|
import { parse, print, types, visit } from "recast";
|
|
3
3
|
const ASTRO_GLOB_REGEX = /Astro2?\s*\.\s*glob\s*\(/;
|
|
4
4
|
const validAstroGlobalNames = /* @__PURE__ */ new Set(["Astro", "Astro2"]);
|
|
5
|
-
function astro(
|
|
5
|
+
function astro(_opts) {
|
|
6
6
|
return {
|
|
7
7
|
name: "astro:postprocess",
|
|
8
8
|
async transform(code, id) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type * as vite from 'vite';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AstroSettings } from '../@types/astro';
|
|
3
3
|
import { LogOptions } from '../core/logger/core.js';
|
|
4
4
|
interface AstroPluginOptions {
|
|
5
|
-
|
|
5
|
+
settings: AstroSettings;
|
|
6
6
|
logging: LogOptions;
|
|
7
7
|
}
|
|
8
|
-
export declare function baseMiddleware(
|
|
9
|
-
export default function createPlugin({
|
|
8
|
+
export declare function baseMiddleware(settings: AstroSettings, logging: LogOptions): vite.Connect.NextHandleFunction;
|
|
9
|
+
export default function createPlugin({ settings, logging }: AstroPluginOptions): vite.Plugin;
|
|
10
10
|
export {};
|
|
@@ -63,7 +63,7 @@ async function writeWebResponse(res, webResponse) {
|
|
|
63
63
|
async function writeSSRResult(webResponse, res) {
|
|
64
64
|
return writeWebResponse(res, webResponse);
|
|
65
65
|
}
|
|
66
|
-
async function handle404Response(origin,
|
|
66
|
+
async function handle404Response(origin, settings, req, res) {
|
|
67
67
|
const pathname = decodeURI(new URL(origin + req.url).pathname);
|
|
68
68
|
const html = notFoundTemplate({
|
|
69
69
|
statusCode: 404,
|
|
@@ -86,7 +86,7 @@ async function handle500Response(viteServer, origin, req, res, err) {
|
|
|
86
86
|
);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
function getCustom404Route(config, manifest) {
|
|
89
|
+
function getCustom404Route({ config }, manifest) {
|
|
90
90
|
const relPages = resolvePages(config).href.replace(config.root.href, "");
|
|
91
91
|
const pattern = new RegExp(`${appendForwardSlash(relPages)}404.(astro|md)`);
|
|
92
92
|
return manifest.routes.find((r) => r.component.match(pattern));
|
|
@@ -94,7 +94,8 @@ function getCustom404Route(config, manifest) {
|
|
|
94
94
|
function log404(logging, pathname) {
|
|
95
95
|
info(logging, "serve", msg.req({ url: pathname, statusCode: 404 }));
|
|
96
96
|
}
|
|
97
|
-
function baseMiddleware(
|
|
97
|
+
function baseMiddleware(settings, logging) {
|
|
98
|
+
const { config } = settings;
|
|
98
99
|
const site = config.site ? new URL(config.base, config.site) : void 0;
|
|
99
100
|
const devRoot = site ? site.pathname : "/";
|
|
100
101
|
return function devBaseMiddleware(req, res, next) {
|
|
@@ -123,11 +124,11 @@ function baseMiddleware(config, logging) {
|
|
|
123
124
|
next();
|
|
124
125
|
};
|
|
125
126
|
}
|
|
126
|
-
async function matchRoute(pathname, routeCache, viteServer, logging, manifest,
|
|
127
|
+
async function matchRoute(pathname, routeCache, viteServer, logging, manifest, settings) {
|
|
127
128
|
const matches = matchAllRoutes(pathname, manifest);
|
|
128
129
|
for await (const maybeRoute of matches) {
|
|
129
|
-
const filePath = new URL(`./${maybeRoute.component}`, config.root);
|
|
130
|
-
const preloadedComponent = await preload({
|
|
130
|
+
const filePath = new URL(`./${maybeRoute.component}`, settings.config.root);
|
|
131
|
+
const preloadedComponent = await preload({ settings, filePath, viteServer });
|
|
131
132
|
const [, mod] = preloadedComponent;
|
|
132
133
|
const paramsAndPropsRes = await getParamsAndProps({
|
|
133
134
|
mod,
|
|
@@ -135,7 +136,7 @@ async function matchRoute(pathname, routeCache, viteServer, logging, manifest, c
|
|
|
135
136
|
routeCache,
|
|
136
137
|
pathname,
|
|
137
138
|
logging,
|
|
138
|
-
ssr: config.output === "server"
|
|
139
|
+
ssr: settings.config.output === "server"
|
|
139
140
|
});
|
|
140
141
|
if (paramsAndPropsRes !== GetParamsAndPropsError.NoMatchingStaticPath) {
|
|
141
142
|
return {
|
|
@@ -154,10 +155,10 @@ async function matchRoute(pathname, routeCache, viteServer, logging, manifest, c
|
|
|
154
155
|
);
|
|
155
156
|
}
|
|
156
157
|
log404(logging, pathname);
|
|
157
|
-
const custom404 = getCustom404Route(
|
|
158
|
+
const custom404 = getCustom404Route(settings, manifest);
|
|
158
159
|
if (custom404) {
|
|
159
|
-
const filePath = new URL(`./${custom404.component}`, config.root);
|
|
160
|
-
const preloadedComponent = await preload({
|
|
160
|
+
const filePath = new URL(`./${custom404.component}`, settings.config.root);
|
|
161
|
+
const preloadedComponent = await preload({ settings, filePath, viteServer });
|
|
161
162
|
const [, mod] = preloadedComponent;
|
|
162
163
|
return {
|
|
163
164
|
route: custom404,
|
|
@@ -168,8 +169,9 @@ async function matchRoute(pathname, routeCache, viteServer, logging, manifest, c
|
|
|
168
169
|
}
|
|
169
170
|
return void 0;
|
|
170
171
|
}
|
|
171
|
-
async function handleRequest(routeCache, viteServer, logging, manifest,
|
|
172
|
+
async function handleRequest(routeCache, viteServer, logging, manifest, settings, req, res) {
|
|
172
173
|
var _a;
|
|
174
|
+
const { config } = settings;
|
|
173
175
|
const origin = `${viteServer.config.server.https ? "https" : "http"}://${req.headers.host}`;
|
|
174
176
|
const buildingToSSR = config.output === "server";
|
|
175
177
|
const url = new URL(origin + ((_a = req.url) == null ? void 0 : _a.replace(/(index)?\.html$/, "")));
|
|
@@ -200,7 +202,7 @@ async function handleRequest(routeCache, viteServer, logging, manifest, config,
|
|
|
200
202
|
viteServer,
|
|
201
203
|
logging,
|
|
202
204
|
manifest,
|
|
203
|
-
|
|
205
|
+
settings
|
|
204
206
|
);
|
|
205
207
|
filePath = matchedRoute == null ? void 0 : matchedRoute.filePath;
|
|
206
208
|
return await handleRoute(
|
|
@@ -213,7 +215,7 @@ async function handleRequest(routeCache, viteServer, logging, manifest, config,
|
|
|
213
215
|
viteServer,
|
|
214
216
|
manifest,
|
|
215
217
|
logging,
|
|
216
|
-
|
|
218
|
+
settings,
|
|
217
219
|
req,
|
|
218
220
|
res
|
|
219
221
|
);
|
|
@@ -224,10 +226,11 @@ async function handleRequest(routeCache, viteServer, logging, manifest, config,
|
|
|
224
226
|
handle500Response(viteServer, origin, req, res, errorWithMetadata);
|
|
225
227
|
}
|
|
226
228
|
}
|
|
227
|
-
async function handleRoute(matchedRoute, url, pathname, body, origin, routeCache, viteServer, manifest, logging,
|
|
229
|
+
async function handleRoute(matchedRoute, url, pathname, body, origin, routeCache, viteServer, manifest, logging, settings, req, res) {
|
|
228
230
|
if (!matchedRoute) {
|
|
229
|
-
return handle404Response(origin,
|
|
231
|
+
return handle404Response(origin, settings, req, res);
|
|
230
232
|
}
|
|
233
|
+
const { config } = settings;
|
|
231
234
|
const filePath = matchedRoute.filePath;
|
|
232
235
|
const { route, preloadedComponent, mod } = matchedRoute;
|
|
233
236
|
const buildingToSSR = config.output === "server";
|
|
@@ -249,7 +252,7 @@ async function handleRoute(matchedRoute, url, pathname, body, origin, routeCache
|
|
|
249
252
|
ssr: config.output === "server"
|
|
250
253
|
});
|
|
251
254
|
const options = {
|
|
252
|
-
|
|
255
|
+
settings,
|
|
253
256
|
filePath,
|
|
254
257
|
logging,
|
|
255
258
|
mode: "development",
|
|
@@ -270,7 +273,7 @@ async function handleRoute(matchedRoute, url, pathname, body, origin, routeCache
|
|
|
270
273
|
viteServer,
|
|
271
274
|
logging,
|
|
272
275
|
manifest,
|
|
273
|
-
|
|
276
|
+
settings
|
|
274
277
|
);
|
|
275
278
|
return handleRoute(
|
|
276
279
|
fourOhFourRoute,
|
|
@@ -282,7 +285,7 @@ async function handleRoute(matchedRoute, url, pathname, body, origin, routeCache
|
|
|
282
285
|
viteServer,
|
|
283
286
|
manifest,
|
|
284
287
|
logging,
|
|
285
|
-
|
|
288
|
+
settings,
|
|
286
289
|
req,
|
|
287
290
|
res
|
|
288
291
|
);
|
|
@@ -303,33 +306,33 @@ async function handleRoute(matchedRoute, url, pathname, body, origin, routeCache
|
|
|
303
306
|
return await writeSSRResult(result, res);
|
|
304
307
|
}
|
|
305
308
|
}
|
|
306
|
-
function createPlugin({
|
|
309
|
+
function createPlugin({ settings, logging }) {
|
|
307
310
|
return {
|
|
308
311
|
name: "astro:server",
|
|
309
312
|
configureServer(viteServer) {
|
|
310
313
|
let routeCache = new RouteCache(logging);
|
|
311
|
-
let manifest = createRouteManifest({
|
|
314
|
+
let manifest = createRouteManifest({ settings }, logging);
|
|
312
315
|
function rebuildManifest(needsManifestRebuild, file) {
|
|
313
316
|
routeCache.clearAll();
|
|
314
317
|
if (needsManifestRebuild) {
|
|
315
|
-
manifest = createRouteManifest({
|
|
318
|
+
manifest = createRouteManifest({ settings }, logging);
|
|
316
319
|
}
|
|
317
320
|
}
|
|
318
321
|
viteServer.watcher.on("add", rebuildManifest.bind(null, true));
|
|
319
322
|
viteServer.watcher.on("unlink", rebuildManifest.bind(null, true));
|
|
320
323
|
viteServer.watcher.on("change", rebuildManifest.bind(null, false));
|
|
321
324
|
return () => {
|
|
322
|
-
if (config.base !== "/") {
|
|
325
|
+
if (settings.config.base !== "/") {
|
|
323
326
|
viteServer.middlewares.stack.unshift({
|
|
324
327
|
route: "",
|
|
325
|
-
handle: baseMiddleware(
|
|
328
|
+
handle: baseMiddleware(settings, logging)
|
|
326
329
|
});
|
|
327
330
|
}
|
|
328
331
|
viteServer.middlewares.use(async (req, res) => {
|
|
329
332
|
if (!req.url || !req.method) {
|
|
330
333
|
throw new Error("Incomplete request");
|
|
331
334
|
}
|
|
332
|
-
handleRequest(routeCache, viteServer, logging, manifest,
|
|
335
|
+
handleRequest(routeCache, viteServer, logging, manifest, settings, req, res);
|
|
333
336
|
});
|
|
334
337
|
};
|
|
335
338
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AstroSettings } from '../@types/astro';
|
|
2
2
|
import type * as vite from 'vite';
|
|
3
3
|
/** Result of successfully parsed tsconfig.json or jsconfig.json. */
|
|
4
4
|
export declare interface Alias {
|
|
@@ -6,6 +6,6 @@ export declare interface Alias {
|
|
|
6
6
|
replacement: string;
|
|
7
7
|
}
|
|
8
8
|
/** Returns a Vite plugin used to alias pathes from tsconfig.json and jsconfig.json. */
|
|
9
|
-
export default function configAliasVitePlugin({
|
|
10
|
-
|
|
9
|
+
export default function configAliasVitePlugin({ settings, }: {
|
|
10
|
+
settings: AstroSettings;
|
|
11
11
|
}): vite.PluginOption;
|
|
@@ -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 = (settings) => {
|
|
4
|
+
const config = settings.tsConfig;
|
|
5
|
+
const configPath = settings.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 = [];
|
|
@@ -40,9 +35,10 @@ const getConfigAlias = (cwd) => {
|
|
|
40
35
|
return aliases;
|
|
41
36
|
};
|
|
42
37
|
function configAliasVitePlugin({
|
|
43
|
-
|
|
38
|
+
settings
|
|
44
39
|
}) {
|
|
45
|
-
const
|
|
40
|
+
const { config } = settings;
|
|
41
|
+
const configAlias = getConfigAlias(settings);
|
|
46
42
|
if (!configAlias)
|
|
47
43
|
return {};
|
|
48
44
|
return {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as vite from 'vite';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AstroSettings } from '../@types/astro';
|
|
3
3
|
interface EnvPluginOptions {
|
|
4
|
-
|
|
4
|
+
settings: AstroSettings;
|
|
5
5
|
}
|
|
6
|
-
export default function envVitePlugin({
|
|
6
|
+
export default function envVitePlugin({ settings }: EnvPluginOptions): vite.PluginOption;
|
|
7
7
|
export {};
|
|
@@ -38,13 +38,12 @@ function getReferencedPrivateKeys(source, privateEnv) {
|
|
|
38
38
|
}
|
|
39
39
|
return references;
|
|
40
40
|
}
|
|
41
|
-
function envVitePlugin({
|
|
42
|
-
config: astroConfig
|
|
43
|
-
}) {
|
|
41
|
+
function envVitePlugin({ settings }) {
|
|
44
42
|
let privateEnv;
|
|
45
43
|
let config;
|
|
46
44
|
let replacements;
|
|
47
45
|
let pattern;
|
|
46
|
+
const { config: astroConfig } = settings;
|
|
48
47
|
return {
|
|
49
48
|
name: "astro:vite-plugin-env",
|
|
50
49
|
enforce: "pre",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Plugin as VitePlugin } from 'vite';
|
|
2
|
-
import {
|
|
2
|
+
import { AstroSettings } from '../@types/astro.js';
|
|
3
3
|
import { LogOptions } from '../core/logger/core.js';
|
|
4
4
|
/** Connect Astro integrations into Vite, as needed. */
|
|
5
|
-
export default function astroIntegrationsContainerPlugin({
|
|
6
|
-
|
|
5
|
+
export default function astroIntegrationsContainerPlugin({ settings, logging, }: {
|
|
6
|
+
settings: AstroSettings;
|
|
7
7
|
logging: LogOptions;
|
|
8
8
|
}): VitePlugin;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { runHookServerSetup } from "../integrations/index.js";
|
|
2
2
|
function astroIntegrationsContainerPlugin({
|
|
3
|
-
|
|
3
|
+
settings,
|
|
4
4
|
logging
|
|
5
5
|
}) {
|
|
6
6
|
return {
|
|
7
7
|
name: "astro:integration-container",
|
|
8
8
|
configureServer(server) {
|
|
9
|
-
runHookServerSetup({ config, server, logging });
|
|
9
|
+
runHookServerSetup({ config: settings.config, server, logging });
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
12
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AstroSettings } from '../@types/astro';
|
|
3
3
|
import type { LogOptions } from '../core/logger/core.js';
|
|
4
4
|
interface AstroPluginJSXOptions {
|
|
5
|
-
|
|
5
|
+
settings: AstroSettings;
|
|
6
6
|
logging: LogOptions;
|
|
7
7
|
}
|
|
8
8
|
/** Use Astro config to allow for alternate or multiple JSX renderers (by default Vite will assume React) */
|
|
9
|
-
export default function jsx({
|
|
9
|
+
export default function jsx({ settings, logging }: AstroPluginJSXOptions): Plugin;
|
|
10
10
|
export {};
|
|
@@ -101,7 +101,7 @@ async function transformJSX({
|
|
|
101
101
|
map: result.map
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
|
-
function jsx({
|
|
104
|
+
function jsx({ settings, logging }) {
|
|
105
105
|
let viteConfig;
|
|
106
106
|
const jsxRenderers = /* @__PURE__ */ new Map();
|
|
107
107
|
const jsxRenderersIntegrationOnly = /* @__PURE__ */ new Map();
|
|
@@ -112,7 +112,7 @@ function jsx({ config, logging }) {
|
|
|
112
112
|
enforce: "pre",
|
|
113
113
|
async configResolved(resolvedConfig) {
|
|
114
114
|
viteConfig = resolvedConfig;
|
|
115
|
-
const possibleRenderers = collectJSXRenderers(
|
|
115
|
+
const possibleRenderers = collectJSXRenderers(settings.renderers);
|
|
116
116
|
for (const [importSource, renderer] of possibleRenderers) {
|
|
117
117
|
jsxRenderers.set(importSource, renderer);
|
|
118
118
|
if (importSource === "astro") {
|
|
@@ -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 = settings.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(
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AstroSettings } from '../@types/astro';
|
|
3
3
|
import type { LogOptions } from '../core/logger/core.js';
|
|
4
4
|
interface AstroPluginOptions {
|
|
5
|
-
|
|
5
|
+
settings: AstroSettings;
|
|
6
6
|
logging: LogOptions;
|
|
7
7
|
}
|
|
8
|
-
export default function markdown({
|
|
8
|
+
export default function markdown({ settings, logging }: AstroPluginOptions): Plugin;
|
|
9
9
|
export {};
|
|
@@ -12,17 +12,17 @@ function safeMatter(source, id) {
|
|
|
12
12
|
throw collectErrorMetadata(e);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
function markdown({
|
|
15
|
+
function markdown({ settings, logging }) {
|
|
16
16
|
return {
|
|
17
17
|
enforce: "pre",
|
|
18
18
|
name: "astro:markdown",
|
|
19
19
|
async load(id) {
|
|
20
20
|
if (id.endsWith(".md")) {
|
|
21
|
-
const { fileId, fileUrl } = getFileInfo(id, config);
|
|
21
|
+
const { fileId, fileUrl } = getFileInfo(id, settings.config);
|
|
22
22
|
const rawFile = await fs.promises.readFile(fileId, "utf-8");
|
|
23
23
|
const raw = safeMatter(rawFile, id);
|
|
24
24
|
const renderResult = await renderMarkdown(raw.content, {
|
|
25
|
-
...config.markdown,
|
|
25
|
+
...settings.config.markdown,
|
|
26
26
|
fileURL: new URL(`file://${fileId}`),
|
|
27
27
|
isAstroFlavoredMd: false
|
|
28
28
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AstroSettings } from '../@types/astro';
|
|
3
3
|
import type { LogOptions } from '../core/logger/core.js';
|
|
4
4
|
interface AstroPluginOptions {
|
|
5
|
-
|
|
5
|
+
settings: AstroSettings;
|
|
6
6
|
logging: LogOptions;
|
|
7
7
|
}
|
|
8
|
-
export default function markdown({
|
|
8
|
+
export default function markdown({ settings }: AstroPluginOptions): Plugin;
|
|
9
9
|
export {};
|
|
@@ -22,7 +22,8 @@ function safeMatter(source, id) {
|
|
|
22
22
|
throw collectErrorMetadata(e);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
function markdown({
|
|
25
|
+
function markdown({ settings }) {
|
|
26
|
+
const { config } = settings;
|
|
26
27
|
function normalizeFilename(filename) {
|
|
27
28
|
if (filename.startsWith("/@fs")) {
|
|
28
29
|
filename = filename.slice("/@fs".length);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Plugin as VitePlugin } from 'vite';
|
|
2
|
-
import {
|
|
2
|
+
import { AstroSettings } from '../@types/astro.js';
|
|
3
3
|
export declare const BEFORE_HYDRATION_SCRIPT_ID: string;
|
|
4
4
|
export declare const PAGE_SCRIPT_ID: string;
|
|
5
5
|
export declare const PAGE_SSR_SCRIPT_ID: string;
|
|
6
|
-
export default function astroScriptsPlugin({
|
|
7
|
-
|
|
6
|
+
export default function astroScriptsPlugin({ settings }: {
|
|
7
|
+
settings: AstroSettings;
|
|
8
8
|
}): VitePlugin;
|