@immense/vue-pom-generator 1.0.105 → 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 +71 -31
- package/class-generation/index.ts +12 -40
- package/dist/class-generation/index.d.ts.map +1 -1
- package/dist/eslint/index.cjs +78 -4
- 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 +78 -4
- package/dist/eslint/index.mjs.map +1 -1
- package/dist/eslint/no-page-goto-in-specs.d.ts +10 -0
- package/dist/eslint/no-page-goto-in-specs.d.ts.map +1 -0
- 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.cjs
CHANGED
|
@@ -27,15 +27,16 @@ const path = require("node:path");
|
|
|
27
27
|
const process = require("node:process");
|
|
28
28
|
const node_module = require("node:module");
|
|
29
29
|
const node_url = require("node:url");
|
|
30
|
-
const compilerDom = require("@vue/compiler-dom");
|
|
31
|
-
const compilerSfc = require("@vue/compiler-sfc");
|
|
32
30
|
const parser = require("@babel/parser");
|
|
33
31
|
const compilerCore = require("@vue/compiler-core");
|
|
32
|
+
const compilerDom = require("@vue/compiler-dom");
|
|
33
|
+
const compilerSfc = require("@vue/compiler-sfc");
|
|
34
34
|
const tsMorph = require("ts-morph");
|
|
35
35
|
const types = require("@babel/types");
|
|
36
|
+
const node_crypto = require("node:crypto");
|
|
36
37
|
const router = require("./router.cjs");
|
|
37
|
-
const vue = require("@vitejs/plugin-vue");
|
|
38
38
|
const node_perf_hooks = require("node:perf_hooks");
|
|
39
|
+
const vue = require("@vitejs/plugin-vue");
|
|
39
40
|
const dom = require("@floating-ui/dom");
|
|
40
41
|
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
41
42
|
function _interopNamespaceDefault(e) {
|
|
@@ -4031,6 +4032,104 @@ function generatePomManifestModule(componentHierarchyMap, elementMetadata, fileN
|
|
|
4031
4032
|
});
|
|
4032
4033
|
});
|
|
4033
4034
|
}
|
|
4035
|
+
const manifestName = ".vue-pom-generator-outputs.json";
|
|
4036
|
+
function hash(content) {
|
|
4037
|
+
return node_crypto.createHash("sha256").update(content).digest("hex");
|
|
4038
|
+
}
|
|
4039
|
+
function readManifest(filePath) {
|
|
4040
|
+
if (!fs.existsSync(filePath)) {
|
|
4041
|
+
return { version: 1, files: {} };
|
|
4042
|
+
}
|
|
4043
|
+
const value = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
4044
|
+
if (!value || typeof value !== "object" || !("version" in value) || value.version !== 1 || !("files" in value) || !value.files || typeof value.files !== "object" || Array.isArray(value.files)) {
|
|
4045
|
+
throw new Error(`[vue-pom-generator] Invalid output ownership manifest: ${filePath}`);
|
|
4046
|
+
}
|
|
4047
|
+
for (const [name, digest] of Object.entries(value.files)) {
|
|
4048
|
+
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))) {
|
|
4049
|
+
throw new Error(`[vue-pom-generator] Invalid output ownership entry in ${filePath}: ${name}`);
|
|
4050
|
+
}
|
|
4051
|
+
}
|
|
4052
|
+
return value;
|
|
4053
|
+
}
|
|
4054
|
+
function assertRegularFile(filePath) {
|
|
4055
|
+
const entry = fs.lstatSync(filePath, { throwIfNoEntry: false });
|
|
4056
|
+
if (entry && !entry.isFile()) {
|
|
4057
|
+
throw new Error(`[vue-pom-generator] Refusing to replace or remove a non-regular output file: ${filePath}`);
|
|
4058
|
+
}
|
|
4059
|
+
}
|
|
4060
|
+
function assertNoSymlinkParents(filePath, outDir, projectRoot) {
|
|
4061
|
+
const relativeOutput = path.relative(projectRoot, outDir);
|
|
4062
|
+
let ancestor = relativeOutput === ".." || relativeOutput.startsWith(`..${path.sep}`) || path.isAbsolute(relativeOutput) ? path.dirname(outDir) : projectRoot;
|
|
4063
|
+
const targetDirectory = path.dirname(filePath);
|
|
4064
|
+
while (path.relative(ancestor, targetDirectory) === ".." || path.relative(ancestor, targetDirectory).startsWith(`..${path.sep}`) || path.isAbsolute(path.relative(ancestor, targetDirectory))) {
|
|
4065
|
+
const parent = path.dirname(ancestor);
|
|
4066
|
+
if (parent === ancestor) {
|
|
4067
|
+
throw new Error(`[vue-pom-generator] Output must be on the same filesystem volume as its manifest: ${filePath}`);
|
|
4068
|
+
}
|
|
4069
|
+
ancestor = parent;
|
|
4070
|
+
}
|
|
4071
|
+
for (const target of [path.dirname(filePath), outDir]) {
|
|
4072
|
+
let directory = target;
|
|
4073
|
+
while (directory !== ancestor) {
|
|
4074
|
+
if (fs.lstatSync(directory, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
4075
|
+
throw new Error(`[vue-pom-generator] Refusing to follow an output directory symlink: ${directory}`);
|
|
4076
|
+
}
|
|
4077
|
+
directory = path.dirname(directory);
|
|
4078
|
+
}
|
|
4079
|
+
}
|
|
4080
|
+
}
|
|
4081
|
+
function writeFile(filePath, content) {
|
|
4082
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
4083
|
+
const temporaryPath = `${filePath}.${node_crypto.randomUUID()}.tmp`;
|
|
4084
|
+
try {
|
|
4085
|
+
fs.writeFileSync(temporaryPath, content, { flag: "wx" });
|
|
4086
|
+
fs.renameSync(temporaryPath, filePath);
|
|
4087
|
+
} finally {
|
|
4088
|
+
if (fs.existsSync(temporaryPath)) {
|
|
4089
|
+
fs.unlinkSync(temporaryPath);
|
|
4090
|
+
}
|
|
4091
|
+
}
|
|
4092
|
+
}
|
|
4093
|
+
function writeGeneratedOutputs(outDir, files, sharedFiles, projectRoot = path.dirname(path.resolve(outDir))) {
|
|
4094
|
+
const root = path.resolve(outDir);
|
|
4095
|
+
const manifestPath = path.join(root, manifestName);
|
|
4096
|
+
assertNoSymlinkParents(manifestPath, root, projectRoot);
|
|
4097
|
+
assertRegularFile(manifestPath);
|
|
4098
|
+
const previous = readManifest(manifestPath);
|
|
4099
|
+
const next = { version: 1, files: {} };
|
|
4100
|
+
const contents = /* @__PURE__ */ new Map();
|
|
4101
|
+
for (const file of files) {
|
|
4102
|
+
const absolutePath = path.resolve(file.filePath);
|
|
4103
|
+
if (contents.has(absolutePath) || absolutePath === manifestPath) {
|
|
4104
|
+
throw new Error(`[vue-pom-generator] Duplicate generated output: ${absolutePath}`);
|
|
4105
|
+
}
|
|
4106
|
+
contents.set(absolutePath, file.content);
|
|
4107
|
+
next.files[path.relative(root, absolutePath).split(path.sep).join("/")] = hash(file.content);
|
|
4108
|
+
}
|
|
4109
|
+
const obsolete = [];
|
|
4110
|
+
for (const [name, digest] of Object.entries(previous.files)) {
|
|
4111
|
+
const absolutePath = path.resolve(root, name);
|
|
4112
|
+
if (contents.has(absolutePath)) continue;
|
|
4113
|
+
assertNoSymlinkParents(absolutePath, root, projectRoot);
|
|
4114
|
+
assertRegularFile(absolutePath);
|
|
4115
|
+
if (!fs.existsSync(absolutePath)) continue;
|
|
4116
|
+
if (hash(fs.readFileSync(absolutePath, "utf8")) !== digest) {
|
|
4117
|
+
throw new Error(`[vue-pom-generator] Obsolete generated file was modified; move or remove it explicitly before regenerating: ${absolutePath}`);
|
|
4118
|
+
}
|
|
4119
|
+
obsolete.push(absolutePath);
|
|
4120
|
+
}
|
|
4121
|
+
for (const file of sharedFiles) {
|
|
4122
|
+
contents.set(path.resolve(file.filePath), file.content);
|
|
4123
|
+
}
|
|
4124
|
+
for (const filePath of contents.keys()) {
|
|
4125
|
+
assertNoSymlinkParents(filePath, root, projectRoot);
|
|
4126
|
+
assertRegularFile(filePath);
|
|
4127
|
+
}
|
|
4128
|
+
for (const [filePath, content] of contents) writeFile(filePath, content);
|
|
4129
|
+
for (const filePath of obsolete) fs.unlinkSync(filePath);
|
|
4130
|
+
writeFile(manifestPath, `${JSON.stringify(next, null, 2)}
|
|
4131
|
+
`);
|
|
4132
|
+
}
|
|
4034
4133
|
function safeRealpath(value) {
|
|
4035
4134
|
try {
|
|
4036
4135
|
if (fs.existsSync(value)) {
|
|
@@ -5792,7 +5891,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5792
5891
|
const {
|
|
5793
5892
|
outDir: outDirOverride,
|
|
5794
5893
|
generateFixtures,
|
|
5795
|
-
vueTestUtilsOutDir,
|
|
5894
|
+
vueTestUtilsOutDir: vueTestUtilsOutDirOverride,
|
|
5796
5895
|
customPomAttachments = [],
|
|
5797
5896
|
projectRoot,
|
|
5798
5897
|
customPomDir,
|
|
@@ -5813,7 +5912,9 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5813
5912
|
elementMetadata = /* @__PURE__ */ new Map()
|
|
5814
5913
|
} = options;
|
|
5815
5914
|
const emitLanguages = emitLanguagesOverride?.length ? emitLanguagesOverride : ["ts"];
|
|
5816
|
-
const
|
|
5915
|
+
const root = projectRoot ?? process.cwd();
|
|
5916
|
+
const outDir = path.resolve(root, outDirOverride ?? "./pom");
|
|
5917
|
+
const vueTestUtilsOutDir = vueTestUtilsOutDirOverride ? path.resolve(root, vueTestUtilsOutDirOverride) : void 0;
|
|
5817
5918
|
if (vueTestUtilsOutDir && path.resolve(vueTestUtilsOutDir) === path.resolve(outDir)) {
|
|
5818
5919
|
throw new Error("[vue-pom-generator] generation.vueTestUtils.outDir must differ from generation.outDir.");
|
|
5819
5920
|
}
|
|
@@ -5823,12 +5924,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5823
5924
|
layoutDirs
|
|
5824
5925
|
}) : void 0);
|
|
5825
5926
|
const emittableComponentHierarchyMap = componentHierarchyMap;
|
|
5826
|
-
const
|
|
5827
|
-
const writeGeneratedFile = (file) => {
|
|
5828
|
-
const resolvedFilePath = path.resolve(file.filePath);
|
|
5829
|
-
createFile(resolvedFilePath, file.content);
|
|
5830
|
-
generatedFilePaths.push(resolvedFilePath);
|
|
5831
|
-
};
|
|
5927
|
+
const generatedFiles = [];
|
|
5832
5928
|
if (emitLanguages.includes("ts")) {
|
|
5833
5929
|
const files = typescriptOutputStructure === "split" ? await generateSplitTypeScriptFiles(emittableComponentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, {
|
|
5834
5930
|
customPomAttachments,
|
|
@@ -5851,9 +5947,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5851
5947
|
routeMetaByComponent,
|
|
5852
5948
|
vueRouterFluentChaining
|
|
5853
5949
|
});
|
|
5854
|
-
|
|
5855
|
-
writeGeneratedFile(file);
|
|
5856
|
-
}
|
|
5950
|
+
generatedFiles.push(...files);
|
|
5857
5951
|
const fixtureRegistryFiles = maybeGenerateFixtureRegistry(emittableComponentHierarchyMap, {
|
|
5858
5952
|
generateFixtures,
|
|
5859
5953
|
pomOutDir: outDir,
|
|
@@ -5862,18 +5956,14 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5862
5956
|
elementMetadata,
|
|
5863
5957
|
testIdAttribute
|
|
5864
5958
|
});
|
|
5865
|
-
|
|
5866
|
-
writeGeneratedFile(fixtureRegistryFile);
|
|
5867
|
-
}
|
|
5959
|
+
generatedFiles.push(...fixtureRegistryFiles);
|
|
5868
5960
|
}
|
|
5869
5961
|
if (emitLanguages.includes("csharp")) {
|
|
5870
5962
|
const csFiles = generateAggregatedCSharpFiles(emittableComponentHierarchyMap, outDir, {
|
|
5871
5963
|
testIdAttribute,
|
|
5872
5964
|
csharp
|
|
5873
5965
|
});
|
|
5874
|
-
|
|
5875
|
-
writeGeneratedFile(file);
|
|
5876
|
-
}
|
|
5966
|
+
generatedFiles.push(...csFiles);
|
|
5877
5967
|
}
|
|
5878
5968
|
if (vueTestUtilsOutDir) {
|
|
5879
5969
|
const vueTestUtilsFiles = generateVueTestUtilsFiles(
|
|
@@ -5881,14 +5971,10 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5881
5971
|
vueTestUtilsOutDir,
|
|
5882
5972
|
{ testIdAttribute }
|
|
5883
5973
|
);
|
|
5884
|
-
|
|
5885
|
-
writeGeneratedFile(file);
|
|
5886
|
-
}
|
|
5887
|
-
}
|
|
5888
|
-
const gitattributesFiles = buildGeneratedGitAttributesFiles(generatedFilePaths);
|
|
5889
|
-
for (const file of gitattributesFiles) {
|
|
5890
|
-
createFile(file.filePath, file.content);
|
|
5974
|
+
generatedFiles.push(...vueTestUtilsFiles);
|
|
5891
5975
|
}
|
|
5976
|
+
const gitattributesFiles = buildGeneratedGitAttributesFiles(generatedFiles.map((file) => file.filePath));
|
|
5977
|
+
writeGeneratedOutputs(outDir, generatedFiles, gitattributesFiles, path.resolve(root));
|
|
5892
5978
|
}
|
|
5893
5979
|
const VUE_TEST_UTILS_OMITTED_PARAMETERS = /* @__PURE__ */ new Set(["annotationText", "timeOut", "timeout", "wait"]);
|
|
5894
5980
|
function getVueTestUtilsParameters(parameters, patterns, options = {}) {
|
|
@@ -7875,16 +7961,6 @@ async function generateAggregatedFiles(componentHierarchyMap, vueFilesPathMap, b
|
|
|
7875
7961
|
...runtimeFiles
|
|
7876
7962
|
];
|
|
7877
7963
|
}
|
|
7878
|
-
function createFile(filePath, content) {
|
|
7879
|
-
const dir = path.dirname(filePath);
|
|
7880
|
-
if (!fs.existsSync(dir)) {
|
|
7881
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
7882
|
-
}
|
|
7883
|
-
if (fs.existsSync(filePath)) {
|
|
7884
|
-
fs.unlinkSync(filePath);
|
|
7885
|
-
}
|
|
7886
|
-
fs.writeFileSync(filePath, content);
|
|
7887
|
-
}
|
|
7888
7964
|
function lowerFirst(value) {
|
|
7889
7965
|
if (!value)
|
|
7890
7966
|
return value;
|
|
@@ -8048,130 +8124,353 @@ function getConstructor(componentInstances, attachmentsForThisView = [], widgetI
|
|
|
8048
8124
|
}
|
|
8049
8125
|
});
|
|
8050
8126
|
}
|
|
8051
|
-
|
|
8052
|
-
|
|
8053
|
-
|
|
8054
|
-
|
|
8055
|
-
|
|
8056
|
-
|
|
8057
|
-
|
|
8058
|
-
|
|
8059
|
-
}
|
|
8060
|
-
function isAsciiDigitCode(code) {
|
|
8061
|
-
return code >= 48 && code <= 57;
|
|
8062
|
-
}
|
|
8063
|
-
function toKebabCaseTag(tag) {
|
|
8064
|
-
let result = "";
|
|
8065
|
-
let previousWasSeparator = false;
|
|
8066
|
-
for (let i = 0; i < tag.length; i += 1) {
|
|
8067
|
-
const ch = tag[i];
|
|
8068
|
-
const code = ch.charCodeAt(0);
|
|
8069
|
-
if (ch === "_" || ch === "-" || ch === "." || ch === " " || ch === " " || ch === "\n" || ch === "\r") {
|
|
8070
|
-
if (result && !previousWasSeparator) {
|
|
8071
|
-
result += "-";
|
|
8072
|
-
}
|
|
8073
|
-
previousWasSeparator = true;
|
|
8074
|
-
continue;
|
|
8075
|
-
}
|
|
8076
|
-
const previous = i > 0 ? tag[i - 1] : "";
|
|
8077
|
-
const previousCode = previous ? previous.charCodeAt(0) : 0;
|
|
8078
|
-
const shouldInsertSeparator = i > 0 && isAsciiUppercaseLetterCode(code) && (isAsciiLetterCode(previousCode) || isAsciiDigitCode(previousCode)) && !previousWasSeparator;
|
|
8079
|
-
if (shouldInsertSeparator) {
|
|
8080
|
-
result += "-";
|
|
8127
|
+
function summarizeHierarchyMap(componentHierarchyMap) {
|
|
8128
|
+
let interactiveComponentCount = 0;
|
|
8129
|
+
let dataTestIdCount = 0;
|
|
8130
|
+
for (const dependencies of componentHierarchyMap.values()) {
|
|
8131
|
+
const selectorCount = dependencies.dataTestIdSet?.size ?? 0;
|
|
8132
|
+
if (selectorCount > 0) {
|
|
8133
|
+
interactiveComponentCount += 1;
|
|
8134
|
+
dataTestIdCount += selectorCount;
|
|
8081
8135
|
}
|
|
8082
|
-
result += ch.toLowerCase();
|
|
8083
|
-
previousWasSeparator = false;
|
|
8084
8136
|
}
|
|
8085
|
-
return
|
|
8137
|
+
return {
|
|
8138
|
+
entryCount: componentHierarchyMap.size,
|
|
8139
|
+
interactiveComponentCount,
|
|
8140
|
+
dataTestIdCount
|
|
8141
|
+
};
|
|
8086
8142
|
}
|
|
8087
|
-
function
|
|
8088
|
-
|
|
8089
|
-
|
|
8090
|
-
const resolved = path.resolve(root);
|
|
8091
|
-
try {
|
|
8092
|
-
if (!fs.existsSync(resolved) || !fs.statSync(resolved).isDirectory()) {
|
|
8093
|
-
continue;
|
|
8094
|
-
}
|
|
8095
|
-
normalized.add(path.normalize(fs.realpathSync(resolved)));
|
|
8096
|
-
} catch {
|
|
8097
|
-
continue;
|
|
8098
|
-
}
|
|
8143
|
+
function isLessRich(candidate, previous) {
|
|
8144
|
+
if (candidate.dataTestIdCount !== previous.dataTestIdCount) {
|
|
8145
|
+
return candidate.dataTestIdCount < previous.dataTestIdCount;
|
|
8099
8146
|
}
|
|
8100
|
-
|
|
8101
|
-
|
|
8102
|
-
function buildSearchRootsKey(searchRoots) {
|
|
8103
|
-
return searchRoots.join("\n");
|
|
8104
|
-
}
|
|
8105
|
-
function buildVueSfcPathIndex(searchRoots) {
|
|
8106
|
-
const indexKey = buildSearchRootsKey(searchRoots);
|
|
8107
|
-
const existingIndex = indexedVueSfcPathsByRoots.get(indexKey);
|
|
8108
|
-
if (existingIndex) {
|
|
8109
|
-
return existingIndex;
|
|
8147
|
+
if (candidate.interactiveComponentCount !== previous.interactiveComponentCount) {
|
|
8148
|
+
return candidate.interactiveComponentCount < previous.interactiveComponentCount;
|
|
8110
8149
|
}
|
|
8111
|
-
|
|
8112
|
-
|
|
8113
|
-
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
|
|
8121
|
-
|
|
8122
|
-
|
|
8123
|
-
|
|
8124
|
-
|
|
8125
|
-
|
|
8126
|
-
|
|
8127
|
-
|
|
8128
|
-
|
|
8129
|
-
|
|
8130
|
-
|
|
8131
|
-
|
|
8132
|
-
|
|
8133
|
-
|
|
8134
|
-
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
|
|
8141
|
-
|
|
8142
|
-
|
|
8143
|
-
|
|
8144
|
-
|
|
8145
|
-
|
|
8146
|
-
|
|
8150
|
+
return candidate.entryCount < previous.entryCount;
|
|
8151
|
+
}
|
|
8152
|
+
function createBuildProcessorPlugin(options) {
|
|
8153
|
+
const {
|
|
8154
|
+
componentHierarchyMap,
|
|
8155
|
+
elementMetadata,
|
|
8156
|
+
vueFilesPathMap,
|
|
8157
|
+
getPageDirs,
|
|
8158
|
+
getComponentDirs,
|
|
8159
|
+
getLayoutDirs,
|
|
8160
|
+
getViewsDir,
|
|
8161
|
+
getSourceDirs,
|
|
8162
|
+
basePageClassPath,
|
|
8163
|
+
normalizedBasePagePath,
|
|
8164
|
+
generation,
|
|
8165
|
+
projectRootRef,
|
|
8166
|
+
collectSource,
|
|
8167
|
+
generationOnly,
|
|
8168
|
+
getResolvedRouterEntry,
|
|
8169
|
+
loggerRef
|
|
8170
|
+
} = options;
|
|
8171
|
+
const {
|
|
8172
|
+
outDir,
|
|
8173
|
+
emitLanguages,
|
|
8174
|
+
typescriptOutputStructure,
|
|
8175
|
+
csharp,
|
|
8176
|
+
generateFixtures,
|
|
8177
|
+
vueTestUtilsOutDir,
|
|
8178
|
+
customPomAttachments,
|
|
8179
|
+
customPomDir,
|
|
8180
|
+
requireCustomPomDir,
|
|
8181
|
+
customPomImportAliases,
|
|
8182
|
+
customPomImportNameCollisionBehavior,
|
|
8183
|
+
testIdAttribute,
|
|
8184
|
+
routerAwarePoms,
|
|
8185
|
+
routerType,
|
|
8186
|
+
routerModuleShims
|
|
8187
|
+
} = generation;
|
|
8188
|
+
let lastGeneratedMetrics = {
|
|
8189
|
+
entryCount: 0,
|
|
8190
|
+
interactiveComponentCount: 0,
|
|
8191
|
+
dataTestIdCount: 0
|
|
8192
|
+
};
|
|
8193
|
+
const getViewsDirAbs = () => path.isAbsolute(getViewsDir()) ? getViewsDir() : path.resolve(projectRootRef.current, getViewsDir());
|
|
8194
|
+
const getPageDirsAbs = () => getPageDirs().map((dir) => path.isAbsolute(dir) ? dir : path.resolve(projectRootRef.current, dir));
|
|
8195
|
+
const supplementHierarchyFromFilesystem = async () => {
|
|
8196
|
+
const walkFilesRecursive = (rootDir) => {
|
|
8197
|
+
const out = [];
|
|
8198
|
+
const stack = [rootDir];
|
|
8199
|
+
while (stack.length) {
|
|
8200
|
+
const dir = stack.pop();
|
|
8201
|
+
if (!dir) continue;
|
|
8202
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
8203
|
+
for (const ent of entries) {
|
|
8204
|
+
if (ent.isDirectory()) {
|
|
8205
|
+
if (ent.name === "node_modules" || ent.name === ".git" || ent.name === "dist")
|
|
8206
|
+
continue;
|
|
8207
|
+
stack.push(path.join(dir, ent.name));
|
|
8208
|
+
continue;
|
|
8209
|
+
}
|
|
8210
|
+
if (ent.isFile() && ent.name.endsWith(".vue")) {
|
|
8211
|
+
out.push(path.join(dir, ent.name));
|
|
8212
|
+
}
|
|
8147
8213
|
}
|
|
8148
|
-
stack.push(fullPath);
|
|
8149
|
-
continue;
|
|
8150
8214
|
}
|
|
8151
|
-
|
|
8215
|
+
return out;
|
|
8216
|
+
};
|
|
8217
|
+
let supplemented = 0;
|
|
8218
|
+
let sourceDirectories = 0;
|
|
8219
|
+
for (const dir of getSourceDirs()) {
|
|
8220
|
+
const absDir = path.resolve(projectRootRef.current, dir);
|
|
8221
|
+
if (!fs.existsSync(absDir))
|
|
8152
8222
|
continue;
|
|
8223
|
+
sourceDirectories++;
|
|
8224
|
+
for (const filePath of walkFilesRecursive(absDir)) {
|
|
8225
|
+
const absolutePath = path.resolve(filePath);
|
|
8226
|
+
const componentName = resolveComponentNameFromPath({
|
|
8227
|
+
filename: absolutePath,
|
|
8228
|
+
projectRoot: projectRootRef.current,
|
|
8229
|
+
viewsDirAbs: getViewsDirAbs(),
|
|
8230
|
+
sourceDirs: getSourceDirs(),
|
|
8231
|
+
extraRoots: [process.cwd()]
|
|
8232
|
+
});
|
|
8233
|
+
if (componentHierarchyMap.has(componentName))
|
|
8234
|
+
continue;
|
|
8235
|
+
await collectSource(fs.readFileSync(absolutePath, "utf8"), absolutePath);
|
|
8236
|
+
supplemented++;
|
|
8153
8237
|
}
|
|
8154
|
-
const matches = index.get(entry.name) ?? [];
|
|
8155
|
-
matches.push(fullPath);
|
|
8156
|
-
index.set(entry.name, matches);
|
|
8157
8238
|
}
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
|
|
8163
|
-
|
|
8164
|
-
|
|
8165
|
-
|
|
8166
|
-
|
|
8167
|
-
|
|
8168
|
-
|
|
8169
|
-
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
|
|
8173
|
-
|
|
8174
|
-
|
|
8239
|
+
if (generationOnly && sourceDirectories === 0) {
|
|
8240
|
+
throw new Error("[vue-pom-generator] No configured source directories exist. Check the Vite root and injection directories.");
|
|
8241
|
+
}
|
|
8242
|
+
if (supplemented > 0) {
|
|
8243
|
+
loggerRef.current.info(`supplemented ${supplemented} components from filesystem walk (not in build graph)`);
|
|
8244
|
+
}
|
|
8245
|
+
};
|
|
8246
|
+
return {
|
|
8247
|
+
name: "vue-pom-generator-build",
|
|
8248
|
+
// This plugin exists to generate code on build output; it is not needed during dev-server HMR.
|
|
8249
|
+
apply: "build",
|
|
8250
|
+
enforce: "pre",
|
|
8251
|
+
async buildStart() {
|
|
8252
|
+
if (!routerAwarePoms) {
|
|
8253
|
+
setRouteNameToComponentNameMap(/* @__PURE__ */ new Map());
|
|
8254
|
+
setResolveToComponentNameFn(() => null);
|
|
8255
|
+
return;
|
|
8256
|
+
}
|
|
8257
|
+
let result;
|
|
8258
|
+
if (routerType === "nuxt") {
|
|
8259
|
+
result = await introspectNuxtPages(projectRootRef.current, { pageDirs: getPageDirsAbs() });
|
|
8260
|
+
} else {
|
|
8261
|
+
const resolvedRouterEntry = getResolvedRouterEntry();
|
|
8262
|
+
if (!resolvedRouterEntry)
|
|
8263
|
+
throw new Error("[vue-pom-generator] router.entry is required when router introspection is enabled.");
|
|
8264
|
+
result = await parseRouterFileFromCwd(resolvedRouterEntry, {
|
|
8265
|
+
moduleShims: routerModuleShims,
|
|
8266
|
+
componentNaming: {
|
|
8267
|
+
projectRoot: projectRootRef.current,
|
|
8268
|
+
viewsDirAbs: getViewsDirAbs(),
|
|
8269
|
+
sourceDirs: getSourceDirs()
|
|
8270
|
+
}
|
|
8271
|
+
});
|
|
8272
|
+
}
|
|
8273
|
+
const { routeNameMap, routePathMap } = result;
|
|
8274
|
+
setRouteNameToComponentNameMap(routeNameMap);
|
|
8275
|
+
setResolveToComponentNameFn((to) => {
|
|
8276
|
+
if (typeof to === "string") {
|
|
8277
|
+
return routePathMap.get(to) ?? null;
|
|
8278
|
+
}
|
|
8279
|
+
const maybe = to;
|
|
8280
|
+
if (typeof maybe.name === "string" && maybe.name.length) {
|
|
8281
|
+
const key = toPascalCase(maybe.name);
|
|
8282
|
+
return routeNameMap.get(key) ?? null;
|
|
8283
|
+
}
|
|
8284
|
+
if (typeof maybe.path === "string" && maybe.path.length) {
|
|
8285
|
+
return routePathMap.get(maybe.path) ?? null;
|
|
8286
|
+
}
|
|
8287
|
+
return null;
|
|
8288
|
+
});
|
|
8289
|
+
if (!fs.existsSync(basePageClassPath)) {
|
|
8290
|
+
this.error(`Base page runtime file not found at ${basePageClassPath}. Ensure it is included in the build.`);
|
|
8291
|
+
}
|
|
8292
|
+
this.addWatchFile(basePageClassPath);
|
|
8293
|
+
const pointerPath = path.resolve(path.dirname(basePageClassPath), "pointer.ts");
|
|
8294
|
+
if (!fs.existsSync(pointerPath)) {
|
|
8295
|
+
this.error(`pointer.ts not found at ${pointerPath}. Ensure it is included in the build.`);
|
|
8296
|
+
}
|
|
8297
|
+
this.addWatchFile(pointerPath);
|
|
8298
|
+
const calloutPath = path.resolve(path.dirname(basePageClassPath), "callout.ts");
|
|
8299
|
+
if (!fs.existsSync(calloutPath)) {
|
|
8300
|
+
this.error(`callout.ts not found at ${calloutPath}. Ensure it is included in the build.`);
|
|
8301
|
+
}
|
|
8302
|
+
this.addWatchFile(calloutPath);
|
|
8303
|
+
const floatingUiCalloutPath = path.resolve(path.dirname(basePageClassPath), "floating-ui-callout.ts");
|
|
8304
|
+
if (fs.existsSync(floatingUiCalloutPath)) {
|
|
8305
|
+
this.addWatchFile(floatingUiCalloutPath);
|
|
8306
|
+
}
|
|
8307
|
+
},
|
|
8308
|
+
async buildEnd(error) {
|
|
8309
|
+
if (error) {
|
|
8310
|
+
return;
|
|
8311
|
+
}
|
|
8312
|
+
await supplementHierarchyFromFilesystem();
|
|
8313
|
+
const metrics = summarizeHierarchyMap(componentHierarchyMap);
|
|
8314
|
+
if (!generationOnly && metrics.dataTestIdCount <= 0) {
|
|
8315
|
+
return;
|
|
8316
|
+
}
|
|
8317
|
+
if (!generationOnly && isLessRich(metrics, lastGeneratedMetrics)) {
|
|
8318
|
+
return;
|
|
8319
|
+
}
|
|
8320
|
+
await generateFiles(componentHierarchyMap, vueFilesPathMap, normalizedBasePagePath, {
|
|
8321
|
+
outDir,
|
|
8322
|
+
emitLanguages,
|
|
8323
|
+
typescriptOutputStructure,
|
|
8324
|
+
csharp,
|
|
8325
|
+
generateFixtures,
|
|
8326
|
+
vueTestUtilsOutDir,
|
|
8327
|
+
customPomAttachments,
|
|
8328
|
+
projectRoot: projectRootRef.current,
|
|
8329
|
+
customPomDir,
|
|
8330
|
+
requireCustomPomDir,
|
|
8331
|
+
customPomImportAliases,
|
|
8332
|
+
customPomImportNameCollisionBehavior,
|
|
8333
|
+
testIdAttribute,
|
|
8334
|
+
vueRouterFluentChaining: routerAwarePoms,
|
|
8335
|
+
routerEntry: getResolvedRouterEntry(),
|
|
8336
|
+
routerType,
|
|
8337
|
+
pageDirs: getPageDirs(),
|
|
8338
|
+
componentDirs: getComponentDirs(),
|
|
8339
|
+
layoutDirs: getLayoutDirs(),
|
|
8340
|
+
elementMetadata
|
|
8341
|
+
});
|
|
8342
|
+
lastGeneratedMetrics = metrics;
|
|
8343
|
+
loggerRef.current.info(`generated POMs (${metrics.entryCount} entries, ${metrics.interactiveComponentCount} interactive components, ${metrics.dataTestIdCount} selectors)`);
|
|
8344
|
+
},
|
|
8345
|
+
closeBundle() {
|
|
8346
|
+
loggerRef.current.info("build complete");
|
|
8347
|
+
}
|
|
8348
|
+
};
|
|
8349
|
+
}
|
|
8350
|
+
const TESTID_CLICK_EVENT_NAME = "__testid_event__";
|
|
8351
|
+
const indexedVueSfcPathsByRoots = /* @__PURE__ */ new Map();
|
|
8352
|
+
const resolvedSfcPathByLookup = /* @__PURE__ */ new Map();
|
|
8353
|
+
function isAsciiUppercaseLetterCode(code) {
|
|
8354
|
+
return code >= 65 && code <= 90;
|
|
8355
|
+
}
|
|
8356
|
+
function isAsciiLetterCode(code) {
|
|
8357
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
8358
|
+
}
|
|
8359
|
+
function isAsciiDigitCode(code) {
|
|
8360
|
+
return code >= 48 && code <= 57;
|
|
8361
|
+
}
|
|
8362
|
+
function toKebabCaseTag(tag) {
|
|
8363
|
+
let result = "";
|
|
8364
|
+
let previousWasSeparator = false;
|
|
8365
|
+
for (let i = 0; i < tag.length; i += 1) {
|
|
8366
|
+
const ch = tag[i];
|
|
8367
|
+
const code = ch.charCodeAt(0);
|
|
8368
|
+
if (ch === "_" || ch === "-" || ch === "." || ch === " " || ch === " " || ch === "\n" || ch === "\r") {
|
|
8369
|
+
if (result && !previousWasSeparator) {
|
|
8370
|
+
result += "-";
|
|
8371
|
+
}
|
|
8372
|
+
previousWasSeparator = true;
|
|
8373
|
+
continue;
|
|
8374
|
+
}
|
|
8375
|
+
const previous = i > 0 ? tag[i - 1] : "";
|
|
8376
|
+
const previousCode = previous ? previous.charCodeAt(0) : 0;
|
|
8377
|
+
const shouldInsertSeparator = i > 0 && isAsciiUppercaseLetterCode(code) && (isAsciiLetterCode(previousCode) || isAsciiDigitCode(previousCode)) && !previousWasSeparator;
|
|
8378
|
+
if (shouldInsertSeparator) {
|
|
8379
|
+
result += "-";
|
|
8380
|
+
}
|
|
8381
|
+
result += ch.toLowerCase();
|
|
8382
|
+
previousWasSeparator = false;
|
|
8383
|
+
}
|
|
8384
|
+
return result;
|
|
8385
|
+
}
|
|
8386
|
+
function normalizeWrapperSearchRoots(wrapperSearchRoots) {
|
|
8387
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
8388
|
+
for (const root of wrapperSearchRoots) {
|
|
8389
|
+
const resolved = path.resolve(root);
|
|
8390
|
+
try {
|
|
8391
|
+
if (!fs.existsSync(resolved) || !fs.statSync(resolved).isDirectory()) {
|
|
8392
|
+
continue;
|
|
8393
|
+
}
|
|
8394
|
+
normalized.add(path.normalize(fs.realpathSync(resolved)));
|
|
8395
|
+
} catch {
|
|
8396
|
+
continue;
|
|
8397
|
+
}
|
|
8398
|
+
}
|
|
8399
|
+
return [...normalized];
|
|
8400
|
+
}
|
|
8401
|
+
function buildSearchRootsKey(searchRoots) {
|
|
8402
|
+
return searchRoots.join("\n");
|
|
8403
|
+
}
|
|
8404
|
+
function buildVueSfcPathIndex(searchRoots) {
|
|
8405
|
+
const indexKey = buildSearchRootsKey(searchRoots);
|
|
8406
|
+
const existingIndex = indexedVueSfcPathsByRoots.get(indexKey);
|
|
8407
|
+
if (existingIndex) {
|
|
8408
|
+
return existingIndex;
|
|
8409
|
+
}
|
|
8410
|
+
const index = /* @__PURE__ */ new Map();
|
|
8411
|
+
const ignoredDirNames = /* @__PURE__ */ new Set([
|
|
8412
|
+
".git",
|
|
8413
|
+
".idea",
|
|
8414
|
+
".next",
|
|
8415
|
+
".nuxt",
|
|
8416
|
+
".output",
|
|
8417
|
+
".turbo",
|
|
8418
|
+
".yarn",
|
|
8419
|
+
"coverage",
|
|
8420
|
+
"dist",
|
|
8421
|
+
"build",
|
|
8422
|
+
"node_modules",
|
|
8423
|
+
"out",
|
|
8424
|
+
"tmp"
|
|
8425
|
+
]);
|
|
8426
|
+
const stack = [...searchRoots];
|
|
8427
|
+
const seenDirs = /* @__PURE__ */ new Set();
|
|
8428
|
+
while (stack.length > 0) {
|
|
8429
|
+
const dirPath = stack.pop();
|
|
8430
|
+
const normalizedDir = path.normalize(dirPath);
|
|
8431
|
+
if (seenDirs.has(normalizedDir)) {
|
|
8432
|
+
continue;
|
|
8433
|
+
}
|
|
8434
|
+
seenDirs.add(normalizedDir);
|
|
8435
|
+
let entries = [];
|
|
8436
|
+
try {
|
|
8437
|
+
entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
8438
|
+
} catch {
|
|
8439
|
+
continue;
|
|
8440
|
+
}
|
|
8441
|
+
for (const entry of entries) {
|
|
8442
|
+
const fullPath = path.join(dirPath, entry.name);
|
|
8443
|
+
if (entry.isDirectory()) {
|
|
8444
|
+
if (ignoredDirNames.has(entry.name) || entry.name.startsWith(".")) {
|
|
8445
|
+
continue;
|
|
8446
|
+
}
|
|
8447
|
+
stack.push(fullPath);
|
|
8448
|
+
continue;
|
|
8449
|
+
}
|
|
8450
|
+
if (!entry.isFile() || !entry.name.endsWith(".vue")) {
|
|
8451
|
+
continue;
|
|
8452
|
+
}
|
|
8453
|
+
const matches = index.get(entry.name) ?? [];
|
|
8454
|
+
matches.push(fullPath);
|
|
8455
|
+
index.set(entry.name, matches);
|
|
8456
|
+
}
|
|
8457
|
+
}
|
|
8458
|
+
indexedVueSfcPathsByRoots.set(indexKey, index);
|
|
8459
|
+
return index;
|
|
8460
|
+
}
|
|
8461
|
+
function resolveSfcPathForTag(tag, vueFilesPathMap, wrapperSearchRoots = []) {
|
|
8462
|
+
const registeredPath = vueFilesPathMap?.get(tag);
|
|
8463
|
+
const normalizedSearchRoots = normalizeWrapperSearchRoots(wrapperSearchRoots);
|
|
8464
|
+
const lookupKey = `${tag}
|
|
8465
|
+
${registeredPath ?? ""}
|
|
8466
|
+
${buildSearchRootsKey(normalizedSearchRoots)}`;
|
|
8467
|
+
if (resolvedSfcPathByLookup.has(lookupKey)) {
|
|
8468
|
+
return resolvedSfcPathByLookup.get(lookupKey) ?? null;
|
|
8469
|
+
}
|
|
8470
|
+
const candidateNames = [`${tag}.vue`, `${toKebabCaseTag(tag)}.vue`];
|
|
8471
|
+
const directCandidates = [
|
|
8472
|
+
registeredPath ? path.resolve(process.cwd(), registeredPath) : null,
|
|
8473
|
+
...normalizedSearchRoots.flatMap((root) => candidateNames.map((fileName) => path.join(root, fileName)))
|
|
8175
8474
|
].filter((value) => !!value);
|
|
8176
8475
|
const directMatch = directCandidates.find((candidatePath) => fs.existsSync(candidatePath));
|
|
8177
8476
|
if (directMatch) {
|
|
@@ -10115,9 +10414,7 @@ function extractMetadataAfterTransform(ast, componentName, elementMetadata, sema
|
|
|
10115
10414
|
}
|
|
10116
10415
|
}
|
|
10117
10416
|
traverseNode(ast);
|
|
10118
|
-
|
|
10119
|
-
elementMetadata.set(componentName, componentMetadata);
|
|
10120
|
-
}
|
|
10417
|
+
elementMetadata.set(componentName, componentMetadata);
|
|
10121
10418
|
return componentMetadata;
|
|
10122
10419
|
}
|
|
10123
10420
|
function createVuePluginWithTestIds(options) {
|
|
@@ -10263,403 +10560,132 @@ function createVuePluginWithTestIds(options) {
|
|
|
10263
10560
|
crossFileKeyRegistry,
|
|
10264
10561
|
optionKeyAttribute
|
|
10265
10562
|
}
|
|
10266
|
-
);
|
|
10267
|
-
perFileTransform.set(componentName, transform);
|
|
10268
|
-
}
|
|
10269
|
-
return transform(node, context);
|
|
10270
|
-
}
|
|
10271
|
-
];
|
|
10272
|
-
};
|
|
10273
|
-
const runtimeNodeTransform = (node, context) => {
|
|
10274
|
-
const filename = context.filename;
|
|
10275
|
-
if (!filename || !filename.endsWith(".vue") || !isFileInScope(filename)) {
|
|
10276
|
-
return;
|
|
10277
|
-
}
|
|
10278
|
-
const transforms = getNodeTransforms(filename);
|
|
10279
|
-
const ourTransform = transforms[transforms.length - 1];
|
|
10280
|
-
return ourTransform(node, context);
|
|
10281
|
-
};
|
|
10282
|
-
const templateCompilerOptions = {
|
|
10283
|
-
...userCompilerOptions,
|
|
10284
|
-
prefixIdentifiers: true,
|
|
10285
|
-
nodeTransforms: [
|
|
10286
|
-
...userNodeTransforms,
|
|
10287
|
-
runtimeNodeTransform
|
|
10288
|
-
]
|
|
10289
|
-
};
|
|
10290
|
-
const metadataCollectorPlugin = {
|
|
10291
|
-
name: "vue-pom-generator-metadata-collector",
|
|
10292
|
-
enforce: "pre",
|
|
10293
|
-
async transform(code, id) {
|
|
10294
|
-
const cleanPath = id.includes("?") ? id.substring(0, id.indexOf("?")) : id;
|
|
10295
|
-
if (!cleanPath.endsWith(".vue") || !isFileInScope(id)) {
|
|
10296
|
-
return null;
|
|
10297
|
-
}
|
|
10298
|
-
if (id !== cleanPath) {
|
|
10299
|
-
return null;
|
|
10300
|
-
}
|
|
10301
|
-
const componentName = getComponentNameFromPath(cleanPath);
|
|
10302
|
-
loggerRef.current.debug(`Collecting metadata for ${cleanPath} (component: ${componentName})`);
|
|
10303
|
-
const compilerSfc2 = await import("@vue/compiler-sfc");
|
|
10304
|
-
const parse = resolveCompilerSfcParse(compilerSfc2);
|
|
10305
|
-
const compilerDom2 = await import("@vue/compiler-dom");
|
|
10306
|
-
const compile = compilerDom2.compile;
|
|
10307
|
-
const { descriptor } = parse(code, { filename: cleanPath });
|
|
10308
|
-
if (descriptor.template) {
|
|
10309
|
-
const mergedExpressionPlugins = Array.from(
|
|
10310
|
-
/* @__PURE__ */ new Set([
|
|
10311
|
-
"typescript",
|
|
10312
|
-
...userCompilerOptions.expressionPlugins ?? []
|
|
10313
|
-
])
|
|
10314
|
-
);
|
|
10315
|
-
compile(descriptor.template.content, {
|
|
10316
|
-
...userCompilerOptions,
|
|
10317
|
-
filename: cleanPath,
|
|
10318
|
-
expressionPlugins: mergedExpressionPlugins,
|
|
10319
|
-
nodeTransforms: getNodeTransforms(cleanPath, componentName)
|
|
10320
|
-
});
|
|
10321
|
-
loggerRef.current.debug(`Metadata collected for ${cleanPath}`);
|
|
10322
|
-
}
|
|
10323
|
-
return null;
|
|
10324
|
-
}
|
|
10325
|
-
};
|
|
10326
|
-
const template = {
|
|
10327
|
-
...userTemplate,
|
|
10328
|
-
compilerOptions: templateCompilerOptions
|
|
10329
|
-
};
|
|
10330
|
-
const internalVuePlugin = vue({
|
|
10331
|
-
...vueOptions,
|
|
10332
|
-
template
|
|
10333
|
-
});
|
|
10334
|
-
const nuxtVueBridgePlugin = {
|
|
10335
|
-
name: "vue-pom-generator-nuxt-vue-bridge",
|
|
10336
|
-
apply: "serve",
|
|
10337
|
-
configResolved(config) {
|
|
10338
|
-
const viteVuePlugin = config.plugins.find((plugin) => {
|
|
10339
|
-
return typeof plugin === "object" && plugin !== null && "name" in plugin && plugin.name === "vite:vue" && "api" in plugin;
|
|
10340
|
-
});
|
|
10341
|
-
const api = viteVuePlugin?.api;
|
|
10342
|
-
if (!api) {
|
|
10343
|
-
throw new Error("[vue-pom-generator] Nuxt bridge could not find vite:vue plugin to patch.");
|
|
10344
|
-
}
|
|
10345
|
-
const currentOptions = api.options ?? {};
|
|
10346
|
-
const currentTemplate = currentOptions.template ?? {};
|
|
10347
|
-
const currentCompilerOptions = currentTemplate.compilerOptions ?? {};
|
|
10348
|
-
const currentNodeTransforms = currentCompilerOptions.nodeTransforms ?? [];
|
|
10349
|
-
if (currentNodeTransforms.includes(runtimeNodeTransform)) {
|
|
10350
|
-
return;
|
|
10351
|
-
}
|
|
10352
|
-
api.options = {
|
|
10353
|
-
...currentOptions,
|
|
10354
|
-
template: {
|
|
10355
|
-
...currentTemplate,
|
|
10356
|
-
compilerOptions: {
|
|
10357
|
-
...currentCompilerOptions,
|
|
10358
|
-
prefixIdentifiers: true,
|
|
10359
|
-
nodeTransforms: [
|
|
10360
|
-
...currentNodeTransforms,
|
|
10361
|
-
runtimeNodeTransform
|
|
10362
|
-
]
|
|
10363
|
-
}
|
|
10364
|
-
}
|
|
10365
|
-
};
|
|
10366
|
-
}
|
|
10367
|
-
};
|
|
10368
|
-
return { metadataCollectorPlugin, internalVuePlugin, nuxtVueBridgePlugin, templateCompilerOptions };
|
|
10369
|
-
}
|
|
10370
|
-
function summarizeHierarchyMap(componentHierarchyMap) {
|
|
10371
|
-
let interactiveComponentCount = 0;
|
|
10372
|
-
let dataTestIdCount = 0;
|
|
10373
|
-
for (const dependencies of componentHierarchyMap.values()) {
|
|
10374
|
-
const selectorCount = dependencies.dataTestIdSet?.size ?? 0;
|
|
10375
|
-
if (selectorCount > 0) {
|
|
10376
|
-
interactiveComponentCount += 1;
|
|
10377
|
-
dataTestIdCount += selectorCount;
|
|
10378
|
-
}
|
|
10379
|
-
}
|
|
10380
|
-
return {
|
|
10381
|
-
entryCount: componentHierarchyMap.size,
|
|
10382
|
-
interactiveComponentCount,
|
|
10383
|
-
dataTestIdCount
|
|
10384
|
-
};
|
|
10385
|
-
}
|
|
10386
|
-
function isLessRich(candidate, previous) {
|
|
10387
|
-
if (candidate.dataTestIdCount !== previous.dataTestIdCount) {
|
|
10388
|
-
return candidate.dataTestIdCount < previous.dataTestIdCount;
|
|
10389
|
-
}
|
|
10390
|
-
if (candidate.interactiveComponentCount !== previous.interactiveComponentCount) {
|
|
10391
|
-
return candidate.interactiveComponentCount < previous.interactiveComponentCount;
|
|
10392
|
-
}
|
|
10393
|
-
return candidate.entryCount < previous.entryCount;
|
|
10394
|
-
}
|
|
10395
|
-
function createBuildProcessorPlugin(options) {
|
|
10396
|
-
const {
|
|
10397
|
-
componentHierarchyMap,
|
|
10398
|
-
elementMetadata,
|
|
10399
|
-
crossFileKeyRegistry,
|
|
10400
|
-
vueFilesPathMap,
|
|
10401
|
-
getPageDirs,
|
|
10402
|
-
getComponentDirs,
|
|
10403
|
-
getLayoutDirs,
|
|
10404
|
-
getViewsDir,
|
|
10405
|
-
getSourceDirs,
|
|
10406
|
-
basePageClassPath,
|
|
10407
|
-
normalizedBasePagePath,
|
|
10408
|
-
generation,
|
|
10409
|
-
projectRootRef,
|
|
10410
|
-
nativeWrappers,
|
|
10411
|
-
optionKeyAttribute,
|
|
10412
|
-
skipTestIdGenerationInsideComponents,
|
|
10413
|
-
getWrapperSearchRoots,
|
|
10414
|
-
getResolvedRouterEntry,
|
|
10415
|
-
loggerRef
|
|
10416
|
-
} = options;
|
|
10417
|
-
const {
|
|
10418
|
-
outDir,
|
|
10419
|
-
emitLanguages,
|
|
10420
|
-
typescriptOutputStructure,
|
|
10421
|
-
csharp,
|
|
10422
|
-
generateFixtures,
|
|
10423
|
-
vueTestUtilsOutDir,
|
|
10424
|
-
customPomAttachments,
|
|
10425
|
-
customPomDir,
|
|
10426
|
-
requireCustomPomDir,
|
|
10427
|
-
customPomImportAliases,
|
|
10428
|
-
customPomImportNameCollisionBehavior,
|
|
10429
|
-
testIdAttribute,
|
|
10430
|
-
nameCollisionBehavior,
|
|
10431
|
-
missingSemanticNameBehavior,
|
|
10432
|
-
existingIdBehavior,
|
|
10433
|
-
routerAwarePoms,
|
|
10434
|
-
routerType,
|
|
10435
|
-
routerModuleShims
|
|
10436
|
-
} = generation;
|
|
10437
|
-
let lastGeneratedMetrics = {
|
|
10438
|
-
entryCount: 0,
|
|
10439
|
-
interactiveComponentCount: 0,
|
|
10440
|
-
dataTestIdCount: 0
|
|
10563
|
+
);
|
|
10564
|
+
perFileTransform.set(componentName, transform);
|
|
10565
|
+
}
|
|
10566
|
+
return transform(node, context);
|
|
10567
|
+
}
|
|
10568
|
+
];
|
|
10441
10569
|
};
|
|
10442
|
-
const
|
|
10443
|
-
|
|
10444
|
-
|
|
10445
|
-
|
|
10446
|
-
const { descriptor } = compilerSfc.parse(source, { filename });
|
|
10447
|
-
if (!descriptor.script && !descriptor.scriptSetup)
|
|
10448
|
-
return { bindings: void 0, isScriptSetup: false };
|
|
10449
|
-
const scriptBlock = compilerSfc.compileScript(descriptor, { id: filename });
|
|
10450
|
-
return { bindings: scriptBlock.bindings, isScriptSetup: !!descriptor.scriptSetup };
|
|
10451
|
-
} catch {
|
|
10452
|
-
return { bindings: void 0, isScriptSetup: false };
|
|
10570
|
+
const runtimeNodeTransform = (node, context) => {
|
|
10571
|
+
const filename = context.filename;
|
|
10572
|
+
if (!filename || !filename.endsWith(".vue") || !isFileInScope(filename)) {
|
|
10573
|
+
return;
|
|
10453
10574
|
}
|
|
10575
|
+
const transforms = getNodeTransforms(filename);
|
|
10576
|
+
const ourTransform = transforms[transforms.length - 1];
|
|
10577
|
+
return ourTransform(node, context);
|
|
10454
10578
|
};
|
|
10455
|
-
const
|
|
10456
|
-
|
|
10457
|
-
|
|
10458
|
-
|
|
10459
|
-
|
|
10460
|
-
|
|
10461
|
-
|
|
10462
|
-
|
|
10463
|
-
|
|
10464
|
-
|
|
10465
|
-
|
|
10466
|
-
|
|
10467
|
-
|
|
10468
|
-
|
|
10469
|
-
|
|
10470
|
-
|
|
10471
|
-
|
|
10472
|
-
|
|
10473
|
-
|
|
10474
|
-
|
|
10475
|
-
|
|
10476
|
-
|
|
10477
|
-
|
|
10478
|
-
|
|
10479
|
-
|
|
10480
|
-
|
|
10481
|
-
|
|
10482
|
-
|
|
10483
|
-
|
|
10484
|
-
|
|
10485
|
-
|
|
10486
|
-
|
|
10487
|
-
|
|
10488
|
-
|
|
10489
|
-
|
|
10490
|
-
|
|
10491
|
-
|
|
10492
|
-
|
|
10493
|
-
|
|
10494
|
-
extraRoots: [process.cwd()]
|
|
10495
|
-
});
|
|
10496
|
-
if (componentHierarchyMap.has(componentName))
|
|
10497
|
-
continue;
|
|
10498
|
-
let sfc = "";
|
|
10499
|
-
try {
|
|
10500
|
-
sfc = fs.readFileSync(absolutePath, "utf8");
|
|
10501
|
-
} catch {
|
|
10502
|
-
continue;
|
|
10503
|
-
}
|
|
10504
|
-
const { descriptor } = compilerSfc.parse(sfc, { filename: absolutePath });
|
|
10505
|
-
const template = descriptor.template?.content ?? "";
|
|
10506
|
-
if (!template.trim()) {
|
|
10507
|
-
vueFilesPathMap.set(componentName, absolutePath);
|
|
10508
|
-
componentHierarchyMap.set(componentName, {
|
|
10509
|
-
filePath: absolutePath,
|
|
10510
|
-
childrenComponentSet: /* @__PURE__ */ new Set(),
|
|
10511
|
-
usedComponentSet: /* @__PURE__ */ new Set(),
|
|
10512
|
-
dataTestIdSet: /* @__PURE__ */ new Set(),
|
|
10513
|
-
isView: false,
|
|
10514
|
-
methodsContent: ""
|
|
10515
|
-
});
|
|
10516
|
-
supplemented++;
|
|
10517
|
-
continue;
|
|
10518
|
-
}
|
|
10519
|
-
const { bindings: bindingMetadata, isScriptSetup } = getScriptInfo(sfc, absolutePath);
|
|
10520
|
-
vueFilesPathMap.set(componentName, absolutePath);
|
|
10521
|
-
try {
|
|
10522
|
-
compilerDom__namespace.compile(template, {
|
|
10523
|
-
filename: absolutePath,
|
|
10524
|
-
prefixIdentifiers: true,
|
|
10525
|
-
inline: isScriptSetup,
|
|
10526
|
-
bindingMetadata,
|
|
10527
|
-
// See dev-plugin.ts — same rationale: enable TS in template
|
|
10528
|
-
// expressions so `(row: RowType) => ...` handlers parse.
|
|
10529
|
-
expressionPlugins: ["typescript"],
|
|
10530
|
-
nodeTransforms: [
|
|
10531
|
-
createTestIdTransform(
|
|
10532
|
-
componentName,
|
|
10533
|
-
componentHierarchyMap,
|
|
10534
|
-
nativeWrappers,
|
|
10535
|
-
skipTestIdGenerationInsideComponents,
|
|
10536
|
-
getViewsDirAbs(),
|
|
10537
|
-
{
|
|
10538
|
-
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
10539
|
-
testIdAttribute,
|
|
10540
|
-
nameCollisionBehavior,
|
|
10541
|
-
missingSemanticNameBehavior,
|
|
10542
|
-
warn: (message) => loggerRef.current.warn(message),
|
|
10543
|
-
vueFilesPathMap,
|
|
10544
|
-
wrapperSearchRoots: getWrapperSearchRoots(),
|
|
10545
|
-
crossFileKeyRegistry,
|
|
10546
|
-
optionKeyAttribute
|
|
10547
|
-
}
|
|
10548
|
-
)
|
|
10549
|
-
]
|
|
10550
|
-
});
|
|
10551
|
-
} catch {
|
|
10579
|
+
const templateCompilerOptions = {
|
|
10580
|
+
...userCompilerOptions,
|
|
10581
|
+
prefixIdentifiers: true,
|
|
10582
|
+
nodeTransforms: [
|
|
10583
|
+
...userNodeTransforms,
|
|
10584
|
+
runtimeNodeTransform
|
|
10585
|
+
]
|
|
10586
|
+
};
|
|
10587
|
+
const collectSource = async (code, cleanPath) => {
|
|
10588
|
+
const componentName = getComponentNameFromPath(cleanPath);
|
|
10589
|
+
loggerRef.current.debug(`Collecting metadata for ${cleanPath} (component: ${componentName})`);
|
|
10590
|
+
const compilerSfc2 = await import("@vue/compiler-sfc");
|
|
10591
|
+
const parse = resolveCompilerSfcParse(compilerSfc2);
|
|
10592
|
+
const { descriptor, errors } = parse(code, { filename: cleanPath });
|
|
10593
|
+
if (errors.length) {
|
|
10594
|
+
throw new Error(`[vue-pom-generator] Cannot parse ${cleanPath}: ${errors.map(String).join("\n")}`);
|
|
10595
|
+
}
|
|
10596
|
+
const script = descriptor.script || descriptor.scriptSetup ? compilerSfc2.compileScript(descriptor, { ...vueOptions?.script, id: cleanPath }) : void 0;
|
|
10597
|
+
if (descriptor.template) {
|
|
10598
|
+
const mergedExpressionPlugins = Array.from(
|
|
10599
|
+
/* @__PURE__ */ new Set([
|
|
10600
|
+
"typescript",
|
|
10601
|
+
...userCompilerOptions.expressionPlugins ?? []
|
|
10602
|
+
])
|
|
10603
|
+
);
|
|
10604
|
+
const compiled = compilerSfc2.compileTemplate({
|
|
10605
|
+
...userTemplate,
|
|
10606
|
+
id: cleanPath,
|
|
10607
|
+
filename: cleanPath,
|
|
10608
|
+
source: descriptor.template.content,
|
|
10609
|
+
ast: descriptor.template.ast,
|
|
10610
|
+
preprocessLang: descriptor.template.lang,
|
|
10611
|
+
compilerOptions: {
|
|
10612
|
+
...userCompilerOptions,
|
|
10613
|
+
prefixIdentifiers: true,
|
|
10614
|
+
inline: !!descriptor.scriptSetup,
|
|
10615
|
+
bindingMetadata: script?.bindings,
|
|
10616
|
+
expressionPlugins: mergedExpressionPlugins,
|
|
10617
|
+
nodeTransforms: getNodeTransforms(cleanPath, componentName)
|
|
10552
10618
|
}
|
|
10553
|
-
|
|
10619
|
+
});
|
|
10620
|
+
if (compiled.errors.length) {
|
|
10621
|
+
throw new Error(`[vue-pom-generator] Cannot compile ${cleanPath}: ${compiled.errors.map(String).join("\n")}`);
|
|
10554
10622
|
}
|
|
10555
|
-
|
|
10556
|
-
|
|
10557
|
-
|
|
10623
|
+
loggerRef.current.debug(`Metadata collected for ${cleanPath}`);
|
|
10624
|
+
} else {
|
|
10625
|
+
vueFilesPathMap.set(componentName, cleanPath);
|
|
10626
|
+
elementMetadata.delete(componentName);
|
|
10627
|
+
componentHierarchyMap.set(componentName, {
|
|
10628
|
+
filePath: cleanPath,
|
|
10629
|
+
childrenComponentSet: /* @__PURE__ */ new Set(),
|
|
10630
|
+
usedComponentSet: /* @__PURE__ */ new Set(),
|
|
10631
|
+
dataTestIdSet: /* @__PURE__ */ new Set(),
|
|
10632
|
+
isView: false,
|
|
10633
|
+
methodsContent: ""
|
|
10634
|
+
});
|
|
10558
10635
|
}
|
|
10559
10636
|
};
|
|
10560
|
-
|
|
10561
|
-
name: "vue-pom-generator-
|
|
10562
|
-
// This plugin exists to generate code on build output; it is not needed during dev-server HMR.
|
|
10563
|
-
apply: "build",
|
|
10637
|
+
const metadataCollectorPlugin = {
|
|
10638
|
+
name: "vue-pom-generator-metadata-collector",
|
|
10564
10639
|
enforce: "pre",
|
|
10565
|
-
async
|
|
10566
|
-
if (!
|
|
10567
|
-
|
|
10568
|
-
|
|
10569
|
-
|
|
10570
|
-
|
|
10571
|
-
|
|
10572
|
-
|
|
10573
|
-
|
|
10574
|
-
|
|
10575
|
-
|
|
10576
|
-
|
|
10577
|
-
|
|
10578
|
-
|
|
10579
|
-
|
|
10580
|
-
|
|
10581
|
-
|
|
10582
|
-
|
|
10583
|
-
|
|
10584
|
-
|
|
10585
|
-
});
|
|
10586
|
-
}
|
|
10587
|
-
const { routeNameMap, routePathMap } = result;
|
|
10588
|
-
setRouteNameToComponentNameMap(routeNameMap);
|
|
10589
|
-
setResolveToComponentNameFn((to) => {
|
|
10590
|
-
if (typeof to === "string") {
|
|
10591
|
-
return routePathMap.get(to) ?? null;
|
|
10592
|
-
}
|
|
10593
|
-
const maybe = to;
|
|
10594
|
-
if (typeof maybe.name === "string" && maybe.name.length) {
|
|
10595
|
-
const key = toPascalCase(maybe.name);
|
|
10596
|
-
return routeNameMap.get(key) ?? null;
|
|
10597
|
-
}
|
|
10598
|
-
if (typeof maybe.path === "string" && maybe.path.length) {
|
|
10599
|
-
return routePathMap.get(maybe.path) ?? null;
|
|
10600
|
-
}
|
|
10601
|
-
return null;
|
|
10640
|
+
async transform(code, id) {
|
|
10641
|
+
if (!id.endsWith(".vue") || !isFileInScope(id)) return null;
|
|
10642
|
+
await collectSource(code, id);
|
|
10643
|
+
return null;
|
|
10644
|
+
}
|
|
10645
|
+
};
|
|
10646
|
+
const template = {
|
|
10647
|
+
...userTemplate,
|
|
10648
|
+
compilerOptions: templateCompilerOptions
|
|
10649
|
+
};
|
|
10650
|
+
const internalVuePlugin = vue({
|
|
10651
|
+
...vueOptions,
|
|
10652
|
+
template
|
|
10653
|
+
});
|
|
10654
|
+
const nuxtVueBridgePlugin = {
|
|
10655
|
+
name: "vue-pom-generator-nuxt-vue-bridge",
|
|
10656
|
+
apply: "serve",
|
|
10657
|
+
configResolved(config) {
|
|
10658
|
+
const viteVuePlugin = config.plugins.find((plugin) => {
|
|
10659
|
+
return typeof plugin === "object" && plugin !== null && "name" in plugin && plugin.name === "vite:vue" && "api" in plugin;
|
|
10602
10660
|
});
|
|
10603
|
-
|
|
10604
|
-
|
|
10605
|
-
|
|
10606
|
-
this.addWatchFile(basePageClassPath);
|
|
10607
|
-
const pointerPath = path.resolve(path.dirname(basePageClassPath), "pointer.ts");
|
|
10608
|
-
if (!fs.existsSync(pointerPath)) {
|
|
10609
|
-
this.error(`pointer.ts not found at ${pointerPath}. Ensure it is included in the build.`);
|
|
10610
|
-
}
|
|
10611
|
-
this.addWatchFile(pointerPath);
|
|
10612
|
-
const calloutPath = path.resolve(path.dirname(basePageClassPath), "callout.ts");
|
|
10613
|
-
if (!fs.existsSync(calloutPath)) {
|
|
10614
|
-
this.error(`callout.ts not found at ${calloutPath}. Ensure it is included in the build.`);
|
|
10615
|
-
}
|
|
10616
|
-
this.addWatchFile(calloutPath);
|
|
10617
|
-
const floatingUiCalloutPath = path.resolve(path.dirname(basePageClassPath), "floating-ui-callout.ts");
|
|
10618
|
-
if (fs.existsSync(floatingUiCalloutPath)) {
|
|
10619
|
-
this.addWatchFile(floatingUiCalloutPath);
|
|
10620
|
-
}
|
|
10621
|
-
},
|
|
10622
|
-
async buildEnd(error) {
|
|
10623
|
-
if (error) {
|
|
10624
|
-
return;
|
|
10625
|
-
}
|
|
10626
|
-
supplementHierarchyFromFilesystem();
|
|
10627
|
-
const metrics = summarizeHierarchyMap(componentHierarchyMap);
|
|
10628
|
-
if (metrics.dataTestIdCount <= 0) {
|
|
10629
|
-
return;
|
|
10661
|
+
const api = viteVuePlugin?.api;
|
|
10662
|
+
if (!api) {
|
|
10663
|
+
throw new Error("[vue-pom-generator] Nuxt bridge could not find vite:vue plugin to patch.");
|
|
10630
10664
|
}
|
|
10631
|
-
|
|
10665
|
+
const currentOptions = api.options ?? {};
|
|
10666
|
+
const currentTemplate = currentOptions.template ?? {};
|
|
10667
|
+
const currentCompilerOptions = currentTemplate.compilerOptions ?? {};
|
|
10668
|
+
const currentNodeTransforms = currentCompilerOptions.nodeTransforms ?? [];
|
|
10669
|
+
if (currentNodeTransforms.includes(runtimeNodeTransform)) {
|
|
10632
10670
|
return;
|
|
10633
10671
|
}
|
|
10634
|
-
|
|
10635
|
-
|
|
10636
|
-
|
|
10637
|
-
|
|
10638
|
-
|
|
10639
|
-
|
|
10640
|
-
|
|
10641
|
-
|
|
10642
|
-
|
|
10643
|
-
|
|
10644
|
-
|
|
10645
|
-
|
|
10646
|
-
|
|
10647
|
-
|
|
10648
|
-
vueRouterFluentChaining: routerAwarePoms,
|
|
10649
|
-
routerEntry: getResolvedRouterEntry(),
|
|
10650
|
-
routerType,
|
|
10651
|
-
pageDirs: getPageDirs(),
|
|
10652
|
-
componentDirs: getComponentDirs(),
|
|
10653
|
-
layoutDirs: getLayoutDirs(),
|
|
10654
|
-
elementMetadata
|
|
10655
|
-
});
|
|
10656
|
-
lastGeneratedMetrics = metrics;
|
|
10657
|
-
loggerRef.current.info(`generated POMs (${metrics.entryCount} entries, ${metrics.interactiveComponentCount} interactive components, ${metrics.dataTestIdCount} selectors)`);
|
|
10658
|
-
},
|
|
10659
|
-
closeBundle() {
|
|
10660
|
-
loggerRef.current.info("build complete");
|
|
10672
|
+
api.options = {
|
|
10673
|
+
...currentOptions,
|
|
10674
|
+
template: {
|
|
10675
|
+
...currentTemplate,
|
|
10676
|
+
compilerOptions: {
|
|
10677
|
+
...currentCompilerOptions,
|
|
10678
|
+
prefixIdentifiers: true,
|
|
10679
|
+
nodeTransforms: [
|
|
10680
|
+
...currentNodeTransforms,
|
|
10681
|
+
runtimeNodeTransform
|
|
10682
|
+
]
|
|
10683
|
+
}
|
|
10684
|
+
}
|
|
10685
|
+
};
|
|
10661
10686
|
}
|
|
10662
10687
|
};
|
|
10688
|
+
return { metadataCollectorPlugin, internalVuePlugin, nuxtVueBridgePlugin, templateCompilerOptions, collectSource };
|
|
10663
10689
|
}
|
|
10664
10690
|
function createDevProcessorPlugin(options) {
|
|
10665
10691
|
const {
|
|
@@ -11237,7 +11263,6 @@ ${code}`,
|
|
|
11237
11263
|
function createInternalPlugins(options) {
|
|
11238
11264
|
const {
|
|
11239
11265
|
componentHierarchyMap,
|
|
11240
|
-
crossFileKeyRegistry,
|
|
11241
11266
|
elementMetadata,
|
|
11242
11267
|
vueFilesPathMap,
|
|
11243
11268
|
nativeWrappers,
|
|
@@ -11253,7 +11278,9 @@ function createInternalPlugins(options) {
|
|
|
11253
11278
|
projectRootRef,
|
|
11254
11279
|
basePageClassPath: basePageClassPathOverride,
|
|
11255
11280
|
loggerRef,
|
|
11256
|
-
annotatorRuntime
|
|
11281
|
+
annotatorRuntime,
|
|
11282
|
+
collectSource,
|
|
11283
|
+
generationOnly
|
|
11257
11284
|
} = options;
|
|
11258
11285
|
const {
|
|
11259
11286
|
routerAwarePoms,
|
|
@@ -11281,7 +11308,6 @@ function createInternalPlugins(options) {
|
|
|
11281
11308
|
const tsProcessor = createBuildProcessorPlugin({
|
|
11282
11309
|
componentHierarchyMap,
|
|
11283
11310
|
elementMetadata,
|
|
11284
|
-
crossFileKeyRegistry,
|
|
11285
11311
|
vueFilesPathMap,
|
|
11286
11312
|
getPageDirs,
|
|
11287
11313
|
getComponentDirs,
|
|
@@ -11292,10 +11318,8 @@ function createInternalPlugins(options) {
|
|
|
11292
11318
|
normalizedBasePagePath,
|
|
11293
11319
|
generation,
|
|
11294
11320
|
projectRootRef,
|
|
11295
|
-
|
|
11296
|
-
|
|
11297
|
-
skipTestIdGenerationInsideComponents,
|
|
11298
|
-
getWrapperSearchRoots,
|
|
11321
|
+
collectSource,
|
|
11322
|
+
generationOnly,
|
|
11299
11323
|
getResolvedRouterEntry: resolveRouterEntry2,
|
|
11300
11324
|
loggerRef
|
|
11301
11325
|
});
|
|
@@ -11457,16 +11481,19 @@ const sharedGeneratorStateRegistry = /* @__PURE__ */ new Map();
|
|
|
11457
11481
|
function toArray(value) {
|
|
11458
11482
|
return Array.isArray(value) ? value : [];
|
|
11459
11483
|
}
|
|
11484
|
+
function createGeneratorState() {
|
|
11485
|
+
return {
|
|
11486
|
+
elementMetadata: /* @__PURE__ */ new Map(),
|
|
11487
|
+
semanticNameMap: /* @__PURE__ */ new Map(),
|
|
11488
|
+
componentHierarchyMap: /* @__PURE__ */ new Map(),
|
|
11489
|
+
crossFileKeyRegistry: /* @__PURE__ */ new Map(),
|
|
11490
|
+
vueFilesPathMap: /* @__PURE__ */ new Map()
|
|
11491
|
+
};
|
|
11492
|
+
}
|
|
11460
11493
|
function getSharedGeneratorState(key) {
|
|
11461
11494
|
let state = sharedGeneratorStateRegistry.get(key);
|
|
11462
11495
|
if (!state) {
|
|
11463
|
-
state =
|
|
11464
|
-
elementMetadata: /* @__PURE__ */ new Map(),
|
|
11465
|
-
semanticNameMap: /* @__PURE__ */ new Map(),
|
|
11466
|
-
componentHierarchyMap: /* @__PURE__ */ new Map(),
|
|
11467
|
-
crossFileKeyRegistry: /* @__PURE__ */ new Map(),
|
|
11468
|
-
vueFilesPathMap: /* @__PURE__ */ new Map()
|
|
11469
|
-
};
|
|
11496
|
+
state = createGeneratorState();
|
|
11470
11497
|
sharedGeneratorStateRegistry.set(key, state);
|
|
11471
11498
|
}
|
|
11472
11499
|
return state;
|
|
@@ -11527,9 +11554,15 @@ function assertNotVitePluginInstance(options) {
|
|
|
11527
11554
|
);
|
|
11528
11555
|
}
|
|
11529
11556
|
function createVuePomGeneratorPlugins(options = {}) {
|
|
11557
|
+
return createGeneratorPlugins(options, false);
|
|
11558
|
+
}
|
|
11559
|
+
function createGeneratorPlugins(options, generationOnly, projectRoot = process.cwd()) {
|
|
11530
11560
|
assertNotVitePluginInstance(options);
|
|
11531
11561
|
const injection = options.injection ?? {};
|
|
11532
|
-
const isNuxt = detectNuxtProject(options,
|
|
11562
|
+
const isNuxt = detectNuxtProject(options, projectRoot);
|
|
11563
|
+
if (generationOnly && isNuxt) {
|
|
11564
|
+
throw new Error("[vue-pom-generator] generateVuePoms does not run Nuxt project preparation. Use the Nuxt Vite integration.");
|
|
11565
|
+
}
|
|
11533
11566
|
const generationSetting = options.generation;
|
|
11534
11567
|
const generationOptions = generationSetting === false ? null : generationSetting ?? {};
|
|
11535
11568
|
const generationEnabled = generationOptions !== null;
|
|
@@ -11615,7 +11648,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
11615
11648
|
]));
|
|
11616
11649
|
const getWrapperSearchRoots = () => resolvedInjectionOptionsRef.current.wrapperSearchRoots;
|
|
11617
11650
|
const sharedStateKey = JSON.stringify({
|
|
11618
|
-
cwd:
|
|
11651
|
+
cwd: projectRoot,
|
|
11619
11652
|
mode: isNuxt ? "nuxt" : "vue",
|
|
11620
11653
|
pageDirs: isNuxt ? null : getPageDirs(),
|
|
11621
11654
|
componentDirs: isNuxt ? null : getComponentDirs(),
|
|
@@ -11627,9 +11660,9 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
11627
11660
|
routerType: resolvedGenerationOptions.routerType,
|
|
11628
11661
|
vuePluginOwnership
|
|
11629
11662
|
});
|
|
11630
|
-
const sharedState = getSharedGeneratorState(sharedStateKey);
|
|
11663
|
+
const sharedState = generationOnly ? createGeneratorState() : getSharedGeneratorState(sharedStateKey);
|
|
11631
11664
|
let templateCompilerOptionsForResolvedPlugin;
|
|
11632
|
-
const projectRootRef = { current:
|
|
11665
|
+
const projectRootRef = { current: projectRoot };
|
|
11633
11666
|
const loggerRef = {
|
|
11634
11667
|
current: createLogger({ verbosity })
|
|
11635
11668
|
};
|
|
@@ -11693,7 +11726,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
11693
11726
|
...getWrapperSearchRoots()
|
|
11694
11727
|
].map((root) => resolveFromProjectRoot(projectRootRef.current, root))));
|
|
11695
11728
|
const { elementMetadata, semanticNameMap, componentHierarchyMap, crossFileKeyRegistry, vueFilesPathMap } = sharedState;
|
|
11696
|
-
const { metadataCollectorPlugin, internalVuePlugin, templateCompilerOptions } = createVuePluginWithTestIds({
|
|
11729
|
+
const { metadataCollectorPlugin, internalVuePlugin, templateCompilerOptions, collectSource } = createVuePluginWithTestIds({
|
|
11697
11730
|
vueOptions,
|
|
11698
11731
|
existingIdBehavior: resolvedGenerationOptions.existingIdBehavior,
|
|
11699
11732
|
nameCollisionBehavior: resolvedGenerationOptions.nameCollisionBehavior,
|
|
@@ -11721,7 +11754,6 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
11721
11754
|
templateCompilerOptionsForResolvedPlugin = templateCompilerOptions;
|
|
11722
11755
|
const internalPlugins = createInternalPlugins({
|
|
11723
11756
|
componentHierarchyMap,
|
|
11724
|
-
crossFileKeyRegistry,
|
|
11725
11757
|
elementMetadata,
|
|
11726
11758
|
vueFilesPathMap,
|
|
11727
11759
|
nativeWrappers,
|
|
@@ -11734,6 +11766,8 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
11734
11766
|
getSourceDirs,
|
|
11735
11767
|
getWrapperSearchRoots: getWrapperSearchRootsAbs,
|
|
11736
11768
|
generation: resolvedGenerationOptions,
|
|
11769
|
+
collectSource,
|
|
11770
|
+
generationOnly,
|
|
11737
11771
|
projectRootRef,
|
|
11738
11772
|
basePageClassPath: basePageClassPathOverride,
|
|
11739
11773
|
loggerRef,
|
|
@@ -13154,6 +13188,44 @@ function mountAnnotatorClient(options) {
|
|
|
13154
13188
|
runtimeWindow[RUNTIME_GUARD] = runtime;
|
|
13155
13189
|
return runtime;
|
|
13156
13190
|
}
|
|
13191
|
+
let generating = false;
|
|
13192
|
+
async function generateVuePoms(options = {}, viteOptions = {}) {
|
|
13193
|
+
if (options.generation === false) {
|
|
13194
|
+
throw new Error("[vue-pom-generator] generateVuePoms requires generation to be enabled.");
|
|
13195
|
+
}
|
|
13196
|
+
const entryId = "virtual:vue-pom-generator-entry";
|
|
13197
|
+
const resolvedEntryId = `\0${entryId}`;
|
|
13198
|
+
const entry = {
|
|
13199
|
+
name: "vue-pom-generator-entry",
|
|
13200
|
+
resolveId(id) {
|
|
13201
|
+
return id === entryId ? resolvedEntryId : void 0;
|
|
13202
|
+
},
|
|
13203
|
+
load(id) {
|
|
13204
|
+
return id === resolvedEntryId ? "export {};" : void 0;
|
|
13205
|
+
}
|
|
13206
|
+
};
|
|
13207
|
+
if (generating) {
|
|
13208
|
+
throw new Error("[vue-pom-generator] Await the previous generateVuePoms call before starting another.");
|
|
13209
|
+
}
|
|
13210
|
+
generating = true;
|
|
13211
|
+
try {
|
|
13212
|
+
const { build } = await import("vite");
|
|
13213
|
+
await build({
|
|
13214
|
+
...viteOptions,
|
|
13215
|
+
configFile: false,
|
|
13216
|
+
publicDir: false,
|
|
13217
|
+
plugins: [entry, ...createGeneratorPlugins(options, true, path.resolve(viteOptions.root ?? ".")), ...viteOptions.plugins ?? []],
|
|
13218
|
+
build: {
|
|
13219
|
+
write: false,
|
|
13220
|
+
emptyOutDir: false,
|
|
13221
|
+
minify: false,
|
|
13222
|
+
rollupOptions: { input: entryId }
|
|
13223
|
+
}
|
|
13224
|
+
});
|
|
13225
|
+
} finally {
|
|
13226
|
+
generating = false;
|
|
13227
|
+
}
|
|
13228
|
+
}
|
|
13157
13229
|
const nuxtConfigMarker = /* @__PURE__ */ Symbol.for("@immense/vue-pom-generator.nuxt");
|
|
13158
13230
|
function defineVuePomGeneratorConfig(options) {
|
|
13159
13231
|
return options;
|
|
@@ -13170,6 +13242,7 @@ exports.createVuePomGeneratorPlugins = createVuePomGeneratorPlugins;
|
|
|
13170
13242
|
exports.default = createVuePomGeneratorPlugins;
|
|
13171
13243
|
exports.defineNuxtPomGeneratorConfig = defineNuxtPomGeneratorConfig;
|
|
13172
13244
|
exports.defineVuePomGeneratorConfig = defineVuePomGeneratorConfig;
|
|
13245
|
+
exports.generateVuePoms = generateVuePoms;
|
|
13173
13246
|
exports.mountAnnotatorClient = mountAnnotatorClient;
|
|
13174
13247
|
exports.vuePomGenerator = createVuePomGeneratorPlugins;
|
|
13175
13248
|
//# sourceMappingURL=index.cjs.map
|