mirror of
https://github.com/denoland/deno.git
synced 2024-11-23 15:16:54 -05:00
1 line
12 KiB
JSON
1 line
12 KiB
JSON
{"name":"proc-log","description":"just emit 'log' events on the process object","dist-tags":{"latest":"4.2.0"},"versions":{"3.0.0":{"name":"proc-log","version":"3.0.0","author":{"name":"GitHub Inc."},"license":"ISC","_id":"proc-log@3.0.0","bugs":{"url":"https://github.com/npm/proc-log/issues"},"tap":{"nyc-arg":["--exclude","tap-snapshots/**"]},"dist":{"shasum":"fb05ef83ccd64fd7b20bbe9c8c1070fc08338dd8","tarball":"http://localhost:4260/proc-log/proc-log-3.0.0.tgz","fileCount":4,"integrity":"sha512-++Vn7NS4Xf9NacaU9Xq3URUuqZETPsf8L4j5/ckhaRYsfPeRyzGw+iDjFhV/Jr3uNmTvvddEJFWh5R1gRgUH8A==","signatures":[{"sig":"MEUCIHifbHgF6M3IpbNVu8XNpsbTUeNJM3qIs5XF1g0YLliHAiEAuptlCUzpR9akldhsbgMLMxeuPC7hOWXL8fkpJ1WgP7E=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":5215,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjSPI6ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpjPQ//UPSrpMvLqry94iJkulfi5zOWvurCtHjX2ttnkkZ/s0H+SigN\r\nvOe8PQcIacbmrBqYSydLuM4XBf3vUErBZXjwegNzTY28q0kNL6JMZink/28e\r\nAaKu2EY50BfKG/yB+StonfnfXiv9XGqtIvdqoVF0yMKbwghjVUNfLb3mjx4+\r\n4D3S3obKZPksS1up5yLCMyMOiz3h5W30M05Ipyyp0IHTVc4NQB7zpVN/fVrt\r\nRBt/Z0aml3JPe+A2tKq8rtIFegVsuyp8oDT/xGugZRNI7cuK3bLTQxQXZvJW\r\neusL/Q/TzuyieN35bZuzrdzk0Ofs7Sx4LUEcbwv2AbBOhUdSZHM71gXe4GHq\r\nP+5qLsmZEoQ/dDbaQ/mYst/bYlvb36Avt0naN+SizCBrS7AuNErb+vW6Lud6\r\nnNF4q0iT0IBERbMAKqMUfAoriTidLInRwHL+YA7Zd4Plw9djUqWF2X3L7q1z\r\n/kwvinhV6tP04LpOlnKOlB5eUD8yyWF5WN0vJPRJu5TseUMOAdSEQ0/qlwRh\r\nA32FMskN+dBEHy6mDa5fJfMkXA8/lARwdyHKq/PvNbQCJCL5FU6WhPgk3heK\r\n94sOQbe4zwx6VHJ1InfFRElXW/MsmN+S4sQnUhbQVHOQp+04h38e54IqqcwF\r\nQbFZXz2zcDVctGitwZjS6dIuinKsLDuXivk=\r\n=QR6L\r\n-----END PGP SIGNATURE-----\r\n"},"main":"lib/index.js","engines":{"node":"^14.17.0 || ^16.13.0 || >=18.0.0"},"gitHead":"a3318aac6541572d897f404c1db7d905016c5cfe","scripts":{"lint":"eslint \"**/*.js\"","snap":"tap","test":"tap","lintfix":"npm run lint -- --fix","postlint":"template-oss-check","postsnap":"eslint index.js test/*.js --fix","posttest":"npm run lint","template-oss-apply":"template-oss-apply --force"},"repository":{"url":"git+https://github.com/npm/proc-log.git","type":"git"},"_npmVersion":"8.19.2","description":"just emit 'log' events on the process object","directories":{},"templateOSS":{"version":"4.5.1","//@npmcli/template-oss":"This file is partially managed by @npmcli/template-oss. Edits may be overwritten."},"_nodeVersion":"18.10.0","_hasShrinkwrap":false,"devDependencies":{"tap":"^16.0.1","@npmcli/template-oss":"4.5.1","@npmcli/eslint-config":"^3.0.1"}},"4.2.0":{"name":"proc-log","version":"4.2.0","author":{"name":"GitHub Inc."},"license":"ISC","_id":"proc-log@4.2.0","bugs":{"url":"https://github.com/npm/proc-log/issues"},"tap":{"nyc-arg":["--exclude","tap-snapshots/**"]},"dist":{"shasum":"b6f461e4026e75fdfe228b265e9f7a00779d7034","tarball":"http://localhost:4260/proc-log/proc-log-4.2.0.tgz","fileCount":4,"integrity":"sha512-g8+OnU/L2v+wyiVK+D5fA34J7EH8jZ8DDlvwhRCMxmMj7UCBvxiO1mGeN+36JXIKF4zevU4kRBd8lVgG9vLelA==","signatures":[{"sig":"MEUCIQCNStNROA4yNJ9PelPPE2Zu/qXkWLycFqs2cUlUrvGcfQIgQloGakWeTeBxeHy8tAlNpXjvlDF+X8/oZk7PB1DfNrQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"attestations":{"url":"http://localhost:4260/attestations/proc-log@4.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":12261},"main":"lib/index.js","engines":{"node":"^14.17.0 || ^16.13.0 || >=18.0.0"},"gitHead":"953e6035670f9afe2ec93f6286d76db2828854d6","scripts":{"lint":"eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"","snap":"tap","test":"tap","lintfix":"npm run lint -- --fix","postlint":"template-oss-check","postsnap":"eslint index.js test/*.js --fix","posttest":"npm run lint","template-oss-apply":"template-oss-apply --force"},"repository":{"url":"git+https://github.com/npm/proc-log.git","type":"git"},"_npmVersion":"10.5.2","description":"just emit 'log' events on the process object","directories":{},"templateOSS":{"publish":true,"version":"4.21.3","//@npmcli/template-oss":"This file is partially managed by @npmcli/template-oss. Edits may be overwritten."},"_nodeVersion":"20.12.1","_hasShrinkwrap":false,"devDependencies":{"tap":"^16.0.1","@npmcli/template-oss":"4.21.3","@npmcli/eslint-config":"^4.0.0"}}},"author":{"name":"GitHub Inc."},"repository":{"url":"git+https://github.com/npm/proc-log.git","type":"git"},"license":"ISC","homepage":"https://github.com/npm/proc-log#readme","bugs":{"url":"https://github.com/npm/proc-log/issues"},"readme":"# proc-log\n\nEmits events on the process object which a listener can consume and print to the terminal or log file.\n\nThis is used by various modules within the npm CLI stack in order to send log events that can be consumed by a listener on the process object.\n\nCurrently emits `log`, `output`, `input`, and `time` events.\n\n## API\n\n```js\nconst { log, output, input, time } = require('proc-log')\n```\n\n#### output\n* `output.standard(...args)` calls `process.emit('output', 'standard', ...args)`\n \n This is for general standard output. Consumers will typically show this on stdout (after optionally formatting or filtering it).\n\n* `output.error(...args)` calls `process.emit('output', 'error', ...args)`\n \n This is for general error output. Consumers will typically show this on stderr (after optionally formatting or filtering it).\n\n* `output.buffer(...args)` calls `process.emit('output', 'buffer', ...args)`\n \n This is for buffered output. Consumers will typically buffer this until they are ready to display.\n\n* `output.flush(...args)` calls `process.emit('output', 'flush', ...args)`\n \n This is to indicate that the output buffer should be flushed.\n\n* `output.LEVELS` an array of strings of all output method names\n\n#### log\n* `log.error(...args)` calls `process.emit('log', 'error', ...args)`\n \n The highest log level. For printing extremely serious errors that indicate something went wrong.\n\n* `log.warn(...args)` calls `process.emit('log', 'warn', ...args)`\n \n A fairly high log level. Things that the user needs to be aware of, but which won't necessarily cause improper functioning of the system.\n\n* `log.notice(...args)` calls `process.emit('log', 'notice', ...args)`\n \n Notices which are important, but not necessarily dangerous or a cause for excess concern.\n\n* `log.info(...args)` calls `process.emit('log', 'info', ...args)`\n \n Informative messages that may benefit the user, but aren't particularly important.\n\n* `log.verbose(...args)` calls `process.emit('log', 'verbose', ...args)`\n \n Noisy output that is more detail that most users will care about.\n\n* `log.silly(...args)` calls `process.emit('log', 'silly', ...args)`\n \n Extremely noisy excessive logging messages that are typically only useful for debugging.\n\n* `log.http(...args)` calls `process.emit('log', 'http', ...args)`\n \n Information about HTTP requests made and/or completed.\n\n* `log.timing(...args)` calls `process.emit('log', 'timing', ...args)`\n \n Timing information.\n\n* `log.pause()` calls `process.emit('log', 'pause')`\n \n Used to tell the consumer to stop printing messages.\n\n* `log.resume()` calls `process.emit('log', 'resume')`\n \n Used to tell the consumer that it is ok to print messages again.\n\n* `log.LEVELS` an array of strings of all log method names\n\n#### input\n\n* `input.start(fn?)` calls `process.emit('input', 'start')`\n\n Used to tell the consumer that the terminal is going to begin reading user input. Returns a function that will call `input.end()` for convenience.\n \n This also takes an optional callback which will run `input.end()` on its completion. If the callback returns a `Promise` then `input.end()` will be run during `finally()`.\n\n* `input.end()` calls `process.emit('input', 'end')`\n\n Used to tell the consumer that the terminal has stopped reading user input.\n\n* `input.read(...args): Promise` calls `process.emit('input', 'read', resolve, reject, ...args)`\n\n Used to tell the consumer that the terminal is reading user input and returns a `Promise` that the producer can `await` until the consumer has finished its async action.\n \n This emits `resolve` and `reject` functions (in addition to all passed in arguments) which the consumer must use to resolve the returned `Promise`.\n\n#### time\n\n* `time.start(timerName, fn?)` calls `process.emit('time', 'start', 'timerName')`\n\n Used to start a timer with the specified name. Returns a function that will call `time.end()` for convenience.\n \n This also takes an optional callback which will run `time.end()` on its completion. If the callback returns a `Promise` then `time.end()` will be run during `finally()`.\n\n* `time.end(timerName)` calls `process.emit('time', 'end', timeName)`\n\n Used to tell the consumer to stop a timer with the specified name.\n\n## Examples\n\n### log\n\nEvery `log` method calls `process.emit('log', level, ...otherArgs)` internally. So in order to consume those events you need to do `process.on('log', fn)`.\n\n#### Colorize based on level\n\nHere's an example of how to consume `proc-log` log events and colorize them based on level:\n\n```js\nconst chalk = require('chalk')\n\nprocess.on('log', (level, ...args) => {\n if (level === 'error') {\n console.log(chalk.red(level), ...args)\n } else {\n console.log(chalk.blue(level), ...args)\n }\n})\n```\n\n#### Pause and resume\n\n`log.pause` and `log.resume` are included so you have the ability to tell your consumer that you want to pause or resume your display of logs. In the npm CLI we use this to buffer all logs on init until we know the correct loglevel to display. But we also setup a second handler that writes everything to a file even if paused.\n\n```js\nlet paused = true\nconst buffer = []\n\n// this handler will buffer and replay logs only after `procLog.resume()` is called\nprocess.on('log', (level, ...args) => {\n if (level === 'resume') {\n buffer.forEach((item) => console.log(...item))\n paused = false\n return\n } \n\n if (paused) {\n buffer.push([level, ...args])\n } else {\n console.log(level, ...args)\n }\n})\n\n// this handler will write everything to a file\nprocess.on('log', (...args) => {\n fs.appendFileSync('debug.log', args.join(' '))\n})\n```\n\n### input\n\n### `start` and `end`\n\n**producer.js**\n```js\nconst { output, input } = require('proc-log')\nconst { readFromUserInput } = require('./my-read')\n\n// Using callback passed to `start`\ntry {\n const res = await input.start(\n readFromUserInput({ prompt: 'OK?', default: 'y' })\n )\n output.standard(`User said ${res}`)\n} catch (err) {\n output.error(`User cancelled: ${err}`)\n}\n\n// Manually calling `start` and `end`\ntry {\n input.start()\n const res = await readFromUserInput({ prompt: 'OK?', default: 'y' })\n output.standard(`User said ${res}`)\n} catch (err) {\n output.error(`User cancelled: ${err}`)\n} finally {\n input.end()\n}\n```\n\n**consumer.js**\n```js\nconst { read } = require('read')\n\nprocess.on('input', (level) => {\n if (level === 'start') {\n // Hide UI to make room for user input being read\n } else if (level === 'end') {\n // Restore UI now that reading is ended\n }\n})\n```\n\n### Using `read` to call `read()`\n\n**producer.js**\n```js\nconst { output, input } = require('proc-log')\n\ntry {\n const res = await input.read({ prompt: 'OK?', default: 'y' })\n output.standard(`User said ${res}`)\n} catch (err) {\n output.error(`User cancelled: ${err}`)\n}\n```\n\n**consumer.js**\n```js\nconst { read } = require('read')\n\nprocess.on('input', (level, ...args) => {\n if (level === 'read') {\n const [res, rej, opts] = args\n read(opts).then(res).catch(rej)\n }\n})\n```","readmeFilename":"README.md"}
|