astro 1.0.0-beta.45 → 1.0.0-beta.48
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 +8 -8
- package/dist/core/build/generate.js +7 -0
- package/dist/core/build/graph.js +27 -0
- package/dist/core/build/index.js +2 -10
- package/dist/core/build/internal.js +5 -1
- package/dist/core/build/page-data.js +9 -26
- package/dist/core/build/static-build.js +14 -44
- package/dist/core/build/vite-plugin-analyzer.js +91 -0
- package/dist/core/build/vite-plugin-ssr.js +23 -9
- package/dist/core/config.js +7 -1
- package/dist/core/create-vite.js +0 -1
- package/dist/core/dev/index.js +1 -1
- package/dist/core/messages.js +3 -3
- package/dist/core/render/core.js +15 -4
- package/dist/core/render/result.js +1 -0
- package/dist/core/routing/manifest/create.js +69 -14
- package/dist/core/routing/manifest/serialization.js +1 -0
- package/dist/integrations/index.js +13 -1
- package/dist/runtime/client/events.js +1 -5
- package/dist/runtime/client/hmr.js +3 -3
- package/dist/{@types/serialize-javascript.d.js → runtime/client/hydration-directives.d.js} +0 -0
- package/dist/runtime/client/idle.js +9 -43
- package/dist/runtime/client/idle.prebuilt.js +4 -0
- package/dist/runtime/client/load.js +5 -37
- package/dist/runtime/client/load.prebuilt.js +4 -0
- package/dist/runtime/client/media.js +11 -45
- package/dist/runtime/client/media.prebuilt.js +4 -0
- package/dist/runtime/client/only.js +5 -37
- package/dist/runtime/client/only.prebuilt.js +4 -0
- package/dist/runtime/client/visible.js +15 -55
- package/dist/runtime/client/visible.prebuilt.js +4 -0
- package/dist/runtime/server/astro-island.js +70 -0
- package/dist/runtime/server/astro-island.prebuilt.js +4 -0
- package/dist/runtime/server/hydration.js +29 -21
- package/dist/runtime/server/index.js +25 -7
- package/dist/runtime/server/metadata.js +0 -36
- package/dist/runtime/server/scripts.js +55 -0
- package/dist/runtime/server/serialize.js +57 -0
- package/dist/runtime/server/util.js +0 -4
- package/dist/types/@types/astro.d.ts +13 -5
- package/dist/types/core/build/graph.d.ts +7 -0
- package/dist/types/core/build/internal.d.ts +18 -1
- package/dist/types/core/build/types.d.ts +0 -2
- package/dist/types/core/build/vite-plugin-analyzer.d.ts +4 -0
- package/dist/types/core/build/vite-plugin-ssr.d.ts +1 -0
- package/dist/types/runtime/client/events.d.ts +0 -1
- package/dist/types/runtime/client/idle.d.ts +0 -6
- package/dist/types/runtime/client/idle.prebuilt.d.ts +7 -0
- package/dist/types/runtime/client/load.d.ts +0 -5
- package/dist/types/runtime/client/load.prebuilt.d.ts +7 -0
- package/dist/types/runtime/client/media.d.ts +0 -5
- package/dist/types/runtime/client/media.prebuilt.d.ts +7 -0
- package/dist/types/runtime/client/only.d.ts +0 -5
- package/dist/types/runtime/client/only.prebuilt.d.ts +7 -0
- package/dist/types/runtime/client/visible.d.ts +0 -7
- package/dist/types/runtime/client/visible.prebuilt.d.ts +7 -0
- package/dist/types/runtime/server/astro-island.d.ts +4 -0
- package/dist/types/runtime/server/astro-island.prebuilt.d.ts +7 -0
- package/dist/types/runtime/server/hydration.d.ts +1 -1
- package/dist/types/runtime/server/metadata.d.ts +0 -10
- package/dist/types/runtime/server/scripts.d.ts +6 -0
- package/dist/types/runtime/server/serialize.d.ts +1 -0
- package/dist/types/runtime/server/util.d.ts +0 -6
- package/dist/types/vite-plugin-astro/compile.d.ts +3 -1
- package/dist/types/vite-plugin-astro/styles.d.ts +3 -1
- package/dist/types/vite-plugin-astro/types.d.ts +8 -0
- package/dist/vite-plugin-astro/compile.js +4 -2
- package/dist/vite-plugin-astro/index.js +8 -1
- package/dist/vite-plugin-astro/styles.js +4 -3
- package/dist/vite-plugin-astro/types.js +0 -0
- package/dist/vite-plugin-build-css/index.js +2 -24
- package/dist/vite-plugin-markdown/index.js +9 -2
- package/package.json +8 -8
package/dist/cli/index.js
CHANGED
|
@@ -40,7 +40,7 @@ function printAstroHelp() {
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
async function printVersion() {
|
|
43
|
-
const version = "1.0.0-beta.
|
|
43
|
+
const version = "1.0.0-beta.48";
|
|
44
44
|
console.log();
|
|
45
45
|
console.log(` ${colors.bgGreen(colors.black(` astro `))} ${colors.green(`v${version}`)}`);
|
|
46
46
|
}
|
|
@@ -83,7 +83,7 @@ async function cli(args) {
|
|
|
83
83
|
} else if (flags.silent) {
|
|
84
84
|
logging.level = "silent";
|
|
85
85
|
}
|
|
86
|
-
const telemetry = new AstroTelemetry({ version: "1.0.0-beta.
|
|
86
|
+
const telemetry = new AstroTelemetry({ version: "1.0.0-beta.48" });
|
|
87
87
|
if (cmd === "telemetry") {
|
|
88
88
|
try {
|
|
89
89
|
const subcommand = (_a = flags._[3]) == null ? void 0 : _a.toString();
|
|
@@ -97,7 +97,7 @@ async function cli(args) {
|
|
|
97
97
|
try {
|
|
98
98
|
const packages = flags._.slice(3);
|
|
99
99
|
telemetry.record(event.eventCliSession({
|
|
100
|
-
astroVersion: "1.0.0-beta.
|
|
100
|
+
astroVersion: "1.0.0-beta.48",
|
|
101
101
|
cliCommand: "add"
|
|
102
102
|
}));
|
|
103
103
|
return await add(packages, { cwd: root, flags, logging, telemetry });
|
|
@@ -108,7 +108,7 @@ async function cli(args) {
|
|
|
108
108
|
case "dev": {
|
|
109
109
|
try {
|
|
110
110
|
const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd });
|
|
111
|
-
telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.
|
|
111
|
+
telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.48", cliCommand: "dev" }, userConfig, flags));
|
|
112
112
|
await devServer(astroConfig, { logging, telemetry });
|
|
113
113
|
return await new Promise(() => {
|
|
114
114
|
});
|
|
@@ -119,7 +119,7 @@ async function cli(args) {
|
|
|
119
119
|
case "build": {
|
|
120
120
|
try {
|
|
121
121
|
const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd });
|
|
122
|
-
telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.
|
|
122
|
+
telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.48", cliCommand: "build" }, userConfig, flags));
|
|
123
123
|
return await build(astroConfig, { logging, telemetry });
|
|
124
124
|
} catch (err) {
|
|
125
125
|
return throwAndExit(err);
|
|
@@ -127,14 +127,14 @@ async function cli(args) {
|
|
|
127
127
|
}
|
|
128
128
|
case "check": {
|
|
129
129
|
const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd });
|
|
130
|
-
telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.
|
|
130
|
+
telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.48", cliCommand: "check" }, userConfig, flags));
|
|
131
131
|
const ret = await check(astroConfig);
|
|
132
132
|
return process.exit(ret);
|
|
133
133
|
}
|
|
134
134
|
case "preview": {
|
|
135
135
|
try {
|
|
136
136
|
const { astroConfig, userConfig } = await openConfig({ cwd: root, flags, cmd });
|
|
137
|
-
telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.
|
|
137
|
+
telemetry.record(event.eventCliSession({ astroVersion: "1.0.0-beta.48", cliCommand: "preview" }, userConfig, flags));
|
|
138
138
|
const server = await preview(astroConfig, { logging, telemetry });
|
|
139
139
|
return await server.closed();
|
|
140
140
|
} catch (err) {
|
|
@@ -144,7 +144,7 @@ async function cli(args) {
|
|
|
144
144
|
case "docs": {
|
|
145
145
|
try {
|
|
146
146
|
await telemetry.record(event.eventCliSession({
|
|
147
|
-
astroVersion: "1.0.0-beta.
|
|
147
|
+
astroVersion: "1.0.0-beta.48",
|
|
148
148
|
cliCommand: "docs"
|
|
149
149
|
}));
|
|
150
150
|
return await openInBrowser("https://docs.astro.build/");
|
|
@@ -34,6 +34,9 @@ function* throttle(max, inPaths) {
|
|
|
34
34
|
yield tmp;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
function shouldSkipDraft(pageModule, astroConfig) {
|
|
38
|
+
return !astroConfig.markdown.drafts && "frontmatter" in pageModule && pageModule.frontmatter.draft === true;
|
|
39
|
+
}
|
|
37
40
|
function rootRelativeFacadeId(facadeId, astroConfig) {
|
|
38
41
|
return facadeId.slice(fileURLToPath(astroConfig.root).length);
|
|
39
42
|
}
|
|
@@ -73,6 +76,10 @@ async function generatePage(opts, internals, pageData, ssrEntry) {
|
|
|
73
76
|
if (!pageModule) {
|
|
74
77
|
throw new Error(`Unable to find the module for ${pageData.component}. This is unexpected and likely a bug in Astro, please report.`);
|
|
75
78
|
}
|
|
79
|
+
if (shouldSkipDraft(pageModule, opts.astroConfig)) {
|
|
80
|
+
info(opts.logging, null, `${magenta("\u26A0\uFE0F")} Skipping draft ${pageData.route.component}`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
76
83
|
const generationOptions = {
|
|
77
84
|
pageData,
|
|
78
85
|
internals,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { resolvedPagesVirtualModuleId } from "../app/index.js";
|
|
2
|
+
function* walkParentInfos(id, ctx, seen = /* @__PURE__ */ new Set()) {
|
|
3
|
+
seen.add(id);
|
|
4
|
+
const info = ctx.getModuleInfo(id);
|
|
5
|
+
if (info) {
|
|
6
|
+
yield info;
|
|
7
|
+
}
|
|
8
|
+
const importers = ((info == null ? void 0 : info.importers) || []).concat((info == null ? void 0 : info.dynamicImporters) || []);
|
|
9
|
+
for (const imp of importers) {
|
|
10
|
+
if (seen.has(imp)) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
yield* walkParentInfos(imp, ctx, seen);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function* getTopLevelPages(id, ctx) {
|
|
17
|
+
for (const info of walkParentInfos(id, ctx)) {
|
|
18
|
+
const importers = ((info == null ? void 0 : info.importers) || []).concat((info == null ? void 0 : info.dynamicImporters) || []);
|
|
19
|
+
if (importers.length <= 2 && importers[0] === resolvedPagesVirtualModuleId) {
|
|
20
|
+
yield info.id;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
getTopLevelPages,
|
|
26
|
+
walkParentInfos
|
|
27
|
+
};
|
package/dist/core/build/index.js
CHANGED
|
@@ -33,7 +33,7 @@ class AstroBuilder {
|
|
|
33
33
|
this.logging = options.logging;
|
|
34
34
|
this.routeCache = new RouteCache(this.logging);
|
|
35
35
|
this.origin = config.site ? new URL(config.site).origin : `http://localhost:${config.server.port}`;
|
|
36
|
-
this.manifest =
|
|
36
|
+
this.manifest = { routes: [] };
|
|
37
37
|
this.timer = {};
|
|
38
38
|
}
|
|
39
39
|
async setup() {
|
|
@@ -42,6 +42,7 @@ class AstroBuilder {
|
|
|
42
42
|
this.timer.init = performance.now();
|
|
43
43
|
this.timer.viteStart = performance.now();
|
|
44
44
|
this.config = await runHookConfigSetup({ config: this.config, command: "build" });
|
|
45
|
+
this.manifest = createRouteManifest({ config: this.config }, this.logging);
|
|
45
46
|
const viteConfig = await createVite({
|
|
46
47
|
mode: this.mode,
|
|
47
48
|
server: {
|
|
@@ -78,15 +79,6 @@ class AstroBuilder {
|
|
|
78
79
|
viteServer,
|
|
79
80
|
ssr: isBuildingToSSR(this.config)
|
|
80
81
|
});
|
|
81
|
-
Object.entries(allPages).forEach(([page, data]) => {
|
|
82
|
-
if ("frontmatter" in data.preload[1]) {
|
|
83
|
-
const frontmatter = data.preload[1].frontmatter;
|
|
84
|
-
if (Boolean(frontmatter.draft) && !this.config.markdown.drafts) {
|
|
85
|
-
debug("build", timerMessage(`Skipping draft page ${page}`, this.timer.loadStart));
|
|
86
|
-
delete allPages[page];
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
82
|
debug("build", timerMessage("All pages loaded", this.timer.loadStart));
|
|
91
83
|
const pageNames = [];
|
|
92
84
|
this.timer.buildStart = performance.now();
|
|
@@ -14,7 +14,11 @@ function createBuildInternals() {
|
|
|
14
14
|
entrySpecifierToBundleMap: /* @__PURE__ */ new Map(),
|
|
15
15
|
pagesByComponent: /* @__PURE__ */ new Map(),
|
|
16
16
|
pagesByViteID: /* @__PURE__ */ new Map(),
|
|
17
|
-
pagesByClientOnly: /* @__PURE__ */ new Map()
|
|
17
|
+
pagesByClientOnly: /* @__PURE__ */ new Map(),
|
|
18
|
+
discoveredHydratedComponents: /* @__PURE__ */ new Set(),
|
|
19
|
+
discoveredClientOnlyComponents: /* @__PURE__ */ new Set(),
|
|
20
|
+
discoveredScripts: /* @__PURE__ */ new Set(),
|
|
21
|
+
staticFiles: /* @__PURE__ */ new Set()
|
|
18
22
|
};
|
|
19
23
|
}
|
|
20
24
|
function trackPageData(internals, component, pageData, componentModuleId, componentURL) {
|
|
@@ -3,7 +3,6 @@ import * as colors from "kleur/colors";
|
|
|
3
3
|
import { fileURLToPath } from "url";
|
|
4
4
|
import { debug } from "../logger/core.js";
|
|
5
5
|
import { removeTrailingForwardSlash } from "../path.js";
|
|
6
|
-
import { preload as ssrPreload } from "../render/dev/index.js";
|
|
7
6
|
import { callGetStaticPaths } from "../render/route-cache.js";
|
|
8
7
|
import { matchRoute } from "../routing/match.js";
|
|
9
8
|
import { isBuildingToSSR } from "../util.js";
|
|
@@ -31,26 +30,15 @@ async function collectPagesData(opts) {
|
|
|
31
30
|
moduleSpecifier: "",
|
|
32
31
|
css: /* @__PURE__ */ new Set(),
|
|
33
32
|
hoistedScript: void 0,
|
|
34
|
-
scripts: /* @__PURE__ */ new Set()
|
|
35
|
-
preload: await ssrPreload({
|
|
36
|
-
astroConfig,
|
|
37
|
-
filePath: new URL(`./${route.component}`, astroConfig.root),
|
|
38
|
-
viteServer
|
|
39
|
-
}).then((routes) => {
|
|
40
|
-
clearInterval(routeCollectionLogTimeout);
|
|
41
|
-
if (buildMode === "static") {
|
|
42
|
-
const html = `${route.pathname}`.replace(/\/?$/, "/index.html");
|
|
43
|
-
debug("build", `\u251C\u2500\u2500 ${colors.bold(colors.green("\u2714"))} ${route.component} \u2192 ${colors.yellow(html)}`);
|
|
44
|
-
} else {
|
|
45
|
-
debug("build", `\u251C\u2500\u2500 ${colors.bold(colors.green("\u2714"))} ${route.component}`);
|
|
46
|
-
}
|
|
47
|
-
return routes;
|
|
48
|
-
}).catch((err) => {
|
|
49
|
-
clearInterval(routeCollectionLogTimeout);
|
|
50
|
-
debug("build", `\u251C\u2500\u2500 ${colors.bold(colors.red("\u2718"))} ${route.component}`);
|
|
51
|
-
throw err;
|
|
52
|
-
})
|
|
33
|
+
scripts: /* @__PURE__ */ new Set()
|
|
53
34
|
};
|
|
35
|
+
clearInterval(routeCollectionLogTimeout);
|
|
36
|
+
if (buildMode === "static") {
|
|
37
|
+
const html = `${route.pathname}`.replace(/\/?$/, "/index.html");
|
|
38
|
+
debug("build", `\u251C\u2500\u2500 ${colors.bold(colors.green("\u2714"))} ${route.component} \u2192 ${colors.yellow(html)}`);
|
|
39
|
+
} else {
|
|
40
|
+
debug("build", `\u251C\u2500\u2500 ${colors.bold(colors.green("\u2714"))} ${route.component}`);
|
|
41
|
+
}
|
|
54
42
|
continue;
|
|
55
43
|
}
|
|
56
44
|
const result = await getStaticPathsForRoute(opts, route).then((_result) => {
|
|
@@ -79,12 +67,7 @@ async function collectPagesData(opts) {
|
|
|
79
67
|
moduleSpecifier: "",
|
|
80
68
|
css: /* @__PURE__ */ new Set(),
|
|
81
69
|
hoistedScript: void 0,
|
|
82
|
-
scripts: /* @__PURE__ */ new Set()
|
|
83
|
-
preload: await ssrPreload({
|
|
84
|
-
astroConfig,
|
|
85
|
-
filePath: new URL(`./${route.component}`, astroConfig.root),
|
|
86
|
-
viteServer
|
|
87
|
-
})
|
|
70
|
+
scripts: /* @__PURE__ */ new Set()
|
|
88
71
|
};
|
|
89
72
|
}
|
|
90
73
|
clearInterval(dataCollectionLogTimeout);
|
|
@@ -22,10 +22,7 @@ import fs from "fs";
|
|
|
22
22
|
import { bgGreen, bgMagenta, black, dim } from "kleur/colors";
|
|
23
23
|
import { fileURLToPath } from "url";
|
|
24
24
|
import * as vite from "vite";
|
|
25
|
-
import {
|
|
26
|
-
createBuildInternals,
|
|
27
|
-
trackClientOnlyPageDatas
|
|
28
|
-
} from "../../core/build/internal.js";
|
|
25
|
+
import { createBuildInternals } from "../../core/build/internal.js";
|
|
29
26
|
import { prependForwardSlash } from "../../core/path.js";
|
|
30
27
|
import { emptyDir, removeDir } from "../../core/util.js";
|
|
31
28
|
import { runHookBuildSetup } from "../../integrations/index.js";
|
|
@@ -35,67 +32,38 @@ import { isBuildingToSSR } from "../util.js";
|
|
|
35
32
|
import { generatePages } from "./generate.js";
|
|
36
33
|
import { trackPageData } from "./internal.js";
|
|
37
34
|
import { getTimeStat } from "./util.js";
|
|
35
|
+
import { vitePluginAnalyzer } from "./vite-plugin-analyzer.js";
|
|
38
36
|
import { vitePluginHoistedScripts } from "./vite-plugin-hoisted-scripts.js";
|
|
39
37
|
import { vitePluginInternals } from "./vite-plugin-internals.js";
|
|
40
38
|
import { vitePluginPages } from "./vite-plugin-pages.js";
|
|
41
|
-
import { vitePluginSSR } from "./vite-plugin-ssr.js";
|
|
39
|
+
import { injectManifest, vitePluginSSR } from "./vite-plugin-ssr.js";
|
|
42
40
|
async function staticBuild(opts) {
|
|
43
41
|
const { allPages, astroConfig } = opts;
|
|
44
42
|
const pageInput = /* @__PURE__ */ new Set();
|
|
45
|
-
const jsInput = /* @__PURE__ */ new Set();
|
|
46
43
|
const facadeIdToPageDataMap = /* @__PURE__ */ new Map();
|
|
47
44
|
const internals = createBuildInternals();
|
|
48
|
-
const uniqueHoistedIds = /* @__PURE__ */ new Map();
|
|
49
45
|
const timer = {};
|
|
50
46
|
timer.buildStart = performance.now();
|
|
51
47
|
for (const [component, pageData] of Object.entries(allPages)) {
|
|
52
48
|
const astroModuleURL = new URL("./" + component, astroConfig.root);
|
|
53
49
|
const astroModuleId = prependForwardSlash(component);
|
|
54
50
|
trackPageData(internals, component, pageData, astroModuleId, astroModuleURL);
|
|
55
|
-
if (pageData.route.type === "page") {
|
|
56
|
-
const [renderers, mod] = pageData.preload;
|
|
57
|
-
const metadata = mod.$$metadata;
|
|
58
|
-
const clientOnlys = Array.from(metadata.clientOnlyComponentPaths());
|
|
59
|
-
trackClientOnlyPageDatas(internals, pageData, clientOnlys);
|
|
60
|
-
const topLevelImports = /* @__PURE__ */ new Set([
|
|
61
|
-
...metadata.hydratedComponentPaths(),
|
|
62
|
-
...clientOnlys,
|
|
63
|
-
...metadata.hydrationDirectiveSpecifiers(),
|
|
64
|
-
...renderers.filter((renderer) => !!renderer.clientEntrypoint).map((renderer) => renderer.clientEntrypoint)
|
|
65
|
-
]);
|
|
66
|
-
const hoistedScripts = new Set(metadata.hoistedScriptPaths());
|
|
67
|
-
if (hoistedScripts.size) {
|
|
68
|
-
const uniqueHoistedId = JSON.stringify(Array.from(hoistedScripts).sort());
|
|
69
|
-
let moduleId;
|
|
70
|
-
if (uniqueHoistedIds.has(uniqueHoistedId)) {
|
|
71
|
-
moduleId = uniqueHoistedIds.get(uniqueHoistedId);
|
|
72
|
-
} else {
|
|
73
|
-
moduleId = `/astro/hoisted.js?q=${uniqueHoistedIds.size}`;
|
|
74
|
-
uniqueHoistedIds.set(uniqueHoistedId, moduleId);
|
|
75
|
-
}
|
|
76
|
-
topLevelImports.add(moduleId);
|
|
77
|
-
if (internals.hoistedScriptIdToPagesMap.has(moduleId)) {
|
|
78
|
-
const pages = internals.hoistedScriptIdToPagesMap.get(moduleId);
|
|
79
|
-
pages.add(astroModuleId);
|
|
80
|
-
} else {
|
|
81
|
-
internals.hoistedScriptIdToPagesMap.set(moduleId, /* @__PURE__ */ new Set([astroModuleId]));
|
|
82
|
-
internals.hoistedScriptIdToHoistedMap.set(moduleId, hoistedScripts);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
for (const specifier of topLevelImports) {
|
|
86
|
-
jsInput.add(specifier);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
51
|
pageInput.add(astroModuleId);
|
|
90
52
|
facadeIdToPageDataMap.set(fileURLToPath(astroModuleURL), pageData);
|
|
91
53
|
}
|
|
92
54
|
emptyDir(astroConfig.outDir, new Set(".git"));
|
|
93
|
-
timer.clientBuild = performance.now();
|
|
94
|
-
await clientBuild(opts, internals, jsInput);
|
|
95
55
|
timer.ssr = performance.now();
|
|
96
56
|
info(opts.logging, "build", isBuildingToSSR(astroConfig) ? "Building SSR entrypoints..." : "Building entrypoints for prerendering...");
|
|
97
57
|
const ssrResult = await ssrBuild(opts, internals, pageInput);
|
|
98
58
|
info(opts.logging, "build", dim(`Completed in ${getTimeStat(timer.ssr, performance.now())}.`));
|
|
59
|
+
const clientInput = /* @__PURE__ */ new Set([
|
|
60
|
+
...internals.discoveredHydratedComponents,
|
|
61
|
+
...internals.discoveredClientOnlyComponents,
|
|
62
|
+
...astroConfig._ctx.renderers.map((r) => r.clientEntrypoint).filter((a) => a),
|
|
63
|
+
...internals.discoveredScripts
|
|
64
|
+
]);
|
|
65
|
+
timer.clientBuild = performance.now();
|
|
66
|
+
await clientBuild(opts, internals, clientInput);
|
|
99
67
|
timer.generate = performance.now();
|
|
100
68
|
if (opts.buildConfig.staticMode) {
|
|
101
69
|
try {
|
|
@@ -104,6 +72,7 @@ async function staticBuild(opts) {
|
|
|
104
72
|
await cleanSsrOutput(opts);
|
|
105
73
|
}
|
|
106
74
|
} else {
|
|
75
|
+
await injectManifest(opts, internals);
|
|
107
76
|
info(opts.logging, null, `
|
|
108
77
|
${bgMagenta(black(" finalizing server assets "))}
|
|
109
78
|
`);
|
|
@@ -150,7 +119,8 @@ async function ssrBuild(opts, internals, input) {
|
|
|
150
119
|
target: "server"
|
|
151
120
|
}),
|
|
152
121
|
...viteConfig.plugins || [],
|
|
153
|
-
isBuildingToSSR(opts.astroConfig) && vitePluginSSR(opts, internals, opts.astroConfig._ctx.adapter)
|
|
122
|
+
isBuildingToSSR(opts.astroConfig) && vitePluginSSR(opts, internals, opts.astroConfig._ctx.adapter),
|
|
123
|
+
vitePluginAnalyzer(opts.astroConfig, internals)
|
|
154
124
|
],
|
|
155
125
|
publicDir: ssr ? false : viteConfig.publicDir,
|
|
156
126
|
root: viteConfig.root,
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { prependForwardSlash } from "../../core/path.js";
|
|
2
|
+
import { getTopLevelPages } from "./graph.js";
|
|
3
|
+
import { getPageDataByViteID, trackClientOnlyPageDatas } from "./internal.js";
|
|
4
|
+
function vitePluginAnalyzer(astroConfig, internals) {
|
|
5
|
+
function hoistedScriptScanner() {
|
|
6
|
+
const uniqueHoistedIds = /* @__PURE__ */ new Map();
|
|
7
|
+
const pageScripts = /* @__PURE__ */ new Map();
|
|
8
|
+
return {
|
|
9
|
+
scan(scripts, from) {
|
|
10
|
+
var _a;
|
|
11
|
+
const hoistedScripts = /* @__PURE__ */ new Set();
|
|
12
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
13
|
+
const hid = `${from.replace("/@fs", "")}?astro&type=script&index=${i}`;
|
|
14
|
+
hoistedScripts.add(hid);
|
|
15
|
+
}
|
|
16
|
+
if (hoistedScripts.size) {
|
|
17
|
+
for (const pageId of getTopLevelPages(from, this)) {
|
|
18
|
+
for (const hid of hoistedScripts) {
|
|
19
|
+
if (pageScripts.has(pageId)) {
|
|
20
|
+
(_a = pageScripts.get(pageId)) == null ? void 0 : _a.add(hid);
|
|
21
|
+
} else {
|
|
22
|
+
pageScripts.set(pageId, /* @__PURE__ */ new Set([hid]));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
finalize() {
|
|
29
|
+
for (const [pageId, hoistedScripts] of pageScripts) {
|
|
30
|
+
const pageData = getPageDataByViteID(internals, pageId);
|
|
31
|
+
if (!pageData)
|
|
32
|
+
continue;
|
|
33
|
+
const { component } = pageData;
|
|
34
|
+
const astroModuleId = prependForwardSlash(component);
|
|
35
|
+
const uniqueHoistedId = JSON.stringify(Array.from(hoistedScripts).sort());
|
|
36
|
+
let moduleId;
|
|
37
|
+
if (uniqueHoistedIds.has(uniqueHoistedId)) {
|
|
38
|
+
moduleId = uniqueHoistedIds.get(uniqueHoistedId);
|
|
39
|
+
} else {
|
|
40
|
+
moduleId = `/astro/hoisted.js?q=${uniqueHoistedIds.size}`;
|
|
41
|
+
uniqueHoistedIds.set(uniqueHoistedId, moduleId);
|
|
42
|
+
}
|
|
43
|
+
internals.discoveredScripts.add(moduleId);
|
|
44
|
+
if (internals.hoistedScriptIdToPagesMap.has(moduleId)) {
|
|
45
|
+
const pages = internals.hoistedScriptIdToPagesMap.get(moduleId);
|
|
46
|
+
pages.add(astroModuleId);
|
|
47
|
+
} else {
|
|
48
|
+
internals.hoistedScriptIdToPagesMap.set(moduleId, /* @__PURE__ */ new Set([astroModuleId]));
|
|
49
|
+
internals.hoistedScriptIdToHoistedMap.set(moduleId, hoistedScripts);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
name: "@astro/rollup-plugin-astro-analyzer",
|
|
57
|
+
generateBundle() {
|
|
58
|
+
var _a;
|
|
59
|
+
const hoistScanner = hoistedScriptScanner();
|
|
60
|
+
const ids = this.getModuleIds();
|
|
61
|
+
for (const id of ids) {
|
|
62
|
+
const info = this.getModuleInfo(id);
|
|
63
|
+
if (!info || !((_a = info.meta) == null ? void 0 : _a.astro))
|
|
64
|
+
continue;
|
|
65
|
+
const astro = info.meta.astro;
|
|
66
|
+
for (const c of astro.hydratedComponents) {
|
|
67
|
+
internals.discoveredHydratedComponents.add(c.resolvedPath || c.specifier);
|
|
68
|
+
}
|
|
69
|
+
hoistScanner.scan.call(this, astro.scripts, id);
|
|
70
|
+
if (astro.clientOnlyComponents.length) {
|
|
71
|
+
const clientOnlys = [];
|
|
72
|
+
for (const c of astro.clientOnlyComponents) {
|
|
73
|
+
const cid = c.resolvedPath || c.specifier;
|
|
74
|
+
internals.discoveredClientOnlyComponents.add(cid);
|
|
75
|
+
clientOnlys.push(cid);
|
|
76
|
+
}
|
|
77
|
+
for (const pageId of getTopLevelPages(id, this)) {
|
|
78
|
+
const pageData = getPageDataByViteID(internals, pageId);
|
|
79
|
+
if (!pageData)
|
|
80
|
+
continue;
|
|
81
|
+
trackClientOnlyPageDatas(internals, pageData, clientOnlys);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
hoistScanner.finalize();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export {
|
|
90
|
+
vitePluginAnalyzer
|
|
91
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import glob from "fast-glob";
|
|
2
|
+
import * as fs from "fs";
|
|
2
3
|
import { fileURLToPath } from "url";
|
|
3
4
|
import { runHookBuildSsr } from "../../integrations/index.js";
|
|
4
5
|
import { BEFORE_HYDRATION_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
@@ -51,30 +52,42 @@ if(_start in adapter) {
|
|
|
51
52
|
return void 0;
|
|
52
53
|
},
|
|
53
54
|
async generateBundle(_opts, bundle) {
|
|
54
|
-
|
|
55
|
+
internals.staticFiles = new Set(await glob("**/*", {
|
|
55
56
|
cwd: fileURLToPath(buildOpts.buildConfig.client)
|
|
56
57
|
}));
|
|
57
58
|
for (const [_chunkName, chunk] of Object.entries(bundle)) {
|
|
58
59
|
if (chunk.type === "asset") {
|
|
59
|
-
staticFiles.add(chunk.fileName);
|
|
60
|
+
internals.staticFiles.add(chunk.fileName);
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
|
-
const
|
|
63
|
-
await runHookBuildSsr({ config: buildOpts.astroConfig, manifest });
|
|
64
|
-
for (const [_chunkName, chunk] of Object.entries(bundle)) {
|
|
63
|
+
for (const [chunkName, chunk] of Object.entries(bundle)) {
|
|
65
64
|
if (chunk.type === "asset") {
|
|
66
65
|
continue;
|
|
67
66
|
}
|
|
68
67
|
if (chunk.modules[resolvedVirtualModuleId]) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return JSON.stringify(manifest);
|
|
72
|
-
});
|
|
68
|
+
internals.ssrEntryChunk = chunk;
|
|
69
|
+
delete bundle[chunkName];
|
|
73
70
|
}
|
|
74
71
|
}
|
|
75
72
|
}
|
|
76
73
|
};
|
|
77
74
|
}
|
|
75
|
+
async function injectManifest(buildOpts, internals) {
|
|
76
|
+
if (!internals.ssrEntryChunk) {
|
|
77
|
+
throw new Error(`Did not generate an entry chunk for SSR`);
|
|
78
|
+
}
|
|
79
|
+
const staticFiles = internals.staticFiles;
|
|
80
|
+
const manifest = buildManifest(buildOpts, internals, Array.from(staticFiles));
|
|
81
|
+
await runHookBuildSsr({ config: buildOpts.astroConfig, manifest });
|
|
82
|
+
const chunk = internals.ssrEntryChunk;
|
|
83
|
+
const code = chunk.code;
|
|
84
|
+
chunk.code = code.replace(replaceExp, () => {
|
|
85
|
+
return JSON.stringify(manifest);
|
|
86
|
+
});
|
|
87
|
+
const serverEntryURL = new URL(buildOpts.buildConfig.serverEntry, buildOpts.buildConfig.server);
|
|
88
|
+
await fs.promises.mkdir(new URL("./", serverEntryURL), { recursive: true });
|
|
89
|
+
await fs.promises.writeFile(serverEntryURL, chunk.code, "utf-8");
|
|
90
|
+
}
|
|
78
91
|
function buildManifest(opts, internals, staticFiles) {
|
|
79
92
|
const { astroConfig } = opts;
|
|
80
93
|
const routes = [];
|
|
@@ -108,6 +121,7 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
108
121
|
return ssrManifest;
|
|
109
122
|
}
|
|
110
123
|
export {
|
|
124
|
+
injectManifest,
|
|
111
125
|
virtualModuleId,
|
|
112
126
|
vitePluginSSR
|
|
113
127
|
};
|
package/dist/core/config.js
CHANGED
|
@@ -205,7 +205,13 @@ See https://astro.build/config for more information.`);
|
|
|
205
205
|
}).optional().default({})
|
|
206
206
|
});
|
|
207
207
|
const result = __spreadProps(__spreadValues({}, await AstroConfigRelativeSchema.parseAsync(userConfig)), {
|
|
208
|
-
_ctx: {
|
|
208
|
+
_ctx: {
|
|
209
|
+
pageExtensions: [],
|
|
210
|
+
scripts: [],
|
|
211
|
+
renderers: [],
|
|
212
|
+
injectedRoutes: [],
|
|
213
|
+
adapter: void 0
|
|
214
|
+
}
|
|
209
215
|
});
|
|
210
216
|
if (!((_a = result.experimental) == null ? void 0 : _a.integrations) && !result.integrations.every((int) => int.name.startsWith("@astrojs/"))) {
|
|
211
217
|
throw new Error([
|
package/dist/core/create-vite.js
CHANGED
package/dist/core/dev/index.js
CHANGED
|
@@ -47,7 +47,7 @@ async function dev(config, options) {
|
|
|
47
47
|
site,
|
|
48
48
|
https: !!((_a = viteConfig.server) == null ? void 0 : _a.https)
|
|
49
49
|
}));
|
|
50
|
-
const currentVersion = "1.0.0-beta.
|
|
50
|
+
const currentVersion = "1.0.0-beta.48";
|
|
51
51
|
if (currentVersion.includes("-")) {
|
|
52
52
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
53
53
|
}
|
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function devStart({
|
|
|
47
47
|
https,
|
|
48
48
|
site
|
|
49
49
|
}) {
|
|
50
|
-
const version = "1.0.0-beta.
|
|
50
|
+
const version = "1.0.0-beta.48";
|
|
51
51
|
const rootPath = site ? site.pathname : "/";
|
|
52
52
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
53
53
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
@@ -60,7 +60,7 @@ function devStart({
|
|
|
60
60
|
if (networkLogging === "host-to-expose") {
|
|
61
61
|
network = `${networkPrefix}${dim("use --host to expose")}`;
|
|
62
62
|
} else if (networkLogging === "visible") {
|
|
63
|
-
const ipv4Networks = Object.values(os.networkInterfaces()).flatMap((networkInterface) => networkInterface ?? []).filter((networkInterface) => (networkInterface == null ? void 0 : networkInterface.address) && (networkInterface == null ? void 0 : networkInterface.family) === "IPv4");
|
|
63
|
+
const ipv4Networks = Object.values(os.networkInterfaces()).flatMap((networkInterface) => networkInterface ?? []).filter((networkInterface) => (networkInterface == null ? void 0 : networkInterface.address) && (networkInterface == null ? void 0 : networkInterface.family) === (Number(process.version.substring(1, 5)) < 18.1 ? "IPv4" : 4));
|
|
64
64
|
for (let { address } of ipv4Networks) {
|
|
65
65
|
if (address.includes("127.0.0.1")) {
|
|
66
66
|
const displayAddress = address.replace("127.0.0.1", localAddress);
|
|
@@ -207,7 +207,7 @@ function printHelp({
|
|
|
207
207
|
};
|
|
208
208
|
let message = [];
|
|
209
209
|
if (headline) {
|
|
210
|
-
message.push(linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green(`v${"1.0.0-beta.
|
|
210
|
+
message.push(linebreak(), ` ${bgGreen(black(` ${commandName} `))} ${green(`v${"1.0.0-beta.48"}`)} ${headline}`);
|
|
211
211
|
}
|
|
212
212
|
if (usage) {
|
|
213
213
|
message.push(linebreak(), ` ${green(commandName)} ${bold(usage)}`);
|
package/dist/core/render/core.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -14,7 +16,8 @@ var __spreadValues = (a, b) => {
|
|
|
14
16
|
}
|
|
15
17
|
return a;
|
|
16
18
|
};
|
|
17
|
-
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { renderComponent, renderHead, renderPage } from "../../runtime/server/index.js";
|
|
18
21
|
import { getParams } from "../routing/params.js";
|
|
19
22
|
import { createResult } from "./result.js";
|
|
20
23
|
import { callGetStaticPaths, findPathItemByKey } from "./route-cache.js";
|
|
@@ -81,8 +84,6 @@ async function render(opts) {
|
|
|
81
84
|
const Component = await mod.default;
|
|
82
85
|
if (!Component)
|
|
83
86
|
throw new Error(`Expected an exported Astro component but received typeof ${typeof Component}`);
|
|
84
|
-
if (!Component.isAstroComponentFactory)
|
|
85
|
-
throw new Error(`Unable to SSR non-Astro component (${route == null ? void 0 : route.component})`);
|
|
86
87
|
const result = createResult({
|
|
87
88
|
links,
|
|
88
89
|
styles,
|
|
@@ -99,7 +100,17 @@ async function render(opts) {
|
|
|
99
100
|
scripts,
|
|
100
101
|
ssr
|
|
101
102
|
});
|
|
102
|
-
let page
|
|
103
|
+
let page;
|
|
104
|
+
if (!Component.isAstroComponentFactory) {
|
|
105
|
+
const props = __spreadProps(__spreadValues({}, pageProps ?? {}), { "server:root": true });
|
|
106
|
+
const html2 = await renderComponent(result, Component.name, Component, props, null);
|
|
107
|
+
page = {
|
|
108
|
+
type: "html",
|
|
109
|
+
html: html2.toString()
|
|
110
|
+
};
|
|
111
|
+
} else {
|
|
112
|
+
page = await renderPage(result, Component, pageProps, null);
|
|
113
|
+
}
|
|
103
114
|
if (page.type === "response") {
|
|
104
115
|
return page;
|
|
105
116
|
}
|