Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

0x

Package Overview
Dependencies
Maintainers
2
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

0x - npm Package Compare versions

Comparing version 4.1.6 to 4.2.0

lib/preload/no-cluster.js

25

lib/preload/redir-stdout.js
'use strict'
const fs = require('fs')
process.stdout.write = ((write) => (chunk, encoding, cb) => {
if (typeof chunk !== 'string' && !(chunk instanceof Buffer)) {
throw new TypeError(
'Invalid data, chunk must be a string or buffer, not ' + typeof chunk);
}
if (typeof encoding === 'function') {
cb = encoding
}
fs.writeSync(3, chunk)
if (typeof cb === 'function') cb()
return true
})(process.stdout.write.bind(process.stdout))
const net = require('net')
const socket = new net.Socket({
fd: 3,
readable: false,
writable: true
})
Object.defineProperty(process, 'stdout', {
configurable: true,
enumerable: true,
get: () => socket
})
{
"name": "0x",
"version": "4.1.6",
"version": "4.2.0",
"description": "🔥 single-command flamegraph profiling 🔥",

@@ -10,2 +10,3 @@ "main": "index.js",

"stress-rest-example": "cd examples/rest-api && npm test",
"start": "./cmd.js --on-port 'npm run stress-rest-example' -- node examples/rest-api",
"lint": "standard"

@@ -12,0 +13,0 @@ },

@@ -32,2 +32,3 @@ 'use strict'

'--print-opt-source',
'-r', path.join(__dirname, '..', 'lib', 'preload', 'no-cluster'),
'-r', path.join(__dirname, '..', 'lib', 'preload', 'redir-stdout'),

@@ -47,16 +48,53 @@ '-r', path.join(__dirname, '..', 'lib', 'preload', 'soft-exit'),

let closeTimer
let softClosed = false
const softClose = () => {
if (softClosed) return
softClosed = true
status('Waiting for subprocess to exit...')
closeTimer = setTimeout(() => {
status('Closing subprocess is taking a long time, it might have hung. Press Ctrl+C again to force close')
}, 3000)
// Stop the subprocess; force stop it on the second SIGINT
proc.stdio[5].destroy()
onsigint = forceClose
process.once('SIGINT', onsigint)
}
const forceClose = () => {
status('Force closing subprocess...')
proc.kill()
}
let onsigint = softClose
process.once('SIGINT', onsigint)
process.once('SIGTERM', forceClose)
process.on('exit', forceClose)
const whenPort = onPort && spawnOnPort(onPort, await when(proc.stdio[5], 'data'))
let onPortError
if (onPort) {
// Graceful close once --on-port process ends
onPortError = whenPort.then(() => {
process.removeListener('SIGINT', onsigint)
softClose()
}, (err) => {
proc.kill()
throw err
})
}
const code = await Promise.race([
new Promise((resolve) => process.once('SIGINT', resolve)),
new Promise((resolve) => proc.once('exit', (code) => resolve(code))),
...(onPort ? [new Promise((resolve, reject) => {
whenPort.then(() => proc.stdio[5].destroy())
whenPort.catch((err) => {
proc.kill()
reject(err)
})
})] : [])
])
when(proc, 'exit'),
// This never resolves but may reject.
// When the --on-port process ends, we still wait for proc's 'exit'.
onPortError
].filter(Boolean))
clearTimeout(closeTimer)
process.removeListener('SIGINT', onsigint)
process.removeListener('SIGTERM', forceClose)
process.removeListener('exit', forceClose)
if (code|0 !== 0) {

@@ -63,0 +101,0 @@ throw Object.assign(Error('Target subprocess error, code: ' + code), { code })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc