astro 1.0.6 → 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/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/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/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/vite-plugin-astro-server/index.js +2 -1
- package/dist/vite-plugin-jsx/index.js +91 -99
- package/package.json +2 -2
|
@@ -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
|
}
|
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
|
};
|
|
@@ -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;
|
|
@@ -253,7 +253,8 @@ async function handleRequest(routeCache, viteServer, logging, manifest, config,
|
|
|
253
253
|
await writeWebResponse(res, result.response);
|
|
254
254
|
} else {
|
|
255
255
|
let contentType = "text/plain";
|
|
256
|
-
const
|
|
256
|
+
const filepath = route.pathname || route.segments.map((segment) => segment.map((p) => p.content).join("")).join("/");
|
|
257
|
+
const computedMimeType = mime.getType(filepath);
|
|
257
258
|
if (computedMimeType) {
|
|
258
259
|
contentType = computedMimeType;
|
|
259
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
|
},
|