@prover-coder-ai/component-tagger 1.0.30 → 1.0.32
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,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
2
|
/**
|
|
3
3
|
* Options for the component tagger Vite plugin.
|
|
4
4
|
*/
|
|
@@ -13,7 +13,7 @@ export type ComponentTaggerOptions = {
|
|
|
13
13
|
* Creates a Vite plugin that injects a single component-path data attribute.
|
|
14
14
|
*
|
|
15
15
|
* @param options - Configuration options for the plugin.
|
|
16
|
-
* @returns Vite
|
|
16
|
+
* @returns Vite plugin for pre-transform tagging.
|
|
17
17
|
*
|
|
18
18
|
* @pure false
|
|
19
19
|
* @effect Babel transform through Effect
|
|
@@ -21,4 +21,4 @@ export type ComponentTaggerOptions = {
|
|
|
21
21
|
* @complexity O(n) time / O(1) space per JSX module
|
|
22
22
|
* @throws Never - errors are typed and surfaced by Effect
|
|
23
23
|
*/
|
|
24
|
-
export declare const componentTagger: (options?: ComponentTaggerOptions) =>
|
|
24
|
+
export declare const componentTagger: (options?: ComponentTaggerOptions) => Plugin;
|
|
@@ -11,14 +11,31 @@ class ComponentTaggerError extends Error {
|
|
|
11
11
|
this.cause = cause;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
14
|
+
const toSourceMapInput = (map) => {
|
|
15
|
+
if (map === null || map === undefined) {
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
|
+
return JSON.stringify({
|
|
19
|
+
file: map.file,
|
|
20
|
+
mappings: map.mappings,
|
|
21
|
+
names: map.names,
|
|
22
|
+
sources: map.sources,
|
|
23
|
+
version: map.version,
|
|
24
|
+
...(map.sourceRoot === undefined ? {} : { sourceRoot: map.sourceRoot }),
|
|
25
|
+
...(map.sourcesContent === undefined ? {} : { sourcesContent: map.sourcesContent })
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const toViteResult = (result, originalCode) => {
|
|
29
|
+
if (result === null || result.code === null || result.code === undefined) {
|
|
30
|
+
return {
|
|
31
|
+
code: originalCode,
|
|
32
|
+
map: null
|
|
33
|
+
};
|
|
34
|
+
}
|
|
18
35
|
const { code } = result;
|
|
19
36
|
return {
|
|
20
37
|
code,
|
|
21
|
-
map: result.map
|
|
38
|
+
map: toSourceMapInput(result.map)
|
|
22
39
|
};
|
|
23
40
|
};
|
|
24
41
|
// CHANGE: use unified JSX tagger visitor from core module.
|
|
@@ -43,7 +60,7 @@ const makeBabelTagger = (relativeFilename, attributeName) => {
|
|
|
43
60
|
*
|
|
44
61
|
* @param code - Source code to transform.
|
|
45
62
|
* @param id - Vite module id for the source code.
|
|
46
|
-
* @returns Vite-compatible transform result
|
|
63
|
+
* @returns Vite-compatible transform result.
|
|
47
64
|
*
|
|
48
65
|
* @pure false
|
|
49
66
|
* @effect Babel transform
|
|
@@ -55,9 +72,9 @@ const makeBabelTagger = (relativeFilename, attributeName) => {
|
|
|
55
72
|
// QUOTE(TZ): "Сам компонент должен быть в текущем app но вот что бы его протестировать надо создать ещё один проект который наш текущий апп будет подключать"
|
|
56
73
|
// REF: user-2026-01-14-frontend-consumer
|
|
57
74
|
// SOURCE: n/a
|
|
58
|
-
// FORMAT THEOREM: forall c in Code: transform(c) = r -> r is tagged
|
|
75
|
+
// FORMAT THEOREM: forall c in Code: transform(c) = r -> r is tagged
|
|
59
76
|
// PURITY: SHELL
|
|
60
|
-
// EFFECT: Effect<ViteTransformResult
|
|
77
|
+
// EFFECT: Effect<ViteTransformResult, ComponentTaggerError, never>
|
|
61
78
|
// INVARIANT: errors are surfaced as ComponentTaggerError only
|
|
62
79
|
// COMPLEXITY: O(n)/O(1)
|
|
63
80
|
const runTransform = (code, id, rootDir, attributeName) => {
|
|
@@ -78,13 +95,13 @@ const runTransform = (code, id, rootDir, attributeName) => {
|
|
|
78
95
|
const error = cause instanceof Error ? cause : new Error(String(cause));
|
|
79
96
|
return new ComponentTaggerError("Babel transform failed", error);
|
|
80
97
|
}
|
|
81
|
-
})), Effect.map((result) => toViteResult(result)));
|
|
98
|
+
})), Effect.map((result) => toViteResult(result, code)));
|
|
82
99
|
};
|
|
83
100
|
/**
|
|
84
101
|
* Creates a Vite plugin that injects a single component-path data attribute.
|
|
85
102
|
*
|
|
86
103
|
* @param options - Configuration options for the plugin.
|
|
87
|
-
* @returns Vite
|
|
104
|
+
* @returns Vite plugin for pre-transform tagging.
|
|
88
105
|
*
|
|
89
106
|
* @pure false
|
|
90
107
|
* @effect Babel transform through Effect
|
|
@@ -99,24 +116,25 @@ const runTransform = (code, id, rootDir, attributeName) => {
|
|
|
99
116
|
// SOURCE: n/a
|
|
100
117
|
// FORMAT THEOREM: forall id: isJsxFile(id) -> transform(id) adds specified attribute
|
|
101
118
|
// PURITY: SHELL
|
|
102
|
-
// EFFECT: Effect<ViteTransformResult
|
|
119
|
+
// EFFECT: Effect<ViteTransformResult, ComponentTaggerError, never>
|
|
103
120
|
// INVARIANT: no duplicate attributes with the same name
|
|
104
121
|
// COMPLEXITY: O(n)/O(1)
|
|
105
122
|
export const componentTagger = (options) => {
|
|
106
123
|
const attributeName = options?.attributeName ?? componentPathAttributeName;
|
|
107
124
|
let resolvedRoot = process.cwd();
|
|
108
|
-
|
|
125
|
+
const plugin = {
|
|
109
126
|
name: "component-path-tagger",
|
|
110
127
|
enforce: "pre",
|
|
111
128
|
apply: "serve",
|
|
112
129
|
configResolved(config) {
|
|
113
130
|
resolvedRoot = config.root;
|
|
114
131
|
},
|
|
115
|
-
transform(code, id) {
|
|
132
|
+
transform(code, id, _options) {
|
|
116
133
|
if (!isJsxFile(id)) {
|
|
117
134
|
return null;
|
|
118
135
|
}
|
|
119
136
|
return Effect.runPromise(pipe(runTransform(code, id, resolvedRoot, attributeName), Effect.provide(NodePathLayer)));
|
|
120
137
|
}
|
|
121
138
|
};
|
|
139
|
+
return plugin;
|
|
122
140
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prover-coder-ai/component-tagger",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.32",
|
|
4
4
|
"description": "Component tagger Vite plugin and Babel plugin for JSX metadata",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -43,12 +43,12 @@
|
|
|
43
43
|
"homepage": "https://github.com/ProverCoderAI/effect-template#readme",
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@babel/core": "^7.29.0",
|
|
46
|
-
"@effect/platform": "^0.
|
|
47
|
-
"@effect/platform-node": "^0.
|
|
48
|
-
"effect": "^3.
|
|
46
|
+
"@effect/platform": "^0.96.0",
|
|
47
|
+
"@effect/platform-node": "^0.106.0",
|
|
48
|
+
"effect": "^3.21.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"vite": "^
|
|
51
|
+
"vite": "^8.0.6"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"prebuild": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|