@eventra_dev/cli-plugin-vue 1.2.5 → 1.3.1

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-139%20passing-brightgreen?style=flat-square&logo=vitest&logoColor=white">
10
+ <img alt="tests passing" src="https://img.shields.io/badge/tests-157%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>
@@ -130,13 +130,25 @@ import Button from './Button.vue'
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
 
133
- - Options API components (`props: [...]` read through `this`).
134
- - `v-bind="obj"` spreads.
133
+ - An Options API component whose `export default` is not the last statement of its `<script>`, whose `props` is not written out in the object (`props: sharedProps`), or whose `this` is read inside a nested `function` (an arrow keeps it). A component with `props: [...]` or `props: { ... }` and `this.x` in its methods is followed, with or without `defineComponent`.
134
+ - `v-bind="obj"` when `obj` is not an object the analysis can see into (a call, a parameter of the page); an object written out or held in a `const` is read, in its place among the props.
135
135
  - Components registered by name instead of imported, and dynamic components (`<component :is="X">`).
136
136
  - Nuxt auto-imported components (used with no `import`): the tag is not matched to its file.
137
137
  - A component whose normal `<script>` has its own `export default`, an `export` other than a type in `<script setup>`, an import after other code, or a `src=` script.
138
138
 
139
- A value the CLI cannot resolve to a plain string (a `v-for` variable, a prop of the page itself) is listed under "Dynamic event names" instead of becoming an event. The same list shows the tracking call inside the component itself, one line per component, because what it tracks is whatever each caller passes; the callers that pass a literal are still found.
139
+ A value the CLI cannot resolve to a plain string (a `v-for` variable, a prop of the page itself) is listed under "Dynamic event names" instead of becoming an event, with the reason (`env`, `variable`, `template`, `call`, `expression`). The tracking call inside the component itself is listed apart, under "Inside a wrapper", because what it tracks is whatever each caller passes; the callers that pass a literal are still found.
140
+
141
+ ## `watch` and external files
142
+
143
+ `<script src="...">` and `<template src="...">` point at other files. `eventra sync`, `check` and `eventra watch` read them, and `watch` rescans the component when one of those files changes (the plugin tells the CLI which files the component was built from).
144
+
145
+ ## Scripts in JSX, and linked files that are not there
146
+
147
+ A script with `lang="tsx"` or `lang="jsx"` is read as TSX, so its JSX is not a syntax error. A `<script src>` or `<template src>` whose file does not exist gets a note from the CLI (what it holds is not in the scan). A syntax error in a linked `<script src>` file is reported against the `.vue` file with the line of the linked file.
148
+
149
+ ## Templates in other languages
150
+
151
+ A `<template lang="pug">` (or `jade`, `haml`, `slm`) is not HTML markup and is not read: the plugin returns a note that the CLI prints after a scan, and the file's `<script>` is read as usual. An empty `event=""` attribute in a template is skipped without a note. `v-memo` is read like `v-if` and the other directives that hold code.
140
152
 
141
153
  ## Nuxt
142
154
 
@@ -182,7 +194,7 @@ No dependency on `@eventra_dev/eventra-cli` - the CLI adapts this shape internal
182
194
 
183
195
  **100% statement/branch/function/line coverage** (v8 provider, `pnpm test:coverage`), enforced via a `coverage.thresholds` block in `vitest.config.ts`.
184
196
 
185
- **139 unit tests** (vitest), covering:
197
+ **157 unit tests** (vitest), covering:
186
198
 
187
199
  | Area | Covers |
188
200
  |---|---|
@@ -31,4 +31,16 @@ export declare function scriptBindings(blocks: readonly VueScriptBlock[]): Scrip
31
31
  * component is scanned as before.
32
32
  */
33
33
  export declare function wrapScriptSetup(block: VueScriptBlock, componentName: string, declaredElsewhere: ReadonlySet<string>): ComponentModule | null;
34
+ /**
35
+ * Turns an Options API component that declares `props` into a function of them, like `wrapScriptSetup` does
36
+ * for `<script setup>`, so a prop that reaches a track() call through `this` is followed from the parent:
37
+ *
38
+ * export default { props: ["track"], methods: { go() { sdk.track(this.track) } } }
39
+ * -> function Button(__props: any) { const __options = { ... go() { sdk.track(__props.track) } } ...
40
+ *
41
+ * `defineComponent({...})` is read the same way. Statements keep their line numbers. Returns null when the
42
+ * block is not an options component with `props`, when `export default` is not the last statement, or when
43
+ * it is written some other way, in which case the component is scanned as before.
44
+ */
45
+ export declare function wrapOptionsApi(block: VueScriptBlock, componentName: string): ComponentModule | null;
34
46
  //# sourceMappingURL=component.d.ts.map
@@ -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,MAAM,WAAW,eAAe;IAC9B,oHAAoH;IACpH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uEAAuE;IACvE,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,4FAA4F;IAC5F,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAID,wFAAwF;AACxF,MAAM,WAAW,cAAc;IAC7B,+GAA+G;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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perty(exports, "__esModule", { value: true });
3
3
  exports.scriptBindings = scriptBindings;
4
4
  exports.wrapScriptSetup = wrapScriptSetup;
5
+ exports.wrapOptionsApi = wrapOptionsApi;
5
6
  const compiler_sfc_1 = require("@vue/compiler-sfc");
6
7
  const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
7
8
  function parseScript(block) {
@@ -243,3 +244,105 @@ function wrapScriptSetup(block, componentName, declaredElsewhere) {
243
244
  code = code.slice(0, headerAt) + header + code.slice(headerAt);
244
245
  return { code, propNames: names, name: componentName };
245
246
  }
247
+ /** `props: ["a", "b"]` or `props: { a: String, b: { type: String } }` of an options object: the names a parent can pass. */
248
+ function optionsPropNames(options) {
249
+ for (const property of options.properties) {
250
+ if (property.type !== "ObjectProperty" || property.computed)
251
+ continue;
252
+ const key = property.key;
253
+ if (!(key.type === "Identifier" ? key.name === "props" : key.type === "StringLiteral" && key.value === "props"))
254
+ continue;
255
+ const value = property.value;
256
+ const names = [];
257
+ if (value.type === "ArrayExpression") {
258
+ for (const element of value.elements)
259
+ if (element?.type === "StringLiteral")
260
+ names.push(element.value);
261
+ }
262
+ else if (value.type === "ObjectExpression") {
263
+ for (const prop of value.properties) {
264
+ if (prop.type !== "ObjectProperty" && prop.type !== "ObjectMethod")
265
+ continue;
266
+ if (prop.key.type === "Identifier" && !prop.computed)
267
+ names.push(prop.key.name);
268
+ else if (prop.key.type === "StringLiteral")
269
+ names.push(prop.key.value);
270
+ }
271
+ }
272
+ else {
273
+ return null;
274
+ }
275
+ return names;
276
+ }
277
+ return null;
278
+ }
279
+ // a nested `function` has a `this` of its own, so a `this.x` inside it is not the component's
280
+ const OWN_THIS = new Set(["FunctionExpression", "FunctionDeclaration", "ClassMethod", "ClassPrivateMethod", "ClassDeclaration", "ClassExpression"]);
281
+ function thisEdits(node, props, out) {
282
+ if (OWN_THIS.has(node.type))
283
+ return;
284
+ // this.track -> __props.track
285
+ if (node.type === "MemberExpression" && node.object.type === "ThisExpression" && !node.computed && node.property.type === "Identifier" && props.has(node.property.name)) {
286
+ out.push({ start: node.start, end: node.end, text: `__props.${node.property.name}` });
287
+ return;
288
+ }
289
+ // const { track } = this -> const { track } = __props
290
+ if (node.type === "VariableDeclarator" && node.id.type === "ObjectPattern" && node.init?.type === "ThisExpression") {
291
+ out.push({ start: node.init.start, end: node.init.end, text: "__props" });
292
+ }
293
+ for (const key of Object.keys(node)) {
294
+ if (key === "loc" || key === "leadingComments" || key === "trailingComments" || key === "innerComments")
295
+ continue;
296
+ const child = node[key];
297
+ if (Array.isArray(child)) {
298
+ for (const item of child)
299
+ if (item && typeof item.type === "string")
300
+ thisEdits(item, props, out);
301
+ }
302
+ else if (child && typeof child.type === "string") {
303
+ thisEdits(child, props, out);
304
+ }
305
+ }
306
+ }
307
+ /**
308
+ * Turns an Options API component that declares `props` into a function of them, like `wrapScriptSetup` does
309
+ * for `<script setup>`, so a prop that reaches a track() call through `this` is followed from the parent:
310
+ *
311
+ * export default { props: ["track"], methods: { go() { sdk.track(this.track) } } }
312
+ * -> function Button(__props: any) { const __options = { ... go() { sdk.track(__props.track) } } ...
313
+ *
314
+ * `defineComponent({...})` is read the same way. Statements keep their line numbers. Returns null when the
315
+ * block is not an options component with `props`, when `export default` is not the last statement, or when
316
+ * it is written some other way, in which case the component is scanned as before.
317
+ */
318
+ function wrapOptionsApi(block, componentName) {
319
+ if (block.setup || block.startLine === undefined)
320
+ return null;
321
+ const statements = parseScript(block);
322
+ if (!statements)
323
+ return null;
324
+ const last = statements[statements.length - 1];
325
+ if (last?.type !== "ExportDefaultDeclaration")
326
+ return null;
327
+ let options = last.declaration;
328
+ if (options.type === "CallExpression" && options.callee.type === "Identifier" && options.callee.name === "defineComponent" && options.arguments.length === 1) {
329
+ options = options.arguments[0];
330
+ }
331
+ if (options.type !== "ObjectExpression")
332
+ return null;
333
+ const names = optionsPropNames(options);
334
+ if (!names || names.length === 0)
335
+ return null;
336
+ const edits = [];
337
+ thisEdits(options, new Set(names), edits);
338
+ // the header replaces `export default [defineComponent(]`, and what follows the options is dropped
339
+ // (`)` and `;`), keeping the line breaks of both, so the lines of the code keep their numbers
340
+ const header = `${/\bawait\b/.test(block.content) ? "async " : ""}function ${componentName}(__props: any) { const __options = `;
341
+ edits.push({ start: last.start, end: options.start, text: header + blank(block.content.slice(last.start, options.start)) });
342
+ edits.push({ start: options.end, end: last.end, text: `;${blank(block.content.slice(options.end, last.end))}` });
343
+ let code = block.content;
344
+ for (const edit of edits.sort((a, b) => b.start - a.start)) {
345
+ code = code.slice(0, edit.start) + edit.text + code.slice(edit.end);
346
+ }
347
+ return { code, propNames: names, name: componentName };
348
+ }
@@ -20,7 +20,8 @@ export interface TemplateHandler {
20
20
  export interface TemplateComponentProp {
21
21
  /** camelCased, the way the child declares it */
22
22
  readonly name: string;
23
- readonly kind: "literal" | "expression";
23
+ /** `spread`: `v-bind="obj"`, whose properties are props in the place it stands among the others (`name` is empty). */
24
+ readonly kind: "literal" | "expression" | "spread";
24
25
  readonly value: string;
25
26
  }
26
27
  /** An element that may be a child component, with the props written on it. Whether it is one depends on the script's imports. */
@@ -39,12 +40,20 @@ export interface ParsedVueSfc {
39
40
  readonly templateHandlers: readonly TemplateHandler[];
40
41
  /** Every element in the template that carries props, for the ones that turn out to be imported components. */
41
42
  readonly componentUsages?: readonly TemplateComponentUsage[];
43
+ /** Absolute paths of the files `<script src>` and `<template src>` point at (also those that are not there yet). */
44
+ readonly srcFiles: readonly string[];
45
+ /** The `src` of a `<script src>` or `<template src>` whose file could not be read: nothing of it is in the scan. */
46
+ readonly missingSrc: readonly string[];
42
47
  readonly errors: readonly string[];
43
48
  }
44
49
  /** Parse a Vue SFC via the real `@vue/compiler-sfc` parser (handles comments, `src=`, malformed markup, etc). */
45
50
  export declare function parseVueSfc(source: string, filePath: string): ParsedVueSfc;
46
- /** Map `App.vue` → `App.vue.ts` (single virtual TS module for the compiler). */
47
- export declare function scriptVirtualPath(vuePath: string): string;
51
+ /**
52
+ * Map `App.vue` → `App.vue.ts` (single virtual TS module for the compiler), or `App.vue.tsx` when a script is JSX
53
+ * (`lang="tsx"` / `lang="jsx"`): the host CLI reads the kind of a file from its extension, and JSX in a `.ts` file is a
54
+ * syntax error.
55
+ */
56
+ export declare function scriptVirtualPath(vuePath: string, jsx?: boolean): string;
48
57
  /**
49
58
  * Build one virtual TS module from the parsed SFC: compiled `<script>` +
50
59
  * `<script setup>` content, followed by a function wrapping synthetic calls
@@ -1 +1 @@
1
- {"version":3,"file":"parse-vue-sfc.d.ts","sourceRoot":"","sources":["../src/parse-vue-sfc.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,+FAA+F;IAC/F,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,8EAA8E;AAC9E,MAAM,WAAW,oBAAoB;IACnC,0GAA0G;IAC1G,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,6GAA6G;AAC7G,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,+GAA+G;AAC/G,MAAM,WAAW,qBAAqB;IACpC,gDAAgD;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,YAAY,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,iIAAiI;AACjI,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,SAAS,qBAAqB,EAAE,CAAC;CACl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 @@ const camelize = (name) => name.replace(/-(\w)/g, (_, letter) => letter.toUpperC
27
27
  const V_FOR_SOURCE = /\s(?:in|of)\s+([\s\S]+)$/;
28
28
  // directives whose value is plain JS. `v-for` is handled apart (its value is `item in source`), and
29
29
  // `v-slot` (a parameter list), `v-pre` and `v-cloak` hold no expression
30
- const CODE_DIRECTIVES = new Set(["on", "bind", "if", "else-if", "show", "html", "text", "model"]);
30
+ const CODE_DIRECTIVES = new Set(["on", "bind", "if", "else-if", "show", "html", "text", "model", "memo"]);
31
31
  function collectEventBindings(root, out, handlers, usages) {
32
32
  function visitChildren(children) {
33
33
  for (const child of children) {
@@ -42,6 +42,11 @@ function collectEventBindings(root, out, handlers, usages) {
42
42
  found.push({ name: camelize(prop.name), kind: "literal", value: prop.value.content });
43
43
  continue;
44
44
  }
45
+ // `v-bind="obj"`: every property of the object is a prop, and a later prop wins over it, as at runtime
46
+ if (prop.name === "bind" && !prop.arg && prop.exp?.type === compiler_core_1.NodeTypes.SIMPLE_EXPRESSION && prop.exp.content.trim()) {
47
+ found.push({ name: "", kind: "spread", value: prop.exp.content.trim() });
48
+ continue;
49
+ }
45
50
  // `:track="expr"`; the same-name shorthand `:track` has no expression and reads the variable of that name
46
51
  if (prop.name === "bind" && prop.arg?.type === compiler_core_1.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic) {
47
52
  const name = camelize(prop.arg.content);
@@ -116,10 +121,17 @@ function collectEventBindings(root, out, handlers, usages) {
116
121
  function parseVueSfc(source, filePath) {
117
122
  const { descriptor, errors } = (0, compiler_sfc_1.parse)(source, { filename: filePath });
118
123
  const scripts = [];
124
+ const srcFiles = [];
125
+ const missingSrc = [];
126
+ const resolveSrc = (src) => node_path_1.default.resolve(node_path_1.default.dirname(filePath), src);
119
127
  for (const block of [descriptor.script, descriptor.scriptSetup]) {
120
128
  if (!block)
121
129
  continue;
130
+ if (block.src)
131
+ srcFiles.push(resolveSrc(block.src));
122
132
  const raw = block.src ? readSrcFile(filePath, block.src) : block.content;
133
+ if (block.src && raw === null)
134
+ missingSrc.push(block.src);
123
135
  const content = raw?.trim();
124
136
  if (!content)
125
137
  continue;
@@ -134,6 +146,8 @@ function parseVueSfc(source, filePath) {
134
146
  const templateHandlers = [];
135
147
  const componentUsages = [];
136
148
  const template = descriptor.template;
149
+ if (template?.src)
150
+ srcFiles.push(resolveSrc(template.src));
137
151
  if (template) {
138
152
  if (template.ast) {
139
153
  collectEventBindings(template.ast, templateEvents, templateHandlers, componentUsages);
@@ -145,6 +159,8 @@ function parseVueSfc(source, filePath) {
145
159
  /* v8 ignore else */
146
160
  if (template.src) {
147
161
  const external = readSrcFile(filePath, template.src);
162
+ if (external === null)
163
+ missingSrc.push(template.src);
148
164
  if (external) {
149
165
  collectEventBindings((0, compiler_dom_1.parse)(external), templateEvents, templateHandlers, componentUsages);
150
166
  }
@@ -157,6 +173,8 @@ function parseVueSfc(source, filePath) {
157
173
  // an empty expression (`@click=""`) holds no code
158
174
  templateHandlers: templateHandlers.filter((handler) => handler.code !== ""),
159
175
  componentUsages,
176
+ srcFiles,
177
+ missingSrc,
160
178
  errors: errors.map((error) => {
161
179
  // @vue/compiler-sfc errors are always Error instances
162
180
  /* v8 ignore else */
@@ -167,9 +185,13 @@ function parseVueSfc(source, filePath) {
167
185
  }),
168
186
  };
169
187
  }
170
- /** Map `App.vue` → `App.vue.ts` (single virtual TS module for the compiler). */
171
- function scriptVirtualPath(vuePath) {
172
- return vuePath.replace(/\.vue$/i, ".vue.ts");
188
+ /**
189
+ * Map `App.vue` → `App.vue.ts` (single virtual TS module for the compiler), or `App.vue.tsx` when a script is JSX
190
+ * (`lang="tsx"` / `lang="jsx"`): the host CLI reads the kind of a file from its extension, and JSX in a `.ts` file is a
191
+ * syntax error.
192
+ */
193
+ function scriptVirtualPath(vuePath, jsx = false) {
194
+ return vuePath.replace(/\.vue$/i, jsx ? ".vue.tsx" : ".vue.ts");
173
195
  }
174
196
  const TEMPLATE_EVENT_CALLEE = "__eventra_vue_template_event__";
175
197
  /**
@@ -195,7 +217,8 @@ function buildScriptModule(parsed, filePath = "") {
195
217
  const last = parsed.scripts[parsed.scripts.length - 1];
196
218
  const others = last ? (0, component_1.scriptBindings)(parsed.scripts.slice(0, -1)) : undefined;
197
219
  if (last && !others?.hasDefaultExport) {
198
- const wrapped = (0, component_1.wrapScriptSetup)(last, componentName(filePath, bindings.declared), others.declared);
220
+ const name = componentName(filePath, bindings.declared);
221
+ const wrapped = (0, component_1.wrapScriptSetup)(last, name, others.declared) ?? (0, component_1.wrapOptionsApi)(last, name);
199
222
  if (wrapped) {
200
223
  scripts = [...parsed.scripts.slice(0, -1), { ...last, content: wrapped.code }];
201
224
  component = wrapped.name;
@@ -260,6 +283,8 @@ function componentCalls(usages, components) {
260
283
  if (!binding)
261
284
  continue;
262
285
  const props = usage.props.map((prop) => {
286
+ if (prop.kind === "spread")
287
+ return `...(${prop.value}\n)`;
263
288
  const key = KEY.test(prop.name) ? prop.name : `"${escapeString(prop.name)}"`;
264
289
  return `${key}: ${prop.kind === "literal" ? `"${escapeString(prop.value)}"` : `(${prop.value}\n)`}`;
265
290
  });
@@ -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;AAIjF,wBAAsB,eAAe,CACnC,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,wBAAwB,CAAC,CA0BnC"}
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"}
package/dist/transform.js CHANGED
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformVueSfc = transformVueSfc;
4
4
  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;
5
7
  const EMPTY_SFC_ERROR = /^At least one <template> or <script> is required/;
6
8
  async function transformVueSfc(input) {
7
9
  const parsed = (0, parse_vue_sfc_1.parseVueSfc)(input.source, input.path);
@@ -16,10 +18,17 @@ async function transformVueSfc(input) {
16
18
  // that looks like a legitimate zero-event file.
17
19
  throw new Error(`Failed to parse Vue SFC ${input.path}: ${errors.join("; ")}`);
18
20
  }
21
+ const language = NON_HTML_TEMPLATE.exec(input.source)?.[1]?.toLowerCase();
22
+ const notes = language ? [`<template lang="${language}"> is not read: events written in it are not in the scan (script events are).`] : [];
23
+ // a linked file that is not there is not an error (it may be generated), but nothing of it is in the scan
24
+ for (const src of parsed.missingSrc)
25
+ notes.push(`"${src}" was not found: what it holds is not in the scan.`);
19
26
  return {
27
+ ...(notes.length > 0 ? { notes } : {}),
28
+ ...(parsed.srcFiles.length > 0 ? { dependsOn: parsed.srcFiles } : {}),
20
29
  modules: [
21
30
  {
22
- path: (0, parse_vue_sfc_1.scriptVirtualPath)(input.path),
31
+ path: (0, parse_vue_sfc_1.scriptVirtualPath)(input.path, parsed.scripts.some((script) => script.lang === "tsx" || script.lang === "jsx")),
23
32
  content: (0, parse_vue_sfc_1.buildScriptModule)(parsed, input.path),
24
33
  },
25
34
  ],
package/dist/types.d.ts CHANGED
@@ -20,6 +20,10 @@ export interface CliPluginStaticCalleeSink {
20
20
  }
21
21
  export interface CliPluginTransformResult {
22
22
  readonly modules: readonly CliPluginVirtualModule[];
23
+ /** Hints about the file that are not errors (shown by the host CLI, never a failure). */
24
+ readonly notes?: readonly string[];
25
+ /** Other files the modules were built from: `eventra watch` rescans this file when one of them changes. */
26
+ readonly dependsOn?: readonly string[];
23
27
  }
24
28
  /** Contract for `@eventra_dev/cli-plugin-vue` and compatible CLI plugins. */
25
29
  export interface CliPluginVue {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,6EAA6E;AAC7E,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;GAIG;AACH,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAC;CACzC;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,OAAO,EAAE,SAAS,sBAAsB,EAAE,CAAC;CACrD;AAED,6EAA6E;AAC7E,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,yBAAyB,EAAE,CAAC;IAC5D,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC7B,SAAS,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;CAC9E"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,6EAA6E;AAC7E,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;GAIG;AACH,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAC;CACzC;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,OAAO,EAAE,SAAS,sBAAsB,EAAE,CAAC;IACpD,yFAAyF;IACzF,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,2GAA2G;IAC3G,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACxC;AAED,6EAA6E;AAC7E,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,yBAAyB,EAAE,CAAC;IAC5D,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC7B,SAAS,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;CAC9E"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eventra_dev/cli-plugin-vue",
3
- "version": "1.2.5",
3
+ "version": "1.3.1",
4
4
  "description": "Eventra CLI plugin — extract track() calls from Vue SFC (.vue) files",
5
5
  "license": "MIT",
6
6
  "author": {