@eventra_dev/cli-plugin-vue 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  <p align="center">
8
8
  <a href="https://www.npmjs.com/package/@eventra_dev/cli-plugin-vue"><img alt="npm version" src="https://img.shields.io/npm/v/@eventra_dev/cli-plugin-vue.svg?style=flat-square&color=blue"></a>
9
9
  <a href="https://www.npmjs.com/package/@eventra_dev/cli-plugin-vue"><img alt="npm downloads" src="https://img.shields.io/npm/dm/@eventra_dev/cli-plugin-vue.svg?style=flat-square&color=blue"></a>
10
- <img alt="tests passing" src="https://img.shields.io/badge/tests-157%20passing-brightgreen?style=flat-square&logo=vitest&logoColor=white">
10
+ <img alt="tests passing" src="https://img.shields.io/badge/tests-165%20passing-brightgreen?style=flat-square&logo=vitest&logoColor=white">
11
11
  <img alt="coverage" src="https://img.shields.io/badge/coverage-100%25-brightgreen?style=flat-square&logo=vitest&logoColor=white">
12
12
  <img alt="node" src="https://img.shields.io/node/v/@eventra_dev/cli-plugin-vue?style=flat-square&color=darkgreen&logo=node.js&logoColor=white">
13
13
  <a href="https://www.typescriptlang.org/"><img alt="TypeScript" src="https://img.shields.io/badge/TypeScript-ready-blue?style=flat-square&logo=typescript&logoColor=white"></a>
@@ -20,7 +20,7 @@ Official [**Eventra CLI**](https://www.npmjs.com/package/@eventra_dev/eventra-cl
20
20
 
21
21
  ## Overview
22
22
 
23
- The CLI core is framework-agnostic and only walks `.ts`/`.tsx`/`.js`/`.jsx`. This plugin teaches it `.vue`: it parses each SFC with the real Vue compiler ([`@vue/compiler-sfc`](https://www.npmjs.com/package/@vue/compiler-sfc)) — not a regex — and hands the CLI a single virtual TypeScript module per file, so every existing detection rule (direct SDK calls, function wrappers, cross-file propagation, dynamic-name reporting) applies to Vue code without any Vue-specific case in the core engine.
23
+ The CLI core is framework-agnostic and only walks TypeScript and JavaScript files (`.ts`, `.tsx`, `.mts`, `.cts`, `.js`, `.jsx`, `.mjs`, `.cjs`). This plugin teaches it `.vue`: it parses each SFC with the real Vue compiler ([`@vue/compiler-sfc`](https://www.npmjs.com/package/@vue/compiler-sfc)) - not a regex - and hands the CLI a single virtual TypeScript module per file, so every existing detection rule (direct SDK calls, function wrappers, cross-file propagation, dynamic-name reporting) applies to Vue code without any Vue-specific case in the core engine.
24
24
 
25
25
  Vue and Nuxt `.vue` files are handled the same way — Nuxt pages/layouts/components are ordinary Vue SFCs. See [Nuxt](#nuxt) below for auto-import composables.
26
26
 
@@ -103,7 +103,7 @@ Tracking calls written in the template itself are read, not only `event` attribu
103
103
  </template>
104
104
  ```
105
105
 
106
- Read: `@click` / `v-on` handlers (one or several statements, multi-line arrow functions), `{{ }}` interpolations the source of `v-for` (`item in items()`), dynamic arguments (`:[name()]`, `@[event()]`) and the expressions of `v-bind`, `v-if`, `v-else-if`, `v-show`, `v-model`, `v-html` and `v-text`. They are placed in the same module as the script, so a function imported or defined there resolves normally; an argument that comes from a `v-for` variable is reported as a dynamic occurrence. The loop variables of `v-for` and `v-slot` parameters are not code and are skipped; the value of a custom directive (`v-focus="x"`) is left alone.
106
+ Read: `@click` / `v-on` handlers (one or several statements, multi-line arrow functions), `{{ }}` interpolations, the source of `v-for` (`item in items()`), dynamic arguments (`:[name()]`, `@[event()]`) and the expressions of `v-bind`, `v-if`, `v-else-if`, `v-show`, `v-model`, `v-html` and `v-text`. They are placed in the same module as the script, so a function imported or defined there resolves normally; an argument that comes from a `v-for` variable is reported as a dynamic occurrence. The loop variables of `v-for` and `v-slot` parameters are not code and are skipped; the value of a custom directive (`v-focus="x"`) is left alone.
107
107
 
108
108
  ### Props of a component, whatever they are called
109
109
 
@@ -126,7 +126,7 @@ import Button from './Button.vue'
126
126
  <template><Button analytics-name="checkout.cta">Pay</Button></template>
127
127
  ```
128
128
 
129
- `checkout.cta` is found. It works with `defineProps<{ ... }>()`, `defineProps([...])`, `defineProps({ ... })`, `withDefaults(...)`, a props object (`const props = defineProps(...)`) and a destructuring (`const { analyticsName } = defineProps(...)`), and also when the template reads the prop by its bare name (`@click="tracker.track(analyticsName)"`). A prop handed on to another component (`<Inner :name="props.analyticsName" />`) is followed. Props the component never tracks are not events. A prop that comes from a `v-for` variable is reported as a dynamic occurrence.
129
+ `checkout.cta` is found. It works with `defineProps<{ ... }>()`, `defineProps([...])`, `defineProps({ ... })`, `withDefaults(...)`, a props object (`const props = defineProps(...)`) and a destructuring (`const { analyticsName } = defineProps(...)`), and also when the template reads the prop by its bare name (`@click="tracker.track(analyticsName)"`). A prop handed on to another component (`<Inner :name="props.analyticsName" />`) is followed. Props the component never tracks are not events. A prop that comes from a `v-for` variable is reported as a dynamic occurrence. A prop named by a reserved word (`class`, `for`, `default`, `new`) does not break the scan; it is read through the props object (`props.class`), as a template has to read it too.
130
130
 
131
131
  **Not followed** (those components are scanned as before, so nothing is lost, but a prop that only they use is not found):
132
132
 
@@ -175,6 +175,8 @@ export interface CliPluginVue {
175
175
  match(path: string): boolean;
176
176
  transform(input: { path: string; source: string }): Promise<{
177
177
  modules: Array<{ path: string; content: string }>;
178
+ notes?: string[]; // e.g. a `<template lang="pug">` that is not read, a `src=` file that is not there
179
+ dependsOn?: string[]; // `<script src>` / `<template src>` files, so `watch` rescans the component
178
180
  }>;
179
181
  }
180
182
  ```
@@ -194,7 +196,7 @@ No dependency on `@eventra_dev/eventra-cli` - the CLI adapts this shape internal
194
196
 
195
197
  **100% statement/branch/function/line coverage** (v8 provider, `pnpm test:coverage`), enforced via a `coverage.thresholds` block in `vitest.config.ts`.
196
198
 
197
- **157 unit tests** (vitest), covering:
199
+ **164 unit tests** (vitest), covering:
198
200
 
199
201
  | Area | Covers |
200
202
  |---|---|
@@ -1 +1 @@
1
- {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAWtD,MAA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;IAC/G,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACvC,4GAA4G;IAC5G,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;CACpC;AAuCD,wGAAwG;AACxG,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,GAAG,cAAc,CAiBhF;AA+DD;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,eAAe,GAAG,IAAI,CAwE5I;AAmDD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CA4BnG"}
package/dist/component.js CHANGED
@@ -5,6 +5,17 @@ exports.wrapScriptSetup = wrapScriptSetup;
5
5
  exports.wrapOptionsApi = wrapOptionsApi;
6
6
  const compiler_sfc_1 = require("@vue/compiler-sfc");
7
7
  const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
8
+ // Words that cannot name a variable in a module (which is strict, and may hold `await`): a prop called `class`,
9
+ // `for`, `default` or `new` is still a prop, but `const { class } = props` would not parse. A template cannot name
10
+ // such a prop bare either (`{{ class }}` is not an expression), so it is simply not made a local.
11
+ const RESERVED = new Set([
12
+ "break", "case", "catch", "class", "const", "continue", "debugger", "default", "delete", "do", "else", "enum", "export",
13
+ "extends", "false", "finally", "for", "function", "if", "import", "in", "instanceof", "new", "null", "return", "super",
14
+ "switch", "this", "throw", "true", "try", "typeof", "var", "void", "while", "with", "yield", "let", "static",
15
+ "implements", "interface", "package", "private", "protected", "public", "await", "arguments", "eval",
16
+ ]);
17
+ /** A prop name that can also be a local of the same name. */
18
+ const bindable = (name) => IDENTIFIER.test(name) && !RESERVED.has(name);
8
19
  function parseScript(block) {
9
20
  const ts = block.lang === "ts" || block.lang === "tsx";
10
21
  const plugins = [];
@@ -204,7 +215,7 @@ function wrapScriptSetup(block, componentName, declaredElsewhere) {
204
215
  if (id?.type === "Identifier") {
205
216
  parameter = id.name;
206
217
  // the template names props bare, so each one is also a local that reads the same parameter path
207
- const bare = names.filter((name) => IDENTIFIER.test(name) && !declaredElsewhere.has(name) && name !== id.name);
218
+ const bare = names.filter((name) => bindable(name) && !declaredElsewhere.has(name) && name !== id.name);
208
219
  if (bare.length > 0)
209
220
  aliases = ` const { ${bare.join(", ")} } = ${parameter};`;
210
221
  }
@@ -220,12 +231,12 @@ function wrapScriptSetup(block, componentName, declaredElsewhere) {
220
231
  else if (key.type === "StringLiteral")
221
232
  present.add(key.value);
222
233
  }
223
- const missing = names.filter((name) => IDENTIFIER.test(name) && !present.has(name) && !declaredElsewhere.has(name));
234
+ const missing = names.filter((name) => bindable(name) && !present.has(name) && !declaredElsewhere.has(name));
224
235
  const text = block.content.slice(id.start, id.typeAnnotation ? id.typeAnnotation.start : id.end).trim();
225
236
  parameter = missing.length > 0 ? text.replace(/\s*\}$/, `${id.properties.length > 0 ? "," : ""} ${missing.join(", ")} }`) : text;
226
237
  }
227
238
  else if (id === null) {
228
- const bare = names.filter((name) => IDENTIFIER.test(name) && !declaredElsewhere.has(name));
239
+ const bare = names.filter((name) => bindable(name) && !declaredElsewhere.has(name));
229
240
  if (bare.length === 0)
230
241
  return null;
231
242
  parameter = `{ ${bare.join(", ")} }`;
@@ -307,6 +307,9 @@ function renderTemplateCode({ handler, code }) {
307
307
  }
308
308
  return ` (${code}\n );`;
309
309
  }
310
+ // The value goes between double quotes in generated TypeScript. JSON escaping covers the quote and the backslash and
311
+ // also line breaks and other control characters: a raw newline used to end the string early, so the name was
312
+ // recorded cut at the newline and nothing reported it.
310
313
  function escapeString(value) {
311
- return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
314
+ return JSON.stringify(value).slice(1, -1);
312
315
  }
@@ -1,3 +1,11 @@
1
1
  import type { CliPluginTransformInput, CliPluginTransformResult } from "./types";
2
+ /**
3
+ * The language of a template in another language than HTML (`<template lang="pug">`), whose events cannot be read:
4
+ * what `/<template\b[^>]*\blang\s*=\s*["']?(pug|jade|haml|slm)\b/i` finds, without its cost. That pattern scanned
5
+ * to the next `>` again from every `<template`, and a file with many of them and no `>` took minutes. Every
6
+ * `<template` before the same `>` sees the same attributes or fewer, so only the first one is looked at, and each
7
+ * part of the text is read once.
8
+ */
9
+ export declare function nonHtmlTemplateLanguage(source: string): string | undefined;
2
10
  export declare function transformVueSfc(input: CliPluginTransformInput): Promise<CliPluginTransformResult>;
3
11
  //# sourceMappingURL=transform.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAOjF,wBAAsB,eAAe,CACnC,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,wBAAwB,CAAC,CAiCnC"}
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAKjF;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAc1E;AAID,wBAAsB,eAAe,CACnC,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,wBAAwB,CAAC,CAiCnC"}
package/dist/transform.js CHANGED
@@ -1,9 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nonHtmlTemplateLanguage = nonHtmlTemplateLanguage;
3
4
  exports.transformVueSfc = transformVueSfc;
4
5
  const parse_vue_sfc_1 = require("./parse-vue-sfc");
5
- // a template in another language is not HTML markup, so its events cannot be read
6
- const NON_HTML_TEMPLATE = /<template\b[^>]*\blang\s*=\s*["']?(pug|jade|haml|slm)\b/i;
6
+ const TEMPLATE_TAG = /<template\b/gi;
7
+ const NON_HTML_LANG = /\blang\s*=\s*["']?(pug|jade|haml|slm)\b/gi;
8
+ /**
9
+ * The language of a template in another language than HTML (`<template lang="pug">`), whose events cannot be read:
10
+ * what `/<template\b[^>]*\blang\s*=\s*["']?(pug|jade|haml|slm)\b/i` finds, without its cost. That pattern scanned
11
+ * to the next `>` again from every `<template`, and a file with many of them and no `>` took minutes. Every
12
+ * `<template` before the same `>` sees the same attributes or fewer, so only the first one is looked at, and each
13
+ * part of the text is read once.
14
+ */
15
+ function nonHtmlTemplateLanguage(source) {
16
+ TEMPLATE_TAG.lastIndex = 0;
17
+ for (let tag = TEMPLATE_TAG.exec(source); tag; tag = TEMPLATE_TAG.exec(source)) {
18
+ const start = TEMPLATE_TAG.lastIndex;
19
+ const close = source.indexOf(">", start);
20
+ const end = close === -1 ? source.length : close;
21
+ // the pattern took the last `lang=` before the `>`
22
+ let language;
23
+ for (const match of source.slice(start, end).matchAll(NON_HTML_LANG))
24
+ language = match[1];
25
+ if (language)
26
+ return language.toLowerCase();
27
+ if (close === -1)
28
+ return undefined;
29
+ TEMPLATE_TAG.lastIndex = close + 1;
30
+ }
31
+ return undefined;
32
+ }
7
33
  const EMPTY_SFC_ERROR = /^At least one <template> or <script> is required/;
8
34
  async function transformVueSfc(input) {
9
35
  const parsed = (0, parse_vue_sfc_1.parseVueSfc)(input.source, input.path);
@@ -18,7 +44,7 @@ async function transformVueSfc(input) {
18
44
  // that looks like a legitimate zero-event file.
19
45
  throw new Error(`Failed to parse Vue SFC ${input.path}: ${errors.join("; ")}`);
20
46
  }
21
- const language = NON_HTML_TEMPLATE.exec(input.source)?.[1]?.toLowerCase();
47
+ const language = nonHtmlTemplateLanguage(input.source);
22
48
  const notes = language ? [`<template lang="${language}"> is not read: events written in it are not in the scan (script events are).`] : [];
23
49
  // a linked file that is not there is not an error (it may be generated), but nothing of it is in the scan
24
50
  for (const src of parsed.missingSrc)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eventra_dev/cli-plugin-vue",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Eventra CLI plugin — extract track() calls from Vue SFC (.vue) files",
5
5
  "license": "MIT",
6
6
  "author": {