@immense/vue-pom-generator 1.0.41 → 1.0.42

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
@@ -5996,7 +5996,7 @@ function createDevProcessorPlugin(options) {
5996
5996
  return;
5997
5997
  scheduleVueFileRegen(ctx.file, "hmr");
5998
5998
  },
5999
- configureServer(server) {
5999
+ async configureServer(server) {
6000
6000
  const getViewsDirAbs = () => path.isAbsolute(viewsDir) ? viewsDir : path.resolve(projectRootRef.current, viewsDir);
6001
6001
  const routerInitPromise = (async () => {
6002
6002
  if (!routerAwarePoms) {
@@ -6073,8 +6073,8 @@ function createDevProcessorPlugin(options) {
6073
6073
  }
6074
6074
  return out;
6075
6075
  };
6076
- const snapshotHierarchy = /* @__PURE__ */ new Map();
6077
- const snapshotVuePathMap = /* @__PURE__ */ new Map();
6076
+ let snapshotHierarchy = /* @__PURE__ */ new Map();
6077
+ let snapshotVuePathMap = /* @__PURE__ */ new Map();
6078
6078
  const filePathToComponentName = /* @__PURE__ */ new Map();
6079
6079
  const getComponentNameForFile = (filePath) => {
6080
6080
  const normalized = path.resolve(filePath);
@@ -6091,12 +6091,12 @@ function createDevProcessorPlugin(options) {
6091
6091
  filePathToComponentName.set(normalized, name);
6092
6092
  return name;
6093
6093
  };
6094
- const compileVueFileIntoSnapshot = (filePath) => {
6094
+ const compileVueFileIntoSnapshot = (filePath, targetHierarchy = snapshotHierarchy, targetVuePathMap = snapshotVuePathMap) => {
6095
6095
  const started = performance.now();
6096
6096
  const absolutePath = path.resolve(filePath);
6097
6097
  const componentName = getComponentNameForFile(absolutePath);
6098
- snapshotVuePathMap.set(componentName, absolutePath);
6099
- snapshotHierarchy.delete(componentName);
6098
+ targetVuePathMap.set(componentName, absolutePath);
6099
+ targetHierarchy.delete(componentName);
6100
6100
  let sfc = "";
6101
6101
  try {
6102
6102
  sfc = fs.readFileSync(absolutePath, "utf8");
@@ -6106,36 +6106,33 @@ function createDevProcessorPlugin(options) {
6106
6106
  const template = extractTemplateFromSfc(sfc, absolutePath);
6107
6107
  if (!template.trim())
6108
6108
  return { componentName, ms: performance.now() - started, compiled: true };
6109
- try {
6110
- compilerDom.compile(template, {
6111
- filename: absolutePath,
6112
- prefixIdentifiers: true,
6113
- nodeTransforms: [
6114
- createTestIdTransform(
6115
- componentName,
6116
- snapshotHierarchy,
6117
- nativeWrappers,
6118
- excludedComponents,
6119
- getViewsDirAbs(),
6120
- {
6121
- existingIdBehavior: "preserve",
6122
- nameCollisionBehavior,
6123
- testIdAttribute,
6124
- warn: (message) => loggerRef.current.warn(message),
6125
- vueFilesPathMap: snapshotVuePathMap,
6126
- wrapperSearchRoots: getWrapperSearchRoots()
6127
- }
6128
- )
6129
- ]
6130
- });
6131
- } catch {
6132
- }
6109
+ compilerDom.compile(template, {
6110
+ filename: absolutePath,
6111
+ prefixIdentifiers: true,
6112
+ nodeTransforms: [
6113
+ createTestIdTransform(
6114
+ componentName,
6115
+ targetHierarchy,
6116
+ nativeWrappers,
6117
+ excludedComponents,
6118
+ getViewsDirAbs(),
6119
+ {
6120
+ existingIdBehavior: "preserve",
6121
+ nameCollisionBehavior,
6122
+ testIdAttribute,
6123
+ warn: (message) => loggerRef.current.warn(message),
6124
+ vueFilesPathMap: targetVuePathMap,
6125
+ wrapperSearchRoots: getWrapperSearchRoots()
6126
+ }
6127
+ )
6128
+ ]
6129
+ });
6133
6130
  return { componentName, ms: performance.now() - started, compiled: true };
6134
6131
  };
6135
6132
  const fullRebuildSnapshotFromFilesystem = () => {
6136
6133
  const t0 = performance.now();
6137
- snapshotHierarchy.clear();
6138
- snapshotVuePathMap.clear();
6134
+ const nextHierarchy = /* @__PURE__ */ new Map();
6135
+ const nextVuePathMap = /* @__PURE__ */ new Map();
6139
6136
  filePathToComponentName.clear();
6140
6137
  let totalVueFiles = 0;
6141
6138
  let compiledCount = 0;
@@ -6146,11 +6143,13 @@ function createDevProcessorPlugin(options) {
6146
6143
  const vueFiles = walkFilesRecursive(absDir);
6147
6144
  totalVueFiles += vueFiles.length;
6148
6145
  for (const file of vueFiles) {
6149
- const res = compileVueFileIntoSnapshot(file);
6146
+ const res = compileVueFileIntoSnapshot(file, nextHierarchy, nextVuePathMap);
6150
6147
  if (res.compiled)
6151
6148
  compiledCount++;
6152
6149
  }
6153
6150
  }
6151
+ snapshotHierarchy = nextHierarchy;
6152
+ snapshotVuePathMap = nextVuePathMap;
6154
6153
  const t1 = performance.now();
6155
6154
  logInfo(`initial scan: found ${totalVueFiles} .vue files in ${scanDirs.join(", ")}`);
6156
6155
  logInfo(`initial compile: ${compiledCount}/${totalVueFiles} files in ${formatMs(t1 - t0)} (components=${snapshotHierarchy.size})`);
@@ -6177,6 +6176,10 @@ function createDevProcessorPlugin(options) {
6177
6176
  const t1 = performance.now();
6178
6177
  logInfo(`generate(${reason}): components=${snapshotHierarchy.size} in ${formatMs(t1 - t0)}`);
6179
6178
  };
6179
+ let timer = null;
6180
+ let maxWaitTimer = null;
6181
+ const pendingChangedVueFiles = /* @__PURE__ */ new Set();
6182
+ const pendingDeletedComponents = /* @__PURE__ */ new Set();
6180
6183
  const initialBuildPromise = (async () => {
6181
6184
  const t0 = performance.now();
6182
6185
  await routerInitPromise;
@@ -6185,13 +6188,44 @@ function createDevProcessorPlugin(options) {
6185
6188
  const t1 = performance.now();
6186
6189
  logInfo(`startup total: ${formatMs(t1 - t0)}`);
6187
6190
  })();
6191
+ const logGenerationError = (reason, message) => {
6192
+ server.config.logger.error(`[vue-pom-generator] dev generation failed during ${reason}: ${message}`);
6193
+ };
6194
+ const regenerateFromPending = async (reason) => {
6195
+ const t0 = performance.now();
6196
+ await initialBuildPromise;
6197
+ const nextHierarchy = new Map(snapshotHierarchy);
6198
+ const nextVuePathMap = new Map(snapshotVuePathMap);
6199
+ for (const componentName of pendingDeletedComponents) {
6200
+ nextHierarchy.delete(componentName);
6201
+ nextVuePathMap.delete(componentName);
6202
+ }
6203
+ const files = Array.from(pendingChangedVueFiles);
6204
+ const deletedCount = pendingDeletedComponents.size;
6205
+ pendingChangedVueFiles.clear();
6206
+ pendingDeletedComponents.clear();
6207
+ let compileMs = 0;
6208
+ for (const f of files) {
6209
+ const res = compileVueFileIntoSnapshot(f, nextHierarchy, nextVuePathMap);
6210
+ compileMs += res.ms;
6211
+ }
6212
+ snapshotHierarchy = nextHierarchy;
6213
+ snapshotVuePathMap = nextVuePathMap;
6214
+ const t1 = performance.now();
6215
+ generateAggregatedFromSnapshot(reason);
6216
+ const t2 = performance.now();
6217
+ return {
6218
+ files,
6219
+ deletedCount,
6220
+ compileMs,
6221
+ preGenerateMs: t1 - t0,
6222
+ generateMs: t2 - t1,
6223
+ totalMs: t2 - t0
6224
+ };
6225
+ };
6188
6226
  const watchedVueGlobs = scanDirs.map((dir) => path.resolve(projectRootRef.current, dir, "**", "*.vue"));
6189
6227
  const watchedPluginGlob = path.resolve(projectRootRef.current, "vite-plugins", "vue-pom-generator", "**", "*.ts");
6190
6228
  server.watcher.add([...watchedVueGlobs, watchedPluginGlob, basePageClassPath]);
6191
- let timer = null;
6192
- let maxWaitTimer = null;
6193
- const pendingChangedVueFiles = /* @__PURE__ */ new Set();
6194
- const pendingDeletedComponents = /* @__PURE__ */ new Set();
6195
6229
  scheduleVueFileRegenLocal = (filePath, source) => {
6196
6230
  pendingChangedVueFiles.add(filePath);
6197
6231
  logDebug(`queued(${source}): files=${pendingChangedVueFiles.size} deleted=${pendingDeletedComponents.size}`);
@@ -6208,29 +6242,14 @@ function createDevProcessorPlugin(options) {
6208
6242
  timer = null;
6209
6243
  }
6210
6244
  maxWaitTimer = null;
6211
- void (async () => {
6212
- const t0 = performance.now();
6213
- await initialBuildPromise;
6214
- for (const componentName of pendingDeletedComponents) {
6215
- snapshotHierarchy.delete(componentName);
6216
- snapshotVuePathMap.delete(componentName);
6217
- }
6218
- const files = Array.from(pendingChangedVueFiles);
6219
- const deletedCount = pendingDeletedComponents.size;
6220
- pendingChangedVueFiles.clear();
6221
- pendingDeletedComponents.clear();
6222
- let compileMs = 0;
6223
- for (const f of files) {
6224
- const res = compileVueFileIntoSnapshot(f);
6225
- compileMs += res.ms;
6226
- }
6227
- const t1 = performance.now();
6228
- generateAggregatedFromSnapshot("max-wait");
6229
- const t2 = performance.now();
6245
+ void regenerateFromPending("max-wait").then(({ files, deletedCount, compileMs, preGenerateMs, generateMs, totalMs }) => {
6230
6246
  logInfo(
6231
- `max-wait: files=${files.length} deleted=${deletedCount} compile=${formatMs(compileMs)} wall=${formatMs(t1 - t0)} gen=${formatMs(t2 - t1)} total=${formatMs(t2 - t0)}`
6247
+ `max-wait: files=${files.length} deleted=${deletedCount} compile=${formatMs(compileMs)} wall=${formatMs(preGenerateMs)} gen=${formatMs(generateMs)} total=${formatMs(totalMs)}`
6232
6248
  );
6233
- })();
6249
+ }).catch((error) => {
6250
+ const message = error instanceof Error ? error.message : String(error);
6251
+ logGenerationError("max-wait", message);
6252
+ });
6234
6253
  }, MAX_WAIT_MS);
6235
6254
  }
6236
6255
  if (wasEmpty) {
@@ -6246,31 +6265,17 @@ function createDevProcessorPlugin(options) {
6246
6265
  clearTimeout(maxWaitTimer);
6247
6266
  maxWaitTimer = null;
6248
6267
  }
6249
- void (async () => {
6250
- const t0 = performance.now();
6251
- await initialBuildPromise;
6252
- for (const componentName of pendingDeletedComponents) {
6253
- snapshotHierarchy.delete(componentName);
6254
- snapshotVuePathMap.delete(componentName);
6255
- }
6256
- const files = Array.from(pendingChangedVueFiles);
6257
- const deletedCount = pendingDeletedComponents.size;
6258
- pendingChangedVueFiles.clear();
6259
- pendingDeletedComponents.clear();
6260
- let compileMs = 0;
6261
- for (const f of files) {
6262
- const res = compileVueFileIntoSnapshot(f);
6263
- compileMs += res.ms;
6264
- }
6265
- const t1 = performance.now();
6266
- generateAggregatedFromSnapshot(files.length || deletedCount ? "batched" : "noop");
6267
- const t2 = performance.now();
6268
+ const reason = pendingChangedVueFiles.size || pendingDeletedComponents.size ? "batched" : "noop";
6269
+ void regenerateFromPending(reason).then(({ files, deletedCount, compileMs, preGenerateMs, generateMs, totalMs }) => {
6268
6270
  if (files.length || deletedCount) {
6269
6271
  logInfo(
6270
- `batched: files=${files.length} deleted=${deletedCount} compile=${formatMs(compileMs)} wall=${formatMs(t1 - t0)} gen=${formatMs(t2 - t1)} total=${formatMs(t2 - t0)}`
6272
+ `batched: files=${files.length} deleted=${deletedCount} compile=${formatMs(compileMs)} wall=${formatMs(preGenerateMs)} gen=${formatMs(generateMs)} total=${formatMs(totalMs)}`
6271
6273
  );
6272
6274
  }
6273
- })();
6275
+ }).catch((error) => {
6276
+ const message = error instanceof Error ? error.message : String(error);
6277
+ logGenerationError(reason, message);
6278
+ });
6274
6279
  }, 75);
6275
6280
  }
6276
6281
  server.watcher.on("change", async (changedPath) => {
@@ -6322,6 +6327,7 @@ function createDevProcessorPlugin(options) {
6322
6327
  });
6323
6328
  setTimeout(() => {
6324
6329
  }, 250);
6330
+ await initialBuildPromise;
6325
6331
  }
6326
6332
  };
6327
6333
  }