vxrn 0.1.44 → 0.1.46

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 (93) hide show
  1. package/dist/cjs/cli.js +6 -1
  2. package/dist/cjs/cli.js.map +1 -1
  3. package/dist/cjs/cli.native.js +6 -1
  4. package/dist/cjs/cli.native.js.map +2 -2
  5. package/dist/cjs/constants.js +2 -1
  6. package/dist/cjs/constants.js.map +1 -1
  7. package/dist/cjs/constants.native.js +3 -1
  8. package/dist/cjs/constants.native.js.map +2 -2
  9. package/dist/cjs/exports/build.js +5 -5
  10. package/dist/cjs/exports/build.js.map +1 -1
  11. package/dist/cjs/exports/build.native.js +8 -9
  12. package/dist/cjs/exports/build.native.js.map +2 -2
  13. package/dist/cjs/exports/dev.js +26 -5
  14. package/dist/cjs/exports/dev.js.map +1 -1
  15. package/dist/cjs/exports/dev.native.js +101 -22
  16. package/dist/cjs/exports/dev.native.js.map +2 -2
  17. package/dist/cjs/plugins/reactNativeCommonJsPlugin.js +1 -1
  18. package/dist/cjs/plugins/reactNativeCommonJsPlugin.js.map +1 -1
  19. package/dist/cjs/plugins/reactNativeCommonJsPlugin.native.js +1 -1
  20. package/dist/cjs/plugins/reactNativeCommonJsPlugin.native.js.map +2 -2
  21. package/dist/cjs/types.native.js.map +1 -1
  22. package/dist/cjs/utils/getBaseViteConfig.js.map +1 -1
  23. package/dist/cjs/utils/getBaseViteConfig.native.js.map +1 -1
  24. package/dist/cjs/utils/getHtml.js +10 -4
  25. package/dist/cjs/utils/getHtml.js.map +1 -1
  26. package/dist/cjs/utils/getHtml.native.js +8 -3
  27. package/dist/cjs/utils/getHtml.native.js.map +2 -2
  28. package/dist/cjs/utils/getOptionsFilled.js +7 -2
  29. package/dist/cjs/utils/getOptionsFilled.js.map +1 -1
  30. package/dist/cjs/utils/getOptionsFilled.native.js +7 -3
  31. package/dist/cjs/utils/getOptionsFilled.native.js.map +2 -2
  32. package/dist/cjs/utils/readVXRNConfig.js +13 -4
  33. package/dist/cjs/utils/readVXRNConfig.js.map +1 -1
  34. package/dist/cjs/utils/readVXRNConfig.native.js +40 -9
  35. package/dist/cjs/utils/readVXRNConfig.native.js.map +2 -2
  36. package/dist/esm/cli.js +6 -1
  37. package/dist/esm/cli.js.map +1 -1
  38. package/dist/esm/cli.mjs +6 -1
  39. package/dist/esm/cli.native.js +6 -1
  40. package/dist/esm/cli.native.js.map +2 -2
  41. package/dist/esm/constants.js +2 -1
  42. package/dist/esm/constants.js.map +1 -1
  43. package/dist/esm/constants.mjs +2 -1
  44. package/dist/esm/constants.native.js +2 -1
  45. package/dist/esm/constants.native.js.map +2 -2
  46. package/dist/esm/exports/build.js +5 -5
  47. package/dist/esm/exports/build.js.map +1 -1
  48. package/dist/esm/exports/build.mjs +5 -6
  49. package/dist/esm/exports/build.native.js +8 -9
  50. package/dist/esm/exports/build.native.js.map +2 -2
  51. package/dist/esm/exports/dev.js +27 -6
  52. package/dist/esm/exports/dev.js.map +1 -1
  53. package/dist/esm/exports/dev.mjs +25 -6
  54. package/dist/esm/exports/dev.native.js +102 -23
  55. package/dist/esm/exports/dev.native.js.map +2 -2
  56. package/dist/esm/plugins/reactNativeCommonJsPlugin.js +1 -1
  57. package/dist/esm/plugins/reactNativeCommonJsPlugin.js.map +1 -1
  58. package/dist/esm/plugins/reactNativeCommonJsPlugin.mjs +1 -1
  59. package/dist/esm/plugins/reactNativeCommonJsPlugin.native.js +1 -1
  60. package/dist/esm/plugins/reactNativeCommonJsPlugin.native.js.map +2 -2
  61. package/dist/esm/utils/getBaseViteConfig.js.map +1 -1
  62. package/dist/esm/utils/getBaseViteConfig.native.js.map +1 -1
  63. package/dist/esm/utils/getHtml.js +10 -4
  64. package/dist/esm/utils/getHtml.js.map +1 -1
  65. package/dist/esm/utils/getHtml.mjs +6 -4
  66. package/dist/esm/utils/getHtml.native.js +8 -3
  67. package/dist/esm/utils/getHtml.native.js.map +2 -2
  68. package/dist/esm/utils/getOptionsFilled.js +7 -2
  69. package/dist/esm/utils/getOptionsFilled.js.map +1 -1
  70. package/dist/esm/utils/getOptionsFilled.mjs +8 -2
  71. package/dist/esm/utils/getOptionsFilled.native.js +7 -3
  72. package/dist/esm/utils/getOptionsFilled.native.js.map +2 -2
  73. package/dist/esm/utils/readVXRNConfig.js +13 -4
  74. package/dist/esm/utils/readVXRNConfig.js.map +1 -1
  75. package/dist/esm/utils/readVXRNConfig.mjs +11 -4
  76. package/dist/esm/utils/readVXRNConfig.native.js +40 -9
  77. package/dist/esm/utils/readVXRNConfig.native.js.map +2 -2
  78. package/package.json +8 -9
  79. package/src/cli.ts +6 -1
  80. package/src/constants.ts +4 -1
  81. package/src/exports/build.ts +10 -6
  82. package/src/exports/dev.ts +54 -17
  83. package/src/plugins/reactNativeCommonJsPlugin.ts +0 -2
  84. package/src/types.ts +11 -1
  85. package/src/utils/getBaseViteConfig.ts +2 -0
  86. package/src/utils/getHtml.ts +12 -4
  87. package/src/utils/getOptionsFilled.ts +7 -2
  88. package/src/utils/readVXRNConfig.ts +22 -10
  89. package/types/constants.d.ts +1 -0
  90. package/types/exports/dev.d.ts +3 -1
  91. package/types/types.d.ts +11 -1
  92. package/types/utils/getHtml.d.ts +2 -2
  93. package/types/utils/getOptionsFilled.d.ts +4 -1
@@ -8,7 +8,7 @@ import {
8
8
  toNodeListener,
9
9
  } from 'h3'
10
10
  import { createProxyEventHandler } from 'h3-proxy'
11
- import { readFile } from 'node:fs/promises'
11
+ import { readFile, rm } from 'node:fs/promises'
12
12
  import { createServer as nodeCreateServer } from 'node:http'
13
13
  import { dirname, join, relative, resolve } from 'node:path'
14
14
  import readline from 'node:readline'
@@ -33,7 +33,7 @@ import {
33
33
  import createViteFlow from '@vxrn/vite-flow'
34
34
  import type { Peer } from 'crossws'
35
35
  import { resolve as importMetaResolve } from 'import-meta-resolve'
36
- import { depsToOptimize, nativeExtensions, optimizeDeps, webExtensions } from '../constants'
36
+ import { depsToOptimize, nativeExtensions, optimizeDeps } from '../constants'
37
37
  import { clientInjectionsPlugin } from '../plugins/clientInjectPlugin'
38
38
  import { reactNativeCommonJsPlugin } from '../plugins/reactNativeCommonJsPlugin'
39
39
  import type { VXRNConfig } from '../types'
@@ -57,10 +57,27 @@ export const resolveFile = (path: string) => {
57
57
 
58
58
  const { ensureDir, pathExists, pathExistsSync } = FSExtra
59
59
 
60
- export const dev = async (_options: VXRNConfig) => {
61
- const options = await getOptionsFilled(_options)
60
+ export const dev = async ({ clean, ...rest }: VXRNConfig & { clean?: boolean }) => {
61
+ const options = await getOptionsFilled(rest)
62
62
  const { host, port, root, cacheDir } = options
63
63
 
64
+ if (clean) {
65
+ try {
66
+ console.info(` [vxrn] cleaning node_modules/.vite`)
67
+ await rm(join(root, 'node_modules', '.vite'), {
68
+ recursive: true,
69
+ force: true,
70
+ })
71
+ } catch (err) {
72
+ if (err instanceof Error) {
73
+ // @ts-expect-error wtf
74
+ if (err.code !== 'ENOENT') {
75
+ throw Error
76
+ }
77
+ }
78
+ }
79
+ }
80
+
64
81
  // TODO move somewhere
65
82
  bindKeypressInput()
66
83
 
@@ -369,7 +386,6 @@ async function getReactNativeBundle(options: VXRNConfigFilled, viteRNClientPlugi
369
386
 
370
387
  {
371
388
  name: 'reanimated',
372
-
373
389
  async transform(code, id) {
374
390
  if (code.includes('worklet')) {
375
391
  const out = await babelReanimated(code, id)
@@ -394,7 +410,7 @@ async function getReactNativeBundle(options: VXRNConfigFilled, viteRNClientPlugi
394
410
  {
395
411
  name: 'treat-js-files-as-jsx',
396
412
  async transform(code, id) {
397
- if (!id.match(/expo-status-bar/)) return null
413
+ if (!id.includes(`expo-status-bar`)) return null
398
414
  // Use the exposed transform from vite, instead of directly
399
415
  // transforming with esbuild
400
416
  return transformWithEsbuild(code, id, {
@@ -404,6 +420,7 @@ async function getReactNativeBundle(options: VXRNConfigFilled, viteRNClientPlugi
404
420
  },
405
421
  },
406
422
  ].filter(Boolean),
423
+
407
424
  appType: 'custom',
408
425
  root,
409
426
  clearScreen: false,
@@ -432,6 +449,7 @@ async function getReactNativeBundle(options: VXRNConfigFilled, viteRNClientPlugi
432
449
  transformMixedEsModules: true,
433
450
  },
434
451
  rollupOptions: {
452
+ input: options.entries.native,
435
453
  treeshake: false,
436
454
  preserveEntrySignatures: 'strict',
437
455
  output: {
@@ -446,13 +464,9 @@ async function getReactNativeBundle(options: VXRNConfigFilled, viteRNClientPlugi
446
464
  nativeBuildConfig = mergeConfig(nativeBuildConfig, options.nativeConfig) as any
447
465
  }
448
466
 
449
- // this fixes my swap-react-native plugin not being called pre 😳
467
+ // // this fixes my swap-react-native plugin not being called pre 😳
450
468
  await resolveConfig(nativeBuildConfig, 'build')
451
469
 
452
- // seems to be not working but needed to put it after the resolve or else it was cleared
453
- // @ts-ignore
454
- // nativeBuildConfig.build.rollupOptions.input = join(root, buildInput)
455
-
456
470
  const buildOutput = await build(nativeBuildConfig)
457
471
 
458
472
  if (!('output' in buildOutput)) {
@@ -503,11 +517,6 @@ __require("${outputModule.fileName}")
503
517
  }
504
518
 
505
519
  appCode = appCode
506
- // this can be done in the individual file transform
507
- .replaceAll('undefined.accept(() => {})', '')
508
- .replaceAll('undefined.accept(function() {});', '')
509
- .replaceAll('(void 0).accept(() => {})', '')
510
- .replaceAll('(void 0).accept(function() {});', '')
511
520
  // TEMP FIX for router tamagui thing since expo router 3 upgrade
512
521
  .replaceAll('dist/esm/index.mjs"', 'dist/esm/index.js"')
513
522
 
@@ -756,6 +765,21 @@ function isWithin(outer: string, inner: string) {
756
765
  // used for normalizing hot reloads
757
766
  let entryRoot = ''
758
767
 
768
+ // function watchNodeModules(modules: string[]): PluginOption {
769
+ // return {
770
+ // name: 'watch-node-modules',
771
+ // config() {
772
+ // return {
773
+ // server: {
774
+ // watch: {
775
+ // ignored: modules.map((m) => `!**/packages/${m}/**`),
776
+ // },
777
+ // },
778
+ // }
779
+ // },
780
+ // }
781
+ // }
782
+
759
783
  async function getViteServerConfig(config: VXRNConfigFilled) {
760
784
  const { root, host, webConfig, cacheDir } = config
761
785
 
@@ -766,7 +790,20 @@ async function getViteServerConfig(config: VXRNConfigFilled) {
766
790
  {
767
791
  root,
768
792
  clearScreen: false,
769
- plugins: [reactNativeHMRPlugin(config)],
793
+ plugins: [
794
+ reactNativeHMRPlugin(config),
795
+ // watchNodeModules(['@tamagui/popper'])
796
+
797
+ {
798
+ name: 'process-env-ssr',
799
+ transform(code, id, options) {
800
+ if (id.includes('node_modules')) return
801
+ if (code.includes('process.env.TAMAGUI_IS_SERVER')) {
802
+ return code.replaceAll('process.env.TAMAGUI_IS_SERVER', `${!!options?.ssr}`)
803
+ }
804
+ },
805
+ },
806
+ ],
770
807
  optimizeDeps,
771
808
  ssr: {
772
809
  noExternal: true,
@@ -87,8 +87,6 @@ export function reactNativeCommonJsPlugin(options: {
87
87
 
88
88
  config.build.rollupOptions ??= {}
89
89
 
90
- config.build.rollupOptions.input = config.root
91
-
92
90
  config.build.rollupOptions.output ??= {}
93
91
 
94
92
  config.build.rollupOptions.plugins ??= []
package/src/types.ts CHANGED
@@ -2,7 +2,17 @@ import type { Options as FlowOptions } from '@vxrn/vite-flow'
2
2
  import type { InlineConfig } from 'vite'
3
3
 
4
4
  export type VXRNConfig = {
5
- entryNative?: string
5
+ /**
6
+ * The entry points to your app. For web, it uses your `root` and looks for an index.html
7
+ *
8
+ * Defaults:
9
+ * native: ./src/entry-native.tsx
10
+ * server: ./src/entry-server.tsx
11
+ */
12
+ entries?: {
13
+ native?: string
14
+ server?: string
15
+ }
6
16
  root?: string
7
17
  host?: string
8
18
  port?: number
@@ -13,12 +13,14 @@ export function getBaseViteConfig({ mode }: { mode: 'development' | 'production'
13
13
  __DEV__: `${mode === 'development'}`,
14
14
  'process.env.NODE_ENV': `"${mode}"`,
15
15
  },
16
+
16
17
  resolve: {
17
18
  alias: {
18
19
  'react-native': 'react-native-web',
19
20
  'react-native-safe-area-context': '@vxrn/safe-area',
20
21
  },
21
22
  },
23
+
22
24
  build: {
23
25
  commonjsOptions: {
24
26
  transformMixedEsModules: true,
@@ -1,12 +1,20 @@
1
1
  export function getHtml({
2
2
  template,
3
- props,
3
+ loaderData,
4
4
  appHtml,
5
5
  headHtml,
6
6
  css,
7
- }: { css?: string; template: string; props: Object; appHtml: string; headHtml: string }) {
8
- const propsHtml = `\n<script>globalThis['__vxrnProps']=${JSON.stringify(props)}</script>`
7
+ }: { css?: string; template: string; loaderData: Object; appHtml: string; headHtml: string }) {
8
+ if (!template.includes(`<!--ssr-outlet-->`)) {
9
+ throw new Error(`No <!--ssr-outlet--> found in html to inject SSR contents`)
10
+ }
11
+ if (!template.includes(`<!--head-outlet-->`)) {
12
+ throw new Error(`No <!--head-outlet--> found in html to inject SSR contents`)
13
+ }
14
+ const loaderDataString = `\n<script>globalThis['__vxrnLoaderData__']=${JSON.stringify(
15
+ loaderData
16
+ )}</script>`
9
17
  return template
10
- .replace(`<!--ssr-outlet-->`, appHtml + propsHtml)
18
+ .replace(`<!--ssr-outlet-->`, appHtml + loaderDataString)
11
19
  .replace(`<!--head-outlet-->`, `${headHtml}\n${css ? `<style>${css}</style>` : ``}`)
12
20
  }
@@ -10,7 +10,7 @@ const require = createRequire(import.meta.url)
10
10
  export type VXRNConfigFilled = Awaited<ReturnType<typeof getOptionsFilled>>
11
11
 
12
12
  export async function getOptionsFilled(options: VXRNConfig) {
13
- const { host = '127.0.0.1', root = process.cwd() } = options
13
+ const { host = '127.0.0.1', root = process.cwd(), entries } = options
14
14
 
15
15
  const defaultPort = options.port || 8081
16
16
  const port = await getPort({
@@ -20,7 +20,7 @@ export async function getOptionsFilled(options: VXRNConfig) {
20
20
 
21
21
  const packageRootDir = join(require.resolve('vxrn'), '../../..')
22
22
 
23
- const cacheDir = join(root, 'node_modules', '.cache', 'vxrn')
23
+ const cacheDir = join(root, 'node_modules', '.vxrn')
24
24
  const internalPatchesDir = join(packageRootDir, 'patches')
25
25
  const userPatchesDir = join(root, 'patches')
26
26
  const [state, packageJSON] = await Promise.all([
@@ -30,6 +30,11 @@ export async function getOptionsFilled(options: VXRNConfig) {
30
30
  ])
31
31
  return {
32
32
  ...options,
33
+ entries: {
34
+ native: './src/entry-native.tsx',
35
+ server: './src/entry-server.tsx',
36
+ ...entries,
37
+ },
33
38
  packageJSON,
34
39
  state,
35
40
  packageRootDir,
@@ -8,6 +8,14 @@ export async function readVXRNConfig(): Promise<VXRNConfig> {
8
8
  return {}
9
9
  }
10
10
 
11
+ if (process.env.VXRN_CJS) {
12
+ const requireFile = jiti(process.cwd(), {
13
+ esmResolve: true,
14
+ })
15
+ const userConfig = requireFile('./vxrn.config.ts')
16
+ return resolveOptionalAsyncFunction(userConfig?.default ?? {})
17
+ }
18
+
11
19
  // try esm load
12
20
  try {
13
21
  // somewhat hacky creating a server just to read config?
@@ -21,17 +29,21 @@ export async function readVXRNConfig(): Promise<VXRNConfig> {
21
29
  })
22
30
 
23
31
  await vite.close()
24
- return userConfig?.default ?? {}
32
+ return resolveOptionalAsyncFunction(userConfig?.default ?? {})
25
33
  } catch (err) {
26
- console.info(`Error loading config via ESM, attempting CJS, DEBUG=1 to see logs`)
27
- if (process.env.DEBUG) {
28
- console.info(err)
29
- }
34
+ console.info(
35
+ ` [vxrn] Error loading config via ESM, attempting CJS, set VXRN_CJS=1 to run in cjs mode`
36
+ )
37
+ throw err
38
+ }
39
+ }
30
40
 
31
- const requireFile = jiti(process.cwd(), {
32
- esmResolve: true,
33
- })
34
- const userConfig = requireFile('./vxrn.config.ts')
35
- return userConfig?.default ?? {}
41
+ async function resolveOptionalAsyncFunction(value: any) {
42
+ if (typeof value === 'function') {
43
+ value = value()
44
+ }
45
+ if (value instanceof Promise) {
46
+ value = await value
36
47
  }
48
+ return value
37
49
  }
@@ -1,4 +1,5 @@
1
1
  export declare const DEFAULT_PORT = 8081;
2
+ export declare const EMPTY_LOADER_STRING = "function loader() {/* \u2737\u2737\u2737 */};";
2
3
  export declare const nativeExtensions: string[];
3
4
  export declare const webExtensions: string[];
4
5
  export declare const depsToOptimize: string[];
@@ -1,7 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  import type { VXRNConfig } from '../types';
3
3
  export declare const resolveFile: (path: string) => string;
4
- export declare const dev: (_options: VXRNConfig) => Promise<{
4
+ export declare const dev: ({ clean, ...rest }: VXRNConfig & {
5
+ clean?: boolean;
6
+ }) => Promise<{
5
7
  server: import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
6
8
  viteServer: import("vite").ViteDevServer;
7
9
  start(): Promise<{
package/types/types.d.ts CHANGED
@@ -1,7 +1,17 @@
1
1
  import type { Options as FlowOptions } from '@vxrn/vite-flow';
2
2
  import type { InlineConfig } from 'vite';
3
3
  export type VXRNConfig = {
4
- entryNative?: string;
4
+ /**
5
+ * The entry points to your app. For web, it uses your `root` and looks for an index.html
6
+ *
7
+ * Defaults:
8
+ * native: ./src/entry-native.tsx
9
+ * server: ./src/entry-server.tsx
10
+ */
11
+ entries?: {
12
+ native?: string;
13
+ server?: string;
14
+ };
5
15
  root?: string;
6
16
  host?: string;
7
17
  port?: number;
@@ -1,7 +1,7 @@
1
- export declare function getHtml({ template, props, appHtml, headHtml, css, }: {
1
+ export declare function getHtml({ template, loaderData, appHtml, headHtml, css, }: {
2
2
  css?: string;
3
3
  template: string;
4
- props: Object;
4
+ loaderData: Object;
5
5
  appHtml: string;
6
6
  headHtml: string;
7
7
  }): string;
@@ -1,6 +1,10 @@
1
1
  import type { VXRNConfig } from '../types';
2
2
  export type VXRNConfigFilled = Awaited<ReturnType<typeof getOptionsFilled>>;
3
3
  export declare function getOptionsFilled(options: VXRNConfig): Promise<{
4
+ entries: {
5
+ native: string;
6
+ server: string;
7
+ };
4
8
  packageJSON: import("pkg-types").PackageJson;
5
9
  state: State;
6
10
  packageRootDir: string;
@@ -10,7 +14,6 @@ export declare function getOptionsFilled(options: VXRNConfig): Promise<{
10
14
  host: string;
11
15
  root: string;
12
16
  port: number;
13
- entryNative?: string | undefined;
14
17
  webConfig?: import("vite").InlineConfig | undefined;
15
18
  nativeConfig?: import("vite").InlineConfig | undefined;
16
19
  flow?: import("@vxrn/vite-flow").Options | undefined;