Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: npm/make-fetch-happen
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v10.1.2
Choose a base ref
...
head repository: npm/make-fetch-happen
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v10.1.3
Choose a head ref
  • 6 commits
  • 10 files changed
  • 5 contributors

Commits on Apr 20, 2022

  1. chore: bump @npmcli/template-oss from 3.2.2 to 3.4.1 (#142)

    * chore: bump @npmcli/template-oss from 3.2.2 to 3.4.1
    
    Bumps [@npmcli/template-oss](https://github.com/npm/template-oss) from 3.2.2 to 3.4.1.
    - [Release notes](https://github.com/npm/template-oss/releases)
    - [Changelog](https://github.com/npm/template-oss/blob/main/CHANGELOG.md)
    - [Commits](npm/template-oss@v3.2.2...v3.4.1)
    
    ---
    updated-dependencies:
    - dependency-name: "@npmcli/template-oss"
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    * chore: postinstall for dependabot template-oss PR
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Luke Karrys <luke@lukekarrys.com>
    dependabot[bot] and lukekarrys authored Apr 20, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    177329d View commit details

Commits on Apr 30, 2022

  1. chore: bump @npmcli/template-oss from 3.4.1 to 3.4.2

    Bumps [@npmcli/template-oss](https://github.com/npm/template-oss) from 3.4.1 to 3.4.2.
    - [Release notes](https://github.com/npm/template-oss/releases)
    - [Changelog](https://github.com/npm/template-oss/blob/main/CHANGELOG.md)
    - [Commits](npm/template-oss@v3.4.1...v3.4.2)
    
    ---
    updated-dependencies:
    - dependency-name: "@npmcli/template-oss"
      dependency-type: direct:development
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored and lukekarrys committed Apr 30, 2022
    Copy the full SHA
    2701188 View commit details
  2. Copy the full SHA
    ac55965 View commit details

Commits on May 9, 2022

  1. fix: make defaults chaining actually work (#144)

    The README says:
    
    > A defaulted `fetch` will also have a `.defaults()` method, so they can
    > be chained.
    
    But this didn't really work, because while the `defaults` method was
    placed on the `defaulted` fetch, a chained defaulted fetch would just
    call the original fetch function directly instead of the intermediate
    function.
    
    This PR makes chaining actually work and adds a test.
    
    Also, it fixes the previous test, which wasn't actually verifying that
    the correct request headers were received because it used the nock API
    incorrectly: the option is `reqheaders` not `reqHeaders`.
    glasser authored May 9, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    aa71e81 View commit details
  2. chore: bump @npmcli/template-oss from 3.4.2 to 3.4.3 (#145)

    * chore: bump @npmcli/template-oss from 3.4.2 to 3.4.3
    
    Bumps [@npmcli/template-oss](https://github.com/npm/template-oss) from 3.4.2 to 3.4.3.
    - [Release notes](https://github.com/npm/template-oss/releases)
    - [Changelog](https://github.com/npm/template-oss/blob/main/CHANGELOG.md)
    - [Commits](npm/template-oss@v3.4.2...v3.4.3)
    
    ---
    updated-dependencies:
    - dependency-name: "@npmcli/template-oss"
      dependency-type: direct:development
      update-type: version-update:semver-patch
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    * chore: postinstall for dependabot template-oss PR
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: npm team <ops+robot@npmjs.com>
    dependabot[bot] and npm-robot authored May 9, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6d35ffe View commit details
  3. chore(main): release 10.1.3 (#146)

    Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
    github-actions[bot] authored May 9, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    06cee12 View commit details
Showing with 59 additions and 26 deletions.
  1. +2 −0 .eslintrc.js
  2. +3 −3 .github/workflows/audit.yml
  3. +6 −6 .github/workflows/ci.yml
  4. +2 −2 .github/workflows/codeql-analysis.yml
  5. +5 −6 .github/workflows/post-dependabot.yml
  6. +2 −2 .github/workflows/pull-request.yml
  7. +7 −0 CHANGELOG.md
  8. +4 −3 lib/index.js
  9. +3 −3 package.json
  10. +25 −1 test/defaults.js
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* This file is automatically added by @npmcli/template-oss. Do not edit. */

'use strict'

const { readdirSync: readdir } = require('fs')

const localConfigs = readdir(__dirname)
6 changes: 3 additions & 3 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
@@ -15,13 +15,13 @@ jobs:
- uses: actions/checkout@v3
- name: Setup git user
run: |
git config --global user.email "ops+npm-cli@npmjs.com"
git config --global user.name "npm cli ops bot"
git config --global user.email "ops+robot@npmjs.com"
git config --global user.name "npm team"
- uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Update npm to latest
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- run: npm i --ignore-scripts --package-lock
- run: npm i --ignore-scripts --no-audit --no-fund --package-lock
- run: npm audit
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -22,15 +22,15 @@ jobs:
- uses: actions/checkout@v3
- name: Setup git user
run: |
git config --global user.email "ops+npm-cli@npmjs.com"
git config --global user.name "npm cli ops bot"
git config --global user.email "ops+robot@npmjs.com"
git config --global user.name "npm team"
- uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Update npm to latest
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- run: npm i --ignore-scripts
- run: npm i --ignore-scripts --no-audit --no-fund
- run: npm run lint

test:
@@ -59,8 +59,8 @@ jobs:
- uses: actions/checkout@v3
- name: Setup git user
run: |
git config --global user.email "ops+npm-cli@npmjs.com"
git config --global user.name "npm cli ops bot"
git config --global user.email "ops+robot@npmjs.com"
git config --global user.name "npm team"
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
@@ -82,5 +82,5 @@ jobs:
if: ${{ !startsWith(matrix.node-version, '10.') }}
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- run: npm -v
- run: npm i --ignore-scripts
- run: npm i --ignore-scripts --no-audit --no-fund
- run: npm test --ignore-scripts
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -34,8 +34,8 @@ jobs:
- uses: actions/checkout@v3
- name: Setup git user
run: |
git config --global user.email "ops+npm-cli@npmjs.com"
git config --global user.name "npm cli ops bot"
git config --global user.email "ops+robot@npmjs.com"
git config --global user.name "npm team"
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
11 changes: 5 additions & 6 deletions .github/workflows/post-dependabot.yml
Original file line number Diff line number Diff line change
@@ -4,21 +4,20 @@ name: Post Dependabot Actions

on: pull_request

# https://docs.github.com/en/rest/overview/permissions-required-for-github-apps
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
permissions:
actions: write
contents: write

jobs:
Install:
template-oss-apply:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
steps:
- uses: actions/checkout@v3
- name: Setup git user
run: |
git config --global user.email "ops+npm-cli@npmjs.com"
git config --global user.name "npm cli ops bot"
git config --global user.email "ops+robot@npmjs.com"
git config --global user.name "npm team"
- uses: actions/setup-node@v3
with:
node-version: 16.x
@@ -36,7 +35,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr checkout ${{ github.event.pull_request.number }}
npm install --ignore-scripts
npm install --ignore-scripts --no-audit --no-fund
npm run template-oss-apply
git add .
git commit -am "chore: postinstall for dependabot template-oss PR"
4 changes: 2 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -20,8 +20,8 @@ jobs:
fetch-depth: 0
- name: Setup git user
run: |
git config --global user.email "ops+npm-cli@npmjs.com"
git config --global user.name "npm cli ops bot"
git config --global user.email "ops+robot@npmjs.com"
git config --global user.name "npm team"
- uses: actions/setup-node@v3
with:
node-version: 16.x
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

### [10.1.3](https://github.com/npm/make-fetch-happen/compare/v10.1.2...v10.1.3) (2022-05-09)


### Bug Fixes

* make `defaults` chaining actually work ([#144](https://github.com/npm/make-fetch-happen/issues/144)) ([aa71e81](https://github.com/npm/make-fetch-happen/commit/aa71e817c71968f547f4d1756b1faf92db7b79ec))

### [10.1.2](https://github.com/npm/make-fetch-happen/compare/v10.1.1...v10.1.2) (2022-04-05)


7 changes: 4 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ const makeFetchHappen = (url, opts) => {
return fetch(request, options)
}

makeFetchHappen.defaults = (defaultUrl, defaultOptions = {}) => {
makeFetchHappen.defaults = (defaultUrl, defaultOptions = {}, wrappedFetch = makeFetchHappen) => {
if (typeof defaultUrl === 'object') {
defaultOptions = defaultUrl
defaultUrl = null
@@ -26,10 +26,11 @@ makeFetchHappen.defaults = (defaultUrl, defaultOptions = {}) => {
...options.headers,
},
}
return makeFetchHappen(finalUrl, finalOptions)
return wrappedFetch(finalUrl, finalOptions)
}

defaultedFetch.defaults = makeFetchHappen.defaults
defaultedFetch.defaults = (defaultUrl1, defaultOptions1 = {}) =>
makeFetchHappen.defaults(defaultUrl1, defaultOptions1, defaultedFetch)
return defaultedFetch
}

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "make-fetch-happen",
"version": "10.1.2",
"version": "10.1.3",
"description": "Opinionated, caching, retrying fetch client",
"main": "lib/index.js",
"files": [
@@ -55,7 +55,7 @@
},
"devDependencies": {
"@npmcli/eslint-config": "^3.0.1",
"@npmcli/template-oss": "3.2.2",
"@npmcli/template-oss": "3.4.3",
"mkdirp": "^1.0.4",
"nock": "^13.2.4",
"rimraf": "^3.0.2",
@@ -73,6 +73,6 @@
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "3.2.2"
"version": "3.4.3"
}
}
26 changes: 25 additions & 1 deletion test/defaults.js
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ t.test('can set default url', async (t) => {

t.test('allows default headers', async (t) => {
const srv = nock('http://localhost', {
reqHeaders: {
reqheaders: {
'x-foo': 'bar',
'x-bar': 'baz',
},
@@ -40,3 +40,27 @@ t.test('allows default headers', async (t) => {
t.same(buf, Buffer.from('success'), 'got body')
t.ok(srv.isDone())
})

t.test('layering default headers works', async (t) => {
const srv = nock('http://localhost', {
reqheaders: {
'x-foo': 'bar',
'x-bar': 'baz',
'x-another': 'yep',
},
})
.get('/test')
.reply(200, 'success')

const defaultedFetch1 = fetch.defaults({ headers: { 'x-foo': 'bar' } })
const defaultedFetch2 = defaultedFetch1.defaults({ headers: { 'x-bar': 'baz' } })
const res = await defaultedFetch2('http://localhost/test', {
headers: {
'x-another': 'yep',
},
})
t.equal(res.status, 200, 'got success')
const buf = await res.buffer()
t.same(buf, Buffer.from('success'), 'got body')
t.ok(srv.isDone())
})