@atlaspack/utils 2.15.4-dev-eae8c193d.0 → 2.15.4-typescript-9a5730863.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/lib/DefaultMap.js +46 -0
- package/lib/Deferred.js +30 -0
- package/lib/PromiseQueue.js +112 -0
- package/lib/TapStream.js +34 -0
- package/lib/alternatives.js +116 -0
- package/lib/ansi-html.js +18 -0
- package/lib/blob.js +40 -0
- package/lib/bundle-url.js +34 -0
- package/lib/collection.js +111 -0
- package/lib/config.js +172 -0
- package/lib/countLines.js +15 -0
- package/lib/debounce.js +18 -0
- package/lib/debug-tools.js +36 -0
- package/lib/dependency-location.js +21 -0
- package/lib/escape-html.js +22 -0
- package/lib/generateBuildMetrics.js +121 -0
- package/lib/generateCertificate.js +129 -0
- package/lib/getCertificate.js +18 -0
- package/lib/getExisting.js +25 -0
- package/lib/getModuleParts.js +30 -0
- package/lib/getRootDir.js +52 -0
- package/lib/glob.js +110 -0
- package/lib/hash.js +50 -0
- package/lib/http-server.js +85 -0
- package/lib/index.js +478 -37346
- package/lib/is-url.js +22 -0
- package/lib/isDirectoryInside.js +18 -0
- package/lib/objectHash.js +27 -0
- package/lib/openInBrowser.js +74 -0
- package/lib/parseCSSImport.js +15 -0
- package/lib/path.js +39 -0
- package/lib/prettifyTime.js +9 -0
- package/lib/prettyDiagnostic.js +136 -0
- package/lib/progress-message.js +27 -0
- package/lib/relativeBundlePath.js +22 -0
- package/lib/relativeUrl.js +24 -0
- package/lib/replaceBundleReferences.js +199 -0
- package/lib/schema.js +336 -0
- package/lib/shared-buffer.js +27 -0
- package/lib/sourcemap.js +127 -0
- package/lib/stream.js +76 -0
- package/lib/throttle.js +15 -0
- package/lib/urlJoin.js +35 -0
- package/package.json +9 -9
- package/lib/index.js.map +0 -1
package/lib/glob.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
}
|