PHP 8.2.30
Preview: signal-handling.js Size: 2.19 KB
/proc/self/root/opt/alt/alt-nodejs22/root/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/signal-handling.js

const signals = require('./signals.js')

// for testing, expose the process being used
module.exports = Object.assign(fn => setup(fn), { process })

// do all of this in a setup function so that we can call it
// multiple times for multiple reifies that might be going on.
// Otherwise, Arborist.reify() is a global action, which is a
// new constraint we'd be adding with this behavior.
const setup = fn => {
  const { process } = module.exports

  const sigListeners = { loaded: false }

  const unload = () => {
    if (!sigListeners.loaded) {
      return
    }
    for (const sig of signals) {
      try {
        process.removeListener(sig, sigListeners[sig])
      } catch {
        // ignore errors
      }
    }
    process.removeListener('beforeExit', onBeforeExit)
    sigListeners.loaded = false
  }

  const onBeforeExit = () => {
    // this trick ensures that we exit with the same signal we caught
    // Ie, if you press ^C and npm gets a SIGINT, we'll do the rollback
    // and then exit with a SIGINT signal once we've removed the handler.
    // The timeout is there because signals are asynchronous, so we need
    // the process to NOT exit on its own, which means we have to have
    // something keeping the event loop looping.  Hence this hack.
    unload()
    process.kill(process.pid, signalReceived)
    setTimeout(() => {}, 500)
  }

  let signalReceived = null
  const listener = (sig, fn) => () => {
    signalReceived = sig

    // if we exit normally, but caught a signal which would have been fatal,
    // then re-send it once we're done with whatever cleanup we have to do.
    unload()
    if (process.listeners(sig).length < 1) {
      process.once('beforeExit', onBeforeExit)
    }

    fn({ signal: sig })
  }

  // do the actual loading here
  for (const sig of signals) {
    sigListeners[sig] = listener(sig, fn)
    const max = process.getMaxListeners()
    try {
      // if we call this a bunch of times, avoid triggering the warning
      const { length } = process.listeners(sig)
      if (length >= max) {
        process.setMaxListeners(length + 1)
      }
      process.on(sig, sigListeners[sig])
    } catch {
      // ignore errors
    }
  }
  sigListeners.loaded = true

  return unload
}

Directory Contents

Dirs: 1 × Files: 38

Name Size Perms Modified Actions
arborist DIR
- drwxr-xr-x 2026-03-14 07:02:09
Edit Download
4.89 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
11.95 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
3.42 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
13.94 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
1.21 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
1.27 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
1.25 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
691 B lrw-r--r-- 2026-02-23 06:54:00
Edit Download
5.00 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
9.57 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
6.63 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
1.07 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
1.26 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
273 B lrw-r--r-- 2026-02-23 06:54:00
Edit Download
3.25 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
3.04 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
42.95 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
1.32 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
225 B lrw-r--r-- 2026-02-23 06:54:00
Edit Download
3.12 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
2.50 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
2.57 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
19.75 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
5.10 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
28.84 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
2.59 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
136 B lrw-r--r-- 2026-02-23 06:54:00
Edit Download
638 B lrw-r--r-- 2026-02-23 06:54:00
Edit Download
501 B lrw-r--r-- 2026-02-23 06:54:00
Edit Download
36.83 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
2.19 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
1.35 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
874 B lrw-r--r-- 2026-02-23 06:54:00
Edit Download
2.92 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
4.04 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
1.45 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
5.82 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download
10.56 KB lrw-r--r-- 2026-02-23 06:54:00
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).