@atlaspack/utils 2.14.5-canary.36 → 2.14.5-canary.361

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 +474 -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
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = generateBuildMetrics;
7
+ const source_map_1 = __importDefault(require("@atlaspack/source-map"));
8
+ const nullthrows_1 = __importDefault(require("nullthrows"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const _1 = require("./");
11
+ async function getSourcemapSizes(filePath, fs, projectRoot) {
12
+ let bundleContents = await fs.readFile(filePath, 'utf-8');
13
+ let mapUrlData = await (0, _1.loadSourceMapUrl)(fs, filePath, bundleContents);
14
+ if (!mapUrlData) {
15
+ return null;
16
+ }
17
+ let rawMap = mapUrlData.map;
18
+ let sourceMap = new source_map_1.default(projectRoot);
19
+ sourceMap.addVLQMap(rawMap);
20
+ let parsedMapData = sourceMap.getMap();
21
+ if (parsedMapData.mappings.length > 2) {
22
+ let sources = parsedMapData.sources.map((s) => path_1.default.normalize(path_1.default.join(projectRoot, s)));
23
+ let currLine = 1;
24
+ let currColumn = 0;
25
+ let currMappingIndex = 0;
26
+ let currMapping = parsedMapData.mappings[currMappingIndex];
27
+ let nextMapping = parsedMapData.mappings[currMappingIndex + 1];
28
+ let sourceSizes = new Array(sources.length).fill(0);
29
+ let unknownOrigin = 0;
30
+ for (let i = 0; i < bundleContents.length; i++) {
31
+ let character = bundleContents[i];
32
+ while (nextMapping &&
33
+ nextMapping.generated.line === currLine &&
34
+ nextMapping.generated.column <= currColumn) {
35
+ currMappingIndex++;
36
+ currMapping = parsedMapData.mappings[currMappingIndex];
37
+ nextMapping = parsedMapData.mappings[currMappingIndex + 1];
38
+ }
39
+ let currentSource = currMapping.source;
40
+ let charSize = Buffer.byteLength(character, 'utf8');
41
+ if (currentSource != null &&
42
+ currMapping.generated.line === currLine &&
43
+ currMapping.generated.column <= currColumn) {
44
+ sourceSizes[currentSource] += charSize;
45
+ }
46
+ else {
47
+ unknownOrigin += charSize;
48
+ }
49
+ if (character === '\n') {
50
+ currColumn = 0;
51
+ currLine++;
52
+ }
53
+ else {
54
+ currColumn++;
55
+ }
56
+ }
57
+ let sizeMap = new Map();
58
+ for (let i = 0; i < sourceSizes.length; i++) {
59
+ sizeMap.set(sources[i], sourceSizes[i]);
60
+ }
61
+ sizeMap.set('', unknownOrigin);
62
+ return sizeMap;
63
+ }
64
+ }
65
+ async function createBundleStats(bundle, fs, projectRoot) {
66
+ let filePath = bundle.filePath;
67
+ let sourcemapSizes = await getSourcemapSizes(filePath, fs, projectRoot);
68
+ let assets = new Map();
69
+ bundle.traverseAssets((asset) => {
70
+ let filePath = path_1.default.normalize(asset.filePath);
71
+ assets.set(filePath, {
72
+ filePath,
73
+ size: asset.stats.size,
74
+ originalSize: asset.stats.size,
75
+ time: asset.stats.time,
76
+ });
77
+ });
78
+ let assetsReport = [];
79
+ if (sourcemapSizes && sourcemapSizes.size) {
80
+ assetsReport = Array.from(sourcemapSizes.keys()).map((filePath) => {
81
+ let foundSize = sourcemapSizes.get(filePath) || 0;
82
+ let stats = assets.get(filePath) || {
83
+ filePath,
84
+ size: foundSize,
85
+ originalSize: foundSize,
86
+ time: 0,
87
+ };
88
+ return {
89
+ ...stats,
90
+ size: foundSize,
91
+ };
92
+ });
93
+ }
94
+ else {
95
+ assetsReport = Array.from(assets.values());
96
+ }
97
+ return {
98
+ filePath: (0, nullthrows_1.default)(bundle.filePath),
99
+ size: bundle.stats.size,
100
+ time: bundle.stats.time,
101
+ assets: assetsReport.sort((a, b) => b.size - a.size),
102
+ };
103
+ }
104
+ async function generateBuildMetrics(bundles, fs, projectRoot) {
105
+ bundles
106
+ .sort((a, b) => b.stats.size - a.stats.size)
107
+ .filter((b) => !!b.filePath);
108
+ return {
109
+ bundles: (await Promise.all(bundles.map((b) => createBundleStats(b, fs, projectRoot)))).filter((e) => !!e),
110
+ };
111
+ }
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = generateCertificate;
7
+ const node_forge_1 = __importDefault(require("node-forge"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const logger_1 = __importDefault(require("@atlaspack/logger"));
10
+ async function generateCertificate(fs, cacheDir, host) {
11
+ let certDirectory = cacheDir;
12
+ const privateKeyPath = path_1.default.join(certDirectory, 'private.pem');
13
+ const certPath = path_1.default.join(certDirectory, 'primary.crt');
14
+ const cachedKey = (await fs.exists(privateKeyPath)) && (await fs.readFile(privateKeyPath));
15
+ const cachedCert = (await fs.exists(certPath)) && (await fs.readFile(certPath));
16
+ if (cachedKey && cachedCert) {
17
+ return {
18
+ key: cachedKey,
19
+ cert: cachedCert,
20
+ };
21
+ }
22
+ logger_1.default.progress('Generating SSL Certificate...');
23
+ const pki = node_forge_1.default.pki;
24
+ const keys = pki.rsa.generateKeyPair(2048);
25
+ const cert = pki.createCertificate();
26
+ cert.publicKey = keys.publicKey;
27
+ cert.serialNumber = Date.now().toString();
28
+ cert.validity.notBefore = new Date();
29
+ cert.validity.notAfter = new Date();
30
+ cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
31
+ const attrs = [
32
+ {
33
+ name: 'commonName',
34
+ value: 'parceljs.org',
35
+ },
36
+ {
37
+ name: 'countryName',
38
+ value: 'US',
39
+ },
40
+ {
41
+ shortName: 'ST',
42
+ value: 'Virginia',
43
+ },
44
+ {
45
+ name: 'localityName',
46
+ value: 'Blacksburg',
47
+ },
48
+ {
49
+ name: 'organizationName',
50
+ value: 'parcelBundler',
51
+ },
52
+ {
53
+ shortName: 'OU',
54
+ value: 'Test',
55
+ },
56
+ ];
57
+ let altNames = [
58
+ {
59
+ type: 2, // DNS
60
+ value: 'localhost',
61
+ },
62
+ {
63
+ type: 7, // IP
64
+ ip: '127.0.0.1',
65
+ },
66
+ ];
67
+ if (host) {
68
+ altNames.push({
69
+ type: 2, // DNS
70
+ value: host,
71
+ });
72
+ }
73
+ cert.setSubject(attrs);
74
+ cert.setIssuer(attrs);
75
+ cert.setExtensions([
76
+ {
77
+ name: 'basicConstraints',
78
+ cA: false,
79
+ },
80
+ {
81
+ name: 'keyUsage',
82
+ keyCertSign: true,
83
+ digitalSignature: true,
84
+ nonRepudiation: true,
85
+ keyEncipherment: true,
86
+ dataEncipherment: true,
87
+ },
88
+ {
89
+ name: 'extKeyUsage',
90
+ serverAuth: true,
91
+ clientAuth: true,
92
+ codeSigning: true,
93
+ emailProtection: true,
94
+ timeStamping: true,
95
+ },
96
+ {
97
+ name: 'nsCertType',
98
+ client: true,
99
+ server: true,
100
+ email: true,
101
+ objsign: true,
102
+ sslCA: true,
103
+ emailCA: true,
104
+ objCA: true,
105
+ },
106
+ {
107
+ name: 'subjectAltName',
108
+ altNames,
109
+ },
110
+ {
111
+ name: 'subjectKeyIdentifier',
112
+ },
113
+ ]);
114
+ cert.sign(keys.privateKey, node_forge_1.default.md.sha256.create());
115
+ const privPem = pki.privateKeyToPem(keys.privateKey);
116
+ const certPem = pki.certificateToPem(cert);
117
+ await fs.mkdirp(certDirectory);
118
+ await fs.writeFile(privateKeyPath, privPem);
119
+ await fs.writeFile(certPath, certPem);
120
+ return {
121
+ key: privPem,
122
+ cert: certPem,
123
+ };
124
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = getCertificate;
4
+ async function getCertificate(fs, options) {
5
+ try {
6
+ let cert = await fs.readFile(options.cert);
7
+ let key = await fs.readFile(options.key);
8
+ return { key, cert };
9
+ }
10
+ catch (err) {
11
+ throw new Error('Certificate and/or key not found');
12
+ }
13
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = getExisting;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ /**
9
+ * Creates an object that contains both source and minified (using the source as a fallback).
10
+ * e.g. builtins.min.js and builtins.js.
11
+ */
12
+ function getExisting(minifiedPath, sourcePath) {
13
+ let source = fs_1.default.readFileSync(sourcePath, 'utf8').trim();
14
+ return {
15
+ source,
16
+ minified: fs_1.default.existsSync(minifiedPath)
17
+ ? fs_1.default.readFileSync(minifiedPath, 'utf8').trim().replace(/;$/, '')
18
+ : source,
19
+ };
20
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = getModuleParts;
7
+ const path_1 = __importDefault(require("path"));
8
+ const path_2 = require("./path");
9
+ /**
10
+ * Returns the package name and the optional subpath
11
+ */
12
+ function getModuleParts(_name) {
13
+ let name = path_1.default.normalize(_name);
14
+ let splitOn = name.indexOf(path_1.default.sep);
15
+ if (name.charAt(0) === '@') {
16
+ splitOn = name.indexOf(path_1.default.sep, splitOn + 1);
17
+ }
18
+ if (splitOn < 0) {
19
+ return [(0, path_2.normalizeSeparators)(name), undefined];
20
+ }
21
+ else {
22
+ return [
23
+ (0, path_2.normalizeSeparators)(name.substring(0, splitOn)),
24
+ name.substring(splitOn + 1) || undefined,
25
+ ];
26
+ }
27
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = getRootDir;
7
+ const glob_1 = require("./glob");
8
+ const path_1 = __importDefault(require("path"));
9
+ function getRootDir(files) {
10
+ let cur = null;
11
+ for (let file of files) {
12
+ let parsed = path_1.default.parse(file);
13
+ parsed.dir = findGlobRoot(parsed.dir);
14
+ if (!cur) {
15
+ cur = parsed;
16
+ }
17
+ else if (parsed.root !== cur.root) {
18
+ // bail out. there is no common root.
19
+ // this can happen on windows, e.g. C:\foo\bar vs. D:\foo\bar
20
+ return process.cwd();
21
+ }
22
+ else {
23
+ // find the common path parts.
24
+ let curParts = cur.dir.split(path_1.default.sep);
25
+ let newParts = parsed.dir.split(path_1.default.sep);
26
+ let len = Math.min(curParts.length, newParts.length);
27
+ let i = 0;
28
+ while (i < len && curParts[i] === newParts[i]) {
29
+ i++;
30
+ }
31
+ cur.dir = i > 1 ? curParts.slice(0, i).join(path_1.default.sep) : cur.root;
32
+ }
33
+ }
34
+ return cur ? cur.dir : process.cwd();
35
+ }
36
+ // Transforms a path like `packages/*/src/index.js` to the root of the glob, `packages/`
37
+ function findGlobRoot(dir) {
38
+ let parts = dir.split(path_1.default.sep);
39
+ let last = parts.length;
40
+ for (let i = parts.length - 1; i >= 0; i--) {
41
+ if ((0, glob_1.isGlob)(parts[i])) {
42
+ last = i;
43
+ }
44
+ }
45
+ return parts.slice(0, last).join(path_1.default.sep);
46
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = getTimeId;
4
+ function getTimeId() {
5
+ let now = new Date();
6
+ return (String(now.getFullYear()) +
7
+ String(now.getMonth() + 1).padStart(2, '0') +
8
+ String(now.getDate()).padStart(2, '0') +
9
+ '-' +
10
+ String(now.getHours()).padStart(2, '0') +
11
+ String(now.getMinutes()).padStart(2, '0') +
12
+ String(now.getSeconds()).padStart(2, '0'));
13
+ }
package/dist/glob.js ADDED
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.isGlob = isGlob;
40
+ exports.isGlobMatch = isGlobMatch;
41
+ exports.globMatch = globMatch;
42
+ exports.globToRegex = globToRegex;
43
+ exports.globSync = globSync;
44
+ exports.glob = glob;
45
+ const is_glob_1 = __importDefault(require("is-glob"));
46
+ const fast_glob_1 = __importDefault(require("fast-glob"));
47
+ const micromatch_1 = __importStar(require("micromatch"));
48
+ const path_1 = require("./path");
49
+ function isGlob(p) {
50
+ return (0, is_glob_1.default)((0, path_1.normalizeSeparators)(p));
51
+ }
52
+ function isGlobMatch(filePath, glob, opts) {
53
+ glob = Array.isArray(glob)
54
+ ? glob.map(path_1.normalizeSeparators)
55
+ : (0, path_1.normalizeSeparators)(glob);
56
+ return (0, micromatch_1.isMatch)(filePath, glob, opts);
57
+ }
58
+ function globMatch(values, glob, opts) {
59
+ glob = Array.isArray(glob)
60
+ ? glob.map(path_1.normalizeSeparators)
61
+ : (0, path_1.normalizeSeparators)(glob);
62
+ return (0, micromatch_1.default)(values, glob, opts);
63
+ }
64
+ function globToRegex(glob, opts) {
65
+ return (0, micromatch_1.makeRe)(glob, opts);
66
+ }
67
+ function globSync(p, fs, options) {
68
+ options = {
69
+ ...options,
70
+ fs: {
71
+ statSync: (p) => {
72
+ return fs.statSync(p);
73
+ },
74
+ lstatSync: (p) => {
75
+ // Our FileSystem interface doesn't have lstat support at the moment,
76
+ // but this is fine for our purposes since we follow symlinks by default.
77
+ return fs.statSync(p);
78
+ },
79
+ // @ts-expect-error TS7006
80
+ readdirSync: (p, opts) => {
81
+ return fs.readdirSync(p, opts);
82
+ },
83
+ },
84
+ };
85
+ return fast_glob_1.default.sync((0, path_1.normalizeSeparators)(p), options);
86
+ }
87
+ function glob(p, fs, options) {
88
+ options = {
89
+ ...options,
90
+ fs: {
91
+ stat: async (p, cb) => {
92
+ try {
93
+ cb(null, await fs.stat(p));
94
+ }
95
+ catch (err) {
96
+ // @ts-expect-error TS2345
97
+ cb(err);
98
+ }
99
+ },
100
+ lstat: async (p, cb) => {
101
+ // Our FileSystem interface doesn't have lstat support at the moment,
102
+ // but this is fine for our purposes since we follow symlinks by default.
103
+ try {
104
+ cb(null, await fs.stat(p));
105
+ }
106
+ catch (err) {
107
+ // @ts-expect-error TS2345
108
+ cb(err);
109
+ }
110
+ },
111
+ // @ts-expect-error TS7006
112
+ readdir: async (p, opts, cb) => {
113
+ if (typeof opts === 'function') {
114
+ cb = opts;
115
+ // @ts-expect-error TS2322
116
+ opts = null;
117
+ }
118
+ try {
119
+ cb(null, await fs.readdir(p, opts));
120
+ }
121
+ catch (err) {
122
+ // @ts-expect-error TS2345
123
+ cb(err);
124
+ }
125
+ },
126
+ },
127
+ };
128
+ return (0, fast_glob_1.default)((0, path_1.normalizeSeparators)(p), options);
129
+ }
package/dist/hash.js ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hashStream = hashStream;
4
+ exports.hashObject = hashObject;
5
+ exports.hashFile = hashFile;
6
+ const collection_1 = require("./collection");
7
+ const rust_1 = require("@atlaspack/rust");
8
+ function hashStream(stream) {
9
+ let hash = new rust_1.Hash();
10
+ return new Promise((resolve, reject) => {
11
+ stream.on('error', (err) => {
12
+ reject(err);
13
+ });
14
+ stream
15
+ .on('data', (chunk) => {
16
+ hash.writeBuffer(chunk);
17
+ })
18
+ .on('end', function () {
19
+ resolve(hash.finish());
20
+ })
21
+ .on('error', (err) => {
22
+ reject(err);
23
+ });
24
+ });
25
+ }
26
+ function hashObject(obj) {
27
+ return (0, rust_1.hashString)(JSON.stringify((0, collection_1.objectSortedEntriesDeep)(obj)));
28
+ }
29
+ let testCache = {
30
+ /*:: ...null */
31
+ };
32
+ function hashFile(fs, filePath) {
33
+ if (process.env.ATLASPACK_BUILD_ENV === 'test') {
34
+ // Development builds of these native modules are especially big and slow to hash.
35
+ if (/parcel-swc\.[^\\/]+\.node$|lightningcss.[^\\/]+.node$/.test(filePath)) {
36
+ let cacheEntry = testCache[filePath];
37
+ if (cacheEntry)
38
+ return cacheEntry;
39
+ let v = hashStream(fs.createReadStream(filePath));
40
+ testCache[filePath] = v;
41
+ return v;
42
+ }
43
+ }
44
+ return hashStream(fs.createReadStream(filePath));
45
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createHTTPServer = createHTTPServer;
7
+ const http_1 = __importDefault(require("http"));
8
+ const https_1 = __importDefault(require("https"));
9
+ const nullthrows_1 = __importDefault(require("nullthrows"));
10
+ const _1 = require("./");
11
+ // Creates either an http or https server with an awaitable dispose
12
+ // that closes any connections
13
+ async function createHTTPServer(options) {
14
+ let server;
15
+ if (!options.https) {
16
+ server = http_1.default.createServer(options.listener);
17
+ }
18
+ else if (options.https === true) {
19
+ let { cert, key } = await (0, _1.generateCertificate)(options.outputFS, options.cacheDir, options.host);
20
+ server = https_1.default.createServer({ cert, key }, options.listener);
21
+ }
22
+ else {
23
+ let { cert, key } = await (0, _1.getCertificate)(options.inputFS, options.https);
24
+ server = https_1.default.createServer({ cert, key }, options.listener);
25
+ }
26
+ // HTTPServer#close only stops accepting new connections, and does not close existing ones.
27
+ // Before closing, destroy any active connections through their sockets. Additionally, remove sockets when they close:
28
+ // https://stackoverflow.com/questions/18874689/force-close-all-connections-in-a-node-js-http-server
29
+ // https://stackoverflow.com/questions/14626636/how-do-i-shutdown-a-node-js-https-server-immediately/14636625#14636625
30
+ let sockets = new Set();
31
+ server.on('connection', (socket) => {
32
+ (0, nullthrows_1.default)(sockets).add(socket);
33
+ socket.on('close', () => {
34
+ (0, nullthrows_1.default)(sockets).delete(socket);
35
+ });
36
+ });
37
+ return {
38
+ server,
39
+ stop() {
40
+ return new Promise((resolve, reject) => {
41
+ for (let socket of (0, nullthrows_1.default)(sockets)) {
42
+ socket.destroy();
43
+ }
44
+ sockets = new Set();
45
+ server.close((err) => {
46
+ if (err != null) {
47
+ reject(err);
48
+ return;
49
+ }
50
+ resolve();
51
+ });
52
+ });
53
+ },
54
+ };
55
+ }