@atlaspack/utils 2.15.4-typescript-9a5730863.0 → 2.16.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 +11 -0
- package/lib/index.js +37333 -465
- package/lib/index.js.map +1 -0
- package/package.json +9 -10
- package/LICENSE +0 -201
- package/lib/DefaultMap.js +0 -46
- package/lib/Deferred.js +0 -30
- package/lib/PromiseQueue.js +0 -112
- package/lib/TapStream.js +0 -34
- package/lib/alternatives.js +0 -116
- package/lib/ansi-html.js +0 -18
- package/lib/blob.js +0 -40
- package/lib/bundle-url.js +0 -34
- package/lib/collection.js +0 -111
- package/lib/config.js +0 -172
- package/lib/countLines.js +0 -15
- package/lib/debounce.js +0 -18
- package/lib/debug-tools.js +0 -36
- package/lib/dependency-location.js +0 -21
- package/lib/escape-html.js +0 -22
- package/lib/generateBuildMetrics.js +0 -121
- package/lib/generateCertificate.js +0 -129
- package/lib/getCertificate.js +0 -18
- package/lib/getExisting.js +0 -25
- package/lib/getModuleParts.js +0 -30
- package/lib/getRootDir.js +0 -52
- package/lib/glob.js +0 -110
- package/lib/hash.js +0 -50
- package/lib/http-server.js +0 -85
- package/lib/is-url.js +0 -22
- package/lib/isDirectoryInside.js +0 -18
- package/lib/objectHash.js +0 -27
- package/lib/openInBrowser.js +0 -74
- package/lib/parseCSSImport.js +0 -15
- package/lib/path.js +0 -39
- package/lib/prettifyTime.js +0 -9
- package/lib/prettyDiagnostic.js +0 -136
- package/lib/progress-message.js +0 -27
- package/lib/relativeBundlePath.js +0 -22
- package/lib/relativeUrl.js +0 -24
- package/lib/replaceBundleReferences.js +0 -199
- package/lib/schema.js +0 -336
- package/lib/shared-buffer.js +0 -27
- package/lib/sourcemap.js +0 -127
- package/lib/stream.js +0 -76
- package/lib/throttle.js +0 -15
- package/lib/urlJoin.js +0 -35
package/lib/getModuleParts.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = getModuleParts;
|
|
7
|
-
function _path() {
|
|
8
|
-
const data = _interopRequireDefault(require("path"));
|
|
9
|
-
_path = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
var _path2 = require("./path");
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
/**
|
|
17
|
-
* Returns the package name and the optional subpath
|
|
18
|
-
*/
|
|
19
|
-
function getModuleParts(_name) {
|
|
20
|
-
let name = _path().default.normalize(_name);
|
|
21
|
-
let splitOn = name.indexOf(_path().default.sep);
|
|
22
|
-
if (name.charAt(0) === '@') {
|
|
23
|
-
splitOn = name.indexOf(_path().default.sep, splitOn + 1);
|
|
24
|
-
}
|
|
25
|
-
if (splitOn < 0) {
|
|
26
|
-
return [(0, _path2.normalizeSeparators)(name), undefined];
|
|
27
|
-
} else {
|
|
28
|
-
return [(0, _path2.normalizeSeparators)(name.substring(0, splitOn)), name.substring(splitOn + 1) || undefined];
|
|
29
|
-
}
|
|
30
|
-
}
|
package/lib/getRootDir.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = getRootDir;
|
|
7
|
-
var _glob = require("./glob");
|
|
8
|
-
function _path() {
|
|
9
|
-
const data = _interopRequireDefault(require("path"));
|
|
10
|
-
_path = function () {
|
|
11
|
-
return data;
|
|
12
|
-
};
|
|
13
|
-
return data;
|
|
14
|
-
}
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
function getRootDir(files) {
|
|
17
|
-
let cur = null;
|
|
18
|
-
for (let file of files) {
|
|
19
|
-
let parsed = _path().default.parse(file);
|
|
20
|
-
parsed.dir = findGlobRoot(parsed.dir);
|
|
21
|
-
if (!cur) {
|
|
22
|
-
cur = parsed;
|
|
23
|
-
} else if (parsed.root !== cur.root) {
|
|
24
|
-
// bail out. there is no common root.
|
|
25
|
-
// this can happen on windows, e.g. C:\foo\bar vs. D:\foo\bar
|
|
26
|
-
return process.cwd();
|
|
27
|
-
} else {
|
|
28
|
-
// find the common path parts.
|
|
29
|
-
let curParts = cur.dir.split(_path().default.sep);
|
|
30
|
-
let newParts = parsed.dir.split(_path().default.sep);
|
|
31
|
-
let len = Math.min(curParts.length, newParts.length);
|
|
32
|
-
let i = 0;
|
|
33
|
-
while (i < len && curParts[i] === newParts[i]) {
|
|
34
|
-
i++;
|
|
35
|
-
}
|
|
36
|
-
cur.dir = i > 1 ? curParts.slice(0, i).join(_path().default.sep) : cur.root;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return cur ? cur.dir : process.cwd();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Transforms a path like `packages/*/src/index.js` to the root of the glob, `packages/`
|
|
43
|
-
function findGlobRoot(dir) {
|
|
44
|
-
let parts = dir.split(_path().default.sep);
|
|
45
|
-
let last = parts.length;
|
|
46
|
-
for (let i = parts.length - 1; i >= 0; i--) {
|
|
47
|
-
if ((0, _glob.isGlob)(parts[i])) {
|
|
48
|
-
last = i;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return parts.slice(0, last).join(_path().default.sep);
|
|
52
|
-
}
|
package/lib/glob.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.glob = glob;
|
|
7
|
-
exports.globMatch = globMatch;
|
|
8
|
-
exports.globSync = globSync;
|
|
9
|
-
exports.globToRegex = globToRegex;
|
|
10
|
-
exports.isGlob = isGlob;
|
|
11
|
-
exports.isGlobMatch = isGlobMatch;
|
|
12
|
-
function _isGlob2() {
|
|
13
|
-
const data = _interopRequireDefault(require("is-glob"));
|
|
14
|
-
_isGlob2 = function () {
|
|
15
|
-
return data;
|
|
16
|
-
};
|
|
17
|
-
return data;
|
|
18
|
-
}
|
|
19
|
-
function _fastGlob() {
|
|
20
|
-
const data = _interopRequireDefault(require("fast-glob"));
|
|
21
|
-
_fastGlob = function () {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
return data;
|
|
25
|
-
}
|
|
26
|
-
function _micromatch() {
|
|
27
|
-
const data = _interopRequireWildcard(require("micromatch"));
|
|
28
|
-
_micromatch = function () {
|
|
29
|
-
return data;
|
|
30
|
-
};
|
|
31
|
-
return data;
|
|
32
|
-
}
|
|
33
|
-
var _path = require("./path");
|
|
34
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
35
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
36
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
37
|
-
function isGlob(p) {
|
|
38
|
-
return (0, _isGlob2().default)((0, _path.normalizeSeparators)(p));
|
|
39
|
-
}
|
|
40
|
-
function isGlobMatch(filePath, glob, opts) {
|
|
41
|
-
glob = Array.isArray(glob) ? glob.map(_path.normalizeSeparators) : (0, _path.normalizeSeparators)(glob);
|
|
42
|
-
return (0, _micromatch().isMatch)(filePath, glob, opts);
|
|
43
|
-
}
|
|
44
|
-
function globMatch(values, glob, opts) {
|
|
45
|
-
glob = Array.isArray(glob) ? glob.map(_path.normalizeSeparators) : (0, _path.normalizeSeparators)(glob);
|
|
46
|
-
return (0, _micromatch().default)(values, glob, opts);
|
|
47
|
-
}
|
|
48
|
-
function globToRegex(glob, opts) {
|
|
49
|
-
return (0, _micromatch().makeRe)(glob, opts);
|
|
50
|
-
}
|
|
51
|
-
function globSync(p, fs, options) {
|
|
52
|
-
// $FlowFixMe
|
|
53
|
-
options = {
|
|
54
|
-
...options,
|
|
55
|
-
fs: {
|
|
56
|
-
statSync: p => {
|
|
57
|
-
return fs.statSync(p);
|
|
58
|
-
},
|
|
59
|
-
lstatSync: p => {
|
|
60
|
-
// Our FileSystem interface doesn't have lstat support at the moment,
|
|
61
|
-
// but this is fine for our purposes since we follow symlinks by default.
|
|
62
|
-
return fs.statSync(p);
|
|
63
|
-
},
|
|
64
|
-
readdirSync: (p, opts) => {
|
|
65
|
-
return fs.readdirSync(p, opts);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// $FlowFixMe
|
|
71
|
-
return _fastGlob().default.sync((0, _path.normalizeSeparators)(p), options);
|
|
72
|
-
}
|
|
73
|
-
function glob(p, fs, options) {
|
|
74
|
-
// $FlowFixMe
|
|
75
|
-
options = {
|
|
76
|
-
...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
|
-
try {
|
|
100
|
-
cb(null, await fs.readdir(p, opts));
|
|
101
|
-
} catch (err) {
|
|
102
|
-
cb(err);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
// $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
|
|
109
|
-
return (0, _fastGlob().default)((0, _path.normalizeSeparators)(p), options);
|
|
110
|
-
}
|
package/lib/hash.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.hashFile = hashFile;
|
|
7
|
-
exports.hashObject = hashObject;
|
|
8
|
-
exports.hashStream = hashStream;
|
|
9
|
-
var _collection = require("./collection");
|
|
10
|
-
function _rust() {
|
|
11
|
-
const data = require("@atlaspack/rust");
|
|
12
|
-
_rust = function () {
|
|
13
|
-
return data;
|
|
14
|
-
};
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
function hashStream(stream) {
|
|
18
|
-
let hash = new (_rust().Hash)();
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
stream.on('error', err => {
|
|
21
|
-
reject(err);
|
|
22
|
-
});
|
|
23
|
-
stream.on('data', chunk => {
|
|
24
|
-
hash.writeBuffer(chunk);
|
|
25
|
-
}).on('end', function () {
|
|
26
|
-
resolve(hash.finish());
|
|
27
|
-
}).on('error', err => {
|
|
28
|
-
reject(err);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
function hashObject(obj) {
|
|
33
|
-
return (0, _rust().hashString)(JSON.stringify((0, _collection.objectSortedEntriesDeep)(obj)));
|
|
34
|
-
}
|
|
35
|
-
let testCache = {
|
|
36
|
-
/*:: ...null */
|
|
37
|
-
};
|
|
38
|
-
function hashFile(fs, filePath) {
|
|
39
|
-
if (process.env.ATLASPACK_BUILD_ENV === 'test') {
|
|
40
|
-
// Development builds of these native modules are especially big and slow to hash.
|
|
41
|
-
if (/parcel-swc\.[^\\/]+\.node$|lightningcss.[^\\/]+.node$/.test(filePath)) {
|
|
42
|
-
let cacheEntry = testCache[filePath];
|
|
43
|
-
if (cacheEntry) return cacheEntry;
|
|
44
|
-
let v = hashStream(fs.createReadStream(filePath));
|
|
45
|
-
testCache[filePath] = v;
|
|
46
|
-
return v;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return hashStream(fs.createReadStream(filePath));
|
|
50
|
-
}
|
package/lib/http-server.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createHTTPServer = createHTTPServer;
|
|
7
|
-
function _http() {
|
|
8
|
-
const data = _interopRequireDefault(require("http"));
|
|
9
|
-
_http = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _https() {
|
|
15
|
-
const data = _interopRequireDefault(require("https"));
|
|
16
|
-
_https = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _nullthrows() {
|
|
22
|
-
const data = _interopRequireDefault(require("nullthrows"));
|
|
23
|
-
_nullthrows = function () {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
var _ = require("./");
|
|
29
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
|
-
// Creates either an http or https server with an awaitable dispose
|
|
31
|
-
// that closes any connections
|
|
32
|
-
async function createHTTPServer(options) {
|
|
33
|
-
let server;
|
|
34
|
-
if (!options.https) {
|
|
35
|
-
server = _http().default.createServer(options.listener);
|
|
36
|
-
} else if (options.https === true) {
|
|
37
|
-
let {
|
|
38
|
-
cert,
|
|
39
|
-
key
|
|
40
|
-
} = await (0, _.generateCertificate)(options.outputFS, options.cacheDir, options.host);
|
|
41
|
-
server = _https().default.createServer({
|
|
42
|
-
cert,
|
|
43
|
-
key
|
|
44
|
-
}, options.listener);
|
|
45
|
-
} else {
|
|
46
|
-
let {
|
|
47
|
-
cert,
|
|
48
|
-
key
|
|
49
|
-
} = await (0, _.getCertificate)(options.inputFS, options.https);
|
|
50
|
-
server = _https().default.createServer({
|
|
51
|
-
cert,
|
|
52
|
-
key
|
|
53
|
-
}, options.listener);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// HTTPServer#close only stops accepting new connections, and does not close existing ones.
|
|
57
|
-
// Before closing, destroy any active connections through their sockets. Additionally, remove sockets when they close:
|
|
58
|
-
// https://stackoverflow.com/questions/18874689/force-close-all-connections-in-a-node-js-http-server
|
|
59
|
-
// https://stackoverflow.com/questions/14626636/how-do-i-shutdown-a-node-js-https-server-immediately/14636625#14636625
|
|
60
|
-
let sockets = new Set();
|
|
61
|
-
server.on('connection', socket => {
|
|
62
|
-
(0, _nullthrows().default)(sockets).add(socket);
|
|
63
|
-
socket.on('close', () => {
|
|
64
|
-
(0, _nullthrows().default)(sockets).delete(socket);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
return {
|
|
68
|
-
server,
|
|
69
|
-
stop() {
|
|
70
|
-
return new Promise((resolve, reject) => {
|
|
71
|
-
for (let socket of (0, _nullthrows().default)(sockets)) {
|
|
72
|
-
socket.destroy();
|
|
73
|
-
}
|
|
74
|
-
sockets = new Set();
|
|
75
|
-
server.close(err => {
|
|
76
|
-
if (err != null) {
|
|
77
|
-
reject(err);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
resolve();
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
}
|
package/lib/is-url.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = isURL;
|
|
7
|
-
function _isUrl() {
|
|
8
|
-
const data = _interopRequireDefault(require("is-url"));
|
|
9
|
-
_isUrl = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
// Matches anchor (ie: #raptors)
|
|
16
|
-
const ANCHOR_REGEXP = /^#/;
|
|
17
|
-
|
|
18
|
-
// Matches scheme (ie: tel:, mailto:, data:, itms-apps:)
|
|
19
|
-
const SCHEME_REGEXP = /^[a-z][a-z0-9\-+.]*:/i;
|
|
20
|
-
function isURL(url) {
|
|
21
|
-
return (0, _isUrl().default)(url) || ANCHOR_REGEXP.test(url) || SCHEME_REGEXP.test(url);
|
|
22
|
-
}
|
package/lib/isDirectoryInside.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = isDirectoryInside;
|
|
7
|
-
function _path() {
|
|
8
|
-
const data = _interopRequireDefault(require("path"));
|
|
9
|
-
_path = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
function isDirectoryInside(child, parent) {
|
|
16
|
-
const relative = _path().default.relative(parent, child);
|
|
17
|
-
return !relative.startsWith('..') && !_path().default.isAbsolute(relative);
|
|
18
|
-
}
|
package/lib/objectHash.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = objectHash;
|
|
7
|
-
function _crypto() {
|
|
8
|
-
const data = _interopRequireDefault(require("crypto"));
|
|
9
|
-
_crypto = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
// $FlowFixMe
|
|
16
|
-
function objectHash(object) {
|
|
17
|
-
let hash = _crypto().default.createHash('md5');
|
|
18
|
-
for (let key of Object.keys(object).sort()) {
|
|
19
|
-
let val = object[key];
|
|
20
|
-
if (typeof val === 'object' && val) {
|
|
21
|
-
hash.update(key + objectHash(val));
|
|
22
|
-
} else {
|
|
23
|
-
hash.update(key + val);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return hash.digest('hex');
|
|
27
|
-
}
|
package/lib/openInBrowser.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = openInBrowser;
|
|
7
|
-
function _open() {
|
|
8
|
-
const data = _interopRequireDefault(require("open"));
|
|
9
|
-
_open = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _child_process() {
|
|
15
|
-
const data = require("child_process");
|
|
16
|
-
_child_process = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _logger() {
|
|
22
|
-
const data = _interopRequireDefault(require("@atlaspack/logger"));
|
|
23
|
-
_logger = function () {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
-
// Chrome app name is platform dependent. we should not hard code it.
|
|
30
|
-
// https://github.com/react-native-community/cli/blob/e2be8a905285d9b37512fc78c9755b9635ecf805/packages/cli/src/commands/server/launchDebugger.ts#L28
|
|
31
|
-
function getChromeAppName() {
|
|
32
|
-
switch (process.platform) {
|
|
33
|
-
case 'darwin':
|
|
34
|
-
return 'google chrome';
|
|
35
|
-
case 'win32':
|
|
36
|
-
return 'chrome';
|
|
37
|
-
case 'linux':
|
|
38
|
-
if (commandExistsUnixSync('google-chrome')) {
|
|
39
|
-
return 'google-chrome';
|
|
40
|
-
}
|
|
41
|
-
if (commandExistsUnixSync('chromium-browser')) {
|
|
42
|
-
return 'chromium-browser';
|
|
43
|
-
}
|
|
44
|
-
return 'chromium';
|
|
45
|
-
default:
|
|
46
|
-
return 'google-chrome';
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function commandExistsUnixSync(commandName) {
|
|
50
|
-
try {
|
|
51
|
-
const stdout = (0, _child_process().execSync)(`command -v ${commandName} 2>/dev/null` + ` && { echo >&1 '${commandName} found'; exit 0; }`);
|
|
52
|
-
return !!stdout;
|
|
53
|
-
} catch (error) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
function getAppName(appName) {
|
|
58
|
-
if (['google', 'chrome'].includes(appName)) {
|
|
59
|
-
return getChromeAppName();
|
|
60
|
-
} else if (['brave', 'Brave'].includes(appName)) {
|
|
61
|
-
return 'Brave Browser';
|
|
62
|
-
} else return appName;
|
|
63
|
-
}
|
|
64
|
-
async function openInBrowser(url, browser) {
|
|
65
|
-
try {
|
|
66
|
-
const options = typeof browser === 'string' && browser.length > 0 ? {
|
|
67
|
-
app: [getAppName(browser)]
|
|
68
|
-
} : undefined;
|
|
69
|
-
await (0, _open().default)(url, options);
|
|
70
|
-
} catch (err) {
|
|
71
|
-
_logger().default.error(`Unexpected error while opening in browser: ${browser}`, '@atlaspack/utils');
|
|
72
|
-
_logger().default.error(err, '@atlaspack/utils');
|
|
73
|
-
}
|
|
74
|
-
}
|
package/lib/parseCSSImport.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = parseCSSImport;
|
|
7
|
-
function parseCSSImport(url) {
|
|
8
|
-
if (!/^(~|\.\/|\/)/.test(url)) {
|
|
9
|
-
return './' + url;
|
|
10
|
-
} else if (!/^(~\/|\.\/|\/)/.test(url)) {
|
|
11
|
-
return url.substring(1);
|
|
12
|
-
} else {
|
|
13
|
-
return url;
|
|
14
|
-
}
|
|
15
|
-
}
|
package/lib/path.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isAbsolute = isAbsolute;
|
|
7
|
-
exports.normalizePath = normalizePath;
|
|
8
|
-
exports.normalizeSeparators = normalizeSeparators;
|
|
9
|
-
exports.relativePath = relativePath;
|
|
10
|
-
function _path() {
|
|
11
|
-
const data = _interopRequireDefault(require("path"));
|
|
12
|
-
_path = function () {
|
|
13
|
-
return data;
|
|
14
|
-
};
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
-
const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:){0,1}[\\/]+/;
|
|
19
|
-
const SEPARATOR_REGEX = /[\\]+/g;
|
|
20
|
-
function isAbsolute(filepath) {
|
|
21
|
-
return ABSOLUTE_PATH_REGEX.test(filepath);
|
|
22
|
-
}
|
|
23
|
-
function normalizeSeparators(filePath) {
|
|
24
|
-
return filePath.replace(SEPARATOR_REGEX, '/');
|
|
25
|
-
}
|
|
26
|
-
function normalizePath(filePath, leadingDotSlash = true) {
|
|
27
|
-
if (leadingDotSlash && (filePath[0] !== '.' || filePath[1] !== '.' && filePath[1] !== '/' && filePath[1] !== '\\') && !_path().default.isAbsolute(filePath)) {
|
|
28
|
-
return normalizeSeparators('./' + filePath);
|
|
29
|
-
} else {
|
|
30
|
-
return normalizeSeparators(filePath);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function relativePath(from, to, leadingDotSlash = true) {
|
|
34
|
-
// Fast path
|
|
35
|
-
if (to.startsWith(from + '/')) {
|
|
36
|
-
return (leadingDotSlash ? './' : '') + to.slice(from.length + 1);
|
|
37
|
-
}
|
|
38
|
-
return normalizePath(_path().default.relative(from, to), leadingDotSlash);
|
|
39
|
-
}
|
package/lib/prettifyTime.js
DELETED
package/lib/prettyDiagnostic.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = prettyDiagnostic;
|
|
7
|
-
function _codeframe() {
|
|
8
|
-
const data = _interopRequireDefault(require("@atlaspack/codeframe"));
|
|
9
|
-
_codeframe = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _markdownAnsi() {
|
|
15
|
-
const data = _interopRequireDefault(require("@atlaspack/markdown-ansi"));
|
|
16
|
-
_markdownAnsi = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _chalk2() {
|
|
22
|
-
const data = _interopRequireDefault(require("chalk"));
|
|
23
|
-
_chalk2 = function () {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
function _path() {
|
|
29
|
-
const data = _interopRequireDefault(require("path"));
|
|
30
|
-
_path = function () {
|
|
31
|
-
return data;
|
|
32
|
-
};
|
|
33
|
-
return data;
|
|
34
|
-
}
|
|
35
|
-
function _terminalLink2() {
|
|
36
|
-
const data = _interopRequireDefault(require("terminal-link"));
|
|
37
|
-
_terminalLink2 = function () {
|
|
38
|
-
return data;
|
|
39
|
-
};
|
|
40
|
-
return data;
|
|
41
|
-
}
|
|
42
|
-
function _snarkdown() {
|
|
43
|
-
const data = _interopRequireDefault(require("snarkdown"));
|
|
44
|
-
_snarkdown = function () {
|
|
45
|
-
return data;
|
|
46
|
-
};
|
|
47
|
-
return data;
|
|
48
|
-
}
|
|
49
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
50
|
-
// $FlowFixMe
|
|
51
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
|
52
|
-
// $FlowFixMe
|
|
53
|
-
/* eslint-enable import/no-extraneous-dependencies */
|
|
54
|
-
async function prettyDiagnostic(diagnostic, options, terminalWidth, format = 'ansi') {
|
|
55
|
-
let {
|
|
56
|
-
origin,
|
|
57
|
-
message,
|
|
58
|
-
stack,
|
|
59
|
-
codeFrames,
|
|
60
|
-
hints,
|
|
61
|
-
skipFormatting,
|
|
62
|
-
documentationURL
|
|
63
|
-
} = diagnostic;
|
|
64
|
-
const md = format === 'ansi' ? _markdownAnsi().default : _snarkdown().default;
|
|
65
|
-
const terminalLink = format === 'ansi' ? _terminalLink2().default :
|
|
66
|
-
// eslint-disable-next-line no-unused-vars
|
|
67
|
-
(text, url, _) => `<a href="${url}">${text}</a>`;
|
|
68
|
-
const chalk = format === 'ansi' ? _chalk2().default : {
|
|
69
|
-
gray: {
|
|
70
|
-
underline: v => `<span style="color: grey; text-decoration: underline;">${v}</span>`
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
let result = {
|
|
74
|
-
message: md(`**${origin ?? 'unknown'}**: `) + (skipFormatting ? message : md(message)),
|
|
75
|
-
stack: '',
|
|
76
|
-
codeframe: '',
|
|
77
|
-
frames: [],
|
|
78
|
-
hints: [],
|
|
79
|
-
documentation: ''
|
|
80
|
-
};
|
|
81
|
-
if (codeFrames != null) {
|
|
82
|
-
for (let codeFrame of codeFrames) {
|
|
83
|
-
let filePath = codeFrame.filePath;
|
|
84
|
-
if (filePath != null && options && !_path().default.isAbsolute(filePath)) {
|
|
85
|
-
filePath = _path().default.join(options.projectRoot, filePath);
|
|
86
|
-
}
|
|
87
|
-
let highlights = codeFrame.codeHighlights;
|
|
88
|
-
let code = codeFrame.code;
|
|
89
|
-
if (code == null && options && filePath != null) {
|
|
90
|
-
code = await options.inputFS.readFile(filePath, 'utf8');
|
|
91
|
-
}
|
|
92
|
-
let formattedCodeFrame = '';
|
|
93
|
-
if (code != null) {
|
|
94
|
-
formattedCodeFrame = (0, _codeframe().default)(code, highlights, {
|
|
95
|
-
useColor: true,
|
|
96
|
-
syntaxHighlighting: true,
|
|
97
|
-
language:
|
|
98
|
-
// $FlowFixMe sketchy null checks do not matter here...
|
|
99
|
-
codeFrame.language || (filePath != null ? _path().default.extname(filePath).substr(1) : undefined),
|
|
100
|
-
terminalWidth
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
let location;
|
|
104
|
-
if (typeof filePath !== 'string') {
|
|
105
|
-
location = '';
|
|
106
|
-
} else if (highlights.length === 0) {
|
|
107
|
-
location = filePath;
|
|
108
|
-
} else {
|
|
109
|
-
location = `${filePath}:${highlights[0].start.line}:${highlights[0].start.column}`;
|
|
110
|
-
}
|
|
111
|
-
result.codeframe += location ? chalk.gray.underline(location) + '\n' : '';
|
|
112
|
-
result.codeframe += formattedCodeFrame;
|
|
113
|
-
if (codeFrame !== codeFrames[codeFrames.length - 1]) {
|
|
114
|
-
result.codeframe += '\n\n';
|
|
115
|
-
}
|
|
116
|
-
result.frames.push({
|
|
117
|
-
location,
|
|
118
|
-
code: formattedCodeFrame
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (stack != null) {
|
|
123
|
-
result.stack = stack;
|
|
124
|
-
}
|
|
125
|
-
if (Array.isArray(hints) && hints.length) {
|
|
126
|
-
result.hints = hints.map(h => {
|
|
127
|
-
return md(h);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
if (documentationURL != null) {
|
|
131
|
-
result.documentation = terminalLink('Learn more', documentationURL, {
|
|
132
|
-
fallback: (text, url) => `${text}: ${url}`
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
return result;
|
|
136
|
-
}
|