pax_global_header00006660000000000000000000000064142010071450014504gustar00rootroot0000000000000052 comment=3c31adc8fa6e64f8d8c4f735d992efa6faca50d0 npmlog-6.0.1/000077500000000000000000000000001420100714500130045ustar00rootroot00000000000000npmlog-6.0.1/.commitlintrc.js000066400000000000000000000006531420100714500161300ustar00rootroot00000000000000// This file is automatically added by @npmcli/template-oss. Do not edit. module.exports = { extends: ['@commitlint/config-conventional'], // If you change rules be sure to also update release-please.yml rules: { 'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'chore', 'deps']], 'header-max-length': [2, 'always', 80], 'subject-case': [0, 'always', ['lower-case', 'sentence-case', 'start-case']], }, } npmlog-6.0.1/.eslintrc.js000066400000000000000000000005061420100714500152440ustar00rootroot00000000000000// This file is automatically added by @npmcli/template-oss. Do not edit. const { readdirSync: readdir } = require('fs') const localConfigs = readdir(__dirname) .filter((file) => file.startsWith('.eslintrc.local.')) .map((file) => `./${file}`) module.exports = { extends: [ '@npmcli', ...localConfigs, ], } npmlog-6.0.1/.github/000077500000000000000000000000001420100714500143445ustar00rootroot00000000000000npmlog-6.0.1/.github/CODEOWNERS000066400000000000000000000000201420100714500157270ustar00rootroot00000000000000* @npm/cli-team npmlog-6.0.1/.github/ISSUE_TEMPLATE/000077500000000000000000000000001420100714500165275ustar00rootroot00000000000000npmlog-6.0.1/.github/ISSUE_TEMPLATE/bug.yml000066400000000000000000000025231420100714500200310ustar00rootroot00000000000000# This file is automatically added by @npmcli/template-oss. Do not edit. name: Bug description: File a bug/issue title: "[BUG] " labels: [Bug, Needs Triage] body: - type: checkboxes attributes: label: Is there an existing issue for this? description: Please [search here](./issues) to see if an issue already exists for your problem. options: - label: I have searched the existing issues required: true - type: textarea attributes: label: Current Behavior description: A clear & concise description of what you're experiencing. validations: required: false - type: textarea attributes: label: Expected Behavior description: A clear & concise description of what you expected to happen. validations: required: false - type: textarea attributes: label: Steps To Reproduce description: Steps to reproduce the behavior. value: | 1. In this environment... 2. With this config... 3. Run '...' 4. See error... validations: required: false - type: textarea attributes: label: Environment description: | examples: - **npm**: 7.6.3 - **Node**: 13.14.0 - **OS**: Ubuntu 20.04 - **platform**: Macbook Pro value: | - npm: - Node: - OS: - platform: validations: required: false �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/.github/ISSUE_TEMPLATE/config.yml������������������������������������������������������0000664�0000000�0000000�00000000145�14201007145�0020517�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# This file is automatically added by @npmcli/template-oss. Do not edit. blank_issues_enabled: true ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/.github/dependabot.yml�����������������������������������������������������������������0000664�0000000�0000000�00000000517�14201007145�0017177�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# This file is automatically added by @npmcli/template-oss. Do not edit. version: 2 updates: - package-ecosystem: npm directory: "/" schedule: interval: daily allow: - dependency-type: direct versioning-strategy: increase commit-message: prefix: deps prefix-development: chore labels: - "Dependencies" ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/.github/settings.yml�������������������������������������������������������������������0000664�0000000�0000000�00000000055�14201007145�0016727�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������--- _extends: '.github:npm-cli/settings.yml' �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/.github/workflows/���������������������������������������������������������������������0000775�0000000�0000000�00000000000�14201007145�0016401�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/.github/workflows/audit.yml������������������������������������������������������������0000664�0000000�0000000�00000000762�14201007145�0020237�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# This file is automatically added by @npmcli/template-oss. Do not edit. name: Audit on: schedule: # "At 01:00 on Monday" https://crontab.guru/#0_1_*_*_1 - cron: "0 1 * * 1" workflow_dispatch: jobs: audit: name: npm audit runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: '16' - name: Install deps run: npm i --package-lock - name: Audit run: npm audit ��������������npmlog-6.0.1/.github/workflows/ci.yml���������������������������������������������������������������0000664�0000000�0000000�00000003344�14201007145�0017523�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# This file is automatically added by @npmcli/template-oss. Do not edit. name: CI on: pull_request: push: branches: - main - latest schedule: # "At 02:00 on Monday" https://crontab.guru/#0_2_*_*_1 - cron: "0 2 * * 1" jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: '16' - run: npm i --prefer-online -g npm@latest - run: npm i - run: npm run lint test: strategy: fail-fast: false matrix: node-version: [12.13.0, 12.x, 14.15.0, 14.x, 16.13.0, 16.x] platform: - os: ubuntu-latest shell: bash - os: macos-latest shell: bash - os: windows-latest shell: cmd runs-on: ${{ matrix.platform.os }} defaults: run: shell: ${{ matrix.platform.shell }} steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} # node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows - name: Update to workable npm (windows) if: matrix.platform.os == 'windows-latest' && (startsWith(matrix.node-version, '12') || startsWith(matrix.node-version, '14')) run: | curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz tar xf npm-7.5.4.tgz cd package node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz cd .. rmdir /s /q package - name: Update npm run: npm i --prefer-online --no-fund --no-audit -g npm@latest - run: npm -v - run: npm i - run: npm test --ignore-scripts ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/.github/workflows/codeql-analysis.yml��������������������������������������������������0000664�0000000�0000000�00000001512�14201007145�0022213�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# This file is automatically added by @npmcli/template-oss. Do not edit. name: "CodeQL" on: push: branches: [ main ] pull_request: # The branches below must be a subset of the branches above branches: [ main ] schedule: # "At 03:00 on Monday" https://crontab.guru/#0_3_*_*_1 - cron: "0 3 * * 1" jobs: analyze: name: Analyze runs-on: ubuntu-latest permissions: actions: read contents: read security-events: write strategy: fail-fast: false matrix: language: [ 'javascript' ] steps: - name: Checkout repository uses: actions/checkout@v2 - name: Initialize CodeQL uses: github/codeql-action/init@v1 with: languages: ${{ matrix.language }} - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v1 ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/.github/workflows/post-dependabot.yml��������������������������������������������������0000664�0000000�0000000�00000002057�14201007145�0022220�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# This file is automatically added by @npmcli/template-oss. Do not edit. name: "Post Dependabot Actions" on: pull_request jobs: Install: runs-on: ubuntu-latest if: ${{ github.actor == 'dependabot[bot]' }} steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: '16' - name: Dependabot metadata id: metadata uses: dependabot/fetch-metadata@v1.1.1 with: github-token: "${{ secrets.GITHUB_TOKEN }}" - name: npm install and commit if: ${{contains(steps.metadata.outputs.dependency-names, '@npmcli/template-oss')}} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | git config --local user.email "ops+npm-cli@npmjs.com" git config --local user.name "npm cli ops bot" gh pr checkout ${{ github.event.pull_request.number }} npm install git add . git commit -am "chore: postinstall for dependabot template-oss PR" git push origin ${{github.ref_name}} ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/.github/workflows/pull-request.yml�����������������������������������������������������0000664�0000000�0000000�00000001525�14201007145�0021571�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# This file is automatically added by @npmcli/template-oss. Do not edit. name: Pull Request Linting on: pull_request: types: [opened, reopened, edited, synchronize] jobs: check: name: Check PR Title or Commits runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 with: fetch-depth: 0 - uses: actions/setup-node@v2 with: node-version: '16' - name: Install deps run: | npm i -D @commitlint/cli @commitlint/config-conventional - name: Check commits OR PR title env: PR_TITLE: ${{ github.event.pull_request.title }} run: | npx commitlint -x @commitlint/config-conventional -V --from origin/main --to ${{ github.event.pull_request.head.sha }} || echo $PR_TITLE | npx commitlint -x @commitlint/config-conventional -V ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/.github/workflows/release-please.yml���������������������������������������������������0000664�0000000�0000000�00000001424�14201007145�0022014�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# This file is automatically added by @npmcli/template-oss. Do not edit. name: Release Please on: push: branches: - main jobs: release-please: runs-on: ubuntu-latest steps: - uses: google-github-actions/release-please-action@v2 id: release with: package-name: conventional-test release-type: node # If you change changelog-types be sure to also update commitlintrc.js changelog-types: > [{"type":"feat","section":"Features","hidden":false}, {"type":"fix","section":"Bug Fixes","hidden":false}, {"type":"docs","section":"Documentation","hidden":false}, {"type":"deps","section":"Dependencies","hidden":false}, {"type":"chore","hidden":true}] ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/.gitignore�����������������������������������������������������������������������������0000664�0000000�0000000�00000000467�14201007145�0015003�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# This file is automatically added by @npmcli/template-oss. Do not edit. # ignore everything in the root /* # keep these !/.commitlintrc.js !/.npmrc !/.eslintrc* !/.github !**/.gitignore !/package.json !/docs !/bin !/lib !/map.js !/tap-snapshots !/test !/scripts !/README* !/LICENSE* !/SECURITY* !/CHANGELOG* ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/.npmrc���������������������������������������������������������������������������������0000664�0000000�0000000�00000000134�14201007145�0014122�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������;This file is automatically added by @npmcli/template-oss. Do not edit. package-lock=false ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/CHANGELOG.md���������������������������������������������������������������������������0000664�0000000�0000000�00000004421�14201007145�0014616�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������### v6.0.0 * Drop support for node 10 and non-lts versions of 12 and 14 ### [6.0.1](https://www.github.com/npm/npmlog/compare/v6.0.0...v6.0.1) (2022-02-09) ### Bug Fixes * evaluate this.heading only once ([3633d33](https://www.github.com/npm/npmlog/commit/3633d3395574fc87d734e31e40f4b19eaa3045c3)) * **notice:** change blue foreground to cyan ([eba1a41](https://www.github.com/npm/npmlog/commit/eba1a413c84bf31d6d0eb2cd3b9254debb07e0fb)) ### Dependencies * @npmcli/template-oss@2.7.1 ([5e7b9f4](https://www.github.com/npm/npmlog/commit/5e7b9f42b5c6b2b32613f5164a4524cc71eeb46f)) * are-we-there-yet@3.0.0 ([7aefa36](https://www.github.com/npm/npmlog/commit/7aefa36320a4265f2825f34db29f129f5927f41b)) ### v5.0.1 * update are-we-there-yet to v2.0.0. ### v5.0.0 * Drop support for node versions 6 and 8 * Fix bug where gauge was enabled when paused ### v4.0.2 * Added installation instructions. ### v4.0.1 * Fix bugs where `log.progressEnabled` got out of sync with how `gauge` kept track of these things resulting in a progressbar that couldn't be disabled. ### v4.0.0 * Allow creating log levels that are an empty string or 0. ### v3.1.2 * Update to `gauge@1.6.0` adding support for default values for template items. ### v3.1.1 * Update to `gauge@1.5.3` to fix to `1.x` compatibility when it comes to when a progress bar is enabled. In `1.x` if you didn't have a TTY the progress bar was never shown. In `2.x` it merely defaults to disabled, but you can enable it explicitly if you still want progress updates. ### v3.1.0 * Update to `gauge@2.5.2`: * Updates the `signal-exit` dependency which fixes an incompatibility with the node profiler. * Uses externalizes its ansi code generation in `console-control-strings` * Make the default progress bar include the last line printed, colored as it would be when printing to a tty. ### v3.0.0 * Switch to `gauge@2.0.0`, for better performance, better look. * Set stderr/stdout blocking if they're tty's, so that we can hide a progress bar going to stderr and then safely print to stdout. Without this the two can end up overlapping producing confusing and sometimes corrupted output. ### v2.0.0 * Make the `error` event non-fatal so that folks can use it as a prefix. ### v1.0.0 * Add progress bar with `gauge@1.1.0` �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/LICENSE.md�����������������������������������������������������������������������������0000664�0000000�0000000�00000001436�14201007145�0014414�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<!-- This file is automatically added by @npmcli/template-oss. Do not edit. --> ISC License Copyright npm, Inc. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND NPM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NPM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/README.md������������������������������������������������������������������������������0000664�0000000�0000000�00000013537�14201007145�0014274�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# npmlog The logger util that npm uses. This logger is very basic. It does the logging for npm. It supports custom levels and colored output. By default, logs are written to stderr. If you want to send log messages to outputs other than streams, then you can change the `log.stream` member, or you can just listen to the events that it emits, and do whatever you want with them. # Installation ```console npm install npmlog --save ``` # Basic Usage ```javascript var log = require('npmlog') // additional stuff ---------------------------+ // message ----------+ | // prefix ----+ | | // level -+ | | | // v v v v log.info('fyi', 'I have a kitty cat: %j', myKittyCat) ``` ## log.level * {String} The level to display logs at. Any logs at or above this level will be displayed. The special level `silent` will prevent anything from being displayed ever. ## log.record * {Array} An array of all the log messages that have been entered. ## log.maxRecordSize * {Number} The maximum number of records to keep. If log.record gets bigger than 10% over this value, then it is sliced down to 90% of this value. The reason for the 10% window is so that it doesn't have to resize a large array on every log entry. ## log.prefixStyle * {Object} A style object that specifies how prefixes are styled. (See below) ## log.headingStyle * {Object} A style object that specifies how the heading is styled. (See below) ## log.heading * {String} Default: "" If set, a heading that is printed at the start of every line. ## log.stream * {Stream} Default: `process.stderr` The stream where output is written. ## log.enableColor() Force colors to be used on all messages, regardless of the output stream. ## log.disableColor() Disable colors on all messages. ## log.enableProgress() Enable the display of log activity spinner and progress bar ## log.disableProgress() Disable the display of a progress bar ## log.enableUnicode() Force the unicode theme to be used for the progress bar. ## log.disableUnicode() Disable the use of unicode in the progress bar. ## log.setGaugeTemplate(template) Set a template for outputting the progress bar. See the [gauge documentation] for details. [gauge documentation]: https://npmjs.com/package/gauge ## log.setGaugeThemeset(themes) Select a themeset to pick themes from for the progress bar. See the [gauge documentation] for details. ## log.pause() Stop emitting messages to the stream, but do not drop them. ## log.resume() Emit all buffered messages that were written while paused. ## log.log(level, prefix, message, ...) * `level` {String} The level to emit the message at * `prefix` {String} A string prefix. Set to "" to skip. * `message...` Arguments to `util.format` Emit a log message at the specified level. ## log\[level](prefix, message, ...) For example, * log.silly(prefix, message, ...) * log.verbose(prefix, message, ...) * log.info(prefix, message, ...) * log.http(prefix, message, ...) * log.warn(prefix, message, ...) * log.error(prefix, message, ...) Like `log.log(level, prefix, message, ...)`. In this way, each level is given a shorthand, so you can do `log.info(prefix, message)`. ## log.addLevel(level, n, style, disp) * `level` {String} Level indicator * `n` {Number} The numeric level * `style` {Object} Object with fg, bg, inverse, etc. * `disp` {String} Optional replacement for `level` in the output. Sets up a new level with a shorthand function and so forth. Note that if the number is `Infinity`, then setting the level to that will cause all log messages to be suppressed. If the number is `-Infinity`, then the only way to show it is to enable all log messages. ## log.newItem(name, todo, weight) * `name` {String} Optional; progress item name. * `todo` {Number} Optional; total amount of work to be done. Default 0. * `weight` {Number} Optional; the weight of this item relative to others. Default 1. This adds a new `are-we-there-yet` item tracker to the progress tracker. The object returned has the `log[level]` methods but is otherwise an `are-we-there-yet` `Tracker` object. ## log.newStream(name, todo, weight) This adds a new `are-we-there-yet` stream tracker to the progress tracker. The object returned has the `log[level]` methods but is otherwise an `are-we-there-yet` `TrackerStream` object. ## log.newGroup(name, weight) This adds a new `are-we-there-yet` tracker group to the progress tracker. The object returned has the `log[level]` methods but is otherwise an `are-we-there-yet` `TrackerGroup` object. # Events Events are all emitted with the message object. * `log` Emitted for all messages * `log.<level>` Emitted for all messages with the `<level>` level. * `<prefix>` Messages with prefixes also emit their prefix as an event. # Style Objects Style objects can have the following fields: * `fg` {String} Color for the foreground text * `bg` {String} Color for the background * `bold`, `inverse`, `underline` {Boolean} Set the associated property * `bell` {Boolean} Make a noise (This is pretty annoying, probably.) # Message Objects Every log event is emitted with a message object, and the `log.record` list contains all of them that have been created. They have the following fields: * `id` {Number} * `level` {String} * `prefix` {String} * `message` {String} Result of `util.format()` * `messageRaw` {Array} Arguments to `util.format()` # Blocking TTYs We use [`set-blocking`](https://npmjs.com/package/set-blocking) to set stderr and stdout blocking if they are tty's and have the setBlocking call. This is a work around for an issue in early versions of Node.js 6.x, which made stderr and stdout non-blocking on OSX. (They are always blocking Windows and were never blocking on Linux.) `npmlog` needs them to be blocking so that it can allow output to stdout and stderr to be interlaced. �����������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/SECURITY.md����������������������������������������������������������������������������0000664�0000000�0000000�00000000246�14201007145�0014577�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<!-- This file is automatically added by @npmcli/template-oss. Do not edit. --> Please send vulnerability reports through [hackerone](https://hackerone.com/github). ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/docs/����������������������������������������������������������������������������������0000775�0000000�0000000�00000000000�14201007145�0013734�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/docs/example.js������������������������������������������������������������������������0000664�0000000�0000000�00000004122�14201007145�0015724�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������var log = require('./log.js') log.heading = 'npm' console.error('log.level=silly') log.level = 'silly' log.silly('silly prefix', 'x = %j', { foo: { bar: 'baz' } }) log.verbose('verbose prefix', 'x = %j', { foo: { bar: 'baz' } }) log.info('info prefix', 'x = %j', { foo: { bar: 'baz' } }) log.timing('timing prefix', 'x = %j', { foo: { bar: 'baz' } }) log.http('http prefix', 'x = %j', { foo: { bar: 'baz' } }) log.notice('notice prefix', 'x = %j', { foo: { bar: 'baz' } }) log.warn('warn prefix', 'x = %j', { foo: { bar: 'baz' } }) log.error('error prefix', 'x = %j', { foo: { bar: 'baz' } }) log.silent('silent prefix', 'x = %j', { foo: { bar: 'baz' } }) console.error('log.level=silent') log.level = 'silent' log.silly('silly prefix', 'x = %j', { foo: { bar: 'baz' } }) log.verbose('verbose prefix', 'x = %j', { foo: { bar: 'baz' } }) log.info('info prefix', 'x = %j', { foo: { bar: 'baz' } }) log.timing('timing prefix', 'x = %j', { foo: { bar: 'baz' } }) log.http('http prefix', 'x = %j', { foo: { bar: 'baz' } }) log.notice('notice prefix', 'x = %j', { foo: { bar: 'baz' } }) log.warn('warn prefix', 'x = %j', { foo: { bar: 'baz' } }) log.error('error prefix', 'x = %j', { foo: { bar: 'baz' } }) log.silent('silent prefix', 'x = %j', { foo: { bar: 'baz' } }) console.error('log.level=info') log.level = 'info' log.silly('silly prefix', 'x = %j', { foo: { bar: 'baz' } }) log.verbose('verbose prefix', 'x = %j', { foo: { bar: 'baz' } }) log.info('info prefix', 'x = %j', { foo: { bar: 'baz' } }) log.timing('timing prefix', 'x = %j', { foo: { bar: 'baz' } }) log.http('http prefix', 'x = %j', { foo: { bar: 'baz' } }) log.notice('notice prefix', 'x = %j', { foo: { bar: 'baz' } }) log.warn('warn prefix', 'x = %j', { foo: { bar: 'baz' } }) log.error('error prefix', 'x = %j', { foo: { bar: 'baz' } }) log.silent('silent prefix', 'x = %j', { foo: { bar: 'baz' } }) log.error('404', 'This is a longer\n' + 'message, with some details\n' + 'and maybe a stack.\n' + new Error('a 404 error').stack) log.addLevel('noise', 10000, { beep: true }) log.noise(false, 'LOUD NOISES') ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/lib/�����������������������������������������������������������������������������������0000775�0000000�0000000�00000000000�14201007145�0013552�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/lib/log.js�����������������������������������������������������������������������������0000664�0000000�0000000�00000021526�14201007145�0014677�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������'use strict' var Progress = require('are-we-there-yet') var Gauge = require('gauge') var EE = require('events').EventEmitter var log = exports = module.exports = new EE() var util = require('util') var setBlocking = require('set-blocking') var consoleControl = require('console-control-strings') setBlocking(true) var stream = process.stderr Object.defineProperty(log, 'stream', { set: function (newStream) { stream = newStream if (this.gauge) { this.gauge.setWriteTo(stream, stream) } }, get: function () { return stream }, }) // by default, decide based on tty-ness. var colorEnabled log.useColor = function () { return colorEnabled != null ? colorEnabled : stream.isTTY } log.enableColor = function () { colorEnabled = true this.gauge.setTheme({ hasColor: colorEnabled, hasUnicode: unicodeEnabled }) } log.disableColor = function () { colorEnabled = false this.gauge.setTheme({ hasColor: colorEnabled, hasUnicode: unicodeEnabled }) } // default level log.level = 'info' log.gauge = new Gauge(stream, { enabled: false, // no progress bars unless asked theme: { hasColor: log.useColor() }, template: [ { type: 'progressbar', length: 20 }, { type: 'activityIndicator', kerning: 1, length: 1 }, { type: 'section', default: '' }, ':', { type: 'logline', kerning: 1, default: '' }, ], }) log.tracker = new Progress.TrackerGroup() // we track this separately as we may need to temporarily disable the // display of the status bar for our own loggy purposes. log.progressEnabled = log.gauge.isEnabled() var unicodeEnabled log.enableUnicode = function () { unicodeEnabled = true this.gauge.setTheme({ hasColor: this.useColor(), hasUnicode: unicodeEnabled }) } log.disableUnicode = function () { unicodeEnabled = false this.gauge.setTheme({ hasColor: this.useColor(), hasUnicode: unicodeEnabled }) } log.setGaugeThemeset = function (themes) { this.gauge.setThemeset(themes) } log.setGaugeTemplate = function (template) { this.gauge.setTemplate(template) } log.enableProgress = function () { if (this.progressEnabled) { return } this.progressEnabled = true this.tracker.on('change', this.showProgress) if (this._paused) { return } this.gauge.enable() } log.disableProgress = function () { if (!this.progressEnabled) { return } this.progressEnabled = false this.tracker.removeListener('change', this.showProgress) this.gauge.disable() } var trackerConstructors = ['newGroup', 'newItem', 'newStream'] var mixinLog = function (tracker) { // mixin the public methods from log into the tracker // (except: conflicts and one's we handle specially) Object.keys(log).forEach(function (P) { if (P[0] === '_') { return } if (trackerConstructors.filter(function (C) { return C === P }).length) { return } if (tracker[P]) { return } if (typeof log[P] !== 'function') { return } var func = log[P] tracker[P] = function () { return func.apply(log, arguments) } }) // if the new tracker is a group, make sure any subtrackers get // mixed in too if (tracker instanceof Progress.TrackerGroup) { trackerConstructors.forEach(function (C) { var func = tracker[C] tracker[C] = function () { return mixinLog(func.apply(tracker, arguments)) } }) } return tracker } // Add tracker constructors to the top level log object trackerConstructors.forEach(function (C) { log[C] = function () { return mixinLog(this.tracker[C].apply(this.tracker, arguments)) } }) log.clearProgress = function (cb) { if (!this.progressEnabled) { return cb && process.nextTick(cb) } this.gauge.hide(cb) } log.showProgress = function (name, completed) { if (!this.progressEnabled) { return } var values = {} if (name) { values.section = name } var last = log.record[log.record.length - 1] if (last) { values.subsection = last.prefix var disp = log.disp[last.level] || last.level var logline = this._format(disp, log.style[last.level]) if (last.prefix) { logline += ' ' + this._format(last.prefix, this.prefixStyle) } logline += ' ' + last.message.split(/\r?\n/)[0] values.logline = logline } values.completed = completed || this.tracker.completed() this.gauge.show(values) }.bind(log) // bind for use in tracker's on-change listener // temporarily stop emitting, but don't drop log.pause = function () { this._paused = true if (this.progressEnabled) { this.gauge.disable() } } log.resume = function () { if (!this._paused) { return } this._paused = false var b = this._buffer this._buffer = [] b.forEach(function (m) { this.emitLog(m) }, this) if (this.progressEnabled) { this.gauge.enable() } } log._buffer = [] var id = 0 log.record = [] log.maxRecordSize = 10000 log.log = function (lvl, prefix, message) { var l = this.levels[lvl] if (l === undefined) { return this.emit('error', new Error(util.format( 'Undefined log level: %j', lvl))) } var a = new Array(arguments.length - 2) var stack = null for (var i = 2; i < arguments.length; i++) { var arg = a[i - 2] = arguments[i] // resolve stack traces to a plain string. if (typeof arg === 'object' && arg instanceof Error && arg.stack) { Object.defineProperty(arg, 'stack', { value: stack = arg.stack + '', enumerable: true, writable: true, }) } } if (stack) { a.unshift(stack + '\n') } message = util.format.apply(util, a) var m = { id: id++, level: lvl, prefix: String(prefix || ''), message: message, messageRaw: a, } this.emit('log', m) this.emit('log.' + lvl, m) if (m.prefix) { this.emit(m.prefix, m) } this.record.push(m) var mrs = this.maxRecordSize var n = this.record.length - mrs if (n > mrs / 10) { var newSize = Math.floor(mrs * 0.9) this.record = this.record.slice(-1 * newSize) } this.emitLog(m) }.bind(log) log.emitLog = function (m) { if (this._paused) { this._buffer.push(m) return } if (this.progressEnabled) { this.gauge.pulse(m.prefix) } var l = this.levels[m.level] if (l === undefined) { return } if (l < this.levels[this.level]) { return } if (l > 0 && !isFinite(l)) { return } // If 'disp' is null or undefined, use the lvl as a default // Allows: '', 0 as valid disp var disp = log.disp[m.level] != null ? log.disp[m.level] : m.level this.clearProgress() m.message.split(/\r?\n/).forEach(function (line) { var heading = this.heading if (heading) { this.write(heading, this.headingStyle) this.write(' ') } this.write(disp, log.style[m.level]) var p = m.prefix || '' if (p) { this.write(' ') } this.write(p, this.prefixStyle) this.write(' ' + line + '\n') }, this) this.showProgress() } log._format = function (msg, style) { if (!stream) { return } var output = '' if (this.useColor()) { style = style || {} var settings = [] if (style.fg) { settings.push(style.fg) } if (style.bg) { settings.push('bg' + style.bg[0].toUpperCase() + style.bg.slice(1)) } if (style.bold) { settings.push('bold') } if (style.underline) { settings.push('underline') } if (style.inverse) { settings.push('inverse') } if (settings.length) { output += consoleControl.color(settings) } if (style.beep) { output += consoleControl.beep() } } output += msg if (this.useColor()) { output += consoleControl.color('reset') } return output } log.write = function (msg, style) { if (!stream) { return } stream.write(this._format(msg, style)) } log.addLevel = function (lvl, n, style, disp) { // If 'disp' is null or undefined, use the lvl as a default if (disp == null) { disp = lvl } this.levels[lvl] = n this.style[lvl] = style if (!this[lvl]) { this[lvl] = function () { var a = new Array(arguments.length + 1) a[0] = lvl for (var i = 0; i < arguments.length; i++) { a[i + 1] = arguments[i] } return this.log.apply(this, a) }.bind(this) } this.disp[lvl] = disp } log.prefixStyle = { fg: 'magenta' } log.headingStyle = { fg: 'white', bg: 'black' } log.style = {} log.levels = {} log.disp = {} log.addLevel('silly', -Infinity, { inverse: true }, 'sill') log.addLevel('verbose', 1000, { fg: 'cyan', bg: 'black' }, 'verb') log.addLevel('info', 2000, { fg: 'green' }) log.addLevel('timing', 2500, { fg: 'green', bg: 'black' }) log.addLevel('http', 3000, { fg: 'green', bg: 'black' }) log.addLevel('notice', 3500, { fg: 'cyan', bg: 'black' }) log.addLevel('warn', 4000, { fg: 'black', bg: 'yellow' }, 'WARN') log.addLevel('error', 5000, { fg: 'red', bg: 'black' }, 'ERR!') log.addLevel('silent', Infinity) // allow 'error' prefix log.on('error', function () {}) ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/package.json���������������������������������������������������������������������������0000664�0000000�0000000�00000002116�14201007145�0015272�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "author": "GitHub Inc.", "name": "npmlog", "description": "logger for npm", "version": "6.0.1", "repository": { "type": "git", "url": "https://github.com/npm/npmlog.git" }, "main": "lib/log.js", "files": [ "bin", "lib" ], "scripts": { "test": "tap", "npmclilint": "npmcli-lint", "lint": "eslint '**/*.js'", "lintfix": "npm run lint -- --fix", "posttest": "npm run lint", "postsnap": "npm run lintfix --", "postlint": "npm-template-check", "preversion": "npm test", "postversion": "npm publish", "prepublishOnly": "git push origin --follow-tags", "snap": "tap", "template-copy": "npm-template-copy --force" }, "dependencies": { "are-we-there-yet": "^3.0.0", "console-control-strings": "^1.1.0", "gauge": "^4.0.0", "set-blocking": "^2.0.0" }, "devDependencies": { "@npmcli/template-oss": "^2.7.1", "tap": "^15.1.6" }, "license": "ISC", "engines": { "node": "^12.13.0 || ^14.15.0 || >=16" }, "tap": { "branches": 95 }, "templateOSS": { "version": "2.7.1" } } ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/test/����������������������������������������������������������������������������������0000775�0000000�0000000�00000000000�14201007145�0013763�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/test/basic.js��������������������������������������������������������������������������0000664�0000000�0000000�00000042142�14201007145�0015405�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������const t = require('tap') const log = require('../') const stream = require('stream') const result = [] const logEvents = [] const logInfoEvents = [] const logPrefixEvents = [] const resultExpect = [ // eslint-disable-next-line max-len '\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[7msill\u001b[0m \u001b[0m\u001b[35msilly prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[36;40mverb\u001b[0m \u001b[0m\u001b[35mverbose prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[32minfo\u001b[0m \u001b[0m\u001b[35minfo prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[32;40mtiming\u001b[0m \u001b[0m\u001b[35mtiming prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[32;40mhttp\u001b[0m \u001b[0m\u001b[35mhttp prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[36;40mnotice\u001b[0m \u001b[0m\u001b[35mnotice prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[30;43mWARN\u001b[0m \u001b[0m\u001b[35mwarn prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[31;40mERR!\u001b[0m \u001b[0m\u001b[35merror prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[32minfo\u001b[0m \u001b[0m\u001b[35minfo prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[32;40mtiming\u001b[0m \u001b[0m\u001b[35mtiming prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[32;40mhttp\u001b[0m \u001b[0m\u001b[35mhttp prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[36;40mnotice\u001b[0m \u001b[0m\u001b[35mnotice prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[30;43mWARN\u001b[0m \u001b[0m\u001b[35mwarn prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[31;40mERR!\u001b[0m \u001b[0m\u001b[35merror prefix\u001b[0m x = {"foo":{"bar":"baz"}}\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[31;40mERR!\u001b[0m \u001b[0m\u001b[35m404\u001b[0m This is a longer\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[31;40mERR!\u001b[0m \u001b[0m\u001b[35m404\u001b[0m message, with some details\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[31;40mERR!\u001b[0m \u001b[0m\u001b[35m404\u001b[0m and maybe a stack.\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[31;40mERR!\u001b[0m \u001b[0m\u001b[35m404\u001b[0m \n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u0007noise\u001b[0m\u001b[35m\u001b[0m LOUD NOISES\n', // eslint-disable-next-line max-len '\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u0007noise\u001b[0m \u001b[0m\u001b[35merror\u001b[0m erroring\n', '\u001b[0m', ] const logPrefixEventsExpect = [ { id: 2, level: 'info', prefix: 'info prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 11, level: 'info', prefix: 'info prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 20, level: 'info', prefix: 'info prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, ] // should be the same. const logInfoEventsExpect = logPrefixEventsExpect const logEventsExpect = [ { id: 0, level: 'silly', prefix: 'silly prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 1, level: 'verbose', prefix: 'verbose prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 2, level: 'info', prefix: 'info prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 3, level: 'timing', prefix: 'timing prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 4, level: 'http', prefix: 'http prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 5, level: 'notice', prefix: 'notice prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 6, level: 'warn', prefix: 'warn prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 7, level: 'error', prefix: 'error prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 8, level: 'silent', prefix: 'silent prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 9, level: 'silly', prefix: 'silly prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 10, level: 'verbose', prefix: 'verbose prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 11, level: 'info', prefix: 'info prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 12, level: 'timing', prefix: 'timing prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 13, level: 'http', prefix: 'http prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 14, level: 'notice', prefix: 'notice prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 15, level: 'warn', prefix: 'warn prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 16, level: 'error', prefix: 'error prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 17, level: 'silent', prefix: 'silent prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 18, level: 'silly', prefix: 'silly prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 19, level: 'verbose', prefix: 'verbose prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 20, level: 'info', prefix: 'info prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 21, level: 'timing', prefix: 'timing prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 22, level: 'http', prefix: 'http prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 23, level: 'notice', prefix: 'notice prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 24, level: 'warn', prefix: 'warn prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 25, level: 'error', prefix: 'error prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 26, level: 'silent', prefix: 'silent prefix', message: 'x = {"foo":{"bar":"baz"}}', messageRaw: ['x = %j', { foo: { bar: 'baz' } }] }, { id: 27, level: 'error', prefix: '404', message: 'This is a longer\nmessage, with some details\nand maybe a stack.\n', messageRaw: ['This is a longer\nmessage, with some details\nand maybe a stack.\n'] }, { id: 28, level: 'noise', prefix: false, message: 'LOUD NOISES', messageRaw: ['LOUD NOISES'] }, { id: 29, level: 'noise', prefix: 'error', message: 'erroring', messageRaw: ['erroring'] }, ] const Stream = require('stream').Stream const s = new Stream() s.write = function (m) { result.push(m) } s.writable = true s.isTTY = true s.end = function () {} log.stream = s log.heading = 'npm' t.test('basic', async t => { t.same(log.stream, s, 'stream getter works') log.on('log', logEvents.push.bind(logEvents)) log.on('log.info', logInfoEvents.push.bind(logInfoEvents)) log.on('info prefix', logPrefixEvents.push.bind(logPrefixEvents)) console.error('log.level=silly') log.level = 'silly' log.silly('silly prefix', 'x = %j', { foo: { bar: 'baz' } }) log.verbose('verbose prefix', 'x = %j', { foo: { bar: 'baz' } }) log.info('info prefix', 'x = %j', { foo: { bar: 'baz' } }) log.timing('timing prefix', 'x = %j', { foo: { bar: 'baz' } }) log.http('http prefix', 'x = %j', { foo: { bar: 'baz' } }) log.notice('notice prefix', 'x = %j', { foo: { bar: 'baz' } }) log.warn('warn prefix', 'x = %j', { foo: { bar: 'baz' } }) log.error('error prefix', 'x = %j', { foo: { bar: 'baz' } }) log.silent('silent prefix', 'x = %j', { foo: { bar: 'baz' } }) console.error('log.level=silent') log.level = 'silent' log.silly('silly prefix', 'x = %j', { foo: { bar: 'baz' } }) log.verbose('verbose prefix', 'x = %j', { foo: { bar: 'baz' } }) log.info('info prefix', 'x = %j', { foo: { bar: 'baz' } }) log.timing('timing prefix', 'x = %j', { foo: { bar: 'baz' } }) log.http('http prefix', 'x = %j', { foo: { bar: 'baz' } }) log.notice('notice prefix', 'x = %j', { foo: { bar: 'baz' } }) log.warn('warn prefix', 'x = %j', { foo: { bar: 'baz' } }) log.error('error prefix', 'x = %j', { foo: { bar: 'baz' } }) log.silent('silent prefix', 'x = %j', { foo: { bar: 'baz' } }) console.error('log.level=info') log.level = 'info' log.silly('silly prefix', 'x = %j', { foo: { bar: 'baz' } }) log.verbose('verbose prefix', 'x = %j', { foo: { bar: 'baz' } }) log.info('info prefix', 'x = %j', { foo: { bar: 'baz' } }) log.timing('timing prefix', 'x = %j', { foo: { bar: 'baz' } }) log.http('http prefix', 'x = %j', { foo: { bar: 'baz' } }) log.notice('notice prefix', 'x = %j', { foo: { bar: 'baz' } }) log.warn('warn prefix', 'x = %j', { foo: { bar: 'baz' } }) log.error('error prefix', 'x = %j', { foo: { bar: 'baz' } }) log.silent('silent prefix', 'x = %j', { foo: { bar: 'baz' } }) log.error('404', 'This is a longer\n' + 'message, with some details\n' + 'and maybe a stack.\n') log.addLevel('noise', 10000, { beep: true }) log.noise(false, 'LOUD NOISES') log.noise('error', 'erroring') t.same(result.join('').trim(), resultExpect.join('').trim(), 'result') t.same(log.record, logEventsExpect, 'record') t.same(logEvents, logEventsExpect, 'logEvents') t.same(logInfoEvents, logInfoEventsExpect, 'logInfoEvents') t.same(logPrefixEvents, logPrefixEventsExpect, 'logPrefixEvents') }) t.test('util functions', async t => { t.teardown(() => { log.resume() log.gauge.enable() }) t.test('enableColor', async t => { t.teardown(() => { log.disableColor() }) log.enableColor() t.same(log.useColor(), true, 'log has color enabled') t.match(log.gauge._theme, { hasColor: true }, 'gauge has color enabled') }) t.test('disableColor', async t => { log.disableColor() t.same(log.useColor(), false, 'color is disabled') t.match(log.gauge._theme, { hasColor: false }, 'gauge has color disabled') }) t.test('enableUnicode', async t => { t.teardown(() => { log.disableUnicode() }) log.enableUnicode() t.match(log.gauge._theme, { hasUnicode: true }, 'gauge has unicode enabled') }) t.test('disableUnicode', async t => { log.disableUnicode() t.match(log.gauge._theme, { hasUnicode: false }, 'gauge has unicode disabled') }) t.test('themes', async t => { const _themes = log.gauge._themes t.teardown(() => { log.setGaugeThemeset(_themes) }) const themes = require('gauge/lib/themes') const newThemes = themes.newThemeSet() log.setGaugeThemeset(newThemes) t.match(log.gauge._themes, newThemes, 'gauge has new theme set') }) t.test('template', async t => { const _template = log.gauge._gauge.template t.teardown(() => { log.gauge._gauge.template = _template }) const template = [{ type: 'progressbar', length: 100 }] log.setGaugeTemplate(template) t.match(log.gauge._gauge.template, template) }) t.test('enableProgress while paused', async t => { t.teardown(() => { log.enableProgress() log.resume() }) log.disableProgress() log.pause() log.enableProgress() t.same(log.gauge.isEnabled(), false, 'gauge is still disabled') }) t.test('pause while progressEnabled', async t => { t.teardown(() => { log.resume() }) log.pause() t.same(log.gauge.isEnabled(), false, 'gauge is disabled') }) t.test('_buffer while paused', async t => { t.teardown(() => { log.resume() }) // const bufferLength = this._buffer.length log.pause() log.log('verbose', 'test', 'test log') t.equal(log._buffer.length, 1, 'message was buffered') log.resume() t.equal(log._buffer.length, 0, 'message was unbuffered') }) }) t.test('log.log', async t => { t.test('emits error on bad loglevel', t => { log.once('error', (err) => { t.match(err, /Undefined log level: "asdf"/) t.end() }) log.log('asdf', 'bad loglevel') }) t.test('resolves stack traces to a plain string', t => { log.once('log', (m) => { t.match(m.message, 'Error: with a stack trace', 'has error message') t.match(m.message, 'at Test', 'has stack info') t.end() }) const err = new Error('with a stack trace') log.log('verbose', 'oops', err) }) t.test('max record size', async t => { const mrs = log.maxRecordSize t.teardown(() => { log.maxRecordSize = mrs }) log.maxRecordSize = 3 log.log('verbose', 'test', 'log 1') log.log('verbose', 'test', 'log 2') log.log('verbose', 'test', 'log 3') log.log('verbose', 'test', 'log 4') t.equal(log.record.length, 3, 'only maxRecordSize entries in record') }) }) t.test('write with no stream', async t => { const gauge = log.gauge t.teardown(() => { log.gauge = gauge log.stream = s }) log.gauge = null log.stream = null log.write('message') t.ok('does not throw') }) t.test('emitLog to nonexistant level', async t => { t.teardown(() => { log.stream = s }) const badStream = new stream.Writable() badStream.on('data', () => { throw new Error('should not have gotten data!') }) log.emitLog({ prefix: 'test', level: 'asdf' }) t.ok('does not throw') }) t.test('emitLog to nonexistant level', async t => { t.teardown(() => { log.stream = s }) const badStream = new stream.Writable() badStream.on('data', () => { throw new Error('should not have gotten data!') }) log.emitLog({ prefix: 'test', level: 'asdf' }) t.ok('does not throw') }) t.test('_format with nonexistant stream', async t => { const gauge = log.gauge t.teardown(() => { log.gauge = gauge log.stream = s }) log.gauge = null log.stream = null t.match(log._format('message'), undefined, 'does nothing') }) t.test('_format', async t => { t.teardown(() => { log.disableColor() }) t.test('nonexistant stream', async t => { const gauge = log.gauge t.teardown(() => { log.gauge = gauge log.stream = s }) log.gauge = null log.stream = null t.match(log._format('message'), undefined, 'does nothing') }) t.test('fg', async t => { log.enableColor() const o = log._format('test message', { bg: 'blue' }) t.match(o, '\u001b[44mtest message\u001b[0m') }) t.test('bg', async t => { log.enableColor() const o = log._format('test message', { bg: 'white' }) t.match(o, '\u001b[47mtest message\u001b[0m') }) t.test('bold', async t => { log.enableColor() const o = log._format('test message', { bold: true }) t.match(o, '\u001b[1mtest message\u001b[0m') }) t.test('underline', async t => { log.enableColor() const o = log._format('test message', { underline: true }) t.match(o, '\u001b[4mtest message\u001b[0m') }) t.test('inverse', async t => { log.enableColor() const o = log._format('test message', { inverse: true }) t.match(o, '\u001b[7mtest message\u001b[0m') }) }) ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/test/display.js������������������������������������������������������������������������0000664�0000000�0000000�00000001425�14201007145�0015770�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������var tap = require('tap') var log = require('../') var actual = '' // Store and stub log.write, so we can get at // the actual arguments passed to it on each call. var write = log.write log.write = function (msg) { actual += msg } tap.test('explicitly set new log level display to empty string', function (t) { log.addLevel('explicitNoLevelDisplayed', 20000, {}, '') log.explicitNoLevelDisplayed('1', '2') t.equal(actual.trim(), '1 2') actual = '' log.explicitNoLevelDisplayed('', '1') t.equal(actual.trim(), '1') actual = '' t.end() }) tap.test('explicitly set new log level display to 0', function (t) { log.addLevel('explicitNoLevelDisplayed', 20000, {}, 0) log.explicitNoLevelDisplayed('', '1') t.equal(actual.trim(), '0 1') t.end() }) log.write = write �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npmlog-6.0.1/test/progress.js�����������������������������������������������������������������������0000664�0000000�0000000�00000012032�14201007145�0016163�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������'use strict' var test = require('tap').test var Progress = require('are-we-there-yet') var log = require('../') var actions = [] log.gauge = { enabled: false, enable: function () { this.enabled = true actions.push(['enable']) }, disable: function () { this.enabled = false actions.push(['disable']) }, isEnabled: function () { return this.enabled }, hide: function () { actions.push(['hide']) }, show: function () { actions.push(['show'].concat(Array.prototype.slice.call(arguments))) }, pulse: function (name) { actions.push(['pulse', name]) }, } function recursiveMatch (t, actual, expected, desc) { if (expected instanceof RegExp) { return t.match(actual, expected, desc + ' matches') } else if (typeof expected === 'boolean') { return t.equal(!!actual, expected, desc + ' exists') } else if (typeof expected !== 'object' || expected == null) { return t.equal(actual, expected, desc + ' are equal') } else { if (actual == null) { actual = {} } Object.keys(expected).forEach(function (key) { recursiveMatch(t, actual && actual[key], expected[key], desc + ':' + key) }) if (Array.isArray(actual)) { if (!t.equal(actual.length, expected.length, desc + ' has matching length')) { t.comment(' Actual: ', actual) t.comment(' Expected: ', expected) } } else { Object.keys(actual).forEach(function (key) { if (expected[key] == null) { t.fail(desc + ':' + key + ' should not be set') } }) } } } function didActions (t, msg, output) { t.equal(actions.length, output.length, msg) for (var cmd = 0; cmd < output.length; ++cmd) { recursiveMatch(t, actions[cmd], output[cmd], msg + ':' + output[cmd][0]) } actions = [] } function resetTracker () { log.disableProgress() log.tracker = new Progress.TrackerGroup() log.enableProgress() actions = [] } test('enableProgress', function (t) { t.plan(4) resetTracker() log.disableProgress() actions = [] log.enableProgress() didActions(t, 'enableProgress', [['enable']]) log.enableProgress() didActions(t, 'enableProgress again', []) }) test('disableProgress', function (t) { t.plan(4) resetTracker() log.disableProgress() didActions(t, 'disableProgress', [['disable']]) log.disableProgress() didActions(t, 'disableProgress again', []) }) test('showProgress', function (t) { t.plan(6) resetTracker() log.disableProgress() actions = [] log.showProgress('foo') didActions(t, 'showProgress disabled', []) log.enableProgress() actions = [] log.showProgress('foo') didActions(t, 'showProgress', [['show', { section: 'foo', completed: 0 }]]) }) test('clearProgress', function (t) { t.plan(4) resetTracker() log.clearProgress() didActions(t, 'clearProgress', [['hide']]) log.disableProgress() actions = [] log.clearProgress() didActions(t, 'clearProgress disabled', []) }) test('newItem', function (t) { t.plan(21) resetTracker() actions = [] var a = log.newItem('test', 10) didActions(t, 'newItem', [['show', { section: 'test', completed: 0, subsection: false, logline: false, }]]) a.completeWork(5) didActions(t, 'newItem:completeWork', [['show', { section: 'test', completed: 0.5, subsection: false, logline: false, }]]) a.finish() didActions(t, 'newItem:finish', [['show', { section: 'test', completed: 1, subsection: false, logline: false, }]]) }) // Test that log objects proxy through. // Test that completion status filters up. test('newGroup', function (t) { t.plan(39) resetTracker() var a = log.newGroup('newGroup') didActions(t, 'newGroup', [['show', { section: 'newGroup', completed: 0, subsection: false, logline: false, }]]) a.warn('test', 'this is a test') didActions(t, 'newGroup:warn', [['pulse', 'test'], ['hide'], ['show', { subsection: 'test', logline: /this is a test$/, completed: 0, }]]) var b = a.newItem('newGroup2', 10) didActions(t, 'newGroup:newItem', [['show', { section: 'newGroup2', completed: 0, subsection: true, logline: true, }]]) b.completeWork(5) didActions(t, 'newGroup:completeWork', [['show', { section: 'newGroup2', completed: 0.5, subsection: true, logline: true, }]]) a.finish() didActions(t, 'newGroup:finish', [['show', { section: 'newGroup', completed: 1, subsection: true, logline: true, }]]) }) test('newStream', function (t) { t.plan(22) resetTracker() var a = log.newStream('newStream', 10) didActions(t, 'newStream', [['show', { completed: 0, section: 'newStream', subsection: true, logline: true, }]]) a.write('abcde') didActions(t, 'newStream', [['show', { completed: 0.5, section: 'newStream', subsection: true, logline: true, }]]) a.write('fghij') didActions(t, 'newStream', [['show', { completed: 1, section: 'newStream', subsection: true, logline: true, }]]) t.equal(log.tracker.completed(), 1, 'Overall completion') }) ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������