@parcel/utils 2.11.0 → 2.13.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/utils",
3
- "version": "2.11.0",
3
+ "version": "2.13.0",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -17,7 +17,7 @@
17
17
  "main": "lib/index.js",
18
18
  "source": "src/index.js",
19
19
  "engines": {
20
- "node": ">= 12.0.0"
20
+ "node": ">= 16.0.0"
21
21
  },
22
22
  "targets": {
23
23
  "main": {
@@ -33,13 +33,13 @@
33
33
  }
34
34
  },
35
35
  "dependencies": {
36
- "@parcel/codeframe": "2.11.0",
37
- "@parcel/diagnostic": "2.11.0",
38
- "@parcel/logger": "2.11.0",
39
- "@parcel/markdown-ansi": "2.11.0",
40
- "@parcel/rust": "2.11.0",
36
+ "@parcel/codeframe": "2.13.0",
37
+ "@parcel/diagnostic": "2.13.0",
38
+ "@parcel/logger": "2.13.0",
39
+ "@parcel/markdown-ansi": "2.13.0",
40
+ "@parcel/rust": "2.13.0",
41
41
  "@parcel/source-map": "^2.1.1",
42
- "chalk": "^4.1.0",
42
+ "chalk": "^4.1.2",
43
43
  "nullthrows": "^1.1.1"
44
44
  },
45
45
  "devDependencies": {
@@ -51,12 +51,11 @@
51
51
  "is-glob": "^4.0.0",
52
52
  "is-url": "^1.2.2",
53
53
  "json5": "^2.2.0",
54
- "lru-cache": "^6.0.0",
54
+ "lru-cache": "^10.0.0",
55
55
  "micromatch": "^4.0.4",
56
56
  "node-forge": "^1.2.1",
57
57
  "nullthrows": "^1.1.1",
58
58
  "open": "^7.0.3",
59
- "random-int": "^1.0.0",
60
59
  "snarkdown": "^2.0.0",
61
60
  "strip-ansi": "^6.0.0",
62
61
  "terminal-link": "^2.1.1"
@@ -67,5 +66,5 @@
67
66
  "./src/openInBrowser.js": false,
68
67
  "@parcel/markdown-ansi": false
69
68
  },
70
- "gitHead": "f8076f1644cabc944695b5ec82602c8ae32bcf21"
69
+ "gitHead": "a53f8f3ba1025c7ea8653e9719e0a61ef9717079"
71
70
  }
@@ -13,6 +13,7 @@ export default class PromiseQueue<T> {
13
13
  _error: mixed;
14
14
  _count: number = 0;
15
15
  _results: Array<T> = [];
16
+ _addSubscriptions: Set<() => void> = new Set();
16
17
 
17
18
  constructor(opts: PromiseQueueOpts = {maxConcurrent: Infinity}) {
18
19
  if (opts.maxConcurrent <= 0) {
@@ -43,12 +44,24 @@ export default class PromiseQueue<T> {
43
44
 
44
45
  this._queue.push(wrapped);
45
46
 
47
+ for (const addFn of this._addSubscriptions) {
48
+ addFn();
49
+ }
50
+
46
51
  if (this._numRunning > 0 && this._numRunning < this._maxConcurrent) {
47
52
  this._next();
48
53
  }
49
54
  });
50
55
  }
51
56
 
57
+ subscribeToAdd(fn: () => void): () => void {
58
+ this._addSubscriptions.add(fn);
59
+
60
+ return () => {
61
+ this._addSubscriptions.delete(fn);
62
+ };
63
+ }
64
+
52
65
  run(): Promise<Array<T>> {
53
66
  if (this._runPromise != null) {
54
67
  return this._runPromise;
@@ -1,6 +1,6 @@
1
1
  // @flow
2
2
  import path from 'path';
3
- import type {FileSystem} from '@parcel/fs';
3
+ import type {FileSystem} from '@parcel/types';
4
4
  import {fuzzySearch} from './schema';
5
5
  import {relativePath} from './path';
6
6
  import {resolveConfig} from './config';
@@ -141,5 +141,5 @@ export async function findAlternativeFiles(
141
141
  });
142
142
  }
143
143
 
144
- return fuzzySearch(potentialFiles, fileSpecifier).slice(0, 2);
144
+ return fuzzySearch(potentialFiles.sort(), fileSpecifier).slice(0, 2);
145
145
  }
package/src/config.js CHANGED
@@ -7,7 +7,7 @@ import path from 'path';
7
7
  import clone from 'clone';
8
8
  import json5 from 'json5';
9
9
  import {parse as toml} from '@iarna/toml';
10
- import LRU from 'lru-cache';
10
+ import {LRUCache} from 'lru-cache';
11
11
 
12
12
  export type ConfigOutput = {|
13
13
  config: ConfigResult,
@@ -19,7 +19,7 @@ export type ConfigOptions = {|
19
19
  parser?: string => any,
20
20
  |};
21
21
 
22
- const configCache = new LRU<FilePath, ConfigOutput>({max: 500});
22
+ const configCache = new LRUCache<FilePath, ConfigOutput>({max: 500});
23
23
  const resolveCache = new Map();
24
24
 
25
25
  export function resolveConfig(
@@ -96,7 +96,7 @@ export async function loadConfig(
96
96
  }
97
97
 
98
98
  loadConfig.clear = () => {
99
- configCache.reset();
99
+ configCache.clear();
100
100
  resolveCache.clear();
101
101
  };
102
102
 
package/src/index.js CHANGED
@@ -86,3 +86,4 @@ export {
86
86
  remapSourceLocation,
87
87
  } from './sourcemap';
88
88
  export {default as stripAnsi} from 'strip-ansi';
89
+ export {detectSVGOVersion} from './svgo';
package/src/svgo.js ADDED
@@ -0,0 +1,50 @@
1
+ // @flow
2
+ export function detectSVGOVersion(
3
+ config: any,
4
+ ): {|version: 3|} | {|version: 2, path: string|} {
5
+ if (!config) {
6
+ return {version: 3};
7
+ }
8
+
9
+ // These options were removed in v2.
10
+ if (config.full != null || config.svg2js != null) {
11
+ return {version: 2, path: config.full != null ? '/full' : '/svg2js'};
12
+ }
13
+
14
+ if (Array.isArray(config.plugins)) {
15
+ // Custom plugins in v2 had additional (required) fields that don't exist anymore.
16
+ let v2Plugin = config.plugins.findIndex(
17
+ p => p?.type != null || (p?.fn && p?.params != null),
18
+ );
19
+ if (v2Plugin !== -1) {
20
+ let field = config.plugins[v2Plugin].type != null ? 'type' : 'params';
21
+ return {version: 2, path: `/plugins/${v2Plugin}/${field}`};
22
+ }
23
+
24
+ // the cleanupIDs plugin lost the prefix option in v3.
25
+ let cleanupIdsIndex = config.plugins.findIndex(
26
+ p => p?.name === 'cleanupIDs',
27
+ );
28
+ let cleanupIDs =
29
+ cleanupIdsIndex !== -1 ? config.plugins[cleanupIdsIndex] : null;
30
+ if (cleanupIDs?.params?.prefix != null) {
31
+ return {version: 2, path: `/plugins/${cleanupIdsIndex}/params/prefix`};
32
+ }
33
+
34
+ // Automatically migrate some options from SVGO 2 config files.
35
+ config.plugins = config.plugins.filter(p => p?.active !== false);
36
+
37
+ for (let i = 0; i < config.plugins.length; i++) {
38
+ let p = config.plugins[i];
39
+ if (p === 'cleanupIDs') {
40
+ config.plugins[i] = 'cleanupIds';
41
+ }
42
+
43
+ if (p?.name === 'cleanupIDs') {
44
+ config.plugins[i].name = 'cleanupIds';
45
+ }
46
+ }
47
+ }
48
+
49
+ return {version: 3};
50
+ }
@@ -1,8 +1,8 @@
1
1
  // @flow
2
2
  import assert from 'assert';
3
- import randomInt from 'random-int';
4
3
 
5
4
  import PromiseQueue from '../src/PromiseQueue';
5
+ import sinon from 'sinon';
6
6
 
7
7
  describe('PromiseQueue', () => {
8
8
  it('run() should resolve when all async functions in queue have completed', async () => {
@@ -65,11 +65,38 @@ describe('PromiseQueue', () => {
65
65
  running++;
66
66
  assert(queue._numRunning === running);
67
67
  assert(running <= maxConcurrent);
68
- await Promise.resolve(randomInt(1, 10)); //sleep(randomInt(1, 10));
68
+ await Promise.resolve(Math.floor(Math.random() * 10) + 1);
69
69
  running--;
70
70
  }),
71
71
  );
72
72
 
73
73
  await queue.run();
74
74
  });
75
+
76
+ it('.add() should notify subscribers', async () => {
77
+ const queue = new PromiseQueue();
78
+
79
+ const subscribedFn = sinon.spy();
80
+ queue.subscribeToAdd(subscribedFn);
81
+
82
+ const promise = queue.add(() => Promise.resolve());
83
+ await queue.run();
84
+ await promise;
85
+
86
+ assert(subscribedFn.called);
87
+ });
88
+
89
+ it('.subscribeToAdd() should allow unsubscribing', async () => {
90
+ const queue = new PromiseQueue();
91
+
92
+ const subscribedFn = sinon.spy();
93
+ const unsubscribe = queue.subscribeToAdd(subscribedFn);
94
+ unsubscribe();
95
+
96
+ const promise = queue.add(() => Promise.resolve());
97
+ await queue.run();
98
+ await promise;
99
+
100
+ assert(!subscribedFn.called);
101
+ });
75
102
  });