@vizejs/unplugin 0.101.0 → 0.103.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/dist/esbuild.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as vizeUnplugin } from "./unplugin-D3PLQ0x8.mjs";
1
+ import { t as vizeUnplugin } from "./unplugin-DdUoejrP.mjs";
2
2
  //#region src/esbuild.ts
3
3
  var esbuild_default = vizeUnplugin.esbuild;
4
4
  //#endregion
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { t as vizeUnplugin } from "./unplugin-D3PLQ0x8.mjs";
1
+ import { t as vizeUnplugin } from "./unplugin-DdUoejrP.mjs";
2
2
  export { vizeUnplugin as default, vizeUnplugin };
package/dist/rollup.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as vizeUnplugin } from "./unplugin-D3PLQ0x8.mjs";
1
+ import { t as vizeUnplugin } from "./unplugin-DdUoejrP.mjs";
2
2
  //#region src/rollup.ts
3
3
  var rollup_default = vizeUnplugin.rollup;
4
4
  //#endregion
@@ -2,7 +2,7 @@ import fs from "node:fs";
2
2
  import { createUnplugin } from "unplugin";
3
3
  import { createHash } from "node:crypto";
4
4
  import * as native from "@vizejs/native";
5
- import path from "node:path";
5
+ import { generateSfcScopeId, wrapSfcScopedPreprocessorStyle } from "@vizejs/native";
6
6
  import { transform } from "oxc-transform";
7
7
  //#region src/filter.ts
8
8
  function createFilter(include, exclude) {
@@ -40,34 +40,7 @@ function hasDelegatedStyles(compiled) {
40
40
  return compiled.styles.some((style) => needsPreprocessor(style) || isCssModule(style));
41
41
  }
42
42
  function generateScopeId(filename, root, isProduction, source) {
43
- const relative = path.relative(root, filename).replace(/^(\.\.[/\\])+/, "").replace(/\\/g, "/");
44
- const input = isProduction ? `${relative}\n${source.replace(/\r\n/g, "\n")}` : relative;
45
- return createHash("sha256").update(input).digest("hex").slice(0, 8);
46
- }
47
- function extractStyleBlocks(source) {
48
- const blocks = [];
49
- const styleRegex = /<style([^>]*)>([\s\S]*?)<\/style>/gi;
50
- let match = null;
51
- let index = 0;
52
- while ((match = styleRegex.exec(source)) !== null) {
53
- const attrs = match[1];
54
- const content = match[2];
55
- const src = attrs.match(/\bsrc=["']([^"']+)["']/)?.[1] ?? null;
56
- const lang = attrs.match(/\blang=["']([^"']+)["']/)?.[1] ?? null;
57
- const scoped = /\bscoped\b/.test(attrs);
58
- const moduleMatch = attrs.match(/\bmodule(?:=["']([^"']+)["'])?/);
59
- const moduleValue = moduleMatch ? moduleMatch[1] || true : false;
60
- blocks.push({
61
- content,
62
- src,
63
- lang,
64
- scoped,
65
- module: moduleValue,
66
- index
67
- });
68
- index++;
69
- }
70
- return blocks;
43
+ return generateSfcScopeId(filename, root, isProduction, source);
71
44
  }
72
45
  function supportsTemplateOnlyHmr(output) {
73
46
  return /(?:^|\n)(?:_sfc_main|__sfc__)\.render\s*=\s*render\b/m.test(output);
@@ -139,19 +112,17 @@ ${output}`;
139
112
  return output;
140
113
  }
141
114
  function wrapScopedPreprocessorStyle(content, scoped, lang) {
142
- if (!scoped || !lang || lang === "css") return content;
143
- const lines = content.split("\n");
144
- const hoisted = [];
145
- const body = [];
146
- for (const line of lines) {
147
- const trimmed = line.trimStart();
148
- if (trimmed.startsWith("@use ") || trimmed.startsWith("@forward ") || trimmed.startsWith("@import ")) {
149
- hoisted.push(line);
150
- continue;
151
- }
152
- body.push(line);
153
- }
154
- return `${hoisted.length > 0 ? `${hoisted.join("\n")}\n\n` : ""}[${scoped}] {\n${body.join("\n")}\n}`;
115
+ return wrapSfcScopedPreprocessorStyle(content, scoped, lang);
116
+ }
117
+ function toStyleBlockInfo(block) {
118
+ return {
119
+ content: block.content,
120
+ src: block.src ?? null,
121
+ lang: block.lang ?? null,
122
+ scoped: block.scoped,
123
+ module: block.module ? block.moduleName ?? true : false,
124
+ index: block.index
125
+ };
155
126
  }
156
127
  //#endregion
157
128
  //#region src/compiler.ts
@@ -178,26 +149,25 @@ function compileVueModule(filePath, source, options, cache) {
178
149
  warnings: []
179
150
  };
180
151
  const scopeId = generateScopeId(filePath, options.root, options.isProduction, source);
181
- const hasScoped = /<style[^>]*\bscoped\b/.test(source);
182
152
  const result = compileSfc(source, {
183
153
  filename: filePath,
184
154
  sourceMap: options.sourceMap,
185
155
  ssr: options.ssr,
186
156
  vapor: options.vapor,
187
157
  customRenderer: options.customRenderer,
188
- scopeId: hasScoped ? `data-v-${scopeId}` : void 0
158
+ scopeId: `data-v-${scopeId}`
189
159
  });
190
160
  if (result.errors.length > 0) throw new Error(result.errors.join("\n"));
191
161
  const compiled = {
192
162
  code: result.code,
193
163
  css: result.css,
194
164
  scopeId,
195
- hasScoped,
165
+ hasScoped: result.hasScoped,
196
166
  templateHash: result.templateHash,
197
167
  styleHash: result.styleHash,
198
168
  scriptHash: result.scriptHash,
199
169
  macroArtifacts: result.macroArtifacts ?? [],
200
- styles: extractStyleBlocks(source)
170
+ styles: result.styles.map(toStyleBlockInfo)
201
171
  };
202
172
  cache.set(filePath, {
203
173
  compiled,
package/dist/webpack.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as vizeUnplugin } from "./unplugin-D3PLQ0x8.mjs";
1
+ import { t as vizeUnplugin } from "./unplugin-DdUoejrP.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.101.0",
3
+ "version": "0.103.0",
4
4
  "description": "Experimental unplugin-based Vue SFC integration for rollup, webpack, and esbuild powered by Vize",
5
5
  "keywords": [
6
6
  "compiler",
@@ -51,7 +51,7 @@
51
51
  "access": "public"
52
52
  },
53
53
  "dependencies": {
54
- "@vizejs/native": "0.101.0",
54
+ "@vizejs/native": "0.103.0",
55
55
  "oxc-transform": "0.130.0",
56
56
  "unplugin": "3.0.0"
57
57
  },
@@ -64,6 +64,9 @@
64
64
  "vue": "3.6.0-beta.10",
65
65
  "webpack": "5.106.2"
66
66
  },
67
+ "engines": {
68
+ "node": ">=22"
69
+ },
67
70
  "scripts": {
68
71
  "build": "vp pack",
69
72
  "dev": "vp pack --watch",