@atlaspack/workers 2.14.21-typescript-5b4d3ad41.0 → 2.14.21

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 (52) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/index.d.ts +2 -94
  3. package/lib/Handle.js +3 -0
  4. package/lib/Worker.js +1 -7
  5. package/lib/WorkerFarm.js +7 -17
  6. package/lib/backend.js +1 -5
  7. package/lib/bus.js +1 -1
  8. package/lib/child.js +4 -11
  9. package/lib/cpuCount.js +2 -6
  10. package/lib/process/ProcessChild.js +1 -6
  11. package/lib/process/ProcessWorker.js +2 -9
  12. package/lib/threads/ThreadsChild.js +0 -3
  13. package/lib/threads/ThreadsWorker.js +2 -10
  14. package/lib/web/WebChild.js +1 -6
  15. package/lib/web/WebWorker.js +4 -20
  16. package/package.json +12 -16
  17. package/src/{Handle.ts → Handle.js} +11 -11
  18. package/src/{Worker.ts → Worker.js} +54 -66
  19. package/src/{WorkerFarm.ts → WorkerFarm.js} +141 -198
  20. package/src/{backend.ts → backend.js} +3 -6
  21. package/src/{bus.ts → bus.js} +3 -2
  22. package/src/{child.ts → child.js} +43 -55
  23. package/src/{childState.ts → childState.js} +2 -1
  24. package/src/{cpuCount.ts → cpuCount.js} +7 -10
  25. package/src/{index.ts → index.js} +1 -0
  26. package/src/process/{ProcessChild.ts → ProcessChild.js} +3 -5
  27. package/src/process/{ProcessWorker.ts → ProcessWorker.js} +7 -10
  28. package/src/threads/{ThreadsChild.ts → ThreadsChild.js} +2 -2
  29. package/src/threads/{ThreadsWorker.ts → ThreadsWorker.js} +8 -14
  30. package/src/{types.ts → types.js} +35 -34
  31. package/src/web/{WebChild.ts → WebChild.js} +2 -6
  32. package/src/web/{WebWorker.ts → WebWorker.js} +7 -19
  33. package/test/{cpuCount.test.ts → cpuCount.test.js} +1 -0
  34. package/test/{workerfarm.test.js → workerfarm.test.cjs} +2 -4
  35. package/LICENSE +0 -201
  36. package/lib/Handle.d.ts +0 -19
  37. package/lib/Worker.d.ts +0 -40
  38. package/lib/WorkerFarm.d.ts +0 -93
  39. package/lib/backend.d.ts +0 -4
  40. package/lib/bus.d.ts +0 -6
  41. package/lib/child.d.ts +0 -43
  42. package/lib/childState.d.ts +0 -3
  43. package/lib/cpuCount.d.ts +0 -2
  44. package/lib/index.d.ts +0 -6
  45. package/lib/process/ProcessChild.d.ts +0 -9
  46. package/lib/process/ProcessWorker.d.ts +0 -16
  47. package/lib/threads/ThreadsChild.d.ts +0 -8
  48. package/lib/threads/ThreadsWorker.d.ts +0 -15
  49. package/lib/types.d.ts +0 -52
  50. package/lib/web/WebChild.d.ts +0 -8
  51. package/lib/web/WebWorker.d.ts +0 -15
  52. package/tsconfig.json +0 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaspack/workers
2
2
 
3
+ ## 2.14.21
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd)]:
8
+ - @atlaspack/types-internal@2.16.0
9
+ - @atlaspack/profiler@2.14.18
10
+ - @atlaspack/utils@2.17.3
11
+
3
12
  ## 2.14.20
4
13
 
5
14
  ### Patch Changes
package/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  // eslint-disable-next-line import/no-extraneous-dependencies
2
2
  import type {FilePath} from '@atlaspack/types';
3
- import type EventEmitter from 'events';
4
3
 
5
4
  type BackendType = 'process' | 'threads';
6
5
 
@@ -16,101 +15,10 @@ export type FarmOptions = {
16
15
  shouldTrace?: boolean;
17
16
  };
18
17
 
19
- export class Bus extends EventEmitter {
20
- emit(event: string, ...args: Array<any>): boolean;
21
- }
22
-
23
- export const bus: Bus;
18
+ declare class WorkerFarm {
19
+ constructor(options: FarmOptions);
24
20
 
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
- };
65
21
  end(): Promise<void>;
66
- static isWorker(): boolean;
67
22
  }
68
23
 
69
24
  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,7 +13,10 @@ 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
16
17
  let HANDLE_ID = 0;
18
+ // $FlowFixMe
19
+
17
20
  const handleById = new Map();
18
21
  class Handle {
19
22
  constructor(opts) {
package/lib/Worker.js CHANGED
@@ -29,8 +29,6 @@ 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
-
34
32
  id = WORKER_ID++;
35
33
  sentSharedReferences = new Set();
36
34
  calls = new Map();
@@ -107,9 +105,7 @@ class Worker extends _events().default {
107
105
  let refsShared = new Set();
108
106
  // in case more refs are created while initial refs are sending
109
107
  while (refsShared.size < sharedRefs.size) {
110
- await Promise.all([...sharedRefs]
111
- // @ts-expect-error TS2769
112
- .filter(([ref]) => !refsShared.has(ref)).map(async ([ref, value]) => {
108
+ await Promise.all([...sharedRefs].filter(([ref]) => !refsShared.has(ref)).map(async ([ref, value]) => {
113
109
  await this.sendSharedReference(ref, value);
114
110
  refsShared.add(ref);
115
111
  }));
@@ -148,10 +144,8 @@ class Worker extends _events().default {
148
144
  args: call.args
149
145
  };
150
146
  if (this.ready || call.skipReadyCheck === true) {
151
- // @ts-expect-error TS2345
152
147
  this.send(msg);
153
148
  } else {
154
- // @ts-expect-error TS2345
155
149
  this.once('ready', () => this.send(msg));
156
150
  }
157
151
  }
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
- this.localWorker = require(this.options.workerPath);
112
111
 
113
- // @ts-expect-error TS2322
112
+ // $FlowFixMe
113
+ this.localWorker = require(this.options.workerPath);
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
130
131
  let result = await this.processRequest({
131
132
  ...request,
132
- // @ts-expect-error TS2322
133
133
  awaitResponse
134
134
  });
135
135
  return (0, _buildCache().deserialize)((0, _buildCache().serialize)(result));
@@ -203,7 +203,6 @@ 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
207
206
  return this.stopWorker(worker);
208
207
  } else {
209
208
  _logger().default.error(error, '@atlaspack/workers');
@@ -262,7 +261,6 @@ class WorkerFarm extends _events().default {
262
261
  continue;
263
262
  }
264
263
  if (worker.calls.size < this.options.maxConcurrentCallsPerWorker) {
265
- // @ts-expect-error TS2345
266
264
  this.callWorker(worker, this.callQueue.shift());
267
265
  }
268
266
  }
@@ -289,7 +287,7 @@ class WorkerFarm extends _events().default {
289
287
  var _this$handles$get;
290
288
  mod = (0, _nullthrows().default)((_this$handles$get = this.handles.get(handleId)) === null || _this$handles$get === void 0 ? void 0 : _this$handles$get.fn);
291
289
  } else if (location) {
292
- // @ts-expect-error TS2339
290
+ // $FlowFixMe
293
291
  if (process.browser) {
294
292
  if (location === '@atlaspack/workers/bus') {
295
293
  mod = bus;
@@ -297,6 +295,7 @@ class WorkerFarm extends _events().default {
297
295
  throw new Error('No dynamic require possible: ' + location);
298
296
  }
299
297
  } else {
298
+ // $FlowFixMe this must be dynamic
300
299
  mod = require(location);
301
300
  }
302
301
  } else {
@@ -317,7 +316,6 @@ class WorkerFarm extends _events().default {
317
316
  let result;
318
317
  if (method == null) {
319
318
  try {
320
- // @ts-expect-error TS2488
321
319
  result = responseFromContent(await mod(...args));
322
320
  } catch (e) {
323
321
  result = errorResponseFromError(e);
@@ -328,6 +326,7 @@ class WorkerFarm extends _events().default {
328
326
  mod = mod.default;
329
327
  }
330
328
  try {
329
+ // $FlowFixMe
331
330
  result = responseFromContent(await mod[method](...args));
332
331
  } catch (e) {
333
332
  result = errorResponseFromError(e);
@@ -436,11 +435,8 @@ class WorkerFarm extends _events().default {
436
435
  // If the reference was created with the isCacheable option set to false,
437
436
  // serializedSharedReferences will contain `null` as the value.
438
437
  if (cached !== null) {
439
- // @ts-expect-error TS2345
440
438
  this.serializedSharedReferences.set(ref, buf);
441
439
  }
442
-
443
- // @ts-expect-error TS2322
444
440
  return buf;
445
441
  }
446
442
  async startProfile() {
@@ -485,7 +481,6 @@ class WorkerFarm extends _events().default {
485
481
  let filename = `profile-${getTimeId()}.trace`;
486
482
  let stream = trace.pipe(_fs().default.createWriteStream(filename));
487
483
  for (let profile of profiles) {
488
- // @ts-expect-error TS2345
489
484
  trace.addCPUProfile(names.shift(), profile);
490
485
  }
491
486
  trace.flush();
@@ -494,7 +489,6 @@ class WorkerFarm extends _events().default {
494
489
  });
495
490
  _logger().default.info({
496
491
  origin: '@atlaspack/workers',
497
- // @ts-expect-error TS2345
498
492
  message: (0, _diagnostic().md)`Wrote profile to ${filename}`
499
493
  });
500
494
  }
@@ -529,7 +523,6 @@ class WorkerFarm extends _events().default {
529
523
  })));
530
524
  _logger().default.info({
531
525
  origin: '@atlaspack/workers',
532
- // @ts-expect-error TS2345
533
526
  message: (0, _diagnostic().md)`Wrote heap snapshots to the following paths:\n${snapshotPaths.join('\n')}`
534
527
  });
535
528
  } catch {
@@ -550,10 +543,7 @@ class WorkerFarm extends _events().default {
550
543
  return _childState.child.workerApi;
551
544
  }
552
545
  static getConcurrentCallsPerWorker(defaultValue = DEFAULT_MAX_CONCURRENT_CALLS) {
553
- return (
554
- // @ts-expect-error TS2345
555
- parseInt(process.env.ATLASPACK_MAX_CONCURRENT_CALLS, 10) || defaultValue
556
- );
546
+ return parseInt(process.env.ATLASPACK_MAX_CONCURRENT_CALLS, 10) || defaultValue;
557
547
  }
558
548
  }
559
549
  exports.default = WorkerFarm;
package/lib/backend.js CHANGED
@@ -5,12 +5,8 @@ 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
-
12
8
  function detectBackend() {
13
- // @ts-expect-error TS2339
9
+ // $FlowFixMe
14
10
  if (process.browser) return 'web';
15
11
  switch (process.env.ATLASPACK_WORKER_BACKEND) {
16
12
  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
- // @ts-expect-error TS2339
20
+ // $FlowFixMe
21
21
  location: process.browser ? '@atlaspack/workers/bus' : __filename,
22
22
  method: 'emit',
23
23
  args: [event, ...args]
package/lib/child.js CHANGED
@@ -51,9 +51,6 @@ 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
57
54
  // The import of './Handle' should really be imported eagerly (with @babel/plugin-transform-modules-commonjs's lazy mode).
58
55
  const Handle = _Handle2.default;
59
56
  class Child {
@@ -61,7 +58,6 @@ class Child {
61
58
  maxConcurrentCalls = 10;
62
59
  responseId = 0;
63
60
  responseQueue = new Map();
64
- // @ts-expect-error TS2749
65
61
  handles = new Map();
66
62
  sharedReferences = new Map();
67
63
  sharedReferencesByValue = new Map();
@@ -82,9 +78,7 @@ class Child {
82
78
  }
83
79
  workerApi = {
84
80
  callMaster: (request, awaitResponse = true) => this.addCall(request, awaitResponse),
85
- // @ts-expect-error TS2749
86
81
  createReverseHandle: fn => this.createReverseHandle(fn),
87
- // @ts-expect-error TS2749
88
82
  runHandle: (handle, args) => this.workerApi.callMaster({
89
83
  handle: handle.id,
90
84
  args
@@ -103,6 +97,7 @@ class Child {
103
97
  this.child.send(data);
104
98
  }
105
99
  async childInit(module, childId) {
100
+ // $FlowFixMe
106
101
  this.module = require(module);
107
102
  this.childId = childId;
108
103
  if (this.module.childInit != null) {
@@ -194,7 +189,7 @@ class Child {
194
189
  } else {
195
190
  try {
196
191
  result = responseFromContent(
197
- // @ts-expect-error TS2538
192
+ // $FlowFixMe
198
193
  await this.module[method](this.workerApi, ...args));
199
194
  } catch (e) {
200
195
  result = errorResponseFromError(e);
@@ -227,11 +222,12 @@ class Child {
227
222
 
228
223
  // Keep in mind to make sure responses to these calls are JSON.Stringify safe
229
224
  addCall(request, awaitResponse = true) {
225
+ // $FlowFixMe
230
226
  let call = {
231
227
  ...request,
232
228
  type: 'request',
233
229
  child: this.childId,
234
- // @ts-expect-error TS2322
230
+ // $FlowFixMe Added in Flow 0.121.0 upgrade in #4381
235
231
  awaitResponse,
236
232
  resolve: () => {},
237
233
  reject: () => {}
@@ -269,7 +265,6 @@ class Child {
269
265
  return;
270
266
  }
271
267
  if (this.responseQueue.size < this.maxConcurrentCalls) {
272
- // @ts-expect-error TS2345
273
268
  this.sendRequest(this.callQueue.shift());
274
269
  }
275
270
  }
@@ -277,8 +272,6 @@ class Child {
277
272
  this.loggerDisposable.dispose();
278
273
  this.tracerDisposable.dispose();
279
274
  }
280
-
281
- // @ts-expect-error TS2749
282
275
  createReverseHandle(fn) {
283
276
  let handle = new Handle({
284
277
  fn,
package/lib/cpuCount.js CHANGED
@@ -50,22 +50,18 @@ function detectRealCores() {
50
50
  }
51
51
  return amount;
52
52
  }
53
-
54
- // @ts-expect-error TS7034
55
53
  let cores;
56
54
  function getCores(bypassCache = false) {
57
55
  // Do not re-run commands if we already have the count...
58
- // @ts-expect-error TS7005
59
56
  if (cores && !bypassCache) {
60
57
  return cores;
61
58
  }
62
59
 
63
- // @ts-expect-error TS2339
60
+ // $FlowFixMe
64
61
  if (process.browser) {
62
+ // eslint-disable-next-line no-undef
65
63
  cores = navigator.hardwareConcurrency / 2;
66
64
  }
67
-
68
- // @ts-expect-error TS7005
69
65
  if (!cores) {
70
66
  try {
71
67
  cores = detectRealCores();
@@ -21,7 +21,6 @@ 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
25
24
  class ProcessChild {
26
25
  constructor(onMessage, onExit) {
27
26
  if (!process.send) {
@@ -29,7 +28,6 @@ class ProcessChild {
29
28
  }
30
29
  this.onMessage = onMessage;
31
30
  this.onExit = onExit;
32
- // @ts-expect-error TS2345
33
31
  process.on('message', data => this.handleMessage(data));
34
32
  }
35
33
  handleMessage(data) {
@@ -40,10 +38,9 @@ class ProcessChild {
40
38
  }
41
39
  send(data) {
42
40
  let processSend = (0, _nullthrows().default)(process.send).bind(process);
43
- // @ts-expect-error TS7006
44
41
  processSend((0, _buildCache().serialize)(data).toString('base64'), err => {
45
42
  if (err && err instanceof Error) {
46
- // @ts-expect-error TS2339
43
+ // $FlowFixMe[prop-missing]
47
44
  if (err.code === 'ERR_IPC_CHANNEL_CLOSED') {
48
45
  // IPC connection closed
49
46
  // no need to keep the worker running if it can't send or receive data
@@ -57,7 +54,5 @@ class ProcessChild {
57
54
  process.exit();
58
55
  }
59
56
  }
60
-
61
- // @ts-expect-error TS2345
62
57
  exports.default = ProcessChild;
63
58
  (0, _childState.setChild)(new _child.Child(ProcessChild));
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.WORKER_PATH = void 0;
6
+ exports.default = void 0;
7
7
  function _child_process() {
8
8
  const data = _interopRequireDefault(require("child_process"));
9
9
  _child_process = function () {
@@ -26,15 +26,8 @@ function _buildCache() {
26
26
  return data;
27
27
  }
28
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
- let WORKER_PATH = exports.WORKER_PATH = _path().default.join(__dirname, 'ProcessChild.js');
30
- if (process.env.ATLASPACK_REGISTER_USE_SRC === 'true') {
31
- exports.WORKER_PATH = WORKER_PATH = _path().default.join(__dirname, 'ProcessChild.ts');
32
- }
33
-
34
- // @ts-expect-error TS2420
29
+ const WORKER_PATH = _path().default.join(__dirname, './ProcessChild.js');
35
30
  class ProcessWorker {
36
- // @ts-expect-error TS2564
37
-
38
31
  processQueue = true;
39
32
  sendQueue = [];
40
33
  constructor(execArgv, onMessage, onError, onExit) {
@@ -28,7 +28,6 @@ function _nullthrows() {
28
28
  var _child = require("../child");
29
29
  var _childState = require("../childState");
30
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
- // @ts-expect-error TS2420
32
31
  class ThreadsChild {
33
32
  constructor(onMessage, onExit) {
34
33
  if (_worker_threads().isMainThread || !_worker_threads().parentPort) {
@@ -46,7 +45,5 @@ class ThreadsChild {
46
45
  (0, _nullthrows().default)(_worker_threads().parentPort).postMessage((0, _buildCache().prepareForSerialization)(data));
47
46
  }
48
47
  }
49
-
50
- // @ts-expect-error TS2345
51
48
  exports.default = ThreadsChild;
52
49
  (0, _childState.setChild)(new _child.Child(ThreadsChild));
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.WORKER_PATH = void 0;
6
+ exports.default = void 0;
7
7
  function _worker_threads() {
8
8
  const data = require("worker_threads");
9
9
  _worker_threads = function () {
@@ -26,15 +26,8 @@ function _buildCache() {
26
26
  return data;
27
27
  }
28
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
- let WORKER_PATH = exports.WORKER_PATH = _path().default.join(__dirname, 'ThreadsChild.js');
30
- if (process.env.ATLASPACK_REGISTER_USE_SRC === 'true') {
31
- exports.WORKER_PATH = WORKER_PATH = _path().default.join(__dirname, 'ThreadsChild.ts');
32
- }
33
-
34
- // @ts-expect-error TS2420
29
+ const WORKER_PATH = _path().default.join(__dirname, './ThreadsChild.js');
35
30
  class ThreadsWorker {
36
- // @ts-expect-error TS2564
37
-
38
31
  constructor(execArgv, onMessage, onError, onExit) {
39
32
  this.execArgv = execArgv;
40
33
  this.onMessage = onMessage;
@@ -56,7 +49,6 @@ class ThreadsWorker {
56
49
  stop() {
57
50
  // In node 12, this returns a promise, but previously it accepted a callback
58
51
  // TODO: Pass a callback in earlier versions of Node
59
- // @ts-expect-error TS2322
60
52
  return Promise.resolve(this.worker.terminate());
61
53
  }
62
54
  handleMessage(data) {
@@ -14,10 +14,6 @@ function _buildCache() {
14
14
  var _child = require("../child");
15
15
  var _childState = require("../childState");
16
16
  /* eslint-env worker*/
17
-
18
- // Type declarations for Web Worker environment
19
-
20
- // @ts-expect-error TS2420
21
17
  class WebChild {
22
18
  constructor(onMessage, onExit) {
23
19
  if (!(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)) {
@@ -32,6 +28,7 @@ class WebChild {
32
28
  this.onExit(0);
33
29
  self.postMessage('stopped');
34
30
  }
31
+ // $FlowFixMe assume WorkerMessage as data
35
32
  this.handleMessage(data);
36
33
  });
37
34
  self.postMessage('online');
@@ -43,7 +40,5 @@ class WebChild {
43
40
  self.postMessage((0, _buildCache().prepareForSerialization)(data));
44
41
  }
45
42
  }
46
-
47
- // @ts-expect-error TS2345
48
43
  exports.default = WebChild;
49
44
  (0, _childState.setChild)(new _child.Child(WebChild));
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.WORKER_PATH = void 0;
6
+ exports.default = void 0;
7
7
  function _buildCache() {
8
8
  const data = require("@atlaspack/build-cache");
9
9
  _buildCache = function () {
@@ -19,18 +19,7 @@ function _utils() {
19
19
  return data;
20
20
  }
21
21
  let id = 0;
22
-
23
- // @ts-expect-error This is actually a module
24
- let WORKER_PATH = exports.WORKER_PATH = new URL('./WebChild.js', import.meta.url);
25
- if (process.env.ATLASPACK_REGISTER_USE_SRC === 'true') {
26
- // @ts-expect-error This is actually a module
27
- exports.WORKER_PATH = WORKER_PATH = new URL('./WebChild.ts', import.meta.url);
28
- }
29
-
30
- // @ts-expect-error TS2420
31
22
  class WebWorker {
32
- // @ts-expect-error TS2564
33
-
34
23
  constructor(execArgv, onMessage, onError, onExit) {
35
24
  this.execArgv = execArgv;
36
25
  this.onMessage = onMessage;
@@ -38,7 +27,7 @@ class WebWorker {
38
27
  this.onExit = onExit;
39
28
  }
40
29
  start() {
41
- // @ts-expect-error TS1470
30
+ // $FlowFixMe[incompatible-call]
42
31
  this.worker = new Worker(new URL('./WebChild.js', import.meta.url), {
43
32
  name: `Parcel Worker ${id++}`,
44
33
  type: 'module'
@@ -47,28 +36,25 @@ class WebWorker {
47
36
  deferred,
48
37
  promise
49
38
  } = (0, _utils().makeDeferredWithPromise)();
50
-
51
- // @ts-expect-error TS7031
52
39
  this.worker.onmessage = ({
53
40
  data
54
41
  }) => {
55
42
  if (data === 'online') {
56
- // @ts-expect-error TS2554
57
43
  deferred.resolve();
58
44
  return;
59
45
  }
46
+
47
+ // $FlowFixMe assume WorkerMessage as data
60
48
  this.handleMessage(data);
61
49
  };
62
50
  this.worker.onerror = this.onError;
63
51
  // Web workers can't crash or intentionally stop on their own, apart from stop() below
64
52
  // this.worker.on('exit', this.onExit);
65
53
 
66
- // @ts-expect-error TS2322
67
54
  return promise;
68
55
  }
69
56
  stop() {
70
57
  if (!this.stopping) {
71
- // @ts-expect-error TS2322
72
58
  this.stopping = (async () => {
73
59
  this.worker.postMessage('stop');
74
60
  let {
@@ -79,7 +65,6 @@ class WebWorker {
79
65
  data
80
66
  }) => {
81
67
  if (data === 'stopped') {
82
- // @ts-expect-error TS2554
83
68
  deferred.resolve();
84
69
  }
85
70
  });
@@ -88,7 +73,6 @@ class WebWorker {
88
73
  this.onExit(0);
89
74
  })();
90
75
  }
91
- // @ts-expect-error TS2322
92
76
  return this.stopping;
93
77
  }
94
78
  handleMessage(data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/workers",
3
- "version": "2.14.21-typescript-5b4d3ad41.0",
3
+ "version": "2.14.21",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -10,28 +10,24 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/atlassian-labs/atlaspack.git"
12
12
  },
13
- "main": "./lib/index.js",
14
- "source": "./src/index.ts",
15
- "types": "./lib/index.d.ts",
13
+ "main": "lib/index.js",
14
+ "source": "src/index.js",
15
+ "types": "index.d.ts",
16
16
  "engines": {
17
17
  "node": ">= 16.0.0"
18
18
  },
19
19
  "dependencies": {
20
- "@atlaspack/build-cache": "2.13.4-typescript-5b4d3ad41.0",
21
- "@atlaspack/diagnostic": "2.14.2-typescript-5b4d3ad41.0",
22
- "@atlaspack/logger": "2.14.14-typescript-5b4d3ad41.0",
23
- "@atlaspack/profiler": "2.14.18-typescript-5b4d3ad41.0",
24
- "@atlaspack/types-internal": "2.15.3-typescript-5b4d3ad41.0",
25
- "@atlaspack/utils": "2.17.3-typescript-5b4d3ad41.0",
20
+ "@atlaspack/build-cache": "2.13.3",
21
+ "@atlaspack/diagnostic": "2.14.1",
22
+ "@atlaspack/logger": "2.14.13",
23
+ "@atlaspack/profiler": "2.14.18",
24
+ "@atlaspack/types-internal": "2.16.0",
25
+ "@atlaspack/utils": "2.17.3",
26
26
  "nullthrows": "^1.1.1"
27
27
  },
28
28
  "browser": {
29
29
  "./src/process/ProcessWorker.js": false,
30
30
  "./src/threads/ThreadsWorker.js": false
31
31
  },
32
- "type": "commonjs",
33
- "scripts": {
34
- "check-ts": "tsc --emitDeclarationOnly --rootDir src"
35
- },
36
- "gitHead": "5b4d3ad41ffa002b989ba77271bb3010a1f05b2a"
37
- }
32
+ "type": "commonjs"
33
+ }