@parcel/workers 2.0.0-nightly.149 → 2.0.0-nightly.1491

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. package/index.d.ts +23 -0
  2. package/lib/Handle.js +16 -58
  3. package/lib/Worker.js +103 -62
  4. package/lib/WorkerFarm.js +272 -192
  5. package/lib/backend.js +4 -6
  6. package/lib/bus.js +11 -13
  7. package/lib/child.js +140 -116
  8. package/lib/childState.js +2 -4
  9. package/lib/core-worker.browser.js +4 -0
  10. package/lib/core-worker.js +4 -0
  11. package/lib/cpuCount.js +36 -25
  12. package/lib/index.js +35 -32
  13. package/lib/process/ProcessChild.js +18 -24
  14. package/lib/process/ProcessWorker.js +27 -38
  15. package/lib/threads/ThreadsChild.js +26 -28
  16. package/lib/threads/ThreadsWorker.js +25 -31
  17. package/lib/web/WebChild.js +44 -0
  18. package/lib/web/WebWorker.js +85 -0
  19. package/package.json +19 -8
  20. package/src/Handle.js +10 -39
  21. package/src/Worker.js +95 -22
  22. package/src/WorkerFarm.js +267 -62
  23. package/src/backend.js +5 -0
  24. package/src/bus.js +3 -2
  25. package/src/child.js +95 -26
  26. package/src/core-worker.browser.js +3 -0
  27. package/src/core-worker.js +2 -0
  28. package/src/cpuCount.js +23 -10
  29. package/src/index.js +8 -2
  30. package/src/process/ProcessChild.js +2 -1
  31. package/src/process/ProcessWorker.js +1 -1
  32. package/src/threads/ThreadsWorker.js +2 -2
  33. package/src/types.js +1 -1
  34. package/src/web/WebChild.js +50 -0
  35. package/src/web/WebWorker.js +85 -0
  36. package/test/cpuCount.test.js +1 -1
  37. package/test/integration/workerfarm/console.js +1 -1
  38. package/test/integration/workerfarm/logging.js +1 -1
  39. package/test/integration/workerfarm/reverse-handle.js +2 -2
  40. package/test/workerfarm.js +5 -5
  41. package/lib/Profiler.js +0 -70
  42. package/lib/Trace.js +0 -126
  43. package/src/Profiler.js +0 -93
  44. package/src/Trace.js +0 -121
package/lib/Trace.js DELETED
@@ -1,126 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _chromeTraceEvent = require("chrome-trace-event");
9
-
10
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
-
12
- class Trace {
13
- constructor() {
14
- _defineProperty(this, "tracer", void 0);
15
-
16
- _defineProperty(this, "tid", void 0);
17
-
18
- _defineProperty(this, "eventId", void 0);
19
-
20
- this.tracer = new _chromeTraceEvent.Tracer();
21
- this.tid = 0;
22
- this.eventId = 0;
23
- this.init();
24
- }
25
-
26
- getEventId() {
27
- return this.eventId++;
28
- }
29
-
30
- init() {
31
- this.tracer.instantEvent({
32
- name: 'TracingStartedInPage',
33
- id: this.getEventId(),
34
- cat: ['disabled-by-default-devtools.timeline'],
35
- args: {
36
- data: {
37
- sessionId: '-1',
38
- page: '0xfff',
39
- frames: [{
40
- frame: '0xfff',
41
- url: 'parcel',
42
- name: ''
43
- }]
44
- }
45
- }
46
- });
47
- this.tracer.instantEvent({
48
- name: 'TracingStartedInBrowser',
49
- id: this.getEventId(),
50
- cat: ['disabled-by-default-devtools.timeline'],
51
- args: {
52
- data: {
53
- sessionId: '-1'
54
- }
55
- }
56
- });
57
- }
58
-
59
- addCPUProfile(name, profile) {
60
- const trace = this.tracer;
61
- const tid = this.tid;
62
- this.tid++;
63
- const cpuStartTime = profile.startTime;
64
- const cpuEndTime = profile.endTime;
65
- trace.instantEvent({
66
- tid,
67
- id: this.getEventId(),
68
- cat: ['toplevel'],
69
- name: 'TaskQueueManager::ProcessTaskFromWorkQueue',
70
- args: {
71
- src_file: '../../ipc/ipc_moji_bootstrap.cc',
72
- src_func: 'Accept'
73
- },
74
- ts: cpuStartTime
75
- });
76
- trace.completeEvent({
77
- tid,
78
- name: 'EvaluateScript',
79
- id: this.getEventId(),
80
- cat: ['devtools.timeline'],
81
- ts: cpuStartTime,
82
- dur: cpuEndTime - cpuStartTime,
83
- args: {
84
- data: {
85
- url: 'parcel',
86
- lineNumber: 1,
87
- columnNumber: 1,
88
- frame: '0xFFF'
89
- }
90
- }
91
- });
92
- trace.instantEvent({
93
- tid,
94
- ts: 0,
95
- ph: 'M',
96
- cat: ['__metadata'],
97
- name: 'thread_name',
98
- args: {
99
- name
100
- }
101
- });
102
- trace.instantEvent({
103
- tid,
104
- name: 'CpuProfile',
105
- id: this.getEventId(),
106
- cat: ['disabled-by-default-devtools.timeline'],
107
- ts: cpuEndTime,
108
- args: {
109
- data: {
110
- cpuProfile: profile
111
- }
112
- }
113
- });
114
- }
115
-
116
- pipe(writable) {
117
- return this.tracer.pipe(writable);
118
- }
119
-
120
- flush() {
121
- this.tracer.push(null);
122
- }
123
-
124
- }
125
-
126
- exports.default = Trace;
package/src/Profiler.js DELETED
@@ -1,93 +0,0 @@
1
- // @flow
2
- import type {Session} from 'inspector';
3
- import invariant from 'assert';
4
- import ThrowableDiagnostic from '@parcel/diagnostic';
5
-
6
- // https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-Profile
7
- export type Profile = {|
8
- nodes: Array<ProfileNode>,
9
- startTime: number,
10
- endTime: number,
11
- samples?: Array<number>,
12
- timeDeltas?: Array<number>,
13
- |};
14
-
15
- // https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-ProfileNode
16
- type ProfileNode = {|
17
- id: number,
18
- callFrame: CallFrame,
19
- hitCount?: number,
20
- children?: Array<number>,
21
- deoptReason?: string,
22
- positionTicks?: PositionTickInfo,
23
- |};
24
-
25
- // https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-CallFrame
26
- type CallFrame = {|
27
- functionName: string,
28
- scriptId: string,
29
- url: string,
30
- lineNumber: string,
31
- columnNumber: string,
32
- |};
33
-
34
- // https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-PositionTickInfo
35
- type PositionTickInfo = {|
36
- line: number,
37
- ticks: number,
38
- |};
39
-
40
- export default class Profiler {
41
- session: Session;
42
-
43
- startProfiling() {
44
- let inspector;
45
- try {
46
- inspector = require('inspector');
47
- } catch (err) {
48
- throw new ThrowableDiagnostic({
49
- diagnostic: {
50
- message: `The inspector module isn't available`,
51
- origin: '@parcel/workers',
52
- hints: ['Disable build profiling'],
53
- },
54
- });
55
- }
56
-
57
- this.session = new inspector.Session();
58
- this.session.connect();
59
-
60
- return Promise.all([
61
- this.sendCommand('Profiler.setSamplingInterval', {
62
- interval: 100,
63
- }),
64
- this.sendCommand('Profiler.enable'),
65
- this.sendCommand('Profiler.start'),
66
- ]);
67
- }
68
-
69
- sendCommand(method: string, params: mixed): Promise<{profile: Profile, ...}> {
70
- invariant(this.session != null);
71
- return new Promise((resolve, reject) => {
72
- this.session.post(method, params, (err, params) => {
73
- if (err == null) {
74
- resolve(params);
75
- } else {
76
- reject(err);
77
- }
78
- });
79
- });
80
- }
81
-
82
- destroy() {
83
- if (this.session != null) {
84
- this.session.disconnect();
85
- }
86
- }
87
-
88
- async stopProfiling(): Promise<Profile> {
89
- let res = await this.sendCommand('Profiler.stop');
90
- this.destroy();
91
- return res.profile;
92
- }
93
- }
package/src/Trace.js DELETED
@@ -1,121 +0,0 @@
1
- // @flow
2
- import type {Profile} from './Profiler';
3
- import type {Writable} from 'stream';
4
- import {Tracer} from 'chrome-trace-event';
5
-
6
- export default class Trace {
7
- tracer: Tracer;
8
- tid: number;
9
- eventId: number;
10
-
11
- constructor() {
12
- this.tracer = new Tracer();
13
- this.tid = 0;
14
- this.eventId = 0;
15
- this.init();
16
- }
17
-
18
- getEventId() {
19
- return this.eventId++;
20
- }
21
-
22
- init() {
23
- this.tracer.instantEvent({
24
- name: 'TracingStartedInPage',
25
- id: this.getEventId(),
26
- cat: ['disabled-by-default-devtools.timeline'],
27
- args: {
28
- data: {
29
- sessionId: '-1',
30
- page: '0xfff',
31
- frames: [
32
- {
33
- frame: '0xfff',
34
- url: 'parcel',
35
- name: '',
36
- },
37
- ],
38
- },
39
- },
40
- });
41
-
42
- this.tracer.instantEvent({
43
- name: 'TracingStartedInBrowser',
44
- id: this.getEventId(),
45
- cat: ['disabled-by-default-devtools.timeline'],
46
- args: {
47
- data: {
48
- sessionId: '-1',
49
- },
50
- },
51
- });
52
- }
53
-
54
- addCPUProfile(name: string, profile: Profile) {
55
- const trace = this.tracer;
56
- const tid = this.tid;
57
- this.tid++;
58
-
59
- const cpuStartTime = profile.startTime;
60
- const cpuEndTime = profile.endTime;
61
-
62
- trace.instantEvent({
63
- tid,
64
- id: this.getEventId(),
65
- cat: ['toplevel'],
66
- name: 'TaskQueueManager::ProcessTaskFromWorkQueue',
67
- args: {
68
- src_file: '../../ipc/ipc_moji_bootstrap.cc',
69
- src_func: 'Accept',
70
- },
71
- ts: cpuStartTime,
72
- });
73
-
74
- trace.completeEvent({
75
- tid,
76
- name: 'EvaluateScript',
77
- id: this.getEventId(),
78
- cat: ['devtools.timeline'],
79
- ts: cpuStartTime,
80
- dur: cpuEndTime - cpuStartTime,
81
- args: {
82
- data: {
83
- url: 'parcel',
84
- lineNumber: 1,
85
- columnNumber: 1,
86
- frame: '0xFFF',
87
- },
88
- },
89
- });
90
-
91
- trace.instantEvent({
92
- tid,
93
- ts: 0,
94
- ph: 'M',
95
- cat: ['__metadata'],
96
- name: 'thread_name',
97
- args: {name},
98
- });
99
-
100
- trace.instantEvent({
101
- tid,
102
- name: 'CpuProfile',
103
- id: this.getEventId(),
104
- cat: ['disabled-by-default-devtools.timeline'],
105
- ts: cpuEndTime,
106
- args: {
107
- data: {
108
- cpuProfile: profile,
109
- },
110
- },
111
- });
112
- }
113
-
114
- pipe(writable: Writable) {
115
- return this.tracer.pipe(writable);
116
- }
117
-
118
- flush() {
119
- this.tracer.push(null);
120
- }
121
- }