Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fastify/autoload

Package Overview
Dependencies
Maintainers
19
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/autoload - npm Package Compare versions

Comparing version 5.7.0 to 5.7.1

13

index.js

@@ -174,3 +174,3 @@ 'use strict'

accumulatePlugin({ file, type }, indexDirent.name)
accumulatePlugin({ file, type })
const hasDirectory = list.find((dirent) => dirent.isDirectory())

@@ -230,3 +230,3 @@

if (!autoHooksPattern.test(dirent.name)) {
accumulatePlugin({ file, type }, dirent.name)
accumulatePlugin({ file, type })
}

@@ -239,10 +239,11 @@ }

function accumulatePlugin ({ file, type }, direntName = 'index.ts') {
const routePath = `${prefix ?? ''}/${direntName}`
function accumulatePlugin ({ file, type }) {
// Replace backward slash to forward slash for consistent behavior between windows and posix.
const filePath = '/' + path.relative(options.dir, file).replace(/\\/g, '/')
if (matchFilter && !filterPath(routePath, matchFilter)) {
if (matchFilter && !filterPath(filePath, matchFilter)) {
return
}
if (ignoreFilter && filterPath(routePath, ignoreFilter)) {
if (ignoreFilter && filterPath(filePath, ignoreFilter)) {
return

@@ -249,0 +250,0 @@ }

{
"name": "@fastify/autoload",
"version": "5.7.0",
"version": "5.7.1",
"description": "Require all plugins in a directory",

@@ -5,0 +5,0 @@ "main": "index.js",

module.exports.default = async (fastify: any) => {
fastify.get("/", function () {
return { foo: "bar" };
return { bar: "bar" };
})
};
module.exports.default = async (fastify: any) => {
fastify.get("/", function () {
return { foo: "bar" };
fastify.get("/customPath", function () {
return { baz: "baz" };
})
};
module.exports.default = async (fastify: any) => {
fastify.get("/", function () {
return { foo: "bar" };
return { foo: "foo" };
})
};

@@ -29,4 +29,4 @@ 'use strict'

expect(response.statusCode).toBe(200)
expect(JSON.parse(response.payload)).toEqual({ foo: 'bar' })
expect(JSON.parse(response.payload)).toEqual({ foo: 'foo' })
})
})

@@ -52,3 +52,3 @@ 'use strict'

dir: join(__dirname, '../commonjs/ts-node/routes'),
matchFilter: "/foo"
matchFilter: (path) => path.startsWith("/foo")
})

@@ -83,3 +83,3 @@

method: 'GET',
url: '/foo/baz'
url: '/foo/baz/customPath'
})

@@ -89,1 +89,18 @@ expect(response.statusCode).toBe(200)

})
describe.concurrent("Vitest match filters without prefix test suite", function () {
const app = Fastify()
app.register(AutoLoad, {
dir: join(__dirname, '../commonjs/ts-node/routes'),
dirNameRoutePrefix: false,
matchFilter: (path) => path.startsWith("/foo/baz")
})
test("Test /baz route", async function () {
const response = await app.inject({
method: 'GET',
url: '/customPath'
})
expect(response.statusCode).toBe(200)
})
})

@@ -7,3 +7,3 @@ import { FastifyPluginCallback, FastifyPluginOptions } from 'fastify'

type RewritePrefix = (folderParent: string, folderName: string) => string | boolean
type Filter = string | RegExp | ((value: {file: string; path: string}) => boolean)
type Filter = string | RegExp | ((path: string) => boolean)

@@ -10,0 +10,0 @@ export interface AutoloadPluginOptions {

@@ -76,4 +76,4 @@ import fastify, { FastifyInstance, FastifyPluginCallback } from 'fastify'

dir: 'test',
ignoreFilter: ({file}) => file.endsWith('.spec.ts'),
matchFilter: ({path}) => path.split("/").at(-2) === 'handlers'
ignoreFilter: (path) => path.endsWith('.spec.ts'),
matchFilter: (path) => path.split('/').at(-2) === 'handlers'
}

@@ -80,0 +80,0 @@ app.register(fastifyAutoloadDefault, opt1)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc