@vizejs/vite-plugin 0.663.0 → 0.665.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-
|
|
1
|
+
import { t as vize } from "./plugin-CAu9ew7B.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
|
|
@@ -3,7 +3,7 @@ import { a as resolveViteConfigExport, i as resolveConfigExport, o as vizeConfig
|
|
|
3
3
|
import { n as registerResolvedVizeConfig, r as unregisterResolvedVizeConfig } from "./config-bridge-Dv6U7_RC.mjs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import * as native from "@vizejs/native";
|
|
6
|
-
import { buildInspectorGraph, chunkVitePrecompileFiles, classifyVitePluginRequest, createViteBareImportBases, createViteBareImportCandidates, createViteVirtualId, detectViteHmrUpdateType, diffVitePrecompileFiles, generateSfcScopeId, generateViteHmrCode, hasViteHmrChanges, isViteBareSpecifier, normalizeViteCssModuleFilename, normalizeViteDevMiddlewareUrl, normalizeVitePrecompileBatchSize, normalizeViteRequireBase, normalizeViteResolvedVuePath, resolveViteAliasRequest, resolveViteCssImports, resolveViteRelativeImport, resolveViteVuePath, scopeViteCssForPipeline, splitViteIdQuery, toViteBrowserImportPrefix, transformViteCssVarsForPipeline } from "@vizejs/native";
|
|
6
|
+
import { buildInspectorGraph, chunkVitePrecompileFiles, classifyVitePluginRequest, createViteBareImportBases, createViteBareImportCandidates, createViteVirtualId, detectViteHmrUpdateType, diffVitePrecompileFiles, generateSfcScopeId, generateViteHmrCode, hasViteHmrChanges, isViteBareSpecifier, normalizeViteCssModuleFilename, normalizeViteDevMiddlewareUrl, normalizeVitePrecompileBatchSize, normalizeViteRequireBase, normalizeViteResolvedVuePath, parseSfc, resolveViteAliasRequest, resolveViteCssImports, resolveViteRelativeImport, resolveViteVuePath, scopeViteCssForPipeline, splitViteIdQuery, toViteBrowserImportPrefix, transformViteCssVarsForPipeline } from "@vizejs/native";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { parseSync } from "oxc-parser";
|
|
9
9
|
import fs from "node:fs";
|
|
@@ -1077,6 +1077,111 @@ async function resolveSfcSrcRequests(importer, requests, resolve) {
|
|
|
1077
1077
|
}
|
|
1078
1078
|
return resolutions;
|
|
1079
1079
|
}
|
|
1080
|
+
const SRC_BLOCK_HINT = /<(?:template|script|style)\b[^>]*\ssrc\s*=/i;
|
|
1081
|
+
const ATTRIBUTE_RE = /\s+([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/gy;
|
|
1082
|
+
/** Split an opening tag into its `src` value and the tag without it. */
|
|
1083
|
+
function splitSrcAttribute(tag, openTag) {
|
|
1084
|
+
const head = `<${tag}`;
|
|
1085
|
+
if (!openTag.toLowerCase().startsWith(head)) return null;
|
|
1086
|
+
const body = openTag.slice(head.length).replace(/\s*\/?\s*>$/, "");
|
|
1087
|
+
let rest = "";
|
|
1088
|
+
let src = null;
|
|
1089
|
+
let consumed = 0;
|
|
1090
|
+
ATTRIBUTE_RE.lastIndex = 0;
|
|
1091
|
+
for (let match = ATTRIBUTE_RE.exec(body); match; match = ATTRIBUTE_RE.exec(body)) {
|
|
1092
|
+
consumed = ATTRIBUTE_RE.lastIndex;
|
|
1093
|
+
if (match[1].toLowerCase() === "src" && src === null) src = match[2] ?? match[3] ?? match[4] ?? "";
|
|
1094
|
+
else rest += match[0];
|
|
1095
|
+
}
|
|
1096
|
+
if (src === null || consumed !== body.length) return null;
|
|
1097
|
+
return {
|
|
1098
|
+
src,
|
|
1099
|
+
openTag: `${head}${rest}>`
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
/** The `src` blocks the native parser finds, so `src` text in scripts or comments is not one. */
|
|
1103
|
+
function collectSrcBlocks(parseSfc, filePath, bytes, source) {
|
|
1104
|
+
let parsed;
|
|
1105
|
+
try {
|
|
1106
|
+
parsed = parseSfc(source, { filename: filePath });
|
|
1107
|
+
} catch {
|
|
1108
|
+
return [];
|
|
1109
|
+
}
|
|
1110
|
+
const blocks = [
|
|
1111
|
+
["template", parsed.template],
|
|
1112
|
+
["script", parsed.script],
|
|
1113
|
+
["script", parsed.scriptSetup],
|
|
1114
|
+
...parsed.styles.map((style) => ["style", style])
|
|
1115
|
+
];
|
|
1116
|
+
const found = [];
|
|
1117
|
+
for (const [tag, block] of blocks) {
|
|
1118
|
+
if (!block) continue;
|
|
1119
|
+
const { start, tagStart, tagEnd } = block.loc;
|
|
1120
|
+
const split = splitSrcAttribute(tag, bytes.subarray(tagStart, start).toString("utf8"));
|
|
1121
|
+
if (split) found.push({
|
|
1122
|
+
tag,
|
|
1123
|
+
...split,
|
|
1124
|
+
tagStart,
|
|
1125
|
+
tagEnd
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
return found;
|
|
1129
|
+
}
|
|
1130
|
+
/** The `src` module requests (not relative paths) of an SFC's blocks, in source order. */
|
|
1131
|
+
function listSfcSrcRequests(parseSfc, filePath, source) {
|
|
1132
|
+
if (!SRC_BLOCK_HINT.test(source)) return [];
|
|
1133
|
+
return collectSrcBlocks(parseSfc, filePath, Buffer.from(source), source).map((block) => block.src).filter((src) => !isRelativeSfcSrc(src));
|
|
1134
|
+
}
|
|
1135
|
+
function readSrcBlock(filePath, tag, src, resolutions) {
|
|
1136
|
+
const resolved = sfcSrcFile(filePath, tag, src, resolutions);
|
|
1137
|
+
try {
|
|
1138
|
+
return {
|
|
1139
|
+
path: resolved,
|
|
1140
|
+
content: fs.readFileSync(resolved, "utf8")
|
|
1141
|
+
};
|
|
1142
|
+
} catch {
|
|
1143
|
+
throw new Error(`[vize] <${tag} src="${src}"> not found (resolved: ${resolved}) in ${filePath}`);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Inline `<template src>`, `<script src>` and `<style src>` files into the SFC
|
|
1148
|
+
* source. Blocks are located by the native parser. Module requests come from
|
|
1149
|
+
* the bundler's `resolutions` (see {@link sfcSrcFile}).
|
|
1150
|
+
*/
|
|
1151
|
+
function inlineSfcSrcBlocks(parseSfc, filePath, source, resolutions) {
|
|
1152
|
+
if (!SRC_BLOCK_HINT.test(source)) return {
|
|
1153
|
+
source,
|
|
1154
|
+
dependencies: []
|
|
1155
|
+
};
|
|
1156
|
+
const bytes = Buffer.from(source);
|
|
1157
|
+
const edits = [];
|
|
1158
|
+
const dependencies = [];
|
|
1159
|
+
for (const block of collectSrcBlocks(parseSfc, filePath, bytes, source)) {
|
|
1160
|
+
const file = readSrcBlock(filePath, block.tag, block.src, resolutions);
|
|
1161
|
+
dependencies.push(file.path);
|
|
1162
|
+
edits.push({
|
|
1163
|
+
start: block.tagStart,
|
|
1164
|
+
end: block.tagEnd,
|
|
1165
|
+
text: `${block.openTag}\n${file.content}\n</${block.tag}>`
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
if (edits.length === 0) return {
|
|
1169
|
+
source,
|
|
1170
|
+
dependencies
|
|
1171
|
+
};
|
|
1172
|
+
edits.sort((a, b) => a.start - b.start);
|
|
1173
|
+
const parts = [];
|
|
1174
|
+
let offset = 0;
|
|
1175
|
+
for (const edit of edits) {
|
|
1176
|
+
parts.push(bytes.subarray(offset, edit.start), Buffer.from(edit.text));
|
|
1177
|
+
offset = edit.end;
|
|
1178
|
+
}
|
|
1179
|
+
parts.push(bytes.subarray(offset));
|
|
1180
|
+
return {
|
|
1181
|
+
source: Buffer.concat(parts).toString("utf8"),
|
|
1182
|
+
dependencies
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1080
1185
|
//#endregion
|
|
1081
1186
|
//#region src/compile-options.ts
|
|
1082
1187
|
function buildCompileFileOptions(filePath, options, scopeId = generateScopeId(filePath, options.root, options.isProd ?? false)) {
|
|
@@ -1168,77 +1273,9 @@ function normalizeStyleBlocks(styles) {
|
|
|
1168
1273
|
index: block.index
|
|
1169
1274
|
}));
|
|
1170
1275
|
}
|
|
1171
|
-
function readSrcImport(filePath, tag, src, resolutions) {
|
|
1172
|
-
const resolvedPath = sfcSrcFile(filePath, tag, src, resolutions);
|
|
1173
|
-
try {
|
|
1174
|
-
return {
|
|
1175
|
-
path: resolvedPath,
|
|
1176
|
-
content: fs.readFileSync(resolvedPath, "utf-8")
|
|
1177
|
-
};
|
|
1178
|
-
} catch {
|
|
1179
|
-
throw new Error(`[vize] <${tag} src="${src}"> not found (resolved: ${resolvedPath}) in ${filePath}`);
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
function stripSrcAttribute(attrs) {
|
|
1183
|
-
return attrs.replace(/\s*\bsrc\s*=\s*(?:"[^"]*"|'[^']*')/i, "");
|
|
1184
|
-
}
|
|
1185
|
-
function inlineSingleSrcBlock(source, filePath, tag, src, dependencies, resolutions) {
|
|
1186
|
-
if (!src) return source;
|
|
1187
|
-
const imported = readSrcImport(filePath, tag, src, resolutions);
|
|
1188
|
-
dependencies.push(imported.path);
|
|
1189
|
-
const pattern = new RegExp(`<${tag}\\b([^>]*)\\bsrc\\s*=\\s*(['"])[^'"]+\\2([^>]*)>[\\s\\S]*?<\\/${tag}>`, "i");
|
|
1190
|
-
return source.replace(pattern, (_match, beforeSrc, _quote, afterSrc) => {
|
|
1191
|
-
return `<${tag}${stripSrcAttribute(`${beforeSrc}${afterSrc}`)}>\n${imported.content}\n</${tag}>`;
|
|
1192
|
-
});
|
|
1193
|
-
}
|
|
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);
|
|
1198
|
-
dependencies.push(imported.path);
|
|
1199
|
-
return `<style${stripSrcAttribute(`${beforeSrc}${afterSrc}`)}>\n${imported.content}\n</style>`;
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
|
-
/**
|
|
1203
|
-
* Cheap necessary condition for an SFC block carrying a `src` attribute.
|
|
1204
|
-
*
|
|
1205
|
-
* `extractSfcSrcInfo` parses a full SFC descriptor, so calling it for every file
|
|
1206
|
-
* costs a second whole-source parse per compile on top of the one the compiler
|
|
1207
|
-
* itself performs -- and block `src` attributes are rare (roughly 4% of files in
|
|
1208
|
-
* a real app). Any `<script src>`/`<template src>`/`<style src>` necessarily
|
|
1209
|
-
* contains `src` followed by `=`, so a source without this substring provably
|
|
1210
|
-
* has nothing to inline and can skip the descriptor parse entirely. False
|
|
1211
|
-
* positives (e.g. `<img src=...>` in a template) simply take the original path.
|
|
1212
|
-
*/
|
|
1213
|
-
const SFC_SRC_ATTRIBUTE_HINT = /\bsrc\s*=/i;
|
|
1214
|
-
/** Module requests in `src` come from the bundler's `resolutions` (see {@link sfcSrcFile}). */
|
|
1215
|
-
function resolveSfcSrcImports(filePath, source, resolutions) {
|
|
1216
|
-
if (!SFC_SRC_ATTRIBUTE_HINT.test(source)) return {
|
|
1217
|
-
source,
|
|
1218
|
-
dependencies: []
|
|
1219
|
-
};
|
|
1220
|
-
const dependencies = [];
|
|
1221
|
-
const srcInfo = native.extractSfcSrcInfo(source, filePath);
|
|
1222
|
-
let resolvedSource = source;
|
|
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);
|
|
1226
|
-
return {
|
|
1227
|
-
source: resolvedSource,
|
|
1228
|
-
dependencies
|
|
1229
|
-
};
|
|
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
|
-
}
|
|
1239
1276
|
function compileFile(filePath, cache, options, source, diagnostics) {
|
|
1240
1277
|
const content = source ?? fs.readFileSync(filePath, "utf-8");
|
|
1241
|
-
const resolved =
|
|
1278
|
+
const resolved = inlineSfcSrcBlocks(native.parseSfc, filePath, content, options.srcResolutions?.get(filePath));
|
|
1242
1279
|
const scopeId = generateScopeId(filePath, options.root, options.isProd ?? false, content);
|
|
1243
1280
|
const result = compileSfc(resolved.source, buildCompileFileOptions(filePath, options, scopeId));
|
|
1244
1281
|
if (result.errors.length > 0) throw new VizeSfcCompileError(filePath, result.errors);
|
|
@@ -1301,7 +1338,7 @@ function compileJsxModule(filePath, source, options = {}) {
|
|
|
1301
1338
|
function compileBatch(files, cache, options) {
|
|
1302
1339
|
const dependenciesByPath = /* @__PURE__ */ new Map();
|
|
1303
1340
|
const resolvedFiles = files.map((file) => {
|
|
1304
|
-
const resolved =
|
|
1341
|
+
const resolved = inlineSfcSrcBlocks(native.parseSfc, file.path, file.source, options.srcResolutions?.get(file.path));
|
|
1305
1342
|
dependenciesByPath.set(file.path, resolved.dependencies);
|
|
1306
1343
|
return {
|
|
1307
1344
|
path: file.path,
|
|
@@ -1863,7 +1900,7 @@ function viteHostResolve(resolve) {
|
|
|
1863
1900
|
* them from `state.srcResolutions`. A request left unresolved fails that compile.
|
|
1864
1901
|
*/
|
|
1865
1902
|
async function prepareSfcSrcRequests(state, resolve, file, source) {
|
|
1866
|
-
const requests = listSfcSrcRequests(file, source);
|
|
1903
|
+
const requests = listSfcSrcRequests(parseSfc, file, source);
|
|
1867
1904
|
if (requests.length === 0) {
|
|
1868
1905
|
state.srcResolutions?.delete(file);
|
|
1869
1906
|
return;
|
|
@@ -3085,22 +3122,6 @@ function createVirtualTypeScriptTransformer(viteApi) {
|
|
|
3085
3122
|
throw new Error("Installed Vite does not expose transformWithOxc or transformWithEsbuild");
|
|
3086
3123
|
};
|
|
3087
3124
|
}
|
|
3088
|
-
/**
|
|
3089
|
-
* Report whether `realPath` names a module Vize's own compiler emitted.
|
|
3090
|
-
*
|
|
3091
|
-
* Vize's Rust emitter guarantees plain JavaScript for every module it produces
|
|
3092
|
-
* (`ensure_javascript_output` at the napi boundary), so re-running Vite's
|
|
3093
|
-
* TypeScript strip over emitter output is a pure re-print. Every emitted module
|
|
3094
|
-
* is recorded in one of the two environment caches, so cache membership is the
|
|
3095
|
-
* cheap, allocation-free proof that the code came from the emitter.
|
|
3096
|
-
*
|
|
3097
|
-
* The probe fails safe: a module the caches do not know about still gets the
|
|
3098
|
-
* strip, which keeps hand-written and malformed virtual modules behaving
|
|
3099
|
-
* exactly as they did before.
|
|
3100
|
-
*/
|
|
3101
|
-
function isVizeEmitterOutput(state, realPath) {
|
|
3102
|
-
return state.cache.has(realPath) || state.ssrCache.has(realPath);
|
|
3103
|
-
}
|
|
3104
3125
|
const transformVirtualTypeScript = createVirtualTypeScriptTransformer(vite);
|
|
3105
3126
|
function getOxcDumpPath(root, realPath) {
|
|
3106
3127
|
const dumpDir = path.resolve(root || process.cwd(), "node_modules", ".vize", "oxc-dumps");
|
|
@@ -3120,10 +3141,9 @@ function getVirtualModuleDefines(state, ssr) {
|
|
|
3120
3141
|
function formatUnknownError$1(error) {
|
|
3121
3142
|
return error instanceof Error ? error.message : String(error);
|
|
3122
3143
|
}
|
|
3123
|
-
async function transformVizeVirtualModule(state, code, realPath, ssr,
|
|
3124
|
-
const needsTsTransform = forceTypeScriptTransform || !isVizeEmitterOutput(state, realPath);
|
|
3144
|
+
async function transformVizeVirtualModule(state, code, realPath, ssr, isMacroArtifact = false) {
|
|
3125
3145
|
try {
|
|
3126
|
-
let transformed =
|
|
3146
|
+
let transformed = isMacroArtifact ? (await transformVirtualTypeScript(code, realPath)).code : code;
|
|
3127
3147
|
if (transformed.includes("import.meta.")) transformed = applyDefineReplacements(transformed, getVirtualModuleDefines(state, ssr));
|
|
3128
3148
|
return transformed === code ? null : {
|
|
3129
3149
|
code: transformed,
|
|
@@ -3886,15 +3906,14 @@ function createPostTransformPlugin(state) {
|
|
|
3886
3906
|
...state,
|
|
3887
3907
|
extractCss
|
|
3888
3908
|
}, id, compiled);
|
|
3889
|
-
|
|
3909
|
+
let transformed = generateOutput(compiled, {
|
|
3890
3910
|
isProduction: state.isProduction,
|
|
3891
3911
|
isDev: state.server !== null,
|
|
3892
3912
|
ssr: isSsr,
|
|
3893
3913
|
extractCss,
|
|
3894
3914
|
filePath: id
|
|
3895
|
-
})
|
|
3915
|
+
});
|
|
3896
3916
|
const defines = transformOptions?.ssr ? state.serverViteDefine : state.clientViteDefine;
|
|
3897
|
-
let transformed = result.code;
|
|
3898
3917
|
if (Object.keys(defines).length > 0) transformed = applyDefineReplacements(transformed, defines);
|
|
3899
3918
|
return {
|
|
3900
3919
|
code: transformed,
|
package/dist/vite-plus.mjs
CHANGED
|
@@ -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-
|
|
403
|
+
const { vize } = await import("./plugin-hkzt_w0x.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.
|
|
3
|
+
"version": "0.665.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.
|
|
55
|
-
"@vizejs/unplugin": "0.
|
|
54
|
+
"@vizejs/native": "0.665.0",
|
|
55
|
+
"@vizejs/unplugin": "0.665.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.
|
|
60
|
+
"vize": "0.665.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/node": "25.9.2",
|
package/dist/plugin-C9HLsCVG.mjs
DELETED