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: fastify/fastify-plugin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.4.0
Choose a base ref
...
head repository: fastify/fastify-plugin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.5.0
Choose a head ref
  • 4 commits
  • 4 files changed
  • 4 contributors

Commits on Dec 5, 2022

  1. build(deps-dev): bump tsd from 0.24.1 to 0.25.0 (#206)

    Bumps [tsd](https://github.com/SamVerschueren/tsd) from 0.24.1 to 0.25.0.
    - [Release notes](https://github.com/SamVerschueren/tsd/releases)
    - [Commits](tsdjs/tsd@v0.24.1...v0.25.0)
    
    ---
    updated-dependencies:
    - dependency-name: tsd
      dependency-type: direct:development
      update-type: version-update:semver-minor
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Dec 5, 2022
    Copy the full SHA
    b7c1190 View commit details

Commits on Jan 6, 2023

  1. Copy the full SHA
    d7c3866 View commit details

Commits on Jan 10, 2023

  1. Copy the full SHA
    cd72d10 View commit details

Commits on Jan 11, 2023

  1. Bumped v4.5.0

    Signed-off-by: Matteo Collina <hello@matteocollina.com>
    mcollina committed Jan 11, 2023
    Copy the full SHA
    42595e8 View commit details
Showing with 32 additions and 3 deletions.
  1. +4 −1 .gitignore
  2. +3 −0 lib/getPluginName.js
  3. +2 −2 package.json
  4. +23 −0 test/test.js
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -135,11 +135,14 @@ dist
# macOS files
.DS_Store

# Clinic
.clinic

# lock files
package-lock.json
pnpm-lock.yaml
yarn.lock

# editor files
.vscode
.idea
.idea
3 changes: 3 additions & 0 deletions lib/getPluginName.js
Original file line number Diff line number Diff line change
@@ -6,9 +6,12 @@ const fileNamePattern = /(\w*(\.\w*)*)\..*/
module.exports = function getPluginName (fn) {
if (fn.name.length > 0) return fn.name

const stackTraceLimit = Error.stackTraceLimit
Error.stackTraceLimit = 10
try {
throw new Error('anonymous function')
} catch (e) {
Error.stackTraceLimit = stackTraceLimit
return extractPluginName(e.stack)
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fastify-plugin",
"version": "4.4.0",
"version": "4.5.0",
"description": "Plugin helper for Fastify",
"main": "plugin.js",
"types": "types/plugin.d.ts",
@@ -32,6 +32,6 @@
"proxyquire": "^2.1.3",
"standard": "^17.0.0",
"tap": "^16.0.1",
"tsd": "^0.24.1"
"tsd": "^0.25.0"
}
}
23 changes: 23 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -155,6 +155,29 @@ test('should set anonymous function name to file it was called from with a count
t.end()
})

test('should set function name if Error.stackTraceLimit is set to 0', t => {
const stackTraceLimit = Error.stackTraceLimit = 0

const fp = proxyquire('../plugin.js', { stubs: {} })

const fn = fp((fastify, opts, next) => {
next()
})

t.equal(fn[Symbol.for('plugin-meta')].name, 'test-auto-0')
t.equal(fn[Symbol.for('fastify.display-name')], 'test-auto-0')

const fn2 = fp((fastify, opts, next) => {
next()
})

t.equal(fn2[Symbol.for('plugin-meta')].name, 'test-auto-1')
t.equal(fn2[Symbol.for('fastify.display-name')], 'test-auto-1')

Error.stackTraceLimit = stackTraceLimit
t.end()
})

test('should set display-name to meta name', t => {
t.plan(2)