@eventra_dev/cli-plugin-vue 1.0.6 → 1.1.0
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 +16 -3
- package/dist/layout.d.ts +23 -0
- package/dist/layout.d.ts.map +1 -0
- package/dist/layout.js +43 -0
- package/dist/parse-vue-sfc.d.ts +13 -0
- package/dist/parse-vue-sfc.d.ts.map +1 -1
- package/dist/parse-vue-sfc.js +62 -12
- package/dist/transform.d.ts.map +1 -1
- package/dist/transform.js +12 -0
- package/package.json +3 -2
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-
|
|
10
|
+
<img alt="tests passing" src="https://img.shields.io/badge/tests-51%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>
|
|
@@ -92,6 +92,19 @@ The expression is copied as-is into the same module scope as the script. If it r
|
|
|
92
92
|
|
|
93
93
|
---
|
|
94
94
|
|
|
95
|
+
### `<template>` - calls in handlers and expressions
|
|
96
|
+
|
|
97
|
+
Tracking calls written in the template itself are read, not only `event` attributes:
|
|
98
|
+
|
|
99
|
+
```vue
|
|
100
|
+
<template>
|
|
101
|
+
<button @click="() => { open(); trackEvent('plan:cogm_open', { id }) }">Open</button>
|
|
102
|
+
<p>{{ trackEvent('panel:viewed') }}</p>
|
|
103
|
+
</template>
|
|
104
|
+
```
|
|
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.
|
|
107
|
+
|
|
95
108
|
## Nuxt
|
|
96
109
|
|
|
97
110
|
Nuxt pages, layouts, and components are ordinary `.vue` SFCs — parsed identically, no extra configuration needed.
|
|
@@ -121,7 +134,7 @@ export interface CliPluginVue {
|
|
|
121
134
|
}
|
|
122
135
|
```
|
|
123
136
|
|
|
124
|
-
No dependency on `@eventra_dev/eventra-cli`
|
|
137
|
+
No dependency on `@eventra_dev/eventra-cli` - the CLI adapts this shape internally. `.vue` → one virtual `.vue.ts` module (compiled script content, then a function wrapping synthetic calls for every template `event="..."` binding and the handlers, interpolations and directive expressions copied from the template, under a `// --- vue template (auto-generated) ---` comment the CLI uses to tell generated code from your own lines). `staticSinks` describes those synthetic calls; the CLI builds its own sink detector from them. See [`@eventra_dev/eventra-cli`'s plugin docs](https://www.npmjs.com/package/@eventra_dev/eventra-cli#plugin-contract-for-authors) for the full external-plugin contract.
|
|
125
138
|
|
|
126
139
|
---
|
|
127
140
|
|
|
@@ -136,7 +149,7 @@ No dependency on `@eventra_dev/eventra-cli` — the CLI adapts this shape intern
|
|
|
136
149
|
|
|
137
150
|
**100% statement/branch/function/line coverage** (v8 provider, `pnpm test:coverage`), enforced via a `coverage.thresholds` block in `vitest.config.ts`.
|
|
138
151
|
|
|
139
|
-
**
|
|
152
|
+
**51 unit tests** (vitest), covering:
|
|
140
153
|
|
|
141
154
|
| Area | Covers |
|
|
142
155
|
|---|---|
|
package/dist/layout.d.ts
ADDED
|
@@ -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
|
+
}
|
package/dist/parse-vue-sfc.d.ts
CHANGED
|
@@ -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 {
|
|
@@ -9,9 +11,20 @@ export interface TemplateEventBinding {
|
|
|
9
11
|
readonly kind: "literal" | "dynamic";
|
|
10
12
|
readonly value: string;
|
|
11
13
|
}
|
|
14
|
+
/** One piece of template code. A handler may be several statements; any other expression is a single one. */
|
|
15
|
+
export interface TemplateHandler {
|
|
16
|
+
readonly handler: boolean;
|
|
17
|
+
readonly code: string;
|
|
18
|
+
}
|
|
12
19
|
export interface ParsedVueSfc {
|
|
13
20
|
readonly scripts: readonly VueScriptBlock[];
|
|
14
21
|
readonly templateEvents: readonly TemplateEventBinding[];
|
|
22
|
+
/**
|
|
23
|
+
* Raw JS of the template's own code, copied verbatim: event handlers (`@click="() => track('x')"`,
|
|
24
|
+
* `@click="a(); b()"`), `{{ }}` interpolations and the expressions of `v-bind`/`v-if`/`v-show`/...
|
|
25
|
+
* Any call to a tracking function in there is an event the component fires.
|
|
26
|
+
*/
|
|
27
|
+
readonly templateHandlers: readonly TemplateHandler[];
|
|
15
28
|
readonly errors: readonly string[];
|
|
16
29
|
}
|
|
17
30
|
/** Parse a Vue SFC via the real `@vue/compiler-sfc` parser (handles comments, `src=`, malformed markup, etc). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-vue-sfc.d.ts","sourceRoot":"","sources":["../src/parse-vue-sfc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-vue-sfc.d.ts","sourceRoot":"","sources":["../src/parse-vue-sfc.ts"],"names":[],"mappings":"AAeA,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,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,CAAC;IAC5C,QAAQ,CAAC,cAAc,EAAE,SAAS,oBAAoB,EAAE,CAAC;IACzD;;;;OAIG;IACH,QAAQ,CAAC,gBAAgB,EAAE,SAAS,eAAe,EAAE,CAAC;IACtD,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AA2FD,iHAAiH;AACjH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,YAAY,CAkD1E;AAED,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzD;AAID;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAgC9D"}
|
package/dist/parse-vue-sfc.js
CHANGED
|
@@ -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) {
|
|
@@ -20,7 +21,12 @@ function readSrcFile(sfcPath, src) {
|
|
|
20
21
|
return null;
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
+
// the part of `item in items()` / `(item, i) of items()` that is an expression: after the `in` / `of`
|
|
25
|
+
const V_FOR_SOURCE = /\s(?:in|of)\s+([\s\S]+)$/;
|
|
26
|
+
// directives whose value is plain JS. `v-for` is handled apart (its value is `item in source`), and
|
|
27
|
+
// `v-slot` (a parameter list), `v-pre` and `v-cloak` hold no expression
|
|
28
|
+
const CODE_DIRECTIVES = new Set(["on", "bind", "if", "else-if", "show", "html", "text", "model"]);
|
|
29
|
+
function collectEventBindings(root, out, handlers) {
|
|
24
30
|
function visitChildren(children) {
|
|
25
31
|
for (const child of children) {
|
|
26
32
|
visitNode(child);
|
|
@@ -45,6 +51,24 @@ function collectEventBindings(root, out) {
|
|
|
45
51
|
if (expr) {
|
|
46
52
|
out.push({ kind: "dynamic", value: expr });
|
|
47
53
|
}
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (prop.type !== compiler_core_1.NodeTypes.DIRECTIVE)
|
|
57
|
+
continue;
|
|
58
|
+
// `:[expr]="..."` / `@[expr]="..."`: the argument is an expression of its own
|
|
59
|
+
if (prop.arg?.type === compiler_core_1.NodeTypes.SIMPLE_EXPRESSION && !prop.arg.isStatic) {
|
|
60
|
+
handlers.push({ handler: false, code: prop.arg.content.trim() });
|
|
61
|
+
}
|
|
62
|
+
if (prop.exp?.type !== compiler_core_1.NodeTypes.SIMPLE_EXPRESSION)
|
|
63
|
+
continue;
|
|
64
|
+
if (prop.name === "for") {
|
|
65
|
+
const source = V_FOR_SOURCE.exec(prop.exp.content)?.[1]?.trim();
|
|
66
|
+
if (source) {
|
|
67
|
+
handlers.push({ handler: false, code: source });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (CODE_DIRECTIVES.has(prop.name)) {
|
|
71
|
+
handlers.push({ handler: prop.name === "on", code: prop.exp.content.trim() });
|
|
48
72
|
}
|
|
49
73
|
}
|
|
50
74
|
}
|
|
@@ -56,6 +80,14 @@ function collectEventBindings(root, out) {
|
|
|
56
80
|
if (node.type === compiler_core_1.NodeTypes.ELEMENT) {
|
|
57
81
|
visitElementProps(node.props);
|
|
58
82
|
visitChildren(node.children);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// `{{ expr }}`
|
|
86
|
+
if (node.type === compiler_core_1.NodeTypes.INTERPOLATION && node.content.type === compiler_core_1.NodeTypes.SIMPLE_EXPRESSION) {
|
|
87
|
+
const code = node.content.content.trim();
|
|
88
|
+
if (code) {
|
|
89
|
+
handlers.push({ handler: false, code });
|
|
90
|
+
}
|
|
59
91
|
}
|
|
60
92
|
}
|
|
61
93
|
visitChildren(root.children);
|
|
@@ -67,20 +99,23 @@ function parseVueSfc(source, filePath) {
|
|
|
67
99
|
for (const block of [descriptor.script, descriptor.scriptSetup]) {
|
|
68
100
|
if (!block)
|
|
69
101
|
continue;
|
|
70
|
-
const
|
|
102
|
+
const raw = block.src ? readSrcFile(filePath, block.src) : block.content;
|
|
103
|
+
const content = raw?.trim();
|
|
71
104
|
if (!content)
|
|
72
105
|
continue;
|
|
73
106
|
scripts.push({
|
|
74
107
|
lang: (block.lang ?? "js").toLowerCase(),
|
|
75
108
|
setup: Boolean(block.setup),
|
|
76
109
|
content,
|
|
110
|
+
startLine: block.src ? undefined : (0, layout_1.firstContentLine)(raw, block.loc.start.line),
|
|
77
111
|
});
|
|
78
112
|
}
|
|
79
113
|
const templateEvents = [];
|
|
114
|
+
const templateHandlers = [];
|
|
80
115
|
const template = descriptor.template;
|
|
81
116
|
if (template) {
|
|
82
117
|
if (template.ast) {
|
|
83
|
-
collectEventBindings(template.ast, templateEvents);
|
|
118
|
+
collectEventBindings(template.ast, templateEvents, templateHandlers);
|
|
84
119
|
}
|
|
85
120
|
else {
|
|
86
121
|
// @vue/compiler-sfc only ever leaves `ast` unset when `src` is set
|
|
@@ -90,7 +125,7 @@ function parseVueSfc(source, filePath) {
|
|
|
90
125
|
if (template.src) {
|
|
91
126
|
const external = readSrcFile(filePath, template.src);
|
|
92
127
|
if (external) {
|
|
93
|
-
collectEventBindings((0, compiler_dom_1.parse)(external), templateEvents);
|
|
128
|
+
collectEventBindings((0, compiler_dom_1.parse)(external), templateEvents, templateHandlers);
|
|
94
129
|
}
|
|
95
130
|
}
|
|
96
131
|
}
|
|
@@ -98,6 +133,8 @@ function parseVueSfc(source, filePath) {
|
|
|
98
133
|
return {
|
|
99
134
|
scripts,
|
|
100
135
|
templateEvents,
|
|
136
|
+
// an empty expression (`@click=""`) holds no code
|
|
137
|
+
templateHandlers: templateHandlers.filter((handler) => handler.code !== ""),
|
|
101
138
|
errors: errors.map((error) => {
|
|
102
139
|
// @vue/compiler-sfc errors are always Error instances
|
|
103
140
|
/* v8 ignore else */
|
|
@@ -129,19 +166,20 @@ function buildScriptModule(parsed) {
|
|
|
129
166
|
parts.push("export {}");
|
|
130
167
|
}
|
|
131
168
|
else {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
parts.push([...header, block.content].join("\n"));
|
|
138
|
-
}
|
|
169
|
+
// Only a leading `@ts-nocheck` is honoured by TypeScript, so only the
|
|
170
|
+
// first block decides. Blocks keep their original line numbers.
|
|
171
|
+
const first = parsed.scripts[0];
|
|
172
|
+
const noCheck = first.lang !== "ts" && first.lang !== "tsx";
|
|
173
|
+
parts.push((0, layout_1.placeBlocks)(parsed.scripts, noCheck ? "// @ts-nocheck" : undefined));
|
|
139
174
|
}
|
|
140
|
-
if (parsed.templateEvents.length > 0) {
|
|
175
|
+
if (parsed.templateEvents.length > 0 || parsed.templateHandlers.length > 0) {
|
|
141
176
|
const lines = [
|
|
142
177
|
"// --- vue template (auto-generated) ---",
|
|
143
178
|
`declare function ${TEMPLATE_EVENT_CALLEE}(name: string): void;`,
|
|
144
179
|
"function __eventraVueTemplate() {",
|
|
180
|
+
// template code goes through the same detection as script code, so a call to a tracking
|
|
181
|
+
// function inside a handler or an interpolation is an event like any other
|
|
182
|
+
...parsed.templateHandlers.map(renderTemplateCode),
|
|
145
183
|
...parsed.templateEvents.map((binding) => binding.kind === "literal"
|
|
146
184
|
? ` ${TEMPLATE_EVENT_CALLEE}("${escapeString(binding.value)}");`
|
|
147
185
|
: ` ${TEMPLATE_EVENT_CALLEE}(${binding.value});`),
|
|
@@ -151,6 +189,18 @@ function buildScriptModule(parsed) {
|
|
|
151
189
|
}
|
|
152
190
|
return `${parts.join("\n\n")}\n`;
|
|
153
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* A handler is a statement list when it is written as one (`a(); b()`), an expression otherwise
|
|
194
|
+
* (`() => a()`, `handler`); both are valid as the body of a block, except a bare `function` which
|
|
195
|
+
* would read as a declaration. Other expressions are parenthesised: `{ a: 1 }` is an object here.
|
|
196
|
+
* The closing brace sits on its own line, so a trailing `// comment` cannot swallow it.
|
|
197
|
+
*/
|
|
198
|
+
function renderTemplateCode({ handler, code }) {
|
|
199
|
+
if (handler && !/^(async\s+)?function\b/.test(code)) {
|
|
200
|
+
return ` {\n${code}\n }`;
|
|
201
|
+
}
|
|
202
|
+
return ` (${code}\n );`;
|
|
203
|
+
}
|
|
154
204
|
function escapeString(value) {
|
|
155
205
|
return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
156
206
|
}
|
package/dist/transform.d.ts.map
CHANGED
|
@@ -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;
|
|
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
|
|
3
|
+
"version": "1.1.0",
|
|
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",
|