bippy 0.5.31 → 0.5.33

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 (41) hide show
  1. package/README.md +58 -69
  2. package/dist/core.cjs +1 -1
  3. package/dist/{core-DrsBZAHE.d.cts → core.d.cts} +6 -5
  4. package/dist/{core-iTvy1nnO.d.ts → core.d.ts} +6 -5
  5. package/dist/core.js +1 -1
  6. package/dist/core2.d.cts +2 -0
  7. package/dist/core2.d.ts +2 -0
  8. package/dist/index.cjs +1 -1
  9. package/dist/index.d.cts +2 -0
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.iife.js +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/install-hook-only.cjs +1 -1
  14. package/dist/install-hook-only.d.ts +1 -0
  15. package/dist/install-hook-only.iife.js +1 -1
  16. package/dist/install-hook-only.js +1 -1
  17. package/dist/{rdt-hook-aNC2TnWN.cjs → rdt-hook.cjs} +1 -1
  18. package/dist/{rdt-hook-mw-MaKML.js → rdt-hook.js} +1 -1
  19. package/dist/source.cjs +12 -12
  20. package/dist/{source-I78uyO4y.d.cts → source.d.cts} +4 -2
  21. package/dist/{source-Dn2Y4PQ3.d.ts → source.d.ts} +4 -2
  22. package/dist/source.js +13 -13
  23. package/package.json +35 -36
  24. package/src/core.ts +91 -194
  25. package/src/index.ts +2 -2
  26. package/src/install-hook-only.ts +1 -1
  27. package/src/rdt-hook.ts +19 -27
  28. package/src/source/constants.ts +13 -14
  29. package/src/source/get-display-name-from-source.ts +10 -20
  30. package/src/source/get-source.ts +26 -31
  31. package/src/source/index.ts +6 -6
  32. package/src/source/owner-stack.ts +83 -127
  33. package/src/source/parse-stack.ts +46 -92
  34. package/src/source/symbolication.ts +19 -54
  35. package/src/types.ts +18 -43
  36. package/dist/core-Dr9ohkJa.d.cts +0 -2
  37. package/dist/core-DtN0NYk0.d.ts +0 -2
  38. package/dist/index-Dm1YWrOH.d.cts +0 -2
  39. package/dist/index-dqaF-imC.d.ts +0 -2
  40. package/dist/install-hook-only-zg3J3t1-.d.cts +0 -1
  41. /package/dist/{install-hook-only-DLjveWKt.d.ts → install-hook-only.d.cts} +0 -0
package/src/rdt-hook.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  // without this, we can't stub the React DevTools global hook, we don't have a way to instrument the application
4
4
  // make sure you import this file first before anything else (particularly React)
5
5
 
6
- import type { ReactDevToolsGlobalHook, ReactRenderer } from './types.js';
6
+ import type { ReactDevToolsGlobalHook, ReactRenderer } from "./types.js";
7
7
 
8
8
  export const version = process.env.VERSION;
9
9
  export const BIPPY_INSTRUMENTATION_STRING = `bippy-${version}`;
@@ -19,13 +19,13 @@ const NO_OP = () => {
19
19
  const checkDCE = (fn: unknown): void => {
20
20
  try {
21
21
  const code = Function.prototype.toString.call(fn);
22
- if (code.indexOf('^_^') > -1) {
22
+ if (code.indexOf("^_^") > -1) {
23
23
  setTimeout(() => {
24
24
  throw new Error(
25
- 'React is running in production mode, but dead code ' +
26
- 'elimination has not been applied. Read how to correctly ' +
27
- 'configure React for production: ' +
28
- 'https://reactjs.org/link/perf-use-production-build',
25
+ "React is running in production mode, but dead code " +
26
+ "elimination has not been applied. Read how to correctly " +
27
+ "configure React for production: " +
28
+ "https://reactjs.org/link/perf-use-production-build",
29
29
  );
30
30
  });
31
31
  }
@@ -35,7 +35,7 @@ const checkDCE = (fn: unknown): void => {
35
35
  export const isRealReactDevtools = (
36
36
  rdtHook: ReactDevToolsGlobalHook | undefined | null = globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__,
37
37
  ): boolean => {
38
- return Boolean(rdtHook && 'getFiberRoots' in rdtHook);
38
+ return Boolean(rdtHook && "getFiberRoots" in rdtHook);
39
39
  };
40
40
 
41
41
  let isReactRefreshOverride = false;
@@ -45,20 +45,18 @@ export const isReactRefresh = (
45
45
  rdtHook: ReactDevToolsGlobalHook | undefined | null = globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__,
46
46
  ): boolean => {
47
47
  if (isReactRefreshOverride) return true;
48
- if (rdtHook && typeof rdtHook.inject === 'function') {
48
+ if (rdtHook && typeof rdtHook.inject === "function") {
49
49
  injectFnStr = rdtHook.inject.toString();
50
50
  }
51
51
  // https://github.com/facebook/react/blob/8f8b336734d7c807f5aa11b0f31540e63302d789/packages/react-refresh/src/ReactFreshRuntime.js#L459
52
- return Boolean(injectFnStr?.includes('(injected)'));
52
+ return Boolean(injectFnStr?.includes("(injected)"));
53
53
  };
54
54
 
55
55
  const onActiveListeners = new Set<() => unknown>();
56
56
 
57
57
  export const _renderers = new Set<ReactRenderer>();
58
58
 
59
- export const installRDTHook = (
60
- onActive?: () => unknown,
61
- ): ReactDevToolsGlobalHook => {
59
+ export const installRDTHook = (onActive?: () => unknown): ReactDevToolsGlobalHook => {
62
60
  const renderers = new Map<number, ReactRenderer>();
63
61
  let i = 0;
64
62
  let rdtHook: ReactDevToolsGlobalHook = {
@@ -85,14 +83,14 @@ export const installRDTHook = (
85
83
  supportsFlight: true,
86
84
  };
87
85
  try {
88
- objectDefineProperty(globalThis, '__REACT_DEVTOOLS_GLOBAL_HOOK__', {
86
+ objectDefineProperty(globalThis, "__REACT_DEVTOOLS_GLOBAL_HOOK__", {
89
87
  configurable: true,
90
88
  enumerable: true,
91
89
  get() {
92
90
  return rdtHook;
93
91
  },
94
92
  set(newHook) {
95
- if (newHook && typeof newHook === 'object') {
93
+ if (newHook && typeof newHook === "object") {
96
94
  const ourRenderers = rdtHook.renderers;
97
95
  rdtHook = newHook;
98
96
  if (ourRenderers.size > 0) {
@@ -111,11 +109,11 @@ export const installRDTHook = (
111
109
  // eslint-disable-next-line @typescript-eslint/unbound-method
112
110
  const originalWindowHasOwnProperty = window.hasOwnProperty;
113
111
  let hasRanHack = false;
114
- objectDefineProperty(window, 'hasOwnProperty', {
112
+ objectDefineProperty(window, "hasOwnProperty", {
115
113
  configurable: true,
116
114
  value: function (this: unknown, ...args: [PropertyKey]) {
117
115
  try {
118
- if (!hasRanHack && args[0] === '__REACT_DEVTOOLS_GLOBAL_HOOK__') {
116
+ if (!hasRanHack && args[0] === "__REACT_DEVTOOLS_GLOBAL_HOOK__") {
119
117
  globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__ = undefined;
120
118
  // special falsy value to know that we've already installed before
121
119
  hasRanHack = true;
@@ -194,18 +192,13 @@ export const patchRDTHook = (onActive?: () => unknown): void => {
194
192
  };
195
193
 
196
194
  export const hasRDTHook = (): boolean => {
197
- return objectHasOwnProperty.call(
198
- globalThis,
199
- '__REACT_DEVTOOLS_GLOBAL_HOOK__',
200
- );
195
+ return objectHasOwnProperty.call(globalThis, "__REACT_DEVTOOLS_GLOBAL_HOOK__");
201
196
  };
202
197
 
203
198
  /**
204
199
  * Returns the current React DevTools global hook.
205
200
  */
206
- export const getRDTHook = (
207
- onActive?: () => unknown,
208
- ): ReactDevToolsGlobalHook => {
201
+ export const getRDTHook = (onActive?: () => unknown): ReactDevToolsGlobalHook => {
209
202
  if (!hasRDTHook()) {
210
203
  return installRDTHook(onActive);
211
204
  }
@@ -217,10 +210,9 @@ export const getRDTHook = (
217
210
 
218
211
  export const isClientEnvironment = (): boolean => {
219
212
  return Boolean(
220
- typeof window !== 'undefined' &&
221
- // eslint-disable-next-line @typescript-eslint/unbound-method
222
- (window.document?.createElement ||
223
- window.navigator?.product === 'ReactNative'),
213
+ typeof window !== "undefined" &&
214
+ // eslint-disable-next-line @typescript-eslint/unbound-method
215
+ (window.document?.createElement || window.navigator?.product === "ReactNative"),
224
216
  );
225
217
  };
226
218
 
@@ -1,27 +1,26 @@
1
1
  export const SCHEME_REGEX = /^[a-zA-Z][a-zA-Z\d+\-.]*:/;
2
2
 
3
3
  export const INTERNAL_SCHEME_PREFIXES = [
4
- 'rsc://',
5
- 'file:///',
6
- 'webpack://',
7
- 'webpack-internal://',
8
- 'node:',
9
- 'turbopack://',
10
- 'metro://',
11
- '/app-pages-browser/',
12
- '/(app-pages-browser)/',
4
+ "rsc://",
5
+ "file:///",
6
+ "webpack://",
7
+ "webpack-internal://",
8
+ "node:",
9
+ "turbopack://",
10
+ "metro://",
11
+ "/app-pages-browser/",
12
+ "/(app-pages-browser)/",
13
13
  ] as const;
14
14
 
15
- export const ABOUT_REACT_PREFIX = 'about://React/';
15
+ export const ABOUT_REACT_PREFIX = "about://React/";
16
16
 
17
- export const ANONYMOUS_FILE_PATTERNS = ['<anonymous>', 'eval', ''] as const;
17
+ export const ANONYMOUS_FILE_PATTERNS = ["<anonymous>", "eval", ""] as const;
18
18
 
19
19
  export const SOURCE_FILE_EXTENSION_REGEX = /\.(jsx|tsx|ts|js)$/;
20
20
 
21
21
  export const BUNDLED_FILE_PATTERN_REGEX =
22
22
  /(\.min|bundle|chunk|vendor|vendors|runtime|polyfill|polyfills)\.(js|mjs|cjs)$|(chunk|bundle|vendor|vendors|runtime|polyfill|polyfills|framework|app|main|index)[-_.][A-Za-z0-9_-]{4,}\.(js|mjs|cjs)$|[\da-f]{8,}\.(js|mjs|cjs)$|[-_.][\da-f]{20,}\.(js|mjs|cjs)$|\/dist\/|\/build\/|\/.next\/|\/out\/|\/node_modules\/|\.webpack\.|\.vite\.|\.turbopack\./i;
23
23
 
24
- export const QUERY_PARAMETER_PATTERN_REGEX =
25
- /^\?[\w~.-]+(?:=[^&#]*)?(?:&[\w~.-]+(?:=[^&#]*)?)*$/;
24
+ export const QUERY_PARAMETER_PATTERN_REGEX = /^\?[\w~.-]+(?:=[^&#]*)?(?:&[\w~.-]+(?:=[^&#]*)?)*$/;
26
25
 
27
- export const SERVER_FRAME_MARKER = '(at Server)';
26
+ export const SERVER_FRAME_MARKER = "(at Server)";
@@ -1,14 +1,14 @@
1
- import { Fiber } from '../types.js';
2
- import { getDisplayName } from '../core.js';
3
- import { getOwnerStack } from './owner-stack.js';
4
- import { getSourceFromSourceMap, getSourceMap } from './symbolication.js';
5
- import { StackFrame } from './parse-stack.js';
1
+ import { Fiber } from "../types.js";
2
+ import { getDisplayName } from "../core.js";
3
+ import { getOwnerStack } from "./owner-stack.js";
4
+ import { getSourceFromSourceMap, getSourceMap } from "./symbolication.js";
5
+ import { StackFrame } from "./parse-stack.js";
6
6
 
7
7
  const extractComponentNameFromSource = (
8
8
  sourceContent: string,
9
9
  lineNumber: number,
10
10
  ): string | null => {
11
- const lines = sourceContent.split('\n');
11
+ const lines = sourceContent.split("\n");
12
12
  const targetLineIndex = lineNumber - 1;
13
13
 
14
14
  if (targetLineIndex < 0 || targetLineIndex >= lines.length) {
@@ -17,7 +17,7 @@ const extractComponentNameFromSource = (
17
17
 
18
18
  const startLine = Math.max(0, targetLineIndex - 5);
19
19
  const endLine = Math.min(lines.length, targetLineIndex + 5);
20
- const contextLines = lines.slice(startLine, endLine).join('\n');
20
+ const contextLines = lines.slice(startLine, endLine).join("\n");
21
21
 
22
22
  const arrowFunctionPattern = /(?:^|export\s+)(?:const|let|var)\s+(\w+)\s*=/m;
23
23
  const functionPattern = /(?:^|export\s+)function\s+(\w+)/m;
@@ -53,11 +53,7 @@ export const getDisplayNameFromSource = async (
53
53
  return getDisplayName(fiber.type);
54
54
  }
55
55
 
56
- const bundleSourceMap = await getSourceMap(
57
- stackFrame.fileName,
58
- cache,
59
- fetchFn,
60
- );
56
+ const bundleSourceMap = await getSourceMap(stackFrame.fileName, cache, fetchFn);
61
57
 
62
58
  if (!bundleSourceMap) {
63
59
  return getDisplayName(fiber.type);
@@ -65,10 +61,7 @@ export const getDisplayNameFromSource = async (
65
61
 
66
62
  let source: StackFrame | null = null;
67
63
 
68
- if (
69
- typeof stackFrame.lineNumber === 'number' &&
70
- typeof stackFrame.columnNumber === 'number'
71
- ) {
64
+ if (typeof stackFrame.lineNumber === "number" && typeof stackFrame.columnNumber === "number") {
72
65
  source = getSourceFromSourceMap(
73
66
  bundleSourceMap,
74
67
  stackFrame.lineNumber,
@@ -90,10 +83,7 @@ export const getDisplayNameFromSource = async (
90
83
  }
91
84
 
92
85
  const sourceContent = bundleSourceMap.sourcesContent[sourceIndex];
93
- const extractedName = extractComponentNameFromSource(
94
- sourceContent,
95
- source.lineNumber,
96
- );
86
+ const extractedName = extractComponentNameFromSource(sourceContent, source.lineNumber);
97
87
 
98
88
  if (extractedName) {
99
89
  return extractedName;
@@ -1,6 +1,6 @@
1
- import { Fiber } from '../types.js';
1
+ import { Fiber } from "../types.js";
2
2
 
3
- import { FiberSource } from './types.js';
3
+ import { FiberSource } from "./types.js";
4
4
  import {
5
5
  SCHEME_REGEX,
6
6
  INTERNAL_SCHEME_PREFIXES,
@@ -9,25 +9,25 @@ import {
9
9
  SOURCE_FILE_EXTENSION_REGEX,
10
10
  BUNDLED_FILE_PATTERN_REGEX,
11
11
  QUERY_PARAMETER_PATTERN_REGEX,
12
- } from './constants.js';
13
- import { getOwnerStack } from './owner-stack.js';
12
+ } from "./constants.js";
13
+ import { getOwnerStack } from "./owner-stack.js";
14
14
 
15
15
  export const hasDebugSource = (
16
16
  fiber: Fiber,
17
17
  ): fiber is Fiber & {
18
- _debugSource: NonNullable<Fiber['_debugSource']>;
18
+ _debugSource: NonNullable<Fiber["_debugSource"]>;
19
19
  } => {
20
20
  const debugSource = fiber._debugSource;
21
21
  if (!debugSource) {
22
22
  return false;
23
23
  }
24
24
  return (
25
- typeof debugSource === 'object' &&
25
+ typeof debugSource === "object" &&
26
26
  debugSource !== null &&
27
- 'fileName' in debugSource &&
28
- typeof debugSource.fileName === 'string' &&
29
- 'lineNumber' in debugSource &&
30
- typeof debugSource.lineNumber === 'number'
27
+ "fileName" in debugSource &&
28
+ typeof debugSource.fileName === "string" &&
29
+ "lineNumber" in debugSource &&
30
+ typeof debugSource.lineNumber === "number"
31
31
  );
32
32
  };
33
33
 
@@ -74,16 +74,15 @@ export const getSource = async (
74
74
  return null;
75
75
  };
76
76
 
77
- const getPathSegmentCount = (path: string): number =>
78
- path.split('/').filter(Boolean).length;
77
+ const getPathSegmentCount = (path: string): number => path.split("/").filter(Boolean).length;
79
78
 
80
79
  const getFirstPathSegment = (path: string): string | null => {
81
- const segments = path.split('/').filter(Boolean);
80
+ const segments = path.split("/").filter(Boolean);
82
81
  return segments[0] ?? null;
83
82
  };
84
83
 
85
84
  const stripSingleBasePathPrefix = (path: string): string => {
86
- const firstSlashIndex = path.indexOf('/', 1);
85
+ const firstSlashIndex = path.indexOf("/", 1);
87
86
  if (firstSlashIndex === -1) {
88
87
  return path;
89
88
  }
@@ -107,7 +106,7 @@ const stripSingleBasePathPrefix = (path: string): string => {
107
106
  return path;
108
107
  }
109
108
 
110
- if (firstRemainderSegment.startsWith('@')) {
109
+ if (firstRemainderSegment.startsWith("@")) {
111
110
  return path;
112
111
  }
113
112
 
@@ -120,18 +119,17 @@ const stripSingleBasePathPrefix = (path: string): string => {
120
119
 
121
120
  export const normalizeFileName = (fileName: string): string => {
122
121
  if (!fileName) {
123
- return '';
122
+ return "";
124
123
  }
125
124
 
126
125
  if (ANONYMOUS_FILE_PATTERNS.some((pattern) => pattern === fileName)) {
127
- return '';
126
+ return "";
128
127
  }
129
128
 
130
129
  let normalizedFileName = fileName;
131
130
 
132
131
  const isHttpUrl =
133
- normalizedFileName.startsWith('http://') ||
134
- normalizedFileName.startsWith('https://');
132
+ normalizedFileName.startsWith("http://") || normalizedFileName.startsWith("https://");
135
133
  if (isHttpUrl) {
136
134
  try {
137
135
  const parsedUrl = new URL(normalizedFileName);
@@ -145,8 +143,8 @@ export const normalizeFileName = (fileName: string): string => {
145
143
 
146
144
  if (normalizedFileName.startsWith(ABOUT_REACT_PREFIX)) {
147
145
  const remainder = normalizedFileName.slice(ABOUT_REACT_PREFIX.length);
148
- const slashIndex = remainder.indexOf('/');
149
- const colonIndex = remainder.indexOf(':');
146
+ const slashIndex = remainder.indexOf("/");
147
+ const colonIndex = remainder.indexOf(":");
150
148
 
151
149
  if (slashIndex !== -1 && (colonIndex === -1 || slashIndex < colonIndex)) {
152
150
  normalizedFileName = remainder.slice(slashIndex + 1);
@@ -162,8 +160,8 @@ export const normalizeFileName = (fileName: string): string => {
162
160
  if (normalizedFileName.startsWith(prefix)) {
163
161
  normalizedFileName = normalizedFileName.slice(prefix.length);
164
162
 
165
- if (prefix === 'file:///') {
166
- normalizedFileName = `/${normalizedFileName.replace(/^\/+/, '')}`;
163
+ if (prefix === "file:///") {
164
+ normalizedFileName = `/${normalizedFileName.replace(/^\/+/, "")}`;
167
165
  }
168
166
 
169
167
  didStripPrefix = true;
@@ -179,18 +177,15 @@ export const normalizeFileName = (fileName: string): string => {
179
177
  }
180
178
  }
181
179
 
182
- if (normalizedFileName.startsWith('//')) {
183
- const firstPathSlashIndex = normalizedFileName.indexOf('/', 2);
180
+ if (normalizedFileName.startsWith("//")) {
181
+ const firstPathSlashIndex = normalizedFileName.indexOf("/", 2);
184
182
  normalizedFileName =
185
- firstPathSlashIndex === -1
186
- ? ''
187
- : normalizedFileName.slice(firstPathSlashIndex);
183
+ firstPathSlashIndex === -1 ? "" : normalizedFileName.slice(firstPathSlashIndex);
188
184
  }
189
185
 
190
- const queryParameterIndex = normalizedFileName.indexOf('?');
186
+ const queryParameterIndex = normalizedFileName.indexOf("?");
191
187
  if (queryParameterIndex !== -1) {
192
- const potentialQueryParameters =
193
- normalizedFileName.slice(queryParameterIndex);
188
+ const potentialQueryParameters = normalizedFileName.slice(queryParameterIndex);
194
189
  if (QUERY_PARAMETER_PATTERN_REGEX.test(potentialQueryParameters)) {
195
190
  normalizedFileName = normalizedFileName.slice(0, queryParameterIndex);
196
191
  }
@@ -1,6 +1,6 @@
1
- export * from './owner-stack.js';
2
- export * from './get-source.js';
3
- export * from './symbolication.js';
4
- export * from './types.js';
5
- export * from './parse-stack.js';
6
- export * from './get-display-name-from-source.js';
1
+ export * from "./owner-stack.js";
2
+ export * from "./get-source.js";
3
+ export * from "./symbolication.js";
4
+ export * from "./types.js";
5
+ export * from "./parse-stack.js";
6
+ export * from "./get-display-name-from-source.js";