@rspack/core 1.3.15 → 1.4.0-beta.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 (49) hide show
  1. package/compiled/@swc/types/index.d.ts +18 -2
  2. package/compiled/@swc/types/package.json +1 -1
  3. package/compiled/tinypool/README.md +4 -196
  4. package/compiled/tinypool/dist/common-Qw-RoVFD.js +28 -0
  5. package/compiled/tinypool/dist/entry/process.d.ts +1 -2
  6. package/compiled/tinypool/dist/entry/process.js +63 -83
  7. package/compiled/tinypool/dist/entry/utils.d.ts +3 -1
  8. package/compiled/tinypool/dist/entry/utils.js +3 -9
  9. package/compiled/tinypool/dist/entry/worker.d.ts +1 -2
  10. package/compiled/tinypool/dist/entry/worker.js +66 -94
  11. package/compiled/tinypool/dist/index.d.ts +132 -125
  12. package/compiled/tinypool/dist/index.js +771 -1035
  13. package/compiled/tinypool/dist/utils-B--2TaWv.js +38 -0
  14. package/compiled/tinypool/dist/utils-De75vAgL.js +10 -0
  15. package/compiled/tinypool/package.json +6 -22
  16. package/compiled/zod/dist/types/v4/classic/schemas.d.ts +19 -14
  17. package/compiled/zod/dist/types/v4/core/api.d.ts +5 -4
  18. package/compiled/zod/dist/types/v4/core/checks.d.ts +1 -1
  19. package/compiled/zod/dist/types/v4/core/core.d.ts +1 -1
  20. package/compiled/zod/dist/types/v4/core/registries.d.ts +3 -1
  21. package/compiled/zod/dist/types/v4/core/schemas.d.ts +33 -39
  22. package/compiled/zod/dist/types/v4/core/to-json-schema.d.ts +2 -2
  23. package/compiled/zod/dist/types/v4/core/util.d.ts +1 -1
  24. package/compiled/zod/dist/types/v4/locales/index.d.ts +1 -0
  25. package/compiled/zod/dist/types/v4/locales/ps.d.ts +4 -0
  26. package/compiled/zod/dist/types/v4/mini/schemas.d.ts +77 -125
  27. package/compiled/zod/index.js +33 -33
  28. package/compiled/zod/package.json +1 -1
  29. package/dist/BuildInfo.d.ts +17 -0
  30. package/dist/FileSystem.d.ts +26 -3
  31. package/dist/Module.d.ts +1 -13
  32. package/dist/builtin-loader/swc/types.d.ts +255 -255
  33. package/dist/config/devServer.d.ts +10 -10
  34. package/dist/config/normalization.d.ts +1 -0
  35. package/dist/config/types.d.ts +10 -1
  36. package/dist/config/utils.d.ts +1 -0
  37. package/dist/config/zod.d.ts +1638 -1068
  38. package/dist/cssExtractLoader.js +5 -5
  39. package/dist/exports.d.ts +2 -1
  40. package/dist/index.js +544 -470
  41. package/dist/loader-runner/index.d.ts +0 -9
  42. package/dist/trace/index.d.ts +16 -18
  43. package/dist/worker.js +2 -2
  44. package/module.d.ts +1 -1
  45. package/package.json +8 -8
  46. package/compiled/tinypool/dist/chunk-6LX4VMOV.js +0 -31
  47. package/compiled/tinypool/dist/chunk-ACQHDOFQ.js +0 -12
  48. package/compiled/tinypool/dist/chunk-E2J7JLFN.js +0 -53
  49. package/compiled/tinypool/dist/chunk-UBWFVGJX.js +0 -38
@@ -635,6 +635,14 @@ interface JscConfig {
635
635
  };
636
636
  minify?: JsMinifyOptions;
637
637
  preserveAllComments?: boolean;
638
+ output?: {
639
+ /**
640
+ * This can be used to keep the output ascii-only.
641
+ * If this option is set, `minify.format.asciiOnly` will be ignored.
642
+ * @default 'utf8'
643
+ */
644
+ charset?: 'utf8' | 'ascii';
645
+ };
638
646
  }
639
647
  type JscTarget = "es3" | "es5" | "es2015" | "es2016" | "es2017" | "es2018" | "es2019" | "es2020" | "es2021" | "es2022" | "es2023" | "es2024" | "esnext";
640
648
  type ParserConfig = TsParserConfig | EsParserConfig;
@@ -774,6 +782,10 @@ interface TransformConfig {
774
782
  * https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax
775
783
  */
776
784
  verbatimModuleSyntax?: boolean;
785
+ /**
786
+ * Native class properties support
787
+ */
788
+ nativeClassProperties?: boolean;
777
789
  }
778
790
  interface ReactConfig {
779
791
  /**
@@ -1059,6 +1071,10 @@ interface BaseModuleConfig {
1059
1071
  ignoreDynamic?: boolean;
1060
1072
  allowTopLevelThis?: boolean;
1061
1073
  preserveImportMeta?: boolean;
1074
+ /**
1075
+ * If set to true, This will resolve top .mjs
1076
+ */
1077
+ resolveFully?: boolean;
1062
1078
  }
1063
1079
  interface Es6Config extends BaseModuleConfig {
1064
1080
  type: "es6";
@@ -2098,9 +2114,9 @@ interface Invalid extends Node, HasSpan {
2098
2114
  }
2099
2115
  type WasmAnalysisOptions = {
2100
2116
  parser?: ParserConfig;
2101
- module?: true | false | 'unknown';
2117
+ module?: true | false | "unknown";
2102
2118
  filename?: string;
2103
- errorFormat?: 'json' | 'normal';
2119
+ errorFormat?: "json" | "normal";
2104
2120
  cacheRoot?: string;
2105
2121
  plugins: WasmPlugin[];
2106
2122
  };
@@ -1 +1 @@
1
- {"name":"@swc/types","author":"강동윤 <kdy1997.dev@gmail.com>","version":"0.1.21","license":"Apache-2.0","types":"index.d.ts","type":"commonjs"}
1
+ {"name":"@swc/types","author":"강동윤 <kdy1997.dev@gmail.com>","version":"0.1.22","license":"Apache-2.0","types":"index.d.ts","type":"commonjs"}
@@ -2,7 +2,7 @@
2
2
 
3
3
  > Piscina: A fast, efficient Node.js Worker Thread Pool implementation
4
4
 
5
- Tinypool is a fork of piscina. What we try to achieve in this library, is to eliminate some dependencies and features that our target users don't need (currently, our main user will be Vitest). Tinypool's install size (38KB) can then be smaller than Piscina's install size (6MB). If you need features like [utilization](https://github.com/piscinajs/piscina#property-utilization-readonly) or [NAPI](https://github.com/piscinajs/piscina#thread-priority-on-linux-systems), [Piscina](https://github.com/piscinajs/piscina) is a better choice for you. We think that Piscina is an amazing library, and we may try to upstream some of the dependencies optimization in this fork.
5
+ Tinypool is a fork of piscina. What we try to achieve in this library, is to eliminate some dependencies and features that our target users don't need (currently, our main user will be Vitest). Tinypool's install size (38KB) can then be smaller than Piscina's install size (6MB). If you need features like [utilization](https://github.com/piscinajs/piscina#property-utilization-readonly) or OS-specific thread priority setting, [Piscina](https://github.com/piscinajs/piscina) is a better choice for you. We think that Piscina is an amazing library, and we may try to upstream some of the dependencies optimization in this fork.
6
6
 
7
7
  - ✅ Smaller install size, 38KB
8
8
  - ✅ Minimal
@@ -10,203 +10,11 @@ Tinypool is a fork of piscina. What we try to achieve in this library, is to eli
10
10
  - ✅ Physical cores instead of Logical cores with [physical-cpu-count](https://www.npmjs.com/package/physical-cpu-count)
11
11
  - ✅ Supports `worker_threads` and `child_process`
12
12
  - ❌ No utilization
13
- - ❌ No NAPI
13
+ - ❌ No OS-specific thread priority setting
14
14
 
15
15
  - Written in TypeScript, and ESM support only. For Node.js 18.x and higher.
16
16
 
17
17
  _In case you need more tiny libraries like tinypool or tinyspy, please consider submitting an [RFC](https://github.com/tinylibs/rfcs)_
18
18
 
19
- ## Example
20
-
21
- ### Using `node:worker_threads`
22
-
23
- #### Basic usage
24
-
25
- ```js
26
- // main.mjs
27
- import Tinypool from 'tinypool'
28
-
29
- const pool = new Tinypool({
30
- filename: new URL('./worker.mjs', import.meta.url).href,
31
- })
32
- const result = await pool.run({ a: 4, b: 6 })
33
- console.log(result) // Prints 10
34
-
35
- // Make sure to destroy pool once it's not needed anymore
36
- // This terminates all pool's idle workers
37
- await pool.destroy()
38
- ```
39
-
40
- ```js
41
- // worker.mjs
42
- export default ({ a, b }) => {
43
- return a + b
44
- }
45
- ```
46
-
47
- #### Main thread <-> worker thread communication
48
-
49
- <details>
50
- <summary>See code</summary>
51
-
52
- ```js
53
- // main.mjs
54
- import Tinypool from 'tinypool'
55
- import { MessageChannel } from 'node:worker_threads'
56
-
57
- const pool = new Tinypool({
58
- filename: new URL('./worker.mjs', import.meta.url).href,
59
- })
60
- const { port1, port2 } = new MessageChannel()
61
- const promise = pool.run({ port: port1 }, { transferList: [port1] })
62
-
63
- port2.on('message', (message) => console.log('Main thread received:', message))
64
- setTimeout(() => port2.postMessage('Hello from main thread!'), 1000)
65
-
66
- await promise
67
-
68
- port1.close()
69
- port2.close()
70
- ```
71
-
72
- ```js
73
- // worker.mjs
74
- export default ({ port }) => {
75
- return new Promise((resolve) => {
76
- port.on('message', (message) => {
77
- console.log('Worker received:', message)
78
-
79
- port.postMessage('Hello from worker thread!')
80
- resolve()
81
- })
82
- })
83
- }
84
- ```
85
-
86
- </details>
87
-
88
- ### Using `node:child_process`
89
-
90
- #### Basic usage
91
-
92
- <details>
93
- <summary>See code</summary>
94
-
95
- ```js
96
- // main.mjs
97
- import Tinypool from 'tinypool'
98
-
99
- const pool = new Tinypool({
100
- runtime: 'child_process',
101
- filename: new URL('./worker.mjs', import.meta.url).href,
102
- })
103
- const result = await pool.run({ a: 4, b: 6 })
104
- console.log(result) // Prints 10
105
- ```
106
-
107
- ```js
108
- // worker.mjs
109
- export default ({ a, b }) => {
110
- return a + b
111
- }
112
- ```
113
-
114
- </details>
115
-
116
- #### Main process <-> worker process communication
117
-
118
- <details>
119
- <summary>See code</summary>
120
-
121
- ```js
122
- // main.mjs
123
- import Tinypool from 'tinypool'
124
-
125
- const pool = new Tinypool({
126
- runtime: 'child_process',
127
- filename: new URL('./worker.mjs', import.meta.url).href,
128
- })
129
-
130
- const messages = []
131
- const listeners = []
132
- const channel = {
133
- onMessage: (listener) => listeners.push(listener),
134
- postMessage: (message) => messages.push(message),
135
- }
136
-
137
- const promise = pool.run({}, { channel })
138
-
139
- // Send message to worker
140
- setTimeout(
141
- () => listeners.forEach((listener) => listener('Hello from main process')),
142
- 1000
143
- )
144
-
145
- // Wait for task to finish
146
- await promise
147
-
148
- console.log(messages)
149
- // [{ received: 'Hello from main process', response: 'Hello from worker' }]
150
- ```
151
-
152
- ```js
153
- // worker.mjs
154
- export default async function run() {
155
- return new Promise((resolve) => {
156
- process.on('message', (message) => {
157
- // Ignore Tinypool's internal messages
158
- if (message?.__tinypool_worker_message__) return
159
-
160
- process.send({ received: message, response: 'Hello from worker' })
161
- resolve()
162
- })
163
- })
164
- }
165
- ```
166
-
167
- </details>
168
-
169
- ## API
170
-
171
- We have a similar API to Piscina, so for more information, you can read Piscina's detailed [documentation](https://github.com/piscinajs/piscina#piscina---the-nodejs-worker-pool) and apply the same techniques here.
172
-
173
- ### Tinypool specific APIs
174
-
175
- #### Pool constructor options
176
-
177
- - `isolateWorkers`: Disabled by default. Always starts with a fresh worker when running tasks to isolate the environment.
178
- - `terminateTimeout`: Disabled by default. If terminating a worker takes `terminateTimeout` amount of milliseconds to execute, an error is raised.
179
- - `maxMemoryLimitBeforeRecycle`: Disabled by default. When defined, the worker's heap memory usage is compared against this value after task has been finished. If the current memory usage exceeds this limit, worker is terminated and a new one is started to take its place. This option is useful when your tasks leak memory and you don't want to enable `isolateWorkers` option.
180
- - `runtime`: Used to pick worker runtime. Default value is `worker_threads`.
181
- - `worker_threads`: Runs workers in [`node:worker_threads`](https://nodejs.org/api/worker_threads.html). For `main thread <-> worker thread` communication you can use [`MessagePort`](https://nodejs.org/api/worker_threads.html#class-messageport) in the `pool.run()` method's [`transferList` option](https://nodejs.org/api/worker_threads.html#portpostmessagevalue-transferlist). See [example](#main-thread---worker-thread-communication).
182
- - `child_process`: Runs workers in [`node:child_process`](https://nodejs.org/api/child_process.html). For `main thread <-> worker process` communication you can use `TinypoolChannel` in the `pool.run()` method's `channel` option. For filtering out the Tinypool's internal messages see `TinypoolWorkerMessage`. See [example](#main-process---worker-process-communication).
183
-
184
- #### Pool methods
185
-
186
- - `cancelPendingTasks()`: Gracefully cancels all pending tasks without stopping or interfering with on-going tasks. This method is useful when your tasks may have side effects and should not be terminated forcefully during task execution. If your tasks don't have any side effects you may want to use [`{ signal }`](https://github.com/piscinajs/piscina#cancelable-tasks) option for forcefully terminating all tasks, including the on-going ones, instead.
187
- - `recycleWorkers(options)`: Waits for all current tasks to finish and re-creates all workers. Can be used to force isolation imperatively even when `isolateWorkers` is disabled. Accepts `{ runtime }` option as argument.
188
-
189
- #### Exports
190
-
191
- - `workerId`: Each worker now has an id ( <= `maxThreads`) that can be imported from `tinypool` in the worker itself (or `process.__tinypool_state__.workerId`).
192
-
193
- ## Authors
194
-
195
- | <a href="https://github.com/Aslemammad"> <img width='150' src="https://avatars.githubusercontent.com/u/37929992?v=4" /><br> Mohammad Bagher </a> |
196
- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
197
-
198
- ## Sponsors
199
-
200
- Your sponsorship can make a huge difference in continuing our work in open source!
201
-
202
- <p align="center">
203
- <a href="https://cdn.jsdelivr.net/gh/aslemammad/static/sponsors.svg">
204
- <img src='https://cdn.jsdelivr.net/gh/aslemammad/static/sponsors.svg'/>
205
- </a>
206
- </p>
207
-
208
- ## Credits
209
-
210
- [The Vitest team](https://vitest.dev/) for giving me the chance of creating and maintaing this project for vitest.
211
-
212
- [Piscina](https://github.com/piscinajs/piscina), because Tinypool is not more than a friendly fork of piscina.
19
+ ## Docs
20
+ Read **[full docs](https://github.com/tinylibs/tinypool#readme)** on GitHub.
@@ -0,0 +1,28 @@
1
+ //#region src/common.ts
2
+ const kMovable = Symbol("Tinypool.kMovable");
3
+ const kTransferable = Symbol.for("Tinypool.transferable");
4
+ const kValue = Symbol.for("Tinypool.valueOf");
5
+ const kQueueOptions = Symbol.for("Tinypool.queueOptions");
6
+ function isTransferable(value) {
7
+ return value != null && typeof value === "object" && kTransferable in value && kValue in value;
8
+ }
9
+ function isMovable(value) {
10
+ return isTransferable(value) && value[kMovable] === true;
11
+ }
12
+ function markMovable(value) {
13
+ Object.defineProperty(value, kMovable, {
14
+ enumerable: false,
15
+ configurable: true,
16
+ writable: true,
17
+ value: true
18
+ });
19
+ }
20
+ function isTaskQueue(value) {
21
+ return typeof value === "object" && value !== null && "size" in value && typeof value.shift === "function" && typeof value.remove === "function" && typeof value.push === "function";
22
+ }
23
+ const kRequestCountField = 0;
24
+ const kResponseCountField = 1;
25
+ const kFieldCount = 2;
26
+
27
+ //#endregion
28
+ export { isMovable, isTaskQueue, isTransferable, kFieldCount, kQueueOptions, kRequestCountField, kResponseCountField, kTransferable, kValue, markMovable };
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ export { };
@@ -1,92 +1,72 @@
1
- import {
2
- stderr,
3
- stdout
4
- } from "../chunk-ACQHDOFQ.js";
5
- import {
6
- getHandler,
7
- throwInNextTick
8
- } from "../chunk-E2J7JLFN.js";
9
- import "../chunk-6LX4VMOV.js";
1
+ import { stderr, stdout } from "../utils-De75vAgL.js";
2
+ import { getHandler, throwInNextTick } from "../utils-B--2TaWv.js";
10
3
 
11
- // src/entry/process.ts
4
+ //#region src/entry/process.ts
12
5
  process.__tinypool_state__ = {
13
- isChildProcess: true,
14
- isTinypoolWorker: true,
15
- workerData: null,
16
- workerId: Number(process.env.TINYPOOL_WORKER_ID)
6
+ isChildProcess: true,
7
+ isTinypoolWorker: true,
8
+ workerData: null,
9
+ workerId: Number(process.env.TINYPOOL_WORKER_ID)
17
10
  };
18
- var memoryUsage = process.memoryUsage.bind(process);
19
- var send = process.send.bind(process);
11
+ const memoryUsage = process.memoryUsage.bind(process);
12
+ const send = process.send.bind(process);
20
13
  process.on("message", (message) => {
21
- if (!message || !message.__tinypool_worker_message__)
22
- return;
23
- if (message.source === "pool") {
24
- const { filename, name } = message;
25
- (async function() {
26
- if (filename !== null) {
27
- await getHandler(filename, name);
28
- }
29
- send(
30
- {
31
- ready: true,
32
- source: "pool",
33
- __tinypool_worker_message__: true
34
- },
35
- () => {
36
- }
37
- );
38
- })().catch(throwInNextTick);
39
- return;
40
- }
41
- if (message.source === "port") {
42
- onMessage(message).catch(throwInNextTick);
43
- return;
44
- }
45
- throw new Error(`Unexpected TinypoolWorkerMessage ${JSON.stringify(message)}`);
14
+ if (!message || !message.__tinypool_worker_message__) return;
15
+ if (message.source === "pool") {
16
+ const { filename, name } = message;
17
+ (async function() {
18
+ if (filename !== null) await getHandler(filename, name);
19
+ send({
20
+ ready: true,
21
+ source: "pool",
22
+ __tinypool_worker_message__: true
23
+ }, () => {});
24
+ })().catch(throwInNextTick);
25
+ return;
26
+ }
27
+ if (message.source === "port") {
28
+ onMessage(message).catch(throwInNextTick);
29
+ return;
30
+ }
31
+ throw new Error(`Unexpected TinypoolWorkerMessage ${JSON.stringify(message)}`);
46
32
  });
47
33
  async function onMessage(message) {
48
- const { taskId, task, filename, name } = message;
49
- let response;
50
- try {
51
- const handler = await getHandler(filename, name);
52
- if (handler === null) {
53
- throw new Error(`No handler function exported from ${filename}`);
54
- }
55
- const result = await handler(task);
56
- response = {
57
- source: "port",
58
- __tinypool_worker_message__: true,
59
- taskId,
60
- result,
61
- error: null,
62
- usedMemory: memoryUsage().heapUsed
63
- };
64
- if (stdout()?.writableLength > 0) {
65
- await new Promise((resolve) => process.stdout.write("", resolve));
66
- }
67
- if (stderr()?.writableLength > 0) {
68
- await new Promise((resolve) => process.stderr.write("", resolve));
69
- }
70
- } catch (error) {
71
- response = {
72
- source: "port",
73
- __tinypool_worker_message__: true,
74
- taskId,
75
- result: null,
76
- error: serializeError(error),
77
- usedMemory: memoryUsage().heapUsed
78
- };
79
- }
80
- send(response);
34
+ const { taskId, task, filename, name } = message;
35
+ let response;
36
+ try {
37
+ const handler = await getHandler(filename, name);
38
+ if (handler === null) throw new Error(`No handler function "${name}" exported from "${filename}"`);
39
+ const result = await handler(task);
40
+ response = {
41
+ source: "port",
42
+ __tinypool_worker_message__: true,
43
+ taskId,
44
+ result,
45
+ error: null,
46
+ usedMemory: memoryUsage().heapUsed
47
+ };
48
+ if (stdout()?.writableLength > 0) await new Promise((resolve) => process.stdout.write("", resolve));
49
+ if (stderr()?.writableLength > 0) await new Promise((resolve) => process.stderr.write("", resolve));
50
+ } catch (error) {
51
+ response = {
52
+ source: "port",
53
+ __tinypool_worker_message__: true,
54
+ taskId,
55
+ result: null,
56
+ error: serializeError(error),
57
+ usedMemory: memoryUsage().heapUsed
58
+ };
59
+ }
60
+ send(response);
81
61
  }
82
62
  function serializeError(error) {
83
- if (error instanceof Error) {
84
- return {
85
- ...error,
86
- name: error.name,
87
- stack: error.stack,
88
- message: error.message
89
- };
90
- }
91
- return String(error);
63
+ if (error instanceof Error) return {
64
+ ...error,
65
+ name: error.name,
66
+ stack: error.stack,
67
+ message: error.message
68
+ };
69
+ return String(error);
92
70
  }
71
+
72
+ //#endregion
@@ -1,5 +1,7 @@
1
+ //#region src/entry/utils.d.ts
1
2
  type Handler = Function;
2
3
  declare function getHandler(filename: string, name: string): Promise<Handler | null>;
3
4
  declare function throwInNextTick(error: Error): void;
4
5
 
5
- export { getHandler, throwInNextTick };
6
+ //#endregion
7
+ export { getHandler, throwInNextTick };
@@ -1,9 +1,3 @@
1
- import {
2
- getHandler,
3
- throwInNextTick
4
- } from "../chunk-E2J7JLFN.js";
5
- import "../chunk-6LX4VMOV.js";
6
- export {
7
- getHandler,
8
- throwInNextTick
9
- };
1
+ import { getHandler, throwInNextTick } from "../utils-B--2TaWv.js";
2
+
3
+ export { getHandler, throwInNextTick };
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ export { };
@@ -1,103 +1,75 @@
1
- import {
2
- isMovable,
3
- kRequestCountField,
4
- kResponseCountField,
5
- kTransferable,
6
- kValue
7
- } from "../chunk-UBWFVGJX.js";
8
- import {
9
- stderr,
10
- stdout
11
- } from "../chunk-ACQHDOFQ.js";
12
- import {
13
- getHandler,
14
- throwInNextTick
15
- } from "../chunk-E2J7JLFN.js";
16
- import "../chunk-6LX4VMOV.js";
1
+ import { isMovable, kRequestCountField, kResponseCountField, kTransferable, kValue } from "../common-Qw-RoVFD.js";
2
+ import { stderr, stdout } from "../utils-De75vAgL.js";
3
+ import { getHandler, throwInNextTick } from "../utils-B--2TaWv.js";
4
+ import { parentPort, receiveMessageOnPort, workerData } from "node:worker_threads";
17
5
 
18
- // src/entry/worker.ts
19
- import {
20
- parentPort,
21
- receiveMessageOnPort,
22
- workerData as tinypoolData
23
- } from "worker_threads";
24
- var [tinypoolPrivateData, workerData] = tinypoolData;
6
+ //#region src/entry/worker.ts
7
+ const [tinypoolPrivateData, workerData$1] = workerData;
25
8
  process.__tinypool_state__ = {
26
- isWorkerThread: true,
27
- isTinypoolWorker: true,
28
- workerData,
29
- workerId: tinypoolPrivateData.workerId
9
+ isWorkerThread: true,
10
+ isTinypoolWorker: true,
11
+ workerData: workerData$1,
12
+ workerId: tinypoolPrivateData.workerId
30
13
  };
31
- var memoryUsage = process.memoryUsage.bind(process);
32
- var useAtomics = process.env.PISCINA_DISABLE_ATOMICS !== "1";
14
+ const memoryUsage = process.memoryUsage.bind(process);
15
+ let useAtomics = process.env.PISCINA_DISABLE_ATOMICS !== "1";
33
16
  parentPort.on("message", (message) => {
34
- useAtomics = process.env.PISCINA_DISABLE_ATOMICS === "1" ? false : message.useAtomics;
35
- const { port, sharedBuffer, filename, name } = message;
36
- (async function() {
37
- if (filename !== null) {
38
- await getHandler(filename, name);
39
- }
40
- const readyMessage = { ready: true };
41
- parentPort.postMessage(readyMessage);
42
- port.on("message", onMessage.bind(null, port, sharedBuffer));
43
- atomicsWaitLoop(port, sharedBuffer);
44
- })().catch(throwInNextTick);
17
+ useAtomics = process.env.PISCINA_DISABLE_ATOMICS === "1" ? false : message.useAtomics;
18
+ const { port, sharedBuffer, filename, name } = message;
19
+ (async function() {
20
+ if (filename !== null) await getHandler(filename, name);
21
+ const readyMessage = { ready: true };
22
+ parentPort.postMessage(readyMessage);
23
+ port.on("message", onMessage.bind(null, port, sharedBuffer));
24
+ atomicsWaitLoop(port, sharedBuffer);
25
+ })().catch(throwInNextTick);
45
26
  });
46
- var currentTasks = 0;
47
- var lastSeenRequestCount = 0;
27
+ let currentTasks = 0;
28
+ let lastSeenRequestCount = 0;
48
29
  function atomicsWaitLoop(port, sharedBuffer) {
49
- if (!useAtomics)
50
- return;
51
- while (currentTasks === 0) {
52
- Atomics.wait(sharedBuffer, kRequestCountField, lastSeenRequestCount);
53
- lastSeenRequestCount = Atomics.load(sharedBuffer, kRequestCountField);
54
- let entry;
55
- while ((entry = receiveMessageOnPort(port)) !== void 0) {
56
- onMessage(port, sharedBuffer, entry.message);
57
- }
58
- }
30
+ if (!useAtomics) return;
31
+ while (currentTasks === 0) {
32
+ Atomics.wait(sharedBuffer, kRequestCountField, lastSeenRequestCount);
33
+ lastSeenRequestCount = Atomics.load(sharedBuffer, kRequestCountField);
34
+ let entry;
35
+ while ((entry = receiveMessageOnPort(port)) !== void 0) onMessage(port, sharedBuffer, entry.message);
36
+ }
59
37
  }
60
38
  function onMessage(port, sharedBuffer, message) {
61
- currentTasks++;
62
- const { taskId, task, filename, name } = message;
63
- (async function() {
64
- let response;
65
- let transferList = [];
66
- try {
67
- const handler = await getHandler(filename, name);
68
- if (handler === null) {
69
- throw new Error(`No handler function exported from ${filename}`);
70
- }
71
- let result = await handler(task);
72
- if (isMovable(result)) {
73
- transferList = transferList.concat(result[kTransferable]);
74
- result = result[kValue];
75
- }
76
- response = {
77
- taskId,
78
- result,
79
- error: null,
80
- usedMemory: memoryUsage().heapUsed
81
- };
82
- if (stdout()?.writableLength > 0) {
83
- await new Promise((resolve) => process.stdout.write("", resolve));
84
- }
85
- if (stderr()?.writableLength > 0) {
86
- await new Promise((resolve) => process.stderr.write("", resolve));
87
- }
88
- } catch (error) {
89
- response = {
90
- taskId,
91
- result: null,
92
- // It may be worth taking a look at the error cloning algorithm we
93
- // use in Node.js core here, it's quite a bit more flexible
94
- error,
95
- usedMemory: memoryUsage().heapUsed
96
- };
97
- }
98
- currentTasks--;
99
- port.postMessage(response, transferList);
100
- Atomics.add(sharedBuffer, kResponseCountField, 1);
101
- atomicsWaitLoop(port, sharedBuffer);
102
- })().catch(throwInNextTick);
39
+ currentTasks++;
40
+ const { taskId, task, filename, name } = message;
41
+ (async function() {
42
+ let response;
43
+ let transferList = [];
44
+ try {
45
+ const handler = await getHandler(filename, name);
46
+ if (handler === null) throw new Error(`No handler function "${name}" exported from "${filename}"`);
47
+ let result = await handler(task);
48
+ if (isMovable(result)) {
49
+ transferList = transferList.concat(result[kTransferable]);
50
+ result = result[kValue];
51
+ }
52
+ response = {
53
+ taskId,
54
+ result,
55
+ error: null,
56
+ usedMemory: memoryUsage().heapUsed
57
+ };
58
+ if (stdout()?.writableLength > 0) await new Promise((resolve) => process.stdout.write("", resolve));
59
+ if (stderr()?.writableLength > 0) await new Promise((resolve) => process.stderr.write("", resolve));
60
+ } catch (error) {
61
+ response = {
62
+ taskId,
63
+ result: null,
64
+ error,
65
+ usedMemory: memoryUsage().heapUsed
66
+ };
67
+ }
68
+ currentTasks--;
69
+ port.postMessage(response, transferList);
70
+ Atomics.add(sharedBuffer, kResponseCountField, 1);
71
+ atomicsWaitLoop(port, sharedBuffer);
72
+ })().catch(throwInNextTick);
103
73
  }
74
+
75
+ //#endregion