@immense/vue-pom-generator 1.0.88 → 1.0.90
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 +12 -0
- package/RELEASE_NOTES.md +63 -36
- package/class-generation/index.ts +6 -11
- package/dist/class-generation/index.d.ts.map +1 -1
- package/dist/eslint/index.cjs +42 -0
- package/dist/eslint/index.cjs.map +1 -1
- package/dist/eslint/index.d.ts +3 -0
- package/dist/eslint/index.d.ts.map +1 -1
- package/dist/eslint/index.mjs +42 -0
- package/dist/eslint/index.mjs.map +1 -1
- package/dist/eslint/no-data-testid-in-specs.d.ts +3 -0
- package/dist/eslint/no-data-testid-in-specs.d.ts.map +1 -0
- package/dist/index.cjs +1481 -1529
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1472 -1520
- package/dist/index.mjs.map +1 -1
- package/dist/manifest-generator.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/resolved-generation-options.d.ts +2 -2
- package/dist/plugin/resolved-generation-options.d.ts.map +1 -1
- package/dist/plugin/resolved-injection-options.d.ts +3 -3
- package/dist/plugin/resolved-injection-options.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +11 -3
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/vue-plugin.d.ts +3 -2
- package/dist/plugin/vue-plugin.d.ts.map +1 -1
- package/dist/router-bridge.d.ts +18 -0
- package/dist/router-bridge.d.ts.map +1 -0
- package/dist/router.cjs +9 -0
- package/dist/router.cjs.map +1 -0
- package/dist/router.mjs +9 -0
- package/dist/router.mjs.map +1 -0
- package/dist/tests/existing-id-behavior.test.d.ts +2 -0
- package/dist/tests/existing-id-behavior.test.d.ts.map +1 -0
- package/dist/tests/router-bridge.test.d.ts +2 -0
- package/dist/tests/router-bridge.test.d.ts.map +1 -0
- package/dist/utils.d.ts +0 -11
- package/dist/utils.d.ts.map +1 -1
- package/dist/vite.config.d.ts.map +1 -1
- package/package.json +6 -1
package/dist/index.cjs
CHANGED
|
@@ -33,8 +33,9 @@ const parser = require("@babel/parser");
|
|
|
33
33
|
const compilerCore = require("@vue/compiler-core");
|
|
34
34
|
const tsMorph = require("ts-morph");
|
|
35
35
|
const types = require("@babel/types");
|
|
36
|
-
const
|
|
36
|
+
const router = require("./router.cjs");
|
|
37
37
|
const vue = require("@vitejs/plugin-vue");
|
|
38
|
+
const node_perf_hooks = require("node:perf_hooks");
|
|
38
39
|
const dom = require("@floating-ui/dom");
|
|
39
40
|
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
40
41
|
function _interopNamespaceDefault(e) {
|
|
@@ -3644,54 +3645,6 @@ function buildPomGeneratedPropertyName(pom) {
|
|
|
3644
3645
|
function buildPomGeneratedActionName(pom) {
|
|
3645
3646
|
return requireStructuredPomName(pom.generatedActionName, "generatedActionName", pom);
|
|
3646
3647
|
}
|
|
3647
|
-
const STANDALONE_WRAPPER_FALLBACK_ROLES = /* @__PURE__ */ new Set([
|
|
3648
|
-
"button",
|
|
3649
|
-
"input",
|
|
3650
|
-
"select",
|
|
3651
|
-
"vselect",
|
|
3652
|
-
"checkbox",
|
|
3653
|
-
"toggle",
|
|
3654
|
-
"radio",
|
|
3655
|
-
"link",
|
|
3656
|
-
"tab"
|
|
3657
|
-
]);
|
|
3658
|
-
function stripTrailingAsciiDigits(value) {
|
|
3659
|
-
let end = value.length;
|
|
3660
|
-
while (end > 0 && isAsciiDigitCode(value.charCodeAt(end - 1))) {
|
|
3661
|
-
end -= 1;
|
|
3662
|
-
}
|
|
3663
|
-
return value.slice(0, end);
|
|
3664
|
-
}
|
|
3665
|
-
function matchesStandaloneWrapperFallbackMethodName(methodName, componentClassName) {
|
|
3666
|
-
let normalizedMethodName = methodName;
|
|
3667
|
-
if (normalizedMethodName.endsWith("ByKey")) {
|
|
3668
|
-
normalizedMethodName = normalizedMethodName.slice(0, -"ByKey".length);
|
|
3669
|
-
}
|
|
3670
|
-
normalizedMethodName = stripTrailingAsciiDigits(normalizedMethodName);
|
|
3671
|
-
return normalizedMethodName === componentClassName;
|
|
3672
|
-
}
|
|
3673
|
-
function shouldSuppressStandaloneWrapperFallbackSurface(componentName, dependencies) {
|
|
3674
|
-
if (dependencies.isView || (dependencies.pomExtraMethods?.length ?? 0) > 0) {
|
|
3675
|
-
return false;
|
|
3676
|
-
}
|
|
3677
|
-
const entries = Array.from(dependencies.dataTestIdSet ?? []);
|
|
3678
|
-
if (!entries.length) {
|
|
3679
|
-
return false;
|
|
3680
|
-
}
|
|
3681
|
-
const primaryEntries = entries.filter((entry) => {
|
|
3682
|
-
return !!entry.pom && entry.pom.emitPrimary !== false;
|
|
3683
|
-
});
|
|
3684
|
-
if (!primaryEntries.length || primaryEntries.length !== entries.length) {
|
|
3685
|
-
return false;
|
|
3686
|
-
}
|
|
3687
|
-
const componentClassName = toPascalCase(componentName.endsWith(".vue") ? componentName.slice(0, -4) : componentName);
|
|
3688
|
-
if (!componentClassName) {
|
|
3689
|
-
return false;
|
|
3690
|
-
}
|
|
3691
|
-
return primaryEntries.every(({ pom }) => {
|
|
3692
|
-
return STANDALONE_WRAPPER_FALLBACK_ROLES.has(pom.nativeRole) && matchesStandaloneWrapperFallbackMethodName(pom.methodName, componentClassName);
|
|
3693
|
-
});
|
|
3694
|
-
}
|
|
3695
3648
|
function safeRealpath(value) {
|
|
3696
3649
|
try {
|
|
3697
3650
|
if (fs.existsSync(value)) {
|
|
@@ -4083,18 +4036,18 @@ function getRoutePropsKeys(record) {
|
|
|
4083
4036
|
}
|
|
4084
4037
|
return { paramKeys: [], queryKeys: [] };
|
|
4085
4038
|
}
|
|
4086
|
-
function buildRouteTemplate(
|
|
4039
|
+
function buildRouteTemplate(router2, record, paramNames) {
|
|
4087
4040
|
if (typeof record.name !== "string" || !record.name.length) {
|
|
4088
4041
|
return record.path;
|
|
4089
4042
|
}
|
|
4090
4043
|
const params = Object.fromEntries(paramNames.map((name) => [name, getParamToken(name)]));
|
|
4091
4044
|
try {
|
|
4092
|
-
return
|
|
4045
|
+
return router2.resolve({ name: record.name, params }).path;
|
|
4093
4046
|
} catch {
|
|
4094
4047
|
return record.path;
|
|
4095
4048
|
}
|
|
4096
4049
|
}
|
|
4097
|
-
function getRouteParamMeta(
|
|
4050
|
+
function getRouteParamMeta(router2, record, paramNames) {
|
|
4098
4051
|
if (typeof record.name !== "string" || !record.name.length) {
|
|
4099
4052
|
return paramNames.map((name) => ({ name, optional: false }));
|
|
4100
4053
|
}
|
|
@@ -4103,7 +4056,7 @@ function getRouteParamMeta(router, record, paramNames) {
|
|
|
4103
4056
|
const params = { ...paramsWithAll };
|
|
4104
4057
|
delete params[name];
|
|
4105
4058
|
try {
|
|
4106
|
-
|
|
4059
|
+
router2.resolve({ name: record.name, params });
|
|
4107
4060
|
return { name, optional: true };
|
|
4108
4061
|
} catch {
|
|
4109
4062
|
return { name, optional: false };
|
|
@@ -4673,16 +4626,16 @@ async function parseRouterFileFromCwd(routerEntryPath, options = {}) {
|
|
|
4673
4626
|
if (typeof makeRouter !== "function") {
|
|
4674
4627
|
throw new TypeError(`[vue-pom-generator] ${routerEntry} must export a default router factory function (export default makeRouter).`);
|
|
4675
4628
|
}
|
|
4676
|
-
let
|
|
4629
|
+
let router2;
|
|
4677
4630
|
try {
|
|
4678
|
-
|
|
4631
|
+
router2 = makeRouter();
|
|
4679
4632
|
} catch (err) {
|
|
4680
4633
|
throw new Error(`[vue-pom-generator] makeRouter() invocation failed: ${String(err)}`);
|
|
4681
4634
|
}
|
|
4682
4635
|
const routeNameMap = /* @__PURE__ */ new Map();
|
|
4683
4636
|
const routePathMap = /* @__PURE__ */ new Map();
|
|
4684
4637
|
const routeMetaEntries = [];
|
|
4685
|
-
for (const r of
|
|
4638
|
+
for (const r of router2.getRoutes()) {
|
|
4686
4639
|
const componentInfo = await getComponentInfoFromRouteRecord(r, { rootDir: cwd });
|
|
4687
4640
|
const componentName = resolveIntrospectedComponentName(componentInfo, options.componentNaming);
|
|
4688
4641
|
if (!componentName)
|
|
@@ -4695,8 +4648,8 @@ async function parseRouterFileFromCwd(routerEntryPath, options = {}) {
|
|
|
4695
4648
|
routeNameMap.set(key, componentName);
|
|
4696
4649
|
}
|
|
4697
4650
|
const { paramKeys, queryKeys } = getRoutePropsKeys(r);
|
|
4698
|
-
const paramsMeta = getRouteParamMeta(
|
|
4699
|
-
const pathTemplate = buildRouteTemplate(
|
|
4651
|
+
const paramsMeta = getRouteParamMeta(router2, r, paramKeys);
|
|
4652
|
+
const pathTemplate = buildRouteTemplate(router2, r, paramsMeta.map((p) => p.name));
|
|
4700
4653
|
if (typeof pathTemplate === "string" && pathTemplate.length) {
|
|
4701
4654
|
routeMetaEntries.push({
|
|
4702
4655
|
componentName,
|
|
@@ -4907,7 +4860,7 @@ const GOTO_RUNTIME_LINES = [
|
|
|
4907
4860
|
"const resolvedUrl = runtimeBaseUrl ? new URL(targetUrl, runtimeBaseUrl).toString() : targetUrl;",
|
|
4908
4861
|
"await this.page.goto(resolvedUrl);"
|
|
4909
4862
|
];
|
|
4910
|
-
const ROUTER_GLOBAL_NAME =
|
|
4863
|
+
const ROUTER_GLOBAL_NAME = router.POM_ROUTER_GLOBAL_NAME;
|
|
4911
4864
|
const pushBlock = (routeNameExpr, paramsExpr, nullable) => {
|
|
4912
4865
|
const routerType = `{ ${ROUTER_GLOBAL_NAME}?: { push: (to: { name: string; params: Record<string, unknown> }) => Promise<unknown>; resolve: (to: { name: string; params: Record<string, unknown> }) => { href: string } } }`;
|
|
4913
4866
|
const routeParamsLine = paramsExpr === "undefined" ? "const routeParams = {};" : nullable ? `const routeParams = Object.fromEntries(Object.entries(${paramsExpr} ?? {}).filter(([, v]) => v !== undefined));` : `const routeParams = Object.fromEntries(Object.entries(${paramsExpr}).filter(([, v]) => v !== undefined));`;
|
|
@@ -5155,11 +5108,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5155
5108
|
componentDirs,
|
|
5156
5109
|
layoutDirs
|
|
5157
5110
|
}) : void 0);
|
|
5158
|
-
const emittableComponentHierarchyMap =
|
|
5159
|
-
Array.from(componentHierarchyMap.entries()).filter(([componentName, dependencies]) => {
|
|
5160
|
-
return !shouldSuppressStandaloneWrapperFallbackSurface(componentName, dependencies);
|
|
5161
|
-
})
|
|
5162
|
-
);
|
|
5111
|
+
const emittableComponentHierarchyMap = componentHierarchyMap;
|
|
5163
5112
|
const generatedFilePaths = [];
|
|
5164
5113
|
const writeGeneratedFile = (file) => {
|
|
5165
5114
|
const resolvedFilePath = path.resolve(file.filePath);
|
|
@@ -8082,1568 +8031,1571 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8082
8031
|
}
|
|
8083
8032
|
};
|
|
8084
8033
|
}
|
|
8085
|
-
function
|
|
8086
|
-
|
|
8087
|
-
|
|
8088
|
-
|
|
8089
|
-
|
|
8090
|
-
|
|
8091
|
-
|
|
8092
|
-
|
|
8093
|
-
|
|
8034
|
+
function supportsInlineTextAccessibleName(role) {
|
|
8035
|
+
return role === "button" || role === "radio";
|
|
8036
|
+
}
|
|
8037
|
+
function buildAccessibilityAudit(metadata, inferredRole) {
|
|
8038
|
+
if (!metadata || !inferredRole) {
|
|
8039
|
+
return void 0;
|
|
8040
|
+
}
|
|
8041
|
+
const role = normalizePomRoleLabel(inferredRole).toLowerCase();
|
|
8042
|
+
const dynamicProps = new Set(metadata.dynamicProps ?? []);
|
|
8043
|
+
const hasDynamicAccessibleNameSignal = dynamicProps.has("aria-label") || dynamicProps.has("title") || !!metadata.hasDynamicText;
|
|
8044
|
+
let accessibleNameSource;
|
|
8045
|
+
const reasons = [];
|
|
8046
|
+
if (metadata.staticAriaLabel) {
|
|
8047
|
+
accessibleNameSource = "aria-label";
|
|
8048
|
+
} else if (supportsInlineTextAccessibleName(role) && metadata.staticTextContent) {
|
|
8049
|
+
accessibleNameSource = "text";
|
|
8050
|
+
} else if (metadata.staticTitle) {
|
|
8051
|
+
accessibleNameSource = "title";
|
|
8052
|
+
} else if (hasDynamicAccessibleNameSignal) {
|
|
8053
|
+
accessibleNameSource = "dynamic";
|
|
8054
|
+
} else if (role === "input" || role === "select") {
|
|
8055
|
+
accessibleNameSource = "unknown";
|
|
8056
|
+
reasons.push("No inline accessible-name signal was found; the element may rely on external markup such as a separate <label>.");
|
|
8057
|
+
} else {
|
|
8058
|
+
accessibleNameSource = "missing";
|
|
8059
|
+
reasons.push("No compile-time accessible-name signal was found.");
|
|
8094
8060
|
}
|
|
8095
8061
|
return {
|
|
8096
|
-
|
|
8097
|
-
|
|
8098
|
-
|
|
8062
|
+
needsReview: accessibleNameSource === "unknown" || accessibleNameSource === "missing",
|
|
8063
|
+
accessibleNameSource,
|
|
8064
|
+
reasons,
|
|
8065
|
+
...metadata.staticAriaLabel ? { staticAriaLabel: metadata.staticAriaLabel } : {},
|
|
8066
|
+
...metadata.staticRole ? { staticRole: metadata.staticRole } : {},
|
|
8067
|
+
...metadata.staticTitle ? { staticTitle: metadata.staticTitle } : {},
|
|
8068
|
+
...metadata.staticTextContent ? { staticTextContent: metadata.staticTextContent } : {}
|
|
8099
8069
|
};
|
|
8100
8070
|
}
|
|
8101
|
-
function
|
|
8102
|
-
|
|
8103
|
-
|
|
8071
|
+
function collectAccessibilityReviewWarnings(manifest) {
|
|
8072
|
+
const warnings = [];
|
|
8073
|
+
for (const [componentName, component] of Object.entries(manifest)) {
|
|
8074
|
+
for (const entry of component.entries) {
|
|
8075
|
+
if (!entry.accessibility?.needsReview) {
|
|
8076
|
+
continue;
|
|
8077
|
+
}
|
|
8078
|
+
const entryLabel = entry.generatedPropertyName ?? entry.testId;
|
|
8079
|
+
const reasonText = entry.accessibility.reasons.join(" ");
|
|
8080
|
+
warnings.push(
|
|
8081
|
+
`[vue-pom-generator] Accessibility review suggested for ${componentName}.${entryLabel} (role=${entry.inferredRole ?? "unknown"}, testId=${JSON.stringify(entry.testId)}): ${reasonText}`
|
|
8082
|
+
);
|
|
8083
|
+
}
|
|
8104
8084
|
}
|
|
8105
|
-
|
|
8106
|
-
|
|
8085
|
+
return warnings;
|
|
8086
|
+
}
|
|
8087
|
+
function findDataTestIdProp(element, attributeName = "data-testid") {
|
|
8088
|
+
return element.props.find(
|
|
8089
|
+
(prop) => prop.type === compilerCore.NodeTypes.ATTRIBUTE && prop.name === attributeName || prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === attributeName
|
|
8090
|
+
);
|
|
8091
|
+
}
|
|
8092
|
+
function getTestIdFromProp(prop) {
|
|
8093
|
+
if (!prop) {
|
|
8094
|
+
return null;
|
|
8107
8095
|
}
|
|
8108
|
-
|
|
8096
|
+
if (prop.type === compilerCore.NodeTypes.ATTRIBUTE) {
|
|
8097
|
+
return prop.value ? prop.value.content : null;
|
|
8098
|
+
}
|
|
8099
|
+
if (prop.type === compilerCore.NodeTypes.DIRECTIVE) {
|
|
8100
|
+
return prop.exp?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION ? prop.exp.content : null;
|
|
8101
|
+
}
|
|
8102
|
+
return null;
|
|
8109
8103
|
}
|
|
8110
|
-
function
|
|
8111
|
-
|
|
8112
|
-
|
|
8113
|
-
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
|
|
8121
|
-
|
|
8122
|
-
|
|
8123
|
-
|
|
8124
|
-
|
|
8125
|
-
|
|
8126
|
-
|
|
8127
|
-
getWrapperSearchRoots,
|
|
8128
|
-
getResolvedRouterEntry,
|
|
8129
|
-
loggerRef
|
|
8130
|
-
} = options;
|
|
8131
|
-
const {
|
|
8132
|
-
outDir,
|
|
8133
|
-
emitLanguages,
|
|
8134
|
-
typescriptOutputStructure,
|
|
8135
|
-
csharp,
|
|
8136
|
-
generateFixtures,
|
|
8137
|
-
customPomAttachments,
|
|
8138
|
-
customPomDir,
|
|
8139
|
-
requireCustomPomDir,
|
|
8140
|
-
customPomImportAliases,
|
|
8141
|
-
customPomImportNameCollisionBehavior,
|
|
8142
|
-
testIdAttribute,
|
|
8143
|
-
nameCollisionBehavior,
|
|
8144
|
-
missingSemanticNameBehavior,
|
|
8145
|
-
existingIdBehavior,
|
|
8146
|
-
routerAwarePoms,
|
|
8147
|
-
routerType,
|
|
8148
|
-
routerModuleShims
|
|
8149
|
-
} = generation;
|
|
8150
|
-
let lastGeneratedMetrics = {
|
|
8151
|
-
entryCount: 0,
|
|
8152
|
-
interactiveComponentCount: 0,
|
|
8153
|
-
dataTestIdCount: 0
|
|
8154
|
-
};
|
|
8155
|
-
const getViewsDirAbs = () => path.isAbsolute(getViewsDir()) ? getViewsDir() : path.resolve(projectRootRef.current, getViewsDir());
|
|
8156
|
-
const getPageDirsAbs = () => getPageDirs().map((dir) => path.isAbsolute(dir) ? dir : path.resolve(projectRootRef.current, dir));
|
|
8157
|
-
const getScriptInfo = (source, filename) => {
|
|
8158
|
-
try {
|
|
8159
|
-
const { descriptor } = compilerSfc.parse(source, { filename });
|
|
8160
|
-
if (!descriptor.script && !descriptor.scriptSetup)
|
|
8161
|
-
return { bindings: void 0, isScriptSetup: false };
|
|
8162
|
-
const scriptBlock = compilerSfc.compileScript(descriptor, { id: filename });
|
|
8163
|
-
return { bindings: scriptBlock.bindings, isScriptSetup: !!descriptor.scriptSetup };
|
|
8164
|
-
} catch {
|
|
8165
|
-
return { bindings: void 0, isScriptSetup: false };
|
|
8104
|
+
function parseDynamicProps(dynamicProps) {
|
|
8105
|
+
if (!dynamicProps) {
|
|
8106
|
+
return void 0;
|
|
8107
|
+
}
|
|
8108
|
+
if (typeof dynamicProps === "string") {
|
|
8109
|
+
const parts = [];
|
|
8110
|
+
let current = "";
|
|
8111
|
+
for (let i = 0; i < dynamicProps.length; i++) {
|
|
8112
|
+
const ch = dynamicProps[i];
|
|
8113
|
+
if (ch === ",") {
|
|
8114
|
+
const token = current.trim();
|
|
8115
|
+
if (token.length)
|
|
8116
|
+
parts.push(token);
|
|
8117
|
+
current = "";
|
|
8118
|
+
continue;
|
|
8119
|
+
}
|
|
8120
|
+
current += ch;
|
|
8166
8121
|
}
|
|
8167
|
-
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
|
|
8173
|
-
|
|
8174
|
-
|
|
8175
|
-
|
|
8176
|
-
|
|
8177
|
-
|
|
8178
|
-
|
|
8179
|
-
continue;
|
|
8180
|
-
}
|
|
8181
|
-
for (const ent of entries) {
|
|
8182
|
-
if (ent.isDirectory()) {
|
|
8183
|
-
if (ent.name === "node_modules" || ent.name === ".git" || ent.name === "dist")
|
|
8184
|
-
continue;
|
|
8185
|
-
stack.push(path.join(dir, ent.name));
|
|
8186
|
-
continue;
|
|
8187
|
-
}
|
|
8188
|
-
if (ent.isFile() && ent.name.endsWith(".vue")) {
|
|
8189
|
-
out.push(path.join(dir, ent.name));
|
|
8190
|
-
}
|
|
8191
|
-
}
|
|
8122
|
+
const last = current.trim();
|
|
8123
|
+
if (last.length)
|
|
8124
|
+
parts.push(last);
|
|
8125
|
+
return parts;
|
|
8126
|
+
}
|
|
8127
|
+
if (isSimpleExpressionNode(dynamicProps)) {
|
|
8128
|
+
const content = dynamicProps.content;
|
|
8129
|
+
if (content.startsWith("[") && content.endsWith("]")) {
|
|
8130
|
+
try {
|
|
8131
|
+
return JSON.parse(content);
|
|
8132
|
+
} catch {
|
|
8133
|
+
return void 0;
|
|
8192
8134
|
}
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
|
|
8196
|
-
|
|
8197
|
-
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8202
|
-
|
|
8203
|
-
|
|
8204
|
-
|
|
8205
|
-
|
|
8206
|
-
|
|
8207
|
-
|
|
8208
|
-
|
|
8209
|
-
|
|
8210
|
-
|
|
8211
|
-
|
|
8212
|
-
|
|
8213
|
-
sfc = fs.readFileSync(absolutePath, "utf8");
|
|
8214
|
-
} catch {
|
|
8215
|
-
continue;
|
|
8135
|
+
}
|
|
8136
|
+
return [content];
|
|
8137
|
+
}
|
|
8138
|
+
return void 0;
|
|
8139
|
+
}
|
|
8140
|
+
function findStaticAttributeValue(element, attributeName) {
|
|
8141
|
+
const attribute = element.props.find(
|
|
8142
|
+
(prop) => prop.type === compilerCore.NodeTypes.ATTRIBUTE && prop.name === attributeName
|
|
8143
|
+
);
|
|
8144
|
+
const value = attribute?.value?.content?.trim();
|
|
8145
|
+
return value || void 0;
|
|
8146
|
+
}
|
|
8147
|
+
function collectStaticTextContent(children) {
|
|
8148
|
+
const parts = [];
|
|
8149
|
+
const visit = (nodes) => {
|
|
8150
|
+
for (const node of nodes) {
|
|
8151
|
+
if (node.type === compilerCore.NodeTypes.TEXT) {
|
|
8152
|
+
const text2 = collapseWhitespace(node.content);
|
|
8153
|
+
if (text2) {
|
|
8154
|
+
parts.push(text2);
|
|
8216
8155
|
}
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
|
|
8221
|
-
componentHierarchyMap.set(componentName, {
|
|
8222
|
-
filePath: absolutePath,
|
|
8223
|
-
childrenComponentSet: /* @__PURE__ */ new Set(),
|
|
8224
|
-
usedComponentSet: /* @__PURE__ */ new Set(),
|
|
8225
|
-
dataTestIdSet: /* @__PURE__ */ new Set(),
|
|
8226
|
-
isView: false,
|
|
8227
|
-
methodsContent: ""
|
|
8228
|
-
});
|
|
8229
|
-
supplemented++;
|
|
8230
|
-
continue;
|
|
8231
|
-
}
|
|
8232
|
-
const { bindings: bindingMetadata, isScriptSetup } = getScriptInfo(sfc, absolutePath);
|
|
8233
|
-
vueFilesPathMap.set(componentName, absolutePath);
|
|
8234
|
-
try {
|
|
8235
|
-
compilerDom__namespace.compile(template, {
|
|
8236
|
-
filename: absolutePath,
|
|
8237
|
-
prefixIdentifiers: true,
|
|
8238
|
-
inline: isScriptSetup,
|
|
8239
|
-
bindingMetadata,
|
|
8240
|
-
// See dev-plugin.ts — same rationale: enable TS in template
|
|
8241
|
-
// expressions so `(row: RowType) => ...` handlers parse.
|
|
8242
|
-
expressionPlugins: ["typescript"],
|
|
8243
|
-
nodeTransforms: [
|
|
8244
|
-
createTestIdTransform(
|
|
8245
|
-
componentName,
|
|
8246
|
-
componentHierarchyMap,
|
|
8247
|
-
nativeWrappers,
|
|
8248
|
-
excludedComponents,
|
|
8249
|
-
getViewsDirAbs(),
|
|
8250
|
-
{
|
|
8251
|
-
existingIdBehavior: existingIdBehavior ?? "error",
|
|
8252
|
-
testIdAttribute,
|
|
8253
|
-
nameCollisionBehavior,
|
|
8254
|
-
missingSemanticNameBehavior,
|
|
8255
|
-
warn: (message) => loggerRef.current.warn(message),
|
|
8256
|
-
vueFilesPathMap,
|
|
8257
|
-
wrapperSearchRoots: getWrapperSearchRoots(),
|
|
8258
|
-
crossFileKeyRegistry,
|
|
8259
|
-
optionKeyAttribute
|
|
8260
|
-
}
|
|
8261
|
-
)
|
|
8262
|
-
]
|
|
8263
|
-
});
|
|
8264
|
-
} catch {
|
|
8265
|
-
}
|
|
8266
|
-
supplemented++;
|
|
8156
|
+
continue;
|
|
8157
|
+
}
|
|
8158
|
+
if (node.type === compilerCore.NodeTypes.ELEMENT) {
|
|
8159
|
+
visit(node.children);
|
|
8267
8160
|
}
|
|
8268
|
-
}
|
|
8269
|
-
if (supplemented > 0) {
|
|
8270
|
-
loggerRef.current.info(`supplemented ${supplemented} components from filesystem walk (not in build graph)`);
|
|
8271
8161
|
}
|
|
8272
8162
|
};
|
|
8273
|
-
|
|
8274
|
-
|
|
8275
|
-
|
|
8276
|
-
|
|
8277
|
-
|
|
8278
|
-
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
|
|
8282
|
-
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
|
|
8286
|
-
|
|
8287
|
-
|
|
8288
|
-
|
|
8289
|
-
|
|
8290
|
-
|
|
8291
|
-
|
|
8292
|
-
|
|
8293
|
-
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
|
|
8297
|
-
|
|
8298
|
-
});
|
|
8299
|
-
}
|
|
8300
|
-
const { routeNameMap, routePathMap } = result;
|
|
8301
|
-
setRouteNameToComponentNameMap(routeNameMap);
|
|
8302
|
-
setResolveToComponentNameFn((to) => {
|
|
8303
|
-
if (typeof to === "string") {
|
|
8304
|
-
return routePathMap.get(to) ?? null;
|
|
8305
|
-
}
|
|
8306
|
-
const maybe = to;
|
|
8307
|
-
if (typeof maybe.name === "string" && maybe.name.length) {
|
|
8308
|
-
const key = toPascalCase(maybe.name);
|
|
8309
|
-
return routeNameMap.get(key) ?? null;
|
|
8310
|
-
}
|
|
8311
|
-
if (typeof maybe.path === "string" && maybe.path.length) {
|
|
8312
|
-
return routePathMap.get(maybe.path) ?? null;
|
|
8313
|
-
}
|
|
8314
|
-
return null;
|
|
8315
|
-
});
|
|
8316
|
-
if (!fs.existsSync(basePageClassPath)) {
|
|
8317
|
-
this.error(`Base page runtime file not found at ${basePageClassPath}. Ensure it is included in the build.`);
|
|
8318
|
-
}
|
|
8319
|
-
this.addWatchFile(basePageClassPath);
|
|
8320
|
-
const pointerPath = path.resolve(path.dirname(basePageClassPath), "pointer.ts");
|
|
8321
|
-
if (!fs.existsSync(pointerPath)) {
|
|
8322
|
-
this.error(`pointer.ts not found at ${pointerPath}. Ensure it is included in the build.`);
|
|
8323
|
-
}
|
|
8324
|
-
this.addWatchFile(pointerPath);
|
|
8325
|
-
const calloutPath = path.resolve(path.dirname(basePageClassPath), "callout.ts");
|
|
8326
|
-
if (!fs.existsSync(calloutPath)) {
|
|
8327
|
-
this.error(`callout.ts not found at ${calloutPath}. Ensure it is included in the build.`);
|
|
8328
|
-
}
|
|
8329
|
-
this.addWatchFile(calloutPath);
|
|
8330
|
-
const floatingUiCalloutPath = path.resolve(path.dirname(basePageClassPath), "floating-ui-callout.ts");
|
|
8331
|
-
if (fs.existsSync(floatingUiCalloutPath)) {
|
|
8332
|
-
this.addWatchFile(floatingUiCalloutPath);
|
|
8333
|
-
}
|
|
8334
|
-
},
|
|
8335
|
-
async buildEnd(error) {
|
|
8336
|
-
if (error) {
|
|
8337
|
-
return;
|
|
8338
|
-
}
|
|
8339
|
-
supplementHierarchyFromFilesystem();
|
|
8340
|
-
const metrics = summarizeHierarchyMap(componentHierarchyMap);
|
|
8341
|
-
if (metrics.dataTestIdCount <= 0) {
|
|
8342
|
-
return;
|
|
8343
|
-
}
|
|
8344
|
-
if (isLessRich(metrics, lastGeneratedMetrics)) {
|
|
8345
|
-
return;
|
|
8346
|
-
}
|
|
8347
|
-
await generateFiles(componentHierarchyMap, vueFilesPathMap, normalizedBasePagePath, {
|
|
8348
|
-
outDir,
|
|
8349
|
-
emitLanguages,
|
|
8350
|
-
typescriptOutputStructure,
|
|
8351
|
-
csharp,
|
|
8352
|
-
generateFixtures,
|
|
8353
|
-
customPomAttachments,
|
|
8354
|
-
projectRoot: projectRootRef.current,
|
|
8355
|
-
customPomDir,
|
|
8356
|
-
requireCustomPomDir,
|
|
8357
|
-
customPomImportAliases,
|
|
8358
|
-
customPomImportNameCollisionBehavior,
|
|
8359
|
-
testIdAttribute,
|
|
8360
|
-
vueRouterFluentChaining: routerAwarePoms,
|
|
8361
|
-
routerEntry: getResolvedRouterEntry(),
|
|
8362
|
-
routerType,
|
|
8363
|
-
pageDirs: getPageDirs(),
|
|
8364
|
-
componentDirs: getComponentDirs(),
|
|
8365
|
-
layoutDirs: getLayoutDirs()
|
|
8366
|
-
});
|
|
8367
|
-
lastGeneratedMetrics = metrics;
|
|
8368
|
-
loggerRef.current.info(`generated POMs (${metrics.entryCount} entries, ${metrics.interactiveComponentCount} interactive components, ${metrics.dataTestIdCount} selectors)`);
|
|
8369
|
-
},
|
|
8370
|
-
closeBundle() {
|
|
8371
|
-
loggerRef.current.info("build complete");
|
|
8163
|
+
visit(children);
|
|
8164
|
+
const text = collapseWhitespace(parts.join(" "));
|
|
8165
|
+
return text || void 0;
|
|
8166
|
+
}
|
|
8167
|
+
function tryCreateElementMetadata(args) {
|
|
8168
|
+
const { element, semanticNameMap } = args;
|
|
8169
|
+
const testIdAttribute = (args.testIdAttribute ?? "data-testid").trim() || "data-testid";
|
|
8170
|
+
const testIdProp = findDataTestIdProp(element, testIdAttribute);
|
|
8171
|
+
if (!testIdProp) {
|
|
8172
|
+
return null;
|
|
8173
|
+
}
|
|
8174
|
+
const testId = getTestIdFromProp(testIdProp);
|
|
8175
|
+
if (!testId) {
|
|
8176
|
+
return null;
|
|
8177
|
+
}
|
|
8178
|
+
if (!element.codegenNode || element.codegenNode.type !== compilerCore.NodeTypes.VNODE_CALL) {
|
|
8179
|
+
return null;
|
|
8180
|
+
}
|
|
8181
|
+
const codegenNode = element.codegenNode;
|
|
8182
|
+
const patchFlag = codegenNode.patchFlag;
|
|
8183
|
+
let dynamicPropsList = parseDynamicProps(codegenNode.dynamicProps);
|
|
8184
|
+
if (!dynamicPropsList && codegenNode.dynamicProps && typeof codegenNode.dynamicProps !== "string" && isSimpleExpressionNode(codegenNode.dynamicProps)) {
|
|
8185
|
+
const content = codegenNode.dynamicProps.content;
|
|
8186
|
+
if (content.startsWith("[") && content.endsWith("]")) {
|
|
8187
|
+
dynamicPropsList = [content];
|
|
8372
8188
|
}
|
|
8189
|
+
}
|
|
8190
|
+
const metadata = {
|
|
8191
|
+
testId,
|
|
8192
|
+
semanticName: semanticNameMap.get(testId),
|
|
8193
|
+
tag: element.tag,
|
|
8194
|
+
tagType: element.tagType,
|
|
8195
|
+
patchFlag,
|
|
8196
|
+
dynamicProps: dynamicPropsList,
|
|
8197
|
+
// Decode patch flags (bitwise) - preserved as-is from existing code.
|
|
8198
|
+
hasClickHandler: patchFlag ? Boolean(patchFlag & 32) : void 0,
|
|
8199
|
+
hasDynamicClass: patchFlag ? Boolean(patchFlag & 2) : void 0,
|
|
8200
|
+
hasDynamicStyle: patchFlag ? Boolean(patchFlag & 4) : void 0,
|
|
8201
|
+
hasDynamicText: patchFlag ? Boolean(patchFlag & 1) : void 0,
|
|
8202
|
+
staticAriaLabel: findStaticAttributeValue(element, "aria-label"),
|
|
8203
|
+
staticRole: findStaticAttributeValue(element, "role"),
|
|
8204
|
+
staticTitle: findStaticAttributeValue(element, "title"),
|
|
8205
|
+
staticTextContent: collectStaticTextContent(element.children),
|
|
8206
|
+
sourceLine: element.loc?.start.line,
|
|
8207
|
+
sourceColumn: element.loc?.start.column
|
|
8373
8208
|
};
|
|
8209
|
+
return metadata;
|
|
8374
8210
|
}
|
|
8375
|
-
function
|
|
8376
|
-
|
|
8377
|
-
|
|
8378
|
-
|
|
8379
|
-
|
|
8380
|
-
|
|
8381
|
-
|
|
8382
|
-
|
|
8383
|
-
|
|
8384
|
-
|
|
8385
|
-
|
|
8386
|
-
|
|
8387
|
-
|
|
8388
|
-
|
|
8389
|
-
|
|
8390
|
-
getResolvedRouterEntry,
|
|
8391
|
-
loggerRef
|
|
8392
|
-
} = options;
|
|
8393
|
-
const {
|
|
8394
|
-
outDir,
|
|
8395
|
-
emitLanguages,
|
|
8396
|
-
typescriptOutputStructure,
|
|
8397
|
-
csharp,
|
|
8398
|
-
generateFixtures,
|
|
8399
|
-
customPomAttachments,
|
|
8400
|
-
customPomDir,
|
|
8401
|
-
requireCustomPomDir,
|
|
8402
|
-
customPomImportAliases,
|
|
8403
|
-
customPomImportNameCollisionBehavior,
|
|
8404
|
-
nameCollisionBehavior,
|
|
8405
|
-
missingSemanticNameBehavior,
|
|
8406
|
-
existingIdBehavior,
|
|
8407
|
-
testIdAttribute,
|
|
8408
|
-
routerAwarePoms,
|
|
8409
|
-
routerType,
|
|
8410
|
-
routerModuleShims
|
|
8411
|
-
} = generation;
|
|
8412
|
-
let scheduleVueFileRegen = null;
|
|
8413
|
-
const getProjectRootCandidates = () => Array.from(/* @__PURE__ */ new Set([
|
|
8414
|
-
path.resolve(projectRootRef.current),
|
|
8415
|
-
path.resolve(process.cwd())
|
|
8211
|
+
function matchesPrimarySelector(extraMethod, pom) {
|
|
8212
|
+
if (extraMethod.selector.kind !== "testId") {
|
|
8213
|
+
return false;
|
|
8214
|
+
}
|
|
8215
|
+
return extraMethod.selector.testId.formatted === pom.selector.formatted && extraMethod.selector.testId.patternKind === pom.selector.patternKind;
|
|
8216
|
+
}
|
|
8217
|
+
function getManifestEntry(componentName, entry, componentMetadata, extraMethods) {
|
|
8218
|
+
const testId = entry.selectorValue.formatted;
|
|
8219
|
+
const metadata = componentMetadata?.get(testId);
|
|
8220
|
+
const pom = entry.pom;
|
|
8221
|
+
const generatedActionName = pom ? buildPomGeneratedActionName(pom) : null;
|
|
8222
|
+
const extraActionNames = pom ? extraMethods.filter((extraMethod) => matchesPrimarySelector(extraMethod, pom)).map((extraMethod) => extraMethod.name).sort((a, b) => a.localeCompare(b)) : [];
|
|
8223
|
+
const generatedActionNames = Array.from(/* @__PURE__ */ new Set([
|
|
8224
|
+
...generatedActionName ? [generatedActionName] : [],
|
|
8225
|
+
...extraActionNames.filter((name) => name !== generatedActionName)
|
|
8416
8226
|
]));
|
|
8417
|
-
const
|
|
8418
|
-
if (path.isAbsolute(maybePath))
|
|
8419
|
-
return maybePath;
|
|
8420
|
-
const candidates = getProjectRootCandidates().map((root) => path.resolve(root, maybePath));
|
|
8421
|
-
return candidates.find((candidate) => fs.existsSync(candidate)) ?? candidates[0];
|
|
8422
|
-
};
|
|
8423
|
-
const getSourceDirRoots = () => Array.from(new Set(
|
|
8424
|
-
getProjectRootCandidates().flatMap((root) => getSourceDirs().map((dir) => path.resolve(root, dir)))
|
|
8425
|
-
));
|
|
8426
|
-
const isContainedInScanDirs = (filePath) => {
|
|
8427
|
-
const absolutePath = path.resolve(filePath);
|
|
8428
|
-
return getSourceDirRoots().some((scanDirAbs) => isPathWithinDir(absolutePath, scanDirAbs));
|
|
8429
|
-
};
|
|
8227
|
+
const accessibility = buildAccessibilityAudit(metadata, pom?.nativeRole ?? null);
|
|
8430
8228
|
return {
|
|
8431
|
-
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8435
|
-
|
|
8436
|
-
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
|
|
8440
|
-
|
|
8441
|
-
|
|
8442
|
-
|
|
8443
|
-
|
|
8444
|
-
|
|
8445
|
-
|
|
8446
|
-
|
|
8447
|
-
|
|
8448
|
-
|
|
8449
|
-
|
|
8450
|
-
|
|
8451
|
-
|
|
8229
|
+
testId,
|
|
8230
|
+
selectorPatternKind: entry.selectorValue.patternKind,
|
|
8231
|
+
semanticName: metadata?.semanticName ?? (pom ? humanizePomMethodName(pom.methodName) : testId),
|
|
8232
|
+
locatorDescription: pom ? buildPomLocatorDescription({
|
|
8233
|
+
componentName,
|
|
8234
|
+
methodName: pom.methodName,
|
|
8235
|
+
nativeRole: pom.nativeRole
|
|
8236
|
+
}) : componentName,
|
|
8237
|
+
inferredRole: pom?.nativeRole ?? null,
|
|
8238
|
+
...accessibility ? { accessibility } : {},
|
|
8239
|
+
generatedPropertyName: pom ? buildPomGeneratedPropertyName(pom) : null,
|
|
8240
|
+
generatedActionName,
|
|
8241
|
+
generatedActionNames,
|
|
8242
|
+
emitPrimary: pom?.emitPrimary !== false,
|
|
8243
|
+
...entry.targetPageObjectModelClass ? { targetPageObjectModelClass: entry.targetPageObjectModelClass } : {},
|
|
8244
|
+
...metadata?.tag ? { sourceTag: metadata.tag } : {},
|
|
8245
|
+
...metadata ? { sourceTagType: metadata.tagType } : {},
|
|
8246
|
+
...metadata?.sourceLine !== void 0 ? { sourceLine: metadata.sourceLine } : {},
|
|
8247
|
+
...metadata?.sourceColumn !== void 0 ? { sourceColumn: metadata.sourceColumn } : {},
|
|
8248
|
+
...metadata?.patchFlag !== void 0 ? { patchFlag: metadata.patchFlag } : {},
|
|
8249
|
+
...metadata?.dynamicProps?.length ? { dynamicProps: metadata.dynamicProps } : {},
|
|
8250
|
+
...metadata?.hasClickHandler !== void 0 ? { hasClickHandler: metadata.hasClickHandler } : {},
|
|
8251
|
+
...metadata?.hasDynamicClass !== void 0 ? { hasDynamicClass: metadata.hasDynamicClass } : {},
|
|
8252
|
+
...metadata?.hasDynamicStyle !== void 0 ? { hasDynamicStyle: metadata.hasDynamicStyle } : {},
|
|
8253
|
+
...metadata?.hasDynamicText !== void 0 ? { hasDynamicText: metadata.hasDynamicText } : {}
|
|
8254
|
+
};
|
|
8255
|
+
}
|
|
8256
|
+
function buildPomManifest(componentHierarchyMap, elementMetadata) {
|
|
8257
|
+
const manifestEntries = Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([componentName, dependencies]) => {
|
|
8258
|
+
const entries = Array.from(dependencies.dataTestIdSet).sort((a, b) => a.selectorValue.formatted.localeCompare(b.selectorValue.formatted)).map((entry) => getManifestEntry(componentName, entry, elementMetadata.get(componentName), dependencies.pomExtraMethods ?? []));
|
|
8259
|
+
if (!entries.length) {
|
|
8260
|
+
return null;
|
|
8261
|
+
}
|
|
8262
|
+
return [componentName, {
|
|
8263
|
+
componentName,
|
|
8264
|
+
className: componentName,
|
|
8265
|
+
sourceFile: dependencies.filePath,
|
|
8266
|
+
kind: dependencies.isView ? "view" : "component",
|
|
8267
|
+
testIds: Array.from(new Set(entries.map((entry) => entry.testId))),
|
|
8268
|
+
entries
|
|
8269
|
+
}];
|
|
8270
|
+
}).filter((entry) => entry !== null);
|
|
8271
|
+
return Object.fromEntries(manifestEntries);
|
|
8272
|
+
}
|
|
8273
|
+
function buildTestIdManifest(componentHierarchyMap) {
|
|
8274
|
+
return Object.fromEntries(
|
|
8275
|
+
Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([componentName, dependencies]) => {
|
|
8276
|
+
const testIds = Array.from(dependencies.dataTestIdSet).map((entry) => entry.selectorValue.formatted).filter(Boolean);
|
|
8277
|
+
if (!testIds.length) {
|
|
8278
|
+
return null;
|
|
8279
|
+
}
|
|
8280
|
+
return [componentName, Array.from(new Set(testIds)).sort((a, b) => a.localeCompare(b))];
|
|
8281
|
+
}).filter((entry) => entry !== null)
|
|
8282
|
+
);
|
|
8283
|
+
}
|
|
8284
|
+
function writeConstJson(value) {
|
|
8285
|
+
return (writer) => {
|
|
8286
|
+
writer.write(`${JSON.stringify(value, null, 2)} as const`);
|
|
8287
|
+
};
|
|
8288
|
+
}
|
|
8289
|
+
function generateTestIdsModule(componentHierarchyMap, elementMetadata) {
|
|
8290
|
+
const pomManifest = buildPomManifest(componentHierarchyMap, elementMetadata);
|
|
8291
|
+
const testIdManifest = buildTestIdManifest(componentHierarchyMap);
|
|
8292
|
+
return renderSourceFile("virtual-testids.ts", (sourceFile) => {
|
|
8293
|
+
sourceFile.addStatements("// Virtual module: test id manifest");
|
|
8294
|
+
sourceFile.addVariableStatement({
|
|
8295
|
+
declarationKind: tsMorph.VariableDeclarationKind.Const,
|
|
8296
|
+
isExported: true,
|
|
8297
|
+
declarations: [{
|
|
8298
|
+
name: "testIdManifest",
|
|
8299
|
+
initializer: writeConstJson(testIdManifest)
|
|
8300
|
+
}]
|
|
8301
|
+
});
|
|
8302
|
+
sourceFile.addVariableStatement({
|
|
8303
|
+
declarationKind: tsMorph.VariableDeclarationKind.Const,
|
|
8304
|
+
isExported: true,
|
|
8305
|
+
declarations: [{
|
|
8306
|
+
name: "pomManifest",
|
|
8307
|
+
initializer: writeConstJson(pomManifest)
|
|
8308
|
+
}]
|
|
8309
|
+
});
|
|
8310
|
+
sourceFile.addTypeAlias({
|
|
8311
|
+
isExported: true,
|
|
8312
|
+
name: "TestIdManifest",
|
|
8313
|
+
type: "typeof testIdManifest"
|
|
8314
|
+
});
|
|
8315
|
+
sourceFile.addTypeAlias({
|
|
8316
|
+
isExported: true,
|
|
8317
|
+
name: "ComponentName",
|
|
8318
|
+
type: "keyof TestIdManifest"
|
|
8319
|
+
});
|
|
8320
|
+
sourceFile.addTypeAlias({
|
|
8321
|
+
isExported: true,
|
|
8322
|
+
name: "PomManifest",
|
|
8323
|
+
type: "typeof pomManifest"
|
|
8324
|
+
});
|
|
8325
|
+
sourceFile.addTypeAlias({
|
|
8326
|
+
isExported: true,
|
|
8327
|
+
name: "PomManifestComponentName",
|
|
8328
|
+
type: "keyof PomManifest"
|
|
8329
|
+
});
|
|
8330
|
+
});
|
|
8331
|
+
}
|
|
8332
|
+
function generatePomManifestModule(componentHierarchyMap, elementMetadata) {
|
|
8333
|
+
const pomManifest = buildPomManifest(componentHierarchyMap, elementMetadata);
|
|
8334
|
+
return renderSourceFile("virtual-pom-manifest.ts", (sourceFile) => {
|
|
8335
|
+
sourceFile.addStatements("// Virtual module: richer POM discoverability manifest");
|
|
8336
|
+
sourceFile.addVariableStatement({
|
|
8337
|
+
declarationKind: tsMorph.VariableDeclarationKind.Const,
|
|
8338
|
+
isExported: true,
|
|
8339
|
+
declarations: [{
|
|
8340
|
+
name: "pomManifest",
|
|
8341
|
+
initializer: writeConstJson(pomManifest)
|
|
8342
|
+
}]
|
|
8343
|
+
});
|
|
8344
|
+
sourceFile.addTypeAlias({
|
|
8345
|
+
isExported: true,
|
|
8346
|
+
name: "PomManifest",
|
|
8347
|
+
type: "typeof pomManifest"
|
|
8348
|
+
});
|
|
8349
|
+
sourceFile.addTypeAlias({
|
|
8350
|
+
isExported: true,
|
|
8351
|
+
name: "PomManifestComponentName",
|
|
8352
|
+
type: "keyof PomManifest"
|
|
8353
|
+
});
|
|
8354
|
+
});
|
|
8355
|
+
}
|
|
8356
|
+
function resolveExistingIdBehavior(config, componentName) {
|
|
8357
|
+
return typeof config === "string" ? config : config.components[componentName] ?? config.default;
|
|
8358
|
+
}
|
|
8359
|
+
function resolveCompilerSfcParse(compilerSfc2) {
|
|
8360
|
+
const parse = compilerSfc2.parse ?? compilerSfc2.default?.parse;
|
|
8361
|
+
if (typeof parse !== "function") {
|
|
8362
|
+
throw new TypeError("[vue-pom-generator] Failed to resolve @vue/compiler-sfc.parse.");
|
|
8363
|
+
}
|
|
8364
|
+
return parse;
|
|
8365
|
+
}
|
|
8366
|
+
function extractMetadataAfterTransform(ast, componentName, elementMetadata, semanticNameMap, testIdAttribute) {
|
|
8367
|
+
const componentMetadata = /* @__PURE__ */ new Map();
|
|
8368
|
+
function traverseNode(node) {
|
|
8369
|
+
if (node.type === compilerCore.NodeTypes.ELEMENT) {
|
|
8370
|
+
const element = node;
|
|
8371
|
+
const testIdAttr = findDataTestIdProp(element, testIdAttribute);
|
|
8372
|
+
if (testIdAttr) {
|
|
8373
|
+
const metadata = tryCreateElementMetadata({
|
|
8374
|
+
element,
|
|
8375
|
+
semanticNameMap,
|
|
8376
|
+
testIdAttribute
|
|
8377
|
+
});
|
|
8378
|
+
if (metadata) {
|
|
8379
|
+
componentMetadata.set(metadata.testId, metadata);
|
|
8452
8380
|
}
|
|
8453
|
-
|
|
8454
|
-
|
|
8455
|
-
|
|
8456
|
-
|
|
8457
|
-
const resolvedRouterEntry = getResolvedRouterEntry();
|
|
8458
|
-
if (!resolvedRouterEntry)
|
|
8459
|
-
throw new Error("[vue-pom-generator] router.entry is required when router introspection is enabled.");
|
|
8460
|
-
result = await parseRouterFileFromCwd(resolvedRouterEntry, {
|
|
8461
|
-
moduleShims: routerModuleShims,
|
|
8462
|
-
componentNaming: {
|
|
8463
|
-
projectRoot: projectRootRef.current,
|
|
8464
|
-
viewsDirAbs: getViewsDirAbs(),
|
|
8465
|
-
sourceDirs: getSourceDirs(),
|
|
8466
|
-
extraRoots: [process.cwd()]
|
|
8467
|
-
}
|
|
8468
|
-
});
|
|
8381
|
+
}
|
|
8382
|
+
if (element.children) {
|
|
8383
|
+
for (const child of element.children) {
|
|
8384
|
+
traverseNode(child);
|
|
8469
8385
|
}
|
|
8470
|
-
|
|
8471
|
-
|
|
8472
|
-
|
|
8473
|
-
|
|
8474
|
-
|
|
8475
|
-
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
|
|
8479
|
-
return routeNameMap.get(key) ?? null;
|
|
8480
|
-
}
|
|
8481
|
-
if (typeof maybe.path === "string" && maybe.path.length) {
|
|
8482
|
-
return routePathMap.get(maybe.path) ?? null;
|
|
8483
|
-
}
|
|
8484
|
-
return null;
|
|
8485
|
-
});
|
|
8486
|
-
})();
|
|
8487
|
-
const logInfo = (message) => loggerRef.current.info(message);
|
|
8488
|
-
const logDebug = (message) => loggerRef.current.debug(message);
|
|
8489
|
-
let scheduleVueFileRegenLocal = null;
|
|
8490
|
-
const formatMs = (ms) => `${ms.toFixed(1)}ms`;
|
|
8491
|
-
const extractTemplateFromSfc = (source, filename) => {
|
|
8492
|
-
const { descriptor } = compilerSfc.parse(source, {
|
|
8493
|
-
filename: filename ?? "anonymous.vue"
|
|
8494
|
-
});
|
|
8495
|
-
return descriptor.template?.content ?? "";
|
|
8496
|
-
};
|
|
8497
|
-
const getScriptInfo = (source, filename) => {
|
|
8498
|
-
try {
|
|
8499
|
-
const { descriptor } = compilerSfc.parse(source, { filename });
|
|
8500
|
-
if (!descriptor.script && !descriptor.scriptSetup)
|
|
8501
|
-
return { bindings: void 0, isScriptSetup: false };
|
|
8502
|
-
const scriptBlock = compilerSfc.compileScript(descriptor, { id: filename });
|
|
8503
|
-
return { bindings: scriptBlock.bindings, isScriptSetup: !!descriptor.scriptSetup };
|
|
8504
|
-
} catch {
|
|
8505
|
-
return { bindings: void 0, isScriptSetup: false };
|
|
8386
|
+
}
|
|
8387
|
+
} else if (node.type === compilerCore.NodeTypes.IF) {
|
|
8388
|
+
for (const branch of node.branches) {
|
|
8389
|
+
traverseNode(branch);
|
|
8390
|
+
}
|
|
8391
|
+
} else if (node.type === compilerCore.NodeTypes.IF_BRANCH || node.type === compilerCore.NodeTypes.FOR) {
|
|
8392
|
+
if (node.children) {
|
|
8393
|
+
for (const child of node.children) {
|
|
8394
|
+
traverseNode(child);
|
|
8506
8395
|
}
|
|
8507
|
-
}
|
|
8508
|
-
|
|
8509
|
-
|
|
8510
|
-
|
|
8511
|
-
|
|
8512
|
-
|
|
8513
|
-
|
|
8514
|
-
|
|
8515
|
-
|
|
8516
|
-
|
|
8517
|
-
|
|
8518
|
-
|
|
8519
|
-
|
|
8520
|
-
|
|
8521
|
-
|
|
8522
|
-
|
|
8523
|
-
|
|
8524
|
-
|
|
8525
|
-
|
|
8526
|
-
|
|
8527
|
-
|
|
8528
|
-
|
|
8529
|
-
|
|
8530
|
-
|
|
8531
|
-
|
|
8532
|
-
|
|
8533
|
-
|
|
8534
|
-
|
|
8535
|
-
|
|
8536
|
-
|
|
8537
|
-
|
|
8538
|
-
|
|
8539
|
-
|
|
8540
|
-
|
|
8541
|
-
|
|
8542
|
-
|
|
8543
|
-
|
|
8544
|
-
|
|
8545
|
-
|
|
8546
|
-
|
|
8547
|
-
|
|
8548
|
-
|
|
8549
|
-
|
|
8550
|
-
|
|
8551
|
-
|
|
8552
|
-
|
|
8553
|
-
|
|
8554
|
-
|
|
8555
|
-
|
|
8556
|
-
|
|
8557
|
-
|
|
8558
|
-
|
|
8559
|
-
|
|
8560
|
-
|
|
8561
|
-
|
|
8562
|
-
|
|
8563
|
-
|
|
8564
|
-
|
|
8565
|
-
|
|
8566
|
-
|
|
8567
|
-
|
|
8568
|
-
|
|
8569
|
-
|
|
8570
|
-
|
|
8571
|
-
|
|
8572
|
-
|
|
8573
|
-
|
|
8574
|
-
|
|
8575
|
-
|
|
8576
|
-
|
|
8577
|
-
|
|
8578
|
-
|
|
8579
|
-
|
|
8580
|
-
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
|
|
8586
|
-
|
|
8587
|
-
filename: absolutePath,
|
|
8588
|
-
prefixIdentifiers: true,
|
|
8589
|
-
inline: isScriptSetup,
|
|
8590
|
-
bindingMetadata,
|
|
8591
|
-
// Vue templates may contain TypeScript type annotations in expressions
|
|
8592
|
-
// (e.g. `@row-click="(row: RowType) => navigateTo(...)"` in Nuxt + TS
|
|
8593
|
-
// apps). Without this flag, Vue's internal processExpression step
|
|
8594
|
-
// delegates to @babel/parser without the TS plugin and crashes on
|
|
8595
|
-
// "Unexpected token, expected ','".
|
|
8596
|
-
expressionPlugins: ["typescript"],
|
|
8597
|
-
nodeTransforms: [
|
|
8396
|
+
}
|
|
8397
|
+
} else if (node.type === compilerCore.NodeTypes.ROOT) {
|
|
8398
|
+
for (const child of node.children) {
|
|
8399
|
+
traverseNode(child);
|
|
8400
|
+
}
|
|
8401
|
+
}
|
|
8402
|
+
}
|
|
8403
|
+
traverseNode(ast);
|
|
8404
|
+
if (componentMetadata.size > 0) {
|
|
8405
|
+
elementMetadata.set(componentName, componentMetadata);
|
|
8406
|
+
}
|
|
8407
|
+
return componentMetadata;
|
|
8408
|
+
}
|
|
8409
|
+
function createVuePluginWithTestIds(options) {
|
|
8410
|
+
const {
|
|
8411
|
+
vueOptions,
|
|
8412
|
+
existingIdBehavior,
|
|
8413
|
+
nameCollisionBehavior,
|
|
8414
|
+
missingSemanticNameBehavior = "error",
|
|
8415
|
+
nativeWrappers,
|
|
8416
|
+
optionKeyAttribute,
|
|
8417
|
+
elementMetadata,
|
|
8418
|
+
semanticNameMap,
|
|
8419
|
+
componentHierarchyMap,
|
|
8420
|
+
crossFileKeyRegistry,
|
|
8421
|
+
vueFilesPathMap,
|
|
8422
|
+
excludedComponents,
|
|
8423
|
+
getViewsDirAbs,
|
|
8424
|
+
testIdAttribute,
|
|
8425
|
+
accessibilityAudit,
|
|
8426
|
+
loggerRef,
|
|
8427
|
+
getSourceDirs,
|
|
8428
|
+
getWrapperSearchRoots,
|
|
8429
|
+
getProjectRoot,
|
|
8430
|
+
annotatorMetadata
|
|
8431
|
+
} = options;
|
|
8432
|
+
const lastAccessibilityWarningSignatureByComponent = /* @__PURE__ */ new Map();
|
|
8433
|
+
const getComponentNameFromPath = (filename) => {
|
|
8434
|
+
return resolveComponentNameFromPath({
|
|
8435
|
+
filename,
|
|
8436
|
+
projectRoot: getProjectRoot(),
|
|
8437
|
+
viewsDirAbs: getViewsDirAbs(),
|
|
8438
|
+
sourceDirs: getSourceDirs(),
|
|
8439
|
+
extraRoots: [process.cwd()]
|
|
8440
|
+
});
|
|
8441
|
+
};
|
|
8442
|
+
const isFileInScope = (filename) => {
|
|
8443
|
+
if (!filename)
|
|
8444
|
+
return false;
|
|
8445
|
+
const cleanPath = filename.includes("?") ? filename.substring(0, filename.indexOf("?")) : filename;
|
|
8446
|
+
const projectRoot = getProjectRoot();
|
|
8447
|
+
const matched = isFileInConfiguredSourceScope({
|
|
8448
|
+
filename,
|
|
8449
|
+
projectRoot,
|
|
8450
|
+
viewsDirAbs: getViewsDirAbs(),
|
|
8451
|
+
sourceDirs: getSourceDirs(),
|
|
8452
|
+
extraRoots: [process.cwd()]
|
|
8453
|
+
});
|
|
8454
|
+
if (cleanPath.endsWith(".vue") && !matched) {
|
|
8455
|
+
const absFilename = path.normalize(path.isAbsolute(cleanPath) ? cleanPath : path.resolve(projectRoot, cleanPath));
|
|
8456
|
+
loggerRef.current.debug(`[isFileInScope] REJECTED: ${absFilename} (Clean: ${cleanPath})`);
|
|
8457
|
+
}
|
|
8458
|
+
return matched;
|
|
8459
|
+
};
|
|
8460
|
+
const userTemplate = vueOptions?.template ?? {};
|
|
8461
|
+
const userCompilerOptions = userTemplate.compilerOptions ?? {};
|
|
8462
|
+
const userNodeTransforms = userCompilerOptions.nodeTransforms ?? [];
|
|
8463
|
+
const perFileTransform = /* @__PURE__ */ new Map();
|
|
8464
|
+
const getNodeTransforms = (filename, componentNameOverride) => {
|
|
8465
|
+
const cleanPath = filename.includes("?") ? filename.substring(0, filename.indexOf("?")) : filename;
|
|
8466
|
+
const viewsDirAbs = getViewsDirAbs();
|
|
8467
|
+
const componentName = componentNameOverride || getComponentNameFromPath(cleanPath);
|
|
8468
|
+
return [
|
|
8469
|
+
...userNodeTransforms,
|
|
8470
|
+
(node, context) => {
|
|
8471
|
+
if (node.type === compilerCore.NodeTypes.ROOT) {
|
|
8472
|
+
componentHierarchyMap.delete(componentName);
|
|
8473
|
+
vueFilesPathMap.set(componentName, filename);
|
|
8474
|
+
perFileTransform.set(
|
|
8475
|
+
componentName,
|
|
8598
8476
|
createTestIdTransform(
|
|
8599
8477
|
componentName,
|
|
8600
|
-
|
|
8478
|
+
componentHierarchyMap,
|
|
8601
8479
|
nativeWrappers,
|
|
8602
8480
|
excludedComponents,
|
|
8603
|
-
|
|
8481
|
+
viewsDirAbs,
|
|
8604
8482
|
{
|
|
8605
|
-
existingIdBehavior: existingIdBehavior
|
|
8483
|
+
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
8484
|
+
testIdAttribute,
|
|
8606
8485
|
nameCollisionBehavior,
|
|
8607
8486
|
missingSemanticNameBehavior,
|
|
8608
|
-
testIdAttribute,
|
|
8609
8487
|
warn: (message) => loggerRef.current.warn(message),
|
|
8610
|
-
vueFilesPathMap
|
|
8488
|
+
vueFilesPathMap,
|
|
8611
8489
|
wrapperSearchRoots: getWrapperSearchRoots(),
|
|
8612
|
-
|
|
8490
|
+
annotatorMetadata,
|
|
8491
|
+
crossFileKeyRegistry,
|
|
8613
8492
|
optionKeyAttribute
|
|
8614
8493
|
}
|
|
8615
8494
|
)
|
|
8616
|
-
|
|
8617
|
-
|
|
8618
|
-
|
|
8619
|
-
|
|
8620
|
-
|
|
8621
|
-
|
|
8622
|
-
|
|
8623
|
-
|
|
8624
|
-
|
|
8625
|
-
|
|
8626
|
-
|
|
8627
|
-
|
|
8628
|
-
|
|
8629
|
-
|
|
8630
|
-
|
|
8631
|
-
|
|
8632
|
-
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
|
|
8640
|
-
|
|
8641
|
-
|
|
8495
|
+
);
|
|
8496
|
+
return () => {
|
|
8497
|
+
const componentMetadata = extractMetadataAfterTransform(
|
|
8498
|
+
node,
|
|
8499
|
+
componentName,
|
|
8500
|
+
elementMetadata,
|
|
8501
|
+
semanticNameMap,
|
|
8502
|
+
testIdAttribute
|
|
8503
|
+
);
|
|
8504
|
+
if (!accessibilityAudit) {
|
|
8505
|
+
return;
|
|
8506
|
+
}
|
|
8507
|
+
const dependencies = componentHierarchyMap.get(componentName);
|
|
8508
|
+
if (!dependencies || componentMetadata.size === 0) {
|
|
8509
|
+
return;
|
|
8510
|
+
}
|
|
8511
|
+
const manifest = buildPomManifest(
|
|
8512
|
+
/* @__PURE__ */ new Map([[componentName, dependencies]]),
|
|
8513
|
+
/* @__PURE__ */ new Map([[componentName, componentMetadata]])
|
|
8514
|
+
);
|
|
8515
|
+
const warnings = collectAccessibilityReviewWarnings(manifest);
|
|
8516
|
+
const signature = warnings.join("\n");
|
|
8517
|
+
if (!signature) {
|
|
8518
|
+
lastAccessibilityWarningSignatureByComponent.delete(componentName);
|
|
8519
|
+
return;
|
|
8520
|
+
}
|
|
8521
|
+
if (lastAccessibilityWarningSignatureByComponent.get(componentName) === signature) {
|
|
8522
|
+
return;
|
|
8523
|
+
}
|
|
8524
|
+
lastAccessibilityWarningSignatureByComponent.set(componentName, signature);
|
|
8525
|
+
for (const warning of warnings) {
|
|
8526
|
+
loggerRef.current.warn(warning);
|
|
8527
|
+
}
|
|
8528
|
+
};
|
|
8642
8529
|
}
|
|
8643
|
-
|
|
8644
|
-
|
|
8645
|
-
|
|
8646
|
-
|
|
8647
|
-
|
|
8648
|
-
|
|
8649
|
-
|
|
8650
|
-
|
|
8651
|
-
|
|
8652
|
-
|
|
8653
|
-
|
|
8654
|
-
|
|
8655
|
-
|
|
8656
|
-
|
|
8657
|
-
|
|
8658
|
-
|
|
8659
|
-
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
componentDirs: getComponentDirs(),
|
|
8665
|
-
layoutDirs: getLayoutDirs(),
|
|
8666
|
-
testIdAttribute,
|
|
8667
|
-
vueRouterFluentChaining: routerAwarePoms,
|
|
8668
|
-
routerEntry: getResolvedRouterEntry(),
|
|
8669
|
-
routerType
|
|
8670
|
-
});
|
|
8671
|
-
const t1 = node_perf_hooks.performance.now();
|
|
8672
|
-
logInfo(`generate(${logLabel}): components=${snapshotHierarchy.size} in ${formatMs(t1 - t0)}`);
|
|
8673
|
-
};
|
|
8674
|
-
let timer = null;
|
|
8675
|
-
let maxWaitTimer = null;
|
|
8676
|
-
const pendingChangedVueFiles = /* @__PURE__ */ new Set();
|
|
8677
|
-
const pendingDeletedComponents = /* @__PURE__ */ new Set();
|
|
8678
|
-
let regenerationSequence = Promise.resolve();
|
|
8679
|
-
const initialBuildPromise = (async () => {
|
|
8680
|
-
const t0 = node_perf_hooks.performance.now();
|
|
8681
|
-
await routerInitPromise;
|
|
8682
|
-
fullRebuildSnapshotFromFilesystem("startup");
|
|
8683
|
-
await generateAggregatedFromSnapshot("startup");
|
|
8684
|
-
const t1 = node_perf_hooks.performance.now();
|
|
8685
|
-
logInfo(`startup total: ${formatMs(t1 - t0)}`);
|
|
8686
|
-
})();
|
|
8687
|
-
const logGenerationError = (reason, message) => {
|
|
8688
|
-
server.config.logger.error(`[vue-pom-generator] dev generation failed during ${reason}: ${message}`);
|
|
8689
|
-
};
|
|
8690
|
-
const regenerateFromPending = async (reason) => {
|
|
8691
|
-
const t0 = node_perf_hooks.performance.now();
|
|
8692
|
-
await initialBuildPromise;
|
|
8693
|
-
const nextHierarchy = new Map(snapshotHierarchy);
|
|
8694
|
-
const nextVuePathMap = new Map(snapshotVuePathMap);
|
|
8695
|
-
for (const componentName of pendingDeletedComponents) {
|
|
8696
|
-
nextHierarchy.delete(componentName);
|
|
8697
|
-
nextVuePathMap.delete(componentName);
|
|
8698
|
-
}
|
|
8699
|
-
const files = Array.from(pendingChangedVueFiles);
|
|
8700
|
-
const deletedCount = pendingDeletedComponents.size;
|
|
8701
|
-
pendingChangedVueFiles.clear();
|
|
8702
|
-
pendingDeletedComponents.clear();
|
|
8703
|
-
let compileMs = 0;
|
|
8704
|
-
for (const f of files) {
|
|
8705
|
-
const res = compileVueFileIntoSnapshot(f, nextHierarchy, nextVuePathMap);
|
|
8706
|
-
compileMs += res.ms;
|
|
8707
|
-
}
|
|
8708
|
-
snapshotHierarchy = nextHierarchy;
|
|
8709
|
-
snapshotVuePathMap = nextVuePathMap;
|
|
8710
|
-
const t1 = node_perf_hooks.performance.now();
|
|
8711
|
-
await generateAggregatedFromSnapshot(reason);
|
|
8712
|
-
const t2 = node_perf_hooks.performance.now();
|
|
8713
|
-
return {
|
|
8714
|
-
files,
|
|
8715
|
-
deletedCount,
|
|
8716
|
-
compileMs,
|
|
8717
|
-
preGenerateMs: t1 - t0,
|
|
8718
|
-
generateMs: t2 - t1,
|
|
8719
|
-
totalMs: t2 - t0
|
|
8720
|
-
};
|
|
8721
|
-
};
|
|
8722
|
-
const enqueueRegeneration = (reason) => {
|
|
8723
|
-
const currentRun = regenerationSequence.catch(() => void 0).then(() => regenerateFromPending(reason));
|
|
8724
|
-
regenerationSequence = currentRun.then(() => void 0, () => void 0);
|
|
8725
|
-
return currentRun;
|
|
8726
|
-
};
|
|
8727
|
-
const runtimeDir = path.dirname(basePageClassPath);
|
|
8728
|
-
const localPluginDir = path.resolve(projectRootRef.current, "vite-plugins", "vue-pom-generator");
|
|
8729
|
-
server.watcher.add([
|
|
8730
|
-
...fs.existsSync(localPluginDir) ? [localPluginDir] : [],
|
|
8731
|
-
basePageClassPath,
|
|
8732
|
-
path.resolve(runtimeDir, "pointer.ts"),
|
|
8733
|
-
path.resolve(runtimeDir, "callout.ts"),
|
|
8734
|
-
path.resolve(runtimeDir, "floating-ui-callout.ts")
|
|
8735
|
-
]);
|
|
8736
|
-
scheduleVueFileRegenLocal = (filePath, source) => {
|
|
8737
|
-
pendingChangedVueFiles.add(filePath);
|
|
8738
|
-
logDebug(`queued(${source}): files=${pendingChangedVueFiles.size} deleted=${pendingDeletedComponents.size}`);
|
|
8739
|
-
scheduleAggregatedRegen();
|
|
8740
|
-
};
|
|
8741
|
-
scheduleVueFileRegen = scheduleVueFileRegenLocal;
|
|
8742
|
-
function scheduleAggregatedRegen() {
|
|
8743
|
-
const wasEmpty = pendingChangedVueFiles.size === 0 && pendingDeletedComponents.size === 0;
|
|
8744
|
-
const MAX_WAIT_MS = 750;
|
|
8745
|
-
if (!maxWaitTimer) {
|
|
8746
|
-
maxWaitTimer = setTimeout(() => {
|
|
8747
|
-
if (timer) {
|
|
8748
|
-
clearTimeout(timer);
|
|
8749
|
-
timer = null;
|
|
8530
|
+
let transform = perFileTransform.get(componentName);
|
|
8531
|
+
if (!transform) {
|
|
8532
|
+
componentHierarchyMap.delete(componentName);
|
|
8533
|
+
vueFilesPathMap.set(componentName, filename);
|
|
8534
|
+
transform = createTestIdTransform(
|
|
8535
|
+
componentName,
|
|
8536
|
+
componentHierarchyMap,
|
|
8537
|
+
nativeWrappers,
|
|
8538
|
+
excludedComponents,
|
|
8539
|
+
viewsDirAbs,
|
|
8540
|
+
{
|
|
8541
|
+
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
8542
|
+
testIdAttribute,
|
|
8543
|
+
nameCollisionBehavior,
|
|
8544
|
+
missingSemanticNameBehavior,
|
|
8545
|
+
warn: (message) => loggerRef.current.warn(message),
|
|
8546
|
+
vueFilesPathMap,
|
|
8547
|
+
wrapperSearchRoots: getWrapperSearchRoots(),
|
|
8548
|
+
annotatorMetadata,
|
|
8549
|
+
crossFileKeyRegistry,
|
|
8550
|
+
optionKeyAttribute
|
|
8750
8551
|
}
|
|
8751
|
-
|
|
8752
|
-
|
|
8753
|
-
logInfo(
|
|
8754
|
-
`max-wait: files=${files.length} deleted=${deletedCount} compile=${formatMs(compileMs)} wall=${formatMs(preGenerateMs)} gen=${formatMs(generateMs)} total=${formatMs(totalMs)}`
|
|
8755
|
-
);
|
|
8756
|
-
}).catch((error) => {
|
|
8757
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
8758
|
-
logGenerationError("max-wait", message);
|
|
8759
|
-
});
|
|
8760
|
-
}, MAX_WAIT_MS);
|
|
8761
|
-
}
|
|
8762
|
-
if (wasEmpty) {
|
|
8763
|
-
const queuedFiles = pendingChangedVueFiles.size;
|
|
8764
|
-
const queuedDeletes = pendingDeletedComponents.size;
|
|
8765
|
-
logDebug(`queued: files=${queuedFiles} deleted=${queuedDeletes}`);
|
|
8552
|
+
);
|
|
8553
|
+
perFileTransform.set(componentName, transform);
|
|
8766
8554
|
}
|
|
8767
|
-
|
|
8768
|
-
clearTimeout(timer);
|
|
8769
|
-
timer = setTimeout(() => {
|
|
8770
|
-
timer = null;
|
|
8771
|
-
if (maxWaitTimer) {
|
|
8772
|
-
clearTimeout(maxWaitTimer);
|
|
8773
|
-
maxWaitTimer = null;
|
|
8774
|
-
}
|
|
8775
|
-
const reason = pendingChangedVueFiles.size || pendingDeletedComponents.size ? "batched" : "noop";
|
|
8776
|
-
void enqueueRegeneration(reason).then(({ files, deletedCount, compileMs, preGenerateMs, generateMs, totalMs }) => {
|
|
8777
|
-
if (files.length || deletedCount) {
|
|
8778
|
-
logInfo(
|
|
8779
|
-
`batched: files=${files.length} deleted=${deletedCount} compile=${formatMs(compileMs)} wall=${formatMs(preGenerateMs)} gen=${formatMs(generateMs)} total=${formatMs(totalMs)}`
|
|
8780
|
-
);
|
|
8781
|
-
}
|
|
8782
|
-
}).catch((error) => {
|
|
8783
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
8784
|
-
logGenerationError(reason, message);
|
|
8785
|
-
});
|
|
8786
|
-
}, 75);
|
|
8555
|
+
return transform(node, context);
|
|
8787
8556
|
}
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
|
|
8791
|
-
|
|
8792
|
-
|
|
8793
|
-
|
|
8794
|
-
if (changedAbsPosix.includes("/vite-plugins/vue-pom-generator/")) {
|
|
8795
|
-
void server.restart();
|
|
8796
|
-
}
|
|
8797
|
-
});
|
|
8798
|
-
server.watcher.on("add", (p) => {
|
|
8799
|
-
if (typeof p !== "string")
|
|
8800
|
-
return;
|
|
8801
|
-
if (!p.endsWith(".vue"))
|
|
8802
|
-
return;
|
|
8803
|
-
if (!isContainedInScanDirs(p))
|
|
8804
|
-
return;
|
|
8805
|
-
void (async () => {
|
|
8806
|
-
await initialBuildPromise;
|
|
8807
|
-
pendingChangedVueFiles.add(p);
|
|
8808
|
-
scheduleAggregatedRegen();
|
|
8809
|
-
})();
|
|
8810
|
-
});
|
|
8811
|
-
server.watcher.on("unlink", (p) => {
|
|
8812
|
-
if (typeof p !== "string")
|
|
8813
|
-
return;
|
|
8814
|
-
if (!p.endsWith(".vue"))
|
|
8815
|
-
return;
|
|
8816
|
-
if (!isContainedInScanDirs(p))
|
|
8817
|
-
return;
|
|
8818
|
-
void (async () => {
|
|
8819
|
-
await initialBuildPromise;
|
|
8820
|
-
const absolutePath = path.resolve(p);
|
|
8821
|
-
const componentName = getComponentNameForFile(absolutePath);
|
|
8822
|
-
filePathToComponentName.delete(absolutePath);
|
|
8823
|
-
pendingDeletedComponents.add(componentName);
|
|
8824
|
-
scheduleAggregatedRegen();
|
|
8825
|
-
})();
|
|
8826
|
-
});
|
|
8827
|
-
setTimeout(() => {
|
|
8828
|
-
}, 250);
|
|
8829
|
-
await initialBuildPromise;
|
|
8557
|
+
];
|
|
8558
|
+
};
|
|
8559
|
+
const runtimeNodeTransform = (node, context) => {
|
|
8560
|
+
const filename = context.filename;
|
|
8561
|
+
if (!filename || !filename.endsWith(".vue") || !isFileInScope(filename)) {
|
|
8562
|
+
return;
|
|
8830
8563
|
}
|
|
8564
|
+
const transforms = getNodeTransforms(filename);
|
|
8565
|
+
const ourTransform = transforms[transforms.length - 1];
|
|
8566
|
+
return ourTransform(node, context);
|
|
8831
8567
|
};
|
|
8832
|
-
|
|
8833
|
-
|
|
8834
|
-
|
|
8835
|
-
|
|
8836
|
-
|
|
8837
|
-
|
|
8838
|
-
|
|
8839
|
-
}
|
|
8840
|
-
const role = normalizePomRoleLabel(inferredRole).toLowerCase();
|
|
8841
|
-
const dynamicProps = new Set(metadata.dynamicProps ?? []);
|
|
8842
|
-
const hasDynamicAccessibleNameSignal = dynamicProps.has("aria-label") || dynamicProps.has("title") || !!metadata.hasDynamicText;
|
|
8843
|
-
let accessibleNameSource;
|
|
8844
|
-
const reasons = [];
|
|
8845
|
-
if (metadata.staticAriaLabel) {
|
|
8846
|
-
accessibleNameSource = "aria-label";
|
|
8847
|
-
} else if (supportsInlineTextAccessibleName(role) && metadata.staticTextContent) {
|
|
8848
|
-
accessibleNameSource = "text";
|
|
8849
|
-
} else if (metadata.staticTitle) {
|
|
8850
|
-
accessibleNameSource = "title";
|
|
8851
|
-
} else if (hasDynamicAccessibleNameSignal) {
|
|
8852
|
-
accessibleNameSource = "dynamic";
|
|
8853
|
-
} else if (role === "input" || role === "select") {
|
|
8854
|
-
accessibleNameSource = "unknown";
|
|
8855
|
-
reasons.push("No inline accessible-name signal was found; the element may rely on external markup such as a separate <label>.");
|
|
8856
|
-
} else {
|
|
8857
|
-
accessibleNameSource = "missing";
|
|
8858
|
-
reasons.push("No compile-time accessible-name signal was found.");
|
|
8859
|
-
}
|
|
8860
|
-
return {
|
|
8861
|
-
needsReview: accessibleNameSource === "unknown" || accessibleNameSource === "missing",
|
|
8862
|
-
accessibleNameSource,
|
|
8863
|
-
reasons,
|
|
8864
|
-
...metadata.staticAriaLabel ? { staticAriaLabel: metadata.staticAriaLabel } : {},
|
|
8865
|
-
...metadata.staticRole ? { staticRole: metadata.staticRole } : {},
|
|
8866
|
-
...metadata.staticTitle ? { staticTitle: metadata.staticTitle } : {},
|
|
8867
|
-
...metadata.staticTextContent ? { staticTextContent: metadata.staticTextContent } : {}
|
|
8568
|
+
const templateCompilerOptions = {
|
|
8569
|
+
...userCompilerOptions,
|
|
8570
|
+
prefixIdentifiers: true,
|
|
8571
|
+
nodeTransforms: [
|
|
8572
|
+
...userNodeTransforms,
|
|
8573
|
+
runtimeNodeTransform
|
|
8574
|
+
]
|
|
8868
8575
|
};
|
|
8869
|
-
|
|
8870
|
-
|
|
8871
|
-
|
|
8872
|
-
|
|
8873
|
-
|
|
8874
|
-
if (!
|
|
8875
|
-
|
|
8576
|
+
const metadataCollectorPlugin = {
|
|
8577
|
+
name: "vue-pom-generator-metadata-collector",
|
|
8578
|
+
enforce: "pre",
|
|
8579
|
+
async transform(code, id) {
|
|
8580
|
+
const cleanPath = id.includes("?") ? id.substring(0, id.indexOf("?")) : id;
|
|
8581
|
+
if (!cleanPath.endsWith(".vue") || !isFileInScope(id)) {
|
|
8582
|
+
return null;
|
|
8876
8583
|
}
|
|
8877
|
-
|
|
8878
|
-
const reasonText = entry.accessibility.reasons.join(" ");
|
|
8879
|
-
warnings.push(
|
|
8880
|
-
`[vue-pom-generator] Accessibility review suggested for ${componentName}.${entryLabel} (role=${entry.inferredRole ?? "unknown"}, testId=${JSON.stringify(entry.testId)}): ${reasonText}`
|
|
8881
|
-
);
|
|
8882
|
-
}
|
|
8883
|
-
}
|
|
8884
|
-
return warnings;
|
|
8885
|
-
}
|
|
8886
|
-
function matchesPrimarySelector(extraMethod, pom) {
|
|
8887
|
-
if (extraMethod.selector.kind !== "testId") {
|
|
8888
|
-
return false;
|
|
8889
|
-
}
|
|
8890
|
-
return extraMethod.selector.testId.formatted === pom.selector.formatted && extraMethod.selector.testId.patternKind === pom.selector.patternKind;
|
|
8891
|
-
}
|
|
8892
|
-
function getManifestEntry(componentName, entry, componentMetadata, extraMethods) {
|
|
8893
|
-
const testId = entry.selectorValue.formatted;
|
|
8894
|
-
const metadata = componentMetadata?.get(testId);
|
|
8895
|
-
const pom = entry.pom;
|
|
8896
|
-
const generatedActionName = pom ? buildPomGeneratedActionName(pom) : null;
|
|
8897
|
-
const extraActionNames = pom ? extraMethods.filter((extraMethod) => matchesPrimarySelector(extraMethod, pom)).map((extraMethod) => extraMethod.name).sort((a, b) => a.localeCompare(b)) : [];
|
|
8898
|
-
const generatedActionNames = Array.from(/* @__PURE__ */ new Set([
|
|
8899
|
-
...generatedActionName ? [generatedActionName] : [],
|
|
8900
|
-
...extraActionNames.filter((name) => name !== generatedActionName)
|
|
8901
|
-
]));
|
|
8902
|
-
const accessibility = buildAccessibilityAudit(metadata, pom?.nativeRole ?? null);
|
|
8903
|
-
return {
|
|
8904
|
-
testId,
|
|
8905
|
-
selectorPatternKind: entry.selectorValue.patternKind,
|
|
8906
|
-
semanticName: metadata?.semanticName ?? (pom ? humanizePomMethodName(pom.methodName) : testId),
|
|
8907
|
-
locatorDescription: pom ? buildPomLocatorDescription({
|
|
8908
|
-
componentName,
|
|
8909
|
-
methodName: pom.methodName,
|
|
8910
|
-
nativeRole: pom.nativeRole
|
|
8911
|
-
}) : componentName,
|
|
8912
|
-
inferredRole: pom?.nativeRole ?? null,
|
|
8913
|
-
...accessibility ? { accessibility } : {},
|
|
8914
|
-
generatedPropertyName: pom ? buildPomGeneratedPropertyName(pom) : null,
|
|
8915
|
-
generatedActionName,
|
|
8916
|
-
generatedActionNames,
|
|
8917
|
-
emitPrimary: pom?.emitPrimary !== false,
|
|
8918
|
-
...entry.targetPageObjectModelClass ? { targetPageObjectModelClass: entry.targetPageObjectModelClass } : {},
|
|
8919
|
-
...metadata?.tag ? { sourceTag: metadata.tag } : {},
|
|
8920
|
-
...metadata ? { sourceTagType: metadata.tagType } : {},
|
|
8921
|
-
...metadata?.sourceLine !== void 0 ? { sourceLine: metadata.sourceLine } : {},
|
|
8922
|
-
...metadata?.sourceColumn !== void 0 ? { sourceColumn: metadata.sourceColumn } : {},
|
|
8923
|
-
...metadata?.patchFlag !== void 0 ? { patchFlag: metadata.patchFlag } : {},
|
|
8924
|
-
...metadata?.dynamicProps?.length ? { dynamicProps: metadata.dynamicProps } : {},
|
|
8925
|
-
...metadata?.hasClickHandler !== void 0 ? { hasClickHandler: metadata.hasClickHandler } : {},
|
|
8926
|
-
...metadata?.hasDynamicClass !== void 0 ? { hasDynamicClass: metadata.hasDynamicClass } : {},
|
|
8927
|
-
...metadata?.hasDynamicStyle !== void 0 ? { hasDynamicStyle: metadata.hasDynamicStyle } : {},
|
|
8928
|
-
...metadata?.hasDynamicText !== void 0 ? { hasDynamicText: metadata.hasDynamicText } : {}
|
|
8929
|
-
};
|
|
8930
|
-
}
|
|
8931
|
-
function buildPomManifest(componentHierarchyMap, elementMetadata) {
|
|
8932
|
-
const manifestEntries = Array.from(componentHierarchyMap.entries()).filter(([componentName, dependencies]) => !shouldSuppressStandaloneWrapperFallbackSurface(componentName, dependencies)).sort((a, b) => a[0].localeCompare(b[0])).map(([componentName, dependencies]) => {
|
|
8933
|
-
const entries = Array.from(dependencies.dataTestIdSet).sort((a, b) => a.selectorValue.formatted.localeCompare(b.selectorValue.formatted)).map((entry) => getManifestEntry(componentName, entry, elementMetadata.get(componentName), dependencies.pomExtraMethods ?? []));
|
|
8934
|
-
if (!entries.length) {
|
|
8935
|
-
return null;
|
|
8936
|
-
}
|
|
8937
|
-
return [componentName, {
|
|
8938
|
-
componentName,
|
|
8939
|
-
className: componentName,
|
|
8940
|
-
sourceFile: dependencies.filePath,
|
|
8941
|
-
kind: dependencies.isView ? "view" : "component",
|
|
8942
|
-
testIds: Array.from(new Set(entries.map((entry) => entry.testId))),
|
|
8943
|
-
entries
|
|
8944
|
-
}];
|
|
8945
|
-
}).filter((entry) => entry !== null);
|
|
8946
|
-
return Object.fromEntries(manifestEntries);
|
|
8947
|
-
}
|
|
8948
|
-
function buildTestIdManifest(componentHierarchyMap) {
|
|
8949
|
-
return Object.fromEntries(
|
|
8950
|
-
Array.from(componentHierarchyMap.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([componentName, dependencies]) => {
|
|
8951
|
-
const testIds = Array.from(dependencies.dataTestIdSet).map((entry) => entry.selectorValue.formatted).filter(Boolean);
|
|
8952
|
-
if (!testIds.length) {
|
|
8584
|
+
if (id !== cleanPath) {
|
|
8953
8585
|
return null;
|
|
8954
8586
|
}
|
|
8955
|
-
|
|
8956
|
-
|
|
8957
|
-
|
|
8958
|
-
|
|
8959
|
-
|
|
8960
|
-
|
|
8961
|
-
|
|
8587
|
+
const componentName = getComponentNameFromPath(cleanPath);
|
|
8588
|
+
loggerRef.current.debug(`Collecting metadata for ${cleanPath} (component: ${componentName})`);
|
|
8589
|
+
const compilerSfc2 = await import("@vue/compiler-sfc");
|
|
8590
|
+
const parse = resolveCompilerSfcParse(compilerSfc2);
|
|
8591
|
+
const compilerDom2 = await import("@vue/compiler-dom");
|
|
8592
|
+
const compile = compilerDom2.compile;
|
|
8593
|
+
const { descriptor } = parse(code, { filename: cleanPath });
|
|
8594
|
+
if (descriptor.template) {
|
|
8595
|
+
const mergedExpressionPlugins = Array.from(
|
|
8596
|
+
/* @__PURE__ */ new Set([
|
|
8597
|
+
"typescript",
|
|
8598
|
+
...userCompilerOptions.expressionPlugins ?? []
|
|
8599
|
+
])
|
|
8600
|
+
);
|
|
8601
|
+
compile(descriptor.template.content, {
|
|
8602
|
+
...userCompilerOptions,
|
|
8603
|
+
filename: cleanPath,
|
|
8604
|
+
expressionPlugins: mergedExpressionPlugins,
|
|
8605
|
+
nodeTransforms: getNodeTransforms(cleanPath, componentName)
|
|
8606
|
+
});
|
|
8607
|
+
loggerRef.current.debug(`Metadata collected for ${cleanPath}`);
|
|
8608
|
+
}
|
|
8609
|
+
return null;
|
|
8610
|
+
}
|
|
8962
8611
|
};
|
|
8963
|
-
|
|
8964
|
-
|
|
8965
|
-
|
|
8966
|
-
|
|
8967
|
-
|
|
8968
|
-
|
|
8969
|
-
|
|
8970
|
-
declarationKind: tsMorph.VariableDeclarationKind.Const,
|
|
8971
|
-
isExported: true,
|
|
8972
|
-
declarations: [{
|
|
8973
|
-
name: "testIdManifest",
|
|
8974
|
-
initializer: writeConstJson(testIdManifest)
|
|
8975
|
-
}]
|
|
8976
|
-
});
|
|
8977
|
-
sourceFile.addVariableStatement({
|
|
8978
|
-
declarationKind: tsMorph.VariableDeclarationKind.Const,
|
|
8979
|
-
isExported: true,
|
|
8980
|
-
declarations: [{
|
|
8981
|
-
name: "pomManifest",
|
|
8982
|
-
initializer: writeConstJson(pomManifest)
|
|
8983
|
-
}]
|
|
8984
|
-
});
|
|
8985
|
-
sourceFile.addTypeAlias({
|
|
8986
|
-
isExported: true,
|
|
8987
|
-
name: "TestIdManifest",
|
|
8988
|
-
type: "typeof testIdManifest"
|
|
8989
|
-
});
|
|
8990
|
-
sourceFile.addTypeAlias({
|
|
8991
|
-
isExported: true,
|
|
8992
|
-
name: "ComponentName",
|
|
8993
|
-
type: "keyof TestIdManifest"
|
|
8994
|
-
});
|
|
8995
|
-
sourceFile.addTypeAlias({
|
|
8996
|
-
isExported: true,
|
|
8997
|
-
name: "PomManifest",
|
|
8998
|
-
type: "typeof pomManifest"
|
|
8999
|
-
});
|
|
9000
|
-
sourceFile.addTypeAlias({
|
|
9001
|
-
isExported: true,
|
|
9002
|
-
name: "PomManifestComponentName",
|
|
9003
|
-
type: "keyof PomManifest"
|
|
9004
|
-
});
|
|
9005
|
-
});
|
|
9006
|
-
}
|
|
9007
|
-
function generatePomManifestModule(componentHierarchyMap, elementMetadata) {
|
|
9008
|
-
const pomManifest = buildPomManifest(componentHierarchyMap, elementMetadata);
|
|
9009
|
-
return renderSourceFile("virtual-pom-manifest.ts", (sourceFile) => {
|
|
9010
|
-
sourceFile.addStatements("// Virtual module: richer POM discoverability manifest");
|
|
9011
|
-
sourceFile.addVariableStatement({
|
|
9012
|
-
declarationKind: tsMorph.VariableDeclarationKind.Const,
|
|
9013
|
-
isExported: true,
|
|
9014
|
-
declarations: [{
|
|
9015
|
-
name: "pomManifest",
|
|
9016
|
-
initializer: writeConstJson(pomManifest)
|
|
9017
|
-
}]
|
|
9018
|
-
});
|
|
9019
|
-
sourceFile.addTypeAlias({
|
|
9020
|
-
isExported: true,
|
|
9021
|
-
name: "PomManifest",
|
|
9022
|
-
type: "typeof pomManifest"
|
|
9023
|
-
});
|
|
9024
|
-
sourceFile.addTypeAlias({
|
|
9025
|
-
isExported: true,
|
|
9026
|
-
name: "PomManifestComponentName",
|
|
9027
|
-
type: "keyof PomManifest"
|
|
9028
|
-
});
|
|
8612
|
+
const template = {
|
|
8613
|
+
...userTemplate,
|
|
8614
|
+
compilerOptions: templateCompilerOptions
|
|
8615
|
+
};
|
|
8616
|
+
const internalVuePlugin = vue({
|
|
8617
|
+
...vueOptions,
|
|
8618
|
+
template
|
|
9029
8619
|
});
|
|
8620
|
+
const nuxtVueBridgePlugin = {
|
|
8621
|
+
name: "vue-pom-generator-nuxt-vue-bridge",
|
|
8622
|
+
apply: "serve",
|
|
8623
|
+
configResolved(config) {
|
|
8624
|
+
const viteVuePlugin = config.plugins.find((plugin) => {
|
|
8625
|
+
return typeof plugin === "object" && plugin !== null && "name" in plugin && plugin.name === "vite:vue" && "api" in plugin;
|
|
8626
|
+
});
|
|
8627
|
+
const api = viteVuePlugin?.api;
|
|
8628
|
+
if (!api) {
|
|
8629
|
+
throw new Error("[vue-pom-generator] Nuxt bridge could not find vite:vue plugin to patch.");
|
|
8630
|
+
}
|
|
8631
|
+
const currentOptions = api.options ?? {};
|
|
8632
|
+
const currentTemplate = currentOptions.template ?? {};
|
|
8633
|
+
const currentCompilerOptions = currentTemplate.compilerOptions ?? {};
|
|
8634
|
+
const currentNodeTransforms = currentCompilerOptions.nodeTransforms ?? [];
|
|
8635
|
+
if (currentNodeTransforms.includes(runtimeNodeTransform)) {
|
|
8636
|
+
return;
|
|
8637
|
+
}
|
|
8638
|
+
api.options = {
|
|
8639
|
+
...currentOptions,
|
|
8640
|
+
template: {
|
|
8641
|
+
...currentTemplate,
|
|
8642
|
+
compilerOptions: {
|
|
8643
|
+
...currentCompilerOptions,
|
|
8644
|
+
prefixIdentifiers: true,
|
|
8645
|
+
nodeTransforms: [
|
|
8646
|
+
...currentNodeTransforms,
|
|
8647
|
+
runtimeNodeTransform
|
|
8648
|
+
]
|
|
8649
|
+
}
|
|
8650
|
+
}
|
|
8651
|
+
};
|
|
8652
|
+
}
|
|
8653
|
+
};
|
|
8654
|
+
return { metadataCollectorPlugin, internalVuePlugin, nuxtVueBridgePlugin, templateCompilerOptions };
|
|
9030
8655
|
}
|
|
9031
|
-
|
|
9032
|
-
|
|
9033
|
-
|
|
9034
|
-
const
|
|
9035
|
-
|
|
9036
|
-
|
|
9037
|
-
|
|
9038
|
-
|
|
9039
|
-
if (id === TEST_IDS_VIRTUAL_ID)
|
|
9040
|
-
return TEST_IDS_RESOLVED_ID;
|
|
9041
|
-
if (id === POM_MANIFEST_VIRTUAL_ID)
|
|
9042
|
-
return POM_MANIFEST_RESOLVED_ID;
|
|
9043
|
-
},
|
|
9044
|
-
load(id) {
|
|
9045
|
-
if (id === TEST_IDS_RESOLVED_ID)
|
|
9046
|
-
return generateTestIdsModule(componentHierarchyMap, elementMetadata);
|
|
9047
|
-
if (id === POM_MANIFEST_RESOLVED_ID)
|
|
9048
|
-
return generatePomManifestModule(componentHierarchyMap, elementMetadata);
|
|
8656
|
+
function summarizeHierarchyMap(componentHierarchyMap) {
|
|
8657
|
+
let interactiveComponentCount = 0;
|
|
8658
|
+
let dataTestIdCount = 0;
|
|
8659
|
+
for (const dependencies of componentHierarchyMap.values()) {
|
|
8660
|
+
const selectorCount = dependencies.dataTestIdSet?.size ?? 0;
|
|
8661
|
+
if (selectorCount > 0) {
|
|
8662
|
+
interactiveComponentCount += 1;
|
|
8663
|
+
dataTestIdCount += selectorCount;
|
|
9049
8664
|
}
|
|
8665
|
+
}
|
|
8666
|
+
return {
|
|
8667
|
+
entryCount: componentHierarchyMap.size,
|
|
8668
|
+
interactiveComponentCount,
|
|
8669
|
+
dataTestIdCount
|
|
9050
8670
|
};
|
|
9051
8671
|
}
|
|
9052
|
-
|
|
9053
|
-
|
|
9054
|
-
|
|
9055
|
-
|
|
9056
|
-
|
|
9057
|
-
|
|
9058
|
-
|
|
9059
|
-
|
|
9060
|
-
];
|
|
9061
|
-
function normalizePathSeparators(filePath) {
|
|
9062
|
-
return filePath.replace(/\\/g, "/");
|
|
8672
|
+
function isLessRich(candidate, previous) {
|
|
8673
|
+
if (candidate.dataTestIdCount !== previous.dataTestIdCount) {
|
|
8674
|
+
return candidate.dataTestIdCount < previous.dataTestIdCount;
|
|
8675
|
+
}
|
|
8676
|
+
if (candidate.interactiveComponentCount !== previous.interactiveComponentCount) {
|
|
8677
|
+
return candidate.interactiveComponentCount < previous.interactiveComponentCount;
|
|
8678
|
+
}
|
|
8679
|
+
return candidate.entryCount < previous.entryCount;
|
|
9063
8680
|
}
|
|
9064
|
-
function
|
|
9065
|
-
return `/@fs/${normalizePathSeparators(filePath)}`;
|
|
9066
|
-
}
|
|
9067
|
-
function resolveAnnotatorClientPath() {
|
|
9068
|
-
const candidates = [
|
|
9069
|
-
node_url.fileURLToPath(new URL("./client.ts", typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href)),
|
|
9070
|
-
node_url.fileURLToPath(new URL("../plugin/runtime/annotator/client.ts", typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href))
|
|
9071
|
-
];
|
|
9072
|
-
const resolved = candidates.find((candidate) => fs.existsSync(candidate));
|
|
9073
|
-
if (!resolved) {
|
|
9074
|
-
throw new Error("[vue-pom-generator] Unable to locate annotator client source.");
|
|
9075
|
-
}
|
|
9076
|
-
return path.resolve(resolved);
|
|
9077
|
-
}
|
|
9078
|
-
function createAnnotatorUiPlugin(options) {
|
|
9079
|
-
const clientPath = resolveAnnotatorClientPath();
|
|
9080
|
-
const clientImportPath = toFsImportPath(clientPath);
|
|
9081
|
-
const clientOptions = JSON.stringify({
|
|
9082
|
-
sourceAttribute: options.sourceAttribute,
|
|
9083
|
-
metadataAttributePrefix: options.metadataAttributePrefix,
|
|
9084
|
-
outputDetail: options.outputDetail,
|
|
9085
|
-
copyToClipboard: options.copyToClipboard,
|
|
9086
|
-
showComponentTree: options.showComponentTree
|
|
9087
|
-
});
|
|
9088
|
-
return {
|
|
9089
|
-
name: "vue-pom-generator:annotator-ui",
|
|
9090
|
-
apply: "serve",
|
|
9091
|
-
resolveId(id) {
|
|
9092
|
-
if (id === ANNOTATOR_CLIENT_VIRTUAL_ID) {
|
|
9093
|
-
return ANNOTATOR_CLIENT_RESOLVED_ID;
|
|
9094
|
-
}
|
|
9095
|
-
},
|
|
9096
|
-
load(id) {
|
|
9097
|
-
if (id !== ANNOTATOR_CLIENT_RESOLVED_ID) {
|
|
9098
|
-
return null;
|
|
9099
|
-
}
|
|
9100
|
-
return [
|
|
9101
|
-
`import { mountAnnotatorClient } from ${JSON.stringify(clientImportPath)};`,
|
|
9102
|
-
`mountAnnotatorClient(${clientOptions});`,
|
|
9103
|
-
""
|
|
9104
|
-
].join("\n");
|
|
9105
|
-
},
|
|
9106
|
-
transform(code, id) {
|
|
9107
|
-
if (!options.enabled) {
|
|
9108
|
-
return null;
|
|
9109
|
-
}
|
|
9110
|
-
const normalizedId = normalizePathSeparators(id);
|
|
9111
|
-
if (!DEFAULT_ENTRY_SUFFIXES.some((suffix) => normalizedId.endsWith(suffix))) {
|
|
9112
|
-
return null;
|
|
9113
|
-
}
|
|
9114
|
-
if (code.includes(ANNOTATOR_CLIENT_VIRTUAL_ID)) {
|
|
9115
|
-
return null;
|
|
9116
|
-
}
|
|
9117
|
-
return {
|
|
9118
|
-
code: `import ${JSON.stringify(ANNOTATOR_CLIENT_VIRTUAL_ID)};
|
|
9119
|
-
${code}`,
|
|
9120
|
-
map: null
|
|
9121
|
-
};
|
|
9122
|
-
},
|
|
9123
|
-
transformIndexHtml() {
|
|
9124
|
-
if (!options.enabled) {
|
|
9125
|
-
return void 0;
|
|
9126
|
-
}
|
|
9127
|
-
const tag = {
|
|
9128
|
-
tag: "script",
|
|
9129
|
-
attrs: { type: "module" },
|
|
9130
|
-
children: `import ${JSON.stringify(ANNOTATOR_CLIENT_VIRTUAL_ID)};`,
|
|
9131
|
-
injectTo: "body"
|
|
9132
|
-
};
|
|
9133
|
-
return [tag];
|
|
9134
|
-
}
|
|
9135
|
-
};
|
|
9136
|
-
}
|
|
9137
|
-
function createInternalPlugins(options) {
|
|
8681
|
+
function createBuildProcessorPlugin(options) {
|
|
9138
8682
|
const {
|
|
9139
8683
|
componentHierarchyMap,
|
|
9140
8684
|
crossFileKeyRegistry,
|
|
9141
|
-
elementMetadata,
|
|
9142
8685
|
vueFilesPathMap,
|
|
9143
|
-
nativeWrappers,
|
|
9144
|
-
optionKeyAttribute,
|
|
9145
|
-
excludedComponents,
|
|
9146
8686
|
getPageDirs,
|
|
9147
8687
|
getComponentDirs,
|
|
9148
8688
|
getLayoutDirs,
|
|
9149
8689
|
getViewsDir,
|
|
9150
8690
|
getSourceDirs,
|
|
9151
|
-
|
|
8691
|
+
basePageClassPath,
|
|
8692
|
+
normalizedBasePagePath,
|
|
9152
8693
|
generation,
|
|
9153
8694
|
projectRootRef,
|
|
9154
|
-
|
|
9155
|
-
|
|
9156
|
-
|
|
8695
|
+
nativeWrappers,
|
|
8696
|
+
optionKeyAttribute,
|
|
8697
|
+
excludedComponents,
|
|
8698
|
+
getWrapperSearchRoots,
|
|
8699
|
+
getResolvedRouterEntry,
|
|
8700
|
+
loggerRef
|
|
9157
8701
|
} = options;
|
|
9158
8702
|
const {
|
|
8703
|
+
outDir,
|
|
8704
|
+
emitLanguages,
|
|
8705
|
+
typescriptOutputStructure,
|
|
8706
|
+
csharp,
|
|
8707
|
+
generateFixtures,
|
|
8708
|
+
customPomAttachments,
|
|
8709
|
+
customPomDir,
|
|
8710
|
+
requireCustomPomDir,
|
|
8711
|
+
customPomImportAliases,
|
|
8712
|
+
customPomImportNameCollisionBehavior,
|
|
8713
|
+
testIdAttribute,
|
|
8714
|
+
nameCollisionBehavior,
|
|
8715
|
+
missingSemanticNameBehavior,
|
|
8716
|
+
existingIdBehavior,
|
|
9159
8717
|
routerAwarePoms,
|
|
9160
|
-
|
|
9161
|
-
|
|
8718
|
+
routerType,
|
|
8719
|
+
routerModuleShims
|
|
9162
8720
|
} = generation;
|
|
9163
|
-
|
|
9164
|
-
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
return void 0;
|
|
9168
|
-
if (!routerEntry)
|
|
9169
|
-
throw new Error("[vue-pom-generator] router.entry is required when router introspection is enabled.");
|
|
9170
|
-
return path.isAbsolute(routerEntry) ? routerEntry : path.resolve(projectRootRef.current, routerEntry);
|
|
8721
|
+
let lastGeneratedMetrics = {
|
|
8722
|
+
entryCount: 0,
|
|
8723
|
+
interactiveComponentCount: 0,
|
|
8724
|
+
dataTestIdCount: 0
|
|
9171
8725
|
};
|
|
9172
|
-
const
|
|
8726
|
+
const getViewsDirAbs = () => path.isAbsolute(getViewsDir()) ? getViewsDir() : path.resolve(projectRootRef.current, getViewsDir());
|
|
8727
|
+
const getPageDirsAbs = () => getPageDirs().map((dir) => path.isAbsolute(dir) ? dir : path.resolve(projectRootRef.current, dir));
|
|
8728
|
+
const getScriptInfo = (source, filename) => {
|
|
9173
8729
|
try {
|
|
9174
|
-
|
|
8730
|
+
const { descriptor } = compilerSfc.parse(source, { filename });
|
|
8731
|
+
if (!descriptor.script && !descriptor.scriptSetup)
|
|
8732
|
+
return { bindings: void 0, isScriptSetup: false };
|
|
8733
|
+
const scriptBlock = compilerSfc.compileScript(descriptor, { id: filename });
|
|
8734
|
+
return { bindings: scriptBlock.bindings, isScriptSetup: !!descriptor.scriptSetup };
|
|
9175
8735
|
} catch {
|
|
9176
|
-
return
|
|
8736
|
+
return { bindings: void 0, isScriptSetup: false };
|
|
9177
8737
|
}
|
|
9178
8738
|
};
|
|
9179
|
-
const
|
|
9180
|
-
|
|
9181
|
-
|
|
9182
|
-
|
|
9183
|
-
|
|
9184
|
-
|
|
9185
|
-
|
|
9186
|
-
|
|
9187
|
-
|
|
9188
|
-
|
|
9189
|
-
|
|
9190
|
-
|
|
9191
|
-
|
|
9192
|
-
|
|
9193
|
-
|
|
9194
|
-
|
|
9195
|
-
|
|
9196
|
-
|
|
9197
|
-
|
|
9198
|
-
|
|
9199
|
-
|
|
9200
|
-
|
|
9201
|
-
|
|
9202
|
-
|
|
9203
|
-
optionKeyAttribute,
|
|
9204
|
-
excludedComponents,
|
|
9205
|
-
getPageDirs,
|
|
9206
|
-
getComponentDirs,
|
|
9207
|
-
getLayoutDirs,
|
|
9208
|
-
getViewsDir,
|
|
9209
|
-
getSourceDirs,
|
|
9210
|
-
getWrapperSearchRoots,
|
|
9211
|
-
projectRootRef,
|
|
9212
|
-
normalizedBasePagePath,
|
|
9213
|
-
basePageClassPath,
|
|
9214
|
-
generation,
|
|
9215
|
-
getResolvedRouterEntry: resolveRouterEntry2,
|
|
9216
|
-
loggerRef
|
|
9217
|
-
});
|
|
9218
|
-
const virtualModules = createTestIdsVirtualModulesPlugin(componentHierarchyMap, elementMetadata);
|
|
9219
|
-
const annotatorUiPlugin = createAnnotatorUiPlugin({
|
|
9220
|
-
...annotatorRuntime.ui,
|
|
9221
|
-
enabled: annotatorRuntime.enabled && annotatorRuntime.ui.enabled,
|
|
9222
|
-
sourceAttribute: annotatorRuntime.sourceAttribute,
|
|
9223
|
-
metadataAttributePrefix: annotatorRuntime.metadataAttributePrefix
|
|
9224
|
-
});
|
|
9225
|
-
return [tsProcessor, devProcessor, virtualModules, annotatorUiPlugin];
|
|
9226
|
-
}
|
|
9227
|
-
function findDataTestIdProp(element, attributeName = "data-testid") {
|
|
9228
|
-
return element.props.find(
|
|
9229
|
-
(prop) => prop.type === compilerCore.NodeTypes.ATTRIBUTE && prop.name === attributeName || prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === attributeName
|
|
9230
|
-
);
|
|
9231
|
-
}
|
|
9232
|
-
function getTestIdFromProp(prop) {
|
|
9233
|
-
if (!prop) {
|
|
9234
|
-
return null;
|
|
9235
|
-
}
|
|
9236
|
-
if (prop.type === compilerCore.NodeTypes.ATTRIBUTE) {
|
|
9237
|
-
return prop.value ? prop.value.content : null;
|
|
9238
|
-
}
|
|
9239
|
-
if (prop.type === compilerCore.NodeTypes.DIRECTIVE) {
|
|
9240
|
-
return prop.exp?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION ? prop.exp.content : null;
|
|
9241
|
-
}
|
|
9242
|
-
return null;
|
|
9243
|
-
}
|
|
9244
|
-
function parseDynamicProps(dynamicProps) {
|
|
9245
|
-
if (!dynamicProps) {
|
|
9246
|
-
return void 0;
|
|
9247
|
-
}
|
|
9248
|
-
if (typeof dynamicProps === "string") {
|
|
9249
|
-
const parts = [];
|
|
9250
|
-
let current = "";
|
|
9251
|
-
for (let i = 0; i < dynamicProps.length; i++) {
|
|
9252
|
-
const ch = dynamicProps[i];
|
|
9253
|
-
if (ch === ",") {
|
|
9254
|
-
const token = current.trim();
|
|
9255
|
-
if (token.length)
|
|
9256
|
-
parts.push(token);
|
|
9257
|
-
current = "";
|
|
9258
|
-
continue;
|
|
9259
|
-
}
|
|
9260
|
-
current += ch;
|
|
9261
|
-
}
|
|
9262
|
-
const last = current.trim();
|
|
9263
|
-
if (last.length)
|
|
9264
|
-
parts.push(last);
|
|
9265
|
-
return parts;
|
|
9266
|
-
}
|
|
9267
|
-
if (isSimpleExpressionNode(dynamicProps)) {
|
|
9268
|
-
const content = dynamicProps.content;
|
|
9269
|
-
if (content.startsWith("[") && content.endsWith("]")) {
|
|
9270
|
-
try {
|
|
9271
|
-
return JSON.parse(content);
|
|
9272
|
-
} catch {
|
|
9273
|
-
return void 0;
|
|
8739
|
+
const supplementHierarchyFromFilesystem = () => {
|
|
8740
|
+
const walkFilesRecursive = (rootDir) => {
|
|
8741
|
+
const out = [];
|
|
8742
|
+
const stack = [rootDir];
|
|
8743
|
+
while (stack.length) {
|
|
8744
|
+
const dir = stack.pop();
|
|
8745
|
+
if (!dir) continue;
|
|
8746
|
+
let entries = [];
|
|
8747
|
+
try {
|
|
8748
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
8749
|
+
} catch {
|
|
8750
|
+
continue;
|
|
8751
|
+
}
|
|
8752
|
+
for (const ent of entries) {
|
|
8753
|
+
if (ent.isDirectory()) {
|
|
8754
|
+
if (ent.name === "node_modules" || ent.name === ".git" || ent.name === "dist")
|
|
8755
|
+
continue;
|
|
8756
|
+
stack.push(path.join(dir, ent.name));
|
|
8757
|
+
continue;
|
|
8758
|
+
}
|
|
8759
|
+
if (ent.isFile() && ent.name.endsWith(".vue")) {
|
|
8760
|
+
out.push(path.join(dir, ent.name));
|
|
8761
|
+
}
|
|
8762
|
+
}
|
|
9274
8763
|
}
|
|
9275
|
-
|
|
9276
|
-
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
const attribute = element.props.find(
|
|
9282
|
-
(prop) => prop.type === compilerCore.NodeTypes.ATTRIBUTE && prop.name === attributeName
|
|
9283
|
-
);
|
|
9284
|
-
const value = attribute?.value?.content?.trim();
|
|
9285
|
-
return value || void 0;
|
|
9286
|
-
}
|
|
9287
|
-
function collectStaticTextContent(children) {
|
|
9288
|
-
const parts = [];
|
|
9289
|
-
const visit = (nodes) => {
|
|
9290
|
-
for (const node of nodes) {
|
|
9291
|
-
if (node.type === compilerCore.NodeTypes.TEXT) {
|
|
9292
|
-
const text2 = collapseWhitespace(node.content);
|
|
9293
|
-
if (text2) {
|
|
9294
|
-
parts.push(text2);
|
|
9295
|
-
}
|
|
8764
|
+
return out;
|
|
8765
|
+
};
|
|
8766
|
+
let supplemented = 0;
|
|
8767
|
+
for (const dir of getSourceDirs()) {
|
|
8768
|
+
const absDir = path.resolve(projectRootRef.current, dir);
|
|
8769
|
+
if (!fs.existsSync(absDir))
|
|
9296
8770
|
continue;
|
|
9297
|
-
|
|
9298
|
-
|
|
9299
|
-
|
|
8771
|
+
for (const filePath of walkFilesRecursive(absDir)) {
|
|
8772
|
+
const absolutePath = path.resolve(filePath);
|
|
8773
|
+
const componentName = resolveComponentNameFromPath({
|
|
8774
|
+
filename: absolutePath,
|
|
8775
|
+
projectRoot: projectRootRef.current,
|
|
8776
|
+
viewsDirAbs: getViewsDirAbs(),
|
|
8777
|
+
sourceDirs: getSourceDirs(),
|
|
8778
|
+
extraRoots: [process.cwd()]
|
|
8779
|
+
});
|
|
8780
|
+
if (componentHierarchyMap.has(componentName))
|
|
8781
|
+
continue;
|
|
8782
|
+
let sfc = "";
|
|
8783
|
+
try {
|
|
8784
|
+
sfc = fs.readFileSync(absolutePath, "utf8");
|
|
8785
|
+
} catch {
|
|
8786
|
+
continue;
|
|
8787
|
+
}
|
|
8788
|
+
const { descriptor } = compilerSfc.parse(sfc, { filename: absolutePath });
|
|
8789
|
+
const template = descriptor.template?.content ?? "";
|
|
8790
|
+
if (!template.trim()) {
|
|
8791
|
+
vueFilesPathMap.set(componentName, absolutePath);
|
|
8792
|
+
componentHierarchyMap.set(componentName, {
|
|
8793
|
+
filePath: absolutePath,
|
|
8794
|
+
childrenComponentSet: /* @__PURE__ */ new Set(),
|
|
8795
|
+
usedComponentSet: /* @__PURE__ */ new Set(),
|
|
8796
|
+
dataTestIdSet: /* @__PURE__ */ new Set(),
|
|
8797
|
+
isView: false,
|
|
8798
|
+
methodsContent: ""
|
|
8799
|
+
});
|
|
8800
|
+
supplemented++;
|
|
8801
|
+
continue;
|
|
8802
|
+
}
|
|
8803
|
+
const { bindings: bindingMetadata, isScriptSetup } = getScriptInfo(sfc, absolutePath);
|
|
8804
|
+
vueFilesPathMap.set(componentName, absolutePath);
|
|
8805
|
+
try {
|
|
8806
|
+
compilerDom__namespace.compile(template, {
|
|
8807
|
+
filename: absolutePath,
|
|
8808
|
+
prefixIdentifiers: true,
|
|
8809
|
+
inline: isScriptSetup,
|
|
8810
|
+
bindingMetadata,
|
|
8811
|
+
// See dev-plugin.ts — same rationale: enable TS in template
|
|
8812
|
+
// expressions so `(row: RowType) => ...` handlers parse.
|
|
8813
|
+
expressionPlugins: ["typescript"],
|
|
8814
|
+
nodeTransforms: [
|
|
8815
|
+
createTestIdTransform(
|
|
8816
|
+
componentName,
|
|
8817
|
+
componentHierarchyMap,
|
|
8818
|
+
nativeWrappers,
|
|
8819
|
+
excludedComponents,
|
|
8820
|
+
getViewsDirAbs(),
|
|
8821
|
+
{
|
|
8822
|
+
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
8823
|
+
testIdAttribute,
|
|
8824
|
+
nameCollisionBehavior,
|
|
8825
|
+
missingSemanticNameBehavior,
|
|
8826
|
+
warn: (message) => loggerRef.current.warn(message),
|
|
8827
|
+
vueFilesPathMap,
|
|
8828
|
+
wrapperSearchRoots: getWrapperSearchRoots(),
|
|
8829
|
+
crossFileKeyRegistry,
|
|
8830
|
+
optionKeyAttribute
|
|
8831
|
+
}
|
|
8832
|
+
)
|
|
8833
|
+
]
|
|
8834
|
+
});
|
|
8835
|
+
} catch {
|
|
8836
|
+
}
|
|
8837
|
+
supplemented++;
|
|
9300
8838
|
}
|
|
9301
8839
|
}
|
|
9302
|
-
|
|
9303
|
-
|
|
9304
|
-
const text = collapseWhitespace(parts.join(" "));
|
|
9305
|
-
return text || void 0;
|
|
9306
|
-
}
|
|
9307
|
-
function tryCreateElementMetadata(args) {
|
|
9308
|
-
const { element, semanticNameMap } = args;
|
|
9309
|
-
const testIdAttribute = (args.testIdAttribute ?? "data-testid").trim() || "data-testid";
|
|
9310
|
-
const testIdProp = findDataTestIdProp(element, testIdAttribute);
|
|
9311
|
-
if (!testIdProp) {
|
|
9312
|
-
return null;
|
|
9313
|
-
}
|
|
9314
|
-
const testId = getTestIdFromProp(testIdProp);
|
|
9315
|
-
if (!testId) {
|
|
9316
|
-
return null;
|
|
9317
|
-
}
|
|
9318
|
-
if (!element.codegenNode || element.codegenNode.type !== compilerCore.NodeTypes.VNODE_CALL) {
|
|
9319
|
-
return null;
|
|
9320
|
-
}
|
|
9321
|
-
const codegenNode = element.codegenNode;
|
|
9322
|
-
const patchFlag = codegenNode.patchFlag;
|
|
9323
|
-
let dynamicPropsList = parseDynamicProps(codegenNode.dynamicProps);
|
|
9324
|
-
if (!dynamicPropsList && codegenNode.dynamicProps && typeof codegenNode.dynamicProps !== "string" && isSimpleExpressionNode(codegenNode.dynamicProps)) {
|
|
9325
|
-
const content = codegenNode.dynamicProps.content;
|
|
9326
|
-
if (content.startsWith("[") && content.endsWith("]")) {
|
|
9327
|
-
dynamicPropsList = [content];
|
|
8840
|
+
if (supplemented > 0) {
|
|
8841
|
+
loggerRef.current.info(`supplemented ${supplemented} components from filesystem walk (not in build graph)`);
|
|
9328
8842
|
}
|
|
9329
|
-
}
|
|
9330
|
-
const metadata = {
|
|
9331
|
-
testId,
|
|
9332
|
-
semanticName: semanticNameMap.get(testId),
|
|
9333
|
-
tag: element.tag,
|
|
9334
|
-
tagType: element.tagType,
|
|
9335
|
-
patchFlag,
|
|
9336
|
-
dynamicProps: dynamicPropsList,
|
|
9337
|
-
// Decode patch flags (bitwise) - preserved as-is from existing code.
|
|
9338
|
-
hasClickHandler: patchFlag ? Boolean(patchFlag & 32) : void 0,
|
|
9339
|
-
hasDynamicClass: patchFlag ? Boolean(patchFlag & 2) : void 0,
|
|
9340
|
-
hasDynamicStyle: patchFlag ? Boolean(patchFlag & 4) : void 0,
|
|
9341
|
-
hasDynamicText: patchFlag ? Boolean(patchFlag & 1) : void 0,
|
|
9342
|
-
staticAriaLabel: findStaticAttributeValue(element, "aria-label"),
|
|
9343
|
-
staticRole: findStaticAttributeValue(element, "role"),
|
|
9344
|
-
staticTitle: findStaticAttributeValue(element, "title"),
|
|
9345
|
-
staticTextContent: collectStaticTextContent(element.children),
|
|
9346
|
-
sourceLine: element.loc?.start.line,
|
|
9347
|
-
sourceColumn: element.loc?.start.column
|
|
9348
8843
|
};
|
|
9349
|
-
return
|
|
9350
|
-
|
|
9351
|
-
|
|
9352
|
-
|
|
9353
|
-
|
|
9354
|
-
|
|
9355
|
-
|
|
9356
|
-
|
|
9357
|
-
|
|
9358
|
-
|
|
9359
|
-
|
|
9360
|
-
|
|
9361
|
-
|
|
9362
|
-
|
|
9363
|
-
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
|
|
9367
|
-
|
|
9368
|
-
|
|
8844
|
+
return {
|
|
8845
|
+
name: "vue-pom-generator-build",
|
|
8846
|
+
// This plugin exists to generate code on build output; it is not needed during dev-server HMR.
|
|
8847
|
+
apply: "build",
|
|
8848
|
+
enforce: "pre",
|
|
8849
|
+
async buildStart() {
|
|
8850
|
+
if (!routerAwarePoms) {
|
|
8851
|
+
setRouteNameToComponentNameMap(/* @__PURE__ */ new Map());
|
|
8852
|
+
setResolveToComponentNameFn(() => null);
|
|
8853
|
+
return;
|
|
8854
|
+
}
|
|
8855
|
+
let result;
|
|
8856
|
+
if (routerType === "nuxt") {
|
|
8857
|
+
result = await introspectNuxtPages(projectRootRef.current, { pageDirs: getPageDirsAbs() });
|
|
8858
|
+
} else {
|
|
8859
|
+
const resolvedRouterEntry = getResolvedRouterEntry();
|
|
8860
|
+
if (!resolvedRouterEntry)
|
|
8861
|
+
throw new Error("[vue-pom-generator] router.entry is required when router introspection is enabled.");
|
|
8862
|
+
result = await parseRouterFileFromCwd(resolvedRouterEntry, {
|
|
8863
|
+
moduleShims: routerModuleShims,
|
|
8864
|
+
componentNaming: {
|
|
8865
|
+
projectRoot: projectRootRef.current,
|
|
8866
|
+
viewsDirAbs: getViewsDirAbs(),
|
|
8867
|
+
sourceDirs: getSourceDirs()
|
|
8868
|
+
}
|
|
9369
8869
|
});
|
|
9370
|
-
|
|
9371
|
-
|
|
8870
|
+
}
|
|
8871
|
+
const { routeNameMap, routePathMap } = result;
|
|
8872
|
+
setRouteNameToComponentNameMap(routeNameMap);
|
|
8873
|
+
setResolveToComponentNameFn((to) => {
|
|
8874
|
+
if (typeof to === "string") {
|
|
8875
|
+
return routePathMap.get(to) ?? null;
|
|
8876
|
+
}
|
|
8877
|
+
const maybe = to;
|
|
8878
|
+
if (typeof maybe.name === "string" && maybe.name.length) {
|
|
8879
|
+
const key = toPascalCase(maybe.name);
|
|
8880
|
+
return routeNameMap.get(key) ?? null;
|
|
8881
|
+
}
|
|
8882
|
+
if (typeof maybe.path === "string" && maybe.path.length) {
|
|
8883
|
+
return routePathMap.get(maybe.path) ?? null;
|
|
9372
8884
|
}
|
|
8885
|
+
return null;
|
|
8886
|
+
});
|
|
8887
|
+
if (!fs.existsSync(basePageClassPath)) {
|
|
8888
|
+
this.error(`Base page runtime file not found at ${basePageClassPath}. Ensure it is included in the build.`);
|
|
9373
8889
|
}
|
|
9374
|
-
|
|
9375
|
-
|
|
9376
|
-
|
|
8890
|
+
this.addWatchFile(basePageClassPath);
|
|
8891
|
+
const pointerPath = path.resolve(path.dirname(basePageClassPath), "pointer.ts");
|
|
8892
|
+
if (!fs.existsSync(pointerPath)) {
|
|
8893
|
+
this.error(`pointer.ts not found at ${pointerPath}. Ensure it is included in the build.`);
|
|
8894
|
+
}
|
|
8895
|
+
this.addWatchFile(pointerPath);
|
|
8896
|
+
const calloutPath = path.resolve(path.dirname(basePageClassPath), "callout.ts");
|
|
8897
|
+
if (!fs.existsSync(calloutPath)) {
|
|
8898
|
+
this.error(`callout.ts not found at ${calloutPath}. Ensure it is included in the build.`);
|
|
8899
|
+
}
|
|
8900
|
+
this.addWatchFile(calloutPath);
|
|
8901
|
+
const floatingUiCalloutPath = path.resolve(path.dirname(basePageClassPath), "floating-ui-callout.ts");
|
|
8902
|
+
if (fs.existsSync(floatingUiCalloutPath)) {
|
|
8903
|
+
this.addWatchFile(floatingUiCalloutPath);
|
|
8904
|
+
}
|
|
8905
|
+
},
|
|
8906
|
+
async buildEnd(error) {
|
|
8907
|
+
if (error) {
|
|
8908
|
+
return;
|
|
8909
|
+
}
|
|
8910
|
+
supplementHierarchyFromFilesystem();
|
|
8911
|
+
const metrics = summarizeHierarchyMap(componentHierarchyMap);
|
|
8912
|
+
if (metrics.dataTestIdCount <= 0) {
|
|
8913
|
+
return;
|
|
8914
|
+
}
|
|
8915
|
+
if (isLessRich(metrics, lastGeneratedMetrics)) {
|
|
8916
|
+
return;
|
|
8917
|
+
}
|
|
8918
|
+
await generateFiles(componentHierarchyMap, vueFilesPathMap, normalizedBasePagePath, {
|
|
8919
|
+
outDir,
|
|
8920
|
+
emitLanguages,
|
|
8921
|
+
typescriptOutputStructure,
|
|
8922
|
+
csharp,
|
|
8923
|
+
generateFixtures,
|
|
8924
|
+
customPomAttachments,
|
|
8925
|
+
projectRoot: projectRootRef.current,
|
|
8926
|
+
customPomDir,
|
|
8927
|
+
requireCustomPomDir,
|
|
8928
|
+
customPomImportAliases,
|
|
8929
|
+
customPomImportNameCollisionBehavior,
|
|
8930
|
+
testIdAttribute,
|
|
8931
|
+
vueRouterFluentChaining: routerAwarePoms,
|
|
8932
|
+
routerEntry: getResolvedRouterEntry(),
|
|
8933
|
+
routerType,
|
|
8934
|
+
pageDirs: getPageDirs(),
|
|
8935
|
+
componentDirs: getComponentDirs(),
|
|
8936
|
+
layoutDirs: getLayoutDirs()
|
|
8937
|
+
});
|
|
8938
|
+
lastGeneratedMetrics = metrics;
|
|
8939
|
+
loggerRef.current.info(`generated POMs (${metrics.entryCount} entries, ${metrics.interactiveComponentCount} interactive components, ${metrics.dataTestIdCount} selectors)`);
|
|
8940
|
+
},
|
|
8941
|
+
closeBundle() {
|
|
8942
|
+
loggerRef.current.info("build complete");
|
|
8943
|
+
}
|
|
8944
|
+
};
|
|
8945
|
+
}
|
|
8946
|
+
function createDevProcessorPlugin(options) {
|
|
8947
|
+
const {
|
|
8948
|
+
nativeWrappers,
|
|
8949
|
+
optionKeyAttribute,
|
|
8950
|
+
excludedComponents,
|
|
8951
|
+
getPageDirs,
|
|
8952
|
+
getComponentDirs,
|
|
8953
|
+
getLayoutDirs,
|
|
8954
|
+
getViewsDir,
|
|
8955
|
+
getSourceDirs,
|
|
8956
|
+
getWrapperSearchRoots,
|
|
8957
|
+
projectRootRef,
|
|
8958
|
+
normalizedBasePagePath,
|
|
8959
|
+
basePageClassPath,
|
|
8960
|
+
generation,
|
|
8961
|
+
getResolvedRouterEntry,
|
|
8962
|
+
loggerRef
|
|
8963
|
+
} = options;
|
|
8964
|
+
const {
|
|
8965
|
+
outDir,
|
|
8966
|
+
emitLanguages,
|
|
8967
|
+
typescriptOutputStructure,
|
|
8968
|
+
csharp,
|
|
8969
|
+
generateFixtures,
|
|
8970
|
+
customPomAttachments,
|
|
8971
|
+
customPomDir,
|
|
8972
|
+
requireCustomPomDir,
|
|
8973
|
+
customPomImportAliases,
|
|
8974
|
+
customPomImportNameCollisionBehavior,
|
|
8975
|
+
nameCollisionBehavior,
|
|
8976
|
+
missingSemanticNameBehavior,
|
|
8977
|
+
existingIdBehavior,
|
|
8978
|
+
testIdAttribute,
|
|
8979
|
+
routerAwarePoms,
|
|
8980
|
+
routerType,
|
|
8981
|
+
routerModuleShims
|
|
8982
|
+
} = generation;
|
|
8983
|
+
let scheduleVueFileRegen = null;
|
|
8984
|
+
const getProjectRootCandidates = () => Array.from(/* @__PURE__ */ new Set([
|
|
8985
|
+
path.resolve(projectRootRef.current),
|
|
8986
|
+
path.resolve(process.cwd())
|
|
8987
|
+
]));
|
|
8988
|
+
const resolveProjectPath = (maybePath) => {
|
|
8989
|
+
if (path.isAbsolute(maybePath))
|
|
8990
|
+
return maybePath;
|
|
8991
|
+
const candidates = getProjectRootCandidates().map((root) => path.resolve(root, maybePath));
|
|
8992
|
+
return candidates.find((candidate) => fs.existsSync(candidate)) ?? candidates[0];
|
|
8993
|
+
};
|
|
8994
|
+
const getSourceDirRoots = () => Array.from(new Set(
|
|
8995
|
+
getProjectRootCandidates().flatMap((root) => getSourceDirs().map((dir) => path.resolve(root, dir)))
|
|
8996
|
+
));
|
|
8997
|
+
const isContainedInScanDirs = (filePath) => {
|
|
8998
|
+
const absolutePath = path.resolve(filePath);
|
|
8999
|
+
return getSourceDirRoots().some((scanDirAbs) => isPathWithinDir(absolutePath, scanDirAbs));
|
|
9000
|
+
};
|
|
9001
|
+
return {
|
|
9002
|
+
name: "vue-pom-generator-dev",
|
|
9003
|
+
apply: "serve",
|
|
9004
|
+
// Prefer hot-update events over filesystem change events for speed and reliability.
|
|
9005
|
+
// This fires when Vite has actually processed the module update.
|
|
9006
|
+
handleHotUpdate(ctx) {
|
|
9007
|
+
if (!scheduleVueFileRegen)
|
|
9008
|
+
return;
|
|
9009
|
+
if (!ctx.file.endsWith(".vue"))
|
|
9010
|
+
return;
|
|
9011
|
+
if (!isContainedInScanDirs(ctx.file))
|
|
9012
|
+
return;
|
|
9013
|
+
scheduleVueFileRegen(ctx.file, "hmr");
|
|
9014
|
+
},
|
|
9015
|
+
async configureServer(server) {
|
|
9016
|
+
const getViewsDirAbs = () => resolveProjectPath(getViewsDir());
|
|
9017
|
+
const getPageDirsAbs = () => getPageDirs().map((dir) => resolveProjectPath(dir));
|
|
9018
|
+
const routerInitPromise = (async () => {
|
|
9019
|
+
if (!routerAwarePoms) {
|
|
9020
|
+
setRouteNameToComponentNameMap(/* @__PURE__ */ new Map());
|
|
9021
|
+
setResolveToComponentNameFn(() => null);
|
|
9022
|
+
return;
|
|
9023
|
+
}
|
|
9024
|
+
let result;
|
|
9025
|
+
if (routerType === "nuxt") {
|
|
9026
|
+
result = await introspectNuxtPages(projectRootRef.current, { pageDirs: getPageDirsAbs() });
|
|
9027
|
+
} else {
|
|
9028
|
+
const resolvedRouterEntry = getResolvedRouterEntry();
|
|
9029
|
+
if (!resolvedRouterEntry)
|
|
9030
|
+
throw new Error("[vue-pom-generator] router.entry is required when router introspection is enabled.");
|
|
9031
|
+
result = await parseRouterFileFromCwd(resolvedRouterEntry, {
|
|
9032
|
+
moduleShims: routerModuleShims,
|
|
9033
|
+
componentNaming: {
|
|
9034
|
+
projectRoot: projectRootRef.current,
|
|
9035
|
+
viewsDirAbs: getViewsDirAbs(),
|
|
9036
|
+
sourceDirs: getSourceDirs(),
|
|
9037
|
+
extraRoots: [process.cwd()]
|
|
9038
|
+
}
|
|
9039
|
+
});
|
|
9040
|
+
}
|
|
9041
|
+
const { routeNameMap, routePathMap } = result;
|
|
9042
|
+
setRouteNameToComponentNameMap(routeNameMap);
|
|
9043
|
+
setResolveToComponentNameFn((to) => {
|
|
9044
|
+
if (typeof to === "string") {
|
|
9045
|
+
return routePathMap.get(to) ?? null;
|
|
9046
|
+
}
|
|
9047
|
+
const maybe = to;
|
|
9048
|
+
if (typeof maybe.name === "string" && maybe.name.length) {
|
|
9049
|
+
const key = toPascalCase(maybe.name);
|
|
9050
|
+
return routeNameMap.get(key) ?? null;
|
|
9051
|
+
}
|
|
9052
|
+
if (typeof maybe.path === "string" && maybe.path.length) {
|
|
9053
|
+
return routePathMap.get(maybe.path) ?? null;
|
|
9054
|
+
}
|
|
9055
|
+
return null;
|
|
9056
|
+
});
|
|
9057
|
+
})();
|
|
9058
|
+
const logInfo = (message) => loggerRef.current.info(message);
|
|
9059
|
+
const logDebug = (message) => loggerRef.current.debug(message);
|
|
9060
|
+
let scheduleVueFileRegenLocal = null;
|
|
9061
|
+
const formatMs = (ms) => `${ms.toFixed(1)}ms`;
|
|
9062
|
+
const extractTemplateFromSfc = (source, filename) => {
|
|
9063
|
+
const { descriptor } = compilerSfc.parse(source, {
|
|
9064
|
+
filename: filename ?? "anonymous.vue"
|
|
9065
|
+
});
|
|
9066
|
+
return descriptor.template?.content ?? "";
|
|
9067
|
+
};
|
|
9068
|
+
const getScriptInfo = (source, filename) => {
|
|
9069
|
+
try {
|
|
9070
|
+
const { descriptor } = compilerSfc.parse(source, { filename });
|
|
9071
|
+
if (!descriptor.script && !descriptor.scriptSetup)
|
|
9072
|
+
return { bindings: void 0, isScriptSetup: false };
|
|
9073
|
+
const scriptBlock = compilerSfc.compileScript(descriptor, { id: filename });
|
|
9074
|
+
return { bindings: scriptBlock.bindings, isScriptSetup: !!descriptor.scriptSetup };
|
|
9075
|
+
} catch {
|
|
9076
|
+
return { bindings: void 0, isScriptSetup: false };
|
|
9077
|
+
}
|
|
9078
|
+
};
|
|
9079
|
+
const walkFilesRecursive = (rootDir) => {
|
|
9080
|
+
const out = [];
|
|
9081
|
+
const stack = [rootDir];
|
|
9082
|
+
while (stack.length) {
|
|
9083
|
+
const dir = stack.pop();
|
|
9084
|
+
if (!dir) continue;
|
|
9085
|
+
let entries = [];
|
|
9086
|
+
try {
|
|
9087
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
9088
|
+
} catch {
|
|
9089
|
+
continue;
|
|
9090
|
+
}
|
|
9091
|
+
for (const ent of entries) {
|
|
9092
|
+
if (ent.isDirectory()) {
|
|
9093
|
+
if (ent.name === "node_modules" || ent.name === ".git" || ent.name === "dist")
|
|
9094
|
+
continue;
|
|
9095
|
+
stack.push(path.join(dir, ent.name));
|
|
9096
|
+
continue;
|
|
9097
|
+
}
|
|
9098
|
+
if (ent.isFile() && ent.name.endsWith(".vue")) {
|
|
9099
|
+
out.push(path.join(dir, ent.name));
|
|
9100
|
+
}
|
|
9101
|
+
}
|
|
9102
|
+
}
|
|
9103
|
+
return out;
|
|
9104
|
+
};
|
|
9105
|
+
let snapshotHierarchy = /* @__PURE__ */ new Map();
|
|
9106
|
+
let snapshotVuePathMap = /* @__PURE__ */ new Map();
|
|
9107
|
+
const filePathToComponentName = /* @__PURE__ */ new Map();
|
|
9108
|
+
const createEmptyComponentDependencies = (absolutePath) => {
|
|
9109
|
+
const viewsDirAbs = path.resolve(getViewsDirAbs());
|
|
9110
|
+
const relToViewsDir = path.relative(viewsDirAbs, absolutePath);
|
|
9111
|
+
const isView = !relToViewsDir.startsWith("..") && !path.isAbsolute(relToViewsDir);
|
|
9112
|
+
return {
|
|
9113
|
+
filePath: absolutePath,
|
|
9114
|
+
childrenComponentSet: /* @__PURE__ */ new Set(),
|
|
9115
|
+
usedComponentSet: /* @__PURE__ */ new Set(),
|
|
9116
|
+
dataTestIdSet: /* @__PURE__ */ new Set(),
|
|
9117
|
+
isView,
|
|
9118
|
+
methodsContent: ""
|
|
9119
|
+
};
|
|
9120
|
+
};
|
|
9121
|
+
const getComponentNameForFile = (filePath) => {
|
|
9122
|
+
const normalized = path.resolve(filePath);
|
|
9123
|
+
const existing = filePathToComponentName.get(normalized);
|
|
9124
|
+
if (existing)
|
|
9125
|
+
return existing;
|
|
9126
|
+
const name = resolveComponentNameFromPath({
|
|
9127
|
+
filename: normalized,
|
|
9128
|
+
projectRoot: projectRootRef.current,
|
|
9129
|
+
viewsDirAbs: getViewsDirAbs(),
|
|
9130
|
+
sourceDirs: getSourceDirs(),
|
|
9131
|
+
extraRoots: [process.cwd()]
|
|
9132
|
+
});
|
|
9133
|
+
filePathToComponentName.set(normalized, name);
|
|
9134
|
+
return name;
|
|
9135
|
+
};
|
|
9136
|
+
const compileVueFileIntoSnapshot = (filePath, targetHierarchy = snapshotHierarchy, targetVuePathMap = snapshotVuePathMap) => {
|
|
9137
|
+
const started = node_perf_hooks.performance.now();
|
|
9138
|
+
const absolutePath = path.resolve(filePath);
|
|
9139
|
+
const componentName = getComponentNameForFile(absolutePath);
|
|
9140
|
+
let sfc = "";
|
|
9141
|
+
try {
|
|
9142
|
+
sfc = fs.readFileSync(absolutePath, "utf8");
|
|
9143
|
+
} catch {
|
|
9144
|
+
return { componentName, ms: node_perf_hooks.performance.now() - started, compiled: false };
|
|
9145
|
+
}
|
|
9146
|
+
const template = extractTemplateFromSfc(sfc, absolutePath);
|
|
9147
|
+
if (!template.trim()) {
|
|
9148
|
+
targetVuePathMap.set(componentName, absolutePath);
|
|
9149
|
+
targetHierarchy.set(componentName, createEmptyComponentDependencies(absolutePath));
|
|
9150
|
+
return { componentName, ms: node_perf_hooks.performance.now() - started, compiled: true };
|
|
9151
|
+
}
|
|
9152
|
+
const { bindings: bindingMetadata, isScriptSetup } = getScriptInfo(sfc, absolutePath);
|
|
9153
|
+
const provisionalHierarchy = /* @__PURE__ */ new Map();
|
|
9154
|
+
const provisionalKeyRegistry = /* @__PURE__ */ new Map();
|
|
9155
|
+
const provisionalVuePathMap = new Map(targetVuePathMap);
|
|
9156
|
+
provisionalVuePathMap.set(componentName, absolutePath);
|
|
9157
|
+
compilerDom__namespace.compile(template, {
|
|
9158
|
+
filename: absolutePath,
|
|
9159
|
+
prefixIdentifiers: true,
|
|
9160
|
+
inline: isScriptSetup,
|
|
9161
|
+
bindingMetadata,
|
|
9162
|
+
// Vue templates may contain TypeScript type annotations in expressions
|
|
9163
|
+
// (e.g. `@row-click="(row: RowType) => navigateTo(...)"` in Nuxt + TS
|
|
9164
|
+
// apps). Without this flag, Vue's internal processExpression step
|
|
9165
|
+
// delegates to @babel/parser without the TS plugin and crashes on
|
|
9166
|
+
// "Unexpected token, expected ','".
|
|
9167
|
+
expressionPlugins: ["typescript"],
|
|
9168
|
+
nodeTransforms: [
|
|
9169
|
+
createTestIdTransform(
|
|
9170
|
+
componentName,
|
|
9171
|
+
provisionalHierarchy,
|
|
9172
|
+
nativeWrappers,
|
|
9173
|
+
excludedComponents,
|
|
9174
|
+
getViewsDirAbs(),
|
|
9175
|
+
{
|
|
9176
|
+
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
9177
|
+
nameCollisionBehavior,
|
|
9178
|
+
missingSemanticNameBehavior,
|
|
9179
|
+
testIdAttribute,
|
|
9180
|
+
warn: (message) => loggerRef.current.warn(message),
|
|
9181
|
+
vueFilesPathMap: provisionalVuePathMap,
|
|
9182
|
+
wrapperSearchRoots: getWrapperSearchRoots(),
|
|
9183
|
+
crossFileKeyRegistry: provisionalKeyRegistry,
|
|
9184
|
+
optionKeyAttribute
|
|
9185
|
+
}
|
|
9186
|
+
)
|
|
9187
|
+
]
|
|
9188
|
+
});
|
|
9189
|
+
targetVuePathMap.set(componentName, absolutePath);
|
|
9190
|
+
targetHierarchy.set(
|
|
9191
|
+
componentName,
|
|
9192
|
+
provisionalHierarchy.get(componentName) ?? createEmptyComponentDependencies(absolutePath)
|
|
9193
|
+
);
|
|
9194
|
+
return { componentName, ms: node_perf_hooks.performance.now() - started, compiled: true };
|
|
9195
|
+
};
|
|
9196
|
+
const fullRebuildSnapshotFromFilesystem = (logLabel) => {
|
|
9197
|
+
const t0 = node_perf_hooks.performance.now();
|
|
9198
|
+
const nextHierarchy = /* @__PURE__ */ new Map();
|
|
9199
|
+
const nextVuePathMap = /* @__PURE__ */ new Map();
|
|
9200
|
+
filePathToComponentName.clear();
|
|
9201
|
+
let totalVueFiles = 0;
|
|
9202
|
+
let compiledCount = 0;
|
|
9203
|
+
for (const absDir of getSourceDirRoots()) {
|
|
9204
|
+
if (!fs.existsSync(absDir))
|
|
9205
|
+
continue;
|
|
9206
|
+
const vueFiles = walkFilesRecursive(absDir);
|
|
9207
|
+
totalVueFiles += vueFiles.length;
|
|
9208
|
+
for (const file of vueFiles) {
|
|
9209
|
+
const res = compileVueFileIntoSnapshot(file, nextHierarchy, nextVuePathMap);
|
|
9210
|
+
if (res.compiled)
|
|
9211
|
+
compiledCount++;
|
|
9212
|
+
}
|
|
9213
|
+
}
|
|
9214
|
+
snapshotHierarchy = nextHierarchy;
|
|
9215
|
+
snapshotVuePathMap = nextVuePathMap;
|
|
9216
|
+
const t1 = node_perf_hooks.performance.now();
|
|
9217
|
+
logInfo(`scan(${logLabel}): found ${totalVueFiles} .vue files in ${getSourceDirs().join(", ")}`);
|
|
9218
|
+
logInfo(`compile(${logLabel}): ${compiledCount}/${totalVueFiles} files in ${formatMs(t1 - t0)} (components=${snapshotHierarchy.size})`);
|
|
9219
|
+
};
|
|
9220
|
+
const generateAggregatedFromSnapshot = async (logLabel) => {
|
|
9221
|
+
const t0 = node_perf_hooks.performance.now();
|
|
9222
|
+
await generateFiles(snapshotHierarchy, snapshotVuePathMap, normalizedBasePagePath, {
|
|
9223
|
+
outDir,
|
|
9224
|
+
emitLanguages,
|
|
9225
|
+
typescriptOutputStructure,
|
|
9226
|
+
csharp,
|
|
9227
|
+
generateFixtures,
|
|
9228
|
+
customPomAttachments,
|
|
9229
|
+
projectRoot: projectRootRef.current,
|
|
9230
|
+
customPomDir,
|
|
9231
|
+
requireCustomPomDir,
|
|
9232
|
+
customPomImportAliases,
|
|
9233
|
+
customPomImportNameCollisionBehavior,
|
|
9234
|
+
pageDirs: getPageDirs(),
|
|
9235
|
+
componentDirs: getComponentDirs(),
|
|
9236
|
+
layoutDirs: getLayoutDirs(),
|
|
9237
|
+
testIdAttribute,
|
|
9238
|
+
vueRouterFluentChaining: routerAwarePoms,
|
|
9239
|
+
routerEntry: getResolvedRouterEntry(),
|
|
9240
|
+
routerType
|
|
9241
|
+
});
|
|
9242
|
+
const t1 = node_perf_hooks.performance.now();
|
|
9243
|
+
logInfo(`generate(${logLabel}): components=${snapshotHierarchy.size} in ${formatMs(t1 - t0)}`);
|
|
9244
|
+
};
|
|
9245
|
+
let timer = null;
|
|
9246
|
+
let maxWaitTimer = null;
|
|
9247
|
+
const pendingChangedVueFiles = /* @__PURE__ */ new Set();
|
|
9248
|
+
const pendingDeletedComponents = /* @__PURE__ */ new Set();
|
|
9249
|
+
let regenerationSequence = Promise.resolve();
|
|
9250
|
+
const initialBuildPromise = (async () => {
|
|
9251
|
+
const t0 = node_perf_hooks.performance.now();
|
|
9252
|
+
await routerInitPromise;
|
|
9253
|
+
fullRebuildSnapshotFromFilesystem("startup");
|
|
9254
|
+
await generateAggregatedFromSnapshot("startup");
|
|
9255
|
+
const t1 = node_perf_hooks.performance.now();
|
|
9256
|
+
logInfo(`startup total: ${formatMs(t1 - t0)}`);
|
|
9257
|
+
})();
|
|
9258
|
+
const logGenerationError = (reason, message) => {
|
|
9259
|
+
server.config.logger.error(`[vue-pom-generator] dev generation failed during ${reason}: ${message}`);
|
|
9260
|
+
};
|
|
9261
|
+
const regenerateFromPending = async (reason) => {
|
|
9262
|
+
const t0 = node_perf_hooks.performance.now();
|
|
9263
|
+
await initialBuildPromise;
|
|
9264
|
+
const nextHierarchy = new Map(snapshotHierarchy);
|
|
9265
|
+
const nextVuePathMap = new Map(snapshotVuePathMap);
|
|
9266
|
+
for (const componentName of pendingDeletedComponents) {
|
|
9267
|
+
nextHierarchy.delete(componentName);
|
|
9268
|
+
nextVuePathMap.delete(componentName);
|
|
9269
|
+
}
|
|
9270
|
+
const files = Array.from(pendingChangedVueFiles);
|
|
9271
|
+
const deletedCount = pendingDeletedComponents.size;
|
|
9272
|
+
pendingChangedVueFiles.clear();
|
|
9273
|
+
pendingDeletedComponents.clear();
|
|
9274
|
+
let compileMs = 0;
|
|
9275
|
+
for (const f of files) {
|
|
9276
|
+
const res = compileVueFileIntoSnapshot(f, nextHierarchy, nextVuePathMap);
|
|
9277
|
+
compileMs += res.ms;
|
|
9278
|
+
}
|
|
9279
|
+
snapshotHierarchy = nextHierarchy;
|
|
9280
|
+
snapshotVuePathMap = nextVuePathMap;
|
|
9281
|
+
const t1 = node_perf_hooks.performance.now();
|
|
9282
|
+
await generateAggregatedFromSnapshot(reason);
|
|
9283
|
+
const t2 = node_perf_hooks.performance.now();
|
|
9284
|
+
return {
|
|
9285
|
+
files,
|
|
9286
|
+
deletedCount,
|
|
9287
|
+
compileMs,
|
|
9288
|
+
preGenerateMs: t1 - t0,
|
|
9289
|
+
generateMs: t2 - t1,
|
|
9290
|
+
totalMs: t2 - t0
|
|
9291
|
+
};
|
|
9292
|
+
};
|
|
9293
|
+
const enqueueRegeneration = (reason) => {
|
|
9294
|
+
const currentRun = regenerationSequence.catch(() => void 0).then(() => regenerateFromPending(reason));
|
|
9295
|
+
regenerationSequence = currentRun.then(() => void 0, () => void 0);
|
|
9296
|
+
return currentRun;
|
|
9297
|
+
};
|
|
9298
|
+
const runtimeDir = path.dirname(basePageClassPath);
|
|
9299
|
+
const localPluginDir = path.resolve(projectRootRef.current, "vite-plugins", "vue-pom-generator");
|
|
9300
|
+
server.watcher.add([
|
|
9301
|
+
...fs.existsSync(localPluginDir) ? [localPluginDir] : [],
|
|
9302
|
+
basePageClassPath,
|
|
9303
|
+
path.resolve(runtimeDir, "pointer.ts"),
|
|
9304
|
+
path.resolve(runtimeDir, "callout.ts"),
|
|
9305
|
+
path.resolve(runtimeDir, "floating-ui-callout.ts")
|
|
9306
|
+
]);
|
|
9307
|
+
scheduleVueFileRegenLocal = (filePath, source) => {
|
|
9308
|
+
pendingChangedVueFiles.add(filePath);
|
|
9309
|
+
logDebug(`queued(${source}): files=${pendingChangedVueFiles.size} deleted=${pendingDeletedComponents.size}`);
|
|
9310
|
+
scheduleAggregatedRegen();
|
|
9311
|
+
};
|
|
9312
|
+
scheduleVueFileRegen = scheduleVueFileRegenLocal;
|
|
9313
|
+
function scheduleAggregatedRegen() {
|
|
9314
|
+
const wasEmpty = pendingChangedVueFiles.size === 0 && pendingDeletedComponents.size === 0;
|
|
9315
|
+
const MAX_WAIT_MS = 750;
|
|
9316
|
+
if (!maxWaitTimer) {
|
|
9317
|
+
maxWaitTimer = setTimeout(() => {
|
|
9318
|
+
if (timer) {
|
|
9319
|
+
clearTimeout(timer);
|
|
9320
|
+
timer = null;
|
|
9321
|
+
}
|
|
9322
|
+
maxWaitTimer = null;
|
|
9323
|
+
void enqueueRegeneration("max-wait").then(({ files, deletedCount, compileMs, preGenerateMs, generateMs, totalMs }) => {
|
|
9324
|
+
logInfo(
|
|
9325
|
+
`max-wait: files=${files.length} deleted=${deletedCount} compile=${formatMs(compileMs)} wall=${formatMs(preGenerateMs)} gen=${formatMs(generateMs)} total=${formatMs(totalMs)}`
|
|
9326
|
+
);
|
|
9327
|
+
}).catch((error) => {
|
|
9328
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
9329
|
+
logGenerationError("max-wait", message);
|
|
9330
|
+
});
|
|
9331
|
+
}, MAX_WAIT_MS);
|
|
9377
9332
|
}
|
|
9378
|
-
|
|
9379
|
-
|
|
9380
|
-
|
|
9381
|
-
|
|
9382
|
-
}
|
|
9383
|
-
} else if (node.type === compilerCore.NodeTypes.IF_BRANCH || node.type === compilerCore.NodeTypes.FOR) {
|
|
9384
|
-
if (node.children) {
|
|
9385
|
-
for (const child of node.children) {
|
|
9386
|
-
traverseNode(child);
|
|
9333
|
+
if (wasEmpty) {
|
|
9334
|
+
const queuedFiles = pendingChangedVueFiles.size;
|
|
9335
|
+
const queuedDeletes = pendingDeletedComponents.size;
|
|
9336
|
+
logDebug(`queued: files=${queuedFiles} deleted=${queuedDeletes}`);
|
|
9387
9337
|
}
|
|
9388
|
-
|
|
9389
|
-
|
|
9390
|
-
|
|
9391
|
-
|
|
9392
|
-
|
|
9393
|
-
|
|
9394
|
-
|
|
9395
|
-
|
|
9396
|
-
|
|
9397
|
-
|
|
9398
|
-
|
|
9399
|
-
|
|
9400
|
-
}
|
|
9401
|
-
|
|
9402
|
-
const {
|
|
9403
|
-
vueOptions,
|
|
9404
|
-
existingIdBehavior,
|
|
9405
|
-
nameCollisionBehavior,
|
|
9406
|
-
missingSemanticNameBehavior = "error",
|
|
9407
|
-
nativeWrappers,
|
|
9408
|
-
optionKeyAttribute,
|
|
9409
|
-
elementMetadata,
|
|
9410
|
-
semanticNameMap,
|
|
9411
|
-
componentHierarchyMap,
|
|
9412
|
-
crossFileKeyRegistry,
|
|
9413
|
-
vueFilesPathMap,
|
|
9414
|
-
excludedComponents,
|
|
9415
|
-
getViewsDirAbs,
|
|
9416
|
-
testIdAttribute,
|
|
9417
|
-
accessibilityAudit,
|
|
9418
|
-
loggerRef,
|
|
9419
|
-
getSourceDirs,
|
|
9420
|
-
getWrapperSearchRoots,
|
|
9421
|
-
getProjectRoot,
|
|
9422
|
-
annotatorMetadata
|
|
9423
|
-
} = options;
|
|
9424
|
-
const lastAccessibilityWarningSignatureByComponent = /* @__PURE__ */ new Map();
|
|
9425
|
-
const getComponentNameFromPath = (filename) => {
|
|
9426
|
-
return resolveComponentNameFromPath({
|
|
9427
|
-
filename,
|
|
9428
|
-
projectRoot: getProjectRoot(),
|
|
9429
|
-
viewsDirAbs: getViewsDirAbs(),
|
|
9430
|
-
sourceDirs: getSourceDirs(),
|
|
9431
|
-
extraRoots: [process.cwd()]
|
|
9432
|
-
});
|
|
9433
|
-
};
|
|
9434
|
-
const isFileInScope = (filename) => {
|
|
9435
|
-
if (!filename)
|
|
9436
|
-
return false;
|
|
9437
|
-
const cleanPath = filename.includes("?") ? filename.substring(0, filename.indexOf("?")) : filename;
|
|
9438
|
-
const projectRoot = getProjectRoot();
|
|
9439
|
-
const matched = isFileInConfiguredSourceScope({
|
|
9440
|
-
filename,
|
|
9441
|
-
projectRoot,
|
|
9442
|
-
viewsDirAbs: getViewsDirAbs(),
|
|
9443
|
-
sourceDirs: getSourceDirs(),
|
|
9444
|
-
extraRoots: [process.cwd()]
|
|
9445
|
-
});
|
|
9446
|
-
if (cleanPath.endsWith(".vue") && !matched) {
|
|
9447
|
-
const absFilename = path.normalize(path.isAbsolute(cleanPath) ? cleanPath : path.resolve(projectRoot, cleanPath));
|
|
9448
|
-
loggerRef.current.debug(`[isFileInScope] REJECTED: ${absFilename} (Clean: ${cleanPath})`);
|
|
9449
|
-
}
|
|
9450
|
-
return matched;
|
|
9451
|
-
};
|
|
9452
|
-
const userTemplate = vueOptions?.template ?? {};
|
|
9453
|
-
const userCompilerOptions = userTemplate.compilerOptions ?? {};
|
|
9454
|
-
const userNodeTransforms = userCompilerOptions.nodeTransforms ?? [];
|
|
9455
|
-
const perFileTransform = /* @__PURE__ */ new Map();
|
|
9456
|
-
const getNodeTransforms = (filename, componentNameOverride) => {
|
|
9457
|
-
const cleanPath = filename.includes("?") ? filename.substring(0, filename.indexOf("?")) : filename;
|
|
9458
|
-
const viewsDirAbs = getViewsDirAbs();
|
|
9459
|
-
const componentName = componentNameOverride || getComponentNameFromPath(cleanPath);
|
|
9460
|
-
return [
|
|
9461
|
-
...userNodeTransforms,
|
|
9462
|
-
(node, context) => {
|
|
9463
|
-
if (node.type === compilerCore.NodeTypes.ROOT) {
|
|
9464
|
-
componentHierarchyMap.delete(componentName);
|
|
9465
|
-
vueFilesPathMap.set(componentName, filename);
|
|
9466
|
-
perFileTransform.set(
|
|
9467
|
-
componentName,
|
|
9468
|
-
createTestIdTransform(
|
|
9469
|
-
componentName,
|
|
9470
|
-
componentHierarchyMap,
|
|
9471
|
-
nativeWrappers,
|
|
9472
|
-
excludedComponents,
|
|
9473
|
-
viewsDirAbs,
|
|
9474
|
-
{
|
|
9475
|
-
existingIdBehavior,
|
|
9476
|
-
testIdAttribute,
|
|
9477
|
-
nameCollisionBehavior,
|
|
9478
|
-
missingSemanticNameBehavior,
|
|
9479
|
-
warn: (message) => loggerRef.current.warn(message),
|
|
9480
|
-
vueFilesPathMap,
|
|
9481
|
-
wrapperSearchRoots: getWrapperSearchRoots(),
|
|
9482
|
-
annotatorMetadata,
|
|
9483
|
-
crossFileKeyRegistry,
|
|
9484
|
-
optionKeyAttribute
|
|
9485
|
-
}
|
|
9486
|
-
)
|
|
9487
|
-
);
|
|
9488
|
-
return () => {
|
|
9489
|
-
const componentMetadata = extractMetadataAfterTransform(
|
|
9490
|
-
node,
|
|
9491
|
-
componentName,
|
|
9492
|
-
elementMetadata,
|
|
9493
|
-
semanticNameMap,
|
|
9494
|
-
testIdAttribute
|
|
9495
|
-
);
|
|
9496
|
-
if (!accessibilityAudit) {
|
|
9497
|
-
return;
|
|
9498
|
-
}
|
|
9499
|
-
const dependencies = componentHierarchyMap.get(componentName);
|
|
9500
|
-
if (!dependencies || componentMetadata.size === 0) {
|
|
9501
|
-
return;
|
|
9502
|
-
}
|
|
9503
|
-
const manifest = buildPomManifest(
|
|
9504
|
-
/* @__PURE__ */ new Map([[componentName, dependencies]]),
|
|
9505
|
-
/* @__PURE__ */ new Map([[componentName, componentMetadata]])
|
|
9506
|
-
);
|
|
9507
|
-
const warnings = collectAccessibilityReviewWarnings(manifest);
|
|
9508
|
-
const signature = warnings.join("\n");
|
|
9509
|
-
if (!signature) {
|
|
9510
|
-
lastAccessibilityWarningSignatureByComponent.delete(componentName);
|
|
9511
|
-
return;
|
|
9512
|
-
}
|
|
9513
|
-
if (lastAccessibilityWarningSignatureByComponent.get(componentName) === signature) {
|
|
9514
|
-
return;
|
|
9515
|
-
}
|
|
9516
|
-
lastAccessibilityWarningSignatureByComponent.set(componentName, signature);
|
|
9517
|
-
for (const warning of warnings) {
|
|
9518
|
-
loggerRef.current.warn(warning);
|
|
9338
|
+
if (timer)
|
|
9339
|
+
clearTimeout(timer);
|
|
9340
|
+
timer = setTimeout(() => {
|
|
9341
|
+
timer = null;
|
|
9342
|
+
if (maxWaitTimer) {
|
|
9343
|
+
clearTimeout(maxWaitTimer);
|
|
9344
|
+
maxWaitTimer = null;
|
|
9345
|
+
}
|
|
9346
|
+
const reason = pendingChangedVueFiles.size || pendingDeletedComponents.size ? "batched" : "noop";
|
|
9347
|
+
void enqueueRegeneration(reason).then(({ files, deletedCount, compileMs, preGenerateMs, generateMs, totalMs }) => {
|
|
9348
|
+
if (files.length || deletedCount) {
|
|
9349
|
+
logInfo(
|
|
9350
|
+
`batched: files=${files.length} deleted=${deletedCount} compile=${formatMs(compileMs)} wall=${formatMs(preGenerateMs)} gen=${formatMs(generateMs)} total=${formatMs(totalMs)}`
|
|
9351
|
+
);
|
|
9519
9352
|
}
|
|
9520
|
-
}
|
|
9353
|
+
}).catch((error) => {
|
|
9354
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
9355
|
+
logGenerationError(reason, message);
|
|
9356
|
+
});
|
|
9357
|
+
}, 75);
|
|
9358
|
+
}
|
|
9359
|
+
server.watcher.on("change", async (changedPath) => {
|
|
9360
|
+
const changedAbsPosix = path.posix.normalize(path.resolve(changedPath));
|
|
9361
|
+
const outDirAbsPosix = path.posix.normalize(path.resolve(projectRootRef.current, outDir ?? "./pom"));
|
|
9362
|
+
if (changedAbsPosix.startsWith(`${outDirAbsPosix}/`) && (changedAbsPosix.endsWith(".g.ts") || changedAbsPosix.endsWith(".g.ts.map"))) {
|
|
9363
|
+
return;
|
|
9521
9364
|
}
|
|
9522
|
-
|
|
9523
|
-
|
|
9524
|
-
componentHierarchyMap.delete(componentName);
|
|
9525
|
-
vueFilesPathMap.set(componentName, filename);
|
|
9526
|
-
transform = createTestIdTransform(
|
|
9527
|
-
componentName,
|
|
9528
|
-
componentHierarchyMap,
|
|
9529
|
-
nativeWrappers,
|
|
9530
|
-
excludedComponents,
|
|
9531
|
-
viewsDirAbs,
|
|
9532
|
-
{
|
|
9533
|
-
existingIdBehavior,
|
|
9534
|
-
testIdAttribute,
|
|
9535
|
-
nameCollisionBehavior,
|
|
9536
|
-
missingSemanticNameBehavior,
|
|
9537
|
-
warn: (message) => loggerRef.current.warn(message),
|
|
9538
|
-
vueFilesPathMap,
|
|
9539
|
-
wrapperSearchRoots: getWrapperSearchRoots(),
|
|
9540
|
-
annotatorMetadata,
|
|
9541
|
-
crossFileKeyRegistry,
|
|
9542
|
-
optionKeyAttribute
|
|
9543
|
-
}
|
|
9544
|
-
);
|
|
9545
|
-
perFileTransform.set(componentName, transform);
|
|
9365
|
+
if (changedAbsPosix.includes("/vite-plugins/vue-pom-generator/")) {
|
|
9366
|
+
void server.restart();
|
|
9546
9367
|
}
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
9368
|
+
});
|
|
9369
|
+
server.watcher.on("add", (p) => {
|
|
9370
|
+
if (typeof p !== "string")
|
|
9371
|
+
return;
|
|
9372
|
+
if (!p.endsWith(".vue"))
|
|
9373
|
+
return;
|
|
9374
|
+
if (!isContainedInScanDirs(p))
|
|
9375
|
+
return;
|
|
9376
|
+
void (async () => {
|
|
9377
|
+
await initialBuildPromise;
|
|
9378
|
+
pendingChangedVueFiles.add(p);
|
|
9379
|
+
scheduleAggregatedRegen();
|
|
9380
|
+
})();
|
|
9381
|
+
});
|
|
9382
|
+
server.watcher.on("unlink", (p) => {
|
|
9383
|
+
if (typeof p !== "string")
|
|
9384
|
+
return;
|
|
9385
|
+
if (!p.endsWith(".vue"))
|
|
9386
|
+
return;
|
|
9387
|
+
if (!isContainedInScanDirs(p))
|
|
9388
|
+
return;
|
|
9389
|
+
void (async () => {
|
|
9390
|
+
await initialBuildPromise;
|
|
9391
|
+
const absolutePath = path.resolve(p);
|
|
9392
|
+
const componentName = getComponentNameForFile(absolutePath);
|
|
9393
|
+
filePathToComponentName.delete(absolutePath);
|
|
9394
|
+
pendingDeletedComponents.add(componentName);
|
|
9395
|
+
scheduleAggregatedRegen();
|
|
9396
|
+
})();
|
|
9397
|
+
});
|
|
9398
|
+
setTimeout(() => {
|
|
9399
|
+
}, 250);
|
|
9400
|
+
await initialBuildPromise;
|
|
9401
|
+
}
|
|
9550
9402
|
};
|
|
9551
|
-
|
|
9552
|
-
|
|
9553
|
-
|
|
9554
|
-
|
|
9403
|
+
}
|
|
9404
|
+
const TEST_IDS_VIRTUAL_ID = "virtual:testids";
|
|
9405
|
+
const TEST_IDS_RESOLVED_ID = `\0${TEST_IDS_VIRTUAL_ID}`;
|
|
9406
|
+
const POM_MANIFEST_VIRTUAL_ID = "virtual:pom-manifest";
|
|
9407
|
+
const POM_MANIFEST_RESOLVED_ID = `\0${POM_MANIFEST_VIRTUAL_ID}`;
|
|
9408
|
+
function createTestIdsVirtualModulesPlugin(componentHierarchyMap, elementMetadata) {
|
|
9409
|
+
return {
|
|
9410
|
+
name: "vue-pom-generator:virtual-testids",
|
|
9411
|
+
resolveId(id) {
|
|
9412
|
+
if (id === TEST_IDS_VIRTUAL_ID)
|
|
9413
|
+
return TEST_IDS_RESOLVED_ID;
|
|
9414
|
+
if (id === POM_MANIFEST_VIRTUAL_ID)
|
|
9415
|
+
return POM_MANIFEST_RESOLVED_ID;
|
|
9416
|
+
},
|
|
9417
|
+
load(id) {
|
|
9418
|
+
if (id === TEST_IDS_RESOLVED_ID)
|
|
9419
|
+
return generateTestIdsModule(componentHierarchyMap, elementMetadata);
|
|
9420
|
+
if (id === POM_MANIFEST_RESOLVED_ID)
|
|
9421
|
+
return generatePomManifestModule(componentHierarchyMap, elementMetadata);
|
|
9555
9422
|
}
|
|
9556
|
-
const transforms = getNodeTransforms(filename);
|
|
9557
|
-
const ourTransform = transforms[transforms.length - 1];
|
|
9558
|
-
return ourTransform(node, context);
|
|
9559
|
-
};
|
|
9560
|
-
const templateCompilerOptions = {
|
|
9561
|
-
...userCompilerOptions,
|
|
9562
|
-
prefixIdentifiers: true,
|
|
9563
|
-
nodeTransforms: [
|
|
9564
|
-
...userNodeTransforms,
|
|
9565
|
-
runtimeNodeTransform
|
|
9566
|
-
]
|
|
9567
9423
|
};
|
|
9568
|
-
|
|
9569
|
-
|
|
9570
|
-
|
|
9571
|
-
|
|
9572
|
-
|
|
9573
|
-
|
|
9424
|
+
}
|
|
9425
|
+
const ANNOTATOR_CLIENT_VIRTUAL_ID = "virtual:vue-pom-generator/annotator-client";
|
|
9426
|
+
const ANNOTATOR_CLIENT_RESOLVED_ID = `\0${ANNOTATOR_CLIENT_VIRTUAL_ID}`;
|
|
9427
|
+
const DEFAULT_ENTRY_SUFFIXES = [
|
|
9428
|
+
"/src/main.ts",
|
|
9429
|
+
"/src/main.js",
|
|
9430
|
+
"/src/main.mts",
|
|
9431
|
+
"/src/main.tsx",
|
|
9432
|
+
"/src/main.jsx"
|
|
9433
|
+
];
|
|
9434
|
+
function normalizePathSeparators(filePath) {
|
|
9435
|
+
return filePath.replace(/\\/g, "/");
|
|
9436
|
+
}
|
|
9437
|
+
function toFsImportPath(filePath) {
|
|
9438
|
+
return `/@fs/${normalizePathSeparators(filePath)}`;
|
|
9439
|
+
}
|
|
9440
|
+
function resolveAnnotatorClientPath() {
|
|
9441
|
+
const candidates = [
|
|
9442
|
+
node_url.fileURLToPath(new URL("./client.ts", typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href)),
|
|
9443
|
+
node_url.fileURLToPath(new URL("../plugin/runtime/annotator/client.ts", typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href))
|
|
9444
|
+
];
|
|
9445
|
+
const resolved = candidates.find((candidate) => fs.existsSync(candidate));
|
|
9446
|
+
if (!resolved) {
|
|
9447
|
+
throw new Error("[vue-pom-generator] Unable to locate annotator client source.");
|
|
9448
|
+
}
|
|
9449
|
+
return path.resolve(resolved);
|
|
9450
|
+
}
|
|
9451
|
+
function createAnnotatorUiPlugin(options) {
|
|
9452
|
+
const clientPath = resolveAnnotatorClientPath();
|
|
9453
|
+
const clientImportPath = toFsImportPath(clientPath);
|
|
9454
|
+
const clientOptions = JSON.stringify({
|
|
9455
|
+
sourceAttribute: options.sourceAttribute,
|
|
9456
|
+
metadataAttributePrefix: options.metadataAttributePrefix,
|
|
9457
|
+
outputDetail: options.outputDetail,
|
|
9458
|
+
copyToClipboard: options.copyToClipboard,
|
|
9459
|
+
showComponentTree: options.showComponentTree
|
|
9460
|
+
});
|
|
9461
|
+
return {
|
|
9462
|
+
name: "vue-pom-generator:annotator-ui",
|
|
9463
|
+
apply: "serve",
|
|
9464
|
+
resolveId(id) {
|
|
9465
|
+
if (id === ANNOTATOR_CLIENT_VIRTUAL_ID) {
|
|
9466
|
+
return ANNOTATOR_CLIENT_RESOLVED_ID;
|
|
9467
|
+
}
|
|
9468
|
+
},
|
|
9469
|
+
load(id) {
|
|
9470
|
+
if (id !== ANNOTATOR_CLIENT_RESOLVED_ID) {
|
|
9574
9471
|
return null;
|
|
9575
9472
|
}
|
|
9576
|
-
|
|
9473
|
+
return [
|
|
9474
|
+
`import { mountAnnotatorClient } from ${JSON.stringify(clientImportPath)};`,
|
|
9475
|
+
`mountAnnotatorClient(${clientOptions});`,
|
|
9476
|
+
""
|
|
9477
|
+
].join("\n");
|
|
9478
|
+
},
|
|
9479
|
+
transform(code, id) {
|
|
9480
|
+
if (!options.enabled) {
|
|
9577
9481
|
return null;
|
|
9578
9482
|
}
|
|
9579
|
-
const
|
|
9580
|
-
|
|
9581
|
-
|
|
9582
|
-
const parse = resolveCompilerSfcParse(compilerSfc2);
|
|
9583
|
-
const compilerDom2 = await import("@vue/compiler-dom");
|
|
9584
|
-
const compile = compilerDom2.compile;
|
|
9585
|
-
const { descriptor } = parse(code, { filename: cleanPath });
|
|
9586
|
-
if (descriptor.template) {
|
|
9587
|
-
const mergedExpressionPlugins = Array.from(
|
|
9588
|
-
/* @__PURE__ */ new Set([
|
|
9589
|
-
"typescript",
|
|
9590
|
-
...userCompilerOptions.expressionPlugins ?? []
|
|
9591
|
-
])
|
|
9592
|
-
);
|
|
9593
|
-
compile(descriptor.template.content, {
|
|
9594
|
-
...userCompilerOptions,
|
|
9595
|
-
filename: cleanPath,
|
|
9596
|
-
expressionPlugins: mergedExpressionPlugins,
|
|
9597
|
-
nodeTransforms: getNodeTransforms(cleanPath, componentName)
|
|
9598
|
-
});
|
|
9599
|
-
loggerRef.current.debug(`Metadata collected for ${cleanPath}`);
|
|
9483
|
+
const normalizedId = normalizePathSeparators(id);
|
|
9484
|
+
if (!DEFAULT_ENTRY_SUFFIXES.some((suffix) => normalizedId.endsWith(suffix))) {
|
|
9485
|
+
return null;
|
|
9600
9486
|
}
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
};
|
|
9604
|
-
const template = {
|
|
9605
|
-
...userTemplate,
|
|
9606
|
-
compilerOptions: templateCompilerOptions
|
|
9607
|
-
};
|
|
9608
|
-
const internalVuePlugin = vue({
|
|
9609
|
-
...vueOptions,
|
|
9610
|
-
template
|
|
9611
|
-
});
|
|
9612
|
-
const nuxtVueBridgePlugin = {
|
|
9613
|
-
name: "vue-pom-generator-nuxt-vue-bridge",
|
|
9614
|
-
apply: "serve",
|
|
9615
|
-
configResolved(config) {
|
|
9616
|
-
const viteVuePlugin = config.plugins.find((plugin) => {
|
|
9617
|
-
return typeof plugin === "object" && plugin !== null && "name" in plugin && plugin.name === "vite:vue" && "api" in plugin;
|
|
9618
|
-
});
|
|
9619
|
-
const api = viteVuePlugin?.api;
|
|
9620
|
-
if (!api) {
|
|
9621
|
-
throw new Error("[vue-pom-generator] Nuxt bridge could not find vite:vue plugin to patch.");
|
|
9487
|
+
if (code.includes(ANNOTATOR_CLIENT_VIRTUAL_ID)) {
|
|
9488
|
+
return null;
|
|
9622
9489
|
}
|
|
9623
|
-
|
|
9624
|
-
|
|
9625
|
-
|
|
9626
|
-
|
|
9627
|
-
|
|
9628
|
-
|
|
9490
|
+
return {
|
|
9491
|
+
code: `import ${JSON.stringify(ANNOTATOR_CLIENT_VIRTUAL_ID)};
|
|
9492
|
+
${code}`,
|
|
9493
|
+
map: null
|
|
9494
|
+
};
|
|
9495
|
+
},
|
|
9496
|
+
transformIndexHtml() {
|
|
9497
|
+
if (!options.enabled) {
|
|
9498
|
+
return void 0;
|
|
9629
9499
|
}
|
|
9630
|
-
|
|
9631
|
-
|
|
9632
|
-
|
|
9633
|
-
|
|
9634
|
-
|
|
9635
|
-
...currentCompilerOptions,
|
|
9636
|
-
prefixIdentifiers: true,
|
|
9637
|
-
nodeTransforms: [
|
|
9638
|
-
...currentNodeTransforms,
|
|
9639
|
-
runtimeNodeTransform
|
|
9640
|
-
]
|
|
9641
|
-
}
|
|
9642
|
-
}
|
|
9500
|
+
const tag = {
|
|
9501
|
+
tag: "script",
|
|
9502
|
+
attrs: { type: "module" },
|
|
9503
|
+
children: `import ${JSON.stringify(ANNOTATOR_CLIENT_VIRTUAL_ID)};`,
|
|
9504
|
+
injectTo: "body"
|
|
9643
9505
|
};
|
|
9506
|
+
return [tag];
|
|
9644
9507
|
}
|
|
9645
9508
|
};
|
|
9646
|
-
|
|
9509
|
+
}
|
|
9510
|
+
function createInternalPlugins(options) {
|
|
9511
|
+
const {
|
|
9512
|
+
componentHierarchyMap,
|
|
9513
|
+
crossFileKeyRegistry,
|
|
9514
|
+
elementMetadata,
|
|
9515
|
+
vueFilesPathMap,
|
|
9516
|
+
nativeWrappers,
|
|
9517
|
+
optionKeyAttribute,
|
|
9518
|
+
excludedComponents,
|
|
9519
|
+
getPageDirs,
|
|
9520
|
+
getComponentDirs,
|
|
9521
|
+
getLayoutDirs,
|
|
9522
|
+
getViewsDir,
|
|
9523
|
+
getSourceDirs,
|
|
9524
|
+
getWrapperSearchRoots,
|
|
9525
|
+
generation,
|
|
9526
|
+
projectRootRef,
|
|
9527
|
+
basePageClassPath: basePageClassPathOverride,
|
|
9528
|
+
loggerRef,
|
|
9529
|
+
annotatorRuntime
|
|
9530
|
+
} = options;
|
|
9531
|
+
const {
|
|
9532
|
+
routerAwarePoms,
|
|
9533
|
+
routerEntry,
|
|
9534
|
+
routerType
|
|
9535
|
+
} = generation;
|
|
9536
|
+
const resolveRouterEntry2 = () => {
|
|
9537
|
+
if (!routerAwarePoms)
|
|
9538
|
+
return void 0;
|
|
9539
|
+
if (routerType === "nuxt")
|
|
9540
|
+
return void 0;
|
|
9541
|
+
if (!routerEntry)
|
|
9542
|
+
throw new Error("[vue-pom-generator] router.entry is required when router introspection is enabled.");
|
|
9543
|
+
return path.isAbsolute(routerEntry) ? routerEntry : path.resolve(projectRootRef.current, routerEntry);
|
|
9544
|
+
};
|
|
9545
|
+
const getDefaultBasePageClassPath = () => {
|
|
9546
|
+
try {
|
|
9547
|
+
return node_url.fileURLToPath(new URL("../class-generation/base-page.ts", typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("index.cjs", document.baseURI).href));
|
|
9548
|
+
} catch {
|
|
9549
|
+
return path.resolve(__dirname, "..", "class-generation", "base-page.ts");
|
|
9550
|
+
}
|
|
9551
|
+
};
|
|
9552
|
+
const basePageClassPath = basePageClassPathOverride ?? getDefaultBasePageClassPath();
|
|
9553
|
+
const normalizedBasePagePath = path.posix.normalize(basePageClassPath);
|
|
9554
|
+
const tsProcessor = createBuildProcessorPlugin({
|
|
9555
|
+
componentHierarchyMap,
|
|
9556
|
+
crossFileKeyRegistry,
|
|
9557
|
+
vueFilesPathMap,
|
|
9558
|
+
getPageDirs,
|
|
9559
|
+
getComponentDirs,
|
|
9560
|
+
getLayoutDirs,
|
|
9561
|
+
getViewsDir,
|
|
9562
|
+
getSourceDirs,
|
|
9563
|
+
basePageClassPath,
|
|
9564
|
+
normalizedBasePagePath,
|
|
9565
|
+
generation,
|
|
9566
|
+
projectRootRef,
|
|
9567
|
+
nativeWrappers,
|
|
9568
|
+
optionKeyAttribute,
|
|
9569
|
+
excludedComponents,
|
|
9570
|
+
getWrapperSearchRoots,
|
|
9571
|
+
getResolvedRouterEntry: resolveRouterEntry2,
|
|
9572
|
+
loggerRef
|
|
9573
|
+
});
|
|
9574
|
+
const devProcessor = createDevProcessorPlugin({
|
|
9575
|
+
nativeWrappers,
|
|
9576
|
+
optionKeyAttribute,
|
|
9577
|
+
excludedComponents,
|
|
9578
|
+
getPageDirs,
|
|
9579
|
+
getComponentDirs,
|
|
9580
|
+
getLayoutDirs,
|
|
9581
|
+
getViewsDir,
|
|
9582
|
+
getSourceDirs,
|
|
9583
|
+
getWrapperSearchRoots,
|
|
9584
|
+
projectRootRef,
|
|
9585
|
+
normalizedBasePagePath,
|
|
9586
|
+
basePageClassPath,
|
|
9587
|
+
generation,
|
|
9588
|
+
getResolvedRouterEntry: resolveRouterEntry2,
|
|
9589
|
+
loggerRef
|
|
9590
|
+
});
|
|
9591
|
+
const virtualModules = createTestIdsVirtualModulesPlugin(componentHierarchyMap, elementMetadata);
|
|
9592
|
+
const annotatorUiPlugin = createAnnotatorUiPlugin({
|
|
9593
|
+
...annotatorRuntime.ui,
|
|
9594
|
+
enabled: annotatorRuntime.enabled && annotatorRuntime.ui.enabled,
|
|
9595
|
+
sourceAttribute: annotatorRuntime.sourceAttribute,
|
|
9596
|
+
metadataAttributePrefix: annotatorRuntime.metadataAttributePrefix
|
|
9597
|
+
});
|
|
9598
|
+
return [tsProcessor, devProcessor, virtualModules, annotatorUiPlugin];
|
|
9647
9599
|
}
|
|
9648
9600
|
const nuxtConfigMarker$1 = /* @__PURE__ */ Symbol.for("@immense/vue-pom-generator.nuxt");
|
|
9649
9601
|
const nuxtConfigFileNames = [
|