@autotracer/plugin-babel-react18 1.0.0-alpha.52

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 (3) hide show
  1. package/README.md +127 -0
  2. package/dist/index.js +49287 -0
  3. package/package.json +41 -0
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # @autotracer/plugin-babel-react18
2
+
3
+ ## Overview
4
+
5
+ `@autotracer/plugin-babel-react18` is the AutoTracer build-time plugin for React apps that already compile through Babel, including Next.js, Create React App, and custom Babel-based setups. It injects `useReactTracer()` and hook labeling during compilation so runtime traces stay readable without hand-editing your components.
6
+
7
+ ## Why Use It
8
+
9
+ This package gives Babel-based apps automatic component and hook labeling without taking over runtime startup. The plugin owns build-time injection only, while your app bootstrap still decides when tracing starts, whether the Dashboard is mounted, and whether tracing stays dormant until you open a narrow capture window.
10
+
11
+ Recommended Babel path: use `@autotracer/plugin-babel-react18` for build-time injection, initialize `reactTracer()` before your client entry renders, and mount `@autotracer/dashboard` yourself when you want the standard browser control workflow in restricted internal builds. When the Dashboard is not mounted, use the lower-level `globalThis.autoTracer` runtime control surface.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pnpm add @autotracer/react18
17
+ pnpm add -D @autotracer/plugin-babel-react18
18
+ ```
19
+
20
+ If this internal browser app uses the Dashboard as its normal control surface, add it separately:
21
+
22
+ ```bash
23
+ pnpm add -D @autotracer/dashboard
24
+ ```
25
+
26
+ ## Configuration
27
+
28
+ Add the plugin to your Babel configuration:
29
+
30
+ ```json
31
+ {
32
+ "plugins": [
33
+ [
34
+ "@autotracer/plugin-babel-react18",
35
+ {
36
+ "mode": "opt-out"
37
+ }
38
+ ]
39
+ ]
40
+ }
41
+ ```
42
+
43
+ To keep tracing out of publicly accessible production builds on the Babel path, exclude the plugin from the production Babel config itself:
44
+
45
+ ```js
46
+ const shouldTrace =
47
+ process.env.NODE_ENV === "development" ||
48
+ process.env.INTERNAL_QA === "true";
49
+
50
+ module.exports = {
51
+ plugins: [
52
+ ...(shouldTrace
53
+ ? [
54
+ [
55
+ "@autotracer/plugin-babel-react18",
56
+ {
57
+ mode: "opt-out",
58
+ },
59
+ ],
60
+ ]
61
+ : []),
62
+ ],
63
+ };
64
+ ```
65
+
66
+ On the Babel path, runtime gating alone is not enough. If the plugin stays enabled in a production build, Babel still injects `useReactTracer()` and hook labeling into compiled components.
67
+
68
+ Use these documentation pages for exact option behavior:
69
+
70
+ - React integration path: https://docs.autotracer.dev/guide/config-react
71
+ - Babel plugin settings: https://docs.autotracer.dev/reference/build/react18/babel/
72
+ - Babel pragma comments: https://docs.autotracer.dev/reference/build/react18/babel/pragmas
73
+ - Runtime settings: https://docs.autotracer.dev/reference/runtime/react18/
74
+ - Runtime API: https://docs.autotracer.dev/api/react18
75
+ - Dashboard workflow: https://docs.autotracer.dev/dashboard/webapps
76
+
77
+ Theme customization stays on the runtime side through `reactTracer({ colors })`. File-based theme loading is available only on the Vite plugin path through https://docs.autotracer.dev/themes/react18/api.
78
+
79
+ Keep this plugin out of publicly accessible builds. The intended use case is development and restricted internal test or QA environments.
80
+
81
+ ## Usage
82
+
83
+ Add the plugin in Babel, then initialize the runtime separately before your client entry renders:
84
+
85
+ ```tsx
86
+ const shouldTrace =
87
+ process.env.NODE_ENV === "development" ||
88
+ process.env.NEXT_PUBLIC_INTERNAL_QA === "true";
89
+
90
+ async function bootstrap(): Promise<void> {
91
+ if (shouldTrace) {
92
+ const { reactTracer, isReactTracerInitialized } =
93
+ await import("@autotracer/react18");
94
+
95
+ if (!isReactTracerInitialized()) {
96
+ reactTracer({
97
+ enabled: false,
98
+ });
99
+ }
100
+ }
101
+ }
102
+
103
+ void bootstrap();
104
+ ```
105
+
106
+ Use the same environment decision for both the Babel plugin and the runtime bootstrap so internal builds get tracing and publicly accessible builds get neither injection nor runtime startup.
107
+
108
+ Use the guide that matches your actual entry path when you need full bootstrap examples:
109
+
110
+ - Next.js Pages Router: https://docs.autotracer.dev/guide/installation-react-nextjs-pages
111
+ - Next.js App Router: https://docs.autotracer.dev/guide/installation-react-nextjs-app
112
+ - Create React App: https://docs.autotracer.dev/guide/installation-react-cra
113
+
114
+ Use pragma comments when you want component-level control inside eligible files:
115
+
116
+ ```tsx
117
+ // @trace
118
+ export function Counter() {
119
+ return <button>Count</button>;
120
+ }
121
+ ```
122
+
123
+ In browser-based internal web apps, the normal control surface is the Dashboard. On this Babel path, you mount it yourself. When the Dashboard is not mounted, use the lower-level `globalThis.autoTracer.reactTracer` API in tests, automation, and other non-Dashboard setups.
124
+
125
+ ## License
126
+
127
+ MIT © Carl Ribbegårdh