@checkly/playwright-core 1.51.11-beta.1 → 1.51.11

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/package.json +1 -1
  2. package/lib/common/socksProxy.js +0 -569
  3. package/lib/common/timeoutSettings.js +0 -73
  4. package/lib/common/types.js +0 -5
  5. package/lib/generated/recorderSource.js +0 -7
  6. package/lib/image_tools/colorUtils.js +0 -98
  7. package/lib/image_tools/compare.js +0 -108
  8. package/lib/image_tools/imageChannel.js +0 -70
  9. package/lib/image_tools/stats.js +0 -102
  10. package/lib/protocol/transport.js +0 -82
  11. package/lib/server/recorder/codeGenerator.js +0 -154
  12. package/lib/server/recorder/csharp.js +0 -311
  13. package/lib/server/recorder/java.js +0 -249
  14. package/lib/server/recorder/javascript.js +0 -230
  15. package/lib/server/recorder/jsonl.js +0 -48
  16. package/lib/server/recorder/language.js +0 -45
  17. package/lib/server/recorder/python.js +0 -276
  18. package/lib/server/recorder/recorderActions.js +0 -6
  19. package/lib/server/recorder/utils.js +0 -46
  20. package/lib/third_party/diff_match_patch.js +0 -2222
  21. package/lib/utils/ascii.js +0 -31
  22. package/lib/utils/comparators.js +0 -171
  23. package/lib/utils/crypto.js +0 -174
  24. package/lib/utils/debug.js +0 -46
  25. package/lib/utils/debugLogger.js +0 -91
  26. package/lib/utils/env.js +0 -49
  27. package/lib/utils/eventsHelper.js +0 -38
  28. package/lib/utils/glob.js +0 -84
  29. package/lib/utils/happy-eyeballs.js +0 -210
  30. package/lib/utils/headers.js +0 -52
  31. package/lib/utils/hostPlatform.js +0 -133
  32. package/lib/utils/httpServer.js +0 -237
  33. package/lib/utils/linuxUtils.js +0 -78
  34. package/lib/utils/manualPromise.js +0 -109
  35. package/lib/utils/mimeType.js +0 -30
  36. package/lib/utils/multimap.js +0 -75
  37. package/lib/utils/network.js +0 -160
  38. package/lib/utils/processLauncher.js +0 -248
  39. package/lib/utils/profiler.js +0 -53
  40. package/lib/utils/rtti.js +0 -44
  41. package/lib/utils/semaphore.js +0 -51
  42. package/lib/utils/spawnAsync.js +0 -45
  43. package/lib/utils/task.js +0 -58
  44. package/lib/utils/time.js +0 -37
  45. package/lib/utils/traceUtils.js +0 -44
  46. package/lib/utils/userAgent.js +0 -105
  47. package/lib/utils/wsServer.js +0 -127
  48. package/lib/utils/zipFile.js +0 -75
  49. package/lib/vite/traceViewer/sw.bundle.js +0 -3
@@ -1,248 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.envArrayToObject = envArrayToObject;
7
- exports.gracefullyCloseAll = gracefullyCloseAll;
8
- exports.gracefullyCloseSet = void 0;
9
- exports.gracefullyProcessExitDoNotHang = gracefullyProcessExitDoNotHang;
10
- exports.launchProcess = launchProcess;
11
- var _fs = _interopRequireDefault(require("fs"));
12
- var childProcess = _interopRequireWildcard(require("child_process"));
13
- var readline = _interopRequireWildcard(require("readline"));
14
- var _ = require("./");
15
- var _fileUtils = require("./fileUtils");
16
- 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); }
17
- 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; }
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
- /**
20
- * Copyright 2017 Google Inc. All rights reserved.
21
- * Modifications copyright (c) Microsoft Corporation.
22
- *
23
- * Licensed under the Apache License, Version 2.0 (the "License");
24
- * you may not use this file except in compliance with the License.
25
- * You may obtain a copy of the License at
26
- *
27
- * http://www.apache.org/licenses/LICENSE-2.0
28
- *
29
- * Unless required by applicable law or agreed to in writing, software
30
- * distributed under the License is distributed on an "AS IS" BASIS,
31
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
- * See the License for the specific language governing permissions and
33
- * limitations under the License.
34
- */
35
-
36
- const gracefullyCloseSet = exports.gracefullyCloseSet = new Set();
37
- const killSet = new Set();
38
- async function gracefullyCloseAll() {
39
- await Promise.all(Array.from(gracefullyCloseSet).map(gracefullyClose => gracefullyClose().catch(e => {})));
40
- }
41
- function gracefullyProcessExitDoNotHang(code) {
42
- // Force exit after 30 seconds.
43
- // eslint-disable-next-line no-restricted-properties
44
- setTimeout(() => process.exit(code), 30000);
45
- // Meanwhile, try to gracefully close all browsers.
46
- gracefullyCloseAll().then(() => {
47
- // eslint-disable-next-line no-restricted-properties
48
- process.exit(code);
49
- });
50
- }
51
- function exitHandler() {
52
- for (const kill of killSet) kill();
53
- }
54
- let sigintHandlerCalled = false;
55
- function sigintHandler() {
56
- const exitWithCode130 = () => {
57
- // Give tests a chance to see that launched process did exit and dispatch any async calls.
58
- if ((0, _.isUnderTest)()) {
59
- // eslint-disable-next-line no-restricted-properties
60
- setTimeout(() => process.exit(130), 1000);
61
- } else {
62
- // eslint-disable-next-line no-restricted-properties
63
- process.exit(130);
64
- }
65
- };
66
- if (sigintHandlerCalled) {
67
- // Resort to default handler from this point on, just in case we hang/stall.
68
- process.off('SIGINT', sigintHandler);
69
-
70
- // Upon second Ctrl+C, immediately kill browsers and exit.
71
- // This prevents hanging in the case where closing the browser takes a lot of time or is buggy.
72
- for (const kill of killSet) kill();
73
- exitWithCode130();
74
- } else {
75
- sigintHandlerCalled = true;
76
- gracefullyCloseAll().then(() => exitWithCode130());
77
- }
78
- }
79
- function sigtermHandler() {
80
- gracefullyCloseAll();
81
- }
82
- function sighupHandler() {
83
- gracefullyCloseAll();
84
- }
85
- const installedHandlers = new Set();
86
- const processHandlers = {
87
- exit: exitHandler,
88
- SIGINT: sigintHandler,
89
- SIGTERM: sigtermHandler,
90
- SIGHUP: sighupHandler
91
- };
92
- function addProcessHandlerIfNeeded(name) {
93
- if (!installedHandlers.has(name)) {
94
- installedHandlers.add(name);
95
- process.on(name, processHandlers[name]);
96
- }
97
- }
98
- function removeProcessHandlersIfNeeded() {
99
- if (killSet.size) return;
100
- for (const handler of installedHandlers) process.off(handler, processHandlers[handler]);
101
- installedHandlers.clear();
102
- }
103
- async function launchProcess(options) {
104
- const stdio = options.stdio === 'pipe' ? ['ignore', 'pipe', 'pipe', 'pipe', 'pipe'] : ['pipe', 'pipe', 'pipe'];
105
- options.log(`<launching> ${options.command} ${options.args ? options.args.join(' ') : ''}`);
106
- const spawnOptions = {
107
- // On non-windows platforms, `detached: true` makes child process a leader of a new
108
- // process group, making it possible to kill child process tree with `.kill(-pid)` command.
109
- // @see https://nodejs.org/api/child_process.html#child_process_options_detached
110
- detached: process.platform !== 'win32',
111
- env: options.env,
112
- cwd: options.cwd,
113
- shell: options.shell,
114
- stdio
115
- };
116
- const spawnedProcess = childProcess.spawn(options.command, options.args || [], spawnOptions);
117
- const cleanup = async () => {
118
- options.log(`[pid=${spawnedProcess.pid || 'N/A'}] starting temporary directories cleanup`);
119
- const errors = await (0, _fileUtils.removeFolders)(options.tempDirectories);
120
- for (let i = 0; i < options.tempDirectories.length; ++i) {
121
- if (errors[i]) options.log(`[pid=${spawnedProcess.pid || 'N/A'}] exception while removing ${options.tempDirectories[i]}: ${errors[i]}`);
122
- }
123
- options.log(`[pid=${spawnedProcess.pid || 'N/A'}] finished temporary directories cleanup`);
124
- };
125
-
126
- // Prevent Unhandled 'error' event.
127
- spawnedProcess.on('error', () => {});
128
- if (!spawnedProcess.pid) {
129
- let failed;
130
- const failedPromise = new Promise((f, r) => failed = f);
131
- spawnedProcess.once('error', error => {
132
- failed(new Error('Failed to launch: ' + error));
133
- });
134
- return cleanup().then(() => failedPromise).then(e => Promise.reject(e));
135
- }
136
- options.log(`<launched> pid=${spawnedProcess.pid}`);
137
- const stdout = readline.createInterface({
138
- input: spawnedProcess.stdout
139
- });
140
- stdout.on('line', data => {
141
- options.log(`[pid=${spawnedProcess.pid}][out] ` + data);
142
- });
143
- const stderr = readline.createInterface({
144
- input: spawnedProcess.stderr
145
- });
146
- stderr.on('line', data => {
147
- options.log(`[pid=${spawnedProcess.pid}][err] ` + data);
148
- });
149
- let processClosed = false;
150
- let fulfillCleanup = () => {};
151
- const waitForCleanup = new Promise(f => fulfillCleanup = f);
152
- spawnedProcess.once('exit', (exitCode, signal) => {
153
- options.log(`[pid=${spawnedProcess.pid}] <process did exit: exitCode=${exitCode}, signal=${signal}>`);
154
- processClosed = true;
155
- gracefullyCloseSet.delete(gracefullyClose);
156
- killSet.delete(killProcessAndCleanup);
157
- removeProcessHandlersIfNeeded();
158
- options.onExit(exitCode, signal);
159
- // Cleanup as process exits.
160
- cleanup().then(fulfillCleanup);
161
- });
162
- addProcessHandlerIfNeeded('exit');
163
- if (options.handleSIGINT) addProcessHandlerIfNeeded('SIGINT');
164
- if (options.handleSIGTERM) addProcessHandlerIfNeeded('SIGTERM');
165
- if (options.handleSIGHUP) addProcessHandlerIfNeeded('SIGHUP');
166
- gracefullyCloseSet.add(gracefullyClose);
167
- killSet.add(killProcessAndCleanup);
168
- let gracefullyClosing = false;
169
- async function gracefullyClose() {
170
- // We keep listeners until we are done, to handle 'exit' and 'SIGINT' while
171
- // asynchronously closing to prevent zombie processes. This might introduce
172
- // reentrancy to this function, for example user sends SIGINT second time.
173
- // In this case, let's forcefully kill the process.
174
- if (gracefullyClosing) {
175
- options.log(`[pid=${spawnedProcess.pid}] <forcefully close>`);
176
- killProcess();
177
- await waitForCleanup; // Ensure the process is dead and we have cleaned up.
178
- return;
179
- }
180
- gracefullyClosing = true;
181
- options.log(`[pid=${spawnedProcess.pid}] <gracefully close start>`);
182
- await options.attemptToGracefullyClose().catch(() => killProcess());
183
- await waitForCleanup; // Ensure the process is dead and we have cleaned up.
184
- options.log(`[pid=${spawnedProcess.pid}] <gracefully close end>`);
185
- }
186
-
187
- // This method has to be sync to be used in the 'exit' event handler.
188
- function killProcess() {
189
- gracefullyCloseSet.delete(gracefullyClose);
190
- killSet.delete(killProcessAndCleanup);
191
- removeProcessHandlersIfNeeded();
192
- options.log(`[pid=${spawnedProcess.pid}] <kill>`);
193
- if (spawnedProcess.pid && !spawnedProcess.killed && !processClosed) {
194
- options.log(`[pid=${spawnedProcess.pid}] <will force kill>`);
195
- // Force kill the browser.
196
- try {
197
- if (process.platform === 'win32') {
198
- const taskkillProcess = childProcess.spawnSync(`taskkill /pid ${spawnedProcess.pid} /T /F`, {
199
- shell: true
200
- });
201
- const [stdout, stderr] = [taskkillProcess.stdout.toString(), taskkillProcess.stderr.toString()];
202
- if (stdout) options.log(`[pid=${spawnedProcess.pid}] taskkill stdout: ${stdout}`);
203
- if (stderr) options.log(`[pid=${spawnedProcess.pid}] taskkill stderr: ${stderr}`);
204
- } else {
205
- process.kill(-spawnedProcess.pid, 'SIGKILL');
206
- }
207
- } catch (e) {
208
- options.log(`[pid=${spawnedProcess.pid}] exception while trying to kill process: ${e}`);
209
- // the process might have already stopped
210
- }
211
- } else {
212
- options.log(`[pid=${spawnedProcess.pid}] <skipped force kill spawnedProcess.killed=${spawnedProcess.killed} processClosed=${processClosed}>`);
213
- }
214
- }
215
- function killProcessAndCleanup() {
216
- killProcess();
217
- options.log(`[pid=${spawnedProcess.pid || 'N/A'}] starting temporary directories cleanup`);
218
- for (const dir of options.tempDirectories) {
219
- try {
220
- _fs.default.rmSync(dir, {
221
- force: true,
222
- recursive: true,
223
- maxRetries: 5
224
- });
225
- } catch (e) {
226
- options.log(`[pid=${spawnedProcess.pid || 'N/A'}] exception while removing ${dir}: ${e}`);
227
- }
228
- }
229
- options.log(`[pid=${spawnedProcess.pid || 'N/A'}] finished temporary directories cleanup`);
230
- }
231
- function killAndWait() {
232
- killProcess();
233
- return waitForCleanup;
234
- }
235
- return {
236
- launchedProcess: spawnedProcess,
237
- gracefullyClose,
238
- kill: killAndWait
239
- };
240
- }
241
- function envArrayToObject(env) {
242
- const result = {};
243
- for (const {
244
- name,
245
- value
246
- } of env) result[name] = value;
247
- return result;
248
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.startProfiling = startProfiling;
7
- exports.stopProfiling = stopProfiling;
8
- var fs = _interopRequireWildcard(require("fs"));
9
- var path = _interopRequireWildcard(require("path"));
10
- 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); }
11
- 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; }
12
- /**
13
- * Copyright Microsoft Corporation. All rights reserved.
14
- *
15
- * Licensed under the Apache License, Version 2.0 (the "License");
16
- * you may not use this file except in compliance with the License.
17
- * You may obtain a copy of the License at
18
- *
19
- * http://www.apache.org/licenses/LICENSE-2.0
20
- *
21
- * Unless required by applicable law or agreed to in writing, software
22
- * distributed under the License is distributed on an "AS IS" BASIS,
23
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
- * See the License for the specific language governing permissions and
25
- * limitations under the License.
26
- */
27
-
28
- const profileDir = process.env.PWTEST_PROFILE_DIR || '';
29
- let session;
30
- async function startProfiling() {
31
- if (!profileDir) return;
32
- session = new (require('inspector').Session)();
33
- session.connect();
34
- await new Promise(f => {
35
- session.post('Profiler.enable', () => {
36
- session.post('Profiler.start', f);
37
- });
38
- });
39
- }
40
- async function stopProfiling(profileName) {
41
- if (!profileDir) return;
42
- await new Promise(f => session.post('Profiler.stop', (err, {
43
- profile
44
- }) => {
45
- if (!err) {
46
- fs.mkdirSync(profileDir, {
47
- recursive: true
48
- });
49
- fs.writeFileSync(path.join(profileDir, profileName + '.json'), JSON.stringify(profile));
50
- }
51
- f();
52
- }));
53
- }
package/lib/utils/rtti.js DELETED
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isError = isError;
7
- exports.isLikelyNpxGlobal = void 0;
8
- exports.isObject = isObject;
9
- exports.isRegExp = isRegExp;
10
- Object.defineProperty(exports, "isString", {
11
- enumerable: true,
12
- get: function () {
13
- return _stringUtils.isString;
14
- }
15
- });
16
- var _stringUtils = require("./isomorphic/stringUtils");
17
- /**
18
- * Copyright (c) Microsoft Corporation.
19
- *
20
- * Licensed under the Apache License, Version 2.0 (the "License");
21
- * you may not use this file except in compliance with the License.
22
- * You may obtain a copy of the License at
23
- *
24
- * http://www.apache.org/licenses/LICENSE-2.0
25
- *
26
- * Unless required by applicable law or agreed to in writing, software
27
- * distributed under the License is distributed on an "AS IS" BASIS,
28
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
- * See the License for the specific language governing permissions and
30
- * limitations under the License.
31
- */
32
-
33
- function isRegExp(obj) {
34
- return obj instanceof RegExp || Object.prototype.toString.call(obj) === '[object RegExp]';
35
- }
36
- function isObject(obj) {
37
- return typeof obj === 'object' && obj !== null;
38
- }
39
- function isError(obj) {
40
- var _Object$getPrototypeO;
41
- return obj instanceof Error || obj && ((_Object$getPrototypeO = Object.getPrototypeOf(obj)) === null || _Object$getPrototypeO === void 0 ? void 0 : _Object$getPrototypeO.name) === 'Error';
42
- }
43
- const isLikelyNpxGlobal = () => process.argv.length >= 2 && process.argv[1].includes('_npx');
44
- exports.isLikelyNpxGlobal = isLikelyNpxGlobal;
@@ -1,51 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Semaphore = void 0;
7
- var _manualPromise = require("./manualPromise");
8
- /**
9
- * Copyright (c) Microsoft Corporation.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
-
24
- class Semaphore {
25
- constructor(max) {
26
- this._max = void 0;
27
- this._acquired = 0;
28
- this._queue = [];
29
- this._max = max;
30
- }
31
- setMax(max) {
32
- this._max = max;
33
- }
34
- acquire() {
35
- const lock = new _manualPromise.ManualPromise();
36
- this._queue.push(lock);
37
- this._flush();
38
- return lock;
39
- }
40
- release() {
41
- --this._acquired;
42
- this._flush();
43
- }
44
- _flush() {
45
- while (this._acquired < this._max && this._queue.length) {
46
- ++this._acquired;
47
- this._queue.shift().resolve();
48
- }
49
- }
50
- }
51
- exports.Semaphore = Semaphore;
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.spawnAsync = spawnAsync;
7
- var _child_process = require("child_process");
8
- /**
9
- * Copyright (c) Microsoft Corporation.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
-
24
- function spawnAsync(cmd, args, options = {}) {
25
- const process = (0, _child_process.spawn)(cmd, args, Object.assign({
26
- windowsHide: true
27
- }, options));
28
- return new Promise(resolve => {
29
- let stdout = '';
30
- let stderr = '';
31
- if (process.stdout) process.stdout.on('data', data => stdout += data.toString());
32
- if (process.stderr) process.stderr.on('data', data => stderr += data.toString());
33
- process.on('close', code => resolve({
34
- stdout,
35
- stderr,
36
- code
37
- }));
38
- process.on('error', error => resolve({
39
- stdout,
40
- stderr,
41
- code: 0,
42
- error
43
- }));
44
- });
45
- }
package/lib/utils/task.js DELETED
@@ -1,58 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.makeWaitForNextTask = makeWaitForNextTask;
7
- /**
8
- * Copyright (c) Microsoft Corporation.
9
- *
10
- * Licensed under the Apache License, Version 2.0 (the "License");
11
- * you may not use this file except in compliance with the License.
12
- * You may obtain a copy of the License at
13
- *
14
- * http://www.apache.org/licenses/LICENSE-2.0
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
-
23
- // See https://joel.tools/microtasks/
24
- function makeWaitForNextTask() {
25
- // As of Mar 2021, Electron v12 doesn't create new task with `setImmediate` despite
26
- // using Node 14 internally, so we fallback to `setTimeout(0)` instead.
27
- // @see https://github.com/electron/electron/issues/28261
28
- if (process.versions.electron) return callback => setTimeout(callback, 0);
29
- if (parseInt(process.versions.node, 10) >= 11) return setImmediate;
30
-
31
- // Unlike Node 11, Node 10 and less have a bug with Task and MicroTask execution order:
32
- // - https://github.com/nodejs/node/issues/22257
33
- //
34
- // So we can't simply run setImmediate to dispatch code in a following task.
35
- // However, we can run setImmediate from-inside setImmediate to make sure we're getting
36
- // in the following task.
37
-
38
- let spinning = false;
39
- const callbacks = [];
40
- const loop = () => {
41
- const callback = callbacks.shift();
42
- if (!callback) {
43
- spinning = false;
44
- return;
45
- }
46
- setImmediate(loop);
47
- // Make sure to call callback() as the last thing since it's
48
- // untrusted code that might throw.
49
- callback();
50
- };
51
- return callback => {
52
- callbacks.push(callback);
53
- if (!spinning) {
54
- spinning = true;
55
- setImmediate(loop);
56
- }
57
- };
58
- }
package/lib/utils/time.js DELETED
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.monotonicTime = monotonicTime;
7
- /**
8
- * Copyright (c) Microsoft Corporation.
9
- *
10
- * Licensed under the Apache License, Version 2.0 (the "License");
11
- * you may not use this file except in compliance with the License.
12
- * You may obtain a copy of the License at
13
- *
14
- * http://www.apache.org/licenses/LICENSE-2.0
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
-
23
- // The `process.hrtime()` returns a time from some arbitrary
24
- // date in the past; on certain systems, this is the time from the system boot.
25
- // The `monotonicTime()` converts this to milliseconds.
26
- //
27
- // For a Linux server with uptime of 36 days, the `monotonicTime()` value
28
- // will be 36 * 86400 * 1000 = 3_110_400_000, which is larger than
29
- // the maximum value that `setTimeout` accepts as an argument: 2_147_483_647.
30
- //
31
- // To make the `monotonicTime()` a reasonable value, we anchor
32
- // it to the time of the first import of this utility.
33
- const initialTime = process.hrtime();
34
- function monotonicTime() {
35
- const [seconds, nanoseconds] = process.hrtime(initialTime);
36
- return seconds * 1000 + (nanoseconds / 1000 | 0) / 1000;
37
- }
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.serializeClientSideCallMetadata = serializeClientSideCallMetadata;
7
- /**
8
- * Copyright (c) Microsoft Corporation.
9
- *
10
- * Licensed under the Apache License, Version 2.0 (the "License");
11
- * you may not use this file except in compliance with the License.
12
- * You may obtain a copy of the License at
13
- *
14
- * http://www.apache.org/licenses/LICENSE-2.0
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
-
23
- function serializeClientSideCallMetadata(metadatas) {
24
- const fileNames = new Map();
25
- const stacks = [];
26
- for (const m of metadatas) {
27
- if (!m.stack || !m.stack.length) continue;
28
- const stack = [];
29
- for (const frame of m.stack) {
30
- let ordinal = fileNames.get(frame.file);
31
- if (typeof ordinal !== 'number') {
32
- ordinal = fileNames.size;
33
- fileNames.set(frame.file, ordinal);
34
- }
35
- const stackFrame = [ordinal, frame.line || 0, frame.column || 0, frame.function || ''];
36
- stack.push(stackFrame);
37
- }
38
- stacks.push([m.id, stack]);
39
- }
40
- return {
41
- files: [...fileNames.keys()],
42
- stacks
43
- };
44
- }