source-map-explorer 2.3.0 → 2.4.2

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -126,11 +126,15 @@ 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
 
133
- * `--gzip`: calculate gzip size. It also sets `onlyMapped` flag
135
+ * `--gzip`: Calculate gzip size. It also sets `onlyMapped` flag
136
+
137
+ * `--sort`: Sort filenames
134
138
 
135
139
  <details>
136
140
  <summary>Examples</summary>
@@ -143,7 +147,7 @@ source-map-explorer -h
143
147
  ```
144
148
  Analyze and debug space usage through source maps.
145
149
  Usage:
146
- source-map-explorer script.js [script.js.map] [--json [result.json] | --html [result.html] | --tsv [result.csv]] [-m | --only-mapped] [--exclude-source-map] [--gzip] [--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]
147
151
 
148
152
  Output:
149
153
  --json If filename specified save output as JSON to specified file otherwise output to stdout. [string]
@@ -160,9 +164,11 @@ Options:
160
164
  --only-mapped, -m Exclude "unmapped" bytes from the output. This will result in total counts less than the file size [boolean]
161
165
  --exclude-source-map Exclude source map comment size from output [boolean]
162
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]
163
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
164
169
  [string]
165
170
  --gzip Calculate gzip size. It also sets onlyMapped flag [boolean]
171
+ --sort Sort filenames [boolean]
166
172
  -h, --help Show help [boolean]
167
173
 
168
174
  Examples:
@@ -294,10 +300,10 @@ source-map-explorer script.js --tsv --no-root
294
300
  ### On error
295
301
  Errors will be displayed only if no output flags specified
296
302
  ```
297
- source-map-explore with-unmapped.js no-map.js
303
+ source-map-explore with-unmapped.js no-map-comment.js
298
304
  ```
299
305
  ```
300
- no-map.js
306
+ no-map-comment.js
301
307
  Unable to find a source map.
302
308
  See https://github.com/danvk/source-map-explorer/blob/master/README.md#generating-source-maps
303
309
  with-unmapped.js
@@ -326,6 +332,7 @@ with-unmapped.js
326
332
  * `format`: [string] - `'json'`, `'tsv'` or `'html'`
327
333
  * `filename`: [string] - Filename to save output to
328
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.
329
336
  * `replaceMap`: <[Object]<{ [from: [string]]: [string] }>> - Mapping for replacement, see `--replace`, `--with` options above for details.
330
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
331
338
  * `gzip`: [boolean] - Calculate gzip size. It also sets `onlyMapped` flag
@@ -555,9 +562,14 @@ source-map-explorer path/to/foo.min.js{,.map}
555
562
 
556
563
  ### Other source map tools
557
564
 
558
- [source-map-visualization](https://sokra.github.io/source-map-visualization)
565
+ - [source-map-visualization](https://sokra.github.io/source-map-visualization)
566
+
567
+ - [bundle-wizard](https://github.com/aholachek/bundle-wizard) - Easier analysis of webapp entry points (uses source-map-explorer under the hood)
568
+
569
+ ### Learn about source maps
559
570
 
560
- [bundle-wizard](https://github.com/aholachek/bundle-wizard): Easier analysis of webapp entry points (uses source-map-explorer under the hood)
571
+ - [Standard](https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit)
572
+ - [Anatomy of source maps](https://www.bugsnag.com/blog/source-maps)
561
573
 
562
574
  [demo]: https://cdn.rawgit.com/danvk/source-map-explorer/08b0e130cb9345f9061760bf8a8d9136ea60b457/demo.html
563
575
  [another demo]: https://cdn.rawgit.com/danvk/source-map-explorer/08b0e130cb9345f9061760bf8a8d9136ea60b457/demo-bug.html
package/dist/api.d.ts CHANGED
@@ -1,10 +1,4 @@
1
- import { BundlesAndFileTokens, ExploreOptions, ExploreResult, Bundle } from './index';
2
- /**
3
- * Analyze bundle(s)
4
- */
1
+ import type { Bundle, BundlesAndFileTokens, ExploreOptions, ExploreResult } from './types';
5
2
  export declare function explore(bundlesAndFileTokens: BundlesAndFileTokens, options?: ExploreOptions): Promise<ExploreResult>;
6
- /**
7
- * Expand list of file tokens into a list of bundles
8
- */
9
3
  export declare function getBundles(fileTokens: string[]): Bundle[];
10
4
  export declare function getBundleName(bundle: Bundle): string;
package/dist/api.js CHANGED
@@ -1,105 +1,69 @@
1
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
-
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
7
+ Object.defineProperty(exports, '__esModule', { value: true });
8
+ const glob_1 = __importDefault(require('glob'));
9
+ const lodash_1 = require('lodash');
10
+ const explore_1 = require('./explore');
11
+ const app_error_1 = require('./app-error');
12
+ const output_1 = require('./output');
13
+ const coverage_1 = require('./coverage');
26
14
  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
15
  if (options.gzip) {
30
16
  options.onlyMapped = true;
31
17
  }
32
-
33
18
  return options;
34
19
  }
35
- /**
36
- * Analyze bundle(s)
37
- */
38
-
39
20
  async function explore(bundlesAndFileTokens, options = {}) {
40
21
  bundlesAndFileTokens = Array.isArray(bundlesAndFileTokens)
41
22
  ? bundlesAndFileTokens
42
23
  : [bundlesAndFileTokens];
43
-
44
24
  if (bundlesAndFileTokens.length === 0) {
45
- throw new _appError.AppError({
46
- code: 'NoBundles',
47
- });
25
+ throw new app_error_1.AppError({ code: 'NoBundles' });
48
26
  }
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
-
27
+ adjustOptions(options);
28
+ const [fileTokens, bundles] = lodash_1.partition(bundlesAndFileTokens, lodash_1.isString);
54
29
  bundles.push(...getBundles(fileTokens));
55
- (0, _coverage.addCoverageRanges)(bundles, options.coverage);
30
+ coverage_1.addCoverageRanges(bundles, options.coverage);
56
31
  const results = await Promise.all(
57
- bundles.map(bundle =>
58
- (0, _explore.exploreBundle)(bundle, options).catch(error => onExploreError(bundle, error))
32
+ bundles.map((bundle) =>
33
+ explore_1.exploreBundle(bundle, options).catch((error) => onExploreError(bundle, error))
59
34
  )
60
35
  );
61
- const exploreResult = getExploreResult(results, options); // Reject if none of results is successful
62
-
36
+ const exploreResult = getExploreResult(results, options);
63
37
  if (exploreResult.bundles.length === 0) {
64
38
  return Promise.reject(exploreResult);
65
39
  }
66
-
67
- (0, _output.saveOutputToFile)(exploreResult, options);
40
+ output_1.saveOutputToFile(exploreResult, options);
68
41
  return exploreResult;
69
42
  }
70
- /**
71
- * Expand list of file tokens into a list of bundles
72
- */
73
-
43
+ exports.explore = explore;
74
44
  function getBundles(fileTokens) {
75
- const filenames = (0, _lodash.flatMap)(fileTokens, filePath =>
76
- _glob.default.hasMagic(filePath) ? expandGlob(filePath) : filePath
45
+ const filenames = lodash_1.flatMap(fileTokens, (filePath) =>
46
+ glob_1.default.hasMagic(filePath) ? expandGlob(filePath) : filePath
77
47
  );
78
- const [mapFilenames, codeFilenames] = (0, _lodash.partition)(filenames, filename =>
48
+ const [mapFilenames, codeFilenames] = lodash_1.partition(filenames, (filename) =>
79
49
  filename.endsWith('.map')
80
50
  );
81
- return codeFilenames.map(code => ({
51
+ return codeFilenames.map((code) => ({
82
52
  code,
83
- map: mapFilenames.find(filename => filename === `${code}.map`),
53
+ map: mapFilenames.find((filename) => filename === `${code}.map`),
84
54
  }));
85
55
  }
86
-
56
+ exports.getBundles = getBundles;
87
57
  function expandGlob(pattern) {
88
- // Make sure pattern match `.map` files as well
89
58
  if (pattern.endsWith('.js')) {
90
59
  pattern = `${pattern}?(.map)`;
91
60
  }
92
-
93
- return _glob.default.sync(pattern);
61
+ return glob_1.default.sync(pattern);
94
62
  }
95
-
96
63
  function getBundleName(bundle) {
97
64
  return Buffer.isBuffer(bundle.code) ? 'Buffer' : bundle.code;
98
65
  }
99
- /**
100
- * Handle error during bundle processing
101
- */
102
-
66
+ exports.getBundleName = getBundleName;
103
67
  function onExploreError(bundle, error) {
104
68
  return {
105
69
  bundleName: getBundleName(bundle),
@@ -108,53 +72,54 @@ function onExploreError(bundle, error) {
108
72
  error,
109
73
  };
110
74
  }
111
-
75
+ function sortFilenames(bundles) {
76
+ return bundles.map((bundle) => ({
77
+ ...bundle,
78
+ files: lodash_1.fromPairs(lodash_1.sortBy(lodash_1.toPairs(bundle.files), 0)),
79
+ }));
80
+ }
112
81
  function getExploreResult(results, options) {
113
- const [bundles, errors] = (0, _lodash.partition)(results, result => 'files' in result);
82
+ const [bundles, errors] = lodash_1.partition(results, (result) => 'files' in result);
83
+ let sortedBundles = lodash_1.sortBy(bundles, (bundle) => bundle.bundleName);
84
+ if (options.sort) {
85
+ sortedBundles = sortFilenames(sortedBundles);
86
+ }
114
87
  errors.push(...getPostExploreErrors(bundles));
115
88
  return {
116
- bundles,
89
+ bundles: sortedBundles,
117
90
  errors,
118
- ...(bundles.length > 0 && {
119
- output: (0, _output.formatOutput)(bundles, options),
120
- }),
91
+ ...(bundles.length > 0 && { output: output_1.formatOutput(sortedBundles, options) }),
121
92
  };
122
93
  }
123
-
124
94
  function getPostExploreErrors(exploreBundleResults) {
125
95
  const errors = [];
126
96
  const isSingleBundle = exploreBundleResults.length === 1;
127
-
128
97
  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
-
98
+ const { bundleName, files, totalBytes } = result;
131
99
  if (isSingleBundle) {
132
100
  const filenames = Object.keys(files).filter(
133
- filename => !_explore.SPECIAL_FILENAMES.includes(filename)
101
+ (filename) => !explore_1.SPECIAL_FILENAMES.includes(filename)
134
102
  );
135
-
136
103
  if (filenames.length === 1) {
137
104
  errors.push({
138
105
  bundleName,
139
106
  isWarning: true,
140
107
  code: 'OneSourceSourceMap',
141
- message: (0, _appError.getErrorMessage)({
108
+ message: app_error_1.getErrorMessage({
142
109
  code: 'OneSourceSourceMap',
143
110
  filename: filenames[0],
144
111
  }),
145
112
  });
146
113
  }
147
114
  }
148
-
149
- if (files[_explore.UNMAPPED_KEY] !== undefined) {
150
- const { size: unmappedBytes } = files[_explore.UNMAPPED_KEY];
151
-
115
+ if (files[explore_1.UNMAPPED_KEY] !== undefined) {
116
+ const { size: unmappedBytes } = files[explore_1.UNMAPPED_KEY];
152
117
  if (unmappedBytes) {
153
118
  errors.push({
154
119
  bundleName,
155
120
  isWarning: true,
156
121
  code: 'UnmappedBytes',
157
- message: (0, _appError.getErrorMessage)({
122
+ message: app_error_1.getErrorMessage({
158
123
  code: 'UnmappedBytes',
159
124
  unmappedBytes,
160
125
  totalBytes,
@@ -163,6 +128,6 @@ function getPostExploreErrors(exploreBundleResults) {
163
128
  }
164
129
  }
165
130
  }
166
-
167
131
  return errors;
168
132
  }
133
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/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,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE7C,MAAM,OAAO,GAAG,MAA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I,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,5 @@
1
1
  /// <reference types="node" />
2
- import { ErrorCode } from './index';
2
+ import type { ErrorCode } from './types';
3
3
  export declare class AppError extends Error {
4
4
  code?: ErrorCode;
5
5
  cause?: Error;
package/dist/app-error.js CHANGED
@@ -1,18 +1,9 @@
1
1
  'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true,
5
- });
6
- exports.getErrorMessage = getErrorMessage;
7
- exports.SOURCE_MAP_INFO_URL = exports.AppError = void 0;
8
-
9
- var _helpers = require('./helpers');
10
-
11
- // If we need advanced error consider using https://github.com/joyent/node-verror
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
+ const helpers_1 = require('./helpers');
12
4
  class AppError extends Error {
13
5
  constructor(errorContext, error) {
14
- super(); // https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
15
-
6
+ super();
16
7
  Object.setPrototypeOf(this, AppError.prototype);
17
8
  const message = getErrorMessage(errorContext);
18
9
  this.message = error ? `${message}: ${error.message}` : message;
@@ -20,69 +11,57 @@ class AppError extends Error {
20
11
  Error.captureStackTrace(this, AppError);
21
12
  }
22
13
  }
23
-
24
14
  exports.AppError = AppError;
25
- const SOURCE_MAP_INFO_URL =
15
+ exports.SOURCE_MAP_INFO_URL =
26
16
  'https://github.com/danvk/source-map-explorer/blob/master/README.md#generating-source-maps';
27
- exports.SOURCE_MAP_INFO_URL = SOURCE_MAP_INFO_URL;
28
-
29
17
  function getErrorMessage(context) {
30
18
  switch (context.code) {
31
19
  case 'NoBundles':
32
20
  return 'No file(s) provided';
33
-
34
21
  case 'NoSourceMap':
35
22
  return `Unable to find a source map.
36
- See ${SOURCE_MAP_INFO_URL}`;
37
-
23
+ See ${exports.SOURCE_MAP_INFO_URL}`;
38
24
  case 'OneSourceSourceMap': {
39
25
  return `Your source map only contains one source (${context.filename}).
40
26
  This can happen if you use browserify+uglifyjs, for example, and don't set the --in-source-map flag to uglify.
41
- See ${SOURCE_MAP_INFO_URL}`;
27
+ See ${exports.SOURCE_MAP_INFO_URL}`;
42
28
  }
43
-
44
29
  case 'UnmappedBytes': {
45
30
  const { unmappedBytes, totalBytes } = context;
46
- const bytesString = (0, _helpers.formatPercent)(unmappedBytes, totalBytes, 2);
31
+ const bytesString = helpers_1.formatPercent(unmappedBytes, totalBytes, 2);
47
32
  return `Unable to map ${unmappedBytes}/${totalBytes} bytes (${bytesString}%)`;
48
33
  }
49
-
50
34
  case 'InvalidMappingLine': {
51
35
  const { generatedLine, maxLine } = context;
52
36
  return `Your source map refers to generated line ${generatedLine}, but the source only contains ${maxLine} line(s).
53
37
  Check that you are using the correct source map.`;
54
38
  }
55
-
56
39
  case 'InvalidMappingColumn': {
57
- const { generatedLine, generatedColumn, maxColumn } = context; // Add 1 since generatedColumn is 0-based
58
-
59
- return `Your source map refers to generated column ${generatedColumn +
60
- 1} on line ${generatedLine}, but the source only contains ${maxColumn} column(s) on that line.
40
+ const { generatedLine, generatedColumn, maxColumn } = context;
41
+ return `Your source map refers to generated column ${
42
+ generatedColumn + 1
43
+ } on line ${generatedLine}, but the source only contains ${maxColumn} column(s) on that line.
61
44
  Check that you are using the correct source map.`;
62
45
  }
63
-
64
46
  case 'CannotSaveFile':
65
47
  return 'Unable to save HTML to file';
66
-
67
48
  case 'CannotCreateTempFile':
68
49
  return 'Unable to create a temporary HTML file';
69
-
70
50
  case 'CannotOpenTempFile': {
71
51
  const { error, tempFile } = context;
72
52
  return `Unable to open web browser. ${error.toString().trim()}
73
53
  Either run with --html, --json, --tsv, --file, or view HTML for the visualization at:
74
54
  ${tempFile}`;
75
55
  }
76
-
77
56
  case 'CannotOpenCoverageFile': {
78
57
  return 'Unable to open/parse coverage file';
79
58
  }
80
-
81
59
  case 'NoCoverageMatches': {
82
60
  return 'No matched bundles found for coverages';
83
61
  }
84
-
85
62
  default:
86
63
  return 'Unknown error';
87
64
  }
88
65
  }
66
+ exports.getErrorMessage = getErrorMessage;
67
+ //# sourceMappingURL=app-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-error.js","sourceRoot":"","sources":["../src/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,IAAI,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;QAEhD,MAAM,OAAO,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;QAE9C,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,OAAO,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QAChE,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC;QAE9B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;CACF;AAhBD,4BAgBC;AAEY,QAAA,mBAAmB,GAC9B,2FAA2F,CAAC;AAmD9F,SAAgB,eAAe,CAAC,OAAqB;IACnD,QAAQ,OAAO,CAAC,IAAI,EAAE;QACpB,KAAK,WAAW;YACd,OAAO,qBAAqB,CAAC;QAE/B,KAAK,aAAa;YAChB,OAAO;MACP,2BAAmB,EAAE,CAAC;QAExB,KAAK,oBAAoB,CAAC,CAAC;YACzB,OAAO,6CAA6C,OAAO,CAAC,QAAQ;;MAEpE,2BAAmB,EAAE,CAAC;SACvB;QAED,KAAK,eAAe,CAAC,CAAC;YACpB,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;YAE9C,MAAM,WAAW,GAAG,uBAAa,CAAC,aAAa,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;YAEhE,OAAO,iBAAiB,aAAa,IAAI,UAAU,WAAW,WAAW,IAAI,CAAC;SAC/E;QAED,KAAK,oBAAoB,CAAC,CAAC;YACzB,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;YAE3C,OAAO,4CAA4C,aAAa,kCAAkC,OAAO;iDAC9D,CAAC;SAC7C;QAED,KAAK,sBAAsB,CAAC,CAAC;YAC3B,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;YAG9D,OAAO,8CACL,eAAe,GAAG,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"]}
package/dist/cli.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { ErrorContext } from './app-error';
2
+ import type { ErrorContext } from './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;