astro 1.0.4 → 1.0.7
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/cli/index.js +1 -1
- package/dist/core/build/static-build.js +10 -25
- package/dist/core/config.js +1 -1
- package/dist/core/dev/index.js +1 -1
- package/dist/core/errors.js +1 -1
- package/dist/core/messages.js +4 -5
- package/dist/core/preview/index.js +5 -0
- package/dist/core/render/result.js +1 -2
- package/dist/core/util.js +1 -1
- package/dist/runtime/client/idle.js +1 -0
- package/dist/runtime/client/idle.prebuilt.js +1 -1
- package/dist/runtime/client/load.js +1 -0
- package/dist/runtime/client/load.prebuilt.js +1 -1
- package/dist/runtime/client/media.js +1 -0
- package/dist/runtime/client/media.prebuilt.js +1 -1
- package/dist/runtime/client/only.js +1 -0
- package/dist/runtime/client/only.prebuilt.js +1 -1
- package/dist/runtime/client/visible.js +1 -0
- package/dist/runtime/client/visible.prebuilt.js +1 -1
- package/dist/runtime/server/astro-global.js +1 -1
- package/dist/runtime/server/astro-island.js +9 -1
- package/dist/runtime/server/astro-island.prebuilt.js +1 -1
- package/dist/runtime/server/render/any.js +2 -1
- package/dist/runtime/server/render/astro.js +4 -0
- package/dist/runtime/server/render/component.js +7 -2
- package/dist/runtime/server/render/page.js +15 -19
- package/dist/runtime/server/render/types.js +0 -0
- package/dist/types/@types/astro.d.ts +1 -16
- package/dist/types/runtime/client/idle.prebuilt.d.ts +1 -1
- package/dist/types/runtime/client/load.prebuilt.d.ts +1 -1
- package/dist/types/runtime/client/media.prebuilt.d.ts +1 -1
- package/dist/types/runtime/client/only.prebuilt.d.ts +1 -1
- package/dist/types/runtime/client/visible.prebuilt.d.ts +1 -1
- package/dist/types/runtime/server/astro-island.d.ts +1 -1
- package/dist/types/runtime/server/astro-island.prebuilt.d.ts +1 -1
- package/dist/types/runtime/server/hydration.d.ts +10 -2
- package/dist/types/runtime/server/index.d.ts +1 -1
- package/dist/types/runtime/server/render/any.d.ts +1 -2
- package/dist/types/runtime/server/render/astro.d.ts +5 -3
- package/dist/types/runtime/server/render/common.d.ts +3 -2
- package/dist/types/runtime/server/render/component.d.ts +3 -2
- package/dist/types/runtime/server/render/index.d.ts +1 -0
- package/dist/types/runtime/server/render/page.d.ts +7 -1
- package/dist/types/runtime/server/render/types.d.ts +7 -0
- package/dist/vite-plugin-astro-server/index.js +2 -7
- package/dist/vite-plugin-jsx/index.js +91 -99
- package/dist/vite-plugin-markdown/index.js +1 -0
- package/package.json +2 -2
package/dist/cli/index.js
CHANGED
|
@@ -78,30 +78,27 @@ ${bgMagenta(black(" finalizing server assets "))}
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
async function ssrBuild(opts, internals, input) {
|
|
81
|
-
var _a, _b, _c
|
|
81
|
+
var _a, _b, _c;
|
|
82
82
|
const { astroConfig, viteConfig } = opts;
|
|
83
83
|
const ssr = astroConfig.output === "server";
|
|
84
84
|
const out = ssr ? opts.buildConfig.server : astroConfig.outDir;
|
|
85
85
|
const viteBuildConfig = {
|
|
86
|
+
...viteConfig,
|
|
86
87
|
logLevel: opts.viteConfig.logLevel ?? "error",
|
|
87
88
|
mode: "production",
|
|
88
|
-
css: viteConfig.css,
|
|
89
|
-
optimizeDeps: {
|
|
90
|
-
include: [...((_a = viteConfig.optimizeDeps) == null ? void 0 : _a.include) ?? []],
|
|
91
|
-
exclude: [...((_b = viteConfig.optimizeDeps) == null ? void 0 : _b.exclude) ?? []]
|
|
92
|
-
},
|
|
93
89
|
build: {
|
|
94
90
|
...viteConfig.build,
|
|
95
91
|
emptyOutDir: false,
|
|
96
92
|
manifest: false,
|
|
97
93
|
outDir: fileURLToPath(out),
|
|
98
94
|
rollupOptions: {
|
|
95
|
+
...(_a = viteConfig.build) == null ? void 0 : _a.rollupOptions,
|
|
99
96
|
input: [],
|
|
100
97
|
output: {
|
|
101
98
|
format: "esm",
|
|
102
99
|
chunkFileNames: "chunks/[name].[hash].mjs",
|
|
103
100
|
assetFileNames: "assets/[name].[hash][extname]",
|
|
104
|
-
...(
|
|
101
|
+
...(_c = (_b = viteConfig.build) == null ? void 0 : _b.rollupOptions) == null ? void 0 : _c.output,
|
|
105
102
|
entryFileNames: opts.buildConfig.serverEntry
|
|
106
103
|
}
|
|
107
104
|
},
|
|
@@ -125,12 +122,7 @@ async function ssrBuild(opts, internals, input) {
|
|
|
125
122
|
vitePluginAnalyzer(internals)
|
|
126
123
|
],
|
|
127
124
|
publicDir: ssr ? false : viteConfig.publicDir,
|
|
128
|
-
|
|
129
|
-
envPrefix: "PUBLIC_",
|
|
130
|
-
server: viteConfig.server,
|
|
131
|
-
base: astroConfig.base,
|
|
132
|
-
ssr: viteConfig.ssr,
|
|
133
|
-
resolve: viteConfig.resolve
|
|
125
|
+
envPrefix: "PUBLIC_"
|
|
134
126
|
};
|
|
135
127
|
await runHookBuildSetup({
|
|
136
128
|
config: astroConfig,
|
|
@@ -141,7 +133,7 @@ async function ssrBuild(opts, internals, input) {
|
|
|
141
133
|
return await vite.build(viteBuildConfig);
|
|
142
134
|
}
|
|
143
135
|
async function clientBuild(opts, internals, input) {
|
|
144
|
-
var _a, _b, _c
|
|
136
|
+
var _a, _b, _c;
|
|
145
137
|
const { astroConfig, viteConfig } = opts;
|
|
146
138
|
const timer = performance.now();
|
|
147
139
|
const ssr = astroConfig.output === "server";
|
|
@@ -155,26 +147,23 @@ async function clientBuild(opts, internals, input) {
|
|
|
155
147
|
info(opts.logging, null, `
|
|
156
148
|
${bgGreen(black(" building client "))}`);
|
|
157
149
|
const viteBuildConfig = {
|
|
150
|
+
...viteConfig,
|
|
158
151
|
logLevel: "info",
|
|
159
152
|
mode: "production",
|
|
160
|
-
css: viteConfig.css,
|
|
161
|
-
optimizeDeps: {
|
|
162
|
-
include: [...((_a = viteConfig.optimizeDeps) == null ? void 0 : _a.include) ?? []],
|
|
163
|
-
exclude: [...((_b = viteConfig.optimizeDeps) == null ? void 0 : _b.exclude) ?? []]
|
|
164
|
-
},
|
|
165
153
|
build: {
|
|
166
154
|
...viteConfig.build,
|
|
167
155
|
emptyOutDir: false,
|
|
168
156
|
minify: "esbuild",
|
|
169
157
|
outDir: fileURLToPath(out),
|
|
170
158
|
rollupOptions: {
|
|
159
|
+
...(_a = viteConfig.build) == null ? void 0 : _a.rollupOptions,
|
|
171
160
|
input: Array.from(input),
|
|
172
161
|
output: {
|
|
173
162
|
format: "esm",
|
|
174
163
|
entryFileNames: "[name].[hash].js",
|
|
175
164
|
chunkFileNames: "chunks/[name].[hash].js",
|
|
176
165
|
assetFileNames: "assets/[name].[hash][extname]",
|
|
177
|
-
...(
|
|
166
|
+
...(_c = (_b = viteConfig.build) == null ? void 0 : _b.rollupOptions) == null ? void 0 : _c.output
|
|
178
167
|
},
|
|
179
168
|
preserveEntrySignatures: "exports-only"
|
|
180
169
|
},
|
|
@@ -191,11 +180,7 @@ ${bgGreen(black(" building client "))}`);
|
|
|
191
180
|
}),
|
|
192
181
|
...viteConfig.plugins || []
|
|
193
182
|
],
|
|
194
|
-
|
|
195
|
-
root: viteConfig.root,
|
|
196
|
-
envPrefix: "PUBLIC_",
|
|
197
|
-
server: viteConfig.server,
|
|
198
|
-
base: astroConfig.base
|
|
183
|
+
envPrefix: "PUBLIC_"
|
|
199
184
|
};
|
|
200
185
|
await runHookBuildSetup({
|
|
201
186
|
config: astroConfig,
|
package/dist/core/config.js
CHANGED
|
@@ -218,7 +218,7 @@ function resolveFlags(flags) {
|
|
|
218
218
|
port: typeof flags.port === "number" ? flags.port : void 0,
|
|
219
219
|
config: typeof flags.config === "string" ? flags.config : void 0,
|
|
220
220
|
host: typeof flags.host === "string" || typeof flags.host === "boolean" ? flags.host : void 0,
|
|
221
|
-
drafts: typeof flags.drafts === "boolean" ? flags.drafts :
|
|
221
|
+
drafts: typeof flags.drafts === "boolean" ? flags.drafts : void 0
|
|
222
222
|
};
|
|
223
223
|
}
|
|
224
224
|
function mergeCLIFlags(astroConfig, flags, cmd) {
|
package/dist/core/dev/index.js
CHANGED
|
@@ -46,7 +46,7 @@ async function dev(config, options) {
|
|
|
46
46
|
https: !!((_a = viteConfig.server) == null ? void 0 : _a.https)
|
|
47
47
|
})
|
|
48
48
|
);
|
|
49
|
-
const currentVersion = "1.0.
|
|
49
|
+
const currentVersion = "1.0.7";
|
|
50
50
|
if (currentVersion.includes("-")) {
|
|
51
51
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
52
52
|
}
|
package/dist/core/errors.js
CHANGED
|
@@ -12,7 +12,7 @@ var AstroErrorCodes = /* @__PURE__ */ ((AstroErrorCodes2) => {
|
|
|
12
12
|
return AstroErrorCodes2;
|
|
13
13
|
})(AstroErrorCodes || {});
|
|
14
14
|
function cleanErrorStack(stack) {
|
|
15
|
-
return stack.split(/\n/g).
|
|
15
|
+
return stack.split(/\n/g).map((l) => l.replace(/\/@fs\//g, "/")).join("\n");
|
|
16
16
|
}
|
|
17
17
|
function fixViteErrorMessage(_err, server, filePath) {
|
|
18
18
|
var _a, _b;
|
package/dist/core/messages.js
CHANGED
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
yellow
|
|
16
16
|
} from "kleur/colors";
|
|
17
17
|
import os from "os";
|
|
18
|
-
import { cleanErrorStack } from "./errors.js";
|
|
19
18
|
import { emoji, getLocalAddress, padMultilineString } from "./util.js";
|
|
20
19
|
const PREFIX_PADDING = 6;
|
|
21
20
|
function req({
|
|
@@ -47,7 +46,7 @@ function devStart({
|
|
|
47
46
|
https,
|
|
48
47
|
site
|
|
49
48
|
}) {
|
|
50
|
-
const version = "1.0.
|
|
49
|
+
const version = "1.0.7";
|
|
51
50
|
const rootPath = site ? site.pathname : "/";
|
|
52
51
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
53
52
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -190,10 +189,10 @@ function formatErrorMessage(err, args = []) {
|
|
|
190
189
|
args.push(red(padMultilineString(err.frame, 4)));
|
|
191
190
|
}
|
|
192
191
|
if (args.length === 1 && err.stack) {
|
|
193
|
-
args.push(dim(
|
|
192
|
+
args.push(dim(err.stack));
|
|
194
193
|
} else if (err.stack) {
|
|
195
194
|
args.push(` ${bold("Stacktrace:")}`);
|
|
196
|
-
args.push(dim(
|
|
195
|
+
args.push(dim(err.stack));
|
|
197
196
|
args.push(``);
|
|
198
197
|
}
|
|
199
198
|
return args.join("\n");
|
|
@@ -226,7 +225,7 @@ function printHelp({
|
|
|
226
225
|
message.push(
|
|
227
226
|
linebreak(),
|
|
228
227
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
229
|
-
`v${"1.0.
|
|
228
|
+
`v${"1.0.7"}`
|
|
230
229
|
)} ${headline}`
|
|
231
230
|
);
|
|
232
231
|
}
|
|
@@ -9,6 +9,11 @@ import * as msg from "../messages.js";
|
|
|
9
9
|
import { getResolvedHostForHttpServer } from "./util.js";
|
|
10
10
|
const HAS_FILE_EXTENSION_REGEXP = /^.*\.[^\\]+$/;
|
|
11
11
|
async function preview(config, { logging }) {
|
|
12
|
+
if (config.output === "server") {
|
|
13
|
+
throw new Error(
|
|
14
|
+
`[preview] 'output: server' not supported. Use your deploy platform's preview command directly instead, if one exists. (ex: 'netlify dev', 'vercel dev', 'wrangler', etc.)`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
12
17
|
const startServerTime = performance.now();
|
|
13
18
|
const defaultOrigin = "http://localhost";
|
|
14
19
|
const trailingSlash = config.trailingSlash;
|
|
@@ -223,8 +223,7 @@ const canonicalURL = new URL(Astro.url.pathname, Astro.site);
|
|
|
223
223
|
renderers,
|
|
224
224
|
pathname,
|
|
225
225
|
hasHydrationScript: false,
|
|
226
|
-
hasDirectives: /* @__PURE__ */ new Set()
|
|
227
|
-
pendingInstructions: /* @__PURE__ */ new Set()
|
|
226
|
+
hasDirectives: /* @__PURE__ */ new Set()
|
|
228
227
|
},
|
|
229
228
|
response
|
|
230
229
|
};
|
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.0.
|
|
8
|
+
const ASTRO_VERSION = "1.0.7";
|
|
9
9
|
function isObject(value) {
|
|
10
10
|
return typeof value === "object" && value != null;
|
|
11
11
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var idle_prebuilt_default = `(self.Astro=self.Astro||{}).idle=
|
|
1
|
+
var idle_prebuilt_default = `(self.Astro=self.Astro||{}).idle=t=>{const e=async()=>{await(await t())()};"requestIdleCallback"in window?window.requestIdleCallback(e):setTimeout(e,200)},window.dispatchEvent(new Event("astro:idle"));`;
|
|
2
2
|
export {
|
|
3
3
|
idle_prebuilt_default as default
|
|
4
4
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var load_prebuilt_default = `(self.Astro=self.Astro||{}).load=a=>{(async()=>await(await a())())()};`;
|
|
1
|
+
var load_prebuilt_default = `(self.Astro=self.Astro||{}).load=a=>{(async()=>await(await a())())()},window.dispatchEvent(new Event("astro:load"));`;
|
|
2
2
|
export {
|
|
3
3
|
load_prebuilt_default as default
|
|
4
4
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var media_prebuilt_default = `(self.Astro=self.Astro||{}).media=(s,a)=>{const t=async()=>{await(await s())()};if(a.value){const e=matchMedia(a.value);e.matches?t():e.addEventListener("change",t,{once:!0})}};`;
|
|
1
|
+
var media_prebuilt_default = `(self.Astro=self.Astro||{}).media=(s,a)=>{const t=async()=>{await(await s())()};if(a.value){const e=matchMedia(a.value);e.matches?t():e.addEventListener("change",t,{once:!0})}},window.dispatchEvent(new Event("astro:media"));`;
|
|
2
2
|
export {
|
|
3
3
|
media_prebuilt_default as default
|
|
4
4
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var only_prebuilt_default = `(self.Astro=self.Astro||{}).only=
|
|
1
|
+
var only_prebuilt_default = `(self.Astro=self.Astro||{}).only=t=>{(async()=>await(await t())())()},window.dispatchEvent(new Event("astro:only"));`;
|
|
2
2
|
export {
|
|
3
3
|
only_prebuilt_default as default
|
|
4
4
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var visible_prebuilt_default = `(self.Astro=self.Astro||{}).visible=(
|
|
1
|
+
var visible_prebuilt_default = `(self.Astro=self.Astro||{}).visible=(s,c,n)=>{const r=async()=>{await(await s())()};let i=new IntersectionObserver(e=>{for(const t of e)if(!!t.isIntersecting){i.disconnect(),r();break}});for(let e=0;e<n.children.length;e++){const t=n.children[e];i.observe(t)}},window.dispatchEvent(new Event("astro:visible"));`;
|
|
2
2
|
export {
|
|
3
3
|
visible_prebuilt_default as default
|
|
4
4
|
};
|
|
@@ -63,8 +63,16 @@ var _a;
|
|
|
63
63
|
async childrenConnectedCallback() {
|
|
64
64
|
window.addEventListener("astro:hydrate", this.hydrate);
|
|
65
65
|
await import(this.getAttribute("before-hydration-url"));
|
|
66
|
+
this.start();
|
|
67
|
+
}
|
|
68
|
+
start() {
|
|
66
69
|
const opts = JSON.parse(this.getAttribute("opts"));
|
|
67
|
-
|
|
70
|
+
const directive = this.getAttribute("client");
|
|
71
|
+
if (Astro[directive] === void 0) {
|
|
72
|
+
window.addEventListener(`astro:${directive}`, () => this.start(), { once: true });
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
Astro[directive](
|
|
68
76
|
async () => {
|
|
69
77
|
const rendererUrl = this.getAttribute("renderer-url");
|
|
70
78
|
const [componentModule, { default: hydrator }] = await Promise.all([
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var astro_island_prebuilt_default = `var
|
|
1
|
+
var astro_island_prebuilt_default = `var d;{const l={0:t=>t,1:t=>JSON.parse(t,n),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,n)),5:t=>new Set(JSON.parse(t,n)),6:t=>BigInt(t),7:t=>new URL(t)},n=(t,r)=>{if(t===""||!Array.isArray(r))return r;const[e,i]=r;return e in l?l[e](i):void 0};customElements.get("astro-island")||customElements.define("astro-island",(d=class extends HTMLElement{constructor(){super(...arguments);this.hydrate=()=>{if(!this.hydrator||this.parentElement?.closest("astro-island[ssr]"))return;const r=this.querySelectorAll("astro-slot"),e={},i=this.querySelectorAll("template[data-astro-template]");for(const s of i)!s.closest(this.tagName)?.isSameNode(this)||(e[s.getAttribute("data-astro-template")||"default"]=s.innerHTML,s.remove());for(const s of r)!s.closest(this.tagName)?.isSameNode(this)||(e[s.getAttribute("name")||"default"]=s.innerHTML);const o=this.hasAttribute("props")?JSON.parse(this.getAttribute("props"),n):{};this.hydrator(this)(this.Component,o,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((r,e)=>{e.disconnect(),this.childrenConnectedCallback()}).observe(this,{childList:!0})}async childrenConnectedCallback(){window.addEventListener("astro:hydrate",this.hydrate),await import(this.getAttribute("before-hydration-url")),this.start()}start(){const r=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 i=this.getAttribute("renderer-url"),[o,{default:s}]=await Promise.all([import(this.getAttribute("component-url")),i?import(i):()=>()=>{}]),a=this.getAttribute("component-export")||"default";if(!a.includes("."))this.Component=o[a];else{this.Component=o;for(const c of a.split("."))this.Component=this.Component[c]}return this.hydrator=s,this.hydrate},r,this)}attributeChangedCallback(){this.hydrator&&this.hydrate()}},d.observedAttributes=["props"],d))}`;
|
|
2
2
|
export {
|
|
3
3
|
astro_island_prebuilt_default as default
|
|
4
4
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { escapeHTML, HTMLString, markHTMLString } from "../escape.js";
|
|
2
2
|
import { AstroComponent, renderAstroComponent } from "./astro.js";
|
|
3
|
+
import { stringifyChunk } from "./common.js";
|
|
3
4
|
async function* renderChild(child) {
|
|
4
5
|
child = await child;
|
|
5
6
|
if (child instanceof HTMLString) {
|
|
@@ -27,7 +28,7 @@ async function renderSlot(result, slotted, fallback) {
|
|
|
27
28
|
let content = "";
|
|
28
29
|
for await (const chunk of iterator) {
|
|
29
30
|
if (chunk.type === "directive") {
|
|
30
|
-
result
|
|
31
|
+
content += stringifyChunk(result, chunk);
|
|
31
32
|
} else {
|
|
32
33
|
content += chunk;
|
|
33
34
|
}
|
|
@@ -35,6 +35,9 @@ class AstroComponent {
|
|
|
35
35
|
function isAstroComponent(obj) {
|
|
36
36
|
return typeof obj === "object" && Object.prototype.toString.call(obj) === "[object AstroComponent]";
|
|
37
37
|
}
|
|
38
|
+
function isAstroComponentFactory(obj) {
|
|
39
|
+
return obj == null ? false : !!obj.isAstroComponentFactory;
|
|
40
|
+
}
|
|
38
41
|
async function* renderAstroComponent(component) {
|
|
39
42
|
for await (const value of component) {
|
|
40
43
|
if (value || value === 0) {
|
|
@@ -83,6 +86,7 @@ async function renderTemplate(htmlParts, ...expressions) {
|
|
|
83
86
|
export {
|
|
84
87
|
AstroComponent,
|
|
85
88
|
isAstroComponent,
|
|
89
|
+
isAstroComponentFactory,
|
|
86
90
|
renderAstroComponent,
|
|
87
91
|
renderTemplate,
|
|
88
92
|
renderToIterable,
|
|
@@ -3,7 +3,12 @@ import { extractDirectives, generateHydrateScript } from "../hydration.js";
|
|
|
3
3
|
import { serializeProps } from "../serialize.js";
|
|
4
4
|
import { shorthash } from "../shorthash.js";
|
|
5
5
|
import { renderSlot } from "./any.js";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
isAstroComponentFactory,
|
|
8
|
+
renderAstroComponent,
|
|
9
|
+
renderTemplate,
|
|
10
|
+
renderToIterable
|
|
11
|
+
} from "./astro.js";
|
|
7
12
|
import { Fragment, Renderer } from "./common.js";
|
|
8
13
|
import { componentIsHTMLElement, renderHTMLElement } from "./dom.js";
|
|
9
14
|
import { formatList, internalSpreadAttributes, renderElement, voidElementNames } from "./util.js";
|
|
@@ -29,7 +34,7 @@ function getComponentType(Component) {
|
|
|
29
34
|
if (Component && typeof Component === "object" && Component["astro:html"]) {
|
|
30
35
|
return "html";
|
|
31
36
|
}
|
|
32
|
-
if (Component
|
|
37
|
+
if (isAstroComponentFactory(Component)) {
|
|
33
38
|
return "astro-factory";
|
|
34
39
|
}
|
|
35
40
|
return "unknown";
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { createResponse } from "../response.js";
|
|
2
|
-
import { isAstroComponent, renderAstroComponent } from "./astro.js";
|
|
2
|
+
import { isAstroComponent, isAstroComponentFactory, renderAstroComponent } from "./astro.js";
|
|
3
3
|
import { stringifyChunk } from "./common.js";
|
|
4
4
|
import { renderComponent } from "./component.js";
|
|
5
5
|
import { maybeRenderHead } from "./head.js";
|
|
6
6
|
const encoder = new TextEncoder();
|
|
7
|
+
const needsHeadRenderingSymbol = Symbol.for("astro.needsHeadRendering");
|
|
8
|
+
function nonAstroPageNeedsHeadInjection(pageComponent) {
|
|
9
|
+
return needsHeadRenderingSymbol in pageComponent && !!pageComponent[needsHeadRenderingSymbol];
|
|
10
|
+
}
|
|
7
11
|
async function renderPage(result, componentFactory, props, children, streaming) {
|
|
8
|
-
if (!componentFactory
|
|
12
|
+
if (!isAstroComponentFactory(componentFactory)) {
|
|
9
13
|
const pageProps = { ...props ?? {}, "server:root": true };
|
|
10
14
|
const output = await renderComponent(
|
|
11
15
|
result,
|
|
@@ -18,15 +22,18 @@ async function renderPage(result, componentFactory, props, children, streaming)
|
|
|
18
22
|
if (!/<!doctype html/i.test(html)) {
|
|
19
23
|
let rest = html;
|
|
20
24
|
html = `<!DOCTYPE html>`;
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
if (nonAstroPageNeedsHeadInjection(componentFactory)) {
|
|
26
|
+
for await (let chunk of maybeRenderHead(result)) {
|
|
27
|
+
html += chunk;
|
|
28
|
+
}
|
|
23
29
|
}
|
|
24
30
|
html += rest;
|
|
25
31
|
}
|
|
26
|
-
|
|
32
|
+
const bytes = encoder.encode(html);
|
|
33
|
+
return new Response(bytes, {
|
|
27
34
|
headers: new Headers([
|
|
28
35
|
["Content-Type", "text/html; charset=utf-8"],
|
|
29
|
-
["Content-Length",
|
|
36
|
+
["Content-Length", bytes.byteLength.toString()]
|
|
30
37
|
])
|
|
31
38
|
});
|
|
32
39
|
}
|
|
@@ -36,24 +43,13 @@ async function renderPage(result, componentFactory, props, children, streaming)
|
|
|
36
43
|
let init = result.response;
|
|
37
44
|
let headers = new Headers(init.headers);
|
|
38
45
|
let body;
|
|
39
|
-
async function* eachChunk() {
|
|
40
|
-
for await (const chunk of iterable) {
|
|
41
|
-
if (result._metadata.pendingInstructions.size) {
|
|
42
|
-
for (const instr of result._metadata.pendingInstructions) {
|
|
43
|
-
result._metadata.pendingInstructions.delete(instr);
|
|
44
|
-
yield instr;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
yield chunk;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
46
|
if (streaming) {
|
|
51
47
|
body = new ReadableStream({
|
|
52
48
|
start(controller) {
|
|
53
49
|
async function read() {
|
|
54
50
|
let i = 0;
|
|
55
51
|
try {
|
|
56
|
-
for await (const chunk of
|
|
52
|
+
for await (const chunk of iterable) {
|
|
57
53
|
let html = stringifyChunk(result, chunk);
|
|
58
54
|
if (i === 0) {
|
|
59
55
|
if (!/<!doctype html/i.test(html)) {
|
|
@@ -74,7 +70,7 @@ async function renderPage(result, componentFactory, props, children, streaming)
|
|
|
74
70
|
} else {
|
|
75
71
|
body = "";
|
|
76
72
|
let i = 0;
|
|
77
|
-
for await (const chunk of
|
|
73
|
+
for await (const chunk of iterable) {
|
|
78
74
|
let html = stringifyChunk(result, chunk);
|
|
79
75
|
if (i === 0) {
|
|
80
76
|
if (!/<!doctype html/i.test(html)) {
|
|
File without changes
|
|
@@ -799,8 +799,7 @@ export interface MarkdownLayoutProps<T extends Record<string, any>> {
|
|
|
799
799
|
rawContent: MarkdownInstance<T>['rawContent'];
|
|
800
800
|
compiledContent: MarkdownInstance<T>['compiledContent'];
|
|
801
801
|
}
|
|
802
|
-
export
|
|
803
|
-
}
|
|
802
|
+
export declare type MDXLayoutProps<T> = Omit<MarkdownLayoutProps<T>, 'rawContent' | 'compiledContent'>;
|
|
804
803
|
export declare type GetHydrateCallback = () => Promise<() => void | Promise<void>>;
|
|
805
804
|
/**
|
|
806
805
|
* getStaticPaths() options
|
|
@@ -1016,25 +1015,11 @@ export interface SSRElement {
|
|
|
1016
1015
|
props: Record<string, any>;
|
|
1017
1016
|
children: string;
|
|
1018
1017
|
}
|
|
1019
|
-
export interface HydrationMetadata {
|
|
1020
|
-
directive: string;
|
|
1021
|
-
value: string;
|
|
1022
|
-
componentUrl: string;
|
|
1023
|
-
componentExport: {
|
|
1024
|
-
value: string;
|
|
1025
|
-
};
|
|
1026
|
-
}
|
|
1027
|
-
export interface SSRRenderInstruction {
|
|
1028
|
-
type: 'directive';
|
|
1029
|
-
result: SSRResult;
|
|
1030
|
-
hydration: HydrationMetadata;
|
|
1031
|
-
}
|
|
1032
1018
|
export interface SSRMetadata {
|
|
1033
1019
|
renderers: SSRLoadedRenderer[];
|
|
1034
1020
|
pathname: string;
|
|
1035
1021
|
hasHydrationScript: boolean;
|
|
1036
1022
|
hasDirectives: Set<string>;
|
|
1037
|
-
pendingInstructions: Set<SSRRenderInstruction>;
|
|
1038
1023
|
}
|
|
1039
1024
|
export interface SSRResult {
|
|
1040
1025
|
styles: Set<SSRElement>;
|
|
@@ -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: "(self.Astro=self.Astro||{}).idle=
|
|
6
|
+
declare const _default: "(self.Astro=self.Astro||{}).idle=t=>{const e=async()=>{await(await t())()};\"requestIdleCallback\"in window?window.requestIdleCallback(e):setTimeout(e,200)},window.dispatchEvent(new Event(\"astro:idle\"));";
|
|
7
7
|
export default _default;
|
|
@@ -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: "(self.Astro=self.Astro||{}).load=a=>{(async()=>await(await a())())()};";
|
|
6
|
+
declare const _default: "(self.Astro=self.Astro||{}).load=a=>{(async()=>await(await a())())()},window.dispatchEvent(new Event(\"astro:load\"));";
|
|
7
7
|
export default _default;
|
|
@@ -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: "(self.Astro=self.Astro||{}).media=(s,a)=>{const t=async()=>{await(await s())()};if(a.value){const e=matchMedia(a.value);e.matches?t():e.addEventListener(\"change\",t,{once:!0})}};";
|
|
6
|
+
declare const _default: "(self.Astro=self.Astro||{}).media=(s,a)=>{const t=async()=>{await(await s())()};if(a.value){const e=matchMedia(a.value);e.matches?t():e.addEventListener(\"change\",t,{once:!0})}},window.dispatchEvent(new Event(\"astro:media\"));";
|
|
7
7
|
export default _default;
|
|
@@ -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: "(self.Astro=self.Astro||{}).only=
|
|
6
|
+
declare const _default: "(self.Astro=self.Astro||{}).only=t=>{(async()=>await(await t())())()},window.dispatchEvent(new Event(\"astro:only\"));";
|
|
7
7
|
export default _default;
|
|
@@ -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: "(self.Astro=self.Astro||{}).visible=(
|
|
6
|
+
declare const _default: "(self.Astro=self.Astro||{}).visible=(s,c,n)=>{const r=async()=>{await(await s())()};let i=new IntersectionObserver(e=>{for(const t of e)if(!!t.isIntersecting){i.disconnect(),r();break}});for(let e=0;e<n.children.length;e++){const t=n.children[e];i.observe(t)}},window.dispatchEvent(new Event(\"astro:visible\"));";
|
|
7
7
|
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
declare type directiveAstroKeys = 'load' | 'idle' | 'visible' | 'media' | 'only';
|
|
2
2
|
declare const Astro: {
|
|
3
|
-
[k in directiveAstroKeys]
|
|
3
|
+
[k in directiveAstroKeys]?: (fn: () => Promise<() => void>, opts: Record<string, any>, root: HTMLElement) => void;
|
|
4
4
|
};
|
|
@@ -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
|
|
6
|
+
declare const _default: "var d;{const l={0:t=>t,1:t=>JSON.parse(t,n),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(JSON.parse(t,n)),5:t=>new Set(JSON.parse(t,n)),6:t=>BigInt(t),7:t=>new URL(t)},n=(t,r)=>{if(t===\"\"||!Array.isArray(r))return r;const[e,i]=r;return e in l?l[e](i):void 0};customElements.get(\"astro-island\")||customElements.define(\"astro-island\",(d=class extends HTMLElement{constructor(){super(...arguments);this.hydrate=()=>{if(!this.hydrator||this.parentElement?.closest(\"astro-island[ssr]\"))return;const r=this.querySelectorAll(\"astro-slot\"),e={},i=this.querySelectorAll(\"template[data-astro-template]\");for(const s of i)!s.closest(this.tagName)?.isSameNode(this)||(e[s.getAttribute(\"data-astro-template\")||\"default\"]=s.innerHTML,s.remove());for(const s of r)!s.closest(this.tagName)?.isSameNode(this)||(e[s.getAttribute(\"name\")||\"default\"]=s.innerHTML);const o=this.hasAttribute(\"props\")?JSON.parse(this.getAttribute(\"props\"),n):{};this.hydrator(this)(this.Component,o,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((r,e)=>{e.disconnect(),this.childrenConnectedCallback()}).observe(this,{childList:!0})}async childrenConnectedCallback(){window.addEventListener(\"astro:hydrate\",this.hydrate),await import(this.getAttribute(\"before-hydration-url\")),this.start()}start(){const r=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 i=this.getAttribute(\"renderer-url\"),[o,{default:s}]=await Promise.all([import(this.getAttribute(\"component-url\")),i?import(i):()=>()=>{}]),a=this.getAttribute(\"component-export\")||\"default\";if(!a.includes(\".\"))this.Component=o[a];else{this.Component=o;for(const c of a.split(\".\"))this.Component=this.Component[c]}return this.hydrator=s,this.hydrate},r,this)}attributeChangedCallback(){this.hydrator&&this.hydrate()}},d.observedAttributes=[\"props\"],d))}";
|
|
7
7
|
export default _default;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import type { AstroComponentMetadata,
|
|
1
|
+
import type { AstroComponentMetadata, SSRElement, SSRLoadedRenderer, SSRResult } from '../../@types/astro';
|
|
2
2
|
export declare const HydrationDirectiveProps: Set<string>;
|
|
3
|
-
export
|
|
3
|
+
export interface HydrationMetadata {
|
|
4
|
+
directive: string;
|
|
5
|
+
value: string;
|
|
6
|
+
componentUrl: string;
|
|
7
|
+
componentExport: {
|
|
8
|
+
value: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
4
11
|
interface ExtractedProps {
|
|
5
12
|
isPage: boolean;
|
|
6
13
|
hydration: HydrationMetadata | null;
|
|
@@ -16,3 +23,4 @@ interface HydrateScriptOptions {
|
|
|
16
23
|
}
|
|
17
24
|
/** For hydrated components, generate a <script type="module"> to load the component */
|
|
18
25
|
export declare function generateHydrateScript(scriptOptions: HydrateScriptOptions, metadata: Required<AstroComponentMetadata>): Promise<SSRElement>;
|
|
26
|
+
export {};
|
|
@@ -4,7 +4,7 @@ export { escapeHTML, HTMLString, markHTMLString, markHTMLString as unescapeHTML,
|
|
|
4
4
|
export type { Metadata } from './metadata';
|
|
5
5
|
export { createMetadata } from './metadata.js';
|
|
6
6
|
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';
|
|
7
|
-
export type { AstroComponentFactory } from './render/index.js';
|
|
7
|
+
export type { AstroComponentFactory, RenderInstruction } from './render/index.js';
|
|
8
8
|
import type { AstroComponentFactory } from './render/index.js';
|
|
9
9
|
export declare function createComponent(cb: AstroComponentFactory): AstroComponentFactory;
|
|
10
10
|
export declare function mergeSlots(...slotted: unknown[]): Record<string, () => any>;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { SSRResult } from '../../../@types/astro';
|
|
2
1
|
export declare function renderChild(child: any): AsyncIterable<any>;
|
|
3
|
-
export declare function renderSlot(result:
|
|
2
|
+
export declare function renderSlot(result: any, slotted: string, fallback?: any): Promise<string>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SSRResult } from '../../../@types/astro';
|
|
2
2
|
import type { AstroComponentFactory } from './index';
|
|
3
|
+
import type { RenderInstruction } from './types';
|
|
3
4
|
export declare class AstroComponent {
|
|
4
5
|
private htmlParts;
|
|
5
6
|
private expressions;
|
|
@@ -8,7 +9,8 @@ export declare class AstroComponent {
|
|
|
8
9
|
[Symbol.asyncIterator](): AsyncGenerator<any, void, undefined>;
|
|
9
10
|
}
|
|
10
11
|
export declare function isAstroComponent(obj: any): obj is AstroComponent;
|
|
11
|
-
export declare function
|
|
12
|
+
export declare function isAstroComponentFactory(obj: any): obj is AstroComponentFactory;
|
|
13
|
+
export declare function renderAstroComponent(component: InstanceType<typeof AstroComponent>): AsyncIterable<string | RenderInstruction>;
|
|
12
14
|
export declare function renderToString(result: SSRResult, componentFactory: AstroComponentFactory, props: any, children: any): Promise<string>;
|
|
13
|
-
export declare function renderToIterable(result: SSRResult, componentFactory: AstroComponentFactory, displayName: string, props: any, children: any): Promise<AsyncIterable<string |
|
|
15
|
+
export declare function renderToIterable(result: SSRResult, componentFactory: AstroComponentFactory, displayName: string, props: any, children: any): Promise<AsyncIterable<string | RenderInstruction>>;
|
|
14
16
|
export declare function renderTemplate(htmlParts: TemplateStringsArray, ...expressions: any[]): Promise<AstroComponent>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SSRResult } from '../../../@types/astro';
|
|
2
|
+
import type { RenderInstruction } from './types.js';
|
|
2
3
|
export declare const Fragment: unique symbol;
|
|
3
4
|
export declare const Renderer: unique symbol;
|
|
4
|
-
export declare function stringifyChunk(result: SSRResult, chunk: string |
|
|
5
|
+
export declare function stringifyChunk(result: SSRResult, chunk: string | RenderInstruction): any;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { SSRResult } from '../../../@types/astro';
|
|
2
|
+
import type { RenderInstruction } from './types.js';
|
|
3
|
+
export declare function renderComponent(result: SSRResult, displayName: string, Component: unknown, _props: Record<string | number, any>, slots?: any): Promise<string | AsyncIterable<string | RenderInstruction>>;
|
|
@@ -6,6 +6,7 @@ export { renderComponent } from './component.js';
|
|
|
6
6
|
export { renderHTMLElement } from './dom.js';
|
|
7
7
|
export { maybeRenderHead, renderHead } from './head.js';
|
|
8
8
|
export { renderPage } from './page.js';
|
|
9
|
+
export type { RenderInstruction } from './types';
|
|
9
10
|
export { addAttribute, defineScriptVars, voidElementNames } from './util.js';
|
|
10
11
|
export interface AstroComponentFactory {
|
|
11
12
|
(result: any, props: any, slots: any): ReturnType<typeof renderTemplate> | Response;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type { SSRResult } from '../../../@types/astro';
|
|
2
2
|
import type { AstroComponentFactory } from './index';
|
|
3
|
-
|
|
3
|
+
declare const needsHeadRenderingSymbol: unique symbol;
|
|
4
|
+
declare type NonAstroPageComponent = {
|
|
5
|
+
name: string;
|
|
6
|
+
[needsHeadRenderingSymbol]: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function renderPage(result: SSRResult, componentFactory: AstroComponentFactory | NonAstroPageComponent, props: any, children: any, streaming: boolean): Promise<Response>;
|
|
9
|
+
export {};
|
|
@@ -176,12 +176,6 @@ async function handleRequest(routeCache, viteServer, logging, manifest, config,
|
|
|
176
176
|
});
|
|
177
177
|
async function matchRoute() {
|
|
178
178
|
const matches = matchAllRoutes(pathname, manifest);
|
|
179
|
-
if (config.output === "server" && matches.length > 1) {
|
|
180
|
-
throw new Error(`Found multiple matching routes for "${pathname}"! When using \`output: 'server'\`, only one route in \`src/pages\` can match a given URL. Found:
|
|
181
|
-
|
|
182
|
-
${matches.map(({ component }) => `- ${component}`).join("\n")}
|
|
183
|
-
`);
|
|
184
|
-
}
|
|
185
179
|
for await (const maybeRoute of matches) {
|
|
186
180
|
const filePath2 = new URL(`./${maybeRoute.component}`, config.root);
|
|
187
181
|
const preloadedComponent = await preload({ astroConfig: config, filePath: filePath2, viteServer });
|
|
@@ -259,7 +253,8 @@ ${matches.map(({ component }) => `- ${component}`).join("\n")}
|
|
|
259
253
|
await writeWebResponse(res, result.response);
|
|
260
254
|
} else {
|
|
261
255
|
let contentType = "text/plain";
|
|
262
|
-
const
|
|
256
|
+
const filepath = route.pathname || route.segments.map((segment) => segment.map((p) => p.content).join("")).join("/");
|
|
257
|
+
const computedMimeType = mime.getType(filepath);
|
|
263
258
|
if (computedMimeType) {
|
|
264
259
|
contentType = computedMimeType;
|
|
265
260
|
}
|
|
@@ -6,7 +6,6 @@ import path from "path";
|
|
|
6
6
|
import { error } from "../core/logger/core.js";
|
|
7
7
|
import { parseNpmName } from "../core/util.js";
|
|
8
8
|
import tagExportsPlugin from "./tag.js";
|
|
9
|
-
const JSX_RENDERER_CACHE = /* @__PURE__ */ new WeakMap();
|
|
10
9
|
const JSX_EXTENSIONS = /* @__PURE__ */ new Set([".jsx", ".tsx", ".mdx"]);
|
|
11
10
|
const IMPORT_STATEMENTS = {
|
|
12
11
|
react: "import React from 'react'",
|
|
@@ -15,6 +14,7 @@ const IMPORT_STATEMENTS = {
|
|
|
15
14
|
astro: "import 'astro/jsx-runtime'"
|
|
16
15
|
};
|
|
17
16
|
const PREVENT_UNUSED_IMPORTS = ";;(React,Fragment,h);";
|
|
17
|
+
const IMPORT_KEYWORD_REGEX = /import/;
|
|
18
18
|
function getEsbuildLoader(fileExt) {
|
|
19
19
|
if (fileExt === ".mdx")
|
|
20
20
|
return "jsx";
|
|
@@ -26,6 +26,36 @@ function collectJSXRenderers(renderers) {
|
|
|
26
26
|
renderersWithJSXSupport.map((r) => [r.jsxImportSource, r])
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
|
+
function detectImportSourceFromComments(code) {
|
|
30
|
+
const multiline = code.match(/\/\*\*?[\S\s]*\*\//gm) || [];
|
|
31
|
+
for (const comment of multiline) {
|
|
32
|
+
const [_, lib] = comment.slice(0, -2).match(/@jsxImportSource\s*(\S+)/) || [];
|
|
33
|
+
if (lib) {
|
|
34
|
+
return lib.trim();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function detectImportSourceFromImports(code, id, jsxRenderers) {
|
|
39
|
+
const { code: jsCode } = await esbuild.transform(code + PREVENT_UNUSED_IMPORTS, {
|
|
40
|
+
loader: getEsbuildLoader(path.extname(id)),
|
|
41
|
+
jsx: "transform",
|
|
42
|
+
jsxFactory: "h",
|
|
43
|
+
jsxFragment: "Fragment",
|
|
44
|
+
sourcefile: id,
|
|
45
|
+
sourcemap: "inline"
|
|
46
|
+
});
|
|
47
|
+
const [imports] = eslexer.parse(jsCode);
|
|
48
|
+
if (imports.length > 0) {
|
|
49
|
+
for (let { n: spec } of imports) {
|
|
50
|
+
const pkg = spec && parseNpmName(spec);
|
|
51
|
+
if (!pkg)
|
|
52
|
+
continue;
|
|
53
|
+
if (jsxRenderers.has(pkg.name)) {
|
|
54
|
+
return pkg.name;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
29
59
|
async function transformJSX({
|
|
30
60
|
code,
|
|
31
61
|
mode,
|
|
@@ -73,11 +103,25 @@ async function transformJSX({
|
|
|
73
103
|
}
|
|
74
104
|
function jsx({ config, logging }) {
|
|
75
105
|
let viteConfig;
|
|
106
|
+
const jsxRenderers = /* @__PURE__ */ new Map();
|
|
107
|
+
const jsxRenderersIntegrationOnly = /* @__PURE__ */ new Map();
|
|
108
|
+
let astroJSXRenderer;
|
|
109
|
+
let defaultJSXRendererEntry;
|
|
76
110
|
return {
|
|
77
111
|
name: "astro:jsx",
|
|
78
112
|
enforce: "pre",
|
|
79
|
-
configResolved(resolvedConfig) {
|
|
113
|
+
async configResolved(resolvedConfig) {
|
|
80
114
|
viteConfig = resolvedConfig;
|
|
115
|
+
const possibleRenderers = await collectJSXRenderers(config._ctx.renderers);
|
|
116
|
+
for (const [importSource, renderer] of possibleRenderers) {
|
|
117
|
+
jsxRenderers.set(importSource, renderer);
|
|
118
|
+
if (importSource === "astro") {
|
|
119
|
+
astroJSXRenderer = renderer;
|
|
120
|
+
} else {
|
|
121
|
+
jsxRenderersIntegrationOnly.set(importSource, renderer);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
defaultJSXRendererEntry = [...jsxRenderersIntegrationOnly.entries()][0];
|
|
81
125
|
},
|
|
82
126
|
async transform(code, id, opts) {
|
|
83
127
|
const ssr = Boolean(opts == null ? void 0 : opts.ssr);
|
|
@@ -85,130 +129,78 @@ function jsx({ config, logging }) {
|
|
|
85
129
|
return null;
|
|
86
130
|
}
|
|
87
131
|
const { mode } = viteConfig;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
jsxRenderers = /* @__PURE__ */ new Map();
|
|
91
|
-
const possibleRenderers = await collectJSXRenderers(config._ctx.renderers);
|
|
92
|
-
if (possibleRenderers.size === 0) {
|
|
93
|
-
throw new Error(
|
|
94
|
-
`${colors.yellow(
|
|
95
|
-
id
|
|
96
|
-
)}
|
|
97
|
-
Unable to resolve a JSX renderer! Did you forget to include one? Add a JSX integration like \`@astrojs/react\` to your \`astro.config.mjs\` file.`
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
for (const [importSource2, renderer] of possibleRenderers) {
|
|
101
|
-
jsxRenderers.set(importSource2, renderer);
|
|
102
|
-
}
|
|
103
|
-
JSX_RENDERER_CACHE.set(config, jsxRenderers);
|
|
104
|
-
}
|
|
105
|
-
const astroRenderer = jsxRenderers.get("astro");
|
|
106
|
-
if ((id.includes(".mdx") || id.includes(".md")) && astroRenderer) {
|
|
107
|
-
const { code: jsxCode } = await esbuild.transform(code, {
|
|
132
|
+
if (id.includes(".mdx") || id.includes(".md")) {
|
|
133
|
+
const { code: jsxCode2 } = await esbuild.transform(code, {
|
|
108
134
|
loader: getEsbuildLoader(path.extname(id)),
|
|
109
135
|
jsx: "preserve",
|
|
110
136
|
sourcefile: id,
|
|
111
137
|
sourcemap: "inline"
|
|
112
138
|
});
|
|
113
139
|
return transformJSX({
|
|
114
|
-
code:
|
|
140
|
+
code: jsxCode2,
|
|
115
141
|
id,
|
|
116
|
-
renderer:
|
|
142
|
+
renderer: astroJSXRenderer,
|
|
117
143
|
mode,
|
|
118
144
|
ssr
|
|
119
145
|
});
|
|
120
146
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
);
|
|
124
|
-
if (nonAstroJsxRenderers.size === 1) {
|
|
125
|
-
const { code: jsxCode } = await esbuild.transform(code, {
|
|
147
|
+
if (defaultJSXRendererEntry && jsxRenderersIntegrationOnly.size === 1) {
|
|
148
|
+
const { code: jsxCode2 } = await esbuild.transform(code, {
|
|
126
149
|
loader: getEsbuildLoader(path.extname(id)),
|
|
127
150
|
jsx: "preserve",
|
|
128
151
|
sourcefile: id,
|
|
129
152
|
sourcemap: "inline"
|
|
130
153
|
});
|
|
131
154
|
return transformJSX({
|
|
132
|
-
code:
|
|
155
|
+
code: jsxCode2,
|
|
133
156
|
id,
|
|
134
|
-
renderer: [
|
|
157
|
+
renderer: defaultJSXRendererEntry[1],
|
|
135
158
|
mode,
|
|
136
159
|
ssr
|
|
137
160
|
});
|
|
138
161
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
jsxFactory: "h",
|
|
143
|
-
jsxFragment: "Fragment",
|
|
144
|
-
sourcefile: id,
|
|
145
|
-
sourcemap: "inline"
|
|
146
|
-
});
|
|
147
|
-
let imports = [];
|
|
148
|
-
if (/import/.test(jsCode)) {
|
|
149
|
-
let [i] = eslexer.parse(jsCode);
|
|
150
|
-
imports = i;
|
|
151
|
-
}
|
|
152
|
-
let importSource;
|
|
153
|
-
if (imports.length > 0) {
|
|
154
|
-
for (let { n: spec } of imports) {
|
|
155
|
-
const pkg = spec && parseNpmName(spec);
|
|
156
|
-
if (!pkg)
|
|
157
|
-
continue;
|
|
158
|
-
if (jsxRenderers.has(pkg.name)) {
|
|
159
|
-
importSource = pkg.name;
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
162
|
+
let importSource = detectImportSourceFromComments(code);
|
|
163
|
+
if (!importSource && IMPORT_KEYWORD_REGEX.test(code)) {
|
|
164
|
+
importSource = await detectImportSourceFromImports(code, id, jsxRenderers);
|
|
163
165
|
}
|
|
164
166
|
if (!importSource) {
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
if (importSource) {
|
|
175
|
-
const jsxRenderer = jsxRenderers.get(importSource);
|
|
176
|
-
if (!jsxRenderer) {
|
|
177
|
-
error(
|
|
178
|
-
logging,
|
|
179
|
-
"renderer",
|
|
180
|
-
`${colors.yellow(
|
|
181
|
-
id
|
|
182
|
-
)} No renderer installed for ${importSource}. Try adding \`@astrojs/${importSource}\` to your project.`
|
|
183
|
-
);
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
const { code: jsxCode } = await esbuild.transform(code, {
|
|
187
|
-
loader: getEsbuildLoader(path.extname(id)),
|
|
188
|
-
jsx: "preserve",
|
|
189
|
-
sourcefile: id,
|
|
190
|
-
sourcemap: "inline"
|
|
191
|
-
});
|
|
192
|
-
return await transformJSX({
|
|
193
|
-
code: jsxCode,
|
|
194
|
-
id,
|
|
195
|
-
renderer: jsxRenderers.get(importSource),
|
|
196
|
-
mode,
|
|
197
|
-
ssr
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
const defaultRenderer = [...jsxRenderers.keys()][0];
|
|
201
|
-
error(
|
|
202
|
-
logging,
|
|
203
|
-
"renderer",
|
|
204
|
-
`${colors.yellow(id)}
|
|
167
|
+
const [defaultRendererName] = defaultJSXRendererEntry[0];
|
|
168
|
+
error(
|
|
169
|
+
logging,
|
|
170
|
+
"renderer",
|
|
171
|
+
`${colors.yellow(id)}
|
|
205
172
|
Unable to resolve a renderer that handles this file! With more than one renderer enabled, you should include an import or use a pragma comment.
|
|
206
173
|
Add ${colors.cyan(
|
|
207
|
-
|
|
208
|
-
|
|
174
|
+
IMPORT_STATEMENTS[defaultRendererName] || `import '${defaultRendererName}';`
|
|
175
|
+
)} or ${colors.cyan(`/* jsxImportSource: ${defaultRendererName} */`)} to this file.
|
|
209
176
|
`
|
|
210
|
-
|
|
211
|
-
|
|
177
|
+
);
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
const selectedJsxRenderer = jsxRenderers.get(importSource);
|
|
181
|
+
if (!selectedJsxRenderer) {
|
|
182
|
+
error(
|
|
183
|
+
logging,
|
|
184
|
+
"renderer",
|
|
185
|
+
`${colors.yellow(
|
|
186
|
+
id
|
|
187
|
+
)} No renderer installed for ${importSource}. Try adding \`@astrojs/${importSource}\` to your project.`
|
|
188
|
+
);
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
const { code: jsxCode } = await esbuild.transform(code, {
|
|
192
|
+
loader: getEsbuildLoader(path.extname(id)),
|
|
193
|
+
jsx: "preserve",
|
|
194
|
+
sourcefile: id,
|
|
195
|
+
sourcemap: "inline"
|
|
196
|
+
});
|
|
197
|
+
return await transformJSX({
|
|
198
|
+
code: jsxCode,
|
|
199
|
+
id,
|
|
200
|
+
renderer: selectedJsxRenderer,
|
|
201
|
+
mode,
|
|
202
|
+
ssr
|
|
203
|
+
});
|
|
212
204
|
}
|
|
213
205
|
};
|
|
214
206
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
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",
|
|
@@ -126,7 +126,7 @@
|
|
|
126
126
|
"tsconfig-resolver": "^3.0.1",
|
|
127
127
|
"unist-util-visit": "^4.1.0",
|
|
128
128
|
"vfile": "^5.3.2",
|
|
129
|
-
"vite": "3.0.
|
|
129
|
+
"vite": "3.0.9",
|
|
130
130
|
"yargs-parser": "^21.0.1",
|
|
131
131
|
"zod": "^3.17.3"
|
|
132
132
|
},
|