@zubra/unplugin 5.3.0 → 5.4.0

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.
package/README.md CHANGED
@@ -103,6 +103,10 @@ In Vite's dev server, editing a component **updates it in place**: the elements
103
103
 
104
104
  Components that import the edited one are recompiled too. Other bundlers' watch modes (Rollup, webpack) recompile on change.
105
105
 
106
+ The dev server also compiles each component for the **Zubra DevTools** (`--devtools`): select a node in the browser's Elements panel and the Zubra pane shows its component's `.zb` file and line, its props and state, and each binding's line and the signals it reads (see `editors/devtools`). Builds carry none of it.
107
+
108
+ To use the DevTools on a build too (a demo, a staging or preview deploy), pass `zubra({ devtools: true })` or set `ZUBRA_DEVTOOLS=1`: components are compiled the same way and `@zubra/runtime` resolves to its development build, which has the hook. It costs some bytes, so production builds leave it off by default.
109
+
106
110
  ## Tests
107
111
 
108
112
  `npm test` builds real React, Vue and plain Vite apps, runs them in Chromium, type-checks the generated typings with TypeScript, and checks the dev server, `build --watch` and error reporting. It needs a Rust toolchain (the compiler is built from this repository) and Playwright with Chromium.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zubra/unplugin",
3
- "version": "5.3.0",
3
+ "version": "5.4.0",
4
4
  "description": "Compile .zb components in Vite, Rollup, webpack, esbuild and Rspack, with React and Vue wrappers picked automatically",
5
5
  "license": "ISC",
6
6
  "repository": {
@@ -34,8 +34,8 @@
34
34
  "unplugin": "3.7.0"
35
35
  },
36
36
  "peerDependencies": {
37
- "@zubra/compiler": "^5.3.0",
38
- "@zubra/runtime": "^5.3.0"
37
+ "@zubra/compiler": "^5.4.0",
38
+ "@zubra/runtime": "^5.4.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@zubra/compiler": "file:../compiler",
package/src/index.js CHANGED
@@ -140,6 +140,10 @@ export const unplugin = createUnplugin((options = {}, meta = {}) => {
140
140
  const relativePath = (path) => path.startsWith(process.cwd()) ? path.slice(process.cwd().length + 1) : path;
141
141
  const compilerModule = options.compilerModule ?? '@zubra/compiler';
142
142
  let dev = false; // Vite's dev server: components hot-reload
143
+ // The Zubra DevTools in a build, not only in Vite's dev server: components compiled with
144
+ // --devtools, and @zubra/runtime's development build (which has the hook) instead of its
145
+ // production one. For demos, staging and previews; it costs bytes, so it's opt-in.
146
+ const devtoolsInBuilds = options.devtools ?? process.env.ZUBRA_DEVTOOLS === '1';
143
147
 
144
148
  /** CLI flags → a request for the WebAssembly compiler. */
145
149
  function asRequest(args) {
@@ -148,6 +152,7 @@ export const unplugin = createUnplugin((options = {}, meta = {}) => {
148
152
  const flag = args[i];
149
153
  if (flag === '--keep-imports') request.keepImports = true;
150
154
  else if (flag === '--no-imports') request.noImports = true;
155
+ else if (flag === '--devtools') request.devtools = true;
151
156
  else {
152
157
  const key = { '--emit': 'emit', '--framework': 'framework', '--runtime': 'runtime', '--css-import': 'cssImport', '--css-import-inline': 'cssImportInline' }[flag];
153
158
  if (!key) throw new Error(`zubra: unexpected compiler flag ${flag}`);
@@ -224,6 +229,14 @@ export const unplugin = createUnplugin((options = {}, meta = {}) => {
224
229
  },
225
230
 
226
231
  async resolveId(source, importer) {
232
+ // With devtools in builds: @zubra/runtime's development build, wherever it's imported from.
233
+ if (devtoolsInBuilds && /^@zubra\/runtime(\/|$)/.test(source)) {
234
+ const resolved = await this.resolve?.(source, importer, { skipSelf: true });
235
+ if (resolved && /[\\/]dist[\\/]production[\\/]/.test(resolved.id)) {
236
+ return { ...resolved, id: resolved.id.replace(/([\\/])dist[\\/]production([\\/])/, '$1src$2') };
237
+ }
238
+ return resolved;
239
+ }
227
240
  const [specifier, query] = split(source);
228
241
  if (!COMPONENT.test(specifier)) return null;
229
242
  let path;
@@ -293,7 +306,10 @@ export const unplugin = createUnplugin((options = {}, meta = {}) => {
293
306
  }
294
307
  let output;
295
308
  try {
296
- output = compile(path, '--emit', 'js', '--keep-imports', '--runtime', runtime, ...styles);
309
+ // In Vite's dev server, what the browser DevTools panel reads: each part's place in the
310
+ // `.zb` file and the script's signals by name (the runtime's development build reads them).
311
+ const devtools = ((dev && meta.framework === 'vite') || devtoolsInBuilds) && !server ? ['--devtools'] : [];
312
+ output = compile(path, '--emit', 'js', '--keep-imports', '--runtime', runtime, ...styles, ...devtools);
297
313
  } catch (error) {
298
314
  return fail(this, error, path);
299
315
  }