react-code-locator 0.1.17 → 0.2.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.
Files changed (60) hide show
  1. package/README.md +89 -266
  2. package/dist/client.cjs +1 -399
  3. package/dist/client.cjs.map +1 -1
  4. package/dist/client.d.cts +1 -1
  5. package/dist/client.d.ts +1 -1
  6. package/dist/client.js +1 -371
  7. package/dist/client.js.map +1 -1
  8. package/dist/esbuild.cjs +29 -7149
  9. package/dist/esbuild.cjs.map +1 -1
  10. package/dist/esbuild.d.cts +1 -1
  11. package/dist/esbuild.d.ts +1 -1
  12. package/dist/esbuild.js +29 -7122
  13. package/dist/esbuild.js.map +1 -1
  14. package/dist/index.cjs +42 -398
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +6 -0
  17. package/dist/index.d.ts +6 -0
  18. package/dist/index.js +42 -370
  19. package/dist/index.js.map +1 -1
  20. package/dist/swc.cjs +29 -7119
  21. package/dist/swc.cjs.map +1 -1
  22. package/dist/swc.d.cts +1 -1
  23. package/dist/swc.d.ts +1 -1
  24. package/dist/swc.js +29 -7090
  25. package/dist/swc.js.map +1 -1
  26. package/dist/{transform-CXh-m5Ez.d.cts → transform-z2n_1yc5.d.cts} +2 -2
  27. package/dist/{transform-CXh-m5Ez.d.ts → transform-z2n_1yc5.d.ts} +2 -2
  28. package/dist/unplugin.cjs +32 -7135
  29. package/dist/unplugin.cjs.map +1 -1
  30. package/dist/unplugin.d.cts +16 -5
  31. package/dist/unplugin.d.ts +16 -5
  32. package/dist/unplugin.js +32 -7106
  33. package/dist/unplugin.js.map +1 -1
  34. package/dist/webpack.cjs +36 -88
  35. package/dist/webpack.cjs.map +1 -1
  36. package/dist/webpack.d.cts +11 -51
  37. package/dist/webpack.d.ts +11 -51
  38. package/dist/webpack.js +36 -58
  39. package/dist/webpack.js.map +1 -1
  40. package/package.json +10 -34
  41. package/dist/core/transform-cjs.cjs +0 -7014
  42. package/dist/core/webpackPitchLoader-cjs.cjs +0 -7032
  43. package/dist/vite.cjs +0 -7200
  44. package/dist/vite.cjs.map +0 -1
  45. package/dist/vite.d.cts +0 -52
  46. package/dist/vite.d.ts +0 -52
  47. package/dist/vite.js +0 -7169
  48. package/dist/vite.js.map +0 -1
  49. package/dist/webpackLoader.cjs +0 -7115
  50. package/dist/webpackLoader.cjs.map +0 -1
  51. package/dist/webpackLoader.d.cts +0 -15
  52. package/dist/webpackLoader.d.ts +0 -15
  53. package/dist/webpackLoader.js +0 -7092
  54. package/dist/webpackLoader.js.map +0 -1
  55. package/dist/webpackRuntimeEntry.cjs +0 -375
  56. package/dist/webpackRuntimeEntry.cjs.map +0 -1
  57. package/dist/webpackRuntimeEntry.d.cts +0 -2
  58. package/dist/webpackRuntimeEntry.d.ts +0 -2
  59. package/dist/webpackRuntimeEntry.js +0 -373
  60. package/dist/webpackRuntimeEntry.js.map +0 -1
package/README.md CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  개발 중인 React 앱에서 요소를 `Shift + Click`하면 해당 UI와 연결된 소스 위치를 찾는 패키지입니다.
4
4
 
5
- - React element 생성 시 source metadata를 붙이고, 브라우저 런타임에서 Fiber를 따라 위치를 계산합니다.
6
- - JSX 디버그 정보가 있으면 우선 사용하고, 없으면 컴포넌트 정의 위치로 fallback 합니다.
7
- - Babel, Vite, esbuild, SWC 파이프라인용 어댑터와 브라우저 런타임을 분리해서 사용할 수 있습니다.
5
+ - React element 생성 시 source metadata를 주입하고, 브라우저 런타임에서 Fiber를 따라 위치를 계산합니다.
6
+ - **완전 번들링**: acorn 기반 순수 JS 파서를 내장 별도 파서 설치 불필요
7
+ - **Universal**: Vite, Webpack, Rollup, esbuild, Rspack 모두 지원
8
+ - **개발 전용**: 프로덕션 빌드에 영향 없음
8
9
 
9
10
  ## 설치
10
11
 
@@ -12,338 +13,160 @@
12
13
  npm i -D react-code-locator
13
14
  ```
14
15
 
15
- 로컬 패키지로 연결할 때는:
16
-
17
- ```bash
18
- npm i -D /absolute/path/to/react-code-locator
19
- ```
16
+ > Vite / Rollup / esbuild / Rspack 플러그인을 사용하려면 `unplugin`도 필요합니다.
17
+ >
18
+ > ```bash
19
+ > npm i -D unplugin
20
+ > ```
21
+ >
22
+ > Webpack은 unplugin 없이 동작합니다.
20
23
 
21
24
  ## 빠른 시작
22
25
 
23
- Vite 환경에서는 `createViteSourceAdapter()`가 source transform과 클라이언트 자동 주입을 함께 제공합니다.
24
-
25
- ```ts
26
- import { defineConfig } from "vite";
27
- import react from "@vitejs/plugin-react";
28
- import { createViteSourceAdapter } from "react-code-locator/vite";
29
-
30
- export default defineConfig(({ command }) => ({
31
- plugins: [
32
- react(),
33
- ...createViteSourceAdapter({
34
- command,
35
- locator: { triggerKey: "shift" },
36
- }).config.plugins,
37
- ],
38
- }));
39
- ```
40
-
41
- 개발 서버에서 `Shift + Click`하면 브라우저 콘솔에 이런 식으로 출력됩니다.
42
-
43
- ```text
44
- [react-code-locator] src/components/Button.tsx:14:1 [jsx]
45
- ```
46
-
47
- ## 제공 엔트리
26
+ ### Vite
48
27
 
49
- ### `react-code-locator/vite`
50
-
51
- Vite + React 프로젝트용 기본 진입점입니다.
52
-
53
- - source transform 플러그인과 브라우저 클라이언트 주입 플러그인을 함께 제공합니다.
54
- - HTML에는 bare import를 직접 넣지 않고 Vite 가상 모듈을 통해 클라이언트를 로드합니다.
55
- - 기본값으로 브라우저 클라이언트도 자동 주입합니다.
28
+ `vitePlugin`은 소스 transform + 클라이언트 런타임 자동 주입을 모두 처리합니다.
56
29
 
57
30
  ```ts
31
+ // vite.config.ts
58
32
  import { defineConfig } from "vite";
59
33
  import react from "@vitejs/plugin-react";
60
- import { createViteSourceAdapter } from "react-code-locator/vite";
34
+ import { vitePlugin } from "react-code-locator";
61
35
 
62
- export default defineConfig(({ command }) => ({
36
+ export default defineConfig({
63
37
  plugins: [
64
38
  react(),
65
- ...createViteSourceAdapter({
66
- command,
67
- locator: { triggerKey: "shift" },
68
- injectClient: true,
69
- }).config.plugins,
39
+ vitePlugin(),
70
40
  ],
71
- }));
72
- ```
73
-
74
- 옵션:
75
-
76
- - `command`: `"serve" | "build"` , 보통 Vite의 `command` 그대로 전달
77
- - `locator.triggerKey`: `"alt" | "meta" | "ctrl" | "shift" | "none"`
78
- - `locator.onLocate(result)`: 위치를 찾았을 때 커스텀 처리
79
- - `locator.onError(error)`: 위치를 못 찾았을 때 커스텀 처리
80
- - `injectClient`: `false`로 두면 브라우저 런타임 자동 주입 비활성화
81
- - `babel`: source transform 옵션
82
-
83
- ### `react-code-locator/client`
84
-
85
- 브라우저 런타임만 수동으로 붙이고 싶을 때 사용합니다.
86
-
87
- ```ts
88
- import { enableReactComponentJump } from "react-code-locator/client";
89
-
90
- const dispose = enableReactComponentJump({
91
- triggerKey: "shift",
92
- onLocate(result) {
93
- console.log("located:", result.source, result.mode);
94
- },
95
41
  });
96
-
97
- // 필요 시 해제
98
- dispose();
99
- ```
100
-
101
- 자동 주입을 끄고 직접 붙이는 예시:
102
-
103
- ```ts
104
- import { defineConfig } from "vite";
105
- import react from "@vitejs/plugin-react";
106
- import { createViteSourceAdapter } from "react-code-locator/vite";
107
-
108
- export default defineConfig(({ command }) => ({
109
- plugins: [
110
- react(),
111
- ...createViteSourceAdapter({
112
- command,
113
- injectClient: false,
114
- }).config.plugins,
115
- ],
116
- }));
117
- ```
118
-
119
- 그 다음 앱 엔트리에서:
120
-
121
- ```ts
122
- import { enableReactComponentJump } from "react-code-locator/client";
123
-
124
- if (import.meta.env.DEV) {
125
- enableReactComponentJump();
126
- }
127
42
  ```
128
43
 
129
- ### `react-code-locator/babel`
130
-
131
- Babel 플러그인만 따로 사용할 때 사용합니다.
132
-
133
- 이 플러그인은 기본적으로 두 가지를 주입합니다.
134
-
135
- - 커스텀 React 컴포넌트 JSX 호출부에 `$componentSourceLoc`
136
- - React 컴포넌트 함수/클래스에 `__componentSourceLoc`
137
- - intrinsic DOM JSX는 prop이 아니라 숨겨진 registry metadata로 추적합니다.
44
+ ### Next.js (Webpack)
138
45
 
139
46
  ```js
140
- const { babelInjectComponentSource } = require("react-code-locator/babel");
47
+ // next.config.js
48
+ const { webpackPlugin } = require("react-code-locator/webpack");
141
49
 
142
50
  module.exports = {
143
- plugins: [babelInjectComponentSource],
51
+ webpack(config, { dev }) {
52
+ if (dev) {
53
+ config.plugins.push(webpackPlugin());
54
+ }
55
+ return config;
56
+ },
144
57
  };
145
58
  ```
146
59
 
147
- ESM 설정 예시:
60
+ ### Create React App
148
61
 
149
- ```ts
150
- import { babelInjectComponentSource } from "react-code-locator/babel";
62
+ ```js
63
+ // config-overrides.js
64
+ const { webpackPlugin } = require("react-code-locator/webpack");
151
65
 
152
- export default {
153
- plugins: [babelInjectComponentSource],
66
+ module.exports = {
67
+ webpack(config, env) {
68
+ if (env === "development") {
69
+ config.plugins.push(webpackPlugin());
70
+ }
71
+ return config;
72
+ },
154
73
  };
155
74
  ```
156
75
 
157
- JSX 호출부 주입을 끄고 싶으면:
76
+ ### Rollup
158
77
 
159
- ```ts
160
- import { babelInjectComponentSource } from "react-code-locator/babel";
78
+ ```js
79
+ // rollup.config.js
80
+ import { rollupPlugin } from "react-code-locator";
161
81
 
162
82
  export default {
163
- plugins: [[babelInjectComponentSource, { injectJsxSource: false }]],
83
+ plugins: [rollupPlugin()],
164
84
  };
165
85
  ```
166
86
 
167
- ### `react-code-locator/webpack`
168
-
169
- Webpack 설정에 Babel 플러그인과 런타임 엔트리를 함께 주입합니다.
87
+ ### esbuild
170
88
 
171
89
  ```js
172
- const { withReactComponentJump } = require("react-code-locator/webpack");
173
- const config = createExistingWebpackConfig();
90
+ import { esbuildPlugin } from "react-code-locator";
174
91
 
175
- module.exports = withReactComponentJump(config, {
176
- env: process.env.NODE_ENV,
92
+ await esbuild.build({
93
+ plugins: [esbuildPlugin()],
177
94
  });
178
95
  ```
179
96
 
180
- 동작 방식:
181
-
182
- - `env !== "development"`이면 원본 config를 그대로 반환
183
- - `babel-loader`를 찾아 `babelInjectComponentSource`를 추가
184
- - 엔트리 앞에 런타임 스크립트를 prepend
185
-
186
- 전제:
187
-
188
- - React 앱이 Babel을 통해 트랜스파일되어야 합니다.
189
- - `module.rules` 안에 `babel-loader`가 있어야 자동 주입이 동작합니다.
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
-
213
- ### `react-code-locator/unplugin` ⭐ New
214
-
215
- **unplugin** 기반 통합 어댑터입니다. Vite, Webpack, Rollup, esbuild, Rspack 모두 지원하며, **Babel 없이** acorn 기반으로 동작합니다.
216
-
217
- ```ts
218
- // vite.config.ts
219
- import { defineConfig } from "vite";
220
- import react from "@vitejs/plugin-react";
221
- import { vitePlugin as reactCodeLocator } from "react-code-locator/unplugin";
222
-
223
- export default defineConfig({
224
- plugins: [
225
- react(),
226
- reactCodeLocator(),
227
- ],
228
- });
229
- ```
97
+ ### Rspack
230
98
 
231
99
  ```js
232
- // webpack.config.js
233
- const { webpackPlugin } = require("react-code-locator/unplugin");
100
+ // rspack.config.js
101
+ const { rspackPlugin } = require("react-code-locator");
234
102
 
235
103
  module.exports = {
236
- plugins: [reactCodeLocator()],
104
+ plugins: [rspackPlugin()],
237
105
  };
238
106
  ```
239
107
 
240
- ```js
241
- // rollup.config.js
242
- import { rollupPlugin } from "react-code-locator/unplugin";
243
-
244
- export default {
245
- plugins: [reactCodeLocator()],
246
- };
247
- ```
108
+ ## 옵션
248
109
 
249
- 옵션:
110
+ 모든 플러그인이 동일한 옵션을 공유합니다.
250
111
 
251
112
  ```ts
252
- reactCodeLocator({
253
- projectRoot: process.cwd(), // 프로젝트 루트 경로
113
+ vitePlugin({
114
+ // 소스 transform 옵션
115
+ projectRoot: process.cwd(), // 프로젝트 루트 (상대 경로 기준)
254
116
  injectComponentSource: true, // 컴포넌트 정의에 소스 주입
255
117
  injectJsxSource: true, // JSX 호출부에 소스 주입
256
118
  include: /\.[jt]sx$/, // 포함할 파일 패턴
257
119
  exclude: /node_modules/, // 제외할 파일 패턴
258
- });
259
- ```
260
-
261
- **주의:** unplugin 어댑터를 사용하려면 `acorn`, `astring`, `estree-walker`, `unplugin`을 설치해야 합니다.
262
120
 
263
- ```bash
264
- npm install -D acorn astring estree-walker unplugin
121
+ // Vite 전용 옵션
122
+ injectClient: true, // 클라이언트 런타임 자동 주입 (기본값: true)
123
+ locator: { // 런타임 옵션
124
+ triggerKey: "shift", // 트리거 키 (기본값: "shift")
125
+ },
126
+ });
265
127
  ```
266
128
 
267
- ### `react-code-locator`
129
+ ## 사용
268
130
 
269
- 런타임 유틸만 직접 사용할 때의 기본 엔트리입니다.
131
+ 개발 서버에서 `Shift + Click`하면 브라우저 콘솔에 소스 위치가 출력됩니다.
270
132
 
271
- ```ts
272
- import { enableReactComponentJump, locateComponentSource } from "react-code-locator";
273
133
  ```
274
-
275
- 루트 엔트리는 브라우저 런타임 전용입니다.
276
- 빌드 도구 어댑터는 반드시 각 subpath에서 가져와야 합니다.
277
-
278
- - Babel: `react-code-locator/babel`
279
- - Vite: `react-code-locator/vite`
280
- - esbuild: `react-code-locator/esbuild`
281
- - SWC: `react-code-locator/swc`
282
- - Webpack: `react-code-locator/webpack`
283
-
284
- 제공 API:
285
-
286
- - `enableReactComponentJump(options)`
287
- - `locateComponentSource(target)`
288
-
289
- `locateComponentSource` 반환값:
290
-
291
- ```ts
292
- type LocatorResult = {
293
- source: string;
294
- mode: "direct" | "screen" | "implementation";
295
- };
134
+ [react-code-locator] src/components/Button.tsx:14:1
296
135
  ```
297
136
 
298
- ## 사용 흐름
137
+ 결과를 클릭하면 클립보드에 복사됩니다.
299
138
 
300
- 정상 동작하려면 보통 아래 두 단계가 같이 필요합니다.
139
+ ### 단축키
301
140
 
302
- 1. 빌드 단계에서 source transform으로 소스 메타데이터 주입
303
- 2. 브라우저에서 클릭 이벤트를 가로채 React Fiber를 따라가며 위치 계산
141
+ | | 동작 |
142
+ |----|------|
143
+ | `Shift + Click` | 소스 위치 찾기 |
144
+ | `Alt + 1` | direct 모드 (JSX 호출부 위치) |
145
+ | `Alt + 2` | screen 모드 (화면에 보이는 컴포넌트) |
146
+ | `Alt + 3` | implementation 모드 (구현체 위치) |
304
147
 
305
- Vite/webpack 어댑터를 쓰면 이 둘을 한 번에 붙일 수 있습니다.
148
+ ## 수동 설정 (고급)
306
149
 
307
- ## 개발/배포 스크립트
150
+ Vite가 아닌 환경에서는 클라이언트 런타임을 직접 초기화해야 합니다.
308
151
 
309
- ```bash
310
- npm run build
311
- ```
312
-
313
- - 라이브러리만 `dist/`로 빌드합니다.
152
+ ```ts
153
+ import { enableReactComponentJump } from "react-code-locator/client";
314
154
 
315
- ```bash
316
- npm run deploy --otp=123456
155
+ enableReactComponentJump({
156
+ triggerKey: "shift",
157
+ onLocate(result) {
158
+ console.log("Source:", result.source);
159
+ },
160
+ });
317
161
  ```
318
162
 
319
- - `build`
320
- - `npm pack --dry-run`
321
- - `npm publish --access public`
322
-
323
- 순서로 실행합니다.
324
-
325
- ## peerDependencies
326
-
327
- - `@babel/core >= 7`
328
- - `@vitejs/plugin-react >= 4`
329
-
330
- 둘 다 optional peer dependency입니다.
331
-
332
- - Babel 플러그인을 직접 쓰거나 Vite 어댑터를 쓸 때 필요할 수 있습니다.
333
- - Webpack 런타임만 소비하는 쪽에서는 사용 방식에 따라 일부만 필요할 수 있습니다.
334
-
335
- ## 주의점
163
+ ## 알려진 제한사항
336
164
 
337
- - 개발 모드 전용입니다.
338
- - React 내부 필드인 Fiber와 `_debugSource`에 의존합니다.
339
- - production build에서는 JSX 디버그 정보가 없어질 있습니다.
340
- - 클릭 이벤트를 capture 단계에서 가로채므로, modifier key가 눌리면 기본 클릭 동작이 막힐 수 있습니다.
341
- - `triggerKey: "none"`이면 모든 클릭에서 동작하므로 일반적으로 권장하지 않습니다.
165
+ - **React Native 미지원**: DOM API에 의존합니다.
166
+ - **Turbopack 미지원**: Next.js 13+의 Turbopack은 현재 지원되지 않습니다.
167
+ - **TSX generic arrow function**: `.tsx` 파일에서 `<T,>` 형태의 제네릭 화살표 함수가 있는 파일은 transform이 스킵됩니다. (`function` 선언형이나 `.ts` 파일에서는 정상 동작합니다.)
168
+ - **개발 전용**: `NODE_ENV=development` 환경에서만 사용하세요.
342
169
 
343
- ## 주요 파일
170
+ ## License
344
171
 
345
- - `src/runtime.ts`: 클릭 이벤트 처리와 React Fiber 기반 소스 탐색
346
- - `src/babelInjectComponentSource.ts`: Babel 메타데이터 주입
347
- - `src/vite.ts`: Vite 어댑터 export
348
- - `src/webpack.cts`: Webpack 어댑터 export
349
- - `src/client.ts`: 브라우저 런타임 export
172
+ MIT