Skip to content
Merged
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
56 changes: 3 additions & 53 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,9 @@
"es-module-lexer": "^1.0.0",
"esbuild": "0.25.4",
"execa": "^8.0.0",
"fast-glob": "^3.3.2",
"fast-glob": "^3.3.3",
"filter-obj": "^6.0.0",
"find-up": "^7.0.0",
"glob": "^8.0.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"is-builtin-module": "^3.1.0",
"is-path-inside": "^4.0.0",
"junk": "^4.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 @@ -60,11 +60,13 @@ const includedFilesToEsbuildExternals = async (includedFiles: string[], baseDir:

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

result.push(...resolved)
// esbuild expects relative paths to always have a 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 @@ -17,8 +17,7 @@ export const getSideFiles = async function (functionPath: string, stat: Stats):
const paths = await glob(`${functionPath}/**`, {
absolute: true,
cwd: functionPath,
ignore: `**/node_modules/**`,
nodir: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼 fast-glob onlyFiles is true by default, I see: https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#onlyfiles

ignore: [`**/node_modules/**`],
})

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

return await glob(`${srcPath}/**`, {
ignore: `${srcPath}/**/node_modules/**`,
nodir: true,
ignore: [`${srcPath}/**/node_modules/**`],
absolute: true,
})
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { normalize, resolve } from 'path'

import fastGlob from 'fast-glob'
import glob from 'fast-glob'

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

Expand Down Expand Up @@ -48,7 +48,7 @@ export const getPathsOfIncludedFiles = async (
{ include: [], excludePatterns: [] },
)

const pathGroups = await fastGlob(include, {
const pathGroups = await glob(include, {
absolute: true,
cwd: basePath,
dot: true,
Expand Down
25 changes: 6 additions & 19 deletions packages/zip-it-and-ship-it/src/utils/matching.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
import { promisify } from 'util'

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

const pGlob = promisify(globFunction)

/**
* Both glob and minimatch only support unix style slashes in patterns
* For this reason we wrap them and ensure all patters are always unixified
* 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: globFunction.IOptions): Promise<string[]> {
let normalizedIgnore

if (options.ignore) {
normalizedIgnore =
typeof options.ignore === 'string'
? normalizePath(options.ignore)
: options.ignore.map((expression) => normalizePath(expression))
}

return pGlob(normalizePath(pattern), { ...options, ignore: normalizedIgnore })
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 minimatch = function (target: string, pattern: string, options?: MinimatchOptions): boolean {
Expand Down
12 changes: 4 additions & 8 deletions packages/zip-it-and-ship-it/tests/v2api.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { readFile } from 'fs/promises'
import { join, resolve } from 'path'
import { platform, version as nodeVersion } from 'process'
import { promisify } from 'util'
import { platform } from 'process'

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

Expand All @@ -18,11 +16,9 @@ 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', () => {
describe('V2 functions API', () => {
afterEach(() => {
vi.resetAllMocks()
})
Expand Down Expand Up @@ -132,7 +128,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