diff --git a/package.json b/package.json index 989ca645b..0b09a8f56 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,6 @@ "eslint-plugin-import": "^2.26.0", "eslint-plugin-prettier": "^4.2.1", "expect": "^27.5.1", - "fast-glob": "^3.3.3", "fetch-mock": "^9.11.0", "file-entry-cache": "^6.0.1", "husky": "^7.0.4", @@ -126,6 +125,7 @@ "patch-package": "^6.4.7", "prettier": "^2.4.1", "semantic-release": "^19.0.5", + "tinyglobby": "^0.2.14", "ts-jest": "^29.2.5", "ts-node": "^10.8.2", "typescript": "4.4.4" diff --git a/packages/cli/package.json b/packages/cli/package.json index 5c9c05546..5fe2169e6 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -46,11 +46,11 @@ "@stoplight/spectral-runtime": "^1.1.2", "@stoplight/types": "^13.6.0", "chalk": "4.1.2", - "fast-glob": "~3.2.12", "hpagent": "~1.2.0", "lodash": "~4.17.21", "pony-cause": "^1.1.1", "stacktracey": "^2.1.8", + "tinyglobby": "^0.2.14", "tslib": "^2.8.1", "yargs": "~17.7.2" }, diff --git a/packages/cli/src/services/linter/utils/__tests__/listFiles.test.ts b/packages/cli/src/services/linter/utils/__tests__/listFiles.test.ts index 0c1fec0d1..407a30f59 100644 --- a/packages/cli/src/services/linter/utils/__tests__/listFiles.test.ts +++ b/packages/cli/src/services/linter/utils/__tests__/listFiles.test.ts @@ -1,13 +1,15 @@ import * as path from '@stoplight/path'; -import * as fg from 'fast-glob'; +import { glob } from 'tinyglobby'; import { listFiles } from '../listFiles'; -jest.mock('fast-glob', () => jest.fn(async () => [])); +jest.mock('tinyglobby', () => ({ + glob: jest.fn(async () => []), +})); describe('listFiles CLI util', () => { it('unixify paths', () => { listFiles(['.\\repro\\lib.yaml', './foo/*.json', '.\\src\\__tests__\\__fixtures__\\*.oas.json'], true); - expect(fg).toBeCalledWith(['./repro/lib.yaml', './foo/*.json', './src/__tests__/__fixtures__/*.oas.json'], { + expect(glob).toBeCalledWith(['./repro/lib.yaml', './foo/*.json', './src/__tests__/__fixtures__/*.oas.json'], { dot: true, absolute: true, }); @@ -16,7 +18,7 @@ describe('listFiles CLI util', () => { it('returns file paths', async () => { const list = [path.join(__dirname, 'foo/a.json'), path.join(__dirname, 'foo/b.json')]; - (fg as unknown as jest.Mock).mockResolvedValueOnce([...list]); + (glob as unknown as jest.Mock).mockResolvedValueOnce([...list]); expect(await listFiles(['./foo/*.json'], true)).toEqual([list, []]); }); @@ -24,7 +26,7 @@ describe('listFiles CLI util', () => { it('given disabled ignoredUnmatchedGlobs, reports unmatched patterns', async () => { const list = [path.join(__dirname, 'foo/a.json'), path.join(__dirname, 'foo/b.json')]; - (fg as unknown as jest.Mock).mockImplementation(async pattern => { + (glob as unknown as jest.Mock).mockImplementation(async pattern => { if (pattern === './foo/*.json') { return list; } diff --git a/packages/cli/src/services/linter/utils/listFiles.ts b/packages/cli/src/services/linter/utils/listFiles.ts index 8049b2462..6a2e69872 100644 --- a/packages/cli/src/services/linter/utils/listFiles.ts +++ b/packages/cli/src/services/linter/utils/listFiles.ts @@ -1,13 +1,13 @@ import { normalize } from '@stoplight/path'; -import fg from 'fast-glob'; +import { glob } from 'tinyglobby'; const GLOB_OPTIONS = { absolute: true, dot: true, }; -async function match(pattern: fg.Pattern | fg.Pattern[]): Promise { - return (await fg(pattern, GLOB_OPTIONS)).map(normalize); +async function match(pattern: string | string[]): Promise { + return (await glob(pattern, GLOB_OPTIONS)).map(normalize); } const compareString = (a: string, b: string): number => a.localeCompare(b); diff --git a/packages/formatters/scripts/bundle-html-templates.mjs b/packages/formatters/scripts/bundle-html-templates.mjs index c54bdcac3..48374f2d2 100644 --- a/packages/formatters/scripts/bundle-html-templates.mjs +++ b/packages/formatters/scripts/bundle-html-templates.mjs @@ -6,11 +6,11 @@ import * as astring from 'astring'; import { builders as b } from 'ast-types'; import eol from 'eol'; -import fg from 'fast-glob'; +import { glob } from 'tinyglobby'; const cwd = path.join(path.dirname(fileURLToPath(import.meta.url)), '..'); -fg('src/html/*.html', { cwd, absolute: true }) +glob('src/html/*.html', { cwd, absolute: true, expandDirectories: false }) .then(files => Promise.all( files.map(async file => ({ file: path.basename(file), content: eol.lf(await fs.readFile(file, 'utf8')) })), diff --git a/test-harness/scripts/generate-tests.ts b/test-harness/scripts/generate-tests.ts index e557aea5c..7fe96bb83 100644 --- a/test-harness/scripts/generate-tests.ts +++ b/test-harness/scripts/generate-tests.ts @@ -1,6 +1,6 @@ import * as path from '@stoplight/path'; import * as swc from '@swc/core'; -import fg from 'fast-glob'; +import { glob } from 'tinyglobby'; import * as fileEntryCache from 'file-entry-cache'; import * as _fs from 'fs'; @@ -50,9 +50,12 @@ function getChangedScenarios(changedFiles: string[], scenarios: string[]): strin (async () => { await fs.mkdir(OUT_DIR, { recursive: true }); - const scenarios = await fg('**/*.scenario', { cwd: SCENARIOS_DIR, absolute: true }); + const scenarios = await glob('**/*.scenario', { cwd: SCENARIOS_DIR, absolute: true, expandDirectories: false }); const cache = fileEntryCache.create('spectral-test-harness', path.join(__dirname, '../../.cache'), true); - const changedFiles = cache.getUpdatedFiles([...scenarios, ...(await fg('**/**', { cwd: OUT_DIR, absolute: true }))]); + const changedFiles = cache.getUpdatedFiles([ + ...scenarios, + ...(await glob('**/**', { cwd: OUT_DIR, absolute: true, expandDirectories: false })), + ]); const changedScenarios = getChangedScenarios(changedFiles, scenarios); await Promise.all( diff --git a/yarn.lock b/yarn.lock index 1320f1a09..e0d876867 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2948,12 +2948,12 @@ __metadata: "@yao-pkg/pkg": 5.11.0 chalk: 4.1.2 es-aggregate-error: ^1.0.7 - fast-glob: ~3.2.12 hpagent: ~1.2.0 lodash: ~4.17.21 nock: ^13.5.4 pony-cause: ^1.1.1 stacktracey: ^2.1.8 + tinyglobby: ^0.2.14 tslib: ^2.8.1 xml2js: ^0.5.0 yargs: ~17.7.2 @@ -6896,32 +6896,6 @@ __metadata: languageName: node linkType: hard -"fast-glob@npm:^3.3.3": - version: 3.3.3 - resolution: "fast-glob@npm:3.3.3" - dependencies: - "@nodelib/fs.stat": ^2.0.2 - "@nodelib/fs.walk": ^1.2.3 - glob-parent: ^5.1.2 - merge2: ^1.3.0 - micromatch: ^4.0.8 - checksum: 0704d7b85c0305fd2cef37777337dfa26230fdd072dce9fb5c82a4b03156f3ffb8ed3e636033e65d45d2a5805a4e475825369a27404c0307f2db0c8eb3366fbd - languageName: node - linkType: hard - -"fast-glob@npm:~3.2.12": - version: 3.2.12 - resolution: "fast-glob@npm:3.2.12" - dependencies: - "@nodelib/fs.stat": ^2.0.2 - "@nodelib/fs.walk": ^1.2.3 - glob-parent: ^5.1.2 - merge2: ^1.3.0 - micromatch: ^4.0.4 - checksum: 0b1990f6ce831c7e28c4d505edcdaad8e27e88ab9fa65eedadb730438cfc7cde4910d6c975d6b7b8dc8a73da4773702ebcfcd6e3518e73938bb1383badfe01c2 - languageName: node - linkType: hard - "fast-json-stable-stringify@npm:2.x, fast-json-stable-stringify@npm:^2.0.0": version: 2.0.0 resolution: "fast-json-stable-stringify@npm:2.0.0" @@ -6982,6 +6956,18 @@ __metadata: languageName: node linkType: hard +"fdir@npm:^6.4.4": + version: 6.4.6 + resolution: "fdir@npm:6.4.6" + peerDependencies: + picomatch: ^3 || ^4 + peerDependenciesMeta: + picomatch: + optional: true + checksum: fe9f3014901d023cf631831dcb9eae5447f4d7f69218001dd01ecf007eccc40f6c129a04411b5cc273a5f93c14e02e971e17270afc9022041c80be924091eb6f + languageName: node + linkType: hard + "fetch-mock@npm:^9.11.0": version: 9.11.0 resolution: "fetch-mock@npm:9.11.0" @@ -10066,7 +10052,7 @@ __metadata: languageName: node linkType: hard -"micromatch@npm:^4.0.0, micromatch@npm:^4.0.2, micromatch@npm:^4.0.4, micromatch@npm:^4.0.8": +"micromatch@npm:^4.0.0, micromatch@npm:^4.0.2, micromatch@npm:^4.0.4": version: 4.0.8 resolution: "micromatch@npm:4.0.8" dependencies: @@ -11466,6 +11452,13 @@ __metadata: languageName: node linkType: hard +"picomatch@npm:^4.0.2": + version: 4.0.2 + resolution: "picomatch@npm:4.0.2" + checksum: a7a5188c954f82c6585720e9143297ccd0e35ad8072231608086ca950bee672d51b0ef676254af0788205e59bd4e4deb4e7708769226bed725bf13370a7d1464 + languageName: node + linkType: hard + "pify@npm:^3.0.0": version: 3.0.0 resolution: "pify@npm:3.0.0" @@ -12297,7 +12290,6 @@ __metadata: eslint-plugin-import: ^2.26.0 eslint-plugin-prettier: ^4.2.1 expect: ^27.5.1 - fast-glob: ^3.3.3 fetch-mock: ^9.11.0 file-entry-cache: ^6.0.1 husky: ^7.0.4 @@ -12315,6 +12307,7 @@ __metadata: patch-package: ^6.4.7 prettier: ^2.4.1 semantic-release: ^19.0.5 + tinyglobby: ^0.2.14 ts-jest: ^29.2.5 ts-node: ^10.8.2 typescript: 4.4.4 @@ -13358,6 +13351,16 @@ __metadata: languageName: node linkType: hard +"tinyglobby@npm:^0.2.14": + version: 0.2.14 + resolution: "tinyglobby@npm:0.2.14" + dependencies: + fdir: ^6.4.4 + picomatch: ^4.0.2 + checksum: 261e986e3f2062dec3a582303bad2ce31b4634b9348648b46828c000d464b012cf474e38f503312367d4117c3f2f18611992738fca684040758bba44c24de522 + languageName: node + linkType: hard + "tmp@npm:^0.0.33": version: 0.0.33 resolution: "tmp@npm:0.0.33"