@hanzo/vite 0.1.1 → 0.1.3

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,CA8BnE"}
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'];
@@ -58,9 +60,20 @@ export function hanzo(config = {}, options) {
58
60
  find: /^@react-native\/assets-registry\/registry$/,
59
61
  replacement: 'react-native-web/dist/modules/AssetRegistry',
60
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` },
61
67
  ];
68
+ const appBuild = config.build ?? {};
69
+ const appPlugins = Array.isArray(config.plugins) ? config.plugins : [];
62
70
  return {
63
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)],
64
77
  resolve: {
65
78
  ...appResolve,
66
79
  alias: aliases,
@@ -69,4 +82,49 @@ export function hanzo(config = {}, options) {
69
82
  },
70
83
  };
71
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
+ // `pre`, so Vite's own HTML pass still runs over the injected script and
111
+ // resolves its import; a script added after that pass reaches the browser
112
+ // with a bare specifier the browser cannot resolve.
113
+ transformIndexHtml: {
114
+ order: 'pre',
115
+ handler() {
116
+ if (!serving)
117
+ return;
118
+ return [
119
+ {
120
+ tag: 'script',
121
+ attrs: { type: 'module' },
122
+ children: "import { listen } from '@hanzo/source/client'\nlisten()",
123
+ injectTo: 'body',
124
+ },
125
+ ];
126
+ },
127
+ },
128
+ };
129
+ };
72
130
  //# 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;AAE3E;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,MAAM,GAAW,EAAE,EAAE,OAAgB;IACzD,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,MA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xC,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,yEAAyE;QACzE,0EAA0E;QAC1E,oDAAoD;QACpD,kBAAkB,EAAE;YAClB,KAAK,EAAE,KAAc;YACrB,OAAO;gBACL,IAAI,CAAC,OAAO;oBAAE,OAAM;gBACpB,OAAO;oBACL;wBACE,GAAG,EAAE,QAAQ;wBACb,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;wBACzB,QAAQ,EAAE,yDAAyD;wBACnE,QAAQ,EAAE,MAAM;qBACjB;iBACF,CAAA;YACH,CAAC;SACF;KACF,CAAA;AACH,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/vite",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
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"