@immense/vue-pom-generator 1.0.107 → 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/RELEASE_NOTES.md +36 -70
- package/class-generation/index.ts +99 -150
- package/dist/class-generation/index.d.ts +3 -0
- package/dist/class-generation/index.d.ts.map +1 -1
- package/dist/index.cjs +162 -167
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +164 -169
- 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/generated-outputs.d.ts.map +1 -1
- package/dist/plugin/internal/dev-plugin.d.ts.map +1 -1
- 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
|
@@ -295,6 +295,58 @@ function applyNuxtDiscoveryToInjectionOptions(options, discovery) {
|
|
|
295
295
|
wrapperSearchRoots: discovery.wrapperSearchRoots
|
|
296
296
|
};
|
|
297
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
|
+
}
|
|
298
350
|
function createTypeScriptProject() {
|
|
299
351
|
return new tsMorph.Project({
|
|
300
352
|
useInMemoryFileSystem: true,
|
|
@@ -359,9 +411,6 @@ function addNamedImport(sourceFile, options) {
|
|
|
359
411
|
namedImports: options.namedImports
|
|
360
412
|
});
|
|
361
413
|
}
|
|
362
|
-
function addExportAll(sourceFile, moduleSpecifier) {
|
|
363
|
-
return sourceFile.addExportDeclaration({ moduleSpecifier });
|
|
364
|
-
}
|
|
365
414
|
function createClassMethod(method) {
|
|
366
415
|
return {
|
|
367
416
|
kind: tsMorph.StructureKind.Method,
|
|
@@ -1458,23 +1507,11 @@ function getSlotScopeVariablesUsedAsBareCallbackHandlers(templateNode) {
|
|
|
1458
1507
|
const vFor = node.props.find(
|
|
1459
1508
|
(prop) => prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "for"
|
|
1460
1509
|
);
|
|
1461
|
-
if (vFor?.
|
|
1462
|
-
const
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
if (aliasSource) {
|
|
1467
|
-
try {
|
|
1468
|
-
const aliasAst = parser.parseExpression(aliasSource, { plugins: ["typescript"] });
|
|
1469
|
-
if (types.isSequenceExpression(aliasAst)) {
|
|
1470
|
-
for (const part of aliasAst.expressions) {
|
|
1471
|
-
names.push(...collectBindingPatternNames(part));
|
|
1472
|
-
}
|
|
1473
|
-
} else {
|
|
1474
|
-
names.push(...collectBindingPatternNames(aliasAst));
|
|
1475
|
-
}
|
|
1476
|
-
} catch {
|
|
1477
|
-
}
|
|
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)));
|
|
1478
1515
|
}
|
|
1479
1516
|
}
|
|
1480
1517
|
}
|
|
@@ -1644,10 +1681,6 @@ function tryGetTemplateSlotScopeBindingNode(expression) {
|
|
|
1644
1681
|
if (!rawSource) {
|
|
1645
1682
|
return null;
|
|
1646
1683
|
}
|
|
1647
|
-
try {
|
|
1648
|
-
return parser.parseExpression(rawSource, { plugins: ["typescript"] });
|
|
1649
|
-
} catch {
|
|
1650
|
-
}
|
|
1651
1684
|
try {
|
|
1652
1685
|
const parsed = parser.parse(`(${rawSource}) => {}`, {
|
|
1653
1686
|
sourceType: "module",
|
|
@@ -4008,29 +4041,30 @@ function generateTestIdsModule(componentHierarchyMap, elementMetadata) {
|
|
|
4008
4041
|
});
|
|
4009
4042
|
});
|
|
4010
4043
|
}
|
|
4011
|
-
function generatePomManifestModule(componentHierarchyMap, elementMetadata, fileName = "virtual-pom-manifest.ts") {
|
|
4044
|
+
function generatePomManifestModule(componentHierarchyMap, elementMetadata, fileName = "virtual-pom-manifest.ts", renderCache) {
|
|
4012
4045
|
const pomManifest = buildPomManifest(componentHierarchyMap, elementMetadata);
|
|
4013
|
-
return
|
|
4014
|
-
|
|
4015
|
-
|
|
4046
|
+
return renderStructuredSourceFile(fileName, {
|
|
4047
|
+
statements: [{
|
|
4048
|
+
kind: tsMorph.StructureKind.VariableStatement,
|
|
4049
|
+
leadingTrivia: "// Rich POM discoverability manifest.\n",
|
|
4016
4050
|
declarationKind: tsMorph.VariableDeclarationKind.Const,
|
|
4017
4051
|
isExported: true,
|
|
4018
4052
|
declarations: [{
|
|
4019
4053
|
name: "pomManifest",
|
|
4020
4054
|
initializer: writeConstJson(pomManifest)
|
|
4021
4055
|
}]
|
|
4022
|
-
}
|
|
4023
|
-
|
|
4056
|
+
}, {
|
|
4057
|
+
kind: tsMorph.StructureKind.TypeAlias,
|
|
4024
4058
|
isExported: true,
|
|
4025
4059
|
name: "PomManifest",
|
|
4026
4060
|
type: "typeof pomManifest"
|
|
4027
|
-
}
|
|
4028
|
-
|
|
4061
|
+
}, {
|
|
4062
|
+
kind: tsMorph.StructureKind.TypeAlias,
|
|
4029
4063
|
isExported: true,
|
|
4030
4064
|
name: "PomManifestComponentName",
|
|
4031
4065
|
type: "keyof PomManifest"
|
|
4032
|
-
}
|
|
4033
|
-
});
|
|
4066
|
+
}]
|
|
4067
|
+
}, { cache: renderCache });
|
|
4034
4068
|
}
|
|
4035
4069
|
const manifestName = ".vue-pom-generator-outputs.json";
|
|
4036
4070
|
function hash(content) {
|
|
@@ -4079,6 +4113,7 @@ function assertNoSymlinkParents(filePath, outDir, projectRoot) {
|
|
|
4079
4113
|
}
|
|
4080
4114
|
}
|
|
4081
4115
|
function writeFile(filePath, content) {
|
|
4116
|
+
if (fs.existsSync(filePath) && fs.readFileSync(filePath, "utf8") === content) return;
|
|
4082
4117
|
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
4083
4118
|
const temporaryPath = `${filePath}.${node_crypto.randomUUID()}.tmp`;
|
|
4084
4119
|
try {
|
|
@@ -5909,7 +5944,8 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5909
5944
|
componentDirs,
|
|
5910
5945
|
layoutDirs,
|
|
5911
5946
|
routeMetaByComponent: routeMetaByComponentOverride,
|
|
5912
|
-
elementMetadata = /* @__PURE__ */ new Map()
|
|
5947
|
+
elementMetadata = /* @__PURE__ */ new Map(),
|
|
5948
|
+
renderCache
|
|
5913
5949
|
} = options;
|
|
5914
5950
|
const emitLanguages = emitLanguagesOverride?.length ? emitLanguagesOverride : ["ts"];
|
|
5915
5951
|
const root = projectRoot ?? process.cwd();
|
|
@@ -5927,6 +5963,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5927
5963
|
const generatedFiles = [];
|
|
5928
5964
|
if (emitLanguages.includes("ts")) {
|
|
5929
5965
|
const files = typescriptOutputStructure === "split" ? await generateSplitTypeScriptFiles(emittableComponentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, {
|
|
5966
|
+
renderCache,
|
|
5930
5967
|
customPomAttachments,
|
|
5931
5968
|
projectRoot,
|
|
5932
5969
|
customPomDir,
|
|
@@ -5937,6 +5974,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5937
5974
|
routeMetaByComponent,
|
|
5938
5975
|
vueRouterFluentChaining
|
|
5939
5976
|
}) : await generateAggregatedFiles(emittableComponentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, {
|
|
5977
|
+
renderCache,
|
|
5940
5978
|
customPomAttachments,
|
|
5941
5979
|
projectRoot,
|
|
5942
5980
|
customPomDir,
|
|
@@ -5949,6 +5987,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5949
5987
|
});
|
|
5950
5988
|
generatedFiles.push(...files);
|
|
5951
5989
|
const fixtureRegistryFiles = maybeGenerateFixtureRegistry(emittableComponentHierarchyMap, {
|
|
5990
|
+
renderCache,
|
|
5952
5991
|
generateFixtures,
|
|
5953
5992
|
pomOutDir: outDir,
|
|
5954
5993
|
projectRoot,
|
|
@@ -5969,12 +6008,13 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5969
6008
|
const vueTestUtilsFiles = generateVueTestUtilsFiles(
|
|
5970
6009
|
emittableComponentHierarchyMap,
|
|
5971
6010
|
vueTestUtilsOutDir,
|
|
5972
|
-
{ testIdAttribute }
|
|
6011
|
+
{ testIdAttribute, renderCache }
|
|
5973
6012
|
);
|
|
5974
6013
|
generatedFiles.push(...vueTestUtilsFiles);
|
|
5975
6014
|
}
|
|
5976
6015
|
const gitattributesFiles = buildGeneratedGitAttributesFiles(generatedFiles.map((file) => file.filePath));
|
|
5977
6016
|
writeGeneratedOutputs(outDir, generatedFiles, gitattributesFiles, path.resolve(root));
|
|
6017
|
+
renderCache?.retain(new Set(generatedFiles.map((file) => file.filePath)));
|
|
5978
6018
|
}
|
|
5979
6019
|
const VUE_TEST_UTILS_OMITTED_PARAMETERS = /* @__PURE__ */ new Set(["annotationText", "timeOut", "timeout", "wait"]);
|
|
5980
6020
|
function getVueTestUtilsParameters(parameters, patterns, options = {}) {
|
|
@@ -6102,7 +6142,7 @@ function getVueTestUtilsComponentMembers(componentInstances, projectedComponentI
|
|
|
6102
6142
|
}));
|
|
6103
6143
|
return members;
|
|
6104
6144
|
}
|
|
6105
|
-
function generateVueTestUtilsContent(componentName, dependencies, componentHierarchyMap, outputDir, runtimePath, generatedFilePathByComponent, testIdAttribute) {
|
|
6145
|
+
function generateVueTestUtilsContent(componentName, dependencies, componentHierarchyMap, outputDir, runtimePath, generatedFilePathByComponent, testIdAttribute, renderCache) {
|
|
6106
6146
|
const prepared = prepareViewObjectModelClass(componentName, dependencies, componentHierarchyMap, {
|
|
6107
6147
|
testIdAttribute
|
|
6108
6148
|
});
|
|
@@ -6122,33 +6162,29 @@ function generateVueTestUtilsContent(componentName, dependencies, componentHiera
|
|
|
6122
6162
|
...getUniquePrimaryPomSpecs(dependencies).flatMap(({ pom }) => getVueTestUtilsPrimaryMembers(pom)),
|
|
6123
6163
|
...(dependencies.pomExtraMethods ?? []).flatMap(getVueTestUtilsExtraMembers)
|
|
6124
6164
|
];
|
|
6125
|
-
return
|
|
6126
|
-
|
|
6165
|
+
return renderStructuredSourceFile(path.join(outputDir, `${componentName}.vtu.g.ts`), {
|
|
6166
|
+
statements: [{
|
|
6167
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
6127
6168
|
moduleSpecifier: runtimeImport,
|
|
6128
6169
|
namedImports: ["VueTestUtilsPom"]
|
|
6129
|
-
}
|
|
6130
|
-
|
|
6170
|
+
}, {
|
|
6171
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
6131
6172
|
moduleSpecifier: runtimeImport,
|
|
6132
6173
|
namedImports: ["VueTestUtilsPomRoot"],
|
|
6133
6174
|
isTypeOnly: true
|
|
6134
|
-
})
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
});
|
|
6140
|
-
}
|
|
6141
|
-
const declaration = sourceFile.addClass({
|
|
6175
|
+
}, ...componentImports.map((componentImport) => ({
|
|
6176
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
6177
|
+
moduleSpecifier: componentImport.moduleSpecifier,
|
|
6178
|
+
namedImports: [componentImport.className]
|
|
6179
|
+
})), createClassDeclaration({
|
|
6142
6180
|
name: prepared.className,
|
|
6143
6181
|
isExported: true,
|
|
6144
6182
|
extends: "VueTestUtilsPom",
|
|
6145
6183
|
docs: [`Vue Test Utils object for ${componentName} (source: ${sourceRel}).`]
|
|
6146
|
-
})
|
|
6147
|
-
for (const member of members) {
|
|
6148
|
-
addClassMember(declaration, member);
|
|
6149
|
-
}
|
|
6184
|
+
}, members)]
|
|
6150
6185
|
}, {
|
|
6151
|
-
prefixText: buildFilePrefix({ eslintDisableSortImports: true })
|
|
6186
|
+
prefixText: buildFilePrefix({ eslintDisableSortImports: true }),
|
|
6187
|
+
cache: renderCache
|
|
6152
6188
|
});
|
|
6153
6189
|
}
|
|
6154
6190
|
function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {}) {
|
|
@@ -6170,7 +6206,8 @@ function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {})
|
|
|
6170
6206
|
path.dirname(filePath),
|
|
6171
6207
|
runtimePath,
|
|
6172
6208
|
generatedFilePathByComponent,
|
|
6173
|
-
testIdAttribute
|
|
6209
|
+
testIdAttribute,
|
|
6210
|
+
options.renderCache
|
|
6174
6211
|
)
|
|
6175
6212
|
};
|
|
6176
6213
|
});
|
|
@@ -6182,12 +6219,13 @@ function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {})
|
|
|
6182
6219
|
if (!runtimeFile) {
|
|
6183
6220
|
throw new Error("[vue-pom-generator] Failed to generate the Vue Test Utils runtime.");
|
|
6184
6221
|
}
|
|
6185
|
-
const indexContent =
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
}
|
|
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 }))
|
|
6190
6227
|
}, {
|
|
6228
|
+
cache: options.renderCache,
|
|
6191
6229
|
prefixText: buildFilePrefix({
|
|
6192
6230
|
eslintDisableSortImports: true,
|
|
6193
6231
|
commentLines: [
|
|
@@ -6241,6 +6279,7 @@ async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathM
|
|
|
6241
6279
|
continue;
|
|
6242
6280
|
}
|
|
6243
6281
|
const content = generateViewObjectModelContent(name, deps, componentHierarchyMap, vueFilesPathMap, runtimeBasePagePath, {
|
|
6282
|
+
renderCache: options.renderCache,
|
|
6244
6283
|
outputDir: path.dirname(filePath),
|
|
6245
6284
|
customPomAttachments: options.customPomAttachments ?? [],
|
|
6246
6285
|
projectRoot,
|
|
@@ -6268,6 +6307,8 @@ async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathM
|
|
|
6268
6307
|
const childImports = getChildImportSpecifiers(outputDir, composed?.childClassNames ?? [], generatedTsFilePathByComponent);
|
|
6269
6308
|
const members = composed?.members ?? getDefaultStubMembers();
|
|
6270
6309
|
const content = renderSplitStubPomContent({
|
|
6310
|
+
filePath,
|
|
6311
|
+
renderCache: options.renderCache,
|
|
6271
6312
|
className: targetClassName,
|
|
6272
6313
|
basePageImportSpecifier,
|
|
6273
6314
|
childImports,
|
|
@@ -6277,14 +6318,13 @@ async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathM
|
|
|
6277
6318
|
}
|
|
6278
6319
|
const runtimeAssetSpecs = getRuntimeGeneratedAssetSpecs(base, basePageClassPath);
|
|
6279
6320
|
const runtimeFiles = buildRuntimeGeneratedFilesFromSpecs(runtimeAssetSpecs);
|
|
6280
|
-
const indexContent =
|
|
6281
|
-
|
|
6282
|
-
|
|
6283
|
-
|
|
6284
|
-
|
|
6285
|
-
addExportAll(sourceFile, `./${stripExtension(path.basename(filePath))}`);
|
|
6286
|
-
}
|
|
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 }))
|
|
6287
6326
|
}, {
|
|
6327
|
+
cache: options.renderCache,
|
|
6288
6328
|
prefixText: buildFilePrefix({
|
|
6289
6329
|
eslintDisableSortImports: true,
|
|
6290
6330
|
commentLines: [
|
|
@@ -6960,7 +7000,8 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
6960
7000
|
const manifestContent = generatePomManifestModule(
|
|
6961
7001
|
componentHierarchyMap,
|
|
6962
7002
|
options.elementMetadata,
|
|
6963
|
-
manifestFileName
|
|
7003
|
+
path.resolve(fixtureOutDirAbs, manifestFileName),
|
|
7004
|
+
options.renderCache
|
|
6964
7005
|
);
|
|
6965
7006
|
const [diagnosticsRuntimeFile] = buildRuntimeGeneratedFilesFromSpecs([{
|
|
6966
7007
|
absolutePath: resolvePluginAsset("../class-generation/diagnostics.ts"),
|
|
@@ -7308,40 +7349,33 @@ function generateViewObjectModelContent(componentName, dependencies, componentHi
|
|
|
7308
7349
|
generatedImports.sort((a, b) => a.className.localeCompare(b.className));
|
|
7309
7350
|
const prefixText = `${buildFilePrefix({ eslintDisableSortImports: true })}${doc}
|
|
7310
7351
|
`;
|
|
7311
|
-
return
|
|
7312
|
-
|
|
7352
|
+
return renderStructuredSourceFile(path.join(outputDir, `${componentName}.g.ts`), {
|
|
7353
|
+
statements: [{
|
|
7354
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7313
7355
|
moduleSpecifier: "@playwright/test",
|
|
7314
7356
|
isTypeOnly: true,
|
|
7315
7357
|
namedImports: [
|
|
7316
7358
|
{ name: "Locator", alias: "PwLocator" },
|
|
7317
7359
|
{ name: "Page", alias: "PwPage" }
|
|
7318
7360
|
]
|
|
7319
|
-
}
|
|
7320
|
-
|
|
7361
|
+
}, {
|
|
7362
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7321
7363
|
moduleSpecifier: basePageImportSpecifier,
|
|
7322
7364
|
namedImports: ["BasePage", "Fluent"]
|
|
7323
|
-
})
|
|
7324
|
-
|
|
7325
|
-
|
|
7326
|
-
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
7330
|
-
|
|
7331
|
-
|
|
7332
|
-
moduleSpecifier: generatedImport.moduleSpecifier,
|
|
7333
|
-
namedImports: [generatedImport.className]
|
|
7334
|
-
});
|
|
7335
|
-
}
|
|
7336
|
-
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({
|
|
7337
7374
|
name: prepared.className,
|
|
7338
7375
|
isExported: true,
|
|
7339
7376
|
extends: "BasePage"
|
|
7340
|
-
})
|
|
7341
|
-
|
|
7342
|
-
addClassMember(classDeclaration, member);
|
|
7343
|
-
}
|
|
7344
|
-
}, { prefixText });
|
|
7377
|
+
}, prepared.members)]
|
|
7378
|
+
}, { prefixText, cache: options.renderCache });
|
|
7345
7379
|
}
|
|
7346
7380
|
function getViewPassthroughMethods(viewName, viewDependencies, componentInstances, componentHierarchyMap, blockedMethodNames = /* @__PURE__ */ new Set()) {
|
|
7347
7381
|
const existingOnView = viewDependencies.generatedMethods ?? /* @__PURE__ */ new Map();
|
|
@@ -7562,35 +7596,32 @@ function renderSplitStubPomContent(options) {
|
|
|
7562
7596
|
"Changes should be made in the generator/template, not in the generated output."
|
|
7563
7597
|
]
|
|
7564
7598
|
});
|
|
7565
|
-
return
|
|
7566
|
-
|
|
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,
|
|
7567
7604
|
moduleSpecifier: "@playwright/test",
|
|
7568
7605
|
isTypeOnly: true,
|
|
7569
7606
|
namedImports: [{ name: "Page", alias: "PwPage" }]
|
|
7570
|
-
}
|
|
7571
|
-
|
|
7607
|
+
}, {
|
|
7608
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7572
7609
|
moduleSpecifier: options.basePageImportSpecifier,
|
|
7573
7610
|
namedImports: ["BasePage"]
|
|
7574
|
-
})
|
|
7575
|
-
|
|
7576
|
-
|
|
7577
|
-
|
|
7578
|
-
|
|
7579
|
-
});
|
|
7580
|
-
}
|
|
7581
|
-
sourceFile.addStatements(buildCommentBlock([
|
|
7582
|
-
"Stub POM generated because it is referenced as a navigation target but",
|
|
7583
|
-
"did not have any generated test ids in this build."
|
|
7584
|
-
]).trimEnd());
|
|
7585
|
-
const classDeclaration = sourceFile.addClass({
|
|
7611
|
+
}, ...options.childImports.map((childImport) => ({
|
|
7612
|
+
kind: tsMorph.StructureKind.ImportDeclaration,
|
|
7613
|
+
moduleSpecifier: childImport.importPath,
|
|
7614
|
+
namedImports: [childImport.className]
|
|
7615
|
+
})), createClassDeclaration({
|
|
7586
7616
|
name: options.className,
|
|
7587
7617
|
isExported: true,
|
|
7588
|
-
extends: "BasePage"
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
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 });
|
|
7594
7625
|
}
|
|
7595
7626
|
function getChildImportSpecifiers(outputDir, childClassNames, generatedTsFilePathByComponent) {
|
|
7596
7627
|
return childClassNames.map((childClassName) => {
|
|
@@ -7604,37 +7635,6 @@ function getChildImportSpecifiers(outputDir, childClassNames, generatedTsFilePat
|
|
|
7604
7635
|
};
|
|
7605
7636
|
}).filter((entry) => !!entry).sort((a, b) => a.className.localeCompare(b.className));
|
|
7606
7637
|
}
|
|
7607
|
-
function isConstructorMember(member) {
|
|
7608
|
-
return member.kind === tsMorph.StructureKind.Constructor;
|
|
7609
|
-
}
|
|
7610
|
-
function isGetterMember(member) {
|
|
7611
|
-
return member.kind === tsMorph.StructureKind.GetAccessor;
|
|
7612
|
-
}
|
|
7613
|
-
function isMethodMember(member) {
|
|
7614
|
-
return member.kind === tsMorph.StructureKind.Method;
|
|
7615
|
-
}
|
|
7616
|
-
function isPropertyMember(member) {
|
|
7617
|
-
return member.kind === tsMorph.StructureKind.Property;
|
|
7618
|
-
}
|
|
7619
|
-
function addClassMember(classDeclaration, member) {
|
|
7620
|
-
if (isConstructorMember(member)) {
|
|
7621
|
-
classDeclaration.addConstructor(member);
|
|
7622
|
-
return;
|
|
7623
|
-
}
|
|
7624
|
-
if (isGetterMember(member)) {
|
|
7625
|
-
classDeclaration.addGetAccessor(member);
|
|
7626
|
-
return;
|
|
7627
|
-
}
|
|
7628
|
-
if (isMethodMember(member)) {
|
|
7629
|
-
classDeclaration.addMethod(member);
|
|
7630
|
-
return;
|
|
7631
|
-
}
|
|
7632
|
-
if (isPropertyMember(member)) {
|
|
7633
|
-
classDeclaration.addProperty(member);
|
|
7634
|
-
return;
|
|
7635
|
-
}
|
|
7636
|
-
throw new Error(`Unsupported class member structure: ${String(member)}`);
|
|
7637
|
-
}
|
|
7638
7638
|
function getRuntimeGeneratedAssetSpecs(baseDir, basePageClassPath) {
|
|
7639
7639
|
const runtimeDirAbs = path.join(baseDir, "_pom-runtime");
|
|
7640
7640
|
const runtimeClassGenAbs = path.join(runtimeDirAbs, "class-generation");
|
|
@@ -7912,37 +7912,30 @@ async function generateAggregatedFiles(componentHierarchyMap, vueFilesPathMap, b
|
|
|
7912
7912
|
"Changes should be made in the generator/template, not in the generated output."
|
|
7913
7913
|
]
|
|
7914
7914
|
});
|
|
7915
|
-
return
|
|
7916
|
-
|
|
7917
|
-
|
|
7918
|
-
|
|
7919
|
-
for (const entry of [...classes, ...stubs]) {
|
|
7920
|
-
if (entry.isStub) {
|
|
7921
|
-
sourceFile.addStatements(buildCommentBlock([
|
|
7922
|
-
"Stub POM generated because it is referenced as a navigation target but",
|
|
7923
|
-
"did not have any generated test ids in this build."
|
|
7924
|
-
]).trimEnd());
|
|
7925
|
-
} else {
|
|
7926
|
-
sourceFile.addStatements(entry.doc);
|
|
7927
|
-
}
|
|
7928
|
-
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({
|
|
7929
7919
|
name: entry.className,
|
|
7930
7920
|
isExported: true,
|
|
7931
|
-
extends: "BasePage"
|
|
7932
|
-
|
|
7933
|
-
|
|
7934
|
-
|
|
7935
|
-
|
|
7936
|
-
|
|
7937
|
-
|
|
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 });
|
|
7938
7930
|
};
|
|
7939
7931
|
const base = ensureDir(outDir);
|
|
7940
7932
|
const outputFile = path.join(base, "page-object-models.g.ts");
|
|
7941
7933
|
const content = makeAggregatedContent(path.dirname(outputFile), [...views, ...components]);
|
|
7942
7934
|
const indexFile = path.join(base, "index.ts");
|
|
7943
|
-
const indexContent =
|
|
7944
|
-
|
|
7935
|
+
const indexContent = renderStructuredSourceFile(indexFile, {
|
|
7936
|
+
statements: [{ kind: tsMorph.StructureKind.ExportDeclaration, moduleSpecifier: "./page-object-models.g" }]
|
|
7945
7937
|
}, {
|
|
7938
|
+
cache: options.renderCache,
|
|
7946
7939
|
prefixText: buildFilePrefix({
|
|
7947
7940
|
eslintDisableSortImports: true,
|
|
7948
7941
|
commentLines: [
|
|
@@ -10759,6 +10752,7 @@ function createDevProcessorPlugin(options) {
|
|
|
10759
10752
|
scheduleVueFileRegen(ctx.file, "hmr");
|
|
10760
10753
|
},
|
|
10761
10754
|
async configureServer(server) {
|
|
10755
|
+
const renderCache = new TypeScriptRenderCache();
|
|
10762
10756
|
const getViewsDirAbs = () => resolveProjectPath(getViewsDir());
|
|
10763
10757
|
const getPageDirsAbs = () => getPageDirs().map((dir) => resolveProjectPath(dir));
|
|
10764
10758
|
const routerInitPromise = (async () => {
|
|
@@ -10966,6 +10960,7 @@ function createDevProcessorPlugin(options) {
|
|
|
10966
10960
|
const generateAggregatedFromSnapshot = async (logLabel) => {
|
|
10967
10961
|
const t0 = node_perf_hooks.performance.now();
|
|
10968
10962
|
await generateFiles(snapshotHierarchy, snapshotVuePathMap, normalizedBasePagePath, {
|
|
10963
|
+
renderCache,
|
|
10969
10964
|
outDir,
|
|
10970
10965
|
emitLanguages,
|
|
10971
10966
|
typescriptOutputStructure,
|