Download next.js/packages/next/src/next-devtools/server/shared.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.54 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/next-devtools/server/shared.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/packages/next/src/next-devtools/server/shared.ts
-
curl -L -o shared.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/packages/next/src/next-devtools/server/shared.ts
2.54 kB
| import { codeFrameColumns } from 'next/dist/compiled/babel/code-frame' | |
| import isInternal from '../../shared/lib/is-internal' | |
| import type { StackFrame } from '../../server/lib/parse-stack' | |
| import { ignoreListAnonymousStackFramesIfSandwiched as ignoreListAnonymousStackFramesIfSandwichedGeneric } from '../../server/lib/source-maps' | |
| export type { StackFrame } | |
| export interface IgnorableStackFrame extends StackFrame { | |
| ignored: boolean | |
| } | |
| export interface OriginalStackFramesRequest { | |
| frames: StackFrame[] | |
| isServer: boolean | |
| isEdgeServer: boolean | |
| isAppDirectory: boolean | |
| } | |
| export type OriginalStackFramesResponse = OriginalStackFrameResponseResult[] | |
| export type OriginalStackFrameResponseResult = | |
| PromiseSettledResult<OriginalStackFrameResponse> | |
| export interface OriginalStackFrameResponse { | |
| originalStackFrame: (StackFrame & { ignored: boolean }) | null | |
| originalCodeFrame: string | null | |
| } | |
| export function ignoreListAnonymousStackFramesIfSandwiched( | |
| responses: OriginalStackFramesResponse | |
| ): void { | |
| ignoreListAnonymousStackFramesIfSandwichedGeneric( | |
| responses, | |
| (response) => { | |
| return ( | |
| response.status === 'fulfilled' && | |
| response.value.originalStackFrame !== null && | |
| response.value.originalStackFrame.file === '<anonymous>' | |
| ) | |
| }, | |
| (response) => { | |
| return ( | |
| response.status === 'fulfilled' && | |
| response.value.originalStackFrame !== null && | |
| response.value.originalStackFrame.ignored === true | |
| ) | |
| }, | |
| (response) => { | |
| return response.status === 'fulfilled' && | |
| response.value.originalStackFrame !== null | |
| ? response.value.originalStackFrame.methodName | |
| : '' | |
| }, | |
| (response) => { | |
| ;( | |
| response as PromiseFulfilledResult<OriginalStackFrameResponse> | |
| ).value.originalStackFrame!.ignored = true | |
| } | |
| ) | |
| } | |
| /** | |
| * It looks up the code frame of the traced source. | |
| * @note It ignores Next.js/React internals, as these can often be huge bundled files. | |
| */ | |
| export function getOriginalCodeFrame( | |
| frame: IgnorableStackFrame, | |
| source: string | null, | |
| colors: boolean = process.stdout.isTTY | |
| ): string | null { | |
| if (!source || isInternal(frame.file)) { | |
| return null | |
| } | |
| return codeFrameColumns( | |
| source, | |
| { | |
| start: { | |
| // 1-based, but -1 means start line without highlighting | |
| line: frame.line1 ?? -1, | |
| // 1-based, but 0 means whole line without column highlighting | |
| column: frame.column1 ?? 0, | |
| }, | |
| }, | |
| { forceColor: colors } | |
| ) | |
| } | |