├── .commitlintrc.js
├── .eslintrc.js
├── .github
├── CODEOWNERS
├── ISSUE_TEMPLATE
│ ├── bug.yml
│ └── config.yml
├── actions
│ ├── create-check
│ │ └── action.yml
│ └── install-latest-npm
│ │ └── action.yml
├── dependabot.yml
├── matchers
│ └── tap.json
├── settings.yml
└── workflows
│ ├── audit.yml
│ ├── ci-release.yml
│ ├── ci.yml
│ ├── codeql-analysis.yml
│ ├── post-dependabot.yml
│ ├── pull-request.yml
│ ├── release-integration.yml
│ └── release.yml
├── .gitignore
├── .npmrc
├── .release-please-manifest.json
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── SECURITY.md
├── lib
└── index.js
├── package.json
├── release-please-config.json
├── tap-snapshots
└── test
│ └── index.js.test.cjs
└── test
├── index.js
├── input.js
├── meta.js
└── time.js
/.commitlintrc.js:
--------------------------------------------------------------------------------
1 | /* This file is automatically added by @npmcli/template-oss. Do not edit. */
2 |
3 | module.exports = {
4 | extends: ['@commitlint/config-conventional'],
5 | rules: {
6 | 'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'deps', 'chore']],
7 | 'header-max-length': [2, 'always', 80],
8 | 'subject-case': [0],
9 | 'body-max-line-length': [0],
10 | 'footer-max-line-length': [0],
11 | },
12 | }
13 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | /* This file is automatically added by @npmcli/template-oss. Do not edit. */
2 |
3 | 'use strict'
4 |
5 | const { readdirSync: readdir } = require('fs')
6 |
7 | const localConfigs = readdir(__dirname)
8 | .filter((file) => file.startsWith('.eslintrc.local.'))
9 | .map((file) => `./${file}`)
10 |
11 | module.exports = {
12 | root: true,
13 | ignorePatterns: [
14 | 'tap-testdir*/',
15 | ],
16 | extends: [
17 | '@npmcli',
18 | ...localConfigs,
19 | ],
20 | }
21 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | * @npm/cli-team
4 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug.yml:
--------------------------------------------------------------------------------
1 | # This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | name: Bug
4 | description: File a bug/issue
5 | title: "[BUG]
"
6 | labels: [ Bug, Needs Triage ]
7 |
8 | body:
9 | - type: checkboxes
10 | attributes:
11 | label: Is there an existing issue for this?
12 | description: Please [search here](./issues) to see if an issue already exists for your problem.
13 | options:
14 | - label: I have searched the existing issues
15 | required: true
16 | - type: textarea
17 | attributes:
18 | label: Current Behavior
19 | description: A clear & concise description of what you're experiencing.
20 | validations:
21 | required: false
22 | - type: textarea
23 | attributes:
24 | label: Expected Behavior
25 | description: A clear & concise description of what you expected to happen.
26 | validations:
27 | required: false
28 | - type: textarea
29 | attributes:
30 | label: Steps To Reproduce
31 | description: Steps to reproduce the behavior.
32 | value: |
33 | 1. In this environment...
34 | 2. With this config...
35 | 3. Run '...'
36 | 4. See error...
37 | validations:
38 | required: false
39 | - type: textarea
40 | attributes:
41 | label: Environment
42 | description: |
43 | examples:
44 | - **npm**: 7.6.3
45 | - **Node**: 13.14.0
46 | - **OS**: Ubuntu 20.04
47 | - **platform**: Macbook Pro
48 | value: |
49 | - npm:
50 | - Node:
51 | - OS:
52 | - platform:
53 | validations:
54 | required: false
55 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | # This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | blank_issues_enabled: true
4 |
--------------------------------------------------------------------------------
/.github/actions/create-check/action.yml:
--------------------------------------------------------------------------------
1 | # This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | name: 'Create Check'
4 | inputs:
5 | name:
6 | required: true
7 | token:
8 | required: true
9 | sha:
10 | required: true
11 | check-name:
12 | default: ''
13 | outputs:
14 | check-id:
15 | value: ${{ steps.create-check.outputs.check_id }}
16 | runs:
17 | using: "composite"
18 | steps:
19 | - name: Get Workflow Job
20 | uses: actions/github-script@v7
21 | id: workflow
22 | env:
23 | JOB_NAME: "${{ inputs.name }}"
24 | SHA: "${{ inputs.sha }}"
25 | with:
26 | result-encoding: string
27 | script: |
28 | const { repo: { owner, repo}, runId, serverUrl } = context
29 | const { JOB_NAME, SHA } = process.env
30 |
31 | const job = await github.rest.actions.listJobsForWorkflowRun({
32 | owner,
33 | repo,
34 | run_id: runId,
35 | per_page: 100
36 | }).then(r => r.data.jobs.find(j => j.name.endsWith(JOB_NAME)))
37 |
38 | return [
39 | `This check is assosciated with ${serverUrl}/${owner}/${repo}/commit/${SHA}.`,
40 | 'Run logs:',
41 | job?.html_url || `could not be found for a job ending with: "${JOB_NAME}"`,
42 | ].join(' ')
43 | - name: Create Check
44 | uses: LouisBrunner/checks-action@v1.6.0
45 | id: create-check
46 | with:
47 | token: ${{ inputs.token }}
48 | sha: ${{ inputs.sha }}
49 | status: in_progress
50 | name: ${{ inputs.check-name || inputs.name }}
51 | output: |
52 | {"summary":"${{ steps.workflow.outputs.result }}"}
53 |
--------------------------------------------------------------------------------
/.github/actions/install-latest-npm/action.yml:
--------------------------------------------------------------------------------
1 | # This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | name: 'Install Latest npm'
4 | description: 'Install the latest version of npm compatible with the Node version'
5 | inputs:
6 | node:
7 | description: 'Current Node version'
8 | required: true
9 | runs:
10 | using: "composite"
11 | steps:
12 | # node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
13 | - name: Update Windows npm
14 | if: |
15 | runner.os == 'Windows' && (
16 | startsWith(inputs.node, 'v10.') ||
17 | startsWith(inputs.node, 'v12.') ||
18 | startsWith(inputs.node, 'v14.')
19 | )
20 | shell: cmd
21 | run: |
22 | curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
23 | tar xf npm-7.5.4.tgz
24 | cd package
25 | node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
26 | cd ..
27 | rmdir /s /q package
28 | - name: Install Latest npm
29 | shell: bash
30 | env:
31 | NODE_VERSION: ${{ inputs.node }}
32 | working-directory: ${{ runner.temp }}
33 | run: |
34 | MATCH=""
35 | SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6")
36 |
37 | echo "node@$NODE_VERSION"
38 |
39 | for SPEC in ${SPECS[@]}; do
40 | ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node')
41 | echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)"
42 |
43 | if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then
44 | MATCH=$SPEC
45 | echo "Found compatible version: npm@$MATCH"
46 | break
47 | fi
48 | done
49 |
50 | if [ -z $MATCH ]; then
51 | echo "Could not find a compatible version of npm for node@$NODE_VERSION"
52 | exit 1
53 | fi
54 |
55 | npm i --prefer-online --no-fund --no-audit -g npm@$MATCH
56 | - name: npm Version
57 | shell: bash
58 | run: npm -v
59 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | # This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | version: 2
4 |
5 | updates:
6 | - package-ecosystem: npm
7 | directory: /
8 | schedule:
9 | interval: daily
10 | target-branch: "main"
11 | allow:
12 | - dependency-type: direct
13 | versioning-strategy: increase-if-necessary
14 | commit-message:
15 | prefix: deps
16 | prefix-development: chore
17 | labels:
18 | - "Dependencies"
19 | open-pull-requests-limit: 10
20 |
--------------------------------------------------------------------------------
/.github/matchers/tap.json:
--------------------------------------------------------------------------------
1 | {
2 | "//@npmcli/template-oss": "This file is automatically added by @npmcli/template-oss. Do not edit.",
3 | "problemMatcher": [
4 | {
5 | "owner": "tap",
6 | "pattern": [
7 | {
8 | "regexp": "^\\s*not ok \\d+ - (.*)",
9 | "message": 1
10 | },
11 | {
12 | "regexp": "^\\s*---"
13 | },
14 | {
15 | "regexp": "^\\s*at:"
16 | },
17 | {
18 | "regexp": "^\\s*line:\\s*(\\d+)",
19 | "line": 1
20 | },
21 | {
22 | "regexp": "^\\s*column:\\s*(\\d+)",
23 | "column": 1
24 | },
25 | {
26 | "regexp": "^\\s*file:\\s*(.*)",
27 | "file": 1
28 | }
29 | ]
30 | }
31 | ]
32 | }
33 |
--------------------------------------------------------------------------------
/.github/settings.yml:
--------------------------------------------------------------------------------
1 | # This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | repository:
4 | allow_merge_commit: false
5 | allow_rebase_merge: true
6 | allow_squash_merge: true
7 | squash_merge_commit_title: PR_TITLE
8 | squash_merge_commit_message: PR_BODY
9 | delete_branch_on_merge: true
10 | enable_automated_security_fixes: true
11 | enable_vulnerability_alerts: true
12 |
13 | branches:
14 | - name: main
15 | protection:
16 | required_status_checks: null
17 | enforce_admins: true
18 | block_creations: true
19 | required_pull_request_reviews:
20 | required_approving_review_count: 1
21 | require_code_owner_reviews: true
22 | require_last_push_approval: true
23 | dismiss_stale_reviews: true
24 | restrictions:
25 | apps: []
26 | users: []
27 | teams: [ "cli-team" ]
28 |
--------------------------------------------------------------------------------
/.github/workflows/audit.yml:
--------------------------------------------------------------------------------
1 | # This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | name: Audit
4 |
5 | on:
6 | workflow_dispatch:
7 | schedule:
8 | # "At 08:00 UTC (01:00 PT) on Monday" https://crontab.guru/#0_8_*_*_1
9 | - cron: "0 8 * * 1"
10 |
11 | permissions:
12 | contents: read
13 |
14 | jobs:
15 | audit:
16 | name: Audit Dependencies
17 | if: github.repository_owner == 'npm'
18 | runs-on: ubuntu-latest
19 | defaults:
20 | run:
21 | shell: bash
22 | steps:
23 | - name: Checkout
24 | uses: actions/checkout@v4
25 | - name: Setup Git User
26 | run: |
27 | git config --global user.email "npm-cli+bot@github.com"
28 | git config --global user.name "npm CLI robot"
29 | - name: Setup Node
30 | uses: actions/setup-node@v4
31 | id: node
32 | with:
33 | node-version: 22.x
34 | check-latest: contains('22.x', '.x')
35 | - name: Install Latest npm
36 | uses: ./.github/actions/install-latest-npm
37 | with:
38 | node: ${{ steps.node.outputs.node-version }}
39 | - name: Install Dependencies
40 | run: npm i --ignore-scripts --no-audit --no-fund --package-lock
41 | - name: Run Production Audit
42 | run: npm audit --omit=dev
43 | - name: Run Full Audit
44 | run: npm audit --audit-level=none
45 |
--------------------------------------------------------------------------------
/.github/workflows/ci-release.yml:
--------------------------------------------------------------------------------
1 | # This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | name: CI - Release
4 |
5 | on:
6 | workflow_dispatch:
7 | inputs:
8 | ref:
9 | required: true
10 | type: string
11 | default: main
12 | workflow_call:
13 | inputs:
14 | ref:
15 | required: true
16 | type: string
17 | check-sha:
18 | required: true
19 | type: string
20 |
21 | permissions:
22 | contents: read
23 | checks: write
24 |
25 | jobs:
26 | lint-all:
27 | name: Lint All
28 | if: github.repository_owner == 'npm'
29 | runs-on: ubuntu-latest
30 | defaults:
31 | run:
32 | shell: bash
33 | steps:
34 | - name: Checkout
35 | uses: actions/checkout@v4
36 | with:
37 | ref: ${{ inputs.ref }}
38 | - name: Setup Git User
39 | run: |
40 | git config --global user.email "npm-cli+bot@github.com"
41 | git config --global user.name "npm CLI robot"
42 | - name: Create Check
43 | id: create-check
44 | if: ${{ inputs.check-sha }}
45 | uses: ./.github/actions/create-check
46 | with:
47 | name: "Lint All"
48 | token: ${{ secrets.GITHUB_TOKEN }}
49 | sha: ${{ inputs.check-sha }}
50 | - name: Setup Node
51 | uses: actions/setup-node@v4
52 | id: node
53 | with:
54 | node-version: 22.x
55 | check-latest: contains('22.x', '.x')
56 | - name: Install Latest npm
57 | uses: ./.github/actions/install-latest-npm
58 | with:
59 | node: ${{ steps.node.outputs.node-version }}
60 | - name: Install Dependencies
61 | run: npm i --ignore-scripts --no-audit --no-fund
62 | - name: Lint
63 | run: npm run lint --ignore-scripts
64 | - name: Post Lint
65 | run: npm run postlint --ignore-scripts
66 | - name: Conclude Check
67 | uses: LouisBrunner/checks-action@v1.6.0
68 | if: steps.create-check.outputs.check-id && always()
69 | with:
70 | token: ${{ secrets.GITHUB_TOKEN }}
71 | conclusion: ${{ job.status }}
72 | check_id: ${{ steps.create-check.outputs.check-id }}
73 |
74 | test-all:
75 | name: Test All - ${{ matrix.platform.name }} - ${{ matrix.node-version }}
76 | if: github.repository_owner == 'npm'
77 | strategy:
78 | fail-fast: false
79 | matrix:
80 | platform:
81 | - name: Linux
82 | os: ubuntu-latest
83 | shell: bash
84 | - name: macOS
85 | os: macos-latest
86 | shell: bash
87 | - name: macOS
88 | os: macos-13
89 | shell: bash
90 | - name: Windows
91 | os: windows-latest
92 | shell: cmd
93 | node-version:
94 | - 18.17.0
95 | - 18.x
96 | - 20.5.0
97 | - 20.x
98 | - 22.x
99 | exclude:
100 | - platform: { name: macOS, os: macos-13, shell: bash }
101 | node-version: 18.17.0
102 | - platform: { name: macOS, os: macos-13, shell: bash }
103 | node-version: 18.x
104 | - platform: { name: macOS, os: macos-13, shell: bash }
105 | node-version: 20.5.0
106 | - platform: { name: macOS, os: macos-13, shell: bash }
107 | node-version: 20.x
108 | - platform: { name: macOS, os: macos-13, shell: bash }
109 | node-version: 22.x
110 | runs-on: ${{ matrix.platform.os }}
111 | defaults:
112 | run:
113 | shell: ${{ matrix.platform.shell }}
114 | steps:
115 | - name: Checkout
116 | uses: actions/checkout@v4
117 | with:
118 | ref: ${{ inputs.ref }}
119 | - name: Setup Git User
120 | run: |
121 | git config --global user.email "npm-cli+bot@github.com"
122 | git config --global user.name "npm CLI robot"
123 | - name: Create Check
124 | id: create-check
125 | if: ${{ inputs.check-sha }}
126 | uses: ./.github/actions/create-check
127 | with:
128 | name: "Test All - ${{ matrix.platform.name }} - ${{ matrix.node-version }}"
129 | token: ${{ secrets.GITHUB_TOKEN }}
130 | sha: ${{ inputs.check-sha }}
131 | - name: Setup Node
132 | uses: actions/setup-node@v4
133 | id: node
134 | with:
135 | node-version: ${{ matrix.node-version }}
136 | check-latest: contains(matrix.node-version, '.x')
137 | - name: Install Latest npm
138 | uses: ./.github/actions/install-latest-npm
139 | with:
140 | node: ${{ steps.node.outputs.node-version }}
141 | - name: Install Dependencies
142 | run: npm i --ignore-scripts --no-audit --no-fund
143 | - name: Add Problem Matcher
144 | run: echo "::add-matcher::.github/matchers/tap.json"
145 | - name: Test
146 | run: npm test --ignore-scripts
147 | - name: Conclude Check
148 | uses: LouisBrunner/checks-action@v1.6.0
149 | if: steps.create-check.outputs.check-id && always()
150 | with:
151 | token: ${{ secrets.GITHUB_TOKEN }}
152 | conclusion: ${{ job.status }}
153 | check_id: ${{ steps.create-check.outputs.check-id }}
154 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | # This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | name: CI
4 |
5 | on:
6 | workflow_dispatch:
7 | pull_request:
8 | push:
9 | branches:
10 | - main
11 | schedule:
12 | # "At 09:00 UTC (02:00 PT) on Monday" https://crontab.guru/#0_9_*_*_1
13 | - cron: "0 9 * * 1"
14 |
15 | permissions:
16 | contents: read
17 |
18 | jobs:
19 | lint:
20 | name: Lint
21 | if: github.repository_owner == 'npm'
22 | runs-on: ubuntu-latest
23 | defaults:
24 | run:
25 | shell: bash
26 | steps:
27 | - name: Checkout
28 | uses: actions/checkout@v4
29 | - name: Setup Git User
30 | run: |
31 | git config --global user.email "npm-cli+bot@github.com"
32 | git config --global user.name "npm CLI robot"
33 | - name: Setup Node
34 | uses: actions/setup-node@v4
35 | id: node
36 | with:
37 | node-version: 22.x
38 | check-latest: contains('22.x', '.x')
39 | - name: Install Latest npm
40 | uses: ./.github/actions/install-latest-npm
41 | with:
42 | node: ${{ steps.node.outputs.node-version }}
43 | - name: Install Dependencies
44 | run: npm i --ignore-scripts --no-audit --no-fund
45 | - name: Lint
46 | run: npm run lint --ignore-scripts
47 | - name: Post Lint
48 | run: npm run postlint --ignore-scripts
49 |
50 | test:
51 | name: Test - ${{ matrix.platform.name }} - ${{ matrix.node-version }}
52 | if: github.repository_owner == 'npm'
53 | strategy:
54 | fail-fast: false
55 | matrix:
56 | platform:
57 | - name: Linux
58 | os: ubuntu-latest
59 | shell: bash
60 | - name: macOS
61 | os: macos-latest
62 | shell: bash
63 | - name: macOS
64 | os: macos-13
65 | shell: bash
66 | - name: Windows
67 | os: windows-latest
68 | shell: cmd
69 | node-version:
70 | - 18.17.0
71 | - 18.x
72 | - 20.5.0
73 | - 20.x
74 | - 22.x
75 | exclude:
76 | - platform: { name: macOS, os: macos-13, shell: bash }
77 | node-version: 18.17.0
78 | - platform: { name: macOS, os: macos-13, shell: bash }
79 | node-version: 18.x
80 | - platform: { name: macOS, os: macos-13, shell: bash }
81 | node-version: 20.5.0
82 | - platform: { name: macOS, os: macos-13, shell: bash }
83 | node-version: 20.x
84 | - platform: { name: macOS, os: macos-13, shell: bash }
85 | node-version: 22.x
86 | runs-on: ${{ matrix.platform.os }}
87 | defaults:
88 | run:
89 | shell: ${{ matrix.platform.shell }}
90 | steps:
91 | - name: Checkout
92 | uses: actions/checkout@v4
93 | - name: Setup Git User
94 | run: |
95 | git config --global user.email "npm-cli+bot@github.com"
96 | git config --global user.name "npm CLI robot"
97 | - name: Setup Node
98 | uses: actions/setup-node@v4
99 | id: node
100 | with:
101 | node-version: ${{ matrix.node-version }}
102 | check-latest: contains(matrix.node-version, '.x')
103 | - name: Install Latest npm
104 | uses: ./.github/actions/install-latest-npm
105 | with:
106 | node: ${{ steps.node.outputs.node-version }}
107 | - name: Install Dependencies
108 | run: npm i --ignore-scripts --no-audit --no-fund
109 | - name: Add Problem Matcher
110 | run: echo "::add-matcher::.github/matchers/tap.json"
111 | - name: Test
112 | run: npm test --ignore-scripts
113 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | # This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | name: CodeQL
4 |
5 | on:
6 | push:
7 | branches:
8 | - main
9 | pull_request:
10 | branches:
11 | - main
12 | schedule:
13 | # "At 10:00 UTC (03:00 PT) on Monday" https://crontab.guru/#0_10_*_*_1
14 | - cron: "0 10 * * 1"
15 |
16 | permissions:
17 | contents: read
18 |
19 | jobs:
20 | analyze:
21 | name: Analyze
22 | runs-on: ubuntu-latest
23 | permissions:
24 | actions: read
25 | contents: read
26 | security-events: write
27 | steps:
28 | - name: Checkout
29 | uses: actions/checkout@v4
30 | - name: Setup Git User
31 | run: |
32 | git config --global user.email "npm-cli+bot@github.com"
33 | git config --global user.name "npm CLI robot"
34 | - name: Initialize CodeQL
35 | uses: github/codeql-action/init@v3
36 | with:
37 | languages: javascript
38 | - name: Perform CodeQL Analysis
39 | uses: github/codeql-action/analyze@v3
40 |
--------------------------------------------------------------------------------
/.github/workflows/post-dependabot.yml:
--------------------------------------------------------------------------------
1 | # This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | name: Post Dependabot
4 |
5 | on: pull_request
6 |
7 | permissions:
8 | contents: write
9 |
10 | jobs:
11 | template-oss:
12 | name: template-oss
13 | if: github.repository_owner == 'npm' && github.actor == 'dependabot[bot]'
14 | runs-on: ubuntu-latest
15 | defaults:
16 | run:
17 | shell: bash
18 | steps:
19 | - name: Checkout
20 | uses: actions/checkout@v4
21 | with:
22 | ref: ${{ github.event.pull_request.head.ref }}
23 | - name: Setup Git User
24 | run: |
25 | git config --global user.email "npm-cli+bot@github.com"
26 | git config --global user.name "npm CLI robot"
27 | - name: Setup Node
28 | uses: actions/setup-node@v4
29 | id: node
30 | with:
31 | node-version: 22.x
32 | check-latest: contains('22.x', '.x')
33 | - name: Install Latest npm
34 | uses: ./.github/actions/install-latest-npm
35 | with:
36 | node: ${{ steps.node.outputs.node-version }}
37 | - name: Install Dependencies
38 | run: npm i --ignore-scripts --no-audit --no-fund
39 | - name: Fetch Dependabot Metadata
40 | id: metadata
41 | uses: dependabot/fetch-metadata@v1
42 | with:
43 | github-token: ${{ secrets.GITHUB_TOKEN }}
44 |
45 | # Dependabot can update multiple directories so we output which directory
46 | # it is acting on so we can run the command for the correct root or workspace
47 | - name: Get Dependabot Directory
48 | if: contains(steps.metadata.outputs.dependency-names, '@npmcli/template-oss')
49 | id: flags
50 | run: |
51 | dependabot_dir="${{ steps.metadata.outputs.directory }}"
52 | if [[ "$dependabot_dir" == "/" || "$dependabot_dir" == "/main" ]]; then
53 | echo "workspace=-iwr" >> $GITHUB_OUTPUT
54 | else
55 | # strip leading slash from directory so it works as a
56 | # a path to the workspace flag
57 | echo "workspace=-w ${dependabot_dir#/}" >> $GITHUB_OUTPUT
58 | fi
59 |
60 | - name: Apply Changes
61 | if: steps.flags.outputs.workspace
62 | id: apply
63 | run: |
64 | npm run template-oss-apply ${{ steps.flags.outputs.workspace }}
65 | if [[ `git status --porcelain` ]]; then
66 | echo "changes=true" >> $GITHUB_OUTPUT
67 | fi
68 | # This only sets the conventional commit prefix. This workflow can't reliably determine
69 | # what the breaking change is though. If a BREAKING CHANGE message is required then
70 | # this PR check will fail and the commit will be amended with stafftools
71 | if [[ "${{ steps.metadata.outputs.update-type }}" == "version-update:semver-major" ]]; then
72 | prefix='feat!'
73 | else
74 | prefix='chore'
75 | fi
76 | echo "message=$prefix: postinstall for dependabot template-oss PR" >> $GITHUB_OUTPUT
77 |
78 | # This step will fail if template-oss has made any workflow updates. It is impossible
79 | # for a workflow to update other workflows. In the case it does fail, we continue
80 | # and then try to apply only a portion of the changes in the next step
81 | - name: Push All Changes
82 | if: steps.apply.outputs.changes
83 | id: push
84 | continue-on-error: true
85 | env:
86 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
87 | run: |
88 | git commit -am "${{ steps.apply.outputs.message }}"
89 | git push
90 |
91 | # If the previous step failed, then reset the commit and remove any workflow changes
92 | # and attempt to commit and push again. This is helpful because we will have a commit
93 | # with the correct prefix that we can then --amend with @npmcli/stafftools later.
94 | - name: Push All Changes Except Workflows
95 | if: steps.apply.outputs.changes && steps.push.outcome == 'failure'
96 | env:
97 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98 | run: |
99 | git reset HEAD~
100 | git checkout HEAD -- .github/workflows/
101 | git clean -fd .github/workflows/
102 | git commit -am "${{ steps.apply.outputs.message }}"
103 | git push
104 |
105 | # Check if all the necessary template-oss changes were applied. Since we continued
106 | # on errors in one of the previous steps, this check will fail if our follow up
107 | # only applied a portion of the changes and we need to followup manually.
108 | #
109 | # Note that this used to run `lint` and `postlint` but that will fail this action
110 | # if we've also shipped any linting changes separate from template-oss. We do
111 | # linting in another action, so we want to fail this one only if there are
112 | # template-oss changes that could not be applied.
113 | - name: Check Changes
114 | if: steps.apply.outputs.changes
115 | run: |
116 | npm exec --offline ${{ steps.flags.outputs.workspace }} -- template-oss-check
117 |
118 | - name: Fail on Breaking Change
119 | if: steps.apply.outputs.changes && startsWith(steps.apply.outputs.message, 'feat!')
120 | run: |
121 | echo "This PR has a breaking change. Run 'npx -p @npmcli/stafftools gh template-oss-fix'"
122 | echo "for more information on how to fix this with a BREAKING CHANGE footer."
123 | exit 1
124 |
--------------------------------------------------------------------------------
/.github/workflows/pull-request.yml:
--------------------------------------------------------------------------------
1 | # This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | name: Pull Request
4 |
5 | on:
6 | pull_request:
7 | types:
8 | - opened
9 | - reopened
10 | - edited
11 | - synchronize
12 |
13 | permissions:
14 | contents: read
15 |
16 | jobs:
17 | commitlint:
18 | name: Lint Commits
19 | if: github.repository_owner == 'npm'
20 | runs-on: ubuntu-latest
21 | defaults:
22 | run:
23 | shell: bash
24 | steps:
25 | - name: Checkout
26 | uses: actions/checkout@v4
27 | with:
28 | fetch-depth: 0
29 | - name: Setup Git User
30 | run: |
31 | git config --global user.email "npm-cli+bot@github.com"
32 | git config --global user.name "npm CLI robot"
33 | - name: Setup Node
34 | uses: actions/setup-node@v4
35 | id: node
36 | with:
37 | node-version: 22.x
38 | check-latest: contains('22.x', '.x')
39 | - name: Install Latest npm
40 | uses: ./.github/actions/install-latest-npm
41 | with:
42 | node: ${{ steps.node.outputs.node-version }}
43 | - name: Install Dependencies
44 | run: npm i --ignore-scripts --no-audit --no-fund
45 | - name: Run Commitlint on Commits
46 | id: commit
47 | continue-on-error: true
48 | run: npx --offline commitlint -V --from 'origin/${{ github.base_ref }}' --to ${{ github.event.pull_request.head.sha }}
49 | - name: Run Commitlint on PR Title
50 | if: steps.commit.outcome == 'failure'
51 | env:
52 | PR_TITLE: ${{ github.event.pull_request.title }}
53 | run: echo "$PR_TITLE" | npx --offline commitlint -V
54 |
--------------------------------------------------------------------------------
/.github/workflows/release-integration.yml:
--------------------------------------------------------------------------------
1 | # This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | name: Release Integration
4 |
5 | on:
6 | workflow_dispatch:
7 | inputs:
8 | releases:
9 | required: true
10 | type: string
11 | description: 'A json array of releases. Required fields: publish: tagName, publishTag. publish check: pkgName, version'
12 | workflow_call:
13 | inputs:
14 | releases:
15 | required: true
16 | type: string
17 | description: 'A json array of releases. Required fields: publish: tagName, publishTag. publish check: pkgName, version'
18 | secrets:
19 | PUBLISH_TOKEN:
20 | required: true
21 |
22 | permissions:
23 | contents: read
24 | id-token: write
25 |
26 | jobs:
27 | publish:
28 | name: Publish
29 | runs-on: ubuntu-latest
30 | defaults:
31 | run:
32 | shell: bash
33 | permissions:
34 | id-token: write
35 | steps:
36 | - name: Checkout
37 | uses: actions/checkout@v4
38 | with:
39 | ref: ${{ fromJSON(inputs.releases)[0].tagName }}
40 | - name: Setup Git User
41 | run: |
42 | git config --global user.email "npm-cli+bot@github.com"
43 | git config --global user.name "npm CLI robot"
44 | - name: Setup Node
45 | uses: actions/setup-node@v4
46 | id: node
47 | with:
48 | node-version: 22.x
49 | check-latest: contains('22.x', '.x')
50 | - name: Install Latest npm
51 | uses: ./.github/actions/install-latest-npm
52 | with:
53 | node: ${{ steps.node.outputs.node-version }}
54 | - name: Install Dependencies
55 | run: npm i --ignore-scripts --no-audit --no-fund
56 | - name: Set npm authToken
57 | run: npm config set '//registry.npmjs.org/:_authToken'=\${PUBLISH_TOKEN}
58 | - name: Publish
59 | env:
60 | PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
61 | RELEASES: ${{ inputs.releases }}
62 | run: |
63 | EXIT_CODE=0
64 |
65 | for release in $(echo $RELEASES | jq -r '.[] | @base64'); do
66 | PUBLISH_TAG=$(echo "$release" | base64 --decode | jq -r .publishTag)
67 | npm publish --provenance --tag="$PUBLISH_TAG"
68 | STATUS=$?
69 | if [[ "$STATUS" -eq 1 ]]; then
70 | EXIT_CODE=$STATUS
71 | fi
72 | done
73 |
74 | exit $EXIT_CODE
75 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | # This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | name: Release
4 |
5 | on:
6 | push:
7 | branches:
8 | - main
9 |
10 | permissions:
11 | contents: write
12 | pull-requests: write
13 | checks: write
14 |
15 | jobs:
16 | release:
17 | outputs:
18 | pr: ${{ steps.release.outputs.pr }}
19 | pr-branch: ${{ steps.release.outputs.pr-branch }}
20 | pr-number: ${{ steps.release.outputs.pr-number }}
21 | pr-sha: ${{ steps.release.outputs.pr-sha }}
22 | releases: ${{ steps.release.outputs.releases }}
23 | comment-id: ${{ steps.create-comment.outputs.comment-id || steps.update-comment.outputs.comment-id }}
24 | check-id: ${{ steps.create-check.outputs.check-id }}
25 | name: Release
26 | if: github.repository_owner == 'npm'
27 | runs-on: ubuntu-latest
28 | defaults:
29 | run:
30 | shell: bash
31 | steps:
32 | - name: Checkout
33 | uses: actions/checkout@v4
34 | - name: Setup Git User
35 | run: |
36 | git config --global user.email "npm-cli+bot@github.com"
37 | git config --global user.name "npm CLI robot"
38 | - name: Setup Node
39 | uses: actions/setup-node@v4
40 | id: node
41 | with:
42 | node-version: 22.x
43 | check-latest: contains('22.x', '.x')
44 | - name: Install Latest npm
45 | uses: ./.github/actions/install-latest-npm
46 | with:
47 | node: ${{ steps.node.outputs.node-version }}
48 | - name: Install Dependencies
49 | run: npm i --ignore-scripts --no-audit --no-fund
50 | - name: Release Please
51 | id: release
52 | env:
53 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54 | run: npx --offline template-oss-release-please --branch="${{ github.ref_name }}" --backport="" --defaultTag="latest"
55 | - name: Create Release Manager Comment Text
56 | if: steps.release.outputs.pr-number
57 | uses: actions/github-script@v7
58 | id: comment-text
59 | with:
60 | result-encoding: string
61 | script: |
62 | const { runId, repo: { owner, repo } } = context
63 | const { data: workflow } = await github.rest.actions.getWorkflowRun({ owner, repo, run_id: runId })
64 | return['## Release Manager', `Release workflow run: ${workflow.html_url}`].join('\n\n')
65 | - name: Find Release Manager Comment
66 | uses: peter-evans/find-comment@v2
67 | if: steps.release.outputs.pr-number
68 | id: found-comment
69 | with:
70 | issue-number: ${{ steps.release.outputs.pr-number }}
71 | comment-author: 'github-actions[bot]'
72 | body-includes: '## Release Manager'
73 | - name: Create Release Manager Comment
74 | id: create-comment
75 | if: steps.release.outputs.pr-number && !steps.found-comment.outputs.comment-id
76 | uses: peter-evans/create-or-update-comment@v3
77 | with:
78 | issue-number: ${{ steps.release.outputs.pr-number }}
79 | body: ${{ steps.comment-text.outputs.result }}
80 | - name: Update Release Manager Comment
81 | id: update-comment
82 | if: steps.release.outputs.pr-number && steps.found-comment.outputs.comment-id
83 | uses: peter-evans/create-or-update-comment@v3
84 | with:
85 | comment-id: ${{ steps.found-comment.outputs.comment-id }}
86 | body: ${{ steps.comment-text.outputs.result }}
87 | edit-mode: 'replace'
88 | - name: Create Check
89 | id: create-check
90 | uses: ./.github/actions/create-check
91 | if: steps.release.outputs.pr-sha
92 | with:
93 | name: "Release"
94 | token: ${{ secrets.GITHUB_TOKEN }}
95 | sha: ${{ steps.release.outputs.pr-sha }}
96 |
97 | update:
98 | needs: release
99 | outputs:
100 | sha: ${{ steps.commit.outputs.sha }}
101 | check-id: ${{ steps.create-check.outputs.check-id }}
102 | name: Update - Release
103 | if: github.repository_owner == 'npm' && needs.release.outputs.pr
104 | runs-on: ubuntu-latest
105 | defaults:
106 | run:
107 | shell: bash
108 | steps:
109 | - name: Checkout
110 | uses: actions/checkout@v4
111 | with:
112 | fetch-depth: 0
113 | ref: ${{ needs.release.outputs.pr-branch }}
114 | - name: Setup Git User
115 | run: |
116 | git config --global user.email "npm-cli+bot@github.com"
117 | git config --global user.name "npm CLI robot"
118 | - name: Setup Node
119 | uses: actions/setup-node@v4
120 | id: node
121 | with:
122 | node-version: 22.x
123 | check-latest: contains('22.x', '.x')
124 | - name: Install Latest npm
125 | uses: ./.github/actions/install-latest-npm
126 | with:
127 | node: ${{ steps.node.outputs.node-version }}
128 | - name: Install Dependencies
129 | run: npm i --ignore-scripts --no-audit --no-fund
130 | - name: Create Release Manager Checklist Text
131 | id: comment-text
132 | env:
133 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
134 | run: npm exec --offline -- template-oss-release-manager --pr="${{ needs.release.outputs.pr-number }}" --backport="" --defaultTag="latest" --publish
135 | - name: Append Release Manager Comment
136 | uses: peter-evans/create-or-update-comment@v3
137 | with:
138 | comment-id: ${{ needs.release.outputs.comment-id }}
139 | body: ${{ steps.comment-text.outputs.result }}
140 | edit-mode: 'append'
141 | - name: Run Post Pull Request Actions
142 | env:
143 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
144 | run: npm run rp-pull-request --ignore-scripts --if-present -- --pr="${{ needs.release.outputs.pr-number }}" --commentId="${{ needs.release.outputs.comment-id }}"
145 | - name: Commit
146 | id: commit
147 | env:
148 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
149 | run: |
150 | git commit --all --amend --no-edit || true
151 | git push --force-with-lease
152 | echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
153 | - name: Create Check
154 | id: create-check
155 | uses: ./.github/actions/create-check
156 | with:
157 | name: "Update - Release"
158 | check-name: "Release"
159 | token: ${{ secrets.GITHUB_TOKEN }}
160 | sha: ${{ steps.commit.outputs.sha }}
161 | - name: Conclude Check
162 | uses: LouisBrunner/checks-action@v1.6.0
163 | with:
164 | token: ${{ secrets.GITHUB_TOKEN }}
165 | conclusion: ${{ job.status }}
166 | check_id: ${{ needs.release.outputs.check-id }}
167 |
168 | ci:
169 | name: CI - Release
170 | needs: [ release, update ]
171 | if: needs.release.outputs.pr
172 | uses: ./.github/workflows/ci-release.yml
173 | with:
174 | ref: ${{ needs.release.outputs.pr-branch }}
175 | check-sha: ${{ needs.update.outputs.sha }}
176 |
177 | post-ci:
178 | needs: [ release, update, ci ]
179 | name: Post CI - Release
180 | if: github.repository_owner == 'npm' && needs.release.outputs.pr && always()
181 | runs-on: ubuntu-latest
182 | defaults:
183 | run:
184 | shell: bash
185 | steps:
186 | - name: Get CI Conclusion
187 | id: conclusion
188 | run: |
189 | result=""
190 | if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
191 | result="failure"
192 | elif [[ "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
193 | result="cancelled"
194 | else
195 | result="success"
196 | fi
197 | echo "result=$result" >> $GITHUB_OUTPUT
198 | - name: Conclude Check
199 | uses: LouisBrunner/checks-action@v1.6.0
200 | with:
201 | token: ${{ secrets.GITHUB_TOKEN }}
202 | conclusion: ${{ steps.conclusion.outputs.result }}
203 | check_id: ${{ needs.update.outputs.check-id }}
204 |
205 | post-release:
206 | needs: release
207 | outputs:
208 | comment-id: ${{ steps.create-comment.outputs.comment-id }}
209 | name: Post Release - Release
210 | if: github.repository_owner == 'npm' && needs.release.outputs.releases
211 | runs-on: ubuntu-latest
212 | defaults:
213 | run:
214 | shell: bash
215 | steps:
216 | - name: Create Release PR Comment Text
217 | id: comment-text
218 | uses: actions/github-script@v7
219 | env:
220 | RELEASES: ${{ needs.release.outputs.releases }}
221 | with:
222 | result-encoding: string
223 | script: |
224 | const releases = JSON.parse(process.env.RELEASES)
225 | const { runId, repo: { owner, repo } } = context
226 | const issue_number = releases[0].prNumber
227 | const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${runId}`
228 |
229 | return [
230 | '## Release Workflow\n',
231 | ...releases.map(r => `- \`${r.pkgName}@${r.version}\` ${r.url}`),
232 | `- Workflow run: :arrows_counterclockwise: ${runUrl}`,
233 | ].join('\n')
234 | - name: Create Release PR Comment
235 | id: create-comment
236 | uses: peter-evans/create-or-update-comment@v3
237 | with:
238 | issue-number: ${{ fromJSON(needs.release.outputs.releases)[0].prNumber }}
239 | body: ${{ steps.comment-text.outputs.result }}
240 |
241 | release-integration:
242 | needs: release
243 | name: Release Integration
244 | if: needs.release.outputs.releases
245 | uses: ./.github/workflows/release-integration.yml
246 | permissions:
247 | contents: read
248 | id-token: write
249 | secrets:
250 | PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
251 | with:
252 | releases: ${{ needs.release.outputs.releases }}
253 |
254 | post-release-integration:
255 | needs: [ release, release-integration, post-release ]
256 | name: Post Release Integration - Release
257 | if: github.repository_owner == 'npm' && needs.release.outputs.releases && always()
258 | runs-on: ubuntu-latest
259 | defaults:
260 | run:
261 | shell: bash
262 | steps:
263 | - name: Get Post Release Conclusion
264 | id: conclusion
265 | run: |
266 | if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
267 | result="x"
268 | elif [[ "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
269 | result="heavy_multiplication_x"
270 | else
271 | result="white_check_mark"
272 | fi
273 | echo "result=$result" >> $GITHUB_OUTPUT
274 | - name: Find Release PR Comment
275 | uses: peter-evans/find-comment@v2
276 | id: found-comment
277 | with:
278 | issue-number: ${{ fromJSON(needs.release.outputs.releases)[0].prNumber }}
279 | comment-author: 'github-actions[bot]'
280 | body-includes: '## Release Workflow'
281 | - name: Create Release PR Comment Text
282 | id: comment-text
283 | if: steps.found-comment.outputs.comment-id
284 | uses: actions/github-script@v7
285 | env:
286 | RESULT: ${{ steps.conclusion.outputs.result }}
287 | BODY: ${{ steps.found-comment.outputs.comment-body }}
288 | with:
289 | result-encoding: string
290 | script: |
291 | const { RESULT, BODY } = process.env
292 | const body = [BODY.replace(/(Workflow run: :)[a-z_]+(:)/, `$1${RESULT}$2`)]
293 | if (RESULT !== 'white_check_mark') {
294 | body.push(':rotating_light::rotating_light::rotating_light:')
295 | body.push([
296 | '@npm/cli-team: The post-release workflow failed for this release.',
297 | 'Manual steps may need to be taken after examining the workflow output.'
298 | ].join(' '))
299 | body.push(':rotating_light::rotating_light::rotating_light:')
300 | }
301 | return body.join('\n\n').trim()
302 | - name: Update Release PR Comment
303 | if: steps.comment-text.outputs.result
304 | uses: peter-evans/create-or-update-comment@v3
305 | with:
306 | comment-id: ${{ steps.found-comment.outputs.comment-id }}
307 | body: ${{ steps.comment-text.outputs.result }}
308 | edit-mode: 'replace'
309 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | # ignore everything in the root
4 | /*
5 |
6 | !**/.gitignore
7 | !/.commitlintrc.js
8 | !/.eslint.config.js
9 | !/.eslintrc.js
10 | !/.eslintrc.local.*
11 | !/.git-blame-ignore-revs
12 | !/.github/
13 | !/.gitignore
14 | !/.npmrc
15 | !/.prettierignore
16 | !/.prettierrc.js
17 | !/.release-please-manifest.json
18 | !/bin/
19 | !/CHANGELOG*
20 | !/CODE_OF_CONDUCT.md
21 | !/CONTRIBUTING.md
22 | !/docs/
23 | !/lib/
24 | !/LICENSE*
25 | !/map.js
26 | !/package.json
27 | !/README*
28 | !/release-please-config.json
29 | !/scripts/
30 | !/SECURITY.md
31 | !/tap-snapshots/
32 | !/test/
33 | !/tsconfig.json
34 | tap-testdir*/
35 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | ; This file is automatically added by @npmcli/template-oss. Do not edit.
2 |
3 | package-lock=false
4 |
--------------------------------------------------------------------------------
/.release-please-manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | ".": "5.0.0"
3 | }
4 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | ## [5.0.0](https://github.com/npm/proc-log/compare/v4.2.0...v5.0.0) (2024-09-03)
4 | ### ⚠️ BREAKING CHANGES
5 | * `proc-log` now supports node `^18.17.0 || >=20.5.0`
6 | ### Bug Fixes
7 | * [`aa3a1f6`](https://github.com/npm/proc-log/commit/aa3a1f65bf38bfd3305a73bdf4b432af12393012) [#101](https://github.com/npm/proc-log/pull/101) align to npm 10 node engine range (@hashtagchris)
8 | ### Chores
9 | * [`2697148`](https://github.com/npm/proc-log/commit/2697148878a32af8c56745486dd0ed44b0e403aa) [#101](https://github.com/npm/proc-log/pull/101) run template-oss-apply (@hashtagchris)
10 | * [`4e025d2`](https://github.com/npm/proc-log/commit/4e025d25c53cd85b767fc9e735f756b9f51a7b57) [#99](https://github.com/npm/proc-log/pull/99) bump @npmcli/eslint-config from 4.0.5 to 5.0.0 (@dependabot[bot])
11 | * [`3d6ab24`](https://github.com/npm/proc-log/commit/3d6ab248c75c9bca053755da4fe9c74e894f0066) [#88](https://github.com/npm/proc-log/pull/88) bump @npmcli/template-oss to 4.22.0 (@lukekarrys)
12 | * [`e12dd15`](https://github.com/npm/proc-log/commit/e12dd15f94483daf7237468a6f4c9df96a4b523d) [#83](https://github.com/npm/proc-log/pull/83) chore: chore: postinstall for dependabot template-oss PR (@lukekarrys)
13 | * [`3cfe857`](https://github.com/npm/proc-log/commit/3cfe8571050f83fe0452a107a0696cafe1af1a51) [#100](https://github.com/npm/proc-log/pull/100) postinstall for dependabot template-oss PR (@hashtagchris)
14 | * [`2b4320c`](https://github.com/npm/proc-log/commit/2b4320c544a0e42fc784d5f75d042908a7227cf6) [#100](https://github.com/npm/proc-log/pull/100) bump @npmcli/template-oss from 4.23.1 to 4.23.3 (@dependabot[bot])
15 |
16 | ## [4.2.0](https://github.com/npm/proc-log/compare/v4.1.0...v4.2.0) (2024-04-16)
17 |
18 | ### Features
19 |
20 | * [`4c0d3cf`](https://github.com/npm/proc-log/commit/4c0d3cfde92e639e81a76655df74e0204a56eec8) [#85](https://github.com/npm/proc-log/pull/85) add flush method to output (#85) (@lukekarrys)
21 |
22 | ## [4.1.0](https://github.com/npm/proc-log/compare/v4.0.0...v4.1.0) (2024-04-15)
23 |
24 | ### Features
25 |
26 | * [`e00086e`](https://github.com/npm/proc-log/commit/e00086ea425a9cb6a849e3853bd3ae79910b3d44) [#80](https://github.com/npm/proc-log/pull/80) add timers and read (@lukekarrys)
27 |
28 | ### Bug Fixes
29 |
30 | * [`4832b21`](https://github.com/npm/proc-log/commit/4832b21f33513ceb0482ba1757594e9776cff408) [#80](https://github.com/npm/proc-log/pull/80) remove args from log pause/resume (@lukekarrys)
31 |
32 | ## [4.0.0](https://github.com/npm/proc-log/compare/v3.0.0...v4.0.0) (2024-04-12)
33 |
34 | ### ⚠️ BREAKING CHANGES
35 |
36 | * the exports on this package have changed. The current functionality has moved to a `log` function in the exports.
37 |
38 | ### Features
39 |
40 | * [`39db1e1`](https://github.com/npm/proc-log/commit/39db1e10e0f10acab4bf02ded5c8b9e6598a6c70) [#77](https://github.com/npm/proc-log/pull/77) add output methods (@wraithgar)
41 | * [`12f35fe`](https://github.com/npm/proc-log/commit/12f35fe4c95caab14966acece3e8fa06ed5e3613) [#77](https://github.com/npm/proc-log/pull/77) log: add timing log level (@wraithgar)
42 | * [`8e90af0`](https://github.com/npm/proc-log/commit/8e90af02d49bed669f9b42d7a31d51d3849aaef1) [#77](https://github.com/npm/proc-log/pull/77) change current exported function "log" (@wraithgar)
43 |
44 | ### Bug Fixes
45 |
46 | * [`ac543c4`](https://github.com/npm/proc-log/commit/ac543c4456443bfa6f044edcfbff2f214e04996b) [#77](https://github.com/npm/proc-log/pull/77) switch to traditional functions (@wraithgar)
47 | * [`978fbf9`](https://github.com/npm/proc-log/commit/978fbf9fbe47a2ec71a61e0adfe61a17c14bce48) [#77](https://github.com/npm/proc-log/pull/77) refactor: don't loop through levels to generate log export (@wraithgar)
48 |
49 | ### Chores
50 |
51 | * [`a393ac6`](https://github.com/npm/proc-log/commit/a393ac604a160c60b677daf2f12658abd25c5f65) [#78](https://github.com/npm/proc-log/pull/78) enable auto publish (#78) (@wraithgar)
52 | * [`3caba0e`](https://github.com/npm/proc-log/commit/3caba0e5209359104e4ae386eb3092bf0a1361be) [#77](https://github.com/npm/proc-log/pull/77) add test plan count for current methods (@wraithgar)
53 | * [`6442a36`](https://github.com/npm/proc-log/commit/6442a3672143060f20cb015808019adbc4378c9f) [#73](https://github.com/npm/proc-log/pull/73) postinstall for dependabot template-oss PR (@lukekarrys)
54 | * [`f8df624`](https://github.com/npm/proc-log/commit/f8df6247c56daf90fe6a9f9042f610cc97662a24) [#73](https://github.com/npm/proc-log/pull/73) bump @npmcli/template-oss from 4.21.1 to 4.21.3 (@dependabot[bot])
55 | * [`31491ca`](https://github.com/npm/proc-log/commit/31491cacfc995dc2811a03ed8718d91520ded2d0) [#70](https://github.com/npm/proc-log/pull/70) postinstall for dependabot template-oss PR (@lukekarrys)
56 | * [`be382b7`](https://github.com/npm/proc-log/commit/be382b7a6eea91f2f59dda5a40f48ac5bf296561) [#70](https://github.com/npm/proc-log/pull/70) bump @npmcli/template-oss from 4.19.0 to 4.21.1 (@dependabot[bot])
57 | * [`de668d7`](https://github.com/npm/proc-log/commit/de668d7d9efdc09c5909c3deb8b7f9b3c7bbb73b) [#51](https://github.com/npm/proc-log/pull/51) postinstall for dependabot template-oss PR (@lukekarrys)
58 | * [`4b8abd0`](https://github.com/npm/proc-log/commit/4b8abd062c223d39842ca1a979341e707847ba39) [#51](https://github.com/npm/proc-log/pull/51) bump @npmcli/template-oss from 4.18.1 to 4.19.0 (@dependabot[bot])
59 | * [`ed8c220`](https://github.com/npm/proc-log/commit/ed8c220a93331069a9d3b5d7e8b1e5d186b54304) [#50](https://github.com/npm/proc-log/pull/50) postinstall for dependabot template-oss PR (@lukekarrys)
60 | * [`36b1d1e`](https://github.com/npm/proc-log/commit/36b1d1ef1be51f7996e0ed0f5645e627d994c14b) [#50](https://github.com/npm/proc-log/pull/50) bump @npmcli/template-oss from 4.18.0 to 4.18.1 (@dependabot[bot])
61 | * [`dfda484`](https://github.com/npm/proc-log/commit/dfda484f3f3f18ddc2e7c0e244d3ab5d2a095f21) [#49](https://github.com/npm/proc-log/pull/49) postinstall for dependabot template-oss PR (@lukekarrys)
62 | * [`f9a8d6d`](https://github.com/npm/proc-log/commit/f9a8d6d954ba383f3a64d291c635b5445ea4bbff) [#49](https://github.com/npm/proc-log/pull/49) bump @npmcli/template-oss from 4.17.0 to 4.18.0 (@dependabot[bot])
63 | * [`857d35e`](https://github.com/npm/proc-log/commit/857d35e1f1023f3ac252743827da42621ce5c30e) [#48](https://github.com/npm/proc-log/pull/48) postinstall for dependabot template-oss PR (@lukekarrys)
64 | * [`6e51a61`](https://github.com/npm/proc-log/commit/6e51a614ed41fd5b50926c0e427282ff65c31acd) [#48](https://github.com/npm/proc-log/pull/48) bump @npmcli/template-oss from 4.15.1 to 4.17.0 (@dependabot[bot])
65 | * [`e668ec7`](https://github.com/npm/proc-log/commit/e668ec7214698b8ce3b2c7c246ea0decafc46a30) [#47](https://github.com/npm/proc-log/pull/47) postinstall for dependabot template-oss PR (@lukekarrys)
66 | * [`eea3f85`](https://github.com/npm/proc-log/commit/eea3f85f3c4c6dc0f39d591d5545b5e982d8812c) [#47](https://github.com/npm/proc-log/pull/47) bump @npmcli/template-oss from 4.14.1 to 4.15.1 (@dependabot[bot])
67 | * [`bc05709`](https://github.com/npm/proc-log/commit/bc05709f98f5f49fd4fa8e16a48ba37da6651157) [#46](https://github.com/npm/proc-log/pull/46) bump @npmcli/template-oss from 4.13.0 to 4.14.1 (#46) (@dependabot[bot], @npm-cli-bot)
68 | * [`98c7267`](https://github.com/npm/proc-log/commit/98c72673600345b4846a4152a316c47e5da10ea2) [#45](https://github.com/npm/proc-log/pull/45) bump @npmcli/template-oss from 4.12.1 to 4.13.0 (#45) (@dependabot[bot], @npm-cli-bot, @nlf)
69 | * [`3500db4`](https://github.com/npm/proc-log/commit/3500db4720fb737430e4dc607a348d457bfaf513) [#44](https://github.com/npm/proc-log/pull/44) bump @npmcli/template-oss from 4.12.0 to 4.12.1 (#44) (@dependabot[bot], @npm-cli-bot)
70 | * [`7636af5`](https://github.com/npm/proc-log/commit/7636af52b117d8083f4d97e4b90ce532c8de1b63) [#43](https://github.com/npm/proc-log/pull/43) postinstall for dependabot template-oss PR (@lukekarrys)
71 | * [`3dc1ca0`](https://github.com/npm/proc-log/commit/3dc1ca0ad5ea12a989be95aad319cde36b4d95f9) [#43](https://github.com/npm/proc-log/pull/43) bump @npmcli/template-oss from 4.11.4 to 4.12.0 (@dependabot[bot])
72 | * [`b62ca21`](https://github.com/npm/proc-log/commit/b62ca21b75b6e878e3f95ccd8e2b84d7ebf38a3f) [#42](https://github.com/npm/proc-log/pull/42) postinstall for dependabot template-oss PR (@lukekarrys)
73 | * [`cef0e0d`](https://github.com/npm/proc-log/commit/cef0e0d8a27e6879ef7d41fc5644ef520c7b92fd) [#42](https://github.com/npm/proc-log/pull/42) bump @npmcli/template-oss from 4.11.3 to 4.11.4 (@dependabot[bot])
74 | * [`cabc576`](https://github.com/npm/proc-log/commit/cabc576873b8081e6440ba6a49406828d5a8b53a) [#41](https://github.com/npm/proc-log/pull/41) postinstall for dependabot template-oss PR (@lukekarrys)
75 | * [`f34b6c7`](https://github.com/npm/proc-log/commit/f34b6c7d0535db65782e3fa993522a1f5df6622e) [#41](https://github.com/npm/proc-log/pull/41) bump @npmcli/template-oss from 4.11.0 to 4.11.3 (@dependabot[bot])
76 | * [`2533092`](https://github.com/npm/proc-log/commit/2533092409fd9a05165aa67a429f20e02a4eb092) [#40](https://github.com/npm/proc-log/pull/40) postinstall for dependabot template-oss PR (@lukekarrys)
77 | * [`bca92ea`](https://github.com/npm/proc-log/commit/bca92eac1f7dcf6a194df132471df7eb60f69ac8) [#40](https://github.com/npm/proc-log/pull/40) bump @npmcli/template-oss from 4.10.0 to 4.11.0 (@dependabot[bot])
78 | * [`3721aed`](https://github.com/npm/proc-log/commit/3721aedec49426d70fff5465425c4a968f790512) [#39](https://github.com/npm/proc-log/pull/39) postinstall for dependabot template-oss PR (@lukekarrys)
79 | * [`94b7ef3`](https://github.com/npm/proc-log/commit/94b7ef3eb362dbd7855737567814e20eaabe507c) [#39](https://github.com/npm/proc-log/pull/39) bump @npmcli/template-oss from 4.8.0 to 4.10.0 (@dependabot[bot])
80 | * [`d4db1ab`](https://github.com/npm/proc-log/commit/d4db1abaddb1754ffc4220f68444388b9c88d7a6) [#37](https://github.com/npm/proc-log/pull/37) postinstall for dependabot template-oss PR (@lukekarrys)
81 | * [`5b16b3a`](https://github.com/npm/proc-log/commit/5b16b3a145b1f238387363e3e87b332ed457673a) [#37](https://github.com/npm/proc-log/pull/37) bump @npmcli/template-oss from 4.6.2 to 4.8.0 (@dependabot[bot])
82 | * [`35fbba3`](https://github.com/npm/proc-log/commit/35fbba37a1aeb96b99737eda9f0ff9f5af192df7) [#36](https://github.com/npm/proc-log/pull/36) postinstall for dependabot template-oss PR (@lukekarrys)
83 | * [`1c0da10`](https://github.com/npm/proc-log/commit/1c0da10c5ec740c6d40fb310f60e91f084827e05) [#36](https://github.com/npm/proc-log/pull/36) bump @npmcli/template-oss from 4.6.1 to 4.6.2 (@dependabot[bot])
84 | * [`487cfeb`](https://github.com/npm/proc-log/commit/487cfeb5ea1780212beacde6ad9505b10f92c432) [#35](https://github.com/npm/proc-log/pull/35) postinstall for dependabot template-oss PR (@lukekarrys)
85 | * [`70dbd12`](https://github.com/npm/proc-log/commit/70dbd124444825c81c897987e3a6c6550225da64) [#35](https://github.com/npm/proc-log/pull/35) bump @npmcli/template-oss from 4.5.1 to 4.6.1 (@dependabot[bot])
86 | * [`d299887`](https://github.com/npm/proc-log/commit/d299887e3d0355ae50fa1e72671c179dbf2efc46) [#34](https://github.com/npm/proc-log/pull/34) bump @npmcli/eslint-config from 3.1.0 to 4.0.0 (@dependabot[bot])
87 |
88 | ## [3.0.0](https://github.com/npm/proc-log/compare/v2.0.1...v3.0.0) (2022-10-10)
89 |
90 | ### ⚠️ BREAKING CHANGES
91 |
92 | * `proc-log` is now compatible with the following semver range for node: `^14.17.0 || ^16.13.0 || >=18.0.0`
93 |
94 | ### Features
95 |
96 | * [`54c85c1`](https://github.com/npm/proc-log/commit/54c85c1d4c0ed59c48d6765b15e8918e2eaf8c3a) [#27](https://github.com/npm/proc-log/pull/27) postinstall for dependabot template-oss PR (@lukekarrys)
97 |
98 | ### [2.0.1](https://github.com/npm/proc-log/compare/v2.0.0...v2.0.1) (2022-03-28)
99 |
100 |
101 | ### Documentation
102 |
103 | * fix pause/resume signatures ([adccecc](https://github.com/npm/proc-log/commit/adccecc2bf5e77427e3fefe826a8e5a1a57640d7))
104 |
105 | ## [2.0.0](https://www.github.com/npm/proc-log/compare/v1.0.0...v2.0.0) (2022-02-10)
106 |
107 |
108 | ### ⚠ BREAKING CHANGES
109 |
110 | * this drops support for node10 and non-LTS versions of node12 and node14
111 |
112 | * @npmcli/template-oss ([#1](https://www.github.com/npm/proc-log/issues/1)) ([d340d8b](https://www.github.com/npm/proc-log/commit/d340d8b90c5612223d456a6d33d36ed83ab1ba41))
113 |
114 |
115 | ### Documentation
116 |
117 | * add example usage ([33ef65c](https://www.github.com/npm/proc-log/commit/33ef65c4dc3cdba2a2555ec1c32f6bd5d281ff6a))
118 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | All interactions in this repo are covered by the [npm Code of
4 | Conduct](https://docs.npmjs.com/policies/conduct)
5 |
6 | The npm cli team may, at its own discretion, moderate, remove, or edit
7 | any interactions such as pull requests, issues, and comments.
8 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Contributing
4 |
5 | ## Code of Conduct
6 |
7 | All interactions in the **npm** organization on GitHub are considered to be covered by our standard [Code of Conduct](https://docs.npmjs.com/policies/conduct).
8 |
9 | ## Reporting Bugs
10 |
11 | Before submitting a new bug report please search for an existing or similar report.
12 |
13 | Use one of our existing issue templates if you believe you've come across a unique problem.
14 |
15 | Duplicate issues, or issues that don't use one of our templates may get closed without a response.
16 |
17 | ## Pull Request Conventions
18 |
19 | ### Commits
20 |
21 | We use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).
22 |
23 | When opening a pull request please be sure that either the pull request title, or each commit in the pull request, has one of the following prefixes:
24 |
25 | - `feat`: For when introducing a new feature. The result will be a new semver minor version of the package when it is next published.
26 | - `fix`: For bug fixes. The result will be a new semver patch version of the package when it is next published.
27 | - `docs`: For documentation updates. The result will be a new semver patch version of the package when it is next published.
28 | - `chore`: For changes that do not affect the published module. Often these are changes to tests. The result will be *no* change to the version of the package when it is next published (as the commit does not affect the published version).
29 |
30 | ### Test Coverage
31 |
32 | Pull requests made against this repo will run `npm test` automatically. Please make sure tests pass locally before submitting a PR.
33 |
34 | Every new feature or bug fix should come with a corresponding test or tests that validate the solutions. Testing also reports on code coverage and will fail if code coverage drops.
35 |
36 | ### Linting
37 |
38 | Linting is also done automatically once tests pass. `npm run lintfix` will fix most linting errors automatically.
39 |
40 | Please make sure linting passes before submitting a PR.
41 |
42 | ## What _not_ to contribute?
43 |
44 | ### Dependencies
45 |
46 | It should be noted that our team does not accept third-party dependency updates/PRs. If you submit a PR trying to update our dependencies we will close it with or without a reference to these contribution guidelines.
47 |
48 | ### Tools/Automation
49 |
50 | Our core team is responsible for the maintenance of the tooling/automation in this project and we ask contributors to not make changes to these when contributing (e.g. `.github/*`, `.eslintrc.json`, `.licensee.json`). Most of those files also have a header at the top to remind folks they are automatically generated. Pull requests that alter these will not be accepted.
51 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The ISC License
2 |
3 | Copyright (c) GitHub, Inc.
4 |
5 | Permission to use, copy, modify, and/or distribute this software for any
6 | purpose with or without fee is hereby granted, provided that the above
7 | copyright notice and this permission notice appear in all copies.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15 | IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # proc-log
2 |
3 | Emits events on the process object which a listener can consume and print to the terminal or log file.
4 |
5 | This 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.
6 |
7 | Currently emits `log`, `output`, `input`, and `time` events.
8 |
9 | ## API
10 |
11 | ```js
12 | const { log, output, input, time } = require('proc-log')
13 | ```
14 |
15 | #### output
16 | * `output.standard(...args)` calls `process.emit('output', 'standard', ...args)`
17 |
18 | This is for general standard output. Consumers will typically show this on stdout (after optionally formatting or filtering it).
19 |
20 | * `output.error(...args)` calls `process.emit('output', 'error', ...args)`
21 |
22 | This is for general error output. Consumers will typically show this on stderr (after optionally formatting or filtering it).
23 |
24 | * `output.buffer(...args)` calls `process.emit('output', 'buffer', ...args)`
25 |
26 | This is for buffered output. Consumers will typically buffer this until they are ready to display.
27 |
28 | * `output.flush(...args)` calls `process.emit('output', 'flush', ...args)`
29 |
30 | This is to indicate that the output buffer should be flushed.
31 |
32 | * `output.LEVELS` an array of strings of all output method names
33 |
34 | #### log
35 | * `log.error(...args)` calls `process.emit('log', 'error', ...args)`
36 |
37 | The highest log level. For printing extremely serious errors that indicate something went wrong.
38 |
39 | * `log.warn(...args)` calls `process.emit('log', 'warn', ...args)`
40 |
41 | 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.
42 |
43 | * `log.notice(...args)` calls `process.emit('log', 'notice', ...args)`
44 |
45 | Notices which are important, but not necessarily dangerous or a cause for excess concern.
46 |
47 | * `log.info(...args)` calls `process.emit('log', 'info', ...args)`
48 |
49 | Informative messages that may benefit the user, but aren't particularly important.
50 |
51 | * `log.verbose(...args)` calls `process.emit('log', 'verbose', ...args)`
52 |
53 | Noisy output that is more detail that most users will care about.
54 |
55 | * `log.silly(...args)` calls `process.emit('log', 'silly', ...args)`
56 |
57 | Extremely noisy excessive logging messages that are typically only useful for debugging.
58 |
59 | * `log.http(...args)` calls `process.emit('log', 'http', ...args)`
60 |
61 | Information about HTTP requests made and/or completed.
62 |
63 | * `log.timing(...args)` calls `process.emit('log', 'timing', ...args)`
64 |
65 | Timing information.
66 |
67 | * `log.pause()` calls `process.emit('log', 'pause')`
68 |
69 | Used to tell the consumer to stop printing messages.
70 |
71 | * `log.resume()` calls `process.emit('log', 'resume')`
72 |
73 | Used to tell the consumer that it is ok to print messages again.
74 |
75 | * `log.LEVELS` an array of strings of all log method names
76 |
77 | #### input
78 |
79 | * `input.start(fn?)` calls `process.emit('input', 'start')`
80 |
81 | 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.
82 |
83 | 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()`.
84 |
85 | * `input.end()` calls `process.emit('input', 'end')`
86 |
87 | Used to tell the consumer that the terminal has stopped reading user input.
88 |
89 | * `input.read(...args): Promise` calls `process.emit('input', 'read', resolve, reject, ...args)`
90 |
91 | 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.
92 |
93 | This emits `resolve` and `reject` functions (in addition to all passed in arguments) which the consumer must use to resolve the returned `Promise`.
94 |
95 | #### time
96 |
97 | * `time.start(timerName, fn?)` calls `process.emit('time', 'start', 'timerName')`
98 |
99 | Used to start a timer with the specified name. Returns a function that will call `time.end()` for convenience.
100 |
101 | 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()`.
102 |
103 | * `time.end(timerName)` calls `process.emit('time', 'end', timeName)`
104 |
105 | Used to tell the consumer to stop a timer with the specified name.
106 |
107 | ## Examples
108 |
109 | ### log
110 |
111 | Every `log` method calls `process.emit('log', level, ...otherArgs)` internally. So in order to consume those events you need to do `process.on('log', fn)`.
112 |
113 | #### Colorize based on level
114 |
115 | Here's an example of how to consume `proc-log` log events and colorize them based on level:
116 |
117 | ```js
118 | const chalk = require('chalk')
119 |
120 | process.on('log', (level, ...args) => {
121 | if (level === 'error') {
122 | console.log(chalk.red(level), ...args)
123 | } else {
124 | console.log(chalk.blue(level), ...args)
125 | }
126 | })
127 | ```
128 |
129 | #### Pause and resume
130 |
131 | `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.
132 |
133 | ```js
134 | let paused = true
135 | const buffer = []
136 |
137 | // this handler will buffer and replay logs only after `procLog.resume()` is called
138 | process.on('log', (level, ...args) => {
139 | if (level === 'resume') {
140 | buffer.forEach((item) => console.log(...item))
141 | paused = false
142 | return
143 | }
144 |
145 | if (paused) {
146 | buffer.push([level, ...args])
147 | } else {
148 | console.log(level, ...args)
149 | }
150 | })
151 |
152 | // this handler will write everything to a file
153 | process.on('log', (...args) => {
154 | fs.appendFileSync('debug.log', args.join(' '))
155 | })
156 | ```
157 |
158 | ### input
159 |
160 | ### `start` and `end`
161 |
162 | **producer.js**
163 | ```js
164 | const { output, input } = require('proc-log')
165 | const { readFromUserInput } = require('./my-read')
166 |
167 | // Using callback passed to `start`
168 | try {
169 | const res = await input.start(
170 | readFromUserInput({ prompt: 'OK?', default: 'y' })
171 | )
172 | output.standard(`User said ${res}`)
173 | } catch (err) {
174 | output.error(`User cancelled: ${err}`)
175 | }
176 |
177 | // Manually calling `start` and `end`
178 | try {
179 | input.start()
180 | const res = await readFromUserInput({ prompt: 'OK?', default: 'y' })
181 | output.standard(`User said ${res}`)
182 | } catch (err) {
183 | output.error(`User cancelled: ${err}`)
184 | } finally {
185 | input.end()
186 | }
187 | ```
188 |
189 | **consumer.js**
190 | ```js
191 | const { read } = require('read')
192 |
193 | process.on('input', (level) => {
194 | if (level === 'start') {
195 | // Hide UI to make room for user input being read
196 | } else if (level === 'end') {
197 | // Restore UI now that reading is ended
198 | }
199 | })
200 | ```
201 |
202 | ### Using `read` to call `read()`
203 |
204 | **producer.js**
205 | ```js
206 | const { output, input } = require('proc-log')
207 |
208 | try {
209 | const res = await input.read({ prompt: 'OK?', default: 'y' })
210 | output.standard(`User said ${res}`)
211 | } catch (err) {
212 | output.error(`User cancelled: ${err}`)
213 | }
214 | ```
215 |
216 | **consumer.js**
217 | ```js
218 | const { read } = require('read')
219 |
220 | process.on('input', (level, ...args) => {
221 | if (level === 'read') {
222 | const [res, rej, opts] = args
223 | read(opts).then(res).catch(rej)
224 | }
225 | })
226 | ```
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | GitHub takes the security of our software products and services seriously, including the open source code repositories managed through our GitHub organizations, such as [GitHub](https://github.com/GitHub).
4 |
5 | If you believe you have found a security vulnerability in this GitHub-owned open source repository, you can report it to us in one of two ways.
6 |
7 | If the vulnerability you have found is *not* [in scope for the GitHub Bug Bounty Program](https://bounty.github.com/#scope) or if you do not wish to be considered for a bounty reward, please report the issue to us directly through [opensource-security@github.com](mailto:opensource-security@github.com).
8 |
9 | If the vulnerability you have found is [in scope for the GitHub Bug Bounty Program](https://bounty.github.com/#scope) and you would like for your finding to be considered for a bounty reward, please submit the vulnerability to us through [HackerOne](https://hackerone.com/github) in order to be eligible to receive a bounty award.
10 |
11 | **Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**
12 |
13 | Thanks for helping make GitHub safe for everyone.
14 |
--------------------------------------------------------------------------------
/lib/index.js:
--------------------------------------------------------------------------------
1 | const META = Symbol('proc-log.meta')
2 | module.exports = {
3 | META: META,
4 | output: {
5 | LEVELS: [
6 | 'standard',
7 | 'error',
8 | 'buffer',
9 | 'flush',
10 | ],
11 | KEYS: {
12 | standard: 'standard',
13 | error: 'error',
14 | buffer: 'buffer',
15 | flush: 'flush',
16 | },
17 | standard: function (...args) {
18 | return process.emit('output', 'standard', ...args)
19 | },
20 | error: function (...args) {
21 | return process.emit('output', 'error', ...args)
22 | },
23 | buffer: function (...args) {
24 | return process.emit('output', 'buffer', ...args)
25 | },
26 | flush: function (...args) {
27 | return process.emit('output', 'flush', ...args)
28 | },
29 | },
30 | log: {
31 | LEVELS: [
32 | 'notice',
33 | 'error',
34 | 'warn',
35 | 'info',
36 | 'verbose',
37 | 'http',
38 | 'silly',
39 | 'timing',
40 | 'pause',
41 | 'resume',
42 | ],
43 | KEYS: {
44 | notice: 'notice',
45 | error: 'error',
46 | warn: 'warn',
47 | info: 'info',
48 | verbose: 'verbose',
49 | http: 'http',
50 | silly: 'silly',
51 | timing: 'timing',
52 | pause: 'pause',
53 | resume: 'resume',
54 | },
55 | error: function (...args) {
56 | return process.emit('log', 'error', ...args)
57 | },
58 | notice: function (...args) {
59 | return process.emit('log', 'notice', ...args)
60 | },
61 | warn: function (...args) {
62 | return process.emit('log', 'warn', ...args)
63 | },
64 | info: function (...args) {
65 | return process.emit('log', 'info', ...args)
66 | },
67 | verbose: function (...args) {
68 | return process.emit('log', 'verbose', ...args)
69 | },
70 | http: function (...args) {
71 | return process.emit('log', 'http', ...args)
72 | },
73 | silly: function (...args) {
74 | return process.emit('log', 'silly', ...args)
75 | },
76 | timing: function (...args) {
77 | return process.emit('log', 'timing', ...args)
78 | },
79 | pause: function () {
80 | return process.emit('log', 'pause')
81 | },
82 | resume: function () {
83 | return process.emit('log', 'resume')
84 | },
85 | },
86 | time: {
87 | LEVELS: [
88 | 'start',
89 | 'end',
90 | ],
91 | KEYS: {
92 | start: 'start',
93 | end: 'end',
94 | },
95 | start: function (name, fn) {
96 | process.emit('time', 'start', name)
97 | function end () {
98 | return process.emit('time', 'end', name)
99 | }
100 | if (typeof fn === 'function') {
101 | const res = fn()
102 | if (res && res.finally) {
103 | return res.finally(end)
104 | }
105 | end()
106 | return res
107 | }
108 | return end
109 | },
110 | end: function (name) {
111 | return process.emit('time', 'end', name)
112 | },
113 | },
114 | input: {
115 | LEVELS: [
116 | 'start',
117 | 'end',
118 | 'read',
119 | ],
120 | KEYS: {
121 | start: 'start',
122 | end: 'end',
123 | read: 'read',
124 | },
125 | start: function (fn) {
126 | process.emit('input', 'start')
127 | function end () {
128 | return process.emit('input', 'end')
129 | }
130 | if (typeof fn === 'function') {
131 | const res = fn()
132 | if (res && res.finally) {
133 | return res.finally(end)
134 | }
135 | end()
136 | return res
137 | }
138 | return end
139 | },
140 | end: function () {
141 | return process.emit('input', 'end')
142 | },
143 | read: function (...args) {
144 | let resolve, reject
145 | const promise = new Promise((_resolve, _reject) => {
146 | resolve = _resolve
147 | reject = _reject
148 | })
149 | process.emit('input', 'read', resolve, reject, ...args)
150 | return promise
151 | },
152 | },
153 | }
154 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "proc-log",
3 | "version": "5.0.0",
4 | "files": [
5 | "bin/",
6 | "lib/"
7 | ],
8 | "main": "lib/index.js",
9 | "description": "just emit 'log' events on the process object",
10 | "repository": {
11 | "type": "git",
12 | "url": "git+https://github.com/npm/proc-log.git"
13 | },
14 | "author": "GitHub Inc.",
15 | "license": "ISC",
16 | "scripts": {
17 | "test": "tap",
18 | "snap": "tap",
19 | "posttest": "npm run lint",
20 | "postsnap": "eslint index.js test/*.js --fix",
21 | "lint": "npm run eslint",
22 | "postlint": "template-oss-check",
23 | "lintfix": "npm run eslint -- --fix",
24 | "template-oss-apply": "template-oss-apply --force",
25 | "eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
26 | },
27 | "devDependencies": {
28 | "@npmcli/eslint-config": "^5.0.0",
29 | "@npmcli/template-oss": "4.24.3",
30 | "tap": "^16.0.1"
31 | },
32 | "engines": {
33 | "node": "^18.17.0 || >=20.5.0"
34 | },
35 | "templateOSS": {
36 | "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
37 | "version": "4.24.3",
38 | "publish": true
39 | },
40 | "tap": {
41 | "nyc-arg": [
42 | "--exclude",
43 | "tap-snapshots/**"
44 | ]
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/release-please-config.json:
--------------------------------------------------------------------------------
1 | {
2 | "group-pull-request-title-pattern": "chore: release ${version}",
3 | "pull-request-title-pattern": "chore: release${component} ${version}",
4 | "changelog-sections": [
5 | {
6 | "type": "feat",
7 | "section": "Features",
8 | "hidden": false
9 | },
10 | {
11 | "type": "fix",
12 | "section": "Bug Fixes",
13 | "hidden": false
14 | },
15 | {
16 | "type": "docs",
17 | "section": "Documentation",
18 | "hidden": false
19 | },
20 | {
21 | "type": "deps",
22 | "section": "Dependencies",
23 | "hidden": false
24 | },
25 | {
26 | "type": "chore",
27 | "section": "Chores",
28 | "hidden": true
29 | }
30 | ],
31 | "packages": {
32 | ".": {
33 | "package-name": ""
34 | }
35 | },
36 | "prerelease-type": "pre.0"
37 | }
38 |
--------------------------------------------------------------------------------
/tap-snapshots/test/index.js.test.cjs:
--------------------------------------------------------------------------------
1 | /* IMPORTANT
2 | * This snapshot file is auto-generated, but designed for humans.
3 | * It should be checked into source control and tracked carefully.
4 | * Re-generate by setting TAP_SNAPSHOT=1 and running tests.
5 | * Make sure to inspect the output below. Do not ignore changes!
6 | */
7 | 'use strict'
8 | exports[`test/index.js TAP input > input keys 1`] = `
9 | Object {
10 | "end": "end",
11 | "read": "read",
12 | "start": "start",
13 | }
14 | `
15 |
16 | exports[`test/index.js TAP input > input levels 1`] = `
17 | Array [
18 | "start",
19 | "end",
20 | "read",
21 | ]
22 | `
23 |
24 | exports[`test/index.js TAP log > log keys 1`] = `
25 | Object {
26 | "error": "error",
27 | "http": "http",
28 | "info": "info",
29 | "notice": "notice",
30 | "pause": "pause",
31 | "resume": "resume",
32 | "silly": "silly",
33 | "timing": "timing",
34 | "verbose": "verbose",
35 | "warn": "warn",
36 | }
37 | `
38 |
39 | exports[`test/index.js TAP log > log levels 1`] = `
40 | Array [
41 | "notice",
42 | "error",
43 | "warn",
44 | "info",
45 | "verbose",
46 | "http",
47 | "silly",
48 | "timing",
49 | "pause",
50 | "resume",
51 | ]
52 | `
53 |
54 | exports[`test/index.js TAP output > output keys 1`] = `
55 | Object {
56 | "buffer": "buffer",
57 | "error": "error",
58 | "flush": "flush",
59 | "standard": "standard",
60 | }
61 | `
62 |
63 | exports[`test/index.js TAP output > output levels 1`] = `
64 | Array [
65 | "standard",
66 | "error",
67 | "buffer",
68 | "flush",
69 | ]
70 | `
71 |
72 | exports[`test/index.js TAP time > time keys 1`] = `
73 | Object {
74 | "end": "end",
75 | "start": "start",
76 | }
77 | `
78 |
79 | exports[`test/index.js TAP time > time levels 1`] = `
80 | Array [
81 | "start",
82 | "end",
83 | ]
84 | `
85 |
--------------------------------------------------------------------------------
/test/index.js:
--------------------------------------------------------------------------------
1 | const t = require('tap')
2 | const procLog = require('../')
3 |
4 | // This makes sure we are testing all known exported methods.
5 | t.plan(5)
6 |
7 | for (const method in procLog) {
8 | if (method === 'META') {
9 | t.test(method, t => {
10 | t.type(procLog[method], 'symbol')
11 | t.end()
12 | })
13 | continue
14 | }
15 |
16 | t.test(method, t => {
17 | const log = procLog[method]
18 | const { LEVELS, KEYS } = log
19 |
20 | t.matchSnapshot(LEVELS, `${method} levels`)
21 | t.matchSnapshot(KEYS, `${method} keys`)
22 |
23 | t.strictSame(Object.keys(KEYS), LEVELS, 'all keys are in levels')
24 | t.strictSame(Object.values(KEYS), LEVELS, 'all vales are in levels')
25 |
26 | t.test(`all ${method}.LEVELS have a function in ${method}`, t => {
27 | for (const level of LEVELS) {
28 | t.test(level, t => {
29 | t.match(log[level], Function)
30 |
31 | process.once(method, (actual, ...args) => {
32 | t.equal(actual, level, `emitted ${method} with expected level`)
33 |
34 | switch (`${method}.${level}`) {
35 | case 'time.start':
36 | case 'time.end':
37 | t.strictSame(args, [1], 'single arg')
38 | break
39 | case 'input.start':
40 | case 'input.end':
41 | case 'log.pause':
42 | case 'log.resume':
43 | t.strictSame(args, [], 'no args')
44 | break
45 | case 'input.read':
46 | t.match(args.slice(0, 2), [Function, Function], 'input gets resolvers')
47 | t.same(args.slice(2), [1, 'two', [3], { 4: 4 }], 'got expected args')
48 | break
49 | default:
50 | t.same(args, [1, 'two', [3], { 4: 4 }], 'got expected args')
51 | }
52 |
53 | t.end()
54 | })
55 |
56 | log[level](1, 'two', [3], { 4: 4 })
57 | })
58 | }
59 |
60 | t.end()
61 | })
62 |
63 | t.test(`all ${method} functions are in ${method}.LEVELS`, t => {
64 | t.plan(LEVELS.length)
65 |
66 | for (const fn in log) {
67 | if (fn !== 'LEVELS' && fn !== 'KEYS') {
68 | t.ok(LEVELS.includes(fn), `${method}.${fn} is in ${method}.LEVELS`)
69 | }
70 | }
71 | })
72 |
73 | t.end()
74 | })
75 | }
76 |
--------------------------------------------------------------------------------
/test/input.js:
--------------------------------------------------------------------------------
1 | const t = require('tap')
2 | const { input } = require('../')
3 |
4 | t.test('read', t => {
5 | t.test('will await promise', async t => {
6 | process.once('input', (level, resolve, reject, ...args) => {
7 | if (level === 'read') {
8 | t.strictSame(args, [1, 2, 3])
9 | setTimeout(() => resolve('done'), 100)
10 | }
11 | })
12 |
13 | await t.resolves(input.read(1, 2, 3), 'done')
14 | })
15 |
16 | t.test('can reject promise', async t => {
17 | process.once('input', (level, resolve, reject, ...args) => {
18 | if (level === 'read') {
19 | t.strictSame(args, [1, 2, 3])
20 | setTimeout(() => reject(new Error('not ok')), 100)
21 | }
22 | })
23 |
24 | await t.rejects(input.read(1, 2, 3), { message: 'not ok' })
25 | })
26 |
27 | t.end()
28 | })
29 |
30 | t.test('start and end', t => {
31 | t.test('returns function to stop', t => {
32 | const called = {}
33 | const handler = (actual) => {
34 | called[actual] = true
35 | if (called.start && called.end) {
36 | t.end()
37 | }
38 | }
39 |
40 | process.on('input', handler)
41 | t.teardown(() => process.off('input', handler))
42 |
43 | input.start()()
44 | })
45 |
46 | t.test('sync callback', t => {
47 | const res = input.start((...args) => {
48 | t.strictSame(args, [], 'get no args')
49 | return 1
50 | })
51 | t.equal(res, 1)
52 | t.end()
53 | })
54 |
55 | t.test('async callback', async t => {
56 | const res = await input.start((...args) => {
57 | t.strictSame(args, [], 'get no args')
58 | return Promise.resolve(1)
59 | })
60 | t.equal(res, 1)
61 | })
62 |
63 | t.test('async callback that errors', async t => {
64 | const called = {}
65 | const handler = (level) => called[level] = true
66 |
67 | process.on('input', handler)
68 | t.teardown(() => process.off('input', handler))
69 |
70 | await t.rejects(input.start(() => {
71 | return Promise.reject(new Error('not ok'))
72 | }), { message: 'not ok' })
73 |
74 | t.ok(called.start)
75 | t.ok(called.end)
76 | })
77 |
78 | t.end()
79 | })
80 |
--------------------------------------------------------------------------------
/test/meta.js:
--------------------------------------------------------------------------------
1 | const t = require('tap')
2 | const { META, output } = require('../')
3 |
4 | // just to show how this would be implemented in consumers
5 | const getMeta = (...args) => {
6 | let meta = {}
7 | const lastArg = args[args.length - 1]
8 | if (
9 | lastArg &&
10 | typeof lastArg === 'object' &&
11 | Object.prototype.hasOwnProperty.call(lastArg, META)
12 | ) {
13 | meta = args.pop()
14 | }
15 | return [meta, ...args]
16 | }
17 |
18 | // an example of wrapping a handler
19 | const wrapMeta = (handler) => (level, ...args) => handler(level, ...getMeta(...args))
20 |
21 | t.test('meta', t => {
22 | process.once('output', (level, ...rawArgs) => {
23 | const [meta, ...args] = getMeta(...rawArgs)
24 | t.equal(level, 'standard')
25 | t.ok(meta.force)
26 | t.strictSame(args, ['arg1', 'arg2'])
27 | t.end()
28 | })
29 |
30 | output.standard('arg1', 'arg2', { [META]: 0, force: true })
31 | })
32 |
33 | t.test('wrap handler', t => {
34 | process.once('output', wrapMeta((level, meta, ...args) => {
35 | t.equal(level, 'standard')
36 | t.ok(meta.force)
37 | t.strictSame(args, ['arg1', { META: true }])
38 | t.end()
39 | }))
40 |
41 | output.standard('arg1', { META: true }, { [META]: null, force: true })
42 | })
43 |
--------------------------------------------------------------------------------
/test/time.js:
--------------------------------------------------------------------------------
1 | const t = require('tap')
2 | const { time } = require('../')
3 |
4 | t.test('time returns function to stop timer', t => {
5 | const called = {}
6 | const handler = (actual, name) => {
7 | t.equal(name, 'timerName')
8 | called[actual] = true
9 | if (called.start && called.end) {
10 | t.end()
11 | }
12 | }
13 |
14 | process.on('time', handler)
15 | t.teardown(() => process.off('time', handler))
16 |
17 | time.start('timerName')()
18 | })
19 |
20 | t.test('time can run a sync callback', t => {
21 | const res = time.start('timerName', (...args) => {
22 | t.strictSame(args, [], 'get no args')
23 | return 1
24 | })
25 | t.equal(res, 1)
26 | t.end()
27 | })
28 |
29 | t.test('time can run an async callback', async t => {
30 | const res = await time.start('timerName', (...args) => {
31 | t.strictSame(args, [], 'get no args')
32 | return Promise.resolve(1)
33 | })
34 | t.equal(res, 1)
35 | })
36 |
37 | t.test('time can run an async callback that errors', async t => {
38 | const called = {}
39 | const handler = (level) => called[level] = true
40 |
41 | process.on('time', handler)
42 | t.teardown(() => process.off('time', handler))
43 |
44 | await t.rejects(time.start('timerName', () => {
45 | return Promise.reject(new Error('not ok'))
46 | }), { message: 'not ok' })
47 |
48 | t.ok(called.start)
49 | t.ok(called.end)
50 | })
51 |
--------------------------------------------------------------------------------