UNPKG

2.85 kBTypeScriptView Raw
1export interface FileData {
2 size: number;
3 coveredSize?: number;
4}
5
6export type FileDataMap = Record<string, FileData>;
7
8export interface FileSizes {
9 files: FileDataMap;
10 mappedBytes: number;
11 unmappedBytes?: number;
12 eolBytes: number;
13 sourceMapCommentBytes: number;
14 totalBytes: number;
15}
16
17export type ErrorCode =
18 | 'Unknown'
19 | 'NoBundles'
20 | 'NoSourceMap'
21 | 'OneSourceSourceMap'
22 | 'UnmappedBytes'
23 | 'InvalidMappingLine'
24 | 'InvalidMappingColumn'
25 | 'CannotSaveFile'
26 | 'CannotCreateTempFile'
27 | 'CannotOpenTempFile'
28 | 'CannotOpenCoverageFile'
29 | 'NoCoverageMatches';
30
31export type File = string | Buffer;
32
33export type ReplaceMap = Record<string, string>;
34
35type OutputFormat = 'json' | 'tsv' | 'html';
36
37/** Represents single bundle */
38export interface Bundle {
39 code: File;
40 map?: File;
41 coverageRanges?: ColumnsRange[][];
42}
43
44export interface ExploreOptions {
45 /** Exclude "unmapped" bytes from the output */
46 onlyMapped?: boolean;
47 /** Exclude source map comment size from output */
48 excludeSourceMapComment?: boolean;
49 /** Output result as a string */
50 output?: {
51 format: OutputFormat;
52 /** Filename to save output to */
53 filename?: string;
54 };
55 /** Disable removing prefix shared by all sources */
56 noRoot?: boolean;
57 /** Disable invalid mapping column/line checks. */
58 noBorderChecks?: boolean;
59 /** Replace "this" by "that" map */
60 replaceMap?: ReplaceMap;
61 coverage?: string;
62 /** Calculate gzip size. Setting it to `true` will also set `onlyMapped` to `true` */
63 gzip?: boolean;
64 /** Sort filenames */
65 sort?: boolean;
66}
67
68export interface ExploreResult {
69 bundles: ExploreBundleResult[];
70 /** Result as a string - either JSON, TSV or HTML */
71 output?: string;
72 errors: ExploreErrorResult[];
73}
74
75export interface ExploreBundleResult extends FileSizes {
76 bundleName: string;
77}
78
79export interface ExploreErrorResult {
80 bundleName: string;
81 code: string;
82 message: string;
83 error?: NodeJS.ErrnoException;
84 isWarning?: boolean;
85}
86
87export type BundlesAndFileTokens = (Bundle | string)[] | Bundle | string;
88
89/** Represents inclusive range (e.g. [0,5] six columns) */
90export interface ColumnsRange {
91 /** Fist column index */
92 start: number;
93 /** Last column index */
94 end: number;
95}
96
97export interface MappingRange extends ColumnsRange {
98 source: string;
99}
100
101/** Represents exclusive range (e.g. [0,5) - four columns) */
102export interface Coverage {
103 url: string;
104 ranges: CoverageRange[];
105 /** File content as one line */
106 text: string;
107}
108
109export interface CoverageRange {
110 /** First column index */
111 start: number;
112 /** Column index next after last column index */
113 end: number;
114}
115
116// TODO: Remove when https://github.com/mozilla/source-map/pull/374 is published
117declare module 'source-map' {
118 export interface MappingItem {
119 lastGeneratedColumn: number | null;
120 }
121}