@parcel/utils 2.0.0-nightly.92 → 2.0.0-nightly.926

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.
Files changed (93) hide show
  1. package/.eslintrc.js +6 -6
  2. package/lib/DefaultMap.js +26 -5
  3. package/lib/Deferred.js +10 -2
  4. package/lib/PromiseQueue.js +21 -30
  5. package/lib/TapStream.js +10 -10
  6. package/lib/alternatives.js +134 -0
  7. package/lib/ansi-html.js +10 -2
  8. package/lib/blob.js +14 -6
  9. package/lib/collection.js +0 -11
  10. package/lib/config.js +107 -34
  11. package/lib/countLines.js +2 -2
  12. package/lib/dependency-location.js +3 -3
  13. package/lib/generateBuildMetrics.js +148 -0
  14. package/lib/generateCertificate.js +33 -8
  15. package/lib/getExisting.js +11 -3
  16. package/lib/getRootDir.js +18 -7
  17. package/lib/glob.js +53 -19
  18. package/lib/hash.js +44 -0
  19. package/lib/http-server.js +48 -10
  20. package/lib/index.js +280 -222
  21. package/lib/is-url.js +12 -2
  22. package/lib/isDirectoryInside.js +24 -0
  23. package/lib/objectHash.js +10 -2
  24. package/lib/openInBrowser.js +94 -0
  25. package/lib/path.js +33 -6
  26. package/lib/prettyDiagnostic.js +107 -25
  27. package/lib/relativeBundlePath.js +13 -7
  28. package/lib/relativeUrl.js +19 -3
  29. package/lib/replaceBundleReferences.js +91 -35
  30. package/lib/schema.js +104 -33
  31. package/lib/sourcemap.js +147 -0
  32. package/lib/stream.js +38 -3
  33. package/lib/urlJoin.js +25 -6
  34. package/package.json +22 -16
  35. package/src/DefaultMap.js +25 -1
  36. package/src/PromiseQueue.js +16 -12
  37. package/src/alternatives.js +143 -0
  38. package/src/ansi-html.js +2 -2
  39. package/src/blob.js +3 -3
  40. package/src/bundle-url.js +1 -1
  41. package/src/collection.js +2 -14
  42. package/src/config.js +67 -34
  43. package/src/countLines.js +5 -2
  44. package/src/debounce.js +1 -1
  45. package/src/dependency-location.js +11 -6
  46. package/src/generateBuildMetrics.js +158 -0
  47. package/src/generateCertificate.js +1 -1
  48. package/src/getCertificate.js +1 -1
  49. package/src/getExisting.js +1 -4
  50. package/src/getRootDir.js +1 -2
  51. package/src/glob.js +29 -11
  52. package/src/hash.js +34 -0
  53. package/src/http-server.js +10 -12
  54. package/src/index.js +49 -23
  55. package/src/is-url.js +1 -1
  56. package/src/isDirectoryInside.js +11 -0
  57. package/src/openInBrowser.js +64 -0
  58. package/src/path.js +38 -6
  59. package/src/prettyDiagnostic.js +59 -28
  60. package/src/relativeBundlePath.js +8 -13
  61. package/src/replaceBundleReferences.js +75 -39
  62. package/src/schema.js +101 -44
  63. package/src/sourcemap.js +135 -0
  64. package/src/stream.js +31 -1
  65. package/src/urlJoin.js +3 -1
  66. package/test/DefaultMap.test.js +8 -5
  67. package/test/input/sourcemap/referenced-min.js +2 -0
  68. package/test/input/sourcemap/referenced-min.js.map +6 -0
  69. package/test/input/sourcemap/source-root.js +2 -0
  70. package/test/input/sourcemap/source-root.js.map +7 -0
  71. package/test/objectHash.test.js +33 -0
  72. package/test/prettifyTime.test.js +17 -0
  73. package/test/replaceBundleReferences.test.js +268 -0
  74. package/test/sourcemap.test.js +207 -0
  75. package/test/throttle.test.js +1 -2
  76. package/test/urlJoin.test.js +37 -0
  77. package/lib/generateBundleReport.js +0 -38
  78. package/lib/loadSourceMapUrl.js +0 -33
  79. package/lib/md5.js +0 -35
  80. package/lib/prettyError.js +0 -43
  81. package/lib/promisify.js +0 -13
  82. package/lib/resolve.js +0 -93
  83. package/lib/serializeObject.js +0 -28
  84. package/src/generateBundleReport.js +0 -51
  85. package/src/loadSourceMapUrl.js +0 -33
  86. package/src/md5.js +0 -44
  87. package/src/prettyError.js +0 -54
  88. package/src/promisify.js +0 -13
  89. package/src/resolve.js +0 -123
  90. package/src/serializeObject.js +0 -22
  91. package/test/input/sourcemap/referenced.js +0 -7
  92. package/test/loadSourceMapUrl.test.js +0 -37
  93. package/test/prettyError.test.js +0 -104
@@ -0,0 +1,268 @@
1
+ // @flow strict-local
2
+
3
+ import type {NamedBundle, Dependency} from '@parcel/types';
4
+
5
+ import assert from 'assert';
6
+ import {getURLReplacement} from '../src/replaceBundleReferences';
7
+
8
+ describe('replace bundle references', () => {
9
+ it('Query params and named pipeline, relative', () => {
10
+ // $FlowFixMe
11
+ let fromBundle: NamedBundle = {
12
+ filePath: '/user/dist/reformat.html',
13
+ name: 'reformat.html',
14
+ // $FlowFixMe
15
+ target: {
16
+ distDir: '/user/dist',
17
+ publicUrl: '/',
18
+ },
19
+ };
20
+
21
+ // $FlowFixMe
22
+ let toBundle: NamedBundle = {
23
+ filePath:
24
+ '/user/dist/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
25
+ name: 'image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
26
+ // $FlowFixMe
27
+ target: {
28
+ distDir: '/user/dist',
29
+ publicUrl: '/',
30
+ },
31
+ };
32
+
33
+ // $FlowFixMe
34
+ let dependency: Dependency = {
35
+ id: '074b36596e3147e900a8ad17ceb5c90b',
36
+ specifier: 'url:./image.jpg?as=webp',
37
+ specifierType: 'esm',
38
+ };
39
+
40
+ let result = getURLReplacement({
41
+ dependency,
42
+ fromBundle,
43
+ toBundle,
44
+ relative: true,
45
+ });
46
+
47
+ assert.equal(
48
+ result.to,
49
+ 'image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
50
+ );
51
+ assert.equal(result.from, '074b36596e3147e900a8ad17ceb5c90b');
52
+ });
53
+
54
+ it('Query params and named pipeline, absolute', () => {
55
+ // $FlowFixMe
56
+ let fromBundle: NamedBundle = {
57
+ filePath: '/user/dist/reformat.html',
58
+ name: 'reformat.html',
59
+ // $FlowFixMe
60
+ target: {
61
+ distDir: '/user/dist',
62
+ publicUrl: '/',
63
+ },
64
+ };
65
+
66
+ // $FlowFixMe
67
+ let toBundle: NamedBundle = {
68
+ filePath:
69
+ '/user/dist/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
70
+ name: 'image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
71
+ // $FlowFixMe
72
+ target: {
73
+ distDir: '/user/dist',
74
+ publicUrl: '/',
75
+ },
76
+ };
77
+
78
+ // $FlowFixMe
79
+ let dependency: Dependency = {
80
+ id: '074b36596e3147e900a8ad17ceb5c90b',
81
+ specifier: 'url:./image.jpg?as=webp',
82
+ specifierType: 'esm',
83
+ };
84
+
85
+ let result = getURLReplacement({
86
+ dependency,
87
+ fromBundle,
88
+ toBundle,
89
+ relative: false,
90
+ });
91
+
92
+ assert.equal(
93
+ result.to,
94
+ '/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
95
+ );
96
+ assert.equal(result.from, '074b36596e3147e900a8ad17ceb5c90b');
97
+ });
98
+
99
+ it('Custom Public URL', () => {
100
+ // $FlowFixMe
101
+ let fromBundle: NamedBundle = {
102
+ filePath: '/user/dist/reformat.html',
103
+ name: 'reformat.html',
104
+ // $FlowFixMe
105
+ target: {
106
+ distDir: '/user/dist',
107
+ publicUrl: 'https://test.com/static',
108
+ },
109
+ };
110
+
111
+ // $FlowFixMe
112
+ let toBundle: NamedBundle = {
113
+ filePath:
114
+ '/user/dist/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
115
+ name: 'image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
116
+ // $FlowFixMe
117
+ target: {
118
+ distDir: '/user/dist',
119
+ publicUrl: 'https://test.com/static',
120
+ },
121
+ };
122
+
123
+ // $FlowFixMe
124
+ let dependency: Dependency = {
125
+ id: '074b36596e314797845a8ad17ceb5c9b',
126
+ specifier: './image.jpg',
127
+ specifierType: 'esm',
128
+ };
129
+
130
+ let result = getURLReplacement({
131
+ dependency,
132
+ fromBundle,
133
+ toBundle,
134
+ relative: false,
135
+ });
136
+
137
+ assert.equal(
138
+ result.to,
139
+ 'https://test.com/static/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
140
+ );
141
+ assert.equal(result.from, '074b36596e314797845a8ad17ceb5c9b');
142
+ });
143
+
144
+ it('Relative with folders in between', () => {
145
+ // $FlowFixMe
146
+ let fromBundle: NamedBundle = {
147
+ filePath: '/user/dist/reformat.html',
148
+ name: 'reformat.html',
149
+ // $FlowFixMe
150
+ target: {
151
+ distDir: '/user/dist',
152
+ publicUrl: 'https://test.com/static',
153
+ },
154
+ };
155
+
156
+ // $FlowFixMe
157
+ let toBundle: NamedBundle = {
158
+ filePath:
159
+ '/user/dist/assets/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
160
+ name: 'image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
161
+ // $FlowFixMe
162
+ target: {
163
+ distDir: '/user/dist/assets',
164
+ publicUrl: 'https://test.com/static',
165
+ },
166
+ };
167
+
168
+ // $FlowFixMe
169
+ let dependency: Dependency = {
170
+ id: '074b36596e3147e900a8ad17ceb5c90b',
171
+ specifier: 'url:./image.jpg?as=webp',
172
+ specifierType: 'esm',
173
+ };
174
+
175
+ let result = getURLReplacement({
176
+ dependency,
177
+ fromBundle,
178
+ toBundle,
179
+ relative: true,
180
+ });
181
+
182
+ assert.equal(
183
+ result.to,
184
+ 'assets/image.HASH_REF_87f9d66c16c2216ccc7e5664cf089305.webp',
185
+ );
186
+ assert.equal(result.from, '074b36596e3147e900a8ad17ceb5c90b');
187
+ });
188
+
189
+ it('should work with bundle names with colons, relative', () => {
190
+ // $FlowFixMe
191
+ let fromBundle: NamedBundle = {
192
+ filePath: '/user/dist/reformat.html',
193
+ name: 'reformat.html',
194
+ // $FlowFixMe
195
+ target: {
196
+ distDir: '/user/dist',
197
+ publicUrl: '/',
198
+ },
199
+ };
200
+
201
+ // $FlowFixMe
202
+ let toBundle: NamedBundle = {
203
+ filePath: '/user/dist/a:b:c.html',
204
+ name: 'a:b:c.html',
205
+ // $FlowFixMe
206
+ target: {
207
+ distDir: '/user/dist',
208
+ publicUrl: '/',
209
+ },
210
+ };
211
+
212
+ // $FlowFixMe
213
+ let dependency: Dependency = {
214
+ id: '074b36596e3147e900a8ad17ceb5c90b',
215
+ specifier: './a:b:c.html',
216
+ specifierType: 'esm',
217
+ };
218
+
219
+ let result = getURLReplacement({
220
+ dependency,
221
+ fromBundle,
222
+ toBundle,
223
+ relative: true,
224
+ });
225
+
226
+ assert.equal(result.to, './a:b:c.html');
227
+ });
228
+
229
+ it('should work with bundle names with colons, absolute', () => {
230
+ // $FlowFixMe
231
+ let fromBundle: NamedBundle = {
232
+ filePath: '/user/dist/reformat.html',
233
+ name: 'reformat.html',
234
+ // $FlowFixMe
235
+ target: {
236
+ distDir: '/user/dist',
237
+ publicUrl: '/',
238
+ },
239
+ };
240
+
241
+ // $FlowFixMe
242
+ let toBundle: NamedBundle = {
243
+ filePath: '/user/dist/a:b:c.html',
244
+ name: 'a:b:c.html',
245
+ // $FlowFixMe
246
+ target: {
247
+ distDir: '/user/dist',
248
+ publicUrl: '/',
249
+ },
250
+ };
251
+
252
+ // $FlowFixMe
253
+ let dependency: Dependency = {
254
+ id: '074b36596e3147e900a8ad17ceb5c90b',
255
+ specifier: './a:b:c.html',
256
+ specifierType: 'esm',
257
+ };
258
+
259
+ let result = getURLReplacement({
260
+ dependency,
261
+ fromBundle,
262
+ toBundle,
263
+ relative: false,
264
+ });
265
+
266
+ assert.equal(result.to, '/a:b:c.html');
267
+ });
268
+ });
@@ -0,0 +1,207 @@
1
+ import assert from 'assert';
2
+ import {
3
+ matchSourceMappingURL,
4
+ loadSourceMapUrl,
5
+ loadSourceMap,
6
+ } from '../src/sourcemap';
7
+ import {NodeFS} from '@parcel/fs';
8
+ import path from 'path';
9
+
10
+ const fs = new NodeFS();
11
+
12
+ describe('loadSourceMap', () => {
13
+ it('should not match sourceMappingURL when not at the end of the bundle', () => {
14
+ // Code example taken from livescript.js (issue #2408 in parcel-bundler)
15
+ // This snippet lead to JSAsset.js being mislead and incorrectly trying to
16
+ // load (due to false-positive match) sourcemap before fix was introduced
17
+ let code = fs.readFileSync(
18
+ path.join(__dirname, './input/sourcemap/no-sourcemap.js'),
19
+ 'utf-8',
20
+ );
21
+
22
+ assert(!matchSourceMappingURL(code));
23
+ });
24
+
25
+ it('should match referenced-min sourceMappingURL when correctly inserted at end of the bundle', () => {
26
+ let code = fs.readFileSync(
27
+ path.join(__dirname, './input/sourcemap/referenced-min.js'),
28
+ 'utf-8',
29
+ );
30
+
31
+ assert(!!matchSourceMappingURL(code));
32
+ });
33
+
34
+ it('should match inline sourceMappingURL when correctly inserted at end of the bundle', () => {
35
+ // inline source map taken from https://github.com/thlorenz/inline-source-map
36
+ let code = fs.readFileSync(
37
+ path.join(__dirname, './input/sourcemap/inline.js'),
38
+ 'utf-8',
39
+ );
40
+
41
+ assert(!!matchSourceMappingURL(code));
42
+ });
43
+
44
+ it('Should be able to load sourcemap data from a url reference', async () => {
45
+ let filename = path.join(__dirname, './input/sourcemap/referenced-min.js');
46
+ let contents = fs.readFileSync(filename, 'utf-8');
47
+
48
+ let foundMap = await loadSourceMapUrl(fs, filename, contents);
49
+ assert.equal(foundMap.url, 'file://referenced-min.js.map');
50
+ assert.equal(
51
+ foundMap.filename,
52
+ path.join(__dirname, 'input/sourcemap/referenced-min.js.map'),
53
+ );
54
+ assert.deepEqual(foundMap.map, {
55
+ version: 3,
56
+ sources: ['./referenced.js'],
57
+ names: ['hello', 'l', 'o', 'console', 'log'],
58
+ mappings:
59
+ 'AAAA,SAASA,QACP,IAAIC,EAAI,QACNC,EAAI,QACNC,QAAQC,IAAIH,EAAI,IAAMC,EAAI,KAE5BF',
60
+ });
61
+ });
62
+
63
+ it('Should be able to load sourcemap data from an inline url reference', async () => {
64
+ let filename = path.join(__dirname, './input/sourcemap/inline.js');
65
+ let contents = fs.readFileSync(filename, 'utf-8');
66
+
67
+ let foundMap = await loadSourceMapUrl(fs, filename, contents);
68
+ assert.equal(
69
+ foundMap.url,
70
+ 'data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmb28uanMiLCJiYXIuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O1VBQ0c7Ozs7Ozs7Ozs7Ozs7O3NCQ0RIO3NCQUNBIn0=',
71
+ );
72
+ assert.equal(foundMap.filename, filename);
73
+ assert.deepEqual(foundMap.map, {
74
+ version: 3,
75
+ file: '',
76
+ sources: ['foo.js', 'bar.js'],
77
+ names: [],
78
+ mappings: ';;;;;;;;;UACG;;;;;;;;;;;;;;sBCDH;sBACA',
79
+ });
80
+ });
81
+
82
+ it('Should be able to load a SourceMap instance from a file', async () => {
83
+ let filename = path.join(__dirname, './input/sourcemap/referenced-min.js');
84
+ let contents = fs.readFileSync(filename, 'utf-8');
85
+
86
+ let map = await loadSourceMap(filename, contents, {
87
+ fs,
88
+ projectRoot: __dirname,
89
+ });
90
+
91
+ assert(!!map);
92
+
93
+ let parsedMap = map.getMap();
94
+ assert.deepEqual(parsedMap.sources, ['input/sourcemap/referenced.js']);
95
+ assert.deepEqual(parsedMap.names, ['hello', 'l', 'o', 'console', 'log']);
96
+ assert.deepEqual(parsedMap.mappings, [
97
+ {
98
+ generated: {line: 1, column: 0},
99
+ original: {line: 1, column: 0},
100
+ source: 0,
101
+ },
102
+ {
103
+ generated: {line: 1, column: 9},
104
+ original: {line: 1, column: 9},
105
+ source: 0,
106
+ name: 0,
107
+ },
108
+ {
109
+ generated: {line: 1, column: 17},
110
+ original: {line: 2, column: 2},
111
+ source: 0,
112
+ },
113
+ {
114
+ generated: {line: 1, column: 21},
115
+ original: {line: 2, column: 6},
116
+ source: 0,
117
+ name: 1,
118
+ },
119
+ {
120
+ generated: {line: 1, column: 23},
121
+ original: {line: 2, column: 10},
122
+ source: 0,
123
+ },
124
+ {
125
+ generated: {line: 1, column: 31},
126
+ original: {line: 3, column: 4},
127
+ source: 0,
128
+ name: 2,
129
+ },
130
+ {
131
+ generated: {line: 1, column: 33},
132
+ original: {line: 3, column: 8},
133
+ source: 0,
134
+ },
135
+ {
136
+ generated: {line: 1, column: 41},
137
+ original: {line: 4, column: 2},
138
+ source: 0,
139
+ name: 3,
140
+ },
141
+ {
142
+ generated: {line: 1, column: 49},
143
+ original: {line: 4, column: 10},
144
+ source: 0,
145
+ name: 4,
146
+ },
147
+ {
148
+ generated: {line: 1, column: 53},
149
+ original: {line: 4, column: 14},
150
+ source: 0,
151
+ name: 1,
152
+ },
153
+ {
154
+ generated: {line: 1, column: 55},
155
+ original: {line: 4, column: 18},
156
+ source: 0,
157
+ },
158
+ {
159
+ generated: {line: 1, column: 59},
160
+ original: {line: 4, column: 24},
161
+ source: 0,
162
+ name: 2,
163
+ },
164
+ {
165
+ generated: {line: 1, column: 61},
166
+ original: {line: 4, column: 28},
167
+ source: 0,
168
+ },
169
+ {
170
+ generated: {line: 1, column: 66},
171
+ original: {line: 6, column: 0},
172
+ source: 0,
173
+ name: 0,
174
+ },
175
+ ]);
176
+ });
177
+
178
+ it('Should remap sources when using sourceRoot', async () => {
179
+ let filename = path.join(__dirname, './input/sourcemap/referenced-min.js');
180
+ let contents = fs.readFileSync(filename, 'utf-8');
181
+
182
+ let map = await loadSourceMap(filename, contents, {
183
+ fs,
184
+ projectRoot: __dirname,
185
+ });
186
+
187
+ assert(!!map);
188
+
189
+ let parsedMap = map.getMap();
190
+ assert.deepEqual(parsedMap.sources, ['input/sourcemap/referenced.js']);
191
+ });
192
+
193
+ it('Should remap sources when using sourceRoot', async () => {
194
+ let filename = path.join(__dirname, './input/sourcemap/source-root.js');
195
+ let contents = fs.readFileSync(filename, 'utf-8');
196
+
197
+ let map = await loadSourceMap(filename, contents, {
198
+ fs,
199
+ projectRoot: __dirname,
200
+ });
201
+
202
+ assert(!!map);
203
+
204
+ let parsedMap = map.getMap();
205
+ assert.deepEqual(parsedMap.sources, ['input/source.js']);
206
+ });
207
+ });
@@ -1,7 +1,6 @@
1
1
  // @flow strict-local
2
2
 
3
3
  import assert from 'assert';
4
- // $FlowFixMe
5
4
  import sinon from 'sinon';
6
5
  import throttle from '../src/throttle';
7
6
 
@@ -35,7 +34,7 @@ describe('throttle', () => {
35
34
 
36
35
  it('preserves the `this` when throttled functions are invoked', () => {
37
36
  let result;
38
- let throttled = throttle(function() {
37
+ let throttled = throttle(function () {
39
38
  result = this.bar;
40
39
  }, 100);
41
40
 
@@ -0,0 +1,37 @@
1
+ // @flow strict-local
2
+
3
+ import assert from 'assert';
4
+ import urlJoin from '../src/urlJoin';
5
+
6
+ describe('urlJoin', () => {
7
+ it('Should join two paths', () => {
8
+ let joinedUrl = urlJoin('/', './image.jpeg?test=test');
9
+ assert.equal(joinedUrl, '/image.jpeg?test=test');
10
+ });
11
+
12
+ it('Should join two paths with longer publicUrl', () => {
13
+ let joinedUrl = urlJoin('/static', './image.jpeg?test=test');
14
+ assert.equal(joinedUrl, '/static/image.jpeg?test=test');
15
+ });
16
+
17
+ it('Should join two paths with longer publicUrl', () => {
18
+ let joinedUrl = urlJoin('/static', 'image.jpeg?test=test');
19
+ assert.equal(joinedUrl, '/static/image.jpeg?test=test');
20
+ });
21
+
22
+ it('Should turn windows path into posix', () => {
23
+ let joinedUrl = urlJoin('/static', '.\\image.jpeg?test=test');
24
+ assert.equal(joinedUrl, '/static/image.jpeg?test=test');
25
+ });
26
+
27
+ it('should support paths with colons', () => {
28
+ let joinedUrl = urlJoin('/static', 'a:b:c.html');
29
+ assert.equal(joinedUrl, '/static/a:b:c.html');
30
+
31
+ joinedUrl = urlJoin('/static', '/a:b:c.html');
32
+ assert.equal(joinedUrl, '/static/a:b:c.html');
33
+
34
+ joinedUrl = urlJoin('/static', './a:b:c.html');
35
+ assert.equal(joinedUrl, '/static/a:b:c.html');
36
+ });
37
+ });
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = generateBundleReport;
7
-
8
- var _nullthrows = _interopRequireDefault(require("nullthrows"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- function generateBundleReport(bundleGraph, largestAssetCount = 10) {
13
- let bundles = [];
14
- bundleGraph.traverseBundles(bundle => {
15
- bundles.push(bundle);
16
- });
17
- bundles.sort((a, b) => b.stats.size - a.stats.size);
18
- return {
19
- bundles: bundles.map(bundle => {
20
- let assets = [];
21
- bundle.traverseAssets(asset => {
22
- assets.push(asset);
23
- });
24
- assets.sort((a, b) => b.stats.size - a.stats.size);
25
- return {
26
- filePath: (0, _nullthrows.default)(bundle.filePath),
27
- size: bundle.stats.size,
28
- time: bundle.stats.time,
29
- largestAssets: assets.slice(0, largestAssetCount).map(asset => ({
30
- filePath: asset.filePath,
31
- size: asset.stats.size,
32
- time: asset.stats.time
33
- })),
34
- totalAssets: assets.length
35
- };
36
- })
37
- };
38
- }
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.matchSourceMappingURL = matchSourceMappingURL;
7
- exports.default = loadSourceMapUrl;
8
-
9
- var _path = _interopRequireDefault(require("path"));
10
-
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
-
13
- const SOURCEMAP_RE = /(?:\/\*|\/\/)\s*[@#]\s*sourceMappingURL\s*=\s*([^\s*]+)(?:\s*\*\/)?\s*$/;
14
- const DATA_URL_RE = /^data:[^;]+(?:;charset=[^;]+)?;base64,(.*)/;
15
-
16
- function matchSourceMappingURL(contents) {
17
- return contents.match(SOURCEMAP_RE);
18
- }
19
-
20
- async function loadSourceMapUrl(fs, filename, contents) {
21
- let match = matchSourceMappingURL(contents);
22
-
23
- if (match) {
24
- let url = match[1].trim();
25
- let dataURLMatch = url.match(DATA_URL_RE);
26
- filename = dataURLMatch ? filename : _path.default.join(_path.default.dirname(filename), url);
27
- return {
28
- url,
29
- filename,
30
- map: JSON.parse(dataURLMatch ? Buffer.from(dataURLMatch[1], 'base64').toString() : await fs.readFile(filename, 'utf8'))
31
- };
32
- }
33
- }
package/lib/md5.js DELETED
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.md5FromString = md5FromString;
7
- exports.md5FromReadableStream = md5FromReadableStream;
8
- exports.md5FromObject = md5FromObject;
9
- exports.md5FromFilePath = md5FromFilePath;
10
-
11
- var _crypto = _interopRequireDefault(require("crypto"));
12
-
13
- var _collection = require("./collection");
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
-
17
- function md5FromString(string, encoding = 'hex') {
18
- return _crypto.default.createHash('md5').update(string).digest(encoding);
19
- }
20
-
21
- function md5FromReadableStream(stream) {
22
- return new Promise((resolve, reject) => {
23
- stream.pipe(_crypto.default.createHash('md5').setEncoding('hex')).on('finish', function () {
24
- resolve(this.read());
25
- }).on('error', reject);
26
- });
27
- }
28
-
29
- function md5FromObject(obj, encoding = 'hex') {
30
- return md5FromString(JSON.stringify((0, _collection.objectSortedEntriesDeep)(obj)), encoding);
31
- }
32
-
33
- function md5FromFilePath(fs, filePath) {
34
- return md5FromReadableStream(fs.createReadStream(filePath));
35
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = prettyError;
7
-
8
- function prettyError(err, opts = {}) {
9
- if (typeof err === 'string') {
10
- return {
11
- message: err
12
- };
13
- }
14
-
15
- let message = err.message;
16
-
17
- if (!message) {
18
- message = 'Unknown error';
19
- }
20
-
21
- if (err.fileName != null) {
22
- let fileName = err.fileName;
23
-
24
- if (err.loc) {
25
- fileName += `:${err.loc.line}:${err.loc.column}`;
26
- }
27
-
28
- message = `${fileName}: ${message}`;
29
- }
30
-
31
- let stack;
32
-
33
- if (err.codeFrame != null && err.codeFrame !== '') {
34
- stack = opts.color === true && err.highlightedCodeFrame || err.codeFrame;
35
- } else if (err.stack) {
36
- stack = err.stack.slice(err.stack.indexOf('\n') + 1);
37
- }
38
-
39
- return {
40
- message,
41
- stack
42
- };
43
- }
package/lib/promisify.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- module.exports = function (fn) {
4
- return function (...args) {
5
- return new Promise(function (resolve, reject) {
6
- fn(...args, function (err, ...res) {
7
- if (err) return reject(err);
8
- if (res.length === 1) return resolve(res[0]);
9
- resolve(res);
10
- });
11
- });
12
- };
13
- };