@atlaspack/utils 2.17.3 → 2.17.4-typescript-17c3d1dec.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/LICENSE +201 -0
- package/lib/DefaultMap.d.ts +13 -0
- package/lib/DefaultMap.js +0 -4
- package/lib/Deferred.d.ts +8 -0
- package/lib/PromiseQueue.d.ts +25 -0
- package/lib/TapStream.d.ts +6 -0
- package/lib/alternatives.d.ts +3 -0
- package/lib/ansi-html.d.ts +1 -0
- package/lib/ansi-html.js +2 -0
- package/lib/blob.d.ts +4 -0
- package/lib/bundle-url.d.ts +4 -0
- package/lib/collection.d.ts +33 -0
- package/lib/config.d.ts +17 -0
- package/lib/config.js +3 -1
- package/lib/countLines.d.ts +1 -0
- package/lib/debounce.d.ts +1 -0
- package/lib/debug-tools.d.ts +6 -0
- package/lib/debug-tools.js +1 -0
- package/lib/dependency-location.d.ts +14 -0
- package/lib/escape-html.d.ts +1 -0
- package/lib/generateBuildMetrics.d.ts +18 -0
- package/lib/generateCertificate.d.ts +5 -0
- package/lib/getCertificate.d.ts +6 -0
- package/lib/getExisting.d.ts +8 -0
- package/lib/getModuleParts.d.ts +4 -0
- package/lib/getRootDir.d.ts +2 -0
- package/lib/glob.d.ts +10 -0
- package/lib/glob.js +12 -4
- package/lib/hash.d.ts +7 -0
- package/lib/http-server.d.ts +19 -0
- package/lib/index.d.ts +48 -0
- package/lib/index.js +164 -9
- package/lib/is-url.d.ts +1 -0
- package/lib/is-url.js +2 -0
- package/lib/isDirectoryInside.d.ts +2 -0
- package/lib/objectHash.d.ts +3 -0
- package/lib/objectHash.js +0 -1
- package/lib/openInBrowser.d.ts +1 -0
- package/lib/parseCSSImport.d.ts +1 -0
- package/lib/path.d.ts +8 -0
- package/lib/prettifyTime.d.ts +1 -0
- package/lib/prettyDiagnostic.d.ts +17 -0
- package/lib/prettyDiagnostic.js +3 -5
- package/lib/progress-message.d.ts +3 -0
- package/lib/relativeBundlePath.d.ts +4 -0
- package/lib/relativeUrl.d.ts +1 -0
- package/lib/replaceBundleReferences.d.ts +39 -0
- package/lib/schema.d.ts +107 -0
- package/lib/schema.js +38 -19
- package/lib/shared-buffer.d.ts +2 -0
- package/lib/shared-buffer.js +5 -1
- package/lib/sourcemap.d.ts +16 -0
- package/lib/stream.d.ts +8 -0
- package/lib/throttle.d.ts +1 -0
- package/lib/urlJoin.d.ts +5 -0
- package/lib/urlJoin.js +1 -1
- package/package.json +22 -15
- package/src/{DefaultMap.js → DefaultMap.ts} +8 -12
- package/src/Deferred.ts +26 -0
- package/src/{PromiseQueue.js → PromiseQueue.ts} +40 -35
- package/src/{TapStream.js → TapStream.ts} +8 -7
- package/src/{alternatives.js → alternatives.ts} +14 -15
- package/src/{ansi-html.js → ansi-html.ts} +1 -1
- package/src/{blob.js → blob.ts} +2 -4
- package/src/{bundle-url.js → bundle-url.ts} +3 -5
- package/src/{collection.js → collection.ts} +14 -21
- package/src/{config.js → config.ts} +18 -19
- package/src/{countLines.js → countLines.ts} +0 -2
- package/src/{debounce.js → debounce.ts} +3 -5
- package/src/{debug-tools.js → debug-tools.ts} +6 -8
- package/src/{dependency-location.js → dependency-location.ts} +15 -11
- package/src/{escape-html.js → escape-html.ts} +5 -3
- package/src/{generateBuildMetrics.js → generateBuildMetrics.ts} +16 -18
- package/src/{generateCertificate.js → generateCertificate.ts} +7 -5
- package/src/{getCertificate.js → getCertificate.ts} +5 -3
- package/src/{getExisting.js → getExisting.ts} +4 -3
- package/src/{getModuleParts.js → getModuleParts.ts} +3 -2
- package/src/{getRootDir.js → getRootDir.ts} +0 -2
- package/src/{glob.js → glob.ts} +14 -10
- package/src/{hash.js → hash.ts} +22 -17
- package/src/{http-server.js → http-server.ts} +32 -38
- package/src/{index.js → index.ts} +7 -8
- package/src/{is-url.js → is-url.ts} +1 -2
- package/src/{isDirectoryInside.js → isDirectoryInside.ts} +0 -1
- package/src/{objectHash.js → objectHash.ts} +1 -4
- package/src/{openInBrowser.js → openInBrowser.ts} +2 -4
- package/src/{parseCSSImport.js → parseCSSImport.ts} +0 -2
- package/src/{path.js → path.ts} +1 -3
- package/src/{prettifyTime.js → prettifyTime.ts} +0 -2
- package/src/{prettyDiagnostic.js → prettyDiagnostic.ts} +22 -20
- package/src/{progress-message.js → progress-message.ts} +3 -2
- package/src/{relativeBundlePath.js → relativeBundlePath.ts} +3 -3
- package/src/{relativeUrl.js → relativeUrl.ts} +0 -1
- package/src/{replaceBundleReferences.js → replaceBundleReferences.ts} +54 -36
- package/src/{schema.js → schema.ts} +158 -141
- package/src/{shared-buffer.js → shared-buffer.ts} +5 -3
- package/src/{sourcemap.js → sourcemap.ts} +16 -6
- package/src/{stream.js → stream.ts} +29 -21
- package/src/throttle.ts +13 -0
- package/src/{urlJoin.js → urlJoin.ts} +1 -3
- package/test/{DefaultMap.test.js → DefaultMap.test.ts} +4 -6
- package/test/{PromiseQueue.test.js → PromiseQueue.test.ts} +5 -6
- package/test/{collection.test.js → collection.test.ts} +0 -2
- package/test/{config.test.js → config.test.ts} +0 -3
- package/test/{objectHash.test.js → objectHash.test.ts} +4 -5
- package/test/{prettifyTime.test.js → prettifyTime.test.ts} +0 -1
- package/test/{replaceBundleReferences.test.js → replaceBundleReferences.test.ts} +0 -32
- package/test/{sourcemap.test.js → sourcemap.test.ts} +0 -1
- package/test/{throttle.test.js → throttle.test.ts} +1 -3
- package/test/{urlJoin.test.js → urlJoin.test.ts} +0 -2
- package/tsconfig.json +4 -0
- package/src/Deferred.js +0 -23
- package/src/throttle.js +0 -15
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SourceLocation } from '@atlaspack/types';
|
|
2
|
+
import type { FileSystem } from '@atlaspack/fs';
|
|
3
|
+
import SourceMap from '@parcel/source-map';
|
|
4
|
+
export declare const SOURCEMAP_RE: RegExp;
|
|
5
|
+
export declare const SOURCEMAP_EXTENSIONS: Set<string>;
|
|
6
|
+
export declare function matchSourceMappingURL(contents: string): RegExpMatchArray | null;
|
|
7
|
+
export declare function loadSourceMapUrl(fs: FileSystem, filename: string, contents: string): Promise<{
|
|
8
|
+
filename: string;
|
|
9
|
+
map: any;
|
|
10
|
+
url: string;
|
|
11
|
+
} | null | undefined>;
|
|
12
|
+
export declare function loadSourceMap(filename: string, contents: string, options: {
|
|
13
|
+
fs: FileSystem;
|
|
14
|
+
projectRoot: string;
|
|
15
|
+
}): Promise<SourceMap | null | undefined>;
|
|
16
|
+
export declare function remapSourceLocation(loc: SourceLocation, originalMap: SourceMap): SourceLocation;
|
package/lib/stream.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
import type { Blob } from '@atlaspack/types';
|
|
3
|
+
export declare function measureStreamLength(stream: Readable): Promise<number>;
|
|
4
|
+
export declare function readableFromStringOrBuffer(str: string | Buffer): Readable;
|
|
5
|
+
export declare function bufferStream(stream: Readable): Promise<Buffer>;
|
|
6
|
+
export declare function blobToStream(blob: Blob): Readable;
|
|
7
|
+
export declare function streamFromPromise(promise: Promise<Blob>): Readable;
|
|
8
|
+
export declare function fallbackStream(stream: Readable, fallback: () => Readable): Readable;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function throttle<TArgs extends Array<unknown>>(fn: (...args: TArgs) => unknown, delay: number): (...args: TArgs) => void;
|
package/lib/urlJoin.d.ts
ADDED
package/lib/urlJoin.js
CHANGED
|
@@ -28,7 +28,7 @@ function urlJoin(publicURL, assetPath) {
|
|
|
28
28
|
// Leading / ensures that paths with colons are not parsed as a protocol.
|
|
29
29
|
let p = assetPath.startsWith('/') ? assetPath : '/' + assetPath;
|
|
30
30
|
const assetUrl = _url().default.parse(p);
|
|
31
|
-
url.pathname = _path().default.posix.join(url.pathname, assetUrl.pathname);
|
|
31
|
+
url.pathname = _path().default.posix.join(url.pathname ?? '', assetUrl.pathname ?? '');
|
|
32
32
|
url.search = assetUrl.search;
|
|
33
33
|
url.hash = assetUrl.hash;
|
|
34
34
|
return _url().default.format(url);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/utils",
|
|
3
|
-
"version": "2.17.
|
|
3
|
+
"version": "2.17.4-typescript-17c3d1dec.0",
|
|
4
4
|
"description": "Blazing fast, zero configuration web application bundler",
|
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
|
6
6
|
"publishConfig": {
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
12
12
|
},
|
|
13
|
-
"main": "lib/index.js",
|
|
14
|
-
"source": "src/index.
|
|
13
|
+
"main": "./lib/index.js",
|
|
14
|
+
"source": "./src/index.ts",
|
|
15
|
+
"types": "./lib/index.d.ts",
|
|
15
16
|
"engines": {
|
|
16
17
|
"node": ">= 16.0.0"
|
|
17
18
|
},
|
|
@@ -30,17 +31,18 @@
|
|
|
30
31
|
}
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@atlaspack/codeframe": "2.13.
|
|
34
|
-
"@atlaspack/diagnostic": "2.14.
|
|
35
|
-
"@atlaspack/feature-flags": "2.20.0",
|
|
36
|
-
"@atlaspack/logger": "2.14.
|
|
37
|
-
"@atlaspack/markdown-ansi": "2.14.
|
|
38
|
-
"@atlaspack/rust": "3.4.
|
|
39
|
-
"@parcel/source-map": "^2.1.1",
|
|
40
|
-
"chalk": "^4.1.0",
|
|
41
|
-
"nullthrows": "^1.1.1",
|
|
34
|
+
"@atlaspack/codeframe": "2.13.5-typescript-17c3d1dec.0",
|
|
35
|
+
"@atlaspack/diagnostic": "2.14.2-typescript-17c3d1dec.0",
|
|
36
|
+
"@atlaspack/feature-flags": "2.20.1-typescript-17c3d1dec.0",
|
|
37
|
+
"@atlaspack/logger": "2.14.14-typescript-17c3d1dec.0",
|
|
38
|
+
"@atlaspack/markdown-ansi": "2.14.2-typescript-17c3d1dec.0",
|
|
39
|
+
"@atlaspack/rust": "3.4.2-typescript-17c3d1dec.0",
|
|
42
40
|
"@iarna/toml": "^2.2.0",
|
|
41
|
+
"@parcel/source-map": "^2.1.1",
|
|
42
|
+
"@types/micromatch": "^4.0.9",
|
|
43
|
+
"@types/node-forge": "^1.3.13",
|
|
43
44
|
"ansi-html-community": "0.0.8",
|
|
45
|
+
"chalk": "^4.1.0",
|
|
44
46
|
"clone": "^2.1.1",
|
|
45
47
|
"fast-glob": "^3.2.12",
|
|
46
48
|
"fastest-levenshtein": "^1.0.16",
|
|
@@ -50,13 +52,14 @@
|
|
|
50
52
|
"lru-cache": "^6.0.0",
|
|
51
53
|
"micromatch": "^4.0.4",
|
|
52
54
|
"node-forge": "^1.2.1",
|
|
55
|
+
"nullthrows": "^1.1.1",
|
|
53
56
|
"open": "^7.0.3",
|
|
54
57
|
"snarkdown": "^2.0.0",
|
|
55
58
|
"strip-ansi": "^6.0.0",
|
|
56
59
|
"terminal-link": "^2.1.1"
|
|
57
60
|
},
|
|
58
61
|
"devDependencies": {
|
|
59
|
-
"@atlaspack/babel-register": "2.14.
|
|
62
|
+
"@atlaspack/babel-register": "2.14.2-typescript-17c3d1dec.0",
|
|
60
63
|
"benny": "^3.7.1",
|
|
61
64
|
"random-int": "^1.0.0"
|
|
62
65
|
},
|
|
@@ -66,5 +69,9 @@
|
|
|
66
69
|
"./src/openInBrowser.js": false,
|
|
67
70
|
"@atlaspack/markdown-ansi": false
|
|
68
71
|
},
|
|
69
|
-
"type": "commonjs"
|
|
70
|
-
|
|
72
|
+
"type": "commonjs",
|
|
73
|
+
"scripts": {
|
|
74
|
+
"check-ts": "tsc --emitDeclarationOnly --rootDir src"
|
|
75
|
+
},
|
|
76
|
+
"gitHead": "17c3d1decf641e688fcfe3ca985e80e9897b7573"
|
|
77
|
+
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
export class DefaultMap<K, V> extends Map<K, V> {
|
|
4
|
-
_getDefault: (K) => V;
|
|
2
|
+
_getDefault: (arg1: K) => V;
|
|
5
3
|
|
|
6
|
-
constructor(getDefault: (K) => V, entries?: Iterable<[K, V]>) {
|
|
4
|
+
constructor(getDefault: (arg1: K) => V, entries?: Iterable<[K, V]>) {
|
|
7
5
|
super(entries);
|
|
8
6
|
this._getDefault = getDefault;
|
|
9
7
|
}
|
|
@@ -17,8 +15,7 @@ export class DefaultMap<K, V> extends Map<K, V> {
|
|
|
17
15
|
this.set(key, ret);
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
return ret;
|
|
18
|
+
return ret as V;
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
21
|
|
|
@@ -26,11 +23,11 @@ interface Key {}
|
|
|
26
23
|
|
|
27
24
|
// Duplicated from DefaultMap implementation for Flow
|
|
28
25
|
// Roughly mirrors https://github.com/facebook/flow/blob/2eb5a78d92c167117ba9caae070afd2b9f598599/lib/core.js#L617
|
|
29
|
-
export class DefaultWeakMap<K
|
|
30
|
-
_getDefault: (K) => V;
|
|
26
|
+
export class DefaultWeakMap<K extends Key, V> extends WeakMap<K, V> {
|
|
27
|
+
_getDefault: (arg1: K) => V;
|
|
31
28
|
|
|
32
|
-
constructor(getDefault: (K) => V, entries?: Iterable<[K, V]>) {
|
|
33
|
-
super(entries);
|
|
29
|
+
constructor(getDefault: (arg1: K) => V, entries?: Iterable<[K, V]>) {
|
|
30
|
+
super(entries as Iterable<readonly [K, V]>);
|
|
34
31
|
this._getDefault = getDefault;
|
|
35
32
|
}
|
|
36
33
|
|
|
@@ -43,7 +40,6 @@ export class DefaultWeakMap<K: Key, V> extends WeakMap<K, V> {
|
|
|
43
40
|
this.set(key, ret);
|
|
44
41
|
}
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
return ret;
|
|
43
|
+
return ret as V;
|
|
48
44
|
}
|
|
49
45
|
}
|
package/src/Deferred.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import invariant from 'assert';
|
|
2
|
+
|
|
3
|
+
export type Deferred<T> = {
|
|
4
|
+
resolve(arg1: T): void;
|
|
5
|
+
reject(arg1: unknown): void;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function makeDeferredWithPromise<T>(): {
|
|
9
|
+
deferred: Deferred<T>;
|
|
10
|
+
promise: Promise<T>;
|
|
11
|
+
} {
|
|
12
|
+
let deferred: Deferred<T> | null | undefined;
|
|
13
|
+
let promise = new Promise<T>(
|
|
14
|
+
(
|
|
15
|
+
resolve: (result: Promise<T> | T) => void,
|
|
16
|
+
reject: (error?: any) => void,
|
|
17
|
+
) => {
|
|
18
|
+
deferred = {resolve, reject};
|
|
19
|
+
},
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
// Promise constructor callback executes synchronously, so this is defined
|
|
23
|
+
invariant(deferred != null);
|
|
24
|
+
|
|
25
|
+
return {deferred, promise};
|
|
26
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import {makeDeferredWithPromise, type Deferred} from './Deferred';
|
|
4
2
|
|
|
5
|
-
type PromiseQueueOpts = {
|
|
3
|
+
type PromiseQueueOpts = {
|
|
4
|
+
maxConcurrent: number;
|
|
5
|
+
};
|
|
6
6
|
|
|
7
7
|
export default class PromiseQueue<T> {
|
|
8
|
-
_deferred:
|
|
8
|
+
_deferred: Deferred<Array<T>> | null | undefined;
|
|
9
9
|
_maxConcurrent: number;
|
|
10
10
|
_numRunning: number = 0;
|
|
11
11
|
_queue: Array<() => Promise<void>> = [];
|
|
12
|
-
_runPromise:
|
|
13
|
-
_error:
|
|
12
|
+
_runPromise: Promise<Array<T>> | null | undefined = null;
|
|
13
|
+
_error: unknown;
|
|
14
14
|
_count: number = 0;
|
|
15
15
|
_results: Array<T> = [];
|
|
16
16
|
_addSubscriptions: Set<() => void> = new Set();
|
|
@@ -28,30 +28,35 @@ 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
|
-
|
|
31
|
+
new Promise(
|
|
32
|
+
(
|
|
33
|
+
resolve: (result: Promise<T> | T) => void,
|
|
34
|
+
reject: (error?: any) => void,
|
|
35
|
+
) => {
|
|
36
|
+
let i = this._count++;
|
|
37
|
+
let wrapped = () =>
|
|
38
|
+
fn().then(
|
|
39
|
+
(result) => {
|
|
40
|
+
this._results[i] = result;
|
|
41
|
+
resolve(result);
|
|
42
|
+
},
|
|
43
|
+
(err) => {
|
|
44
|
+
reject(err);
|
|
45
|
+
throw err;
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
this._queue.push(wrapped);
|
|
50
|
+
|
|
51
|
+
for (const addFn of this._addSubscriptions) {
|
|
52
|
+
addFn();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (this._numRunning > 0 && this._numRunning < this._maxConcurrent) {
|
|
56
|
+
this._next();
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
).catch(() => {});
|
|
55
60
|
}
|
|
56
61
|
|
|
57
62
|
subscribeToAdd(fn: () => void): () => void {
|
|
@@ -71,9 +76,9 @@ export default class PromiseQueue<T> {
|
|
|
71
76
|
return Promise.resolve([]);
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
let {deferred, promise} = makeDeferredWithPromise();
|
|
79
|
+
let {deferred, promise} = makeDeferredWithPromise<Array<T>>();
|
|
75
80
|
this._deferred = deferred;
|
|
76
|
-
this._runPromise = promise
|
|
81
|
+
this._runPromise = promise as Promise<Array<T>>;
|
|
77
82
|
|
|
78
83
|
while (this._queue.length && this._numRunning < this._maxConcurrent) {
|
|
79
84
|
this._next();
|
|
@@ -84,7 +89,7 @@ export default class PromiseQueue<T> {
|
|
|
84
89
|
|
|
85
90
|
async _next(): Promise<void> {
|
|
86
91
|
let fn = this._queue.shift();
|
|
87
|
-
await this._runFn(fn);
|
|
92
|
+
await this._runFn(fn as () => unknown);
|
|
88
93
|
if (this._queue.length) {
|
|
89
94
|
this._next();
|
|
90
95
|
} else if (this._numRunning === 0) {
|
|
@@ -92,11 +97,11 @@ export default class PromiseQueue<T> {
|
|
|
92
97
|
}
|
|
93
98
|
}
|
|
94
99
|
|
|
95
|
-
async _runFn(fn: () =>
|
|
100
|
+
async _runFn(fn: () => unknown): Promise<void> {
|
|
96
101
|
this._numRunning++;
|
|
97
102
|
try {
|
|
98
103
|
await fn();
|
|
99
|
-
} catch (e) {
|
|
104
|
+
} catch (e: any) {
|
|
100
105
|
// Only store the first error that occurs.
|
|
101
106
|
// We don't reject immediately so that any other concurrent
|
|
102
107
|
// requests have time to complete.
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import {Transform} from 'stream';
|
|
4
2
|
|
|
5
3
|
/*
|
|
@@ -7,21 +5,24 @@ import {Transform} from 'stream';
|
|
|
7
5
|
* callback. Continues to pass data chunks down the stream.
|
|
8
6
|
*/
|
|
9
7
|
export default class TapStream extends Transform {
|
|
10
|
-
_tap: (Buffer) =>
|
|
11
|
-
constructor(tap: (Buffer) =>
|
|
12
|
-
super({...options});
|
|
8
|
+
_tap: (arg1: Buffer) => unknown;
|
|
9
|
+
constructor(tap: (arg1: Buffer) => unknown, options: unknown) {
|
|
10
|
+
super({...(options as any)});
|
|
13
11
|
this._tap = tap;
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
_transform(
|
|
17
15
|
chunk: Buffer | string,
|
|
18
16
|
encoding: string,
|
|
19
|
-
callback: (
|
|
17
|
+
callback: (
|
|
18
|
+
err?: Error | null | undefined,
|
|
19
|
+
chunk?: Buffer | string,
|
|
20
|
+
) => unknown,
|
|
20
21
|
) {
|
|
21
22
|
try {
|
|
22
23
|
this._tap(Buffer.from(chunk));
|
|
23
24
|
callback(null, chunk);
|
|
24
|
-
} catch (err) {
|
|
25
|
+
} catch (err: any) {
|
|
25
26
|
callback(err);
|
|
26
27
|
}
|
|
27
28
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import path from 'path';
|
|
3
2
|
import type {FileSystem} from '@atlaspack/types';
|
|
4
3
|
import {fuzzySearch} from './schema';
|
|
@@ -48,7 +47,7 @@ export async function findAlternativeNodeModules(
|
|
|
48
47
|
potentialModules.push(...modules);
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
|
-
} catch (err) {
|
|
50
|
+
} catch (err: any) {
|
|
52
51
|
// ignore
|
|
53
52
|
}
|
|
54
53
|
|
|
@@ -68,16 +67,16 @@ async function findAllFilesUp({
|
|
|
68
67
|
collected,
|
|
69
68
|
leadingDotSlash = true,
|
|
70
69
|
includeDirectories = true,
|
|
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
|
-
|
|
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<unknown> {
|
|
81
80
|
let dirContent = (await fs.readdir(dir)).sort();
|
|
82
81
|
return Promise.all(
|
|
83
82
|
dirContent.map(async (item) => {
|
|
@@ -111,9 +110,9 @@ export async function findAlternativeFiles(
|
|
|
111
110
|
fileSpecifier: string,
|
|
112
111
|
dir: string,
|
|
113
112
|
projectRoot: string,
|
|
114
|
-
leadingDotSlash
|
|
115
|
-
includeDirectories
|
|
116
|
-
includeExtension
|
|
113
|
+
leadingDotSlash: boolean = true,
|
|
114
|
+
includeDirectories: boolean = true,
|
|
115
|
+
includeExtension: boolean = false,
|
|
117
116
|
): Promise<Array<string>> {
|
|
118
117
|
let potentialFiles: Array<string> = [];
|
|
119
118
|
// Find our root, we won't recommend files above the package root as that's bad practise
|
package/src/{blob.js → blob.ts}
RENAMED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import type {Blob} from '@atlaspack/types';
|
|
4
2
|
|
|
5
3
|
import {Buffer} from 'buffer';
|
|
@@ -12,7 +10,7 @@ export function blobToBuffer(blob: Blob): Promise<Buffer> {
|
|
|
12
10
|
} else if (blob instanceof Buffer) {
|
|
13
11
|
return Promise.resolve(Buffer.from(blob));
|
|
14
12
|
} else {
|
|
15
|
-
return Promise.resolve(Buffer.from(blob, 'utf8'));
|
|
13
|
+
return Promise.resolve(Buffer.from(blob as string, 'utf8'));
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
16
|
|
|
@@ -22,6 +20,6 @@ export async function blobToString(blob: Blob): Promise<string> {
|
|
|
22
20
|
} else if (blob instanceof Buffer) {
|
|
23
21
|
return blob.toString();
|
|
24
22
|
} else {
|
|
25
|
-
return blob;
|
|
23
|
+
return blob as string;
|
|
26
24
|
}
|
|
27
25
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
let bundleURL: ?string = null;
|
|
1
|
+
let bundleURL: string | null | undefined = null;
|
|
4
2
|
function getBundleURLCached(): string {
|
|
5
3
|
if (bundleURL == null) {
|
|
6
4
|
bundleURL = _getBundleURL();
|
|
@@ -13,7 +11,7 @@ function _getBundleURL(): string {
|
|
|
13
11
|
// Attempt to find the URL of the current script and use that as the base URL
|
|
14
12
|
try {
|
|
15
13
|
throw new Error();
|
|
16
|
-
} catch (err) {
|
|
14
|
+
} catch (err: any) {
|
|
17
15
|
let stack: string = typeof err.stack === 'string' ? err.stack : '';
|
|
18
16
|
let matches = stack.match(/(https?|file|ftp):\/\/[^)\n]+/g);
|
|
19
17
|
if (matches) {
|
|
@@ -24,7 +22,7 @@ function _getBundleURL(): string {
|
|
|
24
22
|
return '/';
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
export function getBaseURL(url
|
|
25
|
+
export function getBaseURL(url?: string | null): string {
|
|
28
26
|
if (url == null) {
|
|
29
27
|
return '/';
|
|
30
28
|
}
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
export function unique<T>(array: Array<T>): Array<T> {
|
|
4
2
|
return [...new Set(array)];
|
|
5
3
|
}
|
|
6
4
|
|
|
7
5
|
export function objectSortedEntries(obj: {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}): Array<[string, mixed]> {
|
|
6
|
+
readonly [key: string]: unknown;
|
|
7
|
+
}): Array<[string, unknown]> {
|
|
11
8
|
return Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
|
|
12
9
|
}
|
|
13
10
|
|
|
14
11
|
export function objectSortedEntriesDeep(object: {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}): Array<[string, mixed]> {
|
|
12
|
+
readonly [key: string]: unknown;
|
|
13
|
+
}): Array<[string, unknown]> {
|
|
18
14
|
let sortedEntries = objectSortedEntries(object);
|
|
19
15
|
for (let i = 0; i < sortedEntries.length; i++) {
|
|
20
16
|
sortedEntries[i][1] = sortEntry(sortedEntries[i][1]);
|
|
@@ -22,13 +18,13 @@ export function objectSortedEntriesDeep(object: {
|
|
|
22
18
|
return sortedEntries;
|
|
23
19
|
}
|
|
24
20
|
|
|
25
|
-
function sortEntry(entry:
|
|
21
|
+
function sortEntry(entry: unknown): unknown {
|
|
26
22
|
if (Array.isArray(entry)) {
|
|
27
23
|
return entry.map(sortEntry);
|
|
28
24
|
}
|
|
29
25
|
|
|
30
26
|
if (typeof entry === 'object' && entry != null) {
|
|
31
|
-
return objectSortedEntriesDeep(entry);
|
|
27
|
+
return objectSortedEntriesDeep(entry as {readonly [key: string]: unknown});
|
|
32
28
|
}
|
|
33
29
|
|
|
34
30
|
return entry;
|
|
@@ -44,11 +40,8 @@ function sortEntry(entry: mixed) {
|
|
|
44
40
|
* @param {*} b Set B
|
|
45
41
|
* @returns A \ B
|
|
46
42
|
*/
|
|
47
|
-
export function setDifference<T>(
|
|
48
|
-
|
|
49
|
-
b: $ReadOnlySet<T>,
|
|
50
|
-
): Set<T> {
|
|
51
|
-
let difference = new Set();
|
|
43
|
+
export function setDifference<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): Set<T> {
|
|
44
|
+
let difference = new Set<T>();
|
|
52
45
|
for (let e of a) {
|
|
53
46
|
if (!b.has(e)) {
|
|
54
47
|
difference.add(e);
|
|
@@ -69,10 +62,10 @@ export function setDifference<T>(
|
|
|
69
62
|
* @returns A Δ B
|
|
70
63
|
*/
|
|
71
64
|
export function setSymmetricDifference<T>(
|
|
72
|
-
a:
|
|
73
|
-
b:
|
|
65
|
+
a: ReadonlySet<T>,
|
|
66
|
+
b: ReadonlySet<T>,
|
|
74
67
|
): Set<T> {
|
|
75
|
-
let difference = new Set();
|
|
68
|
+
let difference = new Set<T>();
|
|
76
69
|
for (let e of a) {
|
|
77
70
|
if (!b.has(e)) {
|
|
78
71
|
difference.add(e);
|
|
@@ -86,7 +79,7 @@ export function setSymmetricDifference<T>(
|
|
|
86
79
|
return difference;
|
|
87
80
|
}
|
|
88
81
|
|
|
89
|
-
export function setIntersect<T>(a: Set<T>, b:
|
|
82
|
+
export function setIntersect<T>(a: Set<T>, b: ReadonlySet<T>): void {
|
|
90
83
|
for (let entry of a) {
|
|
91
84
|
if (!b.has(entry)) {
|
|
92
85
|
a.delete(entry);
|
|
@@ -95,7 +88,7 @@ export function setIntersect<T>(a: Set<T>, b: $ReadOnlySet<T>): void {
|
|
|
95
88
|
}
|
|
96
89
|
|
|
97
90
|
export function setIntersectStatic<T>(a: Set<T>, b: Set<T>): Set<T> {
|
|
98
|
-
let intersection = new Set();
|
|
91
|
+
let intersection = new Set<T>();
|
|
99
92
|
for (let entry of a) {
|
|
100
93
|
if (b.has(entry)) {
|
|
101
94
|
intersection.add(entry);
|
|
@@ -108,7 +101,7 @@ export function setUnion<T>(a: Iterable<T>, b: Iterable<T>): Set<T> {
|
|
|
108
101
|
return new Set([...a, ...b]);
|
|
109
102
|
}
|
|
110
103
|
|
|
111
|
-
export function setEqual<T>(a:
|
|
104
|
+
export function setEqual<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): boolean {
|
|
112
105
|
if (a.size != b.size) {
|
|
113
106
|
return false;
|
|
114
107
|
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import type {ConfigResult, File, FilePath} from '@atlaspack/types';
|
|
4
2
|
import type {FileSystem} from '@atlaspack/fs';
|
|
5
3
|
import ThrowableDiagnostic from '@atlaspack/diagnostic';
|
|
6
4
|
import path from 'path';
|
|
5
|
+
// @ts-expect-error TS7016
|
|
7
6
|
import clone from 'clone';
|
|
8
7
|
import json5 from 'json5';
|
|
9
8
|
import {parse as toml} from '@iarna/toml';
|
|
10
9
|
import LRU from 'lru-cache';
|
|
11
10
|
|
|
12
|
-
export type ConfigOutput = {
|
|
13
|
-
config: ConfigResult
|
|
14
|
-
files: Array<File
|
|
15
|
-
|
|
11
|
+
export type ConfigOutput = {
|
|
12
|
+
config: ConfigResult;
|
|
13
|
+
files: Array<File>;
|
|
14
|
+
};
|
|
16
15
|
|
|
17
|
-
export type ConfigOptions = {
|
|
18
|
-
parse?: boolean
|
|
19
|
-
parser?: (string) => any
|
|
20
|
-
|
|
16
|
+
export type ConfigOptions = {
|
|
17
|
+
parse?: boolean;
|
|
18
|
+
parser?: (arg1: string) => any;
|
|
19
|
+
};
|
|
21
20
|
|
|
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 | null | undefined> {
|
|
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
|
-
):
|
|
53
|
+
): FilePath | null | undefined {
|
|
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 | null,
|
|
63
63
|
): Promise<ConfigOutput | null> {
|
|
64
64
|
let parse = opts?.parse ?? true;
|
|
65
65
|
let configFile = await resolveConfig(fs, filepath, filenames, projectRoot);
|
|
@@ -73,7 +73,6 @@ 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
|
|
77
76
|
config: clone(module.require(configFile)),
|
|
78
77
|
files: [{filePath: configFile}],
|
|
79
78
|
};
|
|
@@ -83,7 +82,7 @@ export async function loadConfig(
|
|
|
83
82
|
}
|
|
84
83
|
|
|
85
84
|
return readConfig(fs, configFile, opts);
|
|
86
|
-
} catch (err) {
|
|
85
|
+
} catch (err: any) {
|
|
87
86
|
if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
|
|
88
87
|
return null;
|
|
89
88
|
}
|
|
@@ -103,7 +102,7 @@ loadConfig.clear = () => {
|
|
|
103
102
|
export async function readConfig(
|
|
104
103
|
fs: FileSystem,
|
|
105
104
|
configFile: FilePath,
|
|
106
|
-
opts
|
|
105
|
+
opts?: ConfigOptions | null,
|
|
107
106
|
): Promise<ConfigOutput | null> {
|
|
108
107
|
let parse = opts?.parse ?? true;
|
|
109
108
|
let cachedOutput = configCache.get(String(parse) + configFile);
|
|
@@ -121,7 +120,7 @@ export async function readConfig(
|
|
|
121
120
|
let parse = opts?.parser ?? getParser(extname);
|
|
122
121
|
try {
|
|
123
122
|
config = parse(configContent);
|
|
124
|
-
} catch (e) {
|
|
123
|
+
} catch (e: any) {
|
|
125
124
|
if (extname !== '' && extname !== 'json') {
|
|
126
125
|
throw e;
|
|
127
126
|
}
|
|
@@ -161,7 +160,7 @@ export async function readConfig(
|
|
|
161
160
|
|
|
162
161
|
configCache.set(String(parse) + configFile, output);
|
|
163
162
|
return output;
|
|
164
|
-
} catch (err) {
|
|
163
|
+
} catch (err: any) {
|
|
165
164
|
if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
|
|
166
165
|
return null;
|
|
167
166
|
}
|
|
@@ -170,7 +169,7 @@ export async function readConfig(
|
|
|
170
169
|
}
|
|
171
170
|
}
|
|
172
171
|
|
|
173
|
-
function getParser(extname) {
|
|
172
|
+
function getParser(extname: string) {
|
|
174
173
|
switch (extname) {
|
|
175
174
|
case 'toml':
|
|
176
175
|
return toml;
|