bippy 0.6.1-dev.61475ed → 0.6.1-dev.a3b3942
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/LICENSE +1 -1
- package/README.md +32 -48
- package/dist/core.cjs +1 -1
- package/dist/core.d.cts +45 -60
- package/dist/core.d.ts +45 -60
- package/dist/core.js +1 -1
- package/dist/core2.cjs +9 -0
- package/dist/core2.d.cts +11 -3
- package/dist/core2.d.ts +11 -3
- package/dist/core2.js +9 -0
- package/dist/errors.d.cts +420 -0
- package/dist/errors.d.ts +420 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.iife.js +1 -1
- package/dist/index.js +1 -1
- package/dist/install-hook-only.cjs +1 -1
- package/dist/install-hook-only.d.cts +9 -1
- package/dist/install-hook-only.d.ts +9 -1
- package/dist/install-hook-only.iife.js +1 -1
- package/dist/install-hook-only.js +1 -1
- package/dist/rdt-hook.cjs +1 -1
- package/dist/rdt-hook.js +1 -1
- package/dist/source.cjs +14 -5
- package/dist/source.d.cts +27 -11
- package/dist/source.d.ts +27 -11
- package/dist/source.js +14 -5
- package/package.json +22 -16
- package/src/core.ts +349 -328
- package/src/errors.ts +34 -0
- package/src/install-hook-only.ts +2 -2
- package/src/rdt-hook.ts +160 -161
- package/src/react-internals/generated/react-work-tags.ts +318 -0
- package/src/react-internals/index.ts +67 -0
- package/src/react-internals/semver.ts +80 -0
- package/src/react-internals/types.ts +197 -0
- package/src/source/constants.ts +1 -1
- package/src/source/error-stack.ts +11 -0
- package/src/source/get-display-name-from-source.ts +32 -25
- package/src/source/get-source.ts +5 -5
- package/src/source/index.ts +9 -1
- package/src/source/inspect-hooks.ts +215 -182
- package/src/source/owner-stack.ts +127 -166
- package/src/source/parse-debug-stack.ts +4 -4
- package/src/source/parse-hook-names.ts +1 -1
- package/src/source/parse-stack.ts +1 -3
- package/src/source/symbolication.ts +490 -90
- package/dist/get-source.cjs +0 -19
- package/dist/get-source.js +0 -19
- package/dist/react-refresh.cjs +0 -9
- package/dist/react-refresh.d.cts +0 -66
- package/dist/react-refresh.d.ts +0 -66
- package/dist/react-refresh.js +0 -9
- package/dist/unsubscribe.d.cts +0 -298
- package/dist/unsubscribe.d.ts +0 -298
- package/src/react-refresh/constants.ts +0 -9
- package/src/react-refresh/detect-hmr-transport.ts +0 -33
- package/src/react-refresh/index.ts +0 -173
- package/src/react-refresh/metro-hmr-transport.ts +0 -188
- package/src/react-refresh/next-webpack-hmr-transport.ts +0 -72
- package/src/react-refresh/normalize-hmr-file-path.ts +0 -24
- package/src/react-refresh/types.ts +0 -7
- package/src/react-refresh/vite-hmr-transport.ts +0 -116
- package/src/types.ts +0 -438
- package/src/unsubscribe.ts +0 -17
|
@@ -1,9 +1,28 @@
|
|
|
1
|
-
import { Fiber } from "../
|
|
1
|
+
import { Fiber } from "../react-internals/index.js";
|
|
2
2
|
import { getDisplayName } from "../core.js";
|
|
3
|
-
import {
|
|
3
|
+
import { getRawParentStack } from "./owner-stack.js";
|
|
4
4
|
import { getSourceFromSourceMap, getSourceMap } from "./symbolication.js";
|
|
5
5
|
import { StackFrame } from "./parse-stack.js";
|
|
6
6
|
|
|
7
|
+
const COMPONENT_DECLARATION_PATTERNS = [
|
|
8
|
+
/(?:^|export\s+)(?:const|let|var)\s+(\w+)\s*=/,
|
|
9
|
+
/(?:^|export\s+)function\s+(\w+)/,
|
|
10
|
+
/(?:^|export\s+)class\s+(\w+)/,
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
const findComponentDeclarationOnLine = (line: string): string | null => {
|
|
14
|
+
for (const pattern of COMPONENT_DECLARATION_PATTERNS) {
|
|
15
|
+
const match = line.match(pattern);
|
|
16
|
+
if (match?.[1]) return match[1];
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const MAX_DECLARATION_LINE_DISTANCE = 5;
|
|
22
|
+
|
|
23
|
+
// the frame points inside the component, so the nearest declaration wins;
|
|
24
|
+
// searching by pattern over the whole window instead would let an adjacent
|
|
25
|
+
// component's declaration shadow the right one
|
|
7
26
|
const extractComponentNameFromSource = (
|
|
8
27
|
sourceContent: string,
|
|
9
28
|
lineNumber: number,
|
|
@@ -15,27 +34,16 @@ const extractComponentNameFromSource = (
|
|
|
15
34
|
return null;
|
|
16
35
|
}
|
|
17
36
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return arrowMatch[1];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const functionMatch = contextLines.match(functionPattern);
|
|
32
|
-
if (functionMatch?.[1]) {
|
|
33
|
-
return functionMatch[1];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const classMatch = contextLines.match(classPattern);
|
|
37
|
-
if (classMatch?.[1]) {
|
|
38
|
-
return classMatch[1];
|
|
37
|
+
for (let lineDistance = 0; lineDistance <= MAX_DECLARATION_LINE_DISTANCE; lineDistance++) {
|
|
38
|
+
const lineIndexes =
|
|
39
|
+
lineDistance === 0
|
|
40
|
+
? [targetLineIndex]
|
|
41
|
+
: [targetLineIndex - lineDistance, targetLineIndex + lineDistance];
|
|
42
|
+
for (const lineIndex of lineIndexes) {
|
|
43
|
+
if (lineIndex < 0 || lineIndex >= lines.length) continue;
|
|
44
|
+
const declarationName = findComponentDeclarationOnLine(lines[lineIndex]);
|
|
45
|
+
if (declarationName) return declarationName;
|
|
46
|
+
}
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
return null;
|
|
@@ -46,8 +54,7 @@ export const getDisplayNameFromSource = async (
|
|
|
46
54
|
cache = true,
|
|
47
55
|
fetchFn?: (url: string) => Promise<Response>,
|
|
48
56
|
): Promise<string | null> => {
|
|
49
|
-
const
|
|
50
|
-
const stackFrame = parentStackFrames.filter((innerFrame) => innerFrame.fileName)[0];
|
|
57
|
+
const stackFrame = getRawParentStack(fiber).find((innerFrame) => innerFrame.fileName);
|
|
51
58
|
|
|
52
59
|
if (!stackFrame?.fileName) {
|
|
53
60
|
return getDisplayName(fiber.type);
|
package/src/source/get-source.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Fiber } from "../
|
|
1
|
+
import type { Fiber } from "../react-internals/index.js";
|
|
2
2
|
|
|
3
|
-
import { FiberSource } from "./types.js";
|
|
3
|
+
import type { FiberSource } from "./types.js";
|
|
4
4
|
import {
|
|
5
5
|
SCHEME_REGEX,
|
|
6
6
|
INTERNAL_SCHEME_PREFIXES,
|
|
@@ -95,8 +95,7 @@ export const getSource = async (
|
|
|
95
95
|
fetchFn?: (url: string) => Promise<Response>,
|
|
96
96
|
): Promise<FiberSource | null> => {
|
|
97
97
|
if (hasDebugSource(fiber)) {
|
|
98
|
-
|
|
99
|
-
return debugSource || null;
|
|
98
|
+
return fiber._debugSource;
|
|
100
99
|
}
|
|
101
100
|
|
|
102
101
|
const debugStackFrame =
|
|
@@ -171,6 +170,7 @@ export const normalizeFileName = (fileName: string): string => {
|
|
|
171
170
|
}
|
|
172
171
|
|
|
173
172
|
let normalizedFileName = fileName;
|
|
173
|
+
const isWindowsDrivePath = /^[a-zA-Z]:[\\/]/.test(normalizedFileName);
|
|
174
174
|
|
|
175
175
|
const isHttpUrl =
|
|
176
176
|
normalizedFileName.startsWith("http://") || normalizedFileName.startsWith("https://");
|
|
@@ -214,7 +214,7 @@ export const normalizeFileName = (fileName: string): string => {
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
if (SCHEME_REGEX.test(normalizedFileName)) {
|
|
217
|
+
if (!isWindowsDrivePath && SCHEME_REGEX.test(normalizedFileName)) {
|
|
218
218
|
const schemeMatch = normalizedFileName.match(SCHEME_REGEX);
|
|
219
219
|
if (schemeMatch) {
|
|
220
220
|
normalizedFileName = normalizedFileName.slice(schemeMatch[0].length);
|
package/src/source/index.ts
CHANGED
|
@@ -6,12 +6,20 @@ export {
|
|
|
6
6
|
symbolicateStack,
|
|
7
7
|
type DecodedSourceMapSection,
|
|
8
8
|
type IndexSourceMap,
|
|
9
|
-
type
|
|
9
|
+
type SourceFetch,
|
|
10
10
|
type SourceMap,
|
|
11
|
+
type SourceMapRequestOptions,
|
|
11
12
|
type StandardSourceMap,
|
|
12
13
|
} from "./symbolication.js";
|
|
13
14
|
export type { FiberSource } from "./types.js";
|
|
14
15
|
export { parseStack, type ParseOptions, type StackFrame } from "./parse-stack.js";
|
|
15
16
|
export { getDisplayNameFromSource } from "./get-display-name-from-source.js";
|
|
17
|
+
export {
|
|
18
|
+
BippyError,
|
|
19
|
+
BippyHookInspectionError,
|
|
20
|
+
BippyHookRenderError,
|
|
21
|
+
BippySourceMapError,
|
|
22
|
+
BippyUnsupportedHookError,
|
|
23
|
+
} from "../errors.js";
|
|
16
24
|
export { getFiberHooks, type HookSource, type HooksNode, type HooksTree } from "./inspect-hooks.js";
|
|
17
25
|
export { parseHookNames, type HookNames } from "./parse-hook-names.js";
|