Skip to content

Commit

Permalink
fix: update glob to version 8 and fix broken tests (#297)
Browse files Browse the repository at this point in the history
* fix: update glob to version 8 and fix broken tests

In this release glob stopped accepting backward slashes on it's patterns, since `path.join` wil lreturn backward slashes on windows it they have to be replaced by a forward slash which is the posix separator.

I'm not entirely sure about all the consequences of this
change but all the tests seem to be passing and everything should work normally AFAIK since windows accept both backward and forward slashes as path separator.

Closes #281 since glob is already being updated here.

* fix: change replaceAll to regex to support node@14
  • Loading branch information
guilhermelimak committed May 11, 2022
1 parent 510d56d commit 654c7f5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,10 @@ async function fastifyStatic (fastify, opts) {
const indexDirs = new Map()
const routes = new Set()

const winSeparatorRegex = new RegExp(`\\${path.win32.sep}`, 'g')

for (const rootPath of Array.isArray(sendOptions.root) ? sendOptions.root : [sendOptions.root]) {
const files = await globPromise(path.join(rootPath, globPattern), { nodir: true })
const files = await globPromise(path.join(rootPath, globPattern).replace(winSeparatorRegex, path.posix.sep), { nodir: true })
const indexes = typeof opts.index === 'undefined' ? ['index.html'] : [].concat(opts.index)

for (let file of files) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"content-disposition": "^0.5.3",
"encoding-negotiator": "^2.0.1",
"fastify-plugin": "^3.0.0",
"glob": "^7.1.4",
"glob": "^8.0.1",
"p-limit": "^3.1.0",
"readable-stream": "^3.4.0",
"send": "^0.18.0"
Expand Down

0 comments on commit 654c7f5

Please sign in to comment.