vxrn 0.1.62 → 0.1.64

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 (47) hide show
  1. package/dist/cjs/exports/build.js +7 -2
  2. package/dist/cjs/exports/build.js.map +1 -1
  3. package/dist/cjs/exports/build.native.js +15 -8
  4. package/dist/cjs/exports/build.native.js.map +2 -2
  5. package/dist/cjs/exports/createServer.js +9 -34
  6. package/dist/cjs/exports/createServer.js.map +2 -2
  7. package/dist/cjs/exports/createServer.native.js +42 -72
  8. package/dist/cjs/exports/createServer.native.js.map +2 -2
  9. package/dist/cjs/exports/serve.js +9 -3
  10. package/dist/cjs/exports/serve.js.map +2 -2
  11. package/dist/cjs/exports/serve.native.js +7 -3
  12. package/dist/cjs/exports/serve.native.js.map +2 -2
  13. package/dist/cjs/types.native.js.map +1 -1
  14. package/dist/cjs/utils/getHtml.js +12 -4
  15. package/dist/cjs/utils/getHtml.js.map +1 -1
  16. package/dist/cjs/utils/getHtml.native.js +40 -4
  17. package/dist/cjs/utils/getHtml.native.js.map +2 -2
  18. package/dist/esm/exports/build.js +7 -2
  19. package/dist/esm/exports/build.js.map +1 -1
  20. package/dist/esm/exports/build.mjs +12 -6
  21. package/dist/esm/exports/build.native.js +15 -8
  22. package/dist/esm/exports/build.native.js.map +2 -2
  23. package/dist/esm/exports/createServer.js +9 -25
  24. package/dist/esm/exports/createServer.js.map +1 -1
  25. package/dist/esm/exports/createServer.mjs +7 -33
  26. package/dist/esm/exports/createServer.native.js +42 -63
  27. package/dist/esm/exports/createServer.native.js.map +2 -2
  28. package/dist/esm/exports/serve.js +9 -4
  29. package/dist/esm/exports/serve.js.map +1 -1
  30. package/dist/esm/exports/serve.mjs +9 -5
  31. package/dist/esm/exports/serve.native.js +7 -4
  32. package/dist/esm/exports/serve.native.js.map +2 -2
  33. package/dist/esm/utils/getHtml.js +12 -4
  34. package/dist/esm/utils/getHtml.js.map +1 -1
  35. package/dist/esm/utils/getHtml.mjs +5 -4
  36. package/dist/esm/utils/getHtml.native.js +40 -4
  37. package/dist/esm/utils/getHtml.native.js.map +2 -2
  38. package/package.json +11 -8
  39. package/src/exports/build.ts +5 -2
  40. package/src/exports/createServer.ts +47 -28
  41. package/src/exports/serve.ts +8 -4
  42. package/src/types.ts +13 -2
  43. package/src/utils/getHtml.ts +10 -1
  44. package/types/exports/createServer.d.ts +2 -1
  45. package/types/types.d.ts +12 -2
  46. package/types/utils/getHtml.d.ts +2 -1
  47. package/types/utils/getOptionsFilled.d.ts +1 -1
@@ -1,41 +1,60 @@
1
- import { createApp, defineEventHandler } from 'h3'
2
- import sirv from 'sirv'
1
+ import { Hono } from 'hono'
2
+ import { compress } from 'hono/compress'
3
+ // import { cache } from 'hono/cache'
4
+ import { serveStatic } from '@hono/node-server/serve-static'
5
+
3
6
  import type { VXRNConfig } from '../types'
4
7
 
5
8
  export const createProdServer = async (options: VXRNConfig) => {
6
- const app = createApp()
7
-
8
- const sirvStaticMiddleware = sirv('dist/static', {
9
- gzip: true,
10
- })
9
+ const app = new Hono()
11
10
 
12
- if (options.serve) {
13
- options.serve(options, app)
14
- }
11
+ app.use(compress())
15
12
 
16
13
  app.use(
17
- defineEventHandler(async ({ node: { req, res } }) => {
18
- await new Promise<void>((response) => {
19
- sirvStaticMiddleware(req, res, () => {
20
- response()
21
- })
22
- })
14
+ '*',
15
+ serveStatic({
16
+ root: './dist/client',
23
17
  })
24
18
  )
25
19
 
26
- const sirvMiddleware = sirv('dist/client', {
27
- gzip: true,
28
- })
20
+ // app.get(
21
+ // '*',
22
+ // cache({
23
+ // cacheName: 'my-app',
24
+ // cacheControl: 'max-age=3600',
25
+ // })
26
+ // )
29
27
 
30
- app.use(
31
- defineEventHandler(async ({ node: { req, res } }) => {
32
- await new Promise<void>((response) => {
33
- sirvMiddleware(req, res, () => {
34
- response()
35
- })
36
- })
37
- })
38
- )
28
+ if (options.serve) {
29
+ options.serve(options, app)
30
+ }
39
31
 
40
32
  return app
41
33
  }
34
+
35
+ // // testing cache
36
+ // const caches = {}
37
+ // function createCache(name: string) {
38
+ // if (caches[name]) return caches[name] as any
39
+ // const store = {}
40
+ // const cache = {
41
+ // async match(key: string) {
42
+ // console.log('matching', key)
43
+ // return store[key]
44
+ // },
45
+ // async put(key: string, val) {
46
+ // store[key] = val
47
+ // },
48
+ // async delete(key: string) {
49
+ // delete store[key]
50
+ // },
51
+ // }
52
+ // caches[name] = cache
53
+ // return cache
54
+ // }
55
+ // globalThis.caches = {
56
+ // ...createCache(''),
57
+ // async open(name: string) {
58
+ // return createCache(name)
59
+ // },
60
+ // }
@@ -1,5 +1,5 @@
1
- import { toNodeListener } from 'h3'
2
- import { createServer } from 'node:http'
1
+ import { serve as honoServe } from '@hono/node-server'
2
+
3
3
  import type { VXRNConfig } from '../types'
4
4
  import { createProdServer } from './createServer'
5
5
  import { getOptionsFilled } from '../utils/getOptionsFilled'
@@ -7,10 +7,14 @@ import { getOptionsFilled } from '../utils/getOptionsFilled'
7
7
  export const serve = async (optionsIn: VXRNConfig) => {
8
8
  const options = await getOptionsFilled(optionsIn, { mode: 'prod' })
9
9
  const app = await createProdServer(options)
10
- const server = createServer(toNodeListener(app))
11
10
  // strange prevents a cant listen on port issue
12
11
  await new Promise((res) => setTimeout(res, 1))
13
- server.listen(options.port, options.host)
12
+ const server = honoServe({
13
+ fetch: app.fetch,
14
+ port: options.port,
15
+ hostname: options.host,
16
+ })
17
+ // server.listen(options.port, options.host)
14
18
  console.info(`Listening on http://${options.host}:${options.port}`)
15
19
  await new Promise<void>((res) => {
16
20
  server.on('close', () => {
package/src/types.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Options as FlowOptions } from '@vxrn/vite-flow'
2
- import type { App } from 'h3'
2
+ import type { Hono } from 'hono'
3
3
  import type { OutputAsset, OutputChunk } from 'rollup'
4
4
  import type { InlineConfig, UserConfig } from 'vite'
5
5
 
@@ -7,6 +7,17 @@ export type AfterBuildProps = {
7
7
  options: VXRNConfig
8
8
  output: [OutputChunk, ...(OutputChunk | OutputAsset)[]]
9
9
  webBuildConfig: UserConfig
10
+ clientManifest: {
11
+ // app/[user].tsx
12
+ [key: string]: {
13
+ file: string // assets/_user_-Bg0DW2rm.js
14
+ src?: string // app/[user].tsx
15
+ isDynamicEntry?: boolean // true for import.meta.globbed
16
+ isEntry?: boolean // true for index.html
17
+ name: string // _user_
18
+ imports: string[]
19
+ }
20
+ }
10
21
  }
11
22
 
12
23
  export type VXRNConfig = {
@@ -30,7 +41,7 @@ export type VXRNConfig = {
30
41
 
31
42
  afterBuild?: (props: AfterBuildProps) => void | Promise<void>
32
43
 
33
- serve?: (options: VXRNConfig, app: App) => void
44
+ serve?: (options: VXRNConfig, app: Hono) => void
34
45
  }
35
46
 
36
47
  export type HMRListener = (update: { file: string; contents: string }) => void
@@ -6,6 +6,7 @@ export function getHtml({
6
6
  appHtml,
7
7
  headHtml,
8
8
  css,
9
+ preloads,
9
10
  }: {
10
11
  css?: string
11
12
  template: string
@@ -13,6 +14,7 @@ export function getHtml({
13
14
  loaderProps?: any
14
15
  appHtml: string
15
16
  headHtml: string
17
+ preloads: string[]
16
18
  }) {
17
19
  if (!template.includes(`<!--ssr-outlet-->`)) {
18
20
  throw new Error(`No <!--ssr-outlet--> found in html to inject SSR contents`)
@@ -30,6 +32,13 @@ export function getHtml({
30
32
 
31
33
  return template
32
34
  .replace(/\s*<!--ssr-outlet-->\s*/, appHtml)
33
- .replace(`<!--head-outlet-->`, `${headHtml}\n${css ? `<style>${css}</style>\n` : ``}`)
35
+ .replace(
36
+ `<!--head-outlet-->`,
37
+ [
38
+ headHtml,
39
+ `<style>${css}</style>\n`,
40
+ ...preloads.map((src) => `<link rel="modulepreload" href="${src}" />`),
41
+ ].join('\n ')
42
+ )
34
43
  .replace('</body>', loaderDataString)
35
44
  }
@@ -1,3 +1,4 @@
1
+ import { Hono } from 'hono';
1
2
  import type { VXRNConfig } from '../types';
2
- export declare const createProdServer: (options: VXRNConfig) => Promise<import("h3").App>;
3
+ export declare const createProdServer: (options: VXRNConfig) => Promise<Hono<import("hono").Env, import("hono/types").BlankSchema, "/">>;
3
4
  //# sourceMappingURL=createServer.d.ts.map
package/types/types.d.ts CHANGED
@@ -1,11 +1,21 @@
1
1
  import type { Options as FlowOptions } from '@vxrn/vite-flow';
2
- import type { App } from 'h3';
2
+ import type { Hono } from 'hono';
3
3
  import type { OutputAsset, OutputChunk } from 'rollup';
4
4
  import type { InlineConfig, UserConfig } from 'vite';
5
5
  export type AfterBuildProps = {
6
6
  options: VXRNConfig;
7
7
  output: [OutputChunk, ...(OutputChunk | OutputAsset)[]];
8
8
  webBuildConfig: UserConfig;
9
+ clientManifest: {
10
+ [key: string]: {
11
+ file: string;
12
+ src?: string;
13
+ isDynamicEntry?: boolean;
14
+ isEntry?: boolean;
15
+ name: string;
16
+ imports: string[];
17
+ };
18
+ };
9
19
  };
10
20
  export type VXRNConfig = {
11
21
  /**
@@ -26,7 +36,7 @@ export type VXRNConfig = {
26
36
  nativeConfig?: InlineConfig;
27
37
  flow?: FlowOptions;
28
38
  afterBuild?: (props: AfterBuildProps) => void | Promise<void>;
29
- serve?: (options: VXRNConfig, app: App) => void;
39
+ serve?: (options: VXRNConfig, app: Hono) => void;
30
40
  };
31
41
  export type HMRListener = (update: {
32
42
  file: string;
@@ -1,9 +1,10 @@
1
- export declare function getHtml({ template, loaderData, loaderProps, appHtml, headHtml, css, }: {
1
+ export declare function getHtml({ template, loaderData, loaderProps, appHtml, headHtml, css, preloads, }: {
2
2
  css?: string;
3
3
  template: string;
4
4
  loaderData: Object;
5
5
  loaderProps?: any;
6
6
  appHtml: string;
7
7
  headHtml: string;
8
+ preloads: string[];
8
9
  }): string;
9
10
  //# sourceMappingURL=getHtml.d.ts.map
@@ -20,7 +20,7 @@ export declare function getOptionsFilled(options: VXRNConfig, internal?: {
20
20
  nativeConfig?: import("vite").InlineConfig | undefined;
21
21
  flow?: import("@vxrn/vite-flow").Options | undefined;
22
22
  afterBuild?: ((props: import("..").AfterBuildProps) => void | Promise<void>) | undefined;
23
- serve?: ((options: VXRNConfig, app: import("h3").App) => void) | undefined;
23
+ serve?: ((options: VXRNConfig, app: import("hono").Hono<import("hono").Env, import("hono/types").BlankSchema, "/">) => void) | undefined;
24
24
  }>;
25
25
  type State = {
26
26
  applyPatches?: boolean;