@domscribe/react 0.1.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.
- package/adapter/react-adapter.d.ts +121 -0
- package/adapter/react-adapter.d.ts.map +1 -0
- package/adapter/react-adapter.js +486 -0
- package/adapter/types.d.ts +131 -0
- package/adapter/types.d.ts.map +1 -0
- package/adapter/types.js +17 -0
- package/auto-init.d.ts +2 -0
- package/auto-init.d.ts.map +1 -0
- package/auto-init.js +40 -0
- package/component/component-name-resolver.d.ts +118 -0
- package/component/component-name-resolver.d.ts.map +1 -0
- package/component/component-name-resolver.js +361 -0
- package/component/props-extractor.d.ts +51 -0
- package/component/props-extractor.d.ts.map +1 -0
- package/component/props-extractor.js +122 -0
- package/component/state-extractor.d.ts +60 -0
- package/component/state-extractor.d.ts.map +1 -0
- package/component/state-extractor.js +162 -0
- package/component/types.d.ts +256 -0
- package/component/types.d.ts.map +1 -0
- package/component/types.js +5 -0
- package/errors/index.d.ts +36 -0
- package/errors/index.d.ts.map +1 -0
- package/errors/index.js +75 -0
- package/fiber/fiber-walker.d.ts +58 -0
- package/fiber/fiber-walker.d.ts.map +1 -0
- package/fiber/fiber-walker.js +118 -0
- package/fiber/types.d.ts +162 -0
- package/fiber/types.d.ts.map +1 -0
- package/fiber/types.js +32 -0
- package/index.d.ts +14 -0
- package/index.d.ts.map +1 -0
- package/index.js +15 -0
- package/package.json +59 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/utils/constants.d.ts +94 -0
- package/utils/constants.d.ts.map +1 -0
- package/utils/constants.js +123 -0
- package/utils/type-guards.d.ts +31 -0
- package/utils/type-guards.d.ts.map +1 -0
- package/utils/type-guards.js +89 -0
- package/utils/types.d.ts +6 -0
- package/utils/types.d.ts.map +1 -0
- package/utils/types.js +5 -0
- package/vite/index.d.ts +7 -0
- package/vite/index.d.ts.map +1 -0
- package/vite/index.js +5 -0
- package/vite/types.d.ts +56 -0
- package/vite/types.d.ts.map +1 -0
- package/vite/types.js +10 -0
- package/vite/vite-plugin.d.ts +29 -0
- package/vite/vite-plugin.d.ts.map +1 -0
- package/vite/vite-plugin.js +104 -0
- package/webpack/index.d.ts +7 -0
- package/webpack/index.d.ts.map +1 -0
- package/webpack/index.js +5 -0
- package/webpack/webpack-plugin.d.ts +50 -0
- package/webpack/webpack-plugin.d.ts.map +1 -0
- package/webpack/webpack-plugin.js +63 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../packages/domscribe-react/src/utils/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BnB,CAAC;AAEX;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,aAU/B,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,UAoB/B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe;IAC1B;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;CAEK,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;CAKrB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,iBAAiB,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React constants and magic numbers
|
|
3
|
+
* @module @domscribe/react/utils/constants
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* React Fiber tags
|
|
7
|
+
*
|
|
8
|
+
* These are internal constants used by React to identify different types of Fiber nodes.
|
|
9
|
+
* Based on React's ReactWorkTags.js (values may vary slightly across React versions)
|
|
10
|
+
*
|
|
11
|
+
* @see https://github.com/facebook/react/blob/main/packages/react-reconciler/src/ReactWorkTags.js
|
|
12
|
+
*/
|
|
13
|
+
export const REACT_FIBER_TAGS = {
|
|
14
|
+
FunctionComponent: 0,
|
|
15
|
+
ClassComponent: 1,
|
|
16
|
+
IndeterminateComponent: 2, // Before we know whether it's function or class
|
|
17
|
+
HostRoot: 3,
|
|
18
|
+
HostPortal: 4,
|
|
19
|
+
HostComponent: 5, // DOM element (div, span, etc.)
|
|
20
|
+
HostText: 6, // Text node
|
|
21
|
+
Fragment: 7,
|
|
22
|
+
Mode: 8,
|
|
23
|
+
ContextConsumer: 9,
|
|
24
|
+
ContextProvider: 10,
|
|
25
|
+
ForwardRef: 11,
|
|
26
|
+
Profiler: 12,
|
|
27
|
+
SuspenseComponent: 13,
|
|
28
|
+
MemoComponent: 14,
|
|
29
|
+
SimpleMemoComponent: 15,
|
|
30
|
+
LazyComponent: 16,
|
|
31
|
+
IncompleteClassComponent: 17,
|
|
32
|
+
DehydratedFragment: 18,
|
|
33
|
+
SuspenseListComponent: 19,
|
|
34
|
+
ScopeComponent: 21,
|
|
35
|
+
OffscreenComponent: 22,
|
|
36
|
+
LegacyHiddenComponent: 23,
|
|
37
|
+
CacheComponent: 24,
|
|
38
|
+
TracingMarkerComponent: 25,
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* React internal props to exclude from capture
|
|
42
|
+
*
|
|
43
|
+
* These props are internal to React and should not be included in captured props
|
|
44
|
+
*/
|
|
45
|
+
export const REACT_INTERNAL_PROPS = new Set([
|
|
46
|
+
'children',
|
|
47
|
+
'key',
|
|
48
|
+
'ref',
|
|
49
|
+
'__self',
|
|
50
|
+
'__source',
|
|
51
|
+
'__owner',
|
|
52
|
+
'_owner',
|
|
53
|
+
'_store',
|
|
54
|
+
'$$typeof',
|
|
55
|
+
]);
|
|
56
|
+
/**
|
|
57
|
+
* Common HOC (Higher Order Component) patterns
|
|
58
|
+
*
|
|
59
|
+
* Used to detect and unwrap HOC wrappers to find the underlying component
|
|
60
|
+
*/
|
|
61
|
+
export const COMMON_HOC_PATTERNS = [
|
|
62
|
+
'withRouter',
|
|
63
|
+
'withStyles',
|
|
64
|
+
'withTheme',
|
|
65
|
+
'connect', // Redux
|
|
66
|
+
'observer', // MobX
|
|
67
|
+
'inject', // MobX
|
|
68
|
+
'withAuth',
|
|
69
|
+
'withData',
|
|
70
|
+
'withApollo', // Apollo
|
|
71
|
+
'graphql', // Apollo
|
|
72
|
+
'withTracker', // Meteor
|
|
73
|
+
'pure', // Recompose
|
|
74
|
+
'withProps', // Recompose
|
|
75
|
+
'withState', // Recompose
|
|
76
|
+
'withHandlers', // Recompose
|
|
77
|
+
'lifecycle', // Recompose
|
|
78
|
+
'branch', // Recompose
|
|
79
|
+
'renderComponent', // Recompose
|
|
80
|
+
'renderNothing', // Recompose
|
|
81
|
+
];
|
|
82
|
+
/**
|
|
83
|
+
* Default options for various operations
|
|
84
|
+
*/
|
|
85
|
+
export const DEFAULT_OPTIONS = {
|
|
86
|
+
/**
|
|
87
|
+
* Default maximum tree depth
|
|
88
|
+
*/
|
|
89
|
+
MAX_TREE_DEPTH: 50,
|
|
90
|
+
/**
|
|
91
|
+
* Default maximum hooks to parse
|
|
92
|
+
*/
|
|
93
|
+
MAX_HOOKS: 100,
|
|
94
|
+
/**
|
|
95
|
+
* Default maximum wrapper depth
|
|
96
|
+
*/
|
|
97
|
+
MAX_WRAPPER_DEPTH: 3,
|
|
98
|
+
/**
|
|
99
|
+
* Default capture strategy
|
|
100
|
+
*/
|
|
101
|
+
CAPTURE_STRATEGY: 'best-effort',
|
|
102
|
+
/**
|
|
103
|
+
* Default fallback component name
|
|
104
|
+
*/
|
|
105
|
+
FALLBACK_COMPONENT_NAME: 'Anonymous',
|
|
106
|
+
/**
|
|
107
|
+
* Default hook name prefix
|
|
108
|
+
*/
|
|
109
|
+
HOOK_NAME_PREFIX: 'hook_',
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* React element keys (different across React versions)
|
|
113
|
+
*/
|
|
114
|
+
export const REACT_ELEMENT_KEYS = {
|
|
115
|
+
FIBER_16: '__reactInternalInstance',
|
|
116
|
+
FIBER_17_18: '__reactFiber',
|
|
117
|
+
PROPS_16: '__reactEventHandlers',
|
|
118
|
+
PROPS_17_18: '__reactProps',
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* DevTools global hook key
|
|
122
|
+
*/
|
|
123
|
+
export const DEVTOOLS_HOOK_KEY = '__REACT_DEVTOOLS_GLOBAL_HOOK__';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard functions for React structures
|
|
3
|
+
* @module @domscribe/react/utils/type-guards
|
|
4
|
+
*/
|
|
5
|
+
import type { ExtendedReactFiber } from '../fiber/types.js';
|
|
6
|
+
import type { ReactDevToolsHook, ReactDevToolsRenderer, ReactDevToolsRendererInterface } from '../adapter/types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Check if a value is a React Fiber node
|
|
9
|
+
*/
|
|
10
|
+
export declare function isReactFiber(value: unknown): value is ExtendedReactFiber;
|
|
11
|
+
/**
|
|
12
|
+
* Check if a Fiber node is a component fiber (user or HOC)
|
|
13
|
+
*/
|
|
14
|
+
export declare function isComponentFiber(fiber: ExtendedReactFiber): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Check if an element has React Fiber keys
|
|
17
|
+
*/
|
|
18
|
+
export declare function hasReactFiberKey(element: HTMLElement): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Check if a value is a React DevTools global hook
|
|
21
|
+
*/
|
|
22
|
+
export declare function isReactDevToolsHook(value: unknown): value is ReactDevToolsHook;
|
|
23
|
+
/**
|
|
24
|
+
* Check if a value is a React DevTools renderer entry
|
|
25
|
+
*/
|
|
26
|
+
export declare function isReactDevToolsRenderer(value: unknown): value is ReactDevToolsRenderer;
|
|
27
|
+
/**
|
|
28
|
+
* Check if a value is a React DevTools renderer interface entry
|
|
29
|
+
*/
|
|
30
|
+
export declare function isReactDevToolsRendererInterface(value: unknown): value is ReactDevToolsRendererInterface;
|
|
31
|
+
//# sourceMappingURL=type-guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-guards.d.ts","sourceRoot":"","sources":["../../../../packages/domscribe-react/src/utils/type-guards.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,KAAK,EACV,iBAAiB,EACjB,qBAAqB,EACrB,8BAA8B,EAC/B,MAAM,qBAAqB,CAAC;AAE7B;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB,CAQxE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAQnE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAO9D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,iBAAiB,CAwC5B;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,qBAAqB,CAkBhC;AAED;;GAEG;AACH,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,8BAA8B,CAUzC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard functions for React structures
|
|
3
|
+
* @module @domscribe/react/utils/type-guards
|
|
4
|
+
*/
|
|
5
|
+
import { REACT_FIBER_TAGS, REACT_ELEMENT_KEYS } from './constants.js';
|
|
6
|
+
/**
|
|
7
|
+
* Check if a value is a React Fiber node
|
|
8
|
+
*/
|
|
9
|
+
export function isReactFiber(value) {
|
|
10
|
+
return (typeof value === 'object' &&
|
|
11
|
+
value !== null &&
|
|
12
|
+
'tag' in value &&
|
|
13
|
+
typeof value.tag === 'number' &&
|
|
14
|
+
'memoizedProps' in value);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Check if a Fiber node is a component fiber (user or HOC)
|
|
18
|
+
*/
|
|
19
|
+
export function isComponentFiber(fiber) {
|
|
20
|
+
return (fiber.tag === REACT_FIBER_TAGS.FunctionComponent ||
|
|
21
|
+
fiber.tag === REACT_FIBER_TAGS.ClassComponent ||
|
|
22
|
+
fiber.tag === REACT_FIBER_TAGS.ForwardRef ||
|
|
23
|
+
fiber.tag === REACT_FIBER_TAGS.MemoComponent ||
|
|
24
|
+
fiber.tag === REACT_FIBER_TAGS.SimpleMemoComponent);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Check if an element has React Fiber keys
|
|
28
|
+
*/
|
|
29
|
+
export function hasReactFiberKey(element) {
|
|
30
|
+
const keys = Object.keys(element);
|
|
31
|
+
return keys.some((key) => key.startsWith(REACT_ELEMENT_KEYS.FIBER_16) ||
|
|
32
|
+
key.startsWith(REACT_ELEMENT_KEYS.FIBER_17_18));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Check if a value is a React DevTools global hook
|
|
36
|
+
*/
|
|
37
|
+
export function isReactDevToolsHook(value) {
|
|
38
|
+
if (typeof value !== 'object' || value === null) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
if (!('renderers' in value) ||
|
|
42
|
+
typeof value.renderers !== 'object' ||
|
|
43
|
+
value.renderers === null) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (Object.values(value.renderers).some((renderer) => !isReactDevToolsRenderer(renderer))) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if ('rendererInterfaces' in value) {
|
|
50
|
+
if (typeof value.rendererInterfaces !== 'object' ||
|
|
51
|
+
value.rendererInterfaces === null) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (Object.values(value.rendererInterfaces).some((rendererInterface) => !isReactDevToolsRendererInterface(rendererInterface))) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Check if a value is a React DevTools renderer entry
|
|
62
|
+
*/
|
|
63
|
+
export function isReactDevToolsRenderer(value) {
|
|
64
|
+
if (typeof value !== 'object' || value === null) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (!('findFiberByHostInstance' in value)) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
if (typeof value.findFiberByHostInstance !== 'function') {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if ('version' in value && typeof value.version !== 'string') {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Check if a value is a React DevTools renderer interface entry
|
|
80
|
+
*/
|
|
81
|
+
export function isReactDevToolsRendererInterface(value) {
|
|
82
|
+
if (typeof value !== 'object' || value === null) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
if ('version' in value && typeof value.version !== 'string') {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
89
|
+
}
|
package/utils/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../packages/domscribe-react/src/utils/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,YAAY,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC"}
|
package/utils/types.js
ADDED
package/vite/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite plugin entry point
|
|
3
|
+
* @module @domscribe/react/vite
|
|
4
|
+
*/
|
|
5
|
+
export { domscribe } from './vite-plugin.js';
|
|
6
|
+
export type { DomscribeReactPluginOptions, DomscribeRuntimeOptions, DomscribeReactCaptureOptions, } from './types.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/domscribe-react/src/vite/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,YAAY,EACV,2BAA2B,EAC3B,uBAAuB,EACvB,4BAA4B,GAC7B,MAAM,YAAY,CAAC"}
|
package/vite/index.js
ADDED
package/vite/types.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the React-aware Domscribe Vite plugin.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the base transform plugin options — all options are passed through.
|
|
5
|
+
* Adds `runtime` and `capture` namespaces for configuring runtime behavior
|
|
6
|
+
* and React adapter capture settings.
|
|
7
|
+
*
|
|
8
|
+
* @module @domscribe/react/vite/types
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* RuntimeManager configuration (minus adapter, which is framework-specific).
|
|
12
|
+
*/
|
|
13
|
+
export interface DomscribeRuntimeOptions {
|
|
14
|
+
/** Capture phase. @default 1 */
|
|
15
|
+
phase?: 1 | 2;
|
|
16
|
+
/** Redact PII from captured data. @default true */
|
|
17
|
+
redactPII?: boolean;
|
|
18
|
+
/** CSS selectors to block from capture. @default [] */
|
|
19
|
+
blockSelectors?: string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* React adapter capture configuration.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* `hookNameResolvers` uses plain objects (JSON-serializable) in plugin options.
|
|
26
|
+
* Converted to `Map<string, Map<number, string>>` at runtime.
|
|
27
|
+
*/
|
|
28
|
+
export interface DomscribeReactCaptureOptions {
|
|
29
|
+
/** Capture strategy. @default 'best-effort' */
|
|
30
|
+
strategy?: 'devtools' | 'fiber' | 'best-effort';
|
|
31
|
+
/** Maximum component tree depth. @default 50 */
|
|
32
|
+
maxTreeDepth?: number;
|
|
33
|
+
/** Include wrapper/HOC components. @default true */
|
|
34
|
+
includeWrappers?: boolean;
|
|
35
|
+
/** Hook name resolvers as plain objects. Keys are component names, values map hook index to name. */
|
|
36
|
+
hookNameResolvers?: Record<string, Record<number, string>>;
|
|
37
|
+
}
|
|
38
|
+
export interface DomscribeReactPluginOptions {
|
|
39
|
+
include?: RegExp;
|
|
40
|
+
exclude?: RegExp;
|
|
41
|
+
debug?: boolean;
|
|
42
|
+
relay?: {
|
|
43
|
+
autoStart?: boolean;
|
|
44
|
+
port?: number;
|
|
45
|
+
host?: string;
|
|
46
|
+
};
|
|
47
|
+
overlay?: boolean | {
|
|
48
|
+
initialMode?: 'collapsed' | 'expanded';
|
|
49
|
+
debug?: boolean;
|
|
50
|
+
};
|
|
51
|
+
/** RuntimeManager configuration (phase, PII redaction, block selectors). */
|
|
52
|
+
runtime?: DomscribeRuntimeOptions;
|
|
53
|
+
/** React adapter capture configuration (strategy, tree depth, wrappers, hook resolvers). */
|
|
54
|
+
capture?: DomscribeReactCaptureOptions;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../packages/domscribe-react/src/vite/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,gCAAgC;IAChC,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IACd,mDAAmD;IACnD,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,uDAAuD;IACvD,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,4BAA4B;IAC3C,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,UAAU,GAAG,OAAO,GAAG,aAAa,CAAC;IAChD,gDAAgD;IAChD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,qGAAqG;IACrG,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC5D;AAED,MAAM,WAAW,2BAA2B;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE;QACN,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,OAAO,CAAC,EACJ,OAAO,GACP;QACE,WAAW,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC;QACvC,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB,CAAC;IACN,4EAA4E;IAC5E,OAAO,CAAC,EAAE,uBAAuB,CAAC;IAClC,4FAA4F;IAC5F,OAAO,CAAC,EAAE,4BAA4B,CAAC;CACxC"}
|
package/vite/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the React-aware Domscribe Vite plugin.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the base transform plugin options — all options are passed through.
|
|
5
|
+
* Adds `runtime` and `capture` namespaces for configuring runtime behavior
|
|
6
|
+
* and React adapter capture settings.
|
|
7
|
+
*
|
|
8
|
+
* @module @domscribe/react/vite/types
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React-aware Domscribe Vite plugin
|
|
3
|
+
* @module @domscribe/react/vite/vite-plugin
|
|
4
|
+
*/
|
|
5
|
+
import type { Plugin } from 'vite';
|
|
6
|
+
import type { DomscribeReactPluginOptions } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Domscribe Vite plugin for React projects.
|
|
9
|
+
*
|
|
10
|
+
* Creates the base transform plugin internally and adds RuntimeManager + ReactAdapter
|
|
11
|
+
* initialization via a virtual module. No entrypoint changes needed.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* For framework-agnostic usage (no runtime capture), import `domscribe`
|
|
15
|
+
* from `@domscribe/transform/plugins/vite` directly.
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
* ```ts
|
|
19
|
+
* // vite.config.ts
|
|
20
|
+
* import react from '@vitejs/plugin-react'
|
|
21
|
+
* import { domscribe } from '@domscribe/react/vite'
|
|
22
|
+
*
|
|
23
|
+
* export default defineConfig({
|
|
24
|
+
* plugins: [react(), domscribe({ overlay: true })]
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function domscribe(options?: DomscribeReactPluginOptions): Plugin;
|
|
29
|
+
//# sourceMappingURL=vite-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../../../../packages/domscribe-react/src/vite/vite-plugin.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,MAAM,EAA+C,MAAM,MAAM,CAAC;AAEhF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAgB9D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,2BAA2B,GAAG,MAAM,CAoFvE"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { domscribe as baseDomscribe } from '@domscribe/transform/plugins/vite';
|
|
2
|
+
/**
|
|
3
|
+
* URL path for the virtual init module.
|
|
4
|
+
*
|
|
5
|
+
* When the browser fetches this path, Vite's dev server routes it through
|
|
6
|
+
* the plugin pipeline (resolveId → load → transform). The transform step
|
|
7
|
+
* rewrites bare specifiers (`@domscribe/runtime`, `@domscribe/react`) to
|
|
8
|
+
* pre-bundled paths — the same ones the overlay resolves to internally —
|
|
9
|
+
* so RuntimeManager shares a single singleton across all consumers.
|
|
10
|
+
*
|
|
11
|
+
* Direct `/node_modules/` paths bypass pre-bundling and create separate
|
|
12
|
+
* module instances with separate singletons, which breaks runtime capture.
|
|
13
|
+
*/
|
|
14
|
+
const INIT_MODULE_PATH = '/@domscribe/react-init.js';
|
|
15
|
+
/**
|
|
16
|
+
* Domscribe Vite plugin for React projects.
|
|
17
|
+
*
|
|
18
|
+
* Creates the base transform plugin internally and adds RuntimeManager + ReactAdapter
|
|
19
|
+
* initialization via a virtual module. No entrypoint changes needed.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* For framework-agnostic usage (no runtime capture), import `domscribe`
|
|
23
|
+
* from `@domscribe/transform/plugins/vite` directly.
|
|
24
|
+
*
|
|
25
|
+
* Usage:
|
|
26
|
+
* ```ts
|
|
27
|
+
* // vite.config.ts
|
|
28
|
+
* import react from '@vitejs/plugin-react'
|
|
29
|
+
* import { domscribe } from '@domscribe/react/vite'
|
|
30
|
+
*
|
|
31
|
+
* export default defineConfig({
|
|
32
|
+
* plugins: [react(), domscribe({ overlay: true })]
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function domscribe(options) {
|
|
37
|
+
const basePlugin = baseDomscribe(options);
|
|
38
|
+
const baseTransformIndexHtml = basePlugin.transformIndexHtml;
|
|
39
|
+
const baseResolveId = typeof basePlugin.resolveId === 'function' ? basePlugin.resolveId : null;
|
|
40
|
+
const baseLoad = typeof basePlugin.load === 'function' ? basePlugin.load : null;
|
|
41
|
+
basePlugin.name = 'vite-plugin-domscribe-react';
|
|
42
|
+
basePlugin.resolveId = function (id, ...args) {
|
|
43
|
+
if (id === INIT_MODULE_PATH) {
|
|
44
|
+
return INIT_MODULE_PATH;
|
|
45
|
+
}
|
|
46
|
+
return baseResolveId?.call(this, id, ...args) ?? null;
|
|
47
|
+
};
|
|
48
|
+
basePlugin.load = function (id, ...args) {
|
|
49
|
+
if (id === INIT_MODULE_PATH) {
|
|
50
|
+
const rt = options?.runtime ?? {};
|
|
51
|
+
const cap = options?.capture ?? {};
|
|
52
|
+
const debug = options?.debug ?? false;
|
|
53
|
+
// Build hookNameResolvers reconstruction if provided
|
|
54
|
+
const resolversLine = cap.hookNameResolvers
|
|
55
|
+
? `const _r = ${JSON.stringify(cap.hookNameResolvers)};\n` +
|
|
56
|
+
`const _resolvers = new Map(Object.entries(_r).map(([k,v])=>[k,new Map(Object.entries(v).map(([i,n])=>[Number(i),n]))]));`
|
|
57
|
+
: `const _resolvers = new Map();`;
|
|
58
|
+
// Bare specifiers here get rewritten by Vite's transform pipeline
|
|
59
|
+
// to pre-bundled paths, matching what the overlay resolves internally
|
|
60
|
+
return [
|
|
61
|
+
`import { RuntimeManager } from '@domscribe/runtime';`,
|
|
62
|
+
`import { createReactAdapter } from '@domscribe/react';`,
|
|
63
|
+
``,
|
|
64
|
+
resolversLine,
|
|
65
|
+
``,
|
|
66
|
+
`RuntimeManager.getInstance().initialize({`,
|
|
67
|
+
` phase: ${rt.phase ?? 1},`,
|
|
68
|
+
` debug: ${debug},`,
|
|
69
|
+
` redactPII: ${rt.redactPII ?? true},`,
|
|
70
|
+
` blockSelectors: ${JSON.stringify(rt.blockSelectors ?? [])},`,
|
|
71
|
+
` adapter: createReactAdapter({`,
|
|
72
|
+
` strategy: '${cap.strategy ?? 'best-effort'}',`,
|
|
73
|
+
` maxTreeDepth: ${cap.maxTreeDepth ?? 50},`,
|
|
74
|
+
` includeWrappers: ${cap.includeWrappers ?? true},`,
|
|
75
|
+
` debug: ${debug},`,
|
|
76
|
+
` hookNameResolvers: _resolvers,`,
|
|
77
|
+
` }),`,
|
|
78
|
+
`}).catch(e => console.warn('[domscribe] Failed to init React runtime:', e.message));`,
|
|
79
|
+
].join('\n');
|
|
80
|
+
}
|
|
81
|
+
return baseLoad?.call(this, id, ...args) ?? null;
|
|
82
|
+
};
|
|
83
|
+
basePlugin.transformIndexHtml = () => {
|
|
84
|
+
// Call the base plugin's transformIndexHtml (relay port + overlay injection)
|
|
85
|
+
const baseResult = typeof baseTransformIndexHtml === 'function'
|
|
86
|
+
? baseTransformIndexHtml()
|
|
87
|
+
: undefined;
|
|
88
|
+
// Build on existing tags from the base plugin
|
|
89
|
+
const baseTags = baseResult && typeof baseResult === 'object' && 'tags' in baseResult
|
|
90
|
+
? (baseResult.tags ?? [])
|
|
91
|
+
: [];
|
|
92
|
+
// Import the virtual init module — browser fetches this URL, Vite
|
|
93
|
+
// serves it through its full plugin + transform pipeline
|
|
94
|
+
const runtimeTag = {
|
|
95
|
+
tag: 'script',
|
|
96
|
+
attrs: { type: 'module' },
|
|
97
|
+
children: `import('${INIT_MODULE_PATH}');`,
|
|
98
|
+
injectTo: 'body',
|
|
99
|
+
};
|
|
100
|
+
const tags = [...baseTags, runtimeTag];
|
|
101
|
+
return { html: '', tags };
|
|
102
|
+
};
|
|
103
|
+
return basePlugin;
|
|
104
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/domscribe-react/src/webpack/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,YAAY,EAAE,kCAAkC,EAAE,MAAM,qBAAqB,CAAC"}
|
package/webpack/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React-aware Domscribe webpack plugin
|
|
3
|
+
* @module @domscribe/react/webpack/webpack-plugin
|
|
4
|
+
*/
|
|
5
|
+
import type { Compiler, WebpackPluginInstance } from 'webpack';
|
|
6
|
+
import { type WebpackPluginOptions } from '@domscribe/transform/plugins/webpack';
|
|
7
|
+
import type { DomscribeRuntimeOptions, DomscribeReactCaptureOptions } from '../vite/types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Unified options for the React webpack plugin.
|
|
10
|
+
*
|
|
11
|
+
* Extends the base transform options with `runtime` and `capture` namespaces
|
|
12
|
+
* for configuring RuntimeManager and ReactAdapter behavior.
|
|
13
|
+
*/
|
|
14
|
+
export interface DomscribeReactWebpackPluginOptions extends WebpackPluginOptions {
|
|
15
|
+
/** RuntimeManager configuration (phase, PII redaction, block selectors). */
|
|
16
|
+
runtime?: DomscribeRuntimeOptions;
|
|
17
|
+
/** React adapter capture configuration (strategy, tree depth, wrappers, hook resolvers). */
|
|
18
|
+
capture?: DomscribeReactCaptureOptions;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Domscribe webpack plugin for React projects.
|
|
22
|
+
*
|
|
23
|
+
* Creates the base transform plugin internally and adds `@domscribe/react/auto-init`
|
|
24
|
+
* as a webpack entry so that RuntimeManager + ReactAdapter are initialized
|
|
25
|
+
* automatically — no entrypoint changes needed.
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* For framework-agnostic usage (no runtime capture), import `DomscribeWebpackPlugin`
|
|
29
|
+
* from `@domscribe/transform/plugins/webpack` directly.
|
|
30
|
+
*
|
|
31
|
+
* Usage:
|
|
32
|
+
* ```ts
|
|
33
|
+
* // webpack.config.ts
|
|
34
|
+
* import { DomscribeWebpackPlugin } from '@domscribe/react/webpack'
|
|
35
|
+
*
|
|
36
|
+
* export default {
|
|
37
|
+
* plugins: [new DomscribeWebpackPlugin({ overlay: true })]
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare class DomscribeWebpackPlugin implements WebpackPluginInstance {
|
|
42
|
+
private readonly basePlugin;
|
|
43
|
+
private readonly runtimeOptions;
|
|
44
|
+
private readonly captureOptions;
|
|
45
|
+
private readonly debug;
|
|
46
|
+
constructor(options?: DomscribeReactWebpackPluginOptions);
|
|
47
|
+
apply(compiler: Compiler): void;
|
|
48
|
+
private addAdapterEntry;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=webpack-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webpack-plugin.d.ts","sourceRoot":"","sources":["../../../../packages/domscribe-react/src/webpack/webpack-plugin.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EACV,uBAAuB,EACvB,4BAA4B,EAC7B,MAAM,kBAAkB,CAAC;AAE1B;;;;;GAKG;AACH,MAAM,WAAW,kCAAmC,SAAQ,oBAAoB;IAC9E,4EAA4E;IAC5E,OAAO,CAAC,EAAE,uBAAuB,CAAC;IAClC,4FAA4F;IAC5F,OAAO,CAAC,EAAE,4BAA4B,CAAC;CACxC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,sBAAuB,YAAW,qBAAqB;IAClE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA6B;IACxD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA0B;IACzD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA+B;IAC9D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAU;gBAEpB,OAAO,CAAC,EAAE,kCAAkC;IAOxD,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAqB/B,OAAO,CAAC,eAAe;CAUxB"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { DomscribeWebpackPlugin as BaseDomscribeWebpackPlugin, } from '@domscribe/transform/plugins/webpack';
|
|
2
|
+
/**
|
|
3
|
+
* Domscribe webpack plugin for React projects.
|
|
4
|
+
*
|
|
5
|
+
* Creates the base transform plugin internally and adds `@domscribe/react/auto-init`
|
|
6
|
+
* as a webpack entry so that RuntimeManager + ReactAdapter are initialized
|
|
7
|
+
* automatically — no entrypoint changes needed.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* For framework-agnostic usage (no runtime capture), import `DomscribeWebpackPlugin`
|
|
11
|
+
* from `@domscribe/transform/plugins/webpack` directly.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* ```ts
|
|
15
|
+
* // webpack.config.ts
|
|
16
|
+
* import { DomscribeWebpackPlugin } from '@domscribe/react/webpack'
|
|
17
|
+
*
|
|
18
|
+
* export default {
|
|
19
|
+
* plugins: [new DomscribeWebpackPlugin({ overlay: true })]
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export class DomscribeWebpackPlugin {
|
|
24
|
+
basePlugin;
|
|
25
|
+
runtimeOptions;
|
|
26
|
+
captureOptions;
|
|
27
|
+
debug;
|
|
28
|
+
constructor(options) {
|
|
29
|
+
this.basePlugin = new BaseDomscribeWebpackPlugin(options);
|
|
30
|
+
this.runtimeOptions = options?.runtime ?? {};
|
|
31
|
+
this.captureOptions = options?.capture ?? {};
|
|
32
|
+
this.debug = options?.debug ?? false;
|
|
33
|
+
}
|
|
34
|
+
apply(compiler) {
|
|
35
|
+
const { DefinePlugin } = compiler.webpack;
|
|
36
|
+
new DefinePlugin({
|
|
37
|
+
__DOMSCRIBE_RUNTIME_OPTIONS__: JSON.stringify({
|
|
38
|
+
phase: this.runtimeOptions.phase,
|
|
39
|
+
debug: this.debug,
|
|
40
|
+
redactPII: this.runtimeOptions.redactPII,
|
|
41
|
+
blockSelectors: this.runtimeOptions.blockSelectors,
|
|
42
|
+
}),
|
|
43
|
+
__DOMSCRIBE_ADAPTER_OPTIONS__: JSON.stringify({
|
|
44
|
+
strategy: this.captureOptions.strategy,
|
|
45
|
+
maxTreeDepth: this.captureOptions.maxTreeDepth,
|
|
46
|
+
includeWrappers: this.captureOptions.includeWrappers,
|
|
47
|
+
hookNameResolvers: this.captureOptions.hookNameResolvers,
|
|
48
|
+
debug: this.debug,
|
|
49
|
+
}),
|
|
50
|
+
}).apply(compiler);
|
|
51
|
+
this.addAdapterEntry(compiler);
|
|
52
|
+
this.basePlugin.apply(compiler);
|
|
53
|
+
}
|
|
54
|
+
addAdapterEntry(compiler) {
|
|
55
|
+
const entry = compiler.options.entry;
|
|
56
|
+
if (typeof entry === 'object' && !Array.isArray(entry)) {
|
|
57
|
+
const firstKey = Object.keys(entry)[0];
|
|
58
|
+
if (firstKey && entry[firstKey]?.import) {
|
|
59
|
+
entry[firstKey].import.push('@domscribe/react/auto-init');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|