@prover-coder-ai/component-tagger 1.0.4 → 1.0.5
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/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/shell/component-tagger.ts +34 -13
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -26,10 +26,20 @@ const stripQuery = (id: string): string => {
|
|
|
26
26
|
return queryIndex === -1 ? id : id.slice(0, queryIndex)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
// CHANGE: compute relative paths from the resolved Vite root instead of process.cwd().
|
|
30
|
+
// WHY: keep component paths stable across monorepos and custom Vite roots.
|
|
31
|
+
// QUOTE(TZ): "Сам компонент должен быть в текущем app но вот что бы его протестировать надо создать ещё один проект который наш текущий апп будет подключать"
|
|
32
|
+
// REF: user-2026-01-14-frontend-consumer
|
|
33
|
+
// SOURCE: n/a
|
|
34
|
+
// FORMAT THEOREM: forall p in Path: relative(root, p) = r -> resolve(root, r) = p
|
|
35
|
+
// PURITY: SHELL
|
|
36
|
+
// EFFECT: Effect<string, never, Path>
|
|
37
|
+
// INVARIANT: output is deterministic for a fixed root
|
|
38
|
+
// COMPLEXITY: O(n)/O(1)
|
|
39
|
+
const relativeFromRoot = (rootDir: string, absolutePath: string): Effect.Effect<string, never, Path> =>
|
|
30
40
|
pipe(
|
|
31
41
|
Path,
|
|
32
|
-
Effect.map((pathService) => pathService.relative(
|
|
42
|
+
Effect.map((pathService) => pathService.relative(rootDir, absolutePath))
|
|
33
43
|
)
|
|
34
44
|
|
|
35
45
|
const attrExists = (node: t.JSXOpeningElement, attrName: string): boolean =>
|
|
@@ -108,17 +118,20 @@ const makeBabelTagger = (relativeFilename: string): PluginObj => ({
|
|
|
108
118
|
// COMPLEXITY: O(n)/O(1)
|
|
109
119
|
const runTransform = (
|
|
110
120
|
code: string,
|
|
111
|
-
id: string
|
|
121
|
+
id: string,
|
|
122
|
+
rootDir: string
|
|
112
123
|
): Effect.Effect<ViteTransformResult | null, ComponentTaggerError, Path> => {
|
|
113
124
|
const cleanId = stripQuery(id)
|
|
114
125
|
|
|
115
126
|
return pipe(
|
|
116
|
-
|
|
127
|
+
relativeFromRoot(rootDir, cleanId),
|
|
117
128
|
Effect.flatMap((relative) =>
|
|
118
129
|
Effect.tryPromise({
|
|
119
130
|
try: () =>
|
|
120
131
|
transformAsync(code, {
|
|
121
132
|
filename: cleanId,
|
|
133
|
+
babelrc: false,
|
|
134
|
+
configFile: false,
|
|
122
135
|
parserOpts: {
|
|
123
136
|
sourceType: "module",
|
|
124
137
|
plugins: ["typescript", "jsx", "decorators-legacy"]
|
|
@@ -157,14 +170,22 @@ const runTransform = (
|
|
|
157
170
|
// EFFECT: Effect<ViteTransformResult | null, ComponentTaggerError, never>
|
|
158
171
|
// INVARIANT: no duplicate path attributes
|
|
159
172
|
// COMPLEXITY: O(n)/O(1)
|
|
160
|
-
export const componentTagger = (): PluginOption =>
|
|
161
|
-
|
|
162
|
-
enforce: "pre",
|
|
163
|
-
transform(code, id) {
|
|
164
|
-
if (!isJsxFile(id)) {
|
|
165
|
-
return null
|
|
166
|
-
}
|
|
173
|
+
export const componentTagger = (): PluginOption => {
|
|
174
|
+
let resolvedRoot = process.cwd()
|
|
167
175
|
|
|
168
|
-
|
|
176
|
+
return {
|
|
177
|
+
name: "component-path-tagger",
|
|
178
|
+
enforce: "pre",
|
|
179
|
+
apply: "serve",
|
|
180
|
+
configResolved(config) {
|
|
181
|
+
resolvedRoot = config.root
|
|
182
|
+
},
|
|
183
|
+
transform(code, id) {
|
|
184
|
+
if (!isJsxFile(id)) {
|
|
185
|
+
return null
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return Effect.runPromise(pipe(runTransform(code, id, resolvedRoot), Effect.provide(NodePathLayer)))
|
|
189
|
+
}
|
|
169
190
|
}
|
|
170
|
-
}
|
|
191
|
+
}
|