astro 0.25.0-next.2 → 0.25.0-next.3

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.
Files changed (55) hide show
  1. package/components/Markdown.astro +1 -3
  2. package/components/index.js +0 -1
  3. package/dist/adapter-ssg/index.js +22 -0
  4. package/dist/cli/index.js +2 -2
  5. package/dist/core/app/index.js +90 -81
  6. package/dist/core/app/node.js +2 -1
  7. package/dist/core/build/add-rollup-input.js +50 -0
  8. package/dist/core/build/common.js +62 -0
  9. package/dist/core/build/generate.js +174 -0
  10. package/dist/core/build/index.js +21 -8
  11. package/dist/core/build/internal.js +38 -6
  12. package/dist/core/build/page-data.js +29 -2
  13. package/dist/core/build/scan-based-build.js +2 -2
  14. package/dist/core/build/static-build.js +52 -321
  15. package/dist/core/build/util.js +7 -0
  16. package/dist/core/build/vite-plugin-hoisted-scripts.js +7 -3
  17. package/dist/core/build/vite-plugin-internals.js +47 -0
  18. package/dist/core/build/vite-plugin-pages.js +50 -0
  19. package/dist/core/build/vite-plugin-ssr.js +88 -0
  20. package/dist/core/config.js +3 -2
  21. package/dist/core/dev/index.js +1 -1
  22. package/dist/core/messages.js +1 -1
  23. package/dist/core/render/dev/index.js +3 -8
  24. package/dist/core/render/result.js +9 -4
  25. package/dist/core/routing/manifest/serialization.js +4 -4
  26. package/dist/core/util.js +5 -0
  27. package/dist/integrations/index.js +25 -3
  28. package/dist/types/@types/astro.d.ts +49 -16
  29. package/dist/types/adapter-ssg/index.d.ts +3 -0
  30. package/dist/types/core/app/index.d.ts +2 -1
  31. package/dist/types/core/app/node.d.ts +1 -2
  32. package/dist/types/core/app/types.d.ts +4 -2
  33. package/dist/types/core/build/add-rollup-input.d.ts +2 -0
  34. package/dist/types/core/build/common.d.ts +6 -0
  35. package/dist/types/core/build/generate.d.ts +7 -0
  36. package/dist/types/core/build/internal.d.ts +28 -4
  37. package/dist/types/core/build/scan-based-build.d.ts +2 -1
  38. package/dist/types/core/build/static-build.d.ts +1 -18
  39. package/dist/types/core/build/util.d.ts +1 -0
  40. package/dist/types/core/build/vite-plugin-internals.d.ts +3 -0
  41. package/dist/types/core/build/vite-plugin-pages.d.ts +5 -0
  42. package/dist/types/core/build/vite-plugin-ssr.d.ts +6 -0
  43. package/dist/types/core/config.d.ts +18 -0
  44. package/dist/types/core/util.d.ts +1 -0
  45. package/dist/types/integrations/index.d.ts +3 -2
  46. package/dist/types/vite-plugin-build-html/index.d.ts +1 -1
  47. package/dist/types/vite-plugin-scripts/index.d.ts +3 -0
  48. package/dist/vite-plugin-astro/index.js +4 -3
  49. package/dist/vite-plugin-build-css/index.js +7 -16
  50. package/dist/vite-plugin-build-html/index.js +2 -2
  51. package/dist/vite-plugin-env/index.js +19 -6
  52. package/dist/vite-plugin-markdown/index.js +8 -8
  53. package/dist/vite-plugin-scripts/index.js +6 -3
  54. package/package.json +13 -4
  55. package/components/Prism.astro +0 -49
@@ -24,8 +24,6 @@ let { content, class: className } = Astro.props as InternalProps;
24
24
  let html = null;
25
25
  let htmlContent = '';
26
26
 
27
- const { privateRenderMarkdownDoNotUse: renderMarkdown } = Astro as any;
28
-
29
27
  // If no content prop provided, use the slot.
30
28
  if (!content) {
31
29
  content = await Astro.slots.render('default');
@@ -35,7 +33,7 @@ if (!content) {
35
33
  }
36
34
 
37
35
  if (content) {
38
- htmlContent = await renderMarkdown(content, {
36
+ htmlContent = await (Astro as any).__renderMarkdown(content, {
39
37
  mode: 'md',
40
38
  $: {
41
39
  scopedClassName: className,
@@ -1,4 +1,3 @@
1
1
  export { default as Code } from './Code.astro';
2
2
  export { default as Debug } from './Debug.astro';
3
3
  export { default as Markdown } from './Markdown.astro';
4
- export { default as Prism } from './Prism.astro';
@@ -0,0 +1,22 @@
1
+ function getAdapter() {
2
+ return {
3
+ name: "@astrojs/ssg"
4
+ };
5
+ }
6
+ function createIntegration() {
7
+ return {
8
+ name: "@astrojs/ssg",
9
+ hooks: {
10
+ "astro:config:done": ({ setAdapter }) => {
11
+ setAdapter(getAdapter());
12
+ },
13
+ "astro:build:start": ({ buildConfig }) => {
14
+ buildConfig.staticMode = true;
15
+ }
16
+ }
17
+ };
18
+ }
19
+ export {
20
+ createIntegration as default,
21
+ getAdapter
22
+ };
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.25.0-next.2"}`)} ${tagline}`);
42
+ console.log(` ${colors.bgGreen(colors.black(` ${name} `))} ${colors.green(`v${"0.25.0-next.3"}`)} ${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.25.0-next.2";
68
+ const version = "0.25.0-next.3";
69
69
  console.log();
70
70
  console.log(` ${colors.bgGreen(colors.black(` astro `))} ${colors.green(`v${version}`)}`);
71
71
  }
@@ -1,22 +1,3 @@
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));
20
1
  var __accessCheck = (obj, member, msg) => {
21
2
  if (!member.has(obj))
22
3
  throw TypeError("Cannot " + msg);
@@ -39,31 +20,31 @@ var __privateMethod = (obj, member, method) => {
39
20
  __accessCheck(obj, member, "access private method");
40
21
  return method;
41
22
  };
42
- var _manifest, _manifestData, _rootFolder, _routeDataToRouteInfo, _routeCache, _renderersPromise, _loadRenderers, loadRenderers_fn, _loadModule, loadModule_fn;
23
+ var _manifest, _manifestData, _routeDataToRouteInfo, _routeCache, _encoder, _renderPage, renderPage_fn, _callEndpoint, callEndpoint_fn;
24
+ import mime from "mime";
43
25
  import { defaultLogOptions } from "../logger.js";
26
+ import { deserializeManifest } from "./common.js";
44
27
  import { matchRoute } from "../routing/match.js";
45
28
  import { render } from "../render/core.js";
29
+ import { call as callEndpoint } from "../endpoint/index.js";
46
30
  import { RouteCache } from "../render/route-cache.js";
47
31
  import { createLinkStylesheetElementSet, createModuleScriptElementWithSrcSet } from "../render/ssr-element.js";
48
32
  import { prependForwardSlash } from "../path.js";
49
33
  class App {
50
- constructor(manifest, rootFolder) {
51
- __privateAdd(this, _loadRenderers);
52
- __privateAdd(this, _loadModule);
34
+ constructor(manifest) {
35
+ __privateAdd(this, _renderPage);
36
+ __privateAdd(this, _callEndpoint);
53
37
  __privateAdd(this, _manifest, void 0);
54
38
  __privateAdd(this, _manifestData, void 0);
55
- __privateAdd(this, _rootFolder, void 0);
56
39
  __privateAdd(this, _routeDataToRouteInfo, void 0);
57
40
  __privateAdd(this, _routeCache, void 0);
58
- __privateAdd(this, _renderersPromise, void 0);
41
+ __privateAdd(this, _encoder, new TextEncoder());
59
42
  __privateSet(this, _manifest, manifest);
60
43
  __privateSet(this, _manifestData, {
61
44
  routes: manifest.routes.map((route) => route.routeData)
62
45
  });
63
- __privateSet(this, _rootFolder, rootFolder);
64
46
  __privateSet(this, _routeDataToRouteInfo, new Map(manifest.routes.map((route) => [route.routeData, route])));
65
47
  __privateSet(this, _routeCache, new RouteCache(defaultLogOptions));
66
- __privateSet(this, _renderersPromise, __privateMethod(this, _loadRenderers, loadRenderers_fn).call(this));
67
48
  }
68
49
  match(request) {
69
50
  const url = new URL(request.url);
@@ -79,69 +60,97 @@ class App {
79
60
  });
80
61
  }
81
62
  }
82
- const manifest = __privateGet(this, _manifest);
83
- const info = __privateGet(this, _routeDataToRouteInfo).get(routeData);
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);
86
- const links = createLinkStylesheetElementSet(info.links, manifest.site);
87
- const scripts = createModuleScriptElementWithSrcSet(info.scripts, manifest.site);
88
- const result = await render({
89
- legacyBuild: false,
90
- links,
91
- logging: defaultLogOptions,
92
- markdownRender: manifest.markdown.render,
93
- mod,
94
- origin: url.origin,
95
- pathname: url.pathname,
96
- scripts,
97
- renderers,
98
- async resolve(specifier) {
99
- if (!(specifier in manifest.entryModules)) {
100
- throw new Error(`Unable to resolve [${specifier}]`);
101
- }
102
- const bundlePath = manifest.entryModules[specifier];
103
- return prependForwardSlash(bundlePath);
104
- },
105
- route: routeData,
106
- routeCache: __privateGet(this, _routeCache),
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;
63
+ const mod = __privateGet(this, _manifest).pageMap.get(routeData.component);
64
+ if (routeData.type === "page") {
65
+ return __privateMethod(this, _renderPage, renderPage_fn).call(this, request, routeData, mod);
66
+ } else if (routeData.type === "endpoint") {
67
+ return __privateMethod(this, _callEndpoint, callEndpoint_fn).call(this, request, routeData, mod);
68
+ } else {
69
+ throw new Error(`Unsupported route type [${routeData.type}].`);
114
70
  }
115
- let html = result.html;
116
- return new Response(html, {
117
- status: 200
118
- });
119
71
  }
120
72
  }
121
73
  _manifest = new WeakMap();
122
74
  _manifestData = new WeakMap();
123
- _rootFolder = new WeakMap();
124
75
  _routeDataToRouteInfo = new WeakMap();
125
76
  _routeCache = new WeakMap();
126
- _renderersPromise = new WeakMap();
127
- _loadRenderers = new WeakSet();
128
- loadRenderers_fn = async function() {
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 });
132
- }));
77
+ _encoder = new WeakMap();
78
+ _renderPage = new WeakSet();
79
+ renderPage_fn = async function(request, routeData, mod) {
80
+ const url = new URL(request.url);
81
+ const manifest = __privateGet(this, _manifest);
82
+ const renderers = manifest.renderers;
83
+ const info = __privateGet(this, _routeDataToRouteInfo).get(routeData);
84
+ const links = createLinkStylesheetElementSet(info.links, manifest.site);
85
+ const scripts = createModuleScriptElementWithSrcSet(info.scripts, manifest.site);
86
+ const result = await render({
87
+ legacyBuild: false,
88
+ links,
89
+ logging: defaultLogOptions,
90
+ markdownRender: manifest.markdown.render,
91
+ mod,
92
+ origin: url.origin,
93
+ pathname: url.pathname,
94
+ scripts,
95
+ renderers,
96
+ async resolve(specifier) {
97
+ if (!(specifier in manifest.entryModules)) {
98
+ throw new Error(`Unable to resolve [${specifier}]`);
99
+ }
100
+ const bundlePath = manifest.entryModules[specifier];
101
+ return bundlePath.startsWith("data:") ? bundlePath : prependForwardSlash(bundlePath);
102
+ },
103
+ route: routeData,
104
+ routeCache: __privateGet(this, _routeCache),
105
+ site: __privateGet(this, _manifest).site,
106
+ ssr: true,
107
+ method: info.routeData.type === "endpoint" ? "" : "GET",
108
+ headers: request.headers
109
+ });
110
+ if (result.type === "response") {
111
+ return result.response;
112
+ }
113
+ let html = result.html;
114
+ let bytes = __privateGet(this, _encoder).encode(html);
115
+ return new Response(bytes, {
116
+ status: 200,
117
+ headers: {
118
+ "Content-Type": "text/html",
119
+ "Content-Length": bytes.byteLength.toString()
120
+ }
121
+ });
133
122
  };
134
- _loadModule = new WeakSet();
135
- loadModule_fn = async function(rootRelativePath) {
136
- let modUrl = new URL(rootRelativePath, __privateGet(this, _rootFolder)).toString();
137
- let mod;
138
- try {
139
- mod = await import(modUrl);
140
- return mod;
141
- } catch (err) {
142
- throw new Error(`Unable to import ${modUrl}. Does this file exist?`);
123
+ _callEndpoint = new WeakSet();
124
+ callEndpoint_fn = async function(request, routeData, mod) {
125
+ const url = new URL(request.url);
126
+ const handler = mod;
127
+ const result = await callEndpoint(handler, {
128
+ headers: request.headers,
129
+ logging: defaultLogOptions,
130
+ method: request.method,
131
+ origin: url.origin,
132
+ pathname: url.pathname,
133
+ routeCache: __privateGet(this, _routeCache),
134
+ ssr: true
135
+ });
136
+ if (result.type === "response") {
137
+ return result.response;
138
+ } else {
139
+ const body = result.body;
140
+ const headers = new Headers();
141
+ const mimeType = mime.getType(url.pathname);
142
+ if (mimeType) {
143
+ headers.set("Content-Type", mimeType);
144
+ }
145
+ const bytes = __privateGet(this, _encoder).encode(body);
146
+ headers.set("Content-Length", bytes.byteLength.toString());
147
+ return new Response(bytes, {
148
+ status: 200,
149
+ headers
150
+ });
143
151
  }
144
152
  };
145
153
  export {
146
- App
154
+ App,
155
+ deserializeManifest
147
156
  };
@@ -26,9 +26,10 @@ async function loadManifest(rootFolder) {
26
26
  }
27
27
  async function loadApp(rootFolder) {
28
28
  const manifest = await loadManifest(rootFolder);
29
- return new NodeApp(manifest, rootFolder);
29
+ return new NodeApp(manifest);
30
30
  }
31
31
  export {
32
+ NodeApp,
32
33
  loadApp,
33
34
  loadManifest
34
35
  };
@@ -0,0 +1,50 @@
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));
20
+ function fromEntries(entries) {
21
+ const obj = {};
22
+ for (const [k, v] of entries) {
23
+ obj[k] = v;
24
+ }
25
+ return obj;
26
+ }
27
+ function addRollupInput(inputOptions, newInputs) {
28
+ if (!inputOptions.input) {
29
+ return __spreadProps(__spreadValues({}, inputOptions), { input: newInputs });
30
+ }
31
+ if (typeof inputOptions.input === "string") {
32
+ return __spreadProps(__spreadValues({}, inputOptions), {
33
+ input: [inputOptions.input, ...newInputs]
34
+ });
35
+ }
36
+ if (Array.isArray(inputOptions.input)) {
37
+ return __spreadProps(__spreadValues({}, inputOptions), {
38
+ input: [...inputOptions.input, ...newInputs]
39
+ });
40
+ }
41
+ if (typeof inputOptions.input === "object") {
42
+ return __spreadProps(__spreadValues({}, inputOptions), {
43
+ input: __spreadValues(__spreadValues({}, inputOptions.input), fromEntries(newInputs.map((i) => [i.split("/").slice(-1)[0].split(".")[0], i])))
44
+ });
45
+ }
46
+ throw new Error(`Unknown rollup input type. Supported inputs are string, array and object.`);
47
+ }
48
+ export {
49
+ addRollupInput
50
+ };
@@ -0,0 +1,62 @@
1
+ import npath from "path";
2
+ import { appendForwardSlash } from "../../core/path.js";
3
+ const STATUS_CODE_PAGES = /* @__PURE__ */ new Set(["/404", "/500"]);
4
+ function getOutRoot(astroConfig) {
5
+ return new URL("./", astroConfig.dist);
6
+ }
7
+ function getServerRoot(astroConfig) {
8
+ const rootFolder = getOutRoot(astroConfig);
9
+ const serverFolder = new URL("./server/", rootFolder);
10
+ return serverFolder;
11
+ }
12
+ function getClientRoot(astroConfig) {
13
+ const rootFolder = getOutRoot(astroConfig);
14
+ const serverFolder = new URL("./client/", rootFolder);
15
+ return serverFolder;
16
+ }
17
+ function getOutFolder(astroConfig, pathname, routeType) {
18
+ const outRoot = getOutRoot(astroConfig);
19
+ switch (routeType) {
20
+ case "endpoint":
21
+ return new URL("." + appendForwardSlash(npath.dirname(pathname)), outRoot);
22
+ case "page":
23
+ switch (astroConfig.buildOptions.pageUrlFormat) {
24
+ case "directory": {
25
+ if (STATUS_CODE_PAGES.has(pathname)) {
26
+ return new URL("." + appendForwardSlash(npath.dirname(pathname)), outRoot);
27
+ }
28
+ return new URL("." + appendForwardSlash(pathname), outRoot);
29
+ }
30
+ case "file": {
31
+ return new URL("." + appendForwardSlash(npath.dirname(pathname)), outRoot);
32
+ }
33
+ }
34
+ }
35
+ }
36
+ function getOutFile(astroConfig, outFolder, pathname, routeType) {
37
+ switch (routeType) {
38
+ case "endpoint":
39
+ return new URL(npath.basename(pathname), outFolder);
40
+ case "page":
41
+ switch (astroConfig.buildOptions.pageUrlFormat) {
42
+ case "directory": {
43
+ if (STATUS_CODE_PAGES.has(pathname)) {
44
+ const baseName = npath.basename(pathname);
45
+ return new URL("./" + (baseName || "index") + ".html", outFolder);
46
+ }
47
+ return new URL("./index.html", outFolder);
48
+ }
49
+ case "file": {
50
+ const baseName = npath.basename(pathname);
51
+ return new URL("./" + (baseName || "index") + ".html", outFolder);
52
+ }
53
+ }
54
+ }
55
+ }
56
+ export {
57
+ getClientRoot,
58
+ getOutFile,
59
+ getOutFolder,
60
+ getOutRoot,
61
+ getServerRoot
62
+ };
@@ -0,0 +1,174 @@
1
+ import fs from "fs";
2
+ import npath from "path";
3
+ import { fileURLToPath } from "url";
4
+ import { debug, error, info } from "../../core/logger.js";
5
+ import { prependForwardSlash } from "../../core/path.js";
6
+ import { BEFORE_HYDRATION_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
7
+ import { call as callEndpoint } from "../endpoint/index.js";
8
+ import { render } from "../render/core.js";
9
+ import { createLinkStylesheetElementSet, createModuleScriptElementWithSrcSet } from "../render/ssr-element.js";
10
+ import { getOutFile, getOutRoot, getOutFolder, getServerRoot } from "./common.js";
11
+ import { getPageDataByComponent, eachPageData } from "./internal.js";
12
+ import { bgMagenta, black, cyan, dim, magenta } from "kleur/colors";
13
+ import { getTimeStat } from "./util.js";
14
+ const MAX_CONCURRENT_RENDERS = 1;
15
+ function* throttle(max, inPaths) {
16
+ let tmp = [];
17
+ let i = 0;
18
+ for (let path of inPaths) {
19
+ tmp.push(path);
20
+ if (i === max) {
21
+ yield tmp;
22
+ tmp.length = 0;
23
+ i = 0;
24
+ } else {
25
+ i++;
26
+ }
27
+ }
28
+ if (tmp.length) {
29
+ yield tmp;
30
+ }
31
+ }
32
+ function rootRelativeFacadeId(facadeId, astroConfig) {
33
+ return facadeId.slice(fileURLToPath(astroConfig.projectRoot).length);
34
+ }
35
+ function chunkIsPage(astroConfig, output, internals) {
36
+ if (output.type !== "chunk") {
37
+ return false;
38
+ }
39
+ const chunk = output;
40
+ if (chunk.facadeModuleId) {
41
+ const facadeToEntryId = prependForwardSlash(rootRelativeFacadeId(chunk.facadeModuleId, astroConfig));
42
+ return internals.entrySpecifierToBundleMap.has(facadeToEntryId);
43
+ }
44
+ return false;
45
+ }
46
+ async function generatePages(result, opts, internals, facadeIdToPageDataMap) {
47
+ var _a;
48
+ info(opts.logging, null, `
49
+ ${bgMagenta(black(" generating static routes "))}
50
+ `);
51
+ const ssr = !!((_a = opts.astroConfig._ctx.adapter) == null ? void 0 : _a.serverEntrypoint);
52
+ const outFolder = ssr ? getServerRoot(opts.astroConfig) : getOutRoot(opts.astroConfig);
53
+ const ssrEntryURL = new URL(`./entry.mjs?time=${Date.now()}`, outFolder);
54
+ const ssrEntry = await import(ssrEntryURL.toString());
55
+ for (const pageData of eachPageData(internals)) {
56
+ await generatePage(opts, internals, pageData, ssrEntry);
57
+ }
58
+ }
59
+ async function generatePage(opts, internals, pageData, ssrEntry) {
60
+ let timeStart = performance.now();
61
+ const renderers = ssrEntry.renderers;
62
+ const pageInfo = getPageDataByComponent(internals, pageData.route.component);
63
+ const linkIds = Array.from((pageInfo == null ? void 0 : pageInfo.css) ?? []);
64
+ const hoistedId = (pageInfo == null ? void 0 : pageInfo.hoistedScript) ?? null;
65
+ const pageModule = ssrEntry.pageMap.get(pageData.component);
66
+ if (!pageModule) {
67
+ throw new Error(`Unable to find the module for ${pageData.component}. This is unexpected and likely a bug in Astro, please report.`);
68
+ }
69
+ const generationOptions = {
70
+ pageData,
71
+ internals,
72
+ linkIds,
73
+ hoistedId,
74
+ mod: pageModule,
75
+ renderers
76
+ };
77
+ const icon = pageData.route.type === "page" ? cyan("</>") : magenta("{-}");
78
+ info(opts.logging, null, `${icon} ${pageData.route.component}`);
79
+ const renderPromises = [];
80
+ for (const paths of throttle(MAX_CONCURRENT_RENDERS, pageData.paths)) {
81
+ for (const path of paths) {
82
+ renderPromises.push(generatePath(path, opts, generationOptions));
83
+ }
84
+ await Promise.all(renderPromises);
85
+ const timeEnd = performance.now();
86
+ const timeChange = getTimeStat(timeStart, timeEnd);
87
+ let shouldLogTimeChange = !getTimeStat(timeStart, timeEnd).startsWith("0");
88
+ for (const path of paths) {
89
+ const timeIncrease = shouldLogTimeChange ? ` ${dim(`+${timeChange}`)}` : "";
90
+ info(opts.logging, null, ` ${dim("\u2503")} ${path}${timeIncrease}`);
91
+ shouldLogTimeChange = false;
92
+ }
93
+ timeStart = performance.now();
94
+ renderPromises.length = 0;
95
+ }
96
+ }
97
+ function addPageName(pathname, opts) {
98
+ opts.pageNames.push(pathname.replace(/\/?$/, "/").replace(/^\//, ""));
99
+ }
100
+ async function generatePath(pathname, opts, gopts) {
101
+ const { astroConfig, logging, origin, routeCache } = opts;
102
+ const { mod, internals, linkIds, hoistedId, pageData, renderers } = gopts;
103
+ if (pageData.route.type === "page") {
104
+ addPageName(pathname, opts);
105
+ }
106
+ debug("build", `Generating: ${pathname}`);
107
+ const site = astroConfig.buildOptions.site;
108
+ const links = createLinkStylesheetElementSet(linkIds.reverse(), site);
109
+ const scripts = createModuleScriptElementWithSrcSet(hoistedId ? [hoistedId] : [], site);
110
+ for (const script of astroConfig._ctx.scripts) {
111
+ if (script.stage === "head-inline") {
112
+ scripts.add({
113
+ props: {},
114
+ children: script.content
115
+ });
116
+ }
117
+ }
118
+ try {
119
+ const options = {
120
+ legacyBuild: false,
121
+ links,
122
+ logging,
123
+ markdownRender: astroConfig.markdownOptions.render,
124
+ mod,
125
+ origin,
126
+ pathname,
127
+ scripts,
128
+ renderers,
129
+ async resolve(specifier) {
130
+ const hashedFilePath = internals.entrySpecifierToBundleMap.get(specifier);
131
+ if (typeof hashedFilePath !== "string") {
132
+ if (specifier === BEFORE_HYDRATION_SCRIPT_ID) {
133
+ return "data:text/javascript;charset=utf-8,//[no before-hydration script]";
134
+ }
135
+ throw new Error(`Cannot find the built path for ${specifier}`);
136
+ }
137
+ const relPath = npath.posix.relative(pathname, "/" + hashedFilePath);
138
+ const fullyRelativePath = relPath[0] === "." ? relPath : "./" + relPath;
139
+ return fullyRelativePath;
140
+ },
141
+ method: "GET",
142
+ headers: new Headers(),
143
+ route: pageData.route,
144
+ routeCache,
145
+ site: astroConfig.buildOptions.site,
146
+ ssr: opts.astroConfig.buildOptions.experimentalSsr
147
+ };
148
+ let body;
149
+ if (pageData.route.type === "endpoint") {
150
+ const result = await callEndpoint(mod, options);
151
+ if (result.type === "response") {
152
+ throw new Error(`Returning a Response from an endpoint is not supported in SSG mode.`);
153
+ }
154
+ body = result.body;
155
+ } else {
156
+ const result = await render(options);
157
+ if (result.type !== "html") {
158
+ return;
159
+ }
160
+ body = result.html;
161
+ }
162
+ const outFolder = getOutFolder(astroConfig, pathname, pageData.route.type);
163
+ const outFile = getOutFile(astroConfig, outFolder, pathname, pageData.route.type);
164
+ await fs.promises.mkdir(outFolder, { recursive: true });
165
+ await fs.promises.writeFile(outFile, body, "utf-8");
166
+ } catch (err) {
167
+ error(opts.logging, "build", `Error rendering:`, err);
168
+ }
169
+ }
170
+ export {
171
+ chunkIsPage,
172
+ generatePages,
173
+ rootRelativeFacadeId
174
+ };
@@ -12,6 +12,7 @@ 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
14
  import { runHookBuildDone, runHookBuildStart, runHookConfigDone, runHookConfigSetup } from "../../integrations/index.js";
15
+ import { getTimeStat } from "./util.js";
15
16
  async function build(config, options = { logging: defaultLogOptions }) {
16
17
  const builder = new AstroBuilder(config, options);
17
18
  await builder.build();
@@ -33,6 +34,7 @@ class AstroBuilder {
33
34
  this.manifest = createRouteManifest({ config }, this.logging);
34
35
  }
35
36
  async build() {
37
+ info(this.logging, "build", "Initial setup...");
36
38
  const { logging, origin } = this;
37
39
  const timer = {};
38
40
  timer.init = performance.now();
@@ -50,7 +52,9 @@ class AstroBuilder {
50
52
  const viteServer = await vite.createServer(viteConfig);
51
53
  this.viteServer = viteServer;
52
54
  debug("build", timerMessage("Vite started", timer.viteStart));
53
- await runHookBuildStart({ config: this.config });
55
+ const buildConfig = { staticMode: void 0 };
56
+ await runHookBuildStart({ config: this.config, buildConfig });
57
+ info(this.logging, "build", "Collecting page data...");
54
58
  timer.loadStart = performance.now();
55
59
  const { assets, allPages } = await collectPagesData({
56
60
  astroConfig: this.config,
@@ -73,6 +77,7 @@ class AstroBuilder {
73
77
  debug("build", timerMessage("All pages loaded", timer.loadStart));
74
78
  const pageNames = [];
75
79
  timer.buildStart = performance.now();
80
+ info(this.logging, "build", colors.dim(`Completed in ${getTimeStat(timer.init, performance.now())}`));
76
81
  if (!this.config.buildOptions.legacyBuild) {
77
82
  await staticBuild({
78
83
  allPages,
@@ -82,7 +87,8 @@ class AstroBuilder {
82
87
  origin: this.origin,
83
88
  pageNames,
84
89
  routeCache: this.routeCache,
85
- viteConfig: this.viteConfig
90
+ viteConfig: this.viteConfig,
91
+ buildConfig
86
92
  });
87
93
  } else {
88
94
  await scanBasedBuild({
@@ -96,7 +102,6 @@ class AstroBuilder {
96
102
  viteServer: this.viteServer
97
103
  });
98
104
  }
99
- debug("build", timerMessage("Vite build finished", timer.buildStart));
100
105
  timer.assetsStart = performance.now();
101
106
  Object.keys(assets).map((k) => {
102
107
  if (!assets[k])
@@ -119,14 +124,22 @@ class AstroBuilder {
119
124
  await viteServer.close();
120
125
  await runHookBuildDone({ config: this.config, pages: pageNames });
121
126
  if (logging.level && levels[logging.level] <= levels["info"]) {
122
- await this.printStats({ logging, timeStart: timer.init, pageCount: pageNames.length });
127
+ const buildMode = this.config.buildOptions.experimentalSsr ? "ssr" : "static";
128
+ await this.printStats({ logging, timeStart: timer.init, pageCount: pageNames.length, buildMode });
123
129
  }
124
130
  }
125
- async printStats({ logging, timeStart, pageCount }) {
131
+ async printStats({ logging, timeStart, pageCount, buildMode }) {
126
132
  const buildTime = performance.now() - timeStart;
127
- const total = buildTime < 750 ? `${Math.round(buildTime)}ms` : `${(buildTime / 1e3).toFixed(2)}s`;
128
- const perPage = `${Math.round(buildTime / pageCount)}ms`;
129
- info(logging, "build", `${pageCount} pages built in ${colors.bold(total)} ${colors.dim(`(${perPage}/page)`)}`);
133
+ const total = getTimeStat(timeStart, performance.now());
134
+ let messages = [];
135
+ if (buildMode === "static") {
136
+ const timePerPage = Math.round(buildTime / pageCount);
137
+ const perPageMsg = colors.dim(`(${colors.bold(`${timePerPage}ms`)} avg per page + resources)`);
138
+ messages = [`${pageCount} pages built in`, colors.bold(total), perPageMsg];
139
+ } else {
140
+ messages = ["Server built in", colors.bold(total)];
141
+ }
142
+ info(logging, "build", messages.join(" "));
130
143
  info(logging, "build", `\u{1F680} ${colors.cyan(colors.bold("Done"))}`);
131
144
  }
132
145
  }