Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
uses: actions/setup-node@v6
id: node
with:
node-version: 22.x
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ jobs:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
uses: actions/setup-node@v6
id: node
with:
node-version: 22.x
Expand Down Expand Up @@ -68,13 +68,13 @@ jobs:
shell: ${{ matrix.platform.shell }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
uses: actions/setup-node@v6
id: node
with:
node-version: ${{ matrix.node-version }}
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ jobs:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
uses: actions/setup-node@v6
id: node
with:
node-version: 22.x
Expand Down Expand Up @@ -68,13 +68,13 @@ jobs:
shell: ${{ matrix.platform.shell }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
uses: actions/setup-node@v6
id: node
with:
node-version: ${{ matrix.node-version }}
Expand Down Expand Up @@ -105,13 +105,13 @@ jobs:
shell: ${{ matrix.platform.shell }}
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
uses: actions/setup-node@v6
id: node
with:
node-version: ${{ matrix.node-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
security-events: write
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/post-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ jobs:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
uses: actions/setup-node@v6
id: node
with:
node-version: 22.x
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ jobs:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
uses: actions/setup-node@v6
id: node
with:
node-version: 22.x
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
uses: actions/setup-node@v6
id: node
with:
node-version: 22.x
Expand Down
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.30.0",
"version": "5.0.0",
"content": "./scripts/template-oss"
},
"files": [
Expand Down
69 changes: 69 additions & 0 deletions cli/test/_helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const fs = require('node:fs')
const os = require('node:os')
const path = require('node:path')

const writeTree = (dir, spec) => {
fs.mkdirSync(dir, {recursive: true})
for (const [name, value] of Object.entries(spec)) {
const p = path.join(dir, name)
if (value === null || value === undefined) {
continue
}
if (typeof value === 'string' || Buffer.isBuffer(value)) {
fs.writeFileSync(p, value)
} else if (typeof value === 'object') {
writeTree(p, value)
} else {
throw new TypeError(`testdir: unsupported value at ${p}: ${typeof value}`)
}
}
}

const testdir = (t, spec = {}) => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'cli-test-'))
writeTree(dir, spec)
t.after(() => fs.rmSync(dir, {recursive: true, force: true}))
return dir
}

const mockRequire = (t, requestPath, mocks = {}) => {
const sutPath = require.resolve(requestPath, {paths: [__dirname]})
const sutDir = path.dirname(sutPath)

const overridden = []
for (const [spec, value] of Object.entries(mocks)) {
const resolved = require.resolve(spec, {paths: [sutDir]})
overridden.push([resolved, require.cache[resolved]])
require.cache[resolved] = {
id: resolved,
filename: resolved,
loaded: true,
exports: value,
children: [],
paths: [],
parent: null,
}
}

const previousSut = require.cache[sutPath]
delete require.cache[sutPath]
const exported = require(sutPath)

t.after(() => {
delete require.cache[sutPath]
if (previousSut) {
require.cache[sutPath] = previousSut
}
for (const [resolved, prev] of overridden) {
if (prev) {
require.cache[resolved] = prev
} else {
delete require.cache[resolved]
}
}
})

return exported
}

module.exports = {testdir, mockRequire}
Loading
Loading