@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.mjs
CHANGED
|
@@ -8,8 +8,8 @@ import { NodeTypes, stringifyExpression, createSimpleExpression, processExpressi
|
|
|
8
8
|
import * as compilerDom from "@vue/compiler-dom";
|
|
9
9
|
import { parse as parse$2, NodeTypes as NodeTypes$1 } from "@vue/compiler-dom";
|
|
10
10
|
import { parse as parse$1, compileScript } from "@vue/compiler-sfc";
|
|
11
|
-
import { Project, QuoteKind, NewLineKind, IndentationText,
|
|
12
|
-
import { isIdentifier, isObjectPattern, isRestElement, isObjectProperty, isArrayExpression, isStringLiteral, isTemplateLiteral, isArrowFunctionExpression, isExpressionStatement, isAssignmentPattern, isMemberExpression, isOptionalMemberExpression, isCallExpression, isOptionalCallExpression, isAssignmentExpression,
|
|
11
|
+
import { Project, QuoteKind, NewLineKind, IndentationText, CodeBlockWriter, StructureKind, VariableDeclarationKind } from "ts-morph";
|
|
12
|
+
import { isIdentifier, isObjectPattern, isRestElement, isObjectProperty, isArrayExpression, isStringLiteral, isTemplateLiteral, isArrowFunctionExpression, isExpressionStatement, isAssignmentPattern, isMemberExpression, isOptionalMemberExpression, isCallExpression, isOptionalCallExpression, isAssignmentExpression, isObjectExpression, isFile, isBlockStatement, isLogicalExpression, isConditionalExpression, isSequenceExpression, isProgram, isArrayPattern, VISITOR_KEYS, isBooleanLiteral, isNumericLiteral, isNullLiteral, isImportDeclaration, isImportSpecifier, isExportDefaultDeclaration, isExpression, isVariableDeclaration, isFunctionDeclaration, isFunctionExpression, isReturnStatement, isTSAsExpression, isTSTypeAssertion, isTSNonNullExpression, isForInStatement, isIfStatement } from "@babel/types";
|
|
13
13
|
import { createHash, randomUUID } from "node:crypto";
|
|
14
14
|
import { POM_ROUTER_GLOBAL_NAME } from "./router.mjs";
|
|
15
15
|
import { performance } from "node:perf_hooks";
|
|
@@ -254,6 +254,58 @@ function applyNuxtDiscoveryToInjectionOptions(options, discovery) {
|
|
|
254
254
|
wrapperSearchRoots: discovery.wrapperSearchRoots
|
|
255
255
|
};
|
|
256
256
|
}
|
|
257
|
+
class TypeScriptRenderCache {
|
|
258
|
+
entries = /* @__PURE__ */ new Map();
|
|
259
|
+
render(filePath, input, build) {
|
|
260
|
+
const previous = this.entries.get(filePath);
|
|
261
|
+
if (previous?.input === input) return previous.content;
|
|
262
|
+
const content = build();
|
|
263
|
+
this.entries.set(filePath, { input, content });
|
|
264
|
+
return content;
|
|
265
|
+
}
|
|
266
|
+
retain(filePaths) {
|
|
267
|
+
for (const filePath of this.entries.keys()) {
|
|
268
|
+
if (!filePaths.has(filePath)) this.entries.delete(filePath);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function createClassDeclaration(declaration, members) {
|
|
273
|
+
const result = { ...declaration, kind: StructureKind.Class };
|
|
274
|
+
for (const member of members) {
|
|
275
|
+
switch (member.kind) {
|
|
276
|
+
case StructureKind.Constructor:
|
|
277
|
+
(result.ctors ??= []).push(member);
|
|
278
|
+
break;
|
|
279
|
+
case StructureKind.GetAccessor:
|
|
280
|
+
(result.getAccessors ??= []).push(member);
|
|
281
|
+
break;
|
|
282
|
+
case StructureKind.Method:
|
|
283
|
+
(result.methods ??= []).push(member);
|
|
284
|
+
break;
|
|
285
|
+
case StructureKind.Property:
|
|
286
|
+
(result.properties ??= []).push(member);
|
|
287
|
+
break;
|
|
288
|
+
default:
|
|
289
|
+
throw new Error(`Unsupported class member kind: ${String(member.kind)}`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return result;
|
|
293
|
+
}
|
|
294
|
+
function renderStructuredSourceFile(filePath, structure, options = {}) {
|
|
295
|
+
const build = () => {
|
|
296
|
+
const project = createTypeScriptProject();
|
|
297
|
+
const sourceFile = project.createSourceFile(filePath, structure);
|
|
298
|
+
return ensureTrailingNewline(`${options.prefixText ?? ""}${sourceFile.getFullText()}`);
|
|
299
|
+
};
|
|
300
|
+
if (!options.cache) return build();
|
|
301
|
+
const input = JSON.stringify([options.prefixText, structure], (_key, value) => {
|
|
302
|
+
if (typeof value !== "function") return value;
|
|
303
|
+
const writer = createTypeScriptWriter();
|
|
304
|
+
value(writer);
|
|
305
|
+
return writer.toString();
|
|
306
|
+
});
|
|
307
|
+
return options.cache.render(filePath, input, build);
|
|
308
|
+
}
|
|
257
309
|
function createTypeScriptProject() {
|
|
258
310
|
return new Project({
|
|
259
311
|
useInMemoryFileSystem: true,
|
|
@@ -318,9 +370,6 @@ function addNamedImport(sourceFile, options) {
|
|
|
318
370
|
namedImports: options.namedImports
|
|
319
371
|
});
|
|
320
372
|
}
|
|
321
|
-
function addExportAll(sourceFile, moduleSpecifier) {
|
|
322
|
-
return sourceFile.addExportDeclaration({ moduleSpecifier });
|
|
323
|
-
}
|
|
324
373
|
function createClassMethod(method) {
|
|
325
374
|
return {
|
|
326
375
|
kind: StructureKind.Method,
|
|
@@ -1417,23 +1466,11 @@ function getSlotScopeVariablesUsedAsBareCallbackHandlers(templateNode) {
|
|
|
1417
1466
|
const vFor = node.props.find(
|
|
1418
1467
|
(prop) => prop.type === NodeTypes.DIRECTIVE && prop.name === "for"
|
|
1419
1468
|
);
|
|
1420
|
-
if (vFor?.
|
|
1421
|
-
const
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
if (aliasSource) {
|
|
1426
|
-
try {
|
|
1427
|
-
const aliasAst = parseExpression(aliasSource, { plugins: ["typescript"] });
|
|
1428
|
-
if (isSequenceExpression(aliasAst)) {
|
|
1429
|
-
for (const part of aliasAst.expressions) {
|
|
1430
|
-
names.push(...collectBindingPatternNames(part));
|
|
1431
|
-
}
|
|
1432
|
-
} else {
|
|
1433
|
-
names.push(...collectBindingPatternNames(aliasAst));
|
|
1434
|
-
}
|
|
1435
|
-
} catch {
|
|
1436
|
-
}
|
|
1469
|
+
if (vFor?.forParseResult) {
|
|
1470
|
+
const { value, key, index } = vFor.forParseResult;
|
|
1471
|
+
for (const alias of [value, key, index]) {
|
|
1472
|
+
if (alias) {
|
|
1473
|
+
names.push(...collectBindingPatternNames(tryGetTemplateSlotScopeBindingNode(alias)));
|
|
1437
1474
|
}
|
|
1438
1475
|
}
|
|
1439
1476
|
}
|
|
@@ -1603,10 +1640,6 @@ function tryGetTemplateSlotScopeBindingNode(expression) {
|
|
|
1603
1640
|
if (!rawSource) {
|
|
1604
1641
|
return null;
|
|
1605
1642
|
}
|
|
1606
|
-
try {
|
|
1607
|
-
return parseExpression(rawSource, { plugins: ["typescript"] });
|
|
1608
|
-
} catch {
|
|
1609
|
-
}
|
|
1610
1643
|
try {
|
|
1611
1644
|
const parsed = parse(`(${rawSource}) => {}`, {
|
|
1612
1645
|
sourceType: "module",
|
|
@@ -3967,29 +4000,30 @@ function generateTestIdsModule(componentHierarchyMap, elementMetadata) {
|
|
|
3967
4000
|
});
|
|
3968
4001
|
});
|
|
3969
4002
|
}
|
|
3970
|
-
function generatePomManifestModule(componentHierarchyMap, elementMetadata, fileName = "virtual-pom-manifest.ts") {
|
|
4003
|
+
function generatePomManifestModule(componentHierarchyMap, elementMetadata, fileName = "virtual-pom-manifest.ts", renderCache) {
|
|
3971
4004
|
const pomManifest = buildPomManifest(componentHierarchyMap, elementMetadata);
|
|
3972
|
-
return
|
|
3973
|
-
|
|
3974
|
-
|
|
4005
|
+
return renderStructuredSourceFile(fileName, {
|
|
4006
|
+
statements: [{
|
|
4007
|
+
kind: StructureKind.VariableStatement,
|
|
4008
|
+
leadingTrivia: "// Rich POM discoverability manifest.\n",
|
|
3975
4009
|
declarationKind: VariableDeclarationKind.Const,
|
|
3976
4010
|
isExported: true,
|
|
3977
4011
|
declarations: [{
|
|
3978
4012
|
name: "pomManifest",
|
|
3979
4013
|
initializer: writeConstJson(pomManifest)
|
|
3980
4014
|
}]
|
|
3981
|
-
}
|
|
3982
|
-
|
|
4015
|
+
}, {
|
|
4016
|
+
kind: StructureKind.TypeAlias,
|
|
3983
4017
|
isExported: true,
|
|
3984
4018
|
name: "PomManifest",
|
|
3985
4019
|
type: "typeof pomManifest"
|
|
3986
|
-
}
|
|
3987
|
-
|
|
4020
|
+
}, {
|
|
4021
|
+
kind: StructureKind.TypeAlias,
|
|
3988
4022
|
isExported: true,
|
|
3989
4023
|
name: "PomManifestComponentName",
|
|
3990
4024
|
type: "keyof PomManifest"
|
|
3991
|
-
}
|
|
3992
|
-
});
|
|
4025
|
+
}]
|
|
4026
|
+
}, { cache: renderCache });
|
|
3993
4027
|
}
|
|
3994
4028
|
const manifestName = ".vue-pom-generator-outputs.json";
|
|
3995
4029
|
function hash(content) {
|
|
@@ -4038,6 +4072,7 @@ function assertNoSymlinkParents(filePath, outDir, projectRoot) {
|
|
|
4038
4072
|
}
|
|
4039
4073
|
}
|
|
4040
4074
|
function writeFile(filePath, content) {
|
|
4075
|
+
if (fs.existsSync(filePath) && fs.readFileSync(filePath, "utf8") === content) return;
|
|
4041
4076
|
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
4042
4077
|
const temporaryPath = `${filePath}.${randomUUID()}.tmp`;
|
|
4043
4078
|
try {
|
|
@@ -5868,7 +5903,8 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5868
5903
|
componentDirs,
|
|
5869
5904
|
layoutDirs,
|
|
5870
5905
|
routeMetaByComponent: routeMetaByComponentOverride,
|
|
5871
|
-
elementMetadata = /* @__PURE__ */ new Map()
|
|
5906
|
+
elementMetadata = /* @__PURE__ */ new Map(),
|
|
5907
|
+
renderCache
|
|
5872
5908
|
} = options;
|
|
5873
5909
|
const emitLanguages = emitLanguagesOverride?.length ? emitLanguagesOverride : ["ts"];
|
|
5874
5910
|
const root = projectRoot ?? process.cwd();
|
|
@@ -5886,6 +5922,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5886
5922
|
const generatedFiles = [];
|
|
5887
5923
|
if (emitLanguages.includes("ts")) {
|
|
5888
5924
|
const files = typescriptOutputStructure === "split" ? await generateSplitTypeScriptFiles(emittableComponentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, {
|
|
5925
|
+
renderCache,
|
|
5889
5926
|
customPomAttachments,
|
|
5890
5927
|
projectRoot,
|
|
5891
5928
|
customPomDir,
|
|
@@ -5896,6 +5933,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5896
5933
|
routeMetaByComponent,
|
|
5897
5934
|
vueRouterFluentChaining
|
|
5898
5935
|
}) : await generateAggregatedFiles(emittableComponentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, {
|
|
5936
|
+
renderCache,
|
|
5899
5937
|
customPomAttachments,
|
|
5900
5938
|
projectRoot,
|
|
5901
5939
|
customPomDir,
|
|
@@ -5908,6 +5946,7 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5908
5946
|
});
|
|
5909
5947
|
generatedFiles.push(...files);
|
|
5910
5948
|
const fixtureRegistryFiles = maybeGenerateFixtureRegistry(emittableComponentHierarchyMap, {
|
|
5949
|
+
renderCache,
|
|
5911
5950
|
generateFixtures,
|
|
5912
5951
|
pomOutDir: outDir,
|
|
5913
5952
|
projectRoot,
|
|
@@ -5928,12 +5967,13 @@ async function generateFiles(componentHierarchyMap, vueFilesPathMap, basePageCla
|
|
|
5928
5967
|
const vueTestUtilsFiles = generateVueTestUtilsFiles(
|
|
5929
5968
|
emittableComponentHierarchyMap,
|
|
5930
5969
|
vueTestUtilsOutDir,
|
|
5931
|
-
{ testIdAttribute }
|
|
5970
|
+
{ testIdAttribute, renderCache }
|
|
5932
5971
|
);
|
|
5933
5972
|
generatedFiles.push(...vueTestUtilsFiles);
|
|
5934
5973
|
}
|
|
5935
5974
|
const gitattributesFiles = buildGeneratedGitAttributesFiles(generatedFiles.map((file) => file.filePath));
|
|
5936
5975
|
writeGeneratedOutputs(outDir, generatedFiles, gitattributesFiles, path.resolve(root));
|
|
5976
|
+
renderCache?.retain(new Set(generatedFiles.map((file) => file.filePath)));
|
|
5937
5977
|
}
|
|
5938
5978
|
const VUE_TEST_UTILS_OMITTED_PARAMETERS = /* @__PURE__ */ new Set(["annotationText", "timeOut", "timeout", "wait"]);
|
|
5939
5979
|
function getVueTestUtilsParameters(parameters, patterns, options = {}) {
|
|
@@ -6061,7 +6101,7 @@ function getVueTestUtilsComponentMembers(componentInstances, projectedComponentI
|
|
|
6061
6101
|
}));
|
|
6062
6102
|
return members;
|
|
6063
6103
|
}
|
|
6064
|
-
function generateVueTestUtilsContent(componentName, dependencies, componentHierarchyMap, outputDir, runtimePath, generatedFilePathByComponent, testIdAttribute) {
|
|
6104
|
+
function generateVueTestUtilsContent(componentName, dependencies, componentHierarchyMap, outputDir, runtimePath, generatedFilePathByComponent, testIdAttribute, renderCache) {
|
|
6065
6105
|
const prepared = prepareViewObjectModelClass(componentName, dependencies, componentHierarchyMap, {
|
|
6066
6106
|
testIdAttribute
|
|
6067
6107
|
});
|
|
@@ -6081,33 +6121,29 @@ function generateVueTestUtilsContent(componentName, dependencies, componentHiera
|
|
|
6081
6121
|
...getUniquePrimaryPomSpecs(dependencies).flatMap(({ pom }) => getVueTestUtilsPrimaryMembers(pom)),
|
|
6082
6122
|
...(dependencies.pomExtraMethods ?? []).flatMap(getVueTestUtilsExtraMembers)
|
|
6083
6123
|
];
|
|
6084
|
-
return
|
|
6085
|
-
|
|
6124
|
+
return renderStructuredSourceFile(path.join(outputDir, `${componentName}.vtu.g.ts`), {
|
|
6125
|
+
statements: [{
|
|
6126
|
+
kind: StructureKind.ImportDeclaration,
|
|
6086
6127
|
moduleSpecifier: runtimeImport,
|
|
6087
6128
|
namedImports: ["VueTestUtilsPom"]
|
|
6088
|
-
}
|
|
6089
|
-
|
|
6129
|
+
}, {
|
|
6130
|
+
kind: StructureKind.ImportDeclaration,
|
|
6090
6131
|
moduleSpecifier: runtimeImport,
|
|
6091
6132
|
namedImports: ["VueTestUtilsPomRoot"],
|
|
6092
6133
|
isTypeOnly: true
|
|
6093
|
-
})
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
});
|
|
6099
|
-
}
|
|
6100
|
-
const declaration = sourceFile.addClass({
|
|
6134
|
+
}, ...componentImports.map((componentImport) => ({
|
|
6135
|
+
kind: StructureKind.ImportDeclaration,
|
|
6136
|
+
moduleSpecifier: componentImport.moduleSpecifier,
|
|
6137
|
+
namedImports: [componentImport.className]
|
|
6138
|
+
})), createClassDeclaration({
|
|
6101
6139
|
name: prepared.className,
|
|
6102
6140
|
isExported: true,
|
|
6103
6141
|
extends: "VueTestUtilsPom",
|
|
6104
6142
|
docs: [`Vue Test Utils object for ${componentName} (source: ${sourceRel}).`]
|
|
6105
|
-
})
|
|
6106
|
-
for (const member of members) {
|
|
6107
|
-
addClassMember(declaration, member);
|
|
6108
|
-
}
|
|
6143
|
+
}, members)]
|
|
6109
6144
|
}, {
|
|
6110
|
-
prefixText: buildFilePrefix({ eslintDisableSortImports: true })
|
|
6145
|
+
prefixText: buildFilePrefix({ eslintDisableSortImports: true }),
|
|
6146
|
+
cache: renderCache
|
|
6111
6147
|
});
|
|
6112
6148
|
}
|
|
6113
6149
|
function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {}) {
|
|
@@ -6129,7 +6165,8 @@ function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {})
|
|
|
6129
6165
|
path.dirname(filePath),
|
|
6130
6166
|
runtimePath,
|
|
6131
6167
|
generatedFilePathByComponent,
|
|
6132
|
-
testIdAttribute
|
|
6168
|
+
testIdAttribute,
|
|
6169
|
+
options.renderCache
|
|
6133
6170
|
)
|
|
6134
6171
|
};
|
|
6135
6172
|
});
|
|
@@ -6141,12 +6178,13 @@ function generateVueTestUtilsFiles(componentHierarchyMap, outDir, options = {})
|
|
|
6141
6178
|
if (!runtimeFile) {
|
|
6142
6179
|
throw new Error("[vue-pom-generator] Failed to generate the Vue Test Utils runtime.");
|
|
6143
6180
|
}
|
|
6144
|
-
const indexContent =
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
}
|
|
6181
|
+
const indexContent = renderStructuredSourceFile(path.join(base, "index.ts"), {
|
|
6182
|
+
statements: [
|
|
6183
|
+
stripExtension(toPosixRelativePath(base, runtimePath)),
|
|
6184
|
+
...Array.from(generatedFilePathByComponent.values(), (filePath) => `./${stripExtension(path.basename(filePath))}`)
|
|
6185
|
+
].map((moduleSpecifier) => ({ kind: StructureKind.ExportDeclaration, moduleSpecifier }))
|
|
6149
6186
|
}, {
|
|
6187
|
+
cache: options.renderCache,
|
|
6150
6188
|
prefixText: buildFilePrefix({
|
|
6151
6189
|
eslintDisableSortImports: true,
|
|
6152
6190
|
commentLines: [
|
|
@@ -6200,6 +6238,7 @@ async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathM
|
|
|
6200
6238
|
continue;
|
|
6201
6239
|
}
|
|
6202
6240
|
const content = generateViewObjectModelContent(name, deps, componentHierarchyMap, vueFilesPathMap, runtimeBasePagePath, {
|
|
6241
|
+
renderCache: options.renderCache,
|
|
6203
6242
|
outputDir: path.dirname(filePath),
|
|
6204
6243
|
customPomAttachments: options.customPomAttachments ?? [],
|
|
6205
6244
|
projectRoot,
|
|
@@ -6227,6 +6266,8 @@ async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathM
|
|
|
6227
6266
|
const childImports = getChildImportSpecifiers(outputDir, composed?.childClassNames ?? [], generatedTsFilePathByComponent);
|
|
6228
6267
|
const members = composed?.members ?? getDefaultStubMembers();
|
|
6229
6268
|
const content = renderSplitStubPomContent({
|
|
6269
|
+
filePath,
|
|
6270
|
+
renderCache: options.renderCache,
|
|
6230
6271
|
className: targetClassName,
|
|
6231
6272
|
basePageImportSpecifier,
|
|
6232
6273
|
childImports,
|
|
@@ -6236,14 +6277,13 @@ async function generateSplitTypeScriptFiles(componentHierarchyMap, vueFilesPathM
|
|
|
6236
6277
|
}
|
|
6237
6278
|
const runtimeAssetSpecs = getRuntimeGeneratedAssetSpecs(base, basePageClassPath);
|
|
6238
6279
|
const runtimeFiles = buildRuntimeGeneratedFilesFromSpecs(runtimeAssetSpecs);
|
|
6239
|
-
const indexContent =
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
addExportAll(sourceFile, `./${stripExtension(path.basename(filePath))}`);
|
|
6245
|
-
}
|
|
6280
|
+
const indexContent = renderStructuredSourceFile(path.join(base, "index.ts"), {
|
|
6281
|
+
statements: [
|
|
6282
|
+
...runtimeAssetSpecs.map((spec) => stripExtension(toPosixRelativePath(base, spec.outputPath))),
|
|
6283
|
+
...Array.from(generatedTsFilePathByComponent.entries()).sort((a, b) => a[0].localeCompare(b[0])).map(([, filePath]) => `./${stripExtension(path.basename(filePath))}`)
|
|
6284
|
+
].map((moduleSpecifier) => ({ kind: StructureKind.ExportDeclaration, moduleSpecifier }))
|
|
6246
6285
|
}, {
|
|
6286
|
+
cache: options.renderCache,
|
|
6247
6287
|
prefixText: buildFilePrefix({
|
|
6248
6288
|
eslintDisableSortImports: true,
|
|
6249
6289
|
commentLines: [
|
|
@@ -6919,7 +6959,8 @@ function maybeGenerateFixtureRegistry(componentHierarchyMap, options) {
|
|
|
6919
6959
|
const manifestContent = generatePomManifestModule(
|
|
6920
6960
|
componentHierarchyMap,
|
|
6921
6961
|
options.elementMetadata,
|
|
6922
|
-
manifestFileName
|
|
6962
|
+
path.resolve(fixtureOutDirAbs, manifestFileName),
|
|
6963
|
+
options.renderCache
|
|
6923
6964
|
);
|
|
6924
6965
|
const [diagnosticsRuntimeFile] = buildRuntimeGeneratedFilesFromSpecs([{
|
|
6925
6966
|
absolutePath: resolvePluginAsset("../class-generation/diagnostics.ts"),
|
|
@@ -7267,40 +7308,33 @@ function generateViewObjectModelContent(componentName, dependencies, componentHi
|
|
|
7267
7308
|
generatedImports.sort((a, b) => a.className.localeCompare(b.className));
|
|
7268
7309
|
const prefixText = `${buildFilePrefix({ eslintDisableSortImports: true })}${doc}
|
|
7269
7310
|
`;
|
|
7270
|
-
return
|
|
7271
|
-
|
|
7311
|
+
return renderStructuredSourceFile(path.join(outputDir, `${componentName}.g.ts`), {
|
|
7312
|
+
statements: [{
|
|
7313
|
+
kind: StructureKind.ImportDeclaration,
|
|
7272
7314
|
moduleSpecifier: "@playwright/test",
|
|
7273
7315
|
isTypeOnly: true,
|
|
7274
7316
|
namedImports: [
|
|
7275
7317
|
{ name: "Locator", alias: "PwLocator" },
|
|
7276
7318
|
{ name: "Page", alias: "PwPage" }
|
|
7277
7319
|
]
|
|
7278
|
-
}
|
|
7279
|
-
|
|
7320
|
+
}, {
|
|
7321
|
+
kind: StructureKind.ImportDeclaration,
|
|
7280
7322
|
moduleSpecifier: basePageImportSpecifier,
|
|
7281
7323
|
namedImports: ["BasePage", "Fluent"]
|
|
7282
|
-
})
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7286
|
-
|
|
7287
|
-
|
|
7288
|
-
|
|
7289
|
-
|
|
7290
|
-
|
|
7291
|
-
moduleSpecifier: generatedImport.moduleSpecifier,
|
|
7292
|
-
namedImports: [generatedImport.className]
|
|
7293
|
-
});
|
|
7294
|
-
}
|
|
7295
|
-
const classDeclaration = sourceFile.addClass({
|
|
7324
|
+
}, ...customImports.map((customImport) => ({
|
|
7325
|
+
kind: StructureKind.ImportDeclaration,
|
|
7326
|
+
moduleSpecifier: customImport.moduleSpecifier,
|
|
7327
|
+
namedImports: [{ name: customImport.name, alias: customImport.alias }]
|
|
7328
|
+
})), ...generatedImports.map((generatedImport) => ({
|
|
7329
|
+
kind: StructureKind.ImportDeclaration,
|
|
7330
|
+
moduleSpecifier: generatedImport.moduleSpecifier,
|
|
7331
|
+
namedImports: [generatedImport.className]
|
|
7332
|
+
})), createClassDeclaration({
|
|
7296
7333
|
name: prepared.className,
|
|
7297
7334
|
isExported: true,
|
|
7298
7335
|
extends: "BasePage"
|
|
7299
|
-
})
|
|
7300
|
-
|
|
7301
|
-
addClassMember(classDeclaration, member);
|
|
7302
|
-
}
|
|
7303
|
-
}, { prefixText });
|
|
7336
|
+
}, prepared.members)]
|
|
7337
|
+
}, { prefixText, cache: options.renderCache });
|
|
7304
7338
|
}
|
|
7305
7339
|
function getViewPassthroughMethods(viewName, viewDependencies, componentInstances, componentHierarchyMap, blockedMethodNames = /* @__PURE__ */ new Set()) {
|
|
7306
7340
|
const existingOnView = viewDependencies.generatedMethods ?? /* @__PURE__ */ new Map();
|
|
@@ -7521,35 +7555,32 @@ function renderSplitStubPomContent(options) {
|
|
|
7521
7555
|
"Changes should be made in the generator/template, not in the generated output."
|
|
7522
7556
|
]
|
|
7523
7557
|
});
|
|
7524
|
-
return
|
|
7525
|
-
|
|
7558
|
+
return renderStructuredSourceFile(options.filePath, {
|
|
7559
|
+
// Stub ctors take Playwright's full `Page` (aliased `PwPage`), matching non-stub generated
|
|
7560
|
+
// POMs — stubs are constructed with `new Stub(this.page)` where `this.page` is `Page`.
|
|
7561
|
+
statements: [{
|
|
7562
|
+
kind: StructureKind.ImportDeclaration,
|
|
7526
7563
|
moduleSpecifier: "@playwright/test",
|
|
7527
7564
|
isTypeOnly: true,
|
|
7528
7565
|
namedImports: [{ name: "Page", alias: "PwPage" }]
|
|
7529
|
-
}
|
|
7530
|
-
|
|
7566
|
+
}, {
|
|
7567
|
+
kind: StructureKind.ImportDeclaration,
|
|
7531
7568
|
moduleSpecifier: options.basePageImportSpecifier,
|
|
7532
7569
|
namedImports: ["BasePage"]
|
|
7533
|
-
})
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
});
|
|
7539
|
-
}
|
|
7540
|
-
sourceFile.addStatements(buildCommentBlock([
|
|
7541
|
-
"Stub POM generated because it is referenced as a navigation target but",
|
|
7542
|
-
"did not have any generated test ids in this build."
|
|
7543
|
-
]).trimEnd());
|
|
7544
|
-
const classDeclaration = sourceFile.addClass({
|
|
7570
|
+
}, ...options.childImports.map((childImport) => ({
|
|
7571
|
+
kind: StructureKind.ImportDeclaration,
|
|
7572
|
+
moduleSpecifier: childImport.importPath,
|
|
7573
|
+
namedImports: [childImport.className]
|
|
7574
|
+
})), createClassDeclaration({
|
|
7545
7575
|
name: options.className,
|
|
7546
7576
|
isExported: true,
|
|
7547
|
-
extends: "BasePage"
|
|
7548
|
-
|
|
7549
|
-
|
|
7550
|
-
|
|
7551
|
-
|
|
7552
|
-
|
|
7577
|
+
extends: "BasePage",
|
|
7578
|
+
leadingTrivia: buildCommentBlock([
|
|
7579
|
+
"Stub POM generated because it is referenced as a navigation target but",
|
|
7580
|
+
"did not have any generated test ids in this build."
|
|
7581
|
+
])
|
|
7582
|
+
}, options.members)]
|
|
7583
|
+
}, { prefixText, cache: options.renderCache });
|
|
7553
7584
|
}
|
|
7554
7585
|
function getChildImportSpecifiers(outputDir, childClassNames, generatedTsFilePathByComponent) {
|
|
7555
7586
|
return childClassNames.map((childClassName) => {
|
|
@@ -7563,37 +7594,6 @@ function getChildImportSpecifiers(outputDir, childClassNames, generatedTsFilePat
|
|
|
7563
7594
|
};
|
|
7564
7595
|
}).filter((entry) => !!entry).sort((a, b) => a.className.localeCompare(b.className));
|
|
7565
7596
|
}
|
|
7566
|
-
function isConstructorMember(member) {
|
|
7567
|
-
return member.kind === StructureKind.Constructor;
|
|
7568
|
-
}
|
|
7569
|
-
function isGetterMember(member) {
|
|
7570
|
-
return member.kind === StructureKind.GetAccessor;
|
|
7571
|
-
}
|
|
7572
|
-
function isMethodMember(member) {
|
|
7573
|
-
return member.kind === StructureKind.Method;
|
|
7574
|
-
}
|
|
7575
|
-
function isPropertyMember(member) {
|
|
7576
|
-
return member.kind === StructureKind.Property;
|
|
7577
|
-
}
|
|
7578
|
-
function addClassMember(classDeclaration, member) {
|
|
7579
|
-
if (isConstructorMember(member)) {
|
|
7580
|
-
classDeclaration.addConstructor(member);
|
|
7581
|
-
return;
|
|
7582
|
-
}
|
|
7583
|
-
if (isGetterMember(member)) {
|
|
7584
|
-
classDeclaration.addGetAccessor(member);
|
|
7585
|
-
return;
|
|
7586
|
-
}
|
|
7587
|
-
if (isMethodMember(member)) {
|
|
7588
|
-
classDeclaration.addMethod(member);
|
|
7589
|
-
return;
|
|
7590
|
-
}
|
|
7591
|
-
if (isPropertyMember(member)) {
|
|
7592
|
-
classDeclaration.addProperty(member);
|
|
7593
|
-
return;
|
|
7594
|
-
}
|
|
7595
|
-
throw new Error(`Unsupported class member structure: ${String(member)}`);
|
|
7596
|
-
}
|
|
7597
7597
|
function getRuntimeGeneratedAssetSpecs(baseDir, basePageClassPath) {
|
|
7598
7598
|
const runtimeDirAbs = path.join(baseDir, "_pom-runtime");
|
|
7599
7599
|
const runtimeClassGenAbs = path.join(runtimeDirAbs, "class-generation");
|
|
@@ -7871,37 +7871,30 @@ async function generateAggregatedFiles(componentHierarchyMap, vueFilesPathMap, b
|
|
|
7871
7871
|
"Changes should be made in the generator/template, not in the generated output."
|
|
7872
7872
|
]
|
|
7873
7873
|
});
|
|
7874
|
-
return
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
|
|
7878
|
-
for (const entry of [...classes, ...stubs]) {
|
|
7879
|
-
if (entry.isStub) {
|
|
7880
|
-
sourceFile.addStatements(buildCommentBlock([
|
|
7881
|
-
"Stub POM generated because it is referenced as a navigation target but",
|
|
7882
|
-
"did not have any generated test ids in this build."
|
|
7883
|
-
]).trimEnd());
|
|
7884
|
-
} else {
|
|
7885
|
-
sourceFile.addStatements(entry.doc);
|
|
7886
|
-
}
|
|
7887
|
-
const classDeclaration = sourceFile.addClass({
|
|
7874
|
+
return renderStructuredSourceFile(path.join(outputDir, "page-object-models.g.ts"), {
|
|
7875
|
+
statements: [
|
|
7876
|
+
...imports,
|
|
7877
|
+
...[...classes, ...stubs].map((entry) => createClassDeclaration({
|
|
7888
7878
|
name: entry.className,
|
|
7889
7879
|
isExported: true,
|
|
7890
|
-
extends: "BasePage"
|
|
7891
|
-
|
|
7892
|
-
|
|
7893
|
-
|
|
7894
|
-
|
|
7895
|
-
|
|
7896
|
-
|
|
7880
|
+
extends: "BasePage",
|
|
7881
|
+
leadingTrivia: entry.isStub ? buildCommentBlock([
|
|
7882
|
+
"Stub POM generated because it is referenced as a navigation target but",
|
|
7883
|
+
"did not have any generated test ids in this build."
|
|
7884
|
+
]) : `${entry.doc}
|
|
7885
|
+
`
|
|
7886
|
+
}, entry.members))
|
|
7887
|
+
]
|
|
7888
|
+
}, { prefixText, cache: options.renderCache });
|
|
7897
7889
|
};
|
|
7898
7890
|
const base = ensureDir(outDir);
|
|
7899
7891
|
const outputFile = path.join(base, "page-object-models.g.ts");
|
|
7900
7892
|
const content = makeAggregatedContent(path.dirname(outputFile), [...views, ...components]);
|
|
7901
7893
|
const indexFile = path.join(base, "index.ts");
|
|
7902
|
-
const indexContent =
|
|
7903
|
-
|
|
7894
|
+
const indexContent = renderStructuredSourceFile(indexFile, {
|
|
7895
|
+
statements: [{ kind: StructureKind.ExportDeclaration, moduleSpecifier: "./page-object-models.g" }]
|
|
7904
7896
|
}, {
|
|
7897
|
+
cache: options.renderCache,
|
|
7905
7898
|
prefixText: buildFilePrefix({
|
|
7906
7899
|
eslintDisableSortImports: true,
|
|
7907
7900
|
commentLines: [
|
|
@@ -10718,6 +10711,7 @@ function createDevProcessorPlugin(options) {
|
|
|
10718
10711
|
scheduleVueFileRegen(ctx.file, "hmr");
|
|
10719
10712
|
},
|
|
10720
10713
|
async configureServer(server) {
|
|
10714
|
+
const renderCache = new TypeScriptRenderCache();
|
|
10721
10715
|
const getViewsDirAbs = () => resolveProjectPath(getViewsDir());
|
|
10722
10716
|
const getPageDirsAbs = () => getPageDirs().map((dir) => resolveProjectPath(dir));
|
|
10723
10717
|
const routerInitPromise = (async () => {
|
|
@@ -10925,6 +10919,7 @@ function createDevProcessorPlugin(options) {
|
|
|
10925
10919
|
const generateAggregatedFromSnapshot = async (logLabel) => {
|
|
10926
10920
|
const t0 = performance.now();
|
|
10927
10921
|
await generateFiles(snapshotHierarchy, snapshotVuePathMap, normalizedBasePagePath, {
|
|
10922
|
+
renderCache,
|
|
10928
10923
|
outDir,
|
|
10929
10924
|
emitLanguages,
|
|
10930
10925
|
typescriptOutputStructure,
|