@parcel/utils 2.2.0 → 2.3.2
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/lib/index.js +35876 -411
- package/lib/index.js.map +1 -0
- package/package.json +27 -14
- package/src/config.js +2 -2
- package/src/glob.js +14 -3
- package/src/index.js +1 -1
- package/lib/DefaultMap.js +0 -56
- package/lib/Deferred.js +0 -34
- package/lib/PromiseQueue.js +0 -124
- package/lib/TapStream.js +0 -41
- package/lib/alternatives.js +0 -134
- package/lib/ansi-html.js +0 -24
- package/lib/blob.js +0 -49
- package/lib/bundle-url.js +0 -43
- package/lib/collection.js +0 -65
- package/lib/config.js +0 -198
- 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/generateBuildMetrics.js +0 -148
- package/lib/generateCertificate.js +0 -149
- package/lib/getCertificate.js +0 -19
- package/lib/getExisting.js +0 -31
- package/lib/getRootDir.js +0 -66
- package/lib/glob.js +0 -110
- package/lib/hash.js +0 -44
- package/lib/http-server.js +0 -102
- package/lib/is-url.js +0 -27
- package/lib/isDirectoryInside.js +0 -24
- package/lib/objectHash.js +0 -34
- package/lib/openInBrowser.js +0 -94
- package/lib/parseCSSImport.js +0 -16
- package/lib/path.js +0 -49
- package/lib/prettifyTime.js +0 -10
- package/lib/prettyDiagnostic.js +0 -139
- package/lib/relativeBundlePath.js +0 -30
- package/lib/relativeUrl.js +0 -32
- package/lib/replaceBundleReferences.js +0 -211
- package/lib/schema.js +0 -391
- package/lib/shared-buffer.js +0 -31
- package/lib/sourcemap.js +0 -147
- package/lib/stream.js +0 -86
- package/lib/throttle.js +0 -16
- package/lib/urlJoin.js +0 -46
package/lib/glob.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isGlob = isGlob;
|
|
7
|
-
exports.isGlobMatch = isGlobMatch;
|
|
8
|
-
exports.globSync = globSync;
|
|
9
|
-
exports.glob = glob;
|
|
10
|
-
|
|
11
|
-
function _isGlob2() {
|
|
12
|
-
const data = _interopRequireDefault(require("is-glob"));
|
|
13
|
-
|
|
14
|
-
_isGlob2 = function () {
|
|
15
|
-
return data;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
return data;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function _fastGlob() {
|
|
22
|
-
const data = _interopRequireDefault(require("fast-glob"));
|
|
23
|
-
|
|
24
|
-
_fastGlob = function () {
|
|
25
|
-
return data;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
return data;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function _micromatch() {
|
|
32
|
-
const data = require("micromatch");
|
|
33
|
-
|
|
34
|
-
_micromatch = function () {
|
|
35
|
-
return data;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
return data;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
var _path = require("./path");
|
|
42
|
-
|
|
43
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
44
|
-
|
|
45
|
-
function isGlob(p) {
|
|
46
|
-
return (0, _isGlob2().default)((0, _path.normalizeSeparators)(p));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function isGlobMatch(filePath, glob) {
|
|
50
|
-
return (0, _micromatch().isMatch)(filePath, (0, _path.normalizeSeparators)(glob));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function globSync(p, fs, options) {
|
|
54
|
-
// $FlowFixMe
|
|
55
|
-
options = { ...options,
|
|
56
|
-
fs: {
|
|
57
|
-
statSync: p => {
|
|
58
|
-
return fs.statSync(p);
|
|
59
|
-
},
|
|
60
|
-
lstatSync: p => {
|
|
61
|
-
// Our FileSystem interface doesn't have lstat support at the moment,
|
|
62
|
-
// but this is fine for our purposes since we follow symlinks by default.
|
|
63
|
-
return fs.statSync(p);
|
|
64
|
-
},
|
|
65
|
-
readdirSync: (p, opts) => {
|
|
66
|
-
return fs.readdirSync(p, opts);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}; // $FlowFixMe
|
|
70
|
-
|
|
71
|
-
return _fastGlob().default.sync((0, _path.normalizeSeparators)(p), options);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function glob(p, fs, options) {
|
|
75
|
-
// $FlowFixMe
|
|
76
|
-
options = { ...options,
|
|
77
|
-
fs: {
|
|
78
|
-
stat: async (p, cb) => {
|
|
79
|
-
try {
|
|
80
|
-
cb(null, await fs.stat(p));
|
|
81
|
-
} catch (err) {
|
|
82
|
-
cb(err);
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
lstat: async (p, cb) => {
|
|
86
|
-
// Our FileSystem interface doesn't have lstat support at the moment,
|
|
87
|
-
// but this is fine for our purposes since we follow symlinks by default.
|
|
88
|
-
try {
|
|
89
|
-
cb(null, await fs.stat(p));
|
|
90
|
-
} catch (err) {
|
|
91
|
-
cb(err);
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
readdir: async (p, opts, cb) => {
|
|
95
|
-
if (typeof opts === 'function') {
|
|
96
|
-
cb = opts;
|
|
97
|
-
opts = null;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
try {
|
|
101
|
-
cb(null, await fs.readdir(p, opts));
|
|
102
|
-
} catch (err) {
|
|
103
|
-
cb(err);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}; // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
|
|
108
|
-
|
|
109
|
-
return (0, _fastGlob().default)((0, _path.normalizeSeparators)(p), options);
|
|
110
|
-
}
|
package/lib/hash.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.hashStream = hashStream;
|
|
7
|
-
exports.hashObject = hashObject;
|
|
8
|
-
exports.hashFile = hashFile;
|
|
9
|
-
|
|
10
|
-
var _collection = require("./collection");
|
|
11
|
-
|
|
12
|
-
function _hash() {
|
|
13
|
-
const data = require("@parcel/hash");
|
|
14
|
-
|
|
15
|
-
_hash = function () {
|
|
16
|
-
return data;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function hashStream(stream) {
|
|
23
|
-
let hash = new (_hash().Hash)();
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
stream.on('error', err => {
|
|
26
|
-
reject(err);
|
|
27
|
-
});
|
|
28
|
-
stream.on('data', chunk => {
|
|
29
|
-
hash.writeBuffer(chunk);
|
|
30
|
-
}).on('end', function () {
|
|
31
|
-
resolve(hash.finish());
|
|
32
|
-
}).on('error', err => {
|
|
33
|
-
reject(err);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function hashObject(obj) {
|
|
39
|
-
return (0, _hash().hashString)(JSON.stringify((0, _collection.objectSortedEntriesDeep)(obj)));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function hashFile(fs, filePath) {
|
|
43
|
-
return hashStream(fs.createReadStream(filePath));
|
|
44
|
-
}
|
package/lib/http-server.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createHTTPServer = createHTTPServer;
|
|
7
|
-
|
|
8
|
-
function _http() {
|
|
9
|
-
const data = _interopRequireDefault(require("http"));
|
|
10
|
-
|
|
11
|
-
_http = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _https() {
|
|
19
|
-
const data = _interopRequireDefault(require("https"));
|
|
20
|
-
|
|
21
|
-
_https = function () {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function _nullthrows() {
|
|
29
|
-
const data = _interopRequireDefault(require("nullthrows"));
|
|
30
|
-
|
|
31
|
-
_nullthrows = function () {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
var _ = require("./");
|
|
39
|
-
|
|
40
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
41
|
-
|
|
42
|
-
// Creates either an http or https server with an awaitable dispose
|
|
43
|
-
// that closes any connections
|
|
44
|
-
async function createHTTPServer(options) {
|
|
45
|
-
let server;
|
|
46
|
-
|
|
47
|
-
if (!options.https) {
|
|
48
|
-
server = _http().default.createServer(options.listener);
|
|
49
|
-
} else if (options.https === true) {
|
|
50
|
-
let {
|
|
51
|
-
cert,
|
|
52
|
-
key
|
|
53
|
-
} = await (0, _.generateCertificate)(options.outputFS, options.cacheDir, options.host);
|
|
54
|
-
server = _https().default.createServer({
|
|
55
|
-
cert,
|
|
56
|
-
key
|
|
57
|
-
}, options.listener);
|
|
58
|
-
} else {
|
|
59
|
-
let {
|
|
60
|
-
cert,
|
|
61
|
-
key
|
|
62
|
-
} = await (0, _.getCertificate)(options.inputFS, options.https);
|
|
63
|
-
server = _https().default.createServer({
|
|
64
|
-
cert,
|
|
65
|
-
key
|
|
66
|
-
}, options.listener);
|
|
67
|
-
} // HTTPServer#close only stops accepting new connections, and does not close existing ones.
|
|
68
|
-
// Before closing, destroy any active connections through their sockets. Additionally, remove sockets when they close:
|
|
69
|
-
// https://stackoverflow.com/questions/18874689/force-close-all-connections-in-a-node-js-http-server
|
|
70
|
-
// https://stackoverflow.com/questions/14626636/how-do-i-shutdown-a-node-js-https-server-immediately/14636625#14636625
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
let sockets = new Set();
|
|
74
|
-
server.on('connection', socket => {
|
|
75
|
-
(0, _nullthrows().default)(sockets).add(socket);
|
|
76
|
-
socket.on('close', () => {
|
|
77
|
-
(0, _nullthrows().default)(sockets).delete(socket);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
return {
|
|
81
|
-
server,
|
|
82
|
-
|
|
83
|
-
stop() {
|
|
84
|
-
return new Promise((resolve, reject) => {
|
|
85
|
-
for (let socket of (0, _nullthrows().default)(sockets)) {
|
|
86
|
-
socket.destroy();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
sockets = new Set();
|
|
90
|
-
server.close(err => {
|
|
91
|
-
if (err != null) {
|
|
92
|
-
reject(err);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
resolve();
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
};
|
|
102
|
-
}
|
package/lib/is-url.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = isURL;
|
|
7
|
-
|
|
8
|
-
function _isUrl() {
|
|
9
|
-
const data = _interopRequireDefault(require("is-url"));
|
|
10
|
-
|
|
11
|
-
_isUrl = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
// Matches anchor (ie: #raptors)
|
|
21
|
-
const ANCHOR_REGEXP = /^#/; // Matches scheme (ie: tel:, mailto:, data:, itms-apps:)
|
|
22
|
-
|
|
23
|
-
const SCHEME_REGEXP = /^[a-z][a-z0-9\-+.]*:/i;
|
|
24
|
-
|
|
25
|
-
function isURL(url) {
|
|
26
|
-
return (0, _isUrl().default)(url) || ANCHOR_REGEXP.test(url) || SCHEME_REGEXP.test(url);
|
|
27
|
-
}
|
package/lib/isDirectoryInside.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = isDirectoryInside;
|
|
7
|
-
|
|
8
|
-
function _path() {
|
|
9
|
-
const data = _interopRequireDefault(require("path"));
|
|
10
|
-
|
|
11
|
-
_path = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
function isDirectoryInside(child, parent) {
|
|
21
|
-
const relative = _path().default.relative(parent, child);
|
|
22
|
-
|
|
23
|
-
return !relative.startsWith('..') && !_path().default.isAbsolute(relative);
|
|
24
|
-
}
|
package/lib/objectHash.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = objectHash;
|
|
7
|
-
|
|
8
|
-
function _crypto() {
|
|
9
|
-
const data = _interopRequireDefault(require("crypto"));
|
|
10
|
-
|
|
11
|
-
_crypto = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
function objectHash(object) {
|
|
21
|
-
let hash = _crypto().default.createHash('md5');
|
|
22
|
-
|
|
23
|
-
for (let key of Object.keys(object).sort()) {
|
|
24
|
-
let val = object[key];
|
|
25
|
-
|
|
26
|
-
if (typeof val === 'object' && val) {
|
|
27
|
-
hash.update(key + objectHash(val));
|
|
28
|
-
} else {
|
|
29
|
-
hash.update(key + val);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return hash.digest('hex');
|
|
34
|
-
}
|
package/lib/openInBrowser.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = openInBrowser;
|
|
7
|
-
|
|
8
|
-
function _open() {
|
|
9
|
-
const data = _interopRequireDefault(require("open"));
|
|
10
|
-
|
|
11
|
-
_open = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _child_process() {
|
|
19
|
-
const data = require("child_process");
|
|
20
|
-
|
|
21
|
-
_child_process = function () {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function _logger() {
|
|
29
|
-
const data = _interopRequireDefault(require("@parcel/logger"));
|
|
30
|
-
|
|
31
|
-
_logger = function () {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
|
-
|
|
40
|
-
// Chrome app name is platform dependent. we should not hard code it.
|
|
41
|
-
// https://github.com/react-native-community/cli/blob/e2be8a905285d9b37512fc78c9755b9635ecf805/packages/cli/src/commands/server/launchDebugger.ts#L28
|
|
42
|
-
function getChromeAppName() {
|
|
43
|
-
switch (process.platform) {
|
|
44
|
-
case 'darwin':
|
|
45
|
-
return 'google chrome';
|
|
46
|
-
|
|
47
|
-
case 'win32':
|
|
48
|
-
return 'chrome';
|
|
49
|
-
|
|
50
|
-
case 'linux':
|
|
51
|
-
if (commandExistsUnixSync('google-chrome')) {
|
|
52
|
-
return 'google-chrome';
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (commandExistsUnixSync('chromium-browser')) {
|
|
56
|
-
return 'chromium-browser';
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return 'chromium';
|
|
60
|
-
|
|
61
|
-
default:
|
|
62
|
-
return 'google-chrome';
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function commandExistsUnixSync(commandName) {
|
|
67
|
-
try {
|
|
68
|
-
const stdout = (0, _child_process().execSync)(`command -v ${commandName} 2>/dev/null` + ` && { echo >&1 '${commandName} found'; exit 0; }`);
|
|
69
|
-
return !!stdout;
|
|
70
|
-
} catch (error) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function getAppName(appName) {
|
|
76
|
-
if (['google', 'chrome'].includes(appName)) {
|
|
77
|
-
return getChromeAppName();
|
|
78
|
-
} else if (['brave', 'Brave'].includes(appName)) {
|
|
79
|
-
return 'Brave Browser';
|
|
80
|
-
} else return appName;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
async function openInBrowser(url, browser) {
|
|
84
|
-
try {
|
|
85
|
-
const options = typeof browser === 'string' && browser.length > 0 ? {
|
|
86
|
-
app: [getAppName(browser)]
|
|
87
|
-
} : undefined;
|
|
88
|
-
await (0, _open().default)(url, options);
|
|
89
|
-
} catch (err) {
|
|
90
|
-
_logger().default.error(`Unexpected error while opening in browser: ${browser}`, '@parcel/utils');
|
|
91
|
-
|
|
92
|
-
_logger().default.error(err, '@parcel/utils');
|
|
93
|
-
}
|
|
94
|
-
}
|
package/lib/parseCSSImport.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = parseCSSImport;
|
|
7
|
-
|
|
8
|
-
function parseCSSImport(url) {
|
|
9
|
-
if (!/^(~|\.\/|\/)/.test(url)) {
|
|
10
|
-
return './' + url;
|
|
11
|
-
} else if (!/^(~\/|\.\/|\/)/.test(url)) {
|
|
12
|
-
return url.substring(1);
|
|
13
|
-
} else {
|
|
14
|
-
return url;
|
|
15
|
-
}
|
|
16
|
-
}
|
package/lib/path.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isAbsolute = isAbsolute;
|
|
7
|
-
exports.normalizeSeparators = normalizeSeparators;
|
|
8
|
-
exports.normalizePath = normalizePath;
|
|
9
|
-
exports.relativePath = relativePath;
|
|
10
|
-
|
|
11
|
-
function _path() {
|
|
12
|
-
const data = _interopRequireDefault(require("path"));
|
|
13
|
-
|
|
14
|
-
_path = function () {
|
|
15
|
-
return data;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
return data;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
-
|
|
23
|
-
const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:){0,1}[\\/]+/;
|
|
24
|
-
const SEPARATOR_REGEX = /[\\]+/g;
|
|
25
|
-
|
|
26
|
-
function isAbsolute(filepath) {
|
|
27
|
-
return ABSOLUTE_PATH_REGEX.test(filepath);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function normalizeSeparators(filePath) {
|
|
31
|
-
return filePath.replace(SEPARATOR_REGEX, '/');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function normalizePath(filePath, leadingDotSlash = true) {
|
|
35
|
-
if (leadingDotSlash && (filePath[0] !== '.' || filePath[1] !== '.' && filePath[1] !== '/' && filePath[1] !== '\\') && !_path().default.isAbsolute(filePath)) {
|
|
36
|
-
return normalizeSeparators('./' + filePath);
|
|
37
|
-
} else {
|
|
38
|
-
return normalizeSeparators(filePath);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function relativePath(from, to, leadingDotSlash = true) {
|
|
43
|
-
// Fast path
|
|
44
|
-
if (to.startsWith(from + '/')) {
|
|
45
|
-
return (leadingDotSlash ? './' : '') + to.slice(from.length + 1);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return normalizePath(_path().default.relative(from, to), leadingDotSlash);
|
|
49
|
-
}
|
package/lib/prettifyTime.js
DELETED
package/lib/prettyDiagnostic.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = prettyDiagnostic;
|
|
7
|
-
|
|
8
|
-
function _codeframe() {
|
|
9
|
-
const data = _interopRequireDefault(require("@parcel/codeframe"));
|
|
10
|
-
|
|
11
|
-
_codeframe = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _markdownAnsi() {
|
|
19
|
-
const data = _interopRequireDefault(require("@parcel/markdown-ansi"));
|
|
20
|
-
|
|
21
|
-
_markdownAnsi = function () {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function _chalk() {
|
|
29
|
-
const data = _interopRequireDefault(require("chalk"));
|
|
30
|
-
|
|
31
|
-
_chalk = function () {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return data;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function _path() {
|
|
39
|
-
const data = _interopRequireDefault(require("path"));
|
|
40
|
-
|
|
41
|
-
_path = function () {
|
|
42
|
-
return data;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function _nullthrows() {
|
|
49
|
-
const data = _interopRequireDefault(require("nullthrows"));
|
|
50
|
-
|
|
51
|
-
_nullthrows = function () {
|
|
52
|
-
return data;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
return data;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function _terminalLink() {
|
|
59
|
-
const data = _interopRequireDefault(require("terminal-link"));
|
|
60
|
-
|
|
61
|
-
_terminalLink = function () {
|
|
62
|
-
return data;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
return data;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
69
|
-
|
|
70
|
-
// $FlowFixMe
|
|
71
|
-
async function prettyDiagnostic(diagnostic, options, terminalWidth) {
|
|
72
|
-
let {
|
|
73
|
-
origin,
|
|
74
|
-
message,
|
|
75
|
-
stack,
|
|
76
|
-
codeFrames,
|
|
77
|
-
hints,
|
|
78
|
-
skipFormatting,
|
|
79
|
-
documentationURL
|
|
80
|
-
} = diagnostic;
|
|
81
|
-
let result = {
|
|
82
|
-
message: (0, _markdownAnsi().default)(`**${origin !== null && origin !== void 0 ? origin : 'unknown'}**: `) + (skipFormatting ? message : (0, _markdownAnsi().default)(message)),
|
|
83
|
-
stack: '',
|
|
84
|
-
codeframe: '',
|
|
85
|
-
hints: [],
|
|
86
|
-
documentation: ''
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
if (codeFrames != null) {
|
|
90
|
-
for (let codeFrame of codeFrames) {
|
|
91
|
-
var _codeFrame$code;
|
|
92
|
-
|
|
93
|
-
let filePath = codeFrame.filePath;
|
|
94
|
-
|
|
95
|
-
if (filePath != null && options && !_path().default.isAbsolute(filePath)) {
|
|
96
|
-
filePath = _path().default.join(options.projectRoot, filePath);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
let highlights = codeFrame.codeHighlights;
|
|
100
|
-
let code = (_codeFrame$code = codeFrame.code) !== null && _codeFrame$code !== void 0 ? _codeFrame$code : options && (await options.inputFS.readFile((0, _nullthrows().default)(filePath), 'utf8'));
|
|
101
|
-
let formattedCodeFrame = '';
|
|
102
|
-
|
|
103
|
-
if (code != null) {
|
|
104
|
-
formattedCodeFrame = (0, _codeframe().default)(code, highlights, {
|
|
105
|
-
useColor: true,
|
|
106
|
-
syntaxHighlighting: true,
|
|
107
|
-
language: // $FlowFixMe sketchy null checks do not matter here...
|
|
108
|
-
codeFrame.language || (filePath != null ? _path().default.extname(filePath).substr(1) : undefined),
|
|
109
|
-
terminalWidth
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
result.codeframe += typeof filePath !== 'string' ? '' : _chalk().default.gray.underline(`${filePath}:${highlights[0].start.line}:${highlights[0].start.column}\n`);
|
|
114
|
-
result.codeframe += formattedCodeFrame;
|
|
115
|
-
|
|
116
|
-
if (codeFrame !== codeFrames[codeFrames.length - 1]) {
|
|
117
|
-
result.codeframe += '\n\n';
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (stack != null) {
|
|
123
|
-
result.stack = stack;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (Array.isArray(hints) && hints.length) {
|
|
127
|
-
result.hints = hints.map(h => {
|
|
128
|
-
return (0, _markdownAnsi().default)(h);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (documentationURL != null) {
|
|
133
|
-
result.documentation = (0, _terminalLink().default)('Learn more', documentationURL, {
|
|
134
|
-
fallback: (text, url) => `${text}: ${url}`
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return result;
|
|
139
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.relativeBundlePath = relativeBundlePath;
|
|
7
|
-
|
|
8
|
-
function _path() {
|
|
9
|
-
const data = _interopRequireDefault(require("path"));
|
|
10
|
-
|
|
11
|
-
_path = function () {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
var _path2 = require("./path");
|
|
19
|
-
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
|
-
function relativeBundlePath(from, to, opts = {
|
|
23
|
-
leadingDotSlash: true
|
|
24
|
-
}) {
|
|
25
|
-
let fromPath = _path().default.join(from.target.distDir, from.name);
|
|
26
|
-
|
|
27
|
-
let toPath = _path().default.join(to.target.distDir, to.name);
|
|
28
|
-
|
|
29
|
-
return (0, _path2.relativePath)(_path().default.dirname(fromPath), toPath, opts.leadingDotSlash);
|
|
30
|
-
}
|