Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): replace noisy deprecated glob@8 with tinyglobby #6094

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 16 additions & 48 deletions package-lock.json

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

4 changes: 1 addition & 3 deletions packages/zip-it-and-ship-it/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@
"es-module-lexer": "^1.0.0",
"esbuild": "0.19.11",
"execa": "^7.0.0",
"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 +67,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 +77,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 @@ -40,7 +40,7 @@ const includedFilesToEsbuildExternals = async (includedFiles: string[], baseDir:
.map((pattern) => pattern.slice(1))
// esbuild expects relative paths
.map((pattern) => `./${pattern}`)
// esbuild treats * the same as glob treats **, so this replacement is safe
// esbuild treats * the same as tinyglobby treats **, so this replacement is safe
.map((pattern) => pattern.replace(/\*\*/g, '*').replace(/\*(\\\*)+/g, '*'))

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

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

result.push(...resolved)
// esbuild expects relative paths, but tinyglobby uses `posix.normalize()` which strips leading `./`
const esbuildPatterns = resolved.map((pattern) => `./${pattern}`)
result.push(...esbuildPatterns)
} else {
result.push(pattern)
}
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,
onlyFiles: true,
})

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,
onlyFiles: true,
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,
onlyFiles: true,
absolute: true,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ export const getPathsOfIncludedFiles = async (
onlyFiles: false,
// get directories as well to get symlinked directories,
// to filter the regular non symlinked directories out mark them with a slash at the end to filter them out.
// TODO(serhalp) If we can find a better way to do this, we can use tinyglobby here and remove fast-glob entirely.
markDirectories: true,
followSymbolicLinks: false,
})

// now filter the non symlinked directories out that got marked with a trailing slash
const paths = pathGroups.filter((path) => !path.endsWith('/')).map(normalize)

// now filter the non symlinked directories out that got marked with a trailing slash
return { excludePatterns, paths }
}
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
2 changes: 1 addition & 1 deletion packages/zip-it-and-ship-it/tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import cpy from 'cpy'
import decompress from 'decompress'
import merge from 'deepmerge'
import { execa, execaNode } from 'execa'
import glob from 'fast-glob'
import isCI from 'is-ci'
import { pathExists } from 'path-exists'
import semver from 'semver'
import { glob } from 'tinyglobby'
import { dir as getTmpDir, tmpName } from 'tmp-promise'
import unixify from 'unixify'
import { afterAll, afterEach, beforeAll, describe, expect, test, vi } from 'vitest'
Expand Down
2 changes: 1 addition & 1 deletion packages/zip-it-and-ship-it/tests/telemetry.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { join } from 'path'

import decompress from 'decompress'
import glob from 'fast-glob'
import { glob } from 'tinyglobby'
import { dir as getTmpDir } from 'tmp-promise'
import { expect, test } from 'vitest'

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
Loading