vxrn 0.1.46 → 0.1.47

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 (74) hide show
  1. package/dist/cjs/cli.js +7 -2
  2. package/dist/cjs/cli.js.map +1 -1
  3. package/dist/cjs/cli.native.js +7 -2
  4. package/dist/cjs/cli.native.js.map +2 -2
  5. package/dist/cjs/constants.js +6 -6
  6. package/dist/cjs/constants.js.map +1 -1
  7. package/dist/cjs/constants.native.js +9 -8
  8. package/dist/cjs/constants.native.js.map +2 -2
  9. package/dist/cjs/exports/build.js +19 -38
  10. package/dist/cjs/exports/build.js.map +1 -1
  11. package/dist/cjs/exports/build.native.js +38 -91
  12. package/dist/cjs/exports/build.native.js.map +2 -2
  13. package/dist/cjs/exports/dev.js +18 -7
  14. package/dist/cjs/exports/dev.js.map +1 -1
  15. package/dist/cjs/exports/dev.native.js +19 -23
  16. package/dist/cjs/exports/dev.native.js.map +2 -2
  17. package/dist/cjs/utils/getHtml.js +9 -6
  18. package/dist/cjs/utils/getHtml.js.map +1 -1
  19. package/dist/cjs/utils/getHtml.native.js +9 -5
  20. package/dist/cjs/utils/getHtml.native.js.map +2 -2
  21. package/dist/cjs/utils/getVitePath.js +3 -1
  22. package/dist/cjs/utils/getVitePath.js.map +1 -1
  23. package/dist/cjs/utils/getVitePath.native.js +1 -1
  24. package/dist/cjs/utils/getVitePath.native.js.map +1 -1
  25. package/dist/cjs/utils/readVXRNConfig.js +5 -3
  26. package/dist/cjs/utils/readVXRNConfig.js.map +1 -1
  27. package/dist/cjs/utils/readVXRNConfig.native.js +5 -1
  28. package/dist/cjs/utils/readVXRNConfig.native.js.map +2 -2
  29. package/dist/esm/cli.js +7 -2
  30. package/dist/esm/cli.js.map +1 -1
  31. package/dist/esm/cli.mjs +7 -2
  32. package/dist/esm/cli.native.js +7 -2
  33. package/dist/esm/cli.native.js.map +2 -2
  34. package/dist/esm/constants.js +6 -6
  35. package/dist/esm/constants.js.map +1 -1
  36. package/dist/esm/constants.mjs +4 -5
  37. package/dist/esm/constants.native.js +9 -7
  38. package/dist/esm/constants.native.js.map +2 -2
  39. package/dist/esm/exports/build.js +20 -39
  40. package/dist/esm/exports/build.js.map +1 -1
  41. package/dist/esm/exports/build.mjs +25 -34
  42. package/dist/esm/exports/build.native.js +39 -92
  43. package/dist/esm/exports/build.native.js.map +2 -2
  44. package/dist/esm/exports/dev.js +18 -7
  45. package/dist/esm/exports/dev.js.map +1 -1
  46. package/dist/esm/exports/dev.mjs +13 -11
  47. package/dist/esm/exports/dev.native.js +19 -23
  48. package/dist/esm/exports/dev.native.js.map +2 -2
  49. package/dist/esm/utils/getHtml.js +9 -6
  50. package/dist/esm/utils/getHtml.js.map +1 -1
  51. package/dist/esm/utils/getHtml.mjs +11 -4
  52. package/dist/esm/utils/getHtml.native.js +9 -5
  53. package/dist/esm/utils/getHtml.native.js.map +2 -2
  54. package/dist/esm/utils/getVitePath.js +3 -1
  55. package/dist/esm/utils/getVitePath.js.map +1 -1
  56. package/dist/esm/utils/getVitePath.mjs +1 -1
  57. package/dist/esm/utils/getVitePath.native.js +1 -1
  58. package/dist/esm/utils/getVitePath.native.js.map +1 -1
  59. package/dist/esm/utils/readVXRNConfig.js +5 -3
  60. package/dist/esm/utils/readVXRNConfig.js.map +1 -1
  61. package/dist/esm/utils/readVXRNConfig.mjs +5 -1
  62. package/dist/esm/utils/readVXRNConfig.native.js +5 -1
  63. package/dist/esm/utils/readVXRNConfig.native.js.map +2 -2
  64. package/package.json +8 -8
  65. package/src/cli.ts +7 -2
  66. package/src/constants.ts +4 -6
  67. package/src/exports/build.ts +29 -51
  68. package/src/exports/dev.ts +21 -18
  69. package/src/utils/getHtml.ts +21 -6
  70. package/src/utils/getVitePath.ts +3 -1
  71. package/src/utils/readVXRNConfig.ts +6 -4
  72. package/types/constants.d.ts +1 -2
  73. package/types/exports/build.d.ts +3 -1
  74. package/types/utils/getHtml.d.ts +2 -1
@@ -47,6 +47,8 @@ import { checkPatches } from '../utils/patches'
47
47
  let isBuildingNativeBundle: Promise<string> | null = null
48
48
  const hotUpdateCache = new Map<string, string>()
49
49
 
50
+ let connectedNativeClients = 0
51
+
50
52
  export const resolveFile = (path: string) => {
51
53
  try {
52
54
  return importMetaResolve(path, import.meta.url).replace('file://', '')
@@ -217,6 +219,7 @@ export const dev = async ({ clean, ...rest }: VXRNConfig & { clean?: boolean })
217
219
  websocket: {
218
220
  open(peer) {
219
221
  console.debug('[hmr] open', peer)
222
+ connectedNativeClients++
220
223
  },
221
224
 
222
225
  message(peer, message) {
@@ -228,6 +231,7 @@ export const dev = async ({ clean, ...rest }: VXRNConfig & { clean?: boolean })
228
231
 
229
232
  close(peer, event) {
230
233
  console.info('[hmr] close', peer, event)
234
+ connectedNativeClients--
231
235
  },
232
236
 
233
237
  error(peer, error) {
@@ -765,23 +769,8 @@ function isWithin(outer: string, inner: string) {
765
769
  // used for normalizing hot reloads
766
770
  let entryRoot = ''
767
771
 
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
-
783
772
  async function getViteServerConfig(config: VXRNConfigFilled) {
784
- const { root, host, webConfig, cacheDir } = config
773
+ const { root, host, webConfig } = config
785
774
 
786
775
  let serverConfig: UserConfig = mergeConfig(
787
776
  getBaseViteConfig({
@@ -792,7 +781,6 @@ async function getViteServerConfig(config: VXRNConfigFilled) {
792
781
  clearScreen: false,
793
782
  plugins: [
794
783
  reactNativeHMRPlugin(config),
795
- // watchNodeModules(['@tamagui/popper'])
796
784
 
797
785
  {
798
786
  name: 'process-env-ssr',
@@ -805,10 +793,22 @@ async function getViteServerConfig(config: VXRNConfigFilled) {
805
793
  },
806
794
  ],
807
795
  optimizeDeps,
796
+
808
797
  ssr: {
809
- noExternal: true,
798
+ // noExternal true causes many incompat issues because we need things on disk to work
799
+ // eg generally node uses .cjs extensions to "switch" back to cjs mode on import, but once bundled
800
+ // this wont happen, breaking many things
801
+ // but we need react related things always so they dont duplicate
802
+ noExternal: [
803
+ ...optimizeDeps.include,
804
+ 'react',
805
+ 'react-dom',
806
+ 'react-dom/server',
807
+ 'react-dom/client',
808
+ ],
810
809
  optimizeDeps,
811
810
  },
811
+
812
812
  server: {
813
813
  hmr: {
814
814
  path: '/__vxrnhmr',
@@ -850,6 +850,9 @@ function reactNativeHMRPlugin({ root }: VXRNConfigFilled) {
850
850
  if (!isWithin(root, file)) {
851
851
  return
852
852
  }
853
+ if (!connectedNativeClients) {
854
+ return
855
+ }
853
856
 
854
857
  const [module] = modules
855
858
  if (!module) return
@@ -1,20 +1,35 @@
1
+ // TODO merge with the other one
1
2
  export function getHtml({
2
3
  template,
3
4
  loaderData,
5
+ loaderProps,
4
6
  appHtml,
5
7
  headHtml,
6
8
  css,
7
- }: { css?: string; template: string; loaderData: Object; appHtml: string; headHtml: string }) {
9
+ }: {
10
+ css?: string
11
+ template: string
12
+ loaderData: Object
13
+ loaderProps?: any
14
+ appHtml: string
15
+ headHtml: string
16
+ }) {
8
17
  if (!template.includes(`<!--ssr-outlet-->`)) {
9
18
  throw new Error(`No <!--ssr-outlet--> found in html to inject SSR contents`)
10
19
  }
11
20
  if (!template.includes(`<!--head-outlet-->`)) {
12
21
  throw new Error(`No <!--head-outlet--> found in html to inject SSR contents`)
13
22
  }
14
- const loaderDataString = `\n<script>globalThis['__vxrnLoaderData__']=${JSON.stringify(
15
- loaderData
16
- )}</script>`
23
+
24
+ const loaderDataJS = `globalThis['__vxrnLoaderData__']=${JSON.stringify(loaderData)}`
25
+ const loaderPropsJS = `globalThis['__vxrnLoaderProps__']=${JSON.stringify(loaderProps || null)}`
26
+ const loaderDataString = `\n<script>
27
+ ${loaderDataJS};
28
+ ${loaderPropsJS};
29
+ </script>`
30
+
17
31
  return template
18
- .replace(`<!--ssr-outlet-->`, appHtml + loaderDataString)
19
- .replace(`<!--head-outlet-->`, `${headHtml}\n${css ? `<style>${css}</style>` : ``}`)
32
+ .replace(/\s*<!--ssr-outlet-->\s*/, appHtml)
33
+ .replace(`<!--head-outlet-->`, `${headHtml}\n${css ? `<style>${css}</style>\n` : ``}`)
34
+ .replace('</body>', loaderDataString)
20
35
  }
@@ -34,7 +34,9 @@ export async function getVitePath(
34
34
  const resolved = resolve(sourceFile)(moduleName)
35
35
  // figure out symlinks
36
36
  if (!resolved) {
37
- throw new Error(`❌ cant find`)
37
+ throw new Error(
38
+ ` ❌ Path not found ${sourceFile} (rootPath ${rootPath}, importer ${importer}, moduleName ${moduleName})`
39
+ )
38
40
  }
39
41
  const real = await FSExtra.realpath(resolved)
40
42
  let id = real
@@ -30,10 +30,12 @@ export async function readVXRNConfig(): Promise<VXRNConfig> {
30
30
 
31
31
  await vite.close()
32
32
  return resolveOptionalAsyncFunction(userConfig?.default ?? {})
33
- } catch (err) {
34
- console.info(
35
- ` [vxrn] Error loading config via ESM, attempting CJS, set VXRN_CJS=1 to run in cjs mode`
36
- )
33
+ } catch (err: any) {
34
+ console.info(` [vxrn] Error loading config via ESM:
35
+
36
+ ${err.stack}
37
+
38
+ To load as CommonJS, set VXRN_CJS=1`)
37
39
  throw err
38
40
  }
39
41
  }
@@ -1,12 +1,11 @@
1
1
  export declare const DEFAULT_PORT = 8081;
2
- export declare const EMPTY_LOADER_STRING = "function loader() {/* \u2737\u2737\u2737 */};";
3
2
  export declare const nativeExtensions: string[];
4
3
  export declare const webExtensions: string[];
5
4
  export declare const depsToOptimize: string[];
6
5
  export declare const optimizeDeps: {
7
6
  include: string[];
8
- needsInterop: string[];
9
7
  exclude: string[];
8
+ needsInterop: string[];
10
9
  esbuildOptions: {
11
10
  resolveExtensions: string[];
12
11
  };
@@ -1,4 +1,6 @@
1
1
  import type { VXRNConfig } from '../types';
2
2
  export declare const resolveFile: (path: string) => string;
3
- export declare const build: (optionsIn: VXRNConfig) => Promise<void>;
3
+ export declare const build: (optionsIn: VXRNConfig, { step }?: {
4
+ step?: string;
5
+ }) => Promise<void>;
4
6
  //# sourceMappingURL=build.d.ts.map
@@ -1,7 +1,8 @@
1
- export declare function getHtml({ template, loaderData, appHtml, headHtml, css, }: {
1
+ export declare function getHtml({ template, loaderData, loaderProps, appHtml, headHtml, css, }: {
2
2
  css?: string;
3
3
  template: string;
4
4
  loaderData: Object;
5
+ loaderProps?: any;
5
6
  appHtml: string;
6
7
  headHtml: string;
7
8
  }): string;