@parcel/utils 2.0.0-nightly.137 → 2.0.0-nightly.1370
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +6 -6
- package/lib/index.js +37566 -307
- package/lib/index.js.map +1 -0
- package/package.json +45 -20
- package/src/BitSet.js +126 -0
- package/src/DefaultMap.js +1 -1
- package/src/PromiseQueue.js +16 -12
- package/src/alternatives.js +145 -0
- package/src/ansi-html.js +2 -2
- package/src/blob.js +2 -1
- package/src/bundle-url.js +1 -1
- package/src/collection.js +35 -15
- package/src/config.js +132 -45
- package/src/countLines.js +5 -2
- package/src/debounce.js +1 -1
- package/src/dependency-location.js +11 -6
- package/src/generateBuildMetrics.js +158 -0
- package/src/generateCertificate.js +1 -1
- package/src/getCertificate.js +1 -1
- package/src/getExisting.js +1 -4
- package/src/getModuleParts.js +23 -0
- package/src/getRootDir.js +1 -2
- package/src/glob.js +51 -10
- package/src/hash.js +49 -0
- package/src/http-server.js +29 -19
- package/src/index.js +69 -21
- package/src/is-url.js +1 -1
- package/src/isDirectoryInside.js +11 -0
- package/src/openInBrowser.js +64 -0
- package/src/path.js +38 -6
- package/src/prettyDiagnostic.js +74 -24
- package/src/progress-message.js +22 -0
- package/src/relativeBundlePath.js +8 -13
- package/src/replaceBundleReferences.js +85 -41
- package/src/schema.js +100 -44
- package/src/shared-buffer.js +23 -0
- package/src/sourcemap.js +138 -0
- package/src/stream.js +31 -1
- package/src/urlJoin.js +3 -1
- package/test/BitSet.test.js +119 -0
- package/test/DefaultMap.test.js +7 -4
- package/test/collection.test.js +13 -1
- package/test/config.test.js +98 -0
- package/test/input/config/.testrc +3 -0
- package/test/input/config/config.cjs +3 -0
- package/test/input/config/config.js +3 -0
- package/test/input/config/config.json +3 -0
- package/test/input/config/empty.json +0 -0
- package/test/input/config/empty.toml +0 -0
- package/test/input/sourcemap/referenced-min.js +2 -0
- package/test/input/sourcemap/referenced-min.js.map +6 -0
- package/test/input/sourcemap/source-root.js +2 -0
- package/test/input/sourcemap/source-root.js.map +7 -0
- package/test/replaceBundleReferences.test.js +268 -0
- package/test/sourcemap.test.js +207 -0
- package/test/throttle.test.js +1 -2
- package/test/urlJoin.test.js +37 -0
- package/lib/DefaultMap.js +0 -64
- package/lib/Deferred.js +0 -26
- package/lib/PromiseQueue.js +0 -133
- package/lib/TapStream.js +0 -41
- package/lib/ansi-html.js +0 -16
- package/lib/blob.js +0 -31
- package/lib/bundle-url.js +0 -43
- package/lib/collection.js +0 -62
- package/lib/config.js +0 -88
- package/lib/countLines.js +0 -18
- package/lib/debounce.js +0 -20
- package/lib/dependency-location.js +0 -21
- package/lib/escape-html.js +0 -24
- package/lib/generateBundleReport.js +0 -38
- package/lib/generateCertificate.js +0 -124
- package/lib/getCertificate.js +0 -19
- package/lib/getExisting.js +0 -23
- package/lib/getRootDir.js +0 -55
- package/lib/glob.js +0 -76
- package/lib/http-server.js +0 -64
- package/lib/is-url.js +0 -17
- package/lib/loadSourceMapUrl.js +0 -33
- package/lib/md5.js +0 -35
- package/lib/objectHash.js +0 -26
- package/lib/parseCSSImport.js +0 -16
- package/lib/path.js +0 -22
- package/lib/prettifyTime.js +0 -10
- package/lib/prettyDiagnostic.js +0 -57
- package/lib/promisify.js +0 -13
- package/lib/relativeBundlePath.js +0 -24
- package/lib/relativeUrl.js +0 -16
- package/lib/replaceBundleReferences.js +0 -151
- package/lib/resolve.js +0 -93
- package/lib/schema.js +0 -320
- package/lib/serializeObject.js +0 -28
- package/lib/stream.js +0 -51
- package/lib/throttle.js +0 -16
- package/lib/urlJoin.js +0 -27
- package/src/.babelrc +0 -3
- package/src/generateBundleReport.js +0 -51
- package/src/loadSourceMapUrl.js +0 -33
- package/src/md5.js +0 -44
- package/src/promisify.js +0 -13
- package/src/resolve.js +0 -135
- package/src/serializeObject.js +0 -22
- package/test/input/sourcemap/referenced.js +0 -7
- package/test/loadSourceMapUrl.test.js +0 -37
package/src/http-server.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
// @flow strict-local
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type {
|
|
4
|
+
Server as HTTPOnlyServer,
|
|
5
|
+
IncomingMessage as HTTPRequest,
|
|
6
|
+
ServerResponse as HTTPResponse,
|
|
7
|
+
} from 'http';
|
|
8
|
+
import type {
|
|
9
|
+
Server as HTTPSServer,
|
|
10
|
+
IncomingMessage as HTTPSRequest,
|
|
11
|
+
ServerResponse as HTTPSResponse,
|
|
12
|
+
} from 'https';
|
|
5
13
|
import type {Socket} from 'net';
|
|
6
14
|
import type {FilePath, HTTPSOptions} from '@parcel/types';
|
|
7
15
|
import type {FileSystem} from '@parcel/fs';
|
|
@@ -9,15 +17,19 @@ import type {FileSystem} from '@parcel/fs';
|
|
|
9
17
|
import http from 'http';
|
|
10
18
|
import https from 'https';
|
|
11
19
|
import nullthrows from 'nullthrows';
|
|
12
|
-
import {getCertificate, generateCertificate} from '
|
|
20
|
+
import {getCertificate, generateCertificate} from './';
|
|
13
21
|
|
|
14
22
|
type CreateHTTPServerOpts = {|
|
|
15
|
-
|
|
16
|
-
inputFS: FileSystem,
|
|
17
|
-
outputFS: FileSystem,
|
|
18
|
-
cacheDir: FilePath,
|
|
19
|
-
listener?: (mixed, mixed) => void,
|
|
23
|
+
listener?: (HTTPRequest | HTTPSRequest, HTTPResponse | HTTPSResponse) => void,
|
|
20
24
|
host?: string,
|
|
25
|
+
...
|
|
26
|
+
| {|
|
|
27
|
+
https: ?(HTTPSOptions | boolean),
|
|
28
|
+
inputFS: FileSystem,
|
|
29
|
+
outputFS: FileSystem,
|
|
30
|
+
cacheDir: FilePath,
|
|
31
|
+
|}
|
|
32
|
+
| {||},
|
|
21
33
|
|};
|
|
22
34
|
|
|
23
35
|
export type HTTPServer = HTTPOnlyServer | HTTPSServer;
|
|
@@ -34,19 +46,17 @@ export async function createHTTPServer(
|
|
|
34
46
|
if (!options.https) {
|
|
35
47
|
server = http.createServer(options.listener);
|
|
36
48
|
} else if (options.https === true) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
options.host,
|
|
42
|
-
),
|
|
43
|
-
options.listener,
|
|
49
|
+
let {cert, key} = await generateCertificate(
|
|
50
|
+
options.outputFS,
|
|
51
|
+
options.cacheDir,
|
|
52
|
+
options.host,
|
|
44
53
|
);
|
|
54
|
+
|
|
55
|
+
server = https.createServer({cert, key}, options.listener);
|
|
45
56
|
} else {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
57
|
+
let {cert, key} = await getCertificate(options.inputFS, options.https);
|
|
58
|
+
|
|
59
|
+
server = https.createServer({cert, key}, options.listener);
|
|
50
60
|
}
|
|
51
61
|
|
|
52
62
|
// HTTPServer#close only stops accepting new connections, and does not close existing ones.
|
package/src/index.js
CHANGED
|
@@ -1,41 +1,89 @@
|
|
|
1
1
|
// @flow strict-local
|
|
2
|
-
export type * from './
|
|
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';
|
|
3
7
|
export type * from './prettyDiagnostic';
|
|
8
|
+
export type * from './schema';
|
|
4
9
|
|
|
5
10
|
export {default as countLines} from './countLines';
|
|
6
|
-
export {default as
|
|
11
|
+
export {default as generateBuildMetrics} from './generateBuildMetrics';
|
|
7
12
|
export {default as generateCertificate} from './generateCertificate';
|
|
8
13
|
export {default as getCertificate} from './getCertificate';
|
|
14
|
+
export {default as getModuleParts} from './getModuleParts';
|
|
9
15
|
export {default as getRootDir} from './getRootDir';
|
|
16
|
+
export {default as isDirectoryInside} from './isDirectoryInside';
|
|
10
17
|
export {default as isURL} from './is-url';
|
|
11
18
|
export {default as objectHash} from './objectHash';
|
|
12
19
|
export {default as prettifyTime} from './prettifyTime';
|
|
13
20
|
export {default as prettyDiagnostic} from './prettyDiagnostic';
|
|
14
21
|
export {default as PromiseQueue} from './PromiseQueue';
|
|
15
|
-
// $FlowFixMe this is untyped
|
|
16
|
-
export {default as promisify} from './promisify';
|
|
17
22
|
export {default as validateSchema} from './schema';
|
|
18
23
|
export {default as TapStream} from './TapStream';
|
|
19
24
|
export {default as urlJoin} from './urlJoin';
|
|
20
|
-
export {default as loadSourceMapUrl} from './loadSourceMapUrl';
|
|
21
25
|
export {default as relativeUrl} from './relativeUrl';
|
|
22
26
|
export {default as createDependencyLocation} from './dependency-location';
|
|
23
27
|
export {default as debounce} from './debounce';
|
|
24
28
|
export {default as throttle} from './throttle';
|
|
29
|
+
export {default as openInBrowser} from './openInBrowser';
|
|
25
30
|
|
|
26
|
-
export *
|
|
27
|
-
export
|
|
28
|
-
export
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
// Explicit re-exports instead of export * for lazy require performance
|
|
32
|
+
export {findAlternativeNodeModules, findAlternativeFiles} from './alternatives';
|
|
33
|
+
export {blobToBuffer, blobToString} from './blob';
|
|
34
|
+
export {
|
|
35
|
+
unique,
|
|
36
|
+
objectSortedEntries,
|
|
37
|
+
objectSortedEntriesDeep,
|
|
38
|
+
setDifference,
|
|
39
|
+
setEqual,
|
|
40
|
+
setIntersect,
|
|
41
|
+
setUnion,
|
|
42
|
+
} from './collection';
|
|
43
|
+
export {
|
|
44
|
+
resolveConfig,
|
|
45
|
+
resolveConfigSync,
|
|
46
|
+
loadConfig,
|
|
47
|
+
readConfig,
|
|
48
|
+
} from './config';
|
|
49
|
+
export {DefaultMap, DefaultWeakMap} from './DefaultMap';
|
|
50
|
+
export {makeDeferredWithPromise} from './Deferred';
|
|
51
|
+
export {getProgressMessage} from './progress-message.js';
|
|
52
|
+
export {
|
|
53
|
+
isGlob,
|
|
54
|
+
isGlobMatch,
|
|
55
|
+
globMatch,
|
|
56
|
+
globSync,
|
|
57
|
+
glob,
|
|
58
|
+
globToRegex,
|
|
59
|
+
} from './glob';
|
|
60
|
+
export {hashStream, hashObject, hashFile} from './hash';
|
|
61
|
+
export {SharedBuffer} from './shared-buffer';
|
|
62
|
+
export {fuzzySearch} from './schema';
|
|
63
|
+
export {createHTTPServer} from './http-server';
|
|
64
|
+
export {normalizePath, normalizeSeparators, relativePath} from './path';
|
|
65
|
+
export {
|
|
66
|
+
replaceURLReferences,
|
|
67
|
+
replaceInlineReferences,
|
|
68
|
+
} from './replaceBundleReferences';
|
|
69
|
+
export {
|
|
70
|
+
measureStreamLength,
|
|
71
|
+
readableFromStringOrBuffer,
|
|
72
|
+
bufferStream,
|
|
73
|
+
blobToStream,
|
|
74
|
+
streamFromPromise,
|
|
75
|
+
fallbackStream,
|
|
76
|
+
} from './stream';
|
|
77
|
+
export {relativeBundlePath} from './relativeBundlePath';
|
|
78
|
+
export {ansiHtml} from './ansi-html';
|
|
79
|
+
export {escapeHTML} from './escape-html';
|
|
80
|
+
export {
|
|
81
|
+
SOURCEMAP_RE,
|
|
82
|
+
SOURCEMAP_EXTENSIONS,
|
|
83
|
+
matchSourceMappingURL,
|
|
84
|
+
loadSourceMapUrl,
|
|
85
|
+
loadSourceMap,
|
|
86
|
+
remapSourceLocation,
|
|
87
|
+
} from './sourcemap';
|
|
88
|
+
export {BitSet} from './BitSet';
|
|
89
|
+
export {default as stripAnsi} from 'strip-ansi';
|
package/src/is-url.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
import type {FilePath} from '@parcel/types';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
export default function isDirectoryInside(
|
|
6
|
+
child: FilePath,
|
|
7
|
+
parent: FilePath,
|
|
8
|
+
): boolean {
|
|
9
|
+
const relative = path.relative(parent, child);
|
|
10
|
+
return !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
11
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import open from 'open';
|
|
4
|
+
import {execSync} from 'child_process';
|
|
5
|
+
import logger from '@parcel/logger';
|
|
6
|
+
|
|
7
|
+
// Chrome app name is platform dependent. we should not hard code it.
|
|
8
|
+
// https://github.com/react-native-community/cli/blob/e2be8a905285d9b37512fc78c9755b9635ecf805/packages/cli/src/commands/server/launchDebugger.ts#L28
|
|
9
|
+
function getChromeAppName(): string {
|
|
10
|
+
switch (process.platform) {
|
|
11
|
+
case 'darwin':
|
|
12
|
+
return 'google chrome';
|
|
13
|
+
case 'win32':
|
|
14
|
+
return 'chrome';
|
|
15
|
+
case 'linux':
|
|
16
|
+
if (commandExistsUnixSync('google-chrome')) {
|
|
17
|
+
return 'google-chrome';
|
|
18
|
+
}
|
|
19
|
+
if (commandExistsUnixSync('chromium-browser')) {
|
|
20
|
+
return 'chromium-browser';
|
|
21
|
+
}
|
|
22
|
+
return 'chromium';
|
|
23
|
+
|
|
24
|
+
default:
|
|
25
|
+
return 'google-chrome';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function commandExistsUnixSync(commandName: string) {
|
|
30
|
+
try {
|
|
31
|
+
const stdout = execSync(
|
|
32
|
+
`command -v ${commandName} 2>/dev/null` +
|
|
33
|
+
` && { echo >&1 '${commandName} found'; exit 0; }`,
|
|
34
|
+
);
|
|
35
|
+
return !!stdout;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getAppName(appName: string): string {
|
|
42
|
+
if (['google', 'chrome'].includes(appName)) {
|
|
43
|
+
return getChromeAppName();
|
|
44
|
+
} else if (['brave', 'Brave'].includes(appName)) {
|
|
45
|
+
return 'Brave Browser';
|
|
46
|
+
} else return appName;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default async function openInBrowser(url: string, browser: string) {
|
|
50
|
+
try {
|
|
51
|
+
const options =
|
|
52
|
+
typeof browser === 'string' && browser.length > 0
|
|
53
|
+
? {app: [getAppName(browser)]}
|
|
54
|
+
: undefined;
|
|
55
|
+
|
|
56
|
+
await open(url, options);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
logger.error(
|
|
59
|
+
`Unexpected error while opening in browser: ${browser}`,
|
|
60
|
+
'@parcel/utils',
|
|
61
|
+
);
|
|
62
|
+
logger.error(err, '@parcel/utils');
|
|
63
|
+
}
|
|
64
|
+
}
|
package/src/path.js
CHANGED
|
@@ -1,16 +1,48 @@
|
|
|
1
1
|
// @flow strict-local
|
|
2
|
-
|
|
3
2
|
import type {FilePath} from '@parcel/types';
|
|
4
3
|
import path from 'path';
|
|
5
4
|
|
|
6
|
-
const
|
|
5
|
+
const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:){0,1}[\\/]+/;
|
|
6
|
+
const SEPARATOR_REGEX = /[\\]+/g;
|
|
7
|
+
|
|
8
|
+
export function isAbsolute(filepath: string): boolean {
|
|
9
|
+
return ABSOLUTE_PATH_REGEX.test(filepath);
|
|
10
|
+
}
|
|
7
11
|
|
|
8
12
|
export function normalizeSeparators(filePath: FilePath): FilePath {
|
|
9
|
-
|
|
13
|
+
return filePath.replace(SEPARATOR_REGEX, '/');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type PathOptions = {
|
|
17
|
+
noLeadingDotSlash?: boolean,
|
|
18
|
+
...
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function normalizePath(
|
|
22
|
+
filePath: FilePath,
|
|
23
|
+
leadingDotSlash: boolean = true,
|
|
24
|
+
): FilePath {
|
|
25
|
+
if (
|
|
26
|
+
leadingDotSlash &&
|
|
27
|
+
(filePath[0] !== '.' ||
|
|
28
|
+
(filePath[1] !== '.' && filePath[1] !== '/' && filePath[1] !== '\\')) &&
|
|
29
|
+
!path.isAbsolute(filePath)
|
|
30
|
+
) {
|
|
31
|
+
return normalizeSeparators('./' + filePath);
|
|
32
|
+
} else {
|
|
33
|
+
return normalizeSeparators(filePath);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
10
36
|
|
|
11
|
-
|
|
12
|
-
|
|
37
|
+
export function relativePath(
|
|
38
|
+
from: string,
|
|
39
|
+
to: string,
|
|
40
|
+
leadingDotSlash: boolean = true,
|
|
41
|
+
): FilePath {
|
|
42
|
+
// Fast path
|
|
43
|
+
if (to.startsWith(from + '/')) {
|
|
44
|
+
return (leadingDotSlash ? './' : '') + to.slice(from.length + 1);
|
|
13
45
|
}
|
|
14
46
|
|
|
15
|
-
return
|
|
47
|
+
return normalizePath(path.relative(from, to), leadingDotSlash);
|
|
16
48
|
}
|
package/src/prettyDiagnostic.js
CHANGED
|
@@ -1,61 +1,105 @@
|
|
|
1
1
|
// @flow strict-local
|
|
2
2
|
import type {Diagnostic} from '@parcel/diagnostic';
|
|
3
|
+
import type {PluginOptions} from '@parcel/types';
|
|
3
4
|
|
|
4
5
|
import formatCodeFrame from '@parcel/codeframe';
|
|
5
6
|
import mdAnsi from '@parcel/markdown-ansi';
|
|
6
7
|
import chalk from 'chalk';
|
|
7
8
|
import path from 'path';
|
|
9
|
+
// $FlowFixMe
|
|
10
|
+
import terminalLink from 'terminal-link';
|
|
11
|
+
|
|
12
|
+
export type FormattedCodeFrame = {|
|
|
13
|
+
location: string,
|
|
14
|
+
code: string,
|
|
15
|
+
|};
|
|
8
16
|
|
|
9
17
|
export type AnsiDiagnosticResult = {|
|
|
10
18
|
message: string,
|
|
11
19
|
stack: string,
|
|
20
|
+
/** A formatted string containing all code frames, including their file locations. */
|
|
12
21
|
codeframe: string,
|
|
22
|
+
/** A list of code frames with highlighted code and file locations separately. */
|
|
23
|
+
frames: Array<FormattedCodeFrame>,
|
|
13
24
|
hints: Array<string>,
|
|
25
|
+
documentation: string,
|
|
14
26
|
|};
|
|
15
27
|
|
|
16
|
-
export default function prettyDiagnostic(
|
|
28
|
+
export default async function prettyDiagnostic(
|
|
17
29
|
diagnostic: Diagnostic,
|
|
18
|
-
|
|
30
|
+
options?: PluginOptions,
|
|
31
|
+
terminalWidth?: number,
|
|
32
|
+
): Promise<AnsiDiagnosticResult> {
|
|
19
33
|
let {
|
|
20
34
|
origin,
|
|
21
35
|
message,
|
|
22
36
|
stack,
|
|
23
|
-
|
|
37
|
+
codeFrames,
|
|
24
38
|
hints,
|
|
25
|
-
filePath,
|
|
26
|
-
language,
|
|
27
39
|
skipFormatting,
|
|
40
|
+
documentationURL,
|
|
28
41
|
} = diagnostic;
|
|
29
42
|
|
|
30
43
|
let result = {
|
|
31
44
|
message:
|
|
32
45
|
mdAnsi(`**${origin ?? 'unknown'}**: `) +
|
|
33
46
|
(skipFormatting ? message : mdAnsi(message)),
|
|
34
|
-
stack:
|
|
47
|
+
stack: '',
|
|
35
48
|
codeframe: '',
|
|
49
|
+
frames: [],
|
|
36
50
|
hints: [],
|
|
51
|
+
documentation: '',
|
|
37
52
|
};
|
|
38
53
|
|
|
39
|
-
if (
|
|
40
|
-
let
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
if (codeFrames != null) {
|
|
55
|
+
for (let codeFrame of codeFrames) {
|
|
56
|
+
let filePath = codeFrame.filePath;
|
|
57
|
+
if (filePath != null && options && !path.isAbsolute(filePath)) {
|
|
58
|
+
filePath = path.join(options.projectRoot, filePath);
|
|
59
|
+
}
|
|
43
60
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
61
|
+
let highlights = codeFrame.codeHighlights;
|
|
62
|
+
let code = codeFrame.code;
|
|
63
|
+
if (code == null && options && filePath != null) {
|
|
64
|
+
code = await options.inputFS.readFile(filePath, 'utf8');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let formattedCodeFrame = '';
|
|
68
|
+
if (code != null) {
|
|
69
|
+
formattedCodeFrame = formatCodeFrame(code, highlights, {
|
|
70
|
+
useColor: true,
|
|
71
|
+
syntaxHighlighting: true,
|
|
72
|
+
language:
|
|
73
|
+
// $FlowFixMe sketchy null checks do not matter here...
|
|
74
|
+
codeFrame.language ||
|
|
75
|
+
(filePath != null ? path.extname(filePath).substr(1) : undefined),
|
|
76
|
+
terminalWidth,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let location;
|
|
81
|
+
if (typeof filePath !== 'string') {
|
|
82
|
+
location = '';
|
|
83
|
+
} else if (highlights.length === 0) {
|
|
84
|
+
location = filePath;
|
|
85
|
+
} else {
|
|
86
|
+
location = `${filePath}:${highlights[0].start.line}:${highlights[0].start.column}`;
|
|
87
|
+
}
|
|
88
|
+
result.codeframe += location ? chalk.gray.underline(location) + '\n' : '';
|
|
89
|
+
result.codeframe += formattedCodeFrame;
|
|
90
|
+
if (codeFrame !== codeFrames[codeFrames.length - 1]) {
|
|
91
|
+
result.codeframe += '\n\n';
|
|
92
|
+
}
|
|
51
93
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
94
|
+
result.frames.push({
|
|
95
|
+
location,
|
|
96
|
+
code: formattedCodeFrame,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (stack != null) {
|
|
102
|
+
result.stack = stack;
|
|
59
103
|
}
|
|
60
104
|
|
|
61
105
|
if (Array.isArray(hints) && hints.length) {
|
|
@@ -64,5 +108,11 @@ export default function prettyDiagnostic(
|
|
|
64
108
|
});
|
|
65
109
|
}
|
|
66
110
|
|
|
111
|
+
if (documentationURL != null) {
|
|
112
|
+
result.documentation = terminalLink('Learn more', documentationURL, {
|
|
113
|
+
fallback: (text, url) => `${text}: ${url}`,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
67
117
|
return result;
|
|
68
118
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
import type {BuildProgressEvent} from '@parcel/types';
|
|
3
|
+
|
|
4
|
+
import path from 'path';
|
|
5
|
+
|
|
6
|
+
export function getProgressMessage(event: BuildProgressEvent): ?string {
|
|
7
|
+
switch (event.phase) {
|
|
8
|
+
case 'transforming':
|
|
9
|
+
return `Building ${path.basename(event.filePath)}...`;
|
|
10
|
+
|
|
11
|
+
case 'bundling':
|
|
12
|
+
return 'Bundling...';
|
|
13
|
+
|
|
14
|
+
case 'packaging':
|
|
15
|
+
return `Packaging ${event.bundle.displayName}...`;
|
|
16
|
+
|
|
17
|
+
case 'optimizing':
|
|
18
|
+
return `Optimizing ${event.bundle.displayName}...`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
// @flow strict-local
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type {FilePath, NamedBundle} from '@parcel/types';
|
|
4
4
|
|
|
5
5
|
import path from 'path';
|
|
6
|
-
import
|
|
6
|
+
import {relativePath} from './path';
|
|
7
7
|
|
|
8
8
|
export function relativeBundlePath(
|
|
9
|
-
from:
|
|
10
|
-
to:
|
|
9
|
+
from: NamedBundle,
|
|
10
|
+
to: NamedBundle,
|
|
11
11
|
opts: {|leadingDotSlash: boolean|} = {leadingDotSlash: true},
|
|
12
|
-
) {
|
|
13
|
-
let
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (opts.leadingDotSlash && p[0] !== '.') {
|
|
17
|
-
p = './' + p;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return p;
|
|
12
|
+
): FilePath {
|
|
13
|
+
let fromPath = path.join(from.target.distDir, from.name);
|
|
14
|
+
let toPath = path.join(to.target.distDir, to.name);
|
|
15
|
+
return relativePath(path.dirname(fromPath), toPath, opts.leadingDotSlash);
|
|
21
16
|
}
|