@fastify/static 6.11.2 → 6.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.json CHANGED
@@ -1,51 +1,31 @@
1
1
  {
2
- "extends": [
3
- "eslint:recommended",
4
- "plugin:@typescript-eslint/eslint-recommended",
5
- "plugin:@typescript-eslint/recommended",
6
- "standard"
7
- ],
8
- "parser": "@typescript-eslint/parser",
9
- "plugins": ["@typescript-eslint"],
10
- "env": { "node": true },
11
- "parserOptions": {
12
- "ecmaVersion": 6,
13
- "sourceType": "module",
14
- "project": "./tsconfig.eslint.json",
15
- "createDefaultProgram": true
16
- },
17
- "rules": {
18
- "no-console": "off",
19
- "@typescript-eslint/indent": ["error", 2],
20
- "semi": ["error", "never"],
21
- "import/export": "off" // this errors on multiple exports (overload interfaces)
22
- },
23
- "overrides": [
24
- {
25
- "files": ["*.d.ts","*.test-d.ts"],
26
- "rules": {
27
- "no-use-before-define": "off",
28
- "no-redeclare": "off",
29
- "@typescript-eslint/no-explicit-any": "off"
30
- }
2
+ "plugins": ["@typescript-eslint"],
3
+ "extends": ["eslint:recommended", "standard"],
4
+ "overrides": [
5
+ {
6
+ "files": ["types/*.test-d.ts", "types/*.d.ts"],
7
+ "parser": "@typescript-eslint/parser",
8
+ "parserOptions": {
9
+ "project": ["./tsconfig.eslint.json"]
31
10
  },
32
- {
33
- "files": ["*.test-d.ts"],
34
- "rules": {
35
- "@typescript-eslint/no-var-requires": "off",
36
- "no-unused-vars": "off",
37
- "n/handle-callback-err": "off",
38
- "@typescript-eslint/no-empty-function": "off",
39
- "@typescript-eslint/explicit-function-return-type": "off",
40
- "@typescript-eslint/no-unused-vars": "off",
41
- "@typescript-eslint/no-non-null-assertion": "off",
42
- "@typescript-eslint/no-misused-promises": ["error", {
43
- "checksVoidReturn": false
44
- }]
45
- },
46
- "globals": {
47
- "NodeJS": "readonly"
48
- }
11
+ "extends": [
12
+ "plugin:@typescript-eslint/recommended",
13
+ "plugin:@typescript-eslint/recommended-requiring-type-checking"
14
+ ],
15
+ "rules": {
16
+ "no-use-before-define": "off",
17
+ "@typescript-eslint/no-var-requires": "off",
18
+ "@typescript-eslint/no-unused-vars": "off",
19
+ "@typescript-eslint/no-explicit-any": "off",
20
+ "@typescript-eslint/no-floating-promises": "off",
21
+ "@typescript-eslint/no-unsafe-assignment": "off",
22
+ "@typescript-eslint/no-unsafe-argument": "off",
23
+ "@typescript-eslint/no-unsafe-member-access": "off",
24
+ "@typescript-eslint/no-unsafe-call": "off",
25
+ "@typescript-eslint/no-misused-promises": ["error", {
26
+ "checksVoidReturn": false
27
+ }]
49
28
  }
50
- ]
51
- }
29
+ }
30
+ ]
31
+ }
package/index.js CHANGED
@@ -14,12 +14,12 @@ const contentDisposition = require('content-disposition')
14
14
 
15
15
  const dirList = require('./lib/dirList')
16
16
 
17
- const winSeparatorRegex = new RegExp(`\\${path.win32.sep}`, 'g')
18
- const backslashRegex = /\\/g
19
- const startForwardSlashRegex = /^\//
20
- const endForwardSlashRegex = /\/$/
21
- const doubleForwardSlashRegex = /\/\//g
22
- const asteriskRegex = /\*/g
17
+ const winSeparatorRegex = new RegExp(`\\${path.win32.sep}`, 'gu')
18
+ const backslashRegex = /\\/gu
19
+ const startForwardSlashRegex = /^\//u
20
+ const endForwardSlashRegex = /\/$/u
21
+ const doubleForwardSlashRegex = /\/\//gu
22
+ const asteriskRegex = /\*/gu
23
23
 
24
24
  const supportedEncodings = ['br', 'gzip', 'deflate']
25
25
  send.mime.default_type = 'application/octet-stream'
@@ -436,7 +436,7 @@ function checkRootPathForErrors (fastify, rootPath) {
436
436
  throw new Error('"root" option array requires one or more paths')
437
437
  }
438
438
 
439
- if ([...new Set(rootPath)].length !== rootPath.length) {
439
+ if (new Set(rootPath).size !== rootPath.length) {
440
440
  throw new Error(
441
441
  '"root" option array contains one or more duplicate paths'
442
442
  )
@@ -498,7 +498,7 @@ function findIndexFile (pathname, root, indexFiles = ['index.html']) {
498
498
  try {
499
499
  const stats = statSync(p)
500
500
  return !stats.isDirectory()
501
- } catch (e) {
501
+ } catch {
502
502
  return false
503
503
  }
504
504
  })
@@ -542,7 +542,7 @@ function getRedirectUrl (url) {
542
542
  const parsed = new URL(url, 'http://localhost.com/')
543
543
  const parsedPathname = parsed.pathname
544
544
  return parsedPathname + (parsedPathname[parsedPathname.length - 1] !== '/' ? '/' : '') + (parsed.search || '')
545
- } catch (error) {
545
+ } catch {
546
546
  // the try-catch here is actually unreachable, but we keep it for safety and prevent DoS attack
547
547
  /* istanbul ignore next */
548
548
  const err = new Error(`Invalid redirect URL: ${url}`)
package/lib/dirList.js CHANGED
@@ -27,7 +27,7 @@ const dirList = {
27
27
  let stats
28
28
  try {
29
29
  stats = await fs.stat(path.join(dir, filename))
30
- } catch (error) {
30
+ } catch {
31
31
  return
32
32
  }
33
33
  const entry = { name: filename, stats }
@@ -58,7 +58,7 @@ const dirList = {
58
58
  let stats
59
59
  try {
60
60
  stats = await fs.stat(filePath)
61
- } catch (error) {
61
+ } catch {
62
62
  return
63
63
  }
64
64
 
@@ -112,7 +112,7 @@ const dirList = {
112
112
  let entries
113
113
  try {
114
114
  entries = await dirList.list(dir, options, dotfiles)
115
- } catch (error) {
115
+ } catch {
116
116
  return reply.callNotFound()
117
117
  }
118
118
  const format = reply.request.query.format || options.format
@@ -146,7 +146,7 @@ const dirList = {
146
146
  route = path.normalize(path.join(route, '..'))
147
147
  }
148
148
  return {
149
- href: path.join(prefix, route, entry.name).replace(/\\/g, '/'),
149
+ href: path.join(prefix, route, entry.name).replace(/\\/gu, '/'),
150
150
  name: entry.name,
151
151
  stats: entry.stats,
152
152
  extendedInfo: entry.extendedInfo
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@fastify/static",
3
- "version": "6.11.2",
3
+ "version": "6.12.0",
4
4
  "description": "Plugin for serving static files as fast as possible.",
5
5
  "main": "index.js",
6
+ "type": "commonjs",
6
7
  "types": "types/index.d.ts",
7
8
  "scripts": {
8
9
  "coverage": "npm run test:unit -- --coverage-report=html",
@@ -1000,7 +1000,7 @@ t.test('sendFile disabled', (t) => {
1000
1000
  fastify.register(fastifyStatic, pluginOptions)
1001
1001
 
1002
1002
  fastify.get('/foo/bar', function (req, reply) {
1003
- if (typeof reply.sendFile === 'undefined') {
1003
+ if (reply.sendFile === undefined) {
1004
1004
  reply.send('pass')
1005
1005
  } else {
1006
1006
  reply.send('fail')
@@ -1277,7 +1277,7 @@ t.test('sendFile disabled', (t) => {
1277
1277
  fastify.register(fastifyStatic, pluginOptions)
1278
1278
 
1279
1279
  fastify.get('/foo/bar', function (req, reply) {
1280
- if (typeof reply.sendFile === 'undefined') {
1280
+ if (reply.sendFile === undefined) {
1281
1281
  reply.send('pass')
1282
1282
  } else {
1283
1283
  reply.send('fail')
@@ -1316,7 +1316,7 @@ t.test('download disabled', (t) => {
1316
1316
  fastify.register(fastifyStatic, pluginOptions)
1317
1317
 
1318
1318
  fastify.get('/foo/bar', function (req, reply) {
1319
- if (typeof reply.download === 'undefined') {
1319
+ if (reply.download === undefined) {
1320
1320
  t.equal(reply.download, undefined)
1321
1321
  reply.send('pass')
1322
1322
  } else {
@@ -1,13 +1,10 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "es6",
4
- "lib": [ "es2015" ],
5
- "module": "commonjs",
6
- "noEmit": true,
7
- "strict": true
8
- },
9
- "include": [
10
- "types/*.test-d.ts",
11
- "types/*.d.ts"
12
- ]
13
- }
2
+ "compilerOptions": {
3
+ "target": "es6",
4
+ "lib": ["ES2018"],
5
+ "module": "commonjs",
6
+ "noEmit": true,
7
+ "strict": true
8
+ },
9
+ "include": ["types/*.test-d.ts", "types/*.d.ts"]
10
+ }