@immense/vue-pom-generator 1.0.121 → 1.0.122

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.
@@ -1 +1 @@
1
- {"version":3,"file":"internal-plugins.d.ts","sourceRoot":"","sources":["../../plugin/internal-plugins.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,+BAA+B,CAAC;AAMtF,UAAU,4BAA4B;IACpC,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAC3D,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;IAC3D,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,cAAc,EAAE,iBAAiB,CAAC;IAClC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,oCAAoC,EAAE,MAAM,EAAE,CAAC;IAC/C,WAAW,EAAE,MAAM,MAAM,EAAE,CAAC;IAC5B,gBAAgB,EAAE,MAAM,MAAM,EAAE,CAAC;IACjC,aAAa,EAAE,MAAM,MAAM,EAAE,CAAC;IAC9B,WAAW,EAAE,MAAM,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,MAAM,EAAE,CAAC;IAC9B,qBAAqB,EAAE,MAAM,MAAM,EAAE,CAAC;IACtC,UAAU,EAAE,gCAAgC,CAAC;IAC7C,cAAc,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CA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IACrC,cAAc,EAAE,iBAAiB,CAAC;IAClC,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,oCAAoC,EAAE,MAAM,EAAE,CAAC;IAC/C,WAAW,EAAE,MAAM,MAAM,EAAE,CAAC;IAC5B,gBAAgB,EAAE,MAAM,MAAM,EAAE,CAAC;IACjC,aAAa,EAAE,MAAM,MAAM,EAAE,CAAC;IAC9B,WAAW,EAAE,MAAM,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,MAAM,EAAE,CAAC;IAC9B,qBAAqB,EAAE,MAAM,MAAM,EAAE,CAAC;IACtC,UAAU,EAAE,gCAAgC,CAAC;IAC7C,cAAc,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACpC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,cAAc,EAAE,OAAO,CAAC;IACxB,SAAS,EAAE;QAAE,OAAO,EAAE,qBAAqB,CAAA;KAAE,CAAC;IAC9C,gBAAgB,EAAE;QAChB,OAAO,EAAE,OAAO,CAAC;QACjB,eAAe,EAAE,MAAM,CAAC;QACxB,uBAAuB,EAAE,MAAM,CAAC;QAChC,EAAE,EAAE;YACF,OAAO,EAAE,OAAO,CAAC;YACjB,YAAY,EAAE,UAAU,GAAG,UAAU,CAAC;YACtC,eAAe,EAAE,OAAO,CAAC;YACzB,iBAAiB,EAAE,OAAO,CAAC;SAC5B,CAAC;KACH,CAAC;CACH;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,4BAA4B,GAAG,YAAY,EAAE,CA0G3F"}
@@ -21,8 +21,23 @@ export interface ResolvedAnnotatorUiOptions {
21
21
  */
22
22
  declare function normalizePathSeparators(filePath: string): string;
23
23
  export declare function createAnnotatorUiPlugin(options: ResolvedAnnotatorUiOptions): Plugin;
24
+ /**
25
+ * `code`, a compiled single-file component, with its source path set as `__file`, or undefined when it exports no
26
+ * component. The assignment is appended, so no existing code moves and its source map still applies.
27
+ */
28
+ declare function addComponentSourcePath(code: string, file: string): string | undefined;
29
+ /**
30
+ * In a build, lets the annotator name the component behind any element, as it does on the dev server: Vue links each
31
+ * element to its component (`__VUE_PROD_DEVTOOLS__`, which a production build leaves off), and every compiled
32
+ * single-file component gets its source path (`__file`, relative to the Vite root). So a built app, such as a preview
33
+ * deployment, shows the source of static text, slot content and teleported content too.
34
+ */
35
+ export declare function createAnnotatorSourcePlugin(options: {
36
+ enabled: boolean;
37
+ }): Plugin;
24
38
  export declare const __internal: {
25
39
  normalizePathSeparators: typeof normalizePathSeparators;
40
+ addComponentSourcePath: typeof addComponentSourcePath;
26
41
  };
27
42
  export {};
28
43
  //# sourceMappingURL=plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../plugin/runtime/annotator/plugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAqB,MAAM,EAAE,MAAM,MAAM,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,uBAAuB,EAAE,MAAM,CAAC;IAChC,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;IACzB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAYD;;;;;;;;;;GAUG;AACH,iBAAS,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIzD;AAmBD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,0BAA0B,GAAG,MAAM,CAqEnF;AAGD,eAAO,MAAM,UAAU;;CAEtB,CAAC"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../plugin/runtime/annotator/plugin.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAqB,MAAM,EAAE,MAAM,MAAM,CAAC;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,uBAAuB,EAAE,MAAM,CAAC;IAChC,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;IACzB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAYD;;;;;;;;;;GAUG;AACH,iBAAS,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIzD;AAmBD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,0BAA0B,GAAG,MAAM,CAqEnF;AA0BD;;;GAGG;AACH,iBAAS,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG9E;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,CAyBjF;AAGD,eAAO,MAAM,UAAU;;;CAGtB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=annotator-sources.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotator-sources.test.d.ts","sourceRoot":"","sources":["../../tests/annotator-sources.test.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@immense/vue-pom-generator",
3
- "version": "1.0.121",
3
+ "version": "1.0.122",
4
4
  "description": "Injects data-testid attributes for all interactive elements and generates page object models for every page.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -2,6 +2,7 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
 
5
+ import { parse } from "@babel/parser";
5
6
  import type { HtmlTagDescriptor, Plugin } from "vite";
6
7
 
7
8
  import type { OutputDetail } from "./format";
@@ -130,7 +131,74 @@ export function createAnnotatorUiPlugin(options: ResolvedAnnotatorUiOptions): Pl
130
131
  };
131
132
  }
132
133
 
133
- // Exposed for unit tests. Pure helper (no I/O).
134
+ /**
135
+ * The identifier holding a compiled single-file component, from plugin-vue's output: `export default _sfc_main`, or
136
+ * `export default _export_sfc(_sfc_main, [...])`, which sets its options on `_sfc_main` and returns it. Undefined when the
137
+ * module exports something else.
138
+ */
139
+ function findExportedComponent(code: string): string | undefined {
140
+ const program = parse(code, { sourceType: "module", plugins: ["typescript", "jsx"] }).program;
141
+ const exported = program.body.find(node => node.type === "ExportDefaultDeclaration");
142
+ if (!exported) {
143
+ return undefined;
144
+ }
145
+
146
+ const declaration = exported.declaration;
147
+ if (declaration.type === "Identifier") {
148
+ return declaration.name;
149
+ }
150
+
151
+ if (declaration.type === "CallExpression" && declaration.arguments[0]?.type === "Identifier") {
152
+ return declaration.arguments[0].name;
153
+ }
154
+
155
+ return undefined;
156
+ }
157
+
158
+ /**
159
+ * `code`, a compiled single-file component, with its source path set as `__file`, or undefined when it exports no
160
+ * component. The assignment is appended, so no existing code moves and its source map still applies.
161
+ */
162
+ function addComponentSourcePath(code: string, file: string): string | undefined {
163
+ const component = findExportedComponent(code);
164
+ return component ? `${code}\n${component}.__file = ${JSON.stringify(file)};\n` : undefined;
165
+ }
166
+
167
+ /**
168
+ * In a build, lets the annotator name the component behind any element, as it does on the dev server: Vue links each
169
+ * element to its component (`__VUE_PROD_DEVTOOLS__`, which a production build leaves off), and every compiled
170
+ * single-file component gets its source path (`__file`, relative to the Vite root). So a built app, such as a preview
171
+ * deployment, shows the source of static text, slot content and teleported content too.
172
+ */
173
+ export function createAnnotatorSourcePlugin(options: { enabled: boolean }): Plugin {
174
+ let root = process.cwd();
175
+ return {
176
+ name: "vue-pom-generator:annotator-sources",
177
+ enforce: "post",
178
+ // Client builds only: a server render has no annotator to read the links or paths.
179
+ apply(config, { command }) {
180
+ return command === "build" && !config.build?.ssr;
181
+ },
182
+ config() {
183
+ return options.enabled ? { define: { __VUE_PROD_DEVTOOLS__: true } } : undefined;
184
+ },
185
+ configResolved(config) {
186
+ root = config.root;
187
+ },
188
+ transform(code, id, transformOptions) {
189
+ // A component's own module, `Foo.vue`, not one of its `Foo.vue?vue&type=...` blocks.
190
+ if (!options.enabled || transformOptions?.ssr || !id.endsWith(".vue")) {
191
+ return null;
192
+ }
193
+
194
+ const updated = addComponentSourcePath(code, normalizePathSeparators(path.relative(root, id)));
195
+ return updated === undefined ? null : { code: updated, map: null };
196
+ },
197
+ };
198
+ }
199
+
200
+ // Exposed for unit tests. Pure helpers (no I/O).
134
201
  export const __internal = {
135
202
  normalizePathSeparators,
203
+ addComponentSourcePath,
136
204
  };