vxrn 0.1.20 → 0.1.21

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 (173) hide show
  1. package/dist/cjs/cli.js +77 -3
  2. package/dist/cjs/cli.js.map +2 -2
  3. package/dist/cjs/cli.native.js +268 -2
  4. package/dist/cjs/cli.native.js.map +2 -2
  5. package/dist/cjs/constants.js +21 -0
  6. package/dist/cjs/constants.js.map +6 -0
  7. package/dist/cjs/constants.native.js +26 -0
  8. package/dist/cjs/constants.native.js.map +6 -0
  9. package/dist/cjs/dispose.js +28 -0
  10. package/dist/cjs/dispose.js.map +6 -0
  11. package/dist/cjs/dispose.native.js +36 -0
  12. package/dist/cjs/dispose.native.js.map +6 -0
  13. package/dist/cjs/exports/build.js +145 -0
  14. package/dist/cjs/exports/build.js.map +6 -0
  15. package/dist/cjs/exports/build.native.js +409 -0
  16. package/dist/cjs/exports/build.native.js.map +6 -0
  17. package/dist/cjs/exports/checkPatches.js +62 -0
  18. package/dist/cjs/exports/checkPatches.js.map +6 -0
  19. package/dist/cjs/exports/checkPatches.native.js +289 -0
  20. package/dist/cjs/exports/checkPatches.native.js.map +6 -0
  21. package/dist/cjs/exports/dev.js +568 -0
  22. package/dist/cjs/exports/dev.js.map +6 -0
  23. package/dist/cjs/exports/dev.native.js +1111 -0
  24. package/dist/cjs/exports/dev.native.js.map +6 -0
  25. package/dist/cjs/exports/serve.js +55 -0
  26. package/dist/cjs/exports/serve.js.map +6 -0
  27. package/dist/cjs/exports/serve.native.js +236 -0
  28. package/dist/cjs/exports/serve.native.js.map +6 -0
  29. package/dist/cjs/index.js +2 -3
  30. package/dist/cjs/index.js.map +1 -1
  31. package/dist/cjs/index.native.js +3 -5
  32. package/dist/cjs/index.native.js.map +1 -1
  33. package/dist/cjs/plugins/clientInjectPlugin.js +66 -0
  34. package/dist/cjs/plugins/clientInjectPlugin.js.map +6 -0
  35. package/dist/cjs/plugins/clientInjectPlugin.native.js +190 -0
  36. package/dist/cjs/plugins/clientInjectPlugin.native.js.map +6 -0
  37. package/dist/cjs/plugins/reactNativeCommonJsPlugin.js +89 -0
  38. package/dist/cjs/plugins/reactNativeCommonJsPlugin.js.map +6 -0
  39. package/dist/cjs/plugins/reactNativeCommonJsPlugin.native.js +346 -0
  40. package/dist/cjs/plugins/reactNativeCommonJsPlugin.native.js.map +6 -0
  41. package/dist/cjs/utils/checkPatches.js +62 -0
  42. package/dist/cjs/utils/checkPatches.js.map +6 -0
  43. package/dist/cjs/utils/checkPatches.native.js +289 -0
  44. package/dist/cjs/utils/checkPatches.native.js.map +6 -0
  45. package/dist/cjs/utils/dispose.js +28 -0
  46. package/dist/cjs/utils/dispose.js.map +6 -0
  47. package/dist/cjs/utils/dispose.native.js +36 -0
  48. package/dist/cjs/utils/dispose.native.js.map +6 -0
  49. package/dist/cjs/utils/getBaseViteConfig.js +2 -2
  50. package/dist/cjs/utils/getBaseViteConfig.js.map +1 -1
  51. package/dist/cjs/utils/getBaseViteConfig.native.js +2 -2
  52. package/dist/cjs/utils/getBaseViteConfig.native.js.map +1 -1
  53. package/dist/cjs/utils/patches.js +62 -0
  54. package/dist/cjs/utils/patches.js.map +6 -0
  55. package/dist/cjs/utils/patches.native.js +289 -0
  56. package/dist/cjs/utils/patches.native.js.map +6 -0
  57. package/dist/cjs/utils/prerender.js +1 -0
  58. package/dist/cjs/utils/prerender.js.map +6 -0
  59. package/dist/cjs/utils/prerender.native.js +2 -0
  60. package/dist/cjs/utils/prerender.native.js.map +6 -0
  61. package/dist/cjs/vendor/createExpoServer.js +34 -0
  62. package/dist/cjs/vendor/createExpoServer.js.map +6 -0
  63. package/dist/cjs/vendor/createExpoServer.native.js +42 -0
  64. package/dist/cjs/vendor/createExpoServer.native.js.map +6 -0
  65. package/dist/esm/cli.js +58 -3
  66. package/dist/esm/cli.js.map +2 -2
  67. package/dist/esm/cli.mjs +81 -9
  68. package/dist/esm/cli.native.js +249 -3
  69. package/dist/esm/cli.native.js.map +2 -2
  70. package/dist/esm/constants.js +5 -0
  71. package/dist/esm/constants.js.map +6 -0
  72. package/dist/esm/constants.mjs +2 -0
  73. package/dist/esm/constants.native.js +5 -0
  74. package/dist/esm/constants.native.js.map +6 -0
  75. package/dist/esm/dispose.js +12 -0
  76. package/dist/esm/dispose.js.map +6 -0
  77. package/dist/esm/dispose.mjs +8 -0
  78. package/dist/esm/dispose.native.js +14 -0
  79. package/dist/esm/dispose.native.js.map +6 -0
  80. package/dist/esm/exports/build.js +128 -0
  81. package/dist/esm/exports/build.js.map +6 -0
  82. package/dist/esm/exports/build.mjs +119 -0
  83. package/dist/esm/exports/build.native.js +385 -0
  84. package/dist/esm/exports/build.native.js.map +6 -0
  85. package/dist/esm/exports/checkPatches.js +40 -0
  86. package/dist/esm/exports/checkPatches.js.map +6 -0
  87. package/dist/esm/exports/checkPatches.mjs +31 -0
  88. package/dist/esm/exports/checkPatches.native.js +262 -0
  89. package/dist/esm/exports/checkPatches.native.js.map +6 -0
  90. package/dist/esm/exports/dev.js +581 -0
  91. package/dist/esm/exports/dev.js.map +6 -0
  92. package/dist/esm/exports/dev.mjs +543 -0
  93. package/dist/esm/exports/dev.native.js +1102 -0
  94. package/dist/esm/exports/dev.native.js.map +6 -0
  95. package/dist/esm/exports/serve.js +33 -0
  96. package/dist/esm/exports/serve.js.map +6 -0
  97. package/dist/esm/exports/serve.mjs +38 -0
  98. package/dist/esm/exports/serve.native.js +209 -0
  99. package/dist/esm/exports/serve.native.js.map +6 -0
  100. package/dist/esm/index.js +3 -5
  101. package/dist/esm/index.js.map +1 -1
  102. package/dist/esm/index.mjs +3 -4
  103. package/dist/esm/index.native.js +3 -5
  104. package/dist/esm/index.native.js.map +2 -2
  105. package/dist/esm/plugins/clientInjectPlugin.js +42 -0
  106. package/dist/esm/plugins/clientInjectPlugin.js.map +6 -0
  107. package/dist/esm/plugins/clientInjectPlugin.mjs +56 -0
  108. package/dist/esm/plugins/clientInjectPlugin.native.js +161 -0
  109. package/dist/esm/plugins/clientInjectPlugin.native.js.map +6 -0
  110. package/dist/esm/plugins/reactNativeCommonJsPlugin.js +75 -0
  111. package/dist/esm/plugins/reactNativeCommonJsPlugin.js.map +6 -0
  112. package/dist/esm/plugins/reactNativeCommonJsPlugin.mjs +55 -0
  113. package/dist/esm/plugins/reactNativeCommonJsPlugin.native.js +327 -0
  114. package/dist/esm/plugins/reactNativeCommonJsPlugin.native.js.map +6 -0
  115. package/dist/esm/utils/checkPatches.js +40 -0
  116. package/dist/esm/utils/checkPatches.js.map +6 -0
  117. package/dist/esm/utils/checkPatches.mjs +31 -0
  118. package/dist/esm/utils/checkPatches.native.js +262 -0
  119. package/dist/esm/utils/checkPatches.native.js.map +6 -0
  120. package/dist/esm/utils/dispose.js +12 -0
  121. package/dist/esm/utils/dispose.js.map +6 -0
  122. package/dist/esm/utils/dispose.mjs +8 -0
  123. package/dist/esm/utils/dispose.native.js +14 -0
  124. package/dist/esm/utils/dispose.native.js.map +6 -0
  125. package/dist/esm/utils/getBaseViteConfig.js +1 -1
  126. package/dist/esm/utils/getBaseViteConfig.mjs +1 -1
  127. package/dist/esm/utils/getBaseViteConfig.native.js +1 -1
  128. package/dist/esm/utils/patches.js +40 -0
  129. package/dist/esm/utils/patches.js.map +6 -0
  130. package/dist/esm/utils/patches.mjs +31 -0
  131. package/dist/esm/utils/patches.native.js +262 -0
  132. package/dist/esm/utils/patches.native.js.map +6 -0
  133. package/dist/esm/utils/prerender.js +1 -0
  134. package/dist/esm/utils/prerender.js.map +6 -0
  135. package/dist/esm/utils/prerender.mjs +0 -0
  136. package/dist/esm/utils/prerender.native.js +1 -0
  137. package/dist/esm/utils/prerender.native.js.map +6 -0
  138. package/dist/esm/vendor/createExpoServer.js +20 -0
  139. package/dist/esm/vendor/createExpoServer.js.map +6 -0
  140. package/dist/esm/vendor/createExpoServer.mjs +17 -0
  141. package/dist/esm/vendor/createExpoServer.native.js +22 -0
  142. package/dist/esm/vendor/createExpoServer.native.js.map +6 -0
  143. package/package.json +8 -7
  144. package/src/cli.ts +78 -2
  145. package/src/{build.ts → exports/build.ts} +5 -4
  146. package/src/{createDevServer.ts → exports/dev.ts} +13 -63
  147. package/src/exports/serve.ts +51 -0
  148. package/src/index.ts +3 -3
  149. package/src/{dev → plugins}/clientInjectPlugin.ts +1 -12
  150. package/src/{nativePlugin.ts → plugins/reactNativeCommonJsPlugin.ts} +3 -26
  151. package/src/utils/getBaseViteConfig.ts +1 -1
  152. package/src/utils/patches.ts +54 -0
  153. package/types/build.d.ts +4 -4
  154. package/types/constants.d.ts +2 -0
  155. package/types/dispose.d.ts +3 -0
  156. package/types/exports/build.d.ts +4 -0
  157. package/types/exports/dev.d.ts +13 -0
  158. package/types/exports/serve.d.ts +3 -0
  159. package/types/index.d.ts +2 -3
  160. package/types/plugins/clientInjectPlugin.d.ts +7 -0
  161. package/types/plugins/reactNativeCommonJsPlugin.d.ts +7 -0
  162. package/types/utils/checkPatches.d.ts +3 -0
  163. package/types/utils/dispose.d.ts +3 -0
  164. package/types/utils/patches.d.ts +3 -0
  165. package/types/utils/prerender.d.ts +1 -0
  166. package/types/vendor/createExpoServer.d.ts +4 -0
  167. package/src/commands/cli-build.ts +0 -25
  168. package/src/commands/cli-dev.ts +0 -47
  169. package/src/commands/index.ts +0 -10
  170. package/src/dev/createDevServer.ts +0 -234
  171. /package/src/{utils/constants.ts → constants.ts} +0 -0
  172. /package/src/{utils.ts → utils/dispose.ts} +0 -0
  173. /package/src/{createExpoServer.ts → vendor/createExpoServer.ts} +0 -0
@@ -0,0 +1,51 @@
1
+ import sirv from 'sirv'
2
+ import type { VXRNConfig } from '../types'
3
+ import { getOptionsFilled } from '../utils/getOptionsFilled'
4
+ import { createApp, defineEventHandler } from 'h3'
5
+
6
+ export const serve = async (optionsIn: VXRNConfig) => {
7
+ const options = await getOptionsFilled(optionsIn)
8
+
9
+ const app = createApp()
10
+
11
+ const sirvStaticMiddleware = sirv('dist/static', {
12
+ gzip: true,
13
+ })
14
+
15
+ app.use(
16
+ defineEventHandler(async ({ node: { req, res } }) => {
17
+ await new Promise<void>((response) => {
18
+ sirvStaticMiddleware(req, res, () => {
19
+ response()
20
+ })
21
+ })
22
+ })
23
+ )
24
+
25
+ const sirvMiddleware = sirv('dist/client', {
26
+ gzip: true,
27
+ })
28
+
29
+ app.use(
30
+ defineEventHandler(async ({ node: { req, res } }) => {
31
+ await new Promise<void>((response) => {
32
+ sirvMiddleware(req, res, () => {
33
+ response()
34
+ })
35
+ })
36
+ })
37
+ )
38
+ }
39
+
40
+ // app.use(
41
+ // defineEventHandler(async ({ node: { req, res } }) => {
42
+ // const url = req.originalUrl
43
+ // const template = fs.readFileSync(path.resolve('dist/client/index.html'), 'utf-8')
44
+ // // @ts-ignore
45
+ // const render = (await import('./dist/server/entry-server.js')).render
46
+ // const appHtml = await render({ path: url })
47
+ // const html = template.replace(`<!--ssr-outlet-->`, appHtml)
48
+ // res.setHeader('Content-Type', 'text/html')
49
+ // return html
50
+ // })
51
+ // )
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { createDevServer as create } from './createDevServer'
2
- export { build } from './build'
3
- export { nativePlugin } from './nativePlugin'
1
+ export { build } from './exports/build'
2
+ export { dev } from './exports/dev'
3
+
4
4
  export * from './types'
@@ -81,15 +81,6 @@ export function clientInjectionsPlugin(config: ResolvedConfig): Plugin {
81
81
  transform(code, id, options) {
82
82
  if (id.includes('vite-native-client/dist/esm/client.')) {
83
83
  return injectConfigValues(code)
84
- } else if (!options?.ssr && code.includes('process.env.NODE_ENV')) {
85
- // replace process.env.NODE_ENV instead of defining a global
86
- // for it to avoid shimming a `process` object during dev,
87
- // avoiding inconsistencies between dev and build
88
- // return code.replace(
89
- // process_env_NODE_ENV_RE,
90
- // config.define?.['process.env.NODE_ENV'] ||
91
- // JSON.stringify(process.env.NODE_ENV || config.mode)
92
- // )
93
84
  }
94
85
  },
95
86
  }
@@ -104,9 +95,7 @@ function serializeDefine(define: Record<string, any>): string {
104
95
  let res = `{`
105
96
  for (const key in define) {
106
97
  const val = define[key]
107
- res += `${JSON.stringify(key)}: ${
108
- typeof val === 'string' ? `(${val})` : JSON.stringify(val)
109
- }, `
98
+ res += `${JSON.stringify(key)}: ${typeof val === 'string' ? `(${val})` : JSON.stringify(val)}, `
110
99
  }
111
100
  return res + `}`
112
101
  }
@@ -1,10 +1,10 @@
1
- import { dirname } from 'path'
1
+ import { dirname } from 'node:path'
2
2
 
3
3
  import { parse } from 'es-module-lexer'
4
4
  import type { OutputOptions } from 'rollup'
5
5
  import type { Plugin } from 'vite'
6
6
 
7
- import { getVitePath } from './utils/getVitePath'
7
+ import { getVitePath } from '../utils/getVitePath'
8
8
 
9
9
  const extensions = [
10
10
  '.ios.js',
@@ -19,7 +19,7 @@ const extensions = [
19
19
  '.mjs',
20
20
  ]
21
21
 
22
- export function nativePlugin(options: {
22
+ export function reactNativeCommonJsPlugin(options: {
23
23
  root: string
24
24
  port: number
25
25
  mode: 'build' | 'serve'
@@ -93,13 +93,6 @@ export function nativePlugin(options: {
93
93
 
94
94
  config.build.rollupOptions.plugins ??= []
95
95
 
96
- // config.build.rollupOptions.external = [
97
- // 'react-native',
98
- // 'react',
99
- // 'react/jsx-runtime',
100
- // 'react/jsx-dev-runtime',
101
- // ]
102
-
103
96
  if (!Array.isArray(config.build.rollupOptions.plugins)) {
104
97
  throw `x`
105
98
  }
@@ -107,22 +100,6 @@ export function nativePlugin(options: {
107
100
  if (options.mode === 'build') {
108
101
  config.plugins ||= []
109
102
 
110
- // https://vitejs.dev/config/dep-optimization-options.html
111
- // config.build.commonjsOptions ||= {}
112
- // config.build.commonjsOptions.include = []
113
-
114
- // CANT DO THIS BECAUSE TAMAGUI PLUGIN DOES THIS! they clobber each other!
115
- // config.plugins.push(
116
- // viteCommonjs({
117
- // include: ['escape-string-regexp'],
118
- // })
119
- // )
120
-
121
- // config.resolve.alias = {
122
- // ...config.resolve.alias,
123
- // 'react-native': virtualModuleId,
124
- // }
125
-
126
103
  config.build.rollupOptions.plugins.push({
127
104
  name: `force-export-all`,
128
105
 
@@ -1,5 +1,5 @@
1
1
  import type { UserConfig } from 'vite'
2
- import { resolveFile } from '../createDevServer'
2
+ import { resolveFile } from '../exports/dev'
3
3
 
4
4
  export function getBaseViteConfig({ mode }: { mode: 'development' | 'production' }): UserConfig {
5
5
  return {
@@ -0,0 +1,54 @@
1
+ import findNodeModules from 'find-node-modules'
2
+ import { join } from 'node:path'
3
+ import FSExtra from 'fs-extra'
4
+ import type { VXRNConfigFilled } from './getOptionsFilled'
5
+
6
+ const patches = [
7
+ {
8
+ module: 'react-native-screens',
9
+ patchFile: 'react-native-screens+3.22.1.patch',
10
+ },
11
+ ]
12
+ type Patch = (typeof patches)[0]
13
+
14
+ export async function checkPatches(options: VXRNConfigFilled) {
15
+ if (options.state.applyPatches === false) {
16
+ return
17
+ }
18
+
19
+ const nodeModulesDirs = findNodeModules({
20
+ cwd: options.root,
21
+ }).map((relativePath) => join(options.root, relativePath))
22
+
23
+ const patchesToCopy = new Set<Patch>()
24
+
25
+ await Promise.all(
26
+ patches.flatMap((patch) => {
27
+ return nodeModulesDirs.flatMap(async (dir) => {
28
+ if (await FSExtra.pathExists(join(dir, patch.module))) {
29
+ patchesToCopy.add(patch)
30
+ }
31
+ })
32
+ })
33
+ )
34
+
35
+ let didCopy = false
36
+
37
+ for (const patch of [...patchesToCopy]) {
38
+ const dest = join(options.userPatchesDir, patch.patchFile)
39
+ if (!(await FSExtra.pathExists(dest))) {
40
+ didCopy = true
41
+ console.info(`Copying patch ${patch.module}`)
42
+ const src = join(options.internalPatchesDir, patch.patchFile)
43
+ await FSExtra.copy(src, dest)
44
+ }
45
+ }
46
+
47
+ if (didCopy) {
48
+ console.info(
49
+ `\nPlease restart after applying the patch by running "npx patch-package".
50
+ Ideally add it to your devDependencies and as a postinstall script.\n`
51
+ )
52
+ process.exit(0)
53
+ }
54
+ }
package/types/build.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { VXRNConfig } from './types';
2
- export declare const resolveFile: (path: string) => string;
3
- export declare const build: (optionsIn: VXRNConfig) => Promise<void>;
4
- //# sourceMappingURL=build.d.ts.map
1
+ import type { VXRNConfig } from '../types'
2
+ export declare const resolveFile: (path: string) => string
3
+ export declare const build: (optionsIn: VXRNConfig) => Promise<void>
4
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_PORT = 8081;
2
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1,3 @@
1
+ export declare function registerDispose(cb: () => void): void;
2
+ export declare function disposeAll(): void;
3
+ //# sourceMappingURL=dispose.d.ts.map
@@ -0,0 +1,4 @@
1
+ import type { VXRNConfig } from '../types';
2
+ export declare const resolveFile: (path: string) => string;
3
+ export declare const build: (optionsIn: VXRNConfig) => Promise<void>;
4
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import type { VXRNConfig } from '../types';
3
+ export declare const resolveFile: (path: string) => string;
4
+ export declare const dev: (optionsIn: VXRNConfig) => Promise<{
5
+ server: import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
6
+ viteServer: import("vite").ViteDevServer;
7
+ start(): Promise<{
8
+ closePromise: Promise<unknown>;
9
+ }>;
10
+ stop: () => Promise<void>;
11
+ }>;
12
+ export declare function bindKeypressInput(): void;
13
+ //# sourceMappingURL=dev.d.ts.map
@@ -0,0 +1,3 @@
1
+ import type { VXRNConfig } from '../types';
2
+ export declare const serve: (optionsIn: VXRNConfig) => Promise<void>;
3
+ //# sourceMappingURL=serve.d.ts.map
package/types/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- export { createDevServer as create } from './createDevServer';
2
- export { build } from './build';
3
- export { nativePlugin } from './nativePlugin';
1
+ export { build } from './exports/build';
2
+ export { dev } from './exports/dev';
4
3
  export * from './types';
5
4
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,7 @@
1
+ import type { Plugin, ResolvedConfig } from 'vite';
2
+ /**
3
+ * some values used by the client needs to be dynamically injected by the server
4
+ * @server-only
5
+ */
6
+ export declare function clientInjectionsPlugin(config: ResolvedConfig): Plugin;
7
+ //# sourceMappingURL=clientInjectPlugin.d.ts.map
@@ -0,0 +1,7 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare function reactNativeCommonJsPlugin(options: {
3
+ root: string;
4
+ port: number;
5
+ mode: 'build' | 'serve';
6
+ }): Plugin;
7
+ //# sourceMappingURL=reactNativeCommonJsPlugin.d.ts.map
@@ -0,0 +1,3 @@
1
+ import { type VXRNConfigFilled } from './getOptionsFilled';
2
+ export declare function checkPatches(options: VXRNConfigFilled): Promise<void>;
3
+ //# sourceMappingURL=checkPatches.d.ts.map
@@ -0,0 +1,3 @@
1
+ export declare function registerDispose(cb: () => void): void;
2
+ export declare function disposeAll(): void;
3
+ //# sourceMappingURL=dispose.d.ts.map
@@ -0,0 +1,3 @@
1
+ import type { VXRNConfigFilled } from './getOptionsFilled';
2
+ export declare function checkPatches(options: VXRNConfigFilled): Promise<void>;
3
+ //# sourceMappingURL=patches.d.ts.map
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=prerender.d.ts.map
@@ -0,0 +1,4 @@
1
+ import type { App } from 'h3';
2
+ export declare function createExpoServer(root: string, app: App): void;
3
+ export declare function getRoutePaths(cwd: string): string[];
4
+ //# sourceMappingURL=createExpoServer.d.ts.map
@@ -1,25 +0,0 @@
1
- import { defineCommand } from 'citty'
2
- import { build } from '../build'
3
- import { readVXRNConfig } from '../utils/readVXRNConfig'
4
-
5
- export default defineCommand({
6
- meta: {
7
- name: 'build',
8
- version: '0.0.0',
9
- description: 'Build your app',
10
- },
11
- args: {},
12
- async run({ args }) {
13
- const userConfig = await readVXRNConfig()
14
-
15
- process.on('uncaughtException', (err) => {
16
- console.error(err?.message || err)
17
- })
18
-
19
- const results = await build(userConfig)
20
-
21
- if (process.env.DEBUG) {
22
- console.info('results', results)
23
- }
24
- },
25
- })
@@ -1,47 +0,0 @@
1
- import { defineCommand } from 'citty'
2
- import { readVXRNConfig } from '../utils/readVXRNConfig'
3
- import { createDevServer } from '../createDevServer'
4
-
5
- export default defineCommand({
6
- meta: {
7
- name: 'dev',
8
- version: '0.0.0',
9
- description: 'Start the dev server',
10
- },
11
- args: {},
12
- async run({ args }) {
13
- const userConfig = await readVXRNConfig()
14
-
15
- const { start, stop } = await createDevServer({
16
- root: process.cwd(),
17
- host: '127.0.0.1',
18
- webConfig: {
19
- plugins: [],
20
- },
21
- buildConfig: {
22
- plugins: [],
23
- },
24
- flow: {
25
- include: [],
26
- exclude: [],
27
- },
28
- ...userConfig,
29
- })
30
-
31
- const { closePromise } = await start()
32
-
33
- process.on('beforeExit', () => {
34
- stop()
35
- })
36
-
37
- process.on('SIGINT', () => {
38
- stop()
39
- })
40
-
41
- process.on('uncaughtException', (err) => {
42
- console.error(err?.message || err)
43
- })
44
-
45
- await closePromise
46
- },
47
- })
@@ -1,10 +0,0 @@
1
- import type { CommandDef } from 'citty'
2
-
3
- const runDefault = (r: any) => (r.default || r) as Promise<CommandDef>
4
-
5
- export const commands = {
6
- // @ts-ignore
7
- dev: () => import('./cli-dev.mjs').then(runDefault),
8
- // @ts-ignore
9
- build: () => import('./cli-build.mjs').then(runDefault),
10
- }
@@ -1,234 +0,0 @@
1
- // import mime from 'mime/lite'
2
-
3
- // import type { HMRListener } from '../types'
4
- // import { DEFAULT_PORT } from '../utils/constants'
5
- // import { type Server, createServer } from '../vendor/repack/dev-server/src'
6
- // import { bindKeypressInput } from './bindKeypressInput'
7
-
8
- // export async function createDevServer(
9
- // options: {
10
- // host: string
11
- // port: number
12
- // root: string
13
- // },
14
- // {
15
- // listenForHMR,
16
- // hotUpdatedCJSFiles,
17
- // }: {
18
- // listenForHMR: (cb: HMRListener) => void
19
- // hotUpdatedCJSFiles: Map<string, string>
20
- // }
21
- // ) {
22
- // return await createServer({
23
- // options: {
24
- // rootDir: options.root,
25
- // host: options.host,
26
- // port: options.port ?? DEFAULT_PORT,
27
- // // https: args.https
28
- // // ? {
29
- // // cert: args.cert,
30
- // // key: args.key,
31
- // // }
32
- // // : undefined,
33
- // },
34
-
35
- // delegate: (ctx): Server.Delegate => {
36
- // bindKeypressInput(ctx)
37
-
38
- // // if (reversePort && args.port) {
39
- // // runAdbReverse(ctx, args.port)
40
- // // }
41
-
42
- // // let lastStats: webpack.StatsCompilation | undefined
43
-
44
- // // compiler.on('watchRun', ({ platform }) => {
45
- // // ctx.notifyBuildStart(platform)
46
- // // if (platform === 'android') {
47
- // // runAdbReverse(ctx, args.port ?? DEFAULT_PORT)
48
- // // }
49
- // // })
50
-
51
- // // compiler.on('invalid', ({ platform }) => {
52
- // // ctx.notifyBuildStart(platform)
53
- // // ctx.broadcastToHmrClients({ action: 'building' }, platform)
54
- // // })
55
-
56
- // const platform = 'ios'
57
- // listenForHMR((update) => {
58
- // ctx.notifyBuildEnd(platform)
59
- // ctx.broadcastToHmrClients(
60
- // {
61
- // action: 'built',
62
- // body: createHmrBody({
63
- // errors: [],
64
- // warnings: [],
65
- // hash: `${Math.random()}`,
66
- // modules: {},
67
- // name: '',
68
- // time: 0,
69
- // }),
70
- // },
71
- // platform
72
- // )
73
- // })
74
-
75
- // return {
76
- // hotFiles: {
77
- // getSource: (path) => {
78
- // const next = hotUpdatedCJSFiles.get(path)
79
- // // hotUpdatedCJSFiles.delete(path) // memory leak prevent
80
- // return next || ''
81
- // },
82
- // },
83
-
84
- // compiler: {
85
- // getAsset: async (filename, platform, sendProgress) => {
86
- // console.info('[GET] - ', filename)
87
- // return ''
88
- // // return (await compiler.getAsset(filename, platform, sendProgress)).data
89
- // },
90
-
91
- // getMimeType: (filename) => {
92
- // return mime.getType(filename) || 'application/javascript'
93
- // },
94
-
95
- // inferPlatform: (uri) => {
96
- // const url = new URL(uri, 'protocol://domain')
97
- // if (!url.searchParams.get('platform')) {
98
- // const [, platform] = /^\/(.+)\/.+$/.exec(url.pathname) ?? []
99
- // return platform
100
- // }
101
-
102
- // return undefined
103
- // },
104
- // },
105
-
106
- // symbolicator: {
107
- // getSource: async (fileUrl) => {
108
- // console.info('get source', fileUrl)
109
- // // const { filename, platform } = parseFileUrl(fileUrl)
110
- // // return compiler.getSource(filename, platform)
111
- // return ''
112
- // },
113
- // getSourceMap: async (fileUrl) => {
114
- // // const { filename, platform } = parseFileUrl(fileUrl)
115
- // // if (!platform) {
116
- // // throw new Error('Cannot infer platform for file URL')
117
- // // }
118
-
119
- // // return compiler.getSourceMap(filename, platform)
120
- // return ''
121
- // },
122
- // shouldIncludeFrame: (frame) => {
123
- // // If the frame points to internal bootstrap/module system logic, skip the code frame.
124
- // return !/webpack[/\\]runtime[/\\].+\s/.test(frame.file)
125
- // },
126
- // },
127
-
128
- // hmr: {
129
- // getUriPath: () => '/__hmr',
130
- // onClientConnected: (platform, clientId) => {
131
- // // todo
132
- // // const lastStats = {}
133
- // // ctx.broadcastToHmrClients(
134
- // // { action: 'sync', body: createHmrBody(lastStats) },
135
- // // platform,
136
- // // [clientId]
137
- // // )
138
- // },
139
- // },
140
-
141
- // messages: {
142
- // getStatus: () => 'packager-status:running',
143
- // },
144
-
145
- // logger: {
146
- // onMessage: (log) => {
147
- // const logEntry = makeLogEntryFromFastifyLog(log)
148
- // logEntry.issuer = 'DevServer'
149
-
150
- // // ignore for now
151
- // if (logEntry.type === 'debug') return
152
-
153
- // // error DevServer, warn DevServer
154
- // console.info(
155
- // '[logger]',
156
- // logEntry.type === 'info' ? '' : logEntry.type,
157
- // logEntry.message
158
- // .map((m) => {
159
- // return `${m.msg}`
160
- // })
161
- // .join(', ')
162
- // )
163
- // // reporter.process(logEntry)
164
- // },
165
- // },
166
-
167
- // api: {
168
- // // getPlatforms: async () => Object.keys(compiler.workers),
169
- // getPlatforms: async () => ['ios'],
170
- // getAssets: async (platform) => {
171
- // console.info('get assets', platform)
172
- // return []
173
- // // return Object.entries(compiler.assetsCache[platform] ?? {}).map(([name, asset]) => ({
174
- // // name,
175
- // // size: asset.info.size,
176
- // // })),
177
- // },
178
- // getCompilationStats: async (platform) => {
179
- // return null
180
- // // return compiler.statsCache[platform] ?? null
181
- // },
182
- // },
183
- // }
184
- // },
185
- // })
186
- // }
187
-
188
- // function createHmrBody(body: HMRMessageBody): HMRMessageBody | null {
189
- // return body
190
- // }
191
-
192
- // /**
193
- // * Represent Hot Module Replacement Update body.
194
- // *
195
- // * @internal
196
- // */
197
- // export interface HMRMessageBody {
198
- // name: string
199
- // time: number
200
- // hash: string
201
- // warnings: any
202
- // errors: any
203
- // modules: Record<string, string>
204
- // }
205
-
206
- // /**
207
- // * Represent Hot Module Replacement Update message.
208
- // *
209
- // * @internal
210
- // */
211
- // export interface HMRMessage {
212
- // action: 'building' | 'built' | 'sync'
213
- // body: HMRMessageBody | null
214
- // }
215
-
216
- // function makeLogEntryFromFastifyLog(data: any): any {
217
- // const { level, time, pid, hostname, ...rest } = data
218
-
219
- // const levelToTypeMapping: Record<number, any> = {
220
- // 10: 'debug',
221
- // 20: 'debug',
222
- // 30: 'info',
223
- // 40: 'warn',
224
- // 50: 'error',
225
- // 60: 'error',
226
- // }
227
-
228
- // return {
229
- // type: levelToTypeMapping[level],
230
- // timestamp: time,
231
- // issuer: '',
232
- // message: [rest],
233
- // }
234
- // }
File without changes
File without changes