@atlaspack/utils 2.17.3-typescript-bc4459c37.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,3 +1,5 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
1
3
|
import type {FilePath, PackagedBundle} from '@atlaspack/types';
|
|
2
4
|
import type {FileSystem} from '@atlaspack/fs';
|
|
3
5
|
import SourceMap from '@parcel/source-map';
|
|
@@ -5,29 +7,29 @@ import nullthrows from 'nullthrows';
|
|
|
5
7
|
import path from 'path';
|
|
6
8
|
import {loadSourceMapUrl} from './';
|
|
7
9
|
|
|
8
|
-
export type AssetStats = {
|
|
9
|
-
filePath: string
|
|
10
|
-
size: number
|
|
11
|
-
originalSize: number
|
|
12
|
-
time: number
|
|
13
|
-
};
|
|
10
|
+
export type AssetStats = {|
|
|
11
|
+
filePath: string,
|
|
12
|
+
size: number,
|
|
13
|
+
originalSize: number,
|
|
14
|
+
time: number,
|
|
15
|
+
|};
|
|
14
16
|
|
|
15
|
-
export type BundleStats = {
|
|
16
|
-
filePath: string
|
|
17
|
-
size: number
|
|
18
|
-
time: number
|
|
19
|
-
assets: Array<AssetStats
|
|
20
|
-
};
|
|
17
|
+
export type BundleStats = {|
|
|
18
|
+
filePath: string,
|
|
19
|
+
size: number,
|
|
20
|
+
time: number,
|
|
21
|
+
assets: Array<AssetStats>,
|
|
22
|
+
|};
|
|
21
23
|
|
|
22
|
-
export type BuildMetrics = {
|
|
23
|
-
bundles: Array<BundleStats
|
|
24
|
-
};
|
|
24
|
+
export type BuildMetrics = {|
|
|
25
|
+
bundles: Array<BundleStats>,
|
|
26
|
+
|};
|
|
25
27
|
|
|
26
28
|
async function getSourcemapSizes(
|
|
27
29
|
filePath: FilePath,
|
|
28
30
|
fs: FileSystem,
|
|
29
31
|
projectRoot: FilePath,
|
|
30
|
-
): Promise
|
|
32
|
+
): Promise<?Map<string, number>> {
|
|
31
33
|
let bundleContents = await fs.readFile(filePath, 'utf-8');
|
|
32
34
|
let mapUrlData = await loadSourceMapUrl(fs, filePath, bundleContents);
|
|
33
35
|
if (!mapUrlData) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @flow
|
|
1
2
|
import type {FileSystem} from '@atlaspack/fs';
|
|
2
3
|
import forge from 'node-forge';
|
|
3
4
|
import path from 'path';
|
|
@@ -6,11 +7,8 @@ import logger from '@atlaspack/logger';
|
|
|
6
7
|
export default async function generateCertificate(
|
|
7
8
|
fs: FileSystem,
|
|
8
9
|
cacheDir: string,
|
|
9
|
-
host
|
|
10
|
-
): Promise<{
|
|
11
|
-
cert: Buffer;
|
|
12
|
-
key: Buffer;
|
|
13
|
-
}> {
|
|
10
|
+
host: ?string,
|
|
11
|
+
): Promise<{|cert: Buffer, key: Buffer|}> {
|
|
14
12
|
let certDirectory = cacheDir;
|
|
15
13
|
|
|
16
14
|
const privateKeyPath = path.join(certDirectory, 'private.pem');
|
|
@@ -136,7 +134,7 @@ export default async function generateCertificate(
|
|
|
136
134
|
await fs.writeFile(certPath, certPem);
|
|
137
135
|
|
|
138
136
|
return {
|
|
139
|
-
key: privPem
|
|
140
|
-
cert: certPem
|
|
137
|
+
key: privPem,
|
|
138
|
+
cert: certPem,
|
|
141
139
|
};
|
|
142
140
|
}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
+
// @flow
|
|
1
2
|
import type {HTTPSOptions} from '@atlaspack/types';
|
|
2
3
|
import type {FileSystem} from '@atlaspack/fs';
|
|
3
4
|
|
|
4
5
|
export default async function getCertificate(
|
|
5
6
|
fs: FileSystem,
|
|
6
7
|
options: HTTPSOptions,
|
|
7
|
-
): Promise<{
|
|
8
|
-
cert: Buffer;
|
|
9
|
-
key: Buffer;
|
|
10
|
-
}> {
|
|
8
|
+
): Promise<{|cert: Buffer, key: Buffer|}> {
|
|
11
9
|
try {
|
|
12
10
|
let cert = await fs.readFile(options.cert);
|
|
13
11
|
let key = await fs.readFile(options.key);
|
|
14
12
|
|
|
15
13
|
return {key, cert};
|
|
16
|
-
} catch (err
|
|
14
|
+
} catch (err) {
|
|
17
15
|
throw new Error('Certificate and/or key not found');
|
|
18
16
|
}
|
|
19
17
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
1
3
|
import fs from 'fs';
|
|
2
4
|
|
|
3
5
|
/**
|
|
@@ -7,10 +9,7 @@ import fs from 'fs';
|
|
|
7
9
|
export default function getExisting(
|
|
8
10
|
minifiedPath: string,
|
|
9
11
|
sourcePath: string,
|
|
10
|
-
): {
|
|
11
|
-
minified: string;
|
|
12
|
-
source: string;
|
|
13
|
-
} {
|
|
12
|
+
): {|minified: string, source: string|} {
|
|
14
13
|
let source = fs.readFileSync(sourcePath, 'utf8').trim();
|
|
15
14
|
return {
|
|
16
15
|
source,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @flow strict-local
|
|
1
2
|
import path from 'path';
|
|
2
3
|
|
|
3
4
|
import {normalizeSeparators} from './path';
|
|
@@ -5,9 +6,7 @@ import {normalizeSeparators} from './path';
|
|
|
5
6
|
/**
|
|
6
7
|
* Returns the package name and the optional subpath
|
|
7
8
|
*/
|
|
8
|
-
export default function getModuleParts(
|
|
9
|
-
_name: string,
|
|
10
|
-
): [string, string | null | undefined] {
|
|
9
|
+
export default function getModuleParts(_name: string): [string, ?string] {
|
|
11
10
|
let name = path.normalize(_name);
|
|
12
11
|
let splitOn = name.indexOf(path.sep);
|
|
13
12
|
if (name.charAt(0) === '@') {
|
package/src/{glob.ts → glob.js}
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
1
3
|
import type {FilePath, Glob} from '@atlaspack/types';
|
|
2
4
|
import type {FileSystem} from '@atlaspack/fs';
|
|
3
5
|
|
|
4
|
-
// @ts-expect-error TS7016
|
|
5
6
|
import _isGlob from 'is-glob';
|
|
6
|
-
|
|
7
|
-
import fastGlob, {FastGlobOptions} from 'fast-glob';
|
|
7
|
+
import fastGlob, {type FastGlobOptions} from 'fast-glob';
|
|
8
8
|
import micromatch, {isMatch, makeRe, type Options} from 'micromatch';
|
|
9
9
|
import {normalizeSeparators} from './path';
|
|
10
10
|
|
|
@@ -44,27 +44,25 @@ export function globSync(
|
|
|
44
44
|
fs: FileSystem,
|
|
45
45
|
options?: FastGlobOptions<FilePath>,
|
|
46
46
|
): Array<FilePath> {
|
|
47
|
+
// $FlowFixMe
|
|
47
48
|
options = {
|
|
48
49
|
...options,
|
|
49
50
|
fs: {
|
|
50
|
-
// @ts-expect-error TS7006
|
|
51
51
|
statSync: (p) => {
|
|
52
52
|
return fs.statSync(p);
|
|
53
53
|
},
|
|
54
|
-
// @ts-expect-error TS7006
|
|
55
54
|
lstatSync: (p) => {
|
|
56
55
|
// Our FileSystem interface doesn't have lstat support at the moment,
|
|
57
56
|
// but this is fine for our purposes since we follow symlinks by default.
|
|
58
57
|
return fs.statSync(p);
|
|
59
58
|
},
|
|
60
|
-
// @ts-expect-error TS7006
|
|
61
59
|
readdirSync: (p, opts) => {
|
|
62
60
|
return fs.readdirSync(p, opts);
|
|
63
61
|
},
|
|
64
62
|
},
|
|
65
63
|
};
|
|
66
64
|
|
|
67
|
-
//
|
|
65
|
+
// $FlowFixMe
|
|
68
66
|
return fastGlob.sync(normalizeSeparators(p), options);
|
|
69
67
|
}
|
|
70
68
|
|
|
@@ -73,28 +71,26 @@ export function glob(
|
|
|
73
71
|
fs: FileSystem,
|
|
74
72
|
options: FastGlobOptions<FilePath>,
|
|
75
73
|
): Promise<Array<FilePath>> {
|
|
74
|
+
// $FlowFixMe
|
|
76
75
|
options = {
|
|
77
76
|
...options,
|
|
78
77
|
fs: {
|
|
79
|
-
// @ts-expect-error TS7006
|
|
80
78
|
stat: async (p, cb) => {
|
|
81
79
|
try {
|
|
82
80
|
cb(null, await fs.stat(p));
|
|
83
|
-
} catch (err
|
|
81
|
+
} catch (err) {
|
|
84
82
|
cb(err);
|
|
85
83
|
}
|
|
86
84
|
},
|
|
87
|
-
// @ts-expect-error TS7006
|
|
88
85
|
lstat: async (p, cb) => {
|
|
89
86
|
// Our FileSystem interface doesn't have lstat support at the moment,
|
|
90
87
|
// but this is fine for our purposes since we follow symlinks by default.
|
|
91
88
|
try {
|
|
92
89
|
cb(null, await fs.stat(p));
|
|
93
|
-
} catch (err
|
|
90
|
+
} catch (err) {
|
|
94
91
|
cb(err);
|
|
95
92
|
}
|
|
96
93
|
},
|
|
97
|
-
// @ts-expect-error TS7006
|
|
98
94
|
readdir: async (p, opts, cb) => {
|
|
99
95
|
if (typeof opts === 'function') {
|
|
100
96
|
cb = opts;
|
|
@@ -103,13 +99,13 @@ export function glob(
|
|
|
103
99
|
|
|
104
100
|
try {
|
|
105
101
|
cb(null, await fs.readdir(p, opts));
|
|
106
|
-
} catch (err
|
|
102
|
+
} catch (err) {
|
|
107
103
|
cb(err);
|
|
108
104
|
}
|
|
109
105
|
},
|
|
110
106
|
},
|
|
111
107
|
};
|
|
112
108
|
|
|
113
|
-
//
|
|
109
|
+
// $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
|
|
114
110
|
return fastGlob(normalizeSeparators(p), options);
|
|
115
111
|
}
|
package/src/{hash.ts → hash.js}
RENAMED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
1
3
|
import type {Readable} from 'stream';
|
|
2
4
|
import type {FileSystem} from '@atlaspack/fs';
|
|
3
5
|
|
|
@@ -6,35 +8,28 @@ import {hashString, Hash} from '@atlaspack/rust';
|
|
|
6
8
|
|
|
7
9
|
export function hashStream(stream: Readable): Promise<string> {
|
|
8
10
|
let hash = new Hash();
|
|
9
|
-
return new Promise(
|
|
10
|
-
(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
stream.on('error', (err) => {
|
|
13
|
+
reject(err);
|
|
14
|
+
});
|
|
15
|
+
stream
|
|
16
|
+
.on('data', (chunk) => {
|
|
17
|
+
hash.writeBuffer(chunk);
|
|
18
|
+
})
|
|
19
|
+
.on('end', function () {
|
|
20
|
+
resolve(hash.finish());
|
|
21
|
+
})
|
|
22
|
+
.on('error', (err) => {
|
|
15
23
|
reject(err);
|
|
16
24
|
});
|
|
17
|
-
|
|
18
|
-
.on('data', (chunk) => {
|
|
19
|
-
hash.writeBuffer(chunk);
|
|
20
|
-
})
|
|
21
|
-
.on('end', function () {
|
|
22
|
-
resolve(hash.finish());
|
|
23
|
-
})
|
|
24
|
-
.on('error', (err) => {
|
|
25
|
-
reject(err);
|
|
26
|
-
});
|
|
27
|
-
},
|
|
28
|
-
);
|
|
25
|
+
});
|
|
29
26
|
}
|
|
30
27
|
|
|
31
|
-
export function hashObject(obj: {
|
|
28
|
+
export function hashObject(obj: {+[string]: mixed, ...}): string {
|
|
32
29
|
return hashString(JSON.stringify(objectSortedEntriesDeep(obj)));
|
|
33
30
|
}
|
|
34
31
|
|
|
35
|
-
let testCache: {
|
|
36
|
-
[key: string]: Promise<string>;
|
|
37
|
-
} = {
|
|
32
|
+
let testCache: {|[string]: Promise<string>|} = {
|
|
38
33
|
/*:: ...null */
|
|
39
34
|
};
|
|
40
35
|
export function hashFile(fs: FileSystem, filePath: string): Promise<string> {
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
1
3
|
import type {
|
|
2
4
|
Server as HTTPOnlyServer,
|
|
3
5
|
IncomingMessage as HTTPRequest,
|
|
4
6
|
ServerResponse as HTTPResponse,
|
|
5
7
|
} from 'http';
|
|
6
|
-
import type {
|
|
8
|
+
import type {
|
|
9
|
+
Server as HTTPSServer,
|
|
10
|
+
IncomingMessage as HTTPSRequest,
|
|
11
|
+
ServerResponse as HTTPSResponse,
|
|
12
|
+
} from 'https';
|
|
7
13
|
import type {Socket} from 'net';
|
|
8
14
|
import type {FilePath, HTTPSOptions} from '@atlaspack/types';
|
|
9
15
|
import type {FileSystem} from '@atlaspack/fs';
|
|
@@ -13,27 +19,29 @@ import https from 'https';
|
|
|
13
19
|
import nullthrows from 'nullthrows';
|
|
14
20
|
import {getCertificate, generateCertificate} from './';
|
|
15
21
|
|
|
16
|
-
type CreateHTTPServerOpts = {
|
|
17
|
-
listener?: (
|
|
18
|
-
host?: string
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
type CreateHTTPServerOpts = {|
|
|
23
|
+
listener?: (HTTPRequest | HTTPSRequest, HTTPResponse | HTTPSResponse) => void,
|
|
24
|
+
host?: string,
|
|
25
|
+
...
|
|
26
|
+
| {|
|
|
27
|
+
https: ?(HTTPSOptions | boolean),
|
|
28
|
+
inputFS: FileSystem,
|
|
29
|
+
outputFS: FileSystem,
|
|
30
|
+
cacheDir: FilePath,
|
|
31
|
+
|}
|
|
32
|
+
| {||},
|
|
33
|
+
|};
|
|
28
34
|
|
|
29
35
|
export type HTTPServer = HTTPOnlyServer | HTTPSServer;
|
|
30
36
|
|
|
31
37
|
// Creates either an http or https server with an awaitable dispose
|
|
32
38
|
// that closes any connections
|
|
33
|
-
export async function createHTTPServer(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
export async function createHTTPServer(
|
|
40
|
+
options: CreateHTTPServerOpts,
|
|
41
|
+
): Promise<{|
|
|
42
|
+
stop: () => Promise<void>,
|
|
43
|
+
server: HTTPServer,
|
|
44
|
+
|}> {
|
|
37
45
|
let server;
|
|
38
46
|
if (!options.https) {
|
|
39
47
|
server = http.createServer(options.listener);
|
|
@@ -65,23 +73,21 @@ export async function createHTTPServer(options: CreateHTTPServerOpts): Promise<{
|
|
|
65
73
|
return {
|
|
66
74
|
server,
|
|
67
75
|
stop() {
|
|
68
|
-
return new Promise(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
sockets = new Set();
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
for (let socket of nullthrows(sockets)) {
|
|
78
|
+
socket.destroy();
|
|
79
|
+
}
|
|
80
|
+
sockets = new Set();
|
|
74
81
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
server.close((err) => {
|
|
83
|
+
if (err != null) {
|
|
84
|
+
reject(err);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
80
87
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
);
|
|
88
|
+
resolve();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
85
91
|
},
|
|
86
92
|
};
|
|
87
93
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
export type * from './config';
|
|
3
|
+
export type * from './Deferred';
|
|
4
|
+
export type * from './generateBuildMetrics';
|
|
5
|
+
export type * from './http-server';
|
|
6
|
+
export type * from './path';
|
|
7
|
+
export type * from './prettyDiagnostic';
|
|
8
|
+
export type * from './schema';
|
|
8
9
|
|
|
9
10
|
export {default as countLines} from './countLines';
|
|
10
11
|
export {default as generateBuildMetrics} from './generateBuildMetrics';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
1
3
|
import open from 'open';
|
|
2
4
|
import {execSync} from 'child_process';
|
|
3
5
|
import logger from '@atlaspack/logger';
|
|
@@ -31,7 +33,7 @@ function commandExistsUnixSync(commandName: string) {
|
|
|
31
33
|
` && { echo >&1 '${commandName} found'; exit 0; }`,
|
|
32
34
|
);
|
|
33
35
|
return !!stdout;
|
|
34
|
-
} catch (error
|
|
36
|
+
} catch (error) {
|
|
35
37
|
return false;
|
|
36
38
|
}
|
|
37
39
|
}
|
|
@@ -52,7 +54,7 @@ export default async function openInBrowser(url: string, browser: string) {
|
|
|
52
54
|
: undefined;
|
|
53
55
|
|
|
54
56
|
await open(url, options);
|
|
55
|
-
} catch (err
|
|
57
|
+
} catch (err) {
|
|
56
58
|
logger.error(
|
|
57
59
|
`Unexpected error while opening in browser: ${browser}`,
|
|
58
60
|
'@atlaspack/utils',
|
package/src/{path.ts → path.js}
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @flow strict-local
|
|
1
2
|
import type {FilePath} from '@atlaspack/types';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
|
|
@@ -13,7 +14,8 @@ export function normalizeSeparators(filePath: FilePath): FilePath {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
export type PathOptions = {
|
|
16
|
-
noLeadingDotSlash?: boolean
|
|
17
|
+
noLeadingDotSlash?: boolean,
|
|
18
|
+
...
|
|
17
19
|
};
|
|
18
20
|
|
|
19
21
|
export function normalizePath(
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @flow strict-local
|
|
1
2
|
import type {Diagnostic} from '@atlaspack/diagnostic';
|
|
2
3
|
import type {PluginOptions} from '@atlaspack/types';
|
|
3
4
|
|
|
@@ -5,27 +6,29 @@ import formatCodeFrame from '@atlaspack/codeframe';
|
|
|
5
6
|
import _mdAnsi from '@atlaspack/markdown-ansi';
|
|
6
7
|
import _chalk from 'chalk';
|
|
7
8
|
import path from 'path';
|
|
9
|
+
// $FlowFixMe
|
|
8
10
|
import _terminalLink from 'terminal-link';
|
|
9
11
|
|
|
10
12
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
13
|
+
// $FlowFixMe
|
|
11
14
|
import snarkdown from 'snarkdown';
|
|
12
15
|
/* eslint-enable import/no-extraneous-dependencies */
|
|
13
16
|
|
|
14
|
-
export type FormattedCodeFrame = {
|
|
15
|
-
location: string
|
|
16
|
-
code: string
|
|
17
|
-
};
|
|
17
|
+
export type FormattedCodeFrame = {|
|
|
18
|
+
location: string,
|
|
19
|
+
code: string,
|
|
20
|
+
|};
|
|
18
21
|
|
|
19
|
-
export type AnsiDiagnosticResult = {
|
|
20
|
-
message: string
|
|
21
|
-
stack: string
|
|
22
|
+
export type AnsiDiagnosticResult = {|
|
|
23
|
+
message: string,
|
|
24
|
+
stack: string,
|
|
22
25
|
/** A formatted string containing all code frames, including their file locations. */
|
|
23
|
-
codeframe: string
|
|
26
|
+
codeframe: string,
|
|
24
27
|
/** A list of code frames with highlighted code and file locations separately. */
|
|
25
|
-
frames: Array<FormattedCodeFrame
|
|
26
|
-
hints: Array<string
|
|
27
|
-
documentation: string
|
|
28
|
-
};
|
|
28
|
+
frames: Array<FormattedCodeFrame>,
|
|
29
|
+
hints: Array<string>,
|
|
30
|
+
documentation: string,
|
|
31
|
+
|};
|
|
29
32
|
|
|
30
33
|
export default async function prettyDiagnostic(
|
|
31
34
|
diagnostic: Diagnostic,
|
|
@@ -48,24 +51,18 @@ export default async function prettyDiagnostic(
|
|
|
48
51
|
format === 'ansi'
|
|
49
52
|
? _terminalLink
|
|
50
53
|
: // eslint-disable-next-line no-unused-vars
|
|
51
|
-
(
|
|
52
|
-
text: string,
|
|
53
|
-
url: string,
|
|
54
|
-
_: {
|
|
55
|
-
fallback: (text: never, url: never) => string;
|
|
56
|
-
},
|
|
57
|
-
) => `<a href="${url}">${text}</a>`;
|
|
54
|
+
(text, url, _) => `<a href="${url}">${text}</a>`;
|
|
58
55
|
const chalk =
|
|
59
56
|
format === 'ansi'
|
|
60
57
|
? _chalk
|
|
61
58
|
: {
|
|
62
59
|
gray: {
|
|
63
|
-
underline: (v
|
|
60
|
+
underline: (v) =>
|
|
64
61
|
`<span style="color: grey; text-decoration: underline;">${v}</span>`,
|
|
65
62
|
},
|
|
66
63
|
};
|
|
67
64
|
|
|
68
|
-
let result
|
|
65
|
+
let result = {
|
|
69
66
|
message:
|
|
70
67
|
md(`**${origin ?? 'unknown'}**: `) +
|
|
71
68
|
(skipFormatting ? message : md(message)),
|
|
@@ -95,6 +92,7 @@ export default async function prettyDiagnostic(
|
|
|
95
92
|
useColor: true,
|
|
96
93
|
syntaxHighlighting: true,
|
|
97
94
|
language:
|
|
95
|
+
// $FlowFixMe sketchy null checks do not matter here...
|
|
98
96
|
codeFrame.language ||
|
|
99
97
|
(filePath != null ? path.extname(filePath).substr(1) : undefined),
|
|
100
98
|
terminalWidth,
|
|
@@ -134,7 +132,7 @@ export default async function prettyDiagnostic(
|
|
|
134
132
|
|
|
135
133
|
if (documentationURL != null) {
|
|
136
134
|
result.documentation = terminalLink('Learn more', documentationURL, {
|
|
137
|
-
fallback: (text
|
|
135
|
+
fallback: (text, url) => `${text}: ${url}`,
|
|
138
136
|
});
|
|
139
137
|
}
|
|
140
138
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
// @flow strict-local
|
|
1
2
|
import type {BuildProgressEvent} from '@atlaspack/types';
|
|
2
3
|
|
|
3
4
|
import path from 'path';
|
|
4
5
|
|
|
5
|
-
export function getProgressMessage(
|
|
6
|
-
event: BuildProgressEvent,
|
|
7
|
-
): string | null | undefined {
|
|
6
|
+
export function getProgressMessage(event: BuildProgressEvent): ?string {
|
|
8
7
|
switch (event.phase) {
|
|
9
8
|
case 'transforming':
|
|
10
9
|
return `Building ${path.basename(event.filePath)}...`;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
|
|
1
3
|
import type {FilePath, NamedBundle} from '@atlaspack/types';
|
|
2
4
|
|
|
3
5
|
import path from 'path';
|
|
@@ -6,9 +8,7 @@ import {relativePath} from './path';
|
|
|
6
8
|
export function relativeBundlePath(
|
|
7
9
|
from: NamedBundle,
|
|
8
10
|
to: NamedBundle,
|
|
9
|
-
opts: {
|
|
10
|
-
leadingDotSlash: boolean;
|
|
11
|
-
} = {leadingDotSlash: true},
|
|
11
|
+
opts: {|leadingDotSlash: boolean|} = {leadingDotSlash: true},
|
|
12
12
|
): FilePath {
|
|
13
13
|
let fromPath = path.join(from.target.distDir, from.name);
|
|
14
14
|
let toPath = path.join(to.target.distDir, to.name);
|