@immense/vue-pom-generator 1.0.106 → 1.0.107
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 +54 -0
- package/RELEASE_NOTES.md +68 -22
- package/class-generation/index.ts +12 -40
- package/dist/class-generation/index.d.ts.map +1 -1
- package/dist/index.cjs +630 -557
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +631 -558
- package/dist/index.mjs.map +1 -1
- package/dist/plugin/create-vue-pom-generator-plugins.d.ts +2 -0
- package/dist/plugin/create-vue-pom-generator-plugins.d.ts.map +1 -1
- package/dist/plugin/generate-vue-poms.d.ts +10 -0
- package/dist/plugin/generate-vue-poms.d.ts.map +1 -0
- package/dist/plugin/generated-outputs.d.ts +7 -0
- package/dist/plugin/generated-outputs.d.ts.map +1 -0
- package/dist/plugin/internal/build-plugin.d.ts +3 -10
- package/dist/plugin/internal/build-plugin.d.ts.map +1 -1
- package/dist/plugin/internal-plugins.d.ts +2 -1
- package/dist/plugin/internal-plugins.d.ts.map +1 -1
- package/dist/plugin/vue-plugin.d.ts +1 -0
- package/dist/plugin/vue-plugin.d.ts.map +1 -1
- package/dist/tests/generate-vue-poms.test.d.ts +2 -0
- package/dist/tests/generate-vue-poms.test.d.ts.map +1 -0
- package/dist/tests/generated-outputs.test.d.ts +2 -0
- package/dist/tests/generated-outputs.test.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3,16 +3,17 @@ import path from "node:path";
|
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { pathToFileURL, fileURLToPath } from "node:url";
|
|
6
|
+
import { parseExpression, parse } from "@babel/parser";
|
|
7
|
+
import { NodeTypes, stringifyExpression, createSimpleExpression, processExpression, ConstantTypes, ElementTypes } from "@vue/compiler-core";
|
|
6
8
|
import * as compilerDom from "@vue/compiler-dom";
|
|
7
9
|
import { parse as parse$2, NodeTypes as NodeTypes$1 } from "@vue/compiler-dom";
|
|
8
10
|
import { parse as parse$1, compileScript } from "@vue/compiler-sfc";
|
|
9
|
-
import {
|
|
10
|
-
import { NodeTypes, stringifyExpression, createSimpleExpression, processExpression, ConstantTypes, ElementTypes } from "@vue/compiler-core";
|
|
11
|
-
import { Project, QuoteKind, NewLineKind, IndentationText, CodeBlockWriter, StructureKind, VariableDeclarationKind } from "ts-morph";
|
|
11
|
+
import { Project, QuoteKind, NewLineKind, IndentationText, StructureKind, CodeBlockWriter, VariableDeclarationKind } from "ts-morph";
|
|
12
12
|
import { isIdentifier, isObjectPattern, isRestElement, isObjectProperty, isArrayExpression, isStringLiteral, isTemplateLiteral, isArrowFunctionExpression, isExpressionStatement, isAssignmentPattern, isMemberExpression, isOptionalMemberExpression, isCallExpression, isOptionalCallExpression, isAssignmentExpression, isSequenceExpression, isObjectExpression, isFile, isBlockStatement, isLogicalExpression, isConditionalExpression, isProgram, isArrayPattern, VISITOR_KEYS, isBooleanLiteral, isNumericLiteral, isNullLiteral, isImportDeclaration, isImportSpecifier, isExportDefaultDeclaration, isExpression, isVariableDeclaration, isFunctionDeclaration, isFunctionExpression, isReturnStatement, isTSAsExpression, isTSTypeAssertion, isTSNonNullExpression, isForInStatement, isIfStatement } from "@babel/types";
|
|
13
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
13
14
|
import { POM_ROUTER_GLOBAL_NAME } from "./router.mjs";
|
|
14
|
-
import vue from "@vitejs/plugin-vue";
|
|
15
15
|
import { performance } from "node:perf_hooks";
|
|
16
|
+
import vue from "@vitejs/plugin-vue";
|
|
16
17
|
import { autoUpdate, computePosition, offset, autoPlacement, shift, arrow } from "@floating-ui/dom";
|
|
17
18
|
const VUE_POM_GENERATOR_LOG_PREFIX = "[vue-pom-generator]";
|
|
18
19
|
function normalize(message) {
|
|
@@ -3990,6 +3991,104 @@ function generatePomManifestModule(componentHierarchyMap, elementMetadata, fileN
|
|
|
3990
3991
|
});
|
|
3991
3992
|
});
|
|
3992
3993
|
}
|
|
3994
|
+
const manifestName = ".vue-pom-generator-outputs.json";
|
|
3995
|
+
function hash(content) {
|
|
3996
|
+
return createHash("sha256").update(content).digest("hex");
|
|
3997
|
+
}
|
|
3998
|
+
function readManifest(filePath) {
|
|
3999
|
+
if (!fs.existsSync(filePath)) {
|
|
4000
|
+
return { version: 1, files: {} };
|
|
4001
|
+
}
|
|
4002
|
+
const value = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
4003
|
+
if (!value || typeof value !== "object" || !("version" in value) || value.version !== 1 || !("files" in value) || !value.files || typeof value.files !== "object" || Array.isArray(value.files)) {
|
|
4004
|
+
throw new Error(`[vue-pom-generator] Invalid output ownership manifest: ${filePath}`);
|
|
4005
|
+
}
|
|
4006
|
+
for (const [name, digest] of Object.entries(value.files)) {
|
|
4007
|
+
if (!name || path.isAbsolute(name) || path.win32.isAbsolute(name) || name.includes("\\") || name.includes("\0") || path.posix.normalize(name) !== name || name === "." || name === ".." || name.endsWith("/..") || name.endsWith("/") || path.basename(name) === manifestName || typeof digest !== "string" || digest.length !== 64 || !Array.from(digest).every((character) => "0123456789abcdef".includes(character))) {
|
|
4008
|
+
throw new Error(`[vue-pom-generator] Invalid output ownership entry in ${filePath}: ${name}`);
|
|
4009
|
+
}
|
|
4010
|
+
}
|
|
4011
|
+
return value;
|
|
4012
|
+
}
|
|
4013
|
+
function assertRegularFile(filePath) {
|
|
4014
|
+
const entry = fs.lstatSync(filePath, { throwIfNoEntry: false });
|
|
4015
|
+
if (entry && !entry.isFile()) {
|
|
4016
|
+
throw new Error(`[vue-pom-generator] Refusing to replace or remove a non-regular output file: ${filePath}`);
|
|
4017
|
+
}
|
|
4018
|
+
}
|
|
4019
|
+
function assertNoSymlinkParents(filePath, outDir, projectRoot) {
|
|
4020
|
+
const relativeOutput = path.relative(projectRoot, outDir);
|
|
4021
|
+
let ancestor = relativeOutput === ".." || relativeOutput.startsWith(`..${path.sep}`) || path.isAbsolute(relativeOutput) ? path.dirname(outDir) : projectRoot;
|
|
4022
|
+
const targetDirectory = path.dirname(filePath);
|
|
4023
|
+
while (path.relative(ancestor, targetDirectory) === ".." || path.relative(ancestor, targetDirectory).startsWith(`..${path.sep}`) || path.isAbsolute(path.relative(ancestor, targetDirectory))) {
|
|
4024
|
+
const parent = path.dirname(ancestor);
|
|
4025
|
+
if (parent === ancestor) {
|
|
4026
|
+
throw new Error(`[vue-pom-generator] Output must be on the same filesystem volume as its manifest: ${filePath}`);
|
|
4027
|
+
}
|
|
4028
|
+
ancestor = parent;
|
|
4029
|
+
}
|
|
4030
|
+
for (const target of [path.dirname(filePath), outDir]) {
|
|
4031
|
+
let directory = target;
|
|
4032
|
+
while (directory !== ancestor) {
|
|
4033
|
+
if (fs.lstatSync(directory, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
4034
|
+
throw new Error(`[vue-pom-generator] Refusing to follow an output directory symlink: ${directory}`);
|
|
4035
|
+
}
|
|
4036
|
+
directory = path.dirname(directory);
|
|
4037
|
+
}
|
|
4038
|
+
}
|
|
4039
|
+
}
|
|
4040
|
+
function writeFile(filePath, content) {
|
|
4041
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
4042
|
+
const temporaryPath = `${filePath}.${randomUUID()}.tmp`;
|
|
4043
|
+
try {
|
|
4044
|
+
fs.writeFileSync(temporaryPath, content, { flag: "wx" });
|
|
4045
|
+
fs.renameSync(temporaryPath, filePath);
|
|
4046
|
+
} finally {
|
|
4047
|
+
if (fs.existsSync(temporaryPath)) {
|
|
4048
|
+
fs.unlinkSync(temporaryPath);
|
|
4049
|
+
}
|
|
4050
|
+
}
|
|
4051
|
+
}
|
|
4052
|
+
function writeGeneratedOutputs(outDir, files, sharedFiles, projectRoot = path.dirname(path.resolve(outDir))) {
|
|
4053
|
+
const root = path.resolve(outDir);
|
|
4054
|
+
const manifestPath = path.join(root, manifestName);
|
|
4055
|
+
assertNoSymlinkParents(manifestPath, root, projectRoot);
|
|
4056
|
+
assertRegularFile(manifestPath);
|
|
4057
|
+
const previous = readManifest(manifestPath);
|
|
4058
|
+
const next = { version: 1, files: {} };
|
|
4059
|
+
const contents = /* @__PURE__ */ new Map();
|
|
4060
|
+
for (const file of files) {
|
|
4061
|
+
const absolutePath = path.resolve(file.filePath);
|
|
4062
|
+
if (contents.has(absolutePath) || absolutePath === manifestPath) {
|
|
4063
|
+
throw new Error(`[vue-pom-generator] Duplicate generated output: ${absolutePath}`);
|
|
4064
|
+
}
|
|
4065
|
+
contents.set(absolutePath, file.content);
|
|
4066
|
+
next.files[path.relative(root, absolutePath).split(path.sep).join("/")] = hash(file.content);
|
|
4067
|
+
}
|
|
4068
|
+
const obsolete = [];
|
|
4069
|
+
for (const [name, digest] of Object.entries(previous.files)) {
|
|
4070
|
+
const absolutePath = path.resolve(root, name);
|
|
4071
|
+
if (contents.has(absolutePath)) continue;
|
|
4072
|
+
assertNoSymlinkParents(absolutePath, root, projectRoot);
|
|
4073
|
+
assertRegularFile(absolutePath);
|
|
4074
|
+
if (!fs.existsSync(absolutePath)) continue;
|
|
4075
|
+
if (hash(fs.readFileSync(absolutePath, "utf8")) !== digest) {
|
|
4076
|
+
throw new Error(`[vue-pom-generator] Obsolete generated file was modified; move or remove it explicitly before regenerating: ${absolutePath}`);
|
|
4077
|
+
}
|
|
4078
|
+
obsolete.push(absolutePath);
|
|
4079
|
+
}
|
|
4080
|
+
for (const file of sharedFiles) {
|
|
4081
|
+
contents.set(path.resolve(file.filePath), file.content);
|
|
4082
|
+
}
|
|
4083
|
+
for (const filePath of contents.keys()) {
|
|
4084
|
+
assertNoSymlinkParents(filePath, root, projectRoot);
|
|
4085
|
+
assertRegularFile(filePath);
|
|
4086
|
+
}
|
|
4087
|
+
for (const [filePath, content] of contents) writeFile(filePath, content);
|
|
4088
|
+
for (const filePath of obsolete) fs.unlinkSync(filePath);
|
|
4089
|
+
writeFile(manifestPath, `${JSON.stringify(next, null, 2)}
|
|
4090
|
+
`);
|
|
4091
|
+
}
|
|
3993
4092
|
function safeRealpath(value) {
|
|
3994
4093
|
try {
|
|
3995
4094
|
if (fs.existsSync(value)) {
|
|
@@ -5751,7 +5850,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5751
5850
|
const {
|
|
5752
5851
|
outDir: outDirOverride,
|
|
5753
5852
|
generateFixtures,
|
|
5754
|
-
vueTestUtilsOutDir,
|
|
5853
|
+
vueTestUtilsOutDir: vueTestUtilsOutDirOverride,
|
|
5755
5854
|
customPomAttachments = [],
|
|
5756
5855
|
projectRoot,
|
|
5757
5856
|
customPomDir,
|
|
@@ -5772,7 +5871,9 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5772
5871
|
elementMetadata = /* @__PURE__ */ new Map()
|
|
5773
5872
|
} = options;
|
|
5774
5873
|
const emitLanguages = emitLanguagesOverride?.length ? emitLanguagesOverride : ["ts"];
|
|
5775
|
-
const
|
|
5874
|
+
const root = projectRoot ?? process.cwd();
|
|
5875
|
+
const outDir = path.resolve(root, outDirOverride ?? "./pom");
|
|
5876
|
+
const vueTestUtilsOutDir = vueTestUtilsOutDirOverride ? path.resolve(root, vueTestUtilsOutDirOverride) : void 0;
|
|
5776
5877
|
if (vueTestUtilsOutDir && path.resolve(vueTestUtilsOutDir) === path.resolve(outDir)) {
|
|
5777
5878
|
throw new Error("[vue-pom-generator] generation.vueTestUtils.outDir must differ from generation.outDir.");
|
|
5778
5879
|
}
|
|
@@ -5782,12 +5883,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5782
5883
|
layoutDirs
|
|
5783
5884
|
}) : void 0);
|
|
5784
5885
|
const emittableComponentHierarchyMap = componentHierarchyMap;
|
|
5785
|
-
const
|
|
5786
|
-
const writeGeneratedFile = (file) => {
|
|
5787
|
-
const resolvedFilePath = path.resolve(file.filePath);
|
|
5788
|
-
createFile(resolvedFilePath, file.content);
|
|
5789
|
-
generatedFilePaths.push(resolvedFilePath);
|
|
5790
|
-
};
|
|
5886
|
+
const generatedFiles = [];
|
|
5791
5887
|
if (emitLanguages.includes("ts")) {
|
|
5792
5888
|
const files = typescriptOutputStructure === "split" ? await generateSplitTypeScriptFiles(emittableComponentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, {
|
|
5793
5889
|
customPomAttachments,
|
|
@@ -5810,9 +5906,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5810
5906
|
routeMetaByComponent,
|
|
5811
5907
|
vueRouterFluentChaining
|
|
5812
5908
|
});
|
|
5813
|
-
|
|
5814
|
-
writeGeneratedFile(file);
|
|
5815
|
-
}
|
|
5909
|
+
generatedFiles.push(...files);
|
|
5816
5910
|
const fixtureRegistryFiles = maybeGenerateFixtureRegistry(emittableComponentHierarchyMap, {
|
|
5817
5911
|
generateFixtures,
|
|
5818
5912
|
pomOutDir: outDir,
|
|
@@ -5821,18 +5915,14 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5821
5915
|
elementMetadata,
|
|
5822
5916
|
testIdAttribute
|
|
5823
5917
|
});
|
|
5824
|
-
|
|
5825
|
-
writeGeneratedFile(fixtureRegistryFile);
|
|
5826
|
-
}
|
|
5918
|
+
generatedFiles.push(...fixtureRegistryFiles);
|
|
5827
5919
|
}
|
|
5828
5920
|
if (emitLanguages.includes("csharp")) {
|
|
5829
5921
|
const csFiles = generateAggregatedCSharpFiles(emittableComponentHierarchyMap, outDir, {
|
|
5830
5922
|
testIdAttribute,
|
|
5831
5923
|
csharp
|
|
5832
5924
|
});
|
|
5833
|
-
|
|
5834
|
-
writeGeneratedFile(file);
|
|
5835
|
-
}
|
|
5925
|
+
generatedFiles.push(...csFiles);
|
|
5836
5926
|
}
|
|
5837
5927
|
if (vueTestUtilsOutDir) {
|
|
5838
5928
|
const vueTestUtilsFiles = generateVueTestUtilsFiles(
|
|
@@ -5840,14 +5930,10 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5840
5930
|
vueTestUtilsOutDir,
|
|
5841
5931
|
{ testIdAttribute }
|
|
5842
5932
|
);
|
|
5843
|
-
|
|
5844
|
-
writeGeneratedFile(file);
|
|
5845
|
-
}
|
|
5846
|
-
}
|
|
5847
|
-
const gitattributesFiles = buildGeneratedGitAttributesFiles(generatedFilePaths);
|
|
5848
|
-
for (const file of gitattributesFiles) {
|
|
5849
|
-
createFile(file.filePath, file.content);
|
|
5933
|
+
generatedFiles.push(...vueTestUtilsFiles);
|
|
5850
5934
|
}
|
|
5935
|
+
const gitattributesFiles = buildGeneratedGitAttributesFiles(generatedFiles.map((file) => file.filePath));
|
|
5936
|
+
writeGeneratedOutputs(outDir, generatedFiles, gitattributesFiles, path.resolve(root));
|
|
5851
5937
|
}
|
|
5852
5938
|
const VUE_TEST_UTILS_OMITTED_PARAMETERS = /* @__PURE__ */ new Set(["annotationText", "timeOut", "timeout", "wait"]);
|
|
5853
5939
|
function getVueTestUtilsParameters(parameters, patterns, options = {}) {
|
|
@@ -7834,16 +7920,6 @@ async function generateAggregatedFiles(componentHierarchyMap, vueFilesPathMap, b
|
|
|
7834
7920
|
...runtimeFiles
|
|
7835
7921
|
];
|
|
7836
7922
|
}
|
|
7837
|
-
function createFile(filePath, content) {
|
|
7838
|
-
const dir = path.dirname(filePath);
|
|
7839
|
-
if (!fs.existsSync(dir)) {
|
|
7840
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
7841
|
-
}
|
|
7842
|
-
if (fs.existsSync(filePath)) {
|
|
7843
|
-
fs.unlinkSync(filePath);
|
|
7844
|
-
}
|
|
7845
|
-
fs.writeFileSync(filePath, content);
|
|
7846
|
-
}
|
|
7847
7923
|
function lowerFirst(value) {
|
|
7848
7924
|
if (!value)
|
|
7849
7925
|
return value;
|
|
@@ -8007,130 +8083,353 @@ function getConstructor(componentInstances, attachmentsForThisView = [], widgetI
|
|
|
8007
8083
|
}
|
|
8008
8084
|
});
|
|
8009
8085
|
}
|
|
8010
|
-
|
|
8011
|
-
|
|
8012
|
-
|
|
8013
|
-
|
|
8014
|
-
|
|
8015
|
-
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
}
|
|
8019
|
-
function isAsciiDigitCode(code) {
|
|
8020
|
-
return code >= 48 && code <= 57;
|
|
8021
|
-
}
|
|
8022
|
-
function toKebabCaseTag(tag) {
|
|
8023
|
-
let result = "";
|
|
8024
|
-
let previousWasSeparator = false;
|
|
8025
|
-
for (let i = 0; i < tag.length; i += 1) {
|
|
8026
|
-
const ch = tag[i];
|
|
8027
|
-
const code = ch.charCodeAt(0);
|
|
8028
|
-
if (ch === "_" || ch === "-" || ch === "." || ch === " " || ch === " " || ch === "\n" || ch === "\r") {
|
|
8029
|
-
if (result && !previousWasSeparator) {
|
|
8030
|
-
result += "-";
|
|
8031
|
-
}
|
|
8032
|
-
previousWasSeparator = true;
|
|
8033
|
-
continue;
|
|
8034
|
-
}
|
|
8035
|
-
const previous = i > 0 ? tag[i - 1] : "";
|
|
8036
|
-
const previousCode = previous ? previous.charCodeAt(0) : 0;
|
|
8037
|
-
const shouldInsertSeparator = i > 0 && isAsciiUppercaseLetterCode(code) && (isAsciiLetterCode(previousCode) || isAsciiDigitCode(previousCode)) && !previousWasSeparator;
|
|
8038
|
-
if (shouldInsertSeparator) {
|
|
8039
|
-
result += "-";
|
|
8086
|
+
function summarizeHierarchyMap(componentHierarchyMap) {
|
|
8087
|
+
let interactiveComponentCount = 0;
|
|
8088
|
+
let dataTestIdCount = 0;
|
|
8089
|
+
for (const dependencies of componentHierarchyMap.values()) {
|
|
8090
|
+
const selectorCount = dependencies.dataTestIdSet?.size ?? 0;
|
|
8091
|
+
if (selectorCount > 0) {
|
|
8092
|
+
interactiveComponentCount += 1;
|
|
8093
|
+
dataTestIdCount += selectorCount;
|
|
8040
8094
|
}
|
|
8041
|
-
result += ch.toLowerCase();
|
|
8042
|
-
previousWasSeparator = false;
|
|
8043
8095
|
}
|
|
8044
|
-
return
|
|
8096
|
+
return {
|
|
8097
|
+
entryCount: componentHierarchyMap.size,
|
|
8098
|
+
interactiveComponentCount,
|
|
8099
|
+
dataTestIdCount
|
|
8100
|
+
};
|
|
8045
8101
|
}
|
|
8046
|
-
function
|
|
8047
|
-
|
|
8048
|
-
|
|
8049
|
-
const resolved = path.resolve(root);
|
|
8050
|
-
try {
|
|
8051
|
-
if (!fs.existsSync(resolved) || !fs.statSync(resolved).isDirectory()) {
|
|
8052
|
-
continue;
|
|
8053
|
-
}
|
|
8054
|
-
normalized.add(path.normalize(fs.realpathSync(resolved)));
|
|
8055
|
-
} catch {
|
|
8056
|
-
continue;
|
|
8057
|
-
}
|
|
8102
|
+
function isLessRich(candidate, previous) {
|
|
8103
|
+
if (candidate.dataTestIdCount !== previous.dataTestIdCount) {
|
|
8104
|
+
return candidate.dataTestIdCount < previous.dataTestIdCount;
|
|
8058
8105
|
}
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
function buildSearchRootsKey(searchRoots) {
|
|
8062
|
-
return searchRoots.join("\n");
|
|
8063
|
-
}
|
|
8064
|
-
function buildVueSfcPathIndex(searchRoots) {
|
|
8065
|
-
const indexKey = buildSearchRootsKey(searchRoots);
|
|
8066
|
-
const existingIndex = indexedVueSfcPathsByRoots.get(indexKey);
|
|
8067
|
-
if (existingIndex) {
|
|
8068
|
-
return existingIndex;
|
|
8106
|
+
if (candidate.interactiveComponentCount !== previous.interactiveComponentCount) {
|
|
8107
|
+
return candidate.interactiveComponentCount < previous.interactiveComponentCount;
|
|
8069
8108
|
}
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
|
|
8077
|
-
|
|
8078
|
-
|
|
8079
|
-
|
|
8080
|
-
|
|
8081
|
-
|
|
8082
|
-
|
|
8083
|
-
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
|
|
8087
|
-
|
|
8088
|
-
|
|
8089
|
-
|
|
8090
|
-
|
|
8091
|
-
|
|
8092
|
-
|
|
8093
|
-
|
|
8094
|
-
|
|
8095
|
-
|
|
8096
|
-
|
|
8097
|
-
|
|
8098
|
-
|
|
8099
|
-
|
|
8100
|
-
|
|
8101
|
-
|
|
8102
|
-
|
|
8103
|
-
|
|
8104
|
-
|
|
8105
|
-
|
|
8109
|
+
return candidate.entryCount < previous.entryCount;
|
|
8110
|
+
}
|
|
8111
|
+
function createBuildProcessorPlugin(options) {
|
|
8112
|
+
const {
|
|
8113
|
+
componentHierarchyMap,
|
|
8114
|
+
elementMetadata,
|
|
8115
|
+
vueFilesPathMap,
|
|
8116
|
+
getPageDirs,
|
|
8117
|
+
getComponentDirs,
|
|
8118
|
+
getLayoutDirs,
|
|
8119
|
+
getViewsDir,
|
|
8120
|
+
getSourceDirs,
|
|
8121
|
+
basePageClassPath,
|
|
8122
|
+
normalizedBasePagePath,
|
|
8123
|
+
generation,
|
|
8124
|
+
projectRootRef,
|
|
8125
|
+
collectSource,
|
|
8126
|
+
generationOnly,
|
|
8127
|
+
getResolvedRouterEntry,
|
|
8128
|
+
loggerRef
|
|
8129
|
+
} = options;
|
|
8130
|
+
const {
|
|
8131
|
+
outDir,
|
|
8132
|
+
emitLanguages,
|
|
8133
|
+
typescriptOutputStructure,
|
|
8134
|
+
csharp,
|
|
8135
|
+
generateFixtures,
|
|
8136
|
+
vueTestUtilsOutDir,
|
|
8137
|
+
customPomAttachments,
|
|
8138
|
+
customPomDir,
|
|
8139
|
+
requireCustomPomDir,
|
|
8140
|
+
customPomImportAliases,
|
|
8141
|
+
customPomImportNameCollisionBehavior,
|
|
8142
|
+
testIdAttribute,
|
|
8143
|
+
routerAwarePoms,
|
|
8144
|
+
routerType,
|
|
8145
|
+
routerModuleShims
|
|
8146
|
+
} = generation;
|
|
8147
|
+
let lastGeneratedMetrics = {
|
|
8148
|
+
entryCount: 0,
|
|
8149
|
+
interactiveComponentCount: 0,
|
|
8150
|
+
dataTestIdCount: 0
|
|
8151
|
+
};
|
|
8152
|
+
const getViewsDirAbs = () => path.isAbsolute(getViewsDir()) ? getViewsDir() : path.resolve(projectRootRef.current, getViewsDir());
|
|
8153
|
+
const getPageDirsAbs = () => getPageDirs().map((dir) => path.isAbsolute(dir) ? dir : path.resolve(projectRootRef.current, dir));
|
|
8154
|
+
const supplementHierarchyFromFilesystem = async () => {
|
|
8155
|
+
const walkFilesRecursive = (rootDir) => {
|
|
8156
|
+
const out = [];
|
|
8157
|
+
const stack = [rootDir];
|
|
8158
|
+
while (stack.length) {
|
|
8159
|
+
const dir = stack.pop();
|
|
8160
|
+
if (!dir) continue;
|
|
8161
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
8162
|
+
for (const ent of entries) {
|
|
8163
|
+
if (ent.isDirectory()) {
|
|
8164
|
+
if (ent.name === "node_modules" || ent.name === ".git" || ent.name === "dist")
|
|
8165
|
+
continue;
|
|
8166
|
+
stack.push(path.join(dir, ent.name));
|
|
8167
|
+
continue;
|
|
8168
|
+
}
|
|
8169
|
+
if (ent.isFile() && ent.name.endsWith(".vue")) {
|
|
8170
|
+
out.push(path.join(dir, ent.name));
|
|
8171
|
+
}
|
|
8106
8172
|
}
|
|
8107
|
-
stack.push(fullPath);
|
|
8108
|
-
continue;
|
|
8109
8173
|
}
|
|
8110
|
-
|
|
8174
|
+
return out;
|
|
8175
|
+
};
|
|
8176
|
+
let supplemented = 0;
|
|
8177
|
+
let sourceDirectories = 0;
|
|
8178
|
+
for (const dir of getSourceDirs()) {
|
|
8179
|
+
const absDir = path.resolve(projectRootRef.current, dir);
|
|
8180
|
+
if (!fs.existsSync(absDir))
|
|
8111
8181
|
continue;
|
|
8182
|
+
sourceDirectories++;
|
|
8183
|
+
for (const filePath of walkFilesRecursive(absDir)) {
|
|
8184
|
+
const absolutePath = path.resolve(filePath);
|
|
8185
|
+
const componentName = resolveComponentNameFromPath({
|
|
8186
|
+
filename: absolutePath,
|
|
8187
|
+
projectRoot: projectRootRef.current,
|
|
8188
|
+
viewsDirAbs: getViewsDirAbs(),
|
|
8189
|
+
sourceDirs: getSourceDirs(),
|
|
8190
|
+
extraRoots: [process.cwd()]
|
|
8191
|
+
});
|
|
8192
|
+
if (componentHierarchyMap.has(componentName))
|
|
8193
|
+
continue;
|
|
8194
|
+
await collectSource(fs.readFileSync(absolutePath, "utf8"), absolutePath);
|
|
8195
|
+
supplemented++;
|
|
8112
8196
|
}
|
|
8113
|
-
const matches = index.get(entry.name) ?? [];
|
|
8114
|
-
matches.push(fullPath);
|
|
8115
|
-
index.set(entry.name, matches);
|
|
8116
8197
|
}
|
|
8117
|
-
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
|
|
8121
|
-
|
|
8122
|
-
|
|
8123
|
-
|
|
8124
|
-
|
|
8125
|
-
|
|
8126
|
-
|
|
8127
|
-
|
|
8128
|
-
|
|
8129
|
-
|
|
8130
|
-
|
|
8131
|
-
|
|
8132
|
-
|
|
8133
|
-
|
|
8198
|
+
if (generationOnly && sourceDirectories === 0) {
|
|
8199
|
+
throw new Error("[vue-pom-generator] No configured source directories exist. Check the Vite root and injection directories.");
|
|
8200
|
+
}
|
|
8201
|
+
if (supplemented > 0) {
|
|
8202
|
+
loggerRef.current.info(`supplemented ${supplemented} components from filesystem walk (not in build graph)`);
|
|
8203
|
+
}
|
|
8204
|
+
};
|
|
8205
|
+
return {
|
|
8206
|
+
name: "vue-pom-generator-build",
|
|
8207
|
+
// This plugin exists to generate code on build output; it is not needed during dev-server HMR.
|
|
8208
|
+
apply: "build",
|
|
8209
|
+
enforce: "pre",
|
|
8210
|
+
async buildStart() {
|
|
8211
|
+
if (!routerAwarePoms) {
|
|
8212
|
+
setRouteNameToComponentNameMap(/* @__PURE__ */ new Map());
|
|
8213
|
+
setResolveToComponentNameFn(() => null);
|
|
8214
|
+
return;
|
|
8215
|
+
}
|
|
8216
|
+
let result;
|
|
8217
|
+
if (routerType === "nuxt") {
|
|
8218
|
+
result = await introspectNuxtPages(projectRootRef.current, { pageDirs: getPageDirsAbs() });
|
|
8219
|
+
} else {
|
|
8220
|
+
const resolvedRouterEntry = getResolvedRouterEntry();
|
|
8221
|
+
if (!resolvedRouterEntry)
|
|
8222
|
+
throw new Error("[vue-pom-generator] router.entry is required when router introspection is enabled.");
|
|
8223
|
+
result = await parseRouterFileFromCwd(resolvedRouterEntry, {
|
|
8224
|
+
moduleShims: routerModuleShims,
|
|
8225
|
+
componentNaming: {
|
|
8226
|
+
projectRoot: projectRootRef.current,
|
|
8227
|
+
viewsDirAbs: getViewsDirAbs(),
|
|
8228
|
+
sourceDirs: getSourceDirs()
|
|
8229
|
+
}
|
|
8230
|
+
});
|
|
8231
|
+
}
|
|
8232
|
+
const { routeNameMap, routePathMap } = result;
|
|
8233
|
+
setRouteNameToComponentNameMap(routeNameMap);
|
|
8234
|
+
setResolveToComponentNameFn((to) => {
|
|
8235
|
+
if (typeof to === "string") {
|
|
8236
|
+
return routePathMap.get(to) ?? null;
|
|
8237
|
+
}
|
|
8238
|
+
const maybe = to;
|
|
8239
|
+
if (typeof maybe.name === "string" && maybe.name.length) {
|
|
8240
|
+
const key = toPascalCase(maybe.name);
|
|
8241
|
+
return routeNameMap.get(key) ?? null;
|
|
8242
|
+
}
|
|
8243
|
+
if (typeof maybe.path === "string" && maybe.path.length) {
|
|
8244
|
+
return routePathMap.get(maybe.path) ?? null;
|
|
8245
|
+
}
|
|
8246
|
+
return null;
|
|
8247
|
+
});
|
|
8248
|
+
if (!fs.existsSync(basePageClassPath)) {
|
|
8249
|
+
this.error(`Base page runtime file not found at ${basePageClassPath}. Ensure it is included in the build.`);
|
|
8250
|
+
}
|
|
8251
|
+
this.addWatchFile(basePageClassPath);
|
|
8252
|
+
const pointerPath = path.resolve(path.dirname(basePageClassPath), "pointer.ts");
|
|
8253
|
+
if (!fs.existsSync(pointerPath)) {
|
|
8254
|
+
this.error(`pointer.ts not found at ${pointerPath}. Ensure it is included in the build.`);
|
|
8255
|
+
}
|
|
8256
|
+
this.addWatchFile(pointerPath);
|
|
8257
|
+
const calloutPath = path.resolve(path.dirname(basePageClassPath), "callout.ts");
|
|
8258
|
+
if (!fs.existsSync(calloutPath)) {
|
|
8259
|
+
this.error(`callout.ts not found at ${calloutPath}. Ensure it is included in the build.`);
|
|
8260
|
+
}
|
|
8261
|
+
this.addWatchFile(calloutPath);
|
|
8262
|
+
const floatingUiCalloutPath = path.resolve(path.dirname(basePageClassPath), "floating-ui-callout.ts");
|
|
8263
|
+
if (fs.existsSync(floatingUiCalloutPath)) {
|
|
8264
|
+
this.addWatchFile(floatingUiCalloutPath);
|
|
8265
|
+
}
|
|
8266
|
+
},
|
|
8267
|
+
async buildEnd(error) {
|
|
8268
|
+
if (error) {
|
|
8269
|
+
return;
|
|
8270
|
+
}
|
|
8271
|
+
await supplementHierarchyFromFilesystem();
|
|
8272
|
+
const metrics = summarizeHierarchyMap(componentHierarchyMap);
|
|
8273
|
+
if (!generationOnly && metrics.dataTestIdCount <= 0) {
|
|
8274
|
+
return;
|
|
8275
|
+
}
|
|
8276
|
+
if (!generationOnly && isLessRich(metrics, lastGeneratedMetrics)) {
|
|
8277
|
+
return;
|
|
8278
|
+
}
|
|
8279
|
+
await generateFiles(componentHierarchyMap, vueFilesPathMap, normalizedBasePagePath, {
|
|
8280
|
+
outDir,
|
|
8281
|
+
emitLanguages,
|
|
8282
|
+
typescriptOutputStructure,
|
|
8283
|
+
csharp,
|
|
8284
|
+
generateFixtures,
|
|
8285
|
+
vueTestUtilsOutDir,
|
|
8286
|
+
customPomAttachments,
|
|
8287
|
+
projectRoot: projectRootRef.current,
|
|
8288
|
+
customPomDir,
|
|
8289
|
+
requireCustomPomDir,
|
|
8290
|
+
customPomImportAliases,
|
|
8291
|
+
customPomImportNameCollisionBehavior,
|
|
8292
|
+
testIdAttribute,
|
|
8293
|
+
vueRouterFluentChaining: routerAwarePoms,
|
|
8294
|
+
routerEntry: getResolvedRouterEntry(),
|
|
8295
|
+
routerType,
|
|
8296
|
+
pageDirs: getPageDirs(),
|
|
8297
|
+
componentDirs: getComponentDirs(),
|
|
8298
|
+
layoutDirs: getLayoutDirs(),
|
|
8299
|
+
elementMetadata
|
|
8300
|
+
});
|
|
8301
|
+
lastGeneratedMetrics = metrics;
|
|
8302
|
+
loggerRef.current.info(`generated POMs (${metrics.entryCount} entries, ${metrics.interactiveComponentCount} interactive components, ${metrics.dataTestIdCount} selectors)`);
|
|
8303
|
+
},
|
|
8304
|
+
closeBundle() {
|
|
8305
|
+
loggerRef.current.info("build complete");
|
|
8306
|
+
}
|
|
8307
|
+
};
|
|
8308
|
+
}
|
|
8309
|
+
const TESTID_CLICK_EVENT_NAME = "__testid_event__";
|
|
8310
|
+
const indexedVueSfcPathsByRoots = /* @__PURE__ */ new Map();
|
|
8311
|
+
const resolvedSfcPathByLookup = /* @__PURE__ */ new Map();
|
|
8312
|
+
function isAsciiUppercaseLetterCode(code) {
|
|
8313
|
+
return code >= 65 && code <= 90;
|
|
8314
|
+
}
|
|
8315
|
+
function isAsciiLetterCode(code) {
|
|
8316
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
8317
|
+
}
|
|
8318
|
+
function isAsciiDigitCode(code) {
|
|
8319
|
+
return code >= 48 && code <= 57;
|
|
8320
|
+
}
|
|
8321
|
+
function toKebabCaseTag(tag) {
|
|
8322
|
+
let result = "";
|
|
8323
|
+
let previousWasSeparator = false;
|
|
8324
|
+
for (let i = 0; i < tag.length; i += 1) {
|
|
8325
|
+
const ch = tag[i];
|
|
8326
|
+
const code = ch.charCodeAt(0);
|
|
8327
|
+
if (ch === "_" || ch === "-" || ch === "." || ch === " " || ch === " " || ch === "\n" || ch === "\r") {
|
|
8328
|
+
if (result && !previousWasSeparator) {
|
|
8329
|
+
result += "-";
|
|
8330
|
+
}
|
|
8331
|
+
previousWasSeparator = true;
|
|
8332
|
+
continue;
|
|
8333
|
+
}
|
|
8334
|
+
const previous = i > 0 ? tag[i - 1] : "";
|
|
8335
|
+
const previousCode = previous ? previous.charCodeAt(0) : 0;
|
|
8336
|
+
const shouldInsertSeparator = i > 0 && isAsciiUppercaseLetterCode(code) && (isAsciiLetterCode(previousCode) || isAsciiDigitCode(previousCode)) && !previousWasSeparator;
|
|
8337
|
+
if (shouldInsertSeparator) {
|
|
8338
|
+
result += "-";
|
|
8339
|
+
}
|
|
8340
|
+
result += ch.toLowerCase();
|
|
8341
|
+
previousWasSeparator = false;
|
|
8342
|
+
}
|
|
8343
|
+
return result;
|
|
8344
|
+
}
|
|
8345
|
+
function normalizeWrapperSearchRoots(wrapperSearchRoots) {
|
|
8346
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
8347
|
+
for (const root of wrapperSearchRoots) {
|
|
8348
|
+
const resolved = path.resolve(root);
|
|
8349
|
+
try {
|
|
8350
|
+
if (!fs.existsSync(resolved) || !fs.statSync(resolved).isDirectory()) {
|
|
8351
|
+
continue;
|
|
8352
|
+
}
|
|
8353
|
+
normalized.add(path.normalize(fs.realpathSync(resolved)));
|
|
8354
|
+
} catch {
|
|
8355
|
+
continue;
|
|
8356
|
+
}
|
|
8357
|
+
}
|
|
8358
|
+
return [...normalized];
|
|
8359
|
+
}
|
|
8360
|
+
function buildSearchRootsKey(searchRoots) {
|
|
8361
|
+
return searchRoots.join("\n");
|
|
8362
|
+
}
|
|
8363
|
+
function buildVueSfcPathIndex(searchRoots) {
|
|
8364
|
+
const indexKey = buildSearchRootsKey(searchRoots);
|
|
8365
|
+
const existingIndex = indexedVueSfcPathsByRoots.get(indexKey);
|
|
8366
|
+
if (existingIndex) {
|
|
8367
|
+
return existingIndex;
|
|
8368
|
+
}
|
|
8369
|
+
const index = /* @__PURE__ */ new Map();
|
|
8370
|
+
const ignoredDirNames = /* @__PURE__ */ new Set([
|
|
8371
|
+
".git",
|
|
8372
|
+
".idea",
|
|
8373
|
+
".next",
|
|
8374
|
+
".nuxt",
|
|
8375
|
+
".output",
|
|
8376
|
+
".turbo",
|
|
8377
|
+
".yarn",
|
|
8378
|
+
"coverage",
|
|
8379
|
+
"dist",
|
|
8380
|
+
"build",
|
|
8381
|
+
"node_modules",
|
|
8382
|
+
"out",
|
|
8383
|
+
"tmp"
|
|
8384
|
+
]);
|
|
8385
|
+
const stack = [...searchRoots];
|
|
8386
|
+
const seenDirs = /* @__PURE__ */ new Set();
|
|
8387
|
+
while (stack.length > 0) {
|
|
8388
|
+
const dirPath = stack.pop();
|
|
8389
|
+
const normalizedDir = path.normalize(dirPath);
|
|
8390
|
+
if (seenDirs.has(normalizedDir)) {
|
|
8391
|
+
continue;
|
|
8392
|
+
}
|
|
8393
|
+
seenDirs.add(normalizedDir);
|
|
8394
|
+
let entries = [];
|
|
8395
|
+
try {
|
|
8396
|
+
entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
8397
|
+
} catch {
|
|
8398
|
+
continue;
|
|
8399
|
+
}
|
|
8400
|
+
for (const entry of entries) {
|
|
8401
|
+
const fullPath = path.join(dirPath, entry.name);
|
|
8402
|
+
if (entry.isDirectory()) {
|
|
8403
|
+
if (ignoredDirNames.has(entry.name) || entry.name.startsWith(".")) {
|
|
8404
|
+
continue;
|
|
8405
|
+
}
|
|
8406
|
+
stack.push(fullPath);
|
|
8407
|
+
continue;
|
|
8408
|
+
}
|
|
8409
|
+
if (!entry.isFile() || !entry.name.endsWith(".vue")) {
|
|
8410
|
+
continue;
|
|
8411
|
+
}
|
|
8412
|
+
const matches = index.get(entry.name) ?? [];
|
|
8413
|
+
matches.push(fullPath);
|
|
8414
|
+
index.set(entry.name, matches);
|
|
8415
|
+
}
|
|
8416
|
+
}
|
|
8417
|
+
indexedVueSfcPathsByRoots.set(indexKey, index);
|
|
8418
|
+
return index;
|
|
8419
|
+
}
|
|
8420
|
+
function resolveSfcPathForTag(tag, vueFilesPathMap, wrapperSearchRoots = []) {
|
|
8421
|
+
const registeredPath = vueFilesPathMap?.get(tag);
|
|
8422
|
+
const normalizedSearchRoots = normalizeWrapperSearchRoots(wrapperSearchRoots);
|
|
8423
|
+
const lookupKey = `${tag}
|
|
8424
|
+
${registeredPath ?? ""}
|
|
8425
|
+
${buildSearchRootsKey(normalizedSearchRoots)}`;
|
|
8426
|
+
if (resolvedSfcPathByLookup.has(lookupKey)) {
|
|
8427
|
+
return resolvedSfcPathByLookup.get(lookupKey) ?? null;
|
|
8428
|
+
}
|
|
8429
|
+
const candidateNames = [`${tag}.vue`, `${toKebabCaseTag(tag)}.vue`];
|
|
8430
|
+
const directCandidates = [
|
|
8431
|
+
registeredPath ? path.resolve(process.cwd(), registeredPath) : null,
|
|
8432
|
+
...normalizedSearchRoots.flatMap((root) => candidateNames.map((fileName) => path.join(root, fileName)))
|
|
8134
8433
|
].filter((value) => !!value);
|
|
8135
8434
|
const directMatch = directCandidates.find((candidatePath) => fs.existsSync(candidatePath));
|
|
8136
8435
|
if (directMatch) {
|
|
@@ -10074,9 +10373,7 @@ function extractMetadataAfterTransform(ast, componentName, elementMetadata, sema
|
|
|
10074
10373
|
}
|
|
10075
10374
|
}
|
|
10076
10375
|
traverseNode(ast);
|
|
10077
|
-
|
|
10078
|
-
elementMetadata.set(componentName, componentMetadata);
|
|
10079
|
-
}
|
|
10376
|
+
elementMetadata.set(componentName, componentMetadata);
|
|
10080
10377
|
return componentMetadata;
|
|
10081
10378
|
}
|
|
10082
10379
|
function createVuePluginWithTestIds(options) {
|
|
@@ -10222,403 +10519,132 @@ function createVuePluginWithTestIds(options) {
|
|
|
10222
10519
|
crossFileKeyRegistry,
|
|
10223
10520
|
optionKeyAttribute
|
|
10224
10521
|
}
|
|
10225
|
-
);
|
|
10226
|
-
perFileTransform.set(componentName, transform);
|
|
10227
|
-
}
|
|
10228
|
-
return transform(node, context);
|
|
10229
|
-
}
|
|
10230
|
-
];
|
|
10231
|
-
};
|
|
10232
|
-
const runtimeNodeTransform = (node, context) => {
|
|
10233
|
-
const filename = context.filename;
|
|
10234
|
-
if (!filename || !filename.endsWith(".vue") || !isFileInScope(filename)) {
|
|
10235
|
-
return;
|
|
10236
|
-
}
|
|
10237
|
-
const transforms = getNodeTransforms(filename);
|
|
10238
|
-
const ourTransform = transforms[transforms.length - 1];
|
|
10239
|
-
return ourTransform(node, context);
|
|
10240
|
-
};
|
|
10241
|
-
const templateCompilerOptions = {
|
|
10242
|
-
...userCompilerOptions,
|
|
10243
|
-
prefixIdentifiers: true,
|
|
10244
|
-
nodeTransforms: [
|
|
10245
|
-
...userNodeTransforms,
|
|
10246
|
-
runtimeNodeTransform
|
|
10247
|
-
]
|
|
10248
|
-
};
|
|
10249
|
-
const metadataCollectorPlugin = {
|
|
10250
|
-
name: "vue-pom-generator-metadata-collector",
|
|
10251
|
-
enforce: "pre",
|
|
10252
|
-
async transform(code, id) {
|
|
10253
|
-
const cleanPath = id.includes("?") ? id.substring(0, id.indexOf("?")) : id;
|
|
10254
|
-
if (!cleanPath.endsWith(".vue") || !isFileInScope(id)) {
|
|
10255
|
-
return null;
|
|
10256
|
-
}
|
|
10257
|
-
if (id !== cleanPath) {
|
|
10258
|
-
return null;
|
|
10259
|
-
}
|
|
10260
|
-
const componentName = getComponentNameFromPath(cleanPath);
|
|
10261
|
-
loggerRef.current.debug(`Collecting metadata for ${cleanPath} (component: ${componentName})`);
|
|
10262
|
-
const compilerSfc = await import("@vue/compiler-sfc");
|
|
10263
|
-
const parse2 = resolveCompilerSfcParse(compilerSfc);
|
|
10264
|
-
const compilerDom2 = await import("@vue/compiler-dom");
|
|
10265
|
-
const compile = compilerDom2.compile;
|
|
10266
|
-
const { descriptor } = parse2(code, { filename: cleanPath });
|
|
10267
|
-
if (descriptor.template) {
|
|
10268
|
-
const mergedExpressionPlugins = Array.from(
|
|
10269
|
-
/* @__PURE__ */ new Set([
|
|
10270
|
-
"typescript",
|
|
10271
|
-
...userCompilerOptions.expressionPlugins ?? []
|
|
10272
|
-
])
|
|
10273
|
-
);
|
|
10274
|
-
compile(descriptor.template.content, {
|
|
10275
|
-
...userCompilerOptions,
|
|
10276
|
-
filename: cleanPath,
|
|
10277
|
-
expressionPlugins: mergedExpressionPlugins,
|
|
10278
|
-
nodeTransforms: getNodeTransforms(cleanPath, componentName)
|
|
10279
|
-
});
|
|
10280
|
-
loggerRef.current.debug(`Metadata collected for ${cleanPath}`);
|
|
10281
|
-
}
|
|
10282
|
-
return null;
|
|
10283
|
-
}
|
|
10284
|
-
};
|
|
10285
|
-
const template = {
|
|
10286
|
-
...userTemplate,
|
|
10287
|
-
compilerOptions: templateCompilerOptions
|
|
10288
|
-
};
|
|
10289
|
-
const internalVuePlugin = vue({
|
|
10290
|
-
...vueOptions,
|
|
10291
|
-
template
|
|
10292
|
-
});
|
|
10293
|
-
const nuxtVueBridgePlugin = {
|
|
10294
|
-
name: "vue-pom-generator-nuxt-vue-bridge",
|
|
10295
|
-
apply: "serve",
|
|
10296
|
-
configResolved(config) {
|
|
10297
|
-
const viteVuePlugin = config.plugins.find((plugin) => {
|
|
10298
|
-
return typeof plugin === "object" && plugin !== null && "name" in plugin && plugin.name === "vite:vue" && "api" in plugin;
|
|
10299
|
-
});
|
|
10300
|
-
const api = viteVuePlugin?.api;
|
|
10301
|
-
if (!api) {
|
|
10302
|
-
throw new Error("[vue-pom-generator] Nuxt bridge could not find vite:vue plugin to patch.");
|
|
10303
|
-
}
|
|
10304
|
-
const currentOptions = api.options ?? {};
|
|
10305
|
-
const currentTemplate = currentOptions.template ?? {};
|
|
10306
|
-
const currentCompilerOptions = currentTemplate.compilerOptions ?? {};
|
|
10307
|
-
const currentNodeTransforms = currentCompilerOptions.nodeTransforms ?? [];
|
|
10308
|
-
if (currentNodeTransforms.includes(runtimeNodeTransform)) {
|
|
10309
|
-
return;
|
|
10310
|
-
}
|
|
10311
|
-
api.options = {
|
|
10312
|
-
...currentOptions,
|
|
10313
|
-
template: {
|
|
10314
|
-
...currentTemplate,
|
|
10315
|
-
compilerOptions: {
|
|
10316
|
-
...currentCompilerOptions,
|
|
10317
|
-
prefixIdentifiers: true,
|
|
10318
|
-
nodeTransforms: [
|
|
10319
|
-
...currentNodeTransforms,
|
|
10320
|
-
runtimeNodeTransform
|
|
10321
|
-
]
|
|
10322
|
-
}
|
|
10323
|
-
}
|
|
10324
|
-
};
|
|
10325
|
-
}
|
|
10326
|
-
};
|
|
10327
|
-
return { metadataCollectorPlugin, internalVuePlugin, nuxtVueBridgePlugin, templateCompilerOptions };
|
|
10328
|
-
}
|
|
10329
|
-
function summarizeHierarchyMap(componentHierarchyMap) {
|
|
10330
|
-
let interactiveComponentCount = 0;
|
|
10331
|
-
let dataTestIdCount = 0;
|
|
10332
|
-
for (const dependencies of componentHierarchyMap.values()) {
|
|
10333
|
-
const selectorCount = dependencies.dataTestIdSet?.size ?? 0;
|
|
10334
|
-
if (selectorCount > 0) {
|
|
10335
|
-
interactiveComponentCount += 1;
|
|
10336
|
-
dataTestIdCount += selectorCount;
|
|
10337
|
-
}
|
|
10338
|
-
}
|
|
10339
|
-
return {
|
|
10340
|
-
entryCount: componentHierarchyMap.size,
|
|
10341
|
-
interactiveComponentCount,
|
|
10342
|
-
dataTestIdCount
|
|
10343
|
-
};
|
|
10344
|
-
}
|
|
10345
|
-
function isLessRich(candidate, previous) {
|
|
10346
|
-
if (candidate.dataTestIdCount !== previous.dataTestIdCount) {
|
|
10347
|
-
return candidate.dataTestIdCount < previous.dataTestIdCount;
|
|
10348
|
-
}
|
|
10349
|
-
if (candidate.interactiveComponentCount !== previous.interactiveComponentCount) {
|
|
10350
|
-
return candidate.interactiveComponentCount < previous.interactiveComponentCount;
|
|
10351
|
-
}
|
|
10352
|
-
return candidate.entryCount < previous.entryCount;
|
|
10353
|
-
}
|
|
10354
|
-
function createBuildProcessorPlugin(options) {
|
|
10355
|
-
const {
|
|
10356
|
-
componentHierarchyMap,
|
|
10357
|
-
elementMetadata,
|
|
10358
|
-
crossFileKeyRegistry,
|
|
10359
|
-
vueFilesPathMap,
|
|
10360
|
-
getPageDirs,
|
|
10361
|
-
getComponentDirs,
|
|
10362
|
-
getLayoutDirs,
|
|
10363
|
-
getViewsDir,
|
|
10364
|
-
getSourceDirs,
|
|
10365
|
-
basePageClassPath,
|
|
10366
|
-
normalizedBasePagePath,
|
|
10367
|
-
generation,
|
|
10368
|
-
projectRootRef,
|
|
10369
|
-
nativeWrappers,
|
|
10370
|
-
optionKeyAttribute,
|
|
10371
|
-
skipTestIdGenerationInsideComponents,
|
|
10372
|
-
getWrapperSearchRoots,
|
|
10373
|
-
getResolvedRouterEntry,
|
|
10374
|
-
loggerRef
|
|
10375
|
-
} = options;
|
|
10376
|
-
const {
|
|
10377
|
-
outDir,
|
|
10378
|
-
emitLanguages,
|
|
10379
|
-
typescriptOutputStructure,
|
|
10380
|
-
csharp,
|
|
10381
|
-
generateFixtures,
|
|
10382
|
-
vueTestUtilsOutDir,
|
|
10383
|
-
customPomAttachments,
|
|
10384
|
-
customPomDir,
|
|
10385
|
-
requireCustomPomDir,
|
|
10386
|
-
customPomImportAliases,
|
|
10387
|
-
customPomImportNameCollisionBehavior,
|
|
10388
|
-
testIdAttribute,
|
|
10389
|
-
nameCollisionBehavior,
|
|
10390
|
-
missingSemanticNameBehavior,
|
|
10391
|
-
existingIdBehavior,
|
|
10392
|
-
routerAwarePoms,
|
|
10393
|
-
routerType,
|
|
10394
|
-
routerModuleShims
|
|
10395
|
-
} = generation;
|
|
10396
|
-
let lastGeneratedMetrics = {
|
|
10397
|
-
entryCount: 0,
|
|
10398
|
-
interactiveComponentCount: 0,
|
|
10399
|
-
dataTestIdCount: 0
|
|
10522
|
+
);
|
|
10523
|
+
perFileTransform.set(componentName, transform);
|
|
10524
|
+
}
|
|
10525
|
+
return transform(node, context);
|
|
10526
|
+
}
|
|
10527
|
+
];
|
|
10400
10528
|
};
|
|
10401
|
-
const
|
|
10402
|
-
|
|
10403
|
-
|
|
10404
|
-
|
|
10405
|
-
const { descriptor } = parse$1(source, { filename });
|
|
10406
|
-
if (!descriptor.script && !descriptor.scriptSetup)
|
|
10407
|
-
return { bindings: void 0, isScriptSetup: false };
|
|
10408
|
-
const scriptBlock = compileScript(descriptor, { id: filename });
|
|
10409
|
-
return { bindings: scriptBlock.bindings, isScriptSetup: !!descriptor.scriptSetup };
|
|
10410
|
-
} catch {
|
|
10411
|
-
return { bindings: void 0, isScriptSetup: false };
|
|
10529
|
+
const runtimeNodeTransform = (node, context) => {
|
|
10530
|
+
const filename = context.filename;
|
|
10531
|
+
if (!filename || !filename.endsWith(".vue") || !isFileInScope(filename)) {
|
|
10532
|
+
return;
|
|
10412
10533
|
}
|
|
10534
|
+
const transforms = getNodeTransforms(filename);
|
|
10535
|
+
const ourTransform = transforms[transforms.length - 1];
|
|
10536
|
+
return ourTransform(node, context);
|
|
10413
10537
|
};
|
|
10414
|
-
const
|
|
10415
|
-
|
|
10416
|
-
|
|
10417
|
-
|
|
10418
|
-
|
|
10419
|
-
|
|
10420
|
-
|
|
10421
|
-
|
|
10422
|
-
|
|
10423
|
-
|
|
10424
|
-
|
|
10425
|
-
|
|
10426
|
-
|
|
10427
|
-
|
|
10428
|
-
|
|
10429
|
-
|
|
10430
|
-
|
|
10431
|
-
|
|
10432
|
-
|
|
10433
|
-
|
|
10434
|
-
|
|
10435
|
-
|
|
10436
|
-
|
|
10437
|
-
|
|
10438
|
-
|
|
10439
|
-
|
|
10440
|
-
|
|
10441
|
-
|
|
10442
|
-
|
|
10443
|
-
|
|
10444
|
-
|
|
10445
|
-
|
|
10446
|
-
|
|
10447
|
-
|
|
10448
|
-
|
|
10449
|
-
|
|
10450
|
-
|
|
10451
|
-
|
|
10452
|
-
|
|
10453
|
-
extraRoots: [process.cwd()]
|
|
10454
|
-
});
|
|
10455
|
-
if (componentHierarchyMap.has(componentName))
|
|
10456
|
-
continue;
|
|
10457
|
-
let sfc = "";
|
|
10458
|
-
try {
|
|
10459
|
-
sfc = fs.readFileSync(absolutePath, "utf8");
|
|
10460
|
-
} catch {
|
|
10461
|
-
continue;
|
|
10462
|
-
}
|
|
10463
|
-
const { descriptor } = parse$1(sfc, { filename: absolutePath });
|
|
10464
|
-
const template = descriptor.template?.content ?? "";
|
|
10465
|
-
if (!template.trim()) {
|
|
10466
|
-
vueFilesPathMap.set(componentName, absolutePath);
|
|
10467
|
-
componentHierarchyMap.set(componentName, {
|
|
10468
|
-
filePath: absolutePath,
|
|
10469
|
-
childrenComponentSet: /* @__PURE__ */ new Set(),
|
|
10470
|
-
usedComponentSet: /* @__PURE__ */ new Set(),
|
|
10471
|
-
dataTestIdSet: /* @__PURE__ */ new Set(),
|
|
10472
|
-
isView: false,
|
|
10473
|
-
methodsContent: ""
|
|
10474
|
-
});
|
|
10475
|
-
supplemented++;
|
|
10476
|
-
continue;
|
|
10477
|
-
}
|
|
10478
|
-
const { bindings: bindingMetadata, isScriptSetup } = getScriptInfo(sfc, absolutePath);
|
|
10479
|
-
vueFilesPathMap.set(componentName, absolutePath);
|
|
10480
|
-
try {
|
|
10481
|
-
compilerDom.compile(template, {
|
|
10482
|
-
filename: absolutePath,
|
|
10483
|
-
prefixIdentifiers: true,
|
|
10484
|
-
inline: isScriptSetup,
|
|
10485
|
-
bindingMetadata,
|
|
10486
|
-
// See dev-plugin.ts — same rationale: enable TS in template
|
|
10487
|
-
// expressions so `(row: RowType) => ...` handlers parse.
|
|
10488
|
-
expressionPlugins: ["typescript"],
|
|
10489
|
-
nodeTransforms: [
|
|
10490
|
-
createTestIdTransform(
|
|
10491
|
-
componentName,
|
|
10492
|
-
componentHierarchyMap,
|
|
10493
|
-
nativeWrappers,
|
|
10494
|
-
skipTestIdGenerationInsideComponents,
|
|
10495
|
-
getViewsDirAbs(),
|
|
10496
|
-
{
|
|
10497
|
-
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
10498
|
-
testIdAttribute,
|
|
10499
|
-
nameCollisionBehavior,
|
|
10500
|
-
missingSemanticNameBehavior,
|
|
10501
|
-
warn: (message) => loggerRef.current.warn(message),
|
|
10502
|
-
vueFilesPathMap,
|
|
10503
|
-
wrapperSearchRoots: getWrapperSearchRoots(),
|
|
10504
|
-
crossFileKeyRegistry,
|
|
10505
|
-
optionKeyAttribute
|
|
10506
|
-
}
|
|
10507
|
-
)
|
|
10508
|
-
]
|
|
10509
|
-
});
|
|
10510
|
-
} catch {
|
|
10538
|
+
const templateCompilerOptions = {
|
|
10539
|
+
...userCompilerOptions,
|
|
10540
|
+
prefixIdentifiers: true,
|
|
10541
|
+
nodeTransforms: [
|
|
10542
|
+
...userNodeTransforms,
|
|
10543
|
+
runtimeNodeTransform
|
|
10544
|
+
]
|
|
10545
|
+
};
|
|
10546
|
+
const collectSource = async (code, cleanPath) => {
|
|
10547
|
+
const componentName = getComponentNameFromPath(cleanPath);
|
|
10548
|
+
loggerRef.current.debug(`Collecting metadata for ${cleanPath} (component: ${componentName})`);
|
|
10549
|
+
const compilerSfc = await import("@vue/compiler-sfc");
|
|
10550
|
+
const parse2 = resolveCompilerSfcParse(compilerSfc);
|
|
10551
|
+
const { descriptor, errors } = parse2(code, { filename: cleanPath });
|
|
10552
|
+
if (errors.length) {
|
|
10553
|
+
throw new Error(`[vue-pom-generator] Cannot parse ${cleanPath}: ${errors.map(String).join("\n")}`);
|
|
10554
|
+
}
|
|
10555
|
+
const script = descriptor.script || descriptor.scriptSetup ? compilerSfc.compileScript(descriptor, { ...vueOptions?.script, id: cleanPath }) : void 0;
|
|
10556
|
+
if (descriptor.template) {
|
|
10557
|
+
const mergedExpressionPlugins = Array.from(
|
|
10558
|
+
/* @__PURE__ */ new Set([
|
|
10559
|
+
"typescript",
|
|
10560
|
+
...userCompilerOptions.expressionPlugins ?? []
|
|
10561
|
+
])
|
|
10562
|
+
);
|
|
10563
|
+
const compiled = compilerSfc.compileTemplate({
|
|
10564
|
+
...userTemplate,
|
|
10565
|
+
id: cleanPath,
|
|
10566
|
+
filename: cleanPath,
|
|
10567
|
+
source: descriptor.template.content,
|
|
10568
|
+
ast: descriptor.template.ast,
|
|
10569
|
+
preprocessLang: descriptor.template.lang,
|
|
10570
|
+
compilerOptions: {
|
|
10571
|
+
...userCompilerOptions,
|
|
10572
|
+
prefixIdentifiers: true,
|
|
10573
|
+
inline: !!descriptor.scriptSetup,
|
|
10574
|
+
bindingMetadata: script?.bindings,
|
|
10575
|
+
expressionPlugins: mergedExpressionPlugins,
|
|
10576
|
+
nodeTransforms: getNodeTransforms(cleanPath, componentName)
|
|
10511
10577
|
}
|
|
10512
|
-
|
|
10578
|
+
});
|
|
10579
|
+
if (compiled.errors.length) {
|
|
10580
|
+
throw new Error(`[vue-pom-generator] Cannot compile ${cleanPath}: ${compiled.errors.map(String).join("\n")}`);
|
|
10513
10581
|
}
|
|
10514
|
-
|
|
10515
|
-
|
|
10516
|
-
|
|
10582
|
+
loggerRef.current.debug(`Metadata collected for ${cleanPath}`);
|
|
10583
|
+
} else {
|
|
10584
|
+
vueFilesPathMap.set(componentName, cleanPath);
|
|
10585
|
+
elementMetadata.delete(componentName);
|
|
10586
|
+
componentHierarchyMap.set(componentName, {
|
|
10587
|
+
filePath: cleanPath,
|
|
10588
|
+
childrenComponentSet: /* @__PURE__ */ new Set(),
|
|
10589
|
+
usedComponentSet: /* @__PURE__ */ new Set(),
|
|
10590
|
+
dataTestIdSet: /* @__PURE__ */ new Set(),
|
|
10591
|
+
isView: false,
|
|
10592
|
+
methodsContent: ""
|
|
10593
|
+
});
|
|
10517
10594
|
}
|
|
10518
10595
|
};
|
|
10519
|
-
|
|
10520
|
-
name: "vue-pom-generator-
|
|
10521
|
-
// This plugin exists to generate code on build output; it is not needed during dev-server HMR.
|
|
10522
|
-
apply: "build",
|
|
10596
|
+
const metadataCollectorPlugin = {
|
|
10597
|
+
name: "vue-pom-generator-metadata-collector",
|
|
10523
10598
|
enforce: "pre",
|
|
10524
|
-
async
|
|
10525
|
-
if (!
|
|
10526
|
-
|
|
10527
|
-
|
|
10528
|
-
|
|
10529
|
-
|
|
10530
|
-
|
|
10531
|
-
|
|
10532
|
-
|
|
10533
|
-
|
|
10534
|
-
|
|
10535
|
-
|
|
10536
|
-
|
|
10537
|
-
|
|
10538
|
-
|
|
10539
|
-
|
|
10540
|
-
|
|
10541
|
-
|
|
10542
|
-
|
|
10543
|
-
|
|
10544
|
-
});
|
|
10545
|
-
}
|
|
10546
|
-
const { routeNameMap, routePathMap } = result;
|
|
10547
|
-
setRouteNameToComponentNameMap(routeNameMap);
|
|
10548
|
-
setResolveToComponentNameFn((to) => {
|
|
10549
|
-
if (typeof to === "string") {
|
|
10550
|
-
return routePathMap.get(to) ?? null;
|
|
10551
|
-
}
|
|
10552
|
-
const maybe = to;
|
|
10553
|
-
if (typeof maybe.name === "string" && maybe.name.length) {
|
|
10554
|
-
const key = toPascalCase(maybe.name);
|
|
10555
|
-
return routeNameMap.get(key) ?? null;
|
|
10556
|
-
}
|
|
10557
|
-
if (typeof maybe.path === "string" && maybe.path.length) {
|
|
10558
|
-
return routePathMap.get(maybe.path) ?? null;
|
|
10559
|
-
}
|
|
10560
|
-
return null;
|
|
10599
|
+
async transform(code, id) {
|
|
10600
|
+
if (!id.endsWith(".vue") || !isFileInScope(id)) return null;
|
|
10601
|
+
await collectSource(code, id);
|
|
10602
|
+
return null;
|
|
10603
|
+
}
|
|
10604
|
+
};
|
|
10605
|
+
const template = {
|
|
10606
|
+
...userTemplate,
|
|
10607
|
+
compilerOptions: templateCompilerOptions
|
|
10608
|
+
};
|
|
10609
|
+
const internalVuePlugin = vue({
|
|
10610
|
+
...vueOptions,
|
|
10611
|
+
template
|
|
10612
|
+
});
|
|
10613
|
+
const nuxtVueBridgePlugin = {
|
|
10614
|
+
name: "vue-pom-generator-nuxt-vue-bridge",
|
|
10615
|
+
apply: "serve",
|
|
10616
|
+
configResolved(config) {
|
|
10617
|
+
const viteVuePlugin = config.plugins.find((plugin) => {
|
|
10618
|
+
return typeof plugin === "object" && plugin !== null && "name" in plugin && plugin.name === "vite:vue" && "api" in plugin;
|
|
10561
10619
|
});
|
|
10562
|
-
|
|
10563
|
-
|
|
10564
|
-
|
|
10565
|
-
this.addWatchFile(basePageClassPath);
|
|
10566
|
-
const pointerPath = path.resolve(path.dirname(basePageClassPath), "pointer.ts");
|
|
10567
|
-
if (!fs.existsSync(pointerPath)) {
|
|
10568
|
-
this.error(`pointer.ts not found at ${pointerPath}. Ensure it is included in the build.`);
|
|
10569
|
-
}
|
|
10570
|
-
this.addWatchFile(pointerPath);
|
|
10571
|
-
const calloutPath = path.resolve(path.dirname(basePageClassPath), "callout.ts");
|
|
10572
|
-
if (!fs.existsSync(calloutPath)) {
|
|
10573
|
-
this.error(`callout.ts not found at ${calloutPath}. Ensure it is included in the build.`);
|
|
10574
|
-
}
|
|
10575
|
-
this.addWatchFile(calloutPath);
|
|
10576
|
-
const floatingUiCalloutPath = path.resolve(path.dirname(basePageClassPath), "floating-ui-callout.ts");
|
|
10577
|
-
if (fs.existsSync(floatingUiCalloutPath)) {
|
|
10578
|
-
this.addWatchFile(floatingUiCalloutPath);
|
|
10579
|
-
}
|
|
10580
|
-
},
|
|
10581
|
-
async buildEnd(error) {
|
|
10582
|
-
if (error) {
|
|
10583
|
-
return;
|
|
10584
|
-
}
|
|
10585
|
-
supplementHierarchyFromFilesystem();
|
|
10586
|
-
const metrics = summarizeHierarchyMap(componentHierarchyMap);
|
|
10587
|
-
if (metrics.dataTestIdCount <= 0) {
|
|
10588
|
-
return;
|
|
10620
|
+
const api = viteVuePlugin?.api;
|
|
10621
|
+
if (!api) {
|
|
10622
|
+
throw new Error("[vue-pom-generator] Nuxt bridge could not find vite:vue plugin to patch.");
|
|
10589
10623
|
}
|
|
10590
|
-
|
|
10624
|
+
const currentOptions = api.options ?? {};
|
|
10625
|
+
const currentTemplate = currentOptions.template ?? {};
|
|
10626
|
+
const currentCompilerOptions = currentTemplate.compilerOptions ?? {};
|
|
10627
|
+
const currentNodeTransforms = currentCompilerOptions.nodeTransforms ?? [];
|
|
10628
|
+
if (currentNodeTransforms.includes(runtimeNodeTransform)) {
|
|
10591
10629
|
return;
|
|
10592
10630
|
}
|
|
10593
|
-
|
|
10594
|
-
|
|
10595
|
-
|
|
10596
|
-
|
|
10597
|
-
|
|
10598
|
-
|
|
10599
|
-
|
|
10600
|
-
|
|
10601
|
-
|
|
10602
|
-
|
|
10603
|
-
|
|
10604
|
-
|
|
10605
|
-
|
|
10606
|
-
|
|
10607
|
-
vueRouterFluentChaining: routerAwarePoms,
|
|
10608
|
-
routerEntry: getResolvedRouterEntry(),
|
|
10609
|
-
routerType,
|
|
10610
|
-
pageDirs: getPageDirs(),
|
|
10611
|
-
componentDirs: getComponentDirs(),
|
|
10612
|
-
layoutDirs: getLayoutDirs(),
|
|
10613
|
-
elementMetadata
|
|
10614
|
-
});
|
|
10615
|
-
lastGeneratedMetrics = metrics;
|
|
10616
|
-
loggerRef.current.info(`generated POMs (${metrics.entryCount} entries, ${metrics.interactiveComponentCount} interactive components, ${metrics.dataTestIdCount} selectors)`);
|
|
10617
|
-
},
|
|
10618
|
-
closeBundle() {
|
|
10619
|
-
loggerRef.current.info("build complete");
|
|
10631
|
+
api.options = {
|
|
10632
|
+
...currentOptions,
|
|
10633
|
+
template: {
|
|
10634
|
+
...currentTemplate,
|
|
10635
|
+
compilerOptions: {
|
|
10636
|
+
...currentCompilerOptions,
|
|
10637
|
+
prefixIdentifiers: true,
|
|
10638
|
+
nodeTransforms: [
|
|
10639
|
+
...currentNodeTransforms,
|
|
10640
|
+
runtimeNodeTransform
|
|
10641
|
+
]
|
|
10642
|
+
}
|
|
10643
|
+
}
|
|
10644
|
+
};
|
|
10620
10645
|
}
|
|
10621
10646
|
};
|
|
10647
|
+
return { metadataCollectorPlugin, internalVuePlugin, nuxtVueBridgePlugin, templateCompilerOptions, collectSource };
|
|
10622
10648
|
}
|
|
10623
10649
|
function createDevProcessorPlugin(options) {
|
|
10624
10650
|
const {
|
|
@@ -11196,7 +11222,6 @@ ${code}`,
|
|
|
11196
11222
|
function createInternalPlugins(options) {
|
|
11197
11223
|
const {
|
|
11198
11224
|
componentHierarchyMap,
|
|
11199
|
-
crossFileKeyRegistry,
|
|
11200
11225
|
elementMetadata,
|
|
11201
11226
|
vueFilesPathMap,
|
|
11202
11227
|
nativeWrappers,
|
|
@@ -11212,7 +11237,9 @@ function createInternalPlugins(options) {
|
|
|
11212
11237
|
projectRootRef,
|
|
11213
11238
|
basePageClassPath: basePageClassPathOverride,
|
|
11214
11239
|
loggerRef,
|
|
11215
|
-
annotatorRuntime
|
|
11240
|
+
annotatorRuntime,
|
|
11241
|
+
collectSource,
|
|
11242
|
+
generationOnly
|
|
11216
11243
|
} = options;
|
|
11217
11244
|
const {
|
|
11218
11245
|
routerAwarePoms,
|
|
@@ -11240,7 +11267,6 @@ function createInternalPlugins(options) {
|
|
|
11240
11267
|
const tsProcessor = createBuildProcessorPlugin({
|
|
11241
11268
|
componentHierarchyMap,
|
|
11242
11269
|
elementMetadata,
|
|
11243
|
-
crossFileKeyRegistry,
|
|
11244
11270
|
vueFilesPathMap,
|
|
11245
11271
|
getPageDirs,
|
|
11246
11272
|
getComponentDirs,
|
|
@@ -11251,10 +11277,8 @@ function createInternalPlugins(options) {
|
|
|
11251
11277
|
normalizedBasePagePath,
|
|
11252
11278
|
generation,
|
|
11253
11279
|
projectRootRef,
|
|
11254
|
-
|
|
11255
|
-
|
|
11256
|
-
skipTestIdGenerationInsideComponents,
|
|
11257
|
-
getWrapperSearchRoots,
|
|
11280
|
+
collectSource,
|
|
11281
|
+
generationOnly,
|
|
11258
11282
|
getResolvedRouterEntry: resolveRouterEntry2,
|
|
11259
11283
|
loggerRef
|
|
11260
11284
|
});
|
|
@@ -11416,16 +11440,19 @@ const sharedGeneratorStateRegistry = /* @__PURE__ */ new Map();
|
|
|
11416
11440
|
function toArray(value) {
|
|
11417
11441
|
return Array.isArray(value) ? value : [];
|
|
11418
11442
|
}
|
|
11443
|
+
function createGeneratorState() {
|
|
11444
|
+
return {
|
|
11445
|
+
elementMetadata: /* @__PURE__ */ new Map(),
|
|
11446
|
+
semanticNameMap: /* @__PURE__ */ new Map(),
|
|
11447
|
+
componentHierarchyMap: /* @__PURE__ */ new Map(),
|
|
11448
|
+
crossFileKeyRegistry: /* @__PURE__ */ new Map(),
|
|
11449
|
+
vueFilesPathMap: /* @__PURE__ */ new Map()
|
|
11450
|
+
};
|
|
11451
|
+
}
|
|
11419
11452
|
function getSharedGeneratorState(key) {
|
|
11420
11453
|
let state = sharedGeneratorStateRegistry.get(key);
|
|
11421
11454
|
if (!state) {
|
|
11422
|
-
state =
|
|
11423
|
-
elementMetadata: /* @__PURE__ */ new Map(),
|
|
11424
|
-
semanticNameMap: /* @__PURE__ */ new Map(),
|
|
11425
|
-
componentHierarchyMap: /* @__PURE__ */ new Map(),
|
|
11426
|
-
crossFileKeyRegistry: /* @__PURE__ */ new Map(),
|
|
11427
|
-
vueFilesPathMap: /* @__PURE__ */ new Map()
|
|
11428
|
-
};
|
|
11455
|
+
state = createGeneratorState();
|
|
11429
11456
|
sharedGeneratorStateRegistry.set(key, state);
|
|
11430
11457
|
}
|
|
11431
11458
|
return state;
|
|
@@ -11486,9 +11513,15 @@ function assertNotVitePluginInstance(options) {
|
|
|
11486
11513
|
);
|
|
11487
11514
|
}
|
|
11488
11515
|
function createVuePomGeneratorPlugins(options = {}) {
|
|
11516
|
+
return createGeneratorPlugins(options, false);
|
|
11517
|
+
}
|
|
11518
|
+
function createGeneratorPlugins(options, generationOnly, projectRoot = process.cwd()) {
|
|
11489
11519
|
assertNotVitePluginInstance(options);
|
|
11490
11520
|
const injection = options.injection ?? {};
|
|
11491
|
-
const isNuxt = detectNuxtProject(options,
|
|
11521
|
+
const isNuxt = detectNuxtProject(options, projectRoot);
|
|
11522
|
+
if (generationOnly && isNuxt) {
|
|
11523
|
+
throw new Error("[vue-pom-generator] generateVuePoms does not run Nuxt project preparation. Use the Nuxt Vite integration.");
|
|
11524
|
+
}
|
|
11492
11525
|
const generationSetting = options.generation;
|
|
11493
11526
|
const generationOptions = generationSetting === false ? null : generationSetting ?? {};
|
|
11494
11527
|
const generationEnabled = generationOptions !== null;
|
|
@@ -11574,7 +11607,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
11574
11607
|
]));
|
|
11575
11608
|
const getWrapperSearchRoots = () => resolvedInjectionOptionsRef.current.wrapperSearchRoots;
|
|
11576
11609
|
const sharedStateKey = JSON.stringify({
|
|
11577
|
-
cwd:
|
|
11610
|
+
cwd: projectRoot,
|
|
11578
11611
|
mode: isNuxt ? "nuxt" : "vue",
|
|
11579
11612
|
pageDirs: isNuxt ? null : getPageDirs(),
|
|
11580
11613
|
componentDirs: isNuxt ? null : getComponentDirs(),
|
|
@@ -11586,9 +11619,9 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
11586
11619
|
routerType: resolvedGenerationOptions.routerType,
|
|
11587
11620
|
vuePluginOwnership
|
|
11588
11621
|
});
|
|
11589
|
-
const sharedState = getSharedGeneratorState(sharedStateKey);
|
|
11622
|
+
const sharedState = generationOnly ? createGeneratorState() : getSharedGeneratorState(sharedStateKey);
|
|
11590
11623
|
let templateCompilerOptionsForResolvedPlugin;
|
|
11591
|
-
const projectRootRef = { current:
|
|
11624
|
+
const projectRootRef = { current: projectRoot };
|
|
11592
11625
|
const loggerRef = {
|
|
11593
11626
|
current: createLogger({ verbosity })
|
|
11594
11627
|
};
|
|
@@ -11652,7 +11685,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
11652
11685
|
...getWrapperSearchRoots()
|
|
11653
11686
|
].map((root) => resolveFromProjectRoot(projectRootRef.current, root))));
|
|
11654
11687
|
const { elementMetadata, semanticNameMap, componentHierarchyMap, crossFileKeyRegistry, vueFilesPathMap } = sharedState;
|
|
11655
|
-
const { metadataCollectorPlugin, internalVuePlugin, templateCompilerOptions } = createVuePluginWithTestIds({
|
|
11688
|
+
const { metadataCollectorPlugin, internalVuePlugin, templateCompilerOptions, collectSource } = createVuePluginWithTestIds({
|
|
11656
11689
|
vueOptions,
|
|
11657
11690
|
existingIdBehavior: resolvedGenerationOptions.existingIdBehavior,
|
|
11658
11691
|
nameCollisionBehavior: resolvedGenerationOptions.nameCollisionBehavior,
|
|
@@ -11680,7 +11713,6 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
11680
11713
|
templateCompilerOptionsForResolvedPlugin = templateCompilerOptions;
|
|
11681
11714
|
const internalPlugins = createInternalPlugins({
|
|
11682
11715
|
componentHierarchyMap,
|
|
11683
|
-
crossFileKeyRegistry,
|
|
11684
11716
|
elementMetadata,
|
|
11685
11717
|
vueFilesPathMap,
|
|
11686
11718
|
nativeWrappers,
|
|
@@ -11693,6 +11725,8 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
11693
11725
|
getSourceDirs,
|
|
11694
11726
|
getWrapperSearchRoots: getWrapperSearchRootsAbs,
|
|
11695
11727
|
generation: resolvedGenerationOptions,
|
|
11728
|
+
collectSource,
|
|
11729
|
+
generationOnly,
|
|
11696
11730
|
projectRootRef,
|
|
11697
11731
|
basePageClassPath: basePageClassPathOverride,
|
|
11698
11732
|
loggerRef,
|
|
@@ -13113,6 +13147,44 @@ function mountAnnotatorClient(options) {
|
|
|
13113
13147
|
runtimeWindow[RUNTIME_GUARD] = runtime;
|
|
13114
13148
|
return runtime;
|
|
13115
13149
|
}
|
|
13150
|
+
let generating = false;
|
|
13151
|
+
async function generateVuePoms(options = {}, viteOptions = {}) {
|
|
13152
|
+
if (options.generation === false) {
|
|
13153
|
+
throw new Error("[vue-pom-generator] generateVuePoms requires generation to be enabled.");
|
|
13154
|
+
}
|
|
13155
|
+
const entryId = "virtual:vue-pom-generator-entry";
|
|
13156
|
+
const resolvedEntryId = `\0${entryId}`;
|
|
13157
|
+
const entry = {
|
|
13158
|
+
name: "vue-pom-generator-entry",
|
|
13159
|
+
resolveId(id) {
|
|
13160
|
+
return id === entryId ? resolvedEntryId : void 0;
|
|
13161
|
+
},
|
|
13162
|
+
load(id) {
|
|
13163
|
+
return id === resolvedEntryId ? "export {};" : void 0;
|
|
13164
|
+
}
|
|
13165
|
+
};
|
|
13166
|
+
if (generating) {
|
|
13167
|
+
throw new Error("[vue-pom-generator] Await the previous generateVuePoms call before starting another.");
|
|
13168
|
+
}
|
|
13169
|
+
generating = true;
|
|
13170
|
+
try {
|
|
13171
|
+
const { build } = await import("vite");
|
|
13172
|
+
await build({
|
|
13173
|
+
...viteOptions,
|
|
13174
|
+
configFile: false,
|
|
13175
|
+
publicDir: false,
|
|
13176
|
+
plugins: [entry, ...createGeneratorPlugins(options, true, path.resolve(viteOptions.root ?? ".")), ...viteOptions.plugins ?? []],
|
|
13177
|
+
build: {
|
|
13178
|
+
write: false,
|
|
13179
|
+
emptyOutDir: false,
|
|
13180
|
+
minify: false,
|
|
13181
|
+
rollupOptions: { input: entryId }
|
|
13182
|
+
}
|
|
13183
|
+
});
|
|
13184
|
+
} finally {
|
|
13185
|
+
generating = false;
|
|
13186
|
+
}
|
|
13187
|
+
}
|
|
13116
13188
|
const nuxtConfigMarker = /* @__PURE__ */ Symbol.for("@immense/vue-pom-generator.nuxt");
|
|
13117
13189
|
function defineVuePomGeneratorConfig(options) {
|
|
13118
13190
|
return options;
|
|
@@ -13130,6 +13202,7 @@ export {
|
|
|
13130
13202
|
createVuePomGeneratorPlugins as default,
|
|
13131
13203
|
defineNuxtPomGeneratorConfig,
|
|
13132
13204
|
defineVuePomGeneratorConfig,
|
|
13205
|
+
generateVuePoms,
|
|
13133
13206
|
mountAnnotatorClient,
|
|
13134
13207
|
createVuePomGeneratorPlugins as vuePomGenerator
|
|
13135
13208
|
};
|