@immense/vue-pom-generator 1.0.119 → 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/README.md +68 -0
- package/RELEASE_NOTES.md +28 -36
- package/class-generation/index.ts +41 -43
- package/dist/class-generation/index.d.ts +2 -0
- package/dist/class-generation/index.d.ts.map +1 -1
- package/dist/index.cjs +222 -137
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +222 -137
- package/dist/index.mjs.map +1 -1
- package/dist/manifest-generator.d.ts +18 -0
- package/dist/manifest-generator.d.ts.map +1 -1
- package/dist/plugin/create-vue-pom-generator-plugins.d.ts.map +1 -1
- package/dist/plugin/internal/build-plugin.d.ts.map +1 -1
- package/dist/plugin/internal/dev-plugin.d.ts.map +1 -1
- package/dist/plugin/path-utils.d.ts +1 -0
- package/dist/plugin/path-utils.d.ts.map +1 -1
- package/dist/plugin/resolved-generation-options.d.ts +1 -0
- package/dist/plugin/resolved-generation-options.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +6 -0
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/router-introspection.d.ts +10 -1
- package/dist/router-introspection.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -263,6 +263,7 @@ function resolveGenerationSupportOptions(options) {
|
|
|
263
263
|
customPomImportAliases: options.customPomImportAliases,
|
|
264
264
|
customPomImportNameCollisionBehavior: options.customPomImportNameCollisionBehavior ?? "error",
|
|
265
265
|
customPomFixtures: options.customPomFixtures ?? [],
|
|
266
|
+
componentGraph: options.componentGraph ?? false,
|
|
266
267
|
nameCollisionBehavior: options.nameCollisionBehavior ?? "error",
|
|
267
268
|
missingSemanticNameBehavior: options.missingSemanticNameBehavior ?? "error",
|
|
268
269
|
existingIdBehavior: options.existingIdBehavior ?? "error",
|
|
@@ -3918,6 +3919,103 @@ function buildPomGeneratedPropertyName(pom) {
|
|
|
3918
3919
|
function buildPomGeneratedActionName(pom) {
|
|
3919
3920
|
return requireStructuredPomName(pom.generatedActionName, "generatedActionName", pom);
|
|
3920
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
|
+
}
|
|
3921
4019
|
function matchesPrimarySelector(extraMethod, pom) {
|
|
3922
4020
|
if (extraMethod.selector.kind !== "testId") {
|
|
3923
4021
|
return false;
|
|
@@ -3986,6 +4084,56 @@ function buildPomManifest(componentHierarchyMap, elementMetadata) {
|
|
|
3986
4084
|
}).filter((entry) => entry !== null);
|
|
3987
4085
|
return Object.fromEntries(manifestEntries);
|
|
3988
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
|
+
}
|
|
3989
4137
|
function buildTestIdManifest(componentHierarchyMap) {
|
|
3990
4138
|
return Object.fromEntries(
|
|
3991
4139
|
Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([componentName, dependencies]) => {
|
|
@@ -4169,103 +4317,6 @@ function writeGeneratedOutputs(outDir, files, sharedFiles, projectRoot = path.di
|
|
|
4169
4317
|
writeFile(manifestPath, `${JSON.stringify(next, null, 2)}
|
|
4170
4318
|
`);
|
|
4171
4319
|
}
|
|
4172
|
-
function toPosixSlashes(value) {
|
|
4173
|
-
let out = "";
|
|
4174
|
-
for (let i = 0; i < value.length; i++) {
|
|
4175
|
-
const ch = value[i];
|
|
4176
|
-
out += ch === "\\" ? "/" : ch;
|
|
4177
|
-
}
|
|
4178
|
-
return out;
|
|
4179
|
-
}
|
|
4180
|
-
function safeRealpath(value) {
|
|
4181
|
-
try {
|
|
4182
|
-
if (fs.existsSync(value)) {
|
|
4183
|
-
return fs.realpathSync(value);
|
|
4184
|
-
}
|
|
4185
|
-
} catch {
|
|
4186
|
-
return value;
|
|
4187
|
-
}
|
|
4188
|
-
const parent = path.dirname(value);
|
|
4189
|
-
if (!parent || parent === value) {
|
|
4190
|
-
return value;
|
|
4191
|
-
}
|
|
4192
|
-
const resolvedParent = safeRealpath(parent);
|
|
4193
|
-
return resolvedParent === parent ? value : path.join(resolvedParent, path.basename(value));
|
|
4194
|
-
}
|
|
4195
|
-
function normalizeScopePath(value, pathImpl = path) {
|
|
4196
|
-
return pathImpl.normalize(value);
|
|
4197
|
-
}
|
|
4198
|
-
function isNormalizedPathWithinDir(filePathAbs, dirPathAbs, pathImpl = path) {
|
|
4199
|
-
const normalizedFileAbs = normalizeScopePath(filePathAbs, pathImpl);
|
|
4200
|
-
const normalizedDirAbs = normalizeScopePath(dirPathAbs, pathImpl);
|
|
4201
|
-
return normalizedFileAbs === normalizedDirAbs || normalizedFileAbs.startsWith(`${normalizedDirAbs}${pathImpl.sep}`);
|
|
4202
|
-
}
|
|
4203
|
-
function isPathWithinDir(filePathAbs, dirPathAbs) {
|
|
4204
|
-
const fileAbs = path.resolve(filePathAbs);
|
|
4205
|
-
const dirAbs = path.resolve(dirPathAbs);
|
|
4206
|
-
const rel = path.relative(dirAbs, fileAbs);
|
|
4207
|
-
if (!rel)
|
|
4208
|
-
return true;
|
|
4209
|
-
return !rel.startsWith("..") && !path.isAbsolute(rel);
|
|
4210
|
-
}
|
|
4211
|
-
function resolveComponentNameFromPath(options) {
|
|
4212
|
-
const { projectRoot, viewsDirAbs, sourceDirs, extraRoots = [] } = options;
|
|
4213
|
-
const cleanFilename = options.filename.includes("?") ? options.filename.substring(0, options.filename.indexOf("?")) : options.filename;
|
|
4214
|
-
const absFilename = path.isAbsolute(cleanFilename) ? cleanFilename : path.resolve(projectRoot, cleanFilename);
|
|
4215
|
-
const normalizedAbsFilename = toPosixSlashes(path.normalize(safeRealpath(absFilename)));
|
|
4216
|
-
const rootBases = [projectRoot, ...extraRoots.filter((r) => r !== projectRoot)];
|
|
4217
|
-
const roots = [
|
|
4218
|
-
viewsDirAbs,
|
|
4219
|
-
...sourceDirs.flatMap((dir) => path.isAbsolute(dir) ? [dir] : rootBases.map((base) => path.resolve(base, dir)))
|
|
4220
|
-
];
|
|
4221
|
-
const potentialRoots = Array.from(new Set(roots.map((r) => toPosixSlashes(path.normalize(safeRealpath(r)))))).sort((a, b) => b.length - a.length);
|
|
4222
|
-
for (const root of potentialRoots) {
|
|
4223
|
-
if (normalizedAbsFilename.startsWith(`${root}/`) || normalizedAbsFilename === root) {
|
|
4224
|
-
const rel = path.posix.relative(root, normalizedAbsFilename);
|
|
4225
|
-
const parsed = path.posix.parse(rel);
|
|
4226
|
-
const segments = path.posix.join(parsed.dir, parsed.name);
|
|
4227
|
-
return toPascalCase(segments);
|
|
4228
|
-
}
|
|
4229
|
-
}
|
|
4230
|
-
return toPascalCase(path.parse(normalizedAbsFilename).name);
|
|
4231
|
-
}
|
|
4232
|
-
function isFileInConfiguredSourceScope(options) {
|
|
4233
|
-
const { filename, projectRoot, viewsDirAbs, sourceDirs, extraRoots = [], pathImpl = path } = options;
|
|
4234
|
-
if (!filename) {
|
|
4235
|
-
return false;
|
|
4236
|
-
}
|
|
4237
|
-
const cleanFilename = filename.includes("?") ? filename.substring(0, filename.indexOf("?")) : filename;
|
|
4238
|
-
const normalizedProjectRoot = normalizeScopePath(projectRoot, pathImpl);
|
|
4239
|
-
const normalizedAbsFilename = normalizeScopePath(
|
|
4240
|
-
pathImpl.isAbsolute(cleanFilename) ? cleanFilename : pathImpl.resolve(normalizedProjectRoot, cleanFilename),
|
|
4241
|
-
pathImpl
|
|
4242
|
-
);
|
|
4243
|
-
if (normalizedAbsFilename.includes(`${pathImpl.sep}node_modules${pathImpl.sep}`) || normalizedAbsFilename.includes("/node_modules/")) {
|
|
4244
|
-
return false;
|
|
4245
|
-
}
|
|
4246
|
-
const normalizedViewsDirAbs = normalizeScopePath(viewsDirAbs, pathImpl);
|
|
4247
|
-
if (isNormalizedPathWithinDir(normalizedAbsFilename, normalizedViewsDirAbs, pathImpl)) {
|
|
4248
|
-
return true;
|
|
4249
|
-
}
|
|
4250
|
-
const rootsToTry = Array.from(/* @__PURE__ */ new Set([
|
|
4251
|
-
normalizedProjectRoot,
|
|
4252
|
-
...extraRoots.map((root) => normalizeScopePath(root, pathImpl))
|
|
4253
|
-
]));
|
|
4254
|
-
return sourceDirs.some((dir) => {
|
|
4255
|
-
return rootsToTry.some((root) => {
|
|
4256
|
-
const normalizedAbsDir = normalizeScopePath(pathImpl.resolve(root, dir), pathImpl);
|
|
4257
|
-
if (isNormalizedPathWithinDir(normalizedAbsFilename, normalizedAbsDir, pathImpl)) {
|
|
4258
|
-
return true;
|
|
4259
|
-
}
|
|
4260
|
-
if (dir.startsWith("app/") && pathImpl.basename(root) === "app") {
|
|
4261
|
-
const relativeDir = dir.substring(4);
|
|
4262
|
-
const normalizedAbsDirAlt = normalizeScopePath(pathImpl.resolve(root, relativeDir), pathImpl);
|
|
4263
|
-
return isNormalizedPathWithinDir(normalizedAbsFilename, normalizedAbsDirAlt, pathImpl);
|
|
4264
|
-
}
|
|
4265
|
-
return false;
|
|
4266
|
-
});
|
|
4267
|
-
});
|
|
4268
|
-
}
|
|
4269
4320
|
let routerIntrospectionQueue = Promise.resolve();
|
|
4270
4321
|
async function runRouterIntrospectionExclusive(fn) {
|
|
4271
4322
|
const prev = routerIntrospectionQueue.catch(() => void 0);
|
|
@@ -4635,8 +4686,8 @@ function getComponentInfoFromVueComponent(comp, options = {}) {
|
|
|
4635
4686
|
filePath
|
|
4636
4687
|
};
|
|
4637
4688
|
}
|
|
4638
|
-
async function
|
|
4639
|
-
const comp =
|
|
4689
|
+
async function getComponentInfoFromRouteComponent(routeComponent, options = {}) {
|
|
4690
|
+
const comp = routeComponent;
|
|
4640
4691
|
if (!comp) {
|
|
4641
4692
|
return {
|
|
4642
4693
|
componentName: null,
|
|
@@ -4662,6 +4713,39 @@ async function getComponentInfoFromRouteRecord(record, options = {}) {
|
|
|
4662
4713
|
}
|
|
4663
4714
|
return getComponentInfoFromVueComponent(comp, options);
|
|
4664
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
|
+
}
|
|
4665
4749
|
function resolveIntrospectedComponentName(componentInfo, componentNaming) {
|
|
4666
4750
|
if (componentInfo.filePath && componentNaming) {
|
|
4667
4751
|
return resolveComponentNameFromPath({
|
|
@@ -5092,9 +5176,11 @@ async function introspectNuxtPages(projectRoot, options = {}) {
|
|
|
5092
5176
|
// Nuxt file-based routes are named by convention, but the static walk does not
|
|
5093
5177
|
// recover those names — leave null so callers fall back to path-template navigation.
|
|
5094
5178
|
name: null,
|
|
5179
|
+
path: pathTemplate,
|
|
5095
5180
|
pathTemplate,
|
|
5096
5181
|
params,
|
|
5097
|
-
query: []
|
|
5182
|
+
query: [],
|
|
5183
|
+
...options.collectComponentFiles ? { componentFiles: [fullPath] } : {}
|
|
5098
5184
|
});
|
|
5099
5185
|
}
|
|
5100
5186
|
};
|
|
@@ -5168,7 +5254,7 @@ async function parseRouterFileFromCwd(routerEntryPath, options = {}) {
|
|
|
5168
5254
|
const routePathMap = /* @__PURE__ */ new Map();
|
|
5169
5255
|
const routeMetaEntries = [];
|
|
5170
5256
|
for (const r of router2.getRoutes()) {
|
|
5171
|
-
const componentInfo = await
|
|
5257
|
+
const componentInfo = await getComponentInfoFromRouteComponent(r.components?.default, { rootDir: cwd });
|
|
5172
5258
|
const componentName = resolveIntrospectedComponentName(componentInfo, options.componentNaming);
|
|
5173
5259
|
if (!componentName)
|
|
5174
5260
|
continue;
|
|
@@ -5186,9 +5272,11 @@ async function parseRouterFileFromCwd(routerEntryPath, options = {}) {
|
|
|
5186
5272
|
routeMetaEntries.push({
|
|
5187
5273
|
componentName,
|
|
5188
5274
|
name: typeof r.name === "string" && r.name.length ? r.name : null,
|
|
5275
|
+
path: r.path,
|
|
5189
5276
|
pathTemplate,
|
|
5190
5277
|
params: paramsMeta,
|
|
5191
|
-
query: queryKeys
|
|
5278
|
+
query: queryKeys,
|
|
5279
|
+
...options.collectComponentFiles ? { componentFiles: await getRenderedComponentFiles(router2, r, cwd) } : {}
|
|
5192
5280
|
});
|
|
5193
5281
|
}
|
|
5194
5282
|
}
|
|
@@ -5586,7 +5674,7 @@ function resolveVueSourcePath(targetClassName, vueFilesPathMap, projectRoot) {
|
|
|
5586
5674
|
].filter((candidate) => typeof candidate === "string" && candidate.length > 0);
|
|
5587
5675
|
return candidates.find((candidate) => fs.existsSync(candidate));
|
|
5588
5676
|
}
|
|
5589
|
-
async function
|
|
5677
|
+
async function introspectRouteMetaEntries(projectRoot, routerEntry, routerType, options = {}) {
|
|
5590
5678
|
const root = projectRoot ?? process.cwd();
|
|
5591
5679
|
const pageDirs = options.pageDirs?.length ? options.pageDirs : ["src/views"];
|
|
5592
5680
|
const pageDirsAbs = pageDirs.map((dir) => path.isAbsolute(dir) ? dir : path.resolve(root, dir));
|
|
@@ -5597,14 +5685,18 @@ async function getRouteMetaByComponent(projectRoot, routerEntry, routerType, opt
|
|
|
5597
5685
|
...options.layoutDirs?.length ? options.layoutDirs : ["src/layouts"]
|
|
5598
5686
|
];
|
|
5599
5687
|
const extraRoots = process.cwd() !== root ? [process.cwd()] : [];
|
|
5600
|
-
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), {
|
|
5601
5689
|
componentNaming: {
|
|
5602
5690
|
projectRoot: root,
|
|
5603
5691
|
viewsDirAbs: primaryPageDirAbs,
|
|
5604
5692
|
sourceDirs,
|
|
5605
5693
|
extraRoots
|
|
5606
|
-
}
|
|
5694
|
+
},
|
|
5695
|
+
collectComponentFiles: options.collectComponentFiles
|
|
5607
5696
|
});
|
|
5697
|
+
return routeMetaEntries;
|
|
5698
|
+
}
|
|
5699
|
+
function buildRouteMetaByComponent(routeMetaEntries) {
|
|
5608
5700
|
const map = /* @__PURE__ */ new Map();
|
|
5609
5701
|
for (const entry of routeMetaEntries) {
|
|
5610
5702
|
const list = map.get(entry.componentName) ?? [];
|
|
@@ -5946,6 +6038,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5946
6038
|
customPomImportAliases,
|
|
5947
6039
|
customPomImportNameCollisionBehavior = "error",
|
|
5948
6040
|
customPomFixtures = [],
|
|
6041
|
+
componentGraph = false,
|
|
5949
6042
|
testIdAttribute,
|
|
5950
6043
|
emitLanguages: emitLanguagesOverride,
|
|
5951
6044
|
typescriptOutputStructure = "aggregated",
|
|
@@ -5967,11 +6060,13 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5967
6060
|
if (vueTestUtilsOutDir && path.resolve(vueTestUtilsOutDir) === path.resolve(outDir)) {
|
|
5968
6061
|
throw new Error("[vue-pom-generator] generation.vueTestUtils.outDir must differ from generation.outDir.");
|
|
5969
6062
|
}
|
|
5970
|
-
const
|
|
6063
|
+
const routeMetaEntries = vueRouterFluentChaining && (!routeMetaByComponentOverride || componentGraph) ? await introspectRouteMetaEntries(projectRoot, routerEntry, routerType, {
|
|
5971
6064
|
pageDirs,
|
|
5972
6065
|
componentDirs,
|
|
5973
|
-
layoutDirs
|
|
5974
|
-
|
|
6066
|
+
layoutDirs,
|
|
6067
|
+
collectComponentFiles: componentGraph
|
|
6068
|
+
}) : [];
|
|
6069
|
+
const routeMetaByComponent = routeMetaByComponentOverride ?? (vueRouterFluentChaining ? buildRouteMetaByComponent(routeMetaEntries) : void 0);
|
|
5975
6070
|
const emittableComponentHierarchyMap = componentHierarchyMap;
|
|
5976
6071
|
const generatedFiles = [];
|
|
5977
6072
|
if (emitLanguages.includes("ts")) {
|
|
@@ -6006,6 +6101,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
6006
6101
|
projectRoot,
|
|
6007
6102
|
customPomDir,
|
|
6008
6103
|
customPomFixtures,
|
|
6104
|
+
componentGraphRoutes: componentGraph ? routeMetaEntries : void 0,
|
|
6009
6105
|
elementMetadata,
|
|
6010
6106
|
testIdAttribute
|
|
6011
6107
|
});
|
|
@@ -6718,13 +6814,18 @@ function generateAggregatedCSharpFiles(componentHierarchyMap, outDir, options =
|
|
|
6718
6814
|
return [{ filePath: outputFile, content: chunks.join("\n") }];
|
|
6719
6815
|
}
|
|
6720
6816
|
function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
6721
|
-
const { generateFixtures, pomOutDir, customPomFixtures } = options;
|
|
6817
|
+
const { generateFixtures, pomOutDir, customPomFixtures, componentGraphRoutes } = options;
|
|
6722
6818
|
if (!generateFixtures) {
|
|
6723
6819
|
if (customPomFixtures.length > 0) {
|
|
6724
6820
|
throw new VuePomGeneratorError(
|
|
6725
6821
|
"generation.playwright.customPoms.fixtures requires generation.playwright.fixtures to be enabled."
|
|
6726
6822
|
);
|
|
6727
6823
|
}
|
|
6824
|
+
if (componentGraphRoutes) {
|
|
6825
|
+
throw new VuePomGeneratorError(
|
|
6826
|
+
"generation.playwright.componentGraph requires generation.playwright.fixtures to be enabled."
|
|
6827
|
+
);
|
|
6828
|
+
}
|
|
6728
6829
|
return [];
|
|
6729
6830
|
}
|
|
6730
6831
|
const defaultFixtureOutDirRel = pomOutDir;
|
|
@@ -7082,6 +7183,10 @@ Rename the class or remove it from generation.playwright.customPoms.fixtures.`
|
|
|
7082
7183
|
filePath: path.resolve(fixtureOutDirAbs, manifestFileName),
|
|
7083
7184
|
content: manifestContent
|
|
7084
7185
|
},
|
|
7186
|
+
...componentGraphRoutes ? [{
|
|
7187
|
+
filePath: path.resolve(fixtureOutDirAbs, "component-graph.json"),
|
|
7188
|
+
content: generateComponentGraphJson(componentHierarchyMap, componentGraphRoutes, root)
|
|
7189
|
+
}] : [],
|
|
7085
7190
|
diagnosticsRuntimeFile
|
|
7086
7191
|
];
|
|
7087
7192
|
}
|
|
@@ -7091,33 +7196,8 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
|
|
|
7091
7196
|
customPomAttachments = [],
|
|
7092
7197
|
testIdAttribute
|
|
7093
7198
|
} = options;
|
|
7094
|
-
const normalizeTrackedComponentRef = (value) => {
|
|
7095
|
-
return value.endsWith(".vue") ? value.slice(0, -4) : value;
|
|
7096
|
-
};
|
|
7097
|
-
const resolveTrackedComponentRef = (value) => {
|
|
7098
|
-
const normalizedValue = normalizeTrackedComponentRef(value);
|
|
7099
|
-
if (componentHierarchyMap.has(value)) {
|
|
7100
|
-
return value;
|
|
7101
|
-
}
|
|
7102
|
-
if (componentHierarchyMap.has(normalizedValue)) {
|
|
7103
|
-
return normalizedValue;
|
|
7104
|
-
}
|
|
7105
|
-
let match = null;
|
|
7106
|
-
for (const [candidateName, candidateDeps] of componentHierarchyMap.entries()) {
|
|
7107
|
-
const normalizedCandidate = normalizeTrackedComponentRef(candidateName);
|
|
7108
|
-
const candidateBaseName = path.parse(candidateDeps.filePath).name;
|
|
7109
|
-
if (normalizedCandidate !== normalizedValue && candidateBaseName !== normalizedValue) {
|
|
7110
|
-
continue;
|
|
7111
|
-
}
|
|
7112
|
-
if (match && match !== candidateName) {
|
|
7113
|
-
return null;
|
|
7114
|
-
}
|
|
7115
|
-
match = candidateName;
|
|
7116
|
-
}
|
|
7117
|
-
return match;
|
|
7118
|
-
};
|
|
7119
7199
|
const hasGeneratedPomSurface = (value, seen = /* @__PURE__ */ new Set()) => {
|
|
7120
|
-
const resolvedRef = resolveTrackedComponentRef(value);
|
|
7200
|
+
const resolvedRef = resolveTrackedComponentRef(value, componentHierarchyMap);
|
|
7121
7201
|
if (!resolvedRef || seen.has(resolvedRef)) {
|
|
7122
7202
|
return false;
|
|
7123
7203
|
}
|
|
@@ -7138,7 +7218,7 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
|
|
|
7138
7218
|
return toPascalCaseLocal(normalizeTrackedComponentRef(ref)) === ownClassName && ownClassName.length > 0;
|
|
7139
7219
|
};
|
|
7140
7220
|
const resolveComponentInstance = (spec) => {
|
|
7141
|
-
const componentRef = resolveTrackedComponentRef(spec.componentName);
|
|
7221
|
+
const componentRef = resolveTrackedComponentRef(spec.componentName, componentHierarchyMap);
|
|
7142
7222
|
if (!componentRef || isSelfReference(componentRef) || !hasGeneratedPomSurface(componentRef, /* @__PURE__ */ new Set([componentName]))) {
|
|
7143
7223
|
return null;
|
|
7144
7224
|
}
|
|
@@ -7247,7 +7327,7 @@ Move the repetition to the receiving component boundary so the generator can exp
|
|
|
7247
7327
|
const hasChildComponent = (needle) => {
|
|
7248
7328
|
const normalizedNeedle = normalizeTrackedComponentRef(needle);
|
|
7249
7329
|
for (const child of rawComponentRefsForInstances) {
|
|
7250
|
-
const resolvedChild = resolveTrackedComponentRef(child);
|
|
7330
|
+
const resolvedChild = resolveTrackedComponentRef(child, componentHierarchyMap);
|
|
7251
7331
|
if (normalizeTrackedComponentRef(child) === normalizedNeedle)
|
|
7252
7332
|
return true;
|
|
7253
7333
|
if (resolvedChild && normalizeTrackedComponentRef(resolvedChild) === normalizedNeedle)
|
|
@@ -8236,6 +8316,7 @@ function createBuildProcessorPlugin(options) {
|
|
|
8236
8316
|
customPomImportAliases,
|
|
8237
8317
|
customPomImportNameCollisionBehavior,
|
|
8238
8318
|
customPomFixtures,
|
|
8319
|
+
componentGraph,
|
|
8239
8320
|
testIdAttribute,
|
|
8240
8321
|
routerAwarePoms,
|
|
8241
8322
|
routerType,
|
|
@@ -8387,6 +8468,7 @@ function createBuildProcessorPlugin(options) {
|
|
|
8387
8468
|
customPomImportAliases,
|
|
8388
8469
|
customPomImportNameCollisionBehavior,
|
|
8389
8470
|
customPomFixtures,
|
|
8471
|
+
componentGraph,
|
|
8390
8472
|
testIdAttribute,
|
|
8391
8473
|
vueRouterFluentChaining: routerAwarePoms,
|
|
8392
8474
|
routerEntry: getResolvedRouterEntry(),
|
|
@@ -10768,6 +10850,7 @@ function createDevProcessorPlugin(options) {
|
|
|
10768
10850
|
customPomImportAliases,
|
|
10769
10851
|
customPomImportNameCollisionBehavior,
|
|
10770
10852
|
customPomFixtures,
|
|
10853
|
+
componentGraph,
|
|
10771
10854
|
nameCollisionBehavior,
|
|
10772
10855
|
missingSemanticNameBehavior,
|
|
10773
10856
|
existingIdBehavior,
|
|
@@ -11031,6 +11114,7 @@ function createDevProcessorPlugin(options) {
|
|
|
11031
11114
|
customPomImportAliases,
|
|
11032
11115
|
customPomImportNameCollisionBehavior,
|
|
11033
11116
|
customPomFixtures,
|
|
11117
|
+
componentGraph,
|
|
11034
11118
|
pageDirs: getPageDirs(),
|
|
11035
11119
|
componentDirs: getComponentDirs(),
|
|
11036
11120
|
layoutDirs: getLayoutDirs(),
|
|
@@ -11681,6 +11765,7 @@ function createGeneratorPlugins(options, generationOnly, projectRoot = process.c
|
|
|
11681
11765
|
customPomImportAliases: resolvedCustomPomImportAliases,
|
|
11682
11766
|
customPomImportNameCollisionBehavior: customPoms?.importNameCollisionBehavior,
|
|
11683
11767
|
customPomFixtures: resolvedCustomPomFixtures,
|
|
11768
|
+
componentGraph: generationOptions?.playwright?.componentGraph,
|
|
11684
11769
|
nameCollisionBehavior: generationOptions?.nameCollisionBehavior,
|
|
11685
11770
|
missingSemanticNameBehavior: generationOptions?.missingSemanticNameBehavior,
|
|
11686
11771
|
existingIdBehavior: resolvedInjectionOptions.existingIdBehavior,
|