source-map-explorer 2.4.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +6 -2
- package/{dist → bin}/cli.d.ts +1 -1
- package/{dist → bin}/cli.js +20 -10
- package/bin/cli.js.map +1 -0
- package/{dist → lib}/api.d.ts +1 -1
- package/{dist → lib}/api.js +12 -11
- package/lib/api.js.map +1 -0
- package/{dist → lib}/app-error.d.ts +1 -1
- package/{dist → lib}/app-error.js +4 -2
- package/lib/app-error.js.map +1 -0
- package/{dist → lib}/coverage.d.ts +1 -1
- package/{dist → lib}/coverage.js +2 -1
- package/lib/coverage.js.map +1 -0
- package/{dist → lib}/explore.d.ts +1 -1
- package/{dist → lib}/explore.js +8 -2
- package/lib/explore.js.map +1 -0
- package/{dist → lib}/helpers.d.ts +1 -1
- package/{dist → lib}/helpers.js +2 -1
- package/lib/helpers.js.map +1 -0
- package/{dist → lib}/html.d.ts +6 -1
- package/{dist → lib}/html.js +63 -33
- package/lib/html.js.map +1 -0
- package/{dist → lib}/index.d.ts +0 -0
- package/lib/index.js +31 -0
- package/lib/index.js.map +1 -0
- package/{dist → lib}/output.d.ts +1 -1
- package/{dist → lib}/output.js +2 -1
- package/lib/output.js.map +1 -0
- package/{dist → lib}/tree-viz.ejs +0 -0
- package/{dist → lib}/types.d.ts +2 -0
- package/{dist → lib}/vendor/webtreemap.css +0 -0
- package/{dist → lib}/vendor/webtreemap.js +0 -0
- package/package.json +58 -57
- package/dist/api.js.map +0 -1
- package/dist/app-error.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/coverage.js.map +0 -1
- package/dist/explore.js.map +0 -1
- package/dist/helpers.js.map +0 -1
- package/dist/html.js.map +0 -1
- package/dist/index.js +0 -10
- package/dist/index.js.map +0 -1
- package/dist/output.js.map +0 -1
package/README.md
CHANGED
@@ -126,7 +126,9 @@ source-map-explorer foo.min.js --tsv result.tsv
|
|
126
126
|
|
127
127
|
These are regular expressions.
|
128
128
|
|
129
|
-
* `--no-root`: By default, source-map-explorer finds common prefixes between all source files and eliminates them, since they add complexity to the visualization with no real benefit. But if you want to disable this behavior, set the `--no-root` flag.
|
129
|
+
* `--no-root`: By default, `source-map-explorer` finds common prefixes between all source files and eliminates them, since they add complexity to the visualization with no real benefit. But if you want to disable this behavior, set the `--no-root` flag.
|
130
|
+
|
131
|
+
* `--no-border-checks`: Disable invalid mapping column/line checks. By default, when a source map references column/line with bigger index than available in the source `source-map-explorers` throws an error indicating that specified source map might be wrong for the source.
|
130
132
|
|
131
133
|
* `--coverage`: If the path to a valid a chrome code coverage JSON export is supplied, the tree map will be colorized according to which percentage of the modules code was executed
|
132
134
|
|
@@ -145,7 +147,7 @@ source-map-explorer -h
|
|
145
147
|
```
|
146
148
|
Analyze and debug space usage through source maps.
|
147
149
|
Usage:
|
148
|
-
source-map-explorer script.js [script.js.map] [--json [result.json] | --html [result.html] | --tsv [result.csv]] [-m | --only-mapped] [--exclude-source-map] [--gzip] [--sort] [--replace=BEFORE_1 BEFORE_2 --with=AFTER_1 AFTER_2] [--no-root] [--coverage coverage.json] [--version] [--help | -h]
|
150
|
+
source-map-explorer script.js [script.js.map] [--json [result.json] | --html [result.html] | --tsv [result.csv]] [-m | --only-mapped] [--exclude-source-map] [--no-border-checks] [--gzip] [--sort] [--replace=BEFORE_1 BEFORE_2 --with=AFTER_1 AFTER_2] [--no-root] [--coverage coverage.json] [--version] [--help | -h]
|
149
151
|
|
150
152
|
Output:
|
151
153
|
--json If filename specified save output as JSON to specified file otherwise output to stdout. [string]
|
@@ -162,6 +164,7 @@ Options:
|
|
162
164
|
--only-mapped, -m Exclude "unmapped" bytes from the output. This will result in total counts less than the file size [boolean]
|
163
165
|
--exclude-source-map Exclude source map comment size from output [boolean]
|
164
166
|
--no-root To simplify the visualization, source-map-explorer will remove any prefix shared by all sources. If you wish to disable this behavior, set --no-root. [boolean]
|
167
|
+
--no-border-checks Disable invalid mapping column/line checks. [boolean]
|
165
168
|
--coverage If the path to a valid a chrome code coverage JSON export is supplied, the tree map will be colorized according to which percentage of the modules code was executed
|
166
169
|
[string]
|
167
170
|
--gzip Calculate gzip size. It also sets onlyMapped flag [boolean]
|
@@ -329,6 +332,7 @@ with-unmapped.js
|
|
329
332
|
* `format`: [string] - `'json'`, `'tsv'` or `'html'`
|
330
333
|
* `filename`: [string] - Filename to save output to
|
331
334
|
* `noRoot`: [boolean] (default `false`) - See `--no-root` option above for details
|
335
|
+
* `noBorderChecks`: [boolean] - Disable invalid mapping column/line checks. See `--no-border-checks` above.
|
332
336
|
* `replaceMap`: <[Object]<{ [from: [string]]: [string] }>> - Mapping for replacement, see `--replace`, `--with` options above for details.
|
333
337
|
* `coverage`: [string] - If the path to a valid a chrome code coverage JSON export is supplied, the tree map will be colorized according to which percentage of the modules code was executed
|
334
338
|
* `gzip`: [boolean] - Calculate gzip size. It also sets `onlyMapped` flag
|
package/{dist → bin}/cli.d.ts
RENAMED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
import { ErrorContext } from '
|
2
|
+
import type { ErrorContext } from '../lib/app-error';
|
3
3
|
export declare function logError(message: string | ErrorContext, error?: Error): void;
|
4
4
|
export declare function logWarn(message: string): void;
|
5
5
|
export declare function logInfo(message: string): void;
|
package/{dist → bin}/cli.js
RENAMED
@@ -2,18 +2,19 @@
|
|
2
2
|
'use strict';
|
3
3
|
var __importDefault =
|
4
4
|
(this && this.__importDefault) ||
|
5
|
-
function(mod) {
|
5
|
+
function (mod) {
|
6
6
|
return mod && mod.__esModule ? mod : { default: mod };
|
7
7
|
};
|
8
8
|
Object.defineProperty(exports, '__esModule', { value: true });
|
9
|
+
exports.logInfo = exports.logWarn = exports.logError = void 0;
|
9
10
|
const yargs_1 = __importDefault(require('yargs'));
|
10
11
|
const fs_1 = __importDefault(require('fs'));
|
11
12
|
const temp_1 = __importDefault(require('temp'));
|
12
13
|
const open_1 = __importDefault(require('open'));
|
13
14
|
const chalk_1 = __importDefault(require('chalk'));
|
14
15
|
const lodash_1 = require('lodash');
|
15
|
-
const api_1 = require('
|
16
|
-
const app_error_1 = require('
|
16
|
+
const api_1 = require('../lib/api');
|
17
|
+
const app_error_1 = require('../lib/app-error');
|
17
18
|
function parseArguments() {
|
18
19
|
const argv = yargs_1.default
|
19
20
|
.strict()
|
@@ -21,7 +22,7 @@ function parseArguments() {
|
|
21
22
|
.usage('Analyze and debug space usage through source maps.')
|
22
23
|
.usage('Usage:')
|
23
24
|
.usage(
|
24
|
-
'$0 script.js [script.js.map] [--json [result.json] | --html [result.html] | --tsv [result.csv]] [-m | --only-mapped] [--exclude-source-map] [--gzip] [--sort] [--replace=BEFORE_1 BEFORE_2 --with=AFTER_1 AFTER_2] [--no-root] [--coverage coverage.json] [--version] [--help | -h]'
|
25
|
+
'$0 script.js [script.js.map] [--json [result.json] | --html [result.html] | --tsv [result.csv]] [-m | --only-mapped] [--exclude-source-map] [--no-border-checks] [--gzip] [--sort] [--replace=BEFORE_1 BEFORE_2 --with=AFTER_1 AFTER_2] [--no-root] [--coverage coverage.json] [--version] [--help | -h]'
|
25
26
|
)
|
26
27
|
.example('$0 script.js script.js.map', 'Explore bundle')
|
27
28
|
.example('$0 script.js', 'Explore bundle with inline source map')
|
@@ -76,6 +77,10 @@ function parseArguments() {
|
|
76
77
|
description: 'See --replace.',
|
77
78
|
implies: 'replace',
|
78
79
|
},
|
80
|
+
'no-border-checks': {
|
81
|
+
type: 'boolean',
|
82
|
+
description: 'Disable invalid mapping column/line checks.',
|
83
|
+
},
|
79
84
|
coverage: {
|
80
85
|
type: 'string',
|
81
86
|
normalize: true,
|
@@ -101,7 +106,7 @@ function parseArguments() {
|
|
101
106
|
.parserConfiguration({
|
102
107
|
'boolean-negation': false,
|
103
108
|
})
|
104
|
-
.check(argv => {
|
109
|
+
.check((argv) => {
|
105
110
|
if (argv.replace && argv.with && argv.replace.length !== argv.with.length) {
|
106
111
|
throw new Error('--replace flags must be paired with --with flags');
|
107
112
|
}
|
@@ -109,7 +114,7 @@ function parseArguments() {
|
|
109
114
|
})
|
110
115
|
.parse();
|
111
116
|
const quoteRegex = /'/g;
|
112
|
-
argv._ = argv._.map(path => path.replace(quoteRegex, ''));
|
117
|
+
argv._ = argv._.map((path) => path.replace(quoteRegex, ''));
|
113
118
|
return argv;
|
114
119
|
}
|
115
120
|
function logError(message, error) {
|
@@ -141,6 +146,7 @@ function getExploreOptions(argv) {
|
|
141
146
|
onlyMapped,
|
142
147
|
excludeSourceMap: excludeSourceMapComment,
|
143
148
|
noRoot,
|
149
|
+
noBorderChecks,
|
144
150
|
coverage,
|
145
151
|
gzip,
|
146
152
|
sort,
|
@@ -161,6 +167,7 @@ function getExploreOptions(argv) {
|
|
161
167
|
onlyMapped,
|
162
168
|
excludeSourceMapComment,
|
163
169
|
noRoot,
|
170
|
+
noBorderChecks,
|
164
171
|
coverage,
|
165
172
|
gzip,
|
166
173
|
sort,
|
@@ -175,8 +182,10 @@ async function writeHtmlToTempFile(html) {
|
|
175
182
|
fs_1.default.writeFileSync(tempFile, html);
|
176
183
|
const childProcess = await open_1.default(tempFile);
|
177
184
|
if (childProcess.stderr) {
|
178
|
-
childProcess.stderr.once('data', error => {
|
179
|
-
|
185
|
+
childProcess.stderr.once('data', (error) => {
|
186
|
+
if (error.toString().trim() !== '#< CLIXML') {
|
187
|
+
logError({ code: 'CannotOpenTempFile', tempFile, error });
|
188
|
+
}
|
180
189
|
});
|
181
190
|
}
|
182
191
|
} catch (error) {
|
@@ -208,7 +217,7 @@ if (require.main === module) {
|
|
208
217
|
const options = getExploreOptions(argv);
|
209
218
|
api_1
|
210
219
|
.explore(argv._, options)
|
211
|
-
.then(result => {
|
220
|
+
.then((result) => {
|
212
221
|
if (isOutputFormatSpecified && options.output) {
|
213
222
|
const filename = options.output.filename;
|
214
223
|
if (filename) {
|
@@ -223,12 +232,13 @@ if (require.main === module) {
|
|
223
232
|
});
|
224
233
|
}
|
225
234
|
})
|
226
|
-
.catch(error => {
|
235
|
+
.catch((error) => {
|
227
236
|
if (error.errors) {
|
228
237
|
outputErrors(error);
|
229
238
|
} else {
|
230
239
|
logError('Failed to explore', error);
|
231
240
|
}
|
241
|
+
process.exitCode = 1;
|
232
242
|
});
|
233
243
|
}
|
234
244
|
//# sourceMappingURL=cli.js.map
|
package/bin/cli.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli/cli.ts"],"names":[],"mappings":";;;;;;;AAEA,kDAA0B;AAC1B,4CAAoB;AACpB,gDAAwB;AACxB,gDAAwB;AACxB,kDAA0B;AAC1B,mCAA2C;AAE3C,oCAAqC;AACrC,gDAA6D;AAsB7D,SAAS,cAAc;IACrB,MAAM,IAAI,GAAG,eAAK;SACf,MAAM,EAAE;SACR,UAAU,CAAC,qBAAqB,CAAC;SACjC,KAAK,CAAC,oDAAoD,CAAC;SAC3D,KAAK,CAAC,QAAQ,CAAC;SACf,KAAK,CACJ,0SAA0S,CAC3S;SACA,OAAO,CAAC,4BAA4B,EAAE,gBAAgB,CAAC;SACvD,OAAO,CAAC,cAAc,EAAE,uCAAuC,CAAC;SAChE,OAAO,CAAC,gBAAgB,EAAE,2CAA2C,CAAC;SACtE,OAAO,CAAC,oBAAoB,EAAE,4CAA4C,CAAC;SAC3E,OAAO,CAAC,iCAAiC,EAAE,6CAA6C,CAAC;SACzF,aAAa,CAAC,CAAC,EAAE,wCAAwC,CAAC;SAC1D,OAAO,CAAC;QACP,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,yFAAyF;YAC3F,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;SAC3B;QACD,GAAG,EAAE;YACH,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,wFAAwF;YAC1F,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;SAC5B;QACD,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,uHAAuH;YACzH,SAAS,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC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M,EAAE;IAC3B,MAAM,IAAI,GAAG,cAAc,EAAE,CAAC;IAE9B,MAAM,uBAAuB,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,iBAAQ,CAAC,CAAC;IAEhF,MAAM,OAAO,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAExC,aAAO,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC;SACrB,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACf,IAAI,uBAAuB,IAAI,OAAO,CAAC,MAAM,EAAE;YAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC;YAEzC,IAAI,QAAQ,EAAE;gBACZ,OAAO,CAAC,mBAAmB,QAAQ,EAAE,CAAC,CAAC;gBACvC,YAAY,CAAC,MAAM,CAAC,CAAC;aACtB;iBAAM;gBACL,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;aAC5B;SACF;aAAM;YACL,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;gBAC3C,YAAY,CAAC,MAAM,CAAC,CAAC;YACvB,CAAC,CAAC,CAAC;SACJ;IACH,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACf,IAAI,KAAK,CAAC,MAAM,EAAE;YAChB,YAAY,CAAC,KAAK,CAAC,CAAC;SACrB;aAAM;YACL,QAAQ,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;SACtC;QAED,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;CACN","sourcesContent":["#!/usr/bin/env node\n\nimport yargs from 'yargs';\nimport fs from 'fs';\nimport temp from 'temp';\nimport open from 'open';\nimport chalk from 'chalk';\nimport { groupBy, isString } from 'lodash';\n\nimport { explore } from '../lib/api';\nimport { AppError, getErrorMessage } from '../lib/app-error';\n\nimport type { ErrorContext } from '../lib/app-error';\nimport type { ExploreOptions, ReplaceMap, ExploreResult } from '../lib/types';\n\n/** Parsed CLI arguments */\ninterface Arguments {\n _: string[];\n json?: string;\n tsv?: string;\n html?: string;\n onlyMapped?: boolean;\n excludeSourceMap?: boolean;\n noRoot?: boolean;\n replace?: string[];\n with?: string[];\n noBorderChecks?: boolean;\n coverage?: string;\n gzip?: boolean;\n sort?: boolean;\n}\n\nfunction parseArguments(): Arguments {\n const argv = yargs\n .strict()\n .scriptName('source-map-explorer')\n .usage('Analyze and debug space usage through source maps.')\n .usage('Usage:')\n .usage(\n '$0 script.js [script.js.map] [--json [result.json] | --html [result.html] | --tsv [result.csv]] [-m | --only-mapped] [--exclude-source-map] [--no-border-checks] [--gzip] [--sort] [--replace=BEFORE_1 BEFORE_2 --with=AFTER_1 AFTER_2] [--no-root] [--coverage coverage.json] [--version] [--help | -h]'\n )\n .example('$0 script.js script.js.map', 'Explore bundle')\n .example('$0 script.js', 'Explore bundle with inline source map')\n .example('$0 dist/js/*.*', 'Explore all bundles inside dist/js folder')\n .example('$0 script.js --tsv', 'Explore and output result as TSV to stdout')\n .example('$0 script.js --json result.json', 'Explore and save result as JSON to the file')\n .demandCommand(1, 'At least one js file must be specified')\n .options({\n json: {\n type: 'string',\n description:\n 'If filename specified save output as JSON to specified file otherwise output to stdout.',\n conflicts: ['tsv', 'html'],\n },\n tsv: {\n type: 'string',\n description:\n 'If filename specified save output as TSV to specified file otherwise output to stdout.',\n conflicts: ['json', 'html'],\n },\n html: {\n type: 'string',\n description:\n 'If filename specified save output as HTML to specified file otherwise output to stdout rather than opening a browser.',\n conflicts: ['json', 'tsv'],\n },\n\n 'only-mapped': {\n alias: 'm',\n type: 'boolean',\n description:\n 'Exclude \"unmapped\" bytes from the output. This will result in total counts less than the file size',\n },\n\n 'exclude-source-map': {\n type: 'boolean',\n description: 'Exclude source map comment size from output',\n },\n\n 'no-root': {\n type: 'boolean',\n description:\n 'To simplify the visualization, source-map-explorer will remove any prefix shared by all sources. If you wish to disable this behavior, set --no-root.',\n },\n\n replace: {\n type: 'string',\n array: true,\n description:\n 'Apply a simple find/replace on source file names. This can be used to fix some oddities with paths that appear in the source map generation process. Accepts regular expressions.',\n implies: 'with',\n },\n with: {\n type: 'string',\n array: true,\n description: 'See --replace.',\n implies: 'replace',\n },\n\n 'no-border-checks': {\n type: 'boolean',\n description: 'Disable invalid mapping column/line checks.',\n },\n\n coverage: {\n type: 'string',\n normalize: true,\n description:\n 'If the path to a valid a chrome code coverage JSON export is supplied, the tree map will be colorized according to which percentage of the modules code was executed',\n },\n\n gzip: {\n type: 'boolean',\n description: 'Calculate gzip size. It also sets onlyMapped flag',\n conflicts: ['only-mapped'],\n },\n\n sort: {\n type: 'boolean',\n description: 'Sort filenames',\n },\n })\n .group(['json', 'tsv', 'html'], 'Output:')\n .group(['replace', 'with'], 'Replace:')\n .help('h')\n .alias('h', 'help')\n .showHelpOnFail(false, 'Specify --help for available options')\n .wrap(null) // Do not limit line length\n .parserConfiguration({\n 'boolean-negation': false, // Allow --no-root\n })\n .check((argv) => {\n if (argv.replace && argv.with && argv.replace.length !== argv.with.length) {\n throw new Error('--replace flags must be paired with --with flags');\n }\n\n return true;\n })\n .parse();\n\n // Trim extra quotes\n const quoteRegex = /'/g;\n\n argv._ = argv._.map((path) => path.replace(quoteRegex, ''));\n\n return argv;\n}\n\nexport function logError(message: string | ErrorContext, error?: Error): void {\n if (!isString(message)) {\n message = getErrorMessage(message);\n }\n\n if (error) {\n console.error(chalk.red(message), error);\n } else {\n console.error(chalk.red(message));\n }\n}\n\nexport function logWarn(message: string): void {\n console.warn(chalk.yellow(message));\n}\n\nexport function logInfo(message: string): void {\n console.log(chalk.green(message));\n}\n\n/**\n * Create options object for `explore` method\n */\nfunction getExploreOptions(argv: Arguments): ExploreOptions {\n const {\n json,\n tsv,\n html,\n replace: replaceItems,\n with: withItems,\n onlyMapped,\n excludeSourceMap: excludeSourceMapComment,\n noRoot,\n noBorderChecks,\n coverage,\n gzip,\n sort,\n } = argv;\n\n let replaceMap: ReplaceMap | undefined;\n\n if (replaceItems && withItems) {\n replaceMap = replaceItems.reduce<ReplaceMap>((result, item, index) => {\n result[item] = withItems[index];\n\n return result;\n }, {});\n }\n\n return {\n output: {\n // By default CLI needs result in HTML in order to create a temporary file\n format: isString(json) ? 'json' : isString(tsv) ? 'tsv' : 'html',\n filename: json || tsv || html,\n },\n replaceMap,\n onlyMapped,\n excludeSourceMapComment,\n noRoot,\n noBorderChecks,\n coverage,\n gzip,\n sort,\n };\n}\n\n/**\n * Write HTML content to a temporary file and open the file in a browser\n */\nasync function writeHtmlToTempFile(html?: string): Promise<void> {\n if (!html) {\n return;\n }\n\n try {\n const tempFile = temp.path({ prefix: 'sme-result-', suffix: '.html' });\n\n fs.writeFileSync(tempFile, html);\n\n const childProcess = await open(tempFile);\n\n if (childProcess.stderr) {\n // Catch error output from child process\n childProcess.stderr.once('data', (error: Buffer) => {\n // TODO: Figure out why `#< CLIXML` ends up in stderr. Maybe we should simply ignore it\n if (error.toString().trim() !== '#< CLIXML') {\n logError({ code: 'CannotOpenTempFile', tempFile, error });\n }\n });\n }\n } catch (error) {\n throw new AppError({ code: 'CannotCreateTempFile' }, error);\n }\n}\n\nfunction outputErrors({ errors }: ExploreResult): void {\n if (errors.length === 0) {\n return;\n }\n\n // Group errors by bundle name\n const groupedErrors = groupBy(errors, 'bundleName');\n\n Object.entries(groupedErrors).forEach(([bundleName, errors]) => {\n console.group(bundleName);\n\n const hasManyErrors = errors.length > 1;\n\n errors.forEach((error, index) => {\n const message = `${hasManyErrors ? `${index + 1}. ` : ''}${error.message}`;\n\n if (error.isWarning) {\n logWarn(message);\n } else {\n logError(message);\n }\n });\n\n console.groupEnd();\n });\n}\n\nif (require.main === module) {\n const argv = parseArguments();\n\n const isOutputFormatSpecified = [argv.json, argv.tsv, argv.html].some(isString);\n\n const options = getExploreOptions(argv);\n\n explore(argv._, options)\n .then((result) => {\n if (isOutputFormatSpecified && options.output) {\n const filename = options.output.filename;\n\n if (filename) {\n logInfo(`Output saved to ${filename}`);\n outputErrors(result);\n } else {\n console.log(result.output);\n }\n } else {\n writeHtmlToTempFile(result.output).then(() => {\n outputErrors(result);\n });\n }\n })\n .catch((error) => {\n if (error.errors) {\n outputErrors(error);\n } else {\n logError('Failed to explore', error);\n }\n\n process.exitCode = 1;\n });\n}\n"]}
|
package/{dist → lib}/api.d.ts
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Bundle, BundlesAndFileTokens, ExploreOptions, ExploreResult } from './types';
|
1
|
+
import type { Bundle, BundlesAndFileTokens, ExploreOptions, ExploreResult } from './types';
|
2
2
|
export declare function explore(bundlesAndFileTokens: BundlesAndFileTokens, options?: ExploreOptions): Promise<ExploreResult>;
|
3
3
|
export declare function getBundles(fileTokens: string[]): Bundle[];
|
4
4
|
export declare function getBundleName(bundle: Bundle): string;
|
package/{dist → lib}/api.js
RENAMED
@@ -1,10 +1,11 @@
|
|
1
1
|
'use strict';
|
2
2
|
var __importDefault =
|
3
3
|
(this && this.__importDefault) ||
|
4
|
-
function(mod) {
|
4
|
+
function (mod) {
|
5
5
|
return mod && mod.__esModule ? mod : { default: mod };
|
6
6
|
};
|
7
7
|
Object.defineProperty(exports, '__esModule', { value: true });
|
8
|
+
exports.getBundleName = exports.getBundles = exports.explore = void 0;
|
8
9
|
const glob_1 = __importDefault(require('glob'));
|
9
10
|
const lodash_1 = require('lodash');
|
10
11
|
const explore_1 = require('./explore');
|
@@ -29,8 +30,8 @@ async function explore(bundlesAndFileTokens, options = {}) {
|
|
29
30
|
bundles.push(...getBundles(fileTokens));
|
30
31
|
coverage_1.addCoverageRanges(bundles, options.coverage);
|
31
32
|
const results = await Promise.all(
|
32
|
-
bundles.map(bundle =>
|
33
|
-
explore_1.exploreBundle(bundle, options).catch(error => onExploreError(bundle, error))
|
33
|
+
bundles.map((bundle) =>
|
34
|
+
explore_1.exploreBundle(bundle, options).catch((error) => onExploreError(bundle, error))
|
34
35
|
)
|
35
36
|
);
|
36
37
|
const exploreResult = getExploreResult(results, options);
|
@@ -42,15 +43,15 @@ async function explore(bundlesAndFileTokens, options = {}) {
|
|
42
43
|
}
|
43
44
|
exports.explore = explore;
|
44
45
|
function getBundles(fileTokens) {
|
45
|
-
const filenames = lodash_1.flatMap(fileTokens, filePath =>
|
46
|
+
const filenames = lodash_1.flatMap(fileTokens, (filePath) =>
|
46
47
|
glob_1.default.hasMagic(filePath) ? expandGlob(filePath) : filePath
|
47
48
|
);
|
48
|
-
const [mapFilenames, codeFilenames] = lodash_1.partition(filenames, filename =>
|
49
|
+
const [mapFilenames, codeFilenames] = lodash_1.partition(filenames, (filename) =>
|
49
50
|
filename.endsWith('.map')
|
50
51
|
);
|
51
|
-
return codeFilenames.map(code => ({
|
52
|
+
return codeFilenames.map((code) => ({
|
52
53
|
code,
|
53
|
-
map: mapFilenames.find(filename => filename === `${code}.map`),
|
54
|
+
map: mapFilenames.find((filename) => filename === `${code}.map`),
|
54
55
|
}));
|
55
56
|
}
|
56
57
|
exports.getBundles = getBundles;
|
@@ -73,14 +74,14 @@ function onExploreError(bundle, error) {
|
|
73
74
|
};
|
74
75
|
}
|
75
76
|
function sortFilenames(bundles) {
|
76
|
-
return bundles.map(bundle => ({
|
77
|
+
return bundles.map((bundle) => ({
|
77
78
|
...bundle,
|
78
79
|
files: lodash_1.fromPairs(lodash_1.sortBy(lodash_1.toPairs(bundle.files), 0)),
|
79
80
|
}));
|
80
81
|
}
|
81
82
|
function getExploreResult(results, options) {
|
82
|
-
const [bundles, errors] = lodash_1.partition(results, result => 'files' in result);
|
83
|
-
let sortedBundles = lodash_1.sortBy(bundles, bundle => bundle.bundleName);
|
83
|
+
const [bundles, errors] = lodash_1.partition(results, (result) => 'files' in result);
|
84
|
+
let sortedBundles = lodash_1.sortBy(bundles, (bundle) => bundle.bundleName);
|
84
85
|
if (options.sort) {
|
85
86
|
sortedBundles = sortFilenames(sortedBundles);
|
86
87
|
}
|
@@ -98,7 +99,7 @@ function getPostExploreErrors(exploreBundleResults) {
|
|
98
99
|
const { bundleName, files, totalBytes } = result;
|
99
100
|
if (isSingleBundle) {
|
100
101
|
const filenames = Object.keys(files).filter(
|
101
|
-
filename => !explore_1.SPECIAL_FILENAMES.includes(filename)
|
102
|
+
(filename) => !explore_1.SPECIAL_FILENAMES.includes(filename)
|
102
103
|
);
|
103
104
|
if (filenames.length === 1) {
|
104
105
|
errors.push({
|
package/lib/api.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/lib/api.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,mCAAkF;AAElF,uCAA2E;AAC3E,2CAAwD;AACxD,qCAA0D;AAC1D,yCAA+C;AAW/C,SAAS,aAAa,CAAC,OAAuB;IAG5C,IAAI,OAAO,CAAC,IAAI,EAAE;QAChB,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;KAC3B;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAKM,KAAK,UAAU,OAAO,CAC3B,oBAA0C,EAC1C,UAA0B,EAAE;IAE5B,oBAAoB,GAAG,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC;QACxD,CAAC,CAAC,oBAAoB;QACtB,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC;IAE3B,IAAI,oBAAoB,CAAC,MAAM,KAAK,CAAC,EAAE;QACrC,MAAM,IAAI,oBAAQ,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;KAC3C;IAED,aAAa,CAAC,OAAO,CAAC,CAAC;IAGvB,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,kBAAS,CAAC,oBAAoB,EAAE,iBAAQ,CAAC,CAAC;IAGxE,OAAO,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;IAExC,4BAAiB,CAAC,OAAO,EAA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f,IAAI,EAAE,eAAe;oBACrB,OAAO,EAAE,2BAAe,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC;iBAC/E,CAAC,CAAC;aACJ;SACF;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import glob from 'glob';\nimport { partition, flatMap, isString, toPairs, fromPairs, sortBy } from 'lodash';\n\nimport { exploreBundle, UNMAPPED_KEY, SPECIAL_FILENAMES } from './explore';\nimport { AppError, getErrorMessage } from './app-error';\nimport { formatOutput, saveOutputToFile } from './output';\nimport { addCoverageRanges } from './coverage';\n\nimport type {\n Bundle,\n BundlesAndFileTokens,\n ExploreBundleResult,\n ExploreErrorResult,\n ExploreOptions,\n ExploreResult,\n} from './types';\n\nfunction adjustOptions(options: ExploreOptions): ExploreOptions {\n /* Unmapped bytes cannot be calculate because it's impossible to get total size by summing files'\n sizes when calculating gzip size for a file. */\n if (options.gzip) {\n options.onlyMapped = true;\n }\n\n return options;\n}\n\n/**\n * Analyze bundle(s)\n */\nexport async function explore(\n bundlesAndFileTokens: BundlesAndFileTokens,\n options: ExploreOptions = {}\n): Promise<ExploreResult> {\n bundlesAndFileTokens = Array.isArray(bundlesAndFileTokens)\n ? bundlesAndFileTokens\n : [bundlesAndFileTokens];\n\n if (bundlesAndFileTokens.length === 0) {\n throw new AppError({ code: 'NoBundles' });\n }\n\n adjustOptions(options);\n\n // Separate bundles from file tokens\n const [fileTokens, bundles] = partition(bundlesAndFileTokens, isString);\n\n // Get bundles from file tokens\n bundles.push(...getBundles(fileTokens));\n\n addCoverageRanges(bundles, options.coverage);\n\n const results = await Promise.all(\n bundles.map((bundle) =>\n exploreBundle(bundle, options).catch<ExploreErrorResult>((error) =>\n onExploreError(bundle, error)\n )\n )\n );\n\n const exploreResult = getExploreResult(results, options);\n\n // Reject if none of results is successful\n if (exploreResult.bundles.length === 0) {\n return Promise.reject(exploreResult);\n }\n\n saveOutputToFile(exploreResult, options);\n\n return exploreResult;\n}\n\n/**\n * Expand list of file tokens into a list of bundles\n */\nexport function getBundles(fileTokens: string[]): Bundle[] {\n const filenames = flatMap(fileTokens, (filePath) =>\n glob.hasMagic(filePath) ? expandGlob(filePath) : filePath\n );\n\n const [mapFilenames, codeFilenames] = partition(filenames, (filename) =>\n filename.endsWith('.map')\n );\n\n return codeFilenames.map<Bundle>((code) => ({\n code,\n map: mapFilenames.find((filename) => filename === `${code}.map`),\n }));\n}\n\nfunction expandGlob(pattern: string): string[] {\n // Make sure pattern match `.map` files as well\n if (pattern.endsWith('.js')) {\n pattern = `${pattern}?(.map)`;\n }\n\n return glob.sync(pattern);\n}\n\nexport function getBundleName(bundle: Bundle): string {\n return Buffer.isBuffer(bundle.code) ? 'Buffer' : bundle.code;\n}\n\n/**\n * Handle error during bundle processing\n */\nfunction onExploreError(bundle: Bundle, error: NodeJS.ErrnoException): ExploreErrorResult {\n return {\n bundleName: getBundleName(bundle),\n code: error.code || 'Unknown',\n message: error.message,\n error,\n };\n}\n\nfunction sortFilenames(bundles: ExploreBundleResult[]): ExploreBundleResult[] {\n return bundles.map((bundle) => ({\n ...bundle,\n files: fromPairs(sortBy(toPairs(bundle.files), 0)),\n }));\n}\n\nfunction getExploreResult(\n results: (ExploreBundleResult | ExploreErrorResult)[],\n options: ExploreOptions\n): ExploreResult {\n const [bundles, errors] = partition(\n results,\n (result): result is ExploreBundleResult => 'files' in result\n );\n\n let sortedBundles = sortBy(bundles, (bundle) => bundle.bundleName);\n\n if (options.sort) {\n sortedBundles = sortFilenames(sortedBundles);\n }\n\n errors.push(...getPostExploreErrors(bundles));\n\n return {\n bundles: sortedBundles,\n errors,\n ...(bundles.length > 0 && { output: formatOutput(sortedBundles, options) }),\n };\n}\n\nfunction getPostExploreErrors(exploreBundleResults: ExploreBundleResult[]): ExploreErrorResult[] {\n const errors: ExploreErrorResult[] = [];\n\n const isSingleBundle = exploreBundleResults.length === 1;\n\n for (const result of exploreBundleResults) {\n const { bundleName, files, totalBytes } = result;\n\n // Check if source map contains only one file - this make result useless when exploring single bundle\n if (isSingleBundle) {\n const filenames = Object.keys(files).filter(\n (filename) => !SPECIAL_FILENAMES.includes(filename)\n );\n\n if (filenames.length === 1) {\n errors.push({\n bundleName,\n isWarning: true,\n code: 'OneSourceSourceMap',\n message: getErrorMessage({ code: 'OneSourceSourceMap', filename: filenames[0] }),\n });\n }\n }\n\n if (files[UNMAPPED_KEY] !== undefined) {\n const { size: unmappedBytes } = files[UNMAPPED_KEY];\n\n if (unmappedBytes) {\n errors.push({\n bundleName,\n isWarning: true,\n code: 'UnmappedBytes',\n message: getErrorMessage({ code: 'UnmappedBytes', unmappedBytes, totalBytes }),\n });\n }\n }\n }\n\n return errors;\n}\n"]}
|
@@ -1,5 +1,6 @@
|
|
1
1
|
'use strict';
|
2
2
|
Object.defineProperty(exports, '__esModule', { value: true });
|
3
|
+
exports.getErrorMessage = exports.SOURCE_MAP_INFO_URL = exports.AppError = void 0;
|
3
4
|
const helpers_1 = require('./helpers');
|
4
5
|
class AppError extends Error {
|
5
6
|
constructor(errorContext, error) {
|
@@ -38,8 +39,9 @@ Check that you are using the correct source map.`;
|
|
38
39
|
}
|
39
40
|
case 'InvalidMappingColumn': {
|
40
41
|
const { generatedLine, generatedColumn, maxColumn } = context;
|
41
|
-
return `Your source map refers to generated column ${
|
42
|
-
|
42
|
+
return `Your source map refers to generated column ${
|
43
|
+
generatedColumn + 1
|
44
|
+
} on line ${generatedLine}, but the source only contains ${maxColumn} column(s) on that line.
|
43
45
|
Check that you are using the correct source map.`;
|
44
46
|
}
|
45
47
|
case 'CannotSaveFile':
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"app-error.js","sourceRoot":"","sources":["../src/lib/app-error.ts"],"names":[],"mappings":";;;AAAA,uCAA0C;AAK1C,MAAa,QAAS,SAAQ,KAAK;IAIjC,YAAY,YAA0B,EAAE,KAA6B;QACnE,KAAK,EAAE,CAAC;QAER,MAAM,CAAC,cAAc,CAAC,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CACpB,YAAY,aAAa,kCAAkC,SAAS;iDACzB,CAAC;SAC7C;QAED,KAAK,gBAAgB;YACnB,OAAO,6BAA6B,CAAC;QAEvC,KAAK,sBAAsB;YACzB,OAAO,wCAAwC,CAAC;QAElD,KAAK,oBAAoB,CAAC,CAAC;YACzB,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;YAEpC,OAAO,+BAA+B,KAAK,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE;;EAEjE,QAAQ,EAAE,CAAC;SACR;QAED,KAAK,wBAAwB,CAAC,CAAC;YAC7B,OAAO,oCAAoC,CAAC;SAC7C;QAED,KAAK,mBAAmB,CAAC,CAAC;YACxB,OAAO,wCAAwC,CAAC;SACjD;QAED;YACE,OAAO,eAAe,CAAC;KAC1B;AACH,CAAC;AAjED,0CAiEC","sourcesContent":["import { formatPercent } from './helpers';\n\nimport type { ErrorCode } from './types';\n\n// If we need advanced error consider using https://github.com/joyent/node-verror\nexport class AppError extends Error {\n code?: ErrorCode;\n cause?: Error;\n\n constructor(errorContext: ErrorContext, error?: NodeJS.ErrnoException) {\n super();\n // https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work\n Object.setPrototypeOf(this, AppError.prototype);\n\n const message = getErrorMessage(errorContext);\n\n this.message = error ? `${message}: ${error.message}` : message;\n this.code = errorContext.code;\n\n Error.captureStackTrace(this, AppError);\n }\n}\n\nexport const SOURCE_MAP_INFO_URL =\n 'https://github.com/danvk/source-map-explorer/blob/master/README.md#generating-source-maps';\n\ninterface CommonErrorContext {\n code:\n | 'NoBundles'\n | 'NoSourceMap'\n | 'CannotSaveFile'\n | 'CannotCreateTempFile'\n | 'CannotOpenCoverageFile'\n | 'NoCoverageMatches'\n | 'Unknown';\n}\n\ninterface OneSourceSourceMapErrorContext {\n code: 'OneSourceSourceMap';\n filename: string;\n}\n\ninterface UnmappedBytesErrorContext {\n code: 'UnmappedBytes';\n totalBytes: number;\n unmappedBytes: number;\n}\n\ninterface InvalidMappingLineErrorContext {\n code: 'InvalidMappingLine';\n generatedLine: number;\n maxLine: number;\n}\n\ninterface InvalidMappingColumnErrorContext {\n code: 'InvalidMappingColumn';\n generatedLine: number;\n generatedColumn: number;\n maxColumn: number;\n}\n\ninterface CannotOpenTempFileErrorContext {\n code: 'CannotOpenTempFile';\n error: Buffer;\n tempFile: string;\n}\n\nexport type ErrorContext =\n | CommonErrorContext\n | OneSourceSourceMapErrorContext\n | UnmappedBytesErrorContext\n | InvalidMappingLineErrorContext\n | InvalidMappingColumnErrorContext\n | CannotOpenTempFileErrorContext;\n\nexport function getErrorMessage(context: ErrorContext): string {\n switch (context.code) {\n case 'NoBundles':\n return 'No file(s) provided';\n\n case 'NoSourceMap':\n return `Unable to find a source map.\nSee ${SOURCE_MAP_INFO_URL}`;\n\n case 'OneSourceSourceMap': {\n return `Your source map only contains one source (${context.filename}).\nThis can happen if you use browserify+uglifyjs, for example, and don't set the --in-source-map flag to uglify.\nSee ${SOURCE_MAP_INFO_URL}`;\n }\n\n case 'UnmappedBytes': {\n const { unmappedBytes, totalBytes } = context;\n\n const bytesString = formatPercent(unmappedBytes, totalBytes, 2);\n\n return `Unable to map ${unmappedBytes}/${totalBytes} bytes (${bytesString}%)`;\n }\n\n case 'InvalidMappingLine': {\n const { generatedLine, maxLine } = context;\n\n return `Your source map refers to generated line ${generatedLine}, but the source only contains ${maxLine} line(s).\nCheck that you are using the correct source map.`;\n }\n\n case 'InvalidMappingColumn': {\n const { generatedLine, generatedColumn, maxColumn } = context;\n\n // Add 1 since generatedColumn is 0-based\n return `Your source map refers to generated column ${\n generatedColumn + 1\n } on line ${generatedLine}, but the source only contains ${maxColumn} column(s) on that line.\nCheck that you are using the correct source map.`;\n }\n\n case 'CannotSaveFile':\n return 'Unable to save HTML to file';\n\n case 'CannotCreateTempFile':\n return 'Unable to create a temporary HTML file';\n\n case 'CannotOpenTempFile': {\n const { error, tempFile } = context;\n\n return `Unable to open web browser. ${error.toString().trim()}\nEither run with --html, --json, --tsv, --file, or view HTML for the visualization at:\n${tempFile}`;\n }\n\n case 'CannotOpenCoverageFile': {\n return 'Unable to open/parse coverage file';\n }\n\n case 'NoCoverageMatches': {\n return 'No matched bundles found for coverages';\n }\n\n default:\n return 'Unknown error';\n }\n}\n"]}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Bundle, ColumnsRange, MappingRange, FileDataMap } from './types';
|
1
|
+
import type { Bundle, ColumnsRange, MappingRange, FileDataMap } from './types';
|
2
2
|
export declare function addCoverageRanges(bundles: Bundle[], coverageFilename?: string): Bundle[];
|
3
3
|
export declare function setCoveredSizes(line: string, files: FileDataMap, mappingRanges: MappingRange[], coveredRanges: ColumnsRange[]): FileDataMap;
|
4
4
|
export declare function getColorByPercent(percent: number): string;
|
package/{dist → lib}/coverage.js
RENAMED
@@ -1,5 +1,6 @@
|
|
1
1
|
'use strict';
|
2
2
|
Object.defineProperty(exports, '__esModule', { value: true });
|
3
|
+
exports.getColorByPercent = exports.setCoveredSizes = exports.addCoverageRanges = void 0;
|
3
4
|
const url_1 = require('url');
|
4
5
|
const helpers_1 = require('./helpers');
|
5
6
|
const app_error_1 = require('./app-error');
|
@@ -9,7 +10,7 @@ function convertRangesToLinesRanges(coverage) {
|
|
9
10
|
const eolLength = eol.length;
|
10
11
|
const lines = text.split(eol);
|
11
12
|
let offset = 0;
|
12
|
-
const lineRanges = lines.map(line => {
|
13
|
+
const lineRanges = lines.map((line) => {
|
13
14
|
const lineLength = line.length;
|
14
15
|
if (lineLength === 0) {
|
15
16
|
return [];
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"coverage.js","sourceRoot":"","sources":["../src/lib/coverage.ts"],"names":[],"mappings":";;;AAAA,6BAA0B;AAE1B,uCAAsD;AACtD,2CAAuC;AAOvC,SAAS,0BAA0B,CAAC,QAAkB;IACpD,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,QAAQ,C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M,UAAU,GAAG,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACxC,MAAM,UAAU,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;IACpC,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;IAClE,MAAM,YAAY,GAAG,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,iBAAiB,CAAC;IACxE,MAAM,YAAY,GAAG,CAAC,GAAG,YAAY,CAAC;IACtC,MAAM,YAAY,GAAG,YAAY,CAAC;IAElC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,YAAY,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC;IAC5F,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,YAAY,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC;IAC5F,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,YAAY,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC;IAE5F,OAAO,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;AACjC,CAAC;AArBD,8CAqBC","sourcesContent":["import { URL } from 'url';\n\nimport { getFileContent, detectEOL } from './helpers';\nimport { AppError } from './app-error';\n\nimport type { Bundle, Coverage, ColumnsRange, MappingRange, FileDataMap } from './types';\n\n/**\n * Convert one-line coverage ranges (exclusive) into per line ranges (inclusive)\n */\nfunction convertRangesToLinesRanges(coverage: Coverage): ColumnsRange[][] {\n const { ranges, text } = coverage;\n\n const eol = detectEOL(text);\n const eolLength = eol.length;\n const lines = text.split(eol);\n\n // Current line offset\n let offset = 0;\n\n const lineRanges = lines.map((line) => {\n const lineLength = line.length;\n\n if (lineLength === 0) {\n return [];\n }\n\n // Exclusive line start/end\n const lineStart = offset;\n const lineEnd = offset + lineLength;\n\n const lineRanges = ranges.reduce<ColumnsRange[]>((result, { start, end }) => {\n // Inclusive range start/end within the line\n const startIndex = start - lineStart;\n const endIndex = end - lineStart - 1;\n const lineEndIndex = lineLength - 1;\n\n if (start <= lineStart && lineEnd <= end) {\n // Range includes line range\n result.push({ start: 0, end: lineEndIndex });\n } else if (lineStart <= start && end <= lineEnd) {\n // Line range includes range\n result.push({ start: startIndex, end: endIndex });\n } else if (lineStart <= start && start <= lineEnd) {\n // Range starts within line range\n result.push({ start: startIndex, end: lineEndIndex });\n } else if (lineStart <= end && end <= lineEnd) {\n // Range ends within line range\n result.push({ start: 0, end: endIndex });\n }\n\n return result;\n }, []);\n\n // Move to next line jumping over EOL character\n offset = lineEnd + eolLength;\n\n return lineRanges;\n });\n\n return lineRanges;\n}\n\nconst PATH_SEPARATOR_REGEX = /[/\\\\]/;\n\nfunction getPathParts(path: string): string[] {\n return path.split(PATH_SEPARATOR_REGEX).filter(Boolean);\n}\n\n/**\n * Match coverages' ranges to bundles by comparing coverage URL and bundle filename\n */\nexport function addCoverageRanges(bundles: Bundle[], coverageFilename?: string): Bundle[] {\n if (!coverageFilename) {\n return bundles;\n }\n\n try {\n const coverages: Coverage[] = JSON.parse(getFileContent(coverageFilename));\n\n const bundlesPaths = bundles.reduce<[string[], number][]>((result, { code }, index) => {\n if (!Buffer.isBuffer(code)) {\n result.push([getPathParts(code).reverse(), index]);\n }\n\n return result;\n }, []);\n\n coverages\n // pathname contains filename\n .map(({ url }) => getPathParts(new URL(url).pathname).reverse())\n .forEach((partsA, coverageIndex) => {\n // Exclude coverages for inlined code (URL doesn't contain a filename)\n if (!partsA.length) return;\n let matchingBundles = [...bundlesPaths];\n\n // Start from filename and go up to path root\n for (let i = 0; i < partsA.length; i++) {\n matchingBundles = matchingBundles.filter(\n ([partsB]) => i < partsB.length && partsB[i] === partsA[i]\n );\n\n // Stop when exact (among bundles) match found or no matches found\n if (matchingBundles.length <= 1) {\n break;\n }\n }\n\n if (matchingBundles.length === 1) {\n const [[, bundleIndex]] = matchingBundles;\n\n bundles[bundleIndex].coverageRanges = convertRangesToLinesRanges(\n coverages[coverageIndex]\n );\n }\n });\n } catch (error) {\n throw new AppError({ code: 'CannotOpenCoverageFile' }, error);\n }\n\n if (bundles.every(({ coverageRanges }) => coverageRanges === undefined)) {\n throw new AppError({ code: 'NoCoverageMatches' });\n }\n\n return bundles;\n}\n\n/**\n * Find overlaps in arrays of column ranges, using ratcheting pointers instead of nested loops for\n * O(n) runtime instead of O(n^2)\n */\nfunction findCoveredMappingRanges(\n mappingRanges: MappingRange[],\n coveredRanges: ColumnsRange[]\n): MappingRange[] {\n let i = 0;\n let j = 0;\n\n const result: MappingRange[] = [];\n\n while (i < mappingRanges.length && j < coveredRanges.length) {\n const mappingRange = mappingRanges[i];\n const coveredRange = coveredRanges[j];\n\n if (mappingRange.start <= coveredRange.end && coveredRange.start <= mappingRange.end) {\n // Overlaps, calculate amount, move to next coverage range\n const end = Math.min(coveredRange.end, mappingRange.end);\n const start = Math.max(mappingRange.start, coveredRange.start);\n\n result.push({\n start,\n end,\n source: mappingRange.source,\n });\n\n if (\n mappingRanges[i + 1] !== undefined &&\n mappingRanges[i + 1].start <= coveredRange.end &&\n mappingRanges[i + 1].end >= coveredRange.start\n ) {\n // Next module also overlaps current coverage range, advance to next module instead of advancing coverage\n i++;\n } else {\n // Check next coverage range, it may also overlap this module range\n j++;\n }\n } else if (mappingRange.end < coveredRange.start) {\n // Module comes entirely before coverageRange, check next module range\n i++;\n }\n if (coveredRange.end < mappingRange.start) {\n // Module range comes entirely after coverage range, check next coverage range\n j++;\n }\n }\n\n return result;\n}\n\n/**\n * Set covered size for files\n */\nexport function setCoveredSizes(\n line: string,\n files: FileDataMap,\n mappingRanges: MappingRange[],\n coveredRanges: ColumnsRange[]\n): FileDataMap {\n findCoveredMappingRanges(mappingRanges, coveredRanges).forEach(({ start, end, source }) => {\n const rangeByteLength = Buffer.byteLength(line.substring(start, end + 1));\n\n let coveredSize = files[source].coveredSize || 0;\n\n coveredSize += rangeByteLength;\n\n files[source].coveredSize = coveredSize;\n });\n\n return files;\n}\n\nconst percentColors = [\n { percent: 0.0, color: { r: 0xff, g: 0x00, b: 0 } },\n { percent: 0.5, color: { r: 0xff, g: 0xff, b: 0 } },\n { percent: 1.0, color: { r: 0x00, g: 0xff, b: 0 } },\n];\n\n/**\n * Get heat map color by coverage percent\n */\nexport function getColorByPercent(percent: number): string {\n let i = 1;\n\n for (; i < percentColors.length - 1; i++) {\n if (percent < percentColors[i].percent) {\n break;\n }\n }\n\n const lowerColor = percentColors[i - 1];\n const upperColor = percentColors[i];\n const rangeWithinColors = upperColor.percent - lowerColor.percent;\n const rangePercent = (percent - lowerColor.percent) / rangeWithinColors;\n const percentLower = 1 - rangePercent;\n const percentUpper = rangePercent;\n\n const r = Math.floor(lowerColor.color.r * percentLower + upperColor.color.r * percentUpper);\n const g = Math.floor(lowerColor.color.g * percentLower + upperColor.color.g * percentUpper);\n const b = Math.floor(lowerColor.color.b * percentLower + upperColor.color.b * percentUpper);\n\n return `rgb(${r}, ${g}, ${b})`;\n}\n"]}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Bundle, ExploreBundleResult, ExploreOptions, FileDataMap } from './types';
|
1
|
+
import type { Bundle, ExploreBundleResult, ExploreOptions, FileDataMap } from './types';
|
2
2
|
export declare const UNMAPPED_KEY = "[unmapped]";
|
3
3
|
export declare const SOURCE_MAP_COMMENT_KEY = "[sourceMappingURL]";
|
4
4
|
export declare const NO_SOURCE_KEY = "[no source]";
|
package/{dist → lib}/explore.js
RENAMED
@@ -1,10 +1,11 @@
|
|
1
1
|
'use strict';
|
2
2
|
var __importDefault =
|
3
3
|
(this && this.__importDefault) ||
|
4
|
-
function(mod) {
|
4
|
+
function (mod) {
|
5
5
|
return mod && mod.__esModule ? mod : { default: mod };
|
6
6
|
};
|
7
7
|
Object.defineProperty(exports, '__esModule', { value: true });
|
8
|
+
exports.adjustSourcePaths = exports.exploreBundle = exports.SPECIAL_FILENAMES = exports.EOL_KEY = exports.NO_SOURCE_KEY = exports.SOURCE_MAP_COMMENT_KEY = exports.UNMAPPED_KEY = void 0;
|
8
9
|
const convert_source_map_1 = __importDefault(require('convert-source-map'));
|
9
10
|
const path_1 = __importDefault(require('path'));
|
10
11
|
const source_map_1 = require('source-map');
|
@@ -136,6 +137,9 @@ function computeFileSizes(sourceMapData, options, coverageRanges) {
|
|
136
137
|
const lineIndex = generatedLine - 1;
|
137
138
|
const line = lines[lineIndex];
|
138
139
|
if (line === undefined) {
|
140
|
+
if (options.noBorderChecks) {
|
141
|
+
return;
|
142
|
+
}
|
139
143
|
throw new app_error_1.AppError({
|
140
144
|
code: 'InvalidMappingLine',
|
141
145
|
generatedLine,
|
@@ -146,7 +150,9 @@ function computeFileSizes(sourceMapData, options, coverageRanges) {
|
|
146
150
|
context.generatedColumn = lastGeneratedColumn || generatedColumn;
|
147
151
|
context.line = line;
|
148
152
|
context.source = source;
|
149
|
-
|
153
|
+
if (!options.noBorderChecks) {
|
154
|
+
checkInvalidMappingColumn(context);
|
155
|
+
}
|
150
156
|
const start = generatedColumn;
|
151
157
|
const end = lastGeneratedColumn === null ? line.length - 1 : lastGeneratedColumn;
|
152
158
|
const lineRanges = mappingRanges[lineIndex] || [];
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"explore.js","sourceRoot":"","sources":["../src/lib/explore.ts"],"names":[],"mappings":";;;;;;AAAA,4EAAyC;AACzC,gDAAwB;AACxB,2CAAiG;AACjG,0DAAiC;AACjC,mCAAiC;AAEjC,+BAAsC;AACtC,uCAQmB;AACnB,2CAAuC;AACvC,yCAA6C;AAahC,QAAA,YAAY,GAAG,YAAY,CAAC;AAC5B,QAAA,sBAAsB,GAAG,oBAAoB,CAAC;AAC9C,QAAA,aAAa,GAAG,aAAa,CAAC;AAC9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,WAAW,GAAG,gBAAO,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;SAC5E;KACF;IAED,IAAI,OAAO,CAAC,UAAU,EAAE;QACtB,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,EAAE;YAClF,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YAEvC,OAAO,gBAAO,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QAC1E,CAAC,EAAE,WAAW,CAAC,CAAC;KACjB;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAnBD,8CAmBC","sourcesContent":["import convert from 'convert-source-map';\nimport path from 'path';\nimport { BasicSourceMapConsumer, IndexedSourceMapConsumer, SourceMapConsumer } from 'source-map';\nimport gzipSize from 'gzip-size';\nimport { mapKeys } from 'lodash';\n\nimport { getBundleName } from './api';\nimport {\n getFileContent,\n getCommonPathPrefix,\n getFirstRegexMatch,\n detectEOL,\n getOccurrencesCount,\n isEOLAtPosition,\n mergeRanges,\n} from './helpers';\nimport { AppError } from './app-error';\nimport { setCoveredSizes } from './coverage';\n\nimport type {\n Bundle,\n CoverageRange,\n ExploreBundleResult,\n ExploreOptions,\n File,\n FileDataMap,\n FileSizes,\n MappingRange,\n} from './types';\n\nexport const UNMAPPED_KEY = '[unmapped]';\nexport const SOURCE_MAP_COMMENT_KEY = '[sourceMappingURL]';\nexport const NO_SOURCE_KEY = '[no source]';\nexport const EOL_KEY = '[EOLs]';\n\nexport const SPECIAL_FILENAMES = [UNMAPPED_KEY, SOURCE_MAP_COMMENT_KEY, NO_SOURCE_KEY, EOL_KEY];\n\n/**\n * Analyze a bundle\n */\nexport async function exploreBundle(\n bundle: Bundle,\n options: ExploreOptions\n): Promise<ExploreBundleResult> {\n const { code, map, coverageRanges } = bundle;\n\n const sourceMapData = await loadSourceMap(code, map);\n\n const sizes = computeFileSizes(sourceMapData, options, coverageRanges);\n\n const files = adjustSourcePaths(sizes.files, options);\n\n // Free Wasm data\n sourceMapData.consumer.destroy();\n\n return {\n bundleName: getBundleName(bundle),\n ...sizes,\n files,\n };\n}\n\ntype Consumer = BasicSourceMapConsumer | IndexedSourceMapConsumer;\n\ninterface SourceMapData {\n consumer: Consumer;\n codeFileContent: string;\n}\n\n/**\n * Get source map\n */\nasync function loadSourceMap(codeFile: File, sourceMapFile?: File): Promise<SourceMapData> {\n const codeFileContent = getFileContent(codeFile);\n\n let consumer: Consumer;\n\n if (sourceMapFile) {\n const sourceMapFileContent = getFileContent(sourceMapFile);\n\n consumer = await new SourceMapConsumer(sourceMapFileContent);\n } else {\n // Try to read a source map from a 'sourceMappingURL' comment.\n let converter = convert.fromSource(codeFileContent);\n\n if (!converter && !Buffer.isBuffer(codeFile)) {\n converter = convert.fromMapFileSource(codeFileContent, path.dirname(codeFile));\n }\n\n if (!converter) {\n throw new AppError({ code: 'NoSourceMap' });\n }\n\n consumer = await new SourceMapConsumer(converter.toJSON());\n }\n\n if (!consumer) {\n throw new AppError({ code: 'NoSourceMap' });\n }\n\n return {\n consumer,\n codeFileContent,\n };\n}\n\nconst COMMENT_REGEX = convert.commentRegex;\nconst MAP_FILE_COMMENT_REGEX = convert.mapFileCommentRegex;\n\n/**\n * Extract either source map comment/file\n */\nfunction getSourceMapComment(fileContent: string): string {\n const sourceMapComment =\n getFirstRegexMatch(COMMENT_REGEX, fileContent) ||\n getFirstRegexMatch(MAP_FILE_COMMENT_REGEX, fileContent) ||\n '';\n\n // Remove trailing EOLs\n return sourceMapComment.trim();\n}\n\ninterface ComputeFileSizesContext {\n generatedLine: number;\n generatedColumn: number;\n line: string;\n source: string | null;\n consumer: Consumer;\n mapReferenceEOLSources: Set<string>;\n}\n\n/**\n * Check if source map references EOL (see https://github.com/microsoft/TypeScript/issues/34695)\n */\nfunction isReferencingEOL(context: ComputeFileSizesContext, maxColumnIndex: number): boolean {\n const { generatedLine, generatedColumn, source, consumer } = context;\n\n // Ignore difference more than EOL max length (\\r\\n)\n if (maxColumnIndex - generatedColumn > 2) {\n return false;\n }\n\n // Ignore mapping w/o source\n if (!source) {\n return false;\n }\n\n // Don't check the same source twice. It covers most cases even though not 100% reliable\n if (context.mapReferenceEOLSources.has(source)) {\n return true;\n }\n\n const content = consumer.sourceContentFor(source, true);\n\n // Content is needed to detect EOL\n if (!content) {\n return false;\n }\n\n const { line, column } = consumer.originalPositionFor({\n line: generatedLine,\n column: generatedColumn,\n });\n\n if (line === null || column === null) {\n return false;\n }\n\n if (isEOLAtPosition(content, [line, column])) {\n context.mapReferenceEOLSources.add(source);\n\n return true;\n }\n\n return false;\n}\n\nfunction checkInvalidMappingColumn(context: ComputeFileSizesContext): void {\n const { line, generatedLine, generatedColumn } = context;\n const maxColumnIndex = line.length - 1;\n\n if (generatedColumn > maxColumnIndex) {\n if (isReferencingEOL(context, maxColumnIndex)) {\n return;\n }\n\n throw new AppError({\n code: 'InvalidMappingColumn',\n generatedLine,\n generatedColumn,\n maxColumn: line.length,\n });\n }\n}\n\n/**\n * Calculate the number of bytes contributed by each source file\n */\nfunction computeFileSizes(\n sourceMapData: SourceMapData,\n options: ExploreOptions,\n coverageRanges?: CoverageRange[][]\n): FileSizes {\n const { consumer, codeFileContent: fileContent } = sourceMapData;\n\n const sourceMapComment = getSourceMapComment(fileContent);\n // Remove inline source map comment, source map file comment and trailing EOLs\n const sourceContent = fileContent.replace(sourceMapComment, '').trim();\n\n const eol = detectEOL(fileContent);\n // Assume only one type of EOL is used\n const lines = sourceContent.split(eol);\n\n const mappingRanges: MappingRange[][] = [];\n\n const context: ComputeFileSizesContext = {\n generatedLine: -1,\n generatedColumn: -1,\n line: '',\n source: null,\n consumer,\n mapReferenceEOLSources: new Set(),\n };\n\n consumer.computeColumnSpans();\n consumer.eachMapping(({ source, generatedLine, generatedColumn, lastGeneratedColumn }) => {\n // Columns are 0-based, Lines are 1-based\n\n const lineIndex = generatedLine - 1;\n const line = lines[lineIndex];\n\n if (line === undefined) {\n if (options.noBorderChecks) {\n return;\n }\n\n throw new AppError({\n code: 'InvalidMappingLine',\n generatedLine,\n maxLine: lines.length,\n });\n }\n\n context.generatedLine = generatedLine;\n context.generatedColumn = lastGeneratedColumn || generatedColumn;\n context.line = line;\n context.source = source;\n\n if (!options.noBorderChecks) {\n checkInvalidMappingColumn(context);\n }\n\n const start = generatedColumn;\n const end = lastGeneratedColumn === null ? line.length - 1 : lastGeneratedColumn;\n\n const lineRanges = mappingRanges[lineIndex] || [];\n\n lineRanges.push({\n start,\n end,\n source: source === null ? NO_SOURCE_KEY : source,\n });\n\n mappingRanges[lineIndex] = lineRanges;\n });\n\n let files: FileDataMap = {};\n let mappedBytes = 0;\n\n // To account unicode measure byte length rather than symbols count\n const getSize = options.gzip ? gzipSize.sync : Buffer.byteLength;\n\n mappingRanges.forEach((lineRanges, lineIndex) => {\n const line = lines[lineIndex];\n const mergedRanges = mergeRanges(lineRanges);\n\n mergedRanges.forEach(({ start, end, source }) => {\n const rangeString = line.substring(start, end + 1);\n const rangeByteLength = getSize(rangeString);\n\n if (!files[source]) {\n files[source] = { size: 0 };\n }\n\n files[source].size += rangeByteLength;\n\n mappedBytes += rangeByteLength;\n });\n\n if (coverageRanges) {\n files = setCoveredSizes(line, files, mergedRanges, coverageRanges[lineIndex]);\n }\n });\n\n const sourceMapCommentBytes = getSize(sourceMapComment);\n const eolBytes = getOccurrencesCount(eol, fileContent) * Buffer.byteLength(eol);\n const totalBytes = getSize(fileContent);\n let unmappedBytes: number | undefined;\n\n if (!options.excludeSourceMapComment) {\n files[SOURCE_MAP_COMMENT_KEY] = { size: sourceMapCommentBytes };\n }\n\n if (!options.onlyMapped) {\n unmappedBytes = totalBytes - mappedBytes - sourceMapCommentBytes - eolBytes;\n files[UNMAPPED_KEY] = { size: unmappedBytes };\n }\n\n if (eolBytes > 0) {\n files[EOL_KEY] = { size: eolBytes };\n }\n\n return {\n ...(options.excludeSourceMapComment\n ? { totalBytes: totalBytes - sourceMapCommentBytes }\n : { totalBytes }),\n mappedBytes,\n ...(!options.onlyMapped && { unmappedBytes }),\n eolBytes,\n sourceMapCommentBytes,\n files,\n };\n}\n\nexport function adjustSourcePaths(fileSizeMap: FileDataMap, options: ExploreOptions): FileDataMap {\n if (!options.noRoot) {\n const prefix = getCommonPathPrefix(Object.keys(fileSizeMap));\n const length = prefix.length;\n\n if (length) {\n fileSizeMap = mapKeys(fileSizeMap, (size, source) => source.slice(length));\n }\n }\n\n if (options.replaceMap) {\n fileSizeMap = Object.entries(options.replaceMap).reduce((result, [before, after]) => {\n const regexp = new RegExp(before, 'g');\n\n return mapKeys(result, (size, source) => source.replace(regexp, after));\n }, fileSizeMap);\n }\n\n return fileSizeMap;\n}\n"]}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/// <reference types="node" />
|
2
|
-
import { MappingRange } from './types';
|
2
|
+
import type { MappingRange } from './types';
|
3
3
|
export declare function getFileContent(file: Buffer | string): string;
|
4
4
|
export declare function formatBytes(bytes: number, decimals?: number): string;
|
5
5
|
export declare function formatPercent(value: number, total: number, fractionDigits?: number): string;
|
package/{dist → lib}/helpers.js
RENAMED
@@ -1,10 +1,11 @@
|
|
1
1
|
'use strict';
|
2
2
|
var __importDefault =
|
3
3
|
(this && this.__importDefault) ||
|
4
|
-
function(mod) {
|
4
|
+
function (mod) {
|
5
5
|
return mod && mod.__esModule ? mod : { default: mod };
|
6
6
|
};
|
7
7
|
Object.defineProperty(exports, '__esModule', { value: true });
|
8
|
+
exports.mergeRanges = exports.isEOLAtPosition = exports.getOccurrencesCount = exports.detectEOL = exports.getFirstRegexMatch = exports.getCommonPathPrefix = exports.formatPercent = exports.formatBytes = exports.getFileContent = void 0;
|
8
9
|
const fs_1 = __importDefault(require('fs'));
|
9
10
|
function getFileContent(file) {
|
10
11
|
const buffer = Buffer.isBuffer(file) ? file : fs_1.default.readFileSync(file);
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/lib/helpers.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AAIpB,SAAgB,cAAc,CAAC,IAAqB;IAClD,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAEpE,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC3B,CAAC;AAJD,wCAIC;AAED,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAEzE,MAAM,SAAS,GAAG,IAAI,CAAC;AAMvB,SAAgB,WAAW,CAAC,KAAa,EAAE,QAAQ,GAAG,CAAC;IACrD,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;IAE7C,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;IACnE,MAAM,KAAK,GAAG,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAGpD,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;AAC1E,CAAC;AARD,kCAQC;AAED,SAAgB,aAAa,CAAC,KAAa,EA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AAC;IAElC,IAAI,WAAW,KAAK,CAAC,EAAE;QACrB,OAAO,MAAM,CAAC;KACf;IAED,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAEvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC,IAAI,CAAC,EAAE;QACvC,MAAM,aAAa,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC;QAChE,MAAM,aAAa,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;QAEhE,IAAI,aAAa,IAAI,aAAa,EAAE;YAClC,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;SACrB;aAAM;YACL,YAAY,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;YAE1C,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;SACtC;KACF;IAED,YAAY,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;IAE1C,OAAO,YAAY,CAAC;AACtB,CAAC;AA1BD,kCA0BC","sourcesContent":["import fs from 'fs';\n\nimport type { MappingRange } from './types';\n\nexport function getFileContent(file: Buffer | string): string {\n const buffer = Buffer.isBuffer(file) ? file : fs.readFileSync(file);\n\n return buffer.toString();\n}\n\nconst BYTE_SIZES = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n// Bytes\nconst SIZE_BASE = 1024;\n\n/**\n * Format number of bytes as string\n * Source @see https://stackoverflow.com/a/18650828/388951\n */\nexport function formatBytes(bytes: number, decimals = 2): string {\n if (bytes === 0) return `0 ${BYTE_SIZES[0]}`;\n\n const exponent = Math.floor(Math.log(bytes) / Math.log(SIZE_BASE));\n const value = bytes / Math.pow(SIZE_BASE, exponent);\n\n // `parseFloat` removes trailing zero\n return `${parseFloat(value.toFixed(decimals))} ${BYTE_SIZES[exponent]}`;\n}\n\nexport function formatPercent(value: number, total: number, fractionDigits?: number): string {\n return ((100.0 * value) / total).toFixed(fractionDigits);\n}\n\nconst PATH_SEPARATOR_REGEX = /(\\/)/;\n\n/**\n * Find common path prefix\n * Source @see http://stackoverflow.com/a/1917041/388951\n * @param paths List of filenames\n */\nexport function getCommonPathPrefix(paths: string[]): string {\n if (paths.length < 2) return '';\n\n const A = paths.concat().sort();\n const a1 = A[0].split(PATH_SEPARATOR_REGEX);\n const a2 = A[A.length - 1].split(PATH_SEPARATOR_REGEX);\n const L = a1.length;\n\n let i = 0;\n\n while (i < L && a1[i] === a2[i]) i++;\n\n return a1.slice(0, i).join('');\n}\n\nexport function getFirstRegexMatch(regex: RegExp, string: string): string | null {\n const match = string.match(regex);\n\n return match ? match[0] : null;\n}\n\nconst LF = '\\n';\nconst CR_LF = '\\r\\n';\n\nexport function detectEOL(content: string): string {\n return content.includes(CR_LF) ? CR_LF : LF;\n}\n\n/**\n * Get `subString` occurrences count in `string`\n */\nexport function getOccurrencesCount(subString: string, string: string): number {\n let count = 0;\n let position = string.indexOf(subString);\n const subStringLength = subString.length;\n\n while (position !== -1) {\n count += 1;\n position = string.indexOf(subString, position + subStringLength);\n }\n\n return count;\n}\n\nexport function isEOLAtPosition(string: string, [line, column]: [number, number]): boolean {\n const eol = detectEOL(string);\n const eolLength = eol.length;\n\n let lineOffset = 0;\n\n for (let lineIndex = 1; lineIndex < line; lineIndex += 1) {\n lineOffset = string.indexOf(eol, lineOffset);\n\n if (lineOffset === -1) {\n return false;\n }\n\n lineOffset += eolLength;\n }\n\n return string.substr(lineOffset + column, eolLength) === eol;\n}\n\n/**\n * Merge consecutive ranges with the same source\n */\nexport function mergeRanges(ranges: MappingRange[]): MappingRange[] {\n const mergedRanges: MappingRange[] = [];\n const rangesCount = ranges.length;\n\n if (rangesCount === 1) {\n return ranges;\n }\n\n let { start, end, source } = ranges[0];\n\n for (let i = 1; i < rangesCount; i += 1) {\n const isSourceMatch = ranges[i].source === ranges[i - 1].source;\n const isConsecutive = ranges[i].start - ranges[i - 1].end === 1;\n\n if (isSourceMatch && isConsecutive) {\n end = ranges[i].end;\n } else {\n mergedRanges.push({ start, end, source });\n\n ({ start, end, source } = ranges[i]);\n }\n }\n\n mergedRanges.push({ start, end, source });\n\n return mergedRanges;\n}\n"]}
|
package/{dist → lib}/html.d.ts
RENAMED
@@ -1,5 +1,6 @@
|
|
1
|
-
import { ExploreOptions, ExploreBundleResult, FileDataMap } from './types';
|
1
|
+
import type { ExploreOptions, ExploreBundleResult, FileDataMap } from './types';
|
2
2
|
export declare function generateHtml(exploreResults: ExploreBundleResult[], options: ExploreOptions): string;
|
3
|
+
export declare function makeMergedTreeDataMap(treeData: WebTreeData[]): WebTreeData;
|
3
4
|
interface WebTreeMapNode {
|
4
5
|
name: string;
|
5
6
|
data: {
|
@@ -9,5 +10,9 @@ interface WebTreeMapNode {
|
|
9
10
|
};
|
10
11
|
children?: WebTreeMapNode[];
|
11
12
|
}
|
13
|
+
export interface WebTreeData {
|
14
|
+
name: string;
|
15
|
+
data: WebTreeMapNode;
|
16
|
+
}
|
12
17
|
export declare function getWebTreeMapData(files: FileDataMap): WebTreeMapNode;
|
13
18
|
export {};
|