@atlaspack/utils 2.14.5-canary.35 → 2.14.5-canary.351

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.
Files changed (197) hide show
  1. package/CHANGELOG.md +446 -0
  2. package/benchmark.js +23 -0
  3. package/dist/DefaultMap.js +41 -0
  4. package/dist/Deferred.js +16 -0
  5. package/dist/PromiseQueue.js +107 -0
  6. package/dist/TapStream.js +23 -0
  7. package/dist/alternatives.js +97 -0
  8. package/dist/ansi-html.js +12 -0
  9. package/dist/blob.js +29 -0
  10. package/dist/bundle-url.js +32 -0
  11. package/dist/collection.js +106 -0
  12. package/dist/config.js +138 -0
  13. package/dist/countLines.js +12 -0
  14. package/dist/debounce.js +15 -0
  15. package/dist/debug-tools.js +39 -0
  16. package/dist/dependency-location.js +22 -0
  17. package/dist/escape-html.js +19 -0
  18. package/dist/generateBuildMetrics.js +111 -0
  19. package/dist/generateCertificate.js +124 -0
  20. package/dist/getCertificate.js +13 -0
  21. package/dist/getExisting.js +20 -0
  22. package/dist/getModuleParts.js +27 -0
  23. package/dist/getRootDir.js +46 -0
  24. package/dist/getTimeId.js +13 -0
  25. package/dist/glob.js +129 -0
  26. package/dist/hash.js +45 -0
  27. package/dist/http-server.js +55 -0
  28. package/dist/index.js +148 -0
  29. package/dist/is-url.js +15 -0
  30. package/dist/isDirectoryInside.js +11 -0
  31. package/dist/objectHash.js +20 -0
  32. package/dist/openInBrowser.js +61 -0
  33. package/dist/parseCSSImport.js +14 -0
  34. package/dist/path.js +36 -0
  35. package/dist/prettifyTime.js +6 -0
  36. package/dist/prettyDiagnostic.js +108 -0
  37. package/dist/progress-message.js +31 -0
  38. package/dist/relativeBundlePath.js +13 -0
  39. package/dist/relativeUrl.js +11 -0
  40. package/dist/replaceBundleReferences.js +131 -0
  41. package/dist/schema.js +404 -0
  42. package/dist/shared-buffer.js +24 -0
  43. package/dist/sourcemap.js +121 -0
  44. package/dist/stream.js +69 -0
  45. package/dist/throttle.js +12 -0
  46. package/dist/urlJoin.js +22 -0
  47. package/lib/DefaultMap.js +42 -0
  48. package/lib/Deferred.js +30 -0
  49. package/lib/PromiseQueue.js +112 -0
  50. package/lib/TapStream.js +34 -0
  51. package/lib/alternatives.js +116 -0
  52. package/lib/ansi-html.js +20 -0
  53. package/lib/blob.js +40 -0
  54. package/lib/bundle-url.js +34 -0
  55. package/lib/collection.js +111 -0
  56. package/lib/config.js +174 -0
  57. package/lib/countLines.js +15 -0
  58. package/lib/debounce.js +18 -0
  59. package/lib/debug-tools.js +40 -0
  60. package/lib/dependency-location.js +21 -0
  61. package/lib/escape-html.js +22 -0
  62. package/lib/generateBuildMetrics.js +121 -0
  63. package/lib/generateCertificate.js +129 -0
  64. package/lib/getCertificate.js +18 -0
  65. package/lib/getExisting.js +25 -0
  66. package/lib/getModuleParts.js +30 -0
  67. package/lib/getRootDir.js +52 -0
  68. package/lib/getTimeId.js +10 -0
  69. package/lib/glob.js +110 -0
  70. package/lib/hash.js +50 -0
  71. package/lib/http-server.js +85 -0
  72. package/lib/index.js +643 -37310
  73. package/lib/is-url.js +24 -0
  74. package/lib/isDirectoryInside.js +18 -0
  75. package/lib/objectHash.js +26 -0
  76. package/lib/openInBrowser.js +74 -0
  77. package/lib/parseCSSImport.js +15 -0
  78. package/lib/path.js +39 -0
  79. package/lib/prettifyTime.js +9 -0
  80. package/lib/prettyDiagnostic.js +154 -0
  81. package/lib/progress-message.js +39 -0
  82. package/lib/relativeBundlePath.js +22 -0
  83. package/lib/relativeUrl.js +24 -0
  84. package/lib/replaceBundleReferences.js +182 -0
  85. package/lib/schema.js +353 -0
  86. package/lib/shared-buffer.js +31 -0
  87. package/lib/sourcemap.js +138 -0
  88. package/lib/stream.js +76 -0
  89. package/lib/throttle.js +15 -0
  90. package/lib/types/DefaultMap.d.ts +13 -0
  91. package/lib/types/Deferred.d.ts +8 -0
  92. package/lib/types/PromiseQueue.d.ts +25 -0
  93. package/lib/types/TapStream.d.ts +6 -0
  94. package/lib/types/alternatives.d.ts +3 -0
  95. package/lib/types/ansi-html.d.ts +1 -0
  96. package/lib/types/blob.d.ts +4 -0
  97. package/lib/types/bundle-url.d.ts +4 -0
  98. package/lib/types/collection.d.ts +33 -0
  99. package/lib/types/config.d.ts +17 -0
  100. package/lib/types/countLines.d.ts +1 -0
  101. package/lib/types/debounce.d.ts +1 -0
  102. package/lib/types/debug-tools.d.ts +8 -0
  103. package/lib/types/dependency-location.d.ts +14 -0
  104. package/lib/types/escape-html.d.ts +1 -0
  105. package/lib/types/generateBuildMetrics.d.ts +18 -0
  106. package/lib/types/generateCertificate.d.ts +5 -0
  107. package/lib/types/getCertificate.d.ts +5 -0
  108. package/lib/types/getExisting.d.ts +8 -0
  109. package/lib/types/getModuleParts.d.ts +4 -0
  110. package/lib/types/getRootDir.d.ts +2 -0
  111. package/lib/types/getTimeId.d.ts +1 -0
  112. package/lib/types/glob.d.ts +9 -0
  113. package/lib/types/hash.d.ts +7 -0
  114. package/lib/types/http-server.d.ts +19 -0
  115. package/lib/types/index.d.ts +49 -0
  116. package/lib/types/is-url.d.ts +1 -0
  117. package/lib/types/isDirectoryInside.d.ts +2 -0
  118. package/lib/types/objectHash.d.ts +3 -0
  119. package/lib/types/openInBrowser.d.ts +1 -0
  120. package/lib/types/parseCSSImport.d.ts +1 -0
  121. package/lib/types/path.d.ts +8 -0
  122. package/lib/types/prettifyTime.d.ts +1 -0
  123. package/lib/types/prettyDiagnostic.d.ts +18 -0
  124. package/lib/types/progress-message.d.ts +3 -0
  125. package/lib/types/relativeBundlePath.d.ts +4 -0
  126. package/lib/types/relativeUrl.d.ts +1 -0
  127. package/lib/types/replaceBundleReferences.d.ts +39 -0
  128. package/lib/types/schema.d.ts +107 -0
  129. package/lib/types/shared-buffer.d.ts +2 -0
  130. package/lib/types/sourcemap.d.ts +15 -0
  131. package/lib/types/stream.d.ts +8 -0
  132. package/lib/types/throttle.d.ts +1 -0
  133. package/lib/types/urlJoin.d.ts +5 -0
  134. package/lib/urlJoin.js +35 -0
  135. package/package.json +27 -18
  136. package/src/{DefaultMap.js → DefaultMap.ts} +8 -12
  137. package/src/Deferred.ts +26 -0
  138. package/src/{PromiseQueue.js → PromiseQueue.ts} +40 -35
  139. package/src/{TapStream.js → TapStream.ts} +8 -7
  140. package/src/{alternatives.js → alternatives.ts} +15 -16
  141. package/src/{ansi-html.js → ansi-html.ts} +1 -1
  142. package/src/{blob.js → blob.ts} +3 -5
  143. package/src/{bundle-url.js → bundle-url.ts} +3 -5
  144. package/src/{collection.js → collection.ts} +23 -20
  145. package/src/{config.js → config.ts} +20 -21
  146. package/src/{countLines.js → countLines.ts} +0 -2
  147. package/src/{debounce.js → debounce.ts} +3 -5
  148. package/src/debug-tools.ts +48 -0
  149. package/src/{dependency-location.js → dependency-location.ts} +15 -11
  150. package/src/{escape-html.js → escape-html.ts} +5 -3
  151. package/src/{generateBuildMetrics.js → generateBuildMetrics.ts} +19 -21
  152. package/src/{generateCertificate.js → generateCertificate.ts} +8 -6
  153. package/src/{getCertificate.js → getCertificate.ts} +6 -5
  154. package/src/{getExisting.js → getExisting.ts} +4 -3
  155. package/src/{getModuleParts.js → getModuleParts.ts} +3 -2
  156. package/src/{getRootDir.js → getRootDir.ts} +1 -3
  157. package/src/getTimeId.ts +12 -0
  158. package/src/{glob.js → glob.ts} +13 -14
  159. package/src/{hash.js → hash.ts} +23 -18
  160. package/src/{http-server.js → http-server.ts} +34 -40
  161. package/src/{index.js → index.ts} +14 -10
  162. package/src/{is-url.js → is-url.ts} +1 -2
  163. package/src/{isDirectoryInside.js → isDirectoryInside.ts} +1 -2
  164. package/src/{objectHash.js → objectHash.ts} +1 -4
  165. package/src/{openInBrowser.js → openInBrowser.ts} +2 -4
  166. package/src/{parseCSSImport.js → parseCSSImport.ts} +0 -2
  167. package/src/{path.js → path.ts} +2 -4
  168. package/src/{prettifyTime.js → prettifyTime.ts} +0 -2
  169. package/src/{prettyDiagnostic.js → prettyDiagnostic.ts} +47 -24
  170. package/src/progress-message.ts +43 -0
  171. package/src/{relativeBundlePath.js → relativeBundlePath.ts} +4 -4
  172. package/src/{relativeUrl.js → relativeUrl.ts} +0 -1
  173. package/src/{replaceBundleReferences.js → replaceBundleReferences.ts} +67 -51
  174. package/src/schema.ts +552 -0
  175. package/src/{shared-buffer.js → shared-buffer.ts} +5 -3
  176. package/src/{sourcemap.js → sourcemap.ts} +28 -10
  177. package/src/{stream.js → stream.ts} +30 -22
  178. package/src/throttle.ts +13 -0
  179. package/src/{urlJoin.js → urlJoin.ts} +1 -3
  180. package/test/{DefaultMap.test.js → DefaultMap.test.ts} +4 -6
  181. package/test/{PromiseQueue.test.js → PromiseQueue.test.ts} +5 -6
  182. package/test/{collection.test.js → collection.test.ts} +0 -2
  183. package/test/{config.test.js → config.test.ts} +0 -3
  184. package/test/{objectHash.test.js → objectHash.test.ts} +4 -5
  185. package/test/{prettifyTime.test.js → prettifyTime.test.ts} +0 -1
  186. package/test/{replaceBundleReferences.test.js → replaceBundleReferences.test.ts} +0 -32
  187. package/test/schema.test.ts +748 -0
  188. package/test/{sourcemap.test.js → sourcemap.test.ts} +0 -1
  189. package/test/{throttle.test.js → throttle.test.ts} +1 -3
  190. package/test/{urlJoin.test.js → urlJoin.test.ts} +0 -2
  191. package/tsconfig.json +36 -0
  192. package/tsconfig.tsbuildinfo +1 -0
  193. package/lib/index.js.map +0 -1
  194. package/src/Deferred.js +0 -23
  195. package/src/progress-message.js +0 -22
  196. package/src/schema.js +0 -504
  197. package/src/throttle.js +0 -15
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
+ options = {
53
+ ...options,
54
+ fs: {
55
+ statSync: p => {
56
+ return fs.statSync(p);
57
+ },
58
+ lstatSync: p => {
59
+ // Our FileSystem interface doesn't have lstat support at the moment,
60
+ // but this is fine for our purposes since we follow symlinks by default.
61
+ return fs.statSync(p);
62
+ },
63
+ // @ts-expect-error TS7006
64
+ readdirSync: (p, opts) => {
65
+ return fs.readdirSync(p, opts);
66
+ }
67
+ }
68
+ };
69
+ return _fastGlob().default.sync((0, _path.normalizeSeparators)(p), options);
70
+ }
71
+ function glob(p, fs, options) {
72
+ options = {
73
+ ...options,
74
+ fs: {
75
+ stat: async (p, cb) => {
76
+ try {
77
+ cb(null, await fs.stat(p));
78
+ } catch (err) {
79
+ // @ts-expect-error TS2345
80
+ cb(err);
81
+ }
82
+ },
83
+ lstat: async (p, cb) => {
84
+ // Our FileSystem interface doesn't have lstat support at the moment,
85
+ // but this is fine for our purposes since we follow symlinks by default.
86
+ try {
87
+ cb(null, await fs.stat(p));
88
+ } catch (err) {
89
+ // @ts-expect-error TS2345
90
+ cb(err);
91
+ }
92
+ },
93
+ // @ts-expect-error TS7006
94
+ readdir: async (p, opts, cb) => {
95
+ if (typeof opts === 'function') {
96
+ cb = opts;
97
+ // @ts-expect-error TS2322
98
+ opts = null;
99
+ }
100
+ try {
101
+ cb(null, await fs.readdir(p, opts));
102
+ } catch (err) {
103
+ // @ts-expect-error TS2345
104
+ cb(err);
105
+ }
106
+ }
107
+ }
108
+ };
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
+ }