@parcel/utils 2.2.0 → 2.3.2

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/index.js +35876 -411
  2. package/lib/index.js.map +1 -0
  3. package/package.json +27 -14
  4. package/src/config.js +2 -2
  5. package/src/glob.js +14 -3
  6. package/src/index.js +1 -1
  7. package/lib/DefaultMap.js +0 -56
  8. package/lib/Deferred.js +0 -34
  9. package/lib/PromiseQueue.js +0 -124
  10. package/lib/TapStream.js +0 -41
  11. package/lib/alternatives.js +0 -134
  12. package/lib/ansi-html.js +0 -24
  13. package/lib/blob.js +0 -49
  14. package/lib/bundle-url.js +0 -43
  15. package/lib/collection.js +0 -65
  16. package/lib/config.js +0 -198
  17. package/lib/countLines.js +0 -18
  18. package/lib/debounce.js +0 -20
  19. package/lib/dependency-location.js +0 -21
  20. package/lib/escape-html.js +0 -24
  21. package/lib/generateBuildMetrics.js +0 -148
  22. package/lib/generateCertificate.js +0 -149
  23. package/lib/getCertificate.js +0 -19
  24. package/lib/getExisting.js +0 -31
  25. package/lib/getRootDir.js +0 -66
  26. package/lib/glob.js +0 -110
  27. package/lib/hash.js +0 -44
  28. package/lib/http-server.js +0 -102
  29. package/lib/is-url.js +0 -27
  30. package/lib/isDirectoryInside.js +0 -24
  31. package/lib/objectHash.js +0 -34
  32. package/lib/openInBrowser.js +0 -94
  33. package/lib/parseCSSImport.js +0 -16
  34. package/lib/path.js +0 -49
  35. package/lib/prettifyTime.js +0 -10
  36. package/lib/prettyDiagnostic.js +0 -139
  37. package/lib/relativeBundlePath.js +0 -30
  38. package/lib/relativeUrl.js +0 -32
  39. package/lib/replaceBundleReferences.js +0 -211
  40. package/lib/schema.js +0 -391
  41. package/lib/shared-buffer.js +0 -31
  42. package/lib/sourcemap.js +0 -147
  43. package/lib/stream.js +0 -86
  44. package/lib/throttle.js +0 -16
  45. package/lib/urlJoin.js +0 -46
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = relativeUrl;
7
-
8
- function _path() {
9
- const data = _interopRequireDefault(require("path"));
10
-
11
- _path = function () {
12
- return data;
13
- };
14
-
15
- return data;
16
- }
17
-
18
- function _url() {
19
- const data = _interopRequireDefault(require("url"));
20
-
21
- _url = function () {
22
- return data;
23
- };
24
-
25
- return data;
26
- }
27
-
28
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
-
30
- function relativeUrl(from, to) {
31
- return _url().default.format(_url().default.parse(_path().default.relative(from, to)));
32
- }
@@ -1,211 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.replaceURLReferences = replaceURLReferences;
7
- exports.replaceInlineReferences = replaceInlineReferences;
8
- exports.getURLReplacement = getURLReplacement;
9
-
10
- function _stream() {
11
- const data = require("stream");
12
-
13
- _stream = function () {
14
- return data;
15
- };
16
-
17
- return data;
18
- }
19
-
20
- function _nullthrows() {
21
- const data = _interopRequireDefault(require("nullthrows"));
22
-
23
- _nullthrows = function () {
24
- return data;
25
- };
26
-
27
- return data;
28
- }
29
-
30
- function _assert() {
31
- const data = _interopRequireDefault(require("assert"));
32
-
33
- _assert = function () {
34
- return data;
35
- };
36
-
37
- return data;
38
- }
39
-
40
- function _url() {
41
- const data = _interopRequireDefault(require("url"));
42
-
43
- _url = function () {
44
- return data;
45
- };
46
-
47
- return data;
48
- }
49
-
50
- var _ = require("./");
51
-
52
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
53
-
54
- /*
55
- * Replaces references to dependency ids for URL dependencies with:
56
- * - in the case of an unresolvable url dependency, the original specifier.
57
- * These are external requests that Parcel did not bundle.
58
- * - in the case of a reference to another bundle, the relative url to that
59
- * bundle from the current bundle.
60
- */
61
- function replaceURLReferences({
62
- bundle,
63
- bundleGraph,
64
- contents,
65
- map,
66
- relative = true
67
- }) {
68
- let replacements = new Map();
69
- let urlDependencies = [];
70
- bundle.traverse(node => {
71
- if (node.type === 'dependency' && node.value.specifierType === 'url') {
72
- urlDependencies.push(node.value);
73
- }
74
- });
75
-
76
- for (let dependency of urlDependencies) {
77
- var _dependency$meta$plac, _dependency$meta;
78
-
79
- if (dependency.specifierType !== 'url') {
80
- continue;
81
- }
82
-
83
- let placeholder = (_dependency$meta$plac = (_dependency$meta = dependency.meta) === null || _dependency$meta === void 0 ? void 0 : _dependency$meta.placeholder) !== null && _dependency$meta$plac !== void 0 ? _dependency$meta$plac : dependency.id;
84
- (0, _assert().default)(typeof placeholder === 'string');
85
- let resolved = bundleGraph.getReferencedBundle(dependency, bundle);
86
-
87
- if (resolved == null) {
88
- replacements.set(placeholder, {
89
- from: placeholder,
90
- to: dependency.specifier
91
- });
92
- continue;
93
- }
94
-
95
- if (resolved.bundleBehavior === 'inline') {
96
- // If a bundle is inline, it should be replaced with inline contents,
97
- // not a URL.
98
- continue;
99
- }
100
-
101
- replacements.set(placeholder, getURLReplacement({
102
- dependency,
103
- fromBundle: bundle,
104
- toBundle: resolved,
105
- relative
106
- }));
107
- }
108
-
109
- return performReplacement(replacements, contents, map);
110
- }
111
- /*
112
- * Replaces references to dependency ids for inline bundles with the packaged
113
- * contents of that bundle.
114
- */
115
-
116
-
117
- async function replaceInlineReferences({
118
- bundle,
119
- bundleGraph,
120
- contents,
121
- map,
122
- getInlineReplacement,
123
- getInlineBundleContents
124
- }) {
125
- let replacements = new Map();
126
- let dependencies = [];
127
- bundle.traverse(node => {
128
- if (node.type === 'dependency') {
129
- dependencies.push(node.value);
130
- }
131
- });
132
-
133
- for (let dependency of dependencies) {
134
- let entryBundle = bundleGraph.getReferencedBundle(dependency, bundle);
135
-
136
- if ((entryBundle === null || entryBundle === void 0 ? void 0 : entryBundle.bundleBehavior) !== 'inline') {
137
- continue;
138
- }
139
-
140
- let packagedBundle = await getInlineBundleContents(entryBundle, bundleGraph);
141
- let packagedContents = (packagedBundle.contents instanceof _stream().Readable ? await (0, _.bufferStream)(packagedBundle.contents) : packagedBundle.contents).toString();
142
- let inlineType = (0, _nullthrows().default)(entryBundle.getMainEntry()).meta.inlineType;
143
-
144
- if (inlineType == null || inlineType === 'string') {
145
- var _dependency$meta$plac2, _dependency$meta2;
146
-
147
- let placeholder = (_dependency$meta$plac2 = (_dependency$meta2 = dependency.meta) === null || _dependency$meta2 === void 0 ? void 0 : _dependency$meta2.placeholder) !== null && _dependency$meta$plac2 !== void 0 ? _dependency$meta$plac2 : dependency.id;
148
- (0, _assert().default)(typeof placeholder === 'string');
149
- replacements.set(placeholder, getInlineReplacement(dependency, inlineType, packagedContents));
150
- }
151
- }
152
-
153
- return performReplacement(replacements, contents, map);
154
- }
155
-
156
- function getURLReplacement({
157
- dependency,
158
- fromBundle,
159
- toBundle,
160
- relative
161
- }) {
162
- var _dependency$meta$plac3, _dependency$meta3;
163
-
164
- let to;
165
-
166
- let orig = _url().default.parse(dependency.specifier);
167
-
168
- if (relative) {
169
- to = _url().default.format({
170
- pathname: (0, _.relativeBundlePath)(fromBundle, toBundle, {
171
- leadingDotSlash: false
172
- }),
173
- hash: orig.hash
174
- }); // If the resulting path includes a colon character and doesn't start with a ./ or ../
175
- // we need to add one so that the first part before the colon isn't parsed as a URL protocol.
176
-
177
- if (to.includes(':') && !to.startsWith('./') && !to.startsWith('../')) {
178
- to = './' + to;
179
- }
180
- } else {
181
- to = (0, _.urlJoin)(toBundle.target.publicUrl, _url().default.format({
182
- pathname: (0, _nullthrows().default)(toBundle.name),
183
- hash: orig.hash
184
- }));
185
- }
186
-
187
- let placeholder = (_dependency$meta$plac3 = (_dependency$meta3 = dependency.meta) === null || _dependency$meta3 === void 0 ? void 0 : _dependency$meta3.placeholder) !== null && _dependency$meta$plac3 !== void 0 ? _dependency$meta$plac3 : dependency.id;
188
- (0, _assert().default)(typeof placeholder === 'string');
189
- return {
190
- from: placeholder,
191
- to
192
- };
193
- }
194
-
195
- function performReplacement(replacements, contents, map) {
196
- let finalContents = contents;
197
-
198
- for (let {
199
- from,
200
- to
201
- } of replacements.values()) {
202
- // Perform replacement
203
- finalContents = finalContents.split(from).join(to);
204
- }
205
-
206
- return {
207
- contents: finalContents,
208
- // TODO: Update sourcemap with adjusted contents
209
- map
210
- };
211
- }
package/lib/schema.js DELETED
@@ -1,391 +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
- function _diagnostic() {
10
- const data = _interopRequireWildcard(require("@parcel/diagnostic"));
11
-
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
- }
38
-
39
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
40
-
41
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
42
-
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; }
44
-
45
- // flowlint-next-line untyped-import:off
46
- function validateSchema(schema, data) {
47
- function walk(schemaAncestors, dataNode, dataPath) {
48
- let [schemaNode] = schemaAncestors;
49
-
50
- if (schemaNode.type) {
51
- let type = Array.isArray(dataNode) ? 'array' : typeof dataNode;
52
-
53
- if (schemaNode.type !== type) {
54
- return {
55
- type: 'type',
56
- dataType: 'value',
57
- dataPath,
58
- expectedTypes: [schemaNode.type],
59
- ancestors: schemaAncestors,
60
- prettyType: schemaNode.__type
61
- };
62
- } else {
63
- switch (schemaNode.type) {
64
- case 'array':
65
- {
66
- if (schemaNode.items) {
67
- let results = []; // $FlowFixMe type was already checked
68
-
69
- for (let i = 0; i < dataNode.length; i++) {
70
- let result = walk([schemaNode.items].concat(schemaAncestors), // $FlowFixMe type was already checked
71
- dataNode[i], dataPath + '/' + i);
72
- if (result) results.push(result);
73
- }
74
-
75
- if (results.length) return results.reduce((acc, v) => acc.concat(v), []);
76
- }
77
-
78
- break;
79
- }
80
-
81
- case 'string':
82
- {
83
- // $FlowFixMe type was already checked
84
- let value = dataNode;
85
-
86
- if (schemaNode.enum) {
87
- if (!schemaNode.enum.includes(value)) {
88
- return {
89
- type: 'enum',
90
- dataType: 'value',
91
- dataPath,
92
- expectedValues: schemaNode.enum,
93
- actualValue: value,
94
- ancestors: schemaAncestors
95
- };
96
- }
97
- } else if (schemaNode.__validate) {
98
- let validationError = schemaNode.__validate(value);
99
-
100
- if (typeof validationError == 'string') {
101
- return {
102
- type: 'other',
103
- dataType: 'value',
104
- dataPath,
105
- message: validationError,
106
- actualValue: value,
107
- ancestors: schemaAncestors
108
- };
109
- }
110
- }
111
-
112
- break;
113
- }
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
-
136
- case 'object':
137
- {
138
- let results = [];
139
- let invalidProps;
140
-
141
- if (schemaNode.__forbiddenProperties) {
142
- // $FlowFixMe type was already checked
143
- let keys = Object.keys(dataNode);
144
- invalidProps = schemaNode.__forbiddenProperties.filter(val => keys.includes(val));
145
- results.push(...invalidProps.map(k => ({
146
- type: 'forbidden-prop',
147
- dataPath: dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k),
148
- dataType: 'key',
149
- prop: k,
150
- expectedProps: Object.keys(schemaNode.properties),
151
- actualProps: keys,
152
- ancestors: schemaAncestors
153
- })));
154
- }
155
-
156
- if (schemaNode.required) {
157
- // $FlowFixMe type was already checked
158
- let keys = Object.keys(dataNode);
159
- let missingKeys = schemaNode.required.filter(val => !keys.includes(val));
160
- results.push(...missingKeys.map(k => ({
161
- type: 'missing-prop',
162
- dataPath,
163
- dataType: 'value',
164
- prop: k,
165
- expectedProps: schemaNode.required,
166
- actualProps: keys,
167
- ancestors: schemaAncestors
168
- })));
169
- }
170
-
171
- if (schemaNode.properties) {
172
- let {
173
- additionalProperties = true
174
- } = schemaNode; // $FlowFixMe type was already checked
175
-
176
- for (let k in dataNode) {
177
- if (invalidProps && invalidProps.includes(k)) {
178
- // Don't check type on forbidden props
179
- continue;
180
- } else if (k in schemaNode.properties) {
181
- let result = walk([schemaNode.properties[k]].concat(schemaAncestors), // $FlowFixMe type was already checked
182
- dataNode[k], dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k));
183
- if (result) results.push(result);
184
- } else {
185
- if (typeof additionalProperties === 'boolean') {
186
- if (!additionalProperties) {
187
- results.push({
188
- type: 'enum',
189
- dataType: 'key',
190
- dataPath: dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k),
191
- expectedValues: Object.keys(schemaNode.properties).filter( // $FlowFixMe type was already checked
192
- p => !(p in dataNode)),
193
- actualValue: k,
194
- ancestors: schemaAncestors,
195
- prettyType: schemaNode.__type
196
- });
197
- }
198
- } else {
199
- let result = walk([additionalProperties].concat(schemaAncestors), // $FlowFixMe type was already checked
200
- dataNode[k], dataPath + '/' + (0, _diagnostic().encodeJSONKeyComponent)(k));
201
- if (result) results.push(result);
202
- }
203
- }
204
- }
205
- }
206
-
207
- if (results.length) return results.reduce((acc, v) => acc.concat(v), []);
208
- break;
209
- }
210
-
211
- case 'boolean':
212
- // NOOP, type was checked already
213
- break;
214
-
215
- default:
216
- throw new Error(`Unimplemented schema type ${type}?`);
217
- }
218
- }
219
- } else {
220
- if (schemaNode.enum && !schemaNode.enum.includes(dataNode)) {
221
- return {
222
- type: 'enum',
223
- dataType: 'value',
224
- dataPath: dataPath,
225
- expectedValues: schemaNode.enum,
226
- actualValue: schemaNode,
227
- ancestors: schemaAncestors
228
- };
229
- }
230
-
231
- if (schemaNode.oneOf || schemaNode.allOf) {
232
- let list = schemaNode.oneOf || schemaNode.allOf;
233
- let results = [];
234
-
235
- for (let f of list) {
236
- let result = walk([f].concat(schemaAncestors), dataNode, dataPath);
237
- if (result) results.push(result);
238
- }
239
-
240
- if (schemaNode.oneOf ? results.length == schemaNode.oneOf.length : results.length > 0) {
241
- // return the result with more values / longer key
242
- 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);
243
- return results[0];
244
- }
245
- } else if (schemaNode.not) {
246
- let result = walk([schemaNode.not].concat(schemaAncestors), dataNode, dataPath);
247
-
248
- if (!result || result.length == 0) {
249
- return {
250
- type: 'other',
251
- dataPath,
252
- dataType: null,
253
- message: schemaNode.__message,
254
- actualValue: dataNode,
255
- ancestors: schemaAncestors
256
- };
257
- }
258
- }
259
- }
260
-
261
- return undefined;
262
- }
263
-
264
- let result = walk([schema], data, '');
265
- return Array.isArray(result) ? result : result ? [result] : [];
266
- }
267
-
268
- var _default = validateSchema;
269
- exports.default = _default;
270
-
271
- function fuzzySearch(expectedValues, actualValue) {
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
273
- ([, d]) => d * 2 < actualValue.length);
274
- result.sort(([, a], [, b]) => a - b);
275
- return result.map(([v]) => v);
276
- }
277
-
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);
288
-
289
- if (errors.length) {
290
- var _data$filePath;
291
-
292
- let keys = errors.map(e => {
293
- let message;
294
-
295
- if (e.type === 'enum') {
296
- let {
297
- actualValue
298
- } = e;
299
- let expectedValues = e.expectedValues.map(String);
300
- let likely = actualValue != null ? fuzzySearch(expectedValues, String(actualValue)) : [];
301
-
302
- if (likely.length > 0) {
303
- message = `Did you mean ${likely.map(v => JSON.stringify(v)).join(', ')}?`;
304
- } else if (expectedValues.length > 0) {
305
- message = `Possible values: ${expectedValues.map(v => JSON.stringify(v)).join(', ')}`;
306
- } else {
307
- message = 'Unexpected value';
308
- }
309
- } else if (e.type === 'forbidden-prop') {
310
- let {
311
- prop,
312
- expectedProps,
313
- actualProps
314
- } = e;
315
- let likely = fuzzySearch(expectedProps, prop).filter(v => !actualProps.includes(v));
316
-
317
- if (likely.length > 0) {
318
- message = `Did you mean ${likely.map(v => JSON.stringify(v)).join(', ')}?`;
319
- } else {
320
- message = 'Unexpected property';
321
- }
322
- } else if (e.type === 'missing-prop') {
323
- let {
324
- prop,
325
- actualProps
326
- } = e;
327
- let likely = fuzzySearch(actualProps, prop);
328
-
329
- if (likely.length > 0) {
330
- message = `Did you mean ${JSON.stringify(prop)}?`;
331
- e.dataPath += '/' + likely[0];
332
- e.dataType = 'key';
333
- } else {
334
- message = `Missing property ${prop}`;
335
- }
336
- } else if (e.type === 'type') {
337
- if (e.prettyType != null) {
338
- message = `Expected ${e.prettyType}`;
339
- } else {
340
- message = `Expected type ${e.expectedTypes.join(', ')}`;
341
- }
342
- } else {
343
- message = e.message;
344
- }
345
-
346
- return {
347
- key: e.dataPath,
348
- type: e.dataType,
349
- message
350
- };
351
- });
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(({
370
- key,
371
- type,
372
- message
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)({
384
- diagnostic: {
385
- message: message,
386
- origin,
387
- codeFrames
388
- }
389
- });
390
- }
391
- };
@@ -1,31 +0,0 @@
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
- }