@immense/vue-pom-generator 1.0.89 → 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 +64 -39
- package/class-generation/index.ts +5 -5
- 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 +1364 -1360
- 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 +1355 -1351
- package/dist/index.mjs.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/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) {
|
|
@@ -4035,18 +4036,18 @@ function getRoutePropsKeys(record) {
|
|
|
4035
4036
|
}
|
|
4036
4037
|
return { paramKeys: [], queryKeys: [] };
|
|
4037
4038
|
}
|
|
4038
|
-
function buildRouteTemplate(
|
|
4039
|
+
function buildRouteTemplate(router2, record, paramNames) {
|
|
4039
4040
|
if (typeof record.name !== "string" || !record.name.length) {
|
|
4040
4041
|
return record.path;
|
|
4041
4042
|
}
|
|
4042
4043
|
const params = Object.fromEntries(paramNames.map((name) => [name, getParamToken(name)]));
|
|
4043
4044
|
try {
|
|
4044
|
-
return
|
|
4045
|
+
return router2.resolve({ name: record.name, params }).path;
|
|
4045
4046
|
} catch {
|
|
4046
4047
|
return record.path;
|
|
4047
4048
|
}
|
|
4048
4049
|
}
|
|
4049
|
-
function getRouteParamMeta(
|
|
4050
|
+
function getRouteParamMeta(router2, record, paramNames) {
|
|
4050
4051
|
if (typeof record.name !== "string" || !record.name.length) {
|
|
4051
4052
|
return paramNames.map((name) => ({ name, optional: false }));
|
|
4052
4053
|
}
|
|
@@ -4055,7 +4056,7 @@ function getRouteParamMeta(router, record, paramNames) {
|
|
|
4055
4056
|
const params = { ...paramsWithAll };
|
|
4056
4057
|
delete params[name];
|
|
4057
4058
|
try {
|
|
4058
|
-
|
|
4059
|
+
router2.resolve({ name: record.name, params });
|
|
4059
4060
|
return { name, optional: true };
|
|
4060
4061
|
} catch {
|
|
4061
4062
|
return { name, optional: false };
|
|
@@ -4625,16 +4626,16 @@ async function parseRouterFileFromCwd(routerEntryPath, options = {}) {
|
|
|
4625
4626
|
if (typeof makeRouter !== "function") {
|
|
4626
4627
|
throw new TypeError(`[vue-pom-generator] ${routerEntry} must export a default router factory function (export default makeRouter).`);
|
|
4627
4628
|
}
|
|
4628
|
-
let
|
|
4629
|
+
let router2;
|
|
4629
4630
|
try {
|
|
4630
|
-
|
|
4631
|
+
router2 = makeRouter();
|
|
4631
4632
|
} catch (err) {
|
|
4632
4633
|
throw new Error(`[vue-pom-generator] makeRouter() invocation failed: ${String(err)}`);
|
|
4633
4634
|
}
|
|
4634
4635
|
const routeNameMap = /* @__PURE__ */ new Map();
|
|
4635
4636
|
const routePathMap = /* @__PURE__ */ new Map();
|
|
4636
4637
|
const routeMetaEntries = [];
|
|
4637
|
-
for (const r of
|
|
4638
|
+
for (const r of router2.getRoutes()) {
|
|
4638
4639
|
const componentInfo = await getComponentInfoFromRouteRecord(r, { rootDir: cwd });
|
|
4639
4640
|
const componentName = resolveIntrospectedComponentName(componentInfo, options.componentNaming);
|
|
4640
4641
|
if (!componentName)
|
|
@@ -4647,8 +4648,8 @@ async function parseRouterFileFromCwd(routerEntryPath, options = {}) {
|
|
|
4647
4648
|
routeNameMap.set(key, componentName);
|
|
4648
4649
|
}
|
|
4649
4650
|
const { paramKeys, queryKeys } = getRoutePropsKeys(r);
|
|
4650
|
-
const paramsMeta = getRouteParamMeta(
|
|
4651
|
-
const pathTemplate = buildRouteTemplate(
|
|
4651
|
+
const paramsMeta = getRouteParamMeta(router2, r, paramKeys);
|
|
4652
|
+
const pathTemplate = buildRouteTemplate(router2, r, paramsMeta.map((p) => p.name));
|
|
4652
4653
|
if (typeof pathTemplate === "string" && pathTemplate.length) {
|
|
4653
4654
|
routeMetaEntries.push({
|
|
4654
4655
|
componentName,
|
|
@@ -4859,7 +4860,7 @@ const GOTO_RUNTIME_LINES = [
|
|
|
4859
4860
|
"const resolvedUrl = runtimeBaseUrl ? new URL(targetUrl, runtimeBaseUrl).toString() : targetUrl;",
|
|
4860
4861
|
"await this.page.goto(resolvedUrl);"
|
|
4861
4862
|
];
|
|
4862
|
-
const ROUTER_GLOBAL_NAME =
|
|
4863
|
+
const ROUTER_GLOBAL_NAME = router.POM_ROUTER_GLOBAL_NAME;
|
|
4863
4864
|
const pushBlock = (routeNameExpr, paramsExpr, nullable) => {
|
|
4864
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 } } }`;
|
|
4865
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));`;
|
|
@@ -8030,824 +8031,200 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8030
8031
|
}
|
|
8031
8032
|
};
|
|
8032
8033
|
}
|
|
8033
|
-
function
|
|
8034
|
-
|
|
8035
|
-
|
|
8036
|
-
|
|
8037
|
-
|
|
8038
|
-
|
|
8039
|
-
|
|
8040
|
-
|
|
8041
|
-
|
|
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.");
|
|
8042
8060
|
}
|
|
8043
8061
|
return {
|
|
8044
|
-
|
|
8045
|
-
|
|
8046
|
-
|
|
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 } : {}
|
|
8047
8069
|
};
|
|
8048
8070
|
}
|
|
8049
|
-
function
|
|
8050
|
-
|
|
8051
|
-
|
|
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
|
+
}
|
|
8052
8084
|
}
|
|
8053
|
-
|
|
8054
|
-
|
|
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;
|
|
8055
8095
|
}
|
|
8056
|
-
|
|
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;
|
|
8057
8103
|
}
|
|
8058
|
-
function
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
|
|
8062
|
-
|
|
8063
|
-
|
|
8064
|
-
|
|
8065
|
-
|
|
8066
|
-
|
|
8067
|
-
|
|
8068
|
-
|
|
8069
|
-
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
nativeWrappers,
|
|
8073
|
-
optionKeyAttribute,
|
|
8074
|
-
excludedComponents,
|
|
8075
|
-
getWrapperSearchRoots,
|
|
8076
|
-
getResolvedRouterEntry,
|
|
8077
|
-
loggerRef
|
|
8078
|
-
} = options;
|
|
8079
|
-
const {
|
|
8080
|
-
outDir,
|
|
8081
|
-
emitLanguages,
|
|
8082
|
-
typescriptOutputStructure,
|
|
8083
|
-
csharp,
|
|
8084
|
-
generateFixtures,
|
|
8085
|
-
customPomAttachments,
|
|
8086
|
-
customPomDir,
|
|
8087
|
-
requireCustomPomDir,
|
|
8088
|
-
customPomImportAliases,
|
|
8089
|
-
customPomImportNameCollisionBehavior,
|
|
8090
|
-
testIdAttribute,
|
|
8091
|
-
nameCollisionBehavior,
|
|
8092
|
-
missingSemanticNameBehavior,
|
|
8093
|
-
existingIdBehavior,
|
|
8094
|
-
routerAwarePoms,
|
|
8095
|
-
routerType,
|
|
8096
|
-
routerModuleShims
|
|
8097
|
-
} = generation;
|
|
8098
|
-
let lastGeneratedMetrics = {
|
|
8099
|
-
entryCount: 0,
|
|
8100
|
-
interactiveComponentCount: 0,
|
|
8101
|
-
dataTestIdCount: 0
|
|
8102
|
-
};
|
|
8103
|
-
const getViewsDirAbs = () => path.isAbsolute(getViewsDir()) ? getViewsDir() : path.resolve(projectRootRef.current, getViewsDir());
|
|
8104
|
-
const getPageDirsAbs = () => getPageDirs().map((dir) => path.isAbsolute(dir) ? dir : path.resolve(projectRootRef.current, dir));
|
|
8105
|
-
const getScriptInfo = (source, filename) => {
|
|
8106
|
-
try {
|
|
8107
|
-
const { descriptor } = compilerSfc.parse(source, { filename });
|
|
8108
|
-
if (!descriptor.script && !descriptor.scriptSetup)
|
|
8109
|
-
return { bindings: void 0, isScriptSetup: false };
|
|
8110
|
-
const scriptBlock = compilerSfc.compileScript(descriptor, { id: filename });
|
|
8111
|
-
return { bindings: scriptBlock.bindings, isScriptSetup: !!descriptor.scriptSetup };
|
|
8112
|
-
} catch {
|
|
8113
|
-
return { bindings: void 0, isScriptSetup: false };
|
|
8114
|
-
}
|
|
8115
|
-
};
|
|
8116
|
-
const supplementHierarchyFromFilesystem = () => {
|
|
8117
|
-
const walkFilesRecursive = (rootDir) => {
|
|
8118
|
-
const out = [];
|
|
8119
|
-
const stack = [rootDir];
|
|
8120
|
-
while (stack.length) {
|
|
8121
|
-
const dir = stack.pop();
|
|
8122
|
-
if (!dir) continue;
|
|
8123
|
-
let entries = [];
|
|
8124
|
-
try {
|
|
8125
|
-
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
8126
|
-
} catch {
|
|
8127
|
-
continue;
|
|
8128
|
-
}
|
|
8129
|
-
for (const ent of entries) {
|
|
8130
|
-
if (ent.isDirectory()) {
|
|
8131
|
-
if (ent.name === "node_modules" || ent.name === ".git" || ent.name === "dist")
|
|
8132
|
-
continue;
|
|
8133
|
-
stack.push(path.join(dir, ent.name));
|
|
8134
|
-
continue;
|
|
8135
|
-
}
|
|
8136
|
-
if (ent.isFile() && ent.name.endsWith(".vue")) {
|
|
8137
|
-
out.push(path.join(dir, ent.name));
|
|
8138
|
-
}
|
|
8139
|
-
}
|
|
8140
|
-
}
|
|
8141
|
-
return out;
|
|
8142
|
-
};
|
|
8143
|
-
let supplemented = 0;
|
|
8144
|
-
for (const dir of getSourceDirs()) {
|
|
8145
|
-
const absDir = path.resolve(projectRootRef.current, dir);
|
|
8146
|
-
if (!fs.existsSync(absDir))
|
|
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 = "";
|
|
8147
8118
|
continue;
|
|
8148
|
-
for (const filePath of walkFilesRecursive(absDir)) {
|
|
8149
|
-
const absolutePath = path.resolve(filePath);
|
|
8150
|
-
const componentName = resolveComponentNameFromPath({
|
|
8151
|
-
filename: absolutePath,
|
|
8152
|
-
projectRoot: projectRootRef.current,
|
|
8153
|
-
viewsDirAbs: getViewsDirAbs(),
|
|
8154
|
-
sourceDirs: getSourceDirs(),
|
|
8155
|
-
extraRoots: [process.cwd()]
|
|
8156
|
-
});
|
|
8157
|
-
if (componentHierarchyMap.has(componentName))
|
|
8158
|
-
continue;
|
|
8159
|
-
let sfc = "";
|
|
8160
|
-
try {
|
|
8161
|
-
sfc = fs.readFileSync(absolutePath, "utf8");
|
|
8162
|
-
} catch {
|
|
8163
|
-
continue;
|
|
8164
|
-
}
|
|
8165
|
-
const { descriptor } = compilerSfc.parse(sfc, { filename: absolutePath });
|
|
8166
|
-
const template = descriptor.template?.content ?? "";
|
|
8167
|
-
if (!template.trim()) {
|
|
8168
|
-
vueFilesPathMap.set(componentName, absolutePath);
|
|
8169
|
-
componentHierarchyMap.set(componentName, {
|
|
8170
|
-
filePath: absolutePath,
|
|
8171
|
-
childrenComponentSet: /* @__PURE__ */ new Set(),
|
|
8172
|
-
usedComponentSet: /* @__PURE__ */ new Set(),
|
|
8173
|
-
dataTestIdSet: /* @__PURE__ */ new Set(),
|
|
8174
|
-
isView: false,
|
|
8175
|
-
methodsContent: ""
|
|
8176
|
-
});
|
|
8177
|
-
supplemented++;
|
|
8178
|
-
continue;
|
|
8179
|
-
}
|
|
8180
|
-
const { bindings: bindingMetadata, isScriptSetup } = getScriptInfo(sfc, absolutePath);
|
|
8181
|
-
vueFilesPathMap.set(componentName, absolutePath);
|
|
8182
|
-
try {
|
|
8183
|
-
compilerDom__namespace.compile(template, {
|
|
8184
|
-
filename: absolutePath,
|
|
8185
|
-
prefixIdentifiers: true,
|
|
8186
|
-
inline: isScriptSetup,
|
|
8187
|
-
bindingMetadata,
|
|
8188
|
-
// See dev-plugin.ts — same rationale: enable TS in template
|
|
8189
|
-
// expressions so `(row: RowType) => ...` handlers parse.
|
|
8190
|
-
expressionPlugins: ["typescript"],
|
|
8191
|
-
nodeTransforms: [
|
|
8192
|
-
createTestIdTransform(
|
|
8193
|
-
componentName,
|
|
8194
|
-
componentHierarchyMap,
|
|
8195
|
-
nativeWrappers,
|
|
8196
|
-
excludedComponents,
|
|
8197
|
-
getViewsDirAbs(),
|
|
8198
|
-
{
|
|
8199
|
-
existingIdBehavior: existingIdBehavior ?? "error",
|
|
8200
|
-
testIdAttribute,
|
|
8201
|
-
nameCollisionBehavior,
|
|
8202
|
-
missingSemanticNameBehavior,
|
|
8203
|
-
warn: (message) => loggerRef.current.warn(message),
|
|
8204
|
-
vueFilesPathMap,
|
|
8205
|
-
wrapperSearchRoots: getWrapperSearchRoots(),
|
|
8206
|
-
crossFileKeyRegistry,
|
|
8207
|
-
optionKeyAttribute
|
|
8208
|
-
}
|
|
8209
|
-
)
|
|
8210
|
-
]
|
|
8211
|
-
});
|
|
8212
|
-
} catch {
|
|
8213
|
-
}
|
|
8214
|
-
supplemented++;
|
|
8215
8119
|
}
|
|
8120
|
+
current += ch;
|
|
8216
8121
|
}
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
|
|
8221
|
-
|
|
8222
|
-
|
|
8223
|
-
|
|
8224
|
-
|
|
8225
|
-
|
|
8226
|
-
|
|
8227
|
-
|
|
8228
|
-
|
|
8229
|
-
setResolveToComponentNameFn(() => null);
|
|
8230
|
-
return;
|
|
8231
|
-
}
|
|
8232
|
-
let result;
|
|
8233
|
-
if (routerType === "nuxt") {
|
|
8234
|
-
result = await introspectNuxtPages(projectRootRef.current, { pageDirs: getPageDirsAbs() });
|
|
8235
|
-
} else {
|
|
8236
|
-
const resolvedRouterEntry = getResolvedRouterEntry();
|
|
8237
|
-
if (!resolvedRouterEntry)
|
|
8238
|
-
throw new Error("[vue-pom-generator] router.entry is required when router introspection is enabled.");
|
|
8239
|
-
result = await parseRouterFileFromCwd(resolvedRouterEntry, {
|
|
8240
|
-
moduleShims: routerModuleShims,
|
|
8241
|
-
componentNaming: {
|
|
8242
|
-
projectRoot: projectRootRef.current,
|
|
8243
|
-
viewsDirAbs: getViewsDirAbs(),
|
|
8244
|
-
sourceDirs: getSourceDirs()
|
|
8245
|
-
}
|
|
8246
|
-
});
|
|
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;
|
|
8247
8134
|
}
|
|
8248
|
-
|
|
8249
|
-
|
|
8250
|
-
|
|
8251
|
-
|
|
8252
|
-
|
|
8253
|
-
|
|
8254
|
-
|
|
8255
|
-
|
|
8256
|
-
|
|
8257
|
-
|
|
8258
|
-
|
|
8259
|
-
|
|
8260
|
-
|
|
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);
|
|
8261
8155
|
}
|
|
8262
|
-
|
|
8263
|
-
});
|
|
8264
|
-
if (!fs.existsSync(basePageClassPath)) {
|
|
8265
|
-
this.error(`Base page runtime file not found at ${basePageClassPath}. Ensure it is included in the build.`);
|
|
8266
|
-
}
|
|
8267
|
-
this.addWatchFile(basePageClassPath);
|
|
8268
|
-
const pointerPath = path.resolve(path.dirname(basePageClassPath), "pointer.ts");
|
|
8269
|
-
if (!fs.existsSync(pointerPath)) {
|
|
8270
|
-
this.error(`pointer.ts not found at ${pointerPath}. Ensure it is included in the build.`);
|
|
8271
|
-
}
|
|
8272
|
-
this.addWatchFile(pointerPath);
|
|
8273
|
-
const calloutPath = path.resolve(path.dirname(basePageClassPath), "callout.ts");
|
|
8274
|
-
if (!fs.existsSync(calloutPath)) {
|
|
8275
|
-
this.error(`callout.ts not found at ${calloutPath}. Ensure it is included in the build.`);
|
|
8276
|
-
}
|
|
8277
|
-
this.addWatchFile(calloutPath);
|
|
8278
|
-
const floatingUiCalloutPath = path.resolve(path.dirname(basePageClassPath), "floating-ui-callout.ts");
|
|
8279
|
-
if (fs.existsSync(floatingUiCalloutPath)) {
|
|
8280
|
-
this.addWatchFile(floatingUiCalloutPath);
|
|
8281
|
-
}
|
|
8282
|
-
},
|
|
8283
|
-
async buildEnd(error) {
|
|
8284
|
-
if (error) {
|
|
8285
|
-
return;
|
|
8286
|
-
}
|
|
8287
|
-
supplementHierarchyFromFilesystem();
|
|
8288
|
-
const metrics = summarizeHierarchyMap(componentHierarchyMap);
|
|
8289
|
-
if (metrics.dataTestIdCount <= 0) {
|
|
8290
|
-
return;
|
|
8156
|
+
continue;
|
|
8291
8157
|
}
|
|
8292
|
-
if (
|
|
8293
|
-
|
|
8158
|
+
if (node.type === compilerCore.NodeTypes.ELEMENT) {
|
|
8159
|
+
visit(node.children);
|
|
8294
8160
|
}
|
|
8295
|
-
await generateFiles(componentHierarchyMap, vueFilesPathMap, normalizedBasePagePath, {
|
|
8296
|
-
outDir,
|
|
8297
|
-
emitLanguages,
|
|
8298
|
-
typescriptOutputStructure,
|
|
8299
|
-
csharp,
|
|
8300
|
-
generateFixtures,
|
|
8301
|
-
customPomAttachments,
|
|
8302
|
-
projectRoot: projectRootRef.current,
|
|
8303
|
-
customPomDir,
|
|
8304
|
-
requireCustomPomDir,
|
|
8305
|
-
customPomImportAliases,
|
|
8306
|
-
customPomImportNameCollisionBehavior,
|
|
8307
|
-
testIdAttribute,
|
|
8308
|
-
vueRouterFluentChaining: routerAwarePoms,
|
|
8309
|
-
routerEntry: getResolvedRouterEntry(),
|
|
8310
|
-
routerType,
|
|
8311
|
-
pageDirs: getPageDirs(),
|
|
8312
|
-
componentDirs: getComponentDirs(),
|
|
8313
|
-
layoutDirs: getLayoutDirs()
|
|
8314
|
-
});
|
|
8315
|
-
lastGeneratedMetrics = metrics;
|
|
8316
|
-
loggerRef.current.info(`generated POMs (${metrics.entryCount} entries, ${metrics.interactiveComponentCount} interactive components, ${metrics.dataTestIdCount} selectors)`);
|
|
8317
|
-
},
|
|
8318
|
-
closeBundle() {
|
|
8319
|
-
loggerRef.current.info("build complete");
|
|
8320
8161
|
}
|
|
8321
8162
|
};
|
|
8163
|
+
visit(children);
|
|
8164
|
+
const text = collapseWhitespace(parts.join(" "));
|
|
8165
|
+
return text || void 0;
|
|
8322
8166
|
}
|
|
8323
|
-
function
|
|
8324
|
-
const {
|
|
8325
|
-
|
|
8326
|
-
|
|
8327
|
-
|
|
8328
|
-
|
|
8329
|
-
|
|
8330
|
-
|
|
8331
|
-
|
|
8332
|
-
|
|
8333
|
-
|
|
8334
|
-
|
|
8335
|
-
|
|
8336
|
-
|
|
8337
|
-
|
|
8338
|
-
|
|
8339
|
-
|
|
8340
|
-
|
|
8341
|
-
|
|
8342
|
-
|
|
8343
|
-
|
|
8344
|
-
|
|
8345
|
-
|
|
8346
|
-
|
|
8347
|
-
|
|
8348
|
-
|
|
8349
|
-
|
|
8350
|
-
|
|
8351
|
-
|
|
8352
|
-
|
|
8353
|
-
|
|
8354
|
-
|
|
8355
|
-
|
|
8356
|
-
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8360
|
-
|
|
8361
|
-
|
|
8362
|
-
|
|
8363
|
-
|
|
8364
|
-
]));
|
|
8365
|
-
const resolveProjectPath = (maybePath) => {
|
|
8366
|
-
if (path.isAbsolute(maybePath))
|
|
8367
|
-
return maybePath;
|
|
8368
|
-
const candidates = getProjectRootCandidates().map((root) => path.resolve(root, maybePath));
|
|
8369
|
-
return candidates.find((candidate) => fs.existsSync(candidate)) ?? candidates[0];
|
|
8370
|
-
};
|
|
8371
|
-
const getSourceDirRoots = () => Array.from(new Set(
|
|
8372
|
-
getProjectRootCandidates().flatMap((root) => getSourceDirs().map((dir) => path.resolve(root, dir)))
|
|
8373
|
-
));
|
|
8374
|
-
const isContainedInScanDirs = (filePath) => {
|
|
8375
|
-
const absolutePath = path.resolve(filePath);
|
|
8376
|
-
return getSourceDirRoots().some((scanDirAbs) => isPathWithinDir(absolutePath, scanDirAbs));
|
|
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];
|
|
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
|
|
8377
8208
|
};
|
|
8378
|
-
return
|
|
8379
|
-
|
|
8380
|
-
|
|
8381
|
-
|
|
8382
|
-
|
|
8383
|
-
|
|
8384
|
-
|
|
8385
|
-
|
|
8386
|
-
|
|
8387
|
-
|
|
8388
|
-
|
|
8389
|
-
|
|
8390
|
-
|
|
8391
|
-
|
|
8392
|
-
|
|
8393
|
-
|
|
8394
|
-
|
|
8395
|
-
|
|
8396
|
-
|
|
8397
|
-
setRouteNameToComponentNameMap(/* @__PURE__ */ new Map());
|
|
8398
|
-
setResolveToComponentNameFn(() => null);
|
|
8399
|
-
return;
|
|
8400
|
-
}
|
|
8401
|
-
let result;
|
|
8402
|
-
if (routerType === "nuxt") {
|
|
8403
|
-
result = await introspectNuxtPages(projectRootRef.current, { pageDirs: getPageDirsAbs() });
|
|
8404
|
-
} else {
|
|
8405
|
-
const resolvedRouterEntry = getResolvedRouterEntry();
|
|
8406
|
-
if (!resolvedRouterEntry)
|
|
8407
|
-
throw new Error("[vue-pom-generator] router.entry is required when router introspection is enabled.");
|
|
8408
|
-
result = await parseRouterFileFromCwd(resolvedRouterEntry, {
|
|
8409
|
-
moduleShims: routerModuleShims,
|
|
8410
|
-
componentNaming: {
|
|
8411
|
-
projectRoot: projectRootRef.current,
|
|
8412
|
-
viewsDirAbs: getViewsDirAbs(),
|
|
8413
|
-
sourceDirs: getSourceDirs(),
|
|
8414
|
-
extraRoots: [process.cwd()]
|
|
8415
|
-
}
|
|
8416
|
-
});
|
|
8417
|
-
}
|
|
8418
|
-
const { routeNameMap, routePathMap } = result;
|
|
8419
|
-
setRouteNameToComponentNameMap(routeNameMap);
|
|
8420
|
-
setResolveToComponentNameFn((to) => {
|
|
8421
|
-
if (typeof to === "string") {
|
|
8422
|
-
return routePathMap.get(to) ?? null;
|
|
8423
|
-
}
|
|
8424
|
-
const maybe = to;
|
|
8425
|
-
if (typeof maybe.name === "string" && maybe.name.length) {
|
|
8426
|
-
const key = toPascalCase(maybe.name);
|
|
8427
|
-
return routeNameMap.get(key) ?? null;
|
|
8428
|
-
}
|
|
8429
|
-
if (typeof maybe.path === "string" && maybe.path.length) {
|
|
8430
|
-
return routePathMap.get(maybe.path) ?? null;
|
|
8431
|
-
}
|
|
8432
|
-
return null;
|
|
8433
|
-
});
|
|
8434
|
-
})();
|
|
8435
|
-
const logInfo = (message) => loggerRef.current.info(message);
|
|
8436
|
-
const logDebug = (message) => loggerRef.current.debug(message);
|
|
8437
|
-
let scheduleVueFileRegenLocal = null;
|
|
8438
|
-
const formatMs = (ms) => `${ms.toFixed(1)}ms`;
|
|
8439
|
-
const extractTemplateFromSfc = (source, filename) => {
|
|
8440
|
-
const { descriptor } = compilerSfc.parse(source, {
|
|
8441
|
-
filename: filename ?? "anonymous.vue"
|
|
8442
|
-
});
|
|
8443
|
-
return descriptor.template?.content ?? "";
|
|
8444
|
-
};
|
|
8445
|
-
const getScriptInfo = (source, filename) => {
|
|
8446
|
-
try {
|
|
8447
|
-
const { descriptor } = compilerSfc.parse(source, { filename });
|
|
8448
|
-
if (!descriptor.script && !descriptor.scriptSetup)
|
|
8449
|
-
return { bindings: void 0, isScriptSetup: false };
|
|
8450
|
-
const scriptBlock = compilerSfc.compileScript(descriptor, { id: filename });
|
|
8451
|
-
return { bindings: scriptBlock.bindings, isScriptSetup: !!descriptor.scriptSetup };
|
|
8452
|
-
} catch {
|
|
8453
|
-
return { bindings: void 0, isScriptSetup: false };
|
|
8454
|
-
}
|
|
8455
|
-
};
|
|
8456
|
-
const walkFilesRecursive = (rootDir) => {
|
|
8457
|
-
const out = [];
|
|
8458
|
-
const stack = [rootDir];
|
|
8459
|
-
while (stack.length) {
|
|
8460
|
-
const dir = stack.pop();
|
|
8461
|
-
if (!dir) continue;
|
|
8462
|
-
let entries = [];
|
|
8463
|
-
try {
|
|
8464
|
-
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
8465
|
-
} catch {
|
|
8466
|
-
continue;
|
|
8467
|
-
}
|
|
8468
|
-
for (const ent of entries) {
|
|
8469
|
-
if (ent.isDirectory()) {
|
|
8470
|
-
if (ent.name === "node_modules" || ent.name === ".git" || ent.name === "dist")
|
|
8471
|
-
continue;
|
|
8472
|
-
stack.push(path.join(dir, ent.name));
|
|
8473
|
-
continue;
|
|
8474
|
-
}
|
|
8475
|
-
if (ent.isFile() && ent.name.endsWith(".vue")) {
|
|
8476
|
-
out.push(path.join(dir, ent.name));
|
|
8477
|
-
}
|
|
8478
|
-
}
|
|
8479
|
-
}
|
|
8480
|
-
return out;
|
|
8481
|
-
};
|
|
8482
|
-
let snapshotHierarchy = /* @__PURE__ */ new Map();
|
|
8483
|
-
let snapshotVuePathMap = /* @__PURE__ */ new Map();
|
|
8484
|
-
const filePathToComponentName = /* @__PURE__ */ new Map();
|
|
8485
|
-
const createEmptyComponentDependencies = (absolutePath) => {
|
|
8486
|
-
const viewsDirAbs = path.resolve(getViewsDirAbs());
|
|
8487
|
-
const relToViewsDir = path.relative(viewsDirAbs, absolutePath);
|
|
8488
|
-
const isView = !relToViewsDir.startsWith("..") && !path.isAbsolute(relToViewsDir);
|
|
8489
|
-
return {
|
|
8490
|
-
filePath: absolutePath,
|
|
8491
|
-
childrenComponentSet: /* @__PURE__ */ new Set(),
|
|
8492
|
-
usedComponentSet: /* @__PURE__ */ new Set(),
|
|
8493
|
-
dataTestIdSet: /* @__PURE__ */ new Set(),
|
|
8494
|
-
isView,
|
|
8495
|
-
methodsContent: ""
|
|
8496
|
-
};
|
|
8497
|
-
};
|
|
8498
|
-
const getComponentNameForFile = (filePath) => {
|
|
8499
|
-
const normalized = path.resolve(filePath);
|
|
8500
|
-
const existing = filePathToComponentName.get(normalized);
|
|
8501
|
-
if (existing)
|
|
8502
|
-
return existing;
|
|
8503
|
-
const name = resolveComponentNameFromPath({
|
|
8504
|
-
filename: normalized,
|
|
8505
|
-
projectRoot: projectRootRef.current,
|
|
8506
|
-
viewsDirAbs: getViewsDirAbs(),
|
|
8507
|
-
sourceDirs: getSourceDirs(),
|
|
8508
|
-
extraRoots: [process.cwd()]
|
|
8509
|
-
});
|
|
8510
|
-
filePathToComponentName.set(normalized, name);
|
|
8511
|
-
return name;
|
|
8512
|
-
};
|
|
8513
|
-
const compileVueFileIntoSnapshot = (filePath, targetHierarchy = snapshotHierarchy, targetVuePathMap = snapshotVuePathMap) => {
|
|
8514
|
-
const started = node_perf_hooks.performance.now();
|
|
8515
|
-
const absolutePath = path.resolve(filePath);
|
|
8516
|
-
const componentName = getComponentNameForFile(absolutePath);
|
|
8517
|
-
let sfc = "";
|
|
8518
|
-
try {
|
|
8519
|
-
sfc = fs.readFileSync(absolutePath, "utf8");
|
|
8520
|
-
} catch {
|
|
8521
|
-
return { componentName, ms: node_perf_hooks.performance.now() - started, compiled: false };
|
|
8522
|
-
}
|
|
8523
|
-
const template = extractTemplateFromSfc(sfc, absolutePath);
|
|
8524
|
-
if (!template.trim()) {
|
|
8525
|
-
targetVuePathMap.set(componentName, absolutePath);
|
|
8526
|
-
targetHierarchy.set(componentName, createEmptyComponentDependencies(absolutePath));
|
|
8527
|
-
return { componentName, ms: node_perf_hooks.performance.now() - started, compiled: true };
|
|
8528
|
-
}
|
|
8529
|
-
const { bindings: bindingMetadata, isScriptSetup } = getScriptInfo(sfc, absolutePath);
|
|
8530
|
-
const provisionalHierarchy = /* @__PURE__ */ new Map();
|
|
8531
|
-
const provisionalKeyRegistry = /* @__PURE__ */ new Map();
|
|
8532
|
-
const provisionalVuePathMap = new Map(targetVuePathMap);
|
|
8533
|
-
provisionalVuePathMap.set(componentName, absolutePath);
|
|
8534
|
-
compilerDom__namespace.compile(template, {
|
|
8535
|
-
filename: absolutePath,
|
|
8536
|
-
prefixIdentifiers: true,
|
|
8537
|
-
inline: isScriptSetup,
|
|
8538
|
-
bindingMetadata,
|
|
8539
|
-
// Vue templates may contain TypeScript type annotations in expressions
|
|
8540
|
-
// (e.g. `@row-click="(row: RowType) => navigateTo(...)"` in Nuxt + TS
|
|
8541
|
-
// apps). Without this flag, Vue's internal processExpression step
|
|
8542
|
-
// delegates to @babel/parser without the TS plugin and crashes on
|
|
8543
|
-
// "Unexpected token, expected ','".
|
|
8544
|
-
expressionPlugins: ["typescript"],
|
|
8545
|
-
nodeTransforms: [
|
|
8546
|
-
createTestIdTransform(
|
|
8547
|
-
componentName,
|
|
8548
|
-
provisionalHierarchy,
|
|
8549
|
-
nativeWrappers,
|
|
8550
|
-
excludedComponents,
|
|
8551
|
-
getViewsDirAbs(),
|
|
8552
|
-
{
|
|
8553
|
-
existingIdBehavior: existingIdBehavior ?? "error",
|
|
8554
|
-
nameCollisionBehavior,
|
|
8555
|
-
missingSemanticNameBehavior,
|
|
8556
|
-
testIdAttribute,
|
|
8557
|
-
warn: (message) => loggerRef.current.warn(message),
|
|
8558
|
-
vueFilesPathMap: provisionalVuePathMap,
|
|
8559
|
-
wrapperSearchRoots: getWrapperSearchRoots(),
|
|
8560
|
-
crossFileKeyRegistry: provisionalKeyRegistry,
|
|
8561
|
-
optionKeyAttribute
|
|
8562
|
-
}
|
|
8563
|
-
)
|
|
8564
|
-
]
|
|
8565
|
-
});
|
|
8566
|
-
targetVuePathMap.set(componentName, absolutePath);
|
|
8567
|
-
targetHierarchy.set(
|
|
8568
|
-
componentName,
|
|
8569
|
-
provisionalHierarchy.get(componentName) ?? createEmptyComponentDependencies(absolutePath)
|
|
8570
|
-
);
|
|
8571
|
-
return { componentName, ms: node_perf_hooks.performance.now() - started, compiled: true };
|
|
8572
|
-
};
|
|
8573
|
-
const fullRebuildSnapshotFromFilesystem = (logLabel) => {
|
|
8574
|
-
const t0 = node_perf_hooks.performance.now();
|
|
8575
|
-
const nextHierarchy = /* @__PURE__ */ new Map();
|
|
8576
|
-
const nextVuePathMap = /* @__PURE__ */ new Map();
|
|
8577
|
-
filePathToComponentName.clear();
|
|
8578
|
-
let totalVueFiles = 0;
|
|
8579
|
-
let compiledCount = 0;
|
|
8580
|
-
for (const absDir of getSourceDirRoots()) {
|
|
8581
|
-
if (!fs.existsSync(absDir))
|
|
8582
|
-
continue;
|
|
8583
|
-
const vueFiles = walkFilesRecursive(absDir);
|
|
8584
|
-
totalVueFiles += vueFiles.length;
|
|
8585
|
-
for (const file of vueFiles) {
|
|
8586
|
-
const res = compileVueFileIntoSnapshot(file, nextHierarchy, nextVuePathMap);
|
|
8587
|
-
if (res.compiled)
|
|
8588
|
-
compiledCount++;
|
|
8589
|
-
}
|
|
8590
|
-
}
|
|
8591
|
-
snapshotHierarchy = nextHierarchy;
|
|
8592
|
-
snapshotVuePathMap = nextVuePathMap;
|
|
8593
|
-
const t1 = node_perf_hooks.performance.now();
|
|
8594
|
-
logInfo(`scan(${logLabel}): found ${totalVueFiles} .vue files in ${getSourceDirs().join(", ")}`);
|
|
8595
|
-
logInfo(`compile(${logLabel}): ${compiledCount}/${totalVueFiles} files in ${formatMs(t1 - t0)} (components=${snapshotHierarchy.size})`);
|
|
8596
|
-
};
|
|
8597
|
-
const generateAggregatedFromSnapshot = async (logLabel) => {
|
|
8598
|
-
const t0 = node_perf_hooks.performance.now();
|
|
8599
|
-
await generateFiles(snapshotHierarchy, snapshotVuePathMap, normalizedBasePagePath, {
|
|
8600
|
-
outDir,
|
|
8601
|
-
emitLanguages,
|
|
8602
|
-
typescriptOutputStructure,
|
|
8603
|
-
csharp,
|
|
8604
|
-
generateFixtures,
|
|
8605
|
-
customPomAttachments,
|
|
8606
|
-
projectRoot: projectRootRef.current,
|
|
8607
|
-
customPomDir,
|
|
8608
|
-
requireCustomPomDir,
|
|
8609
|
-
customPomImportAliases,
|
|
8610
|
-
customPomImportNameCollisionBehavior,
|
|
8611
|
-
pageDirs: getPageDirs(),
|
|
8612
|
-
componentDirs: getComponentDirs(),
|
|
8613
|
-
layoutDirs: getLayoutDirs(),
|
|
8614
|
-
testIdAttribute,
|
|
8615
|
-
vueRouterFluentChaining: routerAwarePoms,
|
|
8616
|
-
routerEntry: getResolvedRouterEntry(),
|
|
8617
|
-
routerType
|
|
8618
|
-
});
|
|
8619
|
-
const t1 = node_perf_hooks.performance.now();
|
|
8620
|
-
logInfo(`generate(${logLabel}): components=${snapshotHierarchy.size} in ${formatMs(t1 - t0)}`);
|
|
8621
|
-
};
|
|
8622
|
-
let timer = null;
|
|
8623
|
-
let maxWaitTimer = null;
|
|
8624
|
-
const pendingChangedVueFiles = /* @__PURE__ */ new Set();
|
|
8625
|
-
const pendingDeletedComponents = /* @__PURE__ */ new Set();
|
|
8626
|
-
let regenerationSequence = Promise.resolve();
|
|
8627
|
-
const initialBuildPromise = (async () => {
|
|
8628
|
-
const t0 = node_perf_hooks.performance.now();
|
|
8629
|
-
await routerInitPromise;
|
|
8630
|
-
fullRebuildSnapshotFromFilesystem("startup");
|
|
8631
|
-
await generateAggregatedFromSnapshot("startup");
|
|
8632
|
-
const t1 = node_perf_hooks.performance.now();
|
|
8633
|
-
logInfo(`startup total: ${formatMs(t1 - t0)}`);
|
|
8634
|
-
})();
|
|
8635
|
-
const logGenerationError = (reason, message) => {
|
|
8636
|
-
server.config.logger.error(`[vue-pom-generator] dev generation failed during ${reason}: ${message}`);
|
|
8637
|
-
};
|
|
8638
|
-
const regenerateFromPending = async (reason) => {
|
|
8639
|
-
const t0 = node_perf_hooks.performance.now();
|
|
8640
|
-
await initialBuildPromise;
|
|
8641
|
-
const nextHierarchy = new Map(snapshotHierarchy);
|
|
8642
|
-
const nextVuePathMap = new Map(snapshotVuePathMap);
|
|
8643
|
-
for (const componentName of pendingDeletedComponents) {
|
|
8644
|
-
nextHierarchy.delete(componentName);
|
|
8645
|
-
nextVuePathMap.delete(componentName);
|
|
8646
|
-
}
|
|
8647
|
-
const files = Array.from(pendingChangedVueFiles);
|
|
8648
|
-
const deletedCount = pendingDeletedComponents.size;
|
|
8649
|
-
pendingChangedVueFiles.clear();
|
|
8650
|
-
pendingDeletedComponents.clear();
|
|
8651
|
-
let compileMs = 0;
|
|
8652
|
-
for (const f of files) {
|
|
8653
|
-
const res = compileVueFileIntoSnapshot(f, nextHierarchy, nextVuePathMap);
|
|
8654
|
-
compileMs += res.ms;
|
|
8655
|
-
}
|
|
8656
|
-
snapshotHierarchy = nextHierarchy;
|
|
8657
|
-
snapshotVuePathMap = nextVuePathMap;
|
|
8658
|
-
const t1 = node_perf_hooks.performance.now();
|
|
8659
|
-
await generateAggregatedFromSnapshot(reason);
|
|
8660
|
-
const t2 = node_perf_hooks.performance.now();
|
|
8661
|
-
return {
|
|
8662
|
-
files,
|
|
8663
|
-
deletedCount,
|
|
8664
|
-
compileMs,
|
|
8665
|
-
preGenerateMs: t1 - t0,
|
|
8666
|
-
generateMs: t2 - t1,
|
|
8667
|
-
totalMs: t2 - t0
|
|
8668
|
-
};
|
|
8669
|
-
};
|
|
8670
|
-
const enqueueRegeneration = (reason) => {
|
|
8671
|
-
const currentRun = regenerationSequence.catch(() => void 0).then(() => regenerateFromPending(reason));
|
|
8672
|
-
regenerationSequence = currentRun.then(() => void 0, () => void 0);
|
|
8673
|
-
return currentRun;
|
|
8674
|
-
};
|
|
8675
|
-
const runtimeDir = path.dirname(basePageClassPath);
|
|
8676
|
-
const localPluginDir = path.resolve(projectRootRef.current, "vite-plugins", "vue-pom-generator");
|
|
8677
|
-
server.watcher.add([
|
|
8678
|
-
...fs.existsSync(localPluginDir) ? [localPluginDir] : [],
|
|
8679
|
-
basePageClassPath,
|
|
8680
|
-
path.resolve(runtimeDir, "pointer.ts"),
|
|
8681
|
-
path.resolve(runtimeDir, "callout.ts"),
|
|
8682
|
-
path.resolve(runtimeDir, "floating-ui-callout.ts")
|
|
8683
|
-
]);
|
|
8684
|
-
scheduleVueFileRegenLocal = (filePath, source) => {
|
|
8685
|
-
pendingChangedVueFiles.add(filePath);
|
|
8686
|
-
logDebug(`queued(${source}): files=${pendingChangedVueFiles.size} deleted=${pendingDeletedComponents.size}`);
|
|
8687
|
-
scheduleAggregatedRegen();
|
|
8688
|
-
};
|
|
8689
|
-
scheduleVueFileRegen = scheduleVueFileRegenLocal;
|
|
8690
|
-
function scheduleAggregatedRegen() {
|
|
8691
|
-
const wasEmpty = pendingChangedVueFiles.size === 0 && pendingDeletedComponents.size === 0;
|
|
8692
|
-
const MAX_WAIT_MS = 750;
|
|
8693
|
-
if (!maxWaitTimer) {
|
|
8694
|
-
maxWaitTimer = setTimeout(() => {
|
|
8695
|
-
if (timer) {
|
|
8696
|
-
clearTimeout(timer);
|
|
8697
|
-
timer = null;
|
|
8698
|
-
}
|
|
8699
|
-
maxWaitTimer = null;
|
|
8700
|
-
void enqueueRegeneration("max-wait").then(({ files, deletedCount, compileMs, preGenerateMs, generateMs, totalMs }) => {
|
|
8701
|
-
logInfo(
|
|
8702
|
-
`max-wait: files=${files.length} deleted=${deletedCount} compile=${formatMs(compileMs)} wall=${formatMs(preGenerateMs)} gen=${formatMs(generateMs)} total=${formatMs(totalMs)}`
|
|
8703
|
-
);
|
|
8704
|
-
}).catch((error) => {
|
|
8705
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
8706
|
-
logGenerationError("max-wait", message);
|
|
8707
|
-
});
|
|
8708
|
-
}, MAX_WAIT_MS);
|
|
8709
|
-
}
|
|
8710
|
-
if (wasEmpty) {
|
|
8711
|
-
const queuedFiles = pendingChangedVueFiles.size;
|
|
8712
|
-
const queuedDeletes = pendingDeletedComponents.size;
|
|
8713
|
-
logDebug(`queued: files=${queuedFiles} deleted=${queuedDeletes}`);
|
|
8714
|
-
}
|
|
8715
|
-
if (timer)
|
|
8716
|
-
clearTimeout(timer);
|
|
8717
|
-
timer = setTimeout(() => {
|
|
8718
|
-
timer = null;
|
|
8719
|
-
if (maxWaitTimer) {
|
|
8720
|
-
clearTimeout(maxWaitTimer);
|
|
8721
|
-
maxWaitTimer = null;
|
|
8722
|
-
}
|
|
8723
|
-
const reason = pendingChangedVueFiles.size || pendingDeletedComponents.size ? "batched" : "noop";
|
|
8724
|
-
void enqueueRegeneration(reason).then(({ files, deletedCount, compileMs, preGenerateMs, generateMs, totalMs }) => {
|
|
8725
|
-
if (files.length || deletedCount) {
|
|
8726
|
-
logInfo(
|
|
8727
|
-
`batched: files=${files.length} deleted=${deletedCount} compile=${formatMs(compileMs)} wall=${formatMs(preGenerateMs)} gen=${formatMs(generateMs)} total=${formatMs(totalMs)}`
|
|
8728
|
-
);
|
|
8729
|
-
}
|
|
8730
|
-
}).catch((error) => {
|
|
8731
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
8732
|
-
logGenerationError(reason, message);
|
|
8733
|
-
});
|
|
8734
|
-
}, 75);
|
|
8735
|
-
}
|
|
8736
|
-
server.watcher.on("change", async (changedPath) => {
|
|
8737
|
-
const changedAbsPosix = path.posix.normalize(path.resolve(changedPath));
|
|
8738
|
-
const outDirAbsPosix = path.posix.normalize(path.resolve(projectRootRef.current, outDir ?? "./pom"));
|
|
8739
|
-
if (changedAbsPosix.startsWith(`${outDirAbsPosix}/`) && (changedAbsPosix.endsWith(".g.ts") || changedAbsPosix.endsWith(".g.ts.map"))) {
|
|
8740
|
-
return;
|
|
8741
|
-
}
|
|
8742
|
-
if (changedAbsPosix.includes("/vite-plugins/vue-pom-generator/")) {
|
|
8743
|
-
void server.restart();
|
|
8744
|
-
}
|
|
8745
|
-
});
|
|
8746
|
-
server.watcher.on("add", (p) => {
|
|
8747
|
-
if (typeof p !== "string")
|
|
8748
|
-
return;
|
|
8749
|
-
if (!p.endsWith(".vue"))
|
|
8750
|
-
return;
|
|
8751
|
-
if (!isContainedInScanDirs(p))
|
|
8752
|
-
return;
|
|
8753
|
-
void (async () => {
|
|
8754
|
-
await initialBuildPromise;
|
|
8755
|
-
pendingChangedVueFiles.add(p);
|
|
8756
|
-
scheduleAggregatedRegen();
|
|
8757
|
-
})();
|
|
8758
|
-
});
|
|
8759
|
-
server.watcher.on("unlink", (p) => {
|
|
8760
|
-
if (typeof p !== "string")
|
|
8761
|
-
return;
|
|
8762
|
-
if (!p.endsWith(".vue"))
|
|
8763
|
-
return;
|
|
8764
|
-
if (!isContainedInScanDirs(p))
|
|
8765
|
-
return;
|
|
8766
|
-
void (async () => {
|
|
8767
|
-
await initialBuildPromise;
|
|
8768
|
-
const absolutePath = path.resolve(p);
|
|
8769
|
-
const componentName = getComponentNameForFile(absolutePath);
|
|
8770
|
-
filePathToComponentName.delete(absolutePath);
|
|
8771
|
-
pendingDeletedComponents.add(componentName);
|
|
8772
|
-
scheduleAggregatedRegen();
|
|
8773
|
-
})();
|
|
8774
|
-
});
|
|
8775
|
-
setTimeout(() => {
|
|
8776
|
-
}, 250);
|
|
8777
|
-
await initialBuildPromise;
|
|
8778
|
-
}
|
|
8779
|
-
};
|
|
8780
|
-
}
|
|
8781
|
-
function supportsInlineTextAccessibleName(role) {
|
|
8782
|
-
return role === "button" || role === "radio";
|
|
8783
|
-
}
|
|
8784
|
-
function buildAccessibilityAudit(metadata, inferredRole) {
|
|
8785
|
-
if (!metadata || !inferredRole) {
|
|
8786
|
-
return void 0;
|
|
8787
|
-
}
|
|
8788
|
-
const role = normalizePomRoleLabel(inferredRole).toLowerCase();
|
|
8789
|
-
const dynamicProps = new Set(metadata.dynamicProps ?? []);
|
|
8790
|
-
const hasDynamicAccessibleNameSignal = dynamicProps.has("aria-label") || dynamicProps.has("title") || !!metadata.hasDynamicText;
|
|
8791
|
-
let accessibleNameSource;
|
|
8792
|
-
const reasons = [];
|
|
8793
|
-
if (metadata.staticAriaLabel) {
|
|
8794
|
-
accessibleNameSource = "aria-label";
|
|
8795
|
-
} else if (supportsInlineTextAccessibleName(role) && metadata.staticTextContent) {
|
|
8796
|
-
accessibleNameSource = "text";
|
|
8797
|
-
} else if (metadata.staticTitle) {
|
|
8798
|
-
accessibleNameSource = "title";
|
|
8799
|
-
} else if (hasDynamicAccessibleNameSignal) {
|
|
8800
|
-
accessibleNameSource = "dynamic";
|
|
8801
|
-
} else if (role === "input" || role === "select") {
|
|
8802
|
-
accessibleNameSource = "unknown";
|
|
8803
|
-
reasons.push("No inline accessible-name signal was found; the element may rely on external markup such as a separate <label>.");
|
|
8804
|
-
} else {
|
|
8805
|
-
accessibleNameSource = "missing";
|
|
8806
|
-
reasons.push("No compile-time accessible-name signal was found.");
|
|
8807
|
-
}
|
|
8808
|
-
return {
|
|
8809
|
-
needsReview: accessibleNameSource === "unknown" || accessibleNameSource === "missing",
|
|
8810
|
-
accessibleNameSource,
|
|
8811
|
-
reasons,
|
|
8812
|
-
...metadata.staticAriaLabel ? { staticAriaLabel: metadata.staticAriaLabel } : {},
|
|
8813
|
-
...metadata.staticRole ? { staticRole: metadata.staticRole } : {},
|
|
8814
|
-
...metadata.staticTitle ? { staticTitle: metadata.staticTitle } : {},
|
|
8815
|
-
...metadata.staticTextContent ? { staticTextContent: metadata.staticTextContent } : {}
|
|
8816
|
-
};
|
|
8817
|
-
}
|
|
8818
|
-
function collectAccessibilityReviewWarnings(manifest) {
|
|
8819
|
-
const warnings = [];
|
|
8820
|
-
for (const [componentName, component] of Object.entries(manifest)) {
|
|
8821
|
-
for (const entry of component.entries) {
|
|
8822
|
-
if (!entry.accessibility?.needsReview) {
|
|
8823
|
-
continue;
|
|
8824
|
-
}
|
|
8825
|
-
const entryLabel = entry.generatedPropertyName ?? entry.testId;
|
|
8826
|
-
const reasonText = entry.accessibility.reasons.join(" ");
|
|
8827
|
-
warnings.push(
|
|
8828
|
-
`[vue-pom-generator] Accessibility review suggested for ${componentName}.${entryLabel} (role=${entry.inferredRole ?? "unknown"}, testId=${JSON.stringify(entry.testId)}): ${reasonText}`
|
|
8829
|
-
);
|
|
8830
|
-
}
|
|
8831
|
-
}
|
|
8832
|
-
return warnings;
|
|
8833
|
-
}
|
|
8834
|
-
function matchesPrimarySelector(extraMethod, pom) {
|
|
8835
|
-
if (extraMethod.selector.kind !== "testId") {
|
|
8836
|
-
return false;
|
|
8837
|
-
}
|
|
8838
|
-
return extraMethod.selector.testId.formatted === pom.selector.formatted && extraMethod.selector.testId.patternKind === pom.selector.patternKind;
|
|
8839
|
-
}
|
|
8840
|
-
function getManifestEntry(componentName, entry, componentMetadata, extraMethods) {
|
|
8841
|
-
const testId = entry.selectorValue.formatted;
|
|
8842
|
-
const metadata = componentMetadata?.get(testId);
|
|
8843
|
-
const pom = entry.pom;
|
|
8844
|
-
const generatedActionName = pom ? buildPomGeneratedActionName(pom) : null;
|
|
8845
|
-
const extraActionNames = pom ? extraMethods.filter((extraMethod) => matchesPrimarySelector(extraMethod, pom)).map((extraMethod) => extraMethod.name).sort((a, b) => a.localeCompare(b)) : [];
|
|
8846
|
-
const generatedActionNames = Array.from(/* @__PURE__ */ new Set([
|
|
8847
|
-
...generatedActionName ? [generatedActionName] : [],
|
|
8848
|
-
...extraActionNames.filter((name) => name !== generatedActionName)
|
|
8849
|
-
]));
|
|
8850
|
-
const accessibility = buildAccessibilityAudit(metadata, pom?.nativeRole ?? null);
|
|
8209
|
+
return metadata;
|
|
8210
|
+
}
|
|
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)
|
|
8226
|
+
]));
|
|
8227
|
+
const accessibility = buildAccessibilityAudit(metadata, pom?.nativeRole ?? null);
|
|
8851
8228
|
return {
|
|
8852
8229
|
testId,
|
|
8853
8230
|
selectorPatternKind: entry.selectorValue.patternKind,
|
|
@@ -8976,157 +8353,333 @@ function generatePomManifestModule(componentHierarchyMap, elementMetadata) {
|
|
|
8976
8353
|
});
|
|
8977
8354
|
});
|
|
8978
8355
|
}
|
|
8979
|
-
|
|
8980
|
-
|
|
8981
|
-
|
|
8982
|
-
|
|
8983
|
-
|
|
8984
|
-
|
|
8985
|
-
|
|
8986
|
-
|
|
8987
|
-
|
|
8988
|
-
|
|
8989
|
-
|
|
8990
|
-
|
|
8991
|
-
|
|
8992
|
-
|
|
8993
|
-
|
|
8994
|
-
|
|
8995
|
-
if (
|
|
8996
|
-
|
|
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);
|
|
8380
|
+
}
|
|
8381
|
+
}
|
|
8382
|
+
if (element.children) {
|
|
8383
|
+
for (const child of element.children) {
|
|
8384
|
+
traverseNode(child);
|
|
8385
|
+
}
|
|
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);
|
|
8395
|
+
}
|
|
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,
|
|
8476
|
+
createTestIdTransform(
|
|
8477
|
+
componentName,
|
|
8478
|
+
componentHierarchyMap,
|
|
8479
|
+
nativeWrappers,
|
|
8480
|
+
excludedComponents,
|
|
8481
|
+
viewsDirAbs,
|
|
8482
|
+
{
|
|
8483
|
+
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
8484
|
+
testIdAttribute,
|
|
8485
|
+
nameCollisionBehavior,
|
|
8486
|
+
missingSemanticNameBehavior,
|
|
8487
|
+
warn: (message) => loggerRef.current.warn(message),
|
|
8488
|
+
vueFilesPathMap,
|
|
8489
|
+
wrapperSearchRoots: getWrapperSearchRoots(),
|
|
8490
|
+
annotatorMetadata,
|
|
8491
|
+
crossFileKeyRegistry,
|
|
8492
|
+
optionKeyAttribute
|
|
8493
|
+
}
|
|
8494
|
+
)
|
|
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
|
+
};
|
|
8529
|
+
}
|
|
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
|
|
8551
|
+
}
|
|
8552
|
+
);
|
|
8553
|
+
perFileTransform.set(componentName, transform);
|
|
8554
|
+
}
|
|
8555
|
+
return transform(node, context);
|
|
8556
|
+
}
|
|
8557
|
+
];
|
|
8558
|
+
};
|
|
8559
|
+
const runtimeNodeTransform = (node, context) => {
|
|
8560
|
+
const filename = context.filename;
|
|
8561
|
+
if (!filename || !filename.endsWith(".vue") || !isFileInScope(filename)) {
|
|
8562
|
+
return;
|
|
8997
8563
|
}
|
|
8564
|
+
const transforms = getNodeTransforms(filename);
|
|
8565
|
+
const ourTransform = transforms[transforms.length - 1];
|
|
8566
|
+
return ourTransform(node, context);
|
|
8998
8567
|
};
|
|
8999
|
-
|
|
9000
|
-
|
|
9001
|
-
|
|
9002
|
-
|
|
9003
|
-
|
|
9004
|
-
|
|
9005
|
-
|
|
9006
|
-
|
|
9007
|
-
|
|
9008
|
-
|
|
9009
|
-
|
|
9010
|
-
|
|
9011
|
-
|
|
9012
|
-
|
|
9013
|
-
return `/@fs/${normalizePathSeparators(filePath)}`;
|
|
9014
|
-
}
|
|
9015
|
-
function resolveAnnotatorClientPath() {
|
|
9016
|
-
const candidates = [
|
|
9017
|
-
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)),
|
|
9018
|
-
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))
|
|
9019
|
-
];
|
|
9020
|
-
const resolved = candidates.find((candidate) => fs.existsSync(candidate));
|
|
9021
|
-
if (!resolved) {
|
|
9022
|
-
throw new Error("[vue-pom-generator] Unable to locate annotator client source.");
|
|
9023
|
-
}
|
|
9024
|
-
return path.resolve(resolved);
|
|
9025
|
-
}
|
|
9026
|
-
function createAnnotatorUiPlugin(options) {
|
|
9027
|
-
const clientPath = resolveAnnotatorClientPath();
|
|
9028
|
-
const clientImportPath = toFsImportPath(clientPath);
|
|
9029
|
-
const clientOptions = JSON.stringify({
|
|
9030
|
-
sourceAttribute: options.sourceAttribute,
|
|
9031
|
-
metadataAttributePrefix: options.metadataAttributePrefix,
|
|
9032
|
-
outputDetail: options.outputDetail,
|
|
9033
|
-
copyToClipboard: options.copyToClipboard,
|
|
9034
|
-
showComponentTree: options.showComponentTree
|
|
9035
|
-
});
|
|
9036
|
-
return {
|
|
9037
|
-
name: "vue-pom-generator:annotator-ui",
|
|
9038
|
-
apply: "serve",
|
|
9039
|
-
resolveId(id) {
|
|
9040
|
-
if (id === ANNOTATOR_CLIENT_VIRTUAL_ID) {
|
|
9041
|
-
return ANNOTATOR_CLIENT_RESOLVED_ID;
|
|
9042
|
-
}
|
|
9043
|
-
},
|
|
9044
|
-
load(id) {
|
|
9045
|
-
if (id !== ANNOTATOR_CLIENT_RESOLVED_ID) {
|
|
8568
|
+
const templateCompilerOptions = {
|
|
8569
|
+
...userCompilerOptions,
|
|
8570
|
+
prefixIdentifiers: true,
|
|
8571
|
+
nodeTransforms: [
|
|
8572
|
+
...userNodeTransforms,
|
|
8573
|
+
runtimeNodeTransform
|
|
8574
|
+
]
|
|
8575
|
+
};
|
|
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)) {
|
|
9046
8582
|
return null;
|
|
9047
8583
|
}
|
|
9048
|
-
|
|
9049
|
-
`import { mountAnnotatorClient } from ${JSON.stringify(clientImportPath)};`,
|
|
9050
|
-
`mountAnnotatorClient(${clientOptions});`,
|
|
9051
|
-
""
|
|
9052
|
-
].join("\n");
|
|
9053
|
-
},
|
|
9054
|
-
transform(code, id) {
|
|
9055
|
-
if (!options.enabled) {
|
|
8584
|
+
if (id !== cleanPath) {
|
|
9056
8585
|
return null;
|
|
9057
8586
|
}
|
|
9058
|
-
const
|
|
9059
|
-
|
|
9060
|
-
|
|
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}`);
|
|
9061
8608
|
}
|
|
9062
|
-
|
|
9063
|
-
|
|
8609
|
+
return null;
|
|
8610
|
+
}
|
|
8611
|
+
};
|
|
8612
|
+
const template = {
|
|
8613
|
+
...userTemplate,
|
|
8614
|
+
compilerOptions: templateCompilerOptions
|
|
8615
|
+
};
|
|
8616
|
+
const internalVuePlugin = vue({
|
|
8617
|
+
...vueOptions,
|
|
8618
|
+
template
|
|
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.");
|
|
9064
8630
|
}
|
|
9065
|
-
|
|
9066
|
-
|
|
9067
|
-
|
|
9068
|
-
|
|
9069
|
-
|
|
9070
|
-
|
|
9071
|
-
transformIndexHtml() {
|
|
9072
|
-
if (!options.enabled) {
|
|
9073
|
-
return void 0;
|
|
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;
|
|
9074
8637
|
}
|
|
9075
|
-
|
|
9076
|
-
|
|
9077
|
-
|
|
9078
|
-
|
|
9079
|
-
|
|
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
|
+
}
|
|
9080
8651
|
};
|
|
9081
|
-
return [tag];
|
|
9082
8652
|
}
|
|
9083
8653
|
};
|
|
8654
|
+
return { metadataCollectorPlugin, internalVuePlugin, nuxtVueBridgePlugin, templateCompilerOptions };
|
|
9084
8655
|
}
|
|
9085
|
-
function
|
|
9086
|
-
|
|
9087
|
-
|
|
9088
|
-
|
|
9089
|
-
|
|
9090
|
-
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
-
excludedComponents,
|
|
9094
|
-
getPageDirs,
|
|
9095
|
-
getComponentDirs,
|
|
9096
|
-
getLayoutDirs,
|
|
9097
|
-
getViewsDir,
|
|
9098
|
-
getSourceDirs,
|
|
9099
|
-
getWrapperSearchRoots,
|
|
9100
|
-
generation,
|
|
9101
|
-
projectRootRef,
|
|
9102
|
-
basePageClassPath: basePageClassPathOverride,
|
|
9103
|
-
loggerRef,
|
|
9104
|
-
annotatorRuntime
|
|
9105
|
-
} = options;
|
|
9106
|
-
const {
|
|
9107
|
-
routerAwarePoms,
|
|
9108
|
-
routerEntry,
|
|
9109
|
-
routerType
|
|
9110
|
-
} = generation;
|
|
9111
|
-
const resolveRouterEntry2 = () => {
|
|
9112
|
-
if (!routerAwarePoms)
|
|
9113
|
-
return void 0;
|
|
9114
|
-
if (routerType === "nuxt")
|
|
9115
|
-
return void 0;
|
|
9116
|
-
if (!routerEntry)
|
|
9117
|
-
throw new Error("[vue-pom-generator] router.entry is required when router introspection is enabled.");
|
|
9118
|
-
return path.isAbsolute(routerEntry) ? routerEntry : path.resolve(projectRootRef.current, routerEntry);
|
|
9119
|
-
};
|
|
9120
|
-
const getDefaultBasePageClassPath = () => {
|
|
9121
|
-
try {
|
|
9122
|
-
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));
|
|
9123
|
-
} catch {
|
|
9124
|
-
return path.resolve(__dirname, "..", "class-generation", "base-page.ts");
|
|
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;
|
|
9125
8664
|
}
|
|
8665
|
+
}
|
|
8666
|
+
return {
|
|
8667
|
+
entryCount: componentHierarchyMap.size,
|
|
8668
|
+
interactiveComponentCount,
|
|
8669
|
+
dataTestIdCount
|
|
9126
8670
|
};
|
|
9127
|
-
|
|
9128
|
-
|
|
9129
|
-
|
|
8671
|
+
}
|
|
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;
|
|
8680
|
+
}
|
|
8681
|
+
function createBuildProcessorPlugin(options) {
|
|
8682
|
+
const {
|
|
9130
8683
|
componentHierarchyMap,
|
|
9131
8684
|
crossFileKeyRegistry,
|
|
9132
8685
|
vueFilesPathMap,
|
|
@@ -9143,10 +8696,255 @@ function createInternalPlugins(options) {
|
|
|
9143
8696
|
optionKeyAttribute,
|
|
9144
8697
|
excludedComponents,
|
|
9145
8698
|
getWrapperSearchRoots,
|
|
9146
|
-
getResolvedRouterEntry
|
|
8699
|
+
getResolvedRouterEntry,
|
|
9147
8700
|
loggerRef
|
|
9148
|
-
}
|
|
9149
|
-
const
|
|
8701
|
+
} = options;
|
|
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,
|
|
8717
|
+
routerAwarePoms,
|
|
8718
|
+
routerType,
|
|
8719
|
+
routerModuleShims
|
|
8720
|
+
} = generation;
|
|
8721
|
+
let lastGeneratedMetrics = {
|
|
8722
|
+
entryCount: 0,
|
|
8723
|
+
interactiveComponentCount: 0,
|
|
8724
|
+
dataTestIdCount: 0
|
|
8725
|
+
};
|
|
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) => {
|
|
8729
|
+
try {
|
|
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 };
|
|
8735
|
+
} catch {
|
|
8736
|
+
return { bindings: void 0, isScriptSetup: false };
|
|
8737
|
+
}
|
|
8738
|
+
};
|
|
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
|
+
}
|
|
8763
|
+
}
|
|
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))
|
|
8770
|
+
continue;
|
|
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++;
|
|
8838
|
+
}
|
|
8839
|
+
}
|
|
8840
|
+
if (supplemented > 0) {
|
|
8841
|
+
loggerRef.current.info(`supplemented ${supplemented} components from filesystem walk (not in build graph)`);
|
|
8842
|
+
}
|
|
8843
|
+
};
|
|
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
|
+
}
|
|
8869
|
+
});
|
|
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;
|
|
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.`);
|
|
8889
|
+
}
|
|
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 {
|
|
9150
8948
|
nativeWrappers,
|
|
9151
8949
|
optionKeyAttribute,
|
|
9152
8950
|
excludedComponents,
|
|
@@ -9160,438 +8958,644 @@ function createInternalPlugins(options) {
|
|
|
9160
8958
|
normalizedBasePagePath,
|
|
9161
8959
|
basePageClassPath,
|
|
9162
8960
|
generation,
|
|
9163
|
-
getResolvedRouterEntry
|
|
8961
|
+
getResolvedRouterEntry,
|
|
9164
8962
|
loggerRef
|
|
9165
|
-
}
|
|
9166
|
-
const
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9171
|
-
|
|
9172
|
-
|
|
9173
|
-
|
|
9174
|
-
|
|
9175
|
-
|
|
9176
|
-
|
|
9177
|
-
|
|
9178
|
-
|
|
9179
|
-
|
|
9180
|
-
|
|
9181
|
-
|
|
9182
|
-
|
|
9183
|
-
|
|
9184
|
-
|
|
9185
|
-
|
|
9186
|
-
|
|
9187
|
-
|
|
9188
|
-
|
|
9189
|
-
|
|
9190
|
-
|
|
9191
|
-
|
|
9192
|
-
|
|
9193
|
-
|
|
9194
|
-
return
|
|
9195
|
-
}
|
|
9196
|
-
|
|
9197
|
-
|
|
9198
|
-
|
|
9199
|
-
|
|
9200
|
-
|
|
9201
|
-
|
|
9202
|
-
|
|
9203
|
-
|
|
9204
|
-
|
|
9205
|
-
|
|
9206
|
-
|
|
9207
|
-
|
|
9208
|
-
|
|
9209
|
-
|
|
9210
|
-
|
|
9211
|
-
|
|
9212
|
-
|
|
9213
|
-
|
|
9214
|
-
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9218
|
-
|
|
9219
|
-
|
|
9220
|
-
|
|
9221
|
-
|
|
9222
|
-
|
|
9223
|
-
|
|
9224
|
-
|
|
9225
|
-
|
|
9226
|
-
|
|
9227
|
-
|
|
9228
|
-
|
|
9229
|
-
|
|
9230
|
-
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9238
|
-
|
|
9239
|
-
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
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 };
|
|
9243
9145
|
}
|
|
9244
|
-
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
|
|
9259
|
-
|
|
9260
|
-
|
|
9261
|
-
|
|
9262
|
-
|
|
9263
|
-
|
|
9264
|
-
|
|
9265
|
-
|
|
9266
|
-
|
|
9267
|
-
|
|
9268
|
-
|
|
9269
|
-
|
|
9270
|
-
|
|
9271
|
-
|
|
9272
|
-
|
|
9273
|
-
|
|
9274
|
-
|
|
9275
|
-
|
|
9276
|
-
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
|
|
9281
|
-
|
|
9282
|
-
|
|
9283
|
-
|
|
9284
|
-
|
|
9285
|
-
|
|
9286
|
-
hasClickHandler: patchFlag ? Boolean(patchFlag & 32) : void 0,
|
|
9287
|
-
hasDynamicClass: patchFlag ? Boolean(patchFlag & 2) : void 0,
|
|
9288
|
-
hasDynamicStyle: patchFlag ? Boolean(patchFlag & 4) : void 0,
|
|
9289
|
-
hasDynamicText: patchFlag ? Boolean(patchFlag & 1) : void 0,
|
|
9290
|
-
staticAriaLabel: findStaticAttributeValue(element, "aria-label"),
|
|
9291
|
-
staticRole: findStaticAttributeValue(element, "role"),
|
|
9292
|
-
staticTitle: findStaticAttributeValue(element, "title"),
|
|
9293
|
-
staticTextContent: collectStaticTextContent(element.children),
|
|
9294
|
-
sourceLine: element.loc?.start.line,
|
|
9295
|
-
sourceColumn: element.loc?.start.column
|
|
9296
|
-
};
|
|
9297
|
-
return metadata;
|
|
9298
|
-
}
|
|
9299
|
-
function resolveCompilerSfcParse(compilerSfc2) {
|
|
9300
|
-
const parse = compilerSfc2.parse ?? compilerSfc2.default?.parse;
|
|
9301
|
-
if (typeof parse !== "function") {
|
|
9302
|
-
throw new TypeError("[vue-pom-generator] Failed to resolve @vue/compiler-sfc.parse.");
|
|
9303
|
-
}
|
|
9304
|
-
return parse;
|
|
9305
|
-
}
|
|
9306
|
-
function extractMetadataAfterTransform(ast, componentName, elementMetadata, semanticNameMap, testIdAttribute) {
|
|
9307
|
-
const componentMetadata = /* @__PURE__ */ new Map();
|
|
9308
|
-
function traverseNode(node) {
|
|
9309
|
-
if (node.type === compilerCore.NodeTypes.ELEMENT) {
|
|
9310
|
-
const element = node;
|
|
9311
|
-
const testIdAttr = findDataTestIdProp(element, testIdAttribute);
|
|
9312
|
-
if (testIdAttr) {
|
|
9313
|
-
const metadata = tryCreateElementMetadata({
|
|
9314
|
-
element,
|
|
9315
|
-
semanticNameMap,
|
|
9316
|
-
testIdAttribute
|
|
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
|
+
]
|
|
9317
9188
|
});
|
|
9318
|
-
|
|
9319
|
-
|
|
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
|
+
}
|
|
9320
9213
|
}
|
|
9321
|
-
|
|
9322
|
-
|
|
9323
|
-
|
|
9324
|
-
|
|
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);
|
|
9325
9332
|
}
|
|
9326
|
-
|
|
9327
|
-
|
|
9328
|
-
|
|
9329
|
-
|
|
9330
|
-
}
|
|
9331
|
-
} else if (node.type === compilerCore.NodeTypes.IF_BRANCH || node.type === compilerCore.NodeTypes.FOR) {
|
|
9332
|
-
if (node.children) {
|
|
9333
|
-
for (const child of node.children) {
|
|
9334
|
-
traverseNode(child);
|
|
9333
|
+
if (wasEmpty) {
|
|
9334
|
+
const queuedFiles = pendingChangedVueFiles.size;
|
|
9335
|
+
const queuedDeletes = pendingDeletedComponents.size;
|
|
9336
|
+
logDebug(`queued: files=${queuedFiles} deleted=${queuedDeletes}`);
|
|
9335
9337
|
}
|
|
9336
|
-
|
|
9337
|
-
|
|
9338
|
-
|
|
9339
|
-
|
|
9340
|
-
|
|
9341
|
-
|
|
9342
|
-
|
|
9343
|
-
|
|
9344
|
-
|
|
9345
|
-
|
|
9346
|
-
|
|
9347
|
-
|
|
9348
|
-
}
|
|
9349
|
-
|
|
9350
|
-
const {
|
|
9351
|
-
vueOptions,
|
|
9352
|
-
existingIdBehavior,
|
|
9353
|
-
nameCollisionBehavior,
|
|
9354
|
-
missingSemanticNameBehavior = "error",
|
|
9355
|
-
nativeWrappers,
|
|
9356
|
-
optionKeyAttribute,
|
|
9357
|
-
elementMetadata,
|
|
9358
|
-
semanticNameMap,
|
|
9359
|
-
componentHierarchyMap,
|
|
9360
|
-
crossFileKeyRegistry,
|
|
9361
|
-
vueFilesPathMap,
|
|
9362
|
-
excludedComponents,
|
|
9363
|
-
getViewsDirAbs,
|
|
9364
|
-
testIdAttribute,
|
|
9365
|
-
accessibilityAudit,
|
|
9366
|
-
loggerRef,
|
|
9367
|
-
getSourceDirs,
|
|
9368
|
-
getWrapperSearchRoots,
|
|
9369
|
-
getProjectRoot,
|
|
9370
|
-
annotatorMetadata
|
|
9371
|
-
} = options;
|
|
9372
|
-
const lastAccessibilityWarningSignatureByComponent = /* @__PURE__ */ new Map();
|
|
9373
|
-
const getComponentNameFromPath = (filename) => {
|
|
9374
|
-
return resolveComponentNameFromPath({
|
|
9375
|
-
filename,
|
|
9376
|
-
projectRoot: getProjectRoot(),
|
|
9377
|
-
viewsDirAbs: getViewsDirAbs(),
|
|
9378
|
-
sourceDirs: getSourceDirs(),
|
|
9379
|
-
extraRoots: [process.cwd()]
|
|
9380
|
-
});
|
|
9381
|
-
};
|
|
9382
|
-
const isFileInScope = (filename) => {
|
|
9383
|
-
if (!filename)
|
|
9384
|
-
return false;
|
|
9385
|
-
const cleanPath = filename.includes("?") ? filename.substring(0, filename.indexOf("?")) : filename;
|
|
9386
|
-
const projectRoot = getProjectRoot();
|
|
9387
|
-
const matched = isFileInConfiguredSourceScope({
|
|
9388
|
-
filename,
|
|
9389
|
-
projectRoot,
|
|
9390
|
-
viewsDirAbs: getViewsDirAbs(),
|
|
9391
|
-
sourceDirs: getSourceDirs(),
|
|
9392
|
-
extraRoots: [process.cwd()]
|
|
9393
|
-
});
|
|
9394
|
-
if (cleanPath.endsWith(".vue") && !matched) {
|
|
9395
|
-
const absFilename = path.normalize(path.isAbsolute(cleanPath) ? cleanPath : path.resolve(projectRoot, cleanPath));
|
|
9396
|
-
loggerRef.current.debug(`[isFileInScope] REJECTED: ${absFilename} (Clean: ${cleanPath})`);
|
|
9397
|
-
}
|
|
9398
|
-
return matched;
|
|
9399
|
-
};
|
|
9400
|
-
const userTemplate = vueOptions?.template ?? {};
|
|
9401
|
-
const userCompilerOptions = userTemplate.compilerOptions ?? {};
|
|
9402
|
-
const userNodeTransforms = userCompilerOptions.nodeTransforms ?? [];
|
|
9403
|
-
const perFileTransform = /* @__PURE__ */ new Map();
|
|
9404
|
-
const getNodeTransforms = (filename, componentNameOverride) => {
|
|
9405
|
-
const cleanPath = filename.includes("?") ? filename.substring(0, filename.indexOf("?")) : filename;
|
|
9406
|
-
const viewsDirAbs = getViewsDirAbs();
|
|
9407
|
-
const componentName = componentNameOverride || getComponentNameFromPath(cleanPath);
|
|
9408
|
-
return [
|
|
9409
|
-
...userNodeTransforms,
|
|
9410
|
-
(node, context) => {
|
|
9411
|
-
if (node.type === compilerCore.NodeTypes.ROOT) {
|
|
9412
|
-
componentHierarchyMap.delete(componentName);
|
|
9413
|
-
vueFilesPathMap.set(componentName, filename);
|
|
9414
|
-
perFileTransform.set(
|
|
9415
|
-
componentName,
|
|
9416
|
-
createTestIdTransform(
|
|
9417
|
-
componentName,
|
|
9418
|
-
componentHierarchyMap,
|
|
9419
|
-
nativeWrappers,
|
|
9420
|
-
excludedComponents,
|
|
9421
|
-
viewsDirAbs,
|
|
9422
|
-
{
|
|
9423
|
-
existingIdBehavior,
|
|
9424
|
-
testIdAttribute,
|
|
9425
|
-
nameCollisionBehavior,
|
|
9426
|
-
missingSemanticNameBehavior,
|
|
9427
|
-
warn: (message) => loggerRef.current.warn(message),
|
|
9428
|
-
vueFilesPathMap,
|
|
9429
|
-
wrapperSearchRoots: getWrapperSearchRoots(),
|
|
9430
|
-
annotatorMetadata,
|
|
9431
|
-
crossFileKeyRegistry,
|
|
9432
|
-
optionKeyAttribute
|
|
9433
|
-
}
|
|
9434
|
-
)
|
|
9435
|
-
);
|
|
9436
|
-
return () => {
|
|
9437
|
-
const componentMetadata = extractMetadataAfterTransform(
|
|
9438
|
-
node,
|
|
9439
|
-
componentName,
|
|
9440
|
-
elementMetadata,
|
|
9441
|
-
semanticNameMap,
|
|
9442
|
-
testIdAttribute
|
|
9443
|
-
);
|
|
9444
|
-
if (!accessibilityAudit) {
|
|
9445
|
-
return;
|
|
9446
|
-
}
|
|
9447
|
-
const dependencies = componentHierarchyMap.get(componentName);
|
|
9448
|
-
if (!dependencies || componentMetadata.size === 0) {
|
|
9449
|
-
return;
|
|
9450
|
-
}
|
|
9451
|
-
const manifest = buildPomManifest(
|
|
9452
|
-
/* @__PURE__ */ new Map([[componentName, dependencies]]),
|
|
9453
|
-
/* @__PURE__ */ new Map([[componentName, componentMetadata]])
|
|
9454
|
-
);
|
|
9455
|
-
const warnings = collectAccessibilityReviewWarnings(manifest);
|
|
9456
|
-
const signature = warnings.join("\n");
|
|
9457
|
-
if (!signature) {
|
|
9458
|
-
lastAccessibilityWarningSignatureByComponent.delete(componentName);
|
|
9459
|
-
return;
|
|
9460
|
-
}
|
|
9461
|
-
if (lastAccessibilityWarningSignatureByComponent.get(componentName) === signature) {
|
|
9462
|
-
return;
|
|
9463
|
-
}
|
|
9464
|
-
lastAccessibilityWarningSignatureByComponent.set(componentName, signature);
|
|
9465
|
-
for (const warning of warnings) {
|
|
9466
|
-
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
|
+
);
|
|
9467
9352
|
}
|
|
9468
|
-
}
|
|
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;
|
|
9469
9364
|
}
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
componentHierarchyMap.delete(componentName);
|
|
9473
|
-
vueFilesPathMap.set(componentName, filename);
|
|
9474
|
-
transform = createTestIdTransform(
|
|
9475
|
-
componentName,
|
|
9476
|
-
componentHierarchyMap,
|
|
9477
|
-
nativeWrappers,
|
|
9478
|
-
excludedComponents,
|
|
9479
|
-
viewsDirAbs,
|
|
9480
|
-
{
|
|
9481
|
-
existingIdBehavior,
|
|
9482
|
-
testIdAttribute,
|
|
9483
|
-
nameCollisionBehavior,
|
|
9484
|
-
missingSemanticNameBehavior,
|
|
9485
|
-
warn: (message) => loggerRef.current.warn(message),
|
|
9486
|
-
vueFilesPathMap,
|
|
9487
|
-
wrapperSearchRoots: getWrapperSearchRoots(),
|
|
9488
|
-
annotatorMetadata,
|
|
9489
|
-
crossFileKeyRegistry,
|
|
9490
|
-
optionKeyAttribute
|
|
9491
|
-
}
|
|
9492
|
-
);
|
|
9493
|
-
perFileTransform.set(componentName, transform);
|
|
9365
|
+
if (changedAbsPosix.includes("/vite-plugins/vue-pom-generator/")) {
|
|
9366
|
+
void server.restart();
|
|
9494
9367
|
}
|
|
9495
|
-
|
|
9496
|
-
|
|
9497
|
-
|
|
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
|
+
}
|
|
9498
9402
|
};
|
|
9499
|
-
|
|
9500
|
-
|
|
9501
|
-
|
|
9502
|
-
|
|
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);
|
|
9503
9422
|
}
|
|
9504
|
-
const transforms = getNodeTransforms(filename);
|
|
9505
|
-
const ourTransform = transforms[transforms.length - 1];
|
|
9506
|
-
return ourTransform(node, context);
|
|
9507
|
-
};
|
|
9508
|
-
const templateCompilerOptions = {
|
|
9509
|
-
...userCompilerOptions,
|
|
9510
|
-
prefixIdentifiers: true,
|
|
9511
|
-
nodeTransforms: [
|
|
9512
|
-
...userNodeTransforms,
|
|
9513
|
-
runtimeNodeTransform
|
|
9514
|
-
]
|
|
9515
9423
|
};
|
|
9516
|
-
|
|
9517
|
-
|
|
9518
|
-
|
|
9519
|
-
|
|
9520
|
-
|
|
9521
|
-
|
|
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) {
|
|
9522
9471
|
return null;
|
|
9523
9472
|
}
|
|
9524
|
-
|
|
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) {
|
|
9525
9481
|
return null;
|
|
9526
9482
|
}
|
|
9527
|
-
const
|
|
9528
|
-
|
|
9529
|
-
|
|
9530
|
-
const parse = resolveCompilerSfcParse(compilerSfc2);
|
|
9531
|
-
const compilerDom2 = await import("@vue/compiler-dom");
|
|
9532
|
-
const compile = compilerDom2.compile;
|
|
9533
|
-
const { descriptor } = parse(code, { filename: cleanPath });
|
|
9534
|
-
if (descriptor.template) {
|
|
9535
|
-
const mergedExpressionPlugins = Array.from(
|
|
9536
|
-
/* @__PURE__ */ new Set([
|
|
9537
|
-
"typescript",
|
|
9538
|
-
...userCompilerOptions.expressionPlugins ?? []
|
|
9539
|
-
])
|
|
9540
|
-
);
|
|
9541
|
-
compile(descriptor.template.content, {
|
|
9542
|
-
...userCompilerOptions,
|
|
9543
|
-
filename: cleanPath,
|
|
9544
|
-
expressionPlugins: mergedExpressionPlugins,
|
|
9545
|
-
nodeTransforms: getNodeTransforms(cleanPath, componentName)
|
|
9546
|
-
});
|
|
9547
|
-
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;
|
|
9548
9486
|
}
|
|
9549
|
-
|
|
9550
|
-
|
|
9551
|
-
};
|
|
9552
|
-
const template = {
|
|
9553
|
-
...userTemplate,
|
|
9554
|
-
compilerOptions: templateCompilerOptions
|
|
9555
|
-
};
|
|
9556
|
-
const internalVuePlugin = vue({
|
|
9557
|
-
...vueOptions,
|
|
9558
|
-
template
|
|
9559
|
-
});
|
|
9560
|
-
const nuxtVueBridgePlugin = {
|
|
9561
|
-
name: "vue-pom-generator-nuxt-vue-bridge",
|
|
9562
|
-
apply: "serve",
|
|
9563
|
-
configResolved(config) {
|
|
9564
|
-
const viteVuePlugin = config.plugins.find((plugin) => {
|
|
9565
|
-
return typeof plugin === "object" && plugin !== null && "name" in plugin && plugin.name === "vite:vue" && "api" in plugin;
|
|
9566
|
-
});
|
|
9567
|
-
const api = viteVuePlugin?.api;
|
|
9568
|
-
if (!api) {
|
|
9569
|
-
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;
|
|
9570
9489
|
}
|
|
9571
|
-
|
|
9572
|
-
|
|
9573
|
-
|
|
9574
|
-
|
|
9575
|
-
|
|
9576
|
-
|
|
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;
|
|
9577
9499
|
}
|
|
9578
|
-
|
|
9579
|
-
|
|
9580
|
-
|
|
9581
|
-
|
|
9582
|
-
|
|
9583
|
-
...currentCompilerOptions,
|
|
9584
|
-
prefixIdentifiers: true,
|
|
9585
|
-
nodeTransforms: [
|
|
9586
|
-
...currentNodeTransforms,
|
|
9587
|
-
runtimeNodeTransform
|
|
9588
|
-
]
|
|
9589
|
-
}
|
|
9590
|
-
}
|
|
9500
|
+
const tag = {
|
|
9501
|
+
tag: "script",
|
|
9502
|
+
attrs: { type: "module" },
|
|
9503
|
+
children: `import ${JSON.stringify(ANNOTATOR_CLIENT_VIRTUAL_ID)};`,
|
|
9504
|
+
injectTo: "body"
|
|
9591
9505
|
};
|
|
9506
|
+
return [tag];
|
|
9592
9507
|
}
|
|
9593
9508
|
};
|
|
9594
|
-
|
|
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];
|
|
9595
9599
|
}
|
|
9596
9600
|
const nuxtConfigMarker$1 = /* @__PURE__ */ Symbol.for("@immense/vue-pom-generator.nuxt");
|
|
9597
9601
|
const nuxtConfigFileNames = [
|