bippy 0.7.3-dev.ebf9a42 → 0.7.3-dev.fbafc40

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.
@@ -1,26 +1,17 @@
1
- import type { Fiber } from "../react-internals/index.js";
2
- import { getDisplayName } from "../core.js";
1
+ import type { Fiber } from "../react-internals/index";
2
+ import { getDisplayName } from "../core";
3
3
 
4
- import type { FiberSource } from "./types.js";
5
- import {
6
- SCHEME_REGEX,
7
- INTERNAL_SCHEME_PREFIXES,
8
- ABOUT_REACT_PREFIX,
9
- ANONYMOUS_FILE_PATTERNS,
10
- SOURCE_FILE_EXTENSION_REGEX,
11
- BUNDLED_FILE_PATTERN_REGEX,
12
- QUERY_PARAMETER_PATTERN_REGEX,
13
- } from "./constants.js";
14
- import { getDefinitionFrameFromOwnedChild, getParentStack, hasDebugStack } from "./owner-stack.js";
15
- import { parseDebugStack } from "./parse-debug-stack.js";
16
- import { parseStack, type StackFrame } from "./parse-stack.js";
4
+ import type { FiberSource } from "./types";
5
+ import { getDefinitionFrameFromOwnedChild, getParentStack, hasDebugStack } from "./owner-stack";
6
+ import { parseDebugStack } from "./parse-debug-stack";
7
+ import { parseStack, type StackFrame } from "./parse-stack";
17
8
  import {
18
9
  getSourceFromSourceMapByFunctionName,
19
10
  getSourceMap,
20
11
  symbolicateStack,
21
12
  type SourceFetch,
22
13
  type SourceMapRequestOptions,
23
- } from "./symbolication.js";
14
+ } from "./symbolication";
24
15
 
25
16
  export const hasDebugSource = (
26
17
  fiber: Fiber,
@@ -165,130 +156,4 @@ export const getSource = async (
165
156
  return getSourceByComponentName(fiber, shouldUseCache, sourceFetch, requestOptions);
166
157
  };
167
158
 
168
- const getPathSegmentCount = (path: string): number => path.split("/").filter(Boolean).length;
169
-
170
- const stripSingleBasePathPrefix = (path: string): string => {
171
- const firstSlashIndex = path.indexOf("/", 1);
172
- if (firstSlashIndex === -1) {
173
- return path;
174
- }
175
-
176
- const basePath = path.slice(0, firstSlashIndex);
177
- if (getPathSegmentCount(basePath) !== 1) {
178
- return path;
179
- }
180
-
181
- const remainderPath = path.slice(firstSlashIndex);
182
- if (!SOURCE_FILE_EXTENSION_REGEX.test(remainderPath)) {
183
- return path;
184
- }
185
-
186
- const remainderSegments = remainderPath.split("/").filter(Boolean);
187
- if (remainderSegments.length < 2) {
188
- return path;
189
- }
190
-
191
- const firstRemainderSegment = remainderSegments[0];
192
- if (firstRemainderSegment.startsWith("@")) {
193
- return path;
194
- }
195
-
196
- if (firstRemainderSegment.length > 4) {
197
- return path;
198
- }
199
-
200
- return remainderPath;
201
- };
202
-
203
- export const normalizeFileName = (fileName: string): string => {
204
- if (!fileName) {
205
- return "";
206
- }
207
-
208
- if (ANONYMOUS_FILE_PATTERNS.some((pattern) => pattern === fileName)) {
209
- return "";
210
- }
211
-
212
- let normalizedFileName = fileName;
213
- const isWindowsDrivePath = /^[a-zA-Z]:[\\/]/.test(normalizedFileName);
214
-
215
- const isHttpUrl =
216
- normalizedFileName.startsWith("http://") || normalizedFileName.startsWith("https://");
217
- if (isHttpUrl) {
218
- try {
219
- const parsedUrl = new URL(normalizedFileName);
220
- normalizedFileName = parsedUrl.pathname;
221
- } catch {}
222
- normalizedFileName = stripSingleBasePathPrefix(normalizedFileName);
223
- }
224
-
225
- if (normalizedFileName.startsWith(ABOUT_REACT_PREFIX)) {
226
- const remainder = normalizedFileName.slice(ABOUT_REACT_PREFIX.length);
227
- const slashIndex = remainder.indexOf("/");
228
- const colonIndex = remainder.indexOf(":");
229
-
230
- if (slashIndex !== -1 && (colonIndex === -1 || slashIndex < colonIndex)) {
231
- normalizedFileName = remainder.slice(slashIndex + 1);
232
- } else {
233
- normalizedFileName = remainder;
234
- }
235
- }
236
-
237
- let didStripPrefix = true;
238
- while (didStripPrefix) {
239
- didStripPrefix = false;
240
- for (const prefix of INTERNAL_SCHEME_PREFIXES) {
241
- if (normalizedFileName.startsWith(prefix)) {
242
- normalizedFileName = normalizedFileName.slice(prefix.length);
243
-
244
- if (prefix === "file:///") {
245
- normalizedFileName = `/${normalizedFileName.replace(/^\/+/, "")}`;
246
- }
247
-
248
- didStripPrefix = true;
249
- break;
250
- }
251
- }
252
- }
253
-
254
- if (!isWindowsDrivePath) {
255
- const schemeMatch = normalizedFileName.match(SCHEME_REGEX);
256
- if (schemeMatch) {
257
- normalizedFileName = normalizedFileName.slice(schemeMatch[0].length);
258
- }
259
- }
260
-
261
- if (normalizedFileName.startsWith("//")) {
262
- const firstPathSlashIndex = normalizedFileName.indexOf("/", 2);
263
- normalizedFileName =
264
- firstPathSlashIndex === -1 ? "" : normalizedFileName.slice(firstPathSlashIndex);
265
- }
266
-
267
- const queryParameterIndex = normalizedFileName.indexOf("?");
268
- if (queryParameterIndex !== -1) {
269
- const potentialQueryParameters = normalizedFileName.slice(queryParameterIndex);
270
- if (QUERY_PARAMETER_PATTERN_REGEX.test(potentialQueryParameters)) {
271
- normalizedFileName = normalizedFileName.slice(0, queryParameterIndex);
272
- }
273
- }
274
-
275
- return normalizedFileName;
276
- };
277
-
278
- export const isSourceFile = (fileName: string): boolean => {
279
- const normalizedFileName = normalizeFileName(fileName);
280
-
281
- if (!normalizedFileName) {
282
- return false;
283
- }
284
-
285
- if (!SOURCE_FILE_EXTENSION_REGEX.test(normalizedFileName)) {
286
- return false;
287
- }
288
-
289
- if (BUNDLED_FILE_PATTERN_REGEX.test(normalizedFileName)) {
290
- return false;
291
- }
292
-
293
- return true;
294
- };
159
+ export { isSourceFile, normalizeFileName } from "./normalize-file-name";
@@ -6,8 +6,8 @@ export {
6
6
  getParentStack,
7
7
  getRawOwnerStack,
8
8
  hasDebugStack,
9
- } from "./owner-stack.js";
10
- export { getRawSource, getSource, isSourceFile, normalizeFileName } from "./get-source.js";
9
+ } from "./owner-stack";
10
+ export { getRawSource, getSource, isSourceFile, normalizeFileName } from "./get-source";
11
11
  export {
12
12
  getSourceContentFromSourceMap,
13
13
  getSourceFromSourceMap,
@@ -20,22 +20,22 @@ export {
20
20
  type SourceMap,
21
21
  type SourceMapRequestOptions,
22
22
  type StandardSourceMap,
23
- } from "./symbolication.js";
24
- export type { FiberSource } from "./types.js";
25
- export { parseStack, type ParseOptions, type StackFrame } from "./parse-stack.js";
26
- export { getDisplayNameFromSource } from "./get-display-name-from-source.js";
23
+ } from "./symbolication";
24
+ export type { FiberSource } from "./types";
25
+ export { parseStack, type ParseOptions, type StackFrame } from "./parse-stack";
26
+ export { getDisplayNameFromSource } from "./get-display-name-from-source";
27
27
  export {
28
28
  BippyError,
29
29
  BippyHookInspectionError,
30
30
  BippyHookRenderError,
31
31
  BippySourceMapError,
32
32
  BippyUnsupportedHookError,
33
- } from "../errors.js";
33
+ } from "../errors";
34
34
  export {
35
35
  getFiberHooks,
36
36
  inspectHooks,
37
37
  type HookSource,
38
38
  type HooksNode,
39
39
  type HooksTree,
40
- } from "./inspect-hooks.js";
41
- export { parseHookNames, type HookNames } from "./parse-hook-names.js";
40
+ } from "./inspect-hooks";
41
+ export { parseHookNames, type HookNames } from "./parse-hook-names";
@@ -1,5 +1,5 @@
1
- import { getRenderer } from "../core.js";
2
- import type { ReactDevToolsTarget } from "../rdt-hook.js";
1
+ import { getRenderer } from "../core";
2
+ import type { ReactDevToolsTarget } from "../rdt-hook";
3
3
  import type {
4
4
  Fiber,
5
5
  ContextDependency,
@@ -7,19 +7,15 @@ import type {
7
7
  ReactContext,
8
8
  ReactDebugInfo,
9
9
  RendererDispatcherRef,
10
- } from "../react-internals/index.js";
10
+ } from "../react-internals/index";
11
11
  import {
12
12
  BippyHookInspectionError,
13
13
  BippyHookRenderError,
14
14
  BippyUnsupportedHookError,
15
- } from "../errors.js";
16
- import { getReactWorkTagsForFiber } from "../react-internals/index.js";
17
- import { createStackParser, parseStack, type StackFrame } from "./parse-stack.js";
18
- import {
19
- getRendererDispatcherRefs,
20
- readDispatcher,
21
- writeDispatcher,
22
- } from "./renderer-dispatchers.js";
15
+ } from "../errors";
16
+ import { getReactWorkTagsForFiber } from "../react-internals/index";
17
+ import { createStackParser, parseStack, type StackFrame } from "./parse-stack";
18
+ import { getRendererDispatcherRefs, readDispatcher, writeDispatcher } from "./renderer-dispatchers";
23
19
 
24
20
  const REACT_CONTEXT_TYPE = Symbol.for("react.context");
25
21
  const REACT_MEMO_CACHE_SENTINEL = Symbol.for("react.memo_cache_sentinel");
@@ -0,0 +1,416 @@
1
+ import {
2
+ ABOUT_REACT_PREFIX,
3
+ ANONYMOUS_FILE_PATTERNS,
4
+ BUNDLED_FILE_PATTERN_REGEX,
5
+ INTERNAL_SCHEME_PREFIXES,
6
+ QUERY_PARAMETER_PATTERN_REGEX,
7
+ SCHEME_REGEX,
8
+ SOURCE_FILE_EXTENSION_REGEX,
9
+ } from "./constants";
10
+
11
+ const VITE_FS_PREFIX = "/@fs/";
12
+ const VITE_ID_PREFIX = "/@id/";
13
+ const VITE_NULL_BYTE_PLACEHOLDER = "__x00__";
14
+ const NEXT_WEBPACK_NAMESPACE = "_N_E/";
15
+ const TURBOPACK_PROJECT_TOKEN = "[project]/";
16
+ const WINDOWS_DRIVE_PREFIX = /^[a-zA-Z]:[\\/]/;
17
+ const WINDOWS_DRIVE_SEGMENT = /^[a-zA-Z]:$/;
18
+ const APP_PAGES_BROWSER_PREFIX = /^\/?(?:app-pages-browser|\(app-pages-browser\))\//;
19
+ const NEXT_BUNDLER_LAYER_PREFIX =
20
+ /^\/?\((?:action-browser|api-edge|api-node|edge-asset|instrument|middleware|pages-dir-browser|pages-dir-edge|pages-dir-node|rsc|shared|ssr)\)\//;
21
+ const ENCODED_SEPARATOR = /%(?:2f|5c)/i;
22
+ const WINDOWS_EXTENDED_PATH_PREFIX = "\\\\?\\";
23
+ const REACT_ENVIRONMENT_PREFIX = /^React\/[^/]+\//;
24
+ const TURBOPACK_MAGIC_IDENTIFIER = /__TURBOPACK__[a-zA-Z0-9_$]+__/g;
25
+ const TURBOPACK_MAGIC_IDENTIFIER_EXACT = /^__TURBOPACK__([a-zA-Z0-9_$]+)__$/;
26
+ const IMPORTED_MODULE_PREFIX = "imported module ";
27
+ const BUNDLER_LAYER_SUFFIX =
28
+ /\s\[(?:app-[a-z0-9-]+|action-browser|api-edge|api-node|edge-asset|instrument|middleware|pages-dir-browser|pages-dir-edge|pages-dir-node|rsc|shared|ssr)\]$/;
29
+ const BUNDLER_MODULE_TYPE_SUFFIX =
30
+ /\s\((?:asset|client reference proxy|css(?: client reference| module)?|ecmascript(?: client reference to (?:client|ssr))?|javascript|json|less|mdx|raw|sass|scss|static|typescript|unknown|wasm)\b[^)]*\)$/;
31
+ const BUNDLER_EXPORT_SUFFIX = /\s<(?:exports?|locals|namespace)\b[^>]*>$/;
32
+ const BUNDLER_MODULE_SUFFIXES = [
33
+ BUNDLER_MODULE_TYPE_SUFFIX,
34
+ BUNDLER_LAYER_SUFFIX,
35
+ BUNDLER_EXPORT_SUFFIX,
36
+ ];
37
+
38
+ const isWindowsDrivePath = (filePath: string): boolean => WINDOWS_DRIVE_PREFIX.test(filePath);
39
+
40
+ const VIRTUAL_SCHEME_PREFIXES = ["astro:", "cloudflare:", "nitro:"] as const;
41
+
42
+ const isVirtualModuleId = (filePath: string): boolean =>
43
+ filePath.startsWith("\0") ||
44
+ filePath.startsWith("virtual:") ||
45
+ VIRTUAL_SCHEME_PREFIXES.some((prefix) => filePath.startsWith(prefix));
46
+
47
+ const decodeHex = (hexText: string): string => {
48
+ if (hexText.trim() === "") throw new Error("empty hex");
49
+ const codePoint = Number.parseInt(hexText, 16);
50
+ if (Number.isNaN(codePoint)) throw new Error("invalid hex");
51
+ return String.fromCodePoint(codePoint);
52
+ };
53
+
54
+ const decodeMagicIdentifier = (identifier: string): string => {
55
+ const innerIdentifier = identifier.match(TURBOPACK_MAGIC_IDENTIFIER_EXACT)?.[1];
56
+ if (!innerIdentifier) return identifier;
57
+
58
+ let output = "";
59
+ let mode: "text" | "underscore" | "hex" | "long-hex" = "text";
60
+ let buffer = "";
61
+
62
+ for (const character of innerIdentifier) {
63
+ if (mode === "text") {
64
+ if (character === "_") mode = "underscore";
65
+ else if (character === "$") mode = "hex";
66
+ else output += character;
67
+ continue;
68
+ }
69
+
70
+ if (mode === "underscore") {
71
+ if (character === "_") output += " ";
72
+ else if (character === "$") {
73
+ output += "_";
74
+ mode = "hex";
75
+ continue;
76
+ } else output += character;
77
+ mode = "text";
78
+ continue;
79
+ }
80
+
81
+ if (mode === "hex") {
82
+ if (buffer.length === 2) {
83
+ output += decodeHex(buffer);
84
+ buffer = "";
85
+ }
86
+ if (character === "_") {
87
+ if (buffer !== "") throw new Error("invalid hex");
88
+ mode = "long-hex";
89
+ } else if (character === "$") {
90
+ if (buffer !== "") throw new Error("invalid hex");
91
+ mode = "text";
92
+ } else {
93
+ buffer += character;
94
+ }
95
+ continue;
96
+ }
97
+
98
+ if (character === "_") throw new Error("invalid hex");
99
+ if (character === "$") {
100
+ output += decodeHex(buffer);
101
+ buffer = "";
102
+ mode = "text";
103
+ continue;
104
+ }
105
+ buffer += character;
106
+ }
107
+
108
+ return output;
109
+ };
110
+
111
+ const decodeMagicIdentifiers = (filePath: string): string => {
112
+ if (!filePath.includes("__TURBOPACK__")) return filePath;
113
+ const decodedFilePath = filePath.replace(TURBOPACK_MAGIC_IDENTIFIER, (identifier) => {
114
+ try {
115
+ return decodeMagicIdentifier(identifier);
116
+ } catch {
117
+ return identifier;
118
+ }
119
+ });
120
+ if (!decodedFilePath.startsWith(IMPORTED_MODULE_PREFIX)) return decodedFilePath;
121
+ return decodedFilePath.slice(IMPORTED_MODULE_PREFIX.length);
122
+ };
123
+
124
+ const stripBundlerModuleMetadata = (filePath: string): string => {
125
+ let strippedFilePath = filePath;
126
+ let didStripMetadata = true;
127
+ while (didStripMetadata) {
128
+ didStripMetadata = false;
129
+ for (const suffix of BUNDLER_MODULE_SUFFIXES) {
130
+ const suffixMatch = strippedFilePath.match(suffix);
131
+ if (!suffixMatch?.[0]) continue;
132
+ strippedFilePath = strippedFilePath.slice(0, -suffixMatch[0].length).trimEnd();
133
+ didStripMetadata = true;
134
+ break;
135
+ }
136
+ }
137
+ return strippedFilePath;
138
+ };
139
+
140
+ const stripWebpackLoaders = (filePath: string): string => {
141
+ const separatorIndex = filePath.lastIndexOf("!");
142
+ if (separatorIndex <= 0) return filePath;
143
+ const loaderPath = filePath.slice(0, separatorIndex);
144
+ const resourcePath = filePath.slice(separatorIndex + 1);
145
+ if (!loaderPath.includes("/") && !loaderPath.includes("\\")) return filePath;
146
+ const isResourcePath =
147
+ resourcePath.startsWith("./") ||
148
+ resourcePath.startsWith("../") ||
149
+ resourcePath.startsWith("/") ||
150
+ resourcePath.startsWith("\\") ||
151
+ resourcePath.includes("/") ||
152
+ resourcePath.includes("\\") ||
153
+ isWindowsDrivePath(resourcePath);
154
+ if (!isResourcePath) return filePath;
155
+ return resourcePath;
156
+ };
157
+
158
+ const decodePath = (filePath: string): string => {
159
+ if (!filePath.includes("%")) return filePath;
160
+ return filePath
161
+ .split("/")
162
+ .map((segment) => {
163
+ if (!segment.includes("%") || ENCODED_SEPARATOR.test(segment)) return segment;
164
+ try {
165
+ return decodeURIComponent(segment);
166
+ } catch {
167
+ return segment;
168
+ }
169
+ })
170
+ .join("/");
171
+ };
172
+
173
+ const resolveFileProtocol = (specifier: string): string => {
174
+ const afterScheme = specifier.slice("file://".length);
175
+ const postfixIndex = afterScheme.search(/[?#]/);
176
+ const pathWithHost = postfixIndex === -1 ? afterScheme : afterScheme.slice(0, postfixIndex);
177
+
178
+ let hostname = "";
179
+ let pathname = pathWithHost;
180
+ if (pathWithHost.startsWith("/")) {
181
+ pathname = pathWithHost.replace(/^\/+/, "/");
182
+ } else if (isWindowsDrivePath(pathWithHost)) {
183
+ pathname = pathWithHost;
184
+ } else {
185
+ const slashIndex = pathWithHost.indexOf("/");
186
+ hostname = slashIndex === -1 ? pathWithHost : pathWithHost.slice(0, slashIndex);
187
+ pathname = slashIndex === -1 ? "/" : pathWithHost.slice(slashIndex);
188
+ }
189
+
190
+ if (hostname.toLowerCase() === "localhost") hostname = "";
191
+ if (hostname) {
192
+ return `//${hostname}${pathname.startsWith("/") ? pathname : `/${pathname}`}`;
193
+ }
194
+
195
+ if (pathname.startsWith("/") && isWindowsDrivePath(pathname.slice(1))) {
196
+ return pathname.slice(1);
197
+ }
198
+ if (isWindowsDrivePath(pathname)) return pathname;
199
+ return pathname.startsWith("/") ? pathname : `/${pathname}`;
200
+ };
201
+
202
+ const unwrapViteId = (filePath: string): string => {
203
+ if (filePath.startsWith(VITE_FS_PREFIX)) {
204
+ const absolutePath = filePath.slice(VITE_FS_PREFIX.length);
205
+ if (isWindowsDrivePath(absolutePath)) return absolutePath;
206
+ return absolutePath.startsWith("/") ? absolutePath : `/${absolutePath}`;
207
+ }
208
+
209
+ if (!filePath.startsWith(VITE_ID_PREFIX)) return filePath;
210
+ const unwrappedId = filePath
211
+ .slice(VITE_ID_PREFIX.length)
212
+ .replaceAll(VITE_NULL_BYTE_PLACEHOLDER, "\0");
213
+ if (unwrappedId.startsWith("\0") || unwrappedId.startsWith("virtual:")) return "";
214
+ return unwrappedId;
215
+ };
216
+
217
+ const stripWebpackNamespace = (filePath: string): string => {
218
+ if (filePath.startsWith(NEXT_WEBPACK_NAMESPACE)) {
219
+ return filePath.slice(NEXT_WEBPACK_NAMESPACE.length);
220
+ }
221
+ const slashIndex = filePath.indexOf("/");
222
+ if (slashIndex <= 0) return filePath;
223
+ const remainder = filePath.slice(slashIndex + 1);
224
+ if (remainder.startsWith("./") || remainder.startsWith("../")) return remainder;
225
+ return filePath;
226
+ };
227
+
228
+ const stripBundlerLayer = (filePath: string, didStripBundlerScheme: boolean): string => {
229
+ const appPagesMatch = filePath.match(APP_PAGES_BROWSER_PREFIX);
230
+ if (appPagesMatch?.[0]) return filePath.slice(appPagesMatch[0].length);
231
+ if (!didStripBundlerScheme) return filePath;
232
+ const layerMatch = filePath.match(NEXT_BUNDLER_LAYER_PREFIX);
233
+ if (!layerMatch?.[0]) return filePath;
234
+ return filePath.slice(layerMatch[0].length);
235
+ };
236
+
237
+ const stripUrlPostfix = (filePath: string): string => {
238
+ const hashIndex = filePath.indexOf("#");
239
+ const withoutHash = hashIndex === -1 ? filePath : filePath.slice(0, hashIndex);
240
+ const queryParameterIndex = withoutHash.indexOf("?");
241
+ if (queryParameterIndex === -1) return withoutHash;
242
+ const potentialQueryParameters = withoutHash.slice(queryParameterIndex);
243
+ if (!QUERY_PARAMETER_PATTERN_REGEX.test(potentialQueryParameters)) return withoutHash;
244
+ return withoutHash.slice(0, queryParameterIndex);
245
+ };
246
+
247
+ const normalizeLexicalPath = (filePath: string): string => {
248
+ if (!filePath || filePath.includes("\\")) return filePath;
249
+ const isAbsolute = filePath.startsWith("/");
250
+ const isNetworkPath = filePath.startsWith("//");
251
+ const hasRelativeDotPrefix = filePath.startsWith("./");
252
+ const normalizedSegments: string[] = [];
253
+
254
+ for (const segment of filePath.split("/")) {
255
+ if (segment === "" || segment === ".") continue;
256
+ if (segment === "..") {
257
+ const previousSegment = normalizedSegments[normalizedSegments.length - 1];
258
+ if (
259
+ previousSegment &&
260
+ previousSegment !== ".." &&
261
+ (!isNetworkPath || normalizedSegments.length > 2) &&
262
+ !WINDOWS_DRIVE_SEGMENT.test(previousSegment)
263
+ ) {
264
+ normalizedSegments.pop();
265
+ } else if (!isAbsolute && !WINDOWS_DRIVE_SEGMENT.test(previousSegment ?? "")) {
266
+ normalizedSegments.push("..");
267
+ }
268
+ continue;
269
+ }
270
+ normalizedSegments.push(segment);
271
+ }
272
+
273
+ if (isAbsolute) return `${isNetworkPath ? "//" : "/"}${normalizedSegments.join("/")}`;
274
+ const joinedPath = normalizedSegments.join("/");
275
+ if (!joinedPath) return hasRelativeDotPrefix ? "./" : "";
276
+ if (hasRelativeDotPrefix && !joinedPath.startsWith("../")) return `./${joinedPath}`;
277
+ return joinedPath;
278
+ };
279
+
280
+ export const normalizeFileName = (fileName: string): string => {
281
+ if (!fileName) return "";
282
+ if (ANONYMOUS_FILE_PATTERNS.some((pattern) => pattern === fileName)) return "";
283
+ if (isVirtualModuleId(fileName)) return "";
284
+
285
+ let normalizedFileName = fileName;
286
+ if (normalizedFileName.startsWith(WINDOWS_EXTENDED_PATH_PREFIX)) {
287
+ const extendedPath = normalizedFileName.slice(WINDOWS_EXTENDED_PATH_PREFIX.length);
288
+ if (isWindowsDrivePath(extendedPath)) normalizedFileName = extendedPath;
289
+ }
290
+ normalizedFileName = decodeMagicIdentifiers(normalizedFileName);
291
+ if (isVirtualModuleId(normalizedFileName)) return "";
292
+
293
+ let didStripWebpackScheme = false;
294
+ let didStripBundlerScheme = false;
295
+ let didStripRscScheme = false;
296
+ let didResolveFileProtocol = false;
297
+
298
+ const isHttpUrl =
299
+ normalizedFileName.startsWith("http://") || normalizedFileName.startsWith("https://");
300
+ if (isHttpUrl) {
301
+ try {
302
+ normalizedFileName = new URL(normalizedFileName).pathname;
303
+ } catch {}
304
+ normalizedFileName = stripSingleBasePathPrefix(normalizedFileName);
305
+ }
306
+
307
+ if (normalizedFileName.startsWith(ABOUT_REACT_PREFIX)) {
308
+ const remainder = normalizedFileName.slice(ABOUT_REACT_PREFIX.length);
309
+ const slashIndex = remainder.indexOf("/");
310
+ const colonIndex = remainder.indexOf(":");
311
+ normalizedFileName =
312
+ slashIndex !== -1 && (colonIndex === -1 || slashIndex < colonIndex)
313
+ ? remainder.slice(slashIndex + 1)
314
+ : remainder;
315
+ }
316
+
317
+ let didStripPrefix = true;
318
+ while (didStripPrefix) {
319
+ didStripPrefix = false;
320
+ if (normalizedFileName.startsWith("file://")) {
321
+ const resolvedFilePath = resolveFileProtocol(normalizedFileName);
322
+ if (resolvedFilePath === normalizedFileName) break;
323
+ normalizedFileName = resolvedFilePath;
324
+ didResolveFileProtocol = true;
325
+ didStripPrefix = true;
326
+ continue;
327
+ }
328
+ if (didStripRscScheme) {
329
+ const reactEnvironmentMatch = normalizedFileName.match(REACT_ENVIRONMENT_PREFIX);
330
+ if (reactEnvironmentMatch?.[0]) {
331
+ normalizedFileName = normalizedFileName.slice(reactEnvironmentMatch[0].length);
332
+ didStripRscScheme = false;
333
+ didStripPrefix = true;
334
+ continue;
335
+ }
336
+ }
337
+ for (const prefix of INTERNAL_SCHEME_PREFIXES) {
338
+ if (!normalizedFileName.startsWith(prefix)) continue;
339
+ if (prefix === "rsc://") didStripRscScheme = true;
340
+ if (prefix === "webpack://" || prefix === "rspack://") didStripWebpackScheme = true;
341
+ if (
342
+ prefix === "webpack://" ||
343
+ prefix === "webpack-internal://" ||
344
+ prefix === "rspack://" ||
345
+ prefix === "rspack-internal://" ||
346
+ prefix === "turbopack://"
347
+ ) {
348
+ didStripBundlerScheme = true;
349
+ }
350
+ normalizedFileName = normalizedFileName.slice(prefix.length);
351
+ didStripPrefix = true;
352
+ break;
353
+ }
354
+ }
355
+
356
+ if (isVirtualModuleId(normalizedFileName)) return "";
357
+
358
+ if (!isWindowsDrivePath(normalizedFileName)) {
359
+ const schemeMatch = normalizedFileName.match(SCHEME_REGEX);
360
+ if (schemeMatch) normalizedFileName = normalizedFileName.slice(schemeMatch[0].length);
361
+ }
362
+
363
+ if (!didResolveFileProtocol && normalizedFileName.startsWith("//")) {
364
+ const firstPathSlashIndex = normalizedFileName.indexOf("/", 2);
365
+ normalizedFileName =
366
+ firstPathSlashIndex === -1 ? "" : normalizedFileName.slice(firstPathSlashIndex);
367
+ }
368
+
369
+ normalizedFileName = unwrapViteId(normalizedFileName);
370
+ if (didStripWebpackScheme) normalizedFileName = stripWebpackNamespace(normalizedFileName);
371
+ normalizedFileName = stripBundlerLayer(normalizedFileName, didStripBundlerScheme);
372
+ if (normalizedFileName.startsWith(TURBOPACK_PROJECT_TOKEN)) {
373
+ normalizedFileName = `./${normalizedFileName.slice(TURBOPACK_PROJECT_TOKEN.length)}`;
374
+ } else if (normalizedFileName.startsWith(`/${TURBOPACK_PROJECT_TOKEN}`)) {
375
+ normalizedFileName = normalizedFileName.slice(TURBOPACK_PROJECT_TOKEN.length);
376
+ }
377
+ normalizedFileName = stripBundlerModuleMetadata(normalizedFileName);
378
+ const resourcePath = stripWebpackLoaders(normalizedFileName);
379
+ if (resourcePath !== normalizedFileName) return normalizeFileName(resourcePath);
380
+ normalizedFileName = stripUrlPostfix(normalizedFileName);
381
+ normalizedFileName = decodePath(normalizedFileName);
382
+ normalizedFileName = normalizeLexicalPath(normalizedFileName);
383
+ if (isVirtualModuleId(normalizedFileName)) return "";
384
+ return normalizedFileName;
385
+ };
386
+
387
+ const getPathSegmentCount = (path: string): number => path.split("/").filter(Boolean).length;
388
+
389
+ const stripSingleBasePathPrefix = (path: string): string => {
390
+ const firstSlashIndex = path.indexOf("/", 1);
391
+ if (firstSlashIndex === -1) return path;
392
+
393
+ const basePath = path.slice(0, firstSlashIndex);
394
+ if (getPathSegmentCount(basePath) !== 1) return path;
395
+ if (basePath === "/@fs" || basePath === "/@id") return path;
396
+
397
+ const remainderPath = path.slice(firstSlashIndex);
398
+ if (!SOURCE_FILE_EXTENSION_REGEX.test(remainderPath)) return path;
399
+
400
+ const remainderSegments = remainderPath.split("/").filter(Boolean);
401
+ if (remainderSegments.length < 2) return path;
402
+
403
+ const firstRemainderSegment = remainderSegments[0];
404
+ if (!firstRemainderSegment || firstRemainderSegment.startsWith("@")) return path;
405
+ if (firstRemainderSegment.length > 4) return path;
406
+ return remainderPath;
407
+ };
408
+
409
+ export const isSourceFile = (fileName: string): boolean => {
410
+ const normalizedFileName = normalizeFileName(fileName);
411
+ if (!normalizedFileName) return false;
412
+ if (normalizedFileName.includes("\0") || normalizedFileName.startsWith("virtual:")) return false;
413
+ if (!SOURCE_FILE_EXTENSION_REGEX.test(normalizedFileName)) return false;
414
+ if (BUNDLED_FILE_PATTERN_REGEX.test(normalizedFileName)) return false;
415
+ return true;
416
+ };
@@ -1,28 +1,16 @@
1
- import { getDisplayName, getType, traverseFiber } from "../core.js";
2
- import { getReactWorkTagsForFiber } from "../react-internals/index.js";
3
- import type {
4
- Fiber,
5
- RendererDispatcherRef,
6
- ServerComponentInfo,
7
- } from "../react-internals/index.js";
1
+ import { getDisplayName, getType, traverseFiber } from "../core";
2
+ import { getReactWorkTagsForFiber } from "../react-internals/index";
3
+ import type { Fiber, RendererDispatcherRef, ServerComponentInfo } from "../react-internals/index";
8
4
  import {
9
5
  REACT_STACK_BOTTOM_FRAME_PATTERNS,
10
6
  SERVER_ENV_PATTERN,
11
7
  SERVER_COMPONENT_URL_PREFIXES,
12
- } from "./constants.js";
13
- import { getPrepareStackTrace, setPrepareStackTrace } from "./error-stack.js";
14
- import { parseDebugStack } from "./parse-debug-stack.js";
15
- import { parseStack, type StackFrame } from "./parse-stack.js";
16
- import {
17
- getRendererDispatcherRefs,
18
- readDispatcher,
19
- writeDispatcher,
20
- } from "./renderer-dispatchers.js";
21
- import {
22
- symbolicateStack,
23
- type SourceFetch,
24
- type SourceMapRequestOptions,
25
- } from "./symbolication.js";
8
+ } from "./constants";
9
+ import { getPrepareStackTrace, setPrepareStackTrace } from "./error-stack";
10
+ import { parseDebugStack } from "./parse-debug-stack";
11
+ import { parseStack, type StackFrame } from "./parse-stack";
12
+ import { getRendererDispatcherRefs, readDispatcher, writeDispatcher } from "./renderer-dispatchers";
13
+ import { symbolicateStack, type SourceFetch, type SourceMapRequestOptions } from "./symbolication";
26
14
 
27
15
  interface RendererDispatcherSnapshot {
28
16
  currentDispatcherRef: RendererDispatcherRef;