source-map-explorer 2.3.1 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -7
- package/{dist → bin}/cli.d.ts +1 -1
- package/{dist → bin}/cli.js +59 -93
- package/bin/cli.js.map +1 -0
- package/{dist → lib}/api.d.ts +1 -7
- package/lib/api.js +134 -0
- package/lib/api.js.map +1 -0
- package/{dist → lib}/app-error.d.ts +1 -1
- package/{dist → lib}/app-error.js +14 -34
- package/lib/app-error.js.map +1 -0
- package/{dist → lib}/coverage.d.ts +1 -10
- package/{dist → lib}/coverage.js +28 -125
- package/lib/coverage.js.map +1 -0
- package/{dist → lib}/explore.d.ts +1 -4
- package/lib/explore.js +227 -0
- package/lib/explore.js.map +1 -0
- package/{dist → lib}/helpers.d.ts +2 -16
- package/{dist → lib}/helpers.js +36 -68
- package/lib/helpers.js.map +1 -0
- package/{dist → lib}/html.d.ts +6 -7
- package/lib/html.js +191 -0
- package/lib/html.js.map +1 -0
- package/lib/index.d.ts +4 -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 +22 -53
- package/lib/output.js.map +1 -0
- package/{dist → lib}/tree-viz.ejs +0 -0
- package/lib/types.d.ts +121 -0
- package/{dist → lib}/vendor/webtreemap.css +0 -0
- package/{dist → lib}/vendor/webtreemap.js +0 -0
- package/package.json +72 -72
- package/dist/api.js +0 -168
- package/dist/explore.js +0 -258
- package/dist/html.js +0 -213
- package/dist/index.d.ts +0 -92
- package/dist/index.js +0 -38
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/lib/output.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,4CAAoB;AAEpB,iCAAsC;AACtC,2CAAuC;AAIvC,SAAgB,YAAY,CAC1B,OAA8B,EAC9B,OAAuB;IAEvB,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,OAAO;KACR;IAED,QAAQ,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE;QAC7B,KAAK,MAAM;YACT,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAEjD,KAAK,KAAK;YACR,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC;QAE9B,KAAK,MAAM;YACT,OAAO,mBAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KACzC;AACH,CAAC;AAlBD,oCAkBC;AAED,SAAS,WAAW,CAAC,OAA8B;IACjD,MAAM,KAAK,GAAG,CAAC,cAAc,CAAC,CAAC;IAE/B,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAChC,IAAI,KAAK,GAAG,CAAC,EAAE;YAEb,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;SAChB;QAED,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;aACzB,GAAG,CAAmB,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;aAC9D,IAAI,CAAC,eAAe,CAAC;aACrB,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;YAC1B,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,KAAK,IAAI,EAAE,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,IAAI,CAAC,YAAE,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED,SAAS,eAAe,CAAC,CAAC,EAAE,KAAK,CAAmB,EAAE,CAAC,EAAE,KAAK,CAAmB;IAC/E,OAAO,KAAK,GAAG,KAAK,CAAC;AACvB,CAAC;AAED,SAAgB,gBAAgB,CAAC,MAAqB,EAAE,OAAuB;IAC7E,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,OAAO;KACR;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC;IAEzC,IAAI,MAAM,IAAI,QAAQ,EAAE;QACtB,IAAI;YACF,MAAM,GAAG,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAEnC,YAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACvC,YAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;SACpC;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,IAAI,oBAAQ,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,EAAE,KAAK,CAAC,CAAC;SACvD;KACF;AACH,CAAC;AAlBD,4CAkBC","sourcesContent":["import os from 'os';\nimport path from 'path';\nimport fs from 'fs';\n\nimport { generateHtml } from './html';\nimport { AppError } from './app-error';\n\nimport type { ExploreBundleResult, ExploreOptions, ExploreResult } from './types';\n\nexport function formatOutput(\n results: ExploreBundleResult[],\n options: ExploreOptions\n): string | undefined {\n if (!options.output) {\n return;\n }\n\n switch (options.output.format) {\n case 'json':\n return JSON.stringify({ results }, null, ' ');\n\n case 'tsv':\n return outputAsTsv(results);\n\n case 'html':\n return generateHtml(results, options);\n }\n}\n\nfunction outputAsTsv(results: ExploreBundleResult[]): string {\n const lines = ['Source\\tSize'];\n\n results.forEach((bundle, index) => {\n if (index > 0) {\n // Separate bundles by empty line\n lines.push('');\n }\n\n Object.entries(bundle.files)\n .map<[string, number]>(([source, data]) => [source, data.size])\n .sort(sortFilesBySize)\n .forEach(([source, size]) => {\n lines.push(`${source}\\t${size}`);\n });\n });\n\n return lines.join(os.EOL);\n}\n\nfunction sortFilesBySize([, aSize]: [string, number], [, bSize]: [string, number]): number {\n return bSize - aSize;\n}\n\nexport function saveOutputToFile(result: ExploreResult, options: ExploreOptions): void {\n if (!options.output) {\n return;\n }\n\n const output = result.output;\n const filename = options.output.filename;\n\n if (output && filename) {\n try {\n const dir = path.dirname(filename);\n\n fs.mkdirSync(dir, { recursive: true });\n fs.writeFileSync(filename, output);\n } catch (error) {\n throw new AppError({ code: 'CannotSaveFile' }, error);\n }\n }\n}\n"]}
|
|
File without changes
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export interface FileData {
|
|
2
|
+
size: number;
|
|
3
|
+
coveredSize?: number;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export type FileDataMap = Record<string, FileData>;
|
|
7
|
+
|
|
8
|
+
export interface FileSizes {
|
|
9
|
+
files: FileDataMap;
|
|
10
|
+
mappedBytes: number;
|
|
11
|
+
unmappedBytes?: number;
|
|
12
|
+
eolBytes: number;
|
|
13
|
+
sourceMapCommentBytes: number;
|
|
14
|
+
totalBytes: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export 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
|
+
|
|
31
|
+
export type File = string | Buffer;
|
|
32
|
+
|
|
33
|
+
export type ReplaceMap = Record<string, string>;
|
|
34
|
+
|
|
35
|
+
type OutputFormat = 'json' | 'tsv' | 'html';
|
|
36
|
+
|
|
37
|
+
/** Represents single bundle */
|
|
38
|
+
export interface Bundle {
|
|
39
|
+
code: File;
|
|
40
|
+
map?: File;
|
|
41
|
+
coverageRanges?: ColumnsRange[][];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export 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
|
+
|
|
68
|
+
export interface ExploreResult {
|
|
69
|
+
bundles: ExploreBundleResult[];
|
|
70
|
+
/** Result as a string - either JSON, TSV or HTML */
|
|
71
|
+
output?: string;
|
|
72
|
+
errors: ExploreErrorResult[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface ExploreBundleResult extends FileSizes {
|
|
76
|
+
bundleName: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface ExploreErrorResult {
|
|
80
|
+
bundleName: string;
|
|
81
|
+
code: string;
|
|
82
|
+
message: string;
|
|
83
|
+
error?: NodeJS.ErrnoException;
|
|
84
|
+
isWarning?: boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type BundlesAndFileTokens = (Bundle | string)[] | Bundle | string;
|
|
88
|
+
|
|
89
|
+
/** Represents inclusive range (e.g. [0,5] six columns) */
|
|
90
|
+
export interface ColumnsRange {
|
|
91
|
+
/** Fist column index */
|
|
92
|
+
start: number;
|
|
93
|
+
/** Last column index */
|
|
94
|
+
end: number;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface MappingRange extends ColumnsRange {
|
|
98
|
+
source: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Represents exclusive range (e.g. [0,5) - four columns) */
|
|
102
|
+
export interface Coverage {
|
|
103
|
+
url: string;
|
|
104
|
+
ranges: CoverageRange[];
|
|
105
|
+
/** File content as one line */
|
|
106
|
+
text: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export 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
|
|
117
|
+
declare module 'source-map' {
|
|
118
|
+
export interface MappingItem {
|
|
119
|
+
lastGeneratedColumn: number | null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "source-map-explorer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Analyze and debug space usage through source maps",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "lib/index.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"source-map-explorer": "
|
|
7
|
+
"source-map-explorer": "bin/cli.js",
|
|
8
|
+
"sme": "bin/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=10"
|
|
8
12
|
},
|
|
9
13
|
"scripts": {
|
|
10
|
-
"pretest": "npm run build",
|
|
11
|
-
"test": "cross-env NODE_ENV=test mocha",
|
|
12
|
-
"test:update-snapshots": "cross-env SNAPSHOT_UPDATE=1 npm run test",
|
|
13
|
-
"coverage": "nyc --reporter=lcov --reporter=text npm test",
|
|
14
|
-
"lint": "eslint src/**/*.* tests/*.* --fix",
|
|
15
|
-
"build:clean": "rimraf dist/**/*",
|
|
16
|
-
"build:compile": "babel src --out-dir dist --extensions \".ts\" --ignore src/*.d.ts",
|
|
17
|
-
"build:copy": "copyfiles -u 1 src/vendor/*.* src/tree-viz.ejs dist",
|
|
18
|
-
"build:format": "prettier dist/*.js --write",
|
|
19
|
-
"build:types": "tsc -p tsconfig.build.json",
|
|
20
14
|
"build": "npm-run-all build:*",
|
|
21
|
-
"watch": "chokidar src
|
|
15
|
+
"watch": "chokidar src/**/*.* -c \"npm run build\" --silent --initial --debounce=700",
|
|
16
|
+
"test:unit": "mocha --config tests/.mocharc.unit.js",
|
|
17
|
+
"test:e2e": "mocha --config tests/.mocharc.e2e.js",
|
|
18
|
+
"test:perf": "mocha --config tests/.mocharc.perf.js",
|
|
19
|
+
"test": "npm-run-all test:unit test:e2e test:perf",
|
|
20
|
+
"coverage": "nyc --reporter=lcov --reporter=text npm run test:unit",
|
|
21
|
+
"test:update-snapshots": "cross-env SNAPSHOT_UPDATE=1 npm run test",
|
|
22
|
+
"test:generate-data": "ts-node --dir tests generate-data/index.ts",
|
|
23
|
+
"build:clean": "rimraf lib/**/* bin/**/*",
|
|
24
|
+
"build:compile": "tsc --build",
|
|
25
|
+
"build:copy": "copyfiles -u 2 src/lib/vendor/*.* src/lib/tree-viz.ejs src/lib/types.d.ts lib",
|
|
26
|
+
"build:format": "prettier lib/*.js bin/*.js --write",
|
|
27
|
+
"pretest:e2e": "npm run build",
|
|
28
|
+
"coverage:ci": "nyc npm run test:unit && nyc report --reporter=text-lcov | coveralls",
|
|
29
|
+
"lint": "eslint src/**/*.* tests/**/*.* --fix",
|
|
22
30
|
"update-dependencies": "npx npm-check-updates -u && npm i",
|
|
23
31
|
"prepublishOnly": "npm run build"
|
|
24
32
|
},
|
|
@@ -37,21 +45,6 @@
|
|
|
37
45
|
"useRelativePath": true,
|
|
38
46
|
"extension": ".snap"
|
|
39
47
|
},
|
|
40
|
-
"nyc": {
|
|
41
|
-
"require": [
|
|
42
|
-
"@babel/register"
|
|
43
|
-
],
|
|
44
|
-
"extension": [
|
|
45
|
-
".ts"
|
|
46
|
-
],
|
|
47
|
-
"include": "src",
|
|
48
|
-
"exclude": [
|
|
49
|
-
"src/cli.ts",
|
|
50
|
-
"src/index.ts"
|
|
51
|
-
],
|
|
52
|
-
"sourceMap": false,
|
|
53
|
-
"instrument": false
|
|
54
|
-
},
|
|
55
48
|
"repository": {
|
|
56
49
|
"type": "git",
|
|
57
50
|
"url": "git+https://github.com/danvk/source-map-explorer.git"
|
|
@@ -62,76 +55,83 @@
|
|
|
62
55
|
"minification"
|
|
63
56
|
],
|
|
64
57
|
"author": "Dan Vanderkam (danvdk@gmail.com)",
|
|
58
|
+
"maintainers": [
|
|
59
|
+
"Nikolay Borzov <nikolay.n.borzov@gmail.com>"
|
|
60
|
+
],
|
|
65
61
|
"license": "Apache-2.0",
|
|
66
62
|
"bugs": {
|
|
67
63
|
"url": "https://github.com/danvk/source-map-explorer/issues"
|
|
68
64
|
},
|
|
69
65
|
"homepage": "https://github.com/danvk/source-map-explorer#readme",
|
|
70
66
|
"files": [
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
67
|
+
"bin",
|
|
68
|
+
"lib",
|
|
69
|
+
"!*.tsbuildinfo"
|
|
74
70
|
],
|
|
75
71
|
"dependencies": {
|
|
76
72
|
"btoa": "^1.2.1",
|
|
77
|
-
"chalk": "^
|
|
73
|
+
"chalk": "^4.1.0",
|
|
78
74
|
"convert-source-map": "^1.7.0",
|
|
79
|
-
"ejs": "^3.
|
|
75
|
+
"ejs": "^3.1.5",
|
|
80
76
|
"escape-html": "^1.0.3",
|
|
81
77
|
"glob": "^7.1.6",
|
|
82
78
|
"gzip-size": "^5.1.1",
|
|
83
|
-
"lodash": "^4.17.
|
|
84
|
-
"open": "^7.0
|
|
79
|
+
"lodash": "^4.17.20",
|
|
80
|
+
"open": "^7.1.0",
|
|
85
81
|
"source-map": "^0.7.3",
|
|
86
82
|
"temp": "^0.9.1",
|
|
87
|
-
"yargs": "^15.1
|
|
83
|
+
"yargs": "^15.4.1"
|
|
88
84
|
},
|
|
89
85
|
"devDependencies": {
|
|
90
|
-
"@babel/
|
|
91
|
-
"@babel/
|
|
92
|
-
"@
|
|
93
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
|
|
94
|
-
"@babel/preset-env": "^7.8.4",
|
|
95
|
-
"@babel/preset-typescript": "^7.8.3",
|
|
96
|
-
"@babel/register": "^7.8.3",
|
|
86
|
+
"@babel/core": "^7.11.1",
|
|
87
|
+
"@babel/preset-env": "^7.11.0",
|
|
88
|
+
"@istanbuljs/nyc-config-typescript": "^1.0.1",
|
|
97
89
|
"@smpx/snap-shot-it": "^6.6.1",
|
|
90
|
+
"@types/browserify": "^12.0.36",
|
|
98
91
|
"@types/btoa": "^1.2.3",
|
|
99
|
-
"@types/chai": "^4.2.
|
|
100
|
-
"@types/chai-as-promised": "^7.1.
|
|
92
|
+
"@types/chai": "^4.2.12",
|
|
93
|
+
"@types/chai-as-promised": "^7.1.3",
|
|
101
94
|
"@types/concat-stream": "^1.6.0",
|
|
102
95
|
"@types/convert-source-map": "^1.5.1",
|
|
103
|
-
"@types/cross-spawn": "^6.0.
|
|
104
|
-
"@types/ejs": "^3.0.
|
|
105
|
-
"@types/escape-html": "0.0
|
|
106
|
-
"@types/glob": "^7.1.
|
|
107
|
-
"@types/lodash": "^4.14.
|
|
108
|
-
"@types/mocha": "^
|
|
109
|
-
"@types/node": "^
|
|
110
|
-
"@types/rimraf": "^
|
|
96
|
+
"@types/cross-spawn": "^6.0.2",
|
|
97
|
+
"@types/ejs": "^3.0.4",
|
|
98
|
+
"@types/escape-html": "1.0.0",
|
|
99
|
+
"@types/glob": "^7.1.3",
|
|
100
|
+
"@types/lodash": "^4.14.159",
|
|
101
|
+
"@types/mocha": "^8.0.3",
|
|
102
|
+
"@types/node": "^14.x",
|
|
103
|
+
"@types/rimraf": "^3.0.0",
|
|
111
104
|
"@types/temp": "^0.8.34",
|
|
112
|
-
"@types/yargs": "^15.0.
|
|
113
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
114
|
-
"@typescript-eslint/parser": "^
|
|
115
|
-
"
|
|
105
|
+
"@types/yargs": "^15.0.5",
|
|
106
|
+
"@typescript-eslint/eslint-plugin": "^3.9.1",
|
|
107
|
+
"@typescript-eslint/parser": "^3.9.1",
|
|
108
|
+
"babelify": "^10.0.0",
|
|
109
|
+
"browserify": "^16.5.2",
|
|
116
110
|
"chai": "^4.2.0",
|
|
117
111
|
"chai-as-promised": "^7.1.1",
|
|
118
112
|
"chokidar-cli": "^2.1.0",
|
|
119
113
|
"concat-stream": "^2.0.0",
|
|
120
|
-
"copyfiles": "^2.
|
|
121
|
-
"coveralls": "^3.0
|
|
122
|
-
"cross-env": "^7.0.
|
|
123
|
-
"cross-spawn": "^7.0.
|
|
124
|
-
"eslint": "^
|
|
125
|
-
"eslint-config-prettier": "^6.
|
|
126
|
-
"eslint-plugin-prettier": "^3.1.
|
|
127
|
-
"
|
|
128
|
-
"
|
|
129
|
-
"
|
|
114
|
+
"copyfiles": "^2.3.0",
|
|
115
|
+
"coveralls": "^3.1.0",
|
|
116
|
+
"cross-env": "^7.0.2",
|
|
117
|
+
"cross-spawn": "^7.0.3",
|
|
118
|
+
"eslint": "^7.7.0",
|
|
119
|
+
"eslint-config-prettier": "^6.11.0",
|
|
120
|
+
"eslint-plugin-prettier": "^3.1.4",
|
|
121
|
+
"generate-source-map": "0.0.5",
|
|
122
|
+
"husky": "^4.2.5",
|
|
123
|
+
"lint-staged": "^10.2.11",
|
|
124
|
+
"mocha": "^8.1.1",
|
|
130
125
|
"npm-run-all": "^4.1.5",
|
|
131
|
-
"nyc": "^15.
|
|
132
|
-
"prettier": "^
|
|
133
|
-
"rewiremock": "^3.
|
|
126
|
+
"nyc": "^15.1.0",
|
|
127
|
+
"prettier": "^2.0.5",
|
|
128
|
+
"rewiremock": "^3.14.3",
|
|
134
129
|
"rimraf": "^3.0.2",
|
|
135
|
-
"
|
|
130
|
+
"source-map-support": "^0.5.19",
|
|
131
|
+
"terser": "^5.2.1",
|
|
132
|
+
"terser-webpack-plugin": "^4.1.0",
|
|
133
|
+
"ts-node": "^8.10.2",
|
|
134
|
+
"typescript": "^3.9.7",
|
|
135
|
+
"webpack": "^4.44.1"
|
|
136
136
|
}
|
|
137
137
|
}
|
package/dist/api.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true,
|
|
5
|
-
});
|
|
6
|
-
exports.explore = explore;
|
|
7
|
-
exports.getBundles = getBundles;
|
|
8
|
-
exports.getBundleName = getBundleName;
|
|
9
|
-
|
|
10
|
-
var _glob = _interopRequireDefault(require('glob'));
|
|
11
|
-
|
|
12
|
-
var _lodash = require('lodash');
|
|
13
|
-
|
|
14
|
-
var _explore = require('./explore');
|
|
15
|
-
|
|
16
|
-
var _appError = require('./app-error');
|
|
17
|
-
|
|
18
|
-
var _output = require('./output');
|
|
19
|
-
|
|
20
|
-
var _coverage = require('./coverage');
|
|
21
|
-
|
|
22
|
-
function _interopRequireDefault(obj) {
|
|
23
|
-
return obj && obj.__esModule ? obj : { default: obj };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function adjustOptions(options) {
|
|
27
|
-
/* Unmapped bytes cannot be calculate because it's impossible to get total size by summing files'
|
|
28
|
-
sizes when calculating gzip size for a file. */
|
|
29
|
-
if (options.gzip) {
|
|
30
|
-
options.onlyMapped = true;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return options;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Analyze bundle(s)
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
async function explore(bundlesAndFileTokens, options = {}) {
|
|
40
|
-
bundlesAndFileTokens = Array.isArray(bundlesAndFileTokens)
|
|
41
|
-
? bundlesAndFileTokens
|
|
42
|
-
: [bundlesAndFileTokens];
|
|
43
|
-
|
|
44
|
-
if (bundlesAndFileTokens.length === 0) {
|
|
45
|
-
throw new _appError.AppError({
|
|
46
|
-
code: 'NoBundles',
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
adjustOptions(options); // Separate bundles from file tokens
|
|
51
|
-
|
|
52
|
-
const [fileTokens, bundles] = (0, _lodash.partition)(bundlesAndFileTokens, _lodash.isString); // Get bundles from file tokens
|
|
53
|
-
|
|
54
|
-
bundles.push(...getBundles(fileTokens));
|
|
55
|
-
(0, _coverage.addCoverageRanges)(bundles, options.coverage);
|
|
56
|
-
const results = await Promise.all(
|
|
57
|
-
bundles.map(bundle =>
|
|
58
|
-
(0, _explore.exploreBundle)(bundle, options).catch(error => onExploreError(bundle, error))
|
|
59
|
-
)
|
|
60
|
-
);
|
|
61
|
-
const exploreResult = getExploreResult(results, options); // Reject if none of results is successful
|
|
62
|
-
|
|
63
|
-
if (exploreResult.bundles.length === 0) {
|
|
64
|
-
return Promise.reject(exploreResult);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
(0, _output.saveOutputToFile)(exploreResult, options);
|
|
68
|
-
return exploreResult;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Expand list of file tokens into a list of bundles
|
|
72
|
-
*/
|
|
73
|
-
|
|
74
|
-
function getBundles(fileTokens) {
|
|
75
|
-
const filenames = (0, _lodash.flatMap)(fileTokens, filePath =>
|
|
76
|
-
_glob.default.hasMagic(filePath) ? expandGlob(filePath) : filePath
|
|
77
|
-
);
|
|
78
|
-
const [mapFilenames, codeFilenames] = (0, _lodash.partition)(filenames, filename =>
|
|
79
|
-
filename.endsWith('.map')
|
|
80
|
-
);
|
|
81
|
-
return codeFilenames.map(code => ({
|
|
82
|
-
code,
|
|
83
|
-
map: mapFilenames.find(filename => filename === `${code}.map`),
|
|
84
|
-
}));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function expandGlob(pattern) {
|
|
88
|
-
// Make sure pattern match `.map` files as well
|
|
89
|
-
if (pattern.endsWith('.js')) {
|
|
90
|
-
pattern = `${pattern}?(.map)`;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return _glob.default.sync(pattern);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function getBundleName(bundle) {
|
|
97
|
-
return Buffer.isBuffer(bundle.code) ? 'Buffer' : bundle.code;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Handle error during bundle processing
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
function onExploreError(bundle, error) {
|
|
104
|
-
return {
|
|
105
|
-
bundleName: getBundleName(bundle),
|
|
106
|
-
code: error.code || 'Unknown',
|
|
107
|
-
message: error.message,
|
|
108
|
-
error,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function getExploreResult(results, options) {
|
|
113
|
-
const [bundles, errors] = (0, _lodash.partition)(results, result => 'files' in result);
|
|
114
|
-
errors.push(...getPostExploreErrors(bundles));
|
|
115
|
-
return {
|
|
116
|
-
bundles,
|
|
117
|
-
errors,
|
|
118
|
-
...(bundles.length > 0 && {
|
|
119
|
-
output: (0, _output.formatOutput)(bundles, options),
|
|
120
|
-
}),
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function getPostExploreErrors(exploreBundleResults) {
|
|
125
|
-
const errors = [];
|
|
126
|
-
const isSingleBundle = exploreBundleResults.length === 1;
|
|
127
|
-
|
|
128
|
-
for (const result of exploreBundleResults) {
|
|
129
|
-
const { bundleName, files, totalBytes } = result; // Check if source map contains only one file - this make result useless when exploring single bundle
|
|
130
|
-
|
|
131
|
-
if (isSingleBundle) {
|
|
132
|
-
const filenames = Object.keys(files).filter(
|
|
133
|
-
filename => !_explore.SPECIAL_FILENAMES.includes(filename)
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
if (filenames.length === 1) {
|
|
137
|
-
errors.push({
|
|
138
|
-
bundleName,
|
|
139
|
-
isWarning: true,
|
|
140
|
-
code: 'OneSourceSourceMap',
|
|
141
|
-
message: (0, _appError.getErrorMessage)({
|
|
142
|
-
code: 'OneSourceSourceMap',
|
|
143
|
-
filename: filenames[0],
|
|
144
|
-
}),
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (files[_explore.UNMAPPED_KEY] !== undefined) {
|
|
150
|
-
const { size: unmappedBytes } = files[_explore.UNMAPPED_KEY];
|
|
151
|
-
|
|
152
|
-
if (unmappedBytes) {
|
|
153
|
-
errors.push({
|
|
154
|
-
bundleName,
|
|
155
|
-
isWarning: true,
|
|
156
|
-
code: 'UnmappedBytes',
|
|
157
|
-
message: (0, _appError.getErrorMessage)({
|
|
158
|
-
code: 'UnmappedBytes',
|
|
159
|
-
unmappedBytes,
|
|
160
|
-
totalBytes,
|
|
161
|
-
}),
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return errors;
|
|
168
|
-
}
|