|
5 | 5 | // event loop.
|
6 | 6 | const signalExit = require('signal-exit')
|
7 | 7 |
|
8 |
| -const { envAsBoolean, envAsString } = require('./env') |
9 |
| - |
10 |
| -const abortController = new AbortController() |
11 |
| -const { signal: abortSignal } = abortController |
12 |
| - |
13 | 8 | let _browserList
|
14 | 9 | function getBrowserList() {
|
15 | 10 | if (_browserList === undefined) {
|
@@ -134,6 +129,32 @@ function getYarnPkgExtensions() {
|
134 | 129 | return _yarnPkgExtensions
|
135 | 130 | }
|
136 | 131 |
|
| 132 | +const abortController = new AbortController() |
| 133 | + |
| 134 | +const { signal: abortSignal } = abortController |
| 135 | +;(() => { |
| 136 | + // By manually setting `kMaxEventTargetListeners` on `abortSignal` we avoid: |
| 137 | + // TypeError [ERR_INVALID_ARG_TYPE]: The "emitter" argument must be an |
| 138 | + // instance of EventEmitter or EventTarget. Received an instance of |
| 139 | + // AbortSignal |
| 140 | + // |
| 141 | + // in some patch releases of Node 18-23 when calling events.getMaxListeners(abortSignal). |
| 142 | + // See https://github.com/nodejs/node/pull/56807. |
| 143 | + // |
| 144 | + // Instead of calling events.setMaxListeners(10, abortSignal) we set the symbol |
| 145 | + // property directly to keep the constants initialization platform agnostic and |
| 146 | + // not rely on the Node specific 'node:events' module up front. |
| 147 | + const symbols = Object.getOwnPropertySymbols(abortSignal) |
| 148 | + const kMaxEventTargetListeners = symbols.find( |
| 149 | + s => s.description === 'events.maxEventTargetListeners' |
| 150 | + ) |
| 151 | + if (kMaxEventTargetListeners) { |
| 152 | + // The default events.defaultMaxListeners value is 10. |
| 153 | + // https://nodejs.org/api/events.html#eventsdefaultmaxlisteners |
| 154 | + abortSignal[kMaxEventTargetListeners] = 10 |
| 155 | + } |
| 156 | +})() |
| 157 | + |
137 | 158 | // Detect ^C, i.e. Ctrl + C.
|
138 | 159 | signalExit.onExit(() => {
|
139 | 160 | abortController.abort()
|
@@ -431,6 +452,8 @@ const LAZY_SUPPORTS_PROCESS_SEND = () =>
|
431 | 452 | typeof getProcess().send === 'function'
|
432 | 453 |
|
433 | 454 | const LAZY_ENV = () => {
|
| 455 | + // Lazily require('./env'). |
| 456 | + const { envAsBoolean, envAsString } = require('./env') |
434 | 457 | const { env } = getProcess()
|
435 | 458 | return Object.freeze({
|
436 | 459 | __proto__: null,
|
@@ -726,7 +749,7 @@ const lazySkipTestsByEcosystem = () =>
|
726 | 749 | })
|
727 | 750 |
|
728 | 751 | const lazySpinner = () =>
|
729 |
| - // Lazily access require('./spinner').Spinner to avoid cyclical imports. |
| 752 | + // Lazily require('./spinner').Spinner to avoid cyclical imports. |
730 | 753 | require('./spinner').Spinner()
|
731 | 754 |
|
732 | 755 | const lazyWin32EnsureTestsByEcosystem = () =>
|
|
0 commit comments