UNPKG

@backtrace/sourcemap-tools

Version:
81 lines (80 loc) 4.2 kB
import { DebugIdGenerator } from './DebugIdGenerator'; import { RawSourceMap, RawSourceMapWithDebugId } from './models/RawSourceMap'; import { ResultPromise } from './models/Result'; export interface ProcessResultWithoutSourceMap { readonly debugId: string; readonly source: string; } export interface ProcessResultWithSourceMaps extends ProcessResultWithoutSourceMap { readonly sourceMap: RawSourceMapWithDebugId; } export interface ProcessResultWithPaths extends ProcessResultWithSourceMaps { readonly sourcePath: string; readonly sourceMapPath: string; } export interface AddSourcesResult { readonly sourceMap: RawSourceMap; /** * Source paths that were successfully added. */ readonly succeeded: string[]; /** * Source paths that failed to read, but source content was already in the sourcemap. */ readonly skipped: string[]; /** * Source paths that failed to read and the sources content was not in the sourcemap. */ readonly failed: string[]; } export declare class SourceProcessor { private readonly _debugIdGenerator; constructor(_debugIdGenerator: DebugIdGenerator); isSourceProcessed(source: string): boolean; isSourceMapProcessed(sourceMap: RawSourceMap): boolean; isSourceFileProcessed(sourcePath: string): ResultPromise<boolean, string>; isSourceMapFileProcessed(sourceMapPath: string): ResultPromise<boolean, string>; getSourceDebugId(source: string): string | undefined; getSourceMapDebugId(sourceMap: RawSourceMap): string | undefined; getSourceMapFileDebugId(sourceMapPath: string): ResultPromise<string | undefined, string>; /** * Adds required snippets and comments to source * @param source Source content. * @param debugId Debug ID. If not provided, one will be generated from `source`. * @param force Force adding changes. * @returns Used debug ID, new source and new sourcemap. */ processSource(source: string, debugId?: string, force?: boolean): Promise<ProcessResultWithoutSourceMap>; /** * Adds required snippets and comments to source, and modifies sourcemap to include debug ID. * @param source Source content. * @param sourceMap Sourcemap object or JSON. * @param debugId Debug ID. If not provided, one will be generated from `source`. * @param force Force adding changes. * @returns Used debug ID, new source and new sourcemap. */ processSourceAndSourceMap(source: string, sourceMap: RawSourceMap, debugId?: string, force?: boolean): Promise<ProcessResultWithSourceMaps>; /** * Adds required snippets and comments to source, and modifies sourcemap to include debug ID if available. * @param source Source content. * @param sourceMap Sourcemap object or JSON. * @param debugId Debug ID. If not provided, one will be generated from `source`. * @param force Force adding changes. * @returns Used debug ID, new source and new sourcemap. */ private processSourceAndAvailableSourceMap; /** * Adds required snippets and comments to source, and modifies sourcemap to include debug ID. * Will write modified content to the files. * @param sourcePath Path to the source. * @param sourceMapPath Path to the sourcemap. If not specified, will try to resolve from sourceMapURL. * @param debugId Debug ID. If not provided, one will be generated from `source`. * @returns Used debug ID. */ processSourceAndSourceMapFiles(sourcePath: string, sourceMapPath?: string, debugId?: string, force?: boolean): ResultPromise<ProcessResultWithPaths, string>; getSourceMapPathFromSourceFile(sourcePath: string): Promise<import("./models/Result").ResultErr<string> | import("./models/Result").ResultOk<string | undefined>>; getSourceMapPathFromSource(source: string, sourcePath: string): Promise<string | undefined>; addSourcesToSourceMap(sourceMap: string | RawSourceMap, sourceMapPath: string, force: boolean): ResultPromise<AddSourcesResult, string>; doesSourceMapHaveSources(sourceMap: RawSourceMap): boolean; offsetSourceMap(sourceMap: RawSourceMap, count: number): Promise<RawSourceMap>; }