@parcel/utils 2.0.0-nightly.97 → 2.0.0-nightly.970

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 (100) hide show
  1. package/.eslintrc.js +6 -6
  2. package/lib/DefaultMap.js +0 -8
  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 +26 -8
  9. package/lib/collection.js +14 -11
  10. package/lib/config.js +145 -35
  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 +298 -224
  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/shared-buffer.js +31 -0
  32. package/lib/sourcemap.js +147 -0
  33. package/lib/stream.js +38 -3
  34. package/lib/urlJoin.js +25 -6
  35. package/package.json +27 -16
  36. package/src/DefaultMap.js +1 -1
  37. package/src/PromiseQueue.js +16 -12
  38. package/src/alternatives.js +143 -0
  39. package/src/ansi-html.js +2 -2
  40. package/src/blob.js +4 -3
  41. package/src/bundle-url.js +1 -1
  42. package/src/collection.js +14 -14
  43. package/src/config.js +100 -35
  44. package/src/countLines.js +5 -2
  45. package/src/debounce.js +1 -1
  46. package/src/dependency-location.js +11 -6
  47. package/src/generateBuildMetrics.js +158 -0
  48. package/src/generateCertificate.js +1 -1
  49. package/src/getCertificate.js +1 -1
  50. package/src/getExisting.js +1 -4
  51. package/src/getRootDir.js +1 -2
  52. package/src/glob.js +29 -11
  53. package/src/hash.js +34 -0
  54. package/src/http-server.js +10 -12
  55. package/src/index.js +52 -23
  56. package/src/is-url.js +1 -1
  57. package/src/isDirectoryInside.js +11 -0
  58. package/src/openInBrowser.js +64 -0
  59. package/src/path.js +38 -6
  60. package/src/prettyDiagnostic.js +58 -24
  61. package/src/relativeBundlePath.js +8 -13
  62. package/src/replaceBundleReferences.js +75 -39
  63. package/src/schema.js +101 -44
  64. package/src/shared-buffer.js +24 -0
  65. package/src/sourcemap.js +135 -0
  66. package/src/stream.js +31 -1
  67. package/src/urlJoin.js +3 -1
  68. package/test/DefaultMap.test.js +7 -4
  69. package/test/config.test.js +50 -0
  70. package/test/input/config/config.json +3 -0
  71. package/test/input/config/empty.json +0 -0
  72. package/test/input/config/empty.toml +0 -0
  73. package/test/input/sourcemap/referenced-min.js +2 -0
  74. package/test/input/sourcemap/referenced-min.js.map +6 -0
  75. package/test/input/sourcemap/source-root.js +2 -0
  76. package/test/input/sourcemap/source-root.js.map +7 -0
  77. package/test/objectHash.test.js +33 -0
  78. package/test/prettifyTime.test.js +17 -0
  79. package/test/replaceBundleReferences.test.js +268 -0
  80. package/test/sourcemap.test.js +207 -0
  81. package/test/throttle.test.js +1 -2
  82. package/test/urlJoin.test.js +37 -0
  83. package/lib/generateBundleReport.js +0 -38
  84. package/lib/loadSourceMapUrl.js +0 -33
  85. package/lib/md5.js +0 -35
  86. package/lib/prettyError.js +0 -43
  87. package/lib/promisify.js +0 -13
  88. package/lib/resolve.js +0 -93
  89. package/lib/serializeObject.js +0 -28
  90. package/src/.babelrc +0 -3
  91. package/src/generateBundleReport.js +0 -51
  92. package/src/loadSourceMapUrl.js +0 -33
  93. package/src/md5.js +0 -44
  94. package/src/prettyError.js +0 -54
  95. package/src/promisify.js +0 -13
  96. package/src/resolve.js +0 -123
  97. package/src/serializeObject.js +0 -22
  98. package/test/input/sourcemap/referenced.js +0 -7
  99. package/test/loadSourceMapUrl.test.js +0 -37
  100. package/test/prettyError.test.js +0 -104
package/lib/schema.js CHANGED
@@ -3,11 +3,38 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.fuzzySearch = fuzzySearch;
6
7
  exports.default = void 0;
7
8
 
8
- var _diagnostic = _interopRequireWildcard(require("@parcel/diagnostic"));
9
+ function _diagnostic() {
10
+ const data = _interopRequireWildcard(require("@parcel/diagnostic"));
9
11
 
10
- var _jsLevenshtein = _interopRequireDefault(require("js-levenshtein"));
12
+ _diagnostic = function () {
13
+ return data;
14
+ };
15
+
16
+ return data;
17
+ }
18
+
19
+ function _nullthrows() {
20
+ const data = _interopRequireDefault(require("nullthrows"));
21
+
22
+ _nullthrows = function () {
23
+ return data;
24
+ };
25
+
26
+ return data;
27
+ }
28
+
29
+ function _fastestLevenshtein() {
30
+ const data = _interopRequireDefault(require("fastest-levenshtein"));
31
+
32
+ _fastestLevenshtein = function () {
33
+ return data;
34
+ };
35
+
36
+ return data;
37
+ }
11
38
 
12
39
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
40
 
@@ -15,7 +42,7 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
15
42
 
16
43
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
44
 
18
- // $FlowFixMe untyped
45
+ // flowlint-next-line untyped-import:off
19
46
  function validateSchema(schema, data) {
20
47
  function walk(schemaAncestors, dataNode, dataPath) {
21
48
  let [schemaNode] = schemaAncestors;
@@ -68,10 +95,9 @@ function validateSchema(schema, data) {
68
95
  };
69
96
  }
70
97
  } else if (schemaNode.__validate) {
71
- let validationError = schemaNode.__validate(value); // $FlowFixMe
72
-
98
+ let validationError = schemaNode.__validate(value);
73
99
 
74
- if (validationError) {
100
+ if (typeof validationError == 'string') {
75
101
  return {
76
102
  type: 'other',
77
103
  dataType: 'value',
@@ -86,6 +112,27 @@ function validateSchema(schema, data) {
86
112
  break;
87
113
  }
88
114
 
115
+ case 'number':
116
+ {
117
+ // $FlowFixMe type was already checked
118
+ let value = dataNode;
119
+
120
+ if (schemaNode.enum) {
121
+ if (!schemaNode.enum.includes(value)) {
122
+ return {
123
+ type: 'enum',
124
+ dataType: 'value',
125
+ dataPath,
126
+ expectedValues: schemaNode.enum,
127
+ actualValue: value,
128
+ ancestors: schemaAncestors
129
+ };
130
+ }
131
+ }
132
+
133
+ break;
134
+ }
135
+
89
136
  case 'object':
90
137
  {
91
138
  let results = [];
@@ -97,7 +144,7 @@ function validateSchema(schema, data) {
97
144
  invalidProps = schemaNode.__forbiddenProperties.filter(val => keys.includes(val));
98
145
  results.push(...invalidProps.map(k => ({
99
146
  type: 'forbidden-prop',
100
- dataPath: dataPath + '/' + k,
147
+ dataPath: dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k),
101
148
  dataType: 'key',
102
149
  prop: k,
103
150
  expectedProps: Object.keys(schemaNode.properties),
@@ -113,7 +160,7 @@ function validateSchema(schema, data) {
113
160
  results.push(...missingKeys.map(k => ({
114
161
  type: 'missing-prop',
115
162
  dataPath,
116
- dataType: null,
163
+ dataType: 'value',
117
164
  prop: k,
118
165
  expectedProps: schemaNode.required,
119
166
  actualProps: keys,
@@ -132,7 +179,7 @@ function validateSchema(schema, data) {
132
179
  continue;
133
180
  } else if (k in schemaNode.properties) {
134
181
  let result = walk([schemaNode.properties[k]].concat(schemaAncestors), // $FlowFixMe type was already checked
135
- dataNode[k], dataPath + '/' + k);
182
+ dataNode[k], dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k));
136
183
  if (result) results.push(result);
137
184
  } else {
138
185
  if (typeof additionalProperties === 'boolean') {
@@ -140,7 +187,7 @@ function validateSchema(schema, data) {
140
187
  results.push({
141
188
  type: 'enum',
142
189
  dataType: 'key',
143
- dataPath: dataPath + '/' + k,
190
+ dataPath: dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k),
144
191
  expectedValues: Object.keys(schemaNode.properties).filter( // $FlowFixMe type was already checked
145
192
  p => !(p in dataNode)),
146
193
  actualValue: k,
@@ -150,7 +197,7 @@ function validateSchema(schema, data) {
150
197
  }
151
198
  } else {
152
199
  let result = walk([additionalProperties].concat(schemaAncestors), // $FlowFixMe type was already checked
153
- dataNode[k], dataPath + '/' + k);
200
+ dataNode[k], dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k));
154
201
  if (result) results.push(result);
155
202
  }
156
203
  }
@@ -222,18 +269,26 @@ var _default = validateSchema;
222
269
  exports.default = _default;
223
270
 
224
271
  function fuzzySearch(expectedValues, actualValue) {
225
- let result = expectedValues.map(exp => [exp, (0, _jsLevenshtein.default)(exp, actualValue)]).filter( // Remove if more than half of the string would need to be changed
272
+ let result = expectedValues.map(exp => [exp, _fastestLevenshtein().default.distance(exp, actualValue)]).filter( // Remove if more than half of the string would need to be changed
226
273
  ([, d]) => d * 2 < actualValue.length);
227
274
  result.sort(([, a], [, b]) => a - b);
228
275
  return result.map(([v]) => v);
229
276
  }
230
277
 
231
- validateSchema.diagnostic = function (schema, data, dataContentsPath, dataContents, origin, prependKey, message) {
232
- let errors = validateSchema(schema, data);
278
+ validateSchema.diagnostic = function (schema, data, origin, message) {
279
+ var _data$data;
280
+
281
+ if ('source' in data && 'data' in data && typeof data.source !== 'string' && !data) {
282
+ throw new Error('At least one of data.source and data.source must be defined!');
283
+ }
284
+
285
+ let object = data.map ? data.map.data : // $FlowFixMe we can assume it's a JSON object
286
+ (_data$data = data.data) !== null && _data$data !== void 0 ? _data$data : JSON.parse(data.source);
287
+ let errors = validateSchema(schema, object);
233
288
 
234
289
  if (errors.length) {
235
- let dataContentsString = typeof dataContents === 'string' ? dataContents : // $FlowFixMe
236
- JSON.stringify(dataContents, null, '\t');
290
+ var _data$filePath;
291
+
237
292
  let keys = errors.map(e => {
238
293
  let message;
239
294
 
@@ -272,8 +327,8 @@ validateSchema.diagnostic = function (schema, data, dataContentsPath, dataConten
272
327
  let likely = fuzzySearch(actualProps, prop);
273
328
 
274
329
  if (likely.length > 0) {
275
- message = `Did you mean ${likely.map(v => JSON.stringify(v)).join(', ')}?`;
276
- e.dataPath += '/' + prop;
330
+ message = `Did you mean ${JSON.stringify(prop)}?`;
331
+ e.dataPath += '/' + likely[0];
277
332
  e.dataType = 'key';
278
333
  } else {
279
334
  message = `Missing property ${prop}`;
@@ -294,26 +349,42 @@ validateSchema.diagnostic = function (schema, data, dataContentsPath, dataConten
294
349
  message
295
350
  };
296
351
  });
297
- let codeFrame = {
298
- code: dataContentsString,
299
- codeHighlights: (0, _diagnostic.generateJSONCodeHighlights)(dataContentsString, keys.map(({
352
+ let map, code;
353
+
354
+ if (data.map) {
355
+ map = data.map;
356
+ code = data.source;
357
+ } else {
358
+ var _data$source;
359
+
360
+ // $FlowFixMe we can assume that data is valid JSON
361
+ map = (_data$source = data.source) !== null && _data$source !== void 0 ? _data$source : JSON.stringify((0, _nullthrows().default)(data.data), 0, '\t');
362
+ code = map;
363
+ }
364
+
365
+ let codeFrames = [{
366
+ filePath: (_data$filePath = data.filePath) !== null && _data$filePath !== void 0 ? _data$filePath : undefined,
367
+ language: 'json',
368
+ code,
369
+ codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(map, keys.map(({
300
370
  key,
301
371
  type,
302
372
  message
303
- }) => ({
304
- key: prependKey + key,
305
- type: type,
306
- message
307
- })))
308
- };
309
- throw new _diagnostic.default({
373
+ }) => {
374
+ var _data$prependKey;
375
+
376
+ return {
377
+ key: ((_data$prependKey = data.prependKey) !== null && _data$prependKey !== void 0 ? _data$prependKey : '') + key,
378
+ type: type,
379
+ message: message != null ? (0, _diagnostic().escapeMarkdown)(message) : message
380
+ };
381
+ }))
382
+ }];
383
+ throw new (_diagnostic().default)({
310
384
  diagnostic: {
311
- message,
385
+ message: message,
312
386
  origin,
313
- // $FlowFixMe should be a sketchy string check
314
- filePath: dataContentsPath || undefined,
315
- language: 'json',
316
- codeFrame
387
+ codeFrames
317
388
  }
318
389
  });
319
390
  }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SharedBuffer = void 0;
7
+
8
+ /* global MessageChannel:readonly */
9
+ let SharedBuffer; // $FlowFixMe[prop-missing]
10
+
11
+ exports.SharedBuffer = SharedBuffer;
12
+
13
+ if (process.browser) {
14
+ exports.SharedBuffer = SharedBuffer = ArrayBuffer; // Safari has removed the constructor
15
+
16
+ if (typeof SharedArrayBuffer !== 'undefined') {
17
+ let channel = new MessageChannel();
18
+
19
+ try {
20
+ // Firefox might throw when sending the Buffer over a MessagePort
21
+ channel.port1.postMessage(new SharedArrayBuffer(0));
22
+ exports.SharedBuffer = SharedBuffer = SharedArrayBuffer;
23
+ } catch (_) {// NOOP
24
+ }
25
+
26
+ channel.port1.close();
27
+ channel.port2.close();
28
+ }
29
+ } else {
30
+ exports.SharedBuffer = SharedBuffer = SharedArrayBuffer;
31
+ }
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.matchSourceMappingURL = matchSourceMappingURL;
7
+ exports.loadSourceMapUrl = loadSourceMapUrl;
8
+ exports.loadSourceMap = loadSourceMap;
9
+ exports.remapSourceLocation = remapSourceLocation;
10
+ exports.SOURCEMAP_EXTENSIONS = exports.SOURCEMAP_RE = void 0;
11
+
12
+ function _sourceMap() {
13
+ const data = _interopRequireDefault(require("@parcel/source-map"));
14
+
15
+ _sourceMap = function () {
16
+ return data;
17
+ };
18
+
19
+ return data;
20
+ }
21
+
22
+ function _path() {
23
+ const data = _interopRequireDefault(require("path"));
24
+
25
+ _path = function () {
26
+ return data;
27
+ };
28
+
29
+ return data;
30
+ }
31
+
32
+ var _path2 = require("./path");
33
+
34
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
+
36
+ const SOURCEMAP_RE = /(?:\/\*|\/\/)\s*[@#]\s*sourceMappingURL\s*=\s*([^\s*]+)(?:\s*\*\/)?\s*$/;
37
+ exports.SOURCEMAP_RE = SOURCEMAP_RE;
38
+ const DATA_URL_RE = /^data:[^;]+(?:;charset=[^;]+)?;base64,(.*)/;
39
+ const SOURCEMAP_EXTENSIONS = new Set(['css', 'es', 'es6', 'js', 'jsx', 'mjs', 'ts', 'tsx']);
40
+ exports.SOURCEMAP_EXTENSIONS = SOURCEMAP_EXTENSIONS;
41
+
42
+ function matchSourceMappingURL(contents) {
43
+ return contents.match(SOURCEMAP_RE);
44
+ }
45
+
46
+ async function loadSourceMapUrl(fs, filename, contents) {
47
+ let match = matchSourceMappingURL(contents);
48
+
49
+ if (match) {
50
+ let url = match[1].trim();
51
+ let dataURLMatch = url.match(DATA_URL_RE);
52
+ let mapFilePath;
53
+
54
+ if (dataURLMatch) {
55
+ mapFilePath = filename;
56
+ } else {
57
+ mapFilePath = url.replace(/^file:\/\//, '');
58
+ mapFilePath = (0, _path2.isAbsolute)(mapFilePath) ? mapFilePath : _path().default.join(_path().default.dirname(filename), mapFilePath);
59
+ }
60
+
61
+ return {
62
+ url,
63
+ filename: mapFilePath,
64
+ map: JSON.parse(dataURLMatch ? Buffer.from(dataURLMatch[1], 'base64').toString() : await fs.readFile(mapFilePath, 'utf8'))
65
+ };
66
+ }
67
+ }
68
+
69
+ async function loadSourceMap(filename, contents, options) {
70
+ let foundMap = await loadSourceMapUrl(options.fs, filename, contents);
71
+
72
+ if (foundMap) {
73
+ let mapSourceRoot = _path().default.dirname(filename);
74
+
75
+ if (foundMap.map.sourceRoot && !(0, _path2.normalizeSeparators)(foundMap.map.sourceRoot).startsWith('/')) {
76
+ mapSourceRoot = _path().default.join(mapSourceRoot, foundMap.map.sourceRoot);
77
+ }
78
+
79
+ let sourcemapInstance = new (_sourceMap().default)(options.projectRoot);
80
+ sourcemapInstance.addVLQMap({ ...foundMap.map,
81
+ sources: foundMap.map.sources.map(s => {
82
+ return _path().default.join(mapSourceRoot, s);
83
+ })
84
+ });
85
+ return sourcemapInstance;
86
+ }
87
+ }
88
+
89
+ function remapSourceLocation(loc, originalMap) {
90
+ let {
91
+ filePath,
92
+ start: {
93
+ line: startLine,
94
+ column: startCol
95
+ },
96
+ end: {
97
+ line: endLine,
98
+ column: endCol
99
+ }
100
+ } = loc;
101
+ let lineDiff = endLine - startLine;
102
+ let colDiff = endCol - startCol;
103
+ let start = originalMap.findClosestMapping(startLine, startCol);
104
+ let end = originalMap.findClosestMapping(endLine, endCol);
105
+
106
+ if (start !== null && start !== void 0 && start.original) {
107
+ if (start.source) {
108
+ filePath = start.source;
109
+ }
110
+
111
+ ({
112
+ line: startLine,
113
+ column: startCol
114
+ } = start.original);
115
+ startCol++; // source map columns are 0-based
116
+ }
117
+
118
+ if (end !== null && end !== void 0 && end.original) {
119
+ ({
120
+ line: endLine,
121
+ column: endCol
122
+ } = end.original);
123
+ endCol++;
124
+
125
+ if (endLine < startLine) {
126
+ endLine = startLine;
127
+ endCol = startCol;
128
+ } else if (endLine === startLine && endCol < startCol && lineDiff === 0) {
129
+ endCol = startCol + colDiff;
130
+ }
131
+ } else {
132
+ endLine = startLine;
133
+ endCol = startCol;
134
+ }
135
+
136
+ return {
137
+ filePath,
138
+ start: {
139
+ line: startLine,
140
+ column: startCol
141
+ },
142
+ end: {
143
+ line: endLine,
144
+ column: endCol
145
+ }
146
+ };
147
+ }
package/lib/stream.js CHANGED
@@ -7,8 +7,18 @@ exports.measureStreamLength = measureStreamLength;
7
7
  exports.readableFromStringOrBuffer = readableFromStringOrBuffer;
8
8
  exports.bufferStream = bufferStream;
9
9
  exports.blobToStream = blobToStream;
10
+ exports.streamFromPromise = streamFromPromise;
11
+ exports.fallbackStream = fallbackStream;
10
12
 
11
- var _stream = require("stream");
13
+ function _stream() {
14
+ const data = require("stream");
15
+
16
+ _stream = function () {
17
+ return data;
18
+ };
19
+
20
+ return data;
21
+ }
12
22
 
13
23
  function measureStreamLength(stream) {
14
24
  return new Promise((resolve, reject) => {
@@ -23,7 +33,7 @@ function measureStreamLength(stream) {
23
33
 
24
34
  function readableFromStringOrBuffer(str) {
25
35
  // https://stackoverflow.com/questions/12755997/how-to-create-streams-from-string-in-node-js
26
- const stream = new _stream.Readable();
36
+ const stream = new (_stream().Readable)();
27
37
  stream.push(str);
28
38
  stream.push(null);
29
39
  return stream;
@@ -43,9 +53,34 @@ function bufferStream(stream) {
43
53
  }
44
54
 
45
55
  function blobToStream(blob) {
46
- if (blob instanceof _stream.Readable) {
56
+ if (blob instanceof _stream().Readable) {
47
57
  return blob;
48
58
  }
49
59
 
50
60
  return readableFromStringOrBuffer(blob);
61
+ }
62
+
63
+ function streamFromPromise(promise) {
64
+ const stream = new (_stream().PassThrough)();
65
+ promise.then(blob => {
66
+ if (blob instanceof _stream().Readable) {
67
+ blob.pipe(stream);
68
+ } else {
69
+ stream.end(blob);
70
+ }
71
+ });
72
+ return stream;
73
+ }
74
+
75
+ function fallbackStream(stream, fallback) {
76
+ const res = new (_stream().PassThrough)();
77
+ stream.on('error', err => {
78
+ if (err.code === 'ENOENT') {
79
+ fallback().pipe(res);
80
+ } else {
81
+ res.emit('error', err);
82
+ }
83
+ });
84
+ stream.pipe(res);
85
+ return res;
51
86
  }
package/lib/urlJoin.js CHANGED
@@ -5,9 +5,25 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = urlJoin;
7
7
 
8
- var _url = _interopRequireDefault(require("url"));
8
+ function _url() {
9
+ const data = _interopRequireDefault(require("url"));
9
10
 
10
- var _path = _interopRequireDefault(require("path"));
11
+ _url = function () {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _path() {
19
+ const data = _interopRequireDefault(require("path"));
20
+
21
+ _path = function () {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
11
27
 
12
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
29
 
@@ -16,12 +32,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
16
32
  * e.g. from \path\to\res.js to /path/to/res.js.
17
33
  */
18
34
  function urlJoin(publicURL, assetPath) {
19
- const url = _url.default.parse(publicURL, false, true);
35
+ const url = _url().default.parse(publicURL, false, true); // Leading / ensures that paths with colons are not parsed as a protocol.
36
+
37
+
38
+ let p = assetPath.startsWith('/') ? assetPath : '/' + assetPath;
20
39
 
21
- const assetUrl = _url.default.parse(assetPath);
40
+ const assetUrl = _url().default.parse(p);
22
41
 
23
- url.pathname = _path.default.posix.join(url.pathname, assetUrl.pathname);
42
+ url.pathname = _path().default.posix.join(url.pathname, assetUrl.pathname);
24
43
  url.search = assetUrl.search;
25
44
  url.hash = assetUrl.hash;
26
- return _url.default.format(url);
45
+ return _url().default.format(url);
27
46
  }
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@parcel/utils",
3
- "version": "2.0.0-nightly.97+a63f3fc9",
3
+ "version": "2.0.0-nightly.970+5a80fbe4",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
+ "funding": {
10
+ "type": "opencollective",
11
+ "url": "https://opencollective.com/parcel"
12
+ },
9
13
  "repository": {
10
14
  "type": "git",
11
15
  "url": "https://github.com/parcel-bundler/parcel.git"
@@ -13,32 +17,39 @@
13
17
  "main": "lib/index.js",
14
18
  "source": "src/index.js",
15
19
  "engines": {
16
- "node": ">= 10.0.0"
20
+ "node": ">= 12.0.0"
17
21
  },
18
22
  "dependencies": {
19
23
  "@iarna/toml": "^2.2.0",
20
- "@parcel/codeframe": "2.0.0-nightly.97+a63f3fc9",
21
- "@parcel/diagnostic": "2.0.0-nightly.97+a63f3fc9",
22
- "@parcel/logger": "2.0.0-nightly.97+a63f3fc9",
23
- "@parcel/markdown-ansi": "2.0.0-nightly.97+a63f3fc9",
24
- "ansi-html": "^0.0.7",
25
- "chalk": "^2.4.2",
24
+ "@parcel/codeframe": "2.0.0-nightly.970+5a80fbe4",
25
+ "@parcel/diagnostic": "2.0.0-nightly.970+5a80fbe4",
26
+ "@parcel/hash": "2.1.1-nightly.2593+5a80fbe4",
27
+ "@parcel/logger": "2.0.0-nightly.970+5a80fbe4",
28
+ "@parcel/markdown-ansi": "2.0.0-nightly.970+5a80fbe4",
29
+ "@parcel/source-map": "^2.0.0",
30
+ "ansi-html-community": "0.0.8",
31
+ "chalk": "^4.1.0",
26
32
  "clone": "^2.1.1",
27
- "fast-glob": "^3.0.4",
33
+ "fast-glob": "3.1.1",
34
+ "fastest-levenshtein": "^1.0.8",
28
35
  "is-glob": "^4.0.0",
29
36
  "is-url": "^1.2.2",
30
- "js-levenshtein": "^1.1.6",
31
37
  "json5": "^1.0.1",
32
- "micromatch": "^4.0.2",
33
- "node-forge": "^0.8.1",
38
+ "lru-cache": "^6.0.0",
39
+ "micromatch": "^4.0.4",
40
+ "node-forge": "^0.10.0",
34
41
  "nullthrows": "^1.1.1",
35
- "resolve": "^1.12.0",
36
- "serialize-to-js": "^3.0.1",
37
- "terser": "^3.7.3"
42
+ "open": "^7.0.3",
43
+ "terminal-link": "^2.1.1"
38
44
  },
39
45
  "devDependencies": {
40
46
  "@babel/plugin-transform-flow-strip-types": "^7.2.0",
41
47
  "random-int": "^1.0.0"
42
48
  },
43
- "gitHead": "a63f3fc9726483219412920faeb255e035f90747"
49
+ "browser": {
50
+ "./src/generateCertificate.js": false,
51
+ "./src/http-server.js": false,
52
+ "./src/openInBrowser.js": false
53
+ },
54
+ "gitHead": "5a80fbe4af8797d0aab248a66f5254f42f00e83e"
44
55
  }
package/src/DefaultMap.js CHANGED
@@ -24,7 +24,7 @@ export class DefaultMap<K, V> extends Map<K, V> {
24
24
 
25
25
  // Duplicated from DefaultMap implementation for Flow
26
26
  // Roughly mirrors https://github.com/facebook/flow/blob/2eb5a78d92c167117ba9caae070afd2b9f598599/lib/core.js#L617
27
- export class DefaultWeakMap<K: {...}, V> extends WeakMap<K, V> {
27
+ export class DefaultWeakMap<K: interface {}, V> extends WeakMap<K, V> {
28
28
  _getDefault: K => V;
29
29
 
30
30
  constructor(getDefault: K => V, entries?: Iterable<[K, V]>) {
@@ -10,6 +10,7 @@ export default class PromiseQueue<T> {
10
10
  _numRunning: number = 0;
11
11
  _queue: Array<() => Promise<void>> = [];
12
12
  _runPromise: ?Promise<Array<T>> = null;
13
+ _error: mixed;
13
14
  _count: number = 0;
14
15
  _results: Array<T> = [];
15
16
 
@@ -74,7 +75,7 @@ export default class PromiseQueue<T> {
74
75
  if (this._queue.length) {
75
76
  this._next();
76
77
  } else if (this._numRunning === 0) {
77
- this._resolve();
78
+ this._done();
78
79
  }
79
80
  }
80
81
 
@@ -82,10 +83,15 @@ export default class PromiseQueue<T> {
82
83
  this._numRunning++;
83
84
  try {
84
85
  await fn();
85
- this._numRunning--;
86
86
  } catch (e) {
87
- this._reject(e);
88
- // rejecting resets state so numRunning is reset to 0 here
87
+ // Only store the first error that occurs.
88
+ // We don't reject immediately so that any other concurrent
89
+ // requests have time to complete.
90
+ if (this._error == null) {
91
+ this._error = e;
92
+ }
93
+ } finally {
94
+ this._numRunning--;
89
95
  }
90
96
  }
91
97
 
@@ -98,17 +104,15 @@ export default class PromiseQueue<T> {
98
104
  this._deferred = null;
99
105
  }
100
106
 
101
- _reject(err: mixed): void {
107
+ _done(): void {
102
108
  if (this._deferred != null) {
103
- this._deferred.reject(err);
109
+ if (this._error != null) {
110
+ this._deferred.reject(this._error);
111
+ } else {
112
+ this._deferred.resolve(this._results);
113
+ }
104
114
  }
105
- this._resetState();
106
- }
107
115
 
108
- _resolve(): void {
109
- if (this._deferred != null) {
110
- this._deferred.resolve(this._results);
111
- }
112
116
  this._resetState();
113
117
  }
114
118
  }