@parcel/utils 2.9.2 → 2.10.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.9.2",
3
+ "version": "2.10.0",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -24,7 +24,7 @@
24
24
  "includeNodeModules": {
25
25
  "@parcel/codeframe": false,
26
26
  "@parcel/diagnostic": false,
27
- "@parcel/hash": false,
27
+ "@parcel/rust": false,
28
28
  "@parcel/logger": false,
29
29
  "@parcel/markdown-ansi": false,
30
30
  "@parcel/source-map": false,
@@ -33,11 +33,11 @@
33
33
  }
34
34
  },
35
35
  "dependencies": {
36
- "@parcel/codeframe": "2.9.2",
37
- "@parcel/diagnostic": "2.9.2",
38
- "@parcel/hash": "2.9.2",
39
- "@parcel/logger": "2.9.2",
40
- "@parcel/markdown-ansi": "2.9.2",
36
+ "@parcel/codeframe": "2.10.0",
37
+ "@parcel/diagnostic": "2.10.0",
38
+ "@parcel/logger": "2.10.0",
39
+ "@parcel/markdown-ansi": "2.10.0",
40
+ "@parcel/rust": "2.10.0",
41
41
  "@parcel/source-map": "^2.1.1",
42
42
  "chalk": "^4.1.0",
43
43
  "nullthrows": "^1.1.1"
@@ -65,5 +65,5 @@
65
65
  "./src/http-server.js": false,
66
66
  "./src/openInBrowser.js": false
67
67
  },
68
- "gitHead": "76aa20fc2f752fae9c7347f071ea457b112a5dad"
68
+ "gitHead": "0e235842b5b93301379bdfa626e7a4e2ee42ea98"
69
69
  }
package/src/hash.js CHANGED
@@ -4,7 +4,7 @@ import type {Readable} from 'stream';
4
4
  import type {FileSystem} from '@parcel/fs';
5
5
 
6
6
  import {objectSortedEntriesDeep} from './collection';
7
- import {hashString, Hash} from '@parcel/hash';
7
+ import {hashString, Hash} from '@parcel/rust';
8
8
 
9
9
  export function hashStream(stream: Readable): Promise<string> {
10
10
  let hash = new Hash();
package/src/index.js CHANGED
@@ -85,5 +85,4 @@ export {
85
85
  loadSourceMap,
86
86
  remapSourceLocation,
87
87
  } from './sourcemap';
88
- export {BitSet} from './BitSet';
89
88
  export {default as stripAnsi} from 'strip-ansi';
package/src/BitSet.js DELETED
@@ -1,126 +0,0 @@
1
- // @flow strict-local
2
- import nullthrows from 'nullthrows';
3
-
4
- // As our current version of flow doesn't support BigInt's, these values/types
5
- // have been hoisted to keep the flow errors to a minimum. This can be removed
6
- // if we upgrade to a flow version that supports BigInt's
7
- // $FlowFixMe
8
- type TmpBigInt = bigint;
9
- // $FlowFixMe
10
- const BIGINT_ZERO = 0n;
11
- // $FlowFixMe
12
- const BIGINT_ONE = 1n;
13
- // $FlowFixMe
14
- let numberToBigInt = (v: number): TmpBigInt => BigInt(v);
15
-
16
- let bitUnion = (a: TmpBigInt, b: TmpBigInt): TmpBigInt => a | b;
17
-
18
- export class BitSet<Item> {
19
- _value: TmpBigInt;
20
- _lookup: Map<Item, TmpBigInt>;
21
- _items: Array<Item>;
22
-
23
- constructor({
24
- initial,
25
- items,
26
- lookup,
27
- }: {|
28
- items: Array<Item>,
29
- lookup: Map<Item, number>,
30
- initial?: BitSet<Item> | TmpBigInt,
31
- |}) {
32
- if (initial instanceof BitSet) {
33
- this._value = initial?._value;
34
- } else if (initial) {
35
- this._value = initial;
36
- } else {
37
- this._value = BIGINT_ZERO;
38
- }
39
-
40
- this._items = items;
41
- this._lookup = lookup;
42
- }
43
-
44
- static from(items: Array<Item>): BitSet<Item> {
45
- let lookup: Map<Item, TmpBigInt> = new Map();
46
- for (let i = 0; i < items.length; i++) {
47
- lookup.set(items[i], numberToBigInt(i));
48
- }
49
-
50
- return new BitSet({items, lookup});
51
- }
52
-
53
- static union(a: BitSet<Item>, b: BitSet<Item>): BitSet<Item> {
54
- return new BitSet({
55
- initial: bitUnion(a._value, b._value),
56
- lookup: a._lookup,
57
- items: a._items,
58
- });
59
- }
60
-
61
- #getIndex(item: Item) {
62
- return nullthrows(this._lookup.get(item), 'Item is missing from BitSet');
63
- }
64
-
65
- add(item: Item) {
66
- this._value |= BIGINT_ONE << this.#getIndex(item);
67
- }
68
-
69
- delete(item: Item) {
70
- this._value &= ~(BIGINT_ONE << this.#getIndex(item));
71
- }
72
-
73
- has(item: Item): boolean {
74
- return Boolean(this._value & (BIGINT_ONE << this.#getIndex(item)));
75
- }
76
-
77
- intersect(v: BitSet<Item>) {
78
- this._value = this._value & v._value;
79
- }
80
-
81
- union(v: BitSet<Item>) {
82
- this._value = bitUnion(this._value, v._value);
83
- }
84
-
85
- clear() {
86
- this._value = BIGINT_ZERO;
87
- }
88
-
89
- cloneEmpty(): BitSet<Item> {
90
- return new BitSet({
91
- lookup: this._lookup,
92
- items: this._items,
93
- });
94
- }
95
-
96
- clone(): BitSet<Item> {
97
- return new BitSet({
98
- lookup: this._lookup,
99
- items: this._items,
100
- initial: this._value,
101
- });
102
- }
103
-
104
- values(): Array<Item> {
105
- let values = [];
106
- let tmpValue = this._value;
107
- let i;
108
-
109
- // This implementation is optimized for BitSets that contain a very small percentage
110
- // of items compared to the total number of potential items. This makes sense for
111
- // our bundler use-cases where Sets often contain <1% coverage of the total item count.
112
- // In cases where Sets contain a larger percentage of the total items, a regular looping
113
- // strategy would be more performant.
114
- while (tmpValue > BIGINT_ZERO) {
115
- // Get last set bit
116
- i = tmpValue.toString(2).length - 1;
117
-
118
- values.push(this._items[i]);
119
-
120
- // Unset last set bit
121
- tmpValue &= ~(BIGINT_ONE << numberToBigInt(i));
122
- }
123
-
124
- return values;
125
- }
126
- }
@@ -1,119 +0,0 @@
1
- // @flow strict-local
2
-
3
- import assert from 'assert';
4
- import {BitSet} from '../src/BitSet';
5
-
6
- function assertValues<Item>(set: BitSet<Item>, values: Array<Item>) {
7
- let setValues = set.values();
8
-
9
- for (let value of values) {
10
- assert(set.has(value), 'Set.has returned false');
11
- assert(
12
- setValues.some(v => v === value),
13
- 'Set values is missing value',
14
- );
15
- }
16
-
17
- assert(
18
- setValues.length === values.length,
19
- `Expected ${values.length} values but got ${setValues.length}`,
20
- );
21
- }
22
-
23
- describe('BitSet', () => {
24
- it('cloneEmpty should return an empty set', () => {
25
- let set1 = BitSet.from([1, 2, 3, 4, 5]);
26
- set1.add(1);
27
- set1.add(3);
28
-
29
- let set2 = set1.cloneEmpty();
30
-
31
- assertValues(set2, []);
32
- });
33
-
34
- it('clone should return a set with the same values', () => {
35
- let set1 = BitSet.from([1, 2, 3, 4, 5]);
36
- set1.add(1);
37
- set1.add(3);
38
-
39
- let set2 = set1.clone();
40
-
41
- assertValues(set2, [1, 3]);
42
- });
43
-
44
- it('clear should remove all values from the set', () => {
45
- let set1 = BitSet.from([1, 2, 3, 4, 5]);
46
- set1.add(1);
47
- set1.add(3);
48
-
49
- set1.clear();
50
-
51
- assertValues(set1, []);
52
- });
53
-
54
- it('delete should remove values from the set', () => {
55
- let set1 = BitSet.from([1, 2, 3, 4, 5]);
56
- set1.add(1);
57
- set1.add(3);
58
- set1.add(5);
59
-
60
- set1.delete(3);
61
-
62
- assertValues(set1, [1, 5]);
63
- });
64
-
65
- it('should intersect with another BitSet', () => {
66
- let set1 = BitSet.from([1, 2, 3, 4, 5]);
67
- set1.add(1);
68
- set1.add(3);
69
-
70
- let set2 = set1.cloneEmpty();
71
- set2.add(3);
72
- set2.add(5);
73
-
74
- set1.intersect(set2);
75
- assertValues(set1, [3]);
76
- });
77
-
78
- it('should union with another BitSet', () => {
79
- let set1 = BitSet.from([1, 2, 3, 4, 5]);
80
- set1.add(1);
81
- set1.add(3);
82
-
83
- let set2 = set1.cloneEmpty();
84
- set2.add(3);
85
- set2.add(5);
86
-
87
- set1.union(set2);
88
- assertValues(set1, [1, 3, 5]);
89
- });
90
-
91
- it('BitSet.union should create a new BitSet with the union', () => {
92
- let set1 = BitSet.from([1, 2, 3, 4, 5]);
93
- set1.add(1);
94
- set1.add(3);
95
-
96
- let set2 = set1.cloneEmpty();
97
- set2.add(3);
98
- set2.add(5);
99
-
100
- let set3 = BitSet.union(set1, set2);
101
- assertValues(set1, [1, 3]);
102
- assertValues(set2, [3, 5]);
103
- assertValues(set3, [1, 3, 5]);
104
- });
105
-
106
- it('returns an array of all values', () => {
107
- let set = BitSet.from([1, 2, 3, 4]);
108
- set.add(1);
109
- set.add(3);
110
-
111
- assertValues(set, [3, 1]);
112
- });
113
-
114
- it('should return an error if a new item is added', () => {
115
- let set = BitSet.from([1, 2, 3, 4]);
116
-
117
- assert.throws(() => set.add(5), /Item is missing from BitSet/);
118
- });
119
- });