@prover-coder-ai/component-tagger 1.0.3 → 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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @prover-coder-ai/component-tagger
2
2
 
3
+ ## 1.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - chore: automated version bump
8
+
9
+ ## 1.0.4
10
+
11
+ ### Patch Changes
12
+
13
+ - chore: automated version bump
14
+
3
15
  ## 1.0.3
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -10,4 +10,16 @@ Example output:
10
10
 
11
11
  Format: `<relative-file-path>:<line>:<column>`
12
12
 
13
- Recommended: enable only in `development` mode in Vite config.
13
+ ## Usage
14
+
15
+ ```ts
16
+ import { defineConfig, type PluginOption } from "vite"
17
+ import { componentTagger } from "@prover-coder-ai/component-tagger"
18
+
19
+ export default defineConfig(({ mode }) => {
20
+ const isDevelopment = mode === "development"
21
+ const plugins = [isDevelopment && componentTagger()].filter(Boolean) as PluginOption[]
22
+
23
+ return { plugins }
24
+ })
25
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prover-coder-ai/component-tagger",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Component tagger Vite plugin for JSX metadata",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -26,10 +26,20 @@ const stripQuery = (id: string): string => {
26
26
  return queryIndex === -1 ? id : id.slice(0, queryIndex)
27
27
  }
28
28
 
29
- const relativeFromCwd = (absolutePath: string): Effect.Effect<string, never, Path> =>
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(process.cwd(), absolutePath))
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
- relativeFromCwd(cleanId),
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
- name: "component-path-tagger",
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
- return Effect.runPromise(pipe(runTransform(code, id), Effect.provide(NodePathLayer)))
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
+ }