@unpackjs/core 1.5.3 → 1.6.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.
Files changed (238) hide show
  1. package/bin/openChrome.applescript +94 -0
  2. package/compiled/chokidar/index.d.ts +327 -0
  3. package/compiled/chokidar/index.js +1773 -0
  4. package/compiled/chokidar/license +21 -0
  5. package/compiled/chokidar/package.json +1 -0
  6. package/compiled/commander/index.d.ts +971 -0
  7. package/compiled/commander/index.js +2190 -0
  8. package/compiled/commander/license +22 -0
  9. package/compiled/commander/package.json +1 -0
  10. package/compiled/css-loader/api.js +85 -0
  11. package/compiled/css-loader/getUrl.js +26 -0
  12. package/compiled/css-loader/index.d.ts +1 -0
  13. package/compiled/css-loader/index.js +8004 -0
  14. package/compiled/css-loader/license +20 -0
  15. package/compiled/css-loader/noSourceMaps.js +5 -0
  16. package/compiled/css-loader/package.json +1 -0
  17. package/compiled/css-loader/sourceMaps.js +16 -0
  18. package/compiled/fast-glob/index.d.ts +237 -0
  19. package/compiled/fast-glob/index.js +5726 -0
  20. package/compiled/fast-glob/license +21 -0
  21. package/compiled/fast-glob/package.json +1 -0
  22. package/compiled/less-loader/index.d.ts +1 -0
  23. package/compiled/less-loader/index.js +340 -0
  24. package/compiled/less-loader/license +20 -0
  25. package/compiled/less-loader/package.json +1 -0
  26. package/compiled/line-diff/index.d.ts +1 -0
  27. package/compiled/line-diff/index.js +160 -0
  28. package/compiled/line-diff/license +21 -0
  29. package/compiled/line-diff/package.json +1 -0
  30. package/compiled/log-update/index.d.ts +1 -0
  31. package/compiled/log-update/index.js +1970 -0
  32. package/compiled/log-update/package.json +1 -0
  33. package/compiled/portfinder/index.d.ts +64 -0
  34. package/compiled/portfinder/index.js +3401 -0
  35. package/compiled/portfinder/license +22 -0
  36. package/compiled/portfinder/package.json +1 -0
  37. package/compiled/postcss-loader/index.d.ts +1 -0
  38. package/compiled/postcss-loader/index.js +94945 -0
  39. package/compiled/postcss-loader/license +20 -0
  40. package/compiled/postcss-loader/package.json +1 -0
  41. package/compiled/sass-loader/index.d.ts +961 -0
  42. package/compiled/sass-loader/index.js +5610 -0
  43. package/compiled/sass-loader/index1.js +65 -0
  44. package/compiled/sass-loader/license +20 -0
  45. package/compiled/sass-loader/package.json +1 -0
  46. package/compiled/sass-loader/sass.node.js +12 -0
  47. package/compiled/semver/index.d.ts +1 -0
  48. package/compiled/semver/index.js +1940 -0
  49. package/compiled/semver/license +15 -0
  50. package/compiled/semver/package.json +1 -0
  51. package/compiled/style-loader/index.d.ts +1 -0
  52. package/compiled/style-loader/index.js +370 -0
  53. package/compiled/style-loader/license +20 -0
  54. package/compiled/style-loader/package.json +1 -0
  55. package/compiled/style-loader/runtime/injectStylesIntoLinkTag.js +29 -0
  56. package/compiled/style-loader/runtime/injectStylesIntoStyleTag.js +84 -0
  57. package/compiled/style-loader/runtime/insertBySelector.js +34 -0
  58. package/compiled/style-loader/runtime/insertStyleElement.js +10 -0
  59. package/compiled/style-loader/runtime/isEqualLocals.js +28 -0
  60. package/compiled/style-loader/runtime/isOldIE.js +17 -0
  61. package/compiled/style-loader/runtime/setAttributesWithAttributes.js +13 -0
  62. package/compiled/style-loader/runtime/setAttributesWithAttributesAndNonce.js +9 -0
  63. package/compiled/style-loader/runtime/setAttributesWithoutAttributes.js +10 -0
  64. package/compiled/style-loader/runtime/singletonStyleDomAPI.js +86 -0
  65. package/compiled/style-loader/runtime/styleDomAPI.js +61 -0
  66. package/compiled/style-loader/runtime/styleTagTransform.js +14 -0
  67. package/compiled/webpack-bundle-analyzer/index.d.ts +1 -0
  68. package/compiled/webpack-bundle-analyzer/index.js +13276 -0
  69. package/compiled/webpack-bundle-analyzer/license +20 -0
  70. package/compiled/webpack-bundle-analyzer/package.json +1 -0
  71. package/compiled/webpack-bundle-analyzer/public/viewer.js +16 -0
  72. package/compiled/webpack-bundle-analyzer/public/viewer.js.LICENSE.txt +10 -0
  73. package/compiled/webpack-merge/index.d.ts +31 -0
  74. package/compiled/webpack-merge/index.js +1200 -0
  75. package/compiled/webpack-merge/license +20 -0
  76. package/compiled/webpack-merge/package.json +1 -0
  77. package/dist/bundleRequire.cjs +200 -0
  78. package/dist/bundleRequire.d.ts +5 -0
  79. package/dist/bundleRequire.d.ts.map +1 -0
  80. package/dist/bundleRequire.js +173 -0
  81. package/dist/bundler-config/chunkSplit.cjs +151 -0
  82. package/dist/bundler-config/chunkSplit.d.ts +6 -0
  83. package/dist/bundler-config/chunkSplit.d.ts.map +1 -0
  84. package/dist/bundler-config/chunkSplit.js +127 -0
  85. package/dist/bundler-config/css.cjs +168 -0
  86. package/dist/bundler-config/css.d.ts +6 -0
  87. package/dist/bundler-config/css.d.ts.map +1 -0
  88. package/dist/bundler-config/css.js +158 -0
  89. package/dist/bundler-config/experimentCss.cjs +167 -0
  90. package/dist/bundler-config/experimentCss.d.ts +6 -0
  91. package/dist/bundler-config/experimentCss.d.ts.map +1 -0
  92. package/dist/bundler-config/experimentCss.js +157 -0
  93. package/dist/bundler-config/helper.cjs +81 -0
  94. package/dist/bundler-config/helper.d.ts +8 -0
  95. package/dist/bundler-config/helper.d.ts.map +1 -0
  96. package/dist/bundler-config/helper.js +56 -0
  97. package/dist/bundler-config/index.cjs +206 -0
  98. package/dist/bundler-config/index.d.ts +3 -0
  99. package/dist/bundler-config/index.d.ts.map +1 -0
  100. package/dist/bundler-config/index.js +190 -0
  101. package/dist/colors.cjs +60 -0
  102. package/dist/colors.d.ts +6 -0
  103. package/dist/colors.d.ts.map +1 -0
  104. package/dist/colors.js +40 -0
  105. package/dist/{config/index.cjs → config.cjs} +28 -21
  106. package/dist/{config/index.d.ts → config.d.ts} +4 -3
  107. package/dist/config.d.ts.map +1 -0
  108. package/dist/{config/index.js → config.js} +22 -23
  109. package/dist/constants.cjs +86 -0
  110. package/dist/constants.d.ts +25 -0
  111. package/dist/constants.d.ts.map +1 -0
  112. package/dist/constants.js +61 -0
  113. package/dist/createService.cjs +65 -0
  114. package/dist/createService.d.ts +8 -0
  115. package/dist/createService.d.ts.map +1 -0
  116. package/dist/createService.js +41 -0
  117. package/dist/index.cjs +27 -48
  118. package/dist/index.d.ts +7 -7
  119. package/dist/index.d.ts.map +1 -1
  120. package/dist/index.js +8 -51
  121. package/dist/lightningcss/cache.cjs +36 -0
  122. package/dist/lightningcss/cache.d.ts +2 -0
  123. package/dist/lightningcss/cache.d.ts.map +1 -0
  124. package/dist/lightningcss/cache.js +22 -0
  125. package/dist/lightningcss/index.cjs +21 -0
  126. package/dist/lightningcss/index.d.ts +2 -0
  127. package/dist/lightningcss/index.d.ts.map +1 -0
  128. package/dist/lightningcss/index.js +10 -0
  129. package/dist/lightningcss/loader.cjs +56 -0
  130. package/dist/lightningcss/loader.d.ts +5 -0
  131. package/dist/lightningcss/loader.d.ts.map +1 -0
  132. package/dist/lightningcss/loader.js +36 -0
  133. package/dist/lightningcss/minimizer.cjs +114 -0
  134. package/dist/lightningcss/minimizer.d.ts +11 -0
  135. package/dist/lightningcss/minimizer.d.ts.map +1 -0
  136. package/dist/lightningcss/minimizer.js +90 -0
  137. package/dist/logger.cjs +103 -0
  138. package/dist/logger.d.ts +3 -0
  139. package/dist/logger.d.ts.map +1 -0
  140. package/dist/logger.js +79 -0
  141. package/dist/openBrowser.cjs +85 -0
  142. package/dist/openBrowser.d.ts +2 -0
  143. package/dist/openBrowser.d.ts.map +1 -0
  144. package/dist/openBrowser.js +61 -0
  145. package/dist/plugin-progress/rspack.cjs +74 -0
  146. package/dist/plugin-progress/rspack.d.ts +9 -0
  147. package/dist/plugin-progress/rspack.d.ts.map +1 -0
  148. package/dist/plugin-progress/rspack.js +50 -0
  149. package/dist/plugin-progress/webpack.cjs +84 -0
  150. package/dist/plugin-progress/webpack.d.ts +9 -0
  151. package/dist/plugin-progress/webpack.d.ts.map +1 -0
  152. package/dist/plugin-progress/webpack.js +60 -0
  153. package/dist/plugin.cjs +33 -0
  154. package/dist/plugin.d.ts +3 -0
  155. package/dist/plugin.d.ts.map +1 -0
  156. package/dist/plugin.js +19 -0
  157. package/dist/progressBar.cjs +70 -0
  158. package/dist/progressBar.d.ts +14 -0
  159. package/dist/progressBar.d.ts.map +1 -0
  160. package/dist/progressBar.js +46 -0
  161. package/dist/reporter.cjs +133 -0
  162. package/dist/reporter.d.ts +8 -0
  163. package/dist/reporter.d.ts.map +1 -0
  164. package/dist/reporter.js +109 -0
  165. package/dist/run/build.cjs +77 -0
  166. package/dist/run/build.d.ts +3 -0
  167. package/dist/run/build.d.ts.map +1 -0
  168. package/dist/run/build.js +53 -0
  169. package/dist/run/dev.cjs +107 -0
  170. package/dist/run/dev.d.ts +3 -0
  171. package/dist/run/dev.d.ts.map +1 -0
  172. package/dist/run/dev.js +83 -0
  173. package/dist/run/index.cjs +23 -0
  174. package/dist/run/index.d.ts +3 -0
  175. package/dist/run/index.d.ts.map +1 -0
  176. package/dist/run/index.js +11 -0
  177. package/dist/thread-loader/WorkerError.cjs +41 -0
  178. package/dist/thread-loader/WorkerError.js +31 -0
  179. package/dist/thread-loader/WorkerPool.cjs +407 -0
  180. package/dist/thread-loader/WorkerPool.js +387 -0
  181. package/dist/thread-loader/index.cjs +100 -0
  182. package/dist/thread-loader/index.js +85 -0
  183. package/dist/thread-loader/readBuffer.cjs +55 -0
  184. package/dist/thread-loader/readBuffer.js +45 -0
  185. package/dist/thread-loader/serializer.cjs +46 -0
  186. package/dist/thread-loader/serializer.js +31 -0
  187. package/dist/thread-loader/utils.cjs +84 -0
  188. package/dist/thread-loader/utils.js +60 -0
  189. package/dist/thread-loader/worker.cjs +377 -0
  190. package/dist/thread-loader/worker.js +382 -0
  191. package/dist/thread-loader/workerPools.cjs +57 -0
  192. package/dist/thread-loader/workerPools.js +33 -0
  193. package/dist/typed-css-modules/index.cjs +21 -0
  194. package/dist/typed-css-modules/index.d.ts +2 -0
  195. package/dist/typed-css-modules/index.d.ts.map +1 -0
  196. package/dist/typed-css-modules/index.js +10 -0
  197. package/dist/typed-css-modules/loader.cjs +195 -0
  198. package/dist/typed-css-modules/loader.d.ts +10 -0
  199. package/dist/typed-css-modules/loader.d.ts.map +1 -0
  200. package/dist/typed-css-modules/loader.js +170 -0
  201. package/dist/typed-css-modules/plugin.cjs +96 -0
  202. package/dist/typed-css-modules/plugin.d.ts +16 -0
  203. package/dist/typed-css-modules/plugin.d.ts.map +1 -0
  204. package/dist/typed-css-modules/plugin.js +72 -0
  205. package/dist/typed-css-modules/utils.cjs +45 -0
  206. package/dist/typed-css-modules/utils.d.ts +6 -0
  207. package/dist/typed-css-modules/utils.d.ts.map +1 -0
  208. package/dist/typed-css-modules/utils.js +31 -0
  209. package/dist/types/chunkSplit.cjs +15 -0
  210. package/dist/types/chunkSplit.d.ts +35 -0
  211. package/dist/types/chunkSplit.d.ts.map +1 -0
  212. package/dist/types/chunkSplit.js +9 -0
  213. package/dist/types/config.cjs +15 -0
  214. package/dist/types/config.d.ts +176 -0
  215. package/dist/types/config.d.ts.map +1 -0
  216. package/dist/types/config.js +9 -0
  217. package/dist/types/index.cjs +29 -0
  218. package/dist/types/index.d.ts +16 -0
  219. package/dist/types/index.d.ts.map +1 -0
  220. package/dist/types/index.js +14 -0
  221. package/dist/types/lightningcss.cjs +15 -0
  222. package/dist/types/lightningcss.d.ts +11 -0
  223. package/dist/types/lightningcss.d.ts.map +1 -0
  224. package/dist/types/lightningcss.js +9 -0
  225. package/dist/types/logger.cjs +35 -0
  226. package/dist/types/logger.d.ts +16 -0
  227. package/dist/types/logger.d.ts.map +1 -0
  228. package/dist/types/logger.js +21 -0
  229. package/dist/types/plugin.cjs +15 -0
  230. package/dist/types/plugin.d.ts +18 -0
  231. package/dist/types/plugin.d.ts.map +1 -0
  232. package/dist/types/plugin.js +9 -0
  233. package/dist/utils.cjs +293 -0
  234. package/dist/utils.d.ts +39 -0
  235. package/dist/utils.d.ts.map +1 -0
  236. package/dist/utils.js +242 -0
  237. package/package.json +95 -6
  238. package/dist/config/index.d.ts.map +0 -1
@@ -0,0 +1,387 @@
1
+ import { createRequire } from 'node:module';
2
+ var require = createRequire(import.meta['url']);
3
+
4
+ import path from "path";
5
+ import { fileURLToPath } from "url";
6
+ var getFilename = () => fileURLToPath(import.meta.url);
7
+ var getDirname = () => path.dirname(getFilename());
8
+ var __dirname = /* @__PURE__ */ getDirname();
9
+ var __filename = /* @__PURE__ */ getFilename();
10
+ import childProcess from "node:child_process";
11
+ const asyncMapSeries = require("neo-async/mapSeries.js");
12
+ const asyncQueue = require("neo-async/queue.js");
13
+ import WorkerError from "./WorkerError.js";
14
+ import readBuffer from "./readBuffer.js";
15
+ import { replacer, reviver } from "./serializer.js";
16
+ const workerPath = require.resolve("./worker");
17
+ let workerId = 0;
18
+ class PoolWorker {
19
+ constructor(options, onJobDone) {
20
+ this.disposed = false;
21
+ this.nextJobId = 0;
22
+ this.jobs = /* @__PURE__ */ Object.create(null);
23
+ this.activeJobs = 0;
24
+ this.onJobDone = onJobDone;
25
+ this.id = workerId;
26
+ workerId += 1;
27
+ const sanitizedNodeArgs = (options.nodeArgs || []).filter((opt) => !!opt);
28
+ this.worker = childProcess.spawn(
29
+ process.execPath,
30
+ [].concat(sanitizedNodeArgs).concat(workerPath, options.parallelJobs),
31
+ {
32
+ detached: true,
33
+ stdio: ["ignore", "pipe", "pipe", "pipe", "pipe"]
34
+ }
35
+ );
36
+ this.worker.unref();
37
+ if (!this.worker.stdio) {
38
+ throw new Error(
39
+ `Failed to create the worker pool with workerId: ${workerId} and ${""}configuration: ${JSON.stringify(
40
+ options
41
+ )}. Please verify if you hit the OS open files limit.`
42
+ );
43
+ }
44
+ const [, , , readPipe, writePipe] = this.worker.stdio;
45
+ this.readPipe = readPipe;
46
+ this.writePipe = writePipe;
47
+ this.listenStdOutAndErrFromWorker(this.worker.stdout, this.worker.stderr);
48
+ this.readNextMessage();
49
+ }
50
+ listenStdOutAndErrFromWorker(workerStdout, workerStderr) {
51
+ if (workerStdout) {
52
+ workerStdout.on("data", this.writeToStdout);
53
+ }
54
+ if (workerStderr) {
55
+ workerStderr.on("data", this.writeToStderr);
56
+ }
57
+ }
58
+ ignoreStdOutAndErrFromWorker(workerStdout, workerStderr) {
59
+ if (workerStdout) {
60
+ workerStdout.removeListener("data", this.writeToStdout);
61
+ }
62
+ if (workerStderr) {
63
+ workerStderr.removeListener("data", this.writeToStderr);
64
+ }
65
+ }
66
+ writeToStdout(data) {
67
+ if (!this.disposed) {
68
+ process.stdout.write(data);
69
+ }
70
+ }
71
+ writeToStderr(data) {
72
+ if (!this.disposed) {
73
+ process.stderr.write(data);
74
+ }
75
+ }
76
+ run(data, callback) {
77
+ const jobId = this.nextJobId;
78
+ this.nextJobId += 1;
79
+ this.jobs[jobId] = { data, callback };
80
+ this.activeJobs += 1;
81
+ this.writeJson({
82
+ type: "job",
83
+ id: jobId,
84
+ data
85
+ });
86
+ }
87
+ warmup(requires) {
88
+ this.writeJson({
89
+ type: "warmup",
90
+ requires
91
+ });
92
+ }
93
+ writeJson(data) {
94
+ const lengthBuffer = Buffer.alloc(4);
95
+ const messageBuffer = Buffer.from(JSON.stringify(data, replacer), "utf-8");
96
+ lengthBuffer.writeInt32BE(messageBuffer.length, 0);
97
+ this.writePipe.write(lengthBuffer);
98
+ this.writePipe.write(messageBuffer);
99
+ }
100
+ writeEnd() {
101
+ const lengthBuffer = Buffer.alloc(4);
102
+ lengthBuffer.writeInt32BE(0, 0);
103
+ this.writePipe.write(lengthBuffer);
104
+ }
105
+ readNextMessage() {
106
+ this.state = "read length";
107
+ this.readBuffer(4, (lengthReadError, lengthBuffer) => {
108
+ if (lengthReadError) {
109
+ console.error(`Failed to communicate with worker (read length) ${lengthReadError}`);
110
+ return;
111
+ }
112
+ this.state = "length read";
113
+ const length = lengthBuffer.readInt32BE(0);
114
+ this.state = "read message";
115
+ this.readBuffer(length, (messageError, messageBuffer) => {
116
+ if (messageError) {
117
+ console.error(`Failed to communicate with worker (read message) ${messageError}`);
118
+ return;
119
+ }
120
+ this.state = "message read";
121
+ const messageString = messageBuffer.toString("utf-8");
122
+ const message = JSON.parse(messageString, reviver);
123
+ this.state = "process message";
124
+ this.onWorkerMessage(message, (err) => {
125
+ if (err) {
126
+ console.error(`Failed to communicate with worker (process message) ${err}`);
127
+ return;
128
+ }
129
+ this.state = "soon next";
130
+ setImmediate(() => this.readNextMessage());
131
+ });
132
+ });
133
+ });
134
+ }
135
+ onWorkerMessage(message, finalCallback) {
136
+ const { type, id } = message;
137
+ switch (type) {
138
+ case "job": {
139
+ const { data, error, result } = message;
140
+ asyncMapSeries(
141
+ data,
142
+ (length, callback) => this.readBuffer(length, callback),
143
+ (eachErr, buffers) => {
144
+ const { callback: jobCallback } = this.jobs[id];
145
+ const callback = (err, arg) => {
146
+ if (jobCallback) {
147
+ delete this.jobs[id];
148
+ this.activeJobs -= 1;
149
+ this.onJobDone();
150
+ if (err) {
151
+ jobCallback(err instanceof Error ? err : new Error(err), arg);
152
+ } else {
153
+ jobCallback(null, arg);
154
+ }
155
+ }
156
+ finalCallback();
157
+ };
158
+ if (eachErr) {
159
+ callback(eachErr);
160
+ return;
161
+ }
162
+ let bufferPosition = 0;
163
+ if (result.result) {
164
+ result.result = result.result.map((r) => {
165
+ if (r.buffer) {
166
+ const buffer = buffers[bufferPosition];
167
+ bufferPosition += 1;
168
+ if (r.string) {
169
+ return buffer.toString("utf-8");
170
+ }
171
+ return buffer;
172
+ }
173
+ return r.data;
174
+ });
175
+ }
176
+ if (error) {
177
+ callback(this.fromErrorObj(error), result);
178
+ return;
179
+ }
180
+ callback(null, result);
181
+ }
182
+ );
183
+ break;
184
+ }
185
+ case "loadModule": {
186
+ const { request, questionId } = message;
187
+ const { data } = this.jobs[id];
188
+ data.loadModule(request, (error, source, sourceMap) => {
189
+ this.writeJson({
190
+ type: "result",
191
+ id: questionId,
192
+ error: error ? {
193
+ message: error.message,
194
+ details: error.details,
195
+ missing: error.missing
196
+ } : null,
197
+ result: [
198
+ source,
199
+ sourceMap
200
+ // TODO: Serialize module?
201
+ // module,
202
+ ]
203
+ });
204
+ });
205
+ finalCallback();
206
+ break;
207
+ }
208
+ case "resolve": {
209
+ const { context, request, options, questionId } = message;
210
+ const { data } = this.jobs[id];
211
+ if (options) {
212
+ data.getResolve(options)(context, request, (error, result) => {
213
+ this.writeJson({
214
+ type: "result",
215
+ id: questionId,
216
+ error: error ? {
217
+ message: error.message,
218
+ details: error.details,
219
+ missing: error.missing
220
+ } : null,
221
+ result
222
+ });
223
+ });
224
+ } else {
225
+ data.resolve(context, request, (error, result) => {
226
+ this.writeJson({
227
+ type: "result",
228
+ id: questionId,
229
+ error: error ? {
230
+ message: error.message,
231
+ details: error.details,
232
+ missing: error.missing
233
+ } : null,
234
+ result
235
+ });
236
+ });
237
+ }
238
+ finalCallback();
239
+ break;
240
+ }
241
+ case "emitWarning": {
242
+ const { data } = message;
243
+ const { data: jobData } = this.jobs[id];
244
+ jobData.emitWarning(this.fromErrorObj(data));
245
+ finalCallback();
246
+ break;
247
+ }
248
+ case "emitError": {
249
+ const { data } = message;
250
+ const { data: jobData } = this.jobs[id];
251
+ jobData.emitError(this.fromErrorObj(data));
252
+ finalCallback();
253
+ break;
254
+ }
255
+ case "getLogger": {
256
+ const { data } = message;
257
+ const { data: jobData } = this.jobs[id];
258
+ if (!Object.hasOwnProperty.call(jobData.loggers, data.name)) {
259
+ jobData.loggers[data.name] = jobData.getLogger(data.name);
260
+ }
261
+ finalCallback();
262
+ break;
263
+ }
264
+ case "logger": {
265
+ const { data } = message;
266
+ const { data: jobData } = this.jobs[id];
267
+ jobData.loggers[data.name][data.severity](data.message);
268
+ finalCallback();
269
+ break;
270
+ }
271
+ default: {
272
+ console.error(`Unexpected worker message ${type} in WorkerPool.`);
273
+ finalCallback();
274
+ break;
275
+ }
276
+ }
277
+ }
278
+ fromErrorObj(arg) {
279
+ let obj;
280
+ if (typeof arg === "string") {
281
+ obj = { message: arg };
282
+ } else {
283
+ obj = arg;
284
+ }
285
+ return new WorkerError(obj, this.id);
286
+ }
287
+ readBuffer(length, callback) {
288
+ readBuffer(this.readPipe, length, callback);
289
+ }
290
+ dispose() {
291
+ if (!this.disposed) {
292
+ this.disposed = true;
293
+ this.ignoreStdOutAndErrFromWorker(this.worker.stdout, this.worker.stderr);
294
+ this.writeEnd();
295
+ }
296
+ }
297
+ }
298
+ class WorkerPool {
299
+ constructor(options) {
300
+ this.options = options || {};
301
+ this.numberOfWorkers = options.numberOfWorkers;
302
+ this.poolTimeout = options.poolTimeout;
303
+ this.workerNodeArgs = options.workerNodeArgs;
304
+ this.workerParallelJobs = options.workerParallelJobs;
305
+ this.workers = /* @__PURE__ */ new Set();
306
+ this.activeJobs = 0;
307
+ this.timeout = null;
308
+ this.poolQueue = asyncQueue(this.distributeJob.bind(this), options.poolParallelJobs);
309
+ this.terminated = false;
310
+ this.setupLifeCycle();
311
+ }
312
+ isAbleToRun() {
313
+ return !this.terminated;
314
+ }
315
+ terminate() {
316
+ if (this.terminated) {
317
+ return;
318
+ }
319
+ this.terminated = true;
320
+ this.poolQueue.kill();
321
+ this.disposeWorkers(true);
322
+ }
323
+ setupLifeCycle() {
324
+ process.on("exit", () => {
325
+ this.terminate();
326
+ });
327
+ }
328
+ run(data, callback) {
329
+ if (this.timeout) {
330
+ clearTimeout(this.timeout);
331
+ this.timeout = null;
332
+ }
333
+ this.activeJobs += 1;
334
+ this.poolQueue.push(data, callback);
335
+ }
336
+ distributeJob(data, callback) {
337
+ let bestWorker;
338
+ for (const worker of this.workers) {
339
+ if (!bestWorker || worker.activeJobs < bestWorker.activeJobs) {
340
+ bestWorker = worker;
341
+ }
342
+ }
343
+ if (bestWorker && (bestWorker.activeJobs === 0 || this.workers.size >= this.numberOfWorkers)) {
344
+ bestWorker.run(data, callback);
345
+ return;
346
+ }
347
+ const newWorker = this.createWorker();
348
+ newWorker.run(data, callback);
349
+ }
350
+ createWorker() {
351
+ const newWorker = new PoolWorker(
352
+ {
353
+ nodeArgs: this.workerNodeArgs,
354
+ parallelJobs: this.workerParallelJobs
355
+ },
356
+ () => this.onJobDone()
357
+ );
358
+ this.workers.add(newWorker);
359
+ return newWorker;
360
+ }
361
+ warmup(requires) {
362
+ while (this.workers.size < this.numberOfWorkers) {
363
+ this.createWorker().warmup(requires);
364
+ }
365
+ }
366
+ onJobDone() {
367
+ this.activeJobs -= 1;
368
+ if (this.activeJobs === 0 && Number.isFinite(this.poolTimeout)) {
369
+ this.timeout = setTimeout(() => this.disposeWorkers(), this.poolTimeout);
370
+ }
371
+ }
372
+ disposeWorkers(fromTerminate) {
373
+ if (!this.options.poolRespawn && !fromTerminate) {
374
+ this.terminate();
375
+ return;
376
+ }
377
+ if (this.activeJobs === 0 || fromTerminate) {
378
+ for (const worker of this.workers) {
379
+ worker.dispose();
380
+ }
381
+ this.workers.clear();
382
+ }
383
+ }
384
+ }
385
+ export {
386
+ WorkerPool as default
387
+ };
@@ -0,0 +1,100 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var thread_loader_exports = {};
19
+ __export(thread_loader_exports, {
20
+ pitch: () => pitch,
21
+ warmup: () => warmup
22
+ });
23
+ module.exports = __toCommonJS(thread_loader_exports);
24
+ var import_workerPools = require("./workerPools.cjs");
25
+ function pitch() {
26
+ const options = this.getOptions();
27
+ const workerPool = (0, import_workerPools.getPool)(options);
28
+ if (!workerPool.isAbleToRun()) {
29
+ return;
30
+ }
31
+ const callback = this.async();
32
+ workerPool.run(
33
+ {
34
+ loaders: this.loaders.slice(this.loaderIndex + 1).map((l) => {
35
+ return {
36
+ loader: l.path,
37
+ options: l.options,
38
+ ident: l.ident
39
+ };
40
+ }),
41
+ _compiler: {
42
+ fsStartTime: this._compiler.fsStartTime,
43
+ options: { plugins: [] }
44
+ },
45
+ _compilation: {
46
+ outputOptions: {
47
+ hashSalt: this._compilation.outputOptions.hashSalt,
48
+ hashFunction: this._compilation.outputOptions.hashFunction,
49
+ hashDigest: this._compilation.outputOptions.hashDigest,
50
+ hashDigestLength: this._compilation.outputOptions.hashDigestLength
51
+ },
52
+ options: {
53
+ devtool: this._compilation?.options?.devtool
54
+ }
55
+ },
56
+ resourcePath: this.resourcePath,
57
+ resource: this.resourcePath + (this.resourceQuery || ""),
58
+ sourceMap: this.sourceMap,
59
+ emitError: this.emitError,
60
+ emitWarning: this.emitWarning,
61
+ loadModule: this.loadModule,
62
+ resolve: this.resolve,
63
+ getResolve: this.getResolve,
64
+ target: this.target,
65
+ minimize: this.minimize,
66
+ resourceQuery: this.resourceQuery,
67
+ optionsContext: this.rootContext || this.options.context,
68
+ rootContext: this.rootContext,
69
+ getLogger: this.getLogger,
70
+ loggers: {}
71
+ },
72
+ (err, r) => {
73
+ if (r) {
74
+ r.fileDependencies.forEach((d) => this.addDependency(d));
75
+ r.contextDependencies.forEach((d) => this.addContextDependency(d));
76
+ r.missingDependencies.forEach((d) => this.addMissingDependency(d));
77
+ r.buildDependencies.forEach(
78
+ (d) => (
79
+ // Compatibility with webpack v4
80
+ this.addBuildDependency ? this.addBuildDependency(d) : this.addDependency(d)
81
+ )
82
+ );
83
+ }
84
+ if (err) {
85
+ callback(err);
86
+ return;
87
+ }
88
+ callback(null, ...r.result);
89
+ }
90
+ );
91
+ }
92
+ function warmup(options, requires) {
93
+ const workerPool = (0, import_workerPools.getPool)(options);
94
+ workerPool.warmup(requires);
95
+ }
96
+ // Annotate the CommonJS export names for ESM import in node:
97
+ 0 && (module.exports = {
98
+ pitch,
99
+ warmup
100
+ });
@@ -0,0 +1,85 @@
1
+ import { createRequire } from 'node:module';
2
+ var require = createRequire(import.meta['url']);
3
+
4
+ import path from "path";
5
+ import { fileURLToPath } from "url";
6
+ var getFilename = () => fileURLToPath(import.meta.url);
7
+ var getDirname = () => path.dirname(getFilename());
8
+ var __dirname = /* @__PURE__ */ getDirname();
9
+ var __filename = /* @__PURE__ */ getFilename();
10
+ import { getPool } from "./workerPools.js";
11
+ function pitch() {
12
+ const options = this.getOptions();
13
+ const workerPool = getPool(options);
14
+ if (!workerPool.isAbleToRun()) {
15
+ return;
16
+ }
17
+ const callback = this.async();
18
+ workerPool.run(
19
+ {
20
+ loaders: this.loaders.slice(this.loaderIndex + 1).map((l) => {
21
+ return {
22
+ loader: l.path,
23
+ options: l.options,
24
+ ident: l.ident
25
+ };
26
+ }),
27
+ _compiler: {
28
+ fsStartTime: this._compiler.fsStartTime,
29
+ options: { plugins: [] }
30
+ },
31
+ _compilation: {
32
+ outputOptions: {
33
+ hashSalt: this._compilation.outputOptions.hashSalt,
34
+ hashFunction: this._compilation.outputOptions.hashFunction,
35
+ hashDigest: this._compilation.outputOptions.hashDigest,
36
+ hashDigestLength: this._compilation.outputOptions.hashDigestLength
37
+ },
38
+ options: {
39
+ devtool: this._compilation?.options?.devtool
40
+ }
41
+ },
42
+ resourcePath: this.resourcePath,
43
+ resource: this.resourcePath + (this.resourceQuery || ""),
44
+ sourceMap: this.sourceMap,
45
+ emitError: this.emitError,
46
+ emitWarning: this.emitWarning,
47
+ loadModule: this.loadModule,
48
+ resolve: this.resolve,
49
+ getResolve: this.getResolve,
50
+ target: this.target,
51
+ minimize: this.minimize,
52
+ resourceQuery: this.resourceQuery,
53
+ optionsContext: this.rootContext || this.options.context,
54
+ rootContext: this.rootContext,
55
+ getLogger: this.getLogger,
56
+ loggers: {}
57
+ },
58
+ (err, r) => {
59
+ if (r) {
60
+ r.fileDependencies.forEach((d) => this.addDependency(d));
61
+ r.contextDependencies.forEach((d) => this.addContextDependency(d));
62
+ r.missingDependencies.forEach((d) => this.addMissingDependency(d));
63
+ r.buildDependencies.forEach(
64
+ (d) => (
65
+ // Compatibility with webpack v4
66
+ this.addBuildDependency ? this.addBuildDependency(d) : this.addDependency(d)
67
+ )
68
+ );
69
+ }
70
+ if (err) {
71
+ callback(err);
72
+ return;
73
+ }
74
+ callback(null, ...r.result);
75
+ }
76
+ );
77
+ }
78
+ function warmup(options, requires) {
79
+ const workerPool = getPool(options);
80
+ workerPool.warmup(requires);
81
+ }
82
+ export {
83
+ pitch,
84
+ warmup
85
+ };
@@ -0,0 +1,55 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var readBuffer_exports = {};
19
+ __export(readBuffer_exports, {
20
+ default: () => readBuffer
21
+ });
22
+ module.exports = __toCommonJS(readBuffer_exports);
23
+ function readBuffer(pipe, length, callback) {
24
+ if (length === 0) {
25
+ callback(null, Buffer.alloc(0));
26
+ return;
27
+ }
28
+ let remainingLength = length;
29
+ const buffers = [];
30
+ const readChunk = () => {
31
+ const onChunk = (arg) => {
32
+ let chunk = arg;
33
+ let overflow;
34
+ if (chunk.length > remainingLength) {
35
+ overflow = chunk.slice(remainingLength);
36
+ chunk = chunk.slice(0, remainingLength);
37
+ remainingLength = 0;
38
+ } else {
39
+ remainingLength -= chunk.length;
40
+ }
41
+ buffers.push(chunk);
42
+ if (remainingLength === 0) {
43
+ pipe.removeListener("data", onChunk);
44
+ pipe.pause();
45
+ if (overflow) {
46
+ pipe.unshift(overflow);
47
+ }
48
+ callback(null, Buffer.concat(buffers, length));
49
+ }
50
+ };
51
+ pipe.on("data", onChunk);
52
+ pipe.resume();
53
+ };
54
+ readChunk();
55
+ }
@@ -0,0 +1,45 @@
1
+ import { createRequire } from 'node:module';
2
+ var require = createRequire(import.meta['url']);
3
+
4
+ import path from "path";
5
+ import { fileURLToPath } from "url";
6
+ var getFilename = () => fileURLToPath(import.meta.url);
7
+ var getDirname = () => path.dirname(getFilename());
8
+ var __dirname = /* @__PURE__ */ getDirname();
9
+ var __filename = /* @__PURE__ */ getFilename();
10
+ function readBuffer(pipe, length, callback) {
11
+ if (length === 0) {
12
+ callback(null, Buffer.alloc(0));
13
+ return;
14
+ }
15
+ let remainingLength = length;
16
+ const buffers = [];
17
+ const readChunk = () => {
18
+ const onChunk = (arg) => {
19
+ let chunk = arg;
20
+ let overflow;
21
+ if (chunk.length > remainingLength) {
22
+ overflow = chunk.slice(remainingLength);
23
+ chunk = chunk.slice(0, remainingLength);
24
+ remainingLength = 0;
25
+ } else {
26
+ remainingLength -= chunk.length;
27
+ }
28
+ buffers.push(chunk);
29
+ if (remainingLength === 0) {
30
+ pipe.removeListener("data", onChunk);
31
+ pipe.pause();
32
+ if (overflow) {
33
+ pipe.unshift(overflow);
34
+ }
35
+ callback(null, Buffer.concat(buffers, length));
36
+ }
37
+ };
38
+ pipe.on("data", onChunk);
39
+ pipe.resume();
40
+ };
41
+ readChunk();
42
+ }
43
+ export {
44
+ readBuffer as default
45
+ };