vxrn 0.1.47 → 0.1.48

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 (54) hide show
  1. package/dist/cjs/cli.js +5 -0
  2. package/dist/cjs/cli.js.map +1 -1
  3. package/dist/cjs/cli.native.js +41 -34
  4. package/dist/cjs/cli.native.js.map +1 -1
  5. package/dist/cjs/constants.js +1 -69
  6. package/dist/cjs/constants.js.map +1 -1
  7. package/dist/cjs/constants.native.js +1 -105
  8. package/dist/cjs/constants.native.js.map +2 -2
  9. package/dist/cjs/exports/build.js +43 -36
  10. package/dist/cjs/exports/build.js.map +1 -1
  11. package/dist/cjs/exports/build.native.js +205 -133
  12. package/dist/cjs/exports/build.native.js.map +2 -2
  13. package/dist/cjs/exports/dev.js +23 -19
  14. package/dist/cjs/exports/dev.js.map +1 -1
  15. package/dist/cjs/exports/dev.native.js +32 -30
  16. package/dist/cjs/exports/dev.native.js.map +2 -2
  17. package/dist/cjs/utils/getOptimizeDeps.js +132 -0
  18. package/dist/cjs/utils/getOptimizeDeps.js.map +6 -0
  19. package/dist/cjs/utils/getOptimizeDeps.native.js +171 -0
  20. package/dist/cjs/utils/getOptimizeDeps.native.js.map +6 -0
  21. package/dist/esm/cli.js +5 -0
  22. package/dist/esm/cli.js.map +1 -1
  23. package/dist/esm/cli.mjs +5 -0
  24. package/dist/esm/cli.native.js +41 -34
  25. package/dist/esm/cli.native.js.map +1 -1
  26. package/dist/esm/constants.js +1 -69
  27. package/dist/esm/constants.js.map +1 -1
  28. package/dist/esm/constants.mjs +2 -12
  29. package/dist/esm/constants.native.js +1 -103
  30. package/dist/esm/constants.native.js.map +2 -2
  31. package/dist/esm/exports/build.js +40 -34
  32. package/dist/esm/exports/build.js.map +1 -1
  33. package/dist/esm/exports/build.mjs +54 -44
  34. package/dist/esm/exports/build.native.js +204 -132
  35. package/dist/esm/exports/build.native.js.map +2 -2
  36. package/dist/esm/exports/dev.js +20 -15
  37. package/dist/esm/exports/dev.js.map +1 -1
  38. package/dist/esm/exports/dev.mjs +27 -20
  39. package/dist/esm/exports/dev.native.js +29 -26
  40. package/dist/esm/exports/dev.native.js.map +2 -2
  41. package/dist/esm/utils/getOptimizeDeps.js +116 -0
  42. package/dist/esm/utils/getOptimizeDeps.js.map +6 -0
  43. package/dist/esm/utils/getOptimizeDeps.mjs +18 -0
  44. package/dist/esm/utils/getOptimizeDeps.native.js +150 -0
  45. package/dist/esm/utils/getOptimizeDeps.native.js.map +6 -0
  46. package/package.json +10 -10
  47. package/src/cli.ts +5 -0
  48. package/src/constants.ts +0 -75
  49. package/src/exports/build.ts +79 -61
  50. package/src/exports/dev.ts +28 -21
  51. package/src/utils/getOptimizeDeps.ts +122 -0
  52. package/types/constants.d.ts +0 -9
  53. package/types/exports/build.d.ts +5 -2
  54. package/types/utils/getOptimizeDeps.d.ts +13 -0
@@ -0,0 +1,150 @@
1
+ import { webExtensions } from "../constants";
2
+ function _array_like_to_array(arr, len) {
3
+ (len == null || len > arr.length) && (len = arr.length);
4
+ for (var i = 0, arr2 = new Array(len); i < len; i++)
5
+ arr2[i] = arr[i];
6
+ return arr2;
7
+ }
8
+ function _array_without_holes(arr) {
9
+ if (Array.isArray(arr))
10
+ return _array_like_to_array(arr);
11
+ }
12
+ function _iterable_to_array(iter) {
13
+ if (typeof Symbol < "u" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
14
+ return Array.from(iter);
15
+ }
16
+ function _non_iterable_spread() {
17
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
18
+ }
19
+ function _to_consumable_array(arr) {
20
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
21
+ }
22
+ function _unsupported_iterable_to_array(o, minLen) {
23
+ if (o) {
24
+ if (typeof o == "string")
25
+ return _array_like_to_array(o, minLen);
26
+ var n = Object.prototype.toString.call(o).slice(8, -1);
27
+ if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set")
28
+ return Array.from(n);
29
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
30
+ return _array_like_to_array(o, minLen);
31
+ }
32
+ }
33
+ function getOptimizeDeps(mode) {
34
+ var needsInterop = [
35
+ "react",
36
+ "react/jsx-runtime",
37
+ "react/jsx-dev-runtime",
38
+ "react-native-web-internals",
39
+ "react-dom",
40
+ "react-native-web",
41
+ "react-dom/server",
42
+ "react-dom/client",
43
+ "url-parse",
44
+ "@vxrn/safe-area",
45
+ "query-string",
46
+ "escape-string-regexp",
47
+ "use-latest-callback",
48
+ "react-is",
49
+ "fast-deep-equal",
50
+ "react-native-svg",
51
+ "@supabase/auth-helpers-react",
52
+ "parse-numeric-range",
53
+ "use-sync-external-store",
54
+ "use-sync-external-store/shim",
55
+ "expo-constants",
56
+ "expo-linking",
57
+ "uuid",
58
+ "@react-navigation/core",
59
+ "@react-navigation/native",
60
+ "@react-navigation/elements",
61
+ "@react-navigation/bottom-tabs",
62
+ "@react-navigation/native-stack",
63
+ "inline-style-prefixer",
64
+ "@docsearch/react",
65
+ "@algolia/autocomplete-core",
66
+ "@algolia/autocomplete-plugin-algolia-insights",
67
+ "@algolia/autocomplete-shared",
68
+ "react-native-reanimated",
69
+ "moti"
70
+ ], depsToOptimize = _to_consumable_array(needsInterop).concat([
71
+ "requires-port",
72
+ "querystringify",
73
+ "compare-versions",
74
+ "strict-uri-encode",
75
+ "decode-uri-component",
76
+ "split-on-first",
77
+ "filter-obj",
78
+ "scheduler",
79
+ "warn-once",
80
+ "@radix-ui/react-compose-refs",
81
+ "@radix-ui/react-slot",
82
+ "expo-splash-screen",
83
+ "nanoid",
84
+ "swr",
85
+ "refractor/lang/tsx",
86
+ "invariant",
87
+ "tamagui/linear-gradient",
88
+ "@tamagui/linear-gradient",
89
+ "@react-native/normalize-color",
90
+ "@vxrn/router",
91
+ "expo-modules-core",
92
+ "expo-status-bar",
93
+ "react-native-web",
94
+ "react-native-web-lite",
95
+ "react-native",
96
+ "@tamagui/constants",
97
+ "@tamagui/react-native-use-responder-events",
98
+ "@tamagui/alert-dialog",
99
+ "@react-navigation/routers",
100
+ "@tamagui/simple-hash",
101
+ "@tamagui/use-did-finish-ssr",
102
+ "@tamagui/use-event",
103
+ "@tamagui/portal",
104
+ "@tamagui/compose-refs",
105
+ "@tamagui/avatar",
106
+ "@tamagui/core",
107
+ "@tamagui/dialog",
108
+ "@tamagui/group",
109
+ "@tamagui/helpers-icon",
110
+ "@tamagui/helpers",
111
+ "@tamagui/image",
112
+ "@tamagui/lucide-icons",
113
+ "@tamagui/popover",
114
+ "@tamagui/popper",
115
+ "@tamagui/scroll-view",
116
+ "@tamagui/select",
117
+ "@tamagui/sheet",
118
+ "@tamagui/switch",
119
+ "@tamagui/tabs",
120
+ "@tamagui/toast",
121
+ "@tamagui/toggle-group",
122
+ "@tamagui/tooltip",
123
+ "@tamagui/use-window-dimensions",
124
+ "@tamagui/web",
125
+ "tamagui",
126
+ "react-native-web",
127
+ "react-native-web-lite",
128
+ "reforest"
129
+ ]);
130
+ return mode === "build" && depsToOptimize.push("@babel/runtime"), {
131
+ needsInterop,
132
+ depsToOptimize,
133
+ optimizeDeps: {
134
+ include: depsToOptimize,
135
+ exclude: [
136
+ "util",
137
+ "@swc/wasm",
138
+ "@swc/core-darwin-arm64"
139
+ ],
140
+ needsInterop,
141
+ esbuildOptions: {
142
+ resolveExtensions: webExtensions
143
+ }
144
+ }
145
+ };
146
+ }
147
+ export {
148
+ getOptimizeDeps
149
+ };
150
+ //# sourceMappingURL=getOptimizeDeps.js.map
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/utils/Users/n8/vxrn/packages/vxrn/src/utils/getOptimizeDeps.ts"],
4
+ "mappings": "AACA,SAASA,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEvB,SAASC,gBAAgBC,MAAuB;AACrD,MAAMC,eAAe;IACnB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;KAGIC,iBACJ,qBAAGD,YAAAA,EAAAA,OADkB;IAErB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;GACD;AAED,SAAID,SAAS,WAEXE,eAAeC,KAAK,gBAAA,GAGf;IACLF;IACAC;IACAE,cAAc;MACZC,SAASH;MACTI,SAAS;QAAC;QAAQ;QAAa;;MAC/BL;MACAM,gBAAgB;QACdC,mBAAmBV;MACrB;IACF;EACF;AACF;",
5
+ "names": ["webExtensions", "getOptimizeDeps", "mode", "needsInterop", "depsToOptimize", "push", "optimizeDeps", "include", "exclude", "esbuildOptions", "resolveExtensions"]
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vxrn",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "source": "src/index.ts",
5
5
  "types": "./types/index.d.ts",
6
6
  "type": "module",
@@ -29,13 +29,13 @@
29
29
  "@babel/code-frame": "^7.21.4",
30
30
  "@vitejs/plugin-react": "^4.2.1",
31
31
  "@vitejs/plugin-react-swc": "^3.6.0",
32
- "@vxrn/react-native-prebuilt": "0.1.47",
33
- "@vxrn/router": "0.1.47",
34
- "@vxrn/safe-area": "0.1.47",
35
- "@vxrn/vite-flow": "0.1.47",
36
- "@vxrn/vite-native-client": "0.1.47",
37
- "@vxrn/vite-native-hmr": "0.1.47",
38
- "@vxrn/vite-native-swc": "0.1.47",
32
+ "@vxrn/react-native-prebuilt": "0.1.48",
33
+ "@vxrn/router": "0.1.48",
34
+ "@vxrn/safe-area": "0.1.48",
35
+ "@vxrn/vite-flow": "0.1.48",
36
+ "@vxrn/vite-native-client": "0.1.48",
37
+ "@vxrn/vite-native-hmr": "0.1.48",
38
+ "@vxrn/vite-native-swc": "0.1.48",
39
39
  "citty": "^0.1.6",
40
40
  "crossws": "^0.2.4",
41
41
  "es-module-lexer": "^1.3.0",
@@ -47,7 +47,7 @@
47
47
  "get-port-please": "^3.1.2",
48
48
  "glob": "^10.3.12",
49
49
  "h3": "^1.11.1",
50
- "h3-proxy": "^1.12.0",
50
+ "h3-proxy": "^1.13.0",
51
51
  "import-meta-resolve": "^4.0.0",
52
52
  "jiti": "^1.21.0",
53
53
  "metro-inspector-proxy": "^0.71.0",
@@ -60,7 +60,7 @@
60
60
  "sirv": "^2.0.4",
61
61
  "source-map": "^0.7.3",
62
62
  "url": "^0.11.0",
63
- "vite": "^5.2.10",
63
+ "vite": "^5.2.11",
64
64
  "ws": "^8.7.0"
65
65
  },
66
66
  "devDependencies": {
package/src/cli.ts CHANGED
@@ -64,6 +64,11 @@ const build = defineCommand({
64
64
  type: 'string',
65
65
  required: false,
66
66
  },
67
+ // always wanted to be able to just generate one-off pages
68
+ // page: {
69
+ // type: 'string',
70
+ // required: false,
71
+ // },
67
72
  },
68
73
  async run({ args }) {
69
74
  const userConfig = await readVXRNConfig()
package/src/constants.ts CHANGED
@@ -1,5 +1,3 @@
1
- import type { UserConfig } from 'vite'
2
-
3
1
  export const DEFAULT_PORT = 8081
4
2
 
5
3
  export const nativeExtensions = [
@@ -27,76 +25,3 @@ export const webExtensions = [
27
25
  '.css',
28
26
  '.json',
29
27
  ]
30
-
31
- const needsInterop = [
32
- 'react',
33
- 'react/jsx-runtime',
34
- 'react/jsx-dev-runtime',
35
- 'react-native-web-internals',
36
- 'react-dom',
37
- 'react-native-web',
38
- 'react-dom/server',
39
- 'react-dom/client',
40
-
41
- 'url-parse',
42
- '@vxrn/safe-area',
43
- 'query-string',
44
- 'escape-string-regexp',
45
- 'use-latest-callback',
46
- 'react-is',
47
- 'fast-deep-equal',
48
- '@react-navigation/native',
49
- 'react-native-svg',
50
- '@supabase/auth-helpers-react',
51
- 'parse-numeric-range',
52
- 'use-sync-external-store',
53
- 'use-sync-external-store/shim',
54
- ]
55
-
56
- export const depsToOptimize = [
57
- ...needsInterop,
58
- 'swr',
59
- 'tamagui/linear-gradient',
60
- '@tamagui/linear-gradient',
61
- '@react-native/normalize-color',
62
- '@vxrn/router',
63
- 'expo-modules-core',
64
- 'expo-status-bar',
65
- 'react-native-web',
66
- 'react-native-web-lite',
67
- 'react-native',
68
- '@tamagui/alert-dialog',
69
- '@tamagui/avatar',
70
- '@tamagui/core',
71
- '@tamagui/dialog',
72
- '@tamagui/group',
73
- '@tamagui/helpers-icon',
74
- '@tamagui/helpers',
75
- '@tamagui/image',
76
- '@tamagui/lucide-icons',
77
- '@tamagui/popover',
78
- '@tamagui/popper',
79
- '@tamagui/scroll-view',
80
- '@tamagui/select',
81
- '@tamagui/sheet',
82
- '@tamagui/switch',
83
- '@tamagui/tabs',
84
- '@tamagui/toast',
85
- '@tamagui/toggle-group',
86
- '@tamagui/tooltip',
87
- '@tamagui/use-window-dimensions',
88
- '@tamagui/web',
89
- 'tamagui',
90
- 'react-native-web',
91
- 'react-native-web-lite',
92
- 'reforest',
93
- ]
94
-
95
- export const optimizeDeps = {
96
- include: depsToOptimize,
97
- exclude: ['util', '@swc/wasm', '@swc/core-darwin-arm64'],
98
- needsInterop,
99
- esbuildOptions: {
100
- resolveExtensions: webExtensions,
101
- },
102
- } satisfies UserConfig['optimizeDeps']
@@ -4,15 +4,16 @@ import fs from 'node:fs'
4
4
  import { tmpdir } from 'node:os'
5
5
  import path from 'node:path'
6
6
  import { mergeConfig, build as viteBuild, type UserConfig } from 'vite'
7
-
8
7
  import FSExtra from 'fs-extra'
9
8
  import type { OutputAsset, OutputChunk, RollupOutput } from 'rollup'
10
- import { optimizeDeps } from '../constants'
11
9
  import type { VXRNConfig } from '../types'
12
10
  import { getBaseViteConfig } from '../utils/getBaseViteConfig'
13
11
  import { getHtml } from '../utils/getHtml'
12
+ import { getOptimizeDeps } from '../utils/getOptimizeDeps'
14
13
  import { getOptionsFilled, type VXRNConfigFilled } from '../utils/getOptionsFilled'
15
14
 
15
+ Error.stackTraceLimit = Infinity
16
+
16
17
  export const resolveFile = (path: string) => {
17
18
  try {
18
19
  return importMetaResolve(path, import.meta.url).replace('file://', '')
@@ -23,6 +24,8 @@ export const resolveFile = (path: string) => {
23
24
 
24
25
  const { ensureDir, existsSync, readFile, pathExists } = FSExtra
25
26
 
27
+ type BuildOptions = { step?: string; page?: string }
28
+
26
29
  // web only for now
27
30
 
28
31
  // TODO:
@@ -30,12 +33,14 @@ const { ensureDir, existsSync, readFile, pathExists } = FSExtra
30
33
  // - move router stuff into router package
31
34
  // - generateStaticPages becomes a vite 'post' postbuild callback in router plugin
32
35
 
33
- export const build = async (optionsIn: VXRNConfig, { step }: { step?: string } = {}) => {
36
+ export const build = async (optionsIn: VXRNConfig, buildOptions: BuildOptions = {}) => {
34
37
  const options = await getOptionsFilled(optionsIn)
35
38
 
36
39
  // TODO?
37
40
  process.env.NODE_ENV = 'production'
38
41
 
42
+ const { optimizeDeps } = getOptimizeDeps('build')
43
+
39
44
  let webBuildConfig = mergeConfig(
40
45
  getBaseViteConfig({
41
46
  mode: 'production',
@@ -51,7 +56,7 @@ export const build = async (optionsIn: VXRNConfig, { step }: { step?: string } =
51
56
  webBuildConfig = mergeConfig(webBuildConfig, options.webConfig) as any
52
57
  }
53
58
 
54
- if (step !== 'generate') {
59
+ if (buildOptions.step !== 'generate') {
55
60
  console.info(`build client`)
56
61
  await viteBuild(
57
62
  mergeConfig(webBuildConfig, {
@@ -72,10 +77,10 @@ export const build = async (optionsIn: VXRNConfig, { step }: { step?: string } =
72
77
  // },
73
78
  // },
74
79
 
75
- // ssr: {
76
- // noExternal: true,
77
- // optimizeDeps,
78
- // },
80
+ ssr: {
81
+ noExternal: optimizeDeps.include,
82
+ optimizeDeps,
83
+ },
79
84
 
80
85
  build: {
81
86
  // we want one big file of css
@@ -86,7 +91,7 @@ export const build = async (optionsIn: VXRNConfig, { step }: { step?: string } =
86
91
  external: [],
87
92
  },
88
93
  },
89
- })
94
+ } satisfies UserConfig)
90
95
  )) as RollupOutput
91
96
 
92
97
  console.info(`generating static pages`)
@@ -112,58 +117,70 @@ async function generateStaticPages(
112
117
 
113
118
  const assets: OutputAsset[] = []
114
119
 
115
- const allRoutes = (
116
- await Promise.all(
117
- serverOutput.flatMap(async (output) => {
118
- if (output.type === 'asset') {
119
- assets.push(output)
120
- return []
121
- }
122
-
123
- const id = output.facadeModuleId || ''
124
- const file = path.basename(id)
125
- const name = file.replace(/\.[^/.]+$/, '')
126
-
127
- if (!id || file[0] === '_' || file.includes('entry-server')) {
128
- return []
129
- }
130
- if (id.includes('+api')) {
131
- return []
132
- }
133
-
134
- const endpointPath = path.join(options.root, 'dist/server', output.fileName)
135
- const exported = await import(endpointPath)
136
-
137
- const paramsList = ((await exported.generateStaticParams?.()) ?? [{}]) as Object[]
138
-
139
- return await Promise.all(
140
- paramsList.map(async (params) => {
141
- const path = getUrl(params)
142
- const loaderData = (await exported.loader?.({ path, params })) ?? {}
143
- return { path, params, loaderData }
144
- })
145
- )
146
-
147
- function getUrl(_params = {}) {
148
- return name === 'index'
149
- ? '/'
150
- : `/${name
151
- .split('/')
152
- .map((part) => {
153
- if (part[0] === '[') {
154
- const found = _params[part.slice(1, part.length - 1)]
155
- if (!found) {
156
- console.warn('not found', { _params, part })
157
- }
158
- return found
159
- }
160
- return part
161
- })
162
- .join('/')}`
163
- }
164
- })
165
- )
166
- ).flat()
120
+ const allRoutes: {
121
+ path: string
122
+ params: Object
123
+ loaderData: any
124
+ }[] = []
125
+
126
+ for (const output of serverOutput) {
127
+ if (output.type === 'asset') {
128
+ assets.push(output)
129
+ continue
130
+ }
131
+
132
+ const id = output.facadeModuleId || ''
133
+ const file = path.basename(id)
134
+ const name = file.replace(/\.[^/.]+$/, '')
135
+
136
+ if (!id || file[0] === '_' || file.includes('entry-server')) {
137
+ continue
138
+ }
139
+ if (id.includes('+api')) {
140
+ continue
141
+ }
142
+
143
+ const endpointPath = path.join(options.root, 'dist/server', output.fileName)
144
+
145
+ const exported = await import(endpointPath)
146
+
147
+ const paramsList = ((await exported.generateStaticParams?.()) ?? [{}]) as Object[]
148
+
149
+ for (const params of paramsList) {
150
+ const path = getUrl(params)
151
+ const loaderData = (await exported.loader?.({ path, params })) ?? {}
152
+ allRoutes.push({ path, params, loaderData })
153
+ }
154
+
155
+ function getUrl(_params = {}) {
156
+ if (name === 'index') {
157
+ return '/'
158
+ }
159
+ if (name.startsWith('[...')) {
160
+ const part = name.replace('[...', '').replace(']', '')
161
+ return `/${_params[part]}`
162
+ }
163
+ return `/${name
164
+ .split('/')
165
+ .map((part) => {
166
+ if (part[0] === '[') {
167
+ const found = _params[part.slice(1, part.length - 1)]
168
+ if (!found) {
169
+ console.warn('not found', { _params, part })
170
+ }
171
+ return found
172
+ }
173
+ return part
174
+ })
175
+ .join('/')}`
176
+ }
177
+ }
178
+
179
+ // can build them in parallel
180
+ // const allRoutes = (
181
+ // await Promise.all(
182
+ // )
183
+ // ).flat()
167
184
 
168
185
  // for now just inline
169
186
  const cssStringRaw = assets
@@ -189,6 +206,7 @@ async function generateStaticPages(
189
206
  for (const { path, loaderData, params } of allRoutes) {
190
207
  const loaderProps = { params }
191
208
  globalThis['__vxrnLoaderProps__'] = loaderProps
209
+ console.info(`render`, path)
192
210
  const { appHtml, headHtml } = await render({ path })
193
211
  const slashFileName = `${path === '/' ? '/index' : path}.html`
194
212
  const clientHtmlPath = toAbsolute(`dist/client${slashFileName}`)
@@ -13,7 +13,6 @@ import { createServer as nodeCreateServer } from 'node:http'
13
13
  import { dirname, join, relative, resolve } from 'node:path'
14
14
  import readline from 'node:readline'
15
15
  import { WebSocket } from 'ws'
16
-
17
16
  import * as babel from '@babel/core'
18
17
  import { buildReact, buildReactJSX, buildReactNative } from '@vxrn/react-native-prebuilt'
19
18
  import viteReactPlugin, { swcTransform, transformForBuild } from '@vxrn/vite-native-swc'
@@ -33,7 +32,7 @@ import {
33
32
  import createViteFlow from '@vxrn/vite-flow'
34
33
  import type { Peer } from 'crossws'
35
34
  import { resolve as importMetaResolve } from 'import-meta-resolve'
36
- import { depsToOptimize, nativeExtensions, optimizeDeps } from '../constants'
35
+ import { nativeExtensions } from '../constants'
37
36
  import { clientInjectionsPlugin } from '../plugins/clientInjectPlugin'
38
37
  import { reactNativeCommonJsPlugin } from '../plugins/reactNativeCommonJsPlugin'
39
38
  import type { VXRNConfig } from '../types'
@@ -41,6 +40,7 @@ import { getBaseViteConfig } from '../utils/getBaseViteConfig'
41
40
  import { getOptionsFilled, type VXRNConfigFilled } from '../utils/getOptionsFilled'
42
41
  import { getVitePath } from '../utils/getVitePath'
43
42
  import { checkPatches } from '../utils/patches'
43
+ import { getOptimizeDeps } from '../utils/getOptimizeDeps'
44
44
 
45
45
  // sorry for the mess, exploring before abstracting
46
46
 
@@ -178,7 +178,6 @@ export const dev = async ({ clean, ...rest }: VXRNConfig & { clean?: boolean })
178
178
  const { handleUpgrade } = wsAdapter(app.websocket)
179
179
 
180
180
  // vite hmr two way bridge:
181
- // vite hmr:
182
181
  app.use(
183
182
  '/__vxrnhmr',
184
183
  defineEventHandler({
@@ -295,11 +294,14 @@ export const dev = async ({ clean, ...rest }: VXRNConfig & { clean?: boolean })
295
294
  )
296
295
 
297
296
  // Define proxy event handler
298
- const proxyEventHandler = createProxyEventHandler({
299
- target: `http://127.0.0.1:${vitePort}`,
300
- enableLogger: !!process.env.DEBUG,
301
- })
302
- app.use(eventHandler(proxyEventHandler))
297
+ app.use(
298
+ eventHandler(
299
+ createProxyEventHandler({
300
+ target: `http://127.0.0.1:${vitePort}`,
301
+ enableLogger: process.env.DEBUG?.startsWith('vxrn'),
302
+ })
303
+ )
304
+ )
303
305
 
304
306
  const server = nodeCreateServer(toNodeListener(app))
305
307
 
@@ -314,21 +316,23 @@ export const dev = async ({ clean, ...rest }: VXRNConfig & { clean?: boolean })
314
316
 
315
317
  console.info(`Server running on http://localhost:${port}`)
316
318
 
317
- // bridge socket between vite
318
- if (vitePort) {
319
- socket = new WebSocket(`ws://localhost:${vitePort}/__vxrnhmr`, 'vite-hmr')
319
+ server.once('listening', () => {
320
+ // bridge socket between vite
321
+ if (vitePort) {
322
+ socket = new WebSocket(`ws://127.0.0.1:${vitePort}/__vxrnhmr`, 'vite-hmr')
320
323
 
321
- socket.on('message', (msg) => {
322
- const message = msg.toString()
323
- for (const listener of [...clients]) {
324
- listener.send(message)
325
- }
326
- })
324
+ socket.on('message', (msg) => {
325
+ const message = msg.toString()
326
+ for (const listener of [...clients]) {
327
+ listener.send(message)
328
+ }
329
+ })
327
330
 
328
- socket.on('error', (err) => {
329
- console.info('error bridging socket to vite', err)
330
- })
331
- }
331
+ socket.on('error', (err) => {
332
+ console.info('error bridging socket to vite', err)
333
+ })
334
+ }
335
+ })
332
336
 
333
337
  return {
334
338
  closePromise: new Promise((res) => viteServer.httpServer?.on('close', res)),
@@ -343,6 +347,7 @@ export const dev = async ({ clean, ...rest }: VXRNConfig & { clean?: boolean })
343
347
 
344
348
  async function getReactNativeBundle(options: VXRNConfigFilled, viteRNClientPlugin: any) {
345
349
  const { root, port, cacheDir } = options
350
+ const { depsToOptimize } = getOptimizeDeps('build')
346
351
 
347
352
  if (process.env.LOAD_TMP_BUNDLE) {
348
353
  // for easier quick testing things:
@@ -771,6 +776,7 @@ let entryRoot = ''
771
776
 
772
777
  async function getViteServerConfig(config: VXRNConfigFilled) {
773
778
  const { root, host, webConfig } = config
779
+ const { optimizeDeps } = getOptimizeDeps('serve')
774
780
 
775
781
  let serverConfig: UserConfig = mergeConfig(
776
782
  getBaseViteConfig({
@@ -792,6 +798,7 @@ async function getViteServerConfig(config: VXRNConfigFilled) {
792
798
  },
793
799
  },
794
800
  ],
801
+
795
802
  optimizeDeps,
796
803
 
797
804
  ssr: {