@hanzo/vite 0.1.0 → 0.1.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiCA;mDACmD;AACnD,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE5C,MAAM,MAAM,OAAO,GAAG;IACpB,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAA;IACZ,+EAA+E;IAC/E,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9B,8EAA8E;IAC9E,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAClB,CAAA;AAQD;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,YAAK,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAqBnE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoCA;mDACmD;AACnD,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE5C,MAAM,MAAM,OAAO,GAAG;IACpB,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAA;IACZ,+EAA+E;IAC/E,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9B,8EAA8E;IAC9E,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAClB,CAAA;AAQD;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,YAAK,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CA0CnE"}
package/dist/index.js CHANGED
@@ -29,7 +29,9 @@
29
29
  * keeping symlinks does under webpack. One runtime either way, two mechanisms —
30
30
  * because the bundlers genuinely differ, not because we changed our minds.
31
31
  */
32
- import { resolve } from 'node:path';
32
+ import { createRequire } from 'node:module';
33
+ import { dirname, resolve } from 'node:path';
34
+ const need = createRequire(import.meta.url);
33
35
  /** Packages whose identity is load-bearing: a second copy breaks context. */
34
36
  const RUNTIME = ['react', 'react-dom', 'react-native-web', '@hanzo/gui', '@hanzo/ui'];
35
37
  const WEB_FIRST = ['.web.tsx', '.web.ts', '.web.jsx', '.web.js'];
@@ -49,9 +51,29 @@ export function hanzo(config = {}, options) {
49
51
  ...(Array.isArray(appResolve.alias) ? appResolve.alias : []),
50
52
  ...Object.entries(alias).map(([find, to]) => ({ find, replacement: resolve(root, to) })),
51
53
  { find: /^react-native$/, replacement: 'react-native-web' },
54
+ // The asset registry is react-native's, and react-native-web reimplements it
55
+ // with the same `getAssetByID`. react-native-svg's web build reaches for the
56
+ // native one by name, so without this the bundle resolves nothing and the
57
+ // build fails — an icon is enough to trigger it, which is every product
58
+ // component that carries one.
59
+ {
60
+ find: /^@react-native\/assets-registry\/registry$/,
61
+ replacement: 'react-native-web/dist/modules/AssetRegistry',
62
+ },
63
+ // The source runtime is this package's dependency, not the app's, and an
64
+ // isolated node_modules does not let the app see it. Naming the resolved
65
+ // copy here is what keeps an app on `hanzo()` free of configuration.
66
+ { find: /^@hanzo\/source\/(.+)$/, replacement: `${dirname(need.resolve('@hanzo/source/package.json'))}/dist/$1.js` },
52
67
  ];
68
+ const appBuild = config.build ?? {};
69
+ const appPlugins = Array.isArray(config.plugins) ? config.plugins : [];
53
70
  return {
54
71
  ...config,
72
+ // A production bundle names the source it came from. A stack trace, an
73
+ // error report and an edit widget all read that map; without it every one
74
+ // of them points at a minified line.
75
+ build: { sourcemap: true, ...appBuild },
76
+ plugins: [...appPlugins, source(root)],
55
77
  resolve: {
56
78
  ...appResolve,
57
79
  alias: aliases,
@@ -60,4 +82,43 @@ export function hanzo(config = {}, options) {
60
82
  },
61
83
  };
62
84
  }
85
+ /**
86
+ * Where a rendered element came from, in development.
87
+ *
88
+ * The React plugin emits `import { jsxDEV } from 'react/jsx-dev-runtime'` in
89
+ * every app module. Pointing that import at `@hanzo/source` instead keeps the
90
+ * position the compiler already passes, as `data-source` on host elements, and
91
+ * the injected listener opens it in the editor on Alt + right click through
92
+ * Vite's own `/__open-in-editor`. Only modules under the app root are
93
+ * redirected, so the runtime's own import of React is never rewritten into
94
+ * itself; a production build is untouched.
95
+ */
96
+ const source = (root) => {
97
+ let serving = false;
98
+ return {
99
+ name: 'hanzo:source',
100
+ configResolved(resolved) {
101
+ serving = resolved.command === 'serve';
102
+ },
103
+ transform(code, id) {
104
+ if (!serving || !id.startsWith(root) || id.includes('/node_modules/'))
105
+ return;
106
+ if (!code.includes('react/jsx-dev-runtime'))
107
+ return;
108
+ return { code: code.replaceAll('react/jsx-dev-runtime', '@hanzo/source/jsx-dev-runtime'), map: null };
109
+ },
110
+ transformIndexHtml() {
111
+ if (!serving)
112
+ return;
113
+ return [
114
+ {
115
+ tag: 'script',
116
+ attrs: { type: 'module' },
117
+ children: "import { listen } from '@hanzo/source/client'\nlisten()",
118
+ injectTo: 'body',
119
+ },
120
+ ];
121
+ },
122
+ };
123
+ };
63
124
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAenC,6EAA6E;AAC7E,MAAM,OAAO,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,YAAY,EAAE,WAAW,CAAC,CAAA;AAErF,MAAM,SAAS,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,CAAC,CAAA;AAChE,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;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AK,OAAO,CAAA;QACxC,CAAC;QACD,SAAS,CAAC,IAAY,EAAE,EAAU;YAChC,IAAI,CAAC,OAAO,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC;gBAAE,OAAM;YAC7E,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CAAC;gBAAE,OAAM;YACnD,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,uBAAuB,EAAE,+BAA+B,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAA;QACvG,CAAC;QACD,kBAAkB;YAChB,IAAI,CAAC,OAAO;gBAAE,OAAM;YACpB,OAAO;gBACL;oBACE,GAAG,EAAE,QAAQ;oBACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBACzB,QAAQ,EAAE,yDAAyD;oBACnE,QAAQ,EAAE,MAAM;iBACjB;aACF,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/vite",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "The Vite config every Hanzo app shares — one runtime, one compiler, one way.",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "type": "module",
@@ -16,11 +16,11 @@
16
16
  "dist"
17
17
  ],
18
18
  "peerDependencies": {
19
- "vite": ">=6"
19
+ "vite": ">=8"
20
20
  },
21
21
  "devDependencies": {
22
- "typescript": "^7.0.2",
23
- "vitest": "^3.2.4"
22
+ "typescript": "7.0.2",
23
+ "vitest": "^4.1.11"
24
24
  },
25
25
  "publishConfig": {
26
26
  "access": "public"
@@ -30,6 +30,9 @@
30
30
  "url": "git+https://github.com/hanzoai/ui.git",
31
31
  "directory": "pkgs/vite"
32
32
  },
33
+ "dependencies": {
34
+ "@hanzo/source": "0.1.0"
35
+ },
33
36
  "scripts": {
34
37
  "build": "tsc -p tsconfig.json",
35
38
  "test": "vitest run"