@parcel/utils 2.0.0-beta.1 → 2.0.0-nightly.1002
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 +35850 -337
- package/lib/index.js.map +1 -0
- package/package.json +42 -20
- package/src/DefaultMap.js +1 -1
- package/src/PromiseQueue.js +16 -12
- package/src/alternatives.js +143 -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 +14 -14
- package/src/config.js +93 -53
- package/src/countLines.js +5 -2
- package/src/debounce.js +1 -1
- package/src/dependency-location.js +11 -6
- package/src/generateBuildMetrics.js +5 -5
- package/src/generateCertificate.js +1 -1
- package/src/getCertificate.js +1 -1
- package/src/getExisting.js +1 -4
- package/src/getRootDir.js +1 -2
- package/src/glob.js +36 -5
- package/src/hash.js +34 -0
- package/src/http-server.js +4 -11
- package/src/index.js +47 -20
- package/src/is-url.js +1 -1
- package/src/isDirectoryInside.js +4 -1
- package/src/openInBrowser.js +3 -1
- package/src/path.js +17 -2
- package/src/prettyDiagnostic.js +39 -27
- package/src/relativeBundlePath.js +5 -7
- package/src/replaceBundleReferences.js +50 -34
- package/src/schema.js +96 -42
- package/src/shared-buffer.js +24 -0
- package/src/sourcemap.js +84 -10
- package/src/urlJoin.js +3 -1
- package/test/DefaultMap.test.js +7 -4
- package/test/config.test.js +50 -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 +1 -1
- package/test/replaceBundleReferences.test.js +268 -0
- package/test/sourcemap.test.js +5 -9
- 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 -38
- 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 -109
- 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/escape-markdown.js +0 -15
- package/lib/generateBuildMetrics.js +0 -124
- 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 -69
- package/lib/http-server.js +0 -81
- package/lib/is-url.js +0 -17
- package/lib/isDirectoryInside.js +0 -16
- package/lib/md5.js +0 -40
- package/lib/objectHash.js +0 -26
- package/lib/openInBrowser.js +0 -70
- package/lib/parseCSSImport.js +0 -16
- package/lib/path.js +0 -30
- package/lib/prettifyTime.js +0 -10
- package/lib/prettyDiagnostic.js +0 -75
- package/lib/promisify.js +0 -13
- package/lib/relativeBundlePath.js +0 -18
- package/lib/relativeUrl.js +0 -16
- package/lib/replaceBundleReferences.js +0 -166
- package/lib/resolve.js +0 -108
- package/lib/schema.js +0 -321
- package/lib/serializeObject.js +0 -28
- package/lib/sourcemap.js +0 -58
- package/lib/stream.js +0 -78
- package/lib/throttle.js +0 -16
- package/lib/urlJoin.js +0 -27
- package/src/.babelrc +0 -3
- package/src/escape-markdown.js +0 -10
- package/src/md5.js +0 -49
- package/src/promisify.js +0 -13
- package/src/resolve.js +0 -216
- package/src/serializeObject.js +0 -22
- package/test/escapeMarkdown.test.js +0 -29
package/lib/glob.js
DELETED
|
@@ -1,69 +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
|
-
var _isGlob2 = _interopRequireDefault(require("is-glob"));
|
|
12
|
-
|
|
13
|
-
var _fastGlob = _interopRequireDefault(require("fast-glob"));
|
|
14
|
-
|
|
15
|
-
var _micromatch = require("micromatch");
|
|
16
|
-
|
|
17
|
-
var _path = require("./path");
|
|
18
|
-
|
|
19
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
-
|
|
21
|
-
function isGlob(p) {
|
|
22
|
-
return (0, _isGlob2.default)((0, _path.normalizeSeparators)(p));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function isGlobMatch(filePath, glob) {
|
|
26
|
-
return (0, _micromatch.isMatch)(filePath, (0, _path.normalizeSeparators)(glob));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function globSync(p, options) {
|
|
30
|
-
return _fastGlob.default.sync((0, _path.normalizeSeparators)(p), options);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function glob(p, fs, options) {
|
|
34
|
-
// $FlowFixMe
|
|
35
|
-
options = { ...options,
|
|
36
|
-
fs: {
|
|
37
|
-
stat: async (p, cb) => {
|
|
38
|
-
try {
|
|
39
|
-
cb(null, (await fs.stat(p)));
|
|
40
|
-
} catch (err) {
|
|
41
|
-
cb(err);
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
lstat: async (p, cb) => {
|
|
45
|
-
// Our FileSystem interface doesn't have lstat support at the moment,
|
|
46
|
-
// but this is fine for our purposes since we follow symlinks by default.
|
|
47
|
-
try {
|
|
48
|
-
cb(null, (await fs.stat(p)));
|
|
49
|
-
} catch (err) {
|
|
50
|
-
cb(err);
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
readdir: async (p, opts, cb) => {
|
|
54
|
-
if (typeof opts === 'function') {
|
|
55
|
-
cb = opts;
|
|
56
|
-
opts = null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
cb(null, (await fs.readdir(p, opts)));
|
|
61
|
-
} catch (err) {
|
|
62
|
-
cb(err);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}; // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
|
|
67
|
-
|
|
68
|
-
return (0, _fastGlob.default)((0, _path.normalizeSeparators)(p), options);
|
|
69
|
-
}
|
package/lib/http-server.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createHTTPServer = createHTTPServer;
|
|
7
|
-
|
|
8
|
-
var _http = _interopRequireDefault(require("http"));
|
|
9
|
-
|
|
10
|
-
var _http2 = require("http2");
|
|
11
|
-
|
|
12
|
-
var _nullthrows = _interopRequireDefault(require("nullthrows"));
|
|
13
|
-
|
|
14
|
-
var _ = require("../");
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
// $FlowFixMe Flow does not know of http2's existance
|
|
19
|
-
// Creates either an http or https server with an awaitable dispose
|
|
20
|
-
// that closes any connections
|
|
21
|
-
async function createHTTPServer(options) {
|
|
22
|
-
let server;
|
|
23
|
-
|
|
24
|
-
if (!options.https) {
|
|
25
|
-
server = _http.default.createServer(options.listener);
|
|
26
|
-
} else if (options.https === true) {
|
|
27
|
-
let {
|
|
28
|
-
cert,
|
|
29
|
-
key
|
|
30
|
-
} = await (0, _.generateCertificate)(options.outputFS, options.cacheDir, options.host);
|
|
31
|
-
server = (0, _http2.createSecureServer)({
|
|
32
|
-
cert,
|
|
33
|
-
key,
|
|
34
|
-
allowHTTP1: true
|
|
35
|
-
}, options.listener);
|
|
36
|
-
} else {
|
|
37
|
-
let {
|
|
38
|
-
cert,
|
|
39
|
-
key
|
|
40
|
-
} = await (0, _.getCertificate)(options.inputFS, options.https);
|
|
41
|
-
server = (0, _http2.createSecureServer)({
|
|
42
|
-
cert,
|
|
43
|
-
key,
|
|
44
|
-
allowHTTP1: true
|
|
45
|
-
}, options.listener);
|
|
46
|
-
} // HTTPServer#close only stops accepting new connections, and does not close existing ones.
|
|
47
|
-
// Before closing, destroy any active connections through their sockets. Additionally, remove sockets when they close:
|
|
48
|
-
// https://stackoverflow.com/questions/18874689/force-close-all-connections-in-a-node-js-http-server
|
|
49
|
-
// https://stackoverflow.com/questions/14626636/how-do-i-shutdown-a-node-js-https-server-immediately/14636625#14636625
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
let sockets = new Set();
|
|
53
|
-
server.on('connection', socket => {
|
|
54
|
-
(0, _nullthrows.default)(sockets).add(socket);
|
|
55
|
-
socket.on('close', () => {
|
|
56
|
-
(0, _nullthrows.default)(sockets).delete(socket);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
return {
|
|
60
|
-
server,
|
|
61
|
-
|
|
62
|
-
stop() {
|
|
63
|
-
return new Promise((resolve, reject) => {
|
|
64
|
-
for (let socket of (0, _nullthrows.default)(sockets)) {
|
|
65
|
-
socket.destroy();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
sockets = new Set();
|
|
69
|
-
server.close(err => {
|
|
70
|
-
if (err != null) {
|
|
71
|
-
reject(err);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
resolve();
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
};
|
|
81
|
-
}
|
package/lib/is-url.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = isURL;
|
|
7
|
-
|
|
8
|
-
const _isURL = require('is-url'); // Matches anchor (ie: #raptors)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const ANCHOR_REGEXP = /^#/; // Matches scheme (ie: tel:, mailto:, data:, itms-apps:)
|
|
12
|
-
|
|
13
|
-
const SCHEME_REGEXP = /^[a-z][a-z0-9\-+.]*:/i;
|
|
14
|
-
|
|
15
|
-
function isURL(url) {
|
|
16
|
-
return _isURL(url) || ANCHOR_REGEXP.test(url) || SCHEME_REGEXP.test(url);
|
|
17
|
-
}
|
package/lib/isDirectoryInside.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = isDirectoryInside;
|
|
7
|
-
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
function isDirectoryInside(child, parent) {
|
|
13
|
-
const relative = _path.default.relative(parent, child);
|
|
14
|
-
|
|
15
|
-
return !relative.startsWith('..') && !_path.default.isAbsolute(relative);
|
|
16
|
-
}
|
package/lib/md5.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.md5FromString = md5FromString;
|
|
7
|
-
exports.md5FromReadableStream = md5FromReadableStream;
|
|
8
|
-
exports.md5FromObject = md5FromObject;
|
|
9
|
-
exports.md5FromFilePath = md5FromFilePath;
|
|
10
|
-
|
|
11
|
-
var _crypto = _interopRequireDefault(require("crypto"));
|
|
12
|
-
|
|
13
|
-
var _collection = require("./collection");
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
|
-
function md5FromString(string, encoding = 'hex') {
|
|
18
|
-
return _crypto.default.createHash('md5').update(string).digest(encoding);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function md5FromReadableStream(stream) {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
stream.on('error', err => {
|
|
24
|
-
reject(err);
|
|
25
|
-
});
|
|
26
|
-
stream.pipe(_crypto.default.createHash('md5').setEncoding('hex')).on('finish', function () {
|
|
27
|
-
resolve(this.read());
|
|
28
|
-
}).on('error', err => {
|
|
29
|
-
reject(err);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function md5FromObject(obj, encoding = 'hex') {
|
|
35
|
-
return md5FromString(JSON.stringify((0, _collection.objectSortedEntriesDeep)(obj)), encoding);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function md5FromFilePath(fs, filePath) {
|
|
39
|
-
return md5FromReadableStream(fs.createReadStream(filePath));
|
|
40
|
-
}
|
package/lib/objectHash.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = objectHash;
|
|
7
|
-
|
|
8
|
-
var _crypto = _interopRequireDefault(require("crypto"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
function objectHash(object) {
|
|
13
|
-
let hash = _crypto.default.createHash('md5');
|
|
14
|
-
|
|
15
|
-
for (let key of Object.keys(object).sort()) {
|
|
16
|
-
let val = object[key];
|
|
17
|
-
|
|
18
|
-
if (typeof val === 'object' && val) {
|
|
19
|
-
hash.update(key + objectHash(val));
|
|
20
|
-
} else {
|
|
21
|
-
hash.update(key + val);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return hash.digest('hex');
|
|
26
|
-
}
|
package/lib/openInBrowser.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = openInBrowser;
|
|
7
|
-
|
|
8
|
-
var _open = _interopRequireDefault(require("open"));
|
|
9
|
-
|
|
10
|
-
var _child_process = require("child_process");
|
|
11
|
-
|
|
12
|
-
var _logger = _interopRequireDefault(require("@parcel/logger"));
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
// Chrome app name is platform dependent. we should not hard code it.
|
|
17
|
-
// https://github.com/react-native-community/cli/blob/e2be8a905285d9b37512fc78c9755b9635ecf805/packages/cli/src/commands/server/launchDebugger.ts#L28
|
|
18
|
-
function getChromeAppName() {
|
|
19
|
-
switch (process.platform) {
|
|
20
|
-
case 'darwin':
|
|
21
|
-
return 'google chrome';
|
|
22
|
-
|
|
23
|
-
case 'win32':
|
|
24
|
-
return 'chrome';
|
|
25
|
-
|
|
26
|
-
case 'linux':
|
|
27
|
-
if (commandExistsUnixSync('google-chrome')) {
|
|
28
|
-
return 'google-chrome';
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (commandExistsUnixSync('chromium-browser')) {
|
|
32
|
-
return 'chromium-browser';
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return 'chromium';
|
|
36
|
-
|
|
37
|
-
default:
|
|
38
|
-
return 'google-chrome';
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function commandExistsUnixSync(commandName) {
|
|
43
|
-
try {
|
|
44
|
-
const stdout = (0, _child_process.execSync)(`command -v ${commandName} 2>/dev/null` + ` && { echo >&1 '${commandName} found'; exit 0; }`);
|
|
45
|
-
return !!stdout;
|
|
46
|
-
} catch (error) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function getAppName(appName) {
|
|
52
|
-
if (['google', 'chrome'].includes(appName)) {
|
|
53
|
-
return getChromeAppName();
|
|
54
|
-
} else if (['brave', 'Brave'].includes(appName)) {
|
|
55
|
-
return 'Brave Browser';
|
|
56
|
-
} else return appName;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function openInBrowser(url, browser) {
|
|
60
|
-
try {
|
|
61
|
-
const options = typeof browser === 'string' ? {
|
|
62
|
-
app: [getAppName(browser)]
|
|
63
|
-
} : undefined;
|
|
64
|
-
await (0, _open.default)(url, options);
|
|
65
|
-
} catch (err) {
|
|
66
|
-
_logger.default.error(`Unexpected error while opening in browser: ${browser}`, '@parcel/utils');
|
|
67
|
-
|
|
68
|
-
_logger.default.error(err, '@parcel/utils');
|
|
69
|
-
}
|
|
70
|
-
}
|
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,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.normalizeSeparators = normalizeSeparators;
|
|
7
|
-
exports.normalizePath = normalizePath;
|
|
8
|
-
exports.relativePath = relativePath;
|
|
9
|
-
|
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
const SEPARATOR_REGEX = /[\\]+/g;
|
|
15
|
-
|
|
16
|
-
function normalizeSeparators(filePath) {
|
|
17
|
-
return filePath.replace(SEPARATOR_REGEX, '/');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function normalizePath(filePath, leadingDotSlash = true) {
|
|
21
|
-
if (leadingDotSlash && filePath[0] !== '.' && filePath[0] !== '/') {
|
|
22
|
-
return normalizeSeparators('./' + filePath);
|
|
23
|
-
} else {
|
|
24
|
-
return normalizeSeparators(filePath);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function relativePath(from, to, leadingDotSlash = true) {
|
|
29
|
-
return normalizePath(_path.default.relative(from, to), leadingDotSlash);
|
|
30
|
-
}
|
package/lib/prettifyTime.js
DELETED
package/lib/prettyDiagnostic.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = prettyDiagnostic;
|
|
7
|
-
|
|
8
|
-
var _codeframe = _interopRequireDefault(require("@parcel/codeframe"));
|
|
9
|
-
|
|
10
|
-
var _markdownAnsi = _interopRequireDefault(require("@parcel/markdown-ansi"));
|
|
11
|
-
|
|
12
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
13
|
-
|
|
14
|
-
var _path = _interopRequireDefault(require("path"));
|
|
15
|
-
|
|
16
|
-
var _nullthrows = _interopRequireDefault(require("nullthrows"));
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
async function prettyDiagnostic(diagnostic, options, terminalWidth) {
|
|
21
|
-
let {
|
|
22
|
-
origin,
|
|
23
|
-
message,
|
|
24
|
-
stack,
|
|
25
|
-
codeFrame,
|
|
26
|
-
hints,
|
|
27
|
-
filePath,
|
|
28
|
-
language,
|
|
29
|
-
skipFormatting
|
|
30
|
-
} = diagnostic;
|
|
31
|
-
|
|
32
|
-
if (filePath != null && options && !_path.default.isAbsolute(filePath)) {
|
|
33
|
-
filePath = _path.default.join(options.projectRoot, filePath);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let result = {
|
|
37
|
-
message: (0, _markdownAnsi.default)(`**${origin !== null && origin !== void 0 ? origin : 'unknown'}**: `) + (skipFormatting ? message : (0, _markdownAnsi.default)(message)),
|
|
38
|
-
stack: '',
|
|
39
|
-
codeframe: '',
|
|
40
|
-
hints: []
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
if (codeFrame !== undefined) {
|
|
44
|
-
var _codeFrame$code;
|
|
45
|
-
|
|
46
|
-
let highlights = Array.isArray(codeFrame.codeHighlights) ? codeFrame.codeHighlights : [codeFrame.codeHighlights];
|
|
47
|
-
let code = (_codeFrame$code = codeFrame.code) !== null && _codeFrame$code !== void 0 ? _codeFrame$code : options && (await options.inputFS.readFile((0, _nullthrows.default)(filePath), 'utf8'));
|
|
48
|
-
|
|
49
|
-
if (code != null) {
|
|
50
|
-
let formattedCodeFrame = (0, _codeframe.default)(code, highlights, {
|
|
51
|
-
useColor: true,
|
|
52
|
-
syntaxHighlighting: true,
|
|
53
|
-
language: // $FlowFixMe sketchy null checks do not matter here...
|
|
54
|
-
language || (filePath ? _path.default.extname(filePath).substr(1) : undefined),
|
|
55
|
-
terminalWidth
|
|
56
|
-
});
|
|
57
|
-
result.codeframe += typeof filePath !== 'string' ? '' : _chalk.default.underline(`${filePath}:${highlights[0].start.line}:${highlights[0].start.column}\n`);
|
|
58
|
-
result.codeframe += formattedCodeFrame;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (stack != null) {
|
|
63
|
-
result.stack = stack;
|
|
64
|
-
} else if (filePath != null && result.codeframe == null) {
|
|
65
|
-
result.stack = filePath;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (Array.isArray(hints) && hints.length) {
|
|
69
|
-
result.hints = hints.map(h => {
|
|
70
|
-
return (0, _markdownAnsi.default)(h);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return result;
|
|
75
|
-
}
|
package/lib/promisify.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
module.exports = function (fn) {
|
|
4
|
-
return function (...args) {
|
|
5
|
-
return new Promise(function (resolve, reject) {
|
|
6
|
-
fn(...args, function (err, ...res) {
|
|
7
|
-
if (err) return reject(err);
|
|
8
|
-
if (res.length === 1) return resolve(res[0]);
|
|
9
|
-
resolve(res);
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.relativeBundlePath = relativeBundlePath;
|
|
7
|
-
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
|
-
var _path2 = require("./path");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
function relativeBundlePath(from, to, opts = {
|
|
15
|
-
leadingDotSlash: true
|
|
16
|
-
}) {
|
|
17
|
-
return (0, _path2.relativePath)(_path.default.dirname(from.filePath), to.filePath, opts.leadingDotSlash);
|
|
18
|
-
}
|
package/lib/relativeUrl.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = relativeUrl;
|
|
7
|
-
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
|
-
var _url = _interopRequireDefault(require("url"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
function relativeUrl(from, to) {
|
|
15
|
-
return _url.default.format(_url.default.parse(_path.default.relative(from, to)));
|
|
16
|
-
}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.replaceURLReferences = replaceURLReferences;
|
|
7
|
-
exports.replaceInlineReferences = replaceInlineReferences;
|
|
8
|
-
|
|
9
|
-
var _assert = _interopRequireDefault(require("assert"));
|
|
10
|
-
|
|
11
|
-
var _stream = require("stream");
|
|
12
|
-
|
|
13
|
-
var _nullthrows = _interopRequireDefault(require("nullthrows"));
|
|
14
|
-
|
|
15
|
-
var _url = _interopRequireDefault(require("url"));
|
|
16
|
-
|
|
17
|
-
var _ = require("../");
|
|
18
|
-
|
|
19
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
-
|
|
21
|
-
/*
|
|
22
|
-
* Replaces references to dependency ids for URL dependencies with:
|
|
23
|
-
* - in the case of an unresolvable url dependency, the original moduleSpecifier.
|
|
24
|
-
* These are external requests that Parcel did not bundle.
|
|
25
|
-
* - in the case of a reference to another bundle, the relative url to that
|
|
26
|
-
* bundle from the current bundle.
|
|
27
|
-
*/
|
|
28
|
-
function replaceURLReferences({
|
|
29
|
-
bundle,
|
|
30
|
-
bundleGraph,
|
|
31
|
-
contents,
|
|
32
|
-
map,
|
|
33
|
-
relative = true
|
|
34
|
-
}) {
|
|
35
|
-
let replacements = new Map();
|
|
36
|
-
let urlDependencies = [];
|
|
37
|
-
bundle.traverse(node => {
|
|
38
|
-
if (node.type === 'dependency' && node.value.isURL) {
|
|
39
|
-
urlDependencies.push(node.value);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
for (let dependency of urlDependencies) {
|
|
44
|
-
if (!dependency.isURL) {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
let resolved = bundleGraph.resolveExternalDependency(dependency, bundle);
|
|
49
|
-
|
|
50
|
-
if (resolved == null) {
|
|
51
|
-
replacements.set(dependency.id, {
|
|
52
|
-
from: dependency.id,
|
|
53
|
-
to: dependency.moduleSpecifier
|
|
54
|
-
});
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
(0, _assert.default)(resolved.type === 'bundle_group');
|
|
59
|
-
let entryBundle = bundleGraph.getBundlesInBundleGroup(resolved.value).pop();
|
|
60
|
-
|
|
61
|
-
if (entryBundle.isInline) {
|
|
62
|
-
// If a bundle is inline, it should be replaced with inline contents,
|
|
63
|
-
// not a URL.
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
replacements.set(dependency.id, getURLReplacement({
|
|
68
|
-
dependency,
|
|
69
|
-
fromBundle: bundle,
|
|
70
|
-
toBundle: entryBundle,
|
|
71
|
-
relative
|
|
72
|
-
}));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return performReplacement(replacements, contents, map);
|
|
76
|
-
}
|
|
77
|
-
/*
|
|
78
|
-
* Replaces references to dependency ids for inline bundles with the packaged
|
|
79
|
-
* contents of that bundle.
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
async function replaceInlineReferences({
|
|
84
|
-
bundle,
|
|
85
|
-
bundleGraph,
|
|
86
|
-
contents,
|
|
87
|
-
map,
|
|
88
|
-
getInlineReplacement,
|
|
89
|
-
getInlineBundleContents
|
|
90
|
-
}) {
|
|
91
|
-
let replacements = new Map();
|
|
92
|
-
let dependencies = [];
|
|
93
|
-
bundle.traverse(node => {
|
|
94
|
-
if (node.type === 'dependency') {
|
|
95
|
-
dependencies.push(node.value);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
for (let dependency of dependencies) {
|
|
100
|
-
let resolved = bundleGraph.resolveExternalDependency(dependency, bundle);
|
|
101
|
-
|
|
102
|
-
if (resolved == null || resolved.type === 'asset') {
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
let [entryBundle] = bundleGraph.getBundlesInBundleGroup(resolved.value);
|
|
107
|
-
|
|
108
|
-
if (!entryBundle.isInline) {
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
let packagedBundle = await getInlineBundleContents(entryBundle, bundleGraph);
|
|
113
|
-
let packagedContents = (packagedBundle.contents instanceof _stream.Readable ? await (0, _.bufferStream)(packagedBundle.contents) : packagedBundle.contents).toString();
|
|
114
|
-
let inlineType = (0, _nullthrows.default)(entryBundle.getMainEntry()).meta.inlineType;
|
|
115
|
-
|
|
116
|
-
if (inlineType == null || inlineType === 'string') {
|
|
117
|
-
replacements.set(dependency.id, getInlineReplacement(dependency, inlineType, packagedContents));
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return performReplacement(replacements, contents, map);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function getURLReplacement({
|
|
125
|
-
dependency,
|
|
126
|
-
fromBundle,
|
|
127
|
-
toBundle,
|
|
128
|
-
relative
|
|
129
|
-
}) {
|
|
130
|
-
let url = _url.default.parse(dependency.moduleSpecifier);
|
|
131
|
-
|
|
132
|
-
let to;
|
|
133
|
-
|
|
134
|
-
if (relative) {
|
|
135
|
-
url.pathname = (0, _.relativeBundlePath)(fromBundle, toBundle, {
|
|
136
|
-
leadingDotSlash: false
|
|
137
|
-
});
|
|
138
|
-
to = _url.default.format(url);
|
|
139
|
-
} else {
|
|
140
|
-
url.pathname = (0, _nullthrows.default)(toBundle.name);
|
|
141
|
-
to = (0, _.urlJoin)(toBundle.target.publicUrl, _url.default.format(url));
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
from: dependency.id,
|
|
146
|
-
to
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function performReplacement(replacements, contents, map) {
|
|
151
|
-
let finalContents = contents;
|
|
152
|
-
|
|
153
|
-
for (let {
|
|
154
|
-
from,
|
|
155
|
-
to
|
|
156
|
-
} of replacements.values()) {
|
|
157
|
-
// Perform replacement
|
|
158
|
-
finalContents = finalContents.split(from).join(to);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return {
|
|
162
|
-
contents: finalContents,
|
|
163
|
-
// TODO: Update sourcemap with adjusted contents
|
|
164
|
-
map
|
|
165
|
-
};
|
|
166
|
-
}
|