@fastify/autoload
Advanced tools
+7
-6
@@ -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 @@ } |
+1
-1
| { | ||
| "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) | ||
| }) | ||
| }) |
+1
-1
@@ -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) |
Potential vulnerability
Supply chain riskInitial human review suggests the presence of a vulnerability in this package. It is pending further analysis and confirmation.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 6 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Potential vulnerability
Supply chain riskInitial human review suggests the presence of a vulnerability in this package. It is pending further analysis and confirmation.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 6 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
121041
0.46%3540
0.45%