@immense/vue-pom-generator 1.0.120 → 1.0.122

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,6 +1,6 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
- import process from "node:process";
3
+ import process$1 from "node:process";
4
4
  import { createRequire } from "node:module";
5
5
  import { pathToFileURL, fileURLToPath } from "node:url";
6
6
  import { parseExpression, parse } from "@babel/parser";
@@ -140,7 +140,7 @@ function normalizeNuxtComponentDirs(value, baseDir, context) {
140
140
  }
141
141
  return normalizeNuxtComponentDirs(value.dirs, baseDir, context);
142
142
  }
143
- function resolveNuxtProjectDiscovery(nuxtOptions, getLayerDirectories, cwd = process.cwd()) {
143
+ function resolveNuxtProjectDiscovery(nuxtOptions, getLayerDirectories, cwd = process$1.cwd()) {
144
144
  const rootDir = path.resolve(nuxtOptions.rootDir ?? cwd);
145
145
  const srcDir = path.resolve(nuxtOptions.srcDir ?? rootDir);
146
146
  const fallbackLayer = {
@@ -188,7 +188,7 @@ function resolveNuxtProjectDiscovery(nuxtOptions, getLayerDirectories, cwd = pro
188
188
  wrapperSearchRoots: []
189
189
  };
190
190
  }
191
- async function loadNuxtProjectDiscovery(cwd = process.cwd()) {
191
+ async function loadNuxtProjectDiscovery(cwd = process$1.cwd()) {
192
192
  let loadNuxtConfig;
193
193
  let getLayerDirectories;
194
194
  try {
@@ -4292,7 +4292,7 @@ async function runRouterIntrospectionExclusive(fn) {
4292
4292
  }
4293
4293
  }
4294
4294
  function debugLog(message) {
4295
- if (process.env.VUE_TESTID_DEBUG === "1") {
4295
+ if (process$1.env.VUE_TESTID_DEBUG === "1") {
4296
4296
  console.log(`[vue-pom-generator][router-introspection] ${message}`);
4297
4297
  }
4298
4298
  }
@@ -5117,7 +5117,7 @@ async function introspectNuxtPages(projectRoot, options = {}) {
5117
5117
  projectRoot,
5118
5118
  viewsDirAbs: pagesDir,
5119
5119
  sourceDirs: [pagesDir],
5120
- extraRoots: [process.cwd()]
5120
+ extraRoots: [process$1.cwd()]
5121
5121
  });
5122
5122
  const relativePath = path.relative(pagesDir, fullPath);
5123
5123
  const parsed = path.parse(relativePath);
@@ -5551,7 +5551,7 @@ function resolveRouterEntry(projectRoot, routerEntry) {
5551
5551
  if (!routerEntry) {
5552
5552
  throw new Error("[vue-pom-generator] Router entry path is required when routerAwarePoms is enabled.");
5553
5553
  }
5554
- const root = projectRoot ?? process.cwd();
5554
+ const root = projectRoot ?? process$1.cwd();
5555
5555
  return path.isAbsolute(routerEntry) ? routerEntry : path.resolve(root, routerEntry);
5556
5556
  }
5557
5557
  function createMissingCustomPomDirectoryError(configuredDir, resolvedDir) {
@@ -5634,7 +5634,7 @@ function resolveVueSourcePath(targetClassName, vueFilesPathMap, projectRoot) {
5634
5634
  return candidates.find((candidate) => fs.existsSync(candidate));
5635
5635
  }
5636
5636
  async function introspectRouteMetaEntries(projectRoot, routerEntry, routerType, options = {}) {
5637
- const root = projectRoot ?? process.cwd();
5637
+ const root = projectRoot ?? process$1.cwd();
5638
5638
  const pageDirs = options.pageDirs?.length ? options.pageDirs : ["src/views"];
5639
5639
  const pageDirsAbs = pageDirs.map((dir) => path.isAbsolute(dir) ? dir : path.resolve(root, dir));
5640
5640
  const primaryPageDirAbs = pageDirsAbs[0] ?? path.resolve(root, "src/views");
@@ -5643,7 +5643,7 @@ async function introspectRouteMetaEntries(projectRoot, routerEntry, routerType,
5643
5643
  ...options.componentDirs?.length ? options.componentDirs : ["src/components"],
5644
5644
  ...options.layoutDirs?.length ? options.layoutDirs : ["src/layouts"]
5645
5645
  ];
5646
- const extraRoots = process.cwd() !== root ? [process.cwd()] : [];
5646
+ const extraRoots = process$1.cwd() !== root ? [process$1.cwd()] : [];
5647
5647
  const { routeMetaEntries } = routerType === "nuxt" ? await introspectNuxtPages(root, { pageDirs: pageDirsAbs, collectComponentFiles: options.collectComponentFiles }) : await parseRouterFileFromCwd(resolveRouterEntry(root, routerEntry), {
5648
5648
  componentNaming: {
5649
5649
  projectRoot: root,
@@ -6013,7 +6013,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
6013
6013
  renderCache
6014
6014
  } = options;
6015
6015
  const emitLanguages = emitLanguagesOverride?.length ? emitLanguagesOverride : ["ts"];
6016
- const root = projectRoot ?? process.cwd();
6016
+ const root = projectRoot ?? process$1.cwd();
6017
6017
  const outDir = path.resolve(root, outDirOverride ?? "./pom");
6018
6018
  const vueTestUtilsOutDir = vueTestUtilsOutDirOverride ? path.resolve(root, vueTestUtilsOutDirOverride) : void 0;
6019
6019
  if (vueTestUtilsOutDir && path.resolve(vueTestUtilsOutDir) === path.resolve(outDir)) {
@@ -6310,7 +6310,7 @@ function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {})
6310
6310
  ];
6311
6311
  }
6312
6312
  async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, options = {}) {
6313
- const projectRoot = options.projectRoot ?? process.cwd();
6313
+ const projectRoot = options.projectRoot ?? process$1.cwd();
6314
6314
  const entries = Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0]));
6315
6315
  const base = ensureDir(outDir);
6316
6316
  const generatedClassNames = new Set(entries.map(([name]) => name));
@@ -6792,7 +6792,7 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
6792
6792
  const looksLikeFilePath = fixtureOutRel.endsWith(".ts") || fixtureOutRel.endsWith(".tsx") || fixtureOutRel.endsWith(".mts") || fixtureOutRel.endsWith(".cts");
6793
6793
  const fixtureOutDirRel = looksLikeFilePath ? path.dirname(fixtureOutRel) : fixtureOutRel;
6794
6794
  const fixtureFileName = looksLikeFilePath ? path.basename(fixtureOutRel) : "fixtures.g.ts";
6795
- const root = options.projectRoot ?? process.cwd();
6795
+ const root = options.projectRoot ?? process$1.cwd();
6796
6796
  const fixtureOutDirAbs = path.isAbsolute(fixtureOutDirRel) ? fixtureOutDirRel : path.resolve(root, fixtureOutDirRel);
6797
6797
  const customPomDirRel = options.customPomDir ?? "tests/playwright/pom/custom";
6798
6798
  const customPomDirAbs = path.isAbsolute(customPomDirRel) ? customPomDirRel : path.resolve(root, customPomDirRel);
@@ -7394,7 +7394,7 @@ function generateViewObjectModelContent(componentName, dependencies, componentHi
7394
7394
  const sourceRel = toPosixRelativePath(outputDir, filePath);
7395
7395
  const kind = prepared.isView ? "Page" : "Component";
7396
7396
  const doc = `/** ${kind} POM: ${componentName} (source: ${sourceRel}) */`;
7397
- const projectRoot = options.projectRoot ?? process.cwd();
7397
+ const projectRoot = options.projectRoot ?? process$1.cwd();
7398
7398
  const fromAbs = path.isAbsolute(outputDir) ? outputDir : path.resolve(projectRoot, outputDir);
7399
7399
  const toAbs = basePageClassPath ? path.isAbsolute(basePageClassPath) ? basePageClassPath : path.resolve(projectRoot, basePageClassPath) : "";
7400
7400
  const basePageImport = path.relative(fromAbs, toAbs).replace(/\\/g, "/");
@@ -7920,7 +7920,7 @@ function getComposedStubBody(targetClassName, availableClassNames, depsByClassNa
7920
7920
  };
7921
7921
  }
7922
7922
  async function generateAggregatedFiles(componentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, options = {}) {
7923
- const projectRoot = options.projectRoot ?? process.cwd();
7923
+ const projectRoot = options.projectRoot ?? process$1.cwd();
7924
7924
  const entries = Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0]));
7925
7925
  const views = entries.filter(([, d]) => d.isView);
7926
7926
  const components = entries.filter(([, d]) => !d.isView);
@@ -8324,7 +8324,7 @@ function createBuildProcessorPlugin(options) {
8324
8324
  projectRoot: projectRootRef.current,
8325
8325
  viewsDirAbs: getViewsDirAbs(),
8326
8326
  sourceDirs: getSourceDirs(),
8327
- extraRoots: [process.cwd()]
8327
+ extraRoots: [process$1.cwd()]
8328
8328
  });
8329
8329
  if (componentHierarchyMap.has(componentName))
8330
8330
  continue;
@@ -8567,7 +8567,7 @@ ${buildSearchRootsKey(normalizedSearchRoots)}`;
8567
8567
  }
8568
8568
  const candidateNames = [`${tag}.vue`, `${toKebabCaseTag(tag)}.vue`];
8569
8569
  const directCandidates = [
8570
- registeredPath ? path.resolve(process.cwd(), registeredPath) : null,
8570
+ registeredPath ? path.resolve(process$1.cwd(), registeredPath) : null,
8571
8571
  ...normalizedSearchRoots.flatMap((root) => candidateNames.map((fileName) => path.join(root, fileName)))
8572
8572
  ].filter((value) => !!value);
8573
8573
  const directMatch = directCandidates.find((candidatePath) => fs.existsSync(candidatePath));
@@ -10536,7 +10536,7 @@ function createVuePluginWithTestIds(options) {
10536
10536
  projectRoot: getProjectRoot(),
10537
10537
  viewsDirAbs: getViewsDirAbs(),
10538
10538
  sourceDirs: getSourceDirs(),
10539
- extraRoots: [process.cwd()]
10539
+ extraRoots: [process$1.cwd()]
10540
10540
  });
10541
10541
  };
10542
10542
  const isFileInScope = (filename) => {
@@ -10549,7 +10549,7 @@ function createVuePluginWithTestIds(options) {
10549
10549
  projectRoot,
10550
10550
  viewsDirAbs: getViewsDirAbs(),
10551
10551
  sourceDirs: getSourceDirs(),
10552
- extraRoots: [process.cwd()]
10552
+ extraRoots: [process$1.cwd()]
10553
10553
  });
10554
10554
  if (cleanPath.endsWith(".vue") && !matched) {
10555
10555
  const absFilename = path.normalize(path.isAbsolute(cleanPath) ? cleanPath : path.resolve(projectRoot, cleanPath));
@@ -10821,7 +10821,7 @@ function createDevProcessorPlugin(options) {
10821
10821
  let scheduleVueFileRegen = null;
10822
10822
  const getProjectRootCandidates = () => Array.from(/* @__PURE__ */ new Set([
10823
10823
  path.resolve(projectRootRef.current),
10824
- path.resolve(process.cwd())
10824
+ path.resolve(process$1.cwd())
10825
10825
  ]));
10826
10826
  const resolveProjectPath = (maybePath) => {
10827
10827
  if (path.isAbsolute(maybePath))
@@ -10873,7 +10873,7 @@ function createDevProcessorPlugin(options) {
10873
10873
  projectRoot: projectRootRef.current,
10874
10874
  viewsDirAbs: getViewsDirAbs(),
10875
10875
  sourceDirs: getSourceDirs(),
10876
- extraRoots: [process.cwd()]
10876
+ extraRoots: [process$1.cwd()]
10877
10877
  }
10878
10878
  });
10879
10879
  }
@@ -10967,7 +10967,7 @@ function createDevProcessorPlugin(options) {
10967
10967
  projectRoot: projectRootRef.current,
10968
10968
  viewsDirAbs: getViewsDirAbs(),
10969
10969
  sourceDirs: getSourceDirs(),
10970
- extraRoots: [process.cwd()]
10970
+ extraRoots: [process$1.cwd()]
10971
10971
  });
10972
10972
  filePathToComponentName.set(normalized, name);
10973
10973
  return name;
@@ -11356,6 +11356,51 @@ ${code}`,
11356
11356
  }
11357
11357
  };
11358
11358
  }
11359
+ function findExportedComponent(code) {
11360
+ const program = parse(code, { sourceType: "module", plugins: ["typescript", "jsx"] }).program;
11361
+ const exported = program.body.find((node) => node.type === "ExportDefaultDeclaration");
11362
+ if (!exported) {
11363
+ return void 0;
11364
+ }
11365
+ const declaration = exported.declaration;
11366
+ if (declaration.type === "Identifier") {
11367
+ return declaration.name;
11368
+ }
11369
+ if (declaration.type === "CallExpression" && declaration.arguments[0]?.type === "Identifier") {
11370
+ return declaration.arguments[0].name;
11371
+ }
11372
+ return void 0;
11373
+ }
11374
+ function addComponentSourcePath(code, file) {
11375
+ const component = findExportedComponent(code);
11376
+ return component ? `${code}
11377
+ ${component}.__file = ${JSON.stringify(file)};
11378
+ ` : void 0;
11379
+ }
11380
+ function createAnnotatorSourcePlugin(options) {
11381
+ let root = process.cwd();
11382
+ return {
11383
+ name: "vue-pom-generator:annotator-sources",
11384
+ enforce: "post",
11385
+ // Client builds only: a server render has no annotator to read the links or paths.
11386
+ apply(config, { command }) {
11387
+ return command === "build" && !config.build?.ssr;
11388
+ },
11389
+ config() {
11390
+ return options.enabled ? { define: { __VUE_PROD_DEVTOOLS__: true } } : void 0;
11391
+ },
11392
+ configResolved(config) {
11393
+ root = config.root;
11394
+ },
11395
+ transform(code, id, transformOptions) {
11396
+ if (!options.enabled || transformOptions?.ssr || !id.endsWith(".vue")) {
11397
+ return null;
11398
+ }
11399
+ const updated = addComponentSourcePath(code, normalizePathSeparators(path.relative(root, id)));
11400
+ return updated === void 0 ? null : { code: updated, map: null };
11401
+ }
11402
+ };
11403
+ }
11359
11404
  function createInternalPlugins(options) {
11360
11405
  const {
11361
11406
  componentHierarchyMap,
@@ -11444,7 +11489,10 @@ function createInternalPlugins(options) {
11444
11489
  sourceAttribute: annotatorRuntime.sourceAttribute,
11445
11490
  metadataAttributePrefix: annotatorRuntime.metadataAttributePrefix
11446
11491
  });
11447
- return [tsProcessor, devProcessor, virtualModules, annotatorUiPlugin];
11492
+ const annotatorSourcePlugin = createAnnotatorSourcePlugin({
11493
+ enabled: annotatorRuntime.enabled && annotatorRuntime.ui.enabled
11494
+ });
11495
+ return [tsProcessor, devProcessor, virtualModules, annotatorUiPlugin, annotatorSourcePlugin];
11448
11496
  }
11449
11497
  const nuxtConfigMarker$1 = /* @__PURE__ */ Symbol.for("@immense/vue-pom-generator.nuxt");
11450
11498
  const nuxtConfigFileNames = [
@@ -11652,7 +11700,7 @@ function assertNotVitePluginInstance(options) {
11652
11700
  function createVuePomGeneratorPlugins(options = {}) {
11653
11701
  return createGeneratorPlugins(options, false);
11654
11702
  }
11655
- function createGeneratorPlugins(options, generationOnly, projectRoot = process.cwd()) {
11703
+ function createGeneratorPlugins(options, generationOnly, projectRoot = process$1.cwd()) {
11656
11704
  assertNotVitePluginInstance(options);
11657
11705
  const injection = options.injection ?? {};
11658
11706
  const isNuxt = detectNuxtProject(options, projectRoot);
@@ -11775,7 +11823,7 @@ function createGeneratorPlugins(options, generationOnly, projectRoot = process.c
11775
11823
  throw new Error('[vue-pom-generator] Remove generation.router.type="nuxt". Nuxt projects are auto-detected.');
11776
11824
  }
11777
11825
  if (isNuxt) {
11778
- const nuxtDiscovery = await loadNuxtProjectDiscovery(process.cwd());
11826
+ const nuxtDiscovery = await loadNuxtProjectDiscovery(process$1.cwd());
11779
11827
  projectRootRef.current = nuxtDiscovery.rootDir;
11780
11828
  resolvedInjectionOptionsRef.current = applyNuxtDiscoveryToInjectionOptions(
11781
11829
  resolvedInjectionOptionsRef.current,