@vizejs/vite-plugin 0.660.0 → 0.662.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-0HswQ2qL.mjs";
1
+ import { t as vize } from "./plugin-BgHrTuUV.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
@@ -906,6 +906,7 @@ function getCompileOptionsForRequest(state, ssr, file) {
906
906
  const mergedOptions = file === void 0 ? state.mergedOptions : state.fileCompilerOptions?.(file) ?? state.mergedOptions;
907
907
  const options = {
908
908
  ...state.root ? { root: state.root } : {},
909
+ ...state.srcResolutions?.size ? { srcResolutions: state.srcResolutions } : {},
909
910
  sourceMap: mergedOptions?.sourceMap ?? (!state.isProduction || !!state.viteBuildSourcemap),
910
911
  ssr,
911
912
  vapor: !ssr && (mergedOptions?.vapor ?? false),
@@ -1050,6 +1051,33 @@ function ownersOfDependency(cache, resolvedDependency) {
1050
1051
  return owners;
1051
1052
  }
1052
1053
  //#endregion
1054
+ //#region ../shared/sfc-src.ts
1055
+ /**
1056
+ * Whether a block `src` is a path relative to the SFC. Any other `src`
1057
+ * (package, alias, absolute) is a module request that the bundler resolves,
1058
+ * as in Vue's SFC spec and `@vitejs/plugin-vue`.
1059
+ */
1060
+ function isRelativeSfcSrc(src) {
1061
+ return src.startsWith("./") || src.startsWith("../");
1062
+ }
1063
+ /** The file a block `src` names: next to the SFC, or where the bundler resolved it. */
1064
+ function sfcSrcFile(importer, tag, src, resolutions) {
1065
+ if (isRelativeSfcSrc(src)) return path.resolve(path.dirname(importer), src);
1066
+ const file = resolutions?.get(src);
1067
+ if (file !== void 0) return file;
1068
+ throw new Error(`[vize] <${tag} src="${src}"> not found: the bundler resolved no file for this module request from ${importer}`);
1069
+ }
1070
+ /** Resolve an SFC's `src` module requests with the bundler's own resolver. */
1071
+ async function resolveSfcSrcRequests(importer, requests, resolve) {
1072
+ const resolutions = /* @__PURE__ */ new Map();
1073
+ for (const request of new Set(requests)) {
1074
+ if (isRelativeSfcSrc(request)) continue;
1075
+ const file = (await resolve(request, importer))?.replace(/[?#].*$/, "");
1076
+ if (file && path.isAbsolute(file)) resolutions.set(request, file);
1077
+ }
1078
+ return resolutions;
1079
+ }
1080
+ //#endregion
1053
1081
  //#region src/compile-options.ts
1054
1082
  function buildCompileFileOptions(filePath, options, scopeId = generateScopeId(filePath, options.root, options.isProd ?? false)) {
1055
1083
  return {
@@ -1140,11 +1168,8 @@ function normalizeStyleBlocks(styles) {
1140
1168
  index: block.index
1141
1169
  }));
1142
1170
  }
1143
- function resolveRelativeSrc(filePath, src) {
1144
- return path.isAbsolute(src) ? src : path.resolve(path.dirname(filePath), src);
1145
- }
1146
- function readSrcImport(filePath, tag, src) {
1147
- const resolvedPath = resolveRelativeSrc(filePath, src);
1171
+ function readSrcImport(filePath, tag, src, resolutions) {
1172
+ const resolvedPath = sfcSrcFile(filePath, tag, src, resolutions);
1148
1173
  try {
1149
1174
  return {
1150
1175
  path: resolvedPath,
@@ -1157,18 +1182,19 @@ function readSrcImport(filePath, tag, src) {
1157
1182
  function stripSrcAttribute(attrs) {
1158
1183
  return attrs.replace(/\s*\bsrc\s*=\s*(?:"[^"]*"|'[^']*')/i, "");
1159
1184
  }
1160
- function inlineSingleSrcBlock(source, filePath, tag, src, dependencies) {
1185
+ function inlineSingleSrcBlock(source, filePath, tag, src, dependencies, resolutions) {
1161
1186
  if (!src) return source;
1162
- const imported = readSrcImport(filePath, tag, src);
1187
+ const imported = readSrcImport(filePath, tag, src, resolutions);
1163
1188
  dependencies.push(imported.path);
1164
1189
  const pattern = new RegExp(`<${tag}\\b([^>]*)\\bsrc\\s*=\\s*(['"])[^'"]+\\2([^>]*)>[\\s\\S]*?<\\/${tag}>`, "i");
1165
1190
  return source.replace(pattern, (_match, beforeSrc, _quote, afterSrc) => {
1166
1191
  return `<${tag}${stripSrcAttribute(`${beforeSrc}${afterSrc}`)}>\n${imported.content}\n</${tag}>`;
1167
1192
  });
1168
1193
  }
1169
- function inlineStyleSrcBlocks(source, filePath, dependencies) {
1170
- return source.replace(/<style\b([^>]*)\bsrc\s*=\s*(['"])([^'"]+)\2([^>]*)>[\s\S]*?<\/style>/gi, (_match, beforeSrc, _quote, src, afterSrc) => {
1171
- const imported = readSrcImport(filePath, "style", src);
1194
+ const STYLE_SRC_BLOCK_RE = /<style\b([^>]*)\bsrc\s*=\s*(['"])([^'"]+)\2([^>]*)>[\s\S]*?<\/style>/gi;
1195
+ function inlineStyleSrcBlocks(source, filePath, dependencies, resolutions) {
1196
+ return source.replace(STYLE_SRC_BLOCK_RE, (_match, beforeSrc, _quote, src, afterSrc) => {
1197
+ const imported = readSrcImport(filePath, "style", src, resolutions);
1172
1198
  dependencies.push(imported.path);
1173
1199
  return `<style${stripSrcAttribute(`${beforeSrc}${afterSrc}`)}>\n${imported.content}\n</style>`;
1174
1200
  });
@@ -1185,7 +1211,8 @@ function inlineStyleSrcBlocks(source, filePath, dependencies) {
1185
1211
  * positives (e.g. `<img src=...>` in a template) simply take the original path.
1186
1212
  */
1187
1213
  const SFC_SRC_ATTRIBUTE_HINT = /\bsrc\s*=/i;
1188
- function resolveSfcSrcImports(filePath, source) {
1214
+ /** Module requests in `src` come from the bundler's `resolutions` (see {@link sfcSrcFile}). */
1215
+ function resolveSfcSrcImports(filePath, source, resolutions) {
1189
1216
  if (!SFC_SRC_ATTRIBUTE_HINT.test(source)) return {
1190
1217
  source,
1191
1218
  dependencies: []
@@ -1193,17 +1220,25 @@ function resolveSfcSrcImports(filePath, source) {
1193
1220
  const dependencies = [];
1194
1221
  const srcInfo = native.extractSfcSrcInfo(source, filePath);
1195
1222
  let resolvedSource = source;
1196
- resolvedSource = inlineSingleSrcBlock(resolvedSource, filePath, "script", srcInfo.scriptSrc, dependencies);
1197
- resolvedSource = inlineSingleSrcBlock(resolvedSource, filePath, "template", srcInfo.templateSrc, dependencies);
1198
- resolvedSource = inlineStyleSrcBlocks(resolvedSource, filePath, dependencies);
1223
+ resolvedSource = inlineSingleSrcBlock(resolvedSource, filePath, "script", srcInfo.scriptSrc, dependencies, resolutions);
1224
+ resolvedSource = inlineSingleSrcBlock(resolvedSource, filePath, "template", srcInfo.templateSrc, dependencies, resolutions);
1225
+ resolvedSource = inlineStyleSrcBlocks(resolvedSource, filePath, dependencies, resolutions);
1199
1226
  return {
1200
1227
  source: resolvedSource,
1201
1228
  dependencies
1202
1229
  };
1203
1230
  }
1231
+ /** The `src` module requests (not relative paths) the inliner will need resolved. */
1232
+ function listSfcSrcRequests(filePath, source) {
1233
+ if (!SFC_SRC_ATTRIBUTE_HINT.test(source)) return [];
1234
+ const srcInfo = native.extractSfcSrcInfo(source, filePath);
1235
+ const requests = [srcInfo.scriptSrc, srcInfo.templateSrc];
1236
+ for (const match of source.matchAll(STYLE_SRC_BLOCK_RE)) requests.push(match[3]);
1237
+ return requests.filter((src) => !!src && !isRelativeSfcSrc(src));
1238
+ }
1204
1239
  function compileFile(filePath, cache, options, source, diagnostics) {
1205
1240
  const content = source ?? fs.readFileSync(filePath, "utf-8");
1206
- const resolved = resolveSfcSrcImports(filePath, content);
1241
+ const resolved = resolveSfcSrcImports(filePath, content, options.srcResolutions?.get(filePath));
1207
1242
  const scopeId = generateScopeId(filePath, options.root, options.isProd ?? false, content);
1208
1243
  const result = compileSfc(resolved.source, buildCompileFileOptions(filePath, options, scopeId));
1209
1244
  if (result.errors.length > 0) throw new VizeSfcCompileError(filePath, result.errors);
@@ -1266,7 +1301,7 @@ function compileJsxModule(filePath, source, options = {}) {
1266
1301
  function compileBatch(files, cache, options) {
1267
1302
  const dependenciesByPath = /* @__PURE__ */ new Map();
1268
1303
  const resolvedFiles = files.map((file) => {
1269
- const resolved = resolveSfcSrcImports(file.path, file.source);
1304
+ const resolved = resolveSfcSrcImports(file.path, file.source, options.srcResolutions?.get(file.path));
1270
1305
  dependenciesByPath.set(file.path, resolved.dependencies);
1271
1306
  return {
1272
1307
  path: file.path,
@@ -1790,6 +1825,60 @@ function compileScopedBatch(files, state) {
1790
1825
  };
1791
1826
  }
1792
1827
  //#endregion
1828
+ //#region src/plugin/load-sfc.ts
1829
+ function shouldLoadVueSfcRequest(request) {
1830
+ if (!request.isVueSfcPath || request.isVueStyleQuery || request.hasMacroQuery || request.hasDefinePageQuery) return false;
1831
+ if (!request.querySuffix) return true;
1832
+ const params = new URLSearchParams(request.querySuffix.slice(1));
1833
+ if (params.has("raw") || params.has("url") || params.has("worker") || params.has("sharedworker")) return false;
1834
+ return params.has("nuxt_component");
1835
+ }
1836
+ function getLoadableVueSfcPath(request) {
1837
+ if (!shouldLoadVueSfcRequest(request)) return null;
1838
+ return classifyVitePluginRequest(request.normalizedFsId ?? request.path).normalizedVuePath;
1839
+ }
1840
+ function shouldLoadCompiledVueSfcPath(state, realPath, hasNuxtComponentQuery = false) {
1841
+ const isNodeModulesPath = realPath.includes("node_modules");
1842
+ if (!(state.mergedOptions.handleNodeModulesVue ?? true) && isNodeModulesPath && hasNuxtComponentQuery) {
1843
+ state.logger.log(`load: skipping node_modules Vue SFC ${realPath}`);
1844
+ return false;
1845
+ }
1846
+ if (!isNodeModulesPath && !state.filter(realPath)) {
1847
+ state.logger.log(`load: skipping filtered Vue SFC ${realPath}`);
1848
+ return false;
1849
+ }
1850
+ return true;
1851
+ }
1852
+ //#endregion
1853
+ //#region src/plugin/src-requests.ts
1854
+ /** Vite's own resolver (aliases, packages, every `resolveId` plugin). */
1855
+ function viteHostResolve(resolve) {
1856
+ return async (request, importer) => {
1857
+ const result = await resolve(request, importer);
1858
+ return result && !result.external ? result.id : null;
1859
+ };
1860
+ }
1861
+ /**
1862
+ * Resolve one SFC's `src` module requests before the synchronous compile reads
1863
+ * them from `state.srcResolutions`. A request left unresolved fails that compile.
1864
+ */
1865
+ async function prepareSfcSrcRequests(state, resolve, file, source) {
1866
+ const requests = listSfcSrcRequests(file, source);
1867
+ if (requests.length === 0) {
1868
+ state.srcResolutions?.delete(file);
1869
+ return;
1870
+ }
1871
+ (state.srcResolutions ??= /* @__PURE__ */ new Map()).set(file, await resolveSfcSrcRequests(file, requests, resolve));
1872
+ }
1873
+ /** A `load` that compiles its SFC on demand resolves the SFC's requests first. */
1874
+ async function prepareLoadSrcRequests(state, resolve, id) {
1875
+ if (!id.includes(".vue")) return;
1876
+ const request = classifyVitePluginRequest(id);
1877
+ const file = request.vizeVirtualPath ?? fromPluginVisibleVirtualId(id) ?? getLoadableVueSfcPath(request);
1878
+ if (!file?.endsWith(".vue") || state.cache.has(file) || state.ssrCache.has(file) || state.srcResolutions?.has(file) || !fs.existsSync(file)) return;
1879
+ await prepareSfcSrcRequests(state, resolve, file, fs.readFileSync(file, "utf-8"));
1880
+ }
1881
+ //#endregion
1793
1882
  //#region src/plugin/precompile-run.ts
1794
1883
  /**
1795
1884
  * The pre-compilation pass.
@@ -1827,7 +1916,7 @@ function openCacheForRun(state, batchOptions) {
1827
1916
  /**
1828
1917
  * Pre-compile all Vue files matching scan patterns.
1829
1918
  */
1830
- async function compileAll(state, owners = []) {
1919
+ async function compileAll(state, owners = [], resolve) {
1831
1920
  const startTime = performance.now();
1832
1921
  const sfcFiles = (await glob(state.scanPatterns, {
1833
1922
  cwd: state.root,
@@ -1921,6 +2010,7 @@ async function compileAll(state, owners = []) {
1921
2010
  });
1922
2011
  }
1923
2012
  if (fileContents.length === 0) continue;
2013
+ if (resolve) for (const file of fileContents) await prepareSfcSrcRequests(state, resolve, file.path, file.source);
1924
2014
  const result = compileScopedBatch(fileContents, state);
1925
2015
  const chunkFailedCount = result.results.filter((fileResult) => fileResult.errors.length > 0).length;
1926
2016
  failedCount += chunkFailedCount;
@@ -2979,31 +3069,6 @@ async function resolveIdHook(ctx, state, id, importer, options) {
2979
3069
  return null;
2980
3070
  }
2981
3071
  //#endregion
2982
- //#region src/plugin/load-sfc.ts
2983
- function shouldLoadVueSfcRequest(request) {
2984
- if (!request.isVueSfcPath || request.isVueStyleQuery || request.hasMacroQuery || request.hasDefinePageQuery) return false;
2985
- if (!request.querySuffix) return true;
2986
- const params = new URLSearchParams(request.querySuffix.slice(1));
2987
- if (params.has("raw") || params.has("url") || params.has("worker") || params.has("sharedworker")) return false;
2988
- return params.has("nuxt_component");
2989
- }
2990
- function getLoadableVueSfcPath(request) {
2991
- if (!shouldLoadVueSfcRequest(request)) return null;
2992
- return classifyVitePluginRequest(request.normalizedFsId ?? request.path).normalizedVuePath;
2993
- }
2994
- function shouldLoadCompiledVueSfcPath(state, realPath, hasNuxtComponentQuery = false) {
2995
- const isNodeModulesPath = realPath.includes("node_modules");
2996
- if (!(state.mergedOptions.handleNodeModulesVue ?? true) && isNodeModulesPath && hasNuxtComponentQuery) {
2997
- state.logger.log(`load: skipping node_modules Vue SFC ${realPath}`);
2998
- return false;
2999
- }
3000
- if (!isNodeModulesPath && !state.filter(realPath)) {
3001
- state.logger.log(`load: skipping filtered Vue SFC ${realPath}`);
3002
- return false;
3003
- }
3004
- return true;
3005
- }
3006
- //#endregion
3007
3072
  //#region src/plugin/vite-transform.ts
3008
3073
  function createVirtualTypeScriptTransformer(viteApi) {
3009
3074
  return async (code, id) => {
@@ -3438,6 +3503,7 @@ async function handleHotUpdateHook(state, ctx, options = {}) {
3438
3503
  if (initialModules?.size === 0) return [];
3439
3504
  const source = await read();
3440
3505
  const prevCompiled = state.cache.get(file);
3506
+ if (options.resolve) await prepareSfcSrcRequests(state, options.resolve, file, source);
3441
3507
  compileFile(file, state.cache, getCompileOptionsForRequest(state, false, file), source);
3442
3508
  state.ssrCache.delete(file);
3443
3509
  const newCompiled = state.cache.get(file);
@@ -3560,6 +3626,7 @@ async function handleHotUpdateEnvironmentHook(state, environment, options) {
3560
3626
  }, {
3561
3627
  ensureAcceptingClientModule: (vueFile) => environment.moduleGraph.ensureEntryFromUrl(toPluginVisibleVirtualId(vueFile), false),
3562
3628
  requireAcceptingClientModule: true,
3629
+ resolve: viteHostResolve((request, importer) => environment.pluginContainer.resolveId(request, importer)),
3563
3630
  onRecompileError: () => {
3564
3631
  recompileFailed = true;
3565
3632
  }
@@ -3813,6 +3880,7 @@ function createPostTransformPlugin(state) {
3813
3880
  try {
3814
3881
  const isSsr = !!transformOptions?.ssr;
3815
3882
  const extractCss = shouldExtractCssForRequest(state, isSsr);
3883
+ await prepareSfcSrcRequests(state, viteHostResolve((request, importer) => this.resolve(request, importer, { skipSelf: true })), id, source);
3816
3884
  const compiled = compileFile(id, getEnvironmentCache(state, isSsr), getCompileOptionsForRequest(state, isSsr, id), source);
3817
3885
  syncCollectedCssForFile({
3818
3886
  ...state,
@@ -4643,7 +4711,7 @@ function vize(options = {}, compilerDefaults = {}, hostContext) {
4643
4711
  await compileAll({
4644
4712
  ...state,
4645
4713
  extractCss: shouldExtractCssForBuild(state, this)
4646
- }, precompileInputOwners(this, precompileConfig));
4714
+ }, precompileInputOwners(this, precompileConfig), viteHostResolve((request, importer) => this.resolve(request, importer, { skipSelf: true })));
4647
4715
  } catch (error) {
4648
4716
  if (!(error instanceof PrecompileDiagnosticsError)) throw error;
4649
4717
  state.logger.warn(`${error.message}\nStartup scan diagnostics are deferred until import.`);
@@ -4656,7 +4724,8 @@ function vize(options = {}, compilerDefaults = {}, hostContext) {
4656
4724
  ssr: resolveHookSsr(this, options)
4657
4725
  });
4658
4726
  },
4659
- load(id, loadOptions) {
4727
+ async load(id, loadOptions) {
4728
+ await prepareLoadSrcRequests(state, viteHostResolve((request, importer) => this.resolve(request, importer, { skipSelf: true })), id);
4660
4729
  return loadHook(state, id, {
4661
4730
  ...loadOptions,
4662
4731
  ssr: resolveHookSsr(this, loadOptions),
@@ -4676,7 +4745,8 @@ function vize(options = {}, compilerDefaults = {}, hostContext) {
4676
4745
  return id?.includes(".vue") ? true : void 0;
4677
4746
  },
4678
4747
  async handleHotUpdate(ctx) {
4679
- return handleHotUpdateHook(state, ctx);
4748
+ const container = ctx.server.environments?.client?.pluginContainer ?? ctx.server.pluginContainer;
4749
+ return handleHotUpdateHook(state, ctx, { resolve: viteHostResolve((request, importer) => container.resolveId(request, importer)) });
4680
4750
  },
4681
4751
  generateBundle(_, bundle) {
4682
4752
  handleGenerateBundleHook({
@@ -0,0 +1,2 @@
1
+ import { t as vize } from "./plugin-BgHrTuUV.mjs";
2
+ export { vize };
@@ -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-sV6VpY9P.mjs");
403
+ const { vize } = await import("./plugin-C9HLsCVG.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.660.0",
3
+ "version": "0.662.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.660.0",
55
- "@vizejs/unplugin": "0.660.0",
54
+ "@vizejs/native": "0.662.0",
55
+ "@vizejs/unplugin": "0.662.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.660.0"
60
+ "vize": "0.662.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "25.9.2",
@@ -1,2 +0,0 @@
1
- import { t as vize } from "./plugin-0HswQ2qL.mjs";
2
- export { vize };