├── .commitlintrc.cjs
├── .eslintrc.cjs
├── .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
├── package.json
├── release-please-config.json
├── src
└── read.ts
├── test
├── basic.ts
├── fixtures
│ └── setup.ts
└── many.ts
└── tsconfig.json
/.commitlintrc.cjs:
--------------------------------------------------------------------------------
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.cjs:
--------------------------------------------------------------------------------
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 | 'dist/',
16 | ],
17 | parser: '@typescript-eslint/parser',
18 | settings: {
19 | 'import/resolver': {
20 | typescript: {},
21 | },
22 | },
23 | extends: [
24 | '@npmcli',
25 | ...localConfigs,
26 | ],
27 | }
28 |
--------------------------------------------------------------------------------
/.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 | jobs:
12 | audit:
13 | name: Audit Dependencies
14 | if: github.repository_owner == 'npm'
15 | runs-on: ubuntu-latest
16 | defaults:
17 | run:
18 | shell: bash
19 | steps:
20 | - name: Checkout
21 | uses: actions/checkout@v4
22 | - name: Setup Git User
23 | run: |
24 | git config --global user.email "npm-cli+bot@github.com"
25 | git config --global user.name "npm CLI robot"
26 | - name: Setup Node
27 | uses: actions/setup-node@v4
28 | id: node
29 | with:
30 | node-version: 22.x
31 | check-latest: contains('22.x', '.x')
32 | - name: Install Latest npm
33 | uses: ./.github/actions/install-latest-npm
34 | with:
35 | node: ${{ steps.node.outputs.node-version }}
36 | - name: Install Dependencies
37 | run: npm i --ignore-scripts --no-audit --no-fund --package-lock
38 | - name: Run Production Audit
39 | run: npm audit --omit=dev
40 | - name: Run Full Audit
41 | run: npm audit --audit-level=none
42 |
--------------------------------------------------------------------------------
/.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 | jobs:
22 | lint-all:
23 | name: Lint All
24 | if: github.repository_owner == 'npm'
25 | runs-on: ubuntu-latest
26 | defaults:
27 | run:
28 | shell: bash
29 | steps:
30 | - name: Checkout
31 | uses: actions/checkout@v4
32 | with:
33 | ref: ${{ inputs.ref }}
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: Create Check
39 | id: create-check
40 | if: ${{ inputs.check-sha }}
41 | uses: ./.github/actions/create-check
42 | with:
43 | name: "Lint All"
44 | token: ${{ secrets.GITHUB_TOKEN }}
45 | sha: ${{ inputs.check-sha }}
46 | - name: Setup Node
47 | uses: actions/setup-node@v4
48 | id: node
49 | with:
50 | node-version: 22.x
51 | check-latest: contains('22.x', '.x')
52 | - name: Install Latest npm
53 | uses: ./.github/actions/install-latest-npm
54 | with:
55 | node: ${{ steps.node.outputs.node-version }}
56 | - name: Install Dependencies
57 | run: npm i --ignore-scripts --no-audit --no-fund
58 | - name: Lint
59 | run: npm run lint --ignore-scripts
60 | - name: Post Lint
61 | run: npm run postlint --ignore-scripts
62 | - name: Conclude Check
63 | uses: LouisBrunner/checks-action@v1.6.0
64 | if: steps.create-check.outputs.check-id && always()
65 | with:
66 | token: ${{ secrets.GITHUB_TOKEN }}
67 | conclusion: ${{ job.status }}
68 | check_id: ${{ steps.create-check.outputs.check-id }}
69 |
70 | test-all:
71 | name: Test All - ${{ matrix.platform.name }} - ${{ matrix.node-version }}
72 | if: github.repository_owner == 'npm'
73 | strategy:
74 | fail-fast: false
75 | matrix:
76 | platform:
77 | - name: Linux
78 | os: ubuntu-latest
79 | shell: bash
80 | - name: macOS
81 | os: macos-latest
82 | shell: bash
83 | - name: macOS
84 | os: macos-13
85 | shell: bash
86 | - name: Windows
87 | os: windows-latest
88 | shell: cmd
89 | node-version:
90 | - 18.17.0
91 | - 18.x
92 | - 20.5.0
93 | - 20.x
94 | - 22.x
95 | exclude:
96 | - platform: { name: macOS, os: macos-13, shell: bash }
97 | node-version: 18.17.0
98 | - platform: { name: macOS, os: macos-13, shell: bash }
99 | node-version: 18.x
100 | - platform: { name: macOS, os: macos-13, shell: bash }
101 | node-version: 20.5.0
102 | - platform: { name: macOS, os: macos-13, shell: bash }
103 | node-version: 20.x
104 | - platform: { name: macOS, os: macos-13, shell: bash }
105 | node-version: 22.x
106 | runs-on: ${{ matrix.platform.os }}
107 | defaults:
108 | run:
109 | shell: ${{ matrix.platform.shell }}
110 | steps:
111 | - name: Checkout
112 | uses: actions/checkout@v4
113 | with:
114 | ref: ${{ inputs.ref }}
115 | - name: Setup Git User
116 | run: |
117 | git config --global user.email "npm-cli+bot@github.com"
118 | git config --global user.name "npm CLI robot"
119 | - name: Create Check
120 | id: create-check
121 | if: ${{ inputs.check-sha }}
122 | uses: ./.github/actions/create-check
123 | with:
124 | name: "Test All - ${{ matrix.platform.name }} - ${{ matrix.node-version }}"
125 | token: ${{ secrets.GITHUB_TOKEN }}
126 | sha: ${{ inputs.check-sha }}
127 | - name: Setup Node
128 | uses: actions/setup-node@v4
129 | id: node
130 | with:
131 | node-version: ${{ matrix.node-version }}
132 | check-latest: contains(matrix.node-version, '.x')
133 | - name: Install Latest npm
134 | uses: ./.github/actions/install-latest-npm
135 | with:
136 | node: ${{ steps.node.outputs.node-version }}
137 | - name: Install Dependencies
138 | run: npm i --ignore-scripts --no-audit --no-fund
139 | - name: Add Problem Matcher
140 | run: echo "::add-matcher::.github/matchers/tap.json"
141 | - name: Test
142 | run: npm test --ignore-scripts
143 | - name: Conclude Check
144 | uses: LouisBrunner/checks-action@v1.6.0
145 | if: steps.create-check.outputs.check-id && always()
146 | with:
147 | token: ${{ secrets.GITHUB_TOKEN }}
148 | conclusion: ${{ job.status }}
149 | check_id: ${{ steps.create-check.outputs.check-id }}
150 |
--------------------------------------------------------------------------------
/.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 | jobs:
16 | lint:
17 | name: Lint
18 | if: github.repository_owner == 'npm'
19 | runs-on: ubuntu-latest
20 | defaults:
21 | run:
22 | shell: bash
23 | steps:
24 | - name: Checkout
25 | uses: actions/checkout@v4
26 | - name: Setup Git User
27 | run: |
28 | git config --global user.email "npm-cli+bot@github.com"
29 | git config --global user.name "npm CLI robot"
30 | - name: Setup Node
31 | uses: actions/setup-node@v4
32 | id: node
33 | with:
34 | node-version: 22.x
35 | check-latest: contains('22.x', '.x')
36 | - name: Install Latest npm
37 | uses: ./.github/actions/install-latest-npm
38 | with:
39 | node: ${{ steps.node.outputs.node-version }}
40 | - name: Install Dependencies
41 | run: npm i --ignore-scripts --no-audit --no-fund
42 | - name: Lint
43 | run: npm run lint --ignore-scripts
44 | - name: Post Lint
45 | run: npm run postlint --ignore-scripts
46 |
47 | test:
48 | name: Test - ${{ matrix.platform.name }} - ${{ matrix.node-version }}
49 | if: github.repository_owner == 'npm'
50 | strategy:
51 | fail-fast: false
52 | matrix:
53 | platform:
54 | - name: Linux
55 | os: ubuntu-latest
56 | shell: bash
57 | - name: macOS
58 | os: macos-latest
59 | shell: bash
60 | - name: macOS
61 | os: macos-13
62 | shell: bash
63 | - name: Windows
64 | os: windows-latest
65 | shell: cmd
66 | node-version:
67 | - 18.17.0
68 | - 18.x
69 | - 20.5.0
70 | - 20.x
71 | - 22.x
72 | exclude:
73 | - platform: { name: macOS, os: macos-13, shell: bash }
74 | node-version: 18.17.0
75 | - platform: { name: macOS, os: macos-13, shell: bash }
76 | node-version: 18.x
77 | - platform: { name: macOS, os: macos-13, shell: bash }
78 | node-version: 20.5.0
79 | - platform: { name: macOS, os: macos-13, shell: bash }
80 | node-version: 20.x
81 | - platform: { name: macOS, os: macos-13, shell: bash }
82 | node-version: 22.x
83 | runs-on: ${{ matrix.platform.os }}
84 | defaults:
85 | run:
86 | shell: ${{ matrix.platform.shell }}
87 | steps:
88 | - name: Checkout
89 | uses: actions/checkout@v4
90 | - name: Setup Git User
91 | run: |
92 | git config --global user.email "npm-cli+bot@github.com"
93 | git config --global user.name "npm CLI robot"
94 | - name: Setup Node
95 | uses: actions/setup-node@v4
96 | id: node
97 | with:
98 | node-version: ${{ matrix.node-version }}
99 | check-latest: contains(matrix.node-version, '.x')
100 | - name: Install Latest npm
101 | uses: ./.github/actions/install-latest-npm
102 | with:
103 | node: ${{ steps.node.outputs.node-version }}
104 | - name: Install Dependencies
105 | run: npm i --ignore-scripts --no-audit --no-fund
106 | - name: Add Problem Matcher
107 | run: echo "::add-matcher::.github/matchers/tap.json"
108 | - name: Test
109 | run: npm test --ignore-scripts
110 |
--------------------------------------------------------------------------------
/.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 | jobs:
17 | analyze:
18 | name: Analyze
19 | runs-on: ubuntu-latest
20 | permissions:
21 | actions: read
22 | contents: read
23 | security-events: write
24 | steps:
25 | - name: Checkout
26 | uses: actions/checkout@v4
27 | - name: Setup Git User
28 | run: |
29 | git config --global user.email "npm-cli+bot@github.com"
30 | git config --global user.name "npm CLI robot"
31 | - name: Initialize CodeQL
32 | uses: github/codeql-action/init@v3
33 | with:
34 | languages: javascript
35 | - name: Perform CodeQL Analysis
36 | uses: github/codeql-action/analyze@v3
37 |
--------------------------------------------------------------------------------
/.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 | jobs:
14 | commitlint:
15 | name: Lint Commits
16 | if: github.repository_owner == 'npm'
17 | runs-on: ubuntu-latest
18 | defaults:
19 | run:
20 | shell: bash
21 | steps:
22 | - name: Checkout
23 | uses: actions/checkout@v4
24 | with:
25 | fetch-depth: 0
26 | - name: Setup Git User
27 | run: |
28 | git config --global user.email "npm-cli+bot@github.com"
29 | git config --global user.name "npm CLI robot"
30 | - name: Setup Node
31 | uses: actions/setup-node@v4
32 | id: node
33 | with:
34 | node-version: 22.x
35 | check-latest: contains('22.x', '.x')
36 | - name: Install Latest npm
37 | uses: ./.github/actions/install-latest-npm
38 | with:
39 | node: ${{ steps.node.outputs.node-version }}
40 | - name: Install Dependencies
41 | run: npm i --ignore-scripts --no-audit --no-fund
42 | - name: Run Commitlint on Commits
43 | id: commit
44 | continue-on-error: true
45 | run: npx --offline commitlint -V --from 'origin/${{ github.base_ref }}' --to ${{ github.event.pull_request.head.sha }}
46 | - name: Run Commitlint on PR Title
47 | if: steps.commit.outcome == 'failure'
48 | env:
49 | PR_TITLE: ${{ github.event.pull_request.title }}
50 | run: echo "$PR_TITLE" | npx --offline commitlint -V
51 |
--------------------------------------------------------------------------------
/.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 | jobs:
23 | publish:
24 | name: Publish
25 | runs-on: ubuntu-latest
26 | defaults:
27 | run:
28 | shell: bash
29 | permissions:
30 | id-token: write
31 | steps:
32 | - name: Checkout
33 | uses: actions/checkout@v4
34 | with:
35 | ref: ${{ fromJSON(inputs.releases)[0].tagName }}
36 | - name: Setup Git User
37 | run: |
38 | git config --global user.email "npm-cli+bot@github.com"
39 | git config --global user.name "npm CLI robot"
40 | - name: Setup Node
41 | uses: actions/setup-node@v4
42 | id: node
43 | with:
44 | node-version: 22.x
45 | check-latest: contains('22.x', '.x')
46 | - name: Install Latest npm
47 | uses: ./.github/actions/install-latest-npm
48 | with:
49 | node: ${{ steps.node.outputs.node-version }}
50 | - name: Install Dependencies
51 | run: npm i --ignore-scripts --no-audit --no-fund
52 | - name: Set npm authToken
53 | run: npm config set '//registry.npmjs.org/:_authToken'=\${PUBLISH_TOKEN}
54 | - name: Publish
55 | env:
56 | PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
57 | RELEASES: ${{ inputs.releases }}
58 | run: |
59 | EXIT_CODE=0
60 |
61 | for release in $(echo $RELEASES | jq -r '.[] | @base64'); do
62 | PUBLISH_TAG=$(echo "$release" | base64 --decode | jq -r .publishTag)
63 | npm publish --provenance --tag="$PUBLISH_TAG"
64 | STATUS=$?
65 | if [[ "$STATUS" -eq 1 ]]; then
66 | EXIT_CODE=$STATUS
67 | fi
68 | done
69 |
70 | exit $EXIT_CODE
71 |
--------------------------------------------------------------------------------
/.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 | id-token: write
248 | secrets:
249 | PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
250 | with:
251 | releases: ${{ needs.release.outputs.releases }}
252 |
253 | post-release-integration:
254 | needs: [ release, release-integration, post-release ]
255 | name: Post Release Integration - Release
256 | if: github.repository_owner == 'npm' && needs.release.outputs.releases && always()
257 | runs-on: ubuntu-latest
258 | defaults:
259 | run:
260 | shell: bash
261 | steps:
262 | - name: Get Post Release Conclusion
263 | id: conclusion
264 | run: |
265 | if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
266 | result="x"
267 | elif [[ "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
268 | result="heavy_multiplication_x"
269 | else
270 | result="white_check_mark"
271 | fi
272 | echo "result=$result" >> $GITHUB_OUTPUT
273 | - name: Find Release PR Comment
274 | uses: peter-evans/find-comment@v2
275 | id: found-comment
276 | with:
277 | issue-number: ${{ fromJSON(needs.release.outputs.releases)[0].prNumber }}
278 | comment-author: 'github-actions[bot]'
279 | body-includes: '## Release Workflow'
280 | - name: Create Release PR Comment Text
281 | id: comment-text
282 | if: steps.found-comment.outputs.comment-id
283 | uses: actions/github-script@v7
284 | env:
285 | RESULT: ${{ steps.conclusion.outputs.result }}
286 | BODY: ${{ steps.found-comment.outputs.comment-body }}
287 | with:
288 | result-encoding: string
289 | script: |
290 | const { RESULT, BODY } = process.env
291 | const body = [BODY.replace(/(Workflow run: :)[a-z_]+(:)/, `$1${RESULT}$2`)]
292 | if (RESULT !== 'white_check_mark') {
293 | body.push(':rotating_light::rotating_light::rotating_light:')
294 | body.push([
295 | '@npm/cli-team: The post-release workflow failed for this release.',
296 | 'Manual steps may need to be taken after examining the workflow output.'
297 | ].join(' '))
298 | body.push(':rotating_light::rotating_light::rotating_light:')
299 | }
300 | return body.join('\n\n').trim()
301 | - name: Update Release PR Comment
302 | if: steps.comment-text.outputs.result
303 | uses: peter-evans/create-or-update-comment@v3
304 | with:
305 | comment-id: ${{ steps.found-comment.outputs.comment-id }}
306 | body: ${{ steps.comment-text.outputs.result }}
307 | edit-mode: 'replace'
308 |
--------------------------------------------------------------------------------
/.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.cjs
8 | !/.eslint.config.js
9 | !/.eslintrc.cjs
10 | !/.eslintrc.local.*
11 | !/.git-blame-ignore-revs
12 | !/.github/
13 | !/.gitignore
14 | !/.npmrc
15 | !/.prettierignore
16 | !/.prettierrc.cjs
17 | !/.release-please-manifest.json
18 | !/CHANGELOG*
19 | !/CODE_OF_CONDUCT.md
20 | !/CONTRIBUTING.md
21 | !/docs/
22 | !/LICENSE*
23 | !/map.js
24 | !/package.json
25 | !/README*
26 | !/release-please-config.json
27 | !/scripts/
28 | !/SECURITY.md
29 | !/src/
30 | !/tap-snapshots/
31 | !/test/
32 | !/tsconfig.json
33 | tap-testdir*/
34 |
--------------------------------------------------------------------------------
/.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 | ".": "4.1.0"
3 | }
4 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | ## [4.1.0](https://github.com/npm/read/compare/v4.0.0...v4.1.0) (2025-01-30)
4 | ### Features
5 | * [`980e75c`](https://github.com/npm/read/commit/980e75cad4aea099ff37ff445ddb1ae935bc43c8) [#127](https://github.com/npm/read/pull/127) add `history` parameter (#127) (@JupiterPi)
6 |
7 | ## [4.0.0](https://github.com/npm/read/compare/v3.0.1...v4.0.0) (2024-09-25)
8 | ### ⚠️ BREAKING CHANGES
9 | * `read` now supports node `^18.17.0 || >=20.5.0`
10 | ### Bug Fixes
11 | * [`eddeb02`](https://github.com/npm/read/commit/eddeb02b2a807a2e8112126c5c3aacccf134d9fc) [#124](https://github.com/npm/read/pull/124) align to npm 10 node engine range (@hashtagchris)
12 | ### Dependencies
13 | * [`0641d3a`](https://github.com/npm/read/commit/0641d3a4f022d0d779a8cbd8d18c4e27a4054afd) [#124](https://github.com/npm/read/pull/124) `mute-stream@2.0.0`
14 | ### Chores
15 | * [`1b07665`](https://github.com/npm/read/commit/1b076658be7170593a8796e2f0db2184c3a72831) [#109](https://github.com/npm/read/pull/109) bump c8 from 8.0.1 to 10.1.2 (#109) (@dependabot[bot])
16 | * [`cdf4cd8`](https://github.com/npm/read/commit/cdf4cd81806f06062d0c106dc336c4d32ca725c4) [#122](https://github.com/npm/read/pull/122) bump @npmcli/eslint-config from 4.0.5 to 5.0.0 (#122) (@dependabot[bot])
17 | * [`104dc92`](https://github.com/npm/read/commit/104dc924fa08142f5de1fdfd84fa8f33a0cd7556) [#116](https://github.com/npm/read/pull/116) bump tshy from 1.18.0 to 3.0.2 (#116) (@dependabot[bot])
18 | * [`8f24ce4`](https://github.com/npm/read/commit/8f24ce489125cf44bba5022bc0474a7c097bdb07) [#124](https://github.com/npm/read/pull/124) run template-oss-apply (@hashtagchris)
19 | * [`8a7ba09`](https://github.com/npm/read/commit/8a7ba0924f1850cb686de768ab83d7e65e1004e7) [#120](https://github.com/npm/read/pull/120) bump @typescript-eslint/parser from 7.18.0 to 8.0.1 (#120) (@dependabot[bot])
20 | * [`d6beca8`](https://github.com/npm/read/commit/d6beca844bcc8c662ab2856c99a6312fd727e9e7) [#103](https://github.com/npm/read/pull/103) bump @npmcli/template-oss to 4.22.0 (@lukekarrys)
21 | * [`ff55321`](https://github.com/npm/read/commit/ff55321ffe74704ac8be59e1519773f79ce039cf) [#100](https://github.com/npm/read/pull/100) bump @typescript-eslint/parser from 6.21.0 to 7.2.0 (#100) (@dependabot[bot])
22 | * [`d30350d`](https://github.com/npm/read/commit/d30350d8d7eafe7ac1b476d1232e68bb22209308) [#123](https://github.com/npm/read/pull/123) postinstall for dependabot template-oss PR (@hashtagchris)
23 | * [`8558668`](https://github.com/npm/read/commit/8558668dc1c9f02bd63360910389e04319980c1d) [#123](https://github.com/npm/read/pull/123) bump @npmcli/template-oss from 4.23.1 to 4.23.3 (@dependabot[bot])
24 |
25 | ## [3.0.1](https://github.com/npm/read/compare/v3.0.0...v3.0.1) (2023-11-20)
26 |
27 | ### Bug Fixes
28 |
29 | * [`22cb8dc`](https://github.com/npm/read/commit/22cb8dc5c7b567cd2d890ca2d71fed1faaf52d29) [#84](https://github.com/npm/read/pull/84) only ship dist files (@lukekarrys)
30 |
31 | ## [3.0.0](https://github.com/npm/read/compare/v2.1.0...v3.0.0) (2023-11-16)
32 |
33 | ### ⚠️ BREAKING CHANGES
34 |
35 | * `read` is now written in TypeScript and types are now shipped as part of this package.
36 |
37 | ### Features
38 |
39 | * [`18cb7bd`](https://github.com/npm/read/commit/18cb7bd9f364a5cafabd9cb52942f048da7178af) [#77](https://github.com/npm/read/pull/77) convert to typescript and esm (#77) (@lukekarrys)
40 |
41 | ### Documentation
42 |
43 | * [`ada826d`](https://github.com/npm/read/commit/ada826d2ded4e35a1e60d9f50dc31fda083d2a5d) [#59](https://github.com/npm/read/pull/59) remove unnecessary callback param (#59) (@igrep)
44 |
45 | ## [2.1.0](https://github.com/npm/read/compare/v2.0.0...v2.1.0) (2023-04-13)
46 |
47 | ### Features
48 |
49 | * [`c149cf9`](https://github.com/npm/read/commit/c149cf998223e2ae45c013768038717bc4a1c543) [#51](https://github.com/npm/read/pull/51) add completer option to forward to readline (#51) (@wraithgar, @131)
50 |
51 | ### Bug Fixes
52 |
53 | * [`c5932e8`](https://github.com/npm/read/commit/c5932e8d223990dd65a46226f560768c430d1888) [#35](https://github.com/npm/read/pull/35) Support rare \r line break (#35) (@NikxDa, @wraithgar, @wraithgar)
54 | * [`f30fe66`](https://github.com/npm/read/commit/f30fe6640287cbd5a341b7a9f65a60e40558e389) [#52](https://github.com/npm/read/pull/52) extra newline on muted, replaced input (#52) (@wraithgar, @deed02392)
55 |
56 | ## [2.0.0](https://github.com/npm/read/compare/v1.0.7...v2.0.0) (2022-12-13)
57 |
58 | ### ⚠️ BREAKING CHANGES
59 |
60 | * this module has been refactored to use promises
61 | - the API is now promise only and no longer accepts a callback
62 | - the Promise is resolved to a string and no longer returns `isDefault`
63 | * this package is now compatible with the following semver range for node: `^14.17.0 || ^16.13.0 || >=18.0.0`
64 |
65 | ### Features
66 |
67 | * [`c5b56f6`](https://github.com/npm/read/commit/c5b56f6242493173ded23a97f4fd2ffb4017310f) use async/await (@lukekarrys)
68 | * [`5a7563b`](https://github.com/npm/read/commit/5a7563bf20ae1392ee0d0b29a4d0ac5c23df9a33) add template-oss (@lukekarrys)
69 |
70 | ### Documentation
71 |
72 | * [`711d7cd`](https://github.com/npm/read/commit/711d7cd6a3d58472b88c7db1ab2129f37304d72c) [#30](https://github.com/npm/read/pull/30) Fix typo "Writeable" => "Writable" in README.MD (#30) (@vitalymak, @vitalymak)
73 |
74 | ### Dependencies
75 |
76 | * [`6102578`](https://github.com/npm/read/commit/6102578bd1c9d192a1d6601564faa066af13b35d) [#42](https://github.com/npm/read/pull/42) bump mute-stream from 0.0.8 to 1.0.0 (#42)
77 |
--------------------------------------------------------------------------------
/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) Isaac Z. Schlueter and Contributors
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 | ## read
2 |
3 | For reading user input from stdin.
4 |
5 | Similar to the `readline` builtin's `question()` method, but with a
6 | few more features.
7 |
8 | ## Usage
9 |
10 | ```javascript
11 | const { read } = require('read')
12 | // or with ESM: import { read } from 'read'
13 | try {
14 | const result = await read(options)
15 | } catch (er) {
16 | console.error(er)
17 | }
18 | ```
19 |
20 | ## Options
21 |
22 | Every option is optional.
23 |
24 | * `prompt` What to write to stdout before reading input.
25 | * `silent` Don't echo the output as the user types it.
26 | * `replace` Replace silenced characters with the supplied character value.
27 | * `timeout` Number of ms to wait for user input before giving up.
28 | * `default` The default value if the user enters nothing.
29 | * `edit` Allow the user to edit the default value.
30 | * `terminal` Treat the output as a TTY, whether it is or not.
31 | * `input` Readable stream to get input data from. (default `process.stdin`)
32 | * `output` Writable stream to write prompts to. (default: `process.stdout`)
33 | * `completer` Autocomplete callback (see [official api](https://nodejs.org/api/readline.html#readline_readline_createinterface_options) for details
34 | * `history` History array, which will be appended to.
35 |
36 | If silent is true, and the input is a TTY, then read will set raw
37 | mode, and read character by character.
38 |
39 | ## Contributing
40 |
41 | Patches welcome.
42 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "read",
3 | "version": "4.1.0",
4 | "exports": {
5 | "./package.json": "./package.json",
6 | ".": {
7 | "import": {
8 | "types": "./dist/esm/read.d.ts",
9 | "default": "./dist/esm/read.js"
10 | },
11 | "require": {
12 | "types": "./dist/commonjs/read.d.ts",
13 | "default": "./dist/commonjs/read.js"
14 | }
15 | }
16 | },
17 | "type": "module",
18 | "tshy": {
19 | "exports": {
20 | "./package.json": "./package.json",
21 | ".": "./src/read.ts"
22 | }
23 | },
24 | "dependencies": {
25 | "mute-stream": "^2.0.0"
26 | },
27 | "devDependencies": {
28 | "@npmcli/eslint-config": "^5.0.0",
29 | "@npmcli/template-oss": "4.24.3",
30 | "@types/mute-stream": "^0.0.4",
31 | "@types/tap": "^15.0.11",
32 | "@typescript-eslint/parser": "^8.0.1",
33 | "c8": "^10.1.2",
34 | "eslint-import-resolver-typescript": "^4.3.2",
35 | "tap": "^16.3.9",
36 | "ts-node": "^10.9.1",
37 | "tshy": "^3.0.2",
38 | "typescript": "^5.2.2"
39 | },
40 | "engines": {
41 | "node": "^18.17.0 || >=20.5.0"
42 | },
43 | "author": "GitHub Inc.",
44 | "description": "read(1) for node programs",
45 | "repository": {
46 | "type": "git",
47 | "url": "git+https://github.com/npm/read.git"
48 | },
49 | "license": "ISC",
50 | "scripts": {
51 | "prepare": "tshy",
52 | "pretest": "npm run prepare",
53 | "presnap": "npm run prepare",
54 | "test": "c8 tap",
55 | "lint": "npm run eslint",
56 | "postlint": "template-oss-check",
57 | "template-oss-apply": "template-oss-apply --force",
58 | "lintfix": "npm run eslint -- --fix",
59 | "snap": "c8 tap",
60 | "posttest": "npm run lint",
61 | "eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
62 | },
63 | "templateOSS": {
64 | "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
65 | "version": "4.24.3",
66 | "publish": true,
67 | "typescript": true
68 | },
69 | "main": "./dist/commonjs/read.js",
70 | "types": "./dist/commonjs/read.d.ts",
71 | "tap": {
72 | "coverage": false,
73 | "node-arg": [
74 | "--no-warnings",
75 | "--loader",
76 | "ts-node/esm"
77 | ],
78 | "ts": false,
79 | "nyc-arg": [
80 | "--exclude",
81 | "tap-snapshots/**"
82 | ]
83 | },
84 | "files": [
85 | "dist/"
86 | ]
87 | }
88 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/src/read.ts:
--------------------------------------------------------------------------------
1 | import Mute from 'mute-stream'
2 | import { Completer, AsyncCompleter, createInterface, ReadLineOptions } from 'readline'
3 |
4 | export interface Options {
5 | default?: T
6 | input?: ReadLineOptions['input'] & {
7 | isTTY?: boolean
8 | }
9 | output?: ReadLineOptions['output'] & {
10 | isTTY?: boolean
11 | }
12 | prompt?: string
13 | silent?: boolean
14 | timeout?: number
15 | edit?: boolean
16 | terminal?: boolean
17 | replace?: string,
18 | completer?: Completer | AsyncCompleter,
19 | history?: string[],
20 | }
21 |
22 | export async function read ({
23 | default: def,
24 | input = process.stdin,
25 | output = process.stdout,
26 | completer,
27 | prompt = '',
28 | silent,
29 | timeout,
30 | edit,
31 | terminal,
32 | replace,
33 | history,
34 | }: Options): Promise {
35 | if (
36 | typeof def !== 'undefined' &&
37 | typeof def !== 'string' &&
38 | typeof def !== 'number'
39 | ) {
40 | throw new Error('default value must be string or number')
41 | }
42 |
43 | let editDef = false
44 | const defString = def?.toString()
45 | prompt = prompt.trim() + ' '
46 | terminal = !!(terminal || output.isTTY)
47 |
48 | if (defString) {
49 | if (silent) {
50 | prompt += '() '
51 | // TODO: add tests for edit
52 | /* c8 ignore start */
53 | } else if (edit) {
54 | editDef = true
55 | /* c8 ignore stop */
56 | } else {
57 | prompt += '(' + defString + ') '
58 | }
59 | }
60 |
61 | const m = new Mute({ replace, prompt })
62 | m.pipe(output, { end: false })
63 | output = m
64 |
65 | return new Promise((resolve, reject) => {
66 | const rl = createInterface({ input, output, terminal, completer, history })
67 | // TODO: add tests for timeout
68 | /* c8 ignore start */
69 | const timer = timeout && setTimeout(() => onError(new Error('timed out')), timeout)
70 | /* c8 ignore stop */
71 |
72 | m.unmute()
73 | rl.setPrompt(prompt)
74 | rl.prompt()
75 |
76 | if (silent) {
77 | m.mute()
78 | // TODO: add tests for edit + default
79 | /* c8 ignore start */
80 | } else if (editDef && defString) {
81 | const rlEdit = rl as typeof rl & {
82 | line: string,
83 | cursor: number,
84 | _refreshLine: () => void,
85 | }
86 | rlEdit.line = defString
87 | rlEdit.cursor = defString.length
88 | rlEdit._refreshLine()
89 | }
90 | /* c8 ignore stop */
91 |
92 | const done = () => {
93 | rl.close()
94 | clearTimeout(timer)
95 | m.mute()
96 | m.end()
97 | }
98 |
99 | // TODO: add tests for rejecting
100 | /* c8 ignore start */
101 | const onError = (er: Error) => {
102 | done()
103 | reject(er)
104 | }
105 | /* c8 ignore stop */
106 |
107 | rl.on('error', onError)
108 | rl.on('line', line => {
109 | // TODO: add tests for silent
110 | /* c8 ignore start */
111 | if (silent && terminal) {
112 | m.unmute()
113 | }
114 | /* c8 ignore stop */
115 | done()
116 | // TODO: add tests for default
117 | /* c8 ignore start */
118 | // truncate the \n at the end.
119 | return resolve(line.replace(/\r?\n?$/, '') || defString || '')
120 | /* c8 ignore stop */
121 | })
122 |
123 | // TODO: add tests for sigint
124 | /* c8 ignore start */
125 | rl.on('SIGINT', () => {
126 | rl.close()
127 | onError(new Error('canceled'))
128 | })
129 | /* c8 ignore stop */
130 | })
131 | }
132 |
--------------------------------------------------------------------------------
/test/basic.ts:
--------------------------------------------------------------------------------
1 | import t from 'tap'
2 | import { read } from '../src/read.js'
3 | import spawnRead from './fixtures/setup.js'
4 |
5 | async function child () {
6 | const user = await read({ prompt: 'Username: ', default: 'test-user' })
7 | const pass = await read({
8 | prompt: 'Password: ',
9 | default: 'test-pass',
10 | silent: true,
11 | })
12 | const verify = await read({
13 | prompt: 'Password again: ',
14 | default: 'test-pass',
15 | silent: true,
16 | })
17 |
18 | console.error(
19 | JSON.stringify({
20 | user,
21 | pass,
22 | verify,
23 | passMatch: pass === verify,
24 | })
25 | )
26 |
27 | if (process.stdin.unref) {
28 | process.stdin.unref()
29 | }
30 | }
31 |
32 | const main = () => {
33 | t.test('basic', async t => {
34 | const { stdout, stderr } = await spawnRead(import.meta.url, {
35 | 'Username: (test-user)': 'a user',
36 | 'Password: ()': 'a password',
37 | 'Password again: ()': 'a password',
38 | })
39 |
40 | t.same(JSON.parse(stderr), {
41 | user: 'a user',
42 | pass: 'a password',
43 | verify: 'a password',
44 | passMatch: true,
45 | })
46 | t.equal(
47 | stdout,
48 | 'Username: (test-user) Password: () Password again: () '
49 | )
50 | })
51 |
52 | t.test('defaults', async t => {
53 | const { stdout, stderr } = await spawnRead(import.meta.url, {
54 | 'Username: (test-user)': '',
55 | 'Password: ()': '',
56 | 'Password again: ()': '',
57 | })
58 |
59 | t.same(JSON.parse(stderr), {
60 | user: 'test-user',
61 | pass: 'test-pass',
62 | verify: 'test-pass',
63 | passMatch: true,
64 | })
65 | t.equal(
66 | stdout,
67 | 'Username: (test-user) Password: () Password again: () '
68 | )
69 | })
70 |
71 | t.test('errors', async t => {
72 | // @ts-expect-error
73 | t.rejects(() => read({ default: {} }))
74 | })
75 | }
76 |
77 | if (process.argv[2] === 'child') {
78 | child()
79 | } else {
80 | main()
81 | }
82 |
--------------------------------------------------------------------------------
/test/fixtures/setup.ts:
--------------------------------------------------------------------------------
1 | import { spawn } from 'child_process'
2 | import { fileURLToPath } from 'url'
3 |
4 | const esc = (str: string) => str.replace(/([()])/g, '\\$1')
5 |
6 | const spawnRead = async (
7 | url: string,
8 | writes: { [k: string]: string }
9 | ): Promise<{ stdout: string; stderr: string }> => {
10 | const filename = fileURLToPath(url)
11 |
12 | const proc = spawn(process.execPath, [
13 | ...process.execArgv,
14 | filename,
15 | 'child',
16 | ])
17 |
18 | return new Promise((resolve, reject) => {
19 | let stdout = ''
20 | let stderr = ''
21 |
22 | proc.stdout.on('data', c => {
23 | stdout += c
24 | for (const [prompt, write] of Object.entries(writes)) {
25 | if (stdout.match(new RegExp(`${esc(prompt)} $`))) {
26 | return process.nextTick(() => proc.stdin.write(`${write}\n`))
27 | }
28 | }
29 | reject(
30 | new Error(`unknown prompt:\n${stdout}\n${JSON.stringify(writes)}`)
31 | )
32 | })
33 |
34 | proc.stderr.on('data', c => {
35 | stderr += c
36 | })
37 |
38 | proc.on('close', () =>
39 | resolve({
40 | stdout,
41 | stderr,
42 | })
43 | )
44 | })
45 | }
46 |
47 | export default spawnRead
48 |
--------------------------------------------------------------------------------
/test/many.ts:
--------------------------------------------------------------------------------
1 | import t from 'tap'
2 | import spawnRead from './fixtures/setup.js'
3 | import { read } from '../src/read.js'
4 |
5 | const times = new Array(18).fill(null).map((_, i) => (i + 1).toString())
6 |
7 | async function child () {
8 | const res: string[] = []
9 | for (const t of times) {
10 | const r = await read({ prompt: `num ${t}` })
11 | res.push(r)
12 | }
13 |
14 | console.error(...res)
15 |
16 | if (process.stdin.unref) {
17 | process.stdin.unref()
18 | }
19 | }
20 |
21 | const main = () => {
22 | t.test('many reads', async t => {
23 | const writes = times.reduce((acc: { [k: string]: string }, k) => {
24 | acc[`num ${k}`] = k
25 | return acc
26 | }, {})
27 | const { stdout, stderr } = await spawnRead(import.meta.url, writes)
28 |
29 | t.equal(stdout, Object.keys(writes).join(' ') + ' ')
30 | t.equal(stderr, times.join(' ') + '\n')
31 | })
32 | }
33 |
34 | if (process.argv[2] === 'child') {
35 | child()
36 | } else {
37 | main()
38 | }
39 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "jsx": "react",
4 | "declaration": true,
5 | "declarationMap": true,
6 | "inlineSources": true,
7 | "esModuleInterop": true,
8 | "forceConsistentCasingInFileNames": true,
9 | "moduleResolution": "nodenext",
10 | "resolveJsonModule": true,
11 | "skipLibCheck": true,
12 | "sourceMap": true,
13 | "strict": true,
14 | "target": "es2022",
15 | "module": "nodenext"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------