@atlaspack/workers 2.12.1-dev.3450 → 2.12.1-dev.3460

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.
package/lib/WorkerFarm.js CHANGED
@@ -112,7 +112,7 @@ class WorkerFarm extends _events().default {
112
112
 
113
113
  // $FlowFixMe
114
114
  if (process.browser) {
115
- if (this.options.workerPath === '@atlaspack/core/src/worker.js') {
115
+ if (this.options.workerPath === '@atlaspack/core/worker') {
116
116
  this.localWorker = coreWorker;
117
117
  } else {
118
118
  throw new Error('No dynamic require possible: ' + this.options.workerPath);
@@ -299,7 +299,7 @@ class WorkerFarm extends _events().default {
299
299
  } else if (location) {
300
300
  // $FlowFixMe
301
301
  if (process.browser) {
302
- if (location === '@atlaspack/workers/src/bus.js') {
302
+ if (location === '@atlaspack/workers/bus') {
303
303
  mod = bus;
304
304
  } else {
305
305
  throw new Error('No dynamic require possible: ' + location);
package/lib/bus.js CHANGED
@@ -18,7 +18,7 @@ class Bus extends _events().default {
18
18
  if (_childState.child) {
19
19
  _childState.child.workerApi.callMaster({
20
20
  // $FlowFixMe
21
- location: process.browser ? '@atlaspack/workers/src/bus.js' : __filename,
21
+ location: process.browser ? '@atlaspack/workers/bus' : __filename,
22
22
  method: 'emit',
23
23
  args: [event, ...args]
24
24
  }, false);
package/lib/child.js CHANGED
@@ -100,7 +100,7 @@ class Child {
100
100
  async childInit(module, childId) {
101
101
  // $FlowFixMe
102
102
  if (process.browser) {
103
- if (module === '@atlaspack/core/src/worker.js') {
103
+ if (module === '@atlaspack/core/worker') {
104
104
  this.module = coreWorker;
105
105
  } else {
106
106
  throw new Error('No dynamic require possible: ' + module);
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
 
3
- // eslint-disable-next-line monorepo/no-internal-import
4
- module.exports = require('@atlaspack/core/src/worker.js');
3
+ // $FlowFixMe
4
+ module.exports = require('@atlaspack/core/worker');
@@ -11,13 +11,6 @@ function _child_process() {
11
11
  };
12
12
  return data;
13
13
  }
14
- function _path() {
15
- const data = _interopRequireDefault(require("path"));
16
- _path = function () {
17
- return data;
18
- };
19
- return data;
20
- }
21
14
  function _core() {
22
15
  const data = require("@atlaspack/core");
23
16
  _core = function () {
@@ -26,7 +19,7 @@ function _core() {
26
19
  return data;
27
20
  }
28
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
- const WORKER_PATH = _path().default.join(__dirname, 'ProcessChild.js');
22
+ const WORKER_PATH = require.resolve('./ProcessChild');
30
23
  class ProcessWorker {
31
24
  processQueue = true;
32
25
  sendQueue = [];
@@ -11,13 +11,6 @@ function _worker_threads() {
11
11
  };
12
12
  return data;
13
13
  }
14
- function _path() {
15
- const data = _interopRequireDefault(require("path"));
16
- _path = function () {
17
- return data;
18
- };
19
- return data;
20
- }
21
14
  function _core() {
22
15
  const data = require("@atlaspack/core");
23
16
  _core = function () {
@@ -25,8 +18,7 @@ function _core() {
25
18
  };
26
19
  return data;
27
20
  }
28
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
- const WORKER_PATH = _path().default.join(__dirname, 'ThreadsChild.js');
21
+ const WORKER_PATH = require.resolve('./ThreadsChild');
30
22
  class ThreadsWorker {
31
23
  constructor(execArgv, onMessage, onError, onExit) {
32
24
  this.execArgv = execArgv;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/workers",
3
- "version": "2.12.1-dev.3450+58845ef87",
3
+ "version": "2.12.1-dev.3460+340817991",
4
4
  "description": "Blazing fast, zero configuration web application bundler",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "publishConfig": {
@@ -17,20 +17,20 @@
17
17
  "node": ">= 16.0.0"
18
18
  },
19
19
  "dependencies": {
20
- "@atlaspack/diagnostic": "2.12.1-dev.3450+58845ef87",
21
- "@atlaspack/logger": "2.12.1-dev.3450+58845ef87",
22
- "@atlaspack/profiler": "2.12.1-dev.3450+58845ef87",
23
- "@atlaspack/types-internal": "2.12.1-dev.3450+58845ef87",
24
- "@atlaspack/utils": "2.12.1-dev.3450+58845ef87",
20
+ "@atlaspack/diagnostic": "2.12.1-dev.3460+340817991",
21
+ "@atlaspack/logger": "2.12.1-dev.3460+340817991",
22
+ "@atlaspack/profiler": "2.12.1-dev.3460+340817991",
23
+ "@atlaspack/types-internal": "2.12.1-dev.3460+340817991",
24
+ "@atlaspack/utils": "2.12.1-dev.3460+340817991",
25
25
  "nullthrows": "^1.1.1"
26
26
  },
27
27
  "peerDependencies": {
28
- "@atlaspack/core": "^2.12.1-dev.3450+58845ef87"
28
+ "@atlaspack/core": "^2.12.1-dev.3460+340817991"
29
29
  },
30
30
  "browser": {
31
31
  "./src/process/ProcessWorker.js": false,
32
32
  "./src/threads/ThreadsWorker.js": false,
33
33
  "./src/core-worker.js": "./src/core-worker.browser.js"
34
34
  },
35
- "gitHead": "58845ef87446fcedb7d7d8876440c64184645cbb"
35
+ "gitHead": "3408179911d6c67e2bdad99e545dd7a0a9a6782c"
36
36
  }
package/src/Worker.js CHANGED
@@ -51,7 +51,7 @@ export default class Worker extends EventEmitter {
51
51
  let filteredArgs = [];
52
52
  if (process.execArgv) {
53
53
  filteredArgs = process.execArgv.filter(
54
- v =>
54
+ (v) =>
55
55
  !/^--(debug|inspect|no-opt|max-old-space-size=|max-semi-space-size=|expose-gc)/.test(
56
56
  v,
57
57
  ),
@@ -94,13 +94,13 @@ export default class Worker extends EventEmitter {
94
94
  }
95
95
  }
96
96
 
97
- let onMessage = data => this.receive(data);
98
- let onExit = code => {
97
+ let onMessage = (data) => this.receive(data);
98
+ let onExit = (code) => {
99
99
  this.exitCode = code;
100
100
  this.emit('exit', code);
101
101
  };
102
102
 
103
- let onError = err => {
103
+ let onError = (err) => {
104
104
  this.emit('error', err);
105
105
  };
106
106
 
package/src/WorkerFarm.js CHANGED
@@ -105,7 +105,7 @@ export default class WorkerFarm extends EventEmitter {
105
105
 
106
106
  // $FlowFixMe
107
107
  if (process.browser) {
108
- if (this.options.workerPath === '@atlaspack/core/src/worker.js') {
108
+ if (this.options.workerPath === '@atlaspack/core/worker') {
109
109
  this.localWorker = coreWorker;
110
110
  } else {
111
111
  throw new Error(
@@ -266,7 +266,7 @@ export default class WorkerFarm extends EventEmitter {
266
266
 
267
267
  worker.fork(nullthrows(this.options.workerPath));
268
268
 
269
- worker.on('request', data => this.processRequest(data, worker));
269
+ worker.on('request', (data) => this.processRequest(data, worker));
270
270
 
271
271
  worker.on('ready', () => {
272
272
  this.readyWorkers++;
@@ -277,7 +277,7 @@ export default class WorkerFarm extends EventEmitter {
277
277
  });
278
278
  worker.on('response', () => this.processQueue());
279
279
 
280
- worker.on('error', err => this.onError(err, worker));
280
+ worker.on('error', (err) => this.onError(err, worker));
281
281
  worker.once('exit', () => this.stopWorker(worker));
282
282
 
283
283
  this.workers.set(worker.id, worker);
@@ -357,7 +357,7 @@ export default class WorkerFarm extends EventEmitter {
357
357
  } else if (location) {
358
358
  // $FlowFixMe
359
359
  if (process.browser) {
360
- if (location === '@atlaspack/workers/src/bus.js') {
360
+ if (location === '@atlaspack/workers/bus') {
361
361
  mod = (bus: any);
362
362
  } else {
363
363
  throw new Error('No dynamic require possible: ' + location);
@@ -438,7 +438,9 @@ export default class WorkerFarm extends EventEmitter {
438
438
  this.ending = true;
439
439
 
440
440
  await Promise.all(
441
- Array.from(this.workers.values()).map(worker => this.stopWorker(worker)),
441
+ Array.from(this.workers.values()).map((worker) =>
442
+ this.stopWorker(worker),
443
+ ),
442
444
  );
443
445
 
444
446
  for (let handle of this.handles.values()) {
@@ -593,7 +595,7 @@ export default class WorkerFarm extends EventEmitter {
593
595
  }
594
596
 
595
597
  trace.flush();
596
- await new Promise(resolve => {
598
+ await new Promise((resolve) => {
597
599
  stream.once('finish', resolve);
598
600
  });
599
601
 
@@ -629,7 +631,7 @@ export default class WorkerFarm extends EventEmitter {
629
631
  try {
630
632
  let snapshotPaths = await Promise.all(
631
633
  [...this.workers.values()].map(
632
- worker =>
634
+ (worker) =>
633
635
  new Promise((resolve, reject) => {
634
636
  worker.call({
635
637
  method: 'takeHeapSnapshot',
package/src/bus.js CHANGED
@@ -8,9 +8,7 @@ class Bus extends EventEmitter {
8
8
  child.workerApi.callMaster(
9
9
  {
10
10
  // $FlowFixMe
11
- location: process.browser
12
- ? '@atlaspack/workers/src/bus.js'
13
- : __filename,
11
+ location: process.browser ? '@atlaspack/workers/bus' : __filename,
14
12
  method: 'emit',
15
13
  args: [event, ...args],
16
14
  },
package/src/child.js CHANGED
@@ -47,7 +47,7 @@ export class Child {
47
47
 
48
48
  constructor(ChildBackend: Class<ChildImpl>) {
49
49
  this.child = new ChildBackend(
50
- m => {
50
+ (m) => {
51
51
  this.messageListener(m);
52
52
  },
53
53
  () => this.handleEnd(),
@@ -55,11 +55,11 @@ export class Child {
55
55
 
56
56
  // Monitior all logging events inside this child process and forward to
57
57
  // the main process via the bus.
58
- this.loggerDisposable = Logger.onLog(event => {
58
+ this.loggerDisposable = Logger.onLog((event) => {
59
59
  bus.emit('logEvent', event);
60
60
  });
61
61
  // .. and do the same for trace events
62
- this.tracerDisposable = tracer.onTrace(event => {
62
+ this.tracerDisposable = tracer.onTrace((event) => {
63
63
  bus.emit('traceEvent', event);
64
64
  });
65
65
  }
@@ -103,7 +103,7 @@ export class Child {
103
103
  async childInit(module: string, childId: number): Promise<void> {
104
104
  // $FlowFixMe
105
105
  if (process.browser) {
106
- if (module === '@atlaspack/core/src/worker.js') {
106
+ if (module === '@atlaspack/core/worker') {
107
107
  this.module = coreWorker;
108
108
  } else {
109
109
  throw new Error('No dynamic require possible: ' + module);
@@ -1,3 +1,4 @@
1
1
  // @flow
2
- // eslint-disable-next-line monorepo/no-internal-import
3
- module.exports = require('@atlaspack/core/src/worker.js');
2
+
3
+ // $FlowFixMe
4
+ module.exports = require('@atlaspack/core/worker');
package/src/cpuCount.js CHANGED
@@ -29,7 +29,7 @@ export function detectRealCores(): number {
29
29
  } else if (platform === 'win32') {
30
30
  const str = exec('wmic cpu get NumberOfCores').match(/\d+/g);
31
31
  if (str !== null) {
32
- amount = parseInt(str.filter(n => n !== '')[0], 10);
32
+ amount = parseInt(str.filter((n) => n !== '')[0], 10);
33
33
  }
34
34
  }
35
35
 
@@ -22,7 +22,7 @@ export default class ProcessChild implements ChildImpl {
22
22
 
23
23
  this.onMessage = onMessage;
24
24
  this.onExit = onExit;
25
- process.on('message', data => this.handleMessage(data));
25
+ process.on('message', (data) => this.handleMessage(data));
26
26
  }
27
27
 
28
28
  handleMessage(data: string): void {
@@ -35,7 +35,7 @@ export default class ProcessChild implements ChildImpl {
35
35
 
36
36
  send(data: WorkerMessage) {
37
37
  let processSend = nullthrows(process.send).bind(process);
38
- processSend(serialize(data).toString('base64'), err => {
38
+ processSend(serialize(data).toString('base64'), (err) => {
39
39
  if (err && err instanceof Error) {
40
40
  // $FlowFixMe[prop-missing]
41
41
  if (err.code === 'ERR_IPC_CHANNEL_CLOSED') {
@@ -8,10 +8,9 @@ import type {
8
8
  WorkerMessage,
9
9
  } from '../types';
10
10
  import childProcess, {type ChildProcess} from 'child_process';
11
- import path from 'path';
12
11
  import {serialize, deserialize} from '@atlaspack/core';
13
12
 
14
- const WORKER_PATH = path.join(__dirname, 'ProcessChild.js');
13
+ const WORKER_PATH = require.resolve('./ProcessChild');
15
14
 
16
15
  export default class ProcessWorker implements WorkerImpl {
17
16
  execArgv: Object;
@@ -55,7 +54,7 @@ export default class ProcessWorker implements WorkerImpl {
55
54
  this.child.send('die');
56
55
 
57
56
  let forceKill = setTimeout(() => this.child.kill('SIGINT'), 500);
58
- await new Promise(resolve => {
57
+ await new Promise((resolve) => {
59
58
  this.child.once('exit', resolve);
60
59
  });
61
60
 
@@ -68,20 +67,23 @@ export default class ProcessWorker implements WorkerImpl {
68
67
  return;
69
68
  }
70
69
 
71
- let result = this.child.send(serialize(data).toString('base64'), error => {
72
- if (error && error instanceof Error) {
73
- // Ignore this, the workerfarm handles child errors
74
- return;
75
- }
76
-
77
- this.processQueue = true;
78
-
79
- if (this.sendQueue.length > 0) {
80
- let queueCopy = this.sendQueue.slice(0);
81
- this.sendQueue = [];
82
- queueCopy.forEach(entry => this.send(entry));
83
- }
84
- });
70
+ let result = this.child.send(
71
+ serialize(data).toString('base64'),
72
+ (error) => {
73
+ if (error && error instanceof Error) {
74
+ // Ignore this, the workerfarm handles child errors
75
+ return;
76
+ }
77
+
78
+ this.processQueue = true;
79
+
80
+ if (this.sendQueue.length > 0) {
81
+ let queueCopy = this.sendQueue.slice(0);
82
+ this.sendQueue = [];
83
+ queueCopy.forEach((entry) => this.send(entry));
84
+ }
85
+ },
86
+ );
85
87
 
86
88
  if (!result || /^win/.test(process.platform)) {
87
89
  // Queue is handling too much messages throttle it
@@ -26,7 +26,7 @@ export default class ThreadsChild implements ChildImpl {
26
26
 
27
27
  this.onMessage = onMessage;
28
28
  this.onExit = onExit;
29
- parentPort.on('message', data => this.handleMessage(data));
29
+ parentPort.on('message', (data) => this.handleMessage(data));
30
30
  parentPort.on('close', this.onExit);
31
31
  }
32
32
 
@@ -8,13 +8,12 @@ import type {
8
8
  WorkerMessage,
9
9
  } from '../types';
10
10
  import {Worker} from 'worker_threads';
11
- import path from 'path';
12
11
  import {
13
12
  prepareForSerialization,
14
13
  restoreDeserializedObject,
15
14
  } from '@atlaspack/core';
16
15
 
17
- const WORKER_PATH = path.join(__dirname, 'ThreadsChild.js');
16
+ const WORKER_PATH = require.resolve('./ThreadsChild');
18
17
 
19
18
  export default class ThreadsWorker implements WorkerImpl {
20
19
  execArgv: Object;
@@ -41,11 +40,11 @@ export default class ThreadsWorker implements WorkerImpl {
41
40
  env: process.env,
42
41
  });
43
42
 
44
- this.worker.on('message', data => this.handleMessage(data));
43
+ this.worker.on('message', (data) => this.handleMessage(data));
45
44
  this.worker.on('error', this.onError);
46
45
  this.worker.on('exit', this.onExit);
47
46
 
48
- return new Promise<void>(resolve => {
47
+ return new Promise<void>((resolve) => {
49
48
  this.worker.on('online', resolve);
50
49
  });
51
50
  }
@@ -44,7 +44,7 @@ describe('WorkerFarm', function () {
44
44
  assert.equal(await workerfarm.run(i), i);
45
45
  }
46
46
 
47
- await new Promise(resolve => workerfarm.once('warmedup', resolve));
47
+ await new Promise((resolve) => workerfarm.once('warmedup', resolve));
48
48
 
49
49
  assert(workerfarm.workers.size > 0, 'Should have spawned workers.');
50
50
  assert(
@@ -134,7 +134,7 @@ describe('WorkerFarm', function () {
134
134
 
135
135
  it('Forwards stdio from the child process and levels event source if shouldPatchConsole is true', async () => {
136
136
  let events = [];
137
- let logDisposable = Logger.onLog(event => events.push(event));
137
+ let logDisposable = Logger.onLog((event) => events.push(event));
138
138
 
139
139
  let workerfarm = new WorkerFarm({
140
140
  warmWorkers: true,
@@ -209,7 +209,7 @@ describe('WorkerFarm', function () {
209
209
 
210
210
  it('Forwards logger events to the main process', async () => {
211
211
  let events = [];
212
- let logDisposable = Logger.onLog(event => events.push(event));
212
+ let logDisposable = Logger.onLog((event) => events.push(event));
213
213
 
214
214
  let workerfarm = new WorkerFarm({
215
215
  warmWorkers: true,