Skip to content

chore(deps): switch from fast-glob to tinyglobby #6354

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 5 additions & 6 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/zip-it-and-ship-it/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"es-module-lexer": "^1.0.0",
"esbuild": "0.25.5",
"execa": "^8.0.0",
"fast-glob": "^3.3.3",
"filter-obj": "^6.0.0",
"find-up": "^7.0.0",
"is-builtin-module": "^3.1.0",
Expand All @@ -68,6 +67,7 @@
"require-package-name": "^2.0.1",
"resolve": "^2.0.0-next.1",
"semver": "^7.3.8",
"tinyglobby": "https://pkg.pr.new/tinyglobby@131",
"tmp-promise": "^3.0.2",
"toml": "^3.0.0",
"unixify": "^1.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { normalize, resolve } from 'path'
import { lstatSync } from 'fs'

import glob from 'fast-glob'
import { glob } from 'tinyglobby'

import { minimatch } from '../../../utils/matching.js'

Expand Down Expand Up @@ -54,14 +55,21 @@ export const getPathsOfIncludedFiles = async (
dot: true,
ignore: excludePatterns,
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.
markDirectories: true,
followSymbolicLinks: false,
expandDirectories: false,
})

const paths = pathGroups.filter((path) => !path.endsWith('/')).map(normalize)
const paths = pathGroups.filter(pathFilter).map(normalize)

// now filter the non symlinked directories out that got marked with a trailing slash
return { excludePatterns, paths }
}

function pathFilter(path: string) {
try {
const stats = lstatSync(path)
return !stats.isDirectory() || stats.isSymbolicLink()
} catch (_err) {
return false
}
}
9 changes: 5 additions & 4 deletions packages/zip-it-and-ship-it/src/utils/matching.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import originalGlob from 'fast-glob'
import { minimatch as minimatchFunction, type MinimatchOptions } from 'minimatch'
import normalizePath from 'normalize-path'
import { glob as originalGlob, type GlobOptions } from 'tinyglobby'

/**
* Both glob and minimatch only support unix style slashes in patterns
* For this reason we wrap them and ensure all patterns 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: originalGlob.Options): Promise<string[]> {
const normalizedIgnore = options.ignore?.map((expression) => normalizePath(expression))
return originalGlob(normalizePath(pattern), { ...options, ignore: normalizedIgnore })
export const glob = function (pattern: string, options: GlobOptions): Promise<string[]> {
const ignore = Array.isArray(options.ignore) ? options.ignore : options.ignore ? [options.ignore] : []
const normalizedIgnore = ignore.map((expression) => normalizePath(expression))
return originalGlob(normalizePath(pattern), { ...options, ignore: normalizedIgnore, expandDirectories: false })
}

export const minimatch = function (target: string, pattern: string, options?: MinimatchOptions): boolean {
Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -2840,7 +2840,7 @@ describe('zip-it-and-ship-it', () => {

await decompress(files[0].path, unzipPath)

const fileNames: string[] = await glob('**', { dot: true, cwd: unzipPath })
const fileNames: string[] = await glob('**', { dot: true, cwd: unzipPath, expandDirectories: false })
const duplicates = fileNames.filter((item, index) => fileNames.indexOf(item) !== index)
expect(duplicates).toHaveLength(0)
})
Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -32,7 +32,7 @@ test('The telemetry file should be added by default to the function bundle', asy

await decompress(result!.path, unzippedPath)

const files = await glob('**/*', { cwd: unzippedPath })
const files = await glob('**/*', { cwd: unzippedPath, expandDirectories: false })
expect(files.sort()).toEqual([
'___netlify-bootstrap.mjs',
'___netlify-entry-point.mjs',
Expand Down
4 changes: 2 additions & 2 deletions packages/zip-it-and-ship-it/tests/v2api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { platform } from 'process'

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

Expand Down Expand Up @@ -128,7 +128,7 @@ describe('V2 functions API', () => {

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

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

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