@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 CHANGED
@@ -1,86 +1,52 @@
1
- v1.0.106 already covered PR #69, and v1.0.106..HEAD contains only PR #70's commit — so these notes
2
- cover #70. Let me review the actual diff to summarize it accurately.
3
-
4
- All context gathered. The v1.0.106..HEAD range contains only PR #70's commit (#69 was already
5
- shipped in v1.0.106), so these notes cover #70 only.
6
-
7
- v1.0.107
1
+ Release window confirmed: only #72 and #71 fall in range (commit log matches). Now let me review the
2
+ actual diffs to write accurate notes.
8
3
 
9
4
  Highlights
10
5
 
11
- - New generateVuePoms() one-shot API generates all configured POMs once — without the app server,
12
- bundling, or asset output — so a typechecker can run on generated imports before the app starts.
13
- - Generated outputs are now tracked in an ownership manifest (.vue-pom-generator-outputs.json), so
14
- later runs clean up only what the generator previously emitted: renamed/deleted components,
15
- split↔aggregate switches, disabled languages, and moved/disabled VTU or fixture outputs.
16
- - Cleanup is safe by construction: all outputs are rendered, validated, and written atomically
17
- before any pruning; handwritten neighbors and files outside the manifest are never touched, and
18
- failures leave the previous outputs intact.
19
- - Source analysis is unified: the SFC parse/compile pipeline is shared between Vite builds and
20
- one-shot generation, and invalid component sources now fail fast instead of being silently dropped
21
- from POM output.
6
+ - No more HMR regeneration loops on save: unchanged POM renders are now reused, and generated files
7
+ are only rewritten when their bytes actually change — keeping mtimes and Vite watcher state intact
8
+ (]8;id=md-di7kpu;https://github.com/immense/vue-pom-generator/pull/71#71]8;;]8;;).]8;;
9
+ - Faster dev-server saves: a per-dev-server render cache memoizes TypeScript codegen per output
10
+ file, keyed on the serialized render structure (]8;id=md-di7kpu;https://github.com/immense/vue-pom-generator/pull/71#71]8;;]8;;).]8;;
11
+ - Correct v-for alias shadowing: slot-scope callback detection now uses Vue's parsed v-for bindings
12
+ (value/key/index, including destructuring, defaults, and rest) instead of re-parsing alias
13
+ expressions (]8;id=md-d87z0v;https://github.com/immense/vue-pom-generator/pull/72#72]8;;]8;;).]8;;
14
+ - Clean lint is enforced: the release workflow now fails on any lint warning (--max-warnings 0)
15
+ (]8;id=md-d87z0v;https://github.com/immense/vue-pom-generator/pull/72#72]8;;]8;;).]8;;
22
16
 
23
17
  Changes
24
18
 
25
- One-shot generation
26
-
27
- - Add generateVuePoms(options, viteOptions?) and VuePomGenerationViteOptions, exported from the
28
- main entry point (#70).
29
- - Runs a generation-only Vite build with no application entry, asset output, public-directory copy,
30
- or dev server; relative output paths resolve against the provided Vite root.
31
- - Accepts explicit Vite root, mode, resolve, plugins, and logLevel — the application's vite.config
32
- is never loaded implicitly; pass only companion plugins needed for generation (e.g., an app-owned
33
- vue() plugin for vuePluginOwnership: "external").
34
- - Always scans configured source directories (no timestamp cache); an empty source directory is
35
- valid and removes its previous outputs, while no existing source directories is an error.
36
- - Rejects Nuxt projects (use the Nuxt Vite integration), disabled generation, and overlapping
37
- concurrent calls — router introspection uses process-wide state, so calls must be awaited
38
- sequentially and fail explicitly otherwise.
39
-
40
- Generated output ownership and cleanup
41
-
42
- - Record each successful emission in <generation.outDir>/.vue-pom-generator-outputs.json (versioned
43
- manifest with content hashes); keep the manifest with its generated output, and note that the first
44
- run does not claim files produced by older releases.
45
- - Prune only previously-owned, unchanged files that are no longer emitted — after the new outputs
46
- are written — so a failed compilation or emission leaves the previous files and manifest intact.
47
- - Error (naming the file) when an obsolete generated file was hand-edited; reject output
48
- files/directories that are symlinks, including symlinked parents shared with sibling output
49
- directories.
50
- - Treat shared .gitattributes files as consumer-owned: update the generator block without claiming
51
- ownership or pruning the file.
52
- - Resolve generation.outDir and generation.vueTestUtils.outDir against the project root (VTU out
53
- dir must still differ from the POM out dir).
54
-
55
- Internals
19
+ Incremental generation (]8;id=md-di7kpu;https://github.com/immense/vue-pom-generator/pull/71#71]8;;]8;;)]8;;
56
20
 
57
- - Extract the SFC parse/compile step into a shared collectSource used by both the
58
- metadata-collector transform and the build plugin's filesystem supplement walk, removing the build
59
- plugin's duplicated, error-swallowing compile path; SFC parse/template-compile errors now surface
60
- instead of silently omitting the component.
61
- - Skip the "selector-less" and "less-rich snapshot" guards in generation-only mode so one-shot runs
62
- always emit; record (or clear) element metadata even for template-less components.
63
- - Deduplicate shared generator state construction and scope the shared-state key to the provided
64
- project root.
21
+ - Add TypeScriptRenderCache and renderStructuredSourceFile in typescript-codegen.ts: renders are
22
+ memoized per output path, with writer closures resolved to their emitted text before comparison so
23
+ changed selectors, routes, and child methods still invalidate the cache.
24
+ - Refactor class-generation/index.ts to render through cached structured structures; the dev plugin
25
+ owns one cache per dev server and passes it into generateFiles.
26
+ - Skip writing generated files when content is unchanged, repairing removed or externally modified
27
+ outputs.
28
+ - Render the POM manifest module via the structured, cache-aware path (manifest-generator.ts).
29
+ - Add regression coverage (tests/incremental-generation.test.ts, tests/generated-outputs.test.ts)
30
+ plus a repro script and write-up (scripts/repro-hmr-regeneration.mjs,
31
+ docs/hmr-regeneration-reproduction.md).
65
32
 
66
- Breaking Changes
33
+ Vue template semantics & lint (]8;id=md-d87z0v;https://github.com/immense/vue-pom-generator/pull/72#72]8;;]8;;)]8;;
67
34
 
68
- None — the release is additive. Note that invalid component sources now fail builds instead of being
69
- silently skipped, and handwritten edits to generator-owned obsolete files block regeneration until
70
- moved or removed.
35
+ - Track v-for alias shadowing via Vue's forParseResult bindings; binding-pattern parsing now
36
+ matches Vue's function-parameter semantics for object/array destructuring.
37
+ - Update test fixtures (MyList, MyRadioGroup) to use canonical Vue loop bindings and satisfy lint
38
+ rules.
39
+ - Add a Lint step (--max-warnings 0) to the release workflow.
71
40
 
72
41
  Pull Requests Included
73
42
 
74
- - ]8;id=md-ds76et;https://github.com/immense/vue-pom-generator/pull/70#70]8;;]8;; — feat: add one-shot generation and owned cleanup (@dkattan)]8;;
43
+ - ]8;id=md-d87z0v;https://github.com/immense/vue-pom-generator/pull/72#72]8;;]8;; — fix: use Vue loop bindings and enforce clean lint]8;;
44
+ - ]8;id=md-di7kpu;https://github.com/immense/vue-pom-generator/pull/71#71]8;;]8;; — fix: avoid rebuilding unchanged POMs on save]8;;
75
45
 
76
46
  Testing
77
47
 
78
- - New tests/generate-vue-poms.test.ts (12 cases): byte-for-byte parity with a real Vue build,
79
- pruning across renames/mode switches/disabled outputs, failure atomicity, companion plugins, and
80
- concurrency guards.
81
- - New tests/generated-outputs.test.ts (9 cases): manifest pruning, hand-edited obsolete files,
82
- write-failure behavior, and symlink/malformed-manifest rejection.
83
- - scripts/packed-smoke-check.mjs now exercises one-shot generation from the packed package in both
84
- ESM and CJS, and asserts the app build prunes the obsolete split POM. Test suites were not run as
85
- part of these notes.
48
+ - Added tests/incremental-generation.test.ts covering cache reuse and invalidation; extended
49
+ tests/utils.test.ts with v-for alias shadowing cases (simple, nested/defaulted/renamed/rest object
50
+ patterns, array patterns with of) and updated tests/generated-outputs.test.ts.
51
+ - Release CI now also runs the lint suite with warnings disallowed.
86
52
 
@@ -34,7 +34,6 @@ import {
34
34
  import { buildPomLocatorDescription, stripPomActionPrefix } from "../pom-discoverability";
35
35
  import { introspectNuxtPages, parseRouterFileFromCwd } from "../router-introspection";
36
36
  import {
37
- addExportAll,
38
37
  addNamedImport,
39
38
  buildCommentBlock,
40
39
  buildFilePrefix,
@@ -42,17 +41,14 @@ import {
42
41
  createClassGetter,
43
42
  createClassMethod,
44
43
  createClassProperty,
44
+ createClassDeclaration,
45
45
  renderSourceFile,
46
+ renderStructuredSourceFile,
46
47
  StructureKind,
47
48
  VariableDeclarationKind,
48
- type ConstructorDeclarationStructure,
49
- type GetAccessorDeclarationStructure,
50
- type MethodDeclarationStructure,
51
- type OptionalKind,
52
- type PropertyDeclarationStructure,
53
49
  type TypeScriptClassMember,
54
- type TypeScriptSourceFile,
55
50
  type TypeScriptWriter,
51
+ type TypeScriptRenderCache,
56
52
  } from "../typescript-codegen";
57
53
  import {
58
54
  IComponentDependencies,
@@ -742,6 +738,8 @@ function generateMethodsContentForDependencies(componentName: string, dependenci
742
738
  }
743
739
 
744
740
  export interface GenerateFilesOptions {
741
+ /** Per-dev-server rendering cache. Omitted for stateless one-shot/build generation. */
742
+ renderCache?: TypeScriptRenderCache;
745
743
  /**
746
744
  * Output directory for generated files.
747
745
  *
@@ -848,6 +846,7 @@ export interface GenerateFilesOptions {
848
846
  }
849
847
 
850
848
  interface BaseGenerateContentOptions {
849
+ renderCache?: TypeScriptRenderCache;
851
850
  /** Directory the generated .g.ts file will live in (used for relative imports). Defaults to the Vue file's directory. */
852
851
  outputDir?: string;
853
852
 
@@ -906,6 +905,7 @@ export async function generateFiles(
906
905
  layoutDirs,
907
906
  routeMetaByComponent: routeMetaByComponentOverride,
908
907
  elementMetadata = new Map<string, Map<string, ElementMetadata>>(),
908
+ renderCache,
909
909
  } = options;
910
910
 
911
911
  const emitLanguages: Array<"ts" | "csharp"> = emitLanguagesOverride?.length
@@ -933,6 +933,7 @@ export async function generateFiles(
933
933
  if (emitLanguages.includes("ts")) {
934
934
  const files = typescriptOutputStructure === "split"
935
935
  ? await generateSplitTypeScriptFiles(emittableComponentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, {
936
+ renderCache,
936
937
  customPomAttachments,
937
938
  projectRoot,
938
939
  customPomDir,
@@ -944,6 +945,7 @@ export async function generateFiles(
944
945
  vueRouterFluentChaining,
945
946
  })
946
947
  : await generateAggregatedFiles(emittableComponentHierarchyMap, vueFilesPathMap, basePageClassPath, outDir, {
948
+ renderCache,
947
949
  customPomAttachments,
948
950
  projectRoot,
949
951
  customPomDir,
@@ -958,6 +960,7 @@ export async function generateFiles(
958
960
  generatedFiles.push(...files);
959
961
 
960
962
  const fixtureRegistryFiles = maybeGenerateFixtureRegistry(emittableComponentHierarchyMap, {
963
+ renderCache,
961
964
  generateFixtures,
962
965
  pomOutDir: outDir,
963
966
  projectRoot,
@@ -981,13 +984,14 @@ export async function generateFiles(
981
984
  const vueTestUtilsFiles = generateVueTestUtilsFiles(
982
985
  emittableComponentHierarchyMap,
983
986
  vueTestUtilsOutDir,
984
- { testIdAttribute },
987
+ { testIdAttribute, renderCache },
985
988
  );
986
989
  generatedFiles.push(...vueTestUtilsFiles);
987
990
  }
988
991
 
989
992
  const gitattributesFiles = buildGeneratedGitAttributesFiles(generatedFiles.map(file => file.filePath));
990
993
  writeGeneratedOutputs(outDir, generatedFiles, gitattributesFiles, path.resolve(root));
994
+ renderCache?.retain(new Set(generatedFiles.map(file => file.filePath)));
991
995
  }
992
996
 
993
997
  const VUE_TEST_UTILS_OMITTED_PARAMETERS = new Set(["annotationText", "timeOut", "timeout", "wait"]);
@@ -1160,6 +1164,7 @@ function generateVueTestUtilsContent(
1160
1164
  runtimePath: string,
1161
1165
  generatedFilePathByComponent: Map<string, string>,
1162
1166
  testIdAttribute: string,
1167
+ renderCache?: TypeScriptRenderCache,
1163
1168
  ): string {
1164
1169
  const prepared = prepareViewObjectModelClass(componentName, dependencies, componentHierarchyMap, {
1165
1170
  outputStructure: "split",
@@ -1188,41 +1193,36 @@ function generateVueTestUtilsContent(
1188
1193
  ...(dependencies.pomExtraMethods ?? []).flatMap(getVueTestUtilsExtraMembers),
1189
1194
  ];
1190
1195
 
1191
- return renderSourceFile(`${componentName}.vtu.g.ts`, (sourceFile) => {
1192
- addNamedImport(sourceFile, {
1196
+ return renderStructuredSourceFile(path.join(outputDir, `${componentName}.vtu.g.ts`), {
1197
+ statements: [{
1198
+ kind: StructureKind.ImportDeclaration,
1193
1199
  moduleSpecifier: runtimeImport,
1194
1200
  namedImports: ["VueTestUtilsPom"],
1195
- });
1196
- addNamedImport(sourceFile, {
1201
+ }, {
1202
+ kind: StructureKind.ImportDeclaration,
1197
1203
  moduleSpecifier: runtimeImport,
1198
1204
  namedImports: ["VueTestUtilsPomRoot"],
1199
1205
  isTypeOnly: true,
1200
- });
1201
- for (const componentImport of componentImports) {
1202
- addNamedImport(sourceFile, {
1203
- moduleSpecifier: componentImport.moduleSpecifier,
1204
- namedImports: [componentImport.className],
1205
- });
1206
- }
1207
-
1208
- const declaration = sourceFile.addClass({
1206
+ }, ...componentImports.map(componentImport => ({
1207
+ kind: StructureKind.ImportDeclaration as const,
1208
+ moduleSpecifier: componentImport.moduleSpecifier,
1209
+ namedImports: [componentImport.className],
1210
+ })), createClassDeclaration({
1209
1211
  name: prepared.className,
1210
1212
  isExported: true,
1211
1213
  extends: "VueTestUtilsPom",
1212
1214
  docs: [`Vue Test Utils object for ${componentName} (source: ${sourceRel}).`],
1213
- });
1214
- for (const member of members) {
1215
- addClassMember(declaration, member);
1216
- }
1215
+ }, members)],
1217
1216
  }, {
1218
1217
  prefixText: buildFilePrefix({ eslintDisableSortImports: true }),
1218
+ cache: renderCache,
1219
1219
  });
1220
1220
  }
1221
1221
 
1222
1222
  function generateVueTestUtilsFiles(
1223
1223
  componentHierarchyMap: Map<string, IComponentDependencies>,
1224
1224
  outDir: string,
1225
- options: { testIdAttribute?: string } = {},
1225
+ options: { testIdAttribute?: string; renderCache?: TypeScriptRenderCache } = {},
1226
1226
  ): GeneratedFileOutput[] {
1227
1227
  const base = ensureDir(outDir);
1228
1228
  const testIdAttribute = options.testIdAttribute?.trim() || "data-testid";
@@ -1244,6 +1244,7 @@ function generateVueTestUtilsFiles(
1244
1244
  runtimePath,
1245
1245
  generatedFilePathByComponent,
1246
1246
  testIdAttribute,
1247
+ options.renderCache,
1247
1248
  ),
1248
1249
  };
1249
1250
  });
@@ -1255,12 +1256,13 @@ function generateVueTestUtilsFiles(
1255
1256
  if (!runtimeFile) {
1256
1257
  throw new Error("[vue-pom-generator] Failed to generate the Vue Test Utils runtime.");
1257
1258
  }
1258
- const indexContent = renderSourceFile("index.ts", (sourceFile) => {
1259
- addExportAll(sourceFile, stripExtension(toPosixRelativePath(base, runtimePath)));
1260
- for (const [, filePath] of generatedFilePathByComponent) {
1261
- addExportAll(sourceFile, `./${stripExtension(path.basename(filePath))}`);
1262
- }
1259
+ const indexContent = renderStructuredSourceFile(path.join(base, "index.ts"), {
1260
+ statements: [
1261
+ stripExtension(toPosixRelativePath(base, runtimePath)),
1262
+ ...Array.from(generatedFilePathByComponent.values(), filePath => `./${stripExtension(path.basename(filePath))}`),
1263
+ ].map(moduleSpecifier => ({ kind: StructureKind.ExportDeclaration, moduleSpecifier })),
1263
1264
  }, {
1265
+ cache: options.renderCache,
1264
1266
  prefixText: buildFilePrefix({
1265
1267
  eslintDisableSortImports: true,
1266
1268
  commentLines: [
@@ -1283,6 +1285,7 @@ async function generateSplitTypeScriptFiles(
1283
1285
  basePageClassPath: string,
1284
1286
  outDir: string,
1285
1287
  options: {
1288
+ renderCache?: TypeScriptRenderCache;
1286
1289
  customPomAttachments?: GenerateFilesOptions["customPomAttachments"];
1287
1290
  projectRoot?: GenerateFilesOptions["projectRoot"];
1288
1291
  customPomDir?: GenerateFilesOptions["customPomDir"];
@@ -1342,6 +1345,7 @@ async function generateSplitTypeScriptFiles(
1342
1345
  }
1343
1346
 
1344
1347
  const content = generateViewObjectModelContent(name, deps, componentHierarchyMap, vueFilesPathMap, runtimeBasePagePath, {
1348
+ renderCache: options.renderCache,
1345
1349
  outputDir: path.dirname(filePath),
1346
1350
  outputStructure: "split",
1347
1351
  customPomAttachments: options.customPomAttachments ?? [],
@@ -1373,6 +1377,8 @@ async function generateSplitTypeScriptFiles(
1373
1377
  const members = composed?.members ?? getDefaultStubMembers();
1374
1378
 
1375
1379
  const content = renderSplitStubPomContent({
1380
+ filePath,
1381
+ renderCache: options.renderCache,
1376
1382
  className: targetClassName,
1377
1383
  basePageImportSpecifier,
1378
1384
  childImports,
@@ -1384,14 +1390,15 @@ async function generateSplitTypeScriptFiles(
1384
1390
 
1385
1391
  const runtimeAssetSpecs = getRuntimeGeneratedAssetSpecs(base, basePageClassPath);
1386
1392
  const runtimeFiles = buildRuntimeGeneratedFilesFromSpecs(runtimeAssetSpecs);
1387
- const indexContent = renderSourceFile("index.ts", (sourceFile) => {
1388
- for (const spec of runtimeAssetSpecs) {
1389
- addExportAll(sourceFile, stripExtension(toPosixRelativePath(base, spec.outputPath)));
1390
- }
1391
- for (const [, filePath] of Array.from(generatedTsFilePathByComponent.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {
1392
- addExportAll(sourceFile, `./${stripExtension(path.basename(filePath))}`);
1393
- }
1393
+ const indexContent = renderStructuredSourceFile(path.join(base, "index.ts"), {
1394
+ statements: [
1395
+ ...runtimeAssetSpecs.map(spec => stripExtension(toPosixRelativePath(base, spec.outputPath))),
1396
+ ...Array.from(generatedTsFilePathByComponent.entries())
1397
+ .sort((a, b) => a[0].localeCompare(b[0]))
1398
+ .map(([, filePath]) => `./${stripExtension(path.basename(filePath))}`),
1399
+ ].map(moduleSpecifier => ({ kind: StructureKind.ExportDeclaration, moduleSpecifier })),
1394
1400
  }, {
1401
+ cache: options.renderCache,
1395
1402
  prefixText: buildFilePrefix({
1396
1403
  eslintDisableSortImports: true,
1397
1404
  commentLines: [
@@ -1860,6 +1867,7 @@ function generateAggregatedCSharpFiles(
1860
1867
  function maybeGenerateFixtureRegistry(
1861
1868
  componentHierarchyMap: Map<string, IComponentDependencies>,
1862
1869
  options: {
1870
+ renderCache?: TypeScriptRenderCache;
1863
1871
  generateFixtures: GenerateFilesOptions["generateFixtures"];
1864
1872
  pomOutDir: string;
1865
1873
  projectRoot?: string;
@@ -2219,7 +2227,8 @@ function maybeGenerateFixtureRegistry(
2219
2227
  const manifestContent = generatePomManifestModule(
2220
2228
  componentHierarchyMap,
2221
2229
  options.elementMetadata,
2222
- manifestFileName,
2230
+ path.resolve(fixtureOutDirAbs, manifestFileName),
2231
+ options.renderCache,
2223
2232
  );
2224
2233
  const [diagnosticsRuntimeFile] = buildRuntimeGeneratedFilesFromSpecs([{
2225
2234
  absolutePath: resolvePluginAsset("../class-generation/diagnostics.ts"),
@@ -2679,45 +2688,33 @@ function generateViewObjectModelContent(
2679
2688
  generatedImports.sort((a, b) => a.className.localeCompare(b.className));
2680
2689
 
2681
2690
  const prefixText = `${buildFilePrefix({ eslintDisableSortImports: true })}${doc}\n`;
2682
- return renderSourceFile(`${prepared.className}.ts`, (sourceFile) => {
2683
- addNamedImport(sourceFile, {
2691
+ return renderStructuredSourceFile(path.join(outputDir, `${componentName}.g.ts`), {
2692
+ statements: [{
2693
+ kind: StructureKind.ImportDeclaration,
2684
2694
  moduleSpecifier: "@playwright/test",
2685
2695
  isTypeOnly: true,
2686
2696
  namedImports: [
2687
2697
  { name: "Locator", alias: "PwLocator" },
2688
2698
  { name: "Page", alias: "PwPage" },
2689
2699
  ],
2690
- });
2691
-
2692
- addNamedImport(sourceFile, {
2700
+ }, {
2701
+ kind: StructureKind.ImportDeclaration,
2693
2702
  moduleSpecifier: basePageImportSpecifier,
2694
2703
  namedImports: ["BasePage", "Fluent"],
2695
- });
2696
-
2697
- for (const customImport of customImports) {
2698
- addNamedImport(sourceFile, {
2699
- moduleSpecifier: customImport.moduleSpecifier,
2700
- namedImports: [{ name: customImport.name, alias: customImport.alias }],
2701
- });
2702
- }
2703
-
2704
- for (const generatedImport of generatedImports) {
2705
- addNamedImport(sourceFile, {
2706
- moduleSpecifier: generatedImport.moduleSpecifier,
2707
- namedImports: [generatedImport.className],
2708
- });
2709
- }
2710
-
2711
- const classDeclaration = sourceFile.addClass({
2704
+ }, ...customImports.map(customImport => ({
2705
+ kind: StructureKind.ImportDeclaration as const,
2706
+ moduleSpecifier: customImport.moduleSpecifier,
2707
+ namedImports: [{ name: customImport.name, alias: customImport.alias }],
2708
+ })), ...generatedImports.map(generatedImport => ({
2709
+ kind: StructureKind.ImportDeclaration as const,
2710
+ moduleSpecifier: generatedImport.moduleSpecifier,
2711
+ namedImports: [generatedImport.className],
2712
+ })), createClassDeclaration({
2712
2713
  name: prepared.className,
2713
2714
  isExported: true,
2714
2715
  extends: "BasePage",
2715
- });
2716
-
2717
- for (const member of prepared.members) {
2718
- addClassMember(classDeclaration, member);
2719
- }
2720
- }, { prefixText });
2716
+ }, prepared.members)],
2717
+ }, { prefixText, cache: options.renderCache });
2721
2718
  }
2722
2719
 
2723
2720
  function getViewPassthroughMethods(
@@ -3000,6 +2997,8 @@ function getDefaultStubMembers(): TypeScriptClassMember[] {
3000
2997
  }
3001
2998
 
3002
2999
  function renderSplitStubPomContent(options: {
3000
+ filePath: string;
3001
+ renderCache?: TypeScriptRenderCache;
3003
3002
  className: string;
3004
3003
  basePageImportSpecifier: string;
3005
3004
  childImports: Array<{ className: string; importPath: string }>;
@@ -3016,37 +3015,32 @@ function renderSplitStubPomContent(options: {
3016
3015
  ],
3017
3016
  });
3018
3017
 
3019
- return renderSourceFile(`${options.className}.ts`, (sourceFile) => {
3018
+ return renderStructuredSourceFile(options.filePath, {
3020
3019
  // Stub ctors take Playwright's full `Page` (aliased `PwPage`), matching non-stub generated
3021
3020
  // POMs — stubs are constructed with `new Stub(this.page)` where `this.page` is `Page`.
3022
- addNamedImport(sourceFile, {
3021
+ statements: [{
3022
+ kind: StructureKind.ImportDeclaration,
3023
3023
  moduleSpecifier: "@playwright/test",
3024
3024
  isTypeOnly: true,
3025
3025
  namedImports: [{ name: "Page", alias: "PwPage" }],
3026
- });
3027
- addNamedImport(sourceFile, {
3026
+ }, {
3027
+ kind: StructureKind.ImportDeclaration,
3028
3028
  moduleSpecifier: options.basePageImportSpecifier,
3029
3029
  namedImports: ["BasePage"],
3030
- });
3031
- for (const childImport of options.childImports) {
3032
- addNamedImport(sourceFile, {
3033
- moduleSpecifier: childImport.importPath,
3034
- namedImports: [childImport.className],
3035
- });
3036
- }
3037
- sourceFile.addStatements(buildCommentBlock([
3038
- "Stub POM generated because it is referenced as a navigation target but",
3039
- "did not have any generated test ids in this build.",
3040
- ]).trimEnd());
3041
- const classDeclaration = sourceFile.addClass({
3030
+ }, ...options.childImports.map(childImport => ({
3031
+ kind: StructureKind.ImportDeclaration as const,
3032
+ moduleSpecifier: childImport.importPath,
3033
+ namedImports: [childImport.className],
3034
+ })), createClassDeclaration({
3042
3035
  name: options.className,
3043
3036
  isExported: true,
3044
3037
  extends: "BasePage",
3045
- });
3046
- for (const member of options.members) {
3047
- addClassMember(classDeclaration, member);
3048
- }
3049
- }, { prefixText });
3038
+ leadingTrivia: buildCommentBlock([
3039
+ "Stub POM generated because it is referenced as a navigation target but",
3040
+ "did not have any generated test ids in this build.",
3041
+ ]),
3042
+ }, options.members)],
3043
+ }, { prefixText, cache: options.renderCache });
3050
3044
  }
3051
3045
 
3052
3046
  function getChildImportSpecifiers(
@@ -3069,42 +3063,6 @@ function getChildImportSpecifiers(
3069
3063
  .sort((a, b) => a.className.localeCompare(b.className));
3070
3064
  }
3071
3065
 
3072
- function isConstructorMember(member: TypeScriptClassMember): member is OptionalKind<ConstructorDeclarationStructure> {
3073
- return member.kind === StructureKind.Constructor;
3074
- }
3075
-
3076
- function isGetterMember(member: TypeScriptClassMember): member is OptionalKind<GetAccessorDeclarationStructure> {
3077
- return member.kind === StructureKind.GetAccessor;
3078
- }
3079
-
3080
- function isMethodMember(member: TypeScriptClassMember): member is OptionalKind<MethodDeclarationStructure> {
3081
- return member.kind === StructureKind.Method;
3082
- }
3083
-
3084
- function isPropertyMember(member: TypeScriptClassMember): member is OptionalKind<PropertyDeclarationStructure> {
3085
- return member.kind === StructureKind.Property;
3086
- }
3087
-
3088
- function addClassMember(classDeclaration: ReturnType<TypeScriptSourceFile["addClass"]>, member: TypeScriptClassMember): void {
3089
- if (isConstructorMember(member)) {
3090
- classDeclaration.addConstructor(member);
3091
- return;
3092
- }
3093
- if (isGetterMember(member)) {
3094
- classDeclaration.addGetAccessor(member);
3095
- return;
3096
- }
3097
- if (isMethodMember(member)) {
3098
- classDeclaration.addMethod(member);
3099
- return;
3100
- }
3101
- if (isPropertyMember(member)) {
3102
- classDeclaration.addProperty(member);
3103
- return;
3104
- }
3105
- throw new Error(`Unsupported class member structure: ${String(member)}`);
3106
- }
3107
-
3108
3066
  interface RuntimeGeneratedAssetSpec {
3109
3067
  absolutePath: string;
3110
3068
  description: string;
@@ -3360,6 +3318,7 @@ async function generateAggregatedFiles(
3360
3318
  basePageClassPath: string,
3361
3319
  outDir: string,
3362
3320
  options: {
3321
+ renderCache?: TypeScriptRenderCache;
3363
3322
  customPomAttachments?: GenerateFilesOptions["customPomAttachments"];
3364
3323
  projectRoot?: GenerateFilesOptions["projectRoot"];
3365
3324
  customPomDir?: GenerateFilesOptions["customPomDir"];
@@ -3496,33 +3455,22 @@ async function generateAggregatedFiles(
3496
3455
  ],
3497
3456
  });
3498
3457
 
3499
- return renderSourceFile("page-object-models.g.ts", (sourceFile) => {
3500
- for (const line of imports) {
3501
- sourceFile.addStatements(line);
3502
- }
3503
-
3504
- for (const entry of [...classes, ...stubs]) {
3505
- if (entry.isStub) {
3506
- sourceFile.addStatements(buildCommentBlock([
3507
- "Stub POM generated because it is referenced as a navigation target but",
3508
- "did not have any generated test ids in this build.",
3509
- ]).trimEnd());
3510
- }
3511
- else {
3512
- sourceFile.addStatements(entry.doc);
3513
- }
3514
-
3515
- const classDeclaration = sourceFile.addClass({
3458
+ return renderStructuredSourceFile(path.join(outputDir, "page-object-models.g.ts"), {
3459
+ statements: [
3460
+ ...imports,
3461
+ ...[...classes, ...stubs].map(entry => createClassDeclaration({
3516
3462
  name: entry.className,
3517
3463
  isExported: true,
3518
3464
  extends: "BasePage",
3519
- });
3520
-
3521
- for (const member of entry.members) {
3522
- addClassMember(classDeclaration, member);
3523
- }
3524
- }
3525
- }, { prefixText });
3465
+ leadingTrivia: entry.isStub
3466
+ ? buildCommentBlock([
3467
+ "Stub POM generated because it is referenced as a navigation target but",
3468
+ "did not have any generated test ids in this build.",
3469
+ ])
3470
+ : `${entry.doc}\n`,
3471
+ }, entry.members)),
3472
+ ],
3473
+ }, { prefixText, cache: options.renderCache });
3526
3474
  };
3527
3475
 
3528
3476
  const base = ensureDir(outDir);
@@ -3530,9 +3478,10 @@ async function generateAggregatedFiles(
3530
3478
  const content = makeAggregatedContent(path.dirname(outputFile), [...views, ...components]);
3531
3479
 
3532
3480
  const indexFile = path.join(base, "index.ts");
3533
- const indexContent = renderSourceFile("index.ts", (sourceFile) => {
3534
- addExportAll(sourceFile, "./page-object-models.g");
3481
+ const indexContent = renderStructuredSourceFile(indexFile, {
3482
+ statements: [{ kind: StructureKind.ExportDeclaration, moduleSpecifier: "./page-object-models.g" }],
3535
3483
  }, {
3484
+ cache: options.renderCache,
3536
3485
  prefixText: buildFilePrefix({
3537
3486
  eslintDisableSortImports: true,
3538
3487
  commentLines: [
@@ -1,5 +1,6 @@
1
1
  import { generateViewObjectModelMethodContent } from "../method-generation";
2
2
  import type { ElementMetadata } from "../metadata-collector";
3
+ import { type TypeScriptRenderCache } from "../typescript-codegen";
3
4
  import { IComponentDependencies } from "../utils";
4
5
  export { generateViewObjectModelMethodContent };
5
6
  interface RouteParamMeta {
@@ -28,6 +29,8 @@ interface CustomPomAttachment {
28
29
  }
29
30
  export type TypeScriptOutputStructure = "aggregated" | "split";
30
31
  export interface GenerateFilesOptions {
32
+ /** Per-dev-server rendering cache. Omitted for stateless one-shot/build generation. */
33
+ renderCache?: TypeScriptRenderCache;
31
34
  /**
32
35
  * Output directory for generated files.
33
36
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../class-generation/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAkC,oCAAoC,EAAE,MAAM,sBAAsB,CAAC;AAE5G,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AA4C7D,OAAO,EACL,sBAAsB,EASvB,MAAM,UAAU,CAAC;AAuBlB,OAAO,EAAE,oCAAoC,EAAE,CAAC;AA2ChD,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,UAAU,UAAU;IAClB,+FAA+F;IAC/F,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,UAAU,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