@vizejs/vite-plugin 0.712.0 → 0.714.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-D40XcaH-.mjs";
1
+ import { t as vize } from "./plugin-3vU6ECAI.mjs";
2
2
  import { u as rewriteStaticAssetUrls } from "./vue-version-B0qUneRk.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-CnsxzXW5.mjs";
4
4
  //#region src/index.ts
@@ -1137,31 +1137,41 @@ function clearBuildCaches(state) {
1137
1137
  state.viteResolveCache?.clear();
1138
1138
  }
1139
1139
  //#endregion
1140
- //#region src/plugin/compiled-module-cache.ts
1140
+ //#region src/plugin/path-identity.ts
1141
1141
  /**
1142
- * Compiled-module caches carrying a reverse index from a `src`-imported
1143
- * dependency to the SFCs that pulled it in.
1144
- *
1145
- * Every hot update has to answer "which SFCs own this changed file?" before it
1146
- * can do anything else, and that answer used to come from a full scan of both
1147
- * caches with a `path.resolve` per dependency per cached file. HMR latency then
1148
- * grew with the number of components in the project, on the interactive path,
1149
- * for every save — including saves of ordinary `.vue` files, because the scan
1150
- * runs before the `.vue` fast path.
1142
+ * Every stable filesystem identity Vite may use for one authored path.
1151
1143
  *
1152
- * The index is maintained by overriding `set`/`delete`/`clear` rather than by a
1153
- * second structure updated at each call site. `state.cache` is handed to
1154
- * `compileFile` and `compileBatch`, and is also mutated directly from
1155
- * `precompile-run.ts`, `hmr.ts` and `state.ts`; a structure kept in sync by hand
1156
- * across those would drift the first time a new writer appeared. Subclassing
1157
- * puts the bookkeeping where the mutation is.
1158
- *
1159
- * The keys are `path.resolve`d exactly as the previous scan resolved them, so a
1160
- * dependency recorded as a relative path indexes and looks up identically.
1144
+ * Vite normally resolves workspace links, while chokidar and plugins can
1145
+ * report either the logical link or its physical target. Missing watched files
1146
+ * (notably a tsconfig that is created later) still inherit the real identity
1147
+ * of their nearest existing parent.
1161
1148
  */
1149
+ function filesystemPathIdentities(file) {
1150
+ const resolved = path.resolve(file);
1151
+ const identities = new Set([resolved]);
1152
+ let existing = resolved;
1153
+ const missing = [];
1154
+ for (;;) try {
1155
+ const physical = fs.realpathSync.native(existing);
1156
+ identities.add(path.join(physical, ...missing));
1157
+ break;
1158
+ } catch (error) {
1159
+ const code = error.code;
1160
+ if (code !== "ENOENT" && code !== "ENOTDIR") break;
1161
+ const parent = path.dirname(existing);
1162
+ if (parent === existing) break;
1163
+ missing.unshift(path.basename(existing));
1164
+ existing = parent;
1165
+ }
1166
+ return [...identities];
1167
+ }
1168
+ //#endregion
1169
+ //#region src/plugin/compiled-module-cache.ts
1162
1170
  var CompiledModuleCache = class extends Map {
1163
1171
  #ownersByDependency = /* @__PURE__ */ new Map();
1164
1172
  #dependenciesByOwner = /* @__PURE__ */ new Map();
1173
+ #ownersByFileIdentity = /* @__PURE__ */ new Map();
1174
+ #fileIdentitiesByOwner = /* @__PURE__ */ new Map();
1165
1175
  /**
1166
1176
  * Deliberately takes no entries: `Map`'s constructor would call the
1167
1177
  * overridden `set` from inside `super()`, before `#ownersByDependency` exists.
@@ -1173,14 +1183,20 @@ var CompiledModuleCache = class extends Map {
1173
1183
  this.#unindex(file);
1174
1184
  super.set(file, compiled);
1175
1185
  const dependencies = /* @__PURE__ */ new Set();
1176
- for (const dependency of compiled.dependencies ?? []) {
1177
- const key = path.resolve(dependency);
1186
+ for (const dependency of compiled.dependencies ?? []) for (const key of filesystemPathIdentities(dependency)) {
1178
1187
  dependencies.add(key);
1179
1188
  const owners = this.#ownersByDependency.get(key);
1180
1189
  if (owners) owners.add(file);
1181
1190
  else this.#ownersByDependency.set(key, new Set([file]));
1182
1191
  }
1183
1192
  this.#dependenciesByOwner.set(file, dependencies);
1193
+ const fileIdentities = new Set(filesystemPathIdentities(file));
1194
+ for (const identity of fileIdentities) {
1195
+ const owners = this.#ownersByFileIdentity.get(identity);
1196
+ if (owners) owners.add(file);
1197
+ else this.#ownersByFileIdentity.set(identity, new Set([file]));
1198
+ }
1199
+ this.#fileIdentitiesByOwner.set(file, fileIdentities);
1184
1200
  return this;
1185
1201
  }
1186
1202
  delete(file) {
@@ -1190,6 +1206,8 @@ var CompiledModuleCache = class extends Map {
1190
1206
  clear() {
1191
1207
  this.#ownersByDependency.clear();
1192
1208
  this.#dependenciesByOwner.clear();
1209
+ this.#ownersByFileIdentity.clear();
1210
+ this.#fileIdentitiesByOwner.clear();
1193
1211
  super.clear();
1194
1212
  }
1195
1213
  /**
@@ -1202,8 +1220,15 @@ var CompiledModuleCache = class extends Map {
1202
1220
  }
1203
1221
  /** The cached SFCs that `src`-import `resolvedDependency`. */
1204
1222
  ownersOf(resolvedDependency) {
1205
- const owners = this.#ownersByDependency.get(resolvedDependency);
1206
- return owners ? [...owners] : [];
1223
+ const owners = /* @__PURE__ */ new Set();
1224
+ for (const identity of filesystemPathIdentities(resolvedDependency)) for (const owner of this.#ownersByDependency.get(identity) ?? []) owners.add(owner);
1225
+ return [...owners];
1226
+ }
1227
+ /** Cached logical owner paths that name the same physical SFC as `file`. */
1228
+ ownersOfFile(file) {
1229
+ const owners = /* @__PURE__ */ new Set();
1230
+ for (const identity of filesystemPathIdentities(file)) for (const owner of this.#ownersByFileIdentity.get(identity) ?? []) owners.add(owner);
1231
+ return [...owners];
1207
1232
  }
1208
1233
  #unindex(file) {
1209
1234
  for (const dependency of this.#dependenciesByOwner.get(file) ?? []) {
@@ -1213,6 +1238,13 @@ var CompiledModuleCache = class extends Map {
1213
1238
  if (owners.size === 0) this.#ownersByDependency.delete(dependency);
1214
1239
  }
1215
1240
  this.#dependenciesByOwner.delete(file);
1241
+ for (const identity of this.#fileIdentitiesByOwner.get(file) ?? []) {
1242
+ const owners = this.#ownersByFileIdentity.get(identity);
1243
+ if (!owners) continue;
1244
+ owners.delete(file);
1245
+ if (owners.size === 0) this.#ownersByFileIdentity.delete(identity);
1246
+ }
1247
+ this.#fileIdentitiesByOwner.delete(file);
1216
1248
  }
1217
1249
  };
1218
1250
  /**
@@ -1231,9 +1263,16 @@ function evictCompiledModule(cache, file) {
1231
1263
  function ownersOfDependency(cache, resolvedDependency) {
1232
1264
  if (cache instanceof CompiledModuleCache) return cache.ownersOf(resolvedDependency);
1233
1265
  const owners = [];
1234
- for (const [file, compiled] of cache) if (compiled.dependencies?.some((dependency) => path.resolve(dependency) === resolvedDependency)) owners.push(file);
1266
+ const requested = new Set(filesystemPathIdentities(resolvedDependency));
1267
+ for (const [file, compiled] of cache) if (compiled.dependencies?.some((dependency) => filesystemPathIdentities(dependency).some((identity) => requested.has(identity)))) owners.push(file);
1235
1268
  return owners;
1236
1269
  }
1270
+ /** Cached owner paths that are filesystem aliases of `file`. */
1271
+ function ownersOfFile(cache, file) {
1272
+ if (cache instanceof CompiledModuleCache) return cache.ownersOfFile(file);
1273
+ const requested = new Set(filesystemPathIdentities(file));
1274
+ return [...cache.keys()].filter((owner) => filesystemPathIdentities(owner).some((identity) => requested.has(identity)));
1275
+ }
1237
1276
  //#endregion
1238
1277
  //#region ../shared/sfc-src.ts
1239
1278
  /**
@@ -2165,7 +2204,10 @@ function watchTypeProject(cache, context, addWatchFile, api = native) {
2165
2204
  projects.set(context.root, context.revision);
2166
2205
  }
2167
2206
  function typeProjectDependencyRoots(cache, file, api = native) {
2168
- return watched.has(cache) ? api.typeProjectOwners(file) : [];
2207
+ if (!watched.has(cache)) return [];
2208
+ const owners = /* @__PURE__ */ new Set();
2209
+ for (const identity of filesystemPathIdentities(file)) for (const owner of api.typeProjectOwners(identity)) owners.add(owner);
2210
+ return [...owners];
2169
2211
  }
2170
2212
  //#endregion
2171
2213
  //#region src/plugin/precompile-run.ts
@@ -3914,7 +3956,8 @@ const VIZE_COMPONENTS_CSS_FILE = `assets/${VIZE_COMPONENTS_CSS_BASENAME}`;
3914
3956
  * path, so editing an ordinary SFC pays for it too. It used to walk both caches
3915
3957
  * end to end with a `path.resolve` per dependency, which made HMR latency grow
3916
3958
  * with the number of components in the project; the caches now carry a reverse
3917
- * index that answers it in constant time. See `compiled-module-cache.ts`.
3959
+ * index of both logical and physical paths that answers it in constant time.
3960
+ * See `compiled-module-cache.ts`.
3918
3961
  */
3919
3962
  function getVueFilesDependingOn(state, dependencyFile) {
3920
3963
  const dependencies = [path.resolve(dependencyFile), ...typeProjectDependencyRoots(state.cache, dependencyFile)];
@@ -3961,81 +4004,100 @@ async function handleHotUpdateHook(state, ctx, options = {}) {
3961
4004
  }
3962
4005
  return [...affectedModules];
3963
4006
  }
3964
- if (file.endsWith(".vue") && state.filter(file)) try {
3965
- const initialModules = options.requireAcceptingClientModule ? preferAcceptingClientModules(await collectModulesByFile(server, getVueModuleFileCandidates(file)), true) : void 0;
3966
- if (initialModules?.size === 0) return [];
3967
- const source = await read();
3968
- const prevCompiled = state.cache.get(file);
3969
- if (options.resolve) await prepareSfcSrcRequests(state, options.resolve, file, source);
3970
- compileFile(file, state.cache, getCompileOptionsForRequest(state, false, file), source);
3971
- state.ssrCache.delete(file);
3972
- const newCompiled = state.cache.get(file);
3973
- try {
3974
- const stat = fs.statSync(file);
3975
- state.precompileMetadata.set(file, {
3976
- mtimeMs: stat.mtimeMs,
3977
- size: stat.size
3978
- });
3979
- } catch {
3980
- state.precompileMetadata.delete(file);
3981
- }
3982
- if (!hasHmrChanges(prevCompiled, newCompiled)) {
3983
- state.pendingHmrUpdateTypes.delete(file);
3984
- state.logger.log(`Re-compiled: ${path.relative(state.root, file)} (no-op)`);
3985
- return [];
3986
- }
3987
- const updateType = detectHmrUpdateType(prevCompiled, newCompiled);
3988
- state.logger.log(`Re-compiled: ${path.relative(state.root, file)} (${updateType})`);
3989
- const modules = preferAcceptingClientModules(initialModules ?? await collectModulesByFile(server, getVueModuleFileCandidates(file)), options.requireAcceptingClientModule);
3990
- if (isPluginVueCustomElement(state.mergedOptions, file) && updateType === "style-only") {
3991
- if (modules.size > 0) {
3992
- state.pendingHmrUpdateTypes.set(file, "full-reload");
3993
- invalidateModules(server, modules);
3994
- return [...modules];
3995
- }
3996
- state.pendingHmrUpdateTypes.delete(file);
3997
- return [];
3998
- }
3999
- if (newCompiled.styles?.length && updateType === "style-only") {
4000
- const affectedModules = await collectStyleModules(server, file, newCompiled);
4001
- if (affectedModules.size > 0) return [...affectedModules];
4002
- if (modules.size > 0) return [...modules];
4003
- return [];
4004
- }
4005
- if (updateType === "style-only" && newCompiled.css && !hasDelegatedStyles(newCompiled)) {
4006
- state.pendingHmrUpdateTypes.delete(file);
4007
- server.ws.send({
4008
- type: "custom",
4009
- event: "vize:update",
4010
- data: {
4011
- id: newCompiled.scopeId,
4012
- type: "style-only",
4013
- css: resolveCssImports(newCompiled.css, file, state.cssAliasRules, true, state.clientViteBase)
4014
- }
4015
- });
4016
- return [];
4007
+ if (!file.endsWith(".vue")) return;
4008
+ const cachedOwners = new Set([...ownersOfFile(state.cache, file), ...ownersOfFile(state.ssrCache, file)]);
4009
+ const vueFiles = cachedOwners.size > 0 ? [...cachedOwners] : state.filter(file) ? [file] : [];
4010
+ if (vueFiles.length === 0) return;
4011
+ let source;
4012
+ const readSource = () => source ??= read();
4013
+ const affected = /* @__PURE__ */ new Set();
4014
+ let useDefaultHandling = false;
4015
+ try {
4016
+ for (const vueFile of vueFiles) {
4017
+ const modules = await handleVueFileHotUpdate(state, ctx, vueFile, readSource, options);
4018
+ if (modules === void 0) useDefaultHandling = true;
4019
+ else for (const module of modules) affected.add(module);
4017
4020
  }
4021
+ } catch (error) {
4022
+ state.logger.error(`Re-compilation failed for ${file}:`, error);
4023
+ options.onRecompileError?.(error);
4024
+ return;
4025
+ }
4026
+ if (affected.size > 0) return [...affected];
4027
+ return useDefaultHandling ? void 0 : [];
4028
+ }
4029
+ async function handleVueFileHotUpdate(state, ctx, file, readSource, options) {
4030
+ const { server } = ctx;
4031
+ const initialModules = options.requireAcceptingClientModule ? preferAcceptingClientModules(await collectModulesByFile(server, getVueModuleFileCandidates(file)), true) : void 0;
4032
+ if (initialModules?.size === 0) return [];
4033
+ const source = await readSource();
4034
+ const prevCompiled = state.cache.get(file);
4035
+ if (options.resolve) await prepareSfcSrcRequests(state, options.resolve, file, source);
4036
+ compileFile(file, state.cache, getCompileOptionsForRequest(state, false, file), source);
4037
+ state.ssrCache.delete(file);
4038
+ const newCompiled = state.cache.get(file);
4039
+ try {
4040
+ const stat = fs.statSync(file);
4041
+ state.precompileMetadata.set(file, {
4042
+ mtimeMs: stat.mtimeMs,
4043
+ size: stat.size
4044
+ });
4045
+ } catch {
4046
+ state.precompileMetadata.delete(file);
4047
+ }
4048
+ if (!hasHmrChanges(prevCompiled, newCompiled)) {
4049
+ state.pendingHmrUpdateTypes.delete(file);
4050
+ state.logger.log(`Re-compiled: ${path.relative(state.root, file)} (no-op)`);
4051
+ return [];
4052
+ }
4053
+ const updateType = detectHmrUpdateType(prevCompiled, newCompiled);
4054
+ state.logger.log(`Re-compiled: ${path.relative(state.root, file)} (${updateType})`);
4055
+ const modules = preferAcceptingClientModules(initialModules ?? await collectModulesByFile(server, getVueModuleFileCandidates(file)), options.requireAcceptingClientModule);
4056
+ if (isPluginVueCustomElement(state.mergedOptions, file) && updateType === "style-only") {
4018
4057
  if (modules.size > 0) {
4019
- state.pendingHmrUpdateTypes.set(file, updateType);
4058
+ state.pendingHmrUpdateTypes.set(file, "full-reload");
4020
4059
  invalidateModules(server, modules);
4021
- const affected = new Set(modules);
4022
- if (newCompiled.styles?.length && hasStyleChanges(prevCompiled, newCompiled)) {
4023
- const styleModules = await collectStyleModules(server, file, newCompiled);
4024
- invalidateModules(server, styleModules);
4025
- for (const module of styleModules) affected.add(module);
4026
- }
4027
- if (hasCustomBlockChanges(prevCompiled, newCompiled)) {
4028
- const blockModules = await collectCustomBlockModules(server, file, newCompiled);
4029
- invalidateModules(server, blockModules);
4030
- for (const module of blockModules) affected.add(module);
4031
- }
4032
- return [...affected];
4060
+ return [...modules];
4033
4061
  }
4034
4062
  state.pendingHmrUpdateTypes.delete(file);
4035
- } catch (e) {
4036
- state.logger.error(`Re-compilation failed for ${file}:`, e);
4037
- options.onRecompileError?.(e);
4063
+ return [];
4064
+ }
4065
+ if (newCompiled.styles?.length && updateType === "style-only") {
4066
+ const affectedModules = await collectStyleModules(server, file, newCompiled);
4067
+ if (affectedModules.size > 0) return [...affectedModules];
4068
+ if (modules.size > 0) return [...modules];
4069
+ return [];
4070
+ }
4071
+ if (updateType === "style-only" && newCompiled.css && !hasDelegatedStyles(newCompiled)) {
4072
+ state.pendingHmrUpdateTypes.delete(file);
4073
+ server.ws.send({
4074
+ type: "custom",
4075
+ event: "vize:update",
4076
+ data: {
4077
+ id: newCompiled.scopeId,
4078
+ type: "style-only",
4079
+ css: resolveCssImports(newCompiled.css, file, state.cssAliasRules, true, state.clientViteBase)
4080
+ }
4081
+ });
4082
+ return [];
4083
+ }
4084
+ if (modules.size > 0) {
4085
+ state.pendingHmrUpdateTypes.set(file, updateType);
4086
+ invalidateModules(server, modules);
4087
+ const affected = new Set(modules);
4088
+ if (newCompiled.styles?.length && hasStyleChanges(prevCompiled, newCompiled)) {
4089
+ const styleModules = await collectStyleModules(server, file, newCompiled);
4090
+ invalidateModules(server, styleModules);
4091
+ for (const module of styleModules) affected.add(module);
4092
+ }
4093
+ if (hasCustomBlockChanges(prevCompiled, newCompiled)) {
4094
+ const blockModules = await collectCustomBlockModules(server, file, newCompiled);
4095
+ invalidateModules(server, blockModules);
4096
+ for (const module of blockModules) affected.add(module);
4097
+ }
4098
+ return [...affected];
4038
4099
  }
4100
+ state.pendingHmrUpdateTypes.delete(file);
4039
4101
  }
4040
4102
  async function collectStyleModules(server, file, compiled) {
4041
4103
  const styleModules = /* @__PURE__ */ new Set();
@@ -0,0 +1,2 @@
1
+ import { t as vize } from "./plugin-3vU6ECAI.mjs";
2
+ export { vize };
@@ -400,7 +400,7 @@ function defineConfig(config = {}, integration = {}) {
400
400
  const legacy = compiler !== false && (await import("./vue-version-DL5NF2G-.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-BxWZH4w9.mjs");
403
+ const { vize } = await import("./plugin-CaOyzUlE.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.712.0",
3
+ "version": "0.714.0",
4
4
  "description": "High-performance native Vite plugin for Vue SFC compilation powered by Vize",
5
5
  "keywords": [
6
6
  "compiler",
@@ -51,16 +51,17 @@
51
51
  "access": "public"
52
52
  },
53
53
  "dependencies": {
54
- "@vizejs/native": "0.712.0",
55
- "@vizejs/unplugin": "0.712.0",
54
+ "@vizejs/native": "0.714.0",
55
+ "@vizejs/unplugin": "0.714.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.712.0"
60
+ "vize": "0.714.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "25.9.2",
64
+ "oxfmt": "0.63.0",
64
65
  "typescript": "6.0.3",
65
66
  "vite": "npm:@voidzero-dev/vite-plus-core@0.1.24",
66
67
  "vite-plus": "^0.2.3",
@@ -90,8 +91,8 @@
90
91
  "check": "vp check src vite.config.ts",
91
92
  "check:fix": "vp check --fix src vite.config.ts",
92
93
  "fmt": "vp fmt --write src vite.config.ts",
93
- "test": "node scripts/run-tests.mjs",
94
- "test:prepared": "node scripts/run-tests.mjs --require-prepared && node --test --test-concurrency=1 \"src/**/*.test.ts\"",
94
+ "test": "node scripts/run-tests.ts",
95
+ "test:prepared": "node scripts/run-tests.ts --require-prepared && node --test --test-concurrency=1 \"src/**/*.test.ts\"",
95
96
  "test:types:markdown": "vp exec tsc -p type-tests/markdown/tsconfig.json",
96
97
  "test:types:real-vite": "vp exec node type-tests/plugin-vue/check.ts"
97
98
  }
@@ -1,2 +0,0 @@
1
- import { t as vize } from "./plugin-D40XcaH-.mjs";
2
- export { vize };