@immense/vue-pom-generator 1.0.106 → 1.0.108
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 +36 -24
- package/class-generation/index.ts +111 -190
- package/dist/class-generation/index.d.ts +3 -0
- package/dist/class-generation/index.d.ts.map +1 -1
- package/dist/index.cjs +775 -707
- 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 +776 -708
- package/dist/index.mjs.map +1 -1
- package/dist/manifest-generator.d.ts +2 -1
- package/dist/manifest-generator.d.ts.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/dev-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/dist/tests/incremental-generation.test.d.ts +2 -0
- package/dist/tests/incremental-generation.test.d.ts.map +1 -0
- package/dist/typescript-codegen.d.ts +14 -1
- package/dist/typescript-codegen.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- 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) {
|
|
@@ -294,6 +295,58 @@ function applyNuxtDiscoveryToInjectionOptions(options, discovery) {
|
|
|
294
295
|
wrapperSearchRoots: discovery.wrapperSearchRoots
|
|
295
296
|
};
|
|
296
297
|
}
|
|
298
|
+
class TypeScriptRenderCache {
|
|
299
|
+
entries = /* @__PURE__ */ new Map();
|
|
300
|
+
render(filePath, input, build) {
|
|
301
|
+
const previous = this.entries.get(filePath);
|
|
302
|
+
if (previous?.input === input) return previous.content;
|
|
303
|
+
const content = build();
|
|
304
|
+
this.entries.set(filePath, { input, content });
|
|
305
|
+
return content;
|
|
306
|
+
}
|
|
307
|
+
retain(filePaths) {
|
|
308
|
+
for (const filePath of this.entries.keys()) {
|
|
309
|
+
if (!filePaths.has(filePath)) this.entries.delete(filePath);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function createClassDeclaration(declaration, members) {
|
|
314
|
+
const result = { ...declaration, kind: tsMorph.StructureKind.Class };
|
|
315
|
+
for (const member of members) {
|
|
316
|
+
switch (member.kind) {
|
|
317
|
+
case tsMorph.StructureKind.Constructor:
|
|
318
|
+
(result.ctors ??= []).push(member);
|
|
319
|
+
break;
|
|
320
|
+
case tsMorph.StructureKind.GetAccessor:
|
|
321
|
+
(result.getAccessors ??= []).push(member);
|
|
322
|
+
break;
|
|
323
|
+
case tsMorph.StructureKind.Method:
|
|
324
|
+
(result.methods ??= []).push(member);
|
|
325
|
+
break;
|
|
326
|
+
case tsMorph.StructureKind.Property:
|
|
327
|
+
(result.properties ??= []).push(member);
|
|
328
|
+
break;
|
|
329
|
+
default:
|
|
330
|
+
throw new Error(`Unsupported class member kind: ${String(member.kind)}`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return result;
|
|
334
|
+
}
|
|
335
|
+
function renderStructuredSourceFile(filePath, structure, options = {}) {
|
|
336
|
+
const build = () => {
|
|
337
|
+
const project = createTypeScriptProject();
|
|
338
|
+
const sourceFile = project.createSourceFile(filePath, structure);
|
|
339
|
+
return ensureTrailingNewline(`${options.prefixText ?? ""}${sourceFile.getFullText()}`);
|
|
340
|
+
};
|
|
341
|
+
if (!options.cache) return build();
|
|
342
|
+
const input = JSON.stringify([options.prefixText, structure], (_key, value) => {
|
|
343
|
+
if (typeof value !== "function") return value;
|
|
344
|
+
const writer = createTypeScriptWriter();
|
|
345
|
+
value(writer);
|
|
346
|
+
return writer.toString();
|
|
347
|
+
});
|
|
348
|
+
return options.cache.render(filePath, input, build);
|
|
349
|
+
}
|
|
297
350
|
function createTypeScriptProject() {
|
|
298
351
|
return new tsMorph.Project({
|
|
299
352
|
useInMemoryFileSystem: true,
|
|
@@ -358,9 +411,6 @@ function addNamedImport(sourceFile, options) {
|
|
|
358
411
|
namedImports: options.namedImports
|
|
359
412
|
});
|
|
360
413
|
}
|
|
361
|
-
function addExportAll(sourceFile, moduleSpecifier) {
|
|
362
|
-
return sourceFile.addExportDeclaration({ moduleSpecifier });
|
|
363
|
-
}
|
|
364
414
|
function createClassMethod(method) {
|
|
365
415
|
return {
|
|
366
416
|
kind: tsMorph.StructureKind.Method,
|
|
@@ -1457,23 +1507,11 @@ function getSlotScopeVariablesUsedAsBareCallbackHandlers(templateNode) {
|
|
|
1457
1507
|
const vFor = node.props.find(
|
|
1458
1508
|
(prop) => prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "for"
|
|
1459
1509
|
);
|
|
1460
|
-
if (vFor?.
|
|
1461
|
-
const
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
if (aliasSource) {
|
|
1466
|
-
try {
|
|
1467
|
-
const aliasAst = parser.parseExpression(aliasSource, { plugins: ["typescript"] });
|
|
1468
|
-
if (types.isSequenceExpression(aliasAst)) {
|
|
1469
|
-
for (const part of aliasAst.expressions) {
|
|
1470
|
-
names.push(...collectBindingPatternNames(part));
|
|
1471
|
-
}
|
|
1472
|
-
} else {
|
|
1473
|
-
names.push(...collectBindingPatternNames(aliasAst));
|
|
1474
|
-
}
|
|
1475
|
-
} catch {
|
|
1476
|
-
}
|
|
1510
|
+
if (vFor?.forParseResult) {
|
|
1511
|
+
const { value, key, index } = vFor.forParseResult;
|
|
1512
|
+
for (const alias of [value, key, index]) {
|
|
1513
|
+
if (alias) {
|
|
1514
|
+
names.push(...collectBindingPatternNames(tryGetTemplateSlotScopeBindingNode(alias)));
|
|
1477
1515
|
}
|
|
1478
1516
|
}
|
|
1479
1517
|
}
|
|
@@ -1643,10 +1681,6 @@ function tryGetTemplateSlotScopeBindingNode(expression) {
|
|
|
1643
1681
|
if (!rawSource) {
|
|
1644
1682
|
return null;
|
|
1645
1683
|
}
|
|
1646
|
-
try {
|
|
1647
|
-
return parser.parseExpression(rawSource, { plugins: ["typescript"] });
|
|
1648
|
-
} catch {
|
|
1649
|
-
}
|
|
1650
1684
|
try {
|
|
1651
1685
|
const parsed = parser.parse(`(${rawSource}) => {}`, {
|
|
1652
1686
|
sourceType: "module",
|
|
@@ -4007,29 +4041,129 @@ function generateTestIdsModule(componentHierarchyMap, elementMetadata) {
|
|
|
4007
4041
|
});
|
|
4008
4042
|
});
|
|
4009
4043
|
}
|
|
4010
|
-
function generatePomManifestModule(componentHierarchyMap, elementMetadata, fileName = "virtual-pom-manifest.ts") {
|
|
4044
|
+
function generatePomManifestModule(componentHierarchyMap, elementMetadata, fileName = "virtual-pom-manifest.ts", renderCache) {
|
|
4011
4045
|
const pomManifest = buildPomManifest(componentHierarchyMap, elementMetadata);
|
|
4012
|
-
return
|
|
4013
|
-
|
|
4014
|
-
|
|
4046
|
+
return renderStructuredSourceFile(fileName, {
|
|
4047
|
+
statements: [{
|
|
4048
|
+
kind: tsMorph.StructureKind.VariableStatement,
|
|
4049
|
+
leadingTrivia: "// Rich POM discoverability manifest.\n",
|
|
4015
4050
|
declarationKind: tsMorph.VariableDeclarationKind.Const,
|
|
4016
4051
|
isExported: true,
|
|
4017
4052
|
declarations: [{
|
|
4018
4053
|
name: "pomManifest",
|
|
4019
4054
|
initializer: writeConstJson(pomManifest)
|
|
4020
4055
|
}]
|
|
4021
|
-
}
|
|
4022
|
-
|
|
4056
|
+
}, {
|
|
4057
|
+
kind: tsMorph.StructureKind.TypeAlias,
|
|
4023
4058
|
isExported: true,
|
|
4024
4059
|
name: "PomManifest",
|
|
4025
4060
|
type: "typeof pomManifest"
|
|
4026
|
-
}
|
|
4027
|
-
|
|
4061
|
+
}, {
|
|
4062
|
+
kind: tsMorph.StructureKind.TypeAlias,
|
|
4028
4063
|
isExported: true,
|
|
4029
4064
|
name: "PomManifestComponentName",
|
|
4030
4065
|
type: "keyof PomManifest"
|
|
4031
|
-
}
|
|
4032
|
-
});
|
|
4066
|
+
}]
|
|
4067
|
+
}, { cache: renderCache });
|
|
4068
|
+
}
|
|
4069
|
+
const manifestName = ".vue-pom-generator-outputs.json";
|
|
4070
|
+
function hash(content) {
|
|
4071
|
+
return node_crypto.createHash("sha256").update(content).digest("hex");
|
|
4072
|
+
}
|
|
4073
|
+
function readManifest(filePath) {
|
|
4074
|
+
if (!fs.existsSync(filePath)) {
|
|
4075
|
+
return { version: 1, files: {} };
|
|
4076
|
+
}
|
|
4077
|
+
const value = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
4078
|
+
if (!value || typeof value !== "object" || !("version" in value) || value.version !== 1 || !("files" in value) || !value.files || typeof value.files !== "object" || Array.isArray(value.files)) {
|
|
4079
|
+
throw new Error(`[vue-pom-generator] Invalid output ownership manifest: ${filePath}`);
|
|
4080
|
+
}
|
|
4081
|
+
for (const [name, digest] of Object.entries(value.files)) {
|
|
4082
|
+
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))) {
|
|
4083
|
+
throw new Error(`[vue-pom-generator] Invalid output ownership entry in ${filePath}: ${name}`);
|
|
4084
|
+
}
|
|
4085
|
+
}
|
|
4086
|
+
return value;
|
|
4087
|
+
}
|
|
4088
|
+
function assertRegularFile(filePath) {
|
|
4089
|
+
const entry = fs.lstatSync(filePath, { throwIfNoEntry: false });
|
|
4090
|
+
if (entry && !entry.isFile()) {
|
|
4091
|
+
throw new Error(`[vue-pom-generator] Refusing to replace or remove a non-regular output file: ${filePath}`);
|
|
4092
|
+
}
|
|
4093
|
+
}
|
|
4094
|
+
function assertNoSymlinkParents(filePath, outDir, projectRoot) {
|
|
4095
|
+
const relativeOutput = path.relative(projectRoot, outDir);
|
|
4096
|
+
let ancestor = relativeOutput === ".." || relativeOutput.startsWith(`..${path.sep}`) || path.isAbsolute(relativeOutput) ? path.dirname(outDir) : projectRoot;
|
|
4097
|
+
const targetDirectory = path.dirname(filePath);
|
|
4098
|
+
while (path.relative(ancestor, targetDirectory) === ".." || path.relative(ancestor, targetDirectory).startsWith(`..${path.sep}`) || path.isAbsolute(path.relative(ancestor, targetDirectory))) {
|
|
4099
|
+
const parent = path.dirname(ancestor);
|
|
4100
|
+
if (parent === ancestor) {
|
|
4101
|
+
throw new Error(`[vue-pom-generator] Output must be on the same filesystem volume as its manifest: ${filePath}`);
|
|
4102
|
+
}
|
|
4103
|
+
ancestor = parent;
|
|
4104
|
+
}
|
|
4105
|
+
for (const target of [path.dirname(filePath), outDir]) {
|
|
4106
|
+
let directory = target;
|
|
4107
|
+
while (directory !== ancestor) {
|
|
4108
|
+
if (fs.lstatSync(directory, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
4109
|
+
throw new Error(`[vue-pom-generator] Refusing to follow an output directory symlink: ${directory}`);
|
|
4110
|
+
}
|
|
4111
|
+
directory = path.dirname(directory);
|
|
4112
|
+
}
|
|
4113
|
+
}
|
|
4114
|
+
}
|
|
4115
|
+
function writeFile(filePath, content) {
|
|
4116
|
+
if (fs.existsSync(filePath) && fs.readFileSync(filePath, "utf8") === content) return;
|
|
4117
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
4118
|
+
const temporaryPath = `${filePath}.${node_crypto.randomUUID()}.tmp`;
|
|
4119
|
+
try {
|
|
4120
|
+
fs.writeFileSync(temporaryPath, content, { flag: "wx" });
|
|
4121
|
+
fs.renameSync(temporaryPath, filePath);
|
|
4122
|
+
} finally {
|
|
4123
|
+
if (fs.existsSync(temporaryPath)) {
|
|
4124
|
+
fs.unlinkSync(temporaryPath);
|
|
4125
|
+
}
|
|
4126
|
+
}
|
|
4127
|
+
}
|
|
4128
|
+
function writeGeneratedOutputs(outDir, files, sharedFiles, projectRoot = path.dirname(path.resolve(outDir))) {
|
|
4129
|
+
const root = path.resolve(outDir);
|
|
4130
|
+
const manifestPath = path.join(root, manifestName);
|
|
4131
|
+
assertNoSymlinkParents(manifestPath, root, projectRoot);
|
|
4132
|
+
assertRegularFile(manifestPath);
|
|
4133
|
+
const previous = readManifest(manifestPath);
|
|
4134
|
+
const next = { version: 1, files: {} };
|
|
4135
|
+
const contents = /* @__PURE__ */ new Map();
|
|
4136
|
+
for (const file of files) {
|
|
4137
|
+
const absolutePath = path.resolve(file.filePath);
|
|
4138
|
+
if (contents.has(absolutePath) || absolutePath === manifestPath) {
|
|
4139
|
+
throw new Error(`[vue-pom-generator] Duplicate generated output: ${absolutePath}`);
|
|
4140
|
+
}
|
|
4141
|
+
contents.set(absolutePath, file.content);
|
|
4142
|
+
next.files[path.relative(root, absolutePath).split(path.sep).join("/")] = hash(file.content);
|
|
4143
|
+
}
|
|
4144
|
+
const obsolete = [];
|
|
4145
|
+
for (const [name, digest] of Object.entries(previous.files)) {
|
|
4146
|
+
const absolutePath = path.resolve(root, name);
|
|
4147
|
+
if (contents.has(absolutePath)) continue;
|
|
4148
|
+
assertNoSymlinkParents(absolutePath, root, projectRoot);
|
|
4149
|
+
assertRegularFile(absolutePath);
|
|
4150
|
+
if (!fs.existsSync(absolutePath)) continue;
|
|
4151
|
+
if (hash(fs.readFileSync(absolutePath, "utf8")) !== digest) {
|
|
4152
|
+
throw new Error(`[vue-pom-generator] Obsolete generated file was modified; move or remove it explicitly before regenerating: ${absolutePath}`);
|
|
4153
|
+
}
|
|
4154
|
+
obsolete.push(absolutePath);
|
|
4155
|
+
}
|
|
4156
|
+
for (const file of sharedFiles) {
|
|
4157
|
+
contents.set(path.resolve(file.filePath), file.content);
|
|
4158
|
+
}
|
|
4159
|
+
for (const filePath of contents.keys()) {
|
|
4160
|
+
assertNoSymlinkParents(filePath, root, projectRoot);
|
|
4161
|
+
assertRegularFile(filePath);
|
|
4162
|
+
}
|
|
4163
|
+
for (const [filePath, content] of contents) writeFile(filePath, content);
|
|
4164
|
+
for (const filePath of obsolete) fs.unlinkSync(filePath);
|
|
4165
|
+
writeFile(manifestPath, `${JSON.stringify(next, null, 2)}
|
|
4166
|
+
`);
|
|
4033
4167
|
}
|
|
4034
4168
|
function safeRealpath(value) {
|
|
4035
4169
|
try {
|
|
@@ -5792,7 +5926,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5792
5926
|
const {
|
|
5793
5927
|
outDir: outDirOverride,
|
|
5794
5928
|
generateFixtures,
|
|
5795
|
-
vueTestUtilsOutDir,
|
|
5929
|
+
vueTestUtilsOutDir: vueTestUtilsOutDirOverride,
|
|
5796
5930
|
customPomAttachments = [],
|
|
5797
5931
|
projectRoot,
|
|
5798
5932
|
customPomDir,
|
|
@@ -5810,10 +5944,13 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5810
5944
|
componentDirs,
|
|
5811
5945
|
layoutDirs,
|
|
5812
5946
|
routeMetaByComponent: routeMetaByComponentOverride,
|
|
5813
|
-
elementMetadata = /* @__PURE__ */ new Map()
|
|
5947
|
+
elementMetadata = /* @__PURE__ */ new Map(),
|
|
5948
|
+
renderCache
|
|
5814
5949
|
} = options;
|
|
5815
5950
|
const emitLanguages = emitLanguagesOverride?.length ? emitLanguagesOverride : ["ts"];
|
|
5816
|
-
const
|
|
5951
|
+
const root = projectRoot ?? process.cwd();
|
|
5952
|
+
const outDir = path.resolve(root, outDirOverride ?? "./pom");
|
|
5953
|
+
const vueTestUtilsOutDir = vueTestUtilsOutDirOverride ? path.resolve(root, vueTestUtilsOutDirOverride) : void 0;
|
|
5817
5954
|
if (vueTestUtilsOutDir && path.resolve(vueTestUtilsOutDir) === path.resolve(outDir)) {
|
|
5818
5955
|
throw new Error("[vue-pom-generator] generation.vueTestUtils.outDir must differ from generation.outDir.");
|
|
5819
5956
|
}
|
|
@@ -5823,14 +5960,10 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5823
5960
|
layoutDirs
|
|
5824
5961
|
}) : void 0);
|
|
5825
5962
|
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
|
-
};
|
|
5963
|
+
const generatedFiles = [];
|
|
5832
5964
|
if (emitLanguages.includes("ts")) {
|
|
5833
5965
|
const files = typescriptOutputStructure === "split" ? await generateSplitTypeScriptFiles(emittableComponentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, {
|
|
5966
|
+
renderCache,
|
|
5834
5967
|
customPomAttachments,
|
|
5835
5968
|
projectRoot,
|
|
5836
5969
|
customPomDir,
|
|
@@ -5841,6 +5974,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5841
5974
|
routeMetaByComponent,
|
|
5842
5975
|
vueRouterFluentChaining
|
|
5843
5976
|
}) : await generateAggregatedFiles(emittableComponentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, {
|
|
5977
|
+
renderCache,
|
|
5844
5978
|
customPomAttachments,
|
|
5845
5979
|
projectRoot,
|
|
5846
5980
|
customPomDir,
|
|
@@ -5851,10 +5985,9 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5851
5985
|
routeMetaByComponent,
|
|
5852
5986
|
vueRouterFluentChaining
|
|
5853
5987
|
});
|
|
5854
|
-
|
|
5855
|
-
writeGeneratedFile(file);
|
|
5856
|
-
}
|
|
5988
|
+
generatedFiles.push(...files);
|
|
5857
5989
|
const fixtureRegistryFiles = maybeGenerateFixtureRegistry(emittableComponentHierarchyMap, {
|
|
5990
|
+
renderCache,
|
|
5858
5991
|
generateFixtures,
|
|
5859
5992
|
pomOutDir: outDir,
|
|
5860
5993
|
projectRoot,
|
|
@@ -5862,33 +5995,26 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5862
5995
|
elementMetadata,
|
|
5863
5996
|
testIdAttribute
|
|
5864
5997
|
});
|
|
5865
|
-
|
|
5866
|
-
writeGeneratedFile(fixtureRegistryFile);
|
|
5867
|
-
}
|
|
5998
|
+
generatedFiles.push(...fixtureRegistryFiles);
|
|
5868
5999
|
}
|
|
5869
6000
|
if (emitLanguages.includes("csharp")) {
|
|
5870
6001
|
const csFiles = generateAggregatedCSharpFiles(emittableComponentHierarchyMap, outDir, {
|
|
5871
6002
|
testIdAttribute,
|
|
5872
6003
|
csharp
|
|
5873
6004
|
});
|
|
5874
|
-
|
|
5875
|
-
writeGeneratedFile(file);
|
|
5876
|
-
}
|
|
6005
|
+
generatedFiles.push(...csFiles);
|
|
5877
6006
|
}
|
|
5878
6007
|
if (vueTestUtilsOutDir) {
|
|
5879
6008
|
const vueTestUtilsFiles = generateVueTestUtilsFiles(
|
|
5880
6009
|
emittableComponentHierarchyMap,
|
|
5881
6010
|
vueTestUtilsOutDir,
|
|
5882
|
-
{ testIdAttribute }
|
|
6011
|
+
{ testIdAttribute, renderCache }
|
|
5883
6012
|
);
|
|
5884
|
-
|
|
5885
|
-
writeGeneratedFile(file);
|
|
5886
|
-
}
|
|
5887
|
-
}
|
|
5888
|
-
const gitattributesFiles = buildGeneratedGitAttributesFiles(generatedFilePaths);
|
|
5889
|
-
for (const file of gitattributesFiles) {
|
|
5890
|
-
createFile(file.filePath, file.content);
|
|
6013
|
+
generatedFiles.push(...vueTestUtilsFiles);
|
|
5891
6014
|
}
|
|
6015
|
+
const gitattributesFiles = buildGeneratedGitAttributesFiles(generatedFiles.map((file) => file.filePath));
|
|
6016
|
+
writeGeneratedOutputs(outDir, generatedFiles, gitattributesFiles, path.resolve(root));
|
|
6017
|
+
renderCache?.retain(new Set(generatedFiles.map((file) => file.filePath)));
|
|
5892
6018
|
}
|
|
5893
6019
|
const VUE_TEST_UTILS_OMITTED_PARAMETERS = /* @__PURE__ */ new Set(["annotationText", "timeOut", "timeout", "wait"]);
|
|
5894
6020
|
function getVueTestUtilsParameters(parameters, patterns, options = {}) {
|
|
@@ -6016,7 +6142,7 @@ function getVueTestUtilsComponentMembers(componentInstances, projectedComponentI
|
|
|
6016
6142
|
}));
|
|
6017
6143
|
return members;
|
|
6018
6144
|
}
|
|
6019
|
-
function generateVueTestUtilsContent(componentName, dependencies, componentHierarchyMap, outputDir, runtimePath, generatedFilePathByComponent, testIdAttribute) {
|
|
6145
|
+
function generateVueTestUtilsContent(componentName, dependencies, componentHierarchyMap, outputDir, runtimePath, generatedFilePathByComponent, testIdAttribute, renderCache) {
|
|
6020
6146
|
const prepared = prepareViewObjectModelClass(componentName, dependencies, componentHierarchyMap, {
|
|
6021
6147
|
testIdAttribute
|
|
6022
6148
|
});
|
|
@@ -6036,33 +6162,29 @@ function generateVueTestUtilsContent(componentName, dependencies, componentHiera
|
|
|
6036
6162
|
...getUniquePrimaryPomSpecs(dependencies).flatMap(({ pom }) => getVueTestUtilsPrimaryMembers(pom)),
|
|
6037
6163
|
...(dependencies.pomExtraMethods ?? []).flatMap(getVueTestUtilsExtraMembers)
|
|
6038
6164
|
];
|
|
6039
|
-
return
|
|
6040
|
-
|
|
6165
|
+
return renderStructuredSourceFile(path.join(outputDir, `${componentName}.vtu.g.ts`), {
|
|
6166
|
+
statements: [{
|
|
6167
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
6041
6168
|
moduleSpecifier: runtimeImport,
|
|
6042
6169
|
namedImports: ["VueTestUtilsPom"]
|
|
6043
|
-
}
|
|
6044
|
-
|
|
6170
|
+
}, {
|
|
6171
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
6045
6172
|
moduleSpecifier: runtimeImport,
|
|
6046
6173
|
namedImports: ["VueTestUtilsPomRoot"],
|
|
6047
6174
|
isTypeOnly: true
|
|
6048
|
-
})
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
});
|
|
6054
|
-
}
|
|
6055
|
-
const declaration = sourceFile.addClass({
|
|
6175
|
+
}, ...componentImports.map((componentImport) => ({
|
|
6176
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
6177
|
+
moduleSpecifier: componentImport.moduleSpecifier,
|
|
6178
|
+
namedImports: [componentImport.className]
|
|
6179
|
+
})), createClassDeclaration({
|
|
6056
6180
|
name: prepared.className,
|
|
6057
6181
|
isExported: true,
|
|
6058
6182
|
extends: "VueTestUtilsPom",
|
|
6059
6183
|
docs: [`Vue Test Utils object for ${componentName} (source: ${sourceRel}).`]
|
|
6060
|
-
})
|
|
6061
|
-
for (const member of members) {
|
|
6062
|
-
addClassMember(declaration, member);
|
|
6063
|
-
}
|
|
6184
|
+
}, members)]
|
|
6064
6185
|
}, {
|
|
6065
|
-
prefixText: buildFilePrefix({ eslintDisableSortImports: true })
|
|
6186
|
+
prefixText: buildFilePrefix({ eslintDisableSortImports: true }),
|
|
6187
|
+
cache: renderCache
|
|
6066
6188
|
});
|
|
6067
6189
|
}
|
|
6068
6190
|
function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {}) {
|
|
@@ -6084,7 +6206,8 @@ function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {})
|
|
|
6084
6206
|
path.dirname(filePath),
|
|
6085
6207
|
runtimePath,
|
|
6086
6208
|
generatedFilePathByComponent,
|
|
6087
|
-
testIdAttribute
|
|
6209
|
+
testIdAttribute,
|
|
6210
|
+
options.renderCache
|
|
6088
6211
|
)
|
|
6089
6212
|
};
|
|
6090
6213
|
});
|
|
@@ -6096,12 +6219,13 @@ function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {})
|
|
|
6096
6219
|
if (!runtimeFile) {
|
|
6097
6220
|
throw new Error("[vue-pom-generator] Failed to generate the Vue Test Utils runtime.");
|
|
6098
6221
|
}
|
|
6099
|
-
const indexContent =
|
|
6100
|
-
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
}
|
|
6222
|
+
const indexContent = renderStructuredSourceFile(path.join(base, "index.ts"), {
|
|
6223
|
+
statements: [
|
|
6224
|
+
stripExtension(toPosixRelativePath(base, runtimePath)),
|
|
6225
|
+
...Array.from(generatedFilePathByComponent.values(), (filePath) => `./${stripExtension(path.basename(filePath))}`)
|
|
6226
|
+
].map((moduleSpecifier) => ({ kind: tsMorph.StructureKind.ExportDeclaration, moduleSpecifier }))
|
|
6104
6227
|
}, {
|
|
6228
|
+
cache: options.renderCache,
|
|
6105
6229
|
prefixText: buildFilePrefix({
|
|
6106
6230
|
eslintDisableSortImports: true,
|
|
6107
6231
|
commentLines: [
|
|
@@ -6155,6 +6279,7 @@ async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathM
|
|
|
6155
6279
|
continue;
|
|
6156
6280
|
}
|
|
6157
6281
|
const content = generateViewObjectModelContent(name, deps, componentHierarchyMap, vueFilesPathMap, runtimeBasePagePath, {
|
|
6282
|
+
renderCache: options.renderCache,
|
|
6158
6283
|
outputDir: path.dirname(filePath),
|
|
6159
6284
|
customPomAttachments: options.customPomAttachments ?? [],
|
|
6160
6285
|
projectRoot,
|
|
@@ -6182,6 +6307,8 @@ async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathM
|
|
|
6182
6307
|
const childImports = getChildImportSpecifiers(outputDir, composed?.childClassNames ?? [], generatedTsFilePathByComponent);
|
|
6183
6308
|
const members = composed?.members ?? getDefaultStubMembers();
|
|
6184
6309
|
const content = renderSplitStubPomContent({
|
|
6310
|
+
filePath,
|
|
6311
|
+
renderCache: options.renderCache,
|
|
6185
6312
|
className: targetClassName,
|
|
6186
6313
|
basePageImportSpecifier,
|
|
6187
6314
|
childImports,
|
|
@@ -6191,14 +6318,13 @@ async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathM
|
|
|
6191
6318
|
}
|
|
6192
6319
|
const runtimeAssetSpecs = getRuntimeGeneratedAssetSpecs(base, basePageClassPath);
|
|
6193
6320
|
const runtimeFiles = buildRuntimeGeneratedFilesFromSpecs(runtimeAssetSpecs);
|
|
6194
|
-
const indexContent =
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
addExportAll(sourceFile, `./${stripExtension(path.basename(filePath))}`);
|
|
6200
|
-
}
|
|
6321
|
+
const indexContent = renderStructuredSourceFile(path.join(base, "index.ts"), {
|
|
6322
|
+
statements: [
|
|
6323
|
+
...runtimeAssetSpecs.map((spec) => stripExtension(toPosixRelativePath(base, spec.outputPath))),
|
|
6324
|
+
...Array.from(generatedTsFilePathByComponent.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([, filePath]) => `./${stripExtension(path.basename(filePath))}`)
|
|
6325
|
+
].map((moduleSpecifier) => ({ kind: tsMorph.StructureKind.ExportDeclaration, moduleSpecifier }))
|
|
6201
6326
|
}, {
|
|
6327
|
+
cache: options.renderCache,
|
|
6202
6328
|
prefixText: buildFilePrefix({
|
|
6203
6329
|
eslintDisableSortImports: true,
|
|
6204
6330
|
commentLines: [
|
|
@@ -6874,7 +7000,8 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
6874
7000
|
const manifestContent = generatePomManifestModule(
|
|
6875
7001
|
componentHierarchyMap,
|
|
6876
7002
|
options.elementMetadata,
|
|
6877
|
-
manifestFileName
|
|
7003
|
+
path.resolve(fixtureOutDirAbs, manifestFileName),
|
|
7004
|
+
options.renderCache
|
|
6878
7005
|
);
|
|
6879
7006
|
const [diagnosticsRuntimeFile] = buildRuntimeGeneratedFilesFromSpecs([{
|
|
6880
7007
|
absolutePath: resolvePluginAsset("../class-generation/diagnostics.ts"),
|
|
@@ -7222,40 +7349,33 @@ function generateViewObjectModelContent(componentName, dependencies, componentHi
|
|
|
7222
7349
|
generatedImports.sort((a, b) => a.className.localeCompare(b.className));
|
|
7223
7350
|
const prefixText = `${buildFilePrefix({ eslintDisableSortImports: true })}${doc}
|
|
7224
7351
|
`;
|
|
7225
|
-
return
|
|
7226
|
-
|
|
7352
|
+
return renderStructuredSourceFile(path.join(outputDir, `${componentName}.g.ts`), {
|
|
7353
|
+
statements: [{
|
|
7354
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7227
7355
|
moduleSpecifier: "@playwright/test",
|
|
7228
7356
|
isTypeOnly: true,
|
|
7229
7357
|
namedImports: [
|
|
7230
7358
|
{ name: "Locator", alias: "PwLocator" },
|
|
7231
7359
|
{ name: "Page", alias: "PwPage" }
|
|
7232
7360
|
]
|
|
7233
|
-
}
|
|
7234
|
-
|
|
7361
|
+
}, {
|
|
7362
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7235
7363
|
moduleSpecifier: basePageImportSpecifier,
|
|
7236
7364
|
namedImports: ["BasePage", "Fluent"]
|
|
7237
|
-
})
|
|
7238
|
-
|
|
7239
|
-
|
|
7240
|
-
|
|
7241
|
-
|
|
7242
|
-
|
|
7243
|
-
|
|
7244
|
-
|
|
7245
|
-
|
|
7246
|
-
moduleSpecifier: generatedImport.moduleSpecifier,
|
|
7247
|
-
namedImports: [generatedImport.className]
|
|
7248
|
-
});
|
|
7249
|
-
}
|
|
7250
|
-
const classDeclaration = sourceFile.addClass({
|
|
7365
|
+
}, ...customImports.map((customImport) => ({
|
|
7366
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7367
|
+
moduleSpecifier: customImport.moduleSpecifier,
|
|
7368
|
+
namedImports: [{ name: customImport.name, alias: customImport.alias }]
|
|
7369
|
+
})), ...generatedImports.map((generatedImport) => ({
|
|
7370
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7371
|
+
moduleSpecifier: generatedImport.moduleSpecifier,
|
|
7372
|
+
namedImports: [generatedImport.className]
|
|
7373
|
+
})), createClassDeclaration({
|
|
7251
7374
|
name: prepared.className,
|
|
7252
7375
|
isExported: true,
|
|
7253
7376
|
extends: "BasePage"
|
|
7254
|
-
})
|
|
7255
|
-
|
|
7256
|
-
addClassMember(classDeclaration, member);
|
|
7257
|
-
}
|
|
7258
|
-
}, { prefixText });
|
|
7377
|
+
}, prepared.members)]
|
|
7378
|
+
}, { prefixText, cache: options.renderCache });
|
|
7259
7379
|
}
|
|
7260
7380
|
function getViewPassthroughMethods(viewName, viewDependencies, componentInstances, componentHierarchyMap, blockedMethodNames = /* @__PURE__ */ new Set()) {
|
|
7261
7381
|
const existingOnView = viewDependencies.generatedMethods ?? /* @__PURE__ */ new Map();
|
|
@@ -7476,35 +7596,32 @@ function renderSplitStubPomContent(options) {
|
|
|
7476
7596
|
"Changes should be made in the generator/template, not in the generated output."
|
|
7477
7597
|
]
|
|
7478
7598
|
});
|
|
7479
|
-
return
|
|
7480
|
-
|
|
7599
|
+
return renderStructuredSourceFile(options.filePath, {
|
|
7600
|
+
// Stub ctors take Playwright's full `Page` (aliased `PwPage`), matching non-stub generated
|
|
7601
|
+
// POMs — stubs are constructed with `new Stub(this.page)` where `this.page` is `Page`.
|
|
7602
|
+
statements: [{
|
|
7603
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7481
7604
|
moduleSpecifier: "@playwright/test",
|
|
7482
7605
|
isTypeOnly: true,
|
|
7483
7606
|
namedImports: [{ name: "Page", alias: "PwPage" }]
|
|
7484
|
-
}
|
|
7485
|
-
|
|
7607
|
+
}, {
|
|
7608
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7486
7609
|
moduleSpecifier: options.basePageImportSpecifier,
|
|
7487
7610
|
namedImports: ["BasePage"]
|
|
7488
|
-
})
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
|
|
7492
|
-
|
|
7493
|
-
});
|
|
7494
|
-
}
|
|
7495
|
-
sourceFile.addStatements(buildCommentBlock([
|
|
7496
|
-
"Stub POM generated because it is referenced as a navigation target but",
|
|
7497
|
-
"did not have any generated test ids in this build."
|
|
7498
|
-
]).trimEnd());
|
|
7499
|
-
const classDeclaration = sourceFile.addClass({
|
|
7611
|
+
}, ...options.childImports.map((childImport) => ({
|
|
7612
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7613
|
+
moduleSpecifier: childImport.importPath,
|
|
7614
|
+
namedImports: [childImport.className]
|
|
7615
|
+
})), createClassDeclaration({
|
|
7500
7616
|
name: options.className,
|
|
7501
7617
|
isExported: true,
|
|
7502
|
-
extends: "BasePage"
|
|
7503
|
-
|
|
7504
|
-
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
7618
|
+
extends: "BasePage",
|
|
7619
|
+
leadingTrivia: buildCommentBlock([
|
|
7620
|
+
"Stub POM generated because it is referenced as a navigation target but",
|
|
7621
|
+
"did not have any generated test ids in this build."
|
|
7622
|
+
])
|
|
7623
|
+
}, options.members)]
|
|
7624
|
+
}, { prefixText, cache: options.renderCache });
|
|
7508
7625
|
}
|
|
7509
7626
|
function getChildImportSpecifiers(outputDir, childClassNames, generatedTsFilePathByComponent) {
|
|
7510
7627
|
return childClassNames.map((childClassName) => {
|
|
@@ -7518,37 +7635,6 @@ function getChildImportSpecifiers(outputDir, childClassNames, generatedTsFilePat
|
|
|
7518
7635
|
};
|
|
7519
7636
|
}).filter((entry) => !!entry).sort((a, b) => a.className.localeCompare(b.className));
|
|
7520
7637
|
}
|
|
7521
|
-
function isConstructorMember(member) {
|
|
7522
|
-
return member.kind === tsMorph.StructureKind.Constructor;
|
|
7523
|
-
}
|
|
7524
|
-
function isGetterMember(member) {
|
|
7525
|
-
return member.kind === tsMorph.StructureKind.GetAccessor;
|
|
7526
|
-
}
|
|
7527
|
-
function isMethodMember(member) {
|
|
7528
|
-
return member.kind === tsMorph.StructureKind.Method;
|
|
7529
|
-
}
|
|
7530
|
-
function isPropertyMember(member) {
|
|
7531
|
-
return member.kind === tsMorph.StructureKind.Property;
|
|
7532
|
-
}
|
|
7533
|
-
function addClassMember(classDeclaration, member) {
|
|
7534
|
-
if (isConstructorMember(member)) {
|
|
7535
|
-
classDeclaration.addConstructor(member);
|
|
7536
|
-
return;
|
|
7537
|
-
}
|
|
7538
|
-
if (isGetterMember(member)) {
|
|
7539
|
-
classDeclaration.addGetAccessor(member);
|
|
7540
|
-
return;
|
|
7541
|
-
}
|
|
7542
|
-
if (isMethodMember(member)) {
|
|
7543
|
-
classDeclaration.addMethod(member);
|
|
7544
|
-
return;
|
|
7545
|
-
}
|
|
7546
|
-
if (isPropertyMember(member)) {
|
|
7547
|
-
classDeclaration.addProperty(member);
|
|
7548
|
-
return;
|
|
7549
|
-
}
|
|
7550
|
-
throw new Error(`Unsupported class member structure: ${String(member)}`);
|
|
7551
|
-
}
|
|
7552
7638
|
function getRuntimeGeneratedAssetSpecs(baseDir, basePageClassPath) {
|
|
7553
7639
|
const runtimeDirAbs = path.join(baseDir, "_pom-runtime");
|
|
7554
7640
|
const runtimeClassGenAbs = path.join(runtimeDirAbs, "class-generation");
|
|
@@ -7826,37 +7912,30 @@ async function generateAggregatedFiles(componentHierarchyMap, vueFilesPathMap, b
|
|
|
7826
7912
|
"Changes should be made in the generator/template, not in the generated output."
|
|
7827
7913
|
]
|
|
7828
7914
|
});
|
|
7829
|
-
return
|
|
7830
|
-
|
|
7831
|
-
|
|
7832
|
-
|
|
7833
|
-
for (const entry of [...classes, ...stubs]) {
|
|
7834
|
-
if (entry.isStub) {
|
|
7835
|
-
sourceFile.addStatements(buildCommentBlock([
|
|
7836
|
-
"Stub POM generated because it is referenced as a navigation target but",
|
|
7837
|
-
"did not have any generated test ids in this build."
|
|
7838
|
-
]).trimEnd());
|
|
7839
|
-
} else {
|
|
7840
|
-
sourceFile.addStatements(entry.doc);
|
|
7841
|
-
}
|
|
7842
|
-
const classDeclaration = sourceFile.addClass({
|
|
7915
|
+
return renderStructuredSourceFile(path.join(outputDir, "page-object-models.g.ts"), {
|
|
7916
|
+
statements: [
|
|
7917
|
+
...imports,
|
|
7918
|
+
...[...classes, ...stubs].map((entry) => createClassDeclaration({
|
|
7843
7919
|
name: entry.className,
|
|
7844
7920
|
isExported: true,
|
|
7845
|
-
extends: "BasePage"
|
|
7846
|
-
|
|
7847
|
-
|
|
7848
|
-
|
|
7849
|
-
|
|
7850
|
-
|
|
7851
|
-
|
|
7921
|
+
extends: "BasePage",
|
|
7922
|
+
leadingTrivia: entry.isStub ? buildCommentBlock([
|
|
7923
|
+
"Stub POM generated because it is referenced as a navigation target but",
|
|
7924
|
+
"did not have any generated test ids in this build."
|
|
7925
|
+
]) : `${entry.doc}
|
|
7926
|
+
`
|
|
7927
|
+
}, entry.members))
|
|
7928
|
+
]
|
|
7929
|
+
}, { prefixText, cache: options.renderCache });
|
|
7852
7930
|
};
|
|
7853
7931
|
const base = ensureDir(outDir);
|
|
7854
7932
|
const outputFile = path.join(base, "page-object-models.g.ts");
|
|
7855
7933
|
const content = makeAggregatedContent(path.dirname(outputFile), [...views, ...components]);
|
|
7856
7934
|
const indexFile = path.join(base, "index.ts");
|
|
7857
|
-
const indexContent =
|
|
7858
|
-
|
|
7935
|
+
const indexContent = renderStructuredSourceFile(indexFile, {
|
|
7936
|
+
statements: [{ kind: tsMorph.StructureKind.ExportDeclaration, moduleSpecifier: "./page-object-models.g" }]
|
|
7859
7937
|
}, {
|
|
7938
|
+
cache: options.renderCache,
|
|
7860
7939
|
prefixText: buildFilePrefix({
|
|
7861
7940
|
eslintDisableSortImports: true,
|
|
7862
7941
|
commentLines: [
|
|
@@ -7875,16 +7954,6 @@ async function generateAggregatedFiles(componentHierarchyMap, vueFilesPathMap, b
|
|
|
7875
7954
|
...runtimeFiles
|
|
7876
7955
|
];
|
|
7877
7956
|
}
|
|
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
7957
|
function lowerFirst(value) {
|
|
7889
7958
|
if (!value)
|
|
7890
7959
|
return value;
|
|
@@ -8048,108 +8117,331 @@ function getConstructor(componentInstances, attachmentsForThisView = [], widgetI
|
|
|
8048
8117
|
}
|
|
8049
8118
|
});
|
|
8050
8119
|
}
|
|
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 += "-";
|
|
8120
|
+
function summarizeHierarchyMap(componentHierarchyMap) {
|
|
8121
|
+
let interactiveComponentCount = 0;
|
|
8122
|
+
let dataTestIdCount = 0;
|
|
8123
|
+
for (const dependencies of componentHierarchyMap.values()) {
|
|
8124
|
+
const selectorCount = dependencies.dataTestIdSet?.size ?? 0;
|
|
8125
|
+
if (selectorCount > 0) {
|
|
8126
|
+
interactiveComponentCount += 1;
|
|
8127
|
+
dataTestIdCount += selectorCount;
|
|
8081
8128
|
}
|
|
8082
|
-
result += ch.toLowerCase();
|
|
8083
|
-
previousWasSeparator = false;
|
|
8084
8129
|
}
|
|
8085
|
-
return
|
|
8130
|
+
return {
|
|
8131
|
+
entryCount: componentHierarchyMap.size,
|
|
8132
|
+
interactiveComponentCount,
|
|
8133
|
+
dataTestIdCount
|
|
8134
|
+
};
|
|
8086
8135
|
}
|
|
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
|
-
}
|
|
8136
|
+
function isLessRich(candidate, previous) {
|
|
8137
|
+
if (candidate.dataTestIdCount !== previous.dataTestIdCount) {
|
|
8138
|
+
return candidate.dataTestIdCount < previous.dataTestIdCount;
|
|
8099
8139
|
}
|
|
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;
|
|
8140
|
+
if (candidate.interactiveComponentCount !== previous.interactiveComponentCount) {
|
|
8141
|
+
return candidate.interactiveComponentCount < previous.interactiveComponentCount;
|
|
8110
8142
|
}
|
|
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
|
-
|
|
8147
|
-
|
|
8148
|
-
|
|
8149
|
-
|
|
8150
|
-
|
|
8151
|
-
|
|
8152
|
-
|
|
8143
|
+
return candidate.entryCount < previous.entryCount;
|
|
8144
|
+
}
|
|
8145
|
+
function createBuildProcessorPlugin(options) {
|
|
8146
|
+
const {
|
|
8147
|
+
componentHierarchyMap,
|
|
8148
|
+
elementMetadata,
|
|
8149
|
+
vueFilesPathMap,
|
|
8150
|
+
getPageDirs,
|
|
8151
|
+
getComponentDirs,
|
|
8152
|
+
getLayoutDirs,
|
|
8153
|
+
getViewsDir,
|
|
8154
|
+
getSourceDirs,
|
|
8155
|
+
basePageClassPath,
|
|
8156
|
+
normalizedBasePagePath,
|
|
8157
|
+
generation,
|
|
8158
|
+
projectRootRef,
|
|
8159
|
+
collectSource,
|
|
8160
|
+
generationOnly,
|
|
8161
|
+
getResolvedRouterEntry,
|
|
8162
|
+
loggerRef
|
|
8163
|
+
} = options;
|
|
8164
|
+
const {
|
|
8165
|
+
outDir,
|
|
8166
|
+
emitLanguages,
|
|
8167
|
+
typescriptOutputStructure,
|
|
8168
|
+
csharp,
|
|
8169
|
+
generateFixtures,
|
|
8170
|
+
vueTestUtilsOutDir,
|
|
8171
|
+
customPomAttachments,
|
|
8172
|
+
customPomDir,
|
|
8173
|
+
requireCustomPomDir,
|
|
8174
|
+
customPomImportAliases,
|
|
8175
|
+
customPomImportNameCollisionBehavior,
|
|
8176
|
+
testIdAttribute,
|
|
8177
|
+
routerAwarePoms,
|
|
8178
|
+
routerType,
|
|
8179
|
+
routerModuleShims
|
|
8180
|
+
} = generation;
|
|
8181
|
+
let lastGeneratedMetrics = {
|
|
8182
|
+
entryCount: 0,
|
|
8183
|
+
interactiveComponentCount: 0,
|
|
8184
|
+
dataTestIdCount: 0
|
|
8185
|
+
};
|
|
8186
|
+
const getViewsDirAbs = () => path.isAbsolute(getViewsDir()) ? getViewsDir() : path.resolve(projectRootRef.current, getViewsDir());
|
|
8187
|
+
const getPageDirsAbs = () => getPageDirs().map((dir) => path.isAbsolute(dir) ? dir : path.resolve(projectRootRef.current, dir));
|
|
8188
|
+
const supplementHierarchyFromFilesystem = async () => {
|
|
8189
|
+
const walkFilesRecursive = (rootDir) => {
|
|
8190
|
+
const out = [];
|
|
8191
|
+
const stack = [rootDir];
|
|
8192
|
+
while (stack.length) {
|
|
8193
|
+
const dir = stack.pop();
|
|
8194
|
+
if (!dir) continue;
|
|
8195
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
8196
|
+
for (const ent of entries) {
|
|
8197
|
+
if (ent.isDirectory()) {
|
|
8198
|
+
if (ent.name === "node_modules" || ent.name === ".git" || ent.name === "dist")
|
|
8199
|
+
continue;
|
|
8200
|
+
stack.push(path.join(dir, ent.name));
|
|
8201
|
+
continue;
|
|
8202
|
+
}
|
|
8203
|
+
if (ent.isFile() && ent.name.endsWith(".vue")) {
|
|
8204
|
+
out.push(path.join(dir, ent.name));
|
|
8205
|
+
}
|
|
8206
|
+
}
|
|
8207
|
+
}
|
|
8208
|
+
return out;
|
|
8209
|
+
};
|
|
8210
|
+
let supplemented = 0;
|
|
8211
|
+
let sourceDirectories = 0;
|
|
8212
|
+
for (const dir of getSourceDirs()) {
|
|
8213
|
+
const absDir = path.resolve(projectRootRef.current, dir);
|
|
8214
|
+
if (!fs.existsSync(absDir))
|
|
8215
|
+
continue;
|
|
8216
|
+
sourceDirectories++;
|
|
8217
|
+
for (const filePath of walkFilesRecursive(absDir)) {
|
|
8218
|
+
const absolutePath = path.resolve(filePath);
|
|
8219
|
+
const componentName = resolveComponentNameFromPath({
|
|
8220
|
+
filename: absolutePath,
|
|
8221
|
+
projectRoot: projectRootRef.current,
|
|
8222
|
+
viewsDirAbs: getViewsDirAbs(),
|
|
8223
|
+
sourceDirs: getSourceDirs(),
|
|
8224
|
+
extraRoots: [process.cwd()]
|
|
8225
|
+
});
|
|
8226
|
+
if (componentHierarchyMap.has(componentName))
|
|
8227
|
+
continue;
|
|
8228
|
+
await collectSource(fs.readFileSync(absolutePath, "utf8"), absolutePath);
|
|
8229
|
+
supplemented++;
|
|
8230
|
+
}
|
|
8231
|
+
}
|
|
8232
|
+
if (generationOnly && sourceDirectories === 0) {
|
|
8233
|
+
throw new Error("[vue-pom-generator] No configured source directories exist. Check the Vite root and injection directories.");
|
|
8234
|
+
}
|
|
8235
|
+
if (supplemented > 0) {
|
|
8236
|
+
loggerRef.current.info(`supplemented ${supplemented} components from filesystem walk (not in build graph)`);
|
|
8237
|
+
}
|
|
8238
|
+
};
|
|
8239
|
+
return {
|
|
8240
|
+
name: "vue-pom-generator-build",
|
|
8241
|
+
// This plugin exists to generate code on build output; it is not needed during dev-server HMR.
|
|
8242
|
+
apply: "build",
|
|
8243
|
+
enforce: "pre",
|
|
8244
|
+
async buildStart() {
|
|
8245
|
+
if (!routerAwarePoms) {
|
|
8246
|
+
setRouteNameToComponentNameMap(/* @__PURE__ */ new Map());
|
|
8247
|
+
setResolveToComponentNameFn(() => null);
|
|
8248
|
+
return;
|
|
8249
|
+
}
|
|
8250
|
+
let result;
|
|
8251
|
+
if (routerType === "nuxt") {
|
|
8252
|
+
result = await introspectNuxtPages(projectRootRef.current, { pageDirs: getPageDirsAbs() });
|
|
8253
|
+
} else {
|
|
8254
|
+
const resolvedRouterEntry = getResolvedRouterEntry();
|
|
8255
|
+
if (!resolvedRouterEntry)
|
|
8256
|
+
throw new Error("[vue-pom-generator] router.entry is required when router introspection is enabled.");
|
|
8257
|
+
result = await parseRouterFileFromCwd(resolvedRouterEntry, {
|
|
8258
|
+
moduleShims: routerModuleShims,
|
|
8259
|
+
componentNaming: {
|
|
8260
|
+
projectRoot: projectRootRef.current,
|
|
8261
|
+
viewsDirAbs: getViewsDirAbs(),
|
|
8262
|
+
sourceDirs: getSourceDirs()
|
|
8263
|
+
}
|
|
8264
|
+
});
|
|
8265
|
+
}
|
|
8266
|
+
const { routeNameMap, routePathMap } = result;
|
|
8267
|
+
setRouteNameToComponentNameMap(routeNameMap);
|
|
8268
|
+
setResolveToComponentNameFn((to) => {
|
|
8269
|
+
if (typeof to === "string") {
|
|
8270
|
+
return routePathMap.get(to) ?? null;
|
|
8271
|
+
}
|
|
8272
|
+
const maybe = to;
|
|
8273
|
+
if (typeof maybe.name === "string" && maybe.name.length) {
|
|
8274
|
+
const key = toPascalCase(maybe.name);
|
|
8275
|
+
return routeNameMap.get(key) ?? null;
|
|
8276
|
+
}
|
|
8277
|
+
if (typeof maybe.path === "string" && maybe.path.length) {
|
|
8278
|
+
return routePathMap.get(maybe.path) ?? null;
|
|
8279
|
+
}
|
|
8280
|
+
return null;
|
|
8281
|
+
});
|
|
8282
|
+
if (!fs.existsSync(basePageClassPath)) {
|
|
8283
|
+
this.error(`Base page runtime file not found at ${basePageClassPath}. Ensure it is included in the build.`);
|
|
8284
|
+
}
|
|
8285
|
+
this.addWatchFile(basePageClassPath);
|
|
8286
|
+
const pointerPath = path.resolve(path.dirname(basePageClassPath), "pointer.ts");
|
|
8287
|
+
if (!fs.existsSync(pointerPath)) {
|
|
8288
|
+
this.error(`pointer.ts not found at ${pointerPath}. Ensure it is included in the build.`);
|
|
8289
|
+
}
|
|
8290
|
+
this.addWatchFile(pointerPath);
|
|
8291
|
+
const calloutPath = path.resolve(path.dirname(basePageClassPath), "callout.ts");
|
|
8292
|
+
if (!fs.existsSync(calloutPath)) {
|
|
8293
|
+
this.error(`callout.ts not found at ${calloutPath}. Ensure it is included in the build.`);
|
|
8294
|
+
}
|
|
8295
|
+
this.addWatchFile(calloutPath);
|
|
8296
|
+
const floatingUiCalloutPath = path.resolve(path.dirname(basePageClassPath), "floating-ui-callout.ts");
|
|
8297
|
+
if (fs.existsSync(floatingUiCalloutPath)) {
|
|
8298
|
+
this.addWatchFile(floatingUiCalloutPath);
|
|
8299
|
+
}
|
|
8300
|
+
},
|
|
8301
|
+
async buildEnd(error) {
|
|
8302
|
+
if (error) {
|
|
8303
|
+
return;
|
|
8304
|
+
}
|
|
8305
|
+
await supplementHierarchyFromFilesystem();
|
|
8306
|
+
const metrics = summarizeHierarchyMap(componentHierarchyMap);
|
|
8307
|
+
if (!generationOnly && metrics.dataTestIdCount <= 0) {
|
|
8308
|
+
return;
|
|
8309
|
+
}
|
|
8310
|
+
if (!generationOnly && isLessRich(metrics, lastGeneratedMetrics)) {
|
|
8311
|
+
return;
|
|
8312
|
+
}
|
|
8313
|
+
await generateFiles(componentHierarchyMap, vueFilesPathMap, normalizedBasePagePath, {
|
|
8314
|
+
outDir,
|
|
8315
|
+
emitLanguages,
|
|
8316
|
+
typescriptOutputStructure,
|
|
8317
|
+
csharp,
|
|
8318
|
+
generateFixtures,
|
|
8319
|
+
vueTestUtilsOutDir,
|
|
8320
|
+
customPomAttachments,
|
|
8321
|
+
projectRoot: projectRootRef.current,
|
|
8322
|
+
customPomDir,
|
|
8323
|
+
requireCustomPomDir,
|
|
8324
|
+
customPomImportAliases,
|
|
8325
|
+
customPomImportNameCollisionBehavior,
|
|
8326
|
+
testIdAttribute,
|
|
8327
|
+
vueRouterFluentChaining: routerAwarePoms,
|
|
8328
|
+
routerEntry: getResolvedRouterEntry(),
|
|
8329
|
+
routerType,
|
|
8330
|
+
pageDirs: getPageDirs(),
|
|
8331
|
+
componentDirs: getComponentDirs(),
|
|
8332
|
+
layoutDirs: getLayoutDirs(),
|
|
8333
|
+
elementMetadata
|
|
8334
|
+
});
|
|
8335
|
+
lastGeneratedMetrics = metrics;
|
|
8336
|
+
loggerRef.current.info(`generated POMs (${metrics.entryCount} entries, ${metrics.interactiveComponentCount} interactive components, ${metrics.dataTestIdCount} selectors)`);
|
|
8337
|
+
},
|
|
8338
|
+
closeBundle() {
|
|
8339
|
+
loggerRef.current.info("build complete");
|
|
8340
|
+
}
|
|
8341
|
+
};
|
|
8342
|
+
}
|
|
8343
|
+
const TESTID_CLICK_EVENT_NAME = "__testid_event__";
|
|
8344
|
+
const indexedVueSfcPathsByRoots = /* @__PURE__ */ new Map();
|
|
8345
|
+
const resolvedSfcPathByLookup = /* @__PURE__ */ new Map();
|
|
8346
|
+
function isAsciiUppercaseLetterCode(code) {
|
|
8347
|
+
return code >= 65 && code <= 90;
|
|
8348
|
+
}
|
|
8349
|
+
function isAsciiLetterCode(code) {
|
|
8350
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
8351
|
+
}
|
|
8352
|
+
function isAsciiDigitCode(code) {
|
|
8353
|
+
return code >= 48 && code <= 57;
|
|
8354
|
+
}
|
|
8355
|
+
function toKebabCaseTag(tag) {
|
|
8356
|
+
let result = "";
|
|
8357
|
+
let previousWasSeparator = false;
|
|
8358
|
+
for (let i = 0; i < tag.length; i += 1) {
|
|
8359
|
+
const ch = tag[i];
|
|
8360
|
+
const code = ch.charCodeAt(0);
|
|
8361
|
+
if (ch === "_" || ch === "-" || ch === "." || ch === " " || ch === " " || ch === "\n" || ch === "\r") {
|
|
8362
|
+
if (result && !previousWasSeparator) {
|
|
8363
|
+
result += "-";
|
|
8364
|
+
}
|
|
8365
|
+
previousWasSeparator = true;
|
|
8366
|
+
continue;
|
|
8367
|
+
}
|
|
8368
|
+
const previous = i > 0 ? tag[i - 1] : "";
|
|
8369
|
+
const previousCode = previous ? previous.charCodeAt(0) : 0;
|
|
8370
|
+
const shouldInsertSeparator = i > 0 && isAsciiUppercaseLetterCode(code) && (isAsciiLetterCode(previousCode) || isAsciiDigitCode(previousCode)) && !previousWasSeparator;
|
|
8371
|
+
if (shouldInsertSeparator) {
|
|
8372
|
+
result += "-";
|
|
8373
|
+
}
|
|
8374
|
+
result += ch.toLowerCase();
|
|
8375
|
+
previousWasSeparator = false;
|
|
8376
|
+
}
|
|
8377
|
+
return result;
|
|
8378
|
+
}
|
|
8379
|
+
function normalizeWrapperSearchRoots(wrapperSearchRoots) {
|
|
8380
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
8381
|
+
for (const root of wrapperSearchRoots) {
|
|
8382
|
+
const resolved = path.resolve(root);
|
|
8383
|
+
try {
|
|
8384
|
+
if (!fs.existsSync(resolved) || !fs.statSync(resolved).isDirectory()) {
|
|
8385
|
+
continue;
|
|
8386
|
+
}
|
|
8387
|
+
normalized.add(path.normalize(fs.realpathSync(resolved)));
|
|
8388
|
+
} catch {
|
|
8389
|
+
continue;
|
|
8390
|
+
}
|
|
8391
|
+
}
|
|
8392
|
+
return [...normalized];
|
|
8393
|
+
}
|
|
8394
|
+
function buildSearchRootsKey(searchRoots) {
|
|
8395
|
+
return searchRoots.join("\n");
|
|
8396
|
+
}
|
|
8397
|
+
function buildVueSfcPathIndex(searchRoots) {
|
|
8398
|
+
const indexKey = buildSearchRootsKey(searchRoots);
|
|
8399
|
+
const existingIndex = indexedVueSfcPathsByRoots.get(indexKey);
|
|
8400
|
+
if (existingIndex) {
|
|
8401
|
+
return existingIndex;
|
|
8402
|
+
}
|
|
8403
|
+
const index = /* @__PURE__ */ new Map();
|
|
8404
|
+
const ignoredDirNames = /* @__PURE__ */ new Set([
|
|
8405
|
+
".git",
|
|
8406
|
+
".idea",
|
|
8407
|
+
".next",
|
|
8408
|
+
".nuxt",
|
|
8409
|
+
".output",
|
|
8410
|
+
".turbo",
|
|
8411
|
+
".yarn",
|
|
8412
|
+
"coverage",
|
|
8413
|
+
"dist",
|
|
8414
|
+
"build",
|
|
8415
|
+
"node_modules",
|
|
8416
|
+
"out",
|
|
8417
|
+
"tmp"
|
|
8418
|
+
]);
|
|
8419
|
+
const stack = [...searchRoots];
|
|
8420
|
+
const seenDirs = /* @__PURE__ */ new Set();
|
|
8421
|
+
while (stack.length > 0) {
|
|
8422
|
+
const dirPath = stack.pop();
|
|
8423
|
+
const normalizedDir = path.normalize(dirPath);
|
|
8424
|
+
if (seenDirs.has(normalizedDir)) {
|
|
8425
|
+
continue;
|
|
8426
|
+
}
|
|
8427
|
+
seenDirs.add(normalizedDir);
|
|
8428
|
+
let entries = [];
|
|
8429
|
+
try {
|
|
8430
|
+
entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
8431
|
+
} catch {
|
|
8432
|
+
continue;
|
|
8433
|
+
}
|
|
8434
|
+
for (const entry of entries) {
|
|
8435
|
+
const fullPath = path.join(dirPath, entry.name);
|
|
8436
|
+
if (entry.isDirectory()) {
|
|
8437
|
+
if (ignoredDirNames.has(entry.name) || entry.name.startsWith(".")) {
|
|
8438
|
+
continue;
|
|
8439
|
+
}
|
|
8440
|
+
stack.push(fullPath);
|
|
8441
|
+
continue;
|
|
8442
|
+
}
|
|
8443
|
+
if (!entry.isFile() || !entry.name.endsWith(".vue")) {
|
|
8444
|
+
continue;
|
|
8153
8445
|
}
|
|
8154
8446
|
const matches = index.get(entry.name) ?? [];
|
|
8155
8447
|
matches.push(fullPath);
|
|
@@ -10115,9 +10407,7 @@ function extractMetadataAfterTransform(ast, componentName, elementMetadata, sema
|
|
|
10115
10407
|
}
|
|
10116
10408
|
}
|
|
10117
10409
|
traverseNode(ast);
|
|
10118
|
-
|
|
10119
|
-
elementMetadata.set(componentName, componentMetadata);
|
|
10120
|
-
}
|
|
10410
|
+
elementMetadata.set(componentName, componentMetadata);
|
|
10121
10411
|
return componentMetadata;
|
|
10122
10412
|
}
|
|
10123
10413
|
function createVuePluginWithTestIds(options) {
|
|
@@ -10263,403 +10553,132 @@ function createVuePluginWithTestIds(options) {
|
|
|
10263
10553
|
crossFileKeyRegistry,
|
|
10264
10554
|
optionKeyAttribute
|
|
10265
10555
|
}
|
|
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
|
|
10556
|
+
);
|
|
10557
|
+
perFileTransform.set(componentName, transform);
|
|
10558
|
+
}
|
|
10559
|
+
return transform(node, context);
|
|
10560
|
+
}
|
|
10561
|
+
];
|
|
10441
10562
|
};
|
|
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 };
|
|
10563
|
+
const runtimeNodeTransform = (node, context) => {
|
|
10564
|
+
const filename = context.filename;
|
|
10565
|
+
if (!filename || !filename.endsWith(".vue") || !isFileInScope(filename)) {
|
|
10566
|
+
return;
|
|
10453
10567
|
}
|
|
10568
|
+
const transforms = getNodeTransforms(filename);
|
|
10569
|
+
const ourTransform = transforms[transforms.length - 1];
|
|
10570
|
+
return ourTransform(node, context);
|
|
10454
10571
|
};
|
|
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 {
|
|
10572
|
+
const templateCompilerOptions = {
|
|
10573
|
+
...userCompilerOptions,
|
|
10574
|
+
prefixIdentifiers: true,
|
|
10575
|
+
nodeTransforms: [
|
|
10576
|
+
...userNodeTransforms,
|
|
10577
|
+
runtimeNodeTransform
|
|
10578
|
+
]
|
|
10579
|
+
};
|
|
10580
|
+
const collectSource = async (code, cleanPath) => {
|
|
10581
|
+
const componentName = getComponentNameFromPath(cleanPath);
|
|
10582
|
+
loggerRef.current.debug(`Collecting metadata for ${cleanPath} (component: ${componentName})`);
|
|
10583
|
+
const compilerSfc2 = await import("@vue/compiler-sfc");
|
|
10584
|
+
const parse = resolveCompilerSfcParse(compilerSfc2);
|
|
10585
|
+
const { descriptor, errors } = parse(code, { filename: cleanPath });
|
|
10586
|
+
if (errors.length) {
|
|
10587
|
+
throw new Error(`[vue-pom-generator] Cannot parse ${cleanPath}: ${errors.map(String).join("\n")}`);
|
|
10588
|
+
}
|
|
10589
|
+
const script = descriptor.script || descriptor.scriptSetup ? compilerSfc2.compileScript(descriptor, { ...vueOptions?.script, id: cleanPath }) : void 0;
|
|
10590
|
+
if (descriptor.template) {
|
|
10591
|
+
const mergedExpressionPlugins = Array.from(
|
|
10592
|
+
/* @__PURE__ */ new Set([
|
|
10593
|
+
"typescript",
|
|
10594
|
+
...userCompilerOptions.expressionPlugins ?? []
|
|
10595
|
+
])
|
|
10596
|
+
);
|
|
10597
|
+
const compiled = compilerSfc2.compileTemplate({
|
|
10598
|
+
...userTemplate,
|
|
10599
|
+
id: cleanPath,
|
|
10600
|
+
filename: cleanPath,
|
|
10601
|
+
source: descriptor.template.content,
|
|
10602
|
+
ast: descriptor.template.ast,
|
|
10603
|
+
preprocessLang: descriptor.template.lang,
|
|
10604
|
+
compilerOptions: {
|
|
10605
|
+
...userCompilerOptions,
|
|
10606
|
+
prefixIdentifiers: true,
|
|
10607
|
+
inline: !!descriptor.scriptSetup,
|
|
10608
|
+
bindingMetadata: script?.bindings,
|
|
10609
|
+
expressionPlugins: mergedExpressionPlugins,
|
|
10610
|
+
nodeTransforms: getNodeTransforms(cleanPath, componentName)
|
|
10552
10611
|
}
|
|
10553
|
-
|
|
10612
|
+
});
|
|
10613
|
+
if (compiled.errors.length) {
|
|
10614
|
+
throw new Error(`[vue-pom-generator] Cannot compile ${cleanPath}: ${compiled.errors.map(String).join("\n")}`);
|
|
10554
10615
|
}
|
|
10555
|
-
|
|
10556
|
-
|
|
10557
|
-
|
|
10616
|
+
loggerRef.current.debug(`Metadata collected for ${cleanPath}`);
|
|
10617
|
+
} else {
|
|
10618
|
+
vueFilesPathMap.set(componentName, cleanPath);
|
|
10619
|
+
elementMetadata.delete(componentName);
|
|
10620
|
+
componentHierarchyMap.set(componentName, {
|
|
10621
|
+
filePath: cleanPath,
|
|
10622
|
+
childrenComponentSet: /* @__PURE__ */ new Set(),
|
|
10623
|
+
usedComponentSet: /* @__PURE__ */ new Set(),
|
|
10624
|
+
dataTestIdSet: /* @__PURE__ */ new Set(),
|
|
10625
|
+
isView: false,
|
|
10626
|
+
methodsContent: ""
|
|
10627
|
+
});
|
|
10558
10628
|
}
|
|
10559
10629
|
};
|
|
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",
|
|
10630
|
+
const metadataCollectorPlugin = {
|
|
10631
|
+
name: "vue-pom-generator-metadata-collector",
|
|
10564
10632
|
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;
|
|
10633
|
+
async transform(code, id) {
|
|
10634
|
+
if (!id.endsWith(".vue") || !isFileInScope(id)) return null;
|
|
10635
|
+
await collectSource(code, id);
|
|
10636
|
+
return null;
|
|
10637
|
+
}
|
|
10638
|
+
};
|
|
10639
|
+
const template = {
|
|
10640
|
+
...userTemplate,
|
|
10641
|
+
compilerOptions: templateCompilerOptions
|
|
10642
|
+
};
|
|
10643
|
+
const internalVuePlugin = vue({
|
|
10644
|
+
...vueOptions,
|
|
10645
|
+
template
|
|
10646
|
+
});
|
|
10647
|
+
const nuxtVueBridgePlugin = {
|
|
10648
|
+
name: "vue-pom-generator-nuxt-vue-bridge",
|
|
10649
|
+
apply: "serve",
|
|
10650
|
+
configResolved(config) {
|
|
10651
|
+
const viteVuePlugin = config.plugins.find((plugin) => {
|
|
10652
|
+
return typeof plugin === "object" && plugin !== null && "name" in plugin && plugin.name === "vite:vue" && "api" in plugin;
|
|
10602
10653
|
});
|
|
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;
|
|
10654
|
+
const api = viteVuePlugin?.api;
|
|
10655
|
+
if (!api) {
|
|
10656
|
+
throw new Error("[vue-pom-generator] Nuxt bridge could not find vite:vue plugin to patch.");
|
|
10630
10657
|
}
|
|
10631
|
-
|
|
10658
|
+
const currentOptions = api.options ?? {};
|
|
10659
|
+
const currentTemplate = currentOptions.template ?? {};
|
|
10660
|
+
const currentCompilerOptions = currentTemplate.compilerOptions ?? {};
|
|
10661
|
+
const currentNodeTransforms = currentCompilerOptions.nodeTransforms ?? [];
|
|
10662
|
+
if (currentNodeTransforms.includes(runtimeNodeTransform)) {
|
|
10632
10663
|
return;
|
|
10633
10664
|
}
|
|
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");
|
|
10665
|
+
api.options = {
|
|
10666
|
+
...currentOptions,
|
|
10667
|
+
template: {
|
|
10668
|
+
...currentTemplate,
|
|
10669
|
+
compilerOptions: {
|
|
10670
|
+
...currentCompilerOptions,
|
|
10671
|
+
prefixIdentifiers: true,
|
|
10672
|
+
nodeTransforms: [
|
|
10673
|
+
...currentNodeTransforms,
|
|
10674
|
+
runtimeNodeTransform
|
|
10675
|
+
]
|
|
10676
|
+
}
|
|
10677
|
+
}
|
|
10678
|
+
};
|
|
10661
10679
|
}
|
|
10662
10680
|
};
|
|
10681
|
+
return { metadataCollectorPlugin, internalVuePlugin, nuxtVueBridgePlugin, templateCompilerOptions, collectSource };
|
|
10663
10682
|
}
|
|
10664
10683
|
function createDevProcessorPlugin(options) {
|
|
10665
10684
|
const {
|
|
@@ -10733,6 +10752,7 @@ function createDevProcessorPlugin(options) {
|
|
|
10733
10752
|
scheduleVueFileRegen(ctx.file, "hmr");
|
|
10734
10753
|
},
|
|
10735
10754
|
async configureServer(server) {
|
|
10755
|
+
const renderCache = new TypeScriptRenderCache();
|
|
10736
10756
|
const getViewsDirAbs = () => resolveProjectPath(getViewsDir());
|
|
10737
10757
|
const getPageDirsAbs = () => getPageDirs().map((dir) => resolveProjectPath(dir));
|
|
10738
10758
|
const routerInitPromise = (async () => {
|
|
@@ -10940,6 +10960,7 @@ function createDevProcessorPlugin(options) {
|
|
|
10940
10960
|
const generateAggregatedFromSnapshot = async (logLabel) => {
|
|
10941
10961
|
const t0 = node_perf_hooks.performance.now();
|
|
10942
10962
|
await generateFiles(snapshotHierarchy, snapshotVuePathMap, normalizedBasePagePath, {
|
|
10963
|
+
renderCache,
|
|
10943
10964
|
outDir,
|
|
10944
10965
|
emitLanguages,
|
|
10945
10966
|
typescriptOutputStructure,
|
|
@@ -11237,7 +11258,6 @@ ${code}`,
|
|
|
11237
11258
|
function createInternalPlugins(options) {
|
|
11238
11259
|
const {
|
|
11239
11260
|
componentHierarchyMap,
|
|
11240
|
-
crossFileKeyRegistry,
|
|
11241
11261
|
elementMetadata,
|
|
11242
11262
|
vueFilesPathMap,
|
|
11243
11263
|
nativeWrappers,
|
|
@@ -11253,7 +11273,9 @@ function createInternalPlugins(options) {
|
|
|
11253
11273
|
projectRootRef,
|
|
11254
11274
|
basePageClassPath: basePageClassPathOverride,
|
|
11255
11275
|
loggerRef,
|
|
11256
|
-
annotatorRuntime
|
|
11276
|
+
annotatorRuntime,
|
|
11277
|
+
collectSource,
|
|
11278
|
+
generationOnly
|
|
11257
11279
|
} = options;
|
|
11258
11280
|
const {
|
|
11259
11281
|
routerAwarePoms,
|
|
@@ -11281,7 +11303,6 @@ function createInternalPlugins(options) {
|
|
|
11281
11303
|
const tsProcessor = createBuildProcessorPlugin({
|
|
11282
11304
|
componentHierarchyMap,
|
|
11283
11305
|
elementMetadata,
|
|
11284
|
-
crossFileKeyRegistry,
|
|
11285
11306
|
vueFilesPathMap,
|
|
11286
11307
|
getPageDirs,
|
|
11287
11308
|
getComponentDirs,
|
|
@@ -11292,10 +11313,8 @@ function createInternalPlugins(options) {
|
|
|
11292
11313
|
normalizedBasePagePath,
|
|
11293
11314
|
generation,
|
|
11294
11315
|
projectRootRef,
|
|
11295
|
-
|
|
11296
|
-
|
|
11297
|
-
skipTestIdGenerationInsideComponents,
|
|
11298
|
-
getWrapperSearchRoots,
|
|
11316
|
+
collectSource,
|
|
11317
|
+
generationOnly,
|
|
11299
11318
|
getResolvedRouterEntry: resolveRouterEntry2,
|
|
11300
11319
|
loggerRef
|
|
11301
11320
|
});
|
|
@@ -11457,16 +11476,19 @@ const sharedGeneratorStateRegistry = /* @__PURE__ */ new Map();
|
|
|
11457
11476
|
function toArray(value) {
|
|
11458
11477
|
return Array.isArray(value) ? value : [];
|
|
11459
11478
|
}
|
|
11479
|
+
function createGeneratorState() {
|
|
11480
|
+
return {
|
|
11481
|
+
elementMetadata: /* @__PURE__ */ new Map(),
|
|
11482
|
+
semanticNameMap: /* @__PURE__ */ new Map(),
|
|
11483
|
+
componentHierarchyMap: /* @__PURE__ */ new Map(),
|
|
11484
|
+
crossFileKeyRegistry: /* @__PURE__ */ new Map(),
|
|
11485
|
+
vueFilesPathMap: /* @__PURE__ */ new Map()
|
|
11486
|
+
};
|
|
11487
|
+
}
|
|
11460
11488
|
function getSharedGeneratorState(key) {
|
|
11461
11489
|
let state = sharedGeneratorStateRegistry.get(key);
|
|
11462
11490
|
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
|
-
};
|
|
11491
|
+
state = createGeneratorState();
|
|
11470
11492
|
sharedGeneratorStateRegistry.set(key, state);
|
|
11471
11493
|
}
|
|
11472
11494
|
return state;
|
|
@@ -11527,9 +11549,15 @@ function assertNotVitePluginInstance(options) {
|
|
|
11527
11549
|
);
|
|
11528
11550
|
}
|
|
11529
11551
|
function createVuePomGeneratorPlugins(options = {}) {
|
|
11552
|
+
return createGeneratorPlugins(options, false);
|
|
11553
|
+
}
|
|
11554
|
+
function createGeneratorPlugins(options, generationOnly, projectRoot = process.cwd()) {
|
|
11530
11555
|
assertNotVitePluginInstance(options);
|
|
11531
11556
|
const injection = options.injection ?? {};
|
|
11532
|
-
const isNuxt = detectNuxtProject(options,
|
|
11557
|
+
const isNuxt = detectNuxtProject(options, projectRoot);
|
|
11558
|
+
if (generationOnly && isNuxt) {
|
|
11559
|
+
throw new Error("[vue-pom-generator] generateVuePoms does not run Nuxt project preparation. Use the Nuxt Vite integration.");
|
|
11560
|
+
}
|
|
11533
11561
|
const generationSetting = options.generation;
|
|
11534
11562
|
const generationOptions = generationSetting === false ? null : generationSetting ?? {};
|
|
11535
11563
|
const generationEnabled = generationOptions !== null;
|
|
@@ -11615,7 +11643,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
11615
11643
|
]));
|
|
11616
11644
|
const getWrapperSearchRoots = () => resolvedInjectionOptionsRef.current.wrapperSearchRoots;
|
|
11617
11645
|
const sharedStateKey = JSON.stringify({
|
|
11618
|
-
cwd:
|
|
11646
|
+
cwd: projectRoot,
|
|
11619
11647
|
mode: isNuxt ? "nuxt" : "vue",
|
|
11620
11648
|
pageDirs: isNuxt ? null : getPageDirs(),
|
|
11621
11649
|
componentDirs: isNuxt ? null : getComponentDirs(),
|
|
@@ -11627,9 +11655,9 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
11627
11655
|
routerType: resolvedGenerationOptions.routerType,
|
|
11628
11656
|
vuePluginOwnership
|
|
11629
11657
|
});
|
|
11630
|
-
const sharedState = getSharedGeneratorState(sharedStateKey);
|
|
11658
|
+
const sharedState = generationOnly ? createGeneratorState() : getSharedGeneratorState(sharedStateKey);
|
|
11631
11659
|
let templateCompilerOptionsForResolvedPlugin;
|
|
11632
|
-
const projectRootRef = { current:
|
|
11660
|
+
const projectRootRef = { current: projectRoot };
|
|
11633
11661
|
const loggerRef = {
|
|
11634
11662
|
current: createLogger({ verbosity })
|
|
11635
11663
|
};
|
|
@@ -11693,7 +11721,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
11693
11721
|
...getWrapperSearchRoots()
|
|
11694
11722
|
].map((root) => resolveFromProjectRoot(projectRootRef.current, root))));
|
|
11695
11723
|
const { elementMetadata, semanticNameMap, componentHierarchyMap, crossFileKeyRegistry, vueFilesPathMap } = sharedState;
|
|
11696
|
-
const { metadataCollectorPlugin, internalVuePlugin, templateCompilerOptions } = createVuePluginWithTestIds({
|
|
11724
|
+
const { metadataCollectorPlugin, internalVuePlugin, templateCompilerOptions, collectSource } = createVuePluginWithTestIds({
|
|
11697
11725
|
vueOptions,
|
|
11698
11726
|
existingIdBehavior: resolvedGenerationOptions.existingIdBehavior,
|
|
11699
11727
|
nameCollisionBehavior: resolvedGenerationOptions.nameCollisionBehavior,
|
|
@@ -11721,7 +11749,6 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
11721
11749
|
templateCompilerOptionsForResolvedPlugin = templateCompilerOptions;
|
|
11722
11750
|
const internalPlugins = createInternalPlugins({
|
|
11723
11751
|
componentHierarchyMap,
|
|
11724
|
-
crossFileKeyRegistry,
|
|
11725
11752
|
elementMetadata,
|
|
11726
11753
|
vueFilesPathMap,
|
|
11727
11754
|
nativeWrappers,
|
|
@@ -11734,6 +11761,8 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
11734
11761
|
getSourceDirs,
|
|
11735
11762
|
getWrapperSearchRoots: getWrapperSearchRootsAbs,
|
|
11736
11763
|
generation: resolvedGenerationOptions,
|
|
11764
|
+
collectSource,
|
|
11765
|
+
generationOnly,
|
|
11737
11766
|
projectRootRef,
|
|
11738
11767
|
basePageClassPath: basePageClassPathOverride,
|
|
11739
11768
|
loggerRef,
|
|
@@ -13154,6 +13183,44 @@ function mountAnnotatorClient(options) {
|
|
|
13154
13183
|
runtimeWindow[RUNTIME_GUARD] = runtime;
|
|
13155
13184
|
return runtime;
|
|
13156
13185
|
}
|
|
13186
|
+
let generating = false;
|
|
13187
|
+
async function generateVuePoms(options = {}, viteOptions = {}) {
|
|
13188
|
+
if (options.generation === false) {
|
|
13189
|
+
throw new Error("[vue-pom-generator] generateVuePoms requires generation to be enabled.");
|
|
13190
|
+
}
|
|
13191
|
+
const entryId = "virtual:vue-pom-generator-entry";
|
|
13192
|
+
const resolvedEntryId = `\0${entryId}`;
|
|
13193
|
+
const entry = {
|
|
13194
|
+
name: "vue-pom-generator-entry",
|
|
13195
|
+
resolveId(id) {
|
|
13196
|
+
return id === entryId ? resolvedEntryId : void 0;
|
|
13197
|
+
},
|
|
13198
|
+
load(id) {
|
|
13199
|
+
return id === resolvedEntryId ? "export {};" : void 0;
|
|
13200
|
+
}
|
|
13201
|
+
};
|
|
13202
|
+
if (generating) {
|
|
13203
|
+
throw new Error("[vue-pom-generator] Await the previous generateVuePoms call before starting another.");
|
|
13204
|
+
}
|
|
13205
|
+
generating = true;
|
|
13206
|
+
try {
|
|
13207
|
+
const { build } = await import("vite");
|
|
13208
|
+
await build({
|
|
13209
|
+
...viteOptions,
|
|
13210
|
+
configFile: false,
|
|
13211
|
+
publicDir: false,
|
|
13212
|
+
plugins: [entry, ...createGeneratorPlugins(options, true, path.resolve(viteOptions.root ?? ".")), ...viteOptions.plugins ?? []],
|
|
13213
|
+
build: {
|
|
13214
|
+
write: false,
|
|
13215
|
+
emptyOutDir: false,
|
|
13216
|
+
minify: false,
|
|
13217
|
+
rollupOptions: { input: entryId }
|
|
13218
|
+
}
|
|
13219
|
+
});
|
|
13220
|
+
} finally {
|
|
13221
|
+
generating = false;
|
|
13222
|
+
}
|
|
13223
|
+
}
|
|
13157
13224
|
const nuxtConfigMarker = /* @__PURE__ */ Symbol.for("@immense/vue-pom-generator.nuxt");
|
|
13158
13225
|
function defineVuePomGeneratorConfig(options) {
|
|
13159
13226
|
return options;
|
|
@@ -13170,6 +13237,7 @@ exports.createVuePomGeneratorPlugins = createVuePomGeneratorPlugins;
|
|
|
13170
13237
|
exports.default = createVuePomGeneratorPlugins;
|
|
13171
13238
|
exports.defineNuxtPomGeneratorConfig = defineNuxtPomGeneratorConfig;
|
|
13172
13239
|
exports.defineVuePomGeneratorConfig = defineVuePomGeneratorConfig;
|
|
13240
|
+
exports.generateVuePoms = generateVuePoms;
|
|
13173
13241
|
exports.mountAnnotatorClient = mountAnnotatorClient;
|
|
13174
13242
|
exports.vuePomGenerator = createVuePomGeneratorPlugins;
|
|
13175
13243
|
//# sourceMappingURL=index.cjs.map
|