@atlaspack/utils 2.12.1-dev.3478 → 2.12.1-dev.3520

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/utils",
3
- "version": "2.12.1-dev.3478+5fd2da535",
3
+ "version": "2.12.1-dev.3520+8a5346e28",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -29,11 +29,11 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@atlaspack/codeframe": "2.12.1-dev.3478+5fd2da535",
33
- "@atlaspack/diagnostic": "2.12.1-dev.3478+5fd2da535",
34
- "@atlaspack/logger": "2.12.1-dev.3478+5fd2da535",
35
- "@atlaspack/markdown-ansi": "2.12.1-dev.3478+5fd2da535",
36
- "@atlaspack/rust": "2.12.1-dev.3478+5fd2da535",
32
+ "@atlaspack/codeframe": "2.12.1-dev.3520+8a5346e28",
33
+ "@atlaspack/diagnostic": "2.12.1-dev.3520+8a5346e28",
34
+ "@atlaspack/logger": "2.12.1-dev.3520+8a5346e28",
35
+ "@atlaspack/markdown-ansi": "2.12.1-dev.3520+8a5346e28",
36
+ "@atlaspack/rust": "2.12.1-dev.3520+8a5346e28",
37
37
  "@parcel/source-map": "^2.1.1",
38
38
  "chalk": "^4.1.0",
39
39
  "nullthrows": "^1.1.1"
@@ -63,5 +63,5 @@
63
63
  "./src/openInBrowser.js": false,
64
64
  "@atlaspack/markdown-ansi": false
65
65
  },
66
- "gitHead": "5fd2da535ecbe096d57e03aec15e80bb1d7601f7"
66
+ "gitHead": "8a5346e28c1bb3b9cd40f1c4e77c66dd6666f1e4"
67
67
  }
package/src/DefaultMap.js CHANGED
@@ -22,9 +22,11 @@ export class DefaultMap<K, V> extends Map<K, V> {
22
22
  }
23
23
  }
24
24
 
25
+ interface Key {}
26
+
25
27
  // Duplicated from DefaultMap implementation for Flow
26
28
  // Roughly mirrors https://github.com/facebook/flow/blob/2eb5a78d92c167117ba9caae070afd2b9f598599/lib/core.js#L617
27
- export class DefaultWeakMap<K: interface {}, V> extends WeakMap<K, V> {
29
+ export class DefaultWeakMap<K: Key, V> extends WeakMap<K, V> {
28
30
  _getDefault: (K) => V;
29
31
 
30
32
  constructor(getDefault: (K) => V, entries?: Iterable<[K, V]>) {
@@ -27,8 +27,8 @@ export default class PromiseQueue<T> {
27
27
  return this._queue.length;
28
28
  }
29
29
 
30
- add(fn: () => Promise<T>): Promise<T> {
31
- return new Promise((resolve, reject) => {
30
+ add(fn: () => Promise<T>): void {
31
+ new Promise((resolve, reject) => {
32
32
  let i = this._count++;
33
33
  let wrapped = () =>
34
34
  fn().then(
@@ -51,7 +51,7 @@ export default class PromiseQueue<T> {
51
51
  if (this._numRunning > 0 && this._numRunning < this._maxConcurrent) {
52
52
  this._next();
53
53
  }
54
- });
54
+ }).catch(() => {});
55
55
  }
56
56
 
57
57
  subscribeToAdd(fn: () => void): () => void {
@@ -1,10 +1,10 @@
1
1
  // @flow
2
2
 
3
3
  export default function createDependencyLocation(
4
- start: interface {
4
+ start: {|
5
5
  line: number,
6
6
  column: number,
7
- },
7
+ |},
8
8
  specifier: string,
9
9
  lineOffset: number = 0,
10
10
  columnOffset: number = 0,
@@ -23,37 +23,37 @@ describe('PromiseQueue', () => {
23
23
  let error = new Error('some failure');
24
24
  try {
25
25
  let queue = new PromiseQueue();
26
- queue
27
- .add(() => Promise.reject(error))
28
- .catch(
29
- /* catch this to prevent an unhandled promise rejection*/ () => {},
30
- );
26
+ queue.add(() => Promise.reject(error));
31
27
  await queue.run();
32
28
  } catch (e) {
33
29
  assert.equal(e, error);
34
30
  }
35
31
  });
36
32
 
37
- it('.run() should instantly resolve when the queue is empty', async () => {
38
- let queue = new PromiseQueue();
39
- await queue.run();
40
- // no need to assert, test will hang or throw an error if condition fails
33
+ it('run() should reject if any of the async functions in the queue throwo', async () => {
34
+ let error = new Error('some failure');
35
+ try {
36
+ let queue = new PromiseQueue();
37
+ queue.add(() => {
38
+ throw error;
39
+ });
40
+ await queue.run();
41
+ } catch (e) {
42
+ assert.equal(e, error);
43
+ }
41
44
  });
42
45
 
43
- it(".add() should resolve with the same result when the passed in function's promise resolves", async () => {
46
+ it('.run() should instantly resolve when the queue is empty', async () => {
44
47
  let queue = new PromiseQueue();
45
- let promise = queue.add(() => Promise.resolve(42));
46
48
  await queue.run();
47
- let result = await promise;
48
- assert.equal(result, 42);
49
+ // no need to assert, test will hang or throw an error if condition fails
49
50
  });
50
51
 
51
- it(".add() should reject with the same error when the passed in function's promise rejects", async () => {
52
+ it('.add() result should bubble into the run results', async () => {
52
53
  let queue = new PromiseQueue();
53
- let error = new Error('Oh no!');
54
- let promise = queue.add(() => Promise.reject(error));
55
- await queue.run().catch(() => null);
56
- await promise.then(null, (e) => assert.equal(e, error));
54
+ queue.add(() => Promise.resolve(42));
55
+ const result = await queue.run();
56
+ assert.deepEqual(result, [42]);
57
57
  });
58
58
 
59
59
  it('constructor() should allow for configuration of max concurrent running functions', async () => {
@@ -87,6 +87,31 @@ describe('PromiseQueue', () => {
87
87
  assert(subscribedFn.called);
88
88
  });
89
89
 
90
+ it('runs functions concurrently', () => {
91
+ const queue = new PromiseQueue();
92
+
93
+ const fn1 = sinon
94
+ .stub()
95
+ .returns(new Promise((resolve) => setTimeout(resolve, 5000)));
96
+
97
+ queue.add(fn1); // queue does not work if nothing is running, this is broken behaviour
98
+ queue.run();
99
+
100
+ const fn2 = sinon
101
+ .stub()
102
+ .returns(new Promise((resolve) => setTimeout(resolve, 5000)));
103
+ const fn3 = sinon
104
+ .stub()
105
+ .returns(new Promise((resolve) => setTimeout(resolve, 5000)));
106
+
107
+ queue.add(fn2);
108
+ queue.add(fn3);
109
+
110
+ assert(fn1.calledOnce);
111
+ assert(fn2.calledOnce);
112
+ assert(fn3.calledOnce);
113
+ });
114
+
90
115
  it('.subscribeToAdd() should allow unsubscribing', async () => {
91
116
  const queue = new PromiseQueue();
92
117