import * as sourceMap from 'source-map'; import { ScanStats } from "./scanner"; export interface MapInfoInput { outputFile: string; mapFile: string; mapConsumer: sourceMap.RawSourceMap; sources: string[]; } export interface MapInfoOutput { file: string; line: number; column?: number; } export interface FindFilesResult { jsStats: ScanStats; mapFiles: string[]; errors: Map; hash: string; } /** * Given an list of available files and a script path to match, this function * tries to resolve the script to a (hopefully unique) match in the file list * disregarding the full path to the script. This can be useful because repo * file paths (that the UI has) may not necessarily be suffixes of the absolute * paths of the deployed files. This happens when the user deploys a * subdirectory of the repo. * * For example consider a file named `a/b.js` in the repo. If the * directory contents of `a` are deployed rather than the whole repo, we are not * going to have any file named `a/b.js` in the running Node process. * * We incrementally consider more components of the path until we find a unique * match, or return all the potential matches. * * @example findScriptsFuzzy('a/b.js', ['/d/b.js']) // -> ['/d/b.js'] * @example findScriptsFuzzy('a/b.js', ['/c/b.js', '/d/b.js']); // -> [] * @example findScriptsFuzzy('a/b.js', ['/x/a/b.js', '/y/a/b.js']) * // -> ['x/a/b.js', 'y/a/b.js'] * * @param {string} scriptPath partial path to the script. * @param {array} fileList an array of absolute paths of filenames * available. * @return {array} list of files that match. */ export declare function findScriptsFuzzy(scriptPath: string, fileList: string[]): string[]; /** * Given an list of available files and a script path to match, this function * tries to resolve the script to a (hopefully unique) match in the file list * disregarding the full path to the script. This can be useful because repo * file paths (that the UI has) may not necessarily be suffixes of the absolute * paths of the deployed files. This happens when the user deploys a * subdirectory of the repo. * * For example consider a file named `a/b.js` in the repo. If the * directory contents of `a` are deployed rather than the whole repo, we are not * going to have any file named `a/b.js` in the running Node process. * * We incrementally consider more components of the path until we find a unique * match, or return all the potential matches. * * @example findScriptsFuzzy('a/b.js', ['b.js']) // -> ['b.js'] * * @param {string} scriptPath absolute path to the script. * @param {array} fileList an array of partial paths of filenames * available. * @return {array} list of files that match. */ export declare function findScriptsReverseFuzzy(scriptPath: string, fileList: string[]): string[]; /** * @param {!string} scriptPath path of a script */ export declare function pathToRegExp(scriptPath: string): RegExp; export declare class SourceMapper { infoMap: Map; fileMap: Map; private _scanned; static buildRegExp(fileExtensions: string[]): RegExp; /** * This function can be used to find js.map files, this is the preferred async function. See #findFilesSync for the sync version. * @param config the config including director and extensions to scan for * @param precomputedHash (optional) hash to use */ static findFiles(config: { workingDirectory: string; javascriptFileExtensions: string[]; }, precomputedHash?: string): Promise; /** * This function can be used to find js.map files, this is the sync function. See #findFiles for the async version. * @param config the config including director and extensions to scan for * @param precomputedHash (optional) hash to use */ static findFilesSync(config: { workingDirectory: string; javascriptFileExtensions: string[]; }, precomputedHash?: string): FindFilesResult; /** * @constructor */ constructor(); /** * @param {string} mapPath The path to the sourcemap file to process. The * path should be relative to the process's current working directory * @private */ processSourcemap(mapPath: string): Promise; /** * @param {string} mapPath The path to the sourcemap file to process. The * path should be relative to the process's current working directory * @private */ processSourcemapSync(mapPath: string): void; /** * Used to determine if the transpiled file specified by the given path has * a .map file and an source file associated with it. * * If there is no such mapping, it could be because the input file is not * the input to a transpilation process or it is the input to a transpilation * process but its corresponding .map file was not given to the constructor * of this mapper. * * @param {string} inputPath The path to an input file that could * possibly be the output of a transpilation process. The path should be * relative to the process's current working directory. */ hasReverseMappingInfo(inputPath: string): boolean; /** * @param {string} inputPath The path to an input file that could possibly * be the output of a transpilation process. The path should be relative to * the process's current working directory * @param {number} lineNumber The line number in the input file where the line number is * one-based. * @param {number} colNumber (Optional) The column number in the line of the file * specified where the column number is zero-based. * @return {Object} The object returned has a "file" attribute for the * path of the output file associated with the given input file (where the * path is relative to the process's current working directory), * a "line" attribute of the line number in the output file associated with * the given line number for the input file, and an optional "column" number * of the column number of the output file associated with the given file * and line information. * * If the given input file does not have mapping information associated * with it then null is returned. */ reverseMappingInfo(inputPath: string, lineNumber: number, colNumber?: number): MapInfoOutput | null; /** * Used to determine if the source file specified by the given path has * a .map file and an output file associated with it. * * If there is no such mapping, it could be because the input file is not * the input to a transpilation process or it is the input to a transpilation * process but its corresponding .map file was not given to the constructor * of this mapper. * * @param {string} inputPath The path to an input file that could * possibly be the input to a transpilation process. The path should be * relative to the process's current working directory. */ hasMappingInfo(inputPath: string): boolean; private processSourceMapCommon; /** * Used to get the information about the transpiled file from a given input * source file provided there isn't any ambiguity with associating the input * path to exactly one output transpiled file. * * @param inputPath The (possibly relative) path to the original source file. * @return The `MapInfoInput` object that describes the transpiled file * associated with the specified input path. `null` is returned if either * zero files are associated with the input path or if more than one file * could possibly be associated with the given input path. */ private getMappingInfo; /** * @param {string} inputPath The path to an input file that could possibly * be the input to a transpilation process. The path should be relative to * the process's current working directory * @param {number} lineNumber The line number in the input file where the line number is * one-based. * @param {number} colNumber (Optional) The column number in the line of the file * specified where the column number is zero-based. * @return {Object} The object returned has a "file" attribute for the * path of the output file associated with the given input file (where the * path is relative to the process's current working directory), * a "line" attribute of the line number in the output file associated with * the given line number for the input file, and an optional "column" number * of the column number of the output file associated with the given file * and line information. * * If the given input file does not have mapping information associated * with it then null is returned. */ mappingInfo(inputPath: string, lineNumber: number, colNumber: number): MapInfoOutput | null; /** * Used to get the information about the transpiled file from a given input * file provided there isn't any ambiguity with associating the input * path to exactly one output transpiled file. * * @param inputPath The (possibly relative) path to the transpiled file. * @return The `MapInfoInput` object that describes the transpiled file * associated with the specified input path. `null` is returned if either * zero files are associated with the input path or if more than one file * could possibly be associated with the given input path. */ private getReverseMappingInfo; static scanDirectory(dirname: string): Promise; scanDirectorySync(dirname: string): string[]; appendResults(dirname: string, mapFiles: string[]): Promise; appendResultsSync(dirname: string, mapFiles: string[]): void; hasScanned(dirname: string): boolean; } export declare function create(dirname: string, sourcemapPaths: string[]): Promise;