one 1.1.399 → 1.1.401

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.
@@ -0,0 +1,114 @@
1
+ import FSExtra from "fs-extra";
2
+ import { join } from "node:path";
3
+ import * as constants from "../constants.mjs";
4
+ import { getLoaderPath, getPreloadPath } from "../utils/cleanUrl.mjs";
5
+ import { toAbsolute } from "../utils/toAbsolute.mjs";
6
+ import { replaceLoader } from "../vite/replaceLoader.mjs";
7
+ const {
8
+ readFile,
9
+ outputFile
10
+ } = FSExtra;
11
+ async function buildPage(serverEntry, path, relativeId, params, foundRoute, clientManifestEntry, staticDir, clientDir, builtMiddlewares, serverJsPath, preloads, allCSS) {
12
+ const render = await getRender(serverEntry),
13
+ htmlPath = `${path.endsWith("/") ? `${removeTrailingSlash(path)}/index` : path}.html`,
14
+ clientJsPath = join("dist/client", clientManifestEntry.file),
15
+ htmlOutPath = toAbsolute(join(staticDir, htmlPath)),
16
+ preloadPath = getPreloadPath(path);
17
+ let loaderData = {};
18
+ try {
19
+ await FSExtra.writeFile(join(clientDir, preloadPath), preloads.map(preload => `import "${preload}"`).join(`
20
+ `));
21
+ const exported = await import(toAbsolute(serverJsPath));
22
+ if (exported.loader) {
23
+ loaderData = (await exported.loader?.({
24
+ path,
25
+ params
26
+ })) ?? null;
27
+ const code = await readFile(clientJsPath, "utf-8"),
28
+ withLoader =
29
+ // super dirty to quickly make ssr loaders work until we have better
30
+ `
31
+ if (typeof document === 'undefined') globalThis.document = {}
32
+ ` + replaceLoader({
33
+ code,
34
+ loaderData
35
+ }),
36
+ loaderPartialPath = join(clientDir, getLoaderPath(path));
37
+ await outputFile(loaderPartialPath, withLoader);
38
+ }
39
+ if (foundRoute.type !== "ssr") {
40
+ const loaderProps = {
41
+ path,
42
+ params
43
+ };
44
+ if (globalThis.__vxrnresetState?.(), foundRoute.type === "ssg") {
45
+ const html = await render({
46
+ path,
47
+ preloads,
48
+ loaderProps,
49
+ loaderData,
50
+ css: allCSS,
51
+ mode: "ssg"
52
+ });
53
+ await outputFile(htmlOutPath, html);
54
+ } else foundRoute.type === "spa" && (await outputFile(htmlOutPath, `<html><head>
55
+ ${constants.getSpaHeaderElements({
56
+ serverContext: {
57
+ loaderProps,
58
+ loaderData
59
+ }
60
+ })}
61
+ ${preloads.map(preload => ` <script type="module" src="${preload}"></script>`).join(`
62
+ `)}
63
+ ${allCSS.map(file => ` <link rel="stylesheet" href=${file} />`).join(`
64
+ `)}
65
+ </head></html>`));
66
+ }
67
+ } catch (err) {
68
+ const errMsg = err instanceof Error ? `${err.message}
69
+ ${err.stack}` : `${err}`;
70
+ console.error(`Error building static page at ${path} with id ${relativeId}:
71
+
72
+ ${errMsg}
73
+
74
+ loaderData:
75
+
76
+ ${JSON.stringify(loaderData || null, null, 2)}
77
+ params:
78
+
79
+ ${JSON.stringify(params || null, null, 2)}`), console.error(err), process.exit(1);
80
+ }
81
+ const middlewares = (foundRoute.middlewares || []).map(x => builtMiddlewares[x.contextKey]),
82
+ cleanPath = path === "/" ? path : removeTrailingSlash(path);
83
+ return {
84
+ type: foundRoute.type,
85
+ routeFile: foundRoute.file,
86
+ middlewares,
87
+ cleanPath,
88
+ preloadPath,
89
+ clientJsPath,
90
+ serverJsPath,
91
+ htmlPath,
92
+ loaderData,
93
+ params,
94
+ path,
95
+ preloads
96
+ };
97
+ }
98
+ async function getRender(serverEntry) {
99
+ let render = null;
100
+ try {
101
+ const serverImport = await import(serverEntry);
102
+ render = serverImport.default.render ||
103
+ // for an unknown reason this is necessary
104
+ serverImport.default.default?.render, typeof render != "function" && (console.error("\u274C Error: didn't find render function in entry", serverImport), process.exit(1));
105
+ } catch (err) {
106
+ console.error("\u274C Error importing the root entry:"), console.error(` This error happened in the built file: ${serverEntry}`), console.error(err.stack), process.exit(1);
107
+ }
108
+ return render;
109
+ }
110
+ function removeTrailingSlash(path) {
111
+ return path.endsWith("/") ? path.slice(0, path.length - 1) : path;
112
+ }
113
+ export { buildPage };
114
+ //# sourceMappingURL=buildPage.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FSExtra","join","constants","getLoaderPath","getPreloadPath","toAbsolute","replaceLoader","readFile","outputFile","buildPage","serverEntry","path","relativeId","params","foundRoute","clientManifestEntry","staticDir","clientDir","builtMiddlewares","serverJsPath","preloads","allCSS","render","getRender","htmlPath","endsWith","removeTrailingSlash","clientJsPath","file","htmlOutPath","preloadPath","loaderData","writeFile","map","preload","exported","loader","code","withLoader","loaderPartialPath","type","loaderProps","globalThis","__vxrnresetState","html","css","mode","getSpaHeaderElements","serverContext","err","errMsg","Error","message","stack","console","error","JSON","stringify","process","exit","middlewares","x","contextKey","cleanPath","routeFile","serverImport","default","slice","length"],"sources":["../../../src/cli/buildPage.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAOA,OAAA,MAAa;AACpB,SAASC,IAAA,QAAY;AACrB,YAAYC,SAAA,MAAe;AAG3B,SAASC,aAAA,EAAeC,cAAA,QAAsB;AAC9C,SAASC,UAAA,QAAkB;AAC3B,SAASC,aAAA,QAAqB;AAG9B,MAAM;EAAEC,QAAA;EAAUC;AAAW,IAAIR,OAAA;AAEjC,eAAsBS,UACpBC,WAAA,EACAC,IAAA,EACAC,UAAA,EACAC,MAAA,EACAC,UAAA,EACAC,mBAAA,EACAC,SAAA,EACAC,SAAA,EACAC,gBAAA,EACAC,YAAA,EACAC,QAAA,EACAC,MAAA,EAC6B;EAC7B,MAAMC,MAAA,GAAS,MAAMC,SAAA,CAAUb,WAAW;IACpCc,QAAA,GAAW,GAAGb,IAAA,CAAKc,QAAA,CAAS,GAAG,IAAI,GAAGC,mBAAA,CAAoBf,IAAI,CAAC,WAAWA,IAAI;IAC9EgB,YAAA,GAAe1B,IAAA,CAAK,eAAec,mBAAA,CAAoBa,IAAI;IAC3DC,WAAA,GAAcxB,UAAA,CAAWJ,IAAA,CAAKe,SAAA,EAAWQ,QAAQ,CAAC;IAClDM,WAAA,GAAc1B,cAAA,CAAeO,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AAA;IACAF,IAAA;IACAS;EACF;AACF;AAEA,eAAeG,UAAUb,WAAA,EAAqB;EAC5C,IAAIY,MAAA,GAA2B;EAE/B,IAAI;IACF,MAAM2C,YAAA,GAAe,MAAM,OAAOvD,WAAA;IAElCY,MAAA,GACE2C,YAAA,CAAaC,OAAA,CAAQ5C,MAAA;IAAA;IAErB2C,YAAA,CAAaC,OAAA,CAAQA,OAAA,EAAS5C,MAAA,EAE5B,OAAOA,MAAA,IAAW,eACpBgC,OAAA,CAAQC,KAAA,CAAM,sDAAiDU,YAAY,GAC3EP,OAAA,CAAQC,IAAA,CAAK,CAAC;EAElB,SAASV,GAAA,EAAK;IACZK,OAAA,CAAQC,KAAA,CAAM,wCAAmC,GACjDD,OAAA,CAAQC,KAAA,CAAM,4CAA4C7C,WAAW,EAAE,GAEvE4C,OAAA,CAAQC,KAAA,CAAMN,GAAA,CAAII,KAAQ,GAC1BK,OAAA,CAAQC,IAAA,CAAK,CAAC;EAChB;EAEA,OAAOrC,MAAA;AACT;AAEA,SAASI,oBAAoBf,IAAA,EAAc;EACzC,OAAOA,IAAA,CAAKc,QAAA,CAAS,GAAG,IAAId,IAAA,CAAKwD,KAAA,CAAM,GAAGxD,IAAA,CAAKyD,MAAA,GAAS,CAAC,IAAIzD,IAAA;AAC/D","ignoreList":[]}
@@ -0,0 +1,113 @@
1
+ import FSExtra from "fs-extra";
2
+ import { join } from "node:path";
3
+ import * as constants from "../constants";
4
+ import { getLoaderPath, getPreloadPath } from "../utils/cleanUrl";
5
+ import { toAbsolute } from "../utils/toAbsolute";
6
+ import { replaceLoader } from "../vite/replaceLoader";
7
+ var { readFile, outputFile } = FSExtra;
8
+ async function buildPage(serverEntry, path, relativeId, params, foundRoute, clientManifestEntry, staticDir, clientDir, builtMiddlewares, serverJsPath, preloads, allCSS) {
9
+ var render = await getRender(serverEntry), htmlPath = `${path.endsWith("/") ? `${removeTrailingSlash(path)}/index` : path}.html`, clientJsPath = join("dist/client", clientManifestEntry.file), htmlOutPath = toAbsolute(join(staticDir, htmlPath)), preloadPath = getPreloadPath(path), loaderData = {};
10
+ try {
11
+ await FSExtra.writeFile(join(clientDir, preloadPath), preloads.map(function(preload) {
12
+ return `import "${preload}"`;
13
+ }).join(`
14
+ `));
15
+ var exported = await import(toAbsolute(serverJsPath));
16
+ if (exported.loader) {
17
+ var _exported_loader, _ref;
18
+ loaderData = (_ref = await ((_exported_loader = exported.loader) === null || _exported_loader === void 0 ? void 0 : _exported_loader.call(exported, {
19
+ path,
20
+ params
21
+ }))) !== null && _ref !== void 0 ? _ref : null;
22
+ var code = await readFile(clientJsPath, "utf-8"), withLoader = (
23
+ // super dirty to quickly make ssr loaders work until we have better
24
+ `
25
+ if (typeof document === 'undefined') globalThis.document = {}
26
+ ` + replaceLoader({
27
+ code,
28
+ loaderData
29
+ })
30
+ ), loaderPartialPath = join(clientDir, getLoaderPath(path));
31
+ await outputFile(loaderPartialPath, withLoader);
32
+ }
33
+ if (foundRoute.type !== "ssr") {
34
+ var _globalThis___vxrnresetState, _globalThis, loaderProps = {
35
+ path,
36
+ params
37
+ };
38
+ if ((_globalThis___vxrnresetState = (_globalThis = globalThis).__vxrnresetState) === null || _globalThis___vxrnresetState === void 0 || _globalThis___vxrnresetState.call(_globalThis), foundRoute.type === "ssg") {
39
+ var html = await render({
40
+ path,
41
+ preloads,
42
+ loaderProps,
43
+ loaderData,
44
+ css: allCSS,
45
+ mode: "ssg"
46
+ });
47
+ await outputFile(htmlOutPath, html);
48
+ } else foundRoute.type === "spa" && await outputFile(htmlOutPath, `<html><head>
49
+ ${constants.getSpaHeaderElements({
50
+ serverContext: {
51
+ loaderProps,
52
+ loaderData
53
+ }
54
+ })}
55
+ ${preloads.map(function(preload) {
56
+ return ` <script type="module" src="${preload}"></script>`;
57
+ }).join(`
58
+ `)}
59
+ ${allCSS.map(function(file) {
60
+ return ` <link rel="stylesheet" href=${file} />`;
61
+ }).join(`
62
+ `)}
63
+ </head></html>`);
64
+ }
65
+ } catch (err) {
66
+ var errMsg = err instanceof Error ? `${err.message}
67
+ ${err.stack}` : `${err}`;
68
+ console.error(`Error building static page at ${path} with id ${relativeId}:
69
+
70
+ ${errMsg}
71
+
72
+ loaderData:
73
+
74
+ ${JSON.stringify(loaderData || null, null, 2)}
75
+ params:
76
+
77
+ ${JSON.stringify(params || null, null, 2)}`), console.error(err), process.exit(1);
78
+ }
79
+ var middlewares = (foundRoute.middlewares || []).map(function(x) {
80
+ return builtMiddlewares[x.contextKey];
81
+ }), cleanPath = path === "/" ? path : removeTrailingSlash(path);
82
+ return {
83
+ type: foundRoute.type,
84
+ routeFile: foundRoute.file,
85
+ middlewares,
86
+ cleanPath,
87
+ preloadPath,
88
+ clientJsPath,
89
+ serverJsPath,
90
+ htmlPath,
91
+ loaderData,
92
+ params,
93
+ path,
94
+ preloads
95
+ };
96
+ }
97
+ async function getRender(serverEntry) {
98
+ var render = null;
99
+ try {
100
+ var _serverImport_default_default, serverImport = await import(serverEntry);
101
+ render = serverImport.default.render || ((_serverImport_default_default = serverImport.default.default) === null || _serverImport_default_default === void 0 ? void 0 : _serverImport_default_default.render), typeof render != "function" && (console.error("\u274C Error: didn't find render function in entry", serverImport), process.exit(1));
102
+ } catch (err) {
103
+ console.error("\u274C Error importing the root entry:"), console.error(` This error happened in the built file: ${serverEntry}`), console.error(err.stack), process.exit(1);
104
+ }
105
+ return render;
106
+ }
107
+ function removeTrailingSlash(path) {
108
+ return path.endsWith("/") ? path.slice(0, path.length - 1) : path;
109
+ }
110
+ export {
111
+ buildPage
112
+ };
113
+ //# sourceMappingURL=buildPage.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/cli/Users/n8/one/packages/one/src/cli/buildPage.ts"],
4
+ "mappings": "AAAA,OAAOA,aAAa;AACpB,SAASC,YAAY;AACrB,YAAYC,eAAe;AAG3B,SAASC,eAAeC,sBAAsB;AAC9C,SAASC,kBAAkB;AAC3B,SAASC,qBAAqB;AAG9B,IAA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QAAQ3C,YAErB0C,gCAAAA,aAAaC,QAAQA,aAAO,QAA5BD,kCAAAA,SAAAA,SAAAA,8BAA8B1C,SAE5B,OAAOA,UAAW,eACpB+B,QAAQC,MAAM,sDAAiDU,YAAAA,GAC/DP,QAAQC,KAAK,CAAA;EAEjB,SAASV,KAAK;AACZK,YAAQC,MAAM,wCAAmC,GACjDD,QAAQC,MAAM,4CAA4C5C,WAAAA,EAAa,GAEvE2C,QAAQC,MAAMN,IAAI,KAAQ,GAC1BS,QAAQC,KAAK,CAAA;EACf;AAEA,SAAOpC;AACT;AAEA,SAASI,oBAAoBf,MAAY;AACvC,SAAOA,KAAKc,SAAS,GAAA,IAAOd,KAAKuD,MAAM,GAAGvD,KAAKwD,SAAS,CAAA,IAAKxD;AAC/D;",
5
+ "names": ["FSExtra", "join", "constants", "getLoaderPath", "getPreloadPath", "toAbsolute", "replaceLoader", "readFile", "outputFile", "buildPage", "serverEntry", "path", "relativeId", "params", "foundRoute", "clientManifestEntry", "staticDir", "clientDir", "builtMiddlewares", "serverJsPath", "preloads", "allCSS", "render", "getRender", "htmlPath", "endsWith", "removeTrailingSlash", "clientJsPath", "file", "htmlOutPath", "preloadPath", "loaderData", "writeFile", "map", "preload", "exported", "loader", "code", "withLoader", "loaderPartialPath", "type", "globalThis", "loaderProps", "html", "css", "mode", "getSpaHeaderElements", "serverContext", "err", "errMsg", "Error", "message", "stack", "console", "error", "JSON", "stringify", "process", "exit", "middlewares", "x", "contextKey", "cleanPath", "routeFile", "serverImport", "default", "slice", "length"]
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "one",
3
- "version": "1.1.399",
3
+ "version": "1.1.401",
4
4
  "license": "BSD-3-Clause",
5
5
  "sideEffects": [
6
6
  "setup.mjs",
@@ -107,15 +107,15 @@
107
107
  "@react-navigation/routers": "~7",
108
108
  "@swc/core": "^1.10.4",
109
109
  "@ungap/structured-clone": "^1.2.0",
110
- "@vxrn/compiler": "1.1.399",
111
- "@vxrn/resolve": "1.1.399",
112
- "@vxrn/tslib-lite": "1.1.399",
113
- "@vxrn/universal-color-scheme": "1.1.399",
114
- "@vxrn/use-isomorphic-layout-effect": "1.1.399",
110
+ "@vxrn/compiler": "1.1.401",
111
+ "@vxrn/resolve": "1.1.401",
112
+ "@vxrn/tslib-lite": "1.1.401",
113
+ "@vxrn/universal-color-scheme": "1.1.401",
114
+ "@vxrn/use-isomorphic-layout-effect": "1.1.401",
115
115
  "babel-dead-code-elimination": "^1.0.6",
116
116
  "citty": "^0.1.6",
117
117
  "core-js": "^3.38.1",
118
- "create-vxrn": "1.1.399",
118
+ "create-vxrn": "1.1.401",
119
119
  "escape-string-regexp": "^5.0.0",
120
120
  "expo-linking": "~6.3.1",
121
121
  "expo-modules-core": "2.1.2",
@@ -142,12 +142,12 @@
142
142
  "vite": "^6.0.6",
143
143
  "vite-plugin-barrel": "^0.4.1",
144
144
  "vite-tsconfig-paths": "^5.0.1",
145
- "vxrn": "1.1.399",
145
+ "vxrn": "1.1.401",
146
146
  "ws": "^8.18.0",
147
147
  "xxhashjs": "^0.2.2"
148
148
  },
149
149
  "devDependencies": {
150
- "@tamagui/build": "^1.121.10",
150
+ "@tamagui/build": "^1.121.11",
151
151
  "@types/node": "^22.1.0",
152
152
  "@types/react-dom": "^18.2.25",
153
153
  "@types/xxhashjs": "^0.2.4",
package/src/cli/build.ts CHANGED
@@ -15,13 +15,11 @@ import {
15
15
  } from 'vxrn'
16
16
  import * as constants from '../constants'
17
17
  import type { RouteInfo } from '../server/createRoutesManifest'
18
- import type { LoaderProps, RenderApp } from '../types'
19
- import { getLoaderPath, getPreloadPath } from '../utils/cleanUrl'
20
18
  import { toAbsolute } from '../utils/toAbsolute'
21
19
  import { getManifest } from '../vite/getManifest'
22
20
  import { loadUserOneOptions } from '../vite/loadConfig'
23
- import { replaceLoader } from '../vite/replaceLoader'
24
21
  import type { One } from '../vite/types'
22
+ import { buildPage } from './buildPage'
25
23
  import { labelProcess } from './label-process'
26
24
 
27
25
  const { ensureDir, readFile, outputFile } = FSExtra
@@ -213,33 +211,14 @@ export async function build(args: {
213
211
 
214
212
  console.info(`\n 🔨 build static routes\n`)
215
213
 
216
- let render: RenderApp | null = null
217
- const entryServer = vxrnOutput.serverEntry
218
-
219
- try {
220
- const serverImport = await import(entryServer)
221
-
222
- render =
223
- serverImport.default.render ||
224
- // for an unknown reason this is necessary
225
- serverImport.default.default?.render
226
-
227
- if (typeof render !== 'function') {
228
- console.error(`❌ Error: didn't find render function in entry`, serverImport)
229
- process.exit(1)
230
- }
231
- } catch (err) {
232
- console.error(`❌ Error importing the root entry:`)
233
- console.error(` This error happened in the built file: ${entryServer}`)
234
- // @ts-expect-error
235
- console.error(err['stack'])
236
- process.exit(1)
237
- }
238
-
239
214
  const staticDir = join(`dist/static`)
240
215
  const clientDir = join(`dist/client`)
241
216
  await ensureDir(staticDir)
242
217
 
218
+ if (!vxrnOutput.serverOutput) {
219
+ throw new Error(`No server output`)
220
+ }
221
+
243
222
  const outputEntries = [...vxrnOutput.serverOutput.entries()]
244
223
 
245
224
  for (const [index, output] of outputEntries) {
@@ -428,113 +407,32 @@ export async function build(args: {
428
407
  console.info(`paramsList`, JSON.stringify(paramsList, null, 2))
429
408
  }
430
409
 
410
+ const built: One.RouteBuildInfo[] = []
411
+
431
412
  for (const params of paramsList) {
432
413
  const cleanId = relativeId.replace(/\+(spa|ssg|ssr)\.tsx?$/, '')
433
414
  const path = getPathnameFromFilePath(cleanId, params, foundRoute.type === 'ssg')
434
- const htmlPath = `${path.endsWith('/') ? `${removeTrailingSlash(path)}/index` : path}.html`
435
- const clientJsPath = join(`dist/client`, clientManifestEntry.file)
436
- const htmlOutPath = toAbsolute(join(staticDir, htmlPath))
437
-
438
- let loaderData = {}
439
-
440
- try {
441
- console.info(` ↦ route ${path}`)
442
-
443
- const cleanPath = path === '/' ? path : removeTrailingSlash(path)
444
-
445
- const preloadPath = getPreloadPath(path)
446
-
447
- // todo await optimize
448
- await FSExtra.writeFile(
449
- join(clientDir, preloadPath),
450
- preloads.map((preload) => `import "${preload}"`).join('\n')
451
- )
452
-
453
- const middlewares = (foundRoute.middlewares || []).map(
454
- (x) => builtMiddlewares[x.contextKey]
455
- )
456
-
457
- builtRoutes.push({
458
- type: foundRoute.type,
459
- routeFile: foundRoute.file,
460
- middlewares,
461
- cleanPath,
462
- preloadPath,
463
- clientJsPath,
464
- serverJsPath,
465
- htmlPath,
466
- loaderData,
467
- params,
415
+ console.info(` ↦ route ${path}`)
416
+ built.push(
417
+ await buildPage(
418
+ vxrnOutput.serverEntry,
468
419
  path,
420
+ relativeId,
421
+ params,
422
+ foundRoute,
423
+ clientManifestEntry,
424
+ staticDir,
425
+ clientDir,
426
+ builtMiddlewares,
427
+ serverJsPath,
469
428
  preloads,
470
- })
471
-
472
- if (exported.loader) {
473
- loaderData = (await exported.loader?.({ path, params })) ?? null
474
- const code = await readFile(clientJsPath, 'utf-8')
475
- const withLoader =
476
- // super dirty to quickly make ssr loaders work until we have better
477
- `
478
- if (typeof document === 'undefined') globalThis.document = {}
479
- ` +
480
- replaceLoader({
481
- code,
482
- loaderData,
483
- })
484
- const loaderPartialPath = join(clientDir, getLoaderPath(path))
485
- await outputFile(loaderPartialPath, withLoader)
486
- }
487
-
488
- // ssr, we basically skip at build-time and just compile it the js we need
489
- if (foundRoute.type !== 'ssr') {
490
- const loaderProps: LoaderProps = { path, params }
491
- // importing resetState causes issues :/
492
- globalThis['__vxrnresetState']?.()
493
-
494
- if (foundRoute.type === 'ssg') {
495
- const html = await render({
496
- path,
497
- preloads,
498
- loaderProps,
499
- loaderData,
500
- css: allCSS,
501
- mode: 'ssg',
502
- })
503
- await outputFile(htmlOutPath, html)
504
- continue
505
- }
506
-
507
- if (foundRoute.type === 'spa') {
508
- await outputFile(
509
- htmlOutPath,
510
- `<html><head>
511
- ${constants.getSpaHeaderElements({ serverContext: { loaderProps, loaderData } })}
512
- ${preloads
513
- .map((preload) => ` <script type="module" src="${preload}"></script>`)
514
- .join('\n')}
515
- ${allCSS.map((file) => ` <link rel="stylesheet" href=${file} />`).join('\n')}
516
- </head></html>`
517
- )
518
- }
519
- }
520
- } catch (err) {
521
- const errMsg = err instanceof Error ? `${err.message}\n${err.stack}` : `${err}`
522
-
523
- console.error(
524
- `Error building static page at ${path} with id ${relativeId}:
525
-
526
- ${errMsg}
527
-
528
- loaderData:
529
-
530
- ${JSON.stringify(loaderData || null, null, 2)}
531
- params:
532
-
533
- ${JSON.stringify(params || null, null, 2)}`
429
+ allCSS
534
430
  )
535
- console.error(err)
536
- process.exit(1)
537
- }
431
+ )
432
+ }
433
+
434
+ for (const info of built) {
435
+ builtRoutes.push(info)
538
436
  }
539
437
  }
540
438
 
@@ -642,10 +540,6 @@ compatibility_date = "2024-12-05"
642
540
  console.info(`\n\n 💛 build complete\n\n`)
643
541
  }
644
542
 
645
- function removeTrailingSlash(path: string) {
646
- return path.endsWith('/') ? path.slice(0, path.length - 1) : path
647
- }
648
-
649
543
  async function moveAllFiles(src: string, dest: string) {
650
544
  try {
651
545
  await FSExtra.copy(src, dest, { overwrite: true, errorOnExist: false })
@@ -0,0 +1,152 @@
1
+ import FSExtra from 'fs-extra'
2
+ import { join } from 'node:path'
3
+ import * as constants from '../constants'
4
+ import type { RouteInfo } from '../server/createRoutesManifest'
5
+ import type { LoaderProps, RenderApp } from '../types'
6
+ import { getLoaderPath, getPreloadPath } from '../utils/cleanUrl'
7
+ import { toAbsolute } from '../utils/toAbsolute'
8
+ import { replaceLoader } from '../vite/replaceLoader'
9
+ import type { One } from '../vite/types'
10
+
11
+ const { readFile, outputFile } = FSExtra
12
+
13
+ export async function buildPage(
14
+ serverEntry: string,
15
+ path: string,
16
+ relativeId: string,
17
+ params: any,
18
+ foundRoute: RouteInfo<string>,
19
+ clientManifestEntry: any,
20
+ staticDir: string,
21
+ clientDir: string,
22
+ builtMiddlewares: Record<string, string>,
23
+ serverJsPath: string,
24
+ preloads: string[],
25
+ allCSS: string[]
26
+ ): Promise<One.RouteBuildInfo> {
27
+ const render = await getRender(serverEntry)
28
+ const htmlPath = `${path.endsWith('/') ? `${removeTrailingSlash(path)}/index` : path}.html`
29
+ const clientJsPath = join(`dist/client`, clientManifestEntry.file)
30
+ const htmlOutPath = toAbsolute(join(staticDir, htmlPath))
31
+ const preloadPath = getPreloadPath(path)
32
+
33
+ let loaderData = {}
34
+
35
+ try {
36
+ // todo await optimize
37
+ await FSExtra.writeFile(
38
+ join(clientDir, preloadPath),
39
+ preloads.map((preload) => `import "${preload}"`).join('\n')
40
+ )
41
+
42
+ const exported = await import(toAbsolute(serverJsPath))
43
+
44
+ if (exported.loader) {
45
+ loaderData = (await exported.loader?.({ path, params })) ?? null
46
+ const code = await readFile(clientJsPath, 'utf-8')
47
+ const withLoader =
48
+ // super dirty to quickly make ssr loaders work until we have better
49
+ `
50
+ if (typeof document === 'undefined') globalThis.document = {}
51
+ ` +
52
+ replaceLoader({
53
+ code,
54
+ loaderData,
55
+ })
56
+ const loaderPartialPath = join(clientDir, getLoaderPath(path))
57
+ await outputFile(loaderPartialPath, withLoader)
58
+ }
59
+
60
+ // ssr, we basically skip at build-time and just compile it the js we need
61
+ if (foundRoute.type !== 'ssr') {
62
+ const loaderProps: LoaderProps = { path, params }
63
+ // importing resetState causes issues :/
64
+ globalThis['__vxrnresetState']?.()
65
+
66
+ if (foundRoute.type === 'ssg') {
67
+ const html = await render({
68
+ path,
69
+ preloads,
70
+ loaderProps,
71
+ loaderData,
72
+ css: allCSS,
73
+ mode: 'ssg',
74
+ })
75
+ await outputFile(htmlOutPath, html)
76
+ } else if (foundRoute.type === 'spa') {
77
+ await outputFile(
78
+ htmlOutPath,
79
+ `<html><head>
80
+ ${constants.getSpaHeaderElements({ serverContext: { loaderProps, loaderData } })}
81
+ ${preloads
82
+ .map((preload) => ` <script type="module" src="${preload}"></script>`)
83
+ .join('\n')}
84
+ ${allCSS.map((file) => ` <link rel="stylesheet" href=${file} />`).join('\n')}
85
+ </head></html>`
86
+ )
87
+ }
88
+ }
89
+ } catch (err) {
90
+ const errMsg = err instanceof Error ? `${err.message}\n${err.stack}` : `${err}`
91
+
92
+ console.error(
93
+ `Error building static page at ${path} with id ${relativeId}:
94
+
95
+ ${errMsg}
96
+
97
+ loaderData:\n\n${JSON.stringify(loaderData || null, null, 2)}
98
+ params:\n\n${JSON.stringify(params || null, null, 2)}`
99
+ )
100
+ console.error(err)
101
+ process.exit(1)
102
+ }
103
+
104
+ const middlewares = (foundRoute.middlewares || []).map((x) => builtMiddlewares[x.contextKey])
105
+
106
+ const cleanPath = path === '/' ? path : removeTrailingSlash(path)
107
+
108
+ return {
109
+ type: foundRoute.type,
110
+ routeFile: foundRoute.file,
111
+ middlewares,
112
+ cleanPath,
113
+ preloadPath,
114
+ clientJsPath,
115
+ serverJsPath,
116
+ htmlPath,
117
+ loaderData,
118
+ params,
119
+ path,
120
+ preloads,
121
+ }
122
+ }
123
+
124
+ async function getRender(serverEntry: string) {
125
+ let render: RenderApp | null = null
126
+
127
+ try {
128
+ const serverImport = await import(serverEntry)
129
+
130
+ render =
131
+ serverImport.default.render ||
132
+ // for an unknown reason this is necessary
133
+ serverImport.default.default?.render
134
+
135
+ if (typeof render !== 'function') {
136
+ console.error(`❌ Error: didn't find render function in entry`, serverImport)
137
+ process.exit(1)
138
+ }
139
+ } catch (err) {
140
+ console.error(`❌ Error importing the root entry:`)
141
+ console.error(` This error happened in the built file: ${serverEntry}`)
142
+ // @ts-expect-error
143
+ console.error(err['stack'])
144
+ process.exit(1)
145
+ }
146
+
147
+ return render
148
+ }
149
+
150
+ function removeTrailingSlash(path: string) {
151
+ return path.endsWith('/') ? path.slice(0, path.length - 1) : path
152
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"AAgCA,wBAAsB,KAAK,CAAC,IAAI,EAAE;IAChC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,CAAA;CACrC,iBA8lBA"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/cli/build.ts"],"names":[],"mappings":"AA8BA,wBAAsB,KAAK,CAAC,IAAI,EAAE;IAChC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,CAAA;CACrC,iBAwfA"}
@@ -0,0 +1,4 @@
1
+ import type { RouteInfo } from '../server/createRoutesManifest';
2
+ import type { One } from '../vite/types';
3
+ export declare function buildPage(serverEntry: string, path: string, relativeId: string, params: any, foundRoute: RouteInfo<string>, clientManifestEntry: any, staticDir: string, clientDir: string, builtMiddlewares: Record<string, string>, serverJsPath: string, preloads: string[], allCSS: string[]): Promise<One.RouteBuildInfo>;
4
+ //# sourceMappingURL=buildPage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildPage.d.ts","sourceRoot":"","sources":["../../src/cli/buildPage.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAK/D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAA;AAIxC,wBAAsB,SAAS,CAC7B,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,GAAG,EACX,UAAU,EAAE,SAAS,CAAC,MAAM,CAAC,EAC7B,mBAAmB,EAAE,GAAG,EACxB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACxC,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAAE,EAClB,MAAM,EAAE,MAAM,EAAE,GACf,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAgG7B"}