@immense/vue-pom-generator 1.0.118 → 1.0.120

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.cjs CHANGED
@@ -262,6 +262,8 @@ function resolveGenerationSupportOptions(options) {
262
262
  requireCustomPomDir: options.requireCustomPomDir ?? false,
263
263
  customPomImportAliases: options.customPomImportAliases,
264
264
  customPomImportNameCollisionBehavior: options.customPomImportNameCollisionBehavior ?? "error",
265
+ customPomFixtures: options.customPomFixtures ?? [],
266
+ componentGraph: options.componentGraph ?? false,
265
267
  nameCollisionBehavior: options.nameCollisionBehavior ?? "error",
266
268
  missingSemanticNameBehavior: options.missingSemanticNameBehavior ?? "error",
267
269
  existingIdBehavior: options.existingIdBehavior ?? "error",
@@ -3917,6 +3919,103 @@ function buildPomGeneratedPropertyName(pom) {
3917
3919
  function buildPomGeneratedActionName(pom) {
3918
3920
  return requireStructuredPomName(pom.generatedActionName, "generatedActionName", pom);
3919
3921
  }
3922
+ function toPosixSlashes(value) {
3923
+ let out = "";
3924
+ for (let i = 0; i < value.length; i++) {
3925
+ const ch = value[i];
3926
+ out += ch === "\\" ? "/" : ch;
3927
+ }
3928
+ return out;
3929
+ }
3930
+ function safeRealpath(value) {
3931
+ try {
3932
+ if (fs.existsSync(value)) {
3933
+ return fs.realpathSync(value);
3934
+ }
3935
+ } catch {
3936
+ return value;
3937
+ }
3938
+ const parent = path.dirname(value);
3939
+ if (!parent || parent === value) {
3940
+ return value;
3941
+ }
3942
+ const resolvedParent = safeRealpath(parent);
3943
+ return resolvedParent === parent ? value : path.join(resolvedParent, path.basename(value));
3944
+ }
3945
+ function normalizeScopePath(value, pathImpl = path) {
3946
+ return pathImpl.normalize(value);
3947
+ }
3948
+ function isNormalizedPathWithinDir(filePathAbs, dirPathAbs, pathImpl = path) {
3949
+ const normalizedFileAbs = normalizeScopePath(filePathAbs, pathImpl);
3950
+ const normalizedDirAbs = normalizeScopePath(dirPathAbs, pathImpl);
3951
+ return normalizedFileAbs === normalizedDirAbs || normalizedFileAbs.startsWith(`${normalizedDirAbs}${pathImpl.sep}`);
3952
+ }
3953
+ function isPathWithinDir(filePathAbs, dirPathAbs) {
3954
+ const fileAbs = path.resolve(filePathAbs);
3955
+ const dirAbs = path.resolve(dirPathAbs);
3956
+ const rel = path.relative(dirAbs, fileAbs);
3957
+ if (!rel)
3958
+ return true;
3959
+ return !rel.startsWith("..") && !path.isAbsolute(rel);
3960
+ }
3961
+ function resolveComponentNameFromPath(options) {
3962
+ const { projectRoot, viewsDirAbs, sourceDirs, extraRoots = [] } = options;
3963
+ const cleanFilename = options.filename.includes("?") ? options.filename.substring(0, options.filename.indexOf("?")) : options.filename;
3964
+ const absFilename = path.isAbsolute(cleanFilename) ? cleanFilename : path.resolve(projectRoot, cleanFilename);
3965
+ const normalizedAbsFilename = toPosixSlashes(path.normalize(safeRealpath(absFilename)));
3966
+ const rootBases = [projectRoot, ...extraRoots.filter((r) => r !== projectRoot)];
3967
+ const roots = [
3968
+ viewsDirAbs,
3969
+ ...sourceDirs.flatMap((dir) => path.isAbsolute(dir) ? [dir] : rootBases.map((base) => path.resolve(base, dir)))
3970
+ ];
3971
+ const potentialRoots = Array.from(new Set(roots.map((r) => toPosixSlashes(path.normalize(safeRealpath(r)))))).sort((a, b) => b.length - a.length);
3972
+ for (const root of potentialRoots) {
3973
+ if (normalizedAbsFilename.startsWith(`${root}/`) || normalizedAbsFilename === root) {
3974
+ const rel = path.posix.relative(root, normalizedAbsFilename);
3975
+ const parsed = path.posix.parse(rel);
3976
+ const segments = path.posix.join(parsed.dir, parsed.name);
3977
+ return toPascalCase(segments);
3978
+ }
3979
+ }
3980
+ return toPascalCase(path.parse(normalizedAbsFilename).name);
3981
+ }
3982
+ function isFileInConfiguredSourceScope(options) {
3983
+ const { filename, projectRoot, viewsDirAbs, sourceDirs, extraRoots = [], pathImpl = path } = options;
3984
+ if (!filename) {
3985
+ return false;
3986
+ }
3987
+ const cleanFilename = filename.includes("?") ? filename.substring(0, filename.indexOf("?")) : filename;
3988
+ const normalizedProjectRoot = normalizeScopePath(projectRoot, pathImpl);
3989
+ const normalizedAbsFilename = normalizeScopePath(
3990
+ pathImpl.isAbsolute(cleanFilename) ? cleanFilename : pathImpl.resolve(normalizedProjectRoot, cleanFilename),
3991
+ pathImpl
3992
+ );
3993
+ if (normalizedAbsFilename.includes(`${pathImpl.sep}node_modules${pathImpl.sep}`) || normalizedAbsFilename.includes("/node_modules/")) {
3994
+ return false;
3995
+ }
3996
+ const normalizedViewsDirAbs = normalizeScopePath(viewsDirAbs, pathImpl);
3997
+ if (isNormalizedPathWithinDir(normalizedAbsFilename, normalizedViewsDirAbs, pathImpl)) {
3998
+ return true;
3999
+ }
4000
+ const rootsToTry = Array.from(/* @__PURE__ */ new Set([
4001
+ normalizedProjectRoot,
4002
+ ...extraRoots.map((root) => normalizeScopePath(root, pathImpl))
4003
+ ]));
4004
+ return sourceDirs.some((dir) => {
4005
+ return rootsToTry.some((root) => {
4006
+ const normalizedAbsDir = normalizeScopePath(pathImpl.resolve(root, dir), pathImpl);
4007
+ if (isNormalizedPathWithinDir(normalizedAbsFilename, normalizedAbsDir, pathImpl)) {
4008
+ return true;
4009
+ }
4010
+ if (dir.startsWith("app/") && pathImpl.basename(root) === "app") {
4011
+ const relativeDir = dir.substring(4);
4012
+ const normalizedAbsDirAlt = normalizeScopePath(pathImpl.resolve(root, relativeDir), pathImpl);
4013
+ return isNormalizedPathWithinDir(normalizedAbsFilename, normalizedAbsDirAlt, pathImpl);
4014
+ }
4015
+ return false;
4016
+ });
4017
+ });
4018
+ }
3920
4019
  function matchesPrimarySelector(extraMethod, pom) {
3921
4020
  if (extraMethod.selector.kind !== "testId") {
3922
4021
  return false;
@@ -3985,6 +4084,56 @@ function buildPomManifest(componentHierarchyMap, elementMetadata) {
3985
4084
  }).filter((entry) => entry !== null);
3986
4085
  return Object.fromEntries(manifestEntries);
3987
4086
  }
4087
+ function normalizeTrackedComponentRef(value) {
4088
+ return value.endsWith(".vue") ? value.slice(0, -4) : value;
4089
+ }
4090
+ function resolveTrackedComponentRef(value, componentHierarchyMap) {
4091
+ const normalizedValue = normalizeTrackedComponentRef(value);
4092
+ if (componentHierarchyMap.has(value)) {
4093
+ return value;
4094
+ }
4095
+ if (componentHierarchyMap.has(normalizedValue)) {
4096
+ return normalizedValue;
4097
+ }
4098
+ let match = null;
4099
+ for (const [candidateName, candidateDeps] of componentHierarchyMap.entries()) {
4100
+ const normalizedCandidate = normalizeTrackedComponentRef(candidateName);
4101
+ const candidateBaseName = path.parse(candidateDeps.filePath).name;
4102
+ if (normalizedCandidate !== normalizedValue && candidateBaseName !== normalizedValue) {
4103
+ continue;
4104
+ }
4105
+ if (match && match !== candidateName) {
4106
+ return null;
4107
+ }
4108
+ match = candidateName;
4109
+ }
4110
+ return match;
4111
+ }
4112
+ function buildComponentGraph(componentHierarchyMap, routeMetaEntries, projectRoot) {
4113
+ const rootAbs = safeRealpath(path.resolve(projectRoot));
4114
+ const toProjectPath = (filePath) => toPosixSlashes(path.relative(rootAbs, safeRealpath(path.resolve(rootAbs, filePath))));
4115
+ const sortedUnique = (values) => Array.from(new Set(values)).sort((a, b) => a.localeCompare(b));
4116
+ const components = Array.from(componentHierarchyMap.entries(), ([name, dependencies]) => [toProjectPath(dependencies.filePath), {
4117
+ name,
4118
+ // Templates may use kebab-case tags; tags that are not project components (built-ins, libraries) drop out.
4119
+ uses: sortedUnique(Array.from(dependencies.usedComponentSet).flatMap((tag) => {
4120
+ const ref = resolveTrackedComponentRef(toPascalCase(tag), componentHierarchyMap);
4121
+ const used = ref ? componentHierarchyMap.get(ref) : void 0;
4122
+ return used ? [toProjectPath(used.filePath)] : [];
4123
+ }))
4124
+ }]).sort(([a], [b]) => a.localeCompare(b));
4125
+ const routes = routeMetaEntries.map((route) => {
4126
+ if (!route.componentFiles) {
4127
+ throw new Error(`[vue-pom-generator] Route "${route.path}" was introspected without its component files.`);
4128
+ }
4129
+ return { path: route.path, name: route.name, components: Array.from(new Set(route.componentFiles.map(toProjectPath))) };
4130
+ }).sort((a, b) => a.path.localeCompare(b.path) || (a.name ?? "").localeCompare(b.name ?? ""));
4131
+ return { version: 1, components: Object.fromEntries(components), routes };
4132
+ }
4133
+ function generateComponentGraphJson(componentHierarchyMap, routeMetaEntries, projectRoot) {
4134
+ return `${JSON.stringify(buildComponentGraph(componentHierarchyMap, routeMetaEntries, projectRoot), null, 2)}
4135
+ `;
4136
+ }
3988
4137
  function buildTestIdManifest(componentHierarchyMap) {
3989
4138
  return Object.fromEntries(
3990
4139
  Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([componentName, dependencies]) => {
@@ -4168,103 +4317,6 @@ function writeGeneratedOutputs(outDir, files, sharedFiles, projectRoot = path.di
4168
4317
  writeFile(manifestPath, `${JSON.stringify(next, null, 2)}
4169
4318
  `);
4170
4319
  }
4171
- function toPosixSlashes(value) {
4172
- let out = "";
4173
- for (let i = 0; i < value.length; i++) {
4174
- const ch = value[i];
4175
- out += ch === "\\" ? "/" : ch;
4176
- }
4177
- return out;
4178
- }
4179
- function safeRealpath(value) {
4180
- try {
4181
- if (fs.existsSync(value)) {
4182
- return fs.realpathSync(value);
4183
- }
4184
- } catch {
4185
- return value;
4186
- }
4187
- const parent = path.dirname(value);
4188
- if (!parent || parent === value) {
4189
- return value;
4190
- }
4191
- const resolvedParent = safeRealpath(parent);
4192
- return resolvedParent === parent ? value : path.join(resolvedParent, path.basename(value));
4193
- }
4194
- function normalizeScopePath(value, pathImpl = path) {
4195
- return pathImpl.normalize(value);
4196
- }
4197
- function isNormalizedPathWithinDir(filePathAbs, dirPathAbs, pathImpl = path) {
4198
- const normalizedFileAbs = normalizeScopePath(filePathAbs, pathImpl);
4199
- const normalizedDirAbs = normalizeScopePath(dirPathAbs, pathImpl);
4200
- return normalizedFileAbs === normalizedDirAbs || normalizedFileAbs.startsWith(`${normalizedDirAbs}${pathImpl.sep}`);
4201
- }
4202
- function isPathWithinDir(filePathAbs, dirPathAbs) {
4203
- const fileAbs = path.resolve(filePathAbs);
4204
- const dirAbs = path.resolve(dirPathAbs);
4205
- const rel = path.relative(dirAbs, fileAbs);
4206
- if (!rel)
4207
- return true;
4208
- return !rel.startsWith("..") && !path.isAbsolute(rel);
4209
- }
4210
- function resolveComponentNameFromPath(options) {
4211
- const { projectRoot, viewsDirAbs, sourceDirs, extraRoots = [] } = options;
4212
- const cleanFilename = options.filename.includes("?") ? options.filename.substring(0, options.filename.indexOf("?")) : options.filename;
4213
- const absFilename = path.isAbsolute(cleanFilename) ? cleanFilename : path.resolve(projectRoot, cleanFilename);
4214
- const normalizedAbsFilename = toPosixSlashes(path.normalize(safeRealpath(absFilename)));
4215
- const rootBases = [projectRoot, ...extraRoots.filter((r) => r !== projectRoot)];
4216
- const roots = [
4217
- viewsDirAbs,
4218
- ...sourceDirs.flatMap((dir) => path.isAbsolute(dir) ? [dir] : rootBases.map((base) => path.resolve(base, dir)))
4219
- ];
4220
- const potentialRoots = Array.from(new Set(roots.map((r) => toPosixSlashes(path.normalize(safeRealpath(r)))))).sort((a, b) => b.length - a.length);
4221
- for (const root of potentialRoots) {
4222
- if (normalizedAbsFilename.startsWith(`${root}/`) || normalizedAbsFilename === root) {
4223
- const rel = path.posix.relative(root, normalizedAbsFilename);
4224
- const parsed = path.posix.parse(rel);
4225
- const segments = path.posix.join(parsed.dir, parsed.name);
4226
- return toPascalCase(segments);
4227
- }
4228
- }
4229
- return toPascalCase(path.parse(normalizedAbsFilename).name);
4230
- }
4231
- function isFileInConfiguredSourceScope(options) {
4232
- const { filename, projectRoot, viewsDirAbs, sourceDirs, extraRoots = [], pathImpl = path } = options;
4233
- if (!filename) {
4234
- return false;
4235
- }
4236
- const cleanFilename = filename.includes("?") ? filename.substring(0, filename.indexOf("?")) : filename;
4237
- const normalizedProjectRoot = normalizeScopePath(projectRoot, pathImpl);
4238
- const normalizedAbsFilename = normalizeScopePath(
4239
- pathImpl.isAbsolute(cleanFilename) ? cleanFilename : pathImpl.resolve(normalizedProjectRoot, cleanFilename),
4240
- pathImpl
4241
- );
4242
- if (normalizedAbsFilename.includes(`${pathImpl.sep}node_modules${pathImpl.sep}`) || normalizedAbsFilename.includes("/node_modules/")) {
4243
- return false;
4244
- }
4245
- const normalizedViewsDirAbs = normalizeScopePath(viewsDirAbs, pathImpl);
4246
- if (isNormalizedPathWithinDir(normalizedAbsFilename, normalizedViewsDirAbs, pathImpl)) {
4247
- return true;
4248
- }
4249
- const rootsToTry = Array.from(/* @__PURE__ */ new Set([
4250
- normalizedProjectRoot,
4251
- ...extraRoots.map((root) => normalizeScopePath(root, pathImpl))
4252
- ]));
4253
- return sourceDirs.some((dir) => {
4254
- return rootsToTry.some((root) => {
4255
- const normalizedAbsDir = normalizeScopePath(pathImpl.resolve(root, dir), pathImpl);
4256
- if (isNormalizedPathWithinDir(normalizedAbsFilename, normalizedAbsDir, pathImpl)) {
4257
- return true;
4258
- }
4259
- if (dir.startsWith("app/") && pathImpl.basename(root) === "app") {
4260
- const relativeDir = dir.substring(4);
4261
- const normalizedAbsDirAlt = normalizeScopePath(pathImpl.resolve(root, relativeDir), pathImpl);
4262
- return isNormalizedPathWithinDir(normalizedAbsFilename, normalizedAbsDirAlt, pathImpl);
4263
- }
4264
- return false;
4265
- });
4266
- });
4267
- }
4268
4320
  let routerIntrospectionQueue = Promise.resolve();
4269
4321
  async function runRouterIntrospectionExclusive(fn) {
4270
4322
  const prev = routerIntrospectionQueue.catch(() => void 0);
@@ -4634,8 +4686,8 @@ function getComponentInfoFromVueComponent(comp, options = {}) {
4634
4686
  filePath
4635
4687
  };
4636
4688
  }
4637
- async function getComponentInfoFromRouteRecord(record, options = {}) {
4638
- const comp = record.components?.default;
4689
+ async function getComponentInfoFromRouteComponent(routeComponent, options = {}) {
4690
+ const comp = routeComponent;
4639
4691
  if (!comp) {
4640
4692
  return {
4641
4693
  componentName: null,
@@ -4661,6 +4713,39 @@ async function getComponentInfoFromRouteRecord(record, options = {}) {
4661
4713
  }
4662
4714
  return getComponentInfoFromVueComponent(comp, options);
4663
4715
  }
4716
+ function isRouteParamNameCode(code) {
4717
+ return code === 95 || isAsciiLetterCode$1(code) || isAsciiDigitCode$1(code);
4718
+ }
4719
+ function getPathParamNames(routePath) {
4720
+ const names = [];
4721
+ for (let start = routePath.indexOf(":"); start !== -1; start = routePath.indexOf(":", start + 1)) {
4722
+ let end = start + 1;
4723
+ while (end < routePath.length && isRouteParamNameCode(routePath.charCodeAt(end)))
4724
+ end++;
4725
+ if (end > start + 1)
4726
+ names.push(routePath.slice(start + 1, end));
4727
+ }
4728
+ return names;
4729
+ }
4730
+ function getRenderedRouteRecords(router2, record) {
4731
+ const matched = record.name === void 0 ? router2.resolve(record.path).matched : router2.resolve({ name: record.name, params: Object.fromEntries(getPathParamNames(record.path).map((name) => [name, name])) }).matched;
4732
+ const index = matched.findIndex((candidate) => candidate === record || candidate === record.aliasOf);
4733
+ if (index === -1) {
4734
+ throw new Error(`[vue-pom-generator] Cannot resolve the parent routes of unnamed route "${record.path}". Give it a name so the components it renders can be listed.`);
4735
+ }
4736
+ return matched.slice(0, index + 1);
4737
+ }
4738
+ async function getRenderedComponentFiles(router2, record, rootDir) {
4739
+ const files = [];
4740
+ for (const rendered of getRenderedRouteRecords(router2, record)) {
4741
+ for (const routeComponent of Object.values(rendered.components ?? {})) {
4742
+ const { filePath } = await getComponentInfoFromRouteComponent(routeComponent, { rootDir });
4743
+ if (filePath && !files.includes(filePath))
4744
+ files.push(filePath);
4745
+ }
4746
+ }
4747
+ return files;
4748
+ }
4664
4749
  function resolveIntrospectedComponentName(componentInfo, componentNaming) {
4665
4750
  if (componentInfo.filePath && componentNaming) {
4666
4751
  return resolveComponentNameFromPath({
@@ -5091,9 +5176,11 @@ async function introspectNuxtPages(projectRoot, options = {}) {
5091
5176
  // Nuxt file-based routes are named by convention, but the static walk does not
5092
5177
  // recover those names — leave null so callers fall back to path-template navigation.
5093
5178
  name: null,
5179
+ path: pathTemplate,
5094
5180
  pathTemplate,
5095
5181
  params,
5096
- query: []
5182
+ query: [],
5183
+ ...options.collectComponentFiles ? { componentFiles: [fullPath] } : {}
5097
5184
  });
5098
5185
  }
5099
5186
  };
@@ -5167,7 +5254,7 @@ async function parseRouterFileFromCwd(routerEntryPath, options = {}) {
5167
5254
  const routePathMap = /* @__PURE__ */ new Map();
5168
5255
  const routeMetaEntries = [];
5169
5256
  for (const r of router2.getRoutes()) {
5170
- const componentInfo = await getComponentInfoFromRouteRecord(r, { rootDir: cwd });
5257
+ const componentInfo = await getComponentInfoFromRouteComponent(r.components?.default, { rootDir: cwd });
5171
5258
  const componentName = resolveIntrospectedComponentName(componentInfo, options.componentNaming);
5172
5259
  if (!componentName)
5173
5260
  continue;
@@ -5185,9 +5272,11 @@ async function parseRouterFileFromCwd(routerEntryPath, options = {}) {
5185
5272
  routeMetaEntries.push({
5186
5273
  componentName,
5187
5274
  name: typeof r.name === "string" && r.name.length ? r.name : null,
5275
+ path: r.path,
5188
5276
  pathTemplate,
5189
5277
  params: paramsMeta,
5190
- query: queryKeys
5278
+ query: queryKeys,
5279
+ ...options.collectComponentFiles ? { componentFiles: await getRenderedComponentFiles(router2, r, cwd) } : {}
5191
5280
  });
5192
5281
  }
5193
5282
  }
@@ -5585,7 +5674,7 @@ function resolveVueSourcePath(targetClassName, vueFilesPathMap, projectRoot) {
5585
5674
  ].filter((candidate) => typeof candidate === "string" && candidate.length > 0);
5586
5675
  return candidates.find((candidate) => fs.existsSync(candidate));
5587
5676
  }
5588
- async function getRouteMetaByComponent(projectRoot, routerEntry, routerType, options = {}) {
5677
+ async function introspectRouteMetaEntries(projectRoot, routerEntry, routerType, options = {}) {
5589
5678
  const root = projectRoot ?? process.cwd();
5590
5679
  const pageDirs = options.pageDirs?.length ? options.pageDirs : ["src/views"];
5591
5680
  const pageDirsAbs = pageDirs.map((dir) => path.isAbsolute(dir) ? dir : path.resolve(root, dir));
@@ -5596,14 +5685,18 @@ async function getRouteMetaByComponent(projectRoot, routerEntry, routerType, opt
5596
5685
  ...options.layoutDirs?.length ? options.layoutDirs : ["src/layouts"]
5597
5686
  ];
5598
5687
  const extraRoots = process.cwd() !== root ? [process.cwd()] : [];
5599
- const { routeMetaEntries } = routerType === "nuxt" ? await introspectNuxtPages(root, { pageDirs: pageDirsAbs }) : await parseRouterFileFromCwd(resolveRouterEntry(root, routerEntry), {
5688
+ const { routeMetaEntries } = routerType === "nuxt" ? await introspectNuxtPages(root, { pageDirs: pageDirsAbs, collectComponentFiles: options.collectComponentFiles }) : await parseRouterFileFromCwd(resolveRouterEntry(root, routerEntry), {
5600
5689
  componentNaming: {
5601
5690
  projectRoot: root,
5602
5691
  viewsDirAbs: primaryPageDirAbs,
5603
5692
  sourceDirs,
5604
5693
  extraRoots
5605
- }
5694
+ },
5695
+ collectComponentFiles: options.collectComponentFiles
5606
5696
  });
5697
+ return routeMetaEntries;
5698
+ }
5699
+ function buildRouteMetaByComponent(routeMetaEntries) {
5607
5700
  const map = /* @__PURE__ */ new Map();
5608
5701
  for (const entry of routeMetaEntries) {
5609
5702
  const list = map.get(entry.componentName) ?? [];
@@ -5944,6 +6037,8 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
5944
6037
  requireCustomPomDir,
5945
6038
  customPomImportAliases,
5946
6039
  customPomImportNameCollisionBehavior = "error",
6040
+ customPomFixtures = [],
6041
+ componentGraph = false,
5947
6042
  testIdAttribute,
5948
6043
  emitLanguages: emitLanguagesOverride,
5949
6044
  typescriptOutputStructure = "aggregated",
@@ -5965,11 +6060,13 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
5965
6060
  if (vueTestUtilsOutDir && path.resolve(vueTestUtilsOutDir) === path.resolve(outDir)) {
5966
6061
  throw new Error("[vue-pom-generator] generation.vueTestUtils.outDir must differ from generation.outDir.");
5967
6062
  }
5968
- const routeMetaByComponent = routeMetaByComponentOverride ?? (vueRouterFluentChaining ? await getRouteMetaByComponent(projectRoot, routerEntry, routerType, {
6063
+ const routeMetaEntries = vueRouterFluentChaining && (!routeMetaByComponentOverride || componentGraph) ? await introspectRouteMetaEntries(projectRoot, routerEntry, routerType, {
5969
6064
  pageDirs,
5970
6065
  componentDirs,
5971
- layoutDirs
5972
- }) : void 0);
6066
+ layoutDirs,
6067
+ collectComponentFiles: componentGraph
6068
+ }) : [];
6069
+ const routeMetaByComponent = routeMetaByComponentOverride ?? (vueRouterFluentChaining ? buildRouteMetaByComponent(routeMetaEntries) : void 0);
5973
6070
  const emittableComponentHierarchyMap = componentHierarchyMap;
5974
6071
  const generatedFiles = [];
5975
6072
  if (emitLanguages.includes("ts")) {
@@ -6003,6 +6100,8 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
6003
6100
  pomOutDir: outDir,
6004
6101
  projectRoot,
6005
6102
  customPomDir,
6103
+ customPomFixtures,
6104
+ componentGraphRoutes: componentGraph ? routeMetaEntries : void 0,
6006
6105
  elementMetadata,
6007
6106
  testIdAttribute
6008
6107
  });
@@ -6715,9 +6814,20 @@ function generateAggregatedCSharpFiles(componentHierarchyMap, outDir, options =
6715
6814
  return [{ filePath: outputFile, content: chunks.join("\n") }];
6716
6815
  }
6717
6816
  function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
6718
- const { generateFixtures, pomOutDir } = options;
6719
- if (!generateFixtures)
6817
+ const { generateFixtures, pomOutDir, customPomFixtures, componentGraphRoutes } = options;
6818
+ if (!generateFixtures) {
6819
+ if (customPomFixtures.length > 0) {
6820
+ throw new VuePomGeneratorError(
6821
+ "generation.playwright.customPoms.fixtures requires generation.playwright.fixtures to be enabled."
6822
+ );
6823
+ }
6824
+ if (componentGraphRoutes) {
6825
+ throw new VuePomGeneratorError(
6826
+ "generation.playwright.componentGraph requires generation.playwright.fixtures to be enabled."
6827
+ );
6828
+ }
6720
6829
  return [];
6830
+ }
6721
6831
  const defaultFixtureOutDirRel = pomOutDir;
6722
6832
  const fixtureOutRel = typeof generateFixtures === "string" ? generateFixtures : typeof generateFixtures === "object" && generateFixtures?.outDir ? generateFixtures.outDir : defaultFixtureOutDirRel;
6723
6833
  const looksLikeFilePath = fixtureOutRel.endsWith(".ts") || fixtureOutRel.endsWith(".tsx") || fixtureOutRel.endsWith(".mts") || fixtureOutRel.endsWith(".cts");
@@ -6776,6 +6886,42 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
6776
6886
  fixtureName: lowerFirst(name),
6777
6887
  ctorExpression: fixtureCtorExpression(name)
6778
6888
  }));
6889
+ const takenFixtureNames = new Map([
6890
+ ...[...reservedPlaywrightFixtureNames, "pomSetup", "pomFactory", "pomDiagnosticsSetup"].map((name) => [name, "a built-in Playwright or vue-pom-generator fixture"]),
6891
+ ...fixtureClassNames.map((name) => [lowerFirst(name), `the generated fixture for "${name}"`])
6892
+ ]);
6893
+ const customCtorEntries = customPomFixtures.map((className, index) => {
6894
+ if (customPomFixtures.indexOf(className) !== index) {
6895
+ throw new VuePomGeneratorError(
6896
+ `Custom POM fixture class "${className}" is listed more than once in generation.playwright.customPoms.fixtures.
6897
+ Remove the duplicate entry.`
6898
+ );
6899
+ }
6900
+ const filePath = path.join(customPomDirAbs, `${className}.ts`);
6901
+ if (!fs.existsSync(filePath)) {
6902
+ throw new VuePomGeneratorError(
6903
+ `Custom POM fixture class "${className}" was not found.
6904
+ Expected file: ${filePath}
6905
+ Add the file or remove "${className}" from generation.playwright.customPoms.fixtures.`
6906
+ );
6907
+ }
6908
+ const fixtureName = lowerFirst(className);
6909
+ const existingOwner = takenFixtureNames.get(fixtureName);
6910
+ if (existingOwner) {
6911
+ throw new VuePomGeneratorError(
6912
+ `Custom POM fixture "${fixtureName}" (from "${className}") collides with ${existingOwner}.
6913
+ Rename the class or remove it from generation.playwright.customPoms.fixtures.`
6914
+ );
6915
+ }
6916
+ takenFixtureNames.set(fixtureName, `the custom POM fixture for "${className}"`);
6917
+ return {
6918
+ className,
6919
+ fixtureName,
6920
+ ctorExpression: `${className}Custom`,
6921
+ importSpecifier: stripExtension(toPosixRelativePath(fixtureOutDirAbs, filePath))
6922
+ };
6923
+ });
6924
+ const hasCustomFixtures = customCtorEntries.length > 0;
6779
6925
  const fixturesContent = renderSourceFile(fixtureFileName, (sourceFile) => {
6780
6926
  sourceFile.addStatements("/** Generated Playwright fixtures (typed page objects). */");
6781
6927
  addNamedImport(sourceFile, {
@@ -6815,6 +6961,12 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
6815
6961
  namedImports: [{ name: entry.className, alias: entry.localIdentifier }]
6816
6962
  });
6817
6963
  }
6964
+ for (const entry of customCtorEntries) {
6965
+ addNamedImport(sourceFile, {
6966
+ moduleSpecifier: entry.importSpecifier,
6967
+ namedImports: [{ name: entry.className, alias: entry.ctorExpression }]
6968
+ });
6969
+ }
6818
6970
  sourceFile.addInterface({
6819
6971
  isExported: true,
6820
6972
  name: "PlaywrightOptions",
@@ -6854,36 +7006,27 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
6854
7006
  name: "PomDiagnosticsSetupFixture",
6855
7007
  type: "{ pomDiagnosticsSetup: void }"
6856
7008
  });
6857
- sourceFile.addVariableStatement({
6858
- declarationKind: tsMorph.VariableDeclarationKind.Const,
6859
- declarations: [{
6860
- name: "pageCtors",
6861
- initializer: (writer) => {
6862
- writer.write("{").newLine();
6863
- writer.indent(() => {
6864
- for (const entry of pageCtorEntries) {
6865
- writer.writeLine(`${entry.fixtureName}: ${entry.ctorExpression},`);
6866
- }
6867
- });
6868
- writer.write("} as const");
6869
- }
6870
- }]
6871
- });
6872
- sourceFile.addVariableStatement({
6873
- declarationKind: tsMorph.VariableDeclarationKind.Const,
6874
- declarations: [{
6875
- name: "componentCtors",
6876
- initializer: (writer) => {
6877
- writer.write("{").newLine();
6878
- writer.indent(() => {
6879
- for (const entry of componentCtorEntries) {
6880
- writer.writeLine(`${entry.fixtureName}: ${entry.ctorExpression},`);
6881
- }
6882
- });
6883
- writer.write("} as const");
6884
- }
6885
- }]
6886
- });
7009
+ const addCtorMap = (name, entries) => {
7010
+ sourceFile.addVariableStatement({
7011
+ declarationKind: tsMorph.VariableDeclarationKind.Const,
7012
+ declarations: [{
7013
+ name,
7014
+ initializer: (writer) => {
7015
+ writer.write("{").newLine();
7016
+ writer.indent(() => {
7017
+ for (const entry of entries) {
7018
+ writer.writeLine(`${entry.fixtureName}: ${entry.ctorExpression},`);
7019
+ }
7020
+ });
7021
+ writer.write("} as const");
7022
+ }
7023
+ }]
7024
+ });
7025
+ };
7026
+ addCtorMap("pageCtors", pageCtorEntries);
7027
+ addCtorMap("componentCtors", componentCtorEntries);
7028
+ if (hasCustomFixtures)
7029
+ addCtorMap("customCtors", customCtorEntries);
6887
7030
  sourceFile.addTypeAlias({
6888
7031
  isExported: true,
6889
7032
  name: "GeneratedPageFixtures",
@@ -6894,13 +7037,20 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
6894
7037
  name: "GeneratedComponentFixtures",
6895
7038
  type: "{ [K in keyof typeof componentCtors]: InstanceType<(typeof componentCtors)[K]> }"
6896
7039
  });
7040
+ if (hasCustomFixtures) {
7041
+ sourceFile.addTypeAlias({
7042
+ isExported: true,
7043
+ name: "CustomPomFixtures",
7044
+ type: "{ [K in keyof typeof customCtors]: InstanceType<(typeof customCtors)[K]> }"
7045
+ });
7046
+ }
6897
7047
  sourceFile.addTypeAlias({
6898
7048
  isExported: true,
6899
7049
  name: "PomFixtures",
6900
7050
  docs: [{
6901
- description: "Every fixture contributed by the generator: the `animation` option, the internal\n`pomSetup`/`pomFactory` fixtures, and one fixture per generated page/component POM."
7051
+ description: "Every fixture contributed by the generator: the `animation` option, the internal\n`pomSetup`/`pomFactory` fixtures, and one fixture per generated page/component POM" + (hasCustomFixtures ? "\nand per configured custom POM." : ".")
6902
7052
  }],
6903
- type: "PlaywrightOptions & PomSetupFixture & PomFactoryFixture & PomDiagnosticsSetupFixture & GeneratedPageFixtures & GeneratedComponentFixtures"
7053
+ type: "PlaywrightOptions & PomSetupFixture & PomFactoryFixture & PomDiagnosticsSetupFixture & GeneratedPageFixtures & GeneratedComponentFixtures" + (hasCustomFixtures ? " & CustomPomFixtures" : "")
6904
7054
  });
6905
7055
  sourceFile.addFunction({
6906
7056
  name: "makePomFixture",
@@ -6989,6 +7139,8 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
6989
7139
  writer.writeLine("},");
6990
7140
  writer.writeLine("...createPomFixtures(pageCtors),");
6991
7141
  writer.writeLine("...createPomFixtures(componentCtors),");
7142
+ if (hasCustomFixtures)
7143
+ writer.writeLine("...createPomFixtures(customCtors),");
6992
7144
  });
6993
7145
  writer.write(") as TestType<TTestArgs & PomFixtures, TWorkerArgs>;");
6994
7146
  }
@@ -7031,6 +7183,10 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
7031
7183
  filePath: path.resolve(fixtureOutDirAbs, manifestFileName),
7032
7184
  content: manifestContent
7033
7185
  },
7186
+ ...componentGraphRoutes ? [{
7187
+ filePath: path.resolve(fixtureOutDirAbs, "component-graph.json"),
7188
+ content: generateComponentGraphJson(componentHierarchyMap, componentGraphRoutes, root)
7189
+ }] : [],
7034
7190
  diagnosticsRuntimeFile
7035
7191
  ];
7036
7192
  }
@@ -7040,33 +7196,8 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
7040
7196
  customPomAttachments = [],
7041
7197
  testIdAttribute
7042
7198
  } = options;
7043
- const normalizeTrackedComponentRef = (value) => {
7044
- return value.endsWith(".vue") ? value.slice(0, -4) : value;
7045
- };
7046
- const resolveTrackedComponentRef = (value) => {
7047
- const normalizedValue = normalizeTrackedComponentRef(value);
7048
- if (componentHierarchyMap.has(value)) {
7049
- return value;
7050
- }
7051
- if (componentHierarchyMap.has(normalizedValue)) {
7052
- return normalizedValue;
7053
- }
7054
- let match = null;
7055
- for (const [candidateName, candidateDeps] of componentHierarchyMap.entries()) {
7056
- const normalizedCandidate = normalizeTrackedComponentRef(candidateName);
7057
- const candidateBaseName = path.parse(candidateDeps.filePath).name;
7058
- if (normalizedCandidate !== normalizedValue && candidateBaseName !== normalizedValue) {
7059
- continue;
7060
- }
7061
- if (match && match !== candidateName) {
7062
- return null;
7063
- }
7064
- match = candidateName;
7065
- }
7066
- return match;
7067
- };
7068
7199
  const hasGeneratedPomSurface = (value, seen = /* @__PURE__ */ new Set()) => {
7069
- const resolvedRef = resolveTrackedComponentRef(value);
7200
+ const resolvedRef = resolveTrackedComponentRef(value, componentHierarchyMap);
7070
7201
  if (!resolvedRef || seen.has(resolvedRef)) {
7071
7202
  return false;
7072
7203
  }
@@ -7087,7 +7218,7 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
7087
7218
  return toPascalCaseLocal(normalizeTrackedComponentRef(ref)) === ownClassName && ownClassName.length > 0;
7088
7219
  };
7089
7220
  const resolveComponentInstance = (spec) => {
7090
- const componentRef = resolveTrackedComponentRef(spec.componentName);
7221
+ const componentRef = resolveTrackedComponentRef(spec.componentName, componentHierarchyMap);
7091
7222
  if (!componentRef || isSelfReference(componentRef) || !hasGeneratedPomSurface(componentRef, /* @__PURE__ */ new Set([componentName]))) {
7092
7223
  return null;
7093
7224
  }
@@ -7196,7 +7327,7 @@ Move the repetition to the receiving component boundary so the generator can exp
7196
7327
  const hasChildComponent = (needle) => {
7197
7328
  const normalizedNeedle = normalizeTrackedComponentRef(needle);
7198
7329
  for (const child of rawComponentRefsForInstances) {
7199
- const resolvedChild = resolveTrackedComponentRef(child);
7330
+ const resolvedChild = resolveTrackedComponentRef(child, componentHierarchyMap);
7200
7331
  if (normalizeTrackedComponentRef(child) === normalizedNeedle)
7201
7332
  return true;
7202
7333
  if (resolvedChild && normalizeTrackedComponentRef(resolvedChild) === normalizedNeedle)
@@ -8184,6 +8315,8 @@ function createBuildProcessorPlugin(options) {
8184
8315
  requireCustomPomDir,
8185
8316
  customPomImportAliases,
8186
8317
  customPomImportNameCollisionBehavior,
8318
+ customPomFixtures,
8319
+ componentGraph,
8187
8320
  testIdAttribute,
8188
8321
  routerAwarePoms,
8189
8322
  routerType,
@@ -8334,6 +8467,8 @@ function createBuildProcessorPlugin(options) {
8334
8467
  requireCustomPomDir,
8335
8468
  customPomImportAliases,
8336
8469
  customPomImportNameCollisionBehavior,
8470
+ customPomFixtures,
8471
+ componentGraph,
8337
8472
  testIdAttribute,
8338
8473
  vueRouterFluentChaining: routerAwarePoms,
8339
8474
  routerEntry: getResolvedRouterEntry(),
@@ -10714,6 +10849,8 @@ function createDevProcessorPlugin(options) {
10714
10849
  requireCustomPomDir,
10715
10850
  customPomImportAliases,
10716
10851
  customPomImportNameCollisionBehavior,
10852
+ customPomFixtures,
10853
+ componentGraph,
10717
10854
  nameCollisionBehavior,
10718
10855
  missingSemanticNameBehavior,
10719
10856
  existingIdBehavior,
@@ -10976,6 +11113,8 @@ function createDevProcessorPlugin(options) {
10976
11113
  requireCustomPomDir,
10977
11114
  customPomImportAliases,
10978
11115
  customPomImportNameCollisionBehavior,
11116
+ customPomFixtures,
11117
+ componentGraph,
10979
11118
  pageDirs: getPageDirs(),
10980
11119
  componentDirs: getComponentDirs(),
10981
11120
  layoutDirs: getLayoutDirs(),
@@ -11611,7 +11750,8 @@ function createGeneratorPlugins(options, generationOnly, projectRoot = process.c
11611
11750
  const customPoms = generationOptions?.playwright?.customPoms;
11612
11751
  const resolvedCustomPomAttachments = customPoms?.attachments ?? [];
11613
11752
  const resolvedCustomPomImportAliases = customPoms?.importAliases;
11614
- const requireCustomPomDir = customPoms?.dir !== void 0 || resolvedCustomPomAttachments.length > 0 || Object.keys(resolvedCustomPomImportAliases ?? {}).length > 0;
11753
+ const resolvedCustomPomFixtures = customPoms?.fixtures ?? [];
11754
+ const requireCustomPomDir = customPoms?.dir !== void 0 || resolvedCustomPomAttachments.length > 0 || resolvedCustomPomFixtures.length > 0 || Object.keys(resolvedCustomPomImportAliases ?? {}).length > 0;
11615
11755
  const resolvedGenerationOptions = resolveGenerationSupportOptions({
11616
11756
  outDir: generationOptions?.outDir,
11617
11757
  emitLanguages: generationOptions?.emit,
@@ -11624,6 +11764,8 @@ function createGeneratorPlugins(options, generationOnly, projectRoot = process.c
11624
11764
  requireCustomPomDir,
11625
11765
  customPomImportAliases: resolvedCustomPomImportAliases,
11626
11766
  customPomImportNameCollisionBehavior: customPoms?.importNameCollisionBehavior,
11767
+ customPomFixtures: resolvedCustomPomFixtures,
11768
+ componentGraph: generationOptions?.playwright?.componentGraph,
11627
11769
  nameCollisionBehavior: generationOptions?.nameCollisionBehavior,
11628
11770
  missingSemanticNameBehavior: generationOptions?.missingSemanticNameBehavior,
11629
11771
  existingIdBehavior: resolvedInjectionOptions.existingIdBehavior,