@vizejs/vite-plugin 0.668.0 → 0.670.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/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as vize } from "./plugin-tuM13VgA.mjs";
1
+ import { t as vize } from "./plugin-DZ3byUmi.mjs";
2
2
  import { u as rewriteStaticAssetUrls } from "./vue-version-BFh0eI6J.mjs";
3
3
  import { a as resolveViteConfigExport, i as resolveConfigExport, n as defineConfig, o as vizeConfigStore, r as loadConfig, t as VIZE_CONFIG_FILE_ENV } from "./config-LlMZcDZI.mjs";
4
4
  //#region src/index.ts
@@ -0,0 +1,2 @@
1
+ import { t as vize } from "./plugin-DZ3byUmi.mjs";
2
+ export { vize };
@@ -728,7 +728,10 @@ function generateOutputWithMap(compiled, options) {
728
728
  params.set("index", String(block.index));
729
729
  if (block.scoped) params.set("scoped", `data-v-${compiled.scopeId}`);
730
730
  params.set("lang", lang);
731
- if (customElement) {
731
+ if (block.external) {
732
+ if (customElement) throw new Error(`<style src="${block.src}"> resolved to an external module, so it cannot be inlined into a custom element`);
733
+ styleImports.push(`import ${JSON.stringify(block.src)};`);
734
+ } else if (customElement) {
732
735
  if (isCssModule(block)) throw new Error("<style module> is not supported in custom element mode");
733
736
  params.set("inline", "");
734
737
  const bindingName = `_style_${block.index}`;
@@ -1076,11 +1079,11 @@ function ownersOfDependency(cache, resolvedDependency) {
1076
1079
  function isRelativeSfcSrc(src) {
1077
1080
  return src.startsWith("./") || src.startsWith("../");
1078
1081
  }
1079
- /** The file a block `src` names: next to the SFC, or where the bundler resolved it. */
1080
- function sfcSrcFile(importer, tag, src, resolutions) {
1081
- if (isRelativeSfcSrc(src)) return path.resolve(path.dirname(importer), src);
1082
- const file = resolutions?.get(src);
1083
- if (file !== void 0) return file;
1082
+ /** Where a block `src` points: next to the SFC, or where the bundler resolved it. */
1083
+ function sfcSrcTarget(importer, tag, src, resolutions) {
1084
+ if (isRelativeSfcSrc(src)) return { file: path.resolve(path.dirname(importer), src) };
1085
+ const resolution = resolutions?.get(src);
1086
+ if (resolution !== void 0) return resolution;
1084
1087
  throw new Error(`[vize] <${tag} src="${src}"> not found: the bundler resolved no file for this module request from ${importer}`);
1085
1088
  }
1086
1089
  /** Resolve an SFC's `src` module requests with the bundler's own resolver. */
@@ -1088,8 +1091,14 @@ async function resolveSfcSrcRequests(importer, requests, resolve) {
1088
1091
  const resolutions = /* @__PURE__ */ new Map();
1089
1092
  for (const request of new Set(requests)) {
1090
1093
  if (isRelativeSfcSrc(request)) continue;
1091
- const file = (await resolve(request, importer))?.replace(/[?#].*$/, "");
1092
- if (file && path.isAbsolute(file)) resolutions.set(request, file);
1094
+ const resolved = await resolve(request, importer);
1095
+ if (!resolved) continue;
1096
+ if (resolved.external) {
1097
+ resolutions.set(request, { external: true });
1098
+ continue;
1099
+ }
1100
+ const file = resolved.id.replace(/[?#].*$/, "");
1101
+ if (path.isAbsolute(file)) resolutions.set(request, { file });
1093
1102
  }
1094
1103
  return resolutions;
1095
1104
  }
@@ -1115,6 +1124,14 @@ function splitSrcAttribute(tag, openTag) {
1115
1124
  openTag: `${head}${rest}>`
1116
1125
  };
1117
1126
  }
1127
+ function needsContents(kind, block) {
1128
+ const compiled = "is compiled into the component, so vize needs its contents";
1129
+ if (kind === "template") return `the template ${compiled}`;
1130
+ if (kind === "script setup") return `<script setup> ${compiled}`;
1131
+ if (block.scoped) return "a scoped style needs its contents";
1132
+ if (block.module) return "a CSS module needs its contents";
1133
+ return null;
1134
+ }
1118
1135
  /** The `src` blocks the native parser finds, so `src` text in scripts or comments is not one. */
1119
1136
  function collectSrcBlocks(parseSfc, filePath, bytes, source) {
1120
1137
  let parsed;
@@ -1126,7 +1143,7 @@ function collectSrcBlocks(parseSfc, filePath, bytes, source) {
1126
1143
  const blocks = [
1127
1144
  ["template", parsed.template],
1128
1145
  ["script", parsed.script],
1129
- ["script", parsed.scriptSetup],
1146
+ ["script setup", parsed.scriptSetup],
1130
1147
  ...parsed.styles.map((style, index) => [
1131
1148
  "style",
1132
1149
  style,
@@ -1134,16 +1151,19 @@ function collectSrcBlocks(parseSfc, filePath, bytes, source) {
1134
1151
  ])
1135
1152
  ];
1136
1153
  const found = [];
1137
- for (const [tag, block, styleIndex] of blocks) {
1154
+ for (const [kind, block, styleIndex] of blocks) {
1138
1155
  if (!block) continue;
1156
+ const tag = kind === "script setup" ? "script" : kind;
1139
1157
  const { start, tagStart, tagEnd } = block.loc;
1140
1158
  const split = splitSrcAttribute(tag, bytes.subarray(tagStart, start).toString("utf8"));
1141
1159
  if (split) found.push({
1160
+ kind,
1142
1161
  tag,
1143
1162
  ...split,
1144
1163
  tagStart,
1145
1164
  tagEnd,
1146
- styleIndex
1165
+ styleIndex,
1166
+ needsContents: needsContents(kind, block)
1147
1167
  });
1148
1168
  }
1149
1169
  return found;
@@ -1153,46 +1173,66 @@ function listSfcSrcRequests(parseSfc, filePath, source) {
1153
1173
  if (!SRC_BLOCK_HINT.test(source)) return [];
1154
1174
  return collectSrcBlocks(parseSfc, filePath, Buffer.from(source), source).map((block) => block.src).filter((src) => !isRelativeSfcSrc(src));
1155
1175
  }
1156
- function readSrcBlock(filePath, tag, src, resolutions) {
1157
- const resolved = sfcSrcFile(filePath, tag, src, resolutions);
1176
+ function readSrcFile(filePath, tag, src, file) {
1158
1177
  try {
1159
- return {
1160
- path: resolved,
1161
- content: fs.readFileSync(resolved, "utf8")
1162
- };
1178
+ return fs.readFileSync(file, "utf8");
1163
1179
  } catch {
1164
- throw new Error(`[vize] <${tag} src="${src}"> not found (resolved: ${resolved}) in ${filePath}`);
1180
+ throw new Error(`[vize] <${tag} src="${src}"> not found (resolved: ${file}) in ${filePath}`);
1181
+ }
1182
+ }
1183
+ /**
1184
+ * The block for an external module, as `@vitejs/plugin-vue` keeps it: a style
1185
+ * stays in place for the output to import (`null`), a script imports it.
1186
+ */
1187
+ function externalSrcBlock(filePath, block) {
1188
+ if (block.needsContents) {
1189
+ const tag = `${block.openTag.slice(0, -1)} src="${block.src}">`;
1190
+ throw new Error(`[vize] ${tag} resolved to an external module; ${block.needsContents}. Let the bundler bundle "${block.src}" (in ${filePath})`);
1165
1191
  }
1192
+ if (block.kind === "style") return null;
1193
+ const request = JSON.stringify(block.src);
1194
+ return `${block.openTag}\nimport __vize_src_main__ from ${request};\nexport * from ${request};\nexport default __vize_src_main__;\n<\/script>`;
1166
1195
  }
1167
1196
  /**
1168
1197
  * Inline `<template src>`, `<script src>` and `<style src>` files into the SFC
1169
1198
  * source. Blocks are located by the native parser. Module requests come from
1170
- * the bundler's `resolutions` (see {@link sfcSrcFile}).
1199
+ * the bundler's `resolutions`; an external one stays an import.
1171
1200
  */
1172
1201
  function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
1173
1202
  const styleSrcs = /* @__PURE__ */ new Map();
1174
1203
  if (!SRC_BLOCK_HINT.test(source)) return {
1175
1204
  source,
1176
1205
  dependencies: [],
1177
- styleSrcs
1206
+ styleSrcs,
1207
+ imports: []
1178
1208
  };
1179
1209
  const bytes = Buffer.from(source);
1180
1210
  const edits = [];
1181
1211
  const dependencies = [];
1212
+ const imports = [];
1182
1213
  for (const block of collectSrcBlocks(parseSfc, filePath, bytes, source)) {
1183
- const file = readSrcBlock(filePath, block.tag, block.src, resolutions);
1184
- dependencies.push(file.path);
1185
- if (block.styleIndex !== void 0) styleSrcs.set(block.styleIndex, file.path);
1186
- edits.push({
1214
+ const target = sfcSrcTarget(filePath, block.tag, block.src, resolutions);
1215
+ let text;
1216
+ if ("external" in target) {
1217
+ text = externalSrcBlock(filePath, block);
1218
+ if (text === null) imports.push(block.src);
1219
+ } else {
1220
+ const content = readSrcFile(filePath, block.tag, block.src, target.file);
1221
+ dependencies.push(target.file);
1222
+ if (block.styleIndex !== void 0) styleSrcs.set(block.styleIndex, target.file);
1223
+ text = `${block.openTag}\n${content}\n</${block.tag}>`;
1224
+ }
1225
+ if (text !== null) edits.push({
1187
1226
  start: block.tagStart,
1188
1227
  end: block.tagEnd,
1189
- text: `${block.openTag}\n${file.content}\n</${block.tag}>`
1228
+ text
1190
1229
  });
1191
1230
  }
1192
1231
  if (edits.length === 0) return {
1193
1232
  source,
1194
1233
  dependencies,
1195
- styleSrcs
1234
+ styleSrcs,
1235
+ imports
1196
1236
  };
1197
1237
  edits.sort((a, b) => a.start - b.start);
1198
1238
  const parts = [];
@@ -1205,9 +1245,20 @@ function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
1205
1245
  return {
1206
1246
  source: Buffer.concat(parts).toString("utf8"),
1207
1247
  dependencies,
1208
- styleSrcs
1248
+ styleSrcs,
1249
+ imports
1209
1250
  };
1210
1251
  }
1252
+ /**
1253
+ * A `<style src>` the compiler still sees was not inlined. Only an external one
1254
+ * may stay, as an import; any other was written in a form the inliner cannot read.
1255
+ */
1256
+ function assertSfcStyleSrcImports(filePath, styles, imports = []) {
1257
+ for (const style of styles) {
1258
+ if (style.src == null || imports.includes(style.src)) continue;
1259
+ throw new Error(`[vize] ${filePath}: <style src=${JSON.stringify(style.src)}> could not be inlined. Write it as <style src="./file.css"> with a quoted path.`);
1260
+ }
1261
+ }
1211
1262
  //#endregion
1212
1263
  //#region src/compile-options.ts
1213
1264
  function buildCompileFileOptions(filePath, options, scopeId = generateScopeId(filePath, options.root, options.isProd ?? false)) {
@@ -1288,11 +1339,12 @@ var VizeSfcCompileError = class extends Error {
1288
1339
  function formatCompileErrorMessage(filePath, diagnostics) {
1289
1340
  return `[vize] Compilation failed in ${filePath}:\n${diagnostics.map((diagnostic) => ` - ${diagnostic}`).join("\n")}`;
1290
1341
  }
1291
- function normalizeStyleBlocks(styles, styleSrcs) {
1342
+ function normalizeStyleBlocks(styles, inlined) {
1292
1343
  if (!styles) return [];
1293
1344
  return styles.map((block) => ({
1294
1345
  content: block.content,
1295
- src: styleSrcs?.get(block.index) ?? block.src ?? null,
1346
+ src: inlined?.styleSrcs.get(block.index) ?? block.src ?? null,
1347
+ ...block.src != null && inlined?.imports.includes(block.src) ? { external: true } : {},
1296
1348
  lang: block.lang ?? null,
1297
1349
  scoped: block.scoped,
1298
1350
  module: block.module ? block.moduleName ?? true : false,
@@ -1305,6 +1357,7 @@ function compileFile(filePath, cache, options, source, diagnostics) {
1305
1357
  const scopeId = generateScopeId(filePath, options.root, options.isProd ?? false, content);
1306
1358
  const result = compileSfc(resolved.source, buildCompileFileOptions(filePath, options, scopeId));
1307
1359
  if (result.errors.length > 0) throw new VizeSfcCompileError(filePath, result.errors);
1360
+ assertSfcStyleSrcImports(filePath, result.styles ?? [], resolved.imports);
1308
1361
  if (result.warnings.length > 0 && (diagnostics?.logWarnings ?? true)) result.warnings.forEach((warning) => {
1309
1362
  console.warn(`[vize] Warning in ${filePath}: ${warning}`);
1310
1363
  });
@@ -1318,7 +1371,7 @@ function compileFile(filePath, cache, options, source, diagnostics) {
1318
1371
  styleHash: result.styleHash,
1319
1372
  scriptHash: result.scriptHash,
1320
1373
  macroArtifacts: result.macroArtifacts ?? [],
1321
- styles: normalizeStyleBlocks(result.styles, resolved.styleSrcs),
1374
+ styles: normalizeStyleBlocks(result.styles, resolved),
1322
1375
  dependencies: [...resolved.dependencies, ...result.dependencies ?? []]
1323
1376
  };
1324
1377
  cache.set(filePath, compiled);
@@ -1362,12 +1415,10 @@ function compileJsxModule(filePath, source, options = {}) {
1362
1415
  * Returns per-file results with content hashes for HMR.
1363
1416
  */
1364
1417
  function compileBatch(files, cache, options) {
1365
- const dependenciesByPath = /* @__PURE__ */ new Map();
1366
- const styleSrcsByPath = /* @__PURE__ */ new Map();
1418
+ const inlinedByPath = /* @__PURE__ */ new Map();
1367
1419
  const resolvedFiles = files.map((file) => {
1368
1420
  const resolved = inlineSfcSrcBlocks(native.parseSfc, file.path, file.source, options.srcResolutions?.get(file.path));
1369
- dependenciesByPath.set(file.path, resolved.dependencies);
1370
- styleSrcsByPath.set(file.path, resolved.styleSrcs);
1421
+ inlinedByPath.set(file.path, resolved);
1371
1422
  return {
1372
1423
  path: file.path,
1373
1424
  source: resolved.source,
@@ -1393,6 +1444,11 @@ function compileBatch(files, cache, options) {
1393
1444
  if (fallback.macroArtifacts !== void 0) fileResult.macroArtifacts = fallback.macroArtifacts;
1394
1445
  delete fileResult.moduleShape;
1395
1446
  }
1447
+ for (const fileResult of result.results) {
1448
+ if (fileResult.errors.length > 0) continue;
1449
+ const imports = inlinedByPath.get(fileResult.path)?.imports;
1450
+ assertSfcStyleSrcImports(fileResult.path, fileResult.styles ?? [], imports);
1451
+ }
1396
1452
  for (const fileResult of result.results) {
1397
1453
  if (fileResult.errors.length === 0) cache.set(fileResult.path, {
1398
1454
  code: fileResult.code,
@@ -1404,8 +1460,8 @@ function compileBatch(files, cache, options) {
1404
1460
  styleHash: fileResult.styleHash,
1405
1461
  scriptHash: fileResult.scriptHash,
1406
1462
  macroArtifacts: fileResult.macroArtifacts ?? [],
1407
- styles: normalizeStyleBlocks(fileResult.styles, styleSrcsByPath.get(fileResult.path)),
1408
- dependencies: [...dependenciesByPath.get(fileResult.path) ?? [], ...fileResult.dependencies ?? []]
1463
+ styles: normalizeStyleBlocks(fileResult.styles, inlinedByPath.get(fileResult.path)),
1464
+ dependencies: [...inlinedByPath.get(fileResult.path)?.dependencies ?? [], ...fileResult.dependencies ?? []]
1409
1465
  });
1410
1466
  if (fileResult.errors.length > 0) console.error(formatCompileErrorMessage(fileResult.path, fileResult.errors));
1411
1467
  if (fileResult.warnings.length > 0) fileResult.warnings.forEach((warning) => {
@@ -1916,13 +1972,6 @@ function shouldLoadCompiledVueSfcPath(state, realPath, hasNuxtComponentQuery = f
1916
1972
  }
1917
1973
  //#endregion
1918
1974
  //#region src/plugin/src-requests.ts
1919
- /** Vite's own resolver (aliases, packages, every `resolveId` plugin). */
1920
- function viteHostResolve(resolve) {
1921
- return async (request, importer) => {
1922
- const result = await resolve(request, importer);
1923
- return result && !result.external ? result.id : null;
1924
- };
1925
- }
1926
1975
  /**
1927
1976
  * Resolve one SFC's `src` module requests before the synchronous compile reads
1928
1977
  * them from `state.srcResolutions`. A request left unresolved fails that compile.
@@ -3691,7 +3740,7 @@ async function handleHotUpdateEnvironmentHook(state, environment, options) {
3691
3740
  }, {
3692
3741
  ensureAcceptingClientModule: (vueFile) => environment.moduleGraph.ensureEntryFromUrl(toPluginVisibleVirtualId(vueFile), false),
3693
3742
  requireAcceptingClientModule: true,
3694
- resolve: viteHostResolve((request, importer) => environment.pluginContainer.resolveId(request, importer)),
3743
+ resolve: (request, importer) => environment.pluginContainer.resolveId(request, importer),
3695
3744
  onRecompileError: () => {
3696
3745
  recompileFailed = true;
3697
3746
  }
@@ -3945,7 +3994,7 @@ function createPostTransformPlugin(state) {
3945
3994
  try {
3946
3995
  const isSsr = !!transformOptions?.ssr;
3947
3996
  const extractCss = shouldExtractCssForRequest(state, isSsr);
3948
- await prepareSfcSrcRequests(state, viteHostResolve((request, importer) => this.resolve(request, importer, { skipSelf: true })), id, source);
3997
+ await prepareSfcSrcRequests(state, (request, importer) => this.resolve(request, importer, { skipSelf: true }), id, source);
3949
3998
  const compiled = compileFile(id, getEnvironmentCache(state, isSsr), getCompileOptionsForRequest(state, isSsr, id), source);
3950
3999
  syncCollectedCssForFile({
3951
4000
  ...state,
@@ -4775,7 +4824,7 @@ function vize(options = {}, compilerDefaults = {}, hostContext) {
4775
4824
  await compileAll({
4776
4825
  ...state,
4777
4826
  extractCss: shouldExtractCssForBuild(state, this)
4778
- }, precompileInputOwners(this, precompileConfig), viteHostResolve((request, importer) => this.resolve(request, importer, { skipSelf: true })));
4827
+ }, precompileInputOwners(this, precompileConfig), (request, importer) => this.resolve(request, importer, { skipSelf: true }));
4779
4828
  } catch (error) {
4780
4829
  if (!(error instanceof PrecompileDiagnosticsError)) throw error;
4781
4830
  state.logger.warn(`${error.message}\nStartup scan diagnostics are deferred until import.`);
@@ -4789,7 +4838,7 @@ function vize(options = {}, compilerDefaults = {}, hostContext) {
4789
4838
  });
4790
4839
  },
4791
4840
  async load(id, loadOptions) {
4792
- const sfcSource = await prepareLoadSrcRequests(state, viteHostResolve((request, importer) => this.resolve(request, importer, { skipSelf: true })), id);
4841
+ const sfcSource = await prepareLoadSrcRequests(state, (request, importer) => this.resolve(request, importer, { skipSelf: true }), id);
4793
4842
  return loadHook(state, id, {
4794
4843
  ...loadOptions,
4795
4844
  ssr: resolveHookSsr(this, loadOptions),
@@ -4811,7 +4860,7 @@ function vize(options = {}, compilerDefaults = {}, hostContext) {
4811
4860
  },
4812
4861
  async handleHotUpdate(ctx) {
4813
4862
  const container = ctx.server.environments?.client?.pluginContainer ?? ctx.server.pluginContainer;
4814
- return handleHotUpdateHook(state, ctx, { resolve: viteHostResolve((request, importer) => container.resolveId(request, importer)) });
4863
+ return handleHotUpdateHook(state, ctx, { resolve: (request, importer) => container.resolveId(request, importer) });
4815
4864
  },
4816
4865
  generateBundle(_, bundle) {
4817
4866
  handleGenerateBundleHook({
@@ -400,7 +400,7 @@ function defineConfig(config = {}, integration = {}) {
400
400
  const legacy = compiler !== false && (await import("./vue-version-DOjZaMiI.mjs")).isLegacyVueCompatibilityMode(compiler);
401
401
  const plugins = compiler === false || legacy ? [...vp.plugins ?? []] : await withoutVueCompiler(vp.plugins ?? []);
402
402
  if (compiler !== false) {
403
- const { vize } = await import("./plugin-CFfuvH8O.mjs");
403
+ const { vize } = await import("./plugin-BzoGUulL.mjs");
404
404
  plugins.push(vize({
405
405
  ...plugin,
406
406
  configMode: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/vite-plugin",
3
- "version": "0.668.0",
3
+ "version": "0.670.0",
4
4
  "description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
5
5
  "keywords": [
6
6
  "compiler",
@@ -51,13 +51,13 @@
51
51
  "access": "public"
52
52
  },
53
53
  "dependencies": {
54
- "@vizejs/native": "0.668.0",
55
- "@vizejs/unplugin": "0.668.0",
54
+ "@vizejs/native": "0.670.0",
55
+ "@vizejs/unplugin": "0.670.0",
56
56
  "jsonc-parser": "^3.3.1",
57
57
  "oxc-parser": "0.144.0",
58
58
  "picomatch": "4.0.5",
59
59
  "tinyglobby": "0.2.17",
60
- "vize": "0.668.0"
60
+ "vize": "0.670.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "25.9.2",
@@ -1,2 +0,0 @@
1
- import { t as vize } from "./plugin-tuM13VgA.mjs";
2
- export { vize };