@vizejs/vite-plugin 0.310.0 → 0.314.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/README.md
CHANGED
|
@@ -181,8 +181,9 @@ interface VizeNativeOptions {
|
|
|
181
181
|
ssr?: boolean;
|
|
182
182
|
|
|
183
183
|
/**
|
|
184
|
-
* Enable source map generation
|
|
185
|
-
*
|
|
184
|
+
* Enable source map generation. The emitted map's `sources` names the
|
|
185
|
+
* authored `.vue` file, not the virtual `.vue.ts` module.
|
|
186
|
+
* @default true in development, false in production unless `build.sourcemap` is set
|
|
186
187
|
*/
|
|
187
188
|
sourceMap?: boolean;
|
|
188
189
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as VizeVueVersion, c as ResolvedVizeConfig, i as VizeOptions, l as
|
|
1
|
+
import { a as VizeVueVersion, c as VizeInspectorOptions, d as ResolvedVizeConfig, f as UserConfigExport, i as VizeOptions, l as ConfigEnv, n as MacroArtifact, o as VizeInspectorLintPlanProvider, p as VizeConfig, r as VizeCompatibilityOptions, s as VizeInspectorLintPlanRequest, t as CompiledModule, u as LoadConfigOptions } from "./types-BU_B_kFs.mjs";
|
|
2
2
|
import { Plugin } from "vite";
|
|
3
3
|
|
|
4
4
|
//#region src/virtual.d.ts
|
|
@@ -40,4 +40,4 @@ declare const __internal: {
|
|
|
40
40
|
rewriteStaticAssetUrls: typeof rewriteStaticAssetUrls;
|
|
41
41
|
};
|
|
42
42
|
//#endregion
|
|
43
|
-
export { type CompiledModule, type LoadConfigOptions, type MacroArtifact, type ResolvedVizeConfig, type UserConfigExport, VIZE_CONFIG_FILE_ENV, type VizeCompatibilityOptions, type VizeConfig, type VizeOptions, type VizeVueVersion, __internal, rewriteStaticAssetUrls as __internal_rewriteStaticAssetUrls, vize as default, vize, defineConfig, loadConfig, resolveConfigExport, vizeConfigStore };
|
|
43
|
+
export { type CompiledModule, type LoadConfigOptions, type MacroArtifact, type ResolvedVizeConfig, type UserConfigExport, VIZE_CONFIG_FILE_ENV, type VizeCompatibilityOptions, type VizeConfig, type VizeInspectorLintPlanProvider, type VizeInspectorLintPlanRequest, type VizeInspectorOptions, type VizeOptions, type VizeVueVersion, __internal, rewriteStaticAssetUrls as __internal_rewriteStaticAssetUrls, vize as default, vize, defineConfig, loadConfig, resolveConfigExport, vizeConfigStore };
|
package/dist/index.mjs
CHANGED
|
@@ -230,6 +230,89 @@ function insertBeforeSfcMainDefaultExport(code, insertion, options = {}) {
|
|
|
230
230
|
return `${code.slice(0, exportStart)}${insertion}\n${code.slice(exportStart)}`;
|
|
231
231
|
}
|
|
232
232
|
//#endregion
|
|
233
|
+
//#region src/utils/source-map.ts
|
|
234
|
+
function isSourceMapV3(value) {
|
|
235
|
+
if (value === null || typeof value !== "object") return false;
|
|
236
|
+
const map = value;
|
|
237
|
+
return map.version === 3 && Array.isArray(map.sources) && Array.isArray(map.names) && typeof map.mappings === "string";
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Parse a compiler-produced map, or `null` when there is nothing usable.
|
|
241
|
+
*
|
|
242
|
+
* A malformed map is worse than no map — Vite would chain garbage into the
|
|
243
|
+
* bundle's map — so anything that is not a v3 document is dropped.
|
|
244
|
+
*/
|
|
245
|
+
function parseSourceMap(json) {
|
|
246
|
+
if (!json) return null;
|
|
247
|
+
let parsed;
|
|
248
|
+
try {
|
|
249
|
+
parsed = JSON.parse(json);
|
|
250
|
+
} catch {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
return isSourceMapV3(parsed) ? parsed : null;
|
|
254
|
+
}
|
|
255
|
+
function countNewlines(text) {
|
|
256
|
+
let total = 0;
|
|
257
|
+
for (let index = text.indexOf("\n"); index !== -1; index = text.indexOf("\n", index + 1)) total++;
|
|
258
|
+
return total;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Insert `count` unmapped generated lines at generated line `atLine`.
|
|
262
|
+
*
|
|
263
|
+
* Returns the map unchanged when the insertion lands past the last mapped line,
|
|
264
|
+
* because nothing after it needs moving.
|
|
265
|
+
*/
|
|
266
|
+
function shiftMappedLines(map, atLine, count) {
|
|
267
|
+
if (count <= 0) return map;
|
|
268
|
+
const groups = map.mappings.split(";");
|
|
269
|
+
if (atLine >= groups.length) return map;
|
|
270
|
+
const shifted = [
|
|
271
|
+
...groups.slice(0, atLine),
|
|
272
|
+
...Array(count).fill(""),
|
|
273
|
+
...groups.slice(atLine)
|
|
274
|
+
];
|
|
275
|
+
return {
|
|
276
|
+
...map,
|
|
277
|
+
mappings: shifted.join(";")
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* A module's code and the map that describes it, edited together.
|
|
282
|
+
*
|
|
283
|
+
* Every write goes through {@link edit}, so the map is corrected in the same
|
|
284
|
+
* step that changes the code and the two cannot drift.
|
|
285
|
+
*/
|
|
286
|
+
var MappedModule = class {
|
|
287
|
+
code;
|
|
288
|
+
map;
|
|
289
|
+
constructor(code, map) {
|
|
290
|
+
this.code = code;
|
|
291
|
+
this.map = map;
|
|
292
|
+
}
|
|
293
|
+
/** Replace the module with `next`, realigning the map to the new line layout. */
|
|
294
|
+
edit(next) {
|
|
295
|
+
const previous = this.code;
|
|
296
|
+
this.code = next;
|
|
297
|
+
if (this.map === null || next === previous) return;
|
|
298
|
+
const limit = Math.min(previous.length, next.length);
|
|
299
|
+
let prefix = 0;
|
|
300
|
+
while (prefix < limit && previous.charCodeAt(prefix) === next.charCodeAt(prefix)) prefix++;
|
|
301
|
+
let suffix = 0;
|
|
302
|
+
while (suffix < limit - prefix && previous.charCodeAt(previous.length - 1 - suffix) === next.charCodeAt(next.length - 1 - suffix)) suffix++;
|
|
303
|
+
const removed = previous.slice(prefix, previous.length - suffix);
|
|
304
|
+
const addedLines = countNewlines(next.slice(prefix, next.length - suffix)) - countNewlines(removed);
|
|
305
|
+
if (addedLines === 0) return;
|
|
306
|
+
if (addedLines < 0) {
|
|
307
|
+
this.map = null;
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
const editLine = countNewlines(previous.slice(0, prefix));
|
|
311
|
+
const startsAtLineStart = prefix === 0 || previous.charCodeAt(prefix - 1) === 10;
|
|
312
|
+
this.map = shiftMappedLines(this.map, startsAtLineStart ? editLine : editLine + 1, addedLines);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
//#endregion
|
|
233
316
|
//#region src/utils/css.ts
|
|
234
317
|
function scopeCssForPipeline(css, scopeId) {
|
|
235
318
|
return scopeViteCssForPipeline(css, scopeId);
|
|
@@ -433,29 +516,40 @@ function embedsInlineCss(compiled, options) {
|
|
|
433
516
|
return !usesStyleImports(compiled, options) && !options.ssr && !!compiled.css && !(options.isProduction && !!options.extractCss);
|
|
434
517
|
}
|
|
435
518
|
function generateOutput(compiled, options) {
|
|
519
|
+
return generateOutputWithMap(compiled, options).code;
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* `generateOutput` plus the source map that describes the module it returns.
|
|
523
|
+
*
|
|
524
|
+
* The compiler's map (`compiled.map`) describes `compiled.code`; every rewrite
|
|
525
|
+
* below goes through {@link MappedModule}, which realigns the map to the lines
|
|
526
|
+
* it inserts, so the returned map describes the returned code (#3399). `map` is
|
|
527
|
+
* `null` when the compiler produced none.
|
|
528
|
+
*/
|
|
529
|
+
function generateOutputWithMap(compiled, options) {
|
|
436
530
|
const { isProduction, isDev, ssr, hmrUpdateType, extractCss, filePath } = options;
|
|
437
|
-
|
|
438
|
-
const moduleInfo = analyzeModuleOutput(
|
|
531
|
+
const emitted = new MappedModule(compiled.code, parseSourceMap(compiled.map));
|
|
532
|
+
const moduleInfo = compiled.moduleShape ?? analyzeModuleOutput(emitted.code);
|
|
439
533
|
const hasExportDefault = moduleInfo.hasDefaultExport;
|
|
440
534
|
const hasNamedRenderExport = moduleInfo.hasNamedRenderExport;
|
|
441
535
|
const hasNamedSsrRenderExport = moduleInfo.hasNamedSsrRenderExport;
|
|
442
536
|
const hasSfcMainDefined = moduleInfo.hasSfcMainDefined;
|
|
443
537
|
if (hasExportDefault && !hasSfcMainDefined) {
|
|
444
|
-
|
|
445
|
-
if (compiled.hasScoped && compiled.scopeId)
|
|
446
|
-
|
|
538
|
+
emitted.edit(rewriteDefaultExportToSfcMain(emitted.code, moduleInfo));
|
|
539
|
+
if (compiled.hasScoped && compiled.scopeId) emitted.edit(`${emitted.code}\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`);
|
|
540
|
+
emitted.edit(`${emitted.code}\nexport default _sfc_main;`);
|
|
447
541
|
} else if (hasExportDefault && hasSfcMainDefined) {
|
|
448
|
-
if (compiled.hasScoped && compiled.scopeId)
|
|
542
|
+
if (compiled.hasScoped && compiled.scopeId) emitted.edit(insertBeforeSfcMainDefaultExport(emitted.code, `_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`, { moduleInfo }));
|
|
449
543
|
} else if (!hasExportDefault && !hasSfcMainDefined && hasNamedRenderExport) {
|
|
450
|
-
|
|
451
|
-
if (compiled.hasScoped && compiled.scopeId)
|
|
452
|
-
|
|
453
|
-
|
|
544
|
+
emitted.edit(`${emitted.code}\nconst _sfc_main = {};`);
|
|
545
|
+
if (compiled.hasScoped && compiled.scopeId) emitted.edit(`${emitted.code}\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`);
|
|
546
|
+
emitted.edit(`${emitted.code}\n_sfc_main.render = render;`);
|
|
547
|
+
emitted.edit(`${emitted.code}\nexport default _sfc_main;`);
|
|
454
548
|
} else if (!hasExportDefault && !hasSfcMainDefined && hasNamedSsrRenderExport) {
|
|
455
|
-
|
|
456
|
-
if (compiled.hasScoped && compiled.scopeId)
|
|
457
|
-
|
|
458
|
-
|
|
549
|
+
emitted.edit(`${emitted.code}\nconst _sfc_main = {};`);
|
|
550
|
+
if (compiled.hasScoped && compiled.scopeId) emitted.edit(`${emitted.code}\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`);
|
|
551
|
+
emitted.edit(`${emitted.code}\n_sfc_main.ssrRender = ssrRender;`);
|
|
552
|
+
emitted.edit(`${emitted.code}\nexport default _sfc_main;`);
|
|
459
553
|
}
|
|
460
554
|
if (usesStyleImports(compiled, options)) {
|
|
461
555
|
const styleImports = [];
|
|
@@ -479,7 +573,7 @@ function generateOutput(compiled, options) {
|
|
|
479
573
|
}
|
|
480
574
|
}
|
|
481
575
|
const allImports = [...styleImports, ...cssModuleImports].join("\n");
|
|
482
|
-
if (allImports)
|
|
576
|
+
if (allImports) emitted.edit(insertAfterStaticImports(emitted.code, allImports));
|
|
483
577
|
if (cssModuleImports.length > 0) {
|
|
484
578
|
const moduleBindings = [];
|
|
485
579
|
for (const block of compiled.styles) if (isCssModule(block)) {
|
|
@@ -490,14 +584,17 @@ function generateOutput(compiled, options) {
|
|
|
490
584
|
});
|
|
491
585
|
}
|
|
492
586
|
const cssModuleSetup = moduleBindings.map((m) => `_sfc_main.__cssModules = _sfc_main.__cssModules || {};\n_sfc_main.__cssModules[${JSON.stringify(m.name)}] = ${m.bindingName};`).join("\n");
|
|
493
|
-
|
|
587
|
+
emitted.edit(insertBeforeSfcMainDefaultExport(emitted.code, cssModuleSetup, { normalizeSemicolon: true }));
|
|
494
588
|
}
|
|
495
|
-
} else if (!ssr && compiled.css && !(isProduction && extractCss))
|
|
589
|
+
} else if (!ssr && compiled.css && !(isProduction && extractCss)) emitted.edit(prependInlineStyleInjection(emitted.code, compiled.css, compiled.scopeId));
|
|
496
590
|
if (!isProduction && isDev && hasExportDefault) {
|
|
497
|
-
const effectiveHmrUpdateType = hmrUpdateType === "template-only" && !supportsTemplateOnlyHmr(
|
|
498
|
-
|
|
591
|
+
const effectiveHmrUpdateType = hmrUpdateType === "template-only" && !supportsTemplateOnlyHmr(emitted.code) ? "full-reload" : hmrUpdateType ?? "full-reload";
|
|
592
|
+
emitted.edit(`${emitted.code}${generateHmrCode(compiled.scopeId, effectiveHmrUpdateType)}`);
|
|
499
593
|
}
|
|
500
|
-
return
|
|
594
|
+
return {
|
|
595
|
+
code: emitted.code,
|
|
596
|
+
map: emitted.map
|
|
597
|
+
};
|
|
501
598
|
}
|
|
502
599
|
const RESOLVED_CSS_MODULE = "\0vize:all-styles.css";
|
|
503
600
|
/** Create a virtual module ID from a real .vue file path */
|
|
@@ -651,7 +748,7 @@ function getEnvironmentCache(state, ssr) {
|
|
|
651
748
|
}
|
|
652
749
|
function getCompileOptionsForRequest(state, ssr) {
|
|
653
750
|
const options = {
|
|
654
|
-
sourceMap: state.mergedOptions?.sourceMap ?? !state.isProduction,
|
|
751
|
+
sourceMap: state.mergedOptions?.sourceMap ?? (!state.isProduction || !!state.viteBuildSourcemap),
|
|
655
752
|
ssr,
|
|
656
753
|
vapor: !ssr && (state.mergedOptions?.vapor ?? false),
|
|
657
754
|
customRenderer: state.mergedOptions?.customRenderer ?? false,
|
|
@@ -795,6 +892,7 @@ function buildCompileBatchOptions(options) {
|
|
|
795
892
|
includeStyles: true,
|
|
796
893
|
includeMacroArtifacts: true,
|
|
797
894
|
includeHashes: true,
|
|
895
|
+
includeSourceMap: options.sourceMap,
|
|
798
896
|
...options.mode === void 0 ? {} : { mode: options.mode },
|
|
799
897
|
...options.templateSyntax === void 0 ? {} : { templateSyntax: options.templateSyntax },
|
|
800
898
|
...options.runtimeModuleName === void 0 ? {} : { runtimeModuleName: options.runtimeModuleName },
|
|
@@ -901,6 +999,7 @@ function compileFile(filePath, cache, options, source, diagnostics) {
|
|
|
901
999
|
});
|
|
902
1000
|
const compiled = {
|
|
903
1001
|
code: result.code,
|
|
1002
|
+
...result.map ? { map: result.map } : {},
|
|
904
1003
|
css: result.css,
|
|
905
1004
|
scopeId,
|
|
906
1005
|
hasScoped: result.hasScoped,
|
|
@@ -964,6 +1063,7 @@ function compileBatch(files, cache, options) {
|
|
|
964
1063
|
for (const fileResult of result.results) {
|
|
965
1064
|
if (fileResult.errors.length === 0) cache.set(fileResult.path, {
|
|
966
1065
|
code: fileResult.code,
|
|
1066
|
+
...fileResult.map ? { map: fileResult.map } : {},
|
|
967
1067
|
css: fileResult.css,
|
|
968
1068
|
scopeId: fileResult.scopeId,
|
|
969
1069
|
hasScoped: fileResult.hasScoped,
|
|
@@ -1039,7 +1139,7 @@ function resolveCompilerIdentity() {
|
|
|
1039
1139
|
*/
|
|
1040
1140
|
function computePrecompileCacheKey(compileOptions) {
|
|
1041
1141
|
const material = stableStringify({
|
|
1042
|
-
format:
|
|
1142
|
+
format: 3,
|
|
1043
1143
|
compiler: resolveCompilerIdentity(),
|
|
1044
1144
|
options: compileOptions
|
|
1045
1145
|
});
|
|
@@ -1158,7 +1258,7 @@ function encodePrecompileManifest(options) {
|
|
|
1158
1258
|
const indexBody = compressBody(Buffer.from(JSON.stringify(index), "utf8"));
|
|
1159
1259
|
const payloadBody = compressBody(Buffer.concat(records));
|
|
1160
1260
|
const header = Buffer.from(JSON.stringify({
|
|
1161
|
-
format:
|
|
1261
|
+
format: 3,
|
|
1162
1262
|
key,
|
|
1163
1263
|
codec: hasZstd ? "zstd" : "gzip",
|
|
1164
1264
|
index: indexBody.length,
|
|
@@ -1234,7 +1334,7 @@ function decodePrecompileManifest(bytes, options) {
|
|
|
1234
1334
|
return reject("unparsable header");
|
|
1235
1335
|
}
|
|
1236
1336
|
if (typeof header !== "object" || header === null || Array.isArray(header)) return reject("unrecognized header");
|
|
1237
|
-
if (header.format !==
|
|
1337
|
+
if (header.format !== 3 || header.key !== key) return reject("foreign format or key");
|
|
1238
1338
|
if (!isByteLength(header.index) || !isByteLength(header.payload)) return reject("unrecognized body lengths");
|
|
1239
1339
|
const indexStart = headerEnd + 1;
|
|
1240
1340
|
const payloadStart = indexStart + header.index;
|
|
@@ -1450,6 +1550,7 @@ function writeManifest(file, container, onDiagnostic) {
|
|
|
1450
1550
|
*/
|
|
1451
1551
|
function resolvePrecompileBatchOptions(state) {
|
|
1452
1552
|
return {
|
|
1553
|
+
sourceMap: getCompileOptionsForRequest(state, false).sourceMap,
|
|
1453
1554
|
ssr: false,
|
|
1454
1555
|
vapor: state.mergedOptions.vapor ?? false,
|
|
1455
1556
|
mode: state.mergedOptions.mode,
|
|
@@ -2464,12 +2565,15 @@ function loadCompiledSfcModule(state, realPath, isSsr, currentBase, loadOptions)
|
|
|
2464
2565
|
...compiled,
|
|
2465
2566
|
css: resolveCssImports(compiled.css, realPath, state.cssAliasRules, state.server !== null, currentBase)
|
|
2466
2567
|
};
|
|
2467
|
-
const
|
|
2468
|
-
const
|
|
2568
|
+
const emitted = generateOutputWithMap(compiled, outputOptions);
|
|
2569
|
+
const rewritten = new MappedModule(isSsr ? normalizeVueServerRendererImport(emitted.code) : emitted.code, emitted.map);
|
|
2570
|
+
rewritten.edit(rewriteDynamicTemplateImports(rewritten.code, state.dynamicImportAliasRules));
|
|
2571
|
+
rewritten.edit(rewriteStaticAssetUrls(rewritten.code, state.dynamicImportAliasRules));
|
|
2572
|
+
rewritten.edit(rewriteImportMetaGlobBase(rewritten.code, realPath, state.root));
|
|
2469
2573
|
if (!loadOptions?.ssr) state.pendingHmrUpdateTypes.delete(realPath);
|
|
2470
2574
|
return {
|
|
2471
|
-
code:
|
|
2472
|
-
map:
|
|
2575
|
+
code: rewritten.code,
|
|
2576
|
+
map: rewritten.map
|
|
2473
2577
|
};
|
|
2474
2578
|
}
|
|
2475
2579
|
function loadDefinePageArtifact(state, realPath, ssr) {
|
|
@@ -2992,6 +3096,114 @@ function normalizeCssModuleFilename(filename) {
|
|
|
2992
3096
|
return normalized;
|
|
2993
3097
|
}
|
|
2994
3098
|
//#endregion
|
|
3099
|
+
//#region src/plugin/inspector-lint-plan.ts
|
|
3100
|
+
const VIZE_INSPECTOR_LINT_PLAN_ENDPOINT = "/__vize/inspector/lint-plan";
|
|
3101
|
+
const MAX_REQUEST_URL_BYTES = 8 * 1024;
|
|
3102
|
+
const MAX_FILE_COUNT = 128;
|
|
3103
|
+
const MAX_FILE_BYTES = 4 * 1024;
|
|
3104
|
+
const MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
3105
|
+
const ALLOWED_QUERY_KEYS = new Set(["file", "fresh"]);
|
|
3106
|
+
function installInspectorLintPlanMiddleware(devServer, state) {
|
|
3107
|
+
const provider = state.mergedOptions.inspector?.lintPlan;
|
|
3108
|
+
if (!provider) return;
|
|
3109
|
+
devServer.middlewares.use((req, res, next) => {
|
|
3110
|
+
if (!isInspectorLintPlanRequest(req.url, state.clientViteBase)) {
|
|
3111
|
+
next();
|
|
3112
|
+
return;
|
|
3113
|
+
}
|
|
3114
|
+
handleInspectorLintPlanRequest(req, res, provider, state.logger, state.clientViteBase);
|
|
3115
|
+
});
|
|
3116
|
+
}
|
|
3117
|
+
function isInspectorLintPlanRequest(reqUrl, base = "/") {
|
|
3118
|
+
if (!reqUrl) return false;
|
|
3119
|
+
try {
|
|
3120
|
+
return new URL(reqUrl, "http://localhost").pathname === resolveInspectorEndpoint(base);
|
|
3121
|
+
} catch {
|
|
3122
|
+
return false;
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
function parseInspectorLintPlanRequest(reqUrl, base = "/") {
|
|
3126
|
+
if (!reqUrl || !isInspectorLintPlanRequest(reqUrl, base)) return null;
|
|
3127
|
+
if (Buffer.byteLength(reqUrl) > MAX_REQUEST_URL_BYTES) return {
|
|
3128
|
+
statusCode: 414,
|
|
3129
|
+
error: "request_uri_too_long"
|
|
3130
|
+
};
|
|
3131
|
+
const url = new URL(reqUrl, "http://localhost");
|
|
3132
|
+
for (const key of url.searchParams.keys()) if (!ALLOWED_QUERY_KEYS.has(key)) return {
|
|
3133
|
+
statusCode: 400,
|
|
3134
|
+
error: "invalid_query"
|
|
3135
|
+
};
|
|
3136
|
+
const freshValues = url.searchParams.getAll("fresh");
|
|
3137
|
+
if (freshValues.length > 1 || freshValues[0] !== void 0 && freshValues[0] !== "1") return {
|
|
3138
|
+
statusCode: 400,
|
|
3139
|
+
error: "invalid_fresh"
|
|
3140
|
+
};
|
|
3141
|
+
const rawFiles = url.searchParams.getAll("file");
|
|
3142
|
+
if (rawFiles.length > MAX_FILE_COUNT) return {
|
|
3143
|
+
statusCode: 413,
|
|
3144
|
+
error: "too_many_files"
|
|
3145
|
+
};
|
|
3146
|
+
const files = [];
|
|
3147
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3148
|
+
for (const file of rawFiles) {
|
|
3149
|
+
if (!isSafeInspectorFile(file)) return {
|
|
3150
|
+
statusCode: 400,
|
|
3151
|
+
error: "invalid_file"
|
|
3152
|
+
};
|
|
3153
|
+
if (!seen.has(file)) {
|
|
3154
|
+
seen.add(file);
|
|
3155
|
+
files.push(file);
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
return { request: {
|
|
3159
|
+
files,
|
|
3160
|
+
fresh: freshValues[0] === "1"
|
|
3161
|
+
} };
|
|
3162
|
+
}
|
|
3163
|
+
async function handleInspectorLintPlanRequest(req, res, provider, logger, base = "/") {
|
|
3164
|
+
if (req.method !== "GET" && req.method !== "HEAD") {
|
|
3165
|
+
res.setHeader("allow", "GET, HEAD");
|
|
3166
|
+
sendJson$1(res, 405, { error: "method_not_allowed" });
|
|
3167
|
+
return;
|
|
3168
|
+
}
|
|
3169
|
+
const parsed = parseInspectorLintPlanRequest(req.url, base);
|
|
3170
|
+
if (!parsed) {
|
|
3171
|
+
sendJson$1(res, 404, { error: "not_found" });
|
|
3172
|
+
return;
|
|
3173
|
+
}
|
|
3174
|
+
if ("error" in parsed) {
|
|
3175
|
+
sendJson$1(res, parsed.statusCode, { error: parsed.error }, req.method === "HEAD");
|
|
3176
|
+
return;
|
|
3177
|
+
}
|
|
3178
|
+
try {
|
|
3179
|
+
sendJson$1(res, 200, await provider(parsed.request), req.method === "HEAD");
|
|
3180
|
+
} catch (error) {
|
|
3181
|
+
logger.error("Failed to build inspector lint plan:", error);
|
|
3182
|
+
sendJson$1(res, 500, { error: "inspector_lint_plan_failed" }, req.method === "HEAD");
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
function resolveInspectorEndpoint(base) {
|
|
3186
|
+
return `${new URL(base, "http://localhost").pathname.replace(/\/+$/, "")}${VIZE_INSPECTOR_LINT_PLAN_ENDPOINT}`;
|
|
3187
|
+
}
|
|
3188
|
+
function isSafeInspectorFile(file) {
|
|
3189
|
+
if (file.length === 0 || Buffer.byteLength(file) > MAX_FILE_BYTES || file.includes("\0") || file.includes("\\") || path.posix.isAbsolute(file)) return false;
|
|
3190
|
+
return !file.split("/").some((segment) => segment === ".." || segment.length === 0);
|
|
3191
|
+
}
|
|
3192
|
+
function sendJson$1(res, statusCode, payload, headOnly = false) {
|
|
3193
|
+
let body = JSON.stringify(payload);
|
|
3194
|
+
if (body === void 0) throw new TypeError("Inspector payload is not JSON serializable");
|
|
3195
|
+
if (Buffer.byteLength(body) > MAX_RESPONSE_BYTES) {
|
|
3196
|
+
statusCode = 413;
|
|
3197
|
+
body = JSON.stringify({ error: "inspector_response_too_large" });
|
|
3198
|
+
}
|
|
3199
|
+
res.statusCode = statusCode;
|
|
3200
|
+
res.setHeader("cache-control", "no-store");
|
|
3201
|
+
res.setHeader("content-type", "application/json; charset=utf-8");
|
|
3202
|
+
res.setHeader("content-length", Buffer.byteLength(body));
|
|
3203
|
+
res.setHeader("x-content-type-options", "nosniff");
|
|
3204
|
+
res.end(headOnly ? void 0 : body);
|
|
3205
|
+
}
|
|
3206
|
+
//#endregion
|
|
2995
3207
|
//#region src/plugin/dev-middleware.ts
|
|
2996
3208
|
const VIZE_INSPECTOR_GRAPH_ENDPOINT = "/__vize/inspector/graph";
|
|
2997
3209
|
const INSPECTOR_SCRIPT_PATTERNS = ["**/*.{js,jsx,ts,tsx}"];
|
|
@@ -3000,6 +3212,7 @@ const INSPECTOR_FILE_EXTENSION_RE = /\.(?:vue|[jt]sx?)$/;
|
|
|
3000
3212
|
function installDevMiddleware(devServer, state) {
|
|
3001
3213
|
installVirtualAssetMiddleware(devServer, state);
|
|
3002
3214
|
installInspectorGraphMiddleware(devServer, state);
|
|
3215
|
+
installInspectorLintPlanMiddleware(devServer, state);
|
|
3003
3216
|
}
|
|
3004
3217
|
function installVirtualAssetMiddleware(devServer, state) {
|
|
3005
3218
|
devServer.middlewares.use((req, _res, next) => {
|
|
@@ -3343,6 +3556,7 @@ function vize(options = {}) {
|
|
|
3343
3556
|
pendingHmrUpdateTypes: /* @__PURE__ */ new Map(),
|
|
3344
3557
|
viteResolveCache: /* @__PURE__ */ new Map(),
|
|
3345
3558
|
isProduction: false,
|
|
3559
|
+
viteBuildSourcemap: false,
|
|
3346
3560
|
root: "",
|
|
3347
3561
|
clientViteBase: "/",
|
|
3348
3562
|
serverViteBase: "/",
|
|
@@ -3381,6 +3595,7 @@ function vize(options = {}) {
|
|
|
3381
3595
|
async configResolved(resolvedConfig) {
|
|
3382
3596
|
state.root = options.root ?? resolvedConfig.root;
|
|
3383
3597
|
state.isProduction = options.isProduction ?? resolvedConfig.isProduction;
|
|
3598
|
+
state.viteBuildSourcemap = !!resolvedConfig.build?.sourcemap;
|
|
3384
3599
|
const isSsrBuild = !!resolvedConfig.build?.ssr;
|
|
3385
3600
|
const currentBase = resolvedConfig.command === "serve" ? options.devUrlBase ?? resolvedConfig.base ?? "/" : resolvedConfig.base ?? "/";
|
|
3386
3601
|
if (isSsrBuild) state.serverViteBase = currentBase;
|
|
@@ -660,6 +660,41 @@ interface ExperimentalPluginOptions extends ExperimentalCompileFlags {
|
|
|
660
660
|
experimentals?: ExperimentalOptions;
|
|
661
661
|
}
|
|
662
662
|
//#endregion
|
|
663
|
+
//#region src/inspector-types.d.ts
|
|
664
|
+
interface VizeInspectorLintPlanRequest {
|
|
665
|
+
/** Project-relative files whose effective lint rules should be explained. */
|
|
666
|
+
files: string[];
|
|
667
|
+
/** Ask the integration to rebuild its plan before resolving the files. */
|
|
668
|
+
fresh: boolean;
|
|
669
|
+
}
|
|
670
|
+
type VizeInspectorLintPlanProvider = (request: VizeInspectorLintPlanRequest) => unknown;
|
|
671
|
+
interface VizeInspectorOptions {
|
|
672
|
+
/** Optional development-only lint-plan payload provider. */
|
|
673
|
+
lintPlan?: VizeInspectorLintPlanProvider;
|
|
674
|
+
}
|
|
675
|
+
//#endregion
|
|
676
|
+
//#region src/utils/module-output.d.ts
|
|
677
|
+
type ModuleOutputInfo = {
|
|
678
|
+
hasDefaultExport: boolean;
|
|
679
|
+
hasSfcMainDefined: boolean;
|
|
680
|
+
hasNamedRenderExport: boolean;
|
|
681
|
+
hasNamedSsrRenderExport: boolean;
|
|
682
|
+
defaultExportKeywordEnd: number | null;
|
|
683
|
+
defaultExportStart: number | null;
|
|
684
|
+
/**
|
|
685
|
+
* End offset of the whole `export default ...` statement, or `null`.
|
|
686
|
+
*
|
|
687
|
+
* Recorded so {@link insertBeforeSfcMainDefaultExport} can reuse the caller's
|
|
688
|
+
* analysis instead of parsing the module a second time (#3425).
|
|
689
|
+
*/
|
|
690
|
+
defaultExportEnd: number | null;
|
|
691
|
+
/**
|
|
692
|
+
* Whether the default export's declaration is exactly the `_sfc_main`
|
|
693
|
+
* identifier -- the only shape {@link insertBeforeSfcMainDefaultExport} acts on.
|
|
694
|
+
*/
|
|
695
|
+
defaultExportIsSfcMain: boolean;
|
|
696
|
+
};
|
|
697
|
+
//#endregion
|
|
663
698
|
//#region src/types.d.ts
|
|
664
699
|
interface MacroArtifact {
|
|
665
700
|
kind: string;
|
|
@@ -704,6 +739,8 @@ interface VizeOptions extends ExperimentalPluginOptions {
|
|
|
704
739
|
* Direct plugin options still take precedence over these values.
|
|
705
740
|
*/
|
|
706
741
|
config?: UserConfigExport;
|
|
742
|
+
/** Development inspector integrations exposed through Vite's dev server. */
|
|
743
|
+
inspector?: VizeInspectorOptions;
|
|
707
744
|
/**
|
|
708
745
|
* Vue major version for the host project.
|
|
709
746
|
*
|
|
@@ -755,7 +792,10 @@ interface VizeOptions extends ExperimentalPluginOptions {
|
|
|
755
792
|
*/
|
|
756
793
|
isProduction?: boolean;
|
|
757
794
|
ssr?: boolean;
|
|
758
|
-
/**
|
|
795
|
+
/**
|
|
796
|
+
* Enable source map generation.
|
|
797
|
+
* @default development on; production off unless Vite's `build.sourcemap` is set
|
|
798
|
+
*/
|
|
759
799
|
sourceMap?: boolean;
|
|
760
800
|
/**
|
|
761
801
|
* Enable Vapor mode compilation
|
|
@@ -845,6 +885,13 @@ interface StyleBlockInfo {
|
|
|
845
885
|
}
|
|
846
886
|
interface CompiledModule {
|
|
847
887
|
code: string;
|
|
888
|
+
/**
|
|
889
|
+
* Source Map v3 document (JSON) describing `code`, when the compiler was
|
|
890
|
+
* asked for one (#3399). Absent when source maps are off, when the SFC has no
|
|
891
|
+
* script block, and for the rspack and unplugin builders, which do not request
|
|
892
|
+
* maps. Persisted with the rest of the module in the pre-compile cache.
|
|
893
|
+
*/
|
|
894
|
+
map?: string;
|
|
848
895
|
css?: string;
|
|
849
896
|
scopeId: string;
|
|
850
897
|
hasScoped: boolean;
|
|
@@ -857,6 +904,13 @@ interface CompiledModule {
|
|
|
857
904
|
styles?: StyleBlockInfo[];
|
|
858
905
|
/** Files loaded through SFC `src` imports */
|
|
859
906
|
dependencies?: string[];
|
|
907
|
+
/**
|
|
908
|
+
* Module shape reported by the native compiler, so `generateOutput` need not
|
|
909
|
+
* re-parse the emitted module (#3425). Absent for a cache entry written before
|
|
910
|
+
* the field existed, and for the rspack and unplugin builders, which never set
|
|
911
|
+
* it — both fall back to parsing.
|
|
912
|
+
*/
|
|
913
|
+
moduleShape?: ModuleOutputInfo;
|
|
860
914
|
}
|
|
861
915
|
//#endregion
|
|
862
|
-
export { VizeVueVersion as a,
|
|
916
|
+
export { VizeVueVersion as a, VizeInspectorOptions as c, ResolvedVizeConfig as d, UserConfigExport as f, VizeOptions as i, ConfigEnv as l, MacroArtifact as n, VizeInspectorLintPlanProvider as o, VizeConfig as p, VizeCompatibilityOptions as r, VizeInspectorLintPlanRequest as s, CompiledModule as t, LoadConfigOptions as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.314.0",
|
|
4
4
|
"description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiler",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@vizejs/native": "0.
|
|
48
|
+
"@vizejs/native": "0.314.0",
|
|
49
49
|
"oxc-parser": "0.133.0",
|
|
50
50
|
"tinyglobby": "0.2.16",
|
|
51
|
-
"vize": "0.
|
|
51
|
+
"vize": "0.314.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/node": "25.9.2",
|