@vizejs/unplugin 0.656.0 → 0.658.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
@@ -116,7 +116,8 @@ TypeScript/JSX transforms in the pipeline if your SFC scripts use those syntaxes
116
116
 
117
117
  - Vite is still the recommended integration if you need the most complete behavior today.
118
118
  - Plain inline CSS is injected into JavaScript at runtime; CSS asset extraction and SSR stylesheet delivery are not provided by this path.
119
- - External `<style src="...">` blocks and `@import` in plain inline CSS are unsupported and cause an explicit build error. Inline those styles without external imports, or use `@vizejs/vite-plugin` for stylesheet dependency resolution. The unplugin does not read, watch, or cache those external stylesheets.
119
+ - `<style src>`, `<script src>` and `<template src>` files are read relative to the SFC (or from an absolute path), inlined before compilation and watched, as in `@vizejs/vite-plugin`. Alias and package specifiers are not resolved, and a missing file is a build error.
120
+ - `@import` in plain CSS is a build error. Plain CSS is injected at runtime as a string, so an `@import` would be fetched relative to the page. Inline the imported CSS, move the block to a preprocessor or CSS Module (handled by the host CSS pipeline), or use `@vizejs/vite-plugin`.
120
121
  - CSS Modules and preprocessors depend on the host bundler CSS pipeline and are more likely to change than the Vite path.
121
122
  - Scoped preprocessor styles are compiled before they are scoped, as in Vue: Webpack uses your `.scss`/`.less`/`.styl` rules, while Rollup, Rolldown and esbuild run the project's installed `sass` (or `sass-embedded`), `less` or `stylus`.
122
123
  - If your bundler inlines the Vue runtime, Vize injects the usual Vue 3 compile-time feature flags for Rollup-like and Webpack hosts when its compiler is active.
package/dist/babel.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_unplugin = require("./unplugin-pPxtpl3x.cjs");
1
+ const require_unplugin = require("./unplugin-BErqvAH5.cjs");
2
2
  //#region src/babel.ts
3
3
  function vizeBabelPlugin(_api, rawOptions = {}) {
4
4
  const options = require_unplugin.normalizeOptions(rawOptions);
package/dist/babel.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-DX7ymghn.mjs";
1
+ import { a as createFilter, i as generateOutput, r as compileVueModule, t as normalizeOptions } from "./unplugin-DPYDTPhZ.mjs";
2
2
  //#region src/babel.ts
3
3
  function vizeBabelPlugin(_api, rawOptions = {}) {
4
4
  const options = normalizeOptions(rawOptions);
package/dist/esbuild.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/esbuild.ts
2
- var esbuild_default = require("./unplugin-pPxtpl3x.cjs").vizeUnplugin.esbuild;
2
+ var esbuild_default = require("./unplugin-BErqvAH5.cjs").vizeUnplugin.esbuild;
3
3
  //#endregion
4
4
  module.exports = esbuild_default;
package/dist/esbuild.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as vizeUnplugin } from "./unplugin-DX7ymghn.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-DPYDTPhZ.mjs";
2
2
  //#region src/esbuild.ts
3
3
  var esbuild_default = vizeUnplugin.esbuild;
4
4
  //#endregion
package/dist/index.cjs CHANGED
@@ -2,6 +2,6 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- const require_unplugin = require("./unplugin-pPxtpl3x.cjs");
5
+ const require_unplugin = require("./unplugin-BErqvAH5.cjs");
6
6
  exports.default = require_unplugin.vizeUnplugin;
7
7
  exports.vizeUnplugin = require_unplugin.vizeUnplugin;
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as vizeUnplugin } from "./unplugin-DX7ymghn.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-DPYDTPhZ.mjs";
2
2
  export { vizeUnplugin as default, vizeUnplugin };
package/dist/rolldown.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/rolldown.ts
2
- var rolldown_default = require("./unplugin-pPxtpl3x.cjs").vizeUnplugin.rollup;
2
+ var rolldown_default = require("./unplugin-BErqvAH5.cjs").vizeUnplugin.rollup;
3
3
  //#endregion
4
4
  module.exports = rolldown_default;
package/dist/rolldown.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as vizeUnplugin } from "./unplugin-DX7ymghn.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-DPYDTPhZ.mjs";
2
2
  //#region src/rolldown.ts
3
3
  var rolldown_default = vizeUnplugin.rollup;
4
4
  //#endregion
package/dist/rollup.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/rollup.ts
2
- var rollup_default = require("./unplugin-pPxtpl3x.cjs").vizeUnplugin.rollup;
2
+ var rollup_default = require("./unplugin-BErqvAH5.cjs").vizeUnplugin.rollup;
3
3
  //#endregion
4
4
  module.exports = rollup_default;
package/dist/rollup.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as vizeUnplugin } from "./unplugin-DX7ymghn.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-DPYDTPhZ.mjs";
2
2
  //#region src/rollup.ts
3
3
  var rollup_default = vizeUnplugin.rollup;
4
4
  //#endregion
@@ -6,6 +6,8 @@ let unplugin = require("unplugin");
6
6
  let node_crypto = require("node:crypto");
7
7
  let _vizejs_native = require("@vizejs/native");
8
8
  _vizejs_native = require_webpack_styles.__toESM(_vizejs_native, 1);
9
+ let node_path = require("node:path");
10
+ node_path = require_webpack_styles.__toESM(node_path, 1);
9
11
  let oxc_transform = require("oxc-transform");
10
12
  //#region src/filter.ts
11
13
  function createFilter(include, exclude) {
@@ -221,12 +223,104 @@ function hasImportRule(ast) {
221
223
  /** The inline runtime style path cannot resolve external CSS dependencies. */
222
224
  function assertSupportedStyleDependencies(styles, filename) {
223
225
  for (const style of styles) {
224
- if (style.src !== void 0) throw new Error(`[vize] ${filename}: <style src=${JSON.stringify(style.src)}> is not supported by @vizejs/unplugin. Use inline CSS without external imports, or @vizejs/vite-plugin for external stylesheet resolution.`);
226
+ if (style.src !== void 0) throw new Error(`[vize] ${filename}: <style src=${JSON.stringify(style.src)}> could not be inlined by @vizejs/unplugin. Write it as <style src="./file.css"> with a quoted relative path, or use @vizejs/vite-plugin.`);
225
227
  if (style.module || style.lang && style.lang !== "css" || !style.content.includes("@")) continue;
226
228
  if (hasImportRule((0, _vizejs_native.parseCssAst)(style.content, { filename }).ast)) throw new Error(`[vize] ${filename}: CSS @import in <style> is not supported by @vizejs/unplugin's inline style output. Inline the imported CSS, or use @vizejs/vite-plugin for stylesheet dependency resolution.`);
227
229
  }
228
230
  }
229
231
  //#endregion
232
+ //#region src/src-blocks.ts
233
+ const SRC_BLOCK_HINT = /<(?:template|script|style)\b[^>]*\ssrc\s*=/i;
234
+ const ATTRIBUTE_RE = /\s+([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gy;
235
+ /** Split an opening tag into its `src` value and the tag without it. */
236
+ function splitSrcAttribute(tag, openTag) {
237
+ const head = `<${tag}`;
238
+ if (!openTag.toLowerCase().startsWith(head)) return null;
239
+ const body = openTag.slice(head.length).replace(/\s*\/?\s*>$/, "");
240
+ let rest = "";
241
+ let src = null;
242
+ let consumed = 0;
243
+ ATTRIBUTE_RE.lastIndex = 0;
244
+ for (let match = ATTRIBUTE_RE.exec(body); match; match = ATTRIBUTE_RE.exec(body)) {
245
+ consumed = ATTRIBUTE_RE.lastIndex;
246
+ if (match[1].toLowerCase() === "src" && src === null) src = match[2] ?? match[3] ?? match[4] ?? "";
247
+ else rest += match[0];
248
+ }
249
+ if (src === null || consumed !== body.length) return null;
250
+ return {
251
+ src,
252
+ openTag: `${head}${rest}>`
253
+ };
254
+ }
255
+ function readSrcBlock(filePath, tag, src) {
256
+ const resolved = node_path.default.resolve(node_path.default.dirname(filePath), src);
257
+ try {
258
+ return {
259
+ path: resolved,
260
+ content: node_fs.default.readFileSync(resolved, "utf8")
261
+ };
262
+ } catch {
263
+ throw new Error(`[vize] <${tag} src="${src}"> not found (resolved: ${resolved}) in ${filePath}`);
264
+ }
265
+ }
266
+ /**
267
+ * Inline `<template src>`, `<script src>` and `<style src>` files into the SFC
268
+ * source, as `@vizejs/vite-plugin` does. Blocks are located by the native
269
+ * parser, so `src` text inside scripts or comments is left alone.
270
+ */
271
+ function inlineSfcSrcBlocks(filePath, source) {
272
+ if (!SRC_BLOCK_HINT.test(source)) return {
273
+ source,
274
+ dependencies: []
275
+ };
276
+ let parsed;
277
+ try {
278
+ parsed = (0, _vizejs_native.parseSfc)(source, { filename: filePath });
279
+ } catch {
280
+ return {
281
+ source,
282
+ dependencies: []
283
+ };
284
+ }
285
+ const blocks = [
286
+ ["template", parsed.template],
287
+ ["script", parsed.script],
288
+ ...parsed.styles.map((style) => ["style", style])
289
+ ];
290
+ const bytes = Buffer.from(source);
291
+ const edits = [];
292
+ const dependencies = [];
293
+ for (const [tag, block] of blocks) {
294
+ if (!block) continue;
295
+ const { start, tagStart, tagEnd } = block.loc;
296
+ const split = splitSrcAttribute(tag, bytes.subarray(tagStart, start).toString("utf8"));
297
+ if (!split) continue;
298
+ const file = readSrcBlock(filePath, tag, split.src);
299
+ dependencies.push(file.path);
300
+ edits.push({
301
+ start: tagStart,
302
+ end: tagEnd,
303
+ text: `${split.openTag}\n${file.content}\n</${tag}>`
304
+ });
305
+ }
306
+ if (edits.length === 0) return {
307
+ source,
308
+ dependencies
309
+ };
310
+ edits.sort((a, b) => a.start - b.start);
311
+ const parts = [];
312
+ let offset = 0;
313
+ for (const edit of edits) {
314
+ parts.push(bytes.subarray(offset, edit.start), Buffer.from(edit.text));
315
+ offset = edit.end;
316
+ }
317
+ parts.push(bytes.subarray(offset));
318
+ return {
319
+ source: Buffer.concat(parts).toString("utf8"),
320
+ dependencies
321
+ };
322
+ }
323
+ //#endregion
230
324
  //#region src/compiler.ts
231
325
  const { compileSfc, compileJsx } = _vizejs_native;
232
326
  function buildSignature(options) {
@@ -255,15 +349,17 @@ function buildSourceHash(source) {
255
349
  return (0, node_crypto.createHash)("sha256").update(source).digest("hex");
256
350
  }
257
351
  function compileVueModule(filePath, source, options, cache) {
258
- const sourceHash = buildSourceHash(source);
352
+ const { source: inlined, dependencies } = inlineSfcSrcBlocks(filePath, source);
353
+ const sourceHash = buildSourceHash(inlined);
259
354
  const signature = buildSignature(options);
260
355
  const cached = cache.get(filePath);
261
356
  if (cached && cached.sourceHash === sourceHash && cached.signature === signature) return {
262
357
  compiled: cached.compiled,
263
- warnings: []
358
+ warnings: [],
359
+ dependencies
264
360
  };
265
361
  const scopeId = generateScopeId(filePath, options.root, options.isProduction, source);
266
- const result = compileSfc(source, {
362
+ const result = compileSfc(inlined, {
267
363
  filename: filePath,
268
364
  mode: options.mode,
269
365
  sourceMap: options.sourceMap,
@@ -302,7 +398,8 @@ function compileVueModule(filePath, source, options, cache) {
302
398
  });
303
399
  return {
304
400
  compiled,
305
- warnings: result.warnings
401
+ warnings: result.warnings,
402
+ dependencies
306
403
  };
307
404
  }
308
405
  function compileJsxModule(filePath, source, options) {
@@ -537,8 +634,9 @@ const vizeUnplugin = (0, unplugin.createUnplugin)((rawOptions = {}, meta) => {
537
634
  };
538
635
  }
539
636
  if (!isVueFile(id) || !filter(id)) return null;
540
- const { compiled, warnings } = compileVueModule(id, code, options, cache);
637
+ const { compiled, warnings, dependencies } = compileVueModule(id, code, options, cache);
541
638
  for (const warning of warnings) this.warn(`[vize] ${warning}`);
639
+ for (const dependency of dependencies) this.addWatchFile(dependency);
542
640
  const transformed = await stripTypeScript(id, generateOutput(compiled, {
543
641
  isProduction: options.isProduction,
544
642
  isDev: false,
@@ -4,7 +4,8 @@ import fs from "node:fs";
4
4
  import { createUnplugin } from "unplugin";
5
5
  import { createHash } from "node:crypto";
6
6
  import * as native from "@vizejs/native";
7
- import { generateSfcScopeId, parseCssAst } from "@vizejs/native";
7
+ import { generateSfcScopeId, parseCssAst, parseSfc } from "@vizejs/native";
8
+ import path from "node:path";
8
9
  import { transform } from "oxc-transform";
9
10
  //#region src/filter.ts
10
11
  function createFilter(include, exclude) {
@@ -220,12 +221,104 @@ function hasImportRule(ast) {
220
221
  /** The inline runtime style path cannot resolve external CSS dependencies. */
221
222
  function assertSupportedStyleDependencies(styles, filename) {
222
223
  for (const style of styles) {
223
- if (style.src !== void 0) throw new Error(`[vize] ${filename}: <style src=${JSON.stringify(style.src)}> is not supported by @vizejs/unplugin. Use inline CSS without external imports, or @vizejs/vite-plugin for external stylesheet resolution.`);
224
+ if (style.src !== void 0) throw new Error(`[vize] ${filename}: <style src=${JSON.stringify(style.src)}> could not be inlined by @vizejs/unplugin. Write it as <style src="./file.css"> with a quoted relative path, or use @vizejs/vite-plugin.`);
224
225
  if (style.module || style.lang && style.lang !== "css" || !style.content.includes("@")) continue;
225
226
  if (hasImportRule(parseCssAst(style.content, { filename }).ast)) throw new Error(`[vize] ${filename}: CSS @import in <style> is not supported by @vizejs/unplugin's inline style output. Inline the imported CSS, or use @vizejs/vite-plugin for stylesheet dependency resolution.`);
226
227
  }
227
228
  }
228
229
  //#endregion
230
+ //#region src/src-blocks.ts
231
+ const SRC_BLOCK_HINT = /<(?:template|script|style)\b[^>]*\ssrc\s*=/i;
232
+ const ATTRIBUTE_RE = /\s+([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gy;
233
+ /** Split an opening tag into its `src` value and the tag without it. */
234
+ function splitSrcAttribute(tag, openTag) {
235
+ const head = `<${tag}`;
236
+ if (!openTag.toLowerCase().startsWith(head)) return null;
237
+ const body = openTag.slice(head.length).replace(/\s*\/?\s*>$/, "");
238
+ let rest = "";
239
+ let src = null;
240
+ let consumed = 0;
241
+ ATTRIBUTE_RE.lastIndex = 0;
242
+ for (let match = ATTRIBUTE_RE.exec(body); match; match = ATTRIBUTE_RE.exec(body)) {
243
+ consumed = ATTRIBUTE_RE.lastIndex;
244
+ if (match[1].toLowerCase() === "src" && src === null) src = match[2] ?? match[3] ?? match[4] ?? "";
245
+ else rest += match[0];
246
+ }
247
+ if (src === null || consumed !== body.length) return null;
248
+ return {
249
+ src,
250
+ openTag: `${head}${rest}>`
251
+ };
252
+ }
253
+ function readSrcBlock(filePath, tag, src) {
254
+ const resolved = path.resolve(path.dirname(filePath), src);
255
+ try {
256
+ return {
257
+ path: resolved,
258
+ content: fs.readFileSync(resolved, "utf8")
259
+ };
260
+ } catch {
261
+ throw new Error(`[vize] <${tag} src="${src}"> not found (resolved: ${resolved}) in ${filePath}`);
262
+ }
263
+ }
264
+ /**
265
+ * Inline `<template src>`, `<script src>` and `<style src>` files into the SFC
266
+ * source, as `@vizejs/vite-plugin` does. Blocks are located by the native
267
+ * parser, so `src` text inside scripts or comments is left alone.
268
+ */
269
+ function inlineSfcSrcBlocks(filePath, source) {
270
+ if (!SRC_BLOCK_HINT.test(source)) return {
271
+ source,
272
+ dependencies: []
273
+ };
274
+ let parsed;
275
+ try {
276
+ parsed = parseSfc(source, { filename: filePath });
277
+ } catch {
278
+ return {
279
+ source,
280
+ dependencies: []
281
+ };
282
+ }
283
+ const blocks = [
284
+ ["template", parsed.template],
285
+ ["script", parsed.script],
286
+ ...parsed.styles.map((style) => ["style", style])
287
+ ];
288
+ const bytes = Buffer.from(source);
289
+ const edits = [];
290
+ const dependencies = [];
291
+ for (const [tag, block] of blocks) {
292
+ if (!block) continue;
293
+ const { start, tagStart, tagEnd } = block.loc;
294
+ const split = splitSrcAttribute(tag, bytes.subarray(tagStart, start).toString("utf8"));
295
+ if (!split) continue;
296
+ const file = readSrcBlock(filePath, tag, split.src);
297
+ dependencies.push(file.path);
298
+ edits.push({
299
+ start: tagStart,
300
+ end: tagEnd,
301
+ text: `${split.openTag}\n${file.content}\n</${tag}>`
302
+ });
303
+ }
304
+ if (edits.length === 0) return {
305
+ source,
306
+ dependencies
307
+ };
308
+ edits.sort((a, b) => a.start - b.start);
309
+ const parts = [];
310
+ let offset = 0;
311
+ for (const edit of edits) {
312
+ parts.push(bytes.subarray(offset, edit.start), Buffer.from(edit.text));
313
+ offset = edit.end;
314
+ }
315
+ parts.push(bytes.subarray(offset));
316
+ return {
317
+ source: Buffer.concat(parts).toString("utf8"),
318
+ dependencies
319
+ };
320
+ }
321
+ //#endregion
229
322
  //#region src/compiler.ts
230
323
  const { compileSfc, compileJsx } = native;
231
324
  function buildSignature(options) {
@@ -254,15 +347,17 @@ function buildSourceHash(source) {
254
347
  return createHash("sha256").update(source).digest("hex");
255
348
  }
256
349
  function compileVueModule(filePath, source, options, cache) {
257
- const sourceHash = buildSourceHash(source);
350
+ const { source: inlined, dependencies } = inlineSfcSrcBlocks(filePath, source);
351
+ const sourceHash = buildSourceHash(inlined);
258
352
  const signature = buildSignature(options);
259
353
  const cached = cache.get(filePath);
260
354
  if (cached && cached.sourceHash === sourceHash && cached.signature === signature) return {
261
355
  compiled: cached.compiled,
262
- warnings: []
356
+ warnings: [],
357
+ dependencies
263
358
  };
264
359
  const scopeId = generateScopeId(filePath, options.root, options.isProduction, source);
265
- const result = compileSfc(source, {
360
+ const result = compileSfc(inlined, {
266
361
  filename: filePath,
267
362
  mode: options.mode,
268
363
  sourceMap: options.sourceMap,
@@ -301,7 +396,8 @@ function compileVueModule(filePath, source, options, cache) {
301
396
  });
302
397
  return {
303
398
  compiled,
304
- warnings: result.warnings
399
+ warnings: result.warnings,
400
+ dependencies
305
401
  };
306
402
  }
307
403
  function compileJsxModule(filePath, source, options) {
@@ -536,8 +632,9 @@ const vizeUnplugin = createUnplugin((rawOptions = {}, meta) => {
536
632
  };
537
633
  }
538
634
  if (!isVueFile(id) || !filter(id)) return null;
539
- const { compiled, warnings } = compileVueModule(id, code, options, cache);
635
+ const { compiled, warnings, dependencies } = compileVueModule(id, code, options, cache);
540
636
  for (const warning of warnings) this.warn(`[vize] ${warning}`);
637
+ for (const dependency of dependencies) this.addWatchFile(dependency);
541
638
  const transformed = await stripTypeScript(id, generateOutput(compiled, {
542
639
  isProduction: options.isProduction,
543
640
  isDev: false,
package/dist/webpack.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region src/webpack.ts
2
- var webpack_default = require("./unplugin-pPxtpl3x.cjs").vizeUnplugin.webpack;
2
+ var webpack_default = require("./unplugin-BErqvAH5.cjs").vizeUnplugin.webpack;
3
3
  //#endregion
4
4
  module.exports = webpack_default;
package/dist/webpack.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as vizeUnplugin } from "./unplugin-DX7ymghn.mjs";
1
+ import { n as vizeUnplugin } from "./unplugin-DPYDTPhZ.mjs";
2
2
  //#region src/webpack.ts
3
3
  var webpack_default = vizeUnplugin.webpack;
4
4
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/unplugin",
3
- "version": "0.656.0",
3
+ "version": "0.658.0",
4
4
  "description": "Experimental Vue SFC integrations for Rollup, Rolldown, Webpack, esbuild, and Babel powered by Vize",
5
5
  "keywords": [
6
6
  "babel",
@@ -68,7 +68,7 @@
68
68
  "access": "public"
69
69
  },
70
70
  "dependencies": {
71
- "@vizejs/native": "0.656.0",
71
+ "@vizejs/native": "0.658.0",
72
72
  "oxc-transform": "0.144.0",
73
73
  "unplugin": "3.3.0"
74
74
  },