@vizejs/vite-plugin 0.290.0 → 0.302.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.d.mts +5 -862
- package/dist/index.mjs +250 -112
- package/dist/internal/config-bridge.d.mts +26 -0
- package/dist/internal/config-bridge.mjs +21 -0
- package/dist/types-x-lq08Y8.d.mts +862 -0
- package/package.json +9 -3
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { registerResolvedVizeConfig, unregisterResolvedVizeConfig } from "./internal/config-bridge.mjs";
|
|
1
2
|
import { createRequire } from "node:module";
|
|
2
3
|
import { createHash } from "node:crypto";
|
|
3
4
|
import * as native from "@vizejs/native";
|
|
4
5
|
import { applyViteDefineReplacements, buildInspectorGraph, chunkVitePrecompileFiles, classifyVitePluginRequest, createViteBareImportBases, createViteBareImportCandidates, createViteVirtualId, detectViteHmrUpdateType, diffVitePrecompileFiles, generateViteHmrCode, hasViteHmrChanges, isViteBareSpecifier, normalizeViteCssModuleFilename, normalizeViteDevMiddlewareUrl, normalizeVitePrecompileBatchSize, normalizeViteRequireBase, normalizeViteResolvedVuePath, resolveViteAliasRequest, resolveViteCssImports, resolveViteRelativeImport, resolveViteVuePath, rewriteViteDynamicTemplateImports, rewriteViteImportMetaGlobBase, rewriteViteStaticAssetUrls, scopeViteCssForPipeline, shouldApplyViteDefineInVirtualModule, splitViteIdQuery, toViteBrowserImportPrefix, transformViteCssVarsForPipeline } from "@vizejs/native";
|
|
5
|
-
import
|
|
6
|
-
import { parseSync } from "vite";
|
|
6
|
+
import { parseSync } from "oxc-parser";
|
|
7
7
|
import fs from "node:fs";
|
|
8
8
|
import { glob } from "tinyglobby";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import { pathToFileURL } from "node:url";
|
|
11
|
+
import * as vite from "vite";
|
|
11
12
|
//#region src/hmr.ts
|
|
12
13
|
function hasHmrChanges(prev, next) {
|
|
13
14
|
if (!prev) return true;
|
|
@@ -78,6 +79,7 @@ function styleFingerprint(module) {
|
|
|
78
79
|
//#region src/utils/module-output.ts
|
|
79
80
|
const OUTPUT_PARSE_ID = "vize-output.tsx";
|
|
80
81
|
const SFC_MAIN_NAME = "_sfc_main";
|
|
82
|
+
const EXPORT_DEFAULT = "export default";
|
|
81
83
|
function isNode(value) {
|
|
82
84
|
return value != null && typeof value === "object" && typeof value.type === "string";
|
|
83
85
|
}
|
|
@@ -132,6 +134,21 @@ function getExportedNames(statement) {
|
|
|
132
134
|
function findDefaultExport(program) {
|
|
133
135
|
return getProgramBody(program).find((statement) => statement.type === "ExportDefaultDeclaration") ?? null;
|
|
134
136
|
}
|
|
137
|
+
function analyzeFastDefaultOutput(code) {
|
|
138
|
+
if (code.includes(SFC_MAIN_NAME) || code.includes("export function render") || code.includes("export function ssrRender") || code.includes("export {")) return null;
|
|
139
|
+
const defaultExportStart = code.indexOf(EXPORT_DEFAULT);
|
|
140
|
+
if (defaultExportStart === -1 || defaultExportStart !== code.lastIndexOf(EXPORT_DEFAULT)) return null;
|
|
141
|
+
const before = defaultExportStart === 0 ? "\n" : code[defaultExportStart - 1];
|
|
142
|
+
if (!before || !/\s|;/.test(before)) return null;
|
|
143
|
+
return {
|
|
144
|
+
hasDefaultExport: true,
|
|
145
|
+
hasSfcMainDefined: false,
|
|
146
|
+
hasNamedRenderExport: false,
|
|
147
|
+
hasNamedSsrRenderExport: false,
|
|
148
|
+
defaultExportStart,
|
|
149
|
+
defaultExportKeywordEnd: defaultExportStart + 14
|
|
150
|
+
};
|
|
151
|
+
}
|
|
135
152
|
function getExportDefaultKeywordEnd(code, defaultExport) {
|
|
136
153
|
const exportStart = getNodeStart(defaultExport);
|
|
137
154
|
if (exportStart == null) return null;
|
|
@@ -139,9 +156,13 @@ function getExportDefaultKeywordEnd(code, defaultExport) {
|
|
|
139
156
|
return match ? exportStart + match[0].length : null;
|
|
140
157
|
}
|
|
141
158
|
function analyzeModuleOutput(code) {
|
|
159
|
+
const fastOutput = analyzeFastDefaultOutput(code);
|
|
160
|
+
if (fastOutput) return fastOutput;
|
|
142
161
|
const program = parseProgram(code);
|
|
143
162
|
const body = getProgramBody(program);
|
|
144
163
|
const defaultExport = findDefaultExport(program);
|
|
164
|
+
const defaultExportStart = getNodeStart(defaultExport);
|
|
165
|
+
const defaultExportKeywordEnd = defaultExport ? getExportDefaultKeywordEnd(code, defaultExport) : null;
|
|
145
166
|
const exportedNames = body.filter((statement) => statement.type === "ExportNamedDeclaration").flatMap(getExportedNames);
|
|
146
167
|
return {
|
|
147
168
|
hasDefaultExport: defaultExport != null,
|
|
@@ -149,13 +170,22 @@ function analyzeModuleOutput(code) {
|
|
|
149
170
|
return statement.type === "VariableDeclaration" && getVariableDeclarationNames(statement).includes(SFC_MAIN_NAME);
|
|
150
171
|
}),
|
|
151
172
|
hasNamedRenderExport: exportedNames.includes("render"),
|
|
152
|
-
hasNamedSsrRenderExport: exportedNames.includes("ssrRender")
|
|
173
|
+
hasNamedSsrRenderExport: exportedNames.includes("ssrRender"),
|
|
174
|
+
defaultExportKeywordEnd,
|
|
175
|
+
defaultExportStart
|
|
153
176
|
};
|
|
154
177
|
}
|
|
155
|
-
function rewriteDefaultExportToSfcMain(code
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
178
|
+
function rewriteDefaultExportToSfcMain(code, moduleInfo = {
|
|
179
|
+
defaultExportKeywordEnd: null,
|
|
180
|
+
defaultExportStart: null
|
|
181
|
+
}) {
|
|
182
|
+
let exportStart = moduleInfo.defaultExportStart;
|
|
183
|
+
let keywordEnd = moduleInfo.defaultExportKeywordEnd;
|
|
184
|
+
if (exportStart == null || keywordEnd == null) {
|
|
185
|
+
const defaultExport = findDefaultExport(parseProgram(code));
|
|
186
|
+
exportStart = getNodeStart(defaultExport);
|
|
187
|
+
keywordEnd = defaultExport ? getExportDefaultKeywordEnd(code, defaultExport) : null;
|
|
188
|
+
}
|
|
159
189
|
if (exportStart == null || keywordEnd == null) return code;
|
|
160
190
|
return `${code.slice(0, exportStart)}const ${SFC_MAIN_NAME} =${code.slice(keywordEnd)}`;
|
|
161
191
|
}
|
|
@@ -353,7 +383,7 @@ function generateOutput(compiled, options) {
|
|
|
353
383
|
const hasNamedSsrRenderExport = moduleInfo.hasNamedSsrRenderExport;
|
|
354
384
|
const hasSfcMainDefined = moduleInfo.hasSfcMainDefined;
|
|
355
385
|
if (hasExportDefault && !hasSfcMainDefined) {
|
|
356
|
-
output = rewriteDefaultExportToSfcMain(output);
|
|
386
|
+
output = rewriteDefaultExportToSfcMain(output, moduleInfo);
|
|
357
387
|
if (compiled.hasScoped && compiled.scopeId) output += `\n_sfc_main.__scopeId = "data-v-${compiled.scopeId}";`;
|
|
358
388
|
output += "\nexport default _sfc_main;";
|
|
359
389
|
} else if (hasExportDefault && hasSfcMainDefined) {
|
|
@@ -446,9 +476,6 @@ function isPluginVisibleSsrVirtualId(id) {
|
|
|
446
476
|
function toBrowserImportPrefix(replacement) {
|
|
447
477
|
return toViteBrowserImportPrefix(replacement);
|
|
448
478
|
}
|
|
449
|
-
function rewriteDynamicTemplateImports(code, aliasRules) {
|
|
450
|
-
return rewriteViteDynamicTemplateImports(code, aliasRules);
|
|
451
|
-
}
|
|
452
479
|
//#endregion
|
|
453
480
|
//#region src/transform.ts
|
|
454
481
|
/**
|
|
@@ -465,8 +492,13 @@ function rewriteDynamicTemplateImports(code, aliasRules) {
|
|
|
465
492
|
* pipeline handles alias expansion and asset hashing in both dev and build.
|
|
466
493
|
*/
|
|
467
494
|
function rewriteStaticAssetUrls(code, aliasRules) {
|
|
495
|
+
if (aliasRules.length === 0 || !code.includes("src")) return code;
|
|
468
496
|
return rewriteViteStaticAssetUrls(code, aliasRules);
|
|
469
497
|
}
|
|
498
|
+
function rewriteDynamicTemplateImports(code, aliasRules) {
|
|
499
|
+
if (!code.includes("import(") || !code.includes("`")) return code;
|
|
500
|
+
return rewriteViteDynamicTemplateImports(code, aliasRules);
|
|
501
|
+
}
|
|
470
502
|
function rewriteImportMetaGlobBase(code, importer, root) {
|
|
471
503
|
if (!code.includes("import.meta.glob")) return code;
|
|
472
504
|
return rewriteViteImportMetaGlobBase(code, importer, root);
|
|
@@ -494,40 +526,6 @@ function createLogger(debug) {
|
|
|
494
526
|
};
|
|
495
527
|
}
|
|
496
528
|
//#endregion
|
|
497
|
-
//#region src/config.ts
|
|
498
|
-
const require = createRequire(import.meta.url);
|
|
499
|
-
const CONFIG_FILE_NAMES = [
|
|
500
|
-
"vize.config.pkl",
|
|
501
|
-
"vize.config.ts",
|
|
502
|
-
"vize.config.js",
|
|
503
|
-
"vize.config.mjs",
|
|
504
|
-
"vize.config.json"
|
|
505
|
-
];
|
|
506
|
-
let vizeConfigModulePromise = null;
|
|
507
|
-
function loadVizeConfigModule() {
|
|
508
|
-
vizeConfigModulePromise ??= import("vize/config");
|
|
509
|
-
return vizeConfigModulePromise;
|
|
510
|
-
}
|
|
511
|
-
function defineConfig(config) {
|
|
512
|
-
return config;
|
|
513
|
-
}
|
|
514
|
-
async function loadConfig(root, options) {
|
|
515
|
-
return (await loadVizeConfigModule()).loadConfig(root, options);
|
|
516
|
-
}
|
|
517
|
-
async function resolveConfigExport(exported, env) {
|
|
518
|
-
return (await loadVizeConfigModule()).resolveConfigExport(exported, env);
|
|
519
|
-
}
|
|
520
|
-
require.resolve("vize/schemas/vize.config.schema.json");
|
|
521
|
-
require.resolve("vize/pkl/vize.pkl");
|
|
522
|
-
[...CONFIG_FILE_NAMES];
|
|
523
|
-
const VIZE_CONFIG_FILE_ENV = "VIZE_CONFIG_FILE";
|
|
524
|
-
/**
|
|
525
|
-
* Shared config store for inter-plugin communication.
|
|
526
|
-
* Key = project root, Value = resolved VizeConfig.
|
|
527
|
-
* Used by musea() and other plugins to access the unified config.
|
|
528
|
-
*/
|
|
529
|
-
const vizeConfigStore = /* @__PURE__ */ new Map();
|
|
530
|
-
//#endregion
|
|
531
529
|
//#region src/compile-options.ts
|
|
532
530
|
function buildCompileFileOptions(filePath, options) {
|
|
533
531
|
return {
|
|
@@ -626,7 +624,23 @@ function inlineStyleSrcBlocks(source, filePath, dependencies) {
|
|
|
626
624
|
return `<style${stripSrcAttribute(`${beforeSrc}${afterSrc}`)}>\n${imported.content}\n</style>`;
|
|
627
625
|
});
|
|
628
626
|
}
|
|
627
|
+
/**
|
|
628
|
+
* Cheap necessary condition for an SFC block carrying a `src` attribute.
|
|
629
|
+
*
|
|
630
|
+
* `extractSfcSrcInfo` parses a full SFC descriptor, so calling it for every file
|
|
631
|
+
* costs a second whole-source parse per compile on top of the one the compiler
|
|
632
|
+
* itself performs -- and block `src` attributes are rare (roughly 4% of files in
|
|
633
|
+
* a real app). Any `<script src>`/`<template src>`/`<style src>` necessarily
|
|
634
|
+
* contains `src` followed by `=`, so a source without this substring provably
|
|
635
|
+
* has nothing to inline and can skip the descriptor parse entirely. False
|
|
636
|
+
* positives (e.g. `<img src=...>` in a template) simply take the original path.
|
|
637
|
+
*/
|
|
638
|
+
const SFC_SRC_ATTRIBUTE_HINT = /\bsrc\s*=/i;
|
|
629
639
|
function resolveSfcSrcImports(filePath, source) {
|
|
640
|
+
if (!SFC_SRC_ATTRIBUTE_HINT.test(source)) return {
|
|
641
|
+
source,
|
|
642
|
+
dependencies: []
|
|
643
|
+
};
|
|
630
644
|
const dependencies = [];
|
|
631
645
|
const srcInfo = native.extractSfcSrcInfo(source, filePath);
|
|
632
646
|
let resolvedSource = source;
|
|
@@ -1651,7 +1665,64 @@ function createVirtualTypeScriptTransformer(viteApi) {
|
|
|
1651
1665
|
throw new Error("Installed Vite does not expose transformWithOxc or transformWithEsbuild");
|
|
1652
1666
|
};
|
|
1653
1667
|
}
|
|
1668
|
+
/**
|
|
1669
|
+
* Report whether `realPath` names a module Vize's own compiler emitted.
|
|
1670
|
+
*
|
|
1671
|
+
* Vize's Rust emitter guarantees plain JavaScript for every module it produces
|
|
1672
|
+
* (`ensure_javascript_output` at the napi boundary), so re-running Vite's
|
|
1673
|
+
* TypeScript strip over emitter output is a pure re-print. Every emitted module
|
|
1674
|
+
* is recorded in one of the two environment caches, so cache membership is the
|
|
1675
|
+
* cheap, allocation-free proof that the code came from the emitter.
|
|
1676
|
+
*
|
|
1677
|
+
* The probe fails safe: a module the caches do not know about still gets the
|
|
1678
|
+
* strip, which keeps hand-written and malformed virtual modules behaving
|
|
1679
|
+
* exactly as they did before.
|
|
1680
|
+
*/
|
|
1681
|
+
function isVizeEmitterOutput(state, realPath) {
|
|
1682
|
+
return state.cache.has(realPath) || state.ssrCache.has(realPath);
|
|
1683
|
+
}
|
|
1654
1684
|
const transformVirtualTypeScript = createVirtualTypeScriptTransformer(vite);
|
|
1685
|
+
function getOxcDumpPath(root, realPath) {
|
|
1686
|
+
const dumpDir = path.resolve(root || process.cwd(), "node_modules", ".vize", "oxc-dumps");
|
|
1687
|
+
fs.mkdirSync(dumpDir, { recursive: true });
|
|
1688
|
+
return path.join(dumpDir, `vize-oxc-error-${path.basename(realPath)}.ts`);
|
|
1689
|
+
}
|
|
1690
|
+
function getVirtualModuleDefines(state, ssr) {
|
|
1691
|
+
return {
|
|
1692
|
+
"import.meta.client": ssr ? "false" : "true",
|
|
1693
|
+
"import.meta.server": ssr ? "true" : "false",
|
|
1694
|
+
"import.meta.dev": state.isProduction ? "false" : "true",
|
|
1695
|
+
"import.meta.test": "false",
|
|
1696
|
+
"import.meta.prerender": "false",
|
|
1697
|
+
...ssr ? state.serverViteDefine : state.clientViteDefine
|
|
1698
|
+
};
|
|
1699
|
+
}
|
|
1700
|
+
function formatUnknownError$1(error) {
|
|
1701
|
+
return error instanceof Error ? error.message : String(error);
|
|
1702
|
+
}
|
|
1703
|
+
async function transformVizeVirtualModule(state, code, realPath, ssr, forceTypeScriptTransform = false) {
|
|
1704
|
+
const needsTsTransform = forceTypeScriptTransform || !isVizeEmitterOutput(state, realPath);
|
|
1705
|
+
try {
|
|
1706
|
+
let transformed = (needsTsTransform ? await transformVirtualTypeScript(code, realPath) : { code }).code;
|
|
1707
|
+
if (transformed.includes("import.meta.")) transformed = applyDefineReplacements(transformed, getVirtualModuleDefines(state, ssr));
|
|
1708
|
+
return transformed === code ? null : {
|
|
1709
|
+
code: transformed,
|
|
1710
|
+
map: null
|
|
1711
|
+
};
|
|
1712
|
+
} catch (e) {
|
|
1713
|
+
state.logger.error(`transformWithOxc failed for ${realPath}:`, e);
|
|
1714
|
+
let dumpPath = null;
|
|
1715
|
+
try {
|
|
1716
|
+
dumpPath = getOxcDumpPath(state.root, realPath);
|
|
1717
|
+
fs.writeFileSync(dumpPath, code, "utf-8");
|
|
1718
|
+
state.logger.error(`Dumped failing code to ${dumpPath}`);
|
|
1719
|
+
} catch (dumpError) {
|
|
1720
|
+
state.logger.error(`Failed to dump failing virtual module for ${realPath}:`, dumpError);
|
|
1721
|
+
}
|
|
1722
|
+
const message = [`[vize] Virtual module transform failed for ${realPath}: ${formatUnknownError$1(e)}`, dumpPath ? `Dumped failing code to ${dumpPath}` : null].filter(Boolean).join("\n");
|
|
1723
|
+
throw new Error(message);
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1655
1726
|
//#endregion
|
|
1656
1727
|
//#region src/plugin/load.ts
|
|
1657
1728
|
const SERVER_PLACEHOLDER_CODE = `import { createElementBlock, defineComponent } from "vue";
|
|
@@ -1668,21 +1739,6 @@ function getBoundaryPlaceholderCode(realPath, ssr) {
|
|
|
1668
1739
|
if (!ssr && boundaryKind === "server") return SERVER_PLACEHOLDER_CODE;
|
|
1669
1740
|
return null;
|
|
1670
1741
|
}
|
|
1671
|
-
function getOxcDumpPath(root, realPath) {
|
|
1672
|
-
const dumpDir = path.resolve(root || process.cwd(), "node_modules", ".vize", "oxc-dumps");
|
|
1673
|
-
fs.mkdirSync(dumpDir, { recursive: true });
|
|
1674
|
-
return path.join(dumpDir, `vize-oxc-error-${path.basename(realPath)}.ts`);
|
|
1675
|
-
}
|
|
1676
|
-
function getVirtualModuleDefines(state, ssr) {
|
|
1677
|
-
return {
|
|
1678
|
-
"import.meta.client": ssr ? "false" : "true",
|
|
1679
|
-
"import.meta.server": ssr ? "true" : "false",
|
|
1680
|
-
"import.meta.dev": state.isProduction ? "false" : "true",
|
|
1681
|
-
"import.meta.test": "false",
|
|
1682
|
-
"import.meta.prerender": "false",
|
|
1683
|
-
...ssr ? state.serverViteDefine : state.clientViteDefine
|
|
1684
|
-
};
|
|
1685
|
-
}
|
|
1686
1742
|
function normalizeVueServerRendererImport(code) {
|
|
1687
1743
|
return code.replace(/\bfrom\s+(['"])@vue\/server-renderer\1/g, "from \"vue/server-renderer\"");
|
|
1688
1744
|
}
|
|
@@ -1763,6 +1819,7 @@ function loadDefinePageMetaArtifact(state, realPath, ssr) {
|
|
|
1763
1819
|
} : null;
|
|
1764
1820
|
}
|
|
1765
1821
|
function loadHook(state, id, loadOptions) {
|
|
1822
|
+
if (id !== "\0vize:all-styles.css" && !id.startsWith("\0") && !id.includes(".vue")) return null;
|
|
1766
1823
|
const request = classifyVitePluginRequest(id);
|
|
1767
1824
|
const pluginVisibleVirtualPath = fromPluginVisibleVirtualId(id);
|
|
1768
1825
|
const loadableVueSfcPath = getLoadableVueSfcPath(request);
|
|
@@ -1880,41 +1937,15 @@ function transformJsxRequest(state, code, id, options) {
|
|
|
1880
1937
|
};
|
|
1881
1938
|
}
|
|
1882
1939
|
async function transformHook(state, code, id, options) {
|
|
1940
|
+
if (!id.startsWith("\0") && !id.includes(".vue.ts") && !isJsxComponentPath(id)) return null;
|
|
1883
1941
|
const pluginVisibleVirtualPath = fromPluginVisibleVirtualId(id);
|
|
1884
1942
|
const jsxResult = transformJsxRequest(state, code, id, { ssr: options?.ssr });
|
|
1885
1943
|
if (jsxResult !== void 0) return jsxResult;
|
|
1886
1944
|
if (!id.startsWith("\0") && !pluginVisibleVirtualPath) return null;
|
|
1887
1945
|
const request = classifyVitePluginRequest(id);
|
|
1888
|
-
if (request.isVizeVirtual || request.isMacroVirtualId || pluginVisibleVirtualPath)
|
|
1889
|
-
const realPath = request.isMacroVirtualId ? request.strippedVirtualPath ?? "" : request.vizeVirtualPath ?? pluginVisibleVirtualPath ?? "";
|
|
1890
|
-
try {
|
|
1891
|
-
const result = await transformVirtualTypeScript(code, realPath);
|
|
1892
|
-
const defines = getVirtualModuleDefines(state, options?.ssr ?? false);
|
|
1893
|
-
let transformed = result.code;
|
|
1894
|
-
transformed = applyDefineReplacements(transformed, defines);
|
|
1895
|
-
return {
|
|
1896
|
-
code: transformed,
|
|
1897
|
-
map: null
|
|
1898
|
-
};
|
|
1899
|
-
} catch (e) {
|
|
1900
|
-
state.logger.error(`transformWithOxc failed for ${realPath}:`, e);
|
|
1901
|
-
let dumpPath = null;
|
|
1902
|
-
try {
|
|
1903
|
-
dumpPath = getOxcDumpPath(state.root, realPath);
|
|
1904
|
-
fs.writeFileSync(dumpPath, code, "utf-8");
|
|
1905
|
-
state.logger.error(`Dumped failing code to ${dumpPath}`);
|
|
1906
|
-
} catch (dumpError) {
|
|
1907
|
-
state.logger.error(`Failed to dump failing virtual module for ${realPath}:`, dumpError);
|
|
1908
|
-
}
|
|
1909
|
-
const message = [`[vize] Virtual module transform failed for ${realPath}: ${formatUnknownError$1(e)}`, dumpPath ? `Dumped failing code to ${dumpPath}` : null].filter(Boolean).join("\n");
|
|
1910
|
-
throw new Error(message);
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1946
|
+
if (request.isVizeVirtual || request.isMacroVirtualId || pluginVisibleVirtualPath) return transformVizeVirtualModule(state, code, request.isMacroVirtualId ? request.strippedVirtualPath ?? "" : request.vizeVirtualPath ?? pluginVisibleVirtualPath ?? "", options?.ssr ?? false, request.isMacroVirtualId);
|
|
1913
1947
|
return null;
|
|
1914
1948
|
}
|
|
1915
|
-
function formatUnknownError$1(error) {
|
|
1916
|
-
return error instanceof Error ? error.message : String(error);
|
|
1917
|
-
}
|
|
1918
1949
|
//#endregion
|
|
1919
1950
|
//#region src/plugin/hmr.ts
|
|
1920
1951
|
const VIZE_COMPONENTS_CSS_BASENAME = "vize-components.css";
|
|
@@ -2423,6 +2454,43 @@ function createLegacyVueCompatibilityPlugin(options) {
|
|
|
2423
2454
|
};
|
|
2424
2455
|
}
|
|
2425
2456
|
//#endregion
|
|
2457
|
+
//#region src/config.ts
|
|
2458
|
+
const require = createRequire(import.meta.url);
|
|
2459
|
+
const CONFIG_FILE_NAMES = [
|
|
2460
|
+
"vize.config.pkl",
|
|
2461
|
+
"vize.config.ts",
|
|
2462
|
+
"vize.config.js",
|
|
2463
|
+
"vize.config.mjs",
|
|
2464
|
+
"vize.config.json"
|
|
2465
|
+
];
|
|
2466
|
+
let vizeConfigModulePromise = null;
|
|
2467
|
+
function loadVizeConfigModule() {
|
|
2468
|
+
vizeConfigModulePromise ??= import("vize/config");
|
|
2469
|
+
return vizeConfigModulePromise;
|
|
2470
|
+
}
|
|
2471
|
+
function defineConfig(config) {
|
|
2472
|
+
return config;
|
|
2473
|
+
}
|
|
2474
|
+
async function loadConfig(root, options) {
|
|
2475
|
+
return (await loadVizeConfigModule()).loadConfig(root, options);
|
|
2476
|
+
}
|
|
2477
|
+
async function resolveConfigExport(exported, env) {
|
|
2478
|
+
return (await loadVizeConfigModule()).resolveConfigExport(exported, env);
|
|
2479
|
+
}
|
|
2480
|
+
require.resolve("vize/schemas/vize.config.schema.json");
|
|
2481
|
+
require.resolve("vize/pkl/vize.pkl");
|
|
2482
|
+
[...CONFIG_FILE_NAMES];
|
|
2483
|
+
const VIZE_CONFIG_FILE_ENV = "VIZE_CONFIG_FILE";
|
|
2484
|
+
/**
|
|
2485
|
+
* Shared config store for inter-plugin communication.
|
|
2486
|
+
* Key = project root, Value = resolved VizeConfig.
|
|
2487
|
+
*
|
|
2488
|
+
* @deprecated Root identity cannot isolate parallel Vite client/SSR instances
|
|
2489
|
+
* or servers. This export remains temporarily for compatibility; internal Vize
|
|
2490
|
+
* integrations use an exact `ResolvedConfig`-scoped bridge instead.
|
|
2491
|
+
*/
|
|
2492
|
+
const vizeConfigStore = /* @__PURE__ */ new Map();
|
|
2493
|
+
//#endregion
|
|
2426
2494
|
//#region src/plugin/shared-config.ts
|
|
2427
2495
|
function mergeSharedConfig(baseConfig, overrideConfig) {
|
|
2428
2496
|
if (!baseConfig) return overrideConfig;
|
|
@@ -2465,6 +2533,93 @@ function mergeSharedConfig(baseConfig, overrideConfig) {
|
|
|
2465
2533
|
entries: [...baseConfig.entries, ...overrideConfig.entries]
|
|
2466
2534
|
};
|
|
2467
2535
|
}
|
|
2536
|
+
async function resolveSharedConfig(options, root, env, logger) {
|
|
2537
|
+
let fileConfig = null;
|
|
2538
|
+
if (options.configMode !== false) {
|
|
2539
|
+
const configFile = options.configFile ?? process.env["VIZE_CONFIG_FILE"];
|
|
2540
|
+
try {
|
|
2541
|
+
fileConfig = await loadConfig(root, {
|
|
2542
|
+
mode: options.configMode ?? "root",
|
|
2543
|
+
configFile,
|
|
2544
|
+
env
|
|
2545
|
+
});
|
|
2546
|
+
if (fileConfig) logger.log("Loaded config from vize.config file");
|
|
2547
|
+
} catch (error) {
|
|
2548
|
+
logger.warn(`Failed to load vize config from ${configFile ?? root}:`, error);
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
let inlineConfig = null;
|
|
2552
|
+
if (options.config) try {
|
|
2553
|
+
inlineConfig = await resolveConfigExport(options.config, env);
|
|
2554
|
+
logger.log("Loaded inline vize config from plugin options");
|
|
2555
|
+
} catch (error) {
|
|
2556
|
+
logger.warn("Failed to resolve inline vize config:", error);
|
|
2557
|
+
}
|
|
2558
|
+
return mergeSharedConfig(fileConfig, inlineConfig);
|
|
2559
|
+
}
|
|
2560
|
+
//#endregion
|
|
2561
|
+
//#region src/plugin/config-lifecycle.ts
|
|
2562
|
+
const compatibilityOwners = /* @__PURE__ */ new Map();
|
|
2563
|
+
const compatibilityRegistrations = /* @__PURE__ */ new WeakMap();
|
|
2564
|
+
function releaseCompatibilityRegistration(resolvedConfig) {
|
|
2565
|
+
const registration = compatibilityRegistrations.get(resolvedConfig);
|
|
2566
|
+
compatibilityRegistrations.delete(resolvedConfig);
|
|
2567
|
+
if (!registration || compatibilityOwners.get(registration.root) !== registration.token) return;
|
|
2568
|
+
compatibilityOwners.delete(registration.root);
|
|
2569
|
+
if (vizeConfigStore.get(registration.root) === registration.config) vizeConfigStore.delete(registration.root);
|
|
2570
|
+
}
|
|
2571
|
+
function unregisterConfig(resolvedConfig) {
|
|
2572
|
+
unregisterResolvedVizeConfig(resolvedConfig);
|
|
2573
|
+
releaseCompatibilityRegistration(resolvedConfig);
|
|
2574
|
+
}
|
|
2575
|
+
async function register(resolvedConfig, root, sharedConfigPromise) {
|
|
2576
|
+
releaseCompatibilityRegistration(resolvedConfig);
|
|
2577
|
+
const token = Symbol(root);
|
|
2578
|
+
compatibilityOwners.set(root, token);
|
|
2579
|
+
vizeConfigStore.delete(root);
|
|
2580
|
+
registerResolvedVizeConfig(resolvedConfig, sharedConfigPromise);
|
|
2581
|
+
let sharedConfig;
|
|
2582
|
+
try {
|
|
2583
|
+
sharedConfig = await sharedConfigPromise;
|
|
2584
|
+
} catch (error) {
|
|
2585
|
+
unregisterResolvedVizeConfig(resolvedConfig);
|
|
2586
|
+
if (compatibilityOwners.get(root) === token) {
|
|
2587
|
+
compatibilityOwners.delete(root);
|
|
2588
|
+
vizeConfigStore.delete(root);
|
|
2589
|
+
}
|
|
2590
|
+
throw error;
|
|
2591
|
+
}
|
|
2592
|
+
if (compatibilityOwners.get(root) !== token) return sharedConfig;
|
|
2593
|
+
if (sharedConfig) {
|
|
2594
|
+
compatibilityRegistrations.set(resolvedConfig, {
|
|
2595
|
+
config: sharedConfig,
|
|
2596
|
+
root,
|
|
2597
|
+
token
|
|
2598
|
+
});
|
|
2599
|
+
vizeConfigStore.set(root, sharedConfig);
|
|
2600
|
+
} else {
|
|
2601
|
+
compatibilityOwners.delete(root);
|
|
2602
|
+
vizeConfigStore.delete(root);
|
|
2603
|
+
}
|
|
2604
|
+
return sharedConfig;
|
|
2605
|
+
}
|
|
2606
|
+
function configureServerCleanup(devServer) {
|
|
2607
|
+
const resolvedConfig = devServer.config;
|
|
2608
|
+
let unregistered = false;
|
|
2609
|
+
const unregister = () => {
|
|
2610
|
+
if (unregistered) return;
|
|
2611
|
+
unregistered = true;
|
|
2612
|
+
devServer.httpServer?.off("close", unregister);
|
|
2613
|
+
devServer.watcher.off("close", unregister);
|
|
2614
|
+
unregisterConfig(resolvedConfig);
|
|
2615
|
+
};
|
|
2616
|
+
devServer.httpServer?.once("close", unregister);
|
|
2617
|
+
devServer.watcher.once("close", unregister);
|
|
2618
|
+
}
|
|
2619
|
+
function unregisterBuild(context) {
|
|
2620
|
+
const resolvedConfig = context.environment?.getTopLevelConfig?.();
|
|
2621
|
+
if (resolvedConfig) unregisterConfig(resolvedConfig);
|
|
2622
|
+
}
|
|
2468
2623
|
//#endregion
|
|
2469
2624
|
//#region src/plugin/index.ts
|
|
2470
2625
|
function aliasSortKey(find) {
|
|
@@ -2554,29 +2709,8 @@ function vize(options = {}) {
|
|
|
2554
2709
|
command: resolvedConfig.command === "build" ? "build" : "serve",
|
|
2555
2710
|
isSsrBuild: !!resolvedConfig.build?.ssr
|
|
2556
2711
|
};
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
const configFile = options.configFile ?? process.env["VIZE_CONFIG_FILE"];
|
|
2560
|
-
try {
|
|
2561
|
-
fileConfig = await loadConfig(state.root, {
|
|
2562
|
-
mode: options.configMode ?? "root",
|
|
2563
|
-
configFile,
|
|
2564
|
-
env: configEnv
|
|
2565
|
-
});
|
|
2566
|
-
if (fileConfig) state.logger.log("Loaded config from vize.config file");
|
|
2567
|
-
} catch (error) {
|
|
2568
|
-
state.logger.warn(`Failed to load vize config from ${configFile ?? state.root}:`, error);
|
|
2569
|
-
}
|
|
2570
|
-
}
|
|
2571
|
-
let inlineConfig = null;
|
|
2572
|
-
if (options.config) try {
|
|
2573
|
-
inlineConfig = await resolveConfigExport(options.config, configEnv);
|
|
2574
|
-
state.logger.log("Loaded inline vize config from plugin options");
|
|
2575
|
-
} catch (error) {
|
|
2576
|
-
state.logger.warn("Failed to resolve inline vize config:", error);
|
|
2577
|
-
}
|
|
2578
|
-
const sharedConfig = mergeSharedConfig(fileConfig, inlineConfig);
|
|
2579
|
-
if (sharedConfig) vizeConfigStore.set(state.root, sharedConfig);
|
|
2712
|
+
const sharedConfigPromise = resolveSharedConfig(options, state.root, configEnv, state.logger);
|
|
2713
|
+
const sharedConfig = await register(resolvedConfig, state.root, sharedConfigPromise);
|
|
2580
2714
|
const viteConfig = sharedConfig?.vite ?? {};
|
|
2581
2715
|
const compilerConfig = sharedConfig?.compiler ?? {};
|
|
2582
2716
|
const compatibility = resolveCompatibilityOptions(options, compilerConfig);
|
|
@@ -2637,6 +2771,7 @@ function vize(options = {}) {
|
|
|
2637
2771
|
},
|
|
2638
2772
|
configureServer(devServer) {
|
|
2639
2773
|
state.server = devServer;
|
|
2774
|
+
configureServerCleanup(devServer);
|
|
2640
2775
|
installDevMiddleware(devServer, state);
|
|
2641
2776
|
},
|
|
2642
2777
|
async buildStart() {
|
|
@@ -2670,7 +2805,10 @@ function vize(options = {}) {
|
|
|
2670
2805
|
}, this.emitFile.bind(this), bundle);
|
|
2671
2806
|
},
|
|
2672
2807
|
closeBundle() {
|
|
2673
|
-
if (state.server === null)
|
|
2808
|
+
if (state.server === null) {
|
|
2809
|
+
unregisterBuild(this);
|
|
2810
|
+
clearBuildCaches(state);
|
|
2811
|
+
}
|
|
2674
2812
|
}
|
|
2675
2813
|
},
|
|
2676
2814
|
createStylePostTransformPlugin(),
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { c as ResolvedVizeConfig } from "../types-x-lq08Y8.mjs";
|
|
2
|
+
import { ResolvedConfig } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/internal/config-bridge.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Exact Vite-instance registration returned to internal companion plugins.
|
|
7
|
+
*
|
|
8
|
+
* A registered promise resolving to null is intentionally distinct from a
|
|
9
|
+
* missing registration: it means the Vize plugin ran and found no config.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
type ResolvedVizeConfigRegistration = {
|
|
14
|
+
readonly registered: false;
|
|
15
|
+
} | {
|
|
16
|
+
readonly registered: true;
|
|
17
|
+
readonly config: Promise<ResolvedVizeConfig | null>;
|
|
18
|
+
};
|
|
19
|
+
/** @internal */
|
|
20
|
+
declare function registerResolvedVizeConfig(resolvedConfig: ResolvedConfig, config: ResolvedVizeConfig | null | Promise<ResolvedVizeConfig | null>): void;
|
|
21
|
+
/** @internal */
|
|
22
|
+
declare function getResolvedVizeConfigRegistration(resolvedConfig: ResolvedConfig): ResolvedVizeConfigRegistration;
|
|
23
|
+
/** @internal */
|
|
24
|
+
declare function unregisterResolvedVizeConfig(resolvedConfig: ResolvedConfig): boolean;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { ResolvedVizeConfigRegistration, getResolvedVizeConfigRegistration, registerResolvedVizeConfig, unregisterResolvedVizeConfig };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/internal/config-bridge.ts
|
|
2
|
+
const registrations = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
const missingRegistration = Object.freeze({ registered: false });
|
|
4
|
+
/** @internal */
|
|
5
|
+
function registerResolvedVizeConfig(resolvedConfig, config) {
|
|
6
|
+
registrations.set(resolvedConfig, Promise.resolve(config));
|
|
7
|
+
}
|
|
8
|
+
/** @internal */
|
|
9
|
+
function getResolvedVizeConfigRegistration(resolvedConfig) {
|
|
10
|
+
if (!registrations.has(resolvedConfig)) return missingRegistration;
|
|
11
|
+
return {
|
|
12
|
+
registered: true,
|
|
13
|
+
config: registrations.get(resolvedConfig)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** @internal */
|
|
17
|
+
function unregisterResolvedVizeConfig(resolvedConfig) {
|
|
18
|
+
return registrations.delete(resolvedConfig);
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { getResolvedVizeConfigRegistration, registerResolvedVizeConfig, unregisterResolvedVizeConfig };
|