From d5e6f2abd625b719bbd6bffbd123e7f590caae23 Mon Sep 17 00:00:00 2001 From: Mateusz Bocian Date: Fri, 30 May 2025 21:35:12 -0400 Subject: [PATCH 1/2] fix(deps): replace glob with fast-glob --- package-lock.json | 56 +------------------ packages/zip-it-and-ship-it/package.json | 4 +- .../runtimes/node/bundlers/esbuild/bundler.ts | 6 +- .../runtimes/node/bundlers/nft/side_files.ts | 3 +- .../runtimes/node/bundlers/zisi/published.ts | 1 - .../runtimes/node/bundlers/zisi/tree_files.ts | 3 +- .../src/runtimes/node/utils/included_files.ts | 4 +- .../zip-it-and-ship-it/src/utils/matching.ts | 25 ++------- .../zip-it-and-ship-it/tests/v2api.test.ts | 12 ++-- 9 files changed, 22 insertions(+), 92 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9c40cd0cc1..4c88463857 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5292,17 +5292,6 @@ "integrity": "sha512-w28IoSUCJpidD/TGviZwwMJckNESJZXFu7NBZ5YJ4mEUnNraUn9Pm8HSZm/jDF1pDWYKspWE7oVphigUPRakIQ==", "license": "MIT" }, - "node_modules/@types/glob": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/@types/glob/-/glob-8.1.0.tgz", - "integrity": "sha512-IO+MJPVhoqz+28h1qLAcBEH2+xHMK6MTyHJc7MTnnYb6wsoLR29POVGJ7LycmVXIqyy/4/2ShP5sUwTXuOwb/w==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/minimatch": "^5.1.2", - "@types/node": "*" - } - }, "node_modules/@types/http-cache-semantics": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.4.tgz", @@ -5390,13 +5379,6 @@ "@types/lodash": "*" } }, - "node_modules/@types/minimatch": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-5.1.2.tgz", - "integrity": "sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/minimist": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.5.tgz", @@ -12735,6 +12717,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", + "dev": true, "license": "ISC" }, "node_modules/fsevents": { @@ -13162,26 +13145,6 @@ "ini": "^1.3.2" } }, - "node_modules/glob": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", - "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", - "deprecated": "Glob versions prior to v9 are no longer supported", - "license": "ISC", - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^5.0.1", - "once": "^1.3.0" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/glob-parent": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", @@ -13194,18 +13157,6 @@ "node": ">= 6" } }, - "node_modules/glob/node_modules/minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", - "license": "ISC", - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/global-cache-dir": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/global-cache-dir/-/global-cache-dir-5.0.0.tgz", @@ -13966,6 +13917,7 @@ "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", + "dev": true, "license": "ISC", "dependencies": { "once": "^1.3.0", @@ -26646,10 +26598,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", "is-builtin-module": "^3.1.0", "is-path-inside": "^4.0.0", "junk": "^4.0.0", @@ -26675,7 +26626,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", diff --git a/packages/zip-it-and-ship-it/package.json b/packages/zip-it-and-ship-it/package.json index c95f7663fb..ea0f01380d 100644 --- a/packages/zip-it-and-ship-it/package.json +++ b/packages/zip-it-and-ship-it/package.json @@ -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", "is-builtin-module": "^3.1.0", "is-path-inside": "^4.0.0", "junk": "^4.0.0", @@ -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", diff --git a/packages/zip-it-and-ship-it/src/runtimes/node/bundlers/esbuild/bundler.ts b/packages/zip-it-and-ship-it/src/runtimes/node/bundlers/esbuild/bundler.ts index 7da997fa60..0b5dd22c67 100644 --- a/packages/zip-it-and-ship-it/src/runtimes/node/bundlers/esbuild/bundler.ts +++ b/packages/zip-it-and-ship-it/src/runtimes/node/bundlers/esbuild/bundler.ts @@ -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, but tinyglobby uses `posix.normalize()` which strips leading `./` + const esbuildPatterns = resolved.map((pattern) => `./${pattern}`) + result.push(...esbuildPatterns) } else { result.push(pattern) } diff --git a/packages/zip-it-and-ship-it/src/runtimes/node/bundlers/nft/side_files.ts b/packages/zip-it-and-ship-it/src/runtimes/node/bundlers/nft/side_files.ts index 61c46e3fb7..911f3fe85e 100644 --- a/packages/zip-it-and-ship-it/src/runtimes/node/bundlers/nft/side_files.ts +++ b/packages/zip-it-and-ship-it/src/runtimes/node/bundlers/nft/side_files.ts @@ -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, + ignore: [`**/node_modules/**`], }) return paths.filter((path) => !isJunk(basename(path))) diff --git a/packages/zip-it-and-ship-it/src/runtimes/node/bundlers/zisi/published.ts b/packages/zip-it-and-ship-it/src/runtimes/node/bundlers/zisi/published.ts index ab977b5e22..c588731164 100644 --- a/packages/zip-it-and-ship-it/src/runtimes/node/bundlers/zisi/published.ts +++ b/packages/zip-it-and-ship-it/src/runtimes/node/bundlers/zisi/published.ts @@ -5,7 +5,6 @@ export const getPublishedFiles = async function (modulePath: string): Promise { - 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 { + 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 { diff --git a/packages/zip-it-and-ship-it/tests/v2api.test.ts b/packages/zip-it-and-ship-it/tests/v2api.test.ts index fbd323cb06..1c15df6b90 100644 --- a/packages/zip-it-and-ship-it/tests/v2api.test.ts +++ b/packages/zip-it-and-ship-it/tests/v2api.test.ts @@ -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' @@ -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() }) @@ -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}`) From 7a0fe87a7d9af95395d1b6355a8af924edbc890b Mon Sep 17 00:00:00 2001 From: Mateusz Bocian Date: Wed, 4 Jun 2025 13:43:22 -0400 Subject: [PATCH 2/2] chore: update comment --- .../src/runtimes/node/bundlers/esbuild/bundler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/zip-it-and-ship-it/src/runtimes/node/bundlers/esbuild/bundler.ts b/packages/zip-it-and-ship-it/src/runtimes/node/bundlers/esbuild/bundler.ts index 0b5dd22c67..9d4a686471 100644 --- a/packages/zip-it-and-ship-it/src/runtimes/node/bundlers/esbuild/bundler.ts +++ b/packages/zip-it-and-ship-it/src/runtimes/node/bundlers/esbuild/bundler.ts @@ -64,7 +64,7 @@ const includedFilesToEsbuildExternals = async (includedFiles: string[], baseDir: cwd: baseDir, }) - // esbuild expects relative paths, but tinyglobby uses `posix.normalize()` which strips leading `./` + // esbuild expects relative paths instead of posix paths const esbuildPatterns = resolved.map((pattern) => `./${pattern}`) result.push(...esbuildPatterns) } else {