@zubra/unplugin 5.1.2 → 5.3.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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/index.js +10 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zubra/unplugin",
3
- "version": "5.1.2",
3
+ "version": "5.3.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.1.0",
38
- "@zubra/runtime": "^5.1.0"
37
+ "@zubra/compiler": "^5.3.0",
38
+ "@zubra/runtime": "^5.3.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@zubra/compiler": "file:../compiler",
package/src/index.js CHANGED
@@ -26,6 +26,7 @@ import { spawnSync } from 'node:child_process';
26
26
  import { readFileSync, writeFileSync, existsSync, statSync } from 'node:fs';
27
27
  import { addProps, zubraImports } from './props.js';
28
28
  import { basename, dirname, extname, relative, resolve, sep } from 'node:path';
29
+ import { createRequire } from 'node:module';
29
30
 
30
31
  const VARIANTS = ['element', 'react', 'vue'];
31
32
  /** A component file: `.zb`, or a JSX component (`.zb.jsx` / `.zb.tsx`). */
@@ -297,6 +298,15 @@ export const unplugin = createUnplugin((options = {}, meta = {}) => {
297
298
  return fail(this, error, path);
298
299
  }
299
300
  if (output.warnings) this.warn(output.warnings);
301
+ // 'use collection' compiles to an import of @zubra/sync: say what to install, rather than
302
+ // leave the bundler to report an unresolved import.
303
+ if (output.code.includes('from "@zubra/sync"')) {
304
+ try {
305
+ createRequire(path).resolve('@zubra/sync');
306
+ } catch {
307
+ return fail(this, new Error(`${relativePath(path)} starts with 'use collection', which needs @zubra/sync. Install it: npm install @zubra/sync`), path);
308
+ }
309
+ }
300
310
  if (server) return serverRendering ? output.code + serverRenderer(path, compilerModule, runtime) : output.code;
301
311
  return dev && meta.framework === 'vite' ? hot(output.code) : output.code;
302
312
  },