react-code-locator 0.1.8 → 0.1.12

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.
Files changed (52) hide show
  1. package/README.md +49 -44
  2. package/dist/babel.cjs +427 -40
  3. package/dist/babel.cjs.map +1 -1
  4. package/dist/babel.d.cts +12 -1
  5. package/dist/babel.d.ts +12 -1
  6. package/dist/babel.js +424 -29
  7. package/dist/babel.js.map +1 -1
  8. package/dist/babelInjectComponentSource.cjs +403 -38
  9. package/dist/babelInjectComponentSource.cjs.map +1 -1
  10. package/dist/babelInjectComponentSource.d.cts +3 -4
  11. package/dist/babelInjectComponentSource.d.ts +3 -4
  12. package/dist/babelInjectComponentSource.js +403 -28
  13. package/dist/babelInjectComponentSource.js.map +1 -1
  14. package/dist/client-sm5wi0uT.d.cts +15 -0
  15. package/dist/client-sm5wi0uT.d.ts +15 -0
  16. package/dist/client.cjs +166 -27
  17. package/dist/client.cjs.map +1 -1
  18. package/dist/client.d.cts +1 -14
  19. package/dist/client.d.ts +1 -14
  20. package/dist/client.js +166 -27
  21. package/dist/client.js.map +1 -1
  22. package/dist/esbuild.cjs +615 -0
  23. package/dist/esbuild.cjs.map +1 -0
  24. package/dist/esbuild.d.cts +25 -0
  25. package/dist/esbuild.d.ts +25 -0
  26. package/dist/esbuild.js +588 -0
  27. package/dist/esbuild.js.map +1 -0
  28. package/dist/index.cjs +833 -29
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +9 -1
  31. package/dist/index.d.ts +9 -1
  32. package/dist/index.js +820 -28
  33. package/dist/index.js.map +1 -1
  34. package/dist/sourceAdapter-DLWo_ABo.d.cts +15 -0
  35. package/dist/sourceAdapter-DLWo_ABo.d.ts +15 -0
  36. package/dist/swc.cjs +588 -0
  37. package/dist/swc.cjs.map +1 -0
  38. package/dist/swc.d.cts +29 -0
  39. package/dist/swc.d.ts +29 -0
  40. package/dist/swc.js +559 -0
  41. package/dist/swc.js.map +1 -0
  42. package/dist/vite.cjs +525 -84
  43. package/dist/vite.cjs.map +1 -1
  44. package/dist/vite.d.cts +20 -6
  45. package/dist/vite.d.ts +20 -6
  46. package/dist/vite.js +520 -72
  47. package/dist/vite.js.map +1 -1
  48. package/dist/webpackRuntimeEntry.cjs +166 -27
  49. package/dist/webpackRuntimeEntry.cjs.map +1 -1
  50. package/dist/webpackRuntimeEntry.js +166 -27
  51. package/dist/webpackRuntimeEntry.js.map +1 -1
  52. package/package.json +12 -1
package/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  개발 중인 React 앱에서 요소를 `Shift + Click`하면 해당 UI와 연결된 소스 위치를 찾는 패키지입니다.
4
4
 
5
- - JSX 디버그 정보가 있으면 우선 사용해서 정확한 JSX 위치를 찾습니다.
6
- - JSX 정보가 없으면 컴포넌트 정의 위치로 fallback 합니다.
7
- - Vite, Webpack, Babel, 브라우저 런타임을 각각 분리해서 사용할 수 있습니다.
5
+ - React element 생성 source metadata를 붙이고, 브라우저 런타임에서 Fiber를 따라 위치를 계산합니다.
6
+ - JSX 디버그 정보가 있으면 우선 사용하고, 없으면 컴포넌트 정의 위치로 fallback 합니다.
7
+ - Babel, Vite, esbuild, SWC 파이프라인용 어댑터와 브라우저 런타임을 분리해서 사용할 수 있습니다.
8
8
 
9
9
  ## 설치
10
10
 
@@ -20,26 +20,20 @@ npm i -D /absolute/path/to/react-code-locator
20
20
 
21
21
  ## 빠른 시작
22
22
 
23
- Vite 환경에서는 기존 `@vitejs/plugin-react` 설정에 Babel 플러그인을 추가하고, `react-code-locator/vite`는 클라이언트 자동 주입만 맡깁니다.
23
+ Vite 환경에서는 `createViteSourceAdapter()`가 source transform과 클라이언트 자동 주입을 함께 제공합니다.
24
24
 
25
25
  ```ts
26
26
  import { defineConfig } from "vite";
27
27
  import react from "@vitejs/plugin-react";
28
- import { babelInjectComponentSource, reactComponentJump } from "react-code-locator/vite";
28
+ import { createViteSourceAdapter } from "react-code-locator/vite";
29
29
 
30
30
  export default defineConfig(({ command }) => ({
31
31
  plugins: [
32
- react({
33
- babel: {
34
- plugins: [babelInjectComponentSource],
35
- },
36
- }),
37
- ...reactComponentJump({
32
+ react(),
33
+ ...createViteSourceAdapter({
38
34
  command,
39
- locator: {
40
- triggerKey: "shift",
41
- },
42
- }),
35
+ locator: { triggerKey: "shift" },
36
+ }).config.plugins,
43
37
  ],
44
38
  }));
45
39
  ```
@@ -56,30 +50,23 @@ export default defineConfig(({ command }) => ({
56
50
 
57
51
  Vite + React 프로젝트용 기본 진입점입니다.
58
52
 
59
- - 개발 서버에서만 브라우저 클라이언트를 자동 주입합니다.
53
+ - source transform 플러그인과 브라우저 클라이언트 주입 플러그인을 함께 제공합니다.
60
54
  - HTML에는 bare import를 직접 넣지 않고 Vite 가상 모듈을 통해 클라이언트를 로드합니다.
61
55
  - 기본값으로 브라우저 클라이언트도 자동 주입합니다.
62
- - React 플러그인은 직접 만들지 않습니다. 기존 `@vitejs/plugin-react` 설정에 Babel 플러그인을 추가해서 사용해야 합니다.
63
56
 
64
57
  ```ts
65
58
  import { defineConfig } from "vite";
66
59
  import react from "@vitejs/plugin-react";
67
- import { babelInjectComponentSource, reactComponentJump } from "react-code-locator/vite";
60
+ import { createViteSourceAdapter } from "react-code-locator/vite";
68
61
 
69
62
  export default defineConfig(({ command }) => ({
70
63
  plugins: [
71
- react({
72
- babel: {
73
- plugins: [babelInjectComponentSource],
74
- },
75
- }),
76
- ...reactComponentJump({
64
+ react(),
65
+ ...createViteSourceAdapter({
77
66
  command,
78
- locator: {
79
- triggerKey: "shift",
80
- },
67
+ locator: { triggerKey: "shift" },
81
68
  injectClient: true,
82
- }),
69
+ }).config.plugins,
83
70
  ],
84
71
  }));
85
72
  ```
@@ -91,7 +78,7 @@ export default defineConfig(({ command }) => ({
91
78
  - `locator.onLocate(result)`: 위치를 찾았을 때 커스텀 처리
92
79
  - `locator.onError(error)`: 위치를 못 찾았을 때 커스텀 처리
93
80
  - `injectClient`: `false`로 두면 브라우저 런타임 자동 주입 비활성화
94
- - `babelInjectComponentSource`: 기존 `@vitejs/plugin-react`의 `babel.plugins`에 추가
81
+ - `babel`: source transform 옵션
95
82
 
96
83
  ### `react-code-locator/client`
97
84
 
@@ -116,19 +103,15 @@ dispose();
116
103
  ```ts
117
104
  import { defineConfig } from "vite";
118
105
  import react from "@vitejs/plugin-react";
119
- import { babelInjectComponentSource, reactComponentJump } from "react-code-locator/vite";
106
+ import { createViteSourceAdapter } from "react-code-locator/vite";
120
107
 
121
108
  export default defineConfig(({ command }) => ({
122
109
  plugins: [
123
- react({
124
- babel: {
125
- plugins: [babelInjectComponentSource],
126
- },
127
- }),
128
- ...reactComponentJump({
110
+ react(),
111
+ ...createViteSourceAdapter({
129
112
  command,
130
113
  injectClient: false,
131
- }),
114
+ }).config.plugins,
132
115
  ],
133
116
  }));
134
117
  ```
@@ -147,11 +130,11 @@ if (import.meta.env.DEV) {
147
130
 
148
131
  Babel 플러그인만 따로 사용할 때 사용합니다.
149
132
 
150
- 이 플러그인은 기본적으로 가지를 주입합니다.
133
+ 이 플러그인은 기본적으로 가지를 주입합니다.
151
134
 
135
+ - 커스텀 React 컴포넌트 JSX 호출부에 `$componentSourceLoc`
152
136
  - React 컴포넌트 함수/클래스에 `__componentSourceLoc`
153
-
154
- 옵션으로 JSX 요소에도 `__componentSourceLoc`를 주입할 수 있지만 기본값은 `false`입니다.
137
+ - intrinsic DOM JSX는 prop이 아니라 숨겨진 registry metadata로 추적합니다.
155
138
 
156
139
  ```js
157
140
  const { babelInjectComponentSource } = require("react-code-locator/babel");
@@ -171,13 +154,13 @@ export default {
171
154
  };
172
155
  ```
173
156
 
174
- JSX 주입이 필요하면:
157
+ JSX 호출부 주입을 끄고 싶으면:
175
158
 
176
159
  ```ts
177
160
  import { babelInjectComponentSource } from "react-code-locator/babel";
178
161
 
179
162
  export default {
180
- plugins: [[babelInjectComponentSource, { injectJsxSource: true }]],
163
+ plugins: [[babelInjectComponentSource, { injectJsxSource: false }]],
181
164
  };
182
165
  ```
183
166
 
@@ -205,6 +188,28 @@ module.exports = withReactComponentJump(config, {
205
188
  - React 앱이 Babel을 통해 트랜스파일되어야 합니다.
206
189
  - `module.rules` 안에 `babel-loader`가 있어야 자동 주입이 동작합니다.
207
190
 
191
+ ### `react-code-locator/esbuild`
192
+
193
+ esbuild 파이프라인에 source transform 플러그인을 붙일 때 사용합니다.
194
+
195
+ ```ts
196
+ import { createEsbuildSourceAdapter } from "react-code-locator/esbuild";
197
+
198
+ const locator = createEsbuildSourceAdapter();
199
+ const plugins = [...locator.config.plugins];
200
+ ```
201
+
202
+ ### `react-code-locator/swc`
203
+
204
+ SWC 기반 파이프라인에서 공통 source transform을 호출할 때 사용합니다.
205
+
206
+ ```ts
207
+ import { createSwcSourceAdapter } from "react-code-locator/swc";
208
+
209
+ const locator = createSwcSourceAdapter();
210
+ const transform = locator.config.transform;
211
+ ```
212
+
208
213
  ### `react-code-locator`
209
214
 
210
215
  런타임 유틸만 직접 사용할 때의 기본 엔트리입니다.
@@ -223,7 +228,7 @@ import { enableReactComponentJump, locateComponentSource } from "react-code-loca
223
228
  ```ts
224
229
  type LocatorResult = {
225
230
  source: string;
226
- mode: "jsx" | "component";
231
+ mode: "direct" | "screen" | "implementation";
227
232
  };
228
233
  ```
229
234
 
@@ -231,7 +236,7 @@ type LocatorResult = {
231
236
 
232
237
  정상 동작하려면 보통 아래 두 단계가 같이 필요합니다.
233
238
 
234
- 1. 빌드 단계에서 Babel 플러그인으로 소스 메타데이터 주입
239
+ 1. 빌드 단계에서 source transform으로 소스 메타데이터 주입
235
240
  2. 브라우저에서 클릭 이벤트를 가로채 React Fiber를 따라가며 위치 계산
236
241
 
237
242
  Vite/webpack 어댑터를 쓰면 이 둘을 한 번에 붙일 수 있습니다.