@parcel/utils 2.0.0-nightly.137 → 2.0.0-nightly.1370
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/.eslintrc.js +6 -6
- package/lib/index.js +37566 -307
- package/lib/index.js.map +1 -0
- package/package.json +45 -20
- package/src/BitSet.js +126 -0
- package/src/DefaultMap.js +1 -1
- package/src/PromiseQueue.js +16 -12
- package/src/alternatives.js +145 -0
- package/src/ansi-html.js +2 -2
- package/src/blob.js +2 -1
- package/src/bundle-url.js +1 -1
- package/src/collection.js +35 -15
- package/src/config.js +132 -45
- package/src/countLines.js +5 -2
- package/src/debounce.js +1 -1
- package/src/dependency-location.js +11 -6
- package/src/generateBuildMetrics.js +158 -0
- package/src/generateCertificate.js +1 -1
- package/src/getCertificate.js +1 -1
- package/src/getExisting.js +1 -4
- package/src/getModuleParts.js +23 -0
- package/src/getRootDir.js +1 -2
- package/src/glob.js +51 -10
- package/src/hash.js +49 -0
- package/src/http-server.js +29 -19
- package/src/index.js +69 -21
- package/src/is-url.js +1 -1
- package/src/isDirectoryInside.js +11 -0
- package/src/openInBrowser.js +64 -0
- package/src/path.js +38 -6
- package/src/prettyDiagnostic.js +74 -24
- package/src/progress-message.js +22 -0
- package/src/relativeBundlePath.js +8 -13
- package/src/replaceBundleReferences.js +85 -41
- package/src/schema.js +100 -44
- package/src/shared-buffer.js +23 -0
- package/src/sourcemap.js +138 -0
- package/src/stream.js +31 -1
- package/src/urlJoin.js +3 -1
- package/test/BitSet.test.js +119 -0
- package/test/DefaultMap.test.js +7 -4
- package/test/collection.test.js +13 -1
- package/test/config.test.js +98 -0
- package/test/input/config/.testrc +3 -0
- package/test/input/config/config.cjs +3 -0
- package/test/input/config/config.js +3 -0
- package/test/input/config/config.json +3 -0
- package/test/input/config/empty.json +0 -0
- package/test/input/config/empty.toml +0 -0
- package/test/input/sourcemap/referenced-min.js +2 -0
- package/test/input/sourcemap/referenced-min.js.map +6 -0
- package/test/input/sourcemap/source-root.js +2 -0
- package/test/input/sourcemap/source-root.js.map +7 -0
- package/test/replaceBundleReferences.test.js +268 -0
- package/test/sourcemap.test.js +207 -0
- package/test/throttle.test.js +1 -2
- package/test/urlJoin.test.js +37 -0
- package/lib/DefaultMap.js +0 -64
- package/lib/Deferred.js +0 -26
- package/lib/PromiseQueue.js +0 -133
- package/lib/TapStream.js +0 -41
- package/lib/ansi-html.js +0 -16
- package/lib/blob.js +0 -31
- package/lib/bundle-url.js +0 -43
- package/lib/collection.js +0 -62
- package/lib/config.js +0 -88
- package/lib/countLines.js +0 -18
- package/lib/debounce.js +0 -20
- package/lib/dependency-location.js +0 -21
- package/lib/escape-html.js +0 -24
- package/lib/generateBundleReport.js +0 -38
- package/lib/generateCertificate.js +0 -124
- package/lib/getCertificate.js +0 -19
- package/lib/getExisting.js +0 -23
- package/lib/getRootDir.js +0 -55
- package/lib/glob.js +0 -76
- package/lib/http-server.js +0 -64
- package/lib/is-url.js +0 -17
- package/lib/loadSourceMapUrl.js +0 -33
- package/lib/md5.js +0 -35
- package/lib/objectHash.js +0 -26
- package/lib/parseCSSImport.js +0 -16
- package/lib/path.js +0 -22
- package/lib/prettifyTime.js +0 -10
- package/lib/prettyDiagnostic.js +0 -57
- package/lib/promisify.js +0 -13
- package/lib/relativeBundlePath.js +0 -24
- package/lib/relativeUrl.js +0 -16
- package/lib/replaceBundleReferences.js +0 -151
- package/lib/resolve.js +0 -93
- package/lib/schema.js +0 -320
- package/lib/serializeObject.js +0 -28
- package/lib/stream.js +0 -51
- package/lib/throttle.js +0 -16
- package/lib/urlJoin.js +0 -27
- package/src/.babelrc +0 -3
- package/src/generateBundleReport.js +0 -51
- package/src/loadSourceMapUrl.js +0 -33
- package/src/md5.js +0 -44
- package/src/promisify.js +0 -13
- package/src/resolve.js +0 -135
- package/src/serializeObject.js +0 -22
- package/test/input/sourcemap/referenced.js +0 -7
- package/test/loadSourceMapUrl.test.js +0 -37
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/utils",
|
|
3
|
-
"version": "2.0.0-nightly.
|
|
3
|
+
"version": "2.0.0-nightly.1370+5ac45672b",
|
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
+
"funding": {
|
|
10
|
+
"type": "opencollective",
|
|
11
|
+
"url": "https://opencollective.com/parcel"
|
|
12
|
+
},
|
|
9
13
|
"repository": {
|
|
10
14
|
"type": "git",
|
|
11
15
|
"url": "https://github.com/parcel-bundler/parcel.git"
|
|
@@ -13,32 +17,53 @@
|
|
|
13
17
|
"main": "lib/index.js",
|
|
14
18
|
"source": "src/index.js",
|
|
15
19
|
"engines": {
|
|
16
|
-
"node": ">=
|
|
20
|
+
"node": ">= 12.0.0"
|
|
21
|
+
},
|
|
22
|
+
"targets": {
|
|
23
|
+
"main": {
|
|
24
|
+
"includeNodeModules": {
|
|
25
|
+
"@parcel/codeframe": false,
|
|
26
|
+
"@parcel/diagnostic": false,
|
|
27
|
+
"@parcel/rust": false,
|
|
28
|
+
"@parcel/logger": false,
|
|
29
|
+
"@parcel/markdown-ansi": false,
|
|
30
|
+
"@parcel/source-map": false,
|
|
31
|
+
"chalk": false
|
|
32
|
+
}
|
|
33
|
+
}
|
|
17
34
|
},
|
|
18
35
|
"dependencies": {
|
|
36
|
+
"@parcel/codeframe": "2.0.0-nightly.1370+5ac45672b",
|
|
37
|
+
"@parcel/diagnostic": "2.0.0-nightly.1370+5ac45672b",
|
|
38
|
+
"@parcel/logger": "2.0.0-nightly.1370+5ac45672b",
|
|
39
|
+
"@parcel/markdown-ansi": "2.0.0-nightly.1370+5ac45672b",
|
|
40
|
+
"@parcel/rust": "2.9.4-nightly.2993+5ac45672b",
|
|
41
|
+
"@parcel/source-map": "^2.1.1",
|
|
42
|
+
"chalk": "^4.1.0",
|
|
43
|
+
"nullthrows": "^1.1.1"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
19
46
|
"@iarna/toml": "^2.2.0",
|
|
20
|
-
"
|
|
21
|
-
"@parcel/diagnostic": "2.0.0-nightly.137+a07a8b84",
|
|
22
|
-
"@parcel/logger": "2.0.0-nightly.137+a07a8b84",
|
|
23
|
-
"@parcel/markdown-ansi": "2.0.0-nightly.137+a07a8b84",
|
|
24
|
-
"ansi-html": "^0.0.7",
|
|
25
|
-
"chalk": "^2.4.2",
|
|
47
|
+
"ansi-html-community": "0.0.8",
|
|
26
48
|
"clone": "^2.1.1",
|
|
27
|
-
"fast-glob": "3.
|
|
49
|
+
"fast-glob": "^3.2.12",
|
|
50
|
+
"fastest-levenshtein": "^1.0.16",
|
|
28
51
|
"is-glob": "^4.0.0",
|
|
29
52
|
"is-url": "^1.2.2",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"micromatch": "^4.0.
|
|
33
|
-
"node-forge": "^
|
|
53
|
+
"json5": "^2.2.0",
|
|
54
|
+
"lru-cache": "^6.0.0",
|
|
55
|
+
"micromatch": "^4.0.4",
|
|
56
|
+
"node-forge": "^1.2.1",
|
|
34
57
|
"nullthrows": "^1.1.1",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
58
|
+
"open": "^7.0.3",
|
|
59
|
+
"random-int": "^1.0.0",
|
|
60
|
+
"strip-ansi": "^6.0.0",
|
|
61
|
+
"terminal-link": "^2.1.1"
|
|
38
62
|
},
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
63
|
+
"browser": {
|
|
64
|
+
"./src/generateCertificate.js": false,
|
|
65
|
+
"./src/http-server.js": false,
|
|
66
|
+
"./src/openInBrowser.js": false
|
|
42
67
|
},
|
|
43
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "5ac45672bb603841bf294c66019930be4354625a"
|
|
44
69
|
}
|
package/src/BitSet.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
}
|
package/src/DefaultMap.js
CHANGED
|
@@ -24,7 +24,7 @@ export class DefaultMap<K, V> extends Map<K, V> {
|
|
|
24
24
|
|
|
25
25
|
// Duplicated from DefaultMap implementation for Flow
|
|
26
26
|
// Roughly mirrors https://github.com/facebook/flow/blob/2eb5a78d92c167117ba9caae070afd2b9f598599/lib/core.js#L617
|
|
27
|
-
export class DefaultWeakMap<K: {
|
|
27
|
+
export class DefaultWeakMap<K: interface {}, V> extends WeakMap<K, V> {
|
|
28
28
|
_getDefault: K => V;
|
|
29
29
|
|
|
30
30
|
constructor(getDefault: K => V, entries?: Iterable<[K, V]>) {
|
package/src/PromiseQueue.js
CHANGED
|
@@ -10,6 +10,7 @@ export default class PromiseQueue<T> {
|
|
|
10
10
|
_numRunning: number = 0;
|
|
11
11
|
_queue: Array<() => Promise<void>> = [];
|
|
12
12
|
_runPromise: ?Promise<Array<T>> = null;
|
|
13
|
+
_error: mixed;
|
|
13
14
|
_count: number = 0;
|
|
14
15
|
_results: Array<T> = [];
|
|
15
16
|
|
|
@@ -74,7 +75,7 @@ export default class PromiseQueue<T> {
|
|
|
74
75
|
if (this._queue.length) {
|
|
75
76
|
this._next();
|
|
76
77
|
} else if (this._numRunning === 0) {
|
|
77
|
-
this.
|
|
78
|
+
this._done();
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
|
|
@@ -82,10 +83,15 @@ export default class PromiseQueue<T> {
|
|
|
82
83
|
this._numRunning++;
|
|
83
84
|
try {
|
|
84
85
|
await fn();
|
|
85
|
-
this._numRunning--;
|
|
86
86
|
} catch (e) {
|
|
87
|
-
|
|
88
|
-
//
|
|
87
|
+
// Only store the first error that occurs.
|
|
88
|
+
// We don't reject immediately so that any other concurrent
|
|
89
|
+
// requests have time to complete.
|
|
90
|
+
if (this._error == null) {
|
|
91
|
+
this._error = e;
|
|
92
|
+
}
|
|
93
|
+
} finally {
|
|
94
|
+
this._numRunning--;
|
|
89
95
|
}
|
|
90
96
|
}
|
|
91
97
|
|
|
@@ -98,17 +104,15 @@ export default class PromiseQueue<T> {
|
|
|
98
104
|
this._deferred = null;
|
|
99
105
|
}
|
|
100
106
|
|
|
101
|
-
|
|
107
|
+
_done(): void {
|
|
102
108
|
if (this._deferred != null) {
|
|
103
|
-
this.
|
|
109
|
+
if (this._error != null) {
|
|
110
|
+
this._deferred.reject(this._error);
|
|
111
|
+
} else {
|
|
112
|
+
this._deferred.resolve(this._results);
|
|
113
|
+
}
|
|
104
114
|
}
|
|
105
|
-
this._resetState();
|
|
106
|
-
}
|
|
107
115
|
|
|
108
|
-
_resolve(): void {
|
|
109
|
-
if (this._deferred != null) {
|
|
110
|
-
this._deferred.resolve(this._results);
|
|
111
|
-
}
|
|
112
116
|
this._resetState();
|
|
113
117
|
}
|
|
114
118
|
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import type {FileSystem} from '@parcel/fs';
|
|
4
|
+
import {fuzzySearch} from './schema';
|
|
5
|
+
import {relativePath} from './path';
|
|
6
|
+
import {resolveConfig} from './config';
|
|
7
|
+
|
|
8
|
+
export async function findAlternativeNodeModules(
|
|
9
|
+
fs: FileSystem,
|
|
10
|
+
moduleName: string,
|
|
11
|
+
dir: string,
|
|
12
|
+
): Promise<Array<string>> {
|
|
13
|
+
let potentialModules: Array<string> = [];
|
|
14
|
+
let root = path.parse(dir).root;
|
|
15
|
+
let isOrganisationModule = moduleName.startsWith('@');
|
|
16
|
+
|
|
17
|
+
while (dir !== root) {
|
|
18
|
+
// Skip node_modules directories
|
|
19
|
+
if (path.basename(dir) === 'node_modules') {
|
|
20
|
+
dir = path.dirname(dir);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
let modulesDir = path.join(dir, 'node_modules');
|
|
25
|
+
let stats = await fs.stat(modulesDir);
|
|
26
|
+
if (stats.isDirectory()) {
|
|
27
|
+
let dirContent = (await fs.readdir(modulesDir)).sort();
|
|
28
|
+
|
|
29
|
+
// Filter out the modules that interest us
|
|
30
|
+
let modules = dirContent.filter(i =>
|
|
31
|
+
isOrganisationModule ? i.startsWith('@') : !i.startsWith('@'),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// If it's an organisation module, loop through all the modules of that organisation
|
|
35
|
+
if (isOrganisationModule) {
|
|
36
|
+
await Promise.all(
|
|
37
|
+
modules.map(async item => {
|
|
38
|
+
let orgDirPath = path.join(modulesDir, item);
|
|
39
|
+
let orgDirContent = (await fs.readdir(orgDirPath)).sort();
|
|
40
|
+
|
|
41
|
+
// Add all org packages
|
|
42
|
+
potentialModules.push(...orgDirContent.map(i => `${item}/${i}`));
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
45
|
+
} else {
|
|
46
|
+
potentialModules.push(...modules);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} catch (err) {
|
|
50
|
+
// ignore
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Move up a directory
|
|
54
|
+
dir = path.dirname(dir);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return fuzzySearch(potentialModules.sort(), moduleName).slice(0, 2);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function findAllFilesUp({
|
|
61
|
+
fs,
|
|
62
|
+
dir,
|
|
63
|
+
root,
|
|
64
|
+
basedir,
|
|
65
|
+
maxlength,
|
|
66
|
+
collected,
|
|
67
|
+
leadingDotSlash = true,
|
|
68
|
+
includeDirectories = true,
|
|
69
|
+
}: {|
|
|
70
|
+
fs: FileSystem,
|
|
71
|
+
dir: string,
|
|
72
|
+
root: string,
|
|
73
|
+
basedir: string,
|
|
74
|
+
maxlength: number,
|
|
75
|
+
collected: Array<string>,
|
|
76
|
+
leadingDotSlash?: boolean,
|
|
77
|
+
includeDirectories?: boolean,
|
|
78
|
+
|}): Promise<mixed> {
|
|
79
|
+
let dirContent = (await fs.readdir(dir)).sort();
|
|
80
|
+
return Promise.all(
|
|
81
|
+
dirContent.map(async item => {
|
|
82
|
+
let fullPath = path.join(dir, item);
|
|
83
|
+
let relativeFilePath = relativePath(basedir, fullPath, leadingDotSlash);
|
|
84
|
+
if (relativeFilePath.length < maxlength) {
|
|
85
|
+
let stats = await fs.stat(fullPath);
|
|
86
|
+
let isDir = stats.isDirectory();
|
|
87
|
+
if ((isDir && includeDirectories) || stats.isFile()) {
|
|
88
|
+
collected.push(relativeFilePath);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// If it's a directory, run over each item within said directory...
|
|
92
|
+
if (isDir) {
|
|
93
|
+
return findAllFilesUp({
|
|
94
|
+
fs,
|
|
95
|
+
dir: fullPath,
|
|
96
|
+
root,
|
|
97
|
+
basedir,
|
|
98
|
+
maxlength,
|
|
99
|
+
collected,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}),
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export async function findAlternativeFiles(
|
|
108
|
+
fs: FileSystem,
|
|
109
|
+
fileSpecifier: string,
|
|
110
|
+
dir: string,
|
|
111
|
+
projectRoot: string,
|
|
112
|
+
leadingDotSlash?: boolean = true,
|
|
113
|
+
includeDirectories?: boolean = true,
|
|
114
|
+
includeExtension?: boolean = false,
|
|
115
|
+
): Promise<Array<string>> {
|
|
116
|
+
let potentialFiles: Array<string> = [];
|
|
117
|
+
// Find our root, we won't recommend files above the package root as that's bad practise
|
|
118
|
+
let pkg = await resolveConfig(
|
|
119
|
+
fs,
|
|
120
|
+
path.join(dir, 'index'),
|
|
121
|
+
['package.json'],
|
|
122
|
+
projectRoot,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
let pkgRoot = pkg ? path.dirname(pkg) : projectRoot;
|
|
126
|
+
await findAllFilesUp({
|
|
127
|
+
fs,
|
|
128
|
+
dir: pkgRoot,
|
|
129
|
+
root: pkgRoot,
|
|
130
|
+
basedir: dir,
|
|
131
|
+
maxlength: fileSpecifier.length + 10,
|
|
132
|
+
collected: potentialFiles,
|
|
133
|
+
leadingDotSlash,
|
|
134
|
+
includeDirectories,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
if (path.extname(fileSpecifier) === '' && !includeExtension) {
|
|
138
|
+
potentialFiles = potentialFiles.map(p => {
|
|
139
|
+
let ext = path.extname(p);
|
|
140
|
+
return ext.length > 0 ? p.slice(0, -ext.length) : p;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return fuzzySearch(potentialFiles, fileSpecifier).slice(0, 2);
|
|
145
|
+
}
|
package/src/ansi-html.js
CHANGED
package/src/blob.js
CHANGED
package/src/bundle-url.js
CHANGED
package/src/collection.js
CHANGED
|
@@ -4,28 +4,16 @@ export function unique<T>(array: Array<T>): Array<T> {
|
|
|
4
4
|
return [...new Set(array)];
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export function flatMap<T, U>(
|
|
8
|
-
array: Array<T>,
|
|
9
|
-
projectFn: (T, number, Array<T>) => Array<U>,
|
|
10
|
-
): Array<U> {
|
|
11
|
-
let out = [];
|
|
12
|
-
|
|
13
|
-
for (let arr of array.map(projectFn)) {
|
|
14
|
-
out.push(...arr);
|
|
15
|
-
}
|
|
16
|
-
return out;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
7
|
export function objectSortedEntries(obj: {
|
|
20
8
|
+[string]: mixed,
|
|
21
|
-
|
|
9
|
+
...
|
|
22
10
|
}): Array<[string, mixed]> {
|
|
23
11
|
return Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
|
|
24
12
|
}
|
|
25
13
|
|
|
26
14
|
export function objectSortedEntriesDeep(object: {
|
|
27
15
|
+[string]: mixed,
|
|
28
|
-
|
|
16
|
+
...
|
|
29
17
|
}): Array<[string, mixed]> {
|
|
30
18
|
let sortedEntries = objectSortedEntries(object);
|
|
31
19
|
for (let i = 0; i < sortedEntries.length; i++) {
|
|
@@ -46,12 +34,44 @@ function sortEntry(entry: mixed) {
|
|
|
46
34
|
return entry;
|
|
47
35
|
}
|
|
48
36
|
|
|
49
|
-
export function setDifference<T>(
|
|
37
|
+
export function setDifference<T>(
|
|
38
|
+
a: $ReadOnlySet<T>,
|
|
39
|
+
b: $ReadOnlySet<T>,
|
|
40
|
+
): Set<T> {
|
|
50
41
|
let difference = new Set();
|
|
51
42
|
for (let e of a) {
|
|
52
43
|
if (!b.has(e)) {
|
|
53
44
|
difference.add(e);
|
|
54
45
|
}
|
|
55
46
|
}
|
|
47
|
+
for (let d of b) {
|
|
48
|
+
if (!a.has(d)) {
|
|
49
|
+
difference.add(d);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
56
52
|
return difference;
|
|
57
53
|
}
|
|
54
|
+
|
|
55
|
+
export function setIntersect<T>(a: Set<T>, b: $ReadOnlySet<T>): void {
|
|
56
|
+
for (let entry of a) {
|
|
57
|
+
if (!b.has(entry)) {
|
|
58
|
+
a.delete(entry);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function setUnion<T>(a: Iterable<T>, b: Iterable<T>): Set<T> {
|
|
64
|
+
return new Set([...a, ...b]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function setEqual<T>(a: $ReadOnlySet<T>, b: $ReadOnlySet<T>): boolean {
|
|
68
|
+
if (a.size != b.size) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
for (let entry of a) {
|
|
72
|
+
if (!b.has(entry)) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|