@eventra_dev/cli-plugin-vue 1.0.6 → 1.0.7

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-24%20passing-brightgreen?style=flat-square&logo=vitest&logoColor=white">
10
+ <img alt="tests passing" src="https://img.shields.io/badge/tests-27%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>
@@ -136,7 +136,7 @@ No dependency on `@eventra_dev/eventra-cli` — the CLI adapts this shape intern
136
136
 
137
137
  **100% statement/branch/function/line coverage** (v8 provider, `pnpm test:coverage`), enforced via a `coverage.thresholds` block in `vitest.config.ts`.
138
138
 
139
- **24 unit tests** (vitest), covering:
139
+ **27 unit tests** (vitest), covering:
140
140
 
141
141
  | Area | Covers |
142
142
  |---|---|
@@ -0,0 +1,23 @@
1
+ /** One script block to place into a generated module. */
2
+ export interface PlacedBlock {
3
+ readonly content: string;
4
+ /**
5
+ * 1-based line of the block's first character in the original file, or
6
+ * `undefined` when it has no place there (for example a `src=` script that
7
+ * lives in another file).
8
+ */
9
+ readonly startLine?: number;
10
+ }
11
+ /**
12
+ * Concatenate script blocks so every block's first line sits on the same
13
+ * line as in the original file. Dynamic-event reports then point at the line
14
+ * the user wrote instead of a line inside the generated module. When a line is
15
+ * unknown (or already passed) the block is simply separated by a blank line.
16
+ *
17
+ * `leadingDirective` (for example `// @ts-nocheck`) must stay the first
18
+ * thing in the module, so it takes line 1 and the first block starts below it.
19
+ */
20
+ export declare function placeBlocks(blocks: readonly PlacedBlock[], leadingDirective?: string): string;
21
+ /** Line (1-based) of the first non-blank character of `raw`, given the line `raw` starts on. */
22
+ export declare function firstContentLine(raw: string, rawStartLine: number): number;
23
+ //# sourceMappingURL=layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAID;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,CAwB7F;AAED,gGAAgG;AAChG,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAE1E"}
package/dist/layout.js ADDED
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.placeBlocks = placeBlocks;
4
+ exports.firstContentLine = firstContentLine;
5
+ const newlines = (text) => text.split("\n").length - 1;
6
+ /**
7
+ * Concatenate script blocks so every block's first line sits on the same
8
+ * line as in the original file. Dynamic-event reports then point at the line
9
+ * the user wrote instead of a line inside the generated module. When a line is
10
+ * unknown (or already passed) the block is simply separated by a blank line.
11
+ *
12
+ * `leadingDirective` (for example `// @ts-nocheck`) must stay the first
13
+ * thing in the module, so it takes line 1 and the first block starts below it.
14
+ */
15
+ function placeBlocks(blocks, leadingDirective) {
16
+ let out = "";
17
+ let line = 1;
18
+ const emit = (text) => {
19
+ out += text;
20
+ line += newlines(text);
21
+ };
22
+ blocks.forEach((block, index) => {
23
+ const target = block.startLine;
24
+ if (index === 0) {
25
+ if (leadingDirective) {
26
+ emit(leadingDirective);
27
+ emit("\n".repeat(Math.max((target ?? 2) - line, 1)));
28
+ }
29
+ else if (target !== undefined) {
30
+ emit("\n".repeat(Math.max(target - line, 0)));
31
+ }
32
+ }
33
+ else {
34
+ emit("\n".repeat(target !== undefined ? Math.max(target - line, 1) : 2));
35
+ }
36
+ emit(block.content);
37
+ });
38
+ return out;
39
+ }
40
+ /** Line (1-based) of the first non-blank character of `raw`, given the line `raw` starts on. */
41
+ function firstContentLine(raw, rawStartLine) {
42
+ return rawStartLine + newlines(raw.slice(0, raw.length - raw.trimStart().length));
43
+ }
@@ -2,6 +2,8 @@ export interface VueScriptBlock {
2
2
  readonly lang: string;
3
3
  readonly setup: boolean;
4
4
  readonly content: string;
5
+ /** 1-based line of the script's first character in the .vue file; unset for `src=` scripts. */
6
+ readonly startLine?: number;
5
7
  }
6
8
  /** A single `event="..."` binding found on an element in the `<template>`. */
7
9
  export interface TemplateEventBinding {
@@ -1 +1 @@
1
- {"version":3,"file":"parse-vue-sfc.d.ts","sourceRoot":"","sources":["../src/parse-vue-sfc.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,8EAA8E;AAC9E,MAAM,WAAW,oBAAoB;IACnC,0GAA0G;IAC1G,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;IACrC,QAAQ,CAA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MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,YAAY,CA+C1E;AAED,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzD;AAID;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CA6B9D"}
@@ -9,6 +9,7 @@ exports.buildScriptModule = buildScriptModule;
9
9
  const node_fs_1 = __importDefault(require("node:fs"));
10
10
  const node_path_1 = __importDefault(require("node:path"));
11
11
  const compiler_sfc_1 = require("@vue/compiler-sfc");
12
+ const layout_1 = require("./layout");
12
13
  const compiler_dom_1 = require("@vue/compiler-dom");
13
14
  const compiler_core_1 = require("@vue/compiler-core");
14
15
  function readSrcFile(sfcPath, src) {
@@ -67,13 +68,15 @@ function parseVueSfc(source, filePath) {
67
68
  for (const block of [descriptor.script, descriptor.scriptSetup]) {
68
69
  if (!block)
69
70
  continue;
70
- const content = (block.src ? readSrcFile(filePath, block.src) : block.content)?.trim();
71
+ const raw = block.src ? readSrcFile(filePath, block.src) : block.content;
72
+ const content = raw?.trim();
71
73
  if (!content)
72
74
  continue;
73
75
  scripts.push({
74
76
  lang: (block.lang ?? "js").toLowerCase(),
75
77
  setup: Boolean(block.setup),
76
78
  content,
79
+ startLine: block.src ? undefined : (0, layout_1.firstContentLine)(raw, block.loc.start.line),
77
80
  });
78
81
  }
79
82
  const templateEvents = [];
@@ -129,13 +132,11 @@ function buildScriptModule(parsed) {
129
132
  parts.push("export {}");
130
133
  }
131
134
  else {
132
- for (const block of parsed.scripts) {
133
- const header = [`// --- vue script${block.setup ? " setup" : ""} ---`];
134
- if (block.lang !== "ts" && block.lang !== "tsx") {
135
- header.push("// @ts-nocheck");
136
- }
137
- parts.push([...header, block.content].join("\n"));
138
- }
135
+ // Only a leading `@ts-nocheck` is honoured by TypeScript, so only the
136
+ // first block decides. Blocks keep their original line numbers.
137
+ const first = parsed.scripts[0];
138
+ const noCheck = first.lang !== "ts" && first.lang !== "tsx";
139
+ parts.push((0, layout_1.placeBlocks)(parsed.scripts, noCheck ? "// @ts-nocheck" : undefined));
139
140
  }
140
141
  if (parsed.templateEvents.length > 0) {
141
142
  const lines = [
@@ -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;AAEjF,wBAAsB,eAAe,CACnC,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,wBAAwB,CAAC,CAWnC"}
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"}
package/dist/transform.js CHANGED
@@ -2,8 +2,20 @@
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
+ const EMPTY_SFC_ERROR = /^At least one <template> or <script> is required/;
5
6
  async function transformVueSfc(input) {
6
7
  const parsed = (0, parse_vue_sfc_1.parseVueSfc)(input.source, input.path);
8
+ // A file with no <template>/<script> (empty or style-only) is a valid
9
+ // zero-event component, not a parse failure.
10
+ const errors = parsed.errors.filter((error) => !EMPTY_SFC_ERROR.test(error));
11
+ if (errors.length > 0) {
12
+ // A parse error means the compiler could not build a reliable tree -
13
+ // continuing would silently under-report (or miss entirely) every
14
+ // event in this file. Throwing surfaces it through the host CLI's
15
+ // per-file "skip: <file> <message>" path instead of returning a module
16
+ // that looks like a legitimate zero-event file.
17
+ throw new Error(`Failed to parse Vue SFC ${input.path}: ${errors.join("; ")}`);
18
+ }
7
19
  return {
8
20
  modules: [
9
21
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eventra_dev/cli-plugin-vue",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Eventra CLI plugin — extract track() calls from Vue SFC (.vue) files",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -34,7 +34,8 @@
34
34
  "clean": "rm -rf dist",
35
35
  "test": "vitest run",
36
36
  "test:watch": "vitest",
37
- "test:coverage": "vitest run --coverage"
37
+ "test:coverage": "vitest run --coverage",
38
+ "typecheck": "tsc --noEmit -p tsconfig.json"
38
39
  },
39
40
  "dependencies": {
40
41
  "@vue/compiler-core": "^3.5.40",