one 1.1.398 → 1.1.400

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 (43) hide show
  1. package/dist/cjs/cli/build.cjs +7 -104
  2. package/dist/cjs/cli/build.js +23 -95
  3. package/dist/cjs/cli/build.js.map +1 -1
  4. package/dist/cjs/cli/build.native.js +14 -107
  5. package/dist/cjs/cli/build.native.js.map +2 -2
  6. package/dist/cjs/cli/buildPage.cjs +148 -0
  7. package/dist/cjs/cli/buildPage.js +122 -0
  8. package/dist/cjs/cli/buildPage.js.map +6 -0
  9. package/dist/cjs/cli/buildPage.native.js +136 -0
  10. package/dist/cjs/cli/buildPage.native.js.map +6 -0
  11. package/dist/cjs/cli.cjs +2 -2
  12. package/dist/cjs/cli.js +2 -2
  13. package/dist/cjs/cli.js.map +1 -1
  14. package/dist/cjs/cli.native.js +2 -2
  15. package/dist/cjs/cli.native.js.map +1 -1
  16. package/dist/esm/cli/build.js +23 -96
  17. package/dist/esm/cli/build.js.map +1 -1
  18. package/dist/esm/cli/build.mjs +7 -104
  19. package/dist/esm/cli/build.mjs.map +1 -1
  20. package/dist/esm/cli/build.native.js +14 -108
  21. package/dist/esm/cli/build.native.js.map +2 -2
  22. package/dist/esm/cli/buildPage.js +103 -0
  23. package/dist/esm/cli/buildPage.js.map +6 -0
  24. package/dist/esm/cli/buildPage.mjs +114 -0
  25. package/dist/esm/cli/buildPage.mjs.map +1 -0
  26. package/dist/esm/cli/buildPage.native.js +113 -0
  27. package/dist/esm/cli/buildPage.native.js.map +6 -0
  28. package/dist/esm/cli.js +2 -2
  29. package/dist/esm/cli.js.map +1 -1
  30. package/dist/esm/cli.mjs +2 -2
  31. package/dist/esm/cli.mjs.map +1 -1
  32. package/dist/esm/cli.native.js +2 -2
  33. package/dist/esm/cli.native.js.map +1 -1
  34. package/package.json +9 -9
  35. package/src/cli/build.ts +25 -133
  36. package/src/cli/buildPage.ts +152 -0
  37. package/src/cli/dev.ts +1 -1
  38. package/src/cli.ts +2 -2
  39. package/types/cli/build.d.ts.map +1 -1
  40. package/types/cli/buildPage.d.ts +4 -0
  41. package/types/cli/buildPage.d.ts.map +1 -0
  42. package/types/cli/dev.d.ts +1 -1
  43. package/types/cli/dev.d.ts.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "one",
3
- "version": "1.1.398",
3
+ "version": "1.1.400",
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.398",
111
- "@vxrn/resolve": "1.1.398",
112
- "@vxrn/tslib-lite": "1.1.398",
113
- "@vxrn/universal-color-scheme": "1.1.398",
114
- "@vxrn/use-isomorphic-layout-effect": "1.1.398",
110
+ "@vxrn/compiler": "1.1.400",
111
+ "@vxrn/resolve": "1.1.400",
112
+ "@vxrn/tslib-lite": "1.1.400",
113
+ "@vxrn/universal-color-scheme": "1.1.400",
114
+ "@vxrn/use-isomorphic-layout-effect": "1.1.400",
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.398",
118
+ "create-vxrn": "1.1.400",
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.398",
145
+ "vxrn": "1.1.400",
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,30 @@ export async function build(args: {
428
407
  console.info(`paramsList`, JSON.stringify(paramsList, null, 2))
429
408
  }
430
409
 
431
- for (const params of paramsList) {
432
- const cleanId = relativeId.replace(/\+(spa|ssg|ssr)\.tsx?$/, '')
433
- 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 {
410
+ const built = await Promise.all(
411
+ paramsList.map((params) => {
412
+ const cleanId = relativeId.replace(/\+(spa|ssg|ssr)\.tsx?$/, '')
413
+ const path = getPathnameFromFilePath(cleanId, params, foundRoute.type === 'ssg')
441
414
  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
+ return buildPage(
416
+ vxrnOutput.serverEntry,
468
417
  path,
418
+ relativeId,
419
+ params,
420
+ foundRoute,
421
+ clientManifestEntry,
422
+ staticDir,
423
+ clientDir,
424
+ builtMiddlewares,
425
+ serverJsPath,
469
426
  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)}`
427
+ allCSS
534
428
  )
535
- console.error(err)
536
- process.exit(1)
537
- }
429
+ })
430
+ )
431
+
432
+ for (const info of built) {
433
+ builtRoutes.push(info)
538
434
  }
539
435
  }
540
436
 
@@ -642,10 +538,6 @@ compatibility_date = "2024-12-05"
642
538
  console.info(`\n\n 💛 build complete\n\n`)
643
539
  }
644
540
 
645
- function removeTrailingSlash(path: string) {
646
- return path.endsWith('/') ? path.slice(0, path.length - 1) : path
647
- }
648
-
649
541
  async function moveAllFiles(src: string, dest: string) {
650
542
  try {
651
543
  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
+ }
package/src/cli/dev.ts CHANGED
@@ -7,7 +7,7 @@ export async function dev(args: {
7
7
  port?: string
8
8
  https?: boolean
9
9
  mode?: 'development' | 'production'
10
- debugBundle?: boolean
10
+ debugBundle?: string
11
11
  debug?: string
12
12
  }) {
13
13
  labelProcess('dev')
package/src/cli.ts CHANGED
@@ -59,7 +59,7 @@ const dev = defineCommand({
59
59
  'If set to "production" you can run the development server but serve the production bundle',
60
60
  },
61
61
  'debug-bundle': {
62
- type: 'boolean',
62
+ type: 'string',
63
63
  description: `Will output the bundle to a temp file and then serve it from there afterwards allowing you to easily edit the bundle to debug problems.`,
64
64
  },
65
65
  debug: {
@@ -71,7 +71,7 @@ const dev = defineCommand({
71
71
  const { dev } = await import('./cli/dev')
72
72
  await dev({
73
73
  ...args,
74
- debugBundle: !!args['debug-bundle'],
74
+ debugBundle: args['debug-bundle'],
75
75
  mode: modes[args.mode],
76
76
  })
77
77
  },
@@ -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"}
@@ -4,7 +4,7 @@ export declare function dev(args: {
4
4
  port?: string;
5
5
  https?: boolean;
6
6
  mode?: 'development' | 'production';
7
- debugBundle?: boolean;
7
+ debugBundle?: string;
8
8
  debug?: string;
9
9
  }): Promise<void>;
10
10
  //# sourceMappingURL=dev.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/cli/dev.ts"],"names":[],"mappings":"AAGA,wBAAsB,GAAG,CAAC,IAAI,EAAE;IAC9B,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,IAAI,CAAC,EAAE,aAAa,GAAG,YAAY,CAAA;IACnC,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,iBAmCA"}
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/cli/dev.ts"],"names":[],"mappings":"AAGA,wBAAsB,GAAG,CAAC,IAAI,EAAE;IAC9B,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,IAAI,CAAC,EAAE,aAAa,GAAG,YAAY,CAAA;IACnC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,iBAmCA"}