astro 0.24.3 → 0.25.0-next.0
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 +2 -2
- package/dist/core/app/index.js +44 -18
- package/dist/core/app/node.js +10 -4
- package/dist/core/build/index.js +11 -7
- package/dist/core/build/page-data.js +2 -2
- package/dist/core/build/static-build.js +52 -37
- package/dist/core/config.js +125 -3
- package/dist/core/create-vite.js +14 -22
- package/dist/core/dev/index.js +17 -13
- package/dist/core/endpoint/dev/index.js +36 -0
- package/dist/core/endpoint/index.js +44 -0
- package/dist/core/messages.js +1 -1
- package/dist/core/polyfill.js +9 -0
- package/dist/core/render/core.js +21 -13
- package/dist/core/render/dev/css.js +16 -14
- package/dist/core/render/dev/index.js +63 -16
- package/dist/core/render/request.js +23 -0
- package/dist/core/render/result.js +20 -12
- package/dist/core/render/route-cache.js +11 -8
- package/dist/core/routing/validation.js +2 -2
- package/dist/core/util.js +14 -0
- package/dist/integrations/index.js +91 -0
- package/dist/runtime/server/hydration.js +3 -7
- package/dist/runtime/server/index.js +51 -32
- package/dist/types/@types/astro.d.ts +81 -44
- package/dist/types/cli/check.d.ts +1 -1
- package/dist/types/core/app/index.d.ts +2 -2
- package/dist/types/core/app/node.d.ts +2 -2
- package/dist/types/core/app/types.d.ts +2 -2
- package/dist/types/core/build/page-data.d.ts +1 -0
- package/dist/types/core/build/static-build.d.ts +3 -3
- package/dist/types/core/config.d.ts +68 -4
- package/dist/types/core/create-vite.d.ts +1 -1
- package/dist/types/core/endpoint/dev/index.d.ts +8 -0
- package/dist/types/core/endpoint/index.d.ts +12 -0
- package/dist/types/core/polyfill.d.ts +1 -0
- package/dist/types/core/render/core.d.ts +15 -5
- package/dist/types/core/render/dev/css.d.ts +1 -4
- package/dist/types/core/render/dev/index.d.ts +17 -6
- package/dist/types/core/render/request.d.ts +15 -0
- package/dist/types/core/render/result.d.ts +5 -2
- package/dist/types/core/render/route-cache.d.ts +9 -1
- package/dist/types/core/routing/validation.d.ts +5 -1
- package/dist/types/core/util.d.ts +6 -0
- package/dist/types/integrations/index.d.ts +29 -0
- package/dist/types/runtime/server/hydration.d.ts +2 -2
- package/dist/types/runtime/server/index.d.ts +12 -6
- package/dist/types/vite-plugin-astro/compile.d.ts +1 -1
- package/dist/types/vite-plugin-integrations-container/index.d.ts +6 -0
- package/dist/types/vite-plugin-scripts/index.d.ts +5 -0
- package/dist/vite-plugin-astro/compile.js +0 -5
- package/dist/vite-plugin-astro/index.js +27 -17
- package/dist/vite-plugin-astro-server/index.js +52 -8
- package/dist/vite-plugin-build-html/index.js +7 -1
- package/dist/vite-plugin-integrations-container/index.js +12 -0
- package/dist/vite-plugin-jsx/index.js +7 -14
- package/dist/vite-plugin-scripts/index.js +41 -0
- package/package.json +7 -11
- package/dist/core/render/dev/renderers.js +0 -30
- package/dist/core/render/renderer.js +0 -22
- package/dist/types/core/render/dev/renderers.d.ts +0 -3
- package/dist/types/core/render/renderer.d.ts +0 -7
package/dist/cli/index.js
CHANGED
|
@@ -39,7 +39,7 @@ function printHelp() {
|
|
|
39
39
|
console.log();
|
|
40
40
|
}
|
|
41
41
|
function headline(name, tagline) {
|
|
42
|
-
console.log(` ${colors.bgGreen(colors.black(` ${name} `))} ${colors.green(`v${"0.
|
|
42
|
+
console.log(` ${colors.bgGreen(colors.black(` ${name} `))} ${colors.green(`v${"0.25.0-next.0"}`)} ${tagline}`);
|
|
43
43
|
}
|
|
44
44
|
function title(label) {
|
|
45
45
|
console.log(` ${colors.bgWhite(colors.black(` ${label} `))}`);
|
|
@@ -65,7 +65,7 @@ function printHelp() {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
async function printVersion() {
|
|
68
|
-
const version = "0.
|
|
68
|
+
const version = "0.25.0-next.0";
|
|
69
69
|
console.log();
|
|
70
70
|
console.log(` ${colors.bgGreen(colors.black(` astro `))} ${colors.green(`v${version}`)}`);
|
|
71
71
|
}
|
package/dist/core/app/index.js
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1
20
|
var __accessCheck = (obj, member, msg) => {
|
|
2
21
|
if (!member.has(obj))
|
|
3
22
|
throw TypeError("Cannot " + msg);
|
|
@@ -26,7 +45,6 @@ import { matchRoute } from "../routing/match.js";
|
|
|
26
45
|
import { render } from "../render/core.js";
|
|
27
46
|
import { RouteCache } from "../render/route-cache.js";
|
|
28
47
|
import { createLinkStylesheetElementSet, createModuleScriptElementWithSrcSet } from "../render/ssr-element.js";
|
|
29
|
-
import { createRenderer } from "../render/renderer.js";
|
|
30
48
|
import { prependForwardSlash } from "../path.js";
|
|
31
49
|
class App {
|
|
32
50
|
constructor(manifest, rootFolder) {
|
|
@@ -47,22 +65,27 @@ class App {
|
|
|
47
65
|
__privateSet(this, _routeCache, new RouteCache(defaultLogOptions));
|
|
48
66
|
__privateSet(this, _renderersPromise, __privateMethod(this, _loadRenderers, loadRenderers_fn).call(this));
|
|
49
67
|
}
|
|
50
|
-
match(
|
|
51
|
-
|
|
68
|
+
match(request) {
|
|
69
|
+
const url = new URL(request.url);
|
|
70
|
+
return matchRoute(url.pathname, __privateGet(this, _manifestData));
|
|
52
71
|
}
|
|
53
|
-
async render(
|
|
72
|
+
async render(request, routeData) {
|
|
54
73
|
if (!routeData) {
|
|
55
|
-
routeData = this.match(
|
|
74
|
+
routeData = this.match(request);
|
|
56
75
|
if (!routeData) {
|
|
57
|
-
return
|
|
76
|
+
return new Response(null, {
|
|
77
|
+
status: 404,
|
|
78
|
+
statusText: "Not found"
|
|
79
|
+
});
|
|
58
80
|
}
|
|
59
81
|
}
|
|
60
82
|
const manifest = __privateGet(this, _manifest);
|
|
61
83
|
const info = __privateGet(this, _routeDataToRouteInfo).get(routeData);
|
|
62
84
|
const [mod, renderers] = await Promise.all([__privateMethod(this, _loadModule, loadModule_fn).call(this, info.file), __privateGet(this, _renderersPromise)]);
|
|
85
|
+
const url = new URL(request.url);
|
|
63
86
|
const links = createLinkStylesheetElementSet(info.links, manifest.site);
|
|
64
87
|
const scripts = createModuleScriptElementWithSrcSet(info.scripts, manifest.site);
|
|
65
|
-
|
|
88
|
+
const result = await render({
|
|
66
89
|
legacyBuild: false,
|
|
67
90
|
links,
|
|
68
91
|
logging: defaultLogOptions,
|
|
@@ -81,7 +104,17 @@ class App {
|
|
|
81
104
|
},
|
|
82
105
|
route: routeData,
|
|
83
106
|
routeCache: __privateGet(this, _routeCache),
|
|
84
|
-
site: __privateGet(this, _manifest).site
|
|
107
|
+
site: __privateGet(this, _manifest).site,
|
|
108
|
+
ssr: true,
|
|
109
|
+
method: info.routeData.type === "endpoint" ? "" : "GET",
|
|
110
|
+
headers: request.headers
|
|
111
|
+
});
|
|
112
|
+
if (result.type === "response") {
|
|
113
|
+
return result.response;
|
|
114
|
+
}
|
|
115
|
+
let html = result.html;
|
|
116
|
+
return new Response(html, {
|
|
117
|
+
status: 200
|
|
85
118
|
});
|
|
86
119
|
}
|
|
87
120
|
}
|
|
@@ -93,16 +126,9 @@ _routeCache = new WeakMap();
|
|
|
93
126
|
_renderersPromise = new WeakMap();
|
|
94
127
|
_loadRenderers = new WeakSet();
|
|
95
128
|
loadRenderers_fn = async function() {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return
|
|
99
|
-
renderer(name) {
|
|
100
|
-
return import(name);
|
|
101
|
-
},
|
|
102
|
-
server(entry) {
|
|
103
|
-
return import(entry);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
129
|
+
return await Promise.all(__privateGet(this, _manifest).renderers.map(async (renderer) => {
|
|
130
|
+
const mod = await import(renderer.serverEntrypoint);
|
|
131
|
+
return __spreadProps(__spreadValues({}, renderer), { ssr: mod.default });
|
|
106
132
|
}));
|
|
107
133
|
};
|
|
108
134
|
_loadModule = new WeakSet();
|
package/dist/core/app/node.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import { App } from "./index.js";
|
|
3
3
|
import { deserializeManifest } from "./common.js";
|
|
4
|
-
function
|
|
5
|
-
|
|
4
|
+
function createRequestFromNodeRequest(req) {
|
|
5
|
+
let url = `http://${req.headers.host}${req.url}`;
|
|
6
|
+
const entries = Object.entries(req.headers);
|
|
7
|
+
let request = new Request(url, {
|
|
8
|
+
method: req.method || "GET",
|
|
9
|
+
headers: new Headers(entries)
|
|
10
|
+
});
|
|
11
|
+
return request;
|
|
6
12
|
}
|
|
7
13
|
class NodeApp extends App {
|
|
8
14
|
match(req) {
|
|
9
|
-
return super.match(req instanceof
|
|
15
|
+
return super.match(req instanceof Request ? req : createRequestFromNodeRequest(req));
|
|
10
16
|
}
|
|
11
17
|
render(req) {
|
|
12
|
-
return super.render(req instanceof
|
|
18
|
+
return super.render(req instanceof Request ? req : createRequestFromNodeRequest(req));
|
|
13
19
|
}
|
|
14
20
|
}
|
|
15
21
|
async function loadManifest(rootFolder) {
|
package/dist/core/build/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import * as colors from "kleur/colors";
|
|
3
|
-
import {
|
|
3
|
+
import { apply as applyPolyfill } from "../polyfill.js";
|
|
4
4
|
import { performance } from "perf_hooks";
|
|
5
5
|
import * as vite from "vite";
|
|
6
6
|
import { createVite } from "../create-vite.js";
|
|
@@ -11,16 +11,15 @@ import { collectPagesData } from "./page-data.js";
|
|
|
11
11
|
import { build as scanBasedBuild } from "./scan-based-build.js";
|
|
12
12
|
import { staticBuild } from "./static-build.js";
|
|
13
13
|
import { RouteCache } from "../render/route-cache.js";
|
|
14
|
+
import { runHookBuildDone, runHookBuildStart, runHookConfigDone, runHookConfigSetup } from "../../integrations/index.js";
|
|
14
15
|
async function build(config, options = { logging: defaultLogOptions }) {
|
|
15
|
-
polyfill(globalThis, {
|
|
16
|
-
exclude: "window document"
|
|
17
|
-
});
|
|
18
16
|
const builder = new AstroBuilder(config, options);
|
|
19
17
|
await builder.build();
|
|
20
18
|
}
|
|
21
19
|
class AstroBuilder {
|
|
22
20
|
constructor(config, options) {
|
|
23
21
|
this.mode = "production";
|
|
22
|
+
applyPolyfill();
|
|
24
23
|
if (!config.buildOptions.site && config.buildOptions.sitemap !== false) {
|
|
25
24
|
warn(options.logging, "config", `Set "buildOptions.site" to generate correct canonical URLs and sitemap`);
|
|
26
25
|
}
|
|
@@ -38,17 +37,20 @@ class AstroBuilder {
|
|
|
38
37
|
const timer = {};
|
|
39
38
|
timer.init = performance.now();
|
|
40
39
|
timer.viteStart = performance.now();
|
|
41
|
-
|
|
40
|
+
this.config = await runHookConfigSetup({ config: this.config, command: "build" });
|
|
41
|
+
const viteConfig = await createVite({
|
|
42
42
|
mode: this.mode,
|
|
43
43
|
server: {
|
|
44
44
|
hmr: false,
|
|
45
45
|
middlewareMode: "ssr"
|
|
46
46
|
}
|
|
47
|
-
},
|
|
47
|
+
}, { astroConfig: this.config, logging, mode: "build" });
|
|
48
|
+
await runHookConfigDone({ config: this.config });
|
|
48
49
|
this.viteConfig = viteConfig;
|
|
49
50
|
const viteServer = await vite.createServer(viteConfig);
|
|
50
51
|
this.viteServer = viteServer;
|
|
51
52
|
debug("build", timerMessage("Vite started", timer.viteStart));
|
|
53
|
+
await runHookBuildStart({ config: this.config });
|
|
52
54
|
timer.loadStart = performance.now();
|
|
53
55
|
const { assets, allPages } = await collectPagesData({
|
|
54
56
|
astroConfig: this.config,
|
|
@@ -56,7 +58,8 @@ class AstroBuilder {
|
|
|
56
58
|
manifest: this.manifest,
|
|
57
59
|
origin,
|
|
58
60
|
routeCache: this.routeCache,
|
|
59
|
-
viteServer: this.viteServer
|
|
61
|
+
viteServer: this.viteServer,
|
|
62
|
+
ssr: this.config.buildOptions.experimentalSsr
|
|
60
63
|
});
|
|
61
64
|
Object.entries(allPages).forEach(([page, data]) => {
|
|
62
65
|
if ("frontmatter" in data.preload[1]) {
|
|
@@ -114,6 +117,7 @@ class AstroBuilder {
|
|
|
114
117
|
debug("build", timerMessage("Sitemap built", timer.sitemapStart));
|
|
115
118
|
}
|
|
116
119
|
await viteServer.close();
|
|
120
|
+
await runHookBuildDone({ config: this.config, pages: pageNames });
|
|
117
121
|
if (logging.level && levels[logging.level] <= levels["info"]) {
|
|
118
122
|
await this.printStats({ logging, timeStart: timer.init, pageCount: pageNames.length });
|
|
119
123
|
}
|
|
@@ -75,12 +75,12 @@ Use \`rss(data, {stylesheet: '...'})\` to choose a unique, custom URL. (${route.
|
|
|
75
75
|
return { assets, allPages };
|
|
76
76
|
}
|
|
77
77
|
async function getStaticPathsForRoute(opts, route) {
|
|
78
|
-
const { astroConfig, logging, routeCache, viteServer } = opts;
|
|
78
|
+
const { astroConfig, logging, routeCache, ssr, viteServer } = opts;
|
|
79
79
|
if (!viteServer)
|
|
80
80
|
throw new Error(`vite.createServer() not called!`);
|
|
81
81
|
const filePath = new URL(`./${route.component}`, astroConfig.projectRoot);
|
|
82
82
|
const mod = await viteServer.ssrLoadModule(fileURLToPath(filePath));
|
|
83
|
-
const result = await callGetStaticPaths(mod, route, false, logging);
|
|
83
|
+
const result = await callGetStaticPaths({ mod, route, isValidate: false, logging, ssr });
|
|
84
84
|
routeCache.set(route, result);
|
|
85
85
|
return result;
|
|
86
86
|
}
|
|
@@ -17,20 +17,21 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import glob from "fast-glob";
|
|
20
21
|
import fs from "fs";
|
|
21
22
|
import npath from "path";
|
|
22
23
|
import { fileURLToPath } from "url";
|
|
23
|
-
import glob from "fast-glob";
|
|
24
24
|
import * as vite from "vite";
|
|
25
|
+
import { createBuildInternals } from "../../core/build/internal.js";
|
|
25
26
|
import { debug, error } from "../../core/logger.js";
|
|
26
|
-
import {
|
|
27
|
+
import { appendForwardSlash, prependForwardSlash } from "../../core/path.js";
|
|
27
28
|
import { emptyDir, removeDir, resolveDependency } from "../../core/util.js";
|
|
28
|
-
import { createBuildInternals } from "../../core/build/internal.js";
|
|
29
29
|
import { rollupPluginAstroBuildCSS } from "../../vite-plugin-build-css/index.js";
|
|
30
|
-
import {
|
|
31
|
-
import { serializeRouteData } from "../routing/index.js";
|
|
30
|
+
import { call as callEndpoint } from "../endpoint/index.js";
|
|
32
31
|
import { render } from "../render/core.js";
|
|
33
32
|
import { createLinkStylesheetElementSet, createModuleScriptElementWithSrcSet } from "../render/ssr-element.js";
|
|
33
|
+
import { serializeRouteData } from "../routing/index.js";
|
|
34
|
+
import { vitePluginHoistedScripts } from "./vite-plugin-hoisted-scripts.js";
|
|
34
35
|
const MAX_CONCURRENT_RENDERS = 1;
|
|
35
36
|
const STATUS_CODE_PAGES = /* @__PURE__ */ new Set(["/404", "/500"]);
|
|
36
37
|
function addPageName(pathname, opts) {
|
|
@@ -76,12 +77,6 @@ async function staticBuild(opts) {
|
|
|
76
77
|
const pageInput = /* @__PURE__ */ new Set();
|
|
77
78
|
const jsInput = /* @__PURE__ */ new Set();
|
|
78
79
|
const facadeIdToPageDataMap = /* @__PURE__ */ new Map();
|
|
79
|
-
const polyfills = getRenderers(opts).flatMap((renderer) => {
|
|
80
|
-
return (renderer.polyfills || []).concat(renderer.hydrationPolyfills || []);
|
|
81
|
-
});
|
|
82
|
-
for (const polyfill of polyfills) {
|
|
83
|
-
jsInput.add(polyfill);
|
|
84
|
-
}
|
|
85
80
|
const internals = createBuildInternals();
|
|
86
81
|
for (const [component, pageData] of Object.entries(allPages)) {
|
|
87
82
|
const astroModuleURL = new URL("./" + component, astroConfig.projectRoot);
|
|
@@ -93,7 +88,7 @@ async function staticBuild(opts) {
|
|
|
93
88
|
...metadata.hydratedComponentPaths(),
|
|
94
89
|
...metadata.clientOnlyComponentPaths(),
|
|
95
90
|
...metadata.hydrationDirectiveSpecifiers(),
|
|
96
|
-
...renderers.filter((renderer) => !!renderer.
|
|
91
|
+
...renderers.filter((renderer) => !!renderer.clientEntrypoint).map((renderer) => renderer.clientEntrypoint)
|
|
97
92
|
]);
|
|
98
93
|
const hoistedScripts = new Set(metadata.hoistedScriptPaths());
|
|
99
94
|
if (hoistedScripts.size) {
|
|
@@ -124,8 +119,9 @@ async function ssrBuild(opts, internals, input) {
|
|
|
124
119
|
const ssr = astroConfig.buildOptions.experimentalSsr;
|
|
125
120
|
const out = ssr ? getServerRoot(astroConfig) : getOutRoot(astroConfig);
|
|
126
121
|
return await vite.build({
|
|
127
|
-
logLevel: "
|
|
122
|
+
logLevel: "error",
|
|
128
123
|
mode: "production",
|
|
124
|
+
css: viteConfig.css,
|
|
129
125
|
build: __spreadProps(__spreadValues({}, viteConfig.build), {
|
|
130
126
|
emptyOutDir: false,
|
|
131
127
|
manifest: ssr,
|
|
@@ -167,8 +163,9 @@ async function clientBuild(opts, internals, input) {
|
|
|
167
163
|
}
|
|
168
164
|
const out = astroConfig.buildOptions.experimentalSsr ? getClientRoot(astroConfig) : getOutRoot(astroConfig);
|
|
169
165
|
return await vite.build({
|
|
170
|
-
logLevel: "
|
|
166
|
+
logLevel: "error",
|
|
171
167
|
mode: "production",
|
|
168
|
+
css: viteConfig.css,
|
|
172
169
|
build: {
|
|
173
170
|
emptyOutDir: false,
|
|
174
171
|
minify: "esbuild",
|
|
@@ -200,26 +197,16 @@ async function clientBuild(opts, internals, input) {
|
|
|
200
197
|
base: appendForwardSlash(astroConfig.buildOptions.site ? new URL(astroConfig.buildOptions.site).pathname : "/")
|
|
201
198
|
});
|
|
202
199
|
}
|
|
203
|
-
function
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
return viteLoadedRenderers;
|
|
200
|
+
async function loadRenderer(renderer, config) {
|
|
201
|
+
const mod = await import(resolveDependency(renderer.serverEntrypoint, config));
|
|
202
|
+
return __spreadProps(__spreadValues({}, renderer), { ssr: mod.default });
|
|
207
203
|
}
|
|
208
|
-
async function
|
|
209
|
-
|
|
210
|
-
const renderers = await Promise.all(viteLoadedRenderers.map(async (r) => {
|
|
211
|
-
const mod = await import(resolveDependency(r.serverEntry, opts.astroConfig));
|
|
212
|
-
return Object.create(r, {
|
|
213
|
-
ssr: {
|
|
214
|
-
value: mod.default
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
}));
|
|
218
|
-
return renderers;
|
|
204
|
+
async function loadRenderers(config) {
|
|
205
|
+
return Promise.all(config._ctx.renderers.map((r) => loadRenderer(r, config)));
|
|
219
206
|
}
|
|
220
207
|
async function generatePages(result, opts, internals, facadeIdToPageDataMap) {
|
|
221
208
|
debug("build", "Finish build. Begin generating.");
|
|
222
|
-
const renderers = await
|
|
209
|
+
const renderers = await loadRenderers(opts.astroConfig);
|
|
223
210
|
for (let output of result.output) {
|
|
224
211
|
if (chunkIsPage(opts.astroConfig, output, internals)) {
|
|
225
212
|
await generatePage(output, opts, internals, facadeIdToPageDataMap, renderers);
|
|
@@ -264,8 +251,16 @@ async function generatePath(pathname, opts, gopts) {
|
|
|
264
251
|
const site = astroConfig.buildOptions.site;
|
|
265
252
|
const links = createLinkStylesheetElementSet(linkIds.reverse(), site);
|
|
266
253
|
const scripts = createModuleScriptElementWithSrcSet(hoistedId ? [hoistedId] : [], site);
|
|
254
|
+
for (const script of astroConfig._ctx.scripts) {
|
|
255
|
+
if (script.stage === "head-inline") {
|
|
256
|
+
scripts.add({
|
|
257
|
+
props: {},
|
|
258
|
+
children: script.content
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}
|
|
267
262
|
try {
|
|
268
|
-
const
|
|
263
|
+
const options = {
|
|
269
264
|
legacyBuild: false,
|
|
270
265
|
links,
|
|
271
266
|
logging,
|
|
@@ -278,20 +273,40 @@ async function generatePath(pathname, opts, gopts) {
|
|
|
278
273
|
async resolve(specifier) {
|
|
279
274
|
const hashedFilePath = internals.entrySpecifierToBundleMap.get(specifier);
|
|
280
275
|
if (typeof hashedFilePath !== "string") {
|
|
276
|
+
if (specifier === "astro:scripts/before-hydration.js") {
|
|
277
|
+
return "data:text/javascript;charset=utf-8,//[no before-hydration script]";
|
|
278
|
+
}
|
|
281
279
|
throw new Error(`Cannot find the built path for ${specifier}`);
|
|
282
280
|
}
|
|
283
281
|
const relPath = npath.posix.relative(pathname, "/" + hashedFilePath);
|
|
284
282
|
const fullyRelativePath = relPath[0] === "." ? relPath : "./" + relPath;
|
|
285
283
|
return fullyRelativePath;
|
|
286
284
|
},
|
|
285
|
+
method: "GET",
|
|
286
|
+
headers: new Headers(),
|
|
287
287
|
route: pageData.route,
|
|
288
288
|
routeCache,
|
|
289
|
-
site: astroConfig.buildOptions.site
|
|
290
|
-
|
|
289
|
+
site: astroConfig.buildOptions.site,
|
|
290
|
+
ssr: opts.astroConfig.buildOptions.experimentalSsr
|
|
291
|
+
};
|
|
292
|
+
let body;
|
|
293
|
+
if (pageData.route.type === "endpoint") {
|
|
294
|
+
const result = await callEndpoint(mod, options);
|
|
295
|
+
if (result.type === "response") {
|
|
296
|
+
throw new Error(`Returning a Response from an endpoint is not supported in SSG mode.`);
|
|
297
|
+
}
|
|
298
|
+
body = result.body;
|
|
299
|
+
} else {
|
|
300
|
+
const result = await render(options);
|
|
301
|
+
if (result.type !== "html") {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
body = result.html;
|
|
305
|
+
}
|
|
291
306
|
const outFolder = getOutFolder(astroConfig, pathname, pageData.route.type);
|
|
292
307
|
const outFile = getOutFile(astroConfig, outFolder, pathname, pageData.route.type);
|
|
293
308
|
await fs.promises.mkdir(outFolder, { recursive: true });
|
|
294
|
-
await fs.promises.writeFile(outFile,
|
|
309
|
+
await fs.promises.writeFile(outFile, body, "utf-8");
|
|
295
310
|
} catch (err) {
|
|
296
311
|
error(opts.logging, "build", `Error rendering:`, err);
|
|
297
312
|
}
|
|
@@ -336,7 +351,7 @@ async function generateManifest(result, opts, internals) {
|
|
|
336
351
|
markdown: {
|
|
337
352
|
render: astroConfig.markdownOptions.render
|
|
338
353
|
},
|
|
339
|
-
renderers: astroConfig.renderers,
|
|
354
|
+
renderers: astroConfig._ctx.renderers,
|
|
340
355
|
entryModules: Object.fromEntries(internals.entrySpecifierToBundleMap.entries())
|
|
341
356
|
};
|
|
342
357
|
const outputManifestJSON = JSON.stringify(ssrManifest, null, " ");
|
|
@@ -456,8 +471,8 @@ function vitePluginNewBuild(input, internals, ext) {
|
|
|
456
471
|
}
|
|
457
472
|
await Promise.all(promises);
|
|
458
473
|
for (const [, chunk] of Object.entries(bundle)) {
|
|
459
|
-
if (chunk.type === "chunk" && chunk.facadeModuleId
|
|
460
|
-
const specifier = mapping.get(chunk.facadeModuleId);
|
|
474
|
+
if (chunk.type === "chunk" && chunk.facadeModuleId) {
|
|
475
|
+
const specifier = mapping.get(chunk.facadeModuleId) || chunk.facadeModuleId;
|
|
461
476
|
internals.entrySpecifierToBundleMap.set(specifier, chunk.fileName);
|
|
462
477
|
}
|
|
463
478
|
}
|
package/dist/core/config.js
CHANGED
|
@@ -1,17 +1,69 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1
20
|
import * as colors from "kleur/colors";
|
|
2
21
|
import path from "path";
|
|
3
22
|
import { pathToFileURL, fileURLToPath } from "url";
|
|
23
|
+
import { mergeConfig as mergeViteConfig } from "vite";
|
|
4
24
|
import { z } from "zod";
|
|
5
25
|
import load from "@proload/core";
|
|
6
26
|
import loadTypeScript from "@proload/plugin-tsm";
|
|
27
|
+
import postcssrc from "postcss-load-config";
|
|
28
|
+
import { arraify, isObject } from "./util.js";
|
|
7
29
|
load.use([loadTypeScript]);
|
|
30
|
+
async function resolvePostcssConfig(inlineOptions, root) {
|
|
31
|
+
if (isObject(inlineOptions)) {
|
|
32
|
+
const options = __spreadValues({}, inlineOptions);
|
|
33
|
+
delete options.plugins;
|
|
34
|
+
return {
|
|
35
|
+
options,
|
|
36
|
+
plugins: inlineOptions.plugins || []
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const searchPath = typeof inlineOptions === "string" ? inlineOptions : fileURLToPath(root);
|
|
40
|
+
try {
|
|
41
|
+
return await postcssrc({}, searchPath);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
if (!/No PostCSS Config found/.test(err.message)) {
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
options: {},
|
|
48
|
+
plugins: []
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
8
52
|
const AstroConfigSchema = z.object({
|
|
9
53
|
projectRoot: z.string().optional().default(".").transform((val) => new URL(val)),
|
|
10
54
|
src: z.string().optional().default("./src").transform((val) => new URL(val)),
|
|
11
55
|
pages: z.string().optional().default("./src/pages").transform((val) => new URL(val)),
|
|
12
56
|
public: z.string().optional().default("./public").transform((val) => new URL(val)),
|
|
13
57
|
dist: z.string().optional().default("./dist").transform((val) => new URL(val)),
|
|
14
|
-
|
|
58
|
+
integrations: z.preprocess((val) => Array.isArray(val) ? val.flat(Infinity).filter(Boolean) : val, z.array(z.object({ name: z.string(), hooks: z.object({}).passthrough().default({}) })).default([]).refine((arr) => arr.every((integration) => integration.name.startsWith("@astrojs/")), {
|
|
59
|
+
message: `Astro integrations are still experimental, and only official integrations are currently supported`
|
|
60
|
+
})),
|
|
61
|
+
styleOptions: z.object({
|
|
62
|
+
postcss: z.object({
|
|
63
|
+
options: z.any(),
|
|
64
|
+
plugins: z.array(z.any())
|
|
65
|
+
}).optional().default({ options: {}, plugins: [] })
|
|
66
|
+
}).optional().default({}),
|
|
15
67
|
markdownOptions: z.object({
|
|
16
68
|
render: z.any().optional().default(["@astrojs/markdown-remark", {}])
|
|
17
69
|
}).strict().optional().default({}),
|
|
@@ -35,14 +87,48 @@ const AstroConfigSchema = z.object({
|
|
|
35
87
|
});
|
|
36
88
|
async function validateConfig(userConfig, root) {
|
|
37
89
|
const fileProtocolRoot = pathToFileURL(root + path.sep);
|
|
90
|
+
if (userConfig.hasOwnProperty("renderers")) {
|
|
91
|
+
console.error('Astro "renderers" are now "integrations"!');
|
|
92
|
+
console.error("Update your configuration and install new dependencies:");
|
|
93
|
+
try {
|
|
94
|
+
const rendererKeywords = userConfig.renderers.map((r) => r.replace("@astrojs/renderer-", ""));
|
|
95
|
+
const rendererImports = rendererKeywords.map((r) => ` import ${r} from '@astrojs/${r}';`).join("\n");
|
|
96
|
+
const rendererIntegrations = rendererKeywords.map((r) => ` ${r}(),`).join("\n");
|
|
97
|
+
console.error("");
|
|
98
|
+
console.error(colors.dim(" // astro.config.js"));
|
|
99
|
+
if (rendererImports.length > 0) {
|
|
100
|
+
console.error(colors.green(rendererImports));
|
|
101
|
+
}
|
|
102
|
+
console.error("");
|
|
103
|
+
console.error(colors.dim(" // ..."));
|
|
104
|
+
if (rendererIntegrations.length > 0) {
|
|
105
|
+
console.error(colors.green(" integrations: ["));
|
|
106
|
+
console.error(colors.green(rendererIntegrations));
|
|
107
|
+
console.error(colors.green(" ],"));
|
|
108
|
+
} else {
|
|
109
|
+
console.error(colors.green(" integrations: [],"));
|
|
110
|
+
}
|
|
111
|
+
console.error("");
|
|
112
|
+
} catch (err) {
|
|
113
|
+
}
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
38
116
|
const AstroConfigRelativeSchema = AstroConfigSchema.extend({
|
|
39
117
|
projectRoot: z.string().default(".").transform((val) => new URL(addTrailingSlash(val), fileProtocolRoot)),
|
|
40
118
|
src: z.string().default("./src").transform((val) => new URL(addTrailingSlash(val), fileProtocolRoot)),
|
|
41
119
|
pages: z.string().default("./src/pages").transform((val) => new URL(addTrailingSlash(val), fileProtocolRoot)),
|
|
42
120
|
public: z.string().default("./public").transform((val) => new URL(addTrailingSlash(val), fileProtocolRoot)),
|
|
43
|
-
dist: z.string().default("./dist").transform((val) => new URL(addTrailingSlash(val), fileProtocolRoot))
|
|
121
|
+
dist: z.string().default("./dist").transform((val) => new URL(addTrailingSlash(val), fileProtocolRoot)),
|
|
122
|
+
styleOptions: z.object({
|
|
123
|
+
postcss: z.preprocess((val) => resolvePostcssConfig(val, fileProtocolRoot), z.object({
|
|
124
|
+
options: z.any(),
|
|
125
|
+
plugins: z.array(z.any())
|
|
126
|
+
}).optional().default({ options: {}, plugins: [] }))
|
|
127
|
+
}).optional().default({})
|
|
128
|
+
});
|
|
129
|
+
return __spreadProps(__spreadValues({}, await AstroConfigRelativeSchema.parseAsync(userConfig)), {
|
|
130
|
+
_ctx: { scripts: [], renderers: [] }
|
|
44
131
|
});
|
|
45
|
-
return AstroConfigRelativeSchema.parseAsync(userConfig);
|
|
46
132
|
}
|
|
47
133
|
function addTrailingSlash(str) {
|
|
48
134
|
return str.replace(/\/*$/, "/");
|
|
@@ -102,6 +188,9 @@ async function loadConfig(configOptions) {
|
|
|
102
188
|
if (config) {
|
|
103
189
|
userConfig = config.value;
|
|
104
190
|
}
|
|
191
|
+
return resolveConfig(userConfig, root, flags);
|
|
192
|
+
}
|
|
193
|
+
async function resolveConfig(userConfig, root, flags = {}) {
|
|
105
194
|
const mergedConfig = mergeCLIFlags(userConfig, flags);
|
|
106
195
|
const validatedConfig = await validateConfig(mergedConfig, root);
|
|
107
196
|
return validatedConfig;
|
|
@@ -111,9 +200,42 @@ function formatConfigError(err) {
|
|
|
111
200
|
return `${colors.red("[config]")} Astro found issue(s) with your configuration:
|
|
112
201
|
${errorList.join("\n")}`;
|
|
113
202
|
}
|
|
203
|
+
function mergeConfigRecursively(defaults, overrides, rootPath) {
|
|
204
|
+
const merged = __spreadValues({}, defaults);
|
|
205
|
+
for (const key in overrides) {
|
|
206
|
+
const value = overrides[key];
|
|
207
|
+
if (value == null) {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
const existing = merged[key];
|
|
211
|
+
if (existing == null) {
|
|
212
|
+
merged[key] = value;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (key === "vite" && rootPath === "") {
|
|
216
|
+
merged[key] = mergeViteConfig(existing, value);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (Array.isArray(existing) || Array.isArray(value)) {
|
|
220
|
+
merged[key] = [...arraify(existing ?? []), ...arraify(value ?? [])];
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (isObject(existing) && isObject(value)) {
|
|
224
|
+
merged[key] = mergeConfigRecursively(existing, value, rootPath ? `${rootPath}.${key}` : key);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
merged[key] = value;
|
|
228
|
+
}
|
|
229
|
+
return merged;
|
|
230
|
+
}
|
|
231
|
+
function mergeConfig(defaults, overrides, isRoot = true) {
|
|
232
|
+
return mergeConfigRecursively(defaults, overrides, isRoot ? "" : ".");
|
|
233
|
+
}
|
|
114
234
|
export {
|
|
115
235
|
AstroConfigSchema,
|
|
116
236
|
formatConfigError,
|
|
117
237
|
loadConfig,
|
|
238
|
+
mergeConfig,
|
|
239
|
+
resolveConfig,
|
|
118
240
|
validateConfig
|
|
119
241
|
};
|
package/dist/core/create-vite.js
CHANGED
|
@@ -9,7 +9,8 @@ import configAliasVitePlugin from "../vite-plugin-config-alias/index.js";
|
|
|
9
9
|
import markdownVitePlugin from "../vite-plugin-markdown/index.js";
|
|
10
10
|
import jsxVitePlugin from "../vite-plugin-jsx/index.js";
|
|
11
11
|
import envVitePlugin from "../vite-plugin-env/index.js";
|
|
12
|
-
import
|
|
12
|
+
import astroScriptsPlugin from "../vite-plugin-scripts/index.js";
|
|
13
|
+
import astroIntegrationsContainerPlugin from "../vite-plugin-integrations-container/index.js";
|
|
13
14
|
const ALWAYS_EXTERNAL = /* @__PURE__ */ new Set([
|
|
14
15
|
...builtinModules.map((name) => `node:${name}`),
|
|
15
16
|
"@sveltejs/vite-plugin-svelte",
|
|
@@ -25,9 +26,9 @@ const ALWAYS_EXTERNAL = /* @__PURE__ */ new Set([
|
|
|
25
26
|
const ALWAYS_NOEXTERNAL = /* @__PURE__ */ new Set([
|
|
26
27
|
"astro"
|
|
27
28
|
]);
|
|
28
|
-
async function createVite(
|
|
29
|
+
async function createVite(commandConfig, { astroConfig, logging, mode }) {
|
|
29
30
|
const astroPackages = await getAstroPackages(astroConfig);
|
|
30
|
-
|
|
31
|
+
const commonConfig = {
|
|
31
32
|
cacheDir: fileURLToPath(new URL("./node_modules/.vite/", astroConfig.projectRoot)),
|
|
32
33
|
clearScreen: false,
|
|
33
34
|
logLevel: "warn",
|
|
@@ -37,11 +38,13 @@ async function createVite(inlineConfig, { astroConfig, logging, mode }) {
|
|
|
37
38
|
plugins: [
|
|
38
39
|
configAliasVitePlugin({ config: astroConfig }),
|
|
39
40
|
astroVitePlugin({ config: astroConfig, logging }),
|
|
41
|
+
astroScriptsPlugin({ config: astroConfig }),
|
|
40
42
|
mode === "dev" && astroViteServerPlugin({ config: astroConfig, logging }),
|
|
41
43
|
envVitePlugin({ config: astroConfig }),
|
|
42
44
|
markdownVitePlugin({ config: astroConfig }),
|
|
43
45
|
jsxVitePlugin({ config: astroConfig, logging }),
|
|
44
|
-
astroPostprocessVitePlugin({ config: astroConfig })
|
|
46
|
+
astroPostprocessVitePlugin({ config: astroConfig }),
|
|
47
|
+
astroIntegrationsContainerPlugin({ config: astroConfig })
|
|
45
48
|
],
|
|
46
49
|
publicDir: fileURLToPath(astroConfig.public),
|
|
47
50
|
root: fileURLToPath(astroConfig.projectRoot),
|
|
@@ -51,29 +54,18 @@ async function createVite(inlineConfig, { astroConfig, logging, mode }) {
|
|
|
51
54
|
hmr: process.env.NODE_ENV === "test" || process.env.NODE_ENV === "production" ? false : void 0,
|
|
52
55
|
proxy: {}
|
|
53
56
|
},
|
|
57
|
+
css: {
|
|
58
|
+
postcss: astroConfig.styleOptions.postcss || {}
|
|
59
|
+
},
|
|
54
60
|
ssr: {
|
|
55
61
|
external: [...ALWAYS_EXTERNAL],
|
|
56
62
|
noExternal: [...ALWAYS_NOEXTERNAL, ...astroPackages]
|
|
57
63
|
}
|
|
58
64
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
continue;
|
|
64
|
-
if (renderer.viteConfig) {
|
|
65
|
-
if (typeof renderer.viteConfig !== "function") {
|
|
66
|
-
throw new Error(`${name}: viteConfig(options) must be a function! Got ${typeof renderer.viteConfig}.`);
|
|
67
|
-
}
|
|
68
|
-
const rendererConfig = await renderer.viteConfig({ mode: inlineConfig.mode, command: inlineConfig.mode === "production" ? "build" : "serve" });
|
|
69
|
-
viteConfig = vite.mergeConfig(viteConfig, rendererConfig);
|
|
70
|
-
}
|
|
71
|
-
} catch (err) {
|
|
72
|
-
throw new Error(`${name}: ${err}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
viteConfig = vite.mergeConfig(viteConfig, inlineConfig);
|
|
76
|
-
return viteConfig;
|
|
65
|
+
let result = commonConfig;
|
|
66
|
+
result = vite.mergeConfig(result, astroConfig.vite || {});
|
|
67
|
+
result = vite.mergeConfig(result, commandConfig);
|
|
68
|
+
return result;
|
|
77
69
|
}
|
|
78
70
|
async function getAstroPackages({ projectRoot }) {
|
|
79
71
|
const pkgUrl = new URL("./package.json", projectRoot);
|