react-code-locator 0.1.17 → 0.1.18
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/README.md +54 -279
- package/dist/index.cjs +7132 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7126 -15
- package/dist/index.js.map +1 -1
- package/dist/unplugin.cjs +5 -2
- package/dist/unplugin.cjs.map +1 -1
- package/dist/unplugin.d.cts +3 -1
- package/dist/unplugin.d.ts +3 -1
- package/dist/unplugin.js +3 -1
- package/dist/unplugin.js.map +1 -1
- package/package.json +3 -38
- package/dist/core/transform-cjs.cjs +0 -7014
- package/dist/core/webpackPitchLoader-cjs.cjs +0 -7032
- package/dist/webpack.cjs +0 -92
- package/dist/webpack.cjs.map +0 -1
- package/dist/webpack.d.cts +0 -56
- package/dist/webpack.d.ts +0 -56
- package/dist/webpack.js +0 -62
- package/dist/webpack.js.map +0 -1
- package/dist/webpackLoader.cjs +0 -7115
- package/dist/webpackLoader.cjs.map +0 -1
- package/dist/webpackLoader.d.cts +0 -15
- package/dist/webpackLoader.d.ts +0 -15
- package/dist/webpackLoader.js +0 -7092
- package/dist/webpackLoader.js.map +0 -1
- package/dist/webpackRuntimeEntry.cjs +0 -375
- package/dist/webpackRuntimeEntry.cjs.map +0 -1
- package/dist/webpackRuntimeEntry.d.cts +0 -2
- package/dist/webpackRuntimeEntry.d.ts +0 -2
- package/dist/webpackRuntimeEntry.js +0 -373
- package/dist/webpackRuntimeEntry.js.map +0 -1
package/README.md
CHANGED
|
@@ -3,253 +3,72 @@
|
|
|
3
3
|
개발 중인 React 앱에서 요소를 `Shift + Click`하면 해당 UI와 연결된 소스 위치를 찾는 패키지입니다.
|
|
4
4
|
|
|
5
5
|
- React element 생성 시 source metadata를 붙이고, 브라우저 런타임에서 Fiber를 따라 위치를 계산합니다.
|
|
6
|
-
-
|
|
7
|
-
-
|
|
6
|
+
- **Zero Dependency**: Babel 없이 acorn 기반으로 동작합니다.
|
|
7
|
+
- **Universal**: 하나의 패키지로 Vite, Webpack, Rollup, esbuild 모두 지원합니다.
|
|
8
8
|
|
|
9
9
|
## 설치
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
npm i -D react-code-locator
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
로컬 패키지로 연결할 때는:
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npm i -D /absolute/path/to/react-code-locator
|
|
12
|
+
npm i -D react-code-locator unplugin
|
|
19
13
|
```
|
|
20
14
|
|
|
21
15
|
## 빠른 시작
|
|
22
16
|
|
|
23
|
-
Vite
|
|
17
|
+
### Vite
|
|
24
18
|
|
|
25
19
|
```ts
|
|
26
20
|
import { defineConfig } from "vite";
|
|
27
21
|
import react from "@vitejs/plugin-react";
|
|
28
|
-
import {
|
|
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
|
-
## 제공 엔트리
|
|
48
|
-
|
|
49
|
-
### `react-code-locator/vite`
|
|
50
|
-
|
|
51
|
-
Vite + React 프로젝트용 기본 진입점입니다.
|
|
52
|
-
|
|
53
|
-
- source transform 플러그인과 브라우저 클라이언트 주입 플러그인을 함께 제공합니다.
|
|
54
|
-
- HTML에는 bare import를 직접 넣지 않고 Vite 가상 모듈을 통해 클라이언트를 로드합니다.
|
|
55
|
-
- 기본값으로 브라우저 클라이언트도 자동 주입합니다.
|
|
22
|
+
import { vitePlugin } from "react-code-locator";
|
|
56
23
|
|
|
57
|
-
|
|
58
|
-
import { defineConfig } from "vite";
|
|
59
|
-
import react from "@vitejs/plugin-react";
|
|
60
|
-
import { createViteSourceAdapter } from "react-code-locator/vite";
|
|
61
|
-
|
|
62
|
-
export default defineConfig(({ command }) => ({
|
|
24
|
+
export default defineConfig({
|
|
63
25
|
plugins: [
|
|
64
26
|
react(),
|
|
65
|
-
|
|
66
|
-
command,
|
|
67
|
-
locator: { triggerKey: "shift" },
|
|
68
|
-
injectClient: true,
|
|
69
|
-
}).config.plugins,
|
|
27
|
+
vitePlugin(),
|
|
70
28
|
],
|
|
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
29
|
});
|
|
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
30
|
```
|
|
128
31
|
|
|
129
|
-
###
|
|
130
|
-
|
|
131
|
-
Babel 플러그인만 따로 사용할 때 사용합니다.
|
|
132
|
-
|
|
133
|
-
이 플러그인은 기본적으로 두 가지를 주입합니다.
|
|
134
|
-
|
|
135
|
-
- 커스텀 React 컴포넌트 JSX 호출부에 `$componentSourceLoc`
|
|
136
|
-
- React 컴포넌트 함수/클래스에 `__componentSourceLoc`
|
|
137
|
-
- intrinsic DOM JSX는 prop이 아니라 숨겨진 registry metadata로 추적합니다.
|
|
32
|
+
### Webpack (CRA 등)
|
|
138
33
|
|
|
139
34
|
```js
|
|
140
|
-
|
|
35
|
+
// config-overrides.js
|
|
36
|
+
const { webpackPlugin } = require('react-code-locator');
|
|
141
37
|
|
|
142
38
|
module.exports = {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
```ts
|
|
150
|
-
import { babelInjectComponentSource } from "react-code-locator/babel";
|
|
151
|
-
|
|
152
|
-
export default {
|
|
153
|
-
plugins: [babelInjectComponentSource],
|
|
39
|
+
webpack: function(config, env) {
|
|
40
|
+
if (env === 'development') {
|
|
41
|
+
config.plugins.push(webpackPlugin());
|
|
42
|
+
}
|
|
43
|
+
return config;
|
|
44
|
+
}
|
|
154
45
|
};
|
|
155
46
|
```
|
|
156
47
|
|
|
157
|
-
|
|
48
|
+
### Rollup
|
|
158
49
|
|
|
159
|
-
```
|
|
160
|
-
import {
|
|
50
|
+
```js
|
|
51
|
+
import { rollupPlugin } from 'react-code-locator';
|
|
161
52
|
|
|
162
53
|
export default {
|
|
163
|
-
plugins: [
|
|
54
|
+
plugins: [rollupPlugin()]
|
|
164
55
|
};
|
|
165
56
|
```
|
|
166
57
|
|
|
167
|
-
###
|
|
168
|
-
|
|
169
|
-
Webpack 설정에 Babel 플러그인과 런타임 엔트리를 함께 주입합니다.
|
|
58
|
+
### esbuild
|
|
170
59
|
|
|
171
60
|
```js
|
|
172
|
-
|
|
173
|
-
const config = createExistingWebpackConfig();
|
|
174
|
-
|
|
175
|
-
module.exports = withReactComponentJump(config, {
|
|
176
|
-
env: process.env.NODE_ENV,
|
|
177
|
-
});
|
|
178
|
-
```
|
|
61
|
+
import { esbuildPlugin } from 'react-code-locator';
|
|
179
62
|
|
|
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
|
-
],
|
|
63
|
+
const result = await esbuild.build({
|
|
64
|
+
plugins: [esbuildPlugin()]
|
|
228
65
|
});
|
|
229
66
|
```
|
|
230
67
|
|
|
231
|
-
|
|
232
|
-
// webpack.config.js
|
|
233
|
-
const { webpackPlugin } = require("react-code-locator/unplugin");
|
|
234
|
-
|
|
235
|
-
module.exports = {
|
|
236
|
-
plugins: [reactCodeLocator()],
|
|
237
|
-
};
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
```js
|
|
241
|
-
// rollup.config.js
|
|
242
|
-
import { rollupPlugin } from "react-code-locator/unplugin";
|
|
243
|
-
|
|
244
|
-
export default {
|
|
245
|
-
plugins: [reactCodeLocator()],
|
|
246
|
-
};
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
옵션:
|
|
68
|
+
## 옵션
|
|
250
69
|
|
|
251
70
|
```ts
|
|
252
|
-
|
|
71
|
+
vitePlugin({
|
|
253
72
|
projectRoot: process.cwd(), // 프로젝트 루트 경로
|
|
254
73
|
injectComponentSource: true, // 컴포넌트 정의에 소스 주입
|
|
255
74
|
injectJsxSource: true, // JSX 호출부에 소스 주입
|
|
@@ -258,92 +77,48 @@ reactCodeLocator({
|
|
|
258
77
|
});
|
|
259
78
|
```
|
|
260
79
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
```bash
|
|
264
|
-
npm install -D acorn astring estree-walker unplugin
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
### `react-code-locator`
|
|
268
|
-
|
|
269
|
-
런타임 유틸만 직접 사용할 때의 기본 엔트리입니다.
|
|
270
|
-
|
|
271
|
-
```ts
|
|
272
|
-
import { enableReactComponentJump, locateComponentSource } from "react-code-locator";
|
|
273
|
-
```
|
|
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)`
|
|
80
|
+
## 사용
|
|
288
81
|
|
|
289
|
-
`
|
|
82
|
+
개발 서버에서 `Shift + Click`하면 브라우저 콘솔에 소스 위치가 출력됩니다.
|
|
290
83
|
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
source: string;
|
|
294
|
-
mode: "direct" | "screen" | "implementation";
|
|
295
|
-
};
|
|
84
|
+
```text
|
|
85
|
+
[react-code-locator] src/components/Button.tsx:14:1
|
|
296
86
|
```
|
|
297
87
|
|
|
298
|
-
|
|
88
|
+
### 단축키
|
|
299
89
|
|
|
300
|
-
|
|
90
|
+
- `Shift + Click`: 소스 위치 찾기
|
|
91
|
+
- `Alt + 1`: direct 모드 (JSX 호출부)
|
|
92
|
+
- `Alt + 2`: screen 모드 (화면 컴포넌트)
|
|
93
|
+
- `Alt + 3`: implementation 모드 (구현체)
|
|
301
94
|
|
|
302
|
-
|
|
303
|
-
2. 브라우저에서 클릭 이벤트를 가로채 React Fiber를 따라가며 위치 계산
|
|
95
|
+
### 클릭 복사
|
|
304
96
|
|
|
305
|
-
|
|
97
|
+
결과를 클릭하면 클립보드에 복사됩니다.
|
|
306
98
|
|
|
307
|
-
##
|
|
99
|
+
## 수동 주입 (고급)
|
|
308
100
|
|
|
309
|
-
|
|
310
|
-
npm run build
|
|
311
|
-
```
|
|
101
|
+
자동 주입을 사용하지 않고 직접 런타임을 초기화하려면:
|
|
312
102
|
|
|
313
|
-
|
|
103
|
+
```ts
|
|
104
|
+
import { enableReactComponentJump } from "react-code-locator/client";
|
|
314
105
|
|
|
315
|
-
|
|
316
|
-
|
|
106
|
+
if (import.meta.env.DEV) {
|
|
107
|
+
enableReactComponentJump({
|
|
108
|
+
triggerKey: "shift",
|
|
109
|
+
onLocate(result) {
|
|
110
|
+
console.log("Source:", result.source);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
317
114
|
```
|
|
318
115
|
|
|
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
116
|
## 주의점
|
|
336
117
|
|
|
337
|
-
-
|
|
338
|
-
- React
|
|
339
|
-
- production build에서는
|
|
340
|
-
- 클릭 이벤트를 capture 단계에서 가로채므로, modifier key가 눌리면 기본 클릭 동작이 막힐 수 있습니다.
|
|
341
|
-
- `triggerKey: "none"`이면 모든 클릭에서 동작하므로 일반적으로 권장하지 않습니다.
|
|
118
|
+
- **개발 모드 전용**입니다.
|
|
119
|
+
- React 낵부 필드인 Fiber와 `_debugSource`에 의존합니다.
|
|
120
|
+
- production build에서는 동작하지 않습니다.
|
|
342
121
|
|
|
343
|
-
##
|
|
122
|
+
## License
|
|
344
123
|
|
|
345
|
-
|
|
346
|
-
- `src/babelInjectComponentSource.ts`: Babel 메타데이터 주입
|
|
347
|
-
- `src/vite.ts`: Vite 어댑터 export
|
|
348
|
-
- `src/webpack.cts`: Webpack 어댑터 export
|
|
349
|
-
- `src/client.ts`: 브라우저 런타임 export
|
|
124
|
+
MIT
|