@parcel/utils 2.0.0-beta.1 → 2.0.0-nightly.1002

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/index.js +35850 -337
  3. package/lib/index.js.map +1 -0
  4. package/package.json +42 -20
  5. package/src/DefaultMap.js +1 -1
  6. package/src/PromiseQueue.js +16 -12
  7. package/src/alternatives.js +143 -0
  8. package/src/ansi-html.js +2 -2
  9. package/src/blob.js +2 -1
  10. package/src/bundle-url.js +1 -1
  11. package/src/collection.js +14 -14
  12. package/src/config.js +93 -53
  13. package/src/countLines.js +5 -2
  14. package/src/debounce.js +1 -1
  15. package/src/dependency-location.js +11 -6
  16. package/src/generateBuildMetrics.js +5 -5
  17. package/src/generateCertificate.js +1 -1
  18. package/src/getCertificate.js +1 -1
  19. package/src/getExisting.js +1 -4
  20. package/src/getRootDir.js +1 -2
  21. package/src/glob.js +36 -5
  22. package/src/hash.js +34 -0
  23. package/src/http-server.js +4 -11
  24. package/src/index.js +47 -20
  25. package/src/is-url.js +1 -1
  26. package/src/isDirectoryInside.js +4 -1
  27. package/src/openInBrowser.js +3 -1
  28. package/src/path.js +17 -2
  29. package/src/prettyDiagnostic.js +39 -27
  30. package/src/relativeBundlePath.js +5 -7
  31. package/src/replaceBundleReferences.js +50 -34
  32. package/src/schema.js +96 -42
  33. package/src/shared-buffer.js +24 -0
  34. package/src/sourcemap.js +84 -10
  35. package/src/urlJoin.js +3 -1
  36. package/test/DefaultMap.test.js +7 -4
  37. package/test/config.test.js +50 -0
  38. package/test/input/config/config.json +3 -0
  39. package/test/input/config/empty.json +0 -0
  40. package/test/input/config/empty.toml +0 -0
  41. package/test/input/sourcemap/referenced-min.js +1 -1
  42. package/test/replaceBundleReferences.test.js +268 -0
  43. package/test/sourcemap.test.js +5 -9
  44. package/test/throttle.test.js +1 -2
  45. package/test/urlJoin.test.js +37 -0
  46. package/lib/DefaultMap.js +0 -64
  47. package/lib/Deferred.js +0 -26
  48. package/lib/PromiseQueue.js +0 -133
  49. package/lib/TapStream.js +0 -38
  50. package/lib/ansi-html.js +0 -16
  51. package/lib/blob.js +0 -31
  52. package/lib/bundle-url.js +0 -43
  53. package/lib/collection.js +0 -62
  54. package/lib/config.js +0 -109
  55. package/lib/countLines.js +0 -18
  56. package/lib/debounce.js +0 -20
  57. package/lib/dependency-location.js +0 -21
  58. package/lib/escape-html.js +0 -24
  59. package/lib/escape-markdown.js +0 -15
  60. package/lib/generateBuildMetrics.js +0 -124
  61. package/lib/generateCertificate.js +0 -124
  62. package/lib/getCertificate.js +0 -19
  63. package/lib/getExisting.js +0 -23
  64. package/lib/getRootDir.js +0 -55
  65. package/lib/glob.js +0 -69
  66. package/lib/http-server.js +0 -81
  67. package/lib/is-url.js +0 -17
  68. package/lib/isDirectoryInside.js +0 -16
  69. package/lib/md5.js +0 -40
  70. package/lib/objectHash.js +0 -26
  71. package/lib/openInBrowser.js +0 -70
  72. package/lib/parseCSSImport.js +0 -16
  73. package/lib/path.js +0 -30
  74. package/lib/prettifyTime.js +0 -10
  75. package/lib/prettyDiagnostic.js +0 -75
  76. package/lib/promisify.js +0 -13
  77. package/lib/relativeBundlePath.js +0 -18
  78. package/lib/relativeUrl.js +0 -16
  79. package/lib/replaceBundleReferences.js +0 -166
  80. package/lib/resolve.js +0 -108
  81. package/lib/schema.js +0 -321
  82. package/lib/serializeObject.js +0 -28
  83. package/lib/sourcemap.js +0 -58
  84. package/lib/stream.js +0 -78
  85. package/lib/throttle.js +0 -16
  86. package/lib/urlJoin.js +0 -27
  87. package/src/.babelrc +0 -3
  88. package/src/escape-markdown.js +0 -10
  89. package/src/md5.js +0 -49
  90. package/src/promisify.js +0 -13
  91. package/src/resolve.js +0 -216
  92. package/src/serializeObject.js +0 -22
  93. package/test/escapeMarkdown.test.js +0 -29
package/lib/resolve.js DELETED
@@ -1,108 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.resolve = resolve;
7
- exports.resolveSync = resolveSync;
8
-
9
- var _promisify = _interopRequireDefault(require("./promisify"));
10
-
11
- var _resolve2 = _interopRequireDefault(require("resolve"));
12
-
13
- var _ = require("../");
14
-
15
- var _module = _interopRequireDefault(require("module"));
16
-
17
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
-
19
- // $FlowFixMe TODO: Type promisify
20
- // $FlowFixMe this is untyped
21
- const resolveAsync = (0, _promisify.default)(_resolve2.default);
22
-
23
- async function resolve(fs, id, opts) {
24
- if (id === 'pnpapi') {
25
- // the resolve package doesn't recognize pnpapi as a builtin
26
- return {
27
- resolved: 'pnpapi'
28
- };
29
- }
30
-
31
- let res = await resolveAsync(id, { ...opts,
32
-
33
- async readFile(filename, callback) {
34
- try {
35
- let res = await fs.readFile(filename);
36
- callback(null, res);
37
- } catch (err) {
38
- callback(err);
39
- }
40
- },
41
-
42
- async isFile(file, callback) {
43
- try {
44
- let stat = await fs.stat(file);
45
- callback(null, stat.isFile());
46
- } catch (err) {
47
- callback(null, false);
48
- }
49
- },
50
-
51
- async isDirectory(file, callback) {
52
- try {
53
- let stat = await fs.stat(file);
54
- callback(null, stat.isDirectory());
55
- } catch (err) {
56
- callback(null, false);
57
- }
58
- }
59
-
60
- });
61
-
62
- if (typeof res === 'string') {
63
- return {
64
- resolved: res
65
- };
66
- }
67
-
68
- return {
69
- resolved: res[0],
70
- pkg: res[1]
71
- };
72
- }
73
-
74
- function resolveSync(fs, id, opts) {
75
- if (id === 'pnpapi') {
76
- // the resolve package doesn't recognize pnpapi as a builtin
77
- return {
78
- resolved: 'pnpapi'
79
- };
80
- } // $FlowFixMe
81
-
82
-
83
- let res = _resolve2.default.sync(id, { ...opts,
84
- readFileSync: (...args) => {
85
- return fs.readFileSync(...args);
86
- },
87
- isFile: file => {
88
- try {
89
- let stat = fs.statSync(file);
90
- return stat.isFile();
91
- } catch (err) {
92
- return false;
93
- }
94
- },
95
- isDirectory: file => {
96
- try {
97
- let stat = fs.statSync(file);
98
- return stat.isDirectory();
99
- } catch (err) {
100
- return false;
101
- }
102
- }
103
- });
104
-
105
- return {
106
- resolved: res
107
- };
108
- }
package/lib/schema.js DELETED
@@ -1,321 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.fuzzySearch = fuzzySearch;
7
- exports.default = void 0;
8
-
9
- var _diagnostic = _interopRequireWildcard(require("@parcel/diagnostic"));
10
-
11
- var _jsLevenshtein = _interopRequireDefault(require("js-levenshtein"));
12
-
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
-
15
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
16
-
17
- 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; }
18
-
19
- // flowlint-next-line untyped-import:off
20
- function validateSchema(schema, data) {
21
- function walk(schemaAncestors, dataNode, dataPath) {
22
- let [schemaNode] = schemaAncestors;
23
-
24
- if (schemaNode.type) {
25
- let type = Array.isArray(dataNode) ? 'array' : typeof dataNode;
26
-
27
- if (schemaNode.type !== type) {
28
- return {
29
- type: 'type',
30
- dataType: 'value',
31
- dataPath,
32
- expectedTypes: [schemaNode.type],
33
- ancestors: schemaAncestors,
34
- prettyType: schemaNode.__type
35
- };
36
- } else {
37
- switch (schemaNode.type) {
38
- case 'array':
39
- {
40
- if (schemaNode.items) {
41
- let results = []; // $FlowFixMe type was already checked
42
-
43
- for (let i = 0; i < dataNode.length; i++) {
44
- let result = walk([schemaNode.items].concat(schemaAncestors), // $FlowFixMe type was already checked
45
- dataNode[i], dataPath + '/' + i);
46
- if (result) results.push(result);
47
- }
48
-
49
- if (results.length) return results.reduce((acc, v) => acc.concat(v), []);
50
- }
51
-
52
- break;
53
- }
54
-
55
- case 'string':
56
- {
57
- // $FlowFixMe type was already checked
58
- let value = dataNode;
59
-
60
- if (schemaNode.enum) {
61
- if (!schemaNode.enum.includes(value)) {
62
- return {
63
- type: 'enum',
64
- dataType: 'value',
65
- dataPath,
66
- expectedValues: schemaNode.enum,
67
- actualValue: value,
68
- ancestors: schemaAncestors
69
- };
70
- }
71
- } else if (schemaNode.__validate) {
72
- let validationError = schemaNode.__validate(value); // $FlowFixMe
73
-
74
-
75
- if (validationError) {
76
- return {
77
- type: 'other',
78
- dataType: 'value',
79
- dataPath,
80
- message: validationError,
81
- actualValue: value,
82
- ancestors: schemaAncestors
83
- };
84
- }
85
- }
86
-
87
- break;
88
- }
89
-
90
- case 'object':
91
- {
92
- let results = [];
93
- let invalidProps;
94
-
95
- if (schemaNode.__forbiddenProperties) {
96
- // $FlowFixMe type was already checked
97
- let keys = Object.keys(dataNode);
98
- invalidProps = schemaNode.__forbiddenProperties.filter(val => keys.includes(val));
99
- results.push(...invalidProps.map(k => ({
100
- type: 'forbidden-prop',
101
- dataPath: dataPath + '/' + k,
102
- dataType: 'key',
103
- prop: k,
104
- expectedProps: Object.keys(schemaNode.properties),
105
- actualProps: keys,
106
- ancestors: schemaAncestors
107
- })));
108
- }
109
-
110
- if (schemaNode.required) {
111
- // $FlowFixMe type was already checked
112
- let keys = Object.keys(dataNode);
113
- let missingKeys = schemaNode.required.filter(val => !keys.includes(val));
114
- results.push(...missingKeys.map(k => ({
115
- type: 'missing-prop',
116
- dataPath,
117
- dataType: null,
118
- prop: k,
119
- expectedProps: schemaNode.required,
120
- actualProps: keys,
121
- ancestors: schemaAncestors
122
- })));
123
- }
124
-
125
- if (schemaNode.properties) {
126
- let {
127
- additionalProperties = true
128
- } = schemaNode; // $FlowFixMe type was already checked
129
-
130
- for (let k in dataNode) {
131
- if (invalidProps && invalidProps.includes(k)) {
132
- // Don't check type on forbidden props
133
- continue;
134
- } else if (k in schemaNode.properties) {
135
- let result = walk([schemaNode.properties[k]].concat(schemaAncestors), // $FlowFixMe type was already checked
136
- dataNode[k], dataPath + '/' + k);
137
- if (result) results.push(result);
138
- } else {
139
- if (typeof additionalProperties === 'boolean') {
140
- if (!additionalProperties) {
141
- results.push({
142
- type: 'enum',
143
- dataType: 'key',
144
- dataPath: dataPath + '/' + k,
145
- expectedValues: Object.keys(schemaNode.properties).filter( // $FlowFixMe type was already checked
146
- p => !(p in dataNode)),
147
- actualValue: k,
148
- ancestors: schemaAncestors,
149
- prettyType: schemaNode.__type
150
- });
151
- }
152
- } else {
153
- let result = walk([additionalProperties].concat(schemaAncestors), // $FlowFixMe type was already checked
154
- dataNode[k], dataPath + '/' + k);
155
- if (result) results.push(result);
156
- }
157
- }
158
- }
159
- }
160
-
161
- if (results.length) return results.reduce((acc, v) => acc.concat(v), []);
162
- break;
163
- }
164
-
165
- case 'boolean':
166
- // NOOP, type was checked already
167
- break;
168
-
169
- default:
170
- throw new Error(`Unimplemented schema type ${type}?`);
171
- }
172
- }
173
- } else {
174
- if (schemaNode.enum && !schemaNode.enum.includes(dataNode)) {
175
- return {
176
- type: 'enum',
177
- dataType: 'value',
178
- dataPath: dataPath,
179
- expectedValues: schemaNode.enum,
180
- actualValue: schemaNode,
181
- ancestors: schemaAncestors
182
- };
183
- }
184
-
185
- if (schemaNode.oneOf || schemaNode.allOf) {
186
- let list = schemaNode.oneOf || schemaNode.allOf;
187
- let results = [];
188
-
189
- for (let f of list) {
190
- let result = walk([f].concat(schemaAncestors), dataNode, dataPath);
191
- if (result) results.push(result);
192
- }
193
-
194
- if (schemaNode.oneOf ? results.length == schemaNode.oneOf.length : results.length > 0) {
195
- // return the result with more values / longer key
196
- results.sort((a, b) => Array.isArray(a) || Array.isArray(b) ? Array.isArray(a) && !Array.isArray(b) ? -1 : !Array.isArray(a) && Array.isArray(b) ? 1 : Array.isArray(a) && Array.isArray(b) ? b.length - a.length : 0 : b.dataPath.length - a.dataPath.length);
197
- return results[0];
198
- }
199
- } else if (schemaNode.not) {
200
- let result = walk([schemaNode.not].concat(schemaAncestors), dataNode, dataPath);
201
-
202
- if (!result || result.length == 0) {
203
- return {
204
- type: 'other',
205
- dataPath,
206
- dataType: null,
207
- message: schemaNode.__message,
208
- actualValue: dataNode,
209
- ancestors: schemaAncestors
210
- };
211
- }
212
- }
213
- }
214
-
215
- return undefined;
216
- }
217
-
218
- let result = walk([schema], data, '');
219
- return Array.isArray(result) ? result : result ? [result] : [];
220
- }
221
-
222
- var _default = validateSchema;
223
- exports.default = _default;
224
-
225
- function fuzzySearch(expectedValues, actualValue) {
226
- 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
227
- ([, d]) => d * 2 < actualValue.length);
228
- result.sort(([, a], [, b]) => a - b);
229
- return result.map(([v]) => v);
230
- }
231
-
232
- validateSchema.diagnostic = function (schema, data, dataContentsPath, dataContents, origin, prependKey, message) {
233
- let errors = validateSchema(schema, data);
234
-
235
- if (errors.length) {
236
- let dataContentsString = typeof dataContents === 'string' ? dataContents : // $FlowFixMe
237
- JSON.stringify(dataContents, null, '\t');
238
- let keys = errors.map(e => {
239
- let message;
240
-
241
- if (e.type === 'enum') {
242
- let {
243
- actualValue
244
- } = e;
245
- let expectedValues = e.expectedValues.map(String);
246
- let likely = actualValue != null ? fuzzySearch(expectedValues, String(actualValue)) : [];
247
-
248
- if (likely.length > 0) {
249
- message = `Did you mean ${likely.map(v => JSON.stringify(v)).join(', ')}?`;
250
- } else if (expectedValues.length > 0) {
251
- message = `Possible values: ${expectedValues.map(v => JSON.stringify(v)).join(', ')}`;
252
- } else {
253
- message = 'Unexpected value';
254
- }
255
- } else if (e.type === 'forbidden-prop') {
256
- let {
257
- prop,
258
- expectedProps,
259
- actualProps
260
- } = e;
261
- let likely = fuzzySearch(expectedProps, prop).filter(v => !actualProps.includes(v));
262
-
263
- if (likely.length > 0) {
264
- message = `Did you mean ${likely.map(v => JSON.stringify(v)).join(', ')}?`;
265
- } else {
266
- message = 'Unexpected property';
267
- }
268
- } else if (e.type === 'missing-prop') {
269
- let {
270
- prop,
271
- actualProps
272
- } = e;
273
- let likely = fuzzySearch(actualProps, prop);
274
-
275
- if (likely.length > 0) {
276
- message = `Did you mean ${likely.map(v => JSON.stringify(v)).join(', ')}?`;
277
- e.dataPath += '/' + prop;
278
- e.dataType = 'key';
279
- } else {
280
- message = `Missing property ${prop}`;
281
- }
282
- } else if (e.type === 'type') {
283
- if (e.prettyType != null) {
284
- message = `Expected ${e.prettyType}`;
285
- } else {
286
- message = `Expected type ${e.expectedTypes.join(', ')}`;
287
- }
288
- } else {
289
- message = e.message;
290
- }
291
-
292
- return {
293
- key: e.dataPath,
294
- type: e.dataType,
295
- message
296
- };
297
- });
298
- let codeFrame = {
299
- code: dataContentsString,
300
- codeHighlights: (0, _diagnostic.generateJSONCodeHighlights)(dataContentsString, keys.map(({
301
- key,
302
- type,
303
- message
304
- }) => ({
305
- key: prependKey + key,
306
- type: type,
307
- message
308
- })))
309
- };
310
- throw new _diagnostic.default({
311
- diagnostic: {
312
- message,
313
- origin,
314
- // $FlowFixMe should be a sketchy string check
315
- filePath: dataContentsPath || undefined,
316
- language: 'json',
317
- codeFrame
318
- }
319
- });
320
- }
321
- };
@@ -1,28 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = serializeObject;
7
-
8
- var _terser = require("terser");
9
-
10
- var _serializeToJs = _interopRequireDefault(require("serialize-to-js"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- function serializeObject(obj, shouldMinify = false) {
15
- let code = `module.exports = ${(0, _serializeToJs.default)(obj)};`;
16
-
17
- if (shouldMinify) {
18
- let minified = (0, _terser.minify)(code);
19
-
20
- if (minified.error) {
21
- throw minified.error;
22
- }
23
-
24
- code = minified.code;
25
- }
26
-
27
- return code;
28
- }
package/lib/sourcemap.js DELETED
@@ -1,58 +0,0 @@
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
-
10
- var _sourceMap = _interopRequireDefault(require("@parcel/source-map"));
11
-
12
- var _path = _interopRequireDefault(require("path"));
13
-
14
- var _path2 = require("./path");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- const SOURCEMAP_RE = /(?:\/\*|\/\/)\s*[@#]\s*sourceMappingURL\s*=\s*([^\s*]+)(?:\s*\*\/)?\s*$/;
19
- const DATA_URL_RE = /^data:[^;]+(?:;charset=[^;]+)?;base64,(.*)/;
20
-
21
- function matchSourceMappingURL(contents) {
22
- return contents.match(SOURCEMAP_RE);
23
- }
24
-
25
- async function loadSourceMapUrl(fs, filename, contents) {
26
- let match = matchSourceMappingURL(contents);
27
-
28
- if (match) {
29
- let url = match[1].trim();
30
- let dataURLMatch = url.match(DATA_URL_RE);
31
- filename = dataURLMatch ? filename : _path.default.join(_path.default.dirname(filename), url);
32
- return {
33
- url,
34
- filename,
35
- map: JSON.parse(dataURLMatch ? Buffer.from(dataURLMatch[1], 'base64').toString() : await fs.readFile(filename, 'utf8'))
36
- };
37
- }
38
- }
39
-
40
- async function loadSourceMap(filename, contents, options) {
41
- let foundMap = await loadSourceMapUrl(options.fs, filename, contents);
42
-
43
- if (foundMap) {
44
- let mapSourceRoot = _path.default.dirname(filename);
45
-
46
- if (foundMap.map.sourceRoot && !(0, _path2.normalizeSeparators)(foundMap.map.sourceRoot).startsWith('/')) {
47
- mapSourceRoot = _path.default.join(mapSourceRoot, foundMap.map.sourceRoot);
48
- }
49
-
50
- let sourcemapInstance = new _sourceMap.default();
51
- sourcemapInstance.addRawMappings({ ...foundMap.map,
52
- sources: foundMap.map.sources.map(s => {
53
- return _path.default.relative(options.projectRoot, _path.default.join(mapSourceRoot, s));
54
- })
55
- });
56
- return sourcemapInstance;
57
- }
58
- }
package/lib/stream.js DELETED
@@ -1,78 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.measureStreamLength = measureStreamLength;
7
- exports.readableFromStringOrBuffer = readableFromStringOrBuffer;
8
- exports.bufferStream = bufferStream;
9
- exports.blobToStream = blobToStream;
10
- exports.streamFromPromise = streamFromPromise;
11
- exports.fallbackStream = fallbackStream;
12
-
13
- var _stream = require("stream");
14
-
15
- function measureStreamLength(stream) {
16
- return new Promise((resolve, reject) => {
17
- let length = 0;
18
- stream.on('data', chunk => {
19
- length += chunk;
20
- });
21
- stream.on('end', () => resolve(length));
22
- stream.on('error', reject);
23
- });
24
- }
25
-
26
- function readableFromStringOrBuffer(str) {
27
- // https://stackoverflow.com/questions/12755997/how-to-create-streams-from-string-in-node-js
28
- const stream = new _stream.Readable();
29
- stream.push(str);
30
- stream.push(null);
31
- return stream;
32
- }
33
-
34
- function bufferStream(stream) {
35
- return new Promise((resolve, reject) => {
36
- let buf = Buffer.from([]);
37
- stream.on('data', data => {
38
- buf = Buffer.concat([buf, data]);
39
- });
40
- stream.on('end', () => {
41
- resolve(buf);
42
- });
43
- stream.on('error', reject);
44
- });
45
- }
46
-
47
- function blobToStream(blob) {
48
- if (blob instanceof _stream.Readable) {
49
- return blob;
50
- }
51
-
52
- return readableFromStringOrBuffer(blob);
53
- }
54
-
55
- function streamFromPromise(promise) {
56
- const stream = new _stream.PassThrough();
57
- promise.then(blob => {
58
- if (blob instanceof _stream.Readable) {
59
- blob.pipe(stream);
60
- } else {
61
- stream.end(blob);
62
- }
63
- });
64
- return stream;
65
- }
66
-
67
- function fallbackStream(stream, fallback) {
68
- const res = new _stream.PassThrough();
69
- stream.on('error', err => {
70
- if (err.code === 'ENOENT') {
71
- fallback().pipe(res);
72
- } else {
73
- res.emit('error', err);
74
- }
75
- });
76
- stream.pipe(res);
77
- return res;
78
- }
package/lib/throttle.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = throttle;
7
-
8
- function throttle(fn, delay) {
9
- let lastCalled;
10
- return function (...args) {
11
- if (lastCalled == null || lastCalled + delay <= Date.now()) {
12
- fn.call(this, ...args);
13
- lastCalled = Date.now();
14
- }
15
- };
16
- }
package/lib/urlJoin.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = urlJoin;
7
-
8
- var _url = _interopRequireDefault(require("url"));
9
-
10
- var _path = _interopRequireDefault(require("path"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- /**
15
- * Joins a path onto a URL, and normalizes Windows paths
16
- * e.g. from \path\to\res.js to /path/to/res.js.
17
- */
18
- function urlJoin(publicURL, assetPath) {
19
- const url = _url.default.parse(publicURL, false, true);
20
-
21
- const assetUrl = _url.default.parse(assetPath);
22
-
23
- url.pathname = _path.default.posix.join(url.pathname, assetUrl.pathname);
24
- url.search = assetUrl.search;
25
- url.hash = assetUrl.hash;
26
- return _url.default.format(url);
27
- }
package/src/.babelrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "presets": ["@parcel/babel-preset"]
3
- }
@@ -1,10 +0,0 @@
1
- // @flow
2
- const escapeCharacters = ['\\', '*', '_', '~'];
3
-
4
- export function escapeMarkdown(s: string): string {
5
- for (const char of escapeCharacters) {
6
- s = s.replace(new RegExp(`\\${char}`, 'g'), `\\${char}`);
7
- }
8
-
9
- return s;
10
- }