@atlaspack/utils 2.17.1 → 2.17.3-typescript-08dcc1c9b.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/CHANGELOG.md +7 -0
- package/LICENSE +201 -0
- package/lib/DefaultMap.js +0 -4
- package/lib/config.js +3 -1
- package/lib/debug-tools.js +1 -0
- package/lib/generateCertificate.js +2 -0
- package/lib/glob.js +14 -4
- package/lib/index.js +164 -9
- package/lib/is-url.js +2 -0
- package/lib/objectHash.js +0 -1
- package/lib/prettyDiagnostic.js +3 -5
- package/lib/schema.js +38 -19
- package/lib/shared-buffer.js +1 -1
- package/lib/urlJoin.js +1 -1
- package/package.json +18 -13
- package/src/{DefaultMap.js → DefaultMap.ts} +8 -12
- package/src/Deferred.ts +26 -0
- package/src/{PromiseQueue.js → PromiseQueue.ts} +41 -36
- package/src/{TapStream.js → TapStream.ts} +8 -7
- package/src/{alternatives.js → alternatives.ts} +14 -15
- package/src/{ansi-html.js → ansi-html.ts} +0 -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} +8 -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} +16 -11
- 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} +6 -4
- 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
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import type {
|
|
4
2
|
Server as HTTPOnlyServer,
|
|
5
3
|
IncomingMessage as HTTPRequest,
|
|
6
4
|
ServerResponse as HTTPResponse,
|
|
7
5
|
} from 'http';
|
|
8
|
-
import type {
|
|
9
|
-
Server as HTTPSServer,
|
|
10
|
-
IncomingMessage as HTTPSRequest,
|
|
11
|
-
ServerResponse as HTTPSResponse,
|
|
12
|
-
} from 'https';
|
|
6
|
+
import type {Server as HTTPSServer} from 'https';
|
|
13
7
|
import type {Socket} from 'net';
|
|
14
8
|
import type {FilePath, HTTPSOptions} from '@atlaspack/types';
|
|
15
9
|
import type {FileSystem} from '@atlaspack/fs';
|
|
@@ -19,29 +13,27 @@ import https from 'https';
|
|
|
19
13
|
import nullthrows from 'nullthrows';
|
|
20
14
|
import {getCertificate, generateCertificate} from './';
|
|
21
15
|
|
|
22
|
-
type CreateHTTPServerOpts = {
|
|
23
|
-
listener?: (HTTPRequest
|
|
24
|
-
host?: string
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
type CreateHTTPServerOpts = {
|
|
17
|
+
listener?: (arg1: HTTPRequest, arg2: HTTPResponse) => void;
|
|
18
|
+
host?: string;
|
|
19
|
+
} & (
|
|
20
|
+
| {
|
|
21
|
+
https: HTTPSOptions | boolean | null | undefined;
|
|
22
|
+
inputFS: FileSystem;
|
|
23
|
+
outputFS: FileSystem;
|
|
24
|
+
cacheDir: FilePath;
|
|
25
|
+
}
|
|
26
|
+
| Record<any, any>
|
|
27
|
+
);
|
|
34
28
|
|
|
35
29
|
export type HTTPServer = HTTPOnlyServer | HTTPSServer;
|
|
36
30
|
|
|
37
31
|
// Creates either an http or https server with an awaitable dispose
|
|
38
32
|
// that closes any connections
|
|
39
|
-
export async function createHTTPServer(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
server: HTTPServer,
|
|
44
|
-
|}> {
|
|
33
|
+
export async function createHTTPServer(options: CreateHTTPServerOpts): Promise<{
|
|
34
|
+
stop: () => Promise<void>;
|
|
35
|
+
server: HTTPServer;
|
|
36
|
+
}> {
|
|
45
37
|
let server;
|
|
46
38
|
if (!options.https) {
|
|
47
39
|
server = http.createServer(options.listener);
|
|
@@ -73,21 +65,23 @@ export async function createHTTPServer(
|
|
|
73
65
|
return {
|
|
74
66
|
server,
|
|
75
67
|
stop() {
|
|
76
|
-
return new Promise(
|
|
77
|
-
|
|
78
|
-
socket
|
|
79
|
-
|
|
80
|
-
sockets = new Set();
|
|
81
|
-
|
|
82
|
-
server.close((err) => {
|
|
83
|
-
if (err != null) {
|
|
84
|
-
reject(err);
|
|
85
|
-
return;
|
|
68
|
+
return new Promise(
|
|
69
|
+
(resolve: () => void, reject: (error?: any) => void) => {
|
|
70
|
+
for (let socket of nullthrows(sockets)) {
|
|
71
|
+
socket.destroy();
|
|
86
72
|
}
|
|
73
|
+
sockets = new Set();
|
|
74
|
+
|
|
75
|
+
server.close((err) => {
|
|
76
|
+
if (err != null) {
|
|
77
|
+
reject(err);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
87
80
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
81
|
+
resolve();
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
);
|
|
91
85
|
},
|
|
92
86
|
};
|
|
93
87
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export type * from './schema';
|
|
1
|
+
export * from './config';
|
|
2
|
+
export * from './Deferred';
|
|
3
|
+
export * from './generateBuildMetrics';
|
|
4
|
+
export * from './http-server';
|
|
5
|
+
export * from './path';
|
|
6
|
+
export * from './prettyDiagnostic';
|
|
7
|
+
export * from './schema';
|
|
9
8
|
|
|
10
9
|
export {default as countLines} from './countLines';
|
|
11
10
|
export {default as generateBuildMetrics} from './generateBuildMetrics';
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import open from 'open';
|
|
4
2
|
import {execSync} from 'child_process';
|
|
5
3
|
import logger from '@atlaspack/logger';
|
|
@@ -33,7 +31,7 @@ function commandExistsUnixSync(commandName: string) {
|
|
|
33
31
|
` && { echo >&1 '${commandName} found'; exit 0; }`,
|
|
34
32
|
);
|
|
35
33
|
return !!stdout;
|
|
36
|
-
} catch (error) {
|
|
34
|
+
} catch (error: any) {
|
|
37
35
|
return false;
|
|
38
36
|
}
|
|
39
37
|
}
|
|
@@ -54,7 +52,7 @@ export default async function openInBrowser(url: string, browser: string) {
|
|
|
54
52
|
: undefined;
|
|
55
53
|
|
|
56
54
|
await open(url, options);
|
|
57
|
-
} catch (err) {
|
|
55
|
+
} catch (err: any) {
|
|
58
56
|
logger.error(
|
|
59
57
|
`Unexpected error while opening in browser: ${browser}`,
|
|
60
58
|
'@atlaspack/utils',
|
package/src/{path.js → path.ts}
RENAMED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
1
|
import type {FilePath} from '@atlaspack/types';
|
|
3
2
|
import path from 'path';
|
|
4
3
|
|
|
@@ -14,8 +13,7 @@ export function normalizeSeparators(filePath: FilePath): FilePath {
|
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
export type PathOptions = {
|
|
17
|
-
noLeadingDotSlash?: boolean
|
|
18
|
-
...
|
|
16
|
+
noLeadingDotSlash?: boolean;
|
|
19
17
|
};
|
|
20
18
|
|
|
21
19
|
export function normalizePath(
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
1
|
import type {Diagnostic} from '@atlaspack/diagnostic';
|
|
3
2
|
import type {PluginOptions} from '@atlaspack/types';
|
|
4
3
|
|
|
@@ -6,29 +5,27 @@ import formatCodeFrame from '@atlaspack/codeframe';
|
|
|
6
5
|
import _mdAnsi from '@atlaspack/markdown-ansi';
|
|
7
6
|
import _chalk from 'chalk';
|
|
8
7
|
import path from 'path';
|
|
9
|
-
// $FlowFixMe
|
|
10
8
|
import _terminalLink from 'terminal-link';
|
|
11
9
|
|
|
12
10
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
13
|
-
// $FlowFixMe
|
|
14
11
|
import snarkdown from 'snarkdown';
|
|
15
12
|
/* eslint-enable import/no-extraneous-dependencies */
|
|
16
13
|
|
|
17
|
-
export type FormattedCodeFrame = {
|
|
18
|
-
location: string
|
|
19
|
-
code: string
|
|
20
|
-
|
|
14
|
+
export type FormattedCodeFrame = {
|
|
15
|
+
location: string;
|
|
16
|
+
code: string;
|
|
17
|
+
};
|
|
21
18
|
|
|
22
|
-
export type AnsiDiagnosticResult = {
|
|
23
|
-
message: string
|
|
24
|
-
stack: string
|
|
19
|
+
export type AnsiDiagnosticResult = {
|
|
20
|
+
message: string;
|
|
21
|
+
stack: string;
|
|
25
22
|
/** A formatted string containing all code frames, including their file locations. */
|
|
26
|
-
codeframe: string
|
|
23
|
+
codeframe: string;
|
|
27
24
|
/** A list of code frames with highlighted code and file locations separately. */
|
|
28
|
-
frames: Array<FormattedCodeFrame
|
|
29
|
-
hints: Array<string
|
|
30
|
-
documentation: string
|
|
31
|
-
|
|
25
|
+
frames: Array<FormattedCodeFrame>;
|
|
26
|
+
hints: Array<string>;
|
|
27
|
+
documentation: string;
|
|
28
|
+
};
|
|
32
29
|
|
|
33
30
|
export default async function prettyDiagnostic(
|
|
34
31
|
diagnostic: Diagnostic,
|
|
@@ -51,18 +48,24 @@ export default async function prettyDiagnostic(
|
|
|
51
48
|
format === 'ansi'
|
|
52
49
|
? _terminalLink
|
|
53
50
|
: // eslint-disable-next-line no-unused-vars
|
|
54
|
-
(
|
|
51
|
+
(
|
|
52
|
+
text: string,
|
|
53
|
+
url: string,
|
|
54
|
+
_: {
|
|
55
|
+
fallback: (text: never, url: never) => string;
|
|
56
|
+
},
|
|
57
|
+
) => `<a href="${url}">${text}</a>`;
|
|
55
58
|
const chalk =
|
|
56
59
|
format === 'ansi'
|
|
57
60
|
? _chalk
|
|
58
61
|
: {
|
|
59
62
|
gray: {
|
|
60
|
-
underline: (v) =>
|
|
63
|
+
underline: (v: string) =>
|
|
61
64
|
`<span style="color: grey; text-decoration: underline;">${v}</span>`,
|
|
62
65
|
},
|
|
63
66
|
};
|
|
64
67
|
|
|
65
|
-
let result = {
|
|
68
|
+
let result: AnsiDiagnosticResult = {
|
|
66
69
|
message:
|
|
67
70
|
md(`**${origin ?? 'unknown'}**: `) +
|
|
68
71
|
(skipFormatting ? message : md(message)),
|
|
@@ -92,7 +95,6 @@ export default async function prettyDiagnostic(
|
|
|
92
95
|
useColor: true,
|
|
93
96
|
syntaxHighlighting: true,
|
|
94
97
|
language:
|
|
95
|
-
// $FlowFixMe sketchy null checks do not matter here...
|
|
96
98
|
codeFrame.language ||
|
|
97
99
|
(filePath != null ? path.extname(filePath).substr(1) : undefined),
|
|
98
100
|
terminalWidth,
|
|
@@ -132,7 +134,7 @@ export default async function prettyDiagnostic(
|
|
|
132
134
|
|
|
133
135
|
if (documentationURL != null) {
|
|
134
136
|
result.documentation = terminalLink('Learn more', documentationURL, {
|
|
135
|
-
fallback: (text, url) => `${text}: ${url}`,
|
|
137
|
+
fallback: (text: string, url: string) => `${text}: ${url}`,
|
|
136
138
|
});
|
|
137
139
|
}
|
|
138
140
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
1
|
import type {BuildProgressEvent} from '@atlaspack/types';
|
|
3
2
|
|
|
4
3
|
import path from 'path';
|
|
5
4
|
|
|
6
|
-
export function getProgressMessage(
|
|
5
|
+
export function getProgressMessage(
|
|
6
|
+
event: BuildProgressEvent,
|
|
7
|
+
): string | null | undefined {
|
|
7
8
|
switch (event.phase) {
|
|
8
9
|
case 'transforming':
|
|
9
10
|
return `Building ${path.basename(event.filePath)}...`;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import type {FilePath, NamedBundle} from '@atlaspack/types';
|
|
4
2
|
|
|
5
3
|
import path from 'path';
|
|
@@ -8,7 +6,9 @@ import {relativePath} from './path';
|
|
|
8
6
|
export function relativeBundlePath(
|
|
9
7
|
from: NamedBundle,
|
|
10
8
|
to: NamedBundle,
|
|
11
|
-
opts: {
|
|
9
|
+
opts: {
|
|
10
|
+
leadingDotSlash: boolean;
|
|
11
|
+
} = {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);
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow strict-local
|
|
2
|
-
|
|
3
1
|
import type SourceMap from '@parcel/source-map';
|
|
4
2
|
import type {
|
|
5
3
|
Async,
|
|
@@ -20,7 +18,10 @@ import {bufferStream, relativeBundlePath, urlJoin} from './';
|
|
|
20
18
|
|
|
21
19
|
type ReplacementMap = Map<
|
|
22
20
|
string /* dependency id */,
|
|
23
|
-
{
|
|
21
|
+
{
|
|
22
|
+
from: string;
|
|
23
|
+
to: string;
|
|
24
|
+
}
|
|
24
25
|
>;
|
|
25
26
|
|
|
26
27
|
/*
|
|
@@ -35,18 +36,21 @@ export function replaceURLReferences({
|
|
|
35
36
|
bundleGraph,
|
|
36
37
|
contents,
|
|
37
38
|
map,
|
|
38
|
-
getReplacement = (s) => s,
|
|
39
|
+
getReplacement = (s: string) => s,
|
|
39
40
|
relative = true,
|
|
40
|
-
}: {
|
|
41
|
-
bundle: NamedBundle
|
|
42
|
-
bundleGraph: BundleGraph<NamedBundle
|
|
43
|
-
contents: string
|
|
44
|
-
relative?: boolean
|
|
45
|
-
map?:
|
|
46
|
-
getReplacement?: (string) => string
|
|
47
|
-
|
|
41
|
+
}: {
|
|
42
|
+
bundle: NamedBundle;
|
|
43
|
+
bundleGraph: BundleGraph<NamedBundle>;
|
|
44
|
+
contents: string;
|
|
45
|
+
relative?: boolean;
|
|
46
|
+
map?: SourceMap | null | undefined;
|
|
47
|
+
getReplacement?: (arg1: string) => string;
|
|
48
|
+
}): {
|
|
49
|
+
readonly contents: string;
|
|
50
|
+
readonly map: SourceMap | null | undefined;
|
|
51
|
+
} {
|
|
48
52
|
let replacements = new Map();
|
|
49
|
-
let urlDependencies = [];
|
|
53
|
+
let urlDependencies: Array<Dependency> = [];
|
|
50
54
|
bundle.traverse((node) => {
|
|
51
55
|
if (node.type === 'dependency' && node.value.specifierType === 'url') {
|
|
52
56
|
urlDependencies.push(node.value);
|
|
@@ -102,24 +106,32 @@ export async function replaceInlineReferences({
|
|
|
102
106
|
map,
|
|
103
107
|
getInlineReplacement,
|
|
104
108
|
getInlineBundleContents,
|
|
105
|
-
}: {
|
|
106
|
-
bundle: Bundle
|
|
107
|
-
bundleGraph: BundleGraph<NamedBundle
|
|
108
|
-
contents: string
|
|
109
|
+
}: {
|
|
110
|
+
bundle: Bundle;
|
|
111
|
+
bundleGraph: BundleGraph<NamedBundle>;
|
|
112
|
+
contents: string;
|
|
109
113
|
getInlineReplacement: (
|
|
110
|
-
Dependency,
|
|
111
|
-
|
|
112
|
-
string,
|
|
113
|
-
) => {
|
|
114
|
+
arg1: Dependency,
|
|
115
|
+
arg2: 'string' | null | undefined,
|
|
116
|
+
arg3: string,
|
|
117
|
+
) => {
|
|
118
|
+
from: string;
|
|
119
|
+
to: string;
|
|
120
|
+
};
|
|
114
121
|
getInlineBundleContents: (
|
|
115
|
-
Bundle,
|
|
116
|
-
BundleGraph<NamedBundle>,
|
|
117
|
-
) => Async<{
|
|
118
|
-
|
|
119
|
-
|
|
122
|
+
arg1: Bundle,
|
|
123
|
+
arg2: BundleGraph<NamedBundle>,
|
|
124
|
+
) => Async<{
|
|
125
|
+
contents: Blob;
|
|
126
|
+
}>;
|
|
127
|
+
map?: SourceMap | null | undefined;
|
|
128
|
+
}): Promise<{
|
|
129
|
+
readonly contents: string;
|
|
130
|
+
readonly map: SourceMap | null | undefined;
|
|
131
|
+
}> {
|
|
120
132
|
let replacements = new Map();
|
|
121
133
|
|
|
122
|
-
let dependencies = [];
|
|
134
|
+
let dependencies: Array<Dependency> = [];
|
|
123
135
|
bundle.traverse((node) => {
|
|
124
136
|
if (node.type === 'dependency') {
|
|
125
137
|
dependencies.push(node.value);
|
|
@@ -162,13 +174,16 @@ export function getURLReplacement({
|
|
|
162
174
|
toBundle,
|
|
163
175
|
relative,
|
|
164
176
|
getReplacement,
|
|
165
|
-
}: {
|
|
166
|
-
dependency: Dependency
|
|
167
|
-
fromBundle: NamedBundle
|
|
168
|
-
toBundle: NamedBundle
|
|
169
|
-
relative: boolean
|
|
170
|
-
getReplacement?: (string) => string
|
|
171
|
-
|
|
177
|
+
}: {
|
|
178
|
+
dependency: Dependency;
|
|
179
|
+
fromBundle: NamedBundle;
|
|
180
|
+
toBundle: NamedBundle;
|
|
181
|
+
relative: boolean;
|
|
182
|
+
getReplacement?: (arg1: string) => string;
|
|
183
|
+
}): {
|
|
184
|
+
from: string;
|
|
185
|
+
to: string;
|
|
186
|
+
} {
|
|
172
187
|
let to;
|
|
173
188
|
|
|
174
189
|
let orig = URL.parse(dependency.specifier);
|
|
@@ -208,8 +223,11 @@ export function getURLReplacement({
|
|
|
208
223
|
function performReplacement(
|
|
209
224
|
replacements: ReplacementMap,
|
|
210
225
|
contents: string,
|
|
211
|
-
map?:
|
|
212
|
-
): {
|
|
226
|
+
map?: SourceMap | null,
|
|
227
|
+
): {
|
|
228
|
+
readonly contents: string;
|
|
229
|
+
readonly map: SourceMap | null | undefined;
|
|
230
|
+
} {
|
|
213
231
|
let finalContents = contents;
|
|
214
232
|
|
|
215
233
|
if (getFeatureFlag('inlineStringReplacementPerf')) {
|