Skip to content

Commit

Permalink
fix(deps): replace deprecated glob@8
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
serhalp committed Feb 18, 2025
1 parent 24e6f87 commit e38f12d
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 66 deletions.
63 changes: 16 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/zip-it-and-ship-it/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"fast-glob": "^3.3.2",
"filter-obj": "^5.0.0",
"find-up": "^6.0.0",
"glob": "^8.0.3",
"is-builtin-module": "^3.1.0",
"is-path-inside": "^4.0.0",
"junk": "^4.0.0",
Expand All @@ -69,6 +68,7 @@
"require-package-name": "^2.0.1",
"resolve": "^2.0.0-next.1",
"semver": "^7.3.8",
"tinyglobby": "^0.2.11",
"tmp-promise": "^3.0.2",
"toml": "^3.0.0",
"unixify": "^1.0.0",
Expand All @@ -78,7 +78,6 @@
},
"devDependencies": {
"@types/archiver": "6.0.3",
"@types/glob": "8.1.0",
"@types/is-ci": "3.0.4",
"@types/node": "20.12.11",
"@types/normalize-path": "3.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const includedFilesToEsbuildExternals = async (includedFiles: string[], baseDir:

if (hasMultipleGlobs) {
const resolved = await glob(pattern, {
noglobstar: true,
expandDirectories: false,
cwd: baseDir,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const getSideFiles = async function (functionPath: string, stat: Stats):
absolute: true,
cwd: functionPath,
ignore: `**/node_modules/**`,
nodir: true,
expandDirectories: false,
})

return paths.filter((path) => !isJunk(basename(path)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const getPublishedFiles = async function (modulePath: string): Promise<st
const ignore = getIgnoredFiles(modulePath)
const publishedFiles = await glob(`${modulePath}/**`, {
ignore,
nodir: true,
expandDirectories: false,
absolute: true,
dot: true,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const getTreeFiles = async function (srcPath: string, stat: Stats): Promi

return await glob(`${srcPath}/**`, {
ignore: `${srcPath}/**/node_modules/**`,
nodir: true,
expandDirectories: false,
absolute: true,
})
}
12 changes: 4 additions & 8 deletions packages/zip-it-and-ship-it/src/utils/matching.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { promisify } from 'util'

import globFunction from 'glob'
import { minimatch as minimatchFunction, MinimatchOptions } from 'minimatch'
import normalizePath from 'normalize-path'

const pGlob = promisify(globFunction)
import { glob as tinyGlobby, type GlobOptions } from 'tinyglobby'

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

export const glob = function (pattern: string, options: globFunction.IOptions): Promise<string[]> {
let normalizedIgnore
export const glob = function (pattern: string, options: GlobOptions): Promise<string[]> {
let normalizedIgnore: undefined | string | string[]

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

return pGlob(normalizePath(pattern), { ...options, ignore: normalizedIgnore })
return tinyGlobby(normalizePath(pattern), { ...options, ignore: normalizedIgnore })
}

export const minimatch = function (target: string, pattern: string, options?: MinimatchOptions): boolean {
Expand Down
7 changes: 2 additions & 5 deletions packages/zip-it-and-ship-it/tests/v2api.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { readFile } from 'fs/promises'
import { join, resolve } from 'path'
import { platform, version as nodeVersion } from 'process'
import { promisify } from 'util'

import { getPath as getBootstrapPath } from '@netlify/serverless-functions-api'
import merge from 'deepmerge'
import glob from 'glob'
import { pathExists } from 'path-exists'
import semver from 'semver'
import { glob } from 'tinyglobby'
import { dir as getTmpDir } from 'tmp-promise'
import { afterEach, describe, expect, test, vi } from 'vitest'

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

const pGlob = promisify(glob)

vi.mock('../src/utils/shell.js', () => ({ shellUtils: { runCommand: vi.fn() } }))

describe.runIf(semver.gte(nodeVersion, '18.13.0'))('V2 functions API', () => {
Expand Down Expand Up @@ -132,7 +129,7 @@ describe.runIf(semver.gte(nodeVersion, '18.13.0'))('V2 functions API', () => {

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

const untranspiledFiles = await pGlob(`${path}/**/*.ts`)
const untranspiledFiles = await glob(`${path}/**/*.ts`)
expect(untranspiledFiles).toEqual([])

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

0 comments on commit e38f12d

Please sign in to comment.