Skip to content

Commit fadc798

Browse files
committed
fix(deps): replace deprecated glob@8
Installing netlify-cli prints a deprecation warning: netlify/cli#7029. I was going to upgrade `glob`, but then I remembered it's a fairly large library, so why not use this as an opportunity to replace it? See https://github.com/es-tooling/module-replacements/blob/main/docs/modules/glob.md. Compare the APIs: - https://github.com/isaacs/node-glob#readme - https://github.com/SuperchupuDev/tinyglobby?tab=readme-ov-file#api The only differences are option names, which I've updated. Our uses either hardcode patterns or enforce precisely documented user patterns, so we won't hit any of the limitations of tinyglobby.
1 parent 65206cf commit fadc798

File tree

8 files changed

+33
-70
lines changed

8 files changed

+33
-70
lines changed

Diff for: package-lock.json

+16-48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: packages/zip-it-and-ship-it/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"fast-glob": "^3.3.2",
5656
"filter-obj": "^5.0.0",
5757
"find-up": "^6.0.0",
58-
"glob": "^8.0.3",
5958
"is-builtin-module": "^3.1.0",
6059
"is-path-inside": "^4.0.0",
6160
"junk": "^4.0.0",
@@ -69,6 +68,7 @@
6968
"require-package-name": "^2.0.1",
7069
"resolve": "^2.0.0-next.1",
7170
"semver": "^7.3.8",
71+
"tinyglobby": "^0.2.12",
7272
"tmp-promise": "^3.0.2",
7373
"toml": "^3.0.0",
7474
"unixify": "^1.0.0",
@@ -78,7 +78,6 @@
7878
},
7979
"devDependencies": {
8080
"@types/archiver": "6.0.3",
81-
"@types/glob": "8.1.0",
8281
"@types/is-ci": "3.0.4",
8382
"@types/node": "20.12.11",
8483
"@types/normalize-path": "3.0.2",

Diff for: packages/zip-it-and-ship-it/src/runtimes/node/bundlers/esbuild/bundler.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const includedFilesToEsbuildExternals = async (includedFiles: string[], baseDir:
4040
.map((pattern) => pattern.slice(1))
4141
// esbuild expects relative paths
4242
.map((pattern) => `./${pattern}`)
43-
// esbuild treats * the same as glob treats **, so this replacement is safe
43+
// esbuild treats * the same as tinyglobby treats **, so this replacement is safe
4444
.map((pattern) => pattern.replace(/\*\*/g, '*').replace(/\*(\\\*)+/g, '*'))
4545

4646
const result: string[] = []
@@ -60,11 +60,11 @@ const includedFilesToEsbuildExternals = async (includedFiles: string[], baseDir:
6060

6161
if (hasMultipleGlobs) {
6262
const resolved = await glob(pattern, {
63-
noglobstar: true,
6463
cwd: baseDir,
6564
})
66-
67-
result.push(...resolved)
65+
// esbuild expects relative paths, but tinyglobby uses `posix.normalize()` which strips leading `./`
66+
const esbuildPatterns = resolved.map((pattern) => `./${pattern}`)
67+
result.push(...esbuildPatterns)
6868
} else {
6969
result.push(pattern)
7070
}

Diff for: packages/zip-it-and-ship-it/src/runtimes/node/bundlers/nft/side_files.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const getSideFiles = async function (functionPath: string, stat: Stats):
1818
absolute: true,
1919
cwd: functionPath,
2020
ignore: `**/node_modules/**`,
21-
nodir: true,
21+
onlyFiles: true,
2222
})
2323

2424
return paths.filter((path) => !isJunk(basename(path)))

Diff for: packages/zip-it-and-ship-it/src/runtimes/node/bundlers/zisi/published.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const getPublishedFiles = async function (modulePath: string): Promise<st
55
const ignore = getIgnoredFiles(modulePath)
66
const publishedFiles = await glob(`${modulePath}/**`, {
77
ignore,
8-
nodir: true,
8+
onlyFiles: true,
99
absolute: true,
1010
dot: true,
1111
})

Diff for: packages/zip-it-and-ship-it/src/runtimes/node/bundlers/zisi/tree_files.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const getTreeFiles = async function (srcPath: string, stat: Stats): Promi
1010

1111
return await glob(`${srcPath}/**`, {
1212
ignore: `${srcPath}/**/node_modules/**`,
13-
nodir: true,
13+
onlyFiles: true,
1414
absolute: true,
1515
})
1616
}

Diff for: packages/zip-it-and-ship-it/src/utils/matching.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
import { promisify } from 'util'
2-
3-
import globFunction from 'glob'
41
import { minimatch as minimatchFunction, MinimatchOptions } from 'minimatch'
52
import normalizePath from 'normalize-path'
6-
7-
const pGlob = promisify(globFunction)
3+
import { glob as tinyGlobby, type GlobOptions } from 'tinyglobby'
84

95
/**
106
* Both glob and minimatch only support unix style slashes in patterns
117
* For this reason we wrap them and ensure all patters are always unixified
128
* We use `normalize-path` here instead of `unixify` because we do not want to remove drive letters
139
*/
1410

15-
export const glob = function (pattern: string, options: globFunction.IOptions): Promise<string[]> {
16-
let normalizedIgnore
11+
export const glob = function (pattern: string, options: GlobOptions): Promise<string[]> {
12+
let normalizedIgnore: undefined | string | string[]
1713

1814
if (options.ignore) {
1915
normalizedIgnore =
@@ -22,7 +18,7 @@ export const glob = function (pattern: string, options: globFunction.IOptions):
2218
: options.ignore.map((expression) => normalizePath(expression))
2319
}
2420

25-
return pGlob(normalizePath(pattern), { ...options, ignore: normalizedIgnore })
21+
return tinyGlobby(normalizePath(pattern), { ...options, ignore: normalizedIgnore })
2622
}
2723

2824
export const minimatch = function (target: string, pattern: string, options?: MinimatchOptions): boolean {

Diff for: packages/zip-it-and-ship-it/tests/v2api.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { readFile } from 'fs/promises'
22
import { join, resolve } from 'path'
33
import { platform, version as nodeVersion } from 'process'
4-
import { promisify } from 'util'
54

65
import { getPath as getBootstrapPath } from '@netlify/serverless-functions-api'
76
import merge from 'deepmerge'
8-
import glob from 'glob'
97
import { pathExists } from 'path-exists'
108
import semver from 'semver'
9+
import { glob } from 'tinyglobby'
1110
import { dir as getTmpDir } from 'tmp-promise'
1211
import { afterEach, describe, expect, test, vi } from 'vitest'
1312

@@ -18,8 +17,6 @@ import { invokeLambda, readAsBuffer } from './helpers/lambda.js'
1817
import { zipFixture, unzipFiles, importFunctionFile, FIXTURES_ESM_DIR, FIXTURES_DIR } from './helpers/main.js'
1918
import { testMany } from './helpers/test_many.js'
2019

21-
const pGlob = promisify(glob)
22-
2320
vi.mock('../src/utils/shell.js', () => ({ shellUtils: { runCommand: vi.fn() } }))
2421

2522
describe.runIf(semver.gte(nodeVersion, '18.13.0'))('V2 functions API', () => {
@@ -132,7 +129,10 @@ describe.runIf(semver.gte(nodeVersion, '18.13.0'))('V2 functions API', () => {
132129

133130
const [{ name: archive, entryFilename, path }] = files
134131

135-
const untranspiledFiles = await pGlob(`${path}/**/*.ts`)
132+
const untranspiledFiles = await glob(`${path}/**/*.ts`, {
133+
onlyFiles: true,
134+
followSymbolicLinks: false,
135+
})
136136
expect(untranspiledFiles).toEqual([])
137137

138138
const func = await importFunctionFile(`${tmpDir}/${archive}/${entryFilename}`)

0 commit comments

Comments
 (0)