@vizejs/vite-plugin 0.88.0 → 0.89.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 +111 -15
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -352,11 +352,8 @@ function parseCustomMedia(css, map) {
|
|
|
352
352
|
}
|
|
353
353
|
function resolveCssPath(importPath, importer, aliasRules) {
|
|
354
354
|
for (const rule of aliasRules) {
|
|
355
|
-
const
|
|
356
|
-
if (
|
|
357
|
-
const resolved = path.join(rule.replacement, suffix);
|
|
358
|
-
return path.resolve(resolved);
|
|
359
|
-
}
|
|
355
|
+
const resolved = resolveAliasPath(importPath, rule);
|
|
356
|
+
if (resolved !== null) return path.resolve(resolved);
|
|
360
357
|
}
|
|
361
358
|
if (importPath.startsWith(".")) {
|
|
362
359
|
const dir = path.dirname(importer);
|
|
@@ -365,6 +362,18 @@ function resolveCssPath(importPath, importer, aliasRules) {
|
|
|
365
362
|
if (path.isAbsolute(importPath)) return importPath;
|
|
366
363
|
return null;
|
|
367
364
|
}
|
|
365
|
+
function resolveAliasPath(importPath, rule) {
|
|
366
|
+
if (typeof rule.find !== "string") {
|
|
367
|
+
const pattern = stableAliasPattern(rule.find);
|
|
368
|
+
return pattern.test(importPath) ? importPath.replace(pattern, rule.replacement) : null;
|
|
369
|
+
}
|
|
370
|
+
const suffix = matchedAliasSuffix(importPath, rule.find);
|
|
371
|
+
if (suffix !== null) return path.join(rule.replacement, suffix);
|
|
372
|
+
return null;
|
|
373
|
+
}
|
|
374
|
+
function stableAliasPattern(pattern) {
|
|
375
|
+
return new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, ""));
|
|
376
|
+
}
|
|
368
377
|
function matchedAliasSuffix(importPath, find) {
|
|
369
378
|
if (importPath === find) return "";
|
|
370
379
|
const prefix = find.endsWith("/") ? find : `${find}/`;
|
|
@@ -921,10 +930,43 @@ function normalizeRequireBase(importer) {
|
|
|
921
930
|
else if (isMacroVirtualId(normalized)) normalized = normalized.slice(1).split("?")[0] ?? "";
|
|
922
931
|
return normalized.split("?")[0] ?? null;
|
|
923
932
|
}
|
|
933
|
+
function splitIdQuery(id) {
|
|
934
|
+
const queryStart = id.indexOf("?");
|
|
935
|
+
if (queryStart === -1) return [id, ""];
|
|
936
|
+
return [id.slice(0, queryStart), id.slice(queryStart)];
|
|
937
|
+
}
|
|
938
|
+
function isBareSpecifier(id) {
|
|
939
|
+
const [request] = splitIdQuery(id);
|
|
940
|
+
return request !== "" && !request.startsWith("./") && !request.startsWith("../") && !request.startsWith("/") && !request.startsWith("\0") && !request.includes(":");
|
|
941
|
+
}
|
|
942
|
+
function resolveAliasRequest(state, id) {
|
|
943
|
+
const [request, querySuffix] = splitIdQuery(id);
|
|
944
|
+
for (const rule of state.cssAliasRules) {
|
|
945
|
+
if (request === rule.find) return rule.replacement + querySuffix;
|
|
946
|
+
const findPrefix = rule.find.endsWith("/") ? rule.find : rule.find + "/";
|
|
947
|
+
if (request.startsWith(findPrefix)) return (rule.replacement.endsWith("/") ? rule.replacement : rule.replacement + "/") + request.slice(findPrefix.length) + querySuffix;
|
|
948
|
+
}
|
|
949
|
+
return null;
|
|
950
|
+
}
|
|
951
|
+
function pushPnpmHoistBases(candidates, start, isDirectory) {
|
|
952
|
+
if (!start) return;
|
|
953
|
+
let dir = isDirectory ? start : path.dirname(start);
|
|
954
|
+
for (;;) {
|
|
955
|
+
const pnpmHoist = path.join(dir, "node_modules", ".pnpm", "node_modules");
|
|
956
|
+
if (fs.existsSync(pnpmHoist)) {
|
|
957
|
+
candidates.push(path.join(pnpmHoist, "package.json"));
|
|
958
|
+
break;
|
|
959
|
+
}
|
|
960
|
+
const parent = path.dirname(dir);
|
|
961
|
+
if (parent === dir) break;
|
|
962
|
+
dir = parent;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
924
965
|
function resolveBareImportWithNode(state, id, importer) {
|
|
925
|
-
const [request,
|
|
926
|
-
const querySuffix = queryPart ? `?${queryPart}` : "";
|
|
966
|
+
const [request, querySuffix] = splitIdQuery(id);
|
|
927
967
|
const candidates = [normalizeRequireBase(importer), path.join(state.root, "package.json")].filter((candidate) => candidate != null);
|
|
968
|
+
pushPnpmHoistBases(candidates, importer ?? null, false);
|
|
969
|
+
pushPnpmHoistBases(candidates, state.root, true);
|
|
928
970
|
const seen = /* @__PURE__ */ new Set();
|
|
929
971
|
for (const candidate of candidates) {
|
|
930
972
|
if (seen.has(candidate)) continue;
|
|
@@ -935,8 +977,23 @@ function resolveBareImportWithNode(state, id, importer) {
|
|
|
935
977
|
}
|
|
936
978
|
return null;
|
|
937
979
|
}
|
|
980
|
+
function resolveBareImportCandidatesWithNode(state, id, importer, resolvedId) {
|
|
981
|
+
const candidates = [
|
|
982
|
+
resolvedId,
|
|
983
|
+
resolveAliasRequest(state, id),
|
|
984
|
+
id
|
|
985
|
+
].filter((candidate) => candidate != null && isBareSpecifier(candidate));
|
|
986
|
+
const seen = /* @__PURE__ */ new Set();
|
|
987
|
+
for (const candidate of candidates) {
|
|
988
|
+
if (seen.has(candidate)) continue;
|
|
989
|
+
seen.add(candidate);
|
|
990
|
+
const resolved = resolveBareImportWithNode(state, candidate, importer);
|
|
991
|
+
if (resolved) return resolved;
|
|
992
|
+
}
|
|
993
|
+
return null;
|
|
994
|
+
}
|
|
938
995
|
function normalizeResolvedVuePath(id) {
|
|
939
|
-
const pathPart = id
|
|
996
|
+
const [pathPart] = splitIdQuery(id);
|
|
940
997
|
if (!pathPart?.endsWith(".vue")) return null;
|
|
941
998
|
return pathPart.startsWith("/@fs/") ? pathPart.slice(4) : pathPart;
|
|
942
999
|
}
|
|
@@ -1023,21 +1080,57 @@ async function resolveIdHook(ctx, state, id, importer, options) {
|
|
|
1023
1080
|
}
|
|
1024
1081
|
if (!id.endsWith(".vue")) {
|
|
1025
1082
|
if (!id.startsWith("./") && !id.startsWith("../") && !id.startsWith("/")) {
|
|
1026
|
-
|
|
1083
|
+
const aliasRequest = resolveAliasRequest(state, id);
|
|
1084
|
+
if (aliasRequest && isBareSpecifier(aliasRequest)) {
|
|
1085
|
+
const nodeResolved = resolveBareImportCandidatesWithNode(state, id, cleanImporter);
|
|
1086
|
+
if (nodeResolved) {
|
|
1087
|
+
state.logger.log(`resolveId: resolved aliased bare ${id} to ${nodeResolved} via Node fallback`);
|
|
1088
|
+
return nodeResolved;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
try {
|
|
1092
|
+
const resolved = await ctx.resolve(id, cleanImporter, { skipSelf: true });
|
|
1093
|
+
if (resolved) {
|
|
1094
|
+
state.logger.log(`resolveId: resolved bare ${id} to ${resolved.id} via Vite resolver`);
|
|
1095
|
+
if (isBuild && resolved.id.startsWith("/@fs/")) return {
|
|
1096
|
+
...resolved,
|
|
1097
|
+
id: normalizeFsIdForBuild(resolved.id)
|
|
1098
|
+
};
|
|
1099
|
+
const nodeResolved = resolveBareImportCandidatesWithNode(state, id, cleanImporter, resolved.id);
|
|
1100
|
+
if (nodeResolved) {
|
|
1101
|
+
state.logger.log(`resolveId: normalized bare ${id} to ${nodeResolved} via Node fallback`);
|
|
1102
|
+
return nodeResolved;
|
|
1103
|
+
}
|
|
1104
|
+
if (isBareSpecifier(resolved.id)) return null;
|
|
1105
|
+
return resolved;
|
|
1106
|
+
}
|
|
1107
|
+
} catch {}
|
|
1108
|
+
const nodeResolved = resolveBareImportCandidatesWithNode(state, id, cleanImporter);
|
|
1109
|
+
if (nodeResolved) {
|
|
1110
|
+
state.logger.log(`resolveId: resolved bare ${id} to ${nodeResolved} via Node fallback`);
|
|
1111
|
+
return nodeResolved;
|
|
1112
|
+
}
|
|
1113
|
+
if (aliasRequest && aliasRequest !== id && !isBareSpecifier(aliasRequest)) {
|
|
1027
1114
|
try {
|
|
1028
|
-
const resolved = await ctx.resolve(
|
|
1115
|
+
const resolved = await ctx.resolve(aliasRequest, cleanImporter, { skipSelf: true });
|
|
1029
1116
|
if (resolved) {
|
|
1030
|
-
state.logger.log(`resolveId: resolved bare ${id} to ${resolved.id} via Vite resolver`);
|
|
1117
|
+
state.logger.log(`resolveId: resolved aliased bare ${id} to ${resolved.id} via Vite resolver`);
|
|
1031
1118
|
if (isBuild && resolved.id.startsWith("/@fs/")) return {
|
|
1032
1119
|
...resolved,
|
|
1033
1120
|
id: normalizeFsIdForBuild(resolved.id)
|
|
1034
1121
|
};
|
|
1122
|
+
const nodeResolved = resolveBareImportCandidatesWithNode(state, id, cleanImporter, resolved.id);
|
|
1123
|
+
if (nodeResolved) {
|
|
1124
|
+
state.logger.log(`resolveId: normalized aliased bare ${id} to ${nodeResolved} via Node fallback`);
|
|
1125
|
+
return nodeResolved;
|
|
1126
|
+
}
|
|
1127
|
+
if (isBareSpecifier(resolved.id)) return null;
|
|
1035
1128
|
return resolved;
|
|
1036
1129
|
}
|
|
1037
1130
|
} catch {}
|
|
1038
|
-
const nodeResolved =
|
|
1131
|
+
const nodeResolved = resolveBareImportCandidatesWithNode(state, aliasRequest, cleanImporter);
|
|
1039
1132
|
if (nodeResolved) {
|
|
1040
|
-
state.logger.log(`resolveId: resolved bare ${id} to ${nodeResolved} via Node fallback`);
|
|
1133
|
+
state.logger.log(`resolveId: resolved aliased bare ${id} to ${nodeResolved} via Node fallback`);
|
|
1041
1134
|
return nodeResolved;
|
|
1042
1135
|
}
|
|
1043
1136
|
}
|
|
@@ -1515,6 +1608,9 @@ function patchUnoCssBridge(plugins) {
|
|
|
1515
1608
|
}
|
|
1516
1609
|
//#endregion
|
|
1517
1610
|
//#region src/plugin/index.ts
|
|
1611
|
+
function aliasSortKey(find) {
|
|
1612
|
+
return typeof find === "string" ? find.length : find.source.length;
|
|
1613
|
+
}
|
|
1518
1614
|
function vize(options = {}) {
|
|
1519
1615
|
const state = {
|
|
1520
1616
|
cache: /* @__PURE__ */ new Map(),
|
|
@@ -1632,13 +1728,13 @@ function vize(options = {}) {
|
|
|
1632
1728
|
state.dynamicImportAliasRules.sort((a, b) => b.fromPrefix.length - a.fromPrefix.length);
|
|
1633
1729
|
state.cssAliasRules = [];
|
|
1634
1730
|
for (const alias of resolvedConfig.resolve.alias) {
|
|
1635
|
-
if (typeof alias.find
|
|
1731
|
+
if (!(typeof alias.find === "string" || alias.find instanceof RegExp) || typeof alias.replacement !== "string") continue;
|
|
1636
1732
|
state.cssAliasRules.push({
|
|
1637
1733
|
find: alias.find,
|
|
1638
1734
|
replacement: alias.replacement
|
|
1639
1735
|
});
|
|
1640
1736
|
}
|
|
1641
|
-
state.cssAliasRules.sort((a, b) => b.find
|
|
1737
|
+
state.cssAliasRules.sort((a, b) => aliasSortKey(b.find) - aliasSortKey(a.find));
|
|
1642
1738
|
state.filter = createFilter(state.mergedOptions.include, state.mergedOptions.exclude);
|
|
1643
1739
|
state.scanPatterns = state.mergedOptions.scanPatterns ?? ["**/*.vue"];
|
|
1644
1740
|
state.precompileBatchSize = normalizePrecompileBatchSize(state.mergedOptions.precompileBatchSize);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.89.0",
|
|
4
4
|
"description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiler",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@vizejs/native": "0.
|
|
36
|
+
"@vizejs/native": "0.89.0",
|
|
37
37
|
"tinyglobby": "0.2.16",
|
|
38
|
-
"vize": "0.
|
|
38
|
+
"vize": "0.89.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "25.7.0",
|