elegance-js 2.1.37 → 3.0.1

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 (138) hide show
  1. package/README.md +90 -4
  2. package/bin/bootstrap.js +18 -0
  3. package/bin/run.js +2 -0
  4. package/dist/build/common.d.ts +147 -0
  5. package/dist/build/common.d.ts.map +1 -0
  6. package/dist/build/common.js +599 -0
  7. package/dist/build/dev.d.ts +2 -0
  8. package/dist/build/dev.d.ts.map +1 -0
  9. package/dist/build/dev.js +234 -0
  10. package/dist/build/prod.d.ts +2 -0
  11. package/dist/build/prod.d.ts.map +1 -0
  12. package/dist/build/prod.js +212 -0
  13. package/dist/build/render.d.ts +29 -0
  14. package/dist/build/render.d.ts.map +1 -0
  15. package/dist/build/render.js +234 -0
  16. package/dist/client.d.ts +13 -0
  17. package/dist/client.d.ts.map +1 -0
  18. package/dist/client.js +677 -0
  19. package/dist/config.d.ts +7 -0
  20. package/dist/config.d.ts.map +1 -0
  21. package/dist/config.js +80 -0
  22. package/dist/constants.d.ts +10 -0
  23. package/dist/constants.d.ts.map +1 -0
  24. package/dist/constants.js +20 -0
  25. package/dist/elements.d.ts +2 -0
  26. package/dist/elements.d.ts.map +1 -0
  27. package/dist/elements.js +14 -0
  28. package/dist/error.d.ts +20 -0
  29. package/dist/error.d.ts.map +1 -0
  30. package/dist/error.js +123 -0
  31. package/dist/globals.d.ts +6 -0
  32. package/dist/globals.d.ts.map +1 -0
  33. package/dist/globals.js +106 -0
  34. package/dist/logger.d.ts +32 -0
  35. package/dist/logger.d.ts.map +1 -0
  36. package/dist/logger.js +72 -0
  37. package/dist/page-tools.d.ts +19 -0
  38. package/dist/page-tools.d.ts.map +1 -0
  39. package/dist/page-tools.js +141 -0
  40. package/dist/processing/oxc.d.ts +17 -0
  41. package/dist/processing/oxc.d.ts.map +1 -0
  42. package/dist/processing/oxc.js +938 -0
  43. package/dist/processing/taglist.d.ts +2 -0
  44. package/dist/processing/taglist.d.ts.map +1 -0
  45. package/dist/processing/taglist.js +215 -0
  46. package/dist/processing/tsx.d.ts +2 -0
  47. package/dist/processing/tsx.d.ts.map +1 -0
  48. package/dist/processing/tsx.js +131 -0
  49. package/dist/run.d.ts +3 -0
  50. package/dist/run.d.ts.map +1 -0
  51. package/dist/run.js +147 -0
  52. package/dist/server/dev.d.ts +2 -0
  53. package/dist/server/dev.d.ts.map +1 -0
  54. package/dist/server/dev.js +10 -0
  55. package/dist/server/prod.d.ts +2 -0
  56. package/dist/server/prod.d.ts.map +1 -0
  57. package/dist/server/prod.js +42 -0
  58. package/dist/server/security.d.ts +64 -0
  59. package/dist/server/security.d.ts.map +1 -0
  60. package/dist/server/security.js +120 -0
  61. package/dist/server/server.d.ts +73 -99
  62. package/dist/server/server.d.ts.map +1 -0
  63. package/dist/server/server.js +830 -680
  64. package/dist/types/component.d.ts +85 -0
  65. package/dist/types/component.d.ts.map +1 -0
  66. package/dist/types/component.js +0 -0
  67. package/dist/types/config.d.ts +12 -0
  68. package/dist/types/config.d.ts.map +1 -0
  69. package/dist/types/config.js +0 -0
  70. package/dist/types/elements.d.ts +412 -0
  71. package/dist/types/elements.d.ts.map +1 -0
  72. package/dist/types/elements.js +0 -0
  73. package/dist/types/index.d.ts +9 -0
  74. package/dist/types/index.d.ts.map +1 -0
  75. package/dist/types/index.js +5 -0
  76. package/dist/types/jsx.d.ts +976 -0
  77. package/dist/types/jsx.d.ts.map +1 -0
  78. package/dist/types/jsx.js +0 -0
  79. package/dist/types/server-actions.d.ts +60 -0
  80. package/dist/types/server-actions.d.ts.map +1 -0
  81. package/dist/types/server-actions.js +0 -0
  82. package/dist/user-utils.d.ts +23 -0
  83. package/dist/user-utils.d.ts.map +1 -0
  84. package/dist/user-utils.js +61 -0
  85. package/package.json +48 -27
  86. package/dist/client/effect.d.ts +0 -27
  87. package/dist/client/effect.js +0 -37
  88. package/dist/client/eventListener.d.ts +0 -39
  89. package/dist/client/eventListener.js +0 -52
  90. package/dist/client/loadHook.d.ts +0 -34
  91. package/dist/client/loadHook.js +0 -52
  92. package/dist/client/observer.d.ts +0 -36
  93. package/dist/client/observer.js +0 -66
  94. package/dist/client/runtime.d.ts +0 -105
  95. package/dist/client/runtime.js +0 -624
  96. package/dist/client/state.d.ts +0 -40
  97. package/dist/client/state.js +0 -110
  98. package/dist/compilation/compiler.d.ts +0 -163
  99. package/dist/compilation/compiler.js +0 -1164
  100. package/dist/components/ClientComponent.d.ts +0 -22
  101. package/dist/components/ClientComponent.js +0 -55
  102. package/dist/components/Link.d.ts +0 -16
  103. package/dist/components/Link.js +0 -21
  104. package/dist/components/Portal.d.ts +0 -2
  105. package/dist/components/Portal.js +0 -2
  106. package/dist/elements/element.d.ts +0 -87
  107. package/dist/elements/element.js +0 -33
  108. package/dist/elements/element_list.d.ts +0 -7
  109. package/dist/elements/element_list.js +0 -65
  110. package/dist/elements/raw.d.ts +0 -14
  111. package/dist/elements/raw.js +0 -78
  112. package/dist/elements/specific_props.d.ts +0 -750
  113. package/dist/elements/specific_props.js +0 -1
  114. package/dist/global.d.ts +0 -229
  115. package/dist/global.js +0 -1
  116. package/dist/index.d.ts +0 -16
  117. package/dist/index.js +0 -12
  118. package/dist/server/layout.d.ts +0 -34
  119. package/dist/server/layout.js +0 -6
  120. package/dist/server/log.d.ts +0 -12
  121. package/dist/server/log.js +0 -64
  122. package/dist/server/page.d.ts +0 -32
  123. package/dist/server/page.js +0 -6
  124. package/dist/server/runtime.d.ts +0 -6
  125. package/dist/server/runtime.js +0 -92
  126. package/scripts/bootstrap.js +0 -95
  127. package/scripts/bootstrap_files/elegance.txt +0 -40
  128. package/scripts/bootstrap_files/index.txt +0 -3
  129. package/scripts/bootstrap_files/layout.txt +0 -46
  130. package/scripts/bootstrap_files/middleware.txt +0 -18
  131. package/scripts/bootstrap_files/page.txt +0 -123
  132. package/scripts/bootstrap_files/route.txt +0 -6
  133. package/scripts/elegance_dev.ts +0 -42
  134. package/scripts/elegance_prod.ts +0 -42
  135. package/scripts/elegance_static.ts +0 -26
  136. package/scripts/prod.js +0 -13
  137. package/scripts/run.js +0 -13
  138. package/scripts/static.js +0 -13
@@ -0,0 +1,234 @@
1
+ import { getPageRoutes } from "../page-tools.js";
2
+ import { rm, mkdir, writeFile, readFile, unlink } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { performance } from "node:perf_hooks";
5
+ import { c, logger } from "../logger.js";
6
+ import { OUT_DIR, DIST_DIR, CACHE_DIR, PAGES_DIR, loadPaths } from "../constants.js";
7
+ import {
8
+ transpileAllRoutes,
9
+ buildClientRuntime,
10
+ copyPublicDir,
11
+ copyPublicDirIncremental,
12
+ findAndCacheStatusCodePages,
13
+ discoverApiRoutes,
14
+ discoverMiddlewares,
15
+ computeFileHash,
16
+ loadIncrementalState,
17
+ saveIncrementalState,
18
+ loadRouteFromCache,
19
+ pageCacheKey,
20
+ layoutFileCacheKey
21
+ } from "./common.js";
22
+ import { existsSync } from "node:fs";
23
+ import { isRichError, printError, richError } from "../error.js";
24
+ const PUBLIC_DIR = join(process.cwd(), "public");
25
+ const IS_INCREMENTAL = process.env.ELEGANCE_BUILD_MODE === "incremental";
26
+ const SLUG_PATTERN = /\[([^\]]+)\]/;
27
+ async function buildDevAll() {
28
+ logger.info(`Beginning build.. (${IS_INCREMENTAL ? "incremental" : "full"})`);
29
+ const start = performance.now();
30
+ if (existsSync(PAGES_DIR) === false) {
31
+ logger.warn("config.pagesDirectory did not exist, it will be created.");
32
+ await mkdir(PAGES_DIR, { recursive: true });
33
+ }
34
+ if (IS_INCREMENTAL) {
35
+ await rm(DIST_DIR, { recursive: true, force: true });
36
+ await mkdir(DIST_DIR, { recursive: true });
37
+ await mkdir(CACHE_DIR, { recursive: true });
38
+ await copyPublicDirIncremental(PUBLIC_DIR);
39
+ await buildClientRuntime(false);
40
+ } else {
41
+ await rm(OUT_DIR, { recursive: true, force: true });
42
+ await mkdir(OUT_DIR, { recursive: true });
43
+ await mkdir(DIST_DIR, { recursive: true });
44
+ await mkdir(CACHE_DIR, { recursive: true });
45
+ await copyPublicDir(PUBLIC_DIR);
46
+ await buildClientRuntime(false);
47
+ }
48
+ const allRoutes = await getPageRoutes(PAGES_DIR);
49
+ if (IS_INCREMENTAL) {
50
+ await pruneStaleOutputs(allRoutes.map((r) => r.pageFile));
51
+ }
52
+ for (const route of allRoutes) {
53
+ if (!route.isDynamic && SLUG_PATTERN.test(route.pathname)) {
54
+ printError(richError({
55
+ title: "Missing Enumerations",
56
+ cause: `Route ${route.pathname} is marked as a [slug] route, and is currently set to isDynamic = false.For a [slug] route to be static, it must export getEnumeratedRoutes(); so that all possible paths can be generated statically.`,
57
+ origin: route.pathname,
58
+ doShowStack: false
59
+ }));
60
+ process.exit(1);
61
+ }
62
+ }
63
+ const prevState = IS_INCREMENTAL ? await loadIncrementalState() : { fileHashes: {}, clientCodeHashes: {} };
64
+ const nextFileHashes = {};
65
+ const skipServerKeys = /* @__PURE__ */ new Set();
66
+ const unchangedPathnames = /* @__PURE__ */ new Set();
67
+ const allFiles = /* @__PURE__ */ new Set();
68
+ for (const route of allRoutes) {
69
+ allFiles.add(route.pageFile);
70
+ for (const l of route.layouts) allFiles.add(l);
71
+ }
72
+ await Promise.all([...allFiles].map(async (f) => {
73
+ nextFileHashes[f] = await computeFileHash(f);
74
+ }));
75
+ if (IS_INCREMENTAL) {
76
+ for (const route of allRoutes) {
77
+ const key = pageCacheKey(route.pathname);
78
+ const pageChanged = nextFileHashes[route.pageFile] !== prevState.fileHashes[route.pageFile];
79
+ const layoutChanged = route.layouts.some((l) => nextFileHashes[l] !== prevState.fileHashes[l]);
80
+ if (!pageChanged && !layoutChanged && existsSync(join(CACHE_DIR, `${key}.server.mjs`))) {
81
+ skipServerKeys.add(key);
82
+ unchangedPathnames.add(route.pathname);
83
+ for (const l of route.layouts) {
84
+ const lk = layoutFileCacheKey(l);
85
+ if (existsSync(join(CACHE_DIR, `${lk}.server.mjs`)))
86
+ skipServerKeys.add(lk);
87
+ }
88
+ }
89
+ }
90
+ }
91
+ const transpiled = await transpileAllRoutes(allRoutes, false, skipServerKeys);
92
+ let prevManifest = null;
93
+ if (IS_INCREMENTAL) {
94
+ try {
95
+ prevManifest = JSON.parse(await readFile(join(OUT_DIR, "paths.json"), "utf-8"));
96
+ } catch {
97
+ }
98
+ }
99
+ const manifestRoutes = [];
100
+ for (const route of allRoutes) {
101
+ const t = transpiled.get(route.pathname);
102
+ if (!t) {
103
+ printError(richError({
104
+ title: "No transpilation result",
105
+ cause: "This is an internal error within Elegance, please report it.",
106
+ doShowStack: false
107
+ }));
108
+ process.exit(1);
109
+ }
110
+ const key = pageCacheKey(t.pathname);
111
+ const layoutKeys = t.layouts.map(layoutFileCacheKey);
112
+ const sharedChunks = t.sharedChunkPaths;
113
+ if (!route.isDynamic) {
114
+ manifestRoutes.push({
115
+ kind: "static",
116
+ pathname: route.pathname,
117
+ pageFile: route.pageFile,
118
+ layouts: route.layouts,
119
+ layoutCacheKeys: layoutKeys,
120
+ cacheKey: key,
121
+ sharedChunkPaths: sharedChunks
122
+ });
123
+ continue;
124
+ }
125
+ const mod = await loadRouteFromCache({
126
+ pageFile: route.pageFile,
127
+ layouts: route.layouts,
128
+ layoutCacheKeys: layoutKeys,
129
+ cacheKey: key,
130
+ pathname: route.pathname
131
+ });
132
+ if (!mod.getEnumeratedRoutes) {
133
+ if (unchangedPathnames.has(route.pathname) && prevManifest) {
134
+ const prevEntry = prevManifest.routes.find((r) => r.pathname === route.pathname);
135
+ if (prevEntry) {
136
+ manifestRoutes.push(prevEntry);
137
+ continue;
138
+ }
139
+ }
140
+ manifestRoutes.push({
141
+ kind: "dynamic",
142
+ pathname: route.pathname,
143
+ pageFile: route.pageFile,
144
+ layouts: route.layouts,
145
+ layoutCacheKeys: layoutKeys,
146
+ cacheKey: key,
147
+ sharedChunkPaths: sharedChunks
148
+ });
149
+ continue;
150
+ }
151
+ const slugs = await mod.getEnumeratedRoutes();
152
+ const freshPaths = new Set(slugs.map((slug) => route.pathname.replace(/\[([^\]]+)\]/g, slug)));
153
+ if (IS_INCREMENTAL && prevManifest) {
154
+ const prevEnumerated = prevManifest.routes.filter(
155
+ (r) => r.kind === "enumerated" && r.patternPathname === route.pathname
156
+ );
157
+ await Promise.all(
158
+ prevEnumerated.filter((r) => !freshPaths.has(r.pathname)).map((r) => {
159
+ const dir = r.pathname === "/" ? DIST_DIR : join(DIST_DIR, r.pathname);
160
+ return Promise.all([
161
+ unlink(join(dir, "index.html")).catch(() => {
162
+ }),
163
+ unlink(join(dir, "bundle.js")).catch(() => {
164
+ })
165
+ ]);
166
+ })
167
+ );
168
+ }
169
+ for (const slug of slugs) {
170
+ const concretePath = route.pathname.replace(/\[([^\]]+)\]/g, slug);
171
+ manifestRoutes.push({
172
+ kind: "enumerated",
173
+ pathname: concretePath,
174
+ patternPathname: route.pathname,
175
+ pageFile: route.pageFile,
176
+ layouts: route.layouts,
177
+ layoutCacheKeys: layoutKeys,
178
+ cacheKey: key,
179
+ sharedChunkPaths: sharedChunks
180
+ });
181
+ }
182
+ }
183
+ const [statusCodePages, apiRoutes, middlewares] = await Promise.all([
184
+ findAndCacheStatusCodePages(),
185
+ discoverApiRoutes(PAGES_DIR),
186
+ discoverMiddlewares(PAGES_DIR)
187
+ ]);
188
+ const manifest = {
189
+ buildTime: Date.now(),
190
+ routes: manifestRoutes,
191
+ statusCodePages,
192
+ apiRoutes,
193
+ middlewares
194
+ };
195
+ await writeFile(join(OUT_DIR, "paths.json"), JSON.stringify(manifest, null, 2));
196
+ await saveIncrementalState({ fileHashes: nextFileHashes, clientCodeHashes: {} });
197
+ await rm(join(process.cwd(), ".temp"), { recursive: true, force: true }).catch(() => {
198
+ });
199
+ logger.debug(`Built in ${c.dim}${(performance.now() - start).toFixed(1)}ms${c.reset}`);
200
+ }
201
+ async function pruneStaleOutputs(livePageFiles) {
202
+ let prev;
203
+ try {
204
+ prev = JSON.parse(await readFile(join(OUT_DIR, "paths.json"), "utf-8"));
205
+ } catch {
206
+ return;
207
+ }
208
+ const live = new Set(livePageFiles);
209
+ const removals = [];
210
+ for (const entry of prev.routes) {
211
+ if (live.has(entry.pageFile)) continue;
212
+ const dir = entry.pathname === "/" ? DIST_DIR : join(DIST_DIR, entry.pathname);
213
+ removals.push(unlink(join(dir, "index.html")).catch(() => {
214
+ }));
215
+ removals.push(unlink(join(dir, "bundle.js")).catch(() => {
216
+ }));
217
+ }
218
+ if (removals.length === 0) return;
219
+ await Promise.all(removals);
220
+ }
221
+ (async () => {
222
+ await loadPaths();
223
+ try {
224
+ await buildDevAll();
225
+ process.exit(0);
226
+ } catch (err) {
227
+ if (isRichError(err)) {
228
+ printError(err);
229
+ } else {
230
+ console.error(err);
231
+ }
232
+ process.exit(1);
233
+ }
234
+ })();
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=prod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prod.d.ts","sourceRoot":"","sources":["../../src/build/prod.ts"],"names":[],"mappings":""}
@@ -0,0 +1,212 @@
1
+ import { getPageRoutes } from "../page-tools.js";
2
+ import { generateSyntheticBundle } from "../processing/oxc.js";
3
+ import { generatePageHTML, createRenderContext, runWithRenderContext } from "./render.js";
4
+ import { rm, mkdir, writeFile, readFile } from "node:fs/promises";
5
+ import { join } from "node:path";
6
+ import { logger } from "../logger.js";
7
+ import { OUT_DIR, DIST_DIR, CACHE_DIR, PAGES_DIR, loadPaths } from "../constants.js";
8
+ import {
9
+ transpileAllRoutes,
10
+ loadRouteFromCache,
11
+ buildClientRuntime,
12
+ copyPublicDir,
13
+ findAndCacheStatusCodePages,
14
+ discoverApiRoutes,
15
+ discoverMiddlewares,
16
+ runBuildHooks,
17
+ minifyHtml,
18
+ minifyCode,
19
+ getSlugParamName,
20
+ fileHasExports,
21
+ layoutFileCacheKey,
22
+ pageCacheKey,
23
+ preClientMjsPath
24
+ } from "./common.js";
25
+ import { existsSync } from "node:fs";
26
+ import { isRichError, printError, richError } from "../error.js";
27
+ const PUBLIC_DIR = join(process.cwd(), "public");
28
+ async function buildStaticTasks(tasks) {
29
+ logger.info(`Building ${tasks.length} static route${tasks.length === 1 ? "" : "s"}`);
30
+ let built = 0;
31
+ await Promise.all(tasks.map(async ({ route, transpiled, layoutCacheKeys, cacheKey, params, outPathname }) => {
32
+ if (await fileHasExports(route.pageFile) === false) {
33
+ throw richError({
34
+ title: "Empty Page",
35
+ cause: "Empty pages are not allowed in production builds.",
36
+ hint: "Try removing the file, or write a page there.",
37
+ doShowStack: false
38
+ });
39
+ }
40
+ logger.info(` > ${outPathname}`);
41
+ const compiled = await loadRouteFromCache({
42
+ pageFile: route.pageFile,
43
+ layouts: route.layouts,
44
+ layoutCacheKeys,
45
+ cacheKey,
46
+ pathname: outPathname
47
+ });
48
+ const ctx = createRenderContext();
49
+ for (const { id, initial } of compiled.atomSeeds) {
50
+ if (!ctx.atomValues.has(id)) {
51
+ ctx.atomValues.set(id, initial);
52
+ ctx.atomRegistry.push({ id });
53
+ }
54
+ }
55
+ const routeOutDir = outPathname === "/" ? DIST_DIR : join(DIST_DIR, outPathname);
56
+ try {
57
+ await runWithRenderContext(ctx, async () => {
58
+ await runBuildHooks(compiled, "pre");
59
+ const rootNode = await compiled.default(params);
60
+ const metaNodes = await compiled.metadata(params);
61
+ const bundleUrl = `${outPathname === "/" ? "" : outPathname}/bundle.js`;
62
+ const { fullHtml } = await generatePageHTML(
63
+ rootNode,
64
+ metaNodes,
65
+ { ...route, pathname: outPathname },
66
+ bundleUrl,
67
+ ctx,
68
+ transpiled.sharedChunkPaths
69
+ );
70
+ const preClientCode = await readFile(preClientMjsPath(pageCacheKey(transpiled.pathname)), "utf-8");
71
+ const syntheticCode = generateSyntheticBundle(preClientCode, outPathname, ctx.regions, layoutCacheKeys);
72
+ const finalClientCode = await minifyCode(syntheticCode);
73
+ await mkdir(routeOutDir, { recursive: true });
74
+ await writeFile(join(routeOutDir, "bundle.js"), finalClientCode);
75
+ await writeFile(join(routeOutDir, "index.html"), minifyHtml(fullHtml));
76
+ await runBuildHooks(compiled, "post");
77
+ });
78
+ built++;
79
+ } catch (err) {
80
+ if (isRichError(err)) {
81
+ throw err;
82
+ }
83
+ throw richError({
84
+ title: "Failed to Render Route",
85
+ cause: err,
86
+ origin: route.pageFile,
87
+ doShowStack: true
88
+ });
89
+ }
90
+ }));
91
+ }
92
+ async function buildProdAll() {
93
+ logger.info("Beginning production build...");
94
+ if (existsSync(PAGES_DIR) === false) {
95
+ printError(richError({
96
+ title: "Missing pagesDirectory",
97
+ cause: `config.pagesDirectory ${PAGES_DIR} does not exist. This is most likely due to a malformed configuration. Please create the directory and try again.`,
98
+ doShowStack: false
99
+ }));
100
+ process.exit(1);
101
+ }
102
+ await rm(OUT_DIR, { recursive: true, force: true });
103
+ await mkdir(OUT_DIR, { recursive: true });
104
+ await mkdir(DIST_DIR, { recursive: true });
105
+ await mkdir(CACHE_DIR, { recursive: true });
106
+ await copyPublicDir(PUBLIC_DIR);
107
+ await buildClientRuntime(true);
108
+ const allRoutes = await getPageRoutes(PAGES_DIR);
109
+ const splitMap = await transpileAllRoutes(allRoutes, true);
110
+ const staticTasks = [];
111
+ const manifestRoutes = [];
112
+ for (const route of allRoutes) {
113
+ const transpiled = splitMap.get(route.pathname);
114
+ if (!transpiled) {
115
+ printError(richError({
116
+ title: "No transpilation result",
117
+ cause: "This is an internal error within Elegance, please report it.",
118
+ doShowStack: false
119
+ }));
120
+ process.exit(1);
121
+ }
122
+ const cacheKey = pageCacheKey(transpiled.pathname);
123
+ const layoutKeys = transpiled.layouts.map(layoutFileCacheKey);
124
+ if (!route.isDynamic) {
125
+ staticTasks.push({ route, transpiled, layoutCacheKeys: layoutKeys, cacheKey, params: {}, outPathname: route.pathname });
126
+ manifestRoutes.push({
127
+ pathname: route.pathname,
128
+ kind: "static",
129
+ pageFile: route.pageFile,
130
+ layoutCacheKeys: layoutKeys,
131
+ layouts: route.layouts,
132
+ sharedChunkPaths: transpiled.sharedChunkPaths,
133
+ cacheKey
134
+ });
135
+ continue;
136
+ }
137
+ const compiled = await loadRouteFromCache({
138
+ pageFile: route.pageFile,
139
+ layouts: route.layouts,
140
+ layoutCacheKeys: layoutKeys,
141
+ cacheKey,
142
+ pathname: route.pathname
143
+ });
144
+ if (!compiled.getEnumeratedRoutes) {
145
+ manifestRoutes.push({
146
+ pathname: route.pathname,
147
+ kind: "dynamic",
148
+ pageFile: route.pageFile,
149
+ layouts: route.layouts,
150
+ layoutCacheKeys: layoutKeys,
151
+ cacheKey,
152
+ sharedChunkPaths: transpiled.sharedChunkPaths
153
+ });
154
+ continue;
155
+ }
156
+ const rawSlugs = await compiled.getEnumeratedRoutes();
157
+ for (const slug of rawSlugs) {
158
+ const concretePath = route.pathname.replace(/\[([^\]]+)\]/g, slug);
159
+ staticTasks.push({
160
+ route,
161
+ transpiled,
162
+ layoutCacheKeys: layoutKeys,
163
+ cacheKey,
164
+ //params: { [getSlugParamName(route.pathname)]: slug },
165
+ params: { [getSlugParamName(route.pathname)]: slug.split("/") },
166
+ outPathname: concretePath
167
+ });
168
+ manifestRoutes.push({
169
+ pathname: concretePath,
170
+ kind: "enumerated",
171
+ pageFile: route.pageFile,
172
+ layouts: route.layouts,
173
+ layoutCacheKeys: layoutKeys,
174
+ cacheKey,
175
+ sharedChunkPaths: transpiled.sharedChunkPaths,
176
+ patternPathname: route.pathname
177
+ });
178
+ }
179
+ }
180
+ if (staticTasks.length > 0) {
181
+ await buildStaticTasks(staticTasks);
182
+ }
183
+ const [statusCodePages, apiRoutes, middlewares] = await Promise.all([
184
+ findAndCacheStatusCodePages(),
185
+ discoverApiRoutes(PAGES_DIR),
186
+ discoverMiddlewares(PAGES_DIR)
187
+ ]);
188
+ const manifest = {
189
+ buildTime: Date.now(),
190
+ routes: manifestRoutes,
191
+ statusCodePages,
192
+ apiRoutes,
193
+ middlewares
194
+ };
195
+ await writeFile(join(OUT_DIR, "paths.json"), JSON.stringify(manifest, null, 2));
196
+ await rm(join(process.cwd(), ".temp"), { recursive: true, force: true }).catch(() => {
197
+ });
198
+ }
199
+ (async () => {
200
+ await loadPaths();
201
+ try {
202
+ await buildProdAll();
203
+ process.exit(0);
204
+ } catch (err) {
205
+ if (isRichError(err)) {
206
+ printError(err);
207
+ } else {
208
+ console.error(err);
209
+ }
210
+ process.exit(1);
211
+ }
212
+ })();
@@ -0,0 +1,29 @@
1
+ import type { RouteInfo } from "../page-tools";
2
+ import { AsyncLocalStorage } from "node:async_hooks";
3
+ export interface RenderContext {
4
+ atomValues: Map<string, any>;
5
+ atomRegistry: Array<{
6
+ id: string;
7
+ }>;
8
+ regions: Array<any[]>;
9
+ regionCounter: number;
10
+ insideComponentDepth: number;
11
+ }
12
+ export declare const renderContextStorage: AsyncLocalStorage<RenderContext>;
13
+ export declare function createRenderContext(): RenderContext;
14
+ export declare function runWithRenderContext<T>(ctx: RenderContext, fn: () => Promise<T>): Promise<T>;
15
+ export declare function getAtomSnapshot(ctx: RenderContext): Record<string, any>;
16
+ export interface HtmlSink {
17
+ append(s: string): void;
18
+ }
19
+ export declare class HtmlBuilder implements HtmlSink {
20
+ private parts;
21
+ append(s: string): void;
22
+ join(): string;
23
+ }
24
+ export interface GeneratePageHtmlResult {
25
+ fullHtml: string;
26
+ }
27
+ export declare function generatePageHTML(pageRoot: VirtualNode, metaNodes: VirtualNode[], route: RouteInfo, bundleSrc: string, ctx: RenderContext, extraScripts?: string[]): Promise<GeneratePageHtmlResult>;
28
+ export declare function generateDynamicPageHTML(pageRoot: VirtualNode, metaNodes: VirtualNode[], route: RouteInfo, getClientCode: () => string, ctx: RenderContext): Promise<string>;
29
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/build/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAIrD,MAAM,WAAW,aAAa;IAC1B,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,YAAY,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpC,OAAO,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB,EAAE,MAAM,CAAC;CAChC;AAED,eAAO,MAAM,oBAAoB,kCAAyC,CAAC;AAE3E,wBAAgB,mBAAmB,IAAI,aAAa,CAQnD;AAED,wBAAsB,oBAAoB,CAAC,CAAC,EACxC,GAAG,EAAE,aAAa,EAClB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,CAAC,CAAC,CAEZ;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAMvE;AAeD,MAAM,WAAW,QAAQ;IACrB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,qBAAa,WAAY,YAAW,QAAQ;IACxC,OAAO,CAAC,KAAK,CAAgB;IAC7B,MAAM,CAAC,CAAC,EAAE,MAAM;IAChB,IAAI,IAAI,MAAM;CACjB;AAED,MAAM,WAAW,sBAAsB;IACnC,QAAQ,EAAE,MAAM,CAAC;CACpB;AAED,wBAAsB,gBAAgB,CAClC,QAAQ,EAAE,WAAW,EACrB,SAAS,EAAE,WAAW,EAAE,EACxB,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,aAAa,EAClB,YAAY,CAAC,EAAE,MAAM,EAAE,GACxB,OAAO,CAAC,sBAAsB,CAAC,CAgCjC;AAED,wBAAsB,uBAAuB,CACzC,QAAQ,EAAE,WAAW,EACrB,SAAS,EAAE,WAAW,EAAE,EACxB,KAAK,EAAE,SAAS,EAChB,aAAa,EAAE,MAAM,MAAM,EAC3B,GAAG,EAAE,aAAa,GACnB,OAAO,CAAC,MAAM,CAAC,CA6BjB"}