@atlaspack/utils 2.17.3-typescript-5b4d3ad41.0 → 2.17.3
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/CHANGELOG.md +7 -0
- package/lib/DefaultMap.js +4 -0
- package/lib/ansi-html.js +0 -2
- package/lib/config.js +1 -3
- package/lib/debug-tools.js +0 -1
- package/lib/glob.js +4 -12
- package/lib/index.js +9 -164
- package/lib/is-url.js +0 -2
- package/lib/objectHash.js +1 -0
- package/lib/prettyDiagnostic.js +5 -3
- package/lib/schema.js +19 -38
- package/lib/shared-buffer.js +1 -5
- package/lib/urlJoin.js +1 -1
- package/package.json +15 -22
- package/src/{DefaultMap.ts → DefaultMap.js} +12 -8
- package/src/Deferred.js +23 -0
- package/src/{PromiseQueue.ts → PromiseQueue.js} +35 -40
- package/src/{TapStream.ts → TapStream.js} +7 -8
- package/src/{alternatives.ts → alternatives.js} +15 -14
- package/src/{ansi-html.ts → ansi-html.js} +1 -1
- package/src/{blob.ts → blob.js} +4 -2
- package/src/{bundle-url.ts → bundle-url.js} +5 -3
- package/src/{collection.ts → collection.js} +21 -14
- package/src/{config.ts → config.js} +19 -18
- package/src/{countLines.ts → countLines.js} +2 -0
- package/src/{debounce.ts → debounce.js} +5 -3
- package/src/{debug-tools.ts → debug-tools.js} +8 -6
- package/src/{dependency-location.ts → dependency-location.js} +11 -15
- package/src/{escape-html.ts → escape-html.js} +3 -5
- package/src/{generateBuildMetrics.ts → generateBuildMetrics.js} +18 -16
- package/src/{generateCertificate.ts → generateCertificate.js} +5 -7
- package/src/{getCertificate.ts → getCertificate.js} +3 -5
- package/src/{getExisting.ts → getExisting.js} +3 -4
- package/src/{getModuleParts.ts → getModuleParts.js} +2 -3
- package/src/{getRootDir.ts → getRootDir.js} +2 -0
- package/src/{glob.ts → glob.js} +10 -14
- package/src/{hash.ts → hash.js} +17 -22
- package/src/{http-server.ts → http-server.js} +38 -32
- package/src/{index.ts → index.js} +8 -7
- package/src/{is-url.ts → is-url.js} +2 -1
- package/src/{isDirectoryInside.ts → isDirectoryInside.js} +1 -0
- package/src/{objectHash.ts → objectHash.js} +4 -1
- package/src/{openInBrowser.ts → openInBrowser.js} +4 -2
- package/src/{parseCSSImport.ts → parseCSSImport.js} +2 -0
- package/src/{path.ts → path.js} +3 -1
- package/src/{prettifyTime.ts → prettifyTime.js} +2 -0
- package/src/{prettyDiagnostic.ts → prettyDiagnostic.js} +20 -22
- package/src/{progress-message.ts → progress-message.js} +2 -3
- package/src/{relativeBundlePath.ts → relativeBundlePath.js} +3 -3
- package/src/{relativeUrl.ts → relativeUrl.js} +1 -0
- package/src/{replaceBundleReferences.ts → replaceBundleReferences.js} +36 -54
- package/src/{schema.ts → schema.js} +141 -158
- package/src/{shared-buffer.ts → shared-buffer.js} +3 -5
- package/src/{sourcemap.ts → sourcemap.js} +6 -16
- package/src/{stream.ts → stream.js} +21 -29
- package/src/throttle.js +15 -0
- package/src/{urlJoin.ts → urlJoin.js} +3 -1
- package/test/{DefaultMap.test.ts → DefaultMap.test.js} +6 -4
- package/test/{PromiseQueue.test.ts → PromiseQueue.test.js} +6 -5
- package/test/{collection.test.ts → collection.test.js} +2 -0
- package/test/{config.test.ts → config.test.js} +3 -0
- package/test/{objectHash.test.ts → objectHash.test.js} +5 -4
- package/test/{prettifyTime.test.ts → prettifyTime.test.js} +1 -0
- package/test/{replaceBundleReferences.test.ts → replaceBundleReferences.test.js} +32 -0
- package/test/{sourcemap.test.ts → sourcemap.test.js} +1 -0
- package/test/{throttle.test.ts → throttle.test.js} +3 -1
- package/test/{urlJoin.test.ts → urlJoin.test.js} +2 -0
- package/LICENSE +0 -201
- package/lib/DefaultMap.d.ts +0 -13
- package/lib/Deferred.d.ts +0 -8
- package/lib/PromiseQueue.d.ts +0 -25
- package/lib/TapStream.d.ts +0 -6
- package/lib/alternatives.d.ts +0 -3
- package/lib/ansi-html.d.ts +0 -1
- package/lib/blob.d.ts +0 -4
- package/lib/bundle-url.d.ts +0 -4
- package/lib/collection.d.ts +0 -33
- package/lib/config.d.ts +0 -17
- package/lib/countLines.d.ts +0 -1
- package/lib/debounce.d.ts +0 -1
- package/lib/debug-tools.d.ts +0 -6
- package/lib/dependency-location.d.ts +0 -14
- package/lib/escape-html.d.ts +0 -1
- package/lib/generateBuildMetrics.d.ts +0 -18
- package/lib/generateCertificate.d.ts +0 -5
- package/lib/getCertificate.d.ts +0 -6
- package/lib/getExisting.d.ts +0 -8
- package/lib/getModuleParts.d.ts +0 -4
- package/lib/getRootDir.d.ts +0 -2
- package/lib/glob.d.ts +0 -10
- package/lib/hash.d.ts +0 -7
- package/lib/http-server.d.ts +0 -19
- package/lib/index.d.ts +0 -48
- package/lib/is-url.d.ts +0 -1
- package/lib/isDirectoryInside.d.ts +0 -2
- package/lib/objectHash.d.ts +0 -3
- package/lib/openInBrowser.d.ts +0 -1
- package/lib/parseCSSImport.d.ts +0 -1
- package/lib/path.d.ts +0 -8
- package/lib/prettifyTime.d.ts +0 -1
- package/lib/prettyDiagnostic.d.ts +0 -17
- package/lib/progress-message.d.ts +0 -3
- package/lib/relativeBundlePath.d.ts +0 -4
- package/lib/relativeUrl.d.ts +0 -1
- package/lib/replaceBundleReferences.d.ts +0 -39
- package/lib/schema.d.ts +0 -107
- package/lib/shared-buffer.d.ts +0 -2
- package/lib/sourcemap.d.ts +0 -16
- package/lib/stream.d.ts +0 -8
- package/lib/throttle.d.ts +0 -1
- package/lib/urlJoin.d.ts +0 -5
- package/src/Deferred.ts +0 -26
- package/src/throttle.ts +0 -13
- package/tsconfig.json +0 -4
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
1
3
|
export class DefaultMap<K, V> extends Map<K, V> {
|
|
2
|
-
_getDefault: (
|
|
4
|
+
_getDefault: (K) => V;
|
|
3
5
|
|
|
4
|
-
constructor(getDefault: (
|
|
6
|
+
constructor(getDefault: (K) => V, entries?: Iterable<[K, V]>) {
|
|
5
7
|
super(entries);
|
|
6
8
|
this._getDefault = getDefault;
|
|
7
9
|
}
|
|
@@ -15,7 +17,8 @@ export class DefaultMap<K, V> extends Map<K, V> {
|
|
|
15
17
|
this.set(key, ret);
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
// $FlowFixMe
|
|
21
|
+
return ret;
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
24
|
|
|
@@ -23,11 +26,11 @@ interface Key {}
|
|
|
23
26
|
|
|
24
27
|
// Duplicated from DefaultMap implementation for Flow
|
|
25
28
|
// Roughly mirrors https://github.com/facebook/flow/blob/2eb5a78d92c167117ba9caae070afd2b9f598599/lib/core.js#L617
|
|
26
|
-
export class DefaultWeakMap<K
|
|
27
|
-
_getDefault: (
|
|
29
|
+
export class DefaultWeakMap<K: Key, V> extends WeakMap<K, V> {
|
|
30
|
+
_getDefault: (K) => V;
|
|
28
31
|
|
|
29
|
-
constructor(getDefault: (
|
|
30
|
-
super(entries
|
|
32
|
+
constructor(getDefault: (K) => V, entries?: Iterable<[K, V]>) {
|
|
33
|
+
super(entries);
|
|
31
34
|
this._getDefault = getDefault;
|
|
32
35
|
}
|
|
33
36
|
|
|
@@ -40,6 +43,7 @@ export class DefaultWeakMap<K extends Key, V> extends WeakMap<K, V> {
|
|
|
40
43
|
this.set(key, ret);
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
// $FlowFixMe
|
|
47
|
+
return ret;
|
|
44
48
|
}
|
|
45
49
|
}
|
package/src/Deferred.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
import invariant from 'assert';
|
|
4
|
+
|
|
5
|
+
export type Deferred<T> = {|
|
|
6
|
+
resolve(T): void,
|
|
7
|
+
reject(mixed): void,
|
|
8
|
+
|};
|
|
9
|
+
|
|
10
|
+
export function makeDeferredWithPromise<T>(): {|
|
|
11
|
+
deferred: Deferred<T>,
|
|
12
|
+
promise: Promise<T>,
|
|
13
|
+
|} {
|
|
14
|
+
let deferred: ?Deferred<T>;
|
|
15
|
+
let promise = new Promise<T>((resolve, reject) => {
|
|
16
|
+
deferred = {resolve, reject};
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// Promise constructor callback executes synchronously, so this is defined
|
|
20
|
+
invariant(deferred != null);
|
|
21
|
+
|
|
22
|
+
return {deferred, promise};
|
|
23
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
1
3
|
import {makeDeferredWithPromise, type Deferred} from './Deferred';
|
|
2
4
|
|
|
3
|
-
type PromiseQueueOpts = {
|
|
4
|
-
maxConcurrent: number;
|
|
5
|
-
};
|
|
5
|
+
type PromiseQueueOpts = {|maxConcurrent: number|};
|
|
6
6
|
|
|
7
7
|
export default class PromiseQueue<T> {
|
|
8
|
-
_deferred: Deferred<Array<T
|
|
8
|
+
_deferred: ?Deferred<Array<T>>;
|
|
9
9
|
_maxConcurrent: number;
|
|
10
10
|
_numRunning: number = 0;
|
|
11
11
|
_queue: Array<() => Promise<void>> = [];
|
|
12
|
-
_runPromise: Promise<Array<T>>
|
|
13
|
-
_error:
|
|
12
|
+
_runPromise: ?Promise<Array<T>> = null;
|
|
13
|
+
_error: mixed;
|
|
14
14
|
_count: number = 0;
|
|
15
15
|
_results: Array<T> = [];
|
|
16
16
|
_addSubscriptions: Set<() => void> = new Set();
|
|
@@ -28,35 +28,30 @@ export default class PromiseQueue<T> {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
add(fn: () => Promise<T>): void {
|
|
31
|
-
new Promise(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (this._numRunning > 0 && this._numRunning < this._maxConcurrent) {
|
|
56
|
-
this._next();
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
).catch(() => {});
|
|
31
|
+
new Promise((resolve, reject) => {
|
|
32
|
+
let i = this._count++;
|
|
33
|
+
let wrapped = () =>
|
|
34
|
+
fn().then(
|
|
35
|
+
(result) => {
|
|
36
|
+
this._results[i] = result;
|
|
37
|
+
resolve(result);
|
|
38
|
+
},
|
|
39
|
+
(err) => {
|
|
40
|
+
reject(err);
|
|
41
|
+
throw err;
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
this._queue.push(wrapped);
|
|
46
|
+
|
|
47
|
+
for (const addFn of this._addSubscriptions) {
|
|
48
|
+
addFn();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (this._numRunning > 0 && this._numRunning < this._maxConcurrent) {
|
|
52
|
+
this._next();
|
|
53
|
+
}
|
|
54
|
+
}).catch(() => {});
|
|
60
55
|
}
|
|
61
56
|
|
|
62
57
|
subscribeToAdd(fn: () => void): () => void {
|
|
@@ -76,9 +71,9 @@ export default class PromiseQueue<T> {
|
|
|
76
71
|
return Promise.resolve([]);
|
|
77
72
|
}
|
|
78
73
|
|
|
79
|
-
let {deferred, promise} = makeDeferredWithPromise
|
|
74
|
+
let {deferred, promise} = makeDeferredWithPromise();
|
|
80
75
|
this._deferred = deferred;
|
|
81
|
-
this._runPromise = promise
|
|
76
|
+
this._runPromise = promise;
|
|
82
77
|
|
|
83
78
|
while (this._queue.length && this._numRunning < this._maxConcurrent) {
|
|
84
79
|
this._next();
|
|
@@ -89,7 +84,7 @@ export default class PromiseQueue<T> {
|
|
|
89
84
|
|
|
90
85
|
async _next(): Promise<void> {
|
|
91
86
|
let fn = this._queue.shift();
|
|
92
|
-
await this._runFn(fn
|
|
87
|
+
await this._runFn(fn);
|
|
93
88
|
if (this._queue.length) {
|
|
94
89
|
this._next();
|
|
95
90
|
} else if (this._numRunning === 0) {
|
|
@@ -97,11 +92,11 @@ export default class PromiseQueue<T> {
|
|
|
97
92
|
}
|
|
98
93
|
}
|
|
99
94
|
|
|
100
|
-
async _runFn(fn: () =>
|
|
95
|
+
async _runFn(fn: () => mixed): Promise<void> {
|
|
101
96
|
this._numRunning++;
|
|
102
97
|
try {
|
|
103
98
|
await fn();
|
|
104
|
-
} catch (e
|
|
99
|
+
} catch (e) {
|
|
105
100
|
// Only store the first error that occurs.
|
|
106
101
|
// We don't reject immediately so that any other concurrent
|
|
107
102
|
// requests have time to complete.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
1
3
|
import {Transform} from 'stream';
|
|
2
4
|
|
|
3
5
|
/*
|
|
@@ -5,24 +7,21 @@ import {Transform} from 'stream';
|
|
|
5
7
|
* callback. Continues to pass data chunks down the stream.
|
|
6
8
|
*/
|
|
7
9
|
export default class TapStream extends Transform {
|
|
8
|
-
_tap: (
|
|
9
|
-
constructor(tap: (
|
|
10
|
-
super({...
|
|
10
|
+
_tap: (Buffer) => mixed;
|
|
11
|
+
constructor(tap: (Buffer) => mixed, options: mixed) {
|
|
12
|
+
super({...options});
|
|
11
13
|
this._tap = tap;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
_transform(
|
|
15
17
|
chunk: Buffer | string,
|
|
16
18
|
encoding: string,
|
|
17
|
-
callback: (
|
|
18
|
-
err?: Error | null | undefined,
|
|
19
|
-
chunk?: Buffer | string,
|
|
20
|
-
) => unknown,
|
|
19
|
+
callback: (err: ?Error, chunk?: Buffer | string) => mixed,
|
|
21
20
|
) {
|
|
22
21
|
try {
|
|
23
22
|
this._tap(Buffer.from(chunk));
|
|
24
23
|
callback(null, chunk);
|
|
25
|
-
} catch (err
|
|
24
|
+
} catch (err) {
|
|
26
25
|
callback(err);
|
|
27
26
|
}
|
|
28
27
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @flow
|
|
1
2
|
import path from 'path';
|
|
2
3
|
import type {FileSystem} from '@atlaspack/types';
|
|
3
4
|
import {fuzzySearch} from './schema';
|
|
@@ -47,7 +48,7 @@ export async function findAlternativeNodeModules(
|
|
|
47
48
|
potentialModules.push(...modules);
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
|
-
} catch (err
|
|
51
|
+
} catch (err) {
|
|
51
52
|
// ignore
|
|
52
53
|
}
|
|
53
54
|
|
|
@@ -67,16 +68,16 @@ async function findAllFilesUp({
|
|
|
67
68
|
collected,
|
|
68
69
|
leadingDotSlash = true,
|
|
69
70
|
includeDirectories = true,
|
|
70
|
-
}: {
|
|
71
|
-
fs: FileSystem
|
|
72
|
-
dir: string
|
|
73
|
-
root: string
|
|
74
|
-
basedir: string
|
|
75
|
-
maxlength: number
|
|
76
|
-
collected: Array<string
|
|
77
|
-
leadingDotSlash?: boolean
|
|
78
|
-
includeDirectories?: boolean
|
|
79
|
-
}): Promise<
|
|
71
|
+
}: {|
|
|
72
|
+
fs: FileSystem,
|
|
73
|
+
dir: string,
|
|
74
|
+
root: string,
|
|
75
|
+
basedir: string,
|
|
76
|
+
maxlength: number,
|
|
77
|
+
collected: Array<string>,
|
|
78
|
+
leadingDotSlash?: boolean,
|
|
79
|
+
includeDirectories?: boolean,
|
|
80
|
+
|}): Promise<mixed> {
|
|
80
81
|
let dirContent = (await fs.readdir(dir)).sort();
|
|
81
82
|
return Promise.all(
|
|
82
83
|
dirContent.map(async (item) => {
|
|
@@ -110,9 +111,9 @@ export async function findAlternativeFiles(
|
|
|
110
111
|
fileSpecifier: string,
|
|
111
112
|
dir: string,
|
|
112
113
|
projectRoot: string,
|
|
113
|
-
leadingDotSlash
|
|
114
|
-
includeDirectories
|
|
115
|
-
includeExtension
|
|
114
|
+
leadingDotSlash?: boolean = true,
|
|
115
|
+
includeDirectories?: boolean = true,
|
|
116
|
+
includeExtension?: boolean = false,
|
|
116
117
|
): Promise<Array<string>> {
|
|
117
118
|
let potentialFiles: Array<string> = [];
|
|
118
119
|
// Find our root, we won't recommend files above the package root as that's bad practise
|
package/src/{blob.ts → blob.js}
RENAMED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
1
3
|
import type {Blob} from '@atlaspack/types';
|
|
2
4
|
|
|
3
5
|
import {Buffer} from 'buffer';
|
|
@@ -10,7 +12,7 @@ export function blobToBuffer(blob: Blob): Promise<Buffer> {
|
|
|
10
12
|
} else if (blob instanceof Buffer) {
|
|
11
13
|
return Promise.resolve(Buffer.from(blob));
|
|
12
14
|
} else {
|
|
13
|
-
return Promise.resolve(Buffer.from(blob
|
|
15
|
+
return Promise.resolve(Buffer.from(blob, 'utf8'));
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
|
|
@@ -20,6 +22,6 @@ export async function blobToString(blob: Blob): Promise<string> {
|
|
|
20
22
|
} else if (blob instanceof Buffer) {
|
|
21
23
|
return blob.toString();
|
|
22
24
|
} else {
|
|
23
|
-
return blob
|
|
25
|
+
return blob;
|
|
24
26
|
}
|
|
25
27
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
let bundleURL: ?string = null;
|
|
2
4
|
function getBundleURLCached(): string {
|
|
3
5
|
if (bundleURL == null) {
|
|
4
6
|
bundleURL = _getBundleURL();
|
|
@@ -11,7 +13,7 @@ function _getBundleURL(): string {
|
|
|
11
13
|
// Attempt to find the URL of the current script and use that as the base URL
|
|
12
14
|
try {
|
|
13
15
|
throw new Error();
|
|
14
|
-
} catch (err
|
|
16
|
+
} catch (err) {
|
|
15
17
|
let stack: string = typeof err.stack === 'string' ? err.stack : '';
|
|
16
18
|
let matches = stack.match(/(https?|file|ftp):\/\/[^)\n]+/g);
|
|
17
19
|
if (matches) {
|
|
@@ -22,7 +24,7 @@ function _getBundleURL(): string {
|
|
|
22
24
|
return '/';
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
export function getBaseURL(url
|
|
27
|
+
export function getBaseURL(url: ?string): string {
|
|
26
28
|
if (url == null) {
|
|
27
29
|
return '/';
|
|
28
30
|
}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
1
3
|
export function unique<T>(array: Array<T>): Array<T> {
|
|
2
4
|
return [...new Set(array)];
|
|
3
5
|
}
|
|
4
6
|
|
|
5
7
|
export function objectSortedEntries(obj: {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
+[string]: mixed,
|
|
9
|
+
...
|
|
10
|
+
}): Array<[string, mixed]> {
|
|
8
11
|
return Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
export function objectSortedEntriesDeep(object: {
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
+[string]: mixed,
|
|
16
|
+
...
|
|
17
|
+
}): Array<[string, mixed]> {
|
|
14
18
|
let sortedEntries = objectSortedEntries(object);
|
|
15
19
|
for (let i = 0; i < sortedEntries.length; i++) {
|
|
16
20
|
sortedEntries[i][1] = sortEntry(sortedEntries[i][1]);
|
|
@@ -18,13 +22,13 @@ export function objectSortedEntriesDeep(object: {
|
|
|
18
22
|
return sortedEntries;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
|
-
function sortEntry(entry:
|
|
25
|
+
function sortEntry(entry: mixed) {
|
|
22
26
|
if (Array.isArray(entry)) {
|
|
23
27
|
return entry.map(sortEntry);
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
if (typeof entry === 'object' && entry != null) {
|
|
27
|
-
return objectSortedEntriesDeep(entry
|
|
31
|
+
return objectSortedEntriesDeep(entry);
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
return entry;
|
|
@@ -40,8 +44,11 @@ function sortEntry(entry: unknown): unknown {
|
|
|
40
44
|
* @param {*} b Set B
|
|
41
45
|
* @returns A \ B
|
|
42
46
|
*/
|
|
43
|
-
export function setDifference<T>(
|
|
44
|
-
|
|
47
|
+
export function setDifference<T>(
|
|
48
|
+
a: $ReadOnlySet<T>,
|
|
49
|
+
b: $ReadOnlySet<T>,
|
|
50
|
+
): Set<T> {
|
|
51
|
+
let difference = new Set();
|
|
45
52
|
for (let e of a) {
|
|
46
53
|
if (!b.has(e)) {
|
|
47
54
|
difference.add(e);
|
|
@@ -62,10 +69,10 @@ export function setDifference<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): Set<T> {
|
|
|
62
69
|
* @returns A Δ B
|
|
63
70
|
*/
|
|
64
71
|
export function setSymmetricDifference<T>(
|
|
65
|
-
a:
|
|
66
|
-
b:
|
|
72
|
+
a: $ReadOnlySet<T>,
|
|
73
|
+
b: $ReadOnlySet<T>,
|
|
67
74
|
): Set<T> {
|
|
68
|
-
let difference = new Set
|
|
75
|
+
let difference = new Set();
|
|
69
76
|
for (let e of a) {
|
|
70
77
|
if (!b.has(e)) {
|
|
71
78
|
difference.add(e);
|
|
@@ -79,7 +86,7 @@ export function setSymmetricDifference<T>(
|
|
|
79
86
|
return difference;
|
|
80
87
|
}
|
|
81
88
|
|
|
82
|
-
export function setIntersect<T>(a: Set<T>, b:
|
|
89
|
+
export function setIntersect<T>(a: Set<T>, b: $ReadOnlySet<T>): void {
|
|
83
90
|
for (let entry of a) {
|
|
84
91
|
if (!b.has(entry)) {
|
|
85
92
|
a.delete(entry);
|
|
@@ -88,7 +95,7 @@ export function setIntersect<T>(a: Set<T>, b: ReadonlySet<T>): void {
|
|
|
88
95
|
}
|
|
89
96
|
|
|
90
97
|
export function setIntersectStatic<T>(a: Set<T>, b: Set<T>): Set<T> {
|
|
91
|
-
let intersection = new Set
|
|
98
|
+
let intersection = new Set();
|
|
92
99
|
for (let entry of a) {
|
|
93
100
|
if (b.has(entry)) {
|
|
94
101
|
intersection.add(entry);
|
|
@@ -101,7 +108,7 @@ export function setUnion<T>(a: Iterable<T>, b: Iterable<T>): Set<T> {
|
|
|
101
108
|
return new Set([...a, ...b]);
|
|
102
109
|
}
|
|
103
110
|
|
|
104
|
-
export function setEqual<T>(a:
|
|
111
|
+
export function setEqual<T>(a: $ReadOnlySet<T>, b: $ReadOnlySet<T>): boolean {
|
|
105
112
|
if (a.size != b.size) {
|
|
106
113
|
return false;
|
|
107
114
|
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
1
3
|
import type {ConfigResult, File, FilePath} from '@atlaspack/types';
|
|
2
4
|
import type {FileSystem} from '@atlaspack/fs';
|
|
3
5
|
import ThrowableDiagnostic from '@atlaspack/diagnostic';
|
|
4
6
|
import path from 'path';
|
|
5
|
-
// @ts-expect-error TS7016
|
|
6
7
|
import clone from 'clone';
|
|
7
8
|
import json5 from 'json5';
|
|
8
9
|
import {parse as toml} from '@iarna/toml';
|
|
9
10
|
import LRU from 'lru-cache';
|
|
10
11
|
|
|
11
|
-
export type ConfigOutput = {
|
|
12
|
-
config: ConfigResult
|
|
13
|
-
files: Array<File
|
|
14
|
-
};
|
|
12
|
+
export type ConfigOutput = {|
|
|
13
|
+
config: ConfigResult,
|
|
14
|
+
files: Array<File>,
|
|
15
|
+
|};
|
|
15
16
|
|
|
16
|
-
export type ConfigOptions = {
|
|
17
|
-
parse?: boolean
|
|
18
|
-
parser?: (
|
|
19
|
-
};
|
|
17
|
+
export type ConfigOptions = {|
|
|
18
|
+
parse?: boolean,
|
|
19
|
+
parser?: (string) => any,
|
|
20
|
+
|};
|
|
20
21
|
|
|
21
|
-
// @ts-expect-error TS2351
|
|
22
22
|
const configCache = new LRU<FilePath, ConfigOutput>({max: 500});
|
|
23
23
|
const resolveCache = new Map();
|
|
24
24
|
|
|
@@ -27,7 +27,7 @@ export function resolveConfig(
|
|
|
27
27
|
filepath: FilePath,
|
|
28
28
|
filenames: Array<FilePath>,
|
|
29
29
|
projectRoot: FilePath,
|
|
30
|
-
): Promise
|
|
30
|
+
): Promise<?FilePath> {
|
|
31
31
|
// Cache the result of resolving config for this directory.
|
|
32
32
|
// This is automatically invalidated at the end of the current build.
|
|
33
33
|
let key = path.dirname(filepath) + filenames.join(',');
|
|
@@ -50,7 +50,7 @@ export function resolveConfigSync(
|
|
|
50
50
|
filepath: FilePath,
|
|
51
51
|
filenames: Array<FilePath>,
|
|
52
52
|
projectRoot: FilePath,
|
|
53
|
-
): FilePath
|
|
53
|
+
): ?FilePath {
|
|
54
54
|
return fs.findAncestorFile(filenames, path.dirname(filepath), projectRoot);
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -59,7 +59,7 @@ export async function loadConfig(
|
|
|
59
59
|
filepath: FilePath,
|
|
60
60
|
filenames: Array<FilePath>,
|
|
61
61
|
projectRoot: FilePath,
|
|
62
|
-
opts
|
|
62
|
+
opts: ?ConfigOptions,
|
|
63
63
|
): Promise<ConfigOutput | null> {
|
|
64
64
|
let parse = opts?.parse ?? true;
|
|
65
65
|
let configFile = await resolveConfig(fs, filepath, filenames, projectRoot);
|
|
@@ -73,6 +73,7 @@ export async function loadConfig(
|
|
|
73
73
|
let extname = path.extname(configFile).slice(1);
|
|
74
74
|
if (extname === 'js' || extname === 'cjs') {
|
|
75
75
|
let output = {
|
|
76
|
+
// $FlowFixMe
|
|
76
77
|
config: clone(module.require(configFile)),
|
|
77
78
|
files: [{filePath: configFile}],
|
|
78
79
|
};
|
|
@@ -82,7 +83,7 @@ export async function loadConfig(
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
return readConfig(fs, configFile, opts);
|
|
85
|
-
} catch (err
|
|
86
|
+
} catch (err) {
|
|
86
87
|
if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
|
|
87
88
|
return null;
|
|
88
89
|
}
|
|
@@ -102,7 +103,7 @@ loadConfig.clear = () => {
|
|
|
102
103
|
export async function readConfig(
|
|
103
104
|
fs: FileSystem,
|
|
104
105
|
configFile: FilePath,
|
|
105
|
-
opts
|
|
106
|
+
opts: ?ConfigOptions,
|
|
106
107
|
): Promise<ConfigOutput | null> {
|
|
107
108
|
let parse = opts?.parse ?? true;
|
|
108
109
|
let cachedOutput = configCache.get(String(parse) + configFile);
|
|
@@ -120,7 +121,7 @@ export async function readConfig(
|
|
|
120
121
|
let parse = opts?.parser ?? getParser(extname);
|
|
121
122
|
try {
|
|
122
123
|
config = parse(configContent);
|
|
123
|
-
} catch (e
|
|
124
|
+
} catch (e) {
|
|
124
125
|
if (extname !== '' && extname !== 'json') {
|
|
125
126
|
throw e;
|
|
126
127
|
}
|
|
@@ -160,7 +161,7 @@ export async function readConfig(
|
|
|
160
161
|
|
|
161
162
|
configCache.set(String(parse) + configFile, output);
|
|
162
163
|
return output;
|
|
163
|
-
} catch (err
|
|
164
|
+
} catch (err) {
|
|
164
165
|
if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
|
|
165
166
|
return null;
|
|
166
167
|
}
|
|
@@ -169,7 +170,7 @@ export async function readConfig(
|
|
|
169
170
|
}
|
|
170
171
|
}
|
|
171
172
|
|
|
172
|
-
function getParser(extname
|
|
173
|
+
function getParser(extname) {
|
|
173
174
|
switch (extname) {
|
|
174
175
|
case 'toml':
|
|
175
176
|
return toml;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
3
|
+
export default function debounce<TArgs: Array<mixed>>(
|
|
4
|
+
fn: (...args: TArgs) => mixed,
|
|
3
5
|
delay: number,
|
|
4
6
|
): (...args: TArgs) => void {
|
|
5
|
-
let timeout
|
|
7
|
+
let timeout;
|
|
6
8
|
|
|
7
9
|
return function (...args: TArgs) {
|
|
8
10
|
if (timeout) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
1
3
|
/*
|
|
2
4
|
* These tools are intended for Atlaspack developers, to provide extra utilities
|
|
3
5
|
* to make debugging Atlaspack issues more straightforward.
|
|
@@ -9,10 +11,10 @@
|
|
|
9
11
|
* You can enable all tools by setting `ATLASPACK_DEBUG_TOOLS=all`.
|
|
10
12
|
*/
|
|
11
13
|
|
|
12
|
-
type DebugTools = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
14
|
+
type DebugTools = {|
|
|
15
|
+
'asset-file-names-in-output': boolean,
|
|
16
|
+
'simple-cli-reporter': boolean,
|
|
17
|
+
|};
|
|
16
18
|
|
|
17
19
|
export let debugTools: DebugTools = {
|
|
18
20
|
'asset-file-names-in-output': false,
|
|
@@ -26,11 +28,11 @@ for (let tool of envVarValue.split(',')) {
|
|
|
26
28
|
|
|
27
29
|
if (tool === 'all') {
|
|
28
30
|
for (let key in debugTools) {
|
|
29
|
-
debugTools[key
|
|
31
|
+
debugTools[key] = true;
|
|
30
32
|
}
|
|
31
33
|
break;
|
|
32
34
|
} else if (debugTools.hasOwnProperty(tool)) {
|
|
33
|
-
debugTools[tool
|
|
35
|
+
debugTools[tool] = true;
|
|
34
36
|
} else if (tool === '') {
|
|
35
37
|
continue;
|
|
36
38
|
} else {
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
1
3
|
export default function createDependencyLocation(
|
|
2
|
-
start: {
|
|
3
|
-
line: number
|
|
4
|
-
column: number
|
|
5
|
-
},
|
|
4
|
+
start: {|
|
|
5
|
+
line: number,
|
|
6
|
+
column: number,
|
|
7
|
+
|},
|
|
6
8
|
specifier: string,
|
|
7
9
|
lineOffset: number = 0,
|
|
8
10
|
columnOffset: number = 0,
|
|
9
11
|
// Imports are usually wrapped in quotes
|
|
10
12
|
importWrapperLength: number = 2,
|
|
11
|
-
): {
|
|
12
|
-
end: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
filePath: string;
|
|
17
|
-
start: {
|
|
18
|
-
column: number;
|
|
19
|
-
line: number;
|
|
20
|
-
};
|
|
21
|
-
} {
|
|
13
|
+
): {|
|
|
14
|
+
end: {|column: number, line: number|},
|
|
15
|
+
filePath: string,
|
|
16
|
+
start: {|column: number, line: number|},
|
|
17
|
+
|} {
|
|
22
18
|
return {
|
|
23
19
|
filePath: specifier,
|
|
24
20
|
start: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @flow
|
|
1
2
|
// Based on _.escape https://github.com/lodash/lodash/blob/master/escape.js
|
|
2
3
|
const reUnescapedHtml = /[&<>"']/g;
|
|
3
4
|
const reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
|
|
@@ -8,14 +9,11 @@ const htmlEscapes = {
|
|
|
8
9
|
'>': '>',
|
|
9
10
|
'"': '"',
|
|
10
11
|
"'": ''',
|
|
11
|
-
}
|
|
12
|
+
};
|
|
12
13
|
|
|
13
14
|
export function escapeHTML(s: string): string {
|
|
14
15
|
if (reHasUnescapedHtml.test(s)) {
|
|
15
|
-
return s.replace(
|
|
16
|
-
reUnescapedHtml,
|
|
17
|
-
(c) => htmlEscapes[c as keyof typeof htmlEscapes],
|
|
18
|
-
);
|
|
16
|
+
return s.replace(reUnescapedHtml, (c) => htmlEscapes[c]);
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
return s;
|