one 1.1.312 → 1.1.313

Sign up to get free protection for your applications and to get access to all the features.
package/src/serve.ts CHANGED
@@ -2,17 +2,11 @@ import './polyfills-server'
2
2
 
3
3
  import FSExtra from 'fs-extra'
4
4
  import type { Hono } from 'hono'
5
- import Path, { join } from 'node:path'
5
+ import { join } from 'node:path'
6
6
  import type { VXRNOptions } from 'vxrn'
7
7
  import { getServerEntry, loadEnv, serve as vxrnServe } from 'vxrn'
8
- import { labelProcess } from './cli/label-process'
9
- import { createHandleRequest } from './createHandleRequest'
10
8
  import type { RenderAppProps } from './types'
11
- import { isResponse } from './utils/isResponse'
12
- import { isStatusRedirect } from './utils/isStatus'
13
- import { removeUndefined } from './utils/removeUndefined'
14
- import { loadUserOneOptions } from './vite/one'
15
- import { resolveAPIRequest } from './vite/resolveAPIRequest'
9
+
16
10
  import type { One } from './vite/types'
17
11
 
18
12
  process.on('uncaughtException', (err) => {
@@ -20,6 +14,16 @@ process.on('uncaughtException', (err) => {
20
14
  })
21
15
 
22
16
  export async function serve(args: VXRNOptions['server'] = {}) {
17
+ const buildInfo = (await FSExtra.readJSON(`dist/buildInfo.json`)) as One.BuildInfo
18
+
19
+ // ensure cache key matches build
20
+ process.env.ONE_CACHE_KEY = buildInfo.constants.CACHE_KEY
21
+
22
+ // to avoid loading the CACHE_KEY before we set it use async imports:
23
+ const { labelProcess } = await import('./cli/label-process')
24
+ const { removeUndefined } = await import('./utils/removeUndefined')
25
+ const { loadUserOneOptions } = await import('./vite/one')
26
+
23
27
  labelProcess('serve')
24
28
  loadEnv('production')
25
29
 
@@ -43,16 +47,25 @@ export async function serve(args: VXRNOptions['server'] = {}) {
43
47
 
44
48
  async beforeStart(options, app) {
45
49
  await oneOptions.server?.beforeStart?.(options, app)
46
- await oneServe(oneOptions, options, app)
50
+ await oneServe(oneOptions, options, buildInfo, app)
47
51
  },
48
52
  },
49
53
  })
50
54
  }
51
55
 
52
- async function oneServe(options: One.Options, vxrnOptions: VXRNOptions, app: Hono) {
53
- const root = options.root || vxrnOptions.root || '.'
56
+ async function oneServe(
57
+ options: One.PluginOptions,
58
+ vxrnOptions: VXRNOptions,
59
+ buildInfo: One.BuildInfo,
60
+ app: Hono
61
+ ) {
62
+ const { createHandleRequest } = await import('./createHandleRequest')
63
+ const { isResponse } = await import('./utils/isResponse')
64
+ const { isStatusRedirect } = await import('./utils/isStatus')
65
+ const { resolveAPIRequest } = await import('./vite/resolveAPIRequest')
66
+
54
67
  const isAPIRequest = new WeakMap<any, boolean>()
55
- const toAbsolute = (p: string) => Path.resolve(root, p)
68
+ const root = vxrnOptions.root || '.'
56
69
 
57
70
  // add redirects
58
71
  const redirects = options.web?.redirects
@@ -68,8 +81,6 @@ async function oneServe(options: One.Options, vxrnOptions: VXRNOptions, app: Hon
68
81
  }
69
82
  }
70
83
 
71
- const buildInfo = await FSExtra.readJSON(toAbsolute(`dist/buildInfo.json`))
72
-
73
84
  if (!buildInfo) {
74
85
  throw new Error(`No build info found, have you run build?`)
75
86
  }
@@ -132,7 +143,9 @@ async function oneServe(options: One.Options, vxrnOptions: VXRNOptions, app: Hon
132
143
  if (route.type === 'ssr') {
133
144
  const buildInfo = routeToBuildInfo[route.page]
134
145
  if (!buildInfo) {
135
- throw new Error(`No buildinfo found for ${url}, route: ${route.page}`)
146
+ throw new Error(
147
+ `No buildinfo found for ${url}, route: ${route.page}, in keys: ${Object.keys(routeToBuildInfo)}`
148
+ )
136
149
  }
137
150
 
138
151
  try {
package/src/vite/build.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as constants from '../constants'
1
2
  import FSExtra from 'fs-extra'
2
3
  import MicroMatch from 'micromatch'
3
4
  import { createRequire } from 'node:module'
@@ -509,6 +510,7 @@ ${JSON.stringify(params || null, null, 2)}`
509
510
  const buildInfoForWriting = {
510
511
  routeMap,
511
512
  builtRoutes,
513
+ constants: JSON.parse(JSON.stringify({ ...constants })),
512
514
  }
513
515
 
514
516
  const buildInfo = {
package/src/vite/types.ts CHANGED
@@ -139,7 +139,11 @@ export namespace One {
139
139
  permanent: boolean
140
140
  }
141
141
 
142
- export type BuildInfo = Pick<AfterBuildProps, 'routeMap' | 'builtRoutes'>
142
+ export type BuildInfo = Pick<AfterBuildProps, 'routeMap' | 'builtRoutes'> & {
143
+ constants: {
144
+ CACHE_KEY: string
145
+ }
146
+ }
143
147
 
144
148
  export type AfterBuildProps = VXRNAfterBuildProps & {
145
149
  routeMap: Record<string, string>
@@ -1 +1 @@
1
- {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAA;AAK3B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,MAAM,CAAA;AAgBvC,wBAAsB,KAAK,CAAC,IAAI,GAAE,WAAW,CAAC,QAAQ,CAAM;mDAfJ,YACvD;+CAC+C,YAChD;gDAEK,YAAY;iDAEV,YAAY;+CAEX,YAAY;mDAGkB,YAAY;GA+BjD"}
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA,OAAO,oBAAoB,CAAA;AAK3B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,MAAM,CAAA;AAUvC,wBAAsB,KAAK,CAAC,IAAI,GAAE,WAAW,CAAC,QAAQ,CAAM;mDATE,YACvD;+CAIU,YAAY;gDAIX,YAAY;iDACoC,YAAY;+CAGxB,YAEjD;mDAC8B,YAAY;GA+B9C"}
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/vite/build.ts"],"names":[],"mappings":"AA6BA,wBAAsB,KAAK,CAAC,IAAI,EAAE;IAChC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,iBAugBA"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/vite/build.ts"],"names":[],"mappings":"AA8BA,wBAAsB,KAAK,CAAC,IAAI,EAAE;IAChC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,iBAwgBA"}
@@ -112,7 +112,11 @@ export declare namespace One {
112
112
  destination: string;
113
113
  permanent: boolean;
114
114
  };
115
- type BuildInfo = Pick<AfterBuildProps, 'routeMap' | 'builtRoutes'>;
115
+ type BuildInfo = Pick<AfterBuildProps, 'routeMap' | 'builtRoutes'> & {
116
+ constants: {
117
+ CACHE_KEY: string;
118
+ };
119
+ };
116
120
  type AfterBuildProps = VXRNAfterBuildProps & {
117
121
  routeMap: Record<string, string>;
118
122
  builtRoutes: RouteBuildInfo[];
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/vite/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,IAAI,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AACjF,OAAO,KAAK,EACV,WAAW,EACX,QAAQ,EACR,eAAe,IAAI,mBAAmB,EACtC,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EAClB,MAAM,MAAM,CAAA;AAEb,yBAAiB,GAAG,CAAC;IACnB,KAAY,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,aAAa,CAAC,GAAG,aAAa,CAAA;IAE5E,KAAY,eAAe,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAA;IAEnD,KAAY,SAAS,GAAG,eAAe,GAAG,KAAK,GAAG,QAAQ,CAAA;IAE1D,KAAY,YAAY,GAAG;QACzB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;KAC7C,CAAA;IAED,KAAY,eAAe,GAAG;QAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAA;KACpD,CAAA;IAED,KAAY,aAAa,GAAG;QAC1B;;;;;WAKG;QACH,IAAI,CAAC,EAAE,OAAO,CAAA;QAEd;;;;WAIG;QACH,SAAS,CAAC,EAAE,MAAM,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