@atlaspack/utils 2.16.2-noselfbuild-3f2849b52.0 → 2.16.2-noselfbuild-8c516162e.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/lib/DefaultMap.js +46 -0
  2. package/lib/Deferred.js +30 -0
  3. package/lib/PromiseQueue.js +112 -0
  4. package/lib/TapStream.js +34 -0
  5. package/lib/alternatives.js +116 -0
  6. package/lib/ansi-html.js +18 -0
  7. package/lib/blob.js +40 -0
  8. package/lib/bundle-url.js +34 -0
  9. package/lib/collection.js +111 -0
  10. package/lib/config.js +172 -0
  11. package/lib/countLines.js +15 -0
  12. package/lib/debounce.js +18 -0
  13. package/lib/debug-tools.js +36 -0
  14. package/lib/dependency-location.js +21 -0
  15. package/lib/escape-html.js +22 -0
  16. package/lib/generateBuildMetrics.js +121 -0
  17. package/lib/generateCertificate.js +129 -0
  18. package/lib/getCertificate.js +18 -0
  19. package/lib/getExisting.js +25 -0
  20. package/lib/getModuleParts.js +30 -0
  21. package/lib/getRootDir.js +52 -0
  22. package/lib/glob.js +110 -0
  23. package/lib/hash.js +50 -0
  24. package/lib/http-server.js +85 -0
  25. package/lib/index.js +478 -37357
  26. package/lib/is-url.js +22 -0
  27. package/lib/isDirectoryInside.js +18 -0
  28. package/lib/objectHash.js +27 -0
  29. package/lib/openInBrowser.js +74 -0
  30. package/lib/parseCSSImport.js +15 -0
  31. package/lib/path.js +39 -0
  32. package/lib/prettifyTime.js +9 -0
  33. package/lib/prettyDiagnostic.js +136 -0
  34. package/lib/progress-message.js +27 -0
  35. package/lib/relativeBundlePath.js +22 -0
  36. package/lib/relativeUrl.js +24 -0
  37. package/lib/replaceBundleReferences.js +199 -0
  38. package/lib/schema.js +336 -0
  39. package/lib/shared-buffer.js +27 -0
  40. package/lib/sourcemap.js +127 -0
  41. package/lib/stream.js +76 -0
  42. package/lib/throttle.js +15 -0
  43. package/lib/urlJoin.js +35 -0
  44. package/package.json +15 -16
  45. package/lib/index.js.map +0 -1
package/lib/schema.js ADDED
@@ -0,0 +1,336 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ exports.fuzzySearch = fuzzySearch;
8
+ function _diagnostic() {
9
+ const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
10
+ _diagnostic = function () {
11
+ return data;
12
+ };
13
+ return data;
14
+ }
15
+ function _nullthrows() {
16
+ const data = _interopRequireDefault(require("nullthrows"));
17
+ _nullthrows = function () {
18
+ return data;
19
+ };
20
+ return data;
21
+ }
22
+ function levenshtein() {
23
+ const data = _interopRequireWildcard(require("fastest-levenshtein"));
24
+ levenshtein = function () {
25
+ return data;
26
+ };
27
+ return data;
28
+ }
29
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
31
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
32
+ function validateSchema(schema, data) {
33
+ function walk(schemaAncestors, dataNode, dataPath) {
34
+ let [schemaNode] = schemaAncestors;
35
+ if (schemaNode.type) {
36
+ let type = Array.isArray(dataNode) ? 'array' : typeof dataNode;
37
+ if (schemaNode.type !== type) {
38
+ return {
39
+ type: 'type',
40
+ dataType: 'value',
41
+ dataPath,
42
+ expectedTypes: [schemaNode.type],
43
+ ancestors: schemaAncestors,
44
+ prettyType: schemaNode.__type
45
+ };
46
+ } else {
47
+ switch (schemaNode.type) {
48
+ case 'array':
49
+ {
50
+ if (schemaNode.items) {
51
+ let results = [];
52
+ // $FlowFixMe type was already checked
53
+ for (let i = 0; i < dataNode.length; i++) {
54
+ let result = walk([schemaNode.items].concat(schemaAncestors),
55
+ // $FlowFixMe type was already checked
56
+ dataNode[i], dataPath + '/' + i);
57
+ if (result) results.push(result);
58
+ }
59
+ if (results.length) return results.reduce((acc, v) => acc.concat(v), []);
60
+ }
61
+ break;
62
+ }
63
+ case 'string':
64
+ {
65
+ // $FlowFixMe type was already checked
66
+ let value = dataNode;
67
+ if (schemaNode.enum) {
68
+ if (!schemaNode.enum.includes(value)) {
69
+ return {
70
+ type: 'enum',
71
+ dataType: 'value',
72
+ dataPath,
73
+ expectedValues: schemaNode.enum,
74
+ actualValue: value,
75
+ ancestors: schemaAncestors
76
+ };
77
+ }
78
+ } else if (schemaNode.__validate) {
79
+ let validationError = schemaNode.__validate(value);
80
+ if (typeof validationError == 'string') {
81
+ return {
82
+ type: 'other',
83
+ dataType: 'value',
84
+ dataPath,
85
+ message: validationError,
86
+ actualValue: value,
87
+ ancestors: schemaAncestors
88
+ };
89
+ }
90
+ }
91
+ break;
92
+ }
93
+ case 'number':
94
+ {
95
+ // $FlowFixMe type was already checked
96
+ let value = dataNode;
97
+ if (schemaNode.enum) {
98
+ if (!schemaNode.enum.includes(value)) {
99
+ return {
100
+ type: 'enum',
101
+ dataType: 'value',
102
+ dataPath,
103
+ expectedValues: schemaNode.enum,
104
+ actualValue: value,
105
+ ancestors: schemaAncestors
106
+ };
107
+ }
108
+ }
109
+ break;
110
+ }
111
+ case 'object':
112
+ {
113
+ let results = [];
114
+ let invalidProps;
115
+ if (schemaNode.__forbiddenProperties) {
116
+ // $FlowFixMe type was already checked
117
+ let keys = Object.keys(dataNode);
118
+ invalidProps = schemaNode.__forbiddenProperties.filter(val => keys.includes(val));
119
+ results.push(...invalidProps.map(k => ({
120
+ type: 'forbidden-prop',
121
+ dataPath: dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k),
122
+ dataType: 'key',
123
+ prop: k,
124
+ expectedProps: Object.keys(schemaNode.properties),
125
+ actualProps: keys,
126
+ ancestors: schemaAncestors
127
+ })));
128
+ }
129
+ if (schemaNode.required) {
130
+ // $FlowFixMe type was already checked
131
+ let keys = Object.keys(dataNode);
132
+ let missingKeys = schemaNode.required.filter(val => !keys.includes(val));
133
+ results.push(...missingKeys.map(k => ({
134
+ type: 'missing-prop',
135
+ dataPath,
136
+ dataType: 'value',
137
+ prop: k,
138
+ expectedProps: schemaNode.required,
139
+ actualProps: keys,
140
+ ancestors: schemaAncestors
141
+ })));
142
+ }
143
+ if (schemaNode.properties) {
144
+ let {
145
+ additionalProperties = true
146
+ } = schemaNode;
147
+ // $FlowFixMe type was already checked
148
+ for (let k in dataNode) {
149
+ if (invalidProps && invalidProps.includes(k)) {
150
+ // Don't check type on forbidden props
151
+ continue;
152
+ } else if (k in schemaNode.properties) {
153
+ let result = walk([schemaNode.properties[k]].concat(schemaAncestors),
154
+ // $FlowFixMe type was already checked
155
+ dataNode[k], dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k));
156
+ if (result) results.push(result);
157
+ } else {
158
+ if (typeof additionalProperties === 'boolean') {
159
+ if (!additionalProperties) {
160
+ results.push({
161
+ type: 'enum',
162
+ dataType: 'key',
163
+ dataPath: dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k),
164
+ expectedValues: Object.keys(schemaNode.properties).filter(
165
+ // $FlowFixMe type was already checked
166
+ p => !(p in dataNode)),
167
+ actualValue: k,
168
+ ancestors: schemaAncestors,
169
+ prettyType: schemaNode.__type
170
+ });
171
+ }
172
+ } else {
173
+ let result = walk([additionalProperties].concat(schemaAncestors),
174
+ // $FlowFixMe type was already checked
175
+ dataNode[k], dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k));
176
+ if (result) results.push(result);
177
+ }
178
+ }
179
+ }
180
+ }
181
+ if (results.length) return results.reduce((acc, v) => acc.concat(v), []);
182
+ break;
183
+ }
184
+ case 'boolean':
185
+ // NOOP, type was checked already
186
+ break;
187
+ default:
188
+ throw new Error(`Unimplemented schema type ${type}?`);
189
+ }
190
+ }
191
+ } else {
192
+ if (schemaNode.enum && !schemaNode.enum.includes(dataNode)) {
193
+ return {
194
+ type: 'enum',
195
+ dataType: 'value',
196
+ dataPath: dataPath,
197
+ expectedValues: schemaNode.enum,
198
+ actualValue: schemaNode,
199
+ ancestors: schemaAncestors
200
+ };
201
+ }
202
+ if (schemaNode.oneOf || schemaNode.allOf) {
203
+ let list = schemaNode.oneOf || schemaNode.allOf;
204
+ let results = [];
205
+ for (let f of list) {
206
+ let result = walk([f].concat(schemaAncestors), dataNode, dataPath);
207
+ if (result) results.push(result);
208
+ }
209
+ if (schemaNode.oneOf ? results.length == schemaNode.oneOf.length : results.length > 0) {
210
+ // return the result with more values / longer key
211
+ 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);
212
+ return results[0];
213
+ }
214
+ } else if (schemaNode.not) {
215
+ let result = walk([schemaNode.not].concat(schemaAncestors), dataNode, dataPath);
216
+ if (!result || result.length == 0) {
217
+ return {
218
+ type: 'other',
219
+ dataPath,
220
+ dataType: null,
221
+ message: schemaNode.__message,
222
+ actualValue: dataNode,
223
+ ancestors: schemaAncestors
224
+ };
225
+ }
226
+ }
227
+ }
228
+ return undefined;
229
+ }
230
+ let result = walk([schema], data, '');
231
+ return Array.isArray(result) ? result : result ? [result] : [];
232
+ }
233
+ var _default = exports.default = validateSchema;
234
+ function fuzzySearch(expectedValues, actualValue) {
235
+ let result = expectedValues.map(exp => [exp, levenshtein().distance(exp, actualValue)]).filter(
236
+ // Remove if more than half of the string would need to be changed
237
+ ([, d]) => d * 2 < actualValue.length);
238
+ result.sort(([, a], [, b]) => a - b);
239
+ return result.map(([v]) => v);
240
+ }
241
+ validateSchema.diagnostic = function (schema, data, origin, message) {
242
+ if ('source' in data && 'data' in data && typeof data.source !== 'string' && !data) {
243
+ throw new Error('At least one of data.source and data.data must be defined!');
244
+ }
245
+ let object = data.map ? data.map.data :
246
+ // $FlowFixMe we can assume it's a JSON object
247
+ data.data ?? JSON.parse(data.source);
248
+ let errors = validateSchema(schema, object);
249
+ if (errors.length) {
250
+ let keys = errors.map(e => {
251
+ let message;
252
+ if (e.type === 'enum') {
253
+ let {
254
+ actualValue
255
+ } = e;
256
+ let expectedValues = e.expectedValues.map(String);
257
+ let likely = actualValue != null ? fuzzySearch(expectedValues, String(actualValue)) : [];
258
+ if (likely.length > 0) {
259
+ message = `Did you mean ${likely.map(v => JSON.stringify(v)).join(', ')}?`;
260
+ } else if (expectedValues.length > 0) {
261
+ message = `Possible values: ${expectedValues.map(v => JSON.stringify(v)).join(', ')}`;
262
+ } else {
263
+ message = 'Unexpected value';
264
+ }
265
+ } else if (e.type === 'forbidden-prop') {
266
+ let {
267
+ prop,
268
+ expectedProps,
269
+ actualProps
270
+ } = e;
271
+ let likely = fuzzySearch(expectedProps, prop).filter(v => !actualProps.includes(v));
272
+ if (likely.length > 0) {
273
+ message = `Did you mean ${likely.map(v => JSON.stringify(v)).join(', ')}?`;
274
+ } else {
275
+ message = 'Unexpected property';
276
+ }
277
+ } else if (e.type === 'missing-prop') {
278
+ let {
279
+ prop,
280
+ actualProps
281
+ } = e;
282
+ let likely = fuzzySearch(actualProps, prop);
283
+ if (likely.length > 0) {
284
+ message = `Did you mean ${JSON.stringify(prop)}?`;
285
+ e.dataPath += '/' + likely[0];
286
+ e.dataType = 'key';
287
+ } else {
288
+ message = `Missing property ${prop}`;
289
+ }
290
+ } else if (e.type === 'type') {
291
+ if (e.prettyType != null) {
292
+ message = `Expected ${e.prettyType}`;
293
+ } else {
294
+ message = `Expected type ${e.expectedTypes.join(', ')}`;
295
+ }
296
+ } else {
297
+ message = e.message;
298
+ }
299
+ return {
300
+ key: e.dataPath,
301
+ type: e.dataType,
302
+ message
303
+ };
304
+ });
305
+ let map, code;
306
+ if (data.map) {
307
+ map = data.map;
308
+ code = data.source;
309
+ } else {
310
+ // $FlowFixMe we can assume that data is valid JSON
311
+ map = data.source ?? JSON.stringify((0, _nullthrows().default)(data.data), 0, '\t');
312
+ code = map;
313
+ }
314
+ let codeFrames = [{
315
+ filePath: data.filePath ?? undefined,
316
+ language: 'json',
317
+ code,
318
+ codeHighlights: (0, _diagnostic().generateJSONCodeHighlights)(map, keys.map(({
319
+ key,
320
+ type,
321
+ message
322
+ }) => ({
323
+ key: (data.prependKey ?? '') + key,
324
+ type: type,
325
+ message: message != null ? (0, _diagnostic().escapeMarkdown)(message) : message
326
+ })))
327
+ }];
328
+ throw new (_diagnostic().default)({
329
+ diagnostic: {
330
+ message: message,
331
+ origin,
332
+ codeFrames
333
+ }
334
+ });
335
+ }
336
+ };
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SharedBuffer = void 0;
7
+ let SharedBuffer = exports.SharedBuffer = void 0;
8
+
9
+ // $FlowFixMe[prop-missing]
10
+ if (process.browser) {
11
+ exports.SharedBuffer = SharedBuffer = ArrayBuffer;
12
+ // Safari has removed the constructor
13
+ if (typeof SharedArrayBuffer !== 'undefined') {
14
+ let channel = new MessageChannel();
15
+ try {
16
+ // Firefox might throw when sending the Buffer over a MessagePort
17
+ channel.port1.postMessage(new SharedArrayBuffer(0));
18
+ exports.SharedBuffer = SharedBuffer = SharedArrayBuffer;
19
+ } catch (_) {
20
+ // NOOP
21
+ }
22
+ channel.port1.close();
23
+ channel.port2.close();
24
+ }
25
+ } else {
26
+ exports.SharedBuffer = SharedBuffer = SharedArrayBuffer;
27
+ }
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SOURCEMAP_RE = exports.SOURCEMAP_EXTENSIONS = void 0;
7
+ exports.loadSourceMap = loadSourceMap;
8
+ exports.loadSourceMapUrl = loadSourceMapUrl;
9
+ exports.matchSourceMappingURL = matchSourceMappingURL;
10
+ exports.remapSourceLocation = remapSourceLocation;
11
+ function _sourceMap() {
12
+ const data = _interopRequireDefault(require("@parcel/source-map"));
13
+ _sourceMap = function () {
14
+ return data;
15
+ };
16
+ return data;
17
+ }
18
+ function _path() {
19
+ const data = _interopRequireDefault(require("path"));
20
+ _path = function () {
21
+ return data;
22
+ };
23
+ return data;
24
+ }
25
+ var _path2 = require("./path");
26
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
+ const SOURCEMAP_RE = exports.SOURCEMAP_RE = /(?:\/\*|\/\/)\s*[@#]\s*sourceMappingURL\s*=\s*([^\s*]+)(?:\s*\*\/)?\s*$/;
28
+ const DATA_URL_RE = /^data:[^;]+(?:;charset=[^;]+)?;base64,(.*)/;
29
+ const SOURCEMAP_EXTENSIONS = exports.SOURCEMAP_EXTENSIONS = new Set(['css', 'es', 'es6', 'js', 'jsx', 'mjs', 'ts', 'tsx']);
30
+ function matchSourceMappingURL(contents) {
31
+ return contents.match(SOURCEMAP_RE);
32
+ }
33
+ async function loadSourceMapUrl(fs, filename, contents) {
34
+ let match = matchSourceMappingURL(contents);
35
+ if (match) {
36
+ let url = match[1].trim();
37
+ let dataURLMatch = url.match(DATA_URL_RE);
38
+ let mapFilePath;
39
+ if (dataURLMatch) {
40
+ mapFilePath = filename;
41
+ } else {
42
+ mapFilePath = url.replace(/^file:\/\//, '');
43
+ mapFilePath = (0, _path2.isAbsolute)(mapFilePath) ? mapFilePath : _path().default.join(_path().default.dirname(filename), mapFilePath);
44
+ }
45
+ return {
46
+ url,
47
+ filename: mapFilePath,
48
+ map: JSON.parse(dataURLMatch ? Buffer.from(dataURLMatch[1], 'base64').toString() : await fs.readFile(mapFilePath, 'utf8'))
49
+ };
50
+ }
51
+ }
52
+ async function loadSourceMap(filename, contents, options) {
53
+ let foundMap = await loadSourceMapUrl(options.fs, filename, contents);
54
+ if (foundMap) {
55
+ let mapSourceRoot = _path().default.dirname(filename);
56
+ if (foundMap.map.sourceRoot && !(0, _path2.normalizeSeparators)(foundMap.map.sourceRoot).startsWith('/')) {
57
+ mapSourceRoot = _path().default.join(mapSourceRoot, foundMap.map.sourceRoot);
58
+ }
59
+ let sourcemapInstance = new (_sourceMap().default)(options.projectRoot);
60
+ sourcemapInstance.addVLQMap({
61
+ ...foundMap.map,
62
+ sources: foundMap.map.sources.map(s => {
63
+ return _path().default.join(mapSourceRoot, s);
64
+ })
65
+ });
66
+ return sourcemapInstance;
67
+ }
68
+ }
69
+ function remapSourceLocation(loc, originalMap) {
70
+ let {
71
+ filePath,
72
+ start: {
73
+ line: startLine,
74
+ column: startCol
75
+ },
76
+ end: {
77
+ line: endLine,
78
+ column: endCol
79
+ }
80
+ } = loc;
81
+ let lineDiff = endLine - startLine;
82
+ let colDiff = endCol - startCol;
83
+ let start = originalMap.findClosestMapping(startLine, startCol - 1);
84
+ let end = originalMap.findClosestMapping(endLine, endCol - 1);
85
+ if (start !== null && start !== void 0 && start.original) {
86
+ if (start.source) {
87
+ filePath = start.source;
88
+ }
89
+ ({
90
+ line: startLine,
91
+ column: startCol
92
+ } = start.original);
93
+ startCol++; // source map columns are 0-based
94
+ }
95
+
96
+ if (end !== null && end !== void 0 && end.original) {
97
+ ({
98
+ line: endLine,
99
+ column: endCol
100
+ } = end.original);
101
+ endCol++; // source map columns are 0-based
102
+
103
+ if (endLine < startLine) {
104
+ endLine = startLine;
105
+ endCol = startCol;
106
+ } else if (endLine === startLine && endCol < startCol && lineDiff === 0) {
107
+ endCol = startCol + colDiff;
108
+ } else if (endLine === startLine && startCol === endCol && lineDiff === 0) {
109
+ // Prevent 0-length ranges
110
+ endCol = startCol + 1;
111
+ }
112
+ } else {
113
+ endLine = startLine;
114
+ endCol = startCol;
115
+ }
116
+ return {
117
+ filePath,
118
+ start: {
119
+ line: startLine,
120
+ column: startCol
121
+ },
122
+ end: {
123
+ line: endLine,
124
+ column: endCol
125
+ }
126
+ };
127
+ }
package/lib/stream.js ADDED
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.blobToStream = blobToStream;
7
+ exports.bufferStream = bufferStream;
8
+ exports.fallbackStream = fallbackStream;
9
+ exports.measureStreamLength = measureStreamLength;
10
+ exports.readableFromStringOrBuffer = readableFromStringOrBuffer;
11
+ exports.streamFromPromise = streamFromPromise;
12
+ function _stream() {
13
+ const data = require("stream");
14
+ _stream = function () {
15
+ return data;
16
+ };
17
+ return data;
18
+ }
19
+ function measureStreamLength(stream) {
20
+ return new Promise((resolve, reject) => {
21
+ let length = 0;
22
+ stream.on('data', chunk => {
23
+ length += chunk;
24
+ });
25
+ stream.on('end', () => resolve(length));
26
+ stream.on('error', reject);
27
+ });
28
+ }
29
+ function readableFromStringOrBuffer(str) {
30
+ // https://stackoverflow.com/questions/12755997/how-to-create-streams-from-string-in-node-js
31
+ const stream = new (_stream().Readable)();
32
+ stream.push(str);
33
+ stream.push(null);
34
+ return stream;
35
+ }
36
+ function bufferStream(stream) {
37
+ return new Promise((resolve, reject) => {
38
+ let buf = Buffer.from([]);
39
+ stream.on('data', data => {
40
+ buf = Buffer.concat([buf, data]);
41
+ });
42
+ stream.on('end', () => {
43
+ resolve(buf);
44
+ });
45
+ stream.on('error', reject);
46
+ });
47
+ }
48
+ function blobToStream(blob) {
49
+ if (blob instanceof _stream().Readable) {
50
+ return blob;
51
+ }
52
+ return readableFromStringOrBuffer(blob);
53
+ }
54
+ function streamFromPromise(promise) {
55
+ const stream = new (_stream().PassThrough)();
56
+ promise.then(blob => {
57
+ if (blob instanceof _stream().Readable) {
58
+ blob.pipe(stream);
59
+ } else {
60
+ stream.end(blob);
61
+ }
62
+ });
63
+ return stream;
64
+ }
65
+ function fallbackStream(stream, fallback) {
66
+ const res = new (_stream().PassThrough)();
67
+ stream.on('error', err => {
68
+ if (err.code === 'ENOENT') {
69
+ fallback().pipe(res);
70
+ } else {
71
+ res.emit('error', err);
72
+ }
73
+ });
74
+ stream.pipe(res);
75
+ return res;
76
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = throttle;
7
+ function throttle(fn, delay) {
8
+ let lastCalled;
9
+ return function throttled(...args) {
10
+ if (lastCalled == null || lastCalled + delay <= Date.now()) {
11
+ fn.call(this, ...args);
12
+ lastCalled = Date.now();
13
+ }
14
+ };
15
+ }
package/lib/urlJoin.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = urlJoin;
7
+ function _url() {
8
+ const data = _interopRequireDefault(require("url"));
9
+ _url = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _path() {
15
+ const data = _interopRequireDefault(require("path"));
16
+ _path = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
+ /**
23
+ * Joins a path onto a URL, and normalizes Windows paths
24
+ * e.g. from \path\to\res.js to /path/to/res.js.
25
+ */
26
+ function urlJoin(publicURL, assetPath) {
27
+ const url = _url().default.parse(publicURL, false, true);
28
+ // Leading / ensures that paths with colons are not parsed as a protocol.
29
+ let p = assetPath.startsWith('/') ? assetPath : '/' + assetPath;
30
+ const assetUrl = _url().default.parse(p);
31
+ url.pathname = _path().default.posix.join(url.pathname, assetUrl.pathname);
32
+ url.search = assetUrl.search;
33
+ url.hash = assetUrl.hash;
34
+ return _url().default.format(url);
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/utils",
3
- "version": "2.16.2-noselfbuild-3f2849b52.0",
3
+ "version": "2.16.2-noselfbuild-8c516162e.0",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -30,21 +30,16 @@
30
30
  }
31
31
  },
32
32
  "dependencies": {
33
- "@atlaspack/codeframe": "2.13.4-noselfbuild-3f2849b52.0",
34
- "@atlaspack/diagnostic": "2.14.2-noselfbuild-3f2849b52.0",
35
- "@atlaspack/feature-flags": "2.18.5-noselfbuild-3f2849b52.0",
36
- "@atlaspack/logger": "2.14.13-noselfbuild-3f2849b52.0",
37
- "@atlaspack/markdown-ansi": "2.14.2-noselfbuild-3f2849b52.0",
38
- "@atlaspack/rust": "3.4.1-noselfbuild-3f2849b52.0",
39
- "@parcel/source-map": "^2.1.1",
40
- "chalk": "^4.1.0",
41
- "nullthrows": "^1.1.1"
42
- },
43
- "devDependencies": {
44
- "@atlaspack/babel-register": "2.14.2-noselfbuild-3f2849b52.0",
33
+ "@atlaspack/codeframe": "2.13.4-noselfbuild-8c516162e.0",
34
+ "@atlaspack/diagnostic": "2.14.2-noselfbuild-8c516162e.0",
35
+ "@atlaspack/feature-flags": "2.18.5-noselfbuild-8c516162e.0",
36
+ "@atlaspack/logger": "2.14.13-noselfbuild-8c516162e.0",
37
+ "@atlaspack/markdown-ansi": "2.14.2-noselfbuild-8c516162e.0",
38
+ "@atlaspack/rust": "3.4.1-noselfbuild-8c516162e.0",
45
39
  "@iarna/toml": "^2.2.0",
40
+ "@parcel/source-map": "^2.1.1",
46
41
  "ansi-html-community": "0.0.8",
47
- "benny": "^3.7.1",
42
+ "chalk": "^4.1.0",
48
43
  "clone": "^2.1.1",
49
44
  "fast-glob": "^3.2.12",
50
45
  "fastest-levenshtein": "^1.0.16",
@@ -56,11 +51,15 @@
56
51
  "node-forge": "^1.2.1",
57
52
  "nullthrows": "^1.1.1",
58
53
  "open": "^7.0.3",
59
- "random-int": "^1.0.0",
60
54
  "snarkdown": "^2.0.0",
61
55
  "strip-ansi": "^6.0.0",
62
56
  "terminal-link": "^2.1.1"
63
57
  },
58
+ "devDependencies": {
59
+ "@atlaspack/babel-register": "2.14.2-noselfbuild-8c516162e.0",
60
+ "benny": "^3.7.1",
61
+ "random-int": "^1.0.0"
62
+ },
64
63
  "browser": {
65
64
  "./src/generateCertificate.js": false,
66
65
  "./src/http-server.js": false,
@@ -68,5 +67,5 @@
68
67
  "@atlaspack/markdown-ansi": false
69
68
  },
70
69
  "type": "commonjs",
71
- "gitHead": "3f2849b52d0a62d716f1c6cb3a92656e1e4fa18a"
70
+ "gitHead": "8c516162e3109bbebe535130a7de57e9e59a4eb8"
72
71
  }