@atlaspack/workers 2.14.5-canary.2 → 2.14.5-canary.200

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 (51) hide show
  1. package/CHANGELOG.md +274 -0
  2. package/index.d.ts +96 -3
  3. package/lib/Handle.js +0 -3
  4. package/lib/Worker.js +7 -1
  5. package/lib/WorkerFarm.js +15 -7
  6. package/lib/backend.js +5 -1
  7. package/lib/bus.js +1 -1
  8. package/lib/child.js +11 -4
  9. package/lib/cpuCount.js +6 -2
  10. package/lib/process/ProcessChild.js +6 -1
  11. package/lib/process/ProcessWorker.js +9 -2
  12. package/lib/threads/ThreadsChild.js +3 -0
  13. package/lib/threads/ThreadsWorker.js +10 -2
  14. package/lib/types/Handle.d.ts +19 -0
  15. package/lib/types/Worker.d.ts +40 -0
  16. package/lib/types/WorkerFarm.d.ts +93 -0
  17. package/lib/types/backend.d.ts +4 -0
  18. package/lib/types/bus.d.ts +6 -0
  19. package/lib/types/child.d.ts +43 -0
  20. package/lib/types/childState.d.ts +3 -0
  21. package/lib/types/cpuCount.d.ts +2 -0
  22. package/lib/types/index.d.ts +6 -0
  23. package/lib/types/process/ProcessChild.d.ts +9 -0
  24. package/lib/types/process/ProcessWorker.d.ts +16 -0
  25. package/lib/types/threads/ThreadsChild.d.ts +8 -0
  26. package/lib/types/threads/ThreadsWorker.d.ts +15 -0
  27. package/lib/types/types.d.ts +52 -0
  28. package/lib/types/web/WebChild.d.ts +8 -0
  29. package/lib/types/web/WebWorker.d.ts +15 -0
  30. package/lib/web/WebChild.js +6 -1
  31. package/lib/web/WebWorker.js +20 -4
  32. package/package.json +16 -19
  33. package/src/{Handle.js → Handle.ts} +11 -11
  34. package/src/{Worker.js → Worker.ts} +66 -54
  35. package/src/{WorkerFarm.js → WorkerFarm.ts} +196 -141
  36. package/src/{backend.js → backend.ts} +6 -3
  37. package/src/{bus.js → bus.ts} +2 -3
  38. package/src/{child.js → child.ts} +55 -43
  39. package/src/{childState.js → childState.ts} +1 -2
  40. package/src/{cpuCount.js → cpuCount.ts} +10 -7
  41. package/src/{index.js → index.ts} +0 -1
  42. package/src/process/{ProcessChild.js → ProcessChild.ts} +5 -3
  43. package/src/process/{ProcessWorker.js → ProcessWorker.ts} +10 -7
  44. package/src/threads/{ThreadsChild.js → ThreadsChild.ts} +2 -2
  45. package/src/threads/{ThreadsWorker.js → ThreadsWorker.ts} +14 -8
  46. package/src/{types.js → types.ts} +34 -35
  47. package/src/web/{WebChild.js → WebChild.ts} +6 -2
  48. package/src/web/{WebWorker.js → WebWorker.ts} +19 -7
  49. package/test/{cpuCount.test.js → cpuCount.test.ts} +0 -1
  50. package/test/{workerfarm.test.cjs → workerfarm.test.js} +9 -2
  51. package/tsconfig.json +4 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,279 @@
1
1
  # @atlaspack/workers
2
2
 
3
+ ## 2.14.31
4
+
5
+ ### Patch Changes
6
+
7
+ - [#785](https://github.com/atlassian-labs/atlaspack/pull/785) [`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922) Thanks [@matt-koko](https://github.com/matt-koko)! - We need to re-publish every package in Atlaspack with the corrected types field.
8
+
9
+ - Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922)]:
10
+ - @atlaspack/build-cache@2.13.6
11
+ - @atlaspack/diagnostic@2.14.4
12
+ - @atlaspack/logger@2.14.23
13
+ - @atlaspack/profiler@2.14.28
14
+ - @atlaspack/types-internal@2.20.1
15
+ - @atlaspack/utils@2.19.3
16
+
17
+ ## 2.14.30
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [[`eedcbc4`](https://github.com/atlassian-labs/atlaspack/commit/eedcbc408fc1e86a2a8e25f1a41c57146d8529e1), [`f6532d7`](https://github.com/atlassian-labs/atlaspack/commit/f6532d7a4f7f007bd4e5e36af04dd466f0b9f572)]:
22
+ - @atlaspack/types-internal@2.20.0
23
+ - @atlaspack/utils@2.19.2
24
+ - @atlaspack/logger@2.14.22
25
+ - @atlaspack/profiler@2.14.27
26
+
27
+ ## 2.14.29
28
+
29
+ ### Patch Changes
30
+
31
+ - Updated dependencies []:
32
+ - @atlaspack/types-internal@2.19.5
33
+ - @atlaspack/utils@2.19.1
34
+ - @atlaspack/logger@2.14.21
35
+ - @atlaspack/profiler@2.14.26
36
+
37
+ ## 2.14.28
38
+
39
+ ### Patch Changes
40
+
41
+ - Updated dependencies [[`f0349a6`](https://github.com/atlassian-labs/atlaspack/commit/f0349a6b9b04755088f121095ca6301a2ada3767)]:
42
+ - @atlaspack/utils@2.19.0
43
+ - @atlaspack/types-internal@2.19.4
44
+ - @atlaspack/logger@2.14.20
45
+ - @atlaspack/profiler@2.14.25
46
+
47
+ ## 2.14.27
48
+
49
+ ### Patch Changes
50
+
51
+ - Updated dependencies []:
52
+ - @atlaspack/types-internal@2.19.3
53
+ - @atlaspack/utils@2.18.4
54
+ - @atlaspack/logger@2.14.19
55
+ - @atlaspack/profiler@2.14.24
56
+
57
+ ## 2.14.26
58
+
59
+ ### Patch Changes
60
+
61
+ - [#742](https://github.com/atlassian-labs/atlaspack/pull/742) [`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd) Thanks [@yamadapc](https://github.com/yamadapc)! - Internal changes and bug fixes to environmentDeduplication flag
62
+
63
+ - Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd), [`889c65c`](https://github.com/atlassian-labs/atlaspack/commit/889c65cd25b811045e26a117e7404f694dde77a2)]:
64
+ - @atlaspack/types-internal@2.19.2
65
+ - @atlaspack/build-cache@2.13.5
66
+ - @atlaspack/diagnostic@2.14.3
67
+ - @atlaspack/profiler@2.14.23
68
+ - @atlaspack/logger@2.14.18
69
+ - @atlaspack/utils@2.18.3
70
+
71
+ ## 2.14.25
72
+
73
+ ### Patch Changes
74
+
75
+ - Updated dependencies []:
76
+ - @atlaspack/types-internal@2.19.1
77
+ - @atlaspack/utils@2.18.2
78
+ - @atlaspack/logger@2.14.17
79
+ - @atlaspack/profiler@2.14.22
80
+
81
+ ## 2.14.24
82
+
83
+ ### Patch Changes
84
+
85
+ - Updated dependencies [[`7f5841c`](https://github.com/atlassian-labs/atlaspack/commit/7f5841c39df049f9546cccbeea2a7337e0337b45)]:
86
+ - @atlaspack/types-internal@2.19.0
87
+ - @atlaspack/logger@2.14.16
88
+ - @atlaspack/utils@2.18.1
89
+ - @atlaspack/profiler@2.14.21
90
+
91
+ ## 2.14.23
92
+
93
+ ### Patch Changes
94
+
95
+ - Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
96
+ - @atlaspack/utils@2.18.0
97
+ - @atlaspack/types-internal@2.18.0
98
+ - @atlaspack/logger@2.14.15
99
+ - @atlaspack/profiler@2.14.20
100
+
101
+ ## 2.14.22
102
+
103
+ ### Patch Changes
104
+
105
+ - [#720](https://github.com/atlassian-labs/atlaspack/pull/720) [`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94) Thanks [@alshdavid](https://github.com/alshdavid)! - Migrate to TypeScript
106
+
107
+ - Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94), [`43fdd22`](https://github.com/atlassian-labs/atlaspack/commit/43fdd223860fbc97af17d68c65419b97412cb888)]:
108
+ - @atlaspack/types-internal@2.17.0
109
+ - @atlaspack/build-cache@2.13.4
110
+ - @atlaspack/diagnostic@2.14.2
111
+ - @atlaspack/profiler@2.14.19
112
+ - @atlaspack/logger@2.14.14
113
+ - @atlaspack/utils@2.17.4
114
+
115
+ ## 2.14.21
116
+
117
+ ### Patch Changes
118
+
119
+ - Updated dependencies [[`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd)]:
120
+ - @atlaspack/types-internal@2.16.0
121
+ - @atlaspack/profiler@2.14.18
122
+ - @atlaspack/utils@2.17.3
123
+
124
+ ## 2.14.20
125
+
126
+ ### Patch Changes
127
+
128
+ - Updated dependencies []:
129
+ - @atlaspack/types-internal@2.15.2
130
+ - @atlaspack/utils@2.17.2
131
+ - @atlaspack/profiler@2.14.17
132
+
133
+ ## 2.14.19
134
+
135
+ ### Patch Changes
136
+
137
+ - Updated dependencies []:
138
+ - @atlaspack/types-internal@2.15.1
139
+ - @atlaspack/utils@2.17.1
140
+ - @atlaspack/profiler@2.14.16
141
+
142
+ ## 2.14.18
143
+
144
+ ### Patch Changes
145
+
146
+ - Updated dependencies [[`dbb4072`](https://github.com/atlassian-labs/atlaspack/commit/dbb40721ebeb45990a14ba04e6b44e7f836fb32d), [`de23e0c`](https://github.com/atlassian-labs/atlaspack/commit/de23e0ce49d5504fe3947ac26640a3d951087da3), [`18a57cf`](https://github.com/atlassian-labs/atlaspack/commit/18a57cf8a4789b2de5ad8e2676f317a26cc91417), [`a5ed1b4`](https://github.com/atlassian-labs/atlaspack/commit/a5ed1b414498560f393ff491af4da25b6e8dde56)]:
147
+ - @atlaspack/utils@2.17.0
148
+ - @atlaspack/types-internal@2.15.0
149
+ - @atlaspack/logger@2.14.13
150
+ - @atlaspack/profiler@2.14.15
151
+
152
+ ## 2.14.17
153
+
154
+ ### Patch Changes
155
+
156
+ - Updated dependencies []:
157
+ - @atlaspack/logger@2.14.12
158
+ - @atlaspack/utils@2.16.1
159
+
160
+ ## 2.14.16
161
+
162
+ ### Patch Changes
163
+
164
+ - Updated dependencies [[`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
165
+ - @atlaspack/utils@2.16.0
166
+ - @atlaspack/types-internal@2.14.14
167
+ - @atlaspack/profiler@2.14.14
168
+
169
+ ## 2.14.15
170
+
171
+ ### Patch Changes
172
+
173
+ - Updated dependencies []:
174
+ - @atlaspack/types-internal@2.14.13
175
+ - @atlaspack/utils@2.15.3
176
+ - @atlaspack/profiler@2.14.13
177
+
178
+ ## 2.14.14
179
+
180
+ ### Patch Changes
181
+
182
+ - Updated dependencies []:
183
+ - @atlaspack/types-internal@2.14.12
184
+ - @atlaspack/utils@2.15.2
185
+ - @atlaspack/profiler@2.14.12
186
+
187
+ ## 2.14.13
188
+
189
+ ### Patch Changes
190
+
191
+ - [#650](https://github.com/atlassian-labs/atlaspack/pull/650) [`ef3d622`](https://github.com/atlassian-labs/atlaspack/commit/ef3d6228f4e006702198a19c61e051d194d325cb) Thanks [@alshdavid](https://github.com/alshdavid)! - Remove package.json#exports
192
+
193
+ - Updated dependencies [[`ef3d622`](https://github.com/atlassian-labs/atlaspack/commit/ef3d6228f4e006702198a19c61e051d194d325cb)]:
194
+ - @atlaspack/logger@2.14.11
195
+ - @atlaspack/utils@2.15.1
196
+ - @atlaspack/types-internal@2.14.11
197
+ - @atlaspack/profiler@2.14.11
198
+
199
+ ## 2.14.12
200
+
201
+ ### Patch Changes
202
+
203
+ - Updated dependencies [[`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
204
+ - @atlaspack/utils@2.15.0
205
+ - @atlaspack/types-internal@2.14.10
206
+ - @atlaspack/profiler@2.14.10
207
+
208
+ ## 2.14.11
209
+
210
+ ### Patch Changes
211
+
212
+ - Updated dependencies []:
213
+ - @atlaspack/types-internal@2.14.9
214
+ - @atlaspack/utils@2.14.11
215
+ - @atlaspack/profiler@2.14.9
216
+
217
+ ## 2.14.10
218
+
219
+ ### Patch Changes
220
+
221
+ - Updated dependencies [[`51aba5f`](https://github.com/atlassian-labs/atlaspack/commit/51aba5fc0e49235ee06bbc3c376f48c3e7da5c4b)]:
222
+ - @atlaspack/types-internal@2.14.8
223
+ - @atlaspack/profiler@2.14.8
224
+ - @atlaspack/logger@2.14.10
225
+ - @atlaspack/utils@2.14.10
226
+
227
+ ## 2.14.9
228
+
229
+ ### Patch Changes
230
+
231
+ - Updated dependencies []:
232
+ - @atlaspack/logger@2.14.9
233
+ - @atlaspack/utils@2.14.9
234
+ - @atlaspack/types-internal@2.14.7
235
+ - @atlaspack/profiler@2.14.7
236
+
237
+ ## 2.14.8
238
+
239
+ ### Patch Changes
240
+
241
+ - Updated dependencies []:
242
+ - @atlaspack/types-internal@2.14.6
243
+ - @atlaspack/utils@2.14.8
244
+ - @atlaspack/logger@2.14.8
245
+ - @atlaspack/profiler@2.14.6
246
+
247
+ ## 2.14.7
248
+
249
+ ### Patch Changes
250
+
251
+ - Updated dependencies [[`556d6ab`](https://github.com/atlassian-labs/atlaspack/commit/556d6ab8ede759fa7f37fcd3f4da336ef1c55e8f)]:
252
+ - @atlaspack/logger@2.14.7
253
+ - @atlaspack/types-internal@2.14.5
254
+ - @atlaspack/utils@2.14.7
255
+ - @atlaspack/profiler@2.14.5
256
+
257
+ ## 2.14.6
258
+
259
+ ### Patch Changes
260
+
261
+ - Updated dependencies []:
262
+ - @atlaspack/types-internal@2.14.4
263
+ - @atlaspack/utils@2.14.6
264
+ - @atlaspack/logger@2.14.6
265
+ - @atlaspack/profiler@2.14.4
266
+
267
+ ## 2.14.5
268
+
269
+ ### Patch Changes
270
+
271
+ - Updated dependencies []:
272
+ - @atlaspack/types-internal@2.14.3
273
+ - @atlaspack/utils@2.14.5
274
+ - @atlaspack/logger@2.14.5
275
+ - @atlaspack/profiler@2.14.3
276
+
3
277
  ## 2.14.4
4
278
 
5
279
  ### Patch Changes
package/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import {FilePath} from '@atlaspack/types';
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
+ import type {FilePath} from '@atlaspack/types';
3
+ import type EventEmitter from 'events';
2
4
 
3
5
  type BackendType = 'process' | 'threads';
4
6
 
@@ -14,10 +16,101 @@ export type FarmOptions = {
14
16
  shouldTrace?: boolean;
15
17
  };
16
18
 
17
- declare class WorkerFarm {
18
- constructor(options: FarmOptions);
19
+ export class Bus extends EventEmitter {
20
+ emit(event: string, ...args: Array<any>): boolean;
21
+ }
22
+
23
+ export const bus: Bus;
19
24
 
25
+ export declare class WorkerFarm {
26
+ ending: boolean;
27
+ workerApi: {
28
+ callChild: (
29
+ childId: number,
30
+ request: HandleCallRequest,
31
+ ) => Promise<unknown>;
32
+ callMaster: (
33
+ request: CallRequest,
34
+ awaitResponse?: boolean | null | undefined,
35
+ ) => Promise<unknown>;
36
+ createReverseHandle: (fn: HandleFunction) => Handle;
37
+ getSharedReference: (ref: SharedReference) => unknown;
38
+ resolveSharedReference: (value: unknown) => undefined | SharedReference;
39
+ runHandle: (handle: Handle, args: Array<any>) => Promise<unknown>;
40
+ };
41
+ constructor(options: Partial<FarmOptions>);
42
+ createSharedReference(
43
+ value: unknown,
44
+ isCacheable?: boolean,
45
+ ): {
46
+ ref: SharedReference;
47
+ dispose(): Promise<unknown>;
48
+ };
49
+ startProfile(): Promise<void>;
50
+ endProfile(): Promise<void>;
51
+ takeHeapSnapshot(): Promise<void>;
52
+ createHandle(method: string, useMainThread?: boolean): HandleFunction;
53
+ createReverseHandle(fn: HandleFunction): Handle;
54
+ callAllWorkers(method: string, args: Array<any>): Promise<void>;
55
+ static getWorkerApi(): {
56
+ callMaster: (
57
+ request: CallRequest,
58
+ awaitResponse?: boolean | null | undefined,
59
+ ) => Promise<unknown>;
60
+ createReverseHandle: (fn: (...args: Array<any>) => unknown) => Handle;
61
+ getSharedReference: (ref: SharedReference) => unknown;
62
+ resolveSharedReference: (value: unknown) => undefined | SharedReference;
63
+ runHandle: (handle: Handle, args: Array<any>) => Promise<unknown>;
64
+ };
20
65
  end(): Promise<void>;
66
+ static isWorker(): boolean;
21
67
  }
22
68
 
23
69
  export default WorkerFarm;
70
+
71
+ export type SharedReference = number;
72
+
73
+ export type WorkerApi = {
74
+ callMaster(
75
+ arg1: CallRequest,
76
+ arg2?: boolean | null | undefined,
77
+ ): Promise<unknown>;
78
+ createReverseHandle(fn: HandleFunction): Handle;
79
+ getSharedReference(ref: SharedReference): unknown;
80
+ resolveSharedReference(value: unknown): SharedReference | null | undefined;
81
+ callChild?: (childId: number, request: HandleCallRequest) => Promise<unknown>;
82
+ };
83
+
84
+ export type HandleFunction = (...args: Array<any>) => any;
85
+
86
+ export type LocationCallRequest = {
87
+ args: ReadonlyArray<unknown>;
88
+ location: string;
89
+ method?: string;
90
+ };
91
+
92
+ export type HandleCallRequest = {
93
+ args: ReadonlyArray<unknown>;
94
+ handle: number;
95
+ };
96
+
97
+ export type CallRequest = LocationCallRequest | HandleCallRequest;
98
+
99
+ type HandleOpts = {
100
+ fn?: HandleFunction;
101
+ childId?: number | null | undefined;
102
+ id?: number;
103
+ };
104
+
105
+ export declare class Handle {
106
+ id: number;
107
+ childId: number | null | undefined;
108
+ fn: HandleFunction | null | undefined;
109
+ constructor(opts: HandleOpts);
110
+ dispose(): void;
111
+ serialize(): {
112
+ childId: number | null | undefined;
113
+ id: number;
114
+ };
115
+ static deserialize(opts: HandleOpts): Handle;
116
+ }
package/lib/Handle.js CHANGED
@@ -13,10 +13,7 @@ function _buildCache() {
13
13
  }
14
14
  var _package = _interopRequireDefault(require("../package.json"));
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
- // $FlowFixMe
17
16
  let HANDLE_ID = 0;
18
- // $FlowFixMe
19
-
20
17
  const handleById = new Map();
21
18
  class Handle {
22
19
  constructor(opts) {
package/lib/Worker.js CHANGED
@@ -29,6 +29,8 @@ var _backend = require("./backend");
29
29
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
30
  let WORKER_ID = 0;
31
31
  class Worker extends _events().default {
32
+ // @ts-expect-error TS2564
33
+
32
34
  id = WORKER_ID++;
33
35
  sentSharedReferences = new Set();
34
36
  calls = new Map();
@@ -105,7 +107,9 @@ class Worker extends _events().default {
105
107
  let refsShared = new Set();
106
108
  // in case more refs are created while initial refs are sending
107
109
  while (refsShared.size < sharedRefs.size) {
108
- await Promise.all([...sharedRefs].filter(([ref]) => !refsShared.has(ref)).map(async ([ref, value]) => {
110
+ await Promise.all([...sharedRefs]
111
+ // @ts-expect-error TS2769
112
+ .filter(([ref]) => !refsShared.has(ref)).map(async ([ref, value]) => {
109
113
  await this.sendSharedReference(ref, value);
110
114
  refsShared.add(ref);
111
115
  }));
@@ -144,8 +148,10 @@ class Worker extends _events().default {
144
148
  args: call.args
145
149
  };
146
150
  if (this.ready || call.skipReadyCheck === true) {
151
+ // @ts-expect-error TS2345
147
152
  this.send(msg);
148
153
  } else {
154
+ // @ts-expect-error TS2345
149
155
  this.once('ready', () => this.send(msg));
150
156
  }
151
157
  }
package/lib/WorkerFarm.js CHANGED
@@ -108,9 +108,9 @@ class WorkerFarm extends _events().default {
108
108
  if (!this.options.workerPath) {
109
109
  throw new Error('Please provide a worker path!');
110
110
  }
111
-
112
- // $FlowFixMe
113
111
  this.localWorker = require(this.options.workerPath);
112
+
113
+ // @ts-expect-error TS2322
114
114
  this.localWorkerInit = this.localWorker.childInit != null ? this.localWorker.childInit() : null;
115
115
  this.run = this.createHandle('run');
116
116
 
@@ -127,9 +127,9 @@ class WorkerFarm extends _events().default {
127
127
  }
128
128
  workerApi = {
129
129
  callMaster: async (request, awaitResponse = true) => {
130
- // $FlowFixMe
131
130
  let result = await this.processRequest({
132
131
  ...request,
132
+ // @ts-expect-error TS2322
133
133
  awaitResponse
134
134
  });
135
135
  return (0, _buildCache().deserialize)((0, _buildCache().serialize)(result));
@@ -203,6 +203,7 @@ class WorkerFarm extends _events().default {
203
203
  onError(error, worker) {
204
204
  // Handle ipc errors
205
205
  if (error.code === 'ERR_IPC_CHANNEL_CLOSED') {
206
+ // @ts-expect-error TS2322
206
207
  return this.stopWorker(worker);
207
208
  } else {
208
209
  _logger().default.error(error, '@atlaspack/workers');
@@ -261,6 +262,7 @@ class WorkerFarm extends _events().default {
261
262
  continue;
262
263
  }
263
264
  if (worker.calls.size < this.options.maxConcurrentCallsPerWorker) {
265
+ // @ts-expect-error TS2345
264
266
  this.callWorker(worker, this.callQueue.shift());
265
267
  }
266
268
  }
@@ -287,7 +289,7 @@ class WorkerFarm extends _events().default {
287
289
  var _this$handles$get;
288
290
  mod = (0, _nullthrows().default)((_this$handles$get = this.handles.get(handleId)) === null || _this$handles$get === void 0 ? void 0 : _this$handles$get.fn);
289
291
  } else if (location) {
290
- // $FlowFixMe
292
+ // @ts-expect-error TS2339
291
293
  if (process.browser) {
292
294
  if (location === '@atlaspack/workers/bus') {
293
295
  mod = bus;
@@ -295,7 +297,6 @@ class WorkerFarm extends _events().default {
295
297
  throw new Error('No dynamic require possible: ' + location);
296
298
  }
297
299
  } else {
298
- // $FlowFixMe this must be dynamic
299
300
  mod = require(location);
300
301
  }
301
302
  } else {
@@ -316,6 +317,7 @@ class WorkerFarm extends _events().default {
316
317
  let result;
317
318
  if (method == null) {
318
319
  try {
320
+ // @ts-expect-error TS2488
319
321
  result = responseFromContent(await mod(...args));
320
322
  } catch (e) {
321
323
  result = errorResponseFromError(e);
@@ -326,7 +328,6 @@ class WorkerFarm extends _events().default {
326
328
  mod = mod.default;
327
329
  }
328
330
  try {
329
- // $FlowFixMe
330
331
  result = responseFromContent(await mod[method](...args));
331
332
  } catch (e) {
332
333
  result = errorResponseFromError(e);
@@ -435,8 +436,11 @@ class WorkerFarm extends _events().default {
435
436
  // If the reference was created with the isCacheable option set to false,
436
437
  // serializedSharedReferences will contain `null` as the value.
437
438
  if (cached !== null) {
439
+ // @ts-expect-error TS2345
438
440
  this.serializedSharedReferences.set(ref, buf);
439
441
  }
442
+
443
+ // @ts-expect-error TS2322
440
444
  return buf;
441
445
  }
442
446
  async startProfile() {
@@ -481,6 +485,7 @@ class WorkerFarm extends _events().default {
481
485
  let filename = `profile-${getTimeId()}.trace`;
482
486
  let stream = trace.pipe(_fs().default.createWriteStream(filename));
483
487
  for (let profile of profiles) {
488
+ // @ts-expect-error TS2345
484
489
  trace.addCPUProfile(names.shift(), profile);
485
490
  }
486
491
  trace.flush();
@@ -543,7 +548,10 @@ class WorkerFarm extends _events().default {
543
548
  return _childState.child.workerApi;
544
549
  }
545
550
  static getConcurrentCallsPerWorker(defaultValue = DEFAULT_MAX_CONCURRENT_CALLS) {
546
- return parseInt(process.env.ATLASPACK_MAX_CONCURRENT_CALLS, 10) || defaultValue;
551
+ return (
552
+ // @ts-expect-error TS2345
553
+ parseInt(process.env.ATLASPACK_MAX_CONCURRENT_CALLS, 10) || defaultValue
554
+ );
547
555
  }
548
556
  }
549
557
  exports.default = WorkerFarm;
package/lib/backend.js CHANGED
@@ -5,8 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.detectBackend = detectBackend;
7
7
  exports.getWorkerBackend = getWorkerBackend;
8
+ // flow-to-ts helpers
9
+
10
+ // /flow-to-ts helpers
11
+
8
12
  function detectBackend() {
9
- // $FlowFixMe
13
+ // @ts-expect-error TS2339
10
14
  if (process.browser) return 'web';
11
15
  switch (process.env.ATLASPACK_WORKER_BACKEND) {
12
16
  case 'threads':
package/lib/bus.js CHANGED
@@ -17,7 +17,7 @@ class Bus extends _events().default {
17
17
  emit(event, ...args) {
18
18
  if (_childState.child) {
19
19
  _childState.child.workerApi.callMaster({
20
- // $FlowFixMe
20
+ // @ts-expect-error TS2339
21
21
  location: process.browser ? '@atlaspack/workers/bus' : __filename,
22
22
  method: 'emit',
23
23
  args: [event, ...args]
package/lib/child.js CHANGED
@@ -51,6 +51,9 @@ var _Handle2 = _interopRequireDefault(require("./Handle"));
51
51
  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); }
52
52
  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; }
53
53
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
54
+ // flow-to-ts helpers
55
+
56
+ // /flow-to-ts helpers
54
57
  // The import of './Handle' should really be imported eagerly (with @babel/plugin-transform-modules-commonjs's lazy mode).
55
58
  const Handle = _Handle2.default;
56
59
  class Child {
@@ -58,6 +61,7 @@ class Child {
58
61
  maxConcurrentCalls = 10;
59
62
  responseId = 0;
60
63
  responseQueue = new Map();
64
+ // @ts-expect-error TS2749
61
65
  handles = new Map();
62
66
  sharedReferences = new Map();
63
67
  sharedReferencesByValue = new Map();
@@ -78,7 +82,9 @@ class Child {
78
82
  }
79
83
  workerApi = {
80
84
  callMaster: (request, awaitResponse = true) => this.addCall(request, awaitResponse),
85
+ // @ts-expect-error TS2749
81
86
  createReverseHandle: fn => this.createReverseHandle(fn),
87
+ // @ts-expect-error TS2749
82
88
  runHandle: (handle, args) => this.workerApi.callMaster({
83
89
  handle: handle.id,
84
90
  args
@@ -97,7 +103,6 @@ class Child {
97
103
  this.child.send(data);
98
104
  }
99
105
  async childInit(module, childId) {
100
- // $FlowFixMe
101
106
  this.module = require(module);
102
107
  this.childId = childId;
103
108
  if (this.module.childInit != null) {
@@ -189,7 +194,7 @@ class Child {
189
194
  } else {
190
195
  try {
191
196
  result = responseFromContent(
192
- // $FlowFixMe
197
+ // @ts-expect-error TS2538
193
198
  await this.module[method](this.workerApi, ...args));
194
199
  } catch (e) {
195
200
  result = errorResponseFromError(e);
@@ -222,12 +227,11 @@ class Child {
222
227
 
223
228
  // Keep in mind to make sure responses to these calls are JSON.Stringify safe
224
229
  addCall(request, awaitResponse = true) {
225
- // $FlowFixMe
226
230
  let call = {
227
231
  ...request,
228
232
  type: 'request',
229
233
  child: this.childId,
230
- // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
234
+ // @ts-expect-error TS2322
231
235
  awaitResponse,
232
236
  resolve: () => {},
233
237
  reject: () => {}
@@ -265,6 +269,7 @@ class Child {
265
269
  return;
266
270
  }
267
271
  if (this.responseQueue.size < this.maxConcurrentCalls) {
272
+ // @ts-expect-error TS2345
268
273
  this.sendRequest(this.callQueue.shift());
269
274
  }
270
275
  }
@@ -272,6 +277,8 @@ class Child {
272
277
  this.loggerDisposable.dispose();
273
278
  this.tracerDisposable.dispose();
274
279
  }
280
+
281
+ // @ts-expect-error TS2749
275
282
  createReverseHandle(fn) {
276
283
  let handle = new Handle({
277
284
  fn,
package/lib/cpuCount.js CHANGED
@@ -50,18 +50,22 @@ function detectRealCores() {
50
50
  }
51
51
  return amount;
52
52
  }
53
+
54
+ // @ts-expect-error TS7034
53
55
  let cores;
54
56
  function getCores(bypassCache = false) {
55
57
  // Do not re-run commands if we already have the count...
58
+ // @ts-expect-error TS7005
56
59
  if (cores && !bypassCache) {
57
60
  return cores;
58
61
  }
59
62
 
60
- // $FlowFixMe
63
+ // @ts-expect-error TS2339
61
64
  if (process.browser) {
62
- // eslint-disable-next-line no-undef
63
65
  cores = navigator.hardwareConcurrency / 2;
64
66
  }
67
+
68
+ // @ts-expect-error TS7005
65
69
  if (!cores) {
66
70
  try {
67
71
  cores = detectRealCores();
@@ -21,6 +21,7 @@ function _nullthrows() {
21
21
  var _child = require("../child");
22
22
  var _childState = require("../childState");
23
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
+ // @ts-expect-error TS2420
24
25
  class ProcessChild {
25
26
  constructor(onMessage, onExit) {
26
27
  if (!process.send) {
@@ -28,6 +29,7 @@ class ProcessChild {
28
29
  }
29
30
  this.onMessage = onMessage;
30
31
  this.onExit = onExit;
32
+ // @ts-expect-error TS2345
31
33
  process.on('message', data => this.handleMessage(data));
32
34
  }
33
35
  handleMessage(data) {
@@ -38,9 +40,10 @@ class ProcessChild {
38
40
  }
39
41
  send(data) {
40
42
  let processSend = (0, _nullthrows().default)(process.send).bind(process);
43
+ // @ts-expect-error TS7006
41
44
  processSend((0, _buildCache().serialize)(data).toString('base64'), err => {
42
45
  if (err && err instanceof Error) {
43
- // $FlowFixMe[prop-missing]
46
+ // @ts-expect-error TS2339
44
47
  if (err.code === 'ERR_IPC_CHANNEL_CLOSED') {
45
48
  // IPC connection closed
46
49
  // no need to keep the worker running if it can't send or receive data
@@ -54,5 +57,7 @@ class ProcessChild {
54
57
  process.exit();
55
58
  }
56
59
  }
60
+
61
+ // @ts-expect-error TS2345
57
62
  exports.default = ProcessChild;
58
63
  (0, _childState.setChild)(new _child.Child(ProcessChild));