import { createRequire } from "node:module"; import fs from "node:fs"; import { createFilter, formatPostcssSourceMap, isCSSRequest, normalizePath, transformWithEsbuild } from "vite"; import { computed, shallowRef } from "vue"; import { exactRegex, makeIdFiltersToMatchWithQuery } from "@rolldown/pluginutils"; import path from "node:path"; import crypto from "node:crypto"; import { isatty } from "node:tty"; import { formatWithOptions, inspect } from "node:util"; //#region package.json var version = "6.0.8"; //#endregion //#region src/compiler.ts function resolveCompiler(root) { const compiler = tryResolveCompiler(root) || tryResolveCompiler(); if (!compiler) throw new Error("Failed to resolve vue/compiler-sfc.\n@vitejs/plugin-vue requires vue (>=3.2.25) to be present in the dependency tree."); return compiler; } function tryResolveCompiler(root) { const vueMeta = tryRequire("vue/package.json", root); if (vueMeta && vueMeta.version.split(".")[0] >= 3) return tryRequire("vue/compiler-sfc", root); } const _require = createRequire(import.meta.url); function tryRequire(id, from) { try { return from ? _require(_require.resolve(id, { paths: [from] })) : _require(id); } catch (e) {} } //#endregion //#region src/utils/query.ts function parseVueRequest(id) { const [filename, rawQuery] = id.split(`?`, 2); const query = Object.fromEntries(new URLSearchParams(rawQuery)); if (query.vue != null) query.vue = true; if (query.index != null) query.index = Number(query.index); if (query.raw != null) query.raw = true; if (query.url != null) query.url = true; if (query.scoped != null) query.scoped = true; return { filename, query }; } //#endregion //#region src/utils/descriptorCache.ts const cache = /* @__PURE__ */ new Map(); const hmrCache = /* @__PURE__ */ new Map(); const prevCache = /* @__PURE__ */ new Map(); function createDescriptor(filename, source, { root, isProduction, sourceMap, compiler, template, features }, hmr = false) { const { descriptor, errors } = compiler.parse(source, { filename, sourceMap, templateParseOptions: template?.compilerOptions }); const normalizedPath = normalizePath(path.relative(root, filename)); const componentIdGenerator = features?.componentIdGenerator; if (componentIdGenerator === "filepath") descriptor.id = getHash(normalizedPath); else if (componentIdGenerator === "filepath-source") descriptor.id = getHash(normalizedPath + source); else if (typeof componentIdGenerator === "function") descriptor.id = componentIdGenerator(normalizedPath, source, isProduction, getHash); else descriptor.id = getHash(normalizedPath + (isProduction ? source : "")); (hmr ? hmrCache : cache).set(filename, descriptor); return { descriptor, errors }; } function getPrevDescriptor(filename) { return prevCache.get(filename); } function invalidateDescriptor(filename, hmr = false) { const _cache = hmr ? hmrCache : cache; const prev = _cache.get(filename); _cache.delete(filename); if (prev) prevCache.set(filename, prev); } function getDescriptor(filename, options, createIfNotFound = true, hmr = false, code) { const _cache = hmr ? hmrCache : cache; if (_cache.has(filename)) return _cache.get(filename); if (createIfNotFound) { const { descriptor, errors } = createDescriptor(filename, code ?? fs.readFileSync(filename, "utf-8"), options, hmr); if (errors.length && !hmr) throw errors[0]; return descriptor; } } function getSrcDescriptor(filename, query) { if (query.scoped) return cache.get(`${filename}?src=${query.src}`); return cache.get(filename); } function getTempSrcDescriptor(filename, query) { return { filename, id: query.id || "", styles: [{ scoped: query.scoped, loc: { start: { line: 0, column: 0 } } }], isTemp: true }; } function setSrcDescriptor(filename, entry, scoped) { if (scoped) { cache.set(`${filename}?src=${entry.id}`, entry); return; } cache.set(filename, entry); } function getHash(text) { return crypto.hash("sha256", text, "hex").substring(0, 8); } //#endregion //#region ../../node_modules/.pnpm/slash@5.1.0/node_modules/slash/index.js function slash(path) { if (path.startsWith("\\\\?\\")) return path; return path.replace(/\\/g, "/"); } //#endregion //#region src/utils/error.ts function createRollupError(id, error) { const { message, name, stack } = error; const rollupError = { id, plugin: "vue", message, name, stack }; if ("code" in error && error.loc) rollupError.loc = { file: id, line: error.loc.start.line, column: error.loc.start.column }; return rollupError; } //#endregion //#region src/utils/vapor.ts /** * Resolve the effective Vapor mode for an SFC handled by this plugin. * * `descriptor.vapor` is the per-file opt-in marker. `features.vapor` is the * plugin-level force switch for SFCs that can be forced into Vapor mode. */ function isVaporMode(descriptor, options) { if (descriptor.vapor) return true; if (options.features?.vapor) return canForceVaporMode(descriptor); return false; } /** * `features.vapor` can force template-only SFCs, `