From 377e34344c89dd7445b8eed73247ac3e765bdbee Mon Sep 17 00:00:00 2001 From: Senja Jarva Date: Thu, 15 Dec 2022 16:24:54 +0200 Subject: [PATCH] chore: change globby library to glob Closes #2370 --- @commitlint/config-lerna-scopes/index.js | 15 +++++++-------- @commitlint/config-lerna-scopes/package.json | 2 +- @commitlint/config-patternplate/index.js | 8 +++----- @commitlint/config-patternplate/package.json | 2 +- @commitlint/ensure/package.json | 2 +- @commitlint/ensure/src/index.test.ts | 8 ++++---- @commitlint/rules/package.json | 2 +- @commitlint/rules/src/index.test.ts | 10 +++++----- yarn.lock | 4 ++-- 9 files changed, 25 insertions(+), 28 deletions(-) diff --git a/@commitlint/config-lerna-scopes/index.js b/@commitlint/config-lerna-scopes/index.js index b82ce0922c..0d7f05e295 100644 --- a/@commitlint/config-lerna-scopes/index.js +++ b/@commitlint/config-lerna-scopes/index.js @@ -1,7 +1,7 @@ +const glob = require('glob'); const Path = require('path'); const importFrom = require('import-from'); const resolvePkg = require('resolve-pkg'); -const Globby = require('globby'); const semver = require('semver'); module.exports = { @@ -21,14 +21,13 @@ function getPackages(context) { const {workspaces} = require(Path.join(cwd, 'package.json')); if (Array.isArray(workspaces) && workspaces.length) { // use yarn workspaces - return Globby( - workspaces.map((ws) => { - return Path.posix.join(ws, 'package.json'); - }), - {cwd, ignore: ['**/node_modules/**']} - ).then((pJsons = []) => { - return pJsons.map((pJson) => require(Path.join(cwd, pJson))); + + const wsGlobs = workspaces.flatMap((ws) => { + const path = Path.posix.join(ws, 'package.json'); + return glob.sync(path, {cwd, ignore: ['**/node_modules/**']}); }); + + return wsGlobs.map((pJson) => require(Path.join(cwd, pJson))); } const lernaVersion = getLernaVersion(cwd); diff --git a/@commitlint/config-lerna-scopes/package.json b/@commitlint/config-lerna-scopes/package.json index 6d76cd74e5..2c6dfe0dae 100644 --- a/@commitlint/config-lerna-scopes/package.json +++ b/@commitlint/config-lerna-scopes/package.json @@ -38,7 +38,7 @@ "node": ">=v14" }, "dependencies": { - "globby": "^11.0.1", + "glob": "^8.0.3", "import-from": "4.0.0", "resolve-pkg": "2.0.0", "semver": "7.3.7" diff --git a/@commitlint/config-patternplate/index.js b/@commitlint/config-patternplate/index.js index 7abaece74c..478ddc7941 100644 --- a/@commitlint/config-patternplate/index.js +++ b/@commitlint/config-patternplate/index.js @@ -1,5 +1,5 @@ +const glob = require('glob'); const path = require('path'); -const globby = require('globby'); const merge = require('lodash.merge'); function pathToId(root, filePath) { @@ -9,10 +9,8 @@ function pathToId(root, filePath) { function getPatternIDs() { const root = path.resolve(process.cwd(), './patterns'); - const glob = path.resolve(root, '**/pattern.json'); - return globby(glob).then((results) => - results.map((result) => pathToId(root, result)) - ); + const pattern = path.resolve(root, '**/pattern.json'); + return glob.sync(pattern).map((result) => pathToId(root, result)); } module.exports = merge(require('@commitlint/config-angular'), { diff --git a/@commitlint/config-patternplate/package.json b/@commitlint/config-patternplate/package.json index 2c3a5691bb..31850a32c6 100644 --- a/@commitlint/config-patternplate/package.json +++ b/@commitlint/config-patternplate/package.json @@ -31,7 +31,7 @@ }, "dependencies": { "@commitlint/config-angular": "^17.3.0", - "globby": "^11.0.0", + "glob": "^8.0.3", "lodash.merge": "^4.6.2" }, "devDependencies": { diff --git a/@commitlint/ensure/package.json b/@commitlint/ensure/package.json index 79a8d27862..cd1f070a50 100644 --- a/@commitlint/ensure/package.json +++ b/@commitlint/ensure/package.json @@ -41,7 +41,7 @@ "@types/lodash.snakecase": "^4.1.7", "@types/lodash.startcase": "^4.4.7", "@types/lodash.upperfirst": "^4.3.7", - "globby": "^11.0.0" + "glob": "^8.0.3" }, "dependencies": { "@commitlint/types": "^17.0.0", diff --git a/@commitlint/ensure/src/index.test.ts b/@commitlint/ensure/src/index.test.ts index d8928a3cb0..e14f9e4bc0 100644 --- a/@commitlint/ensure/src/index.test.ts +++ b/@commitlint/ensure/src/index.test.ts @@ -1,11 +1,11 @@ import path from 'path'; -import globby from 'globby'; +import glob from 'glob'; import camelCase from 'lodash.camelcase'; import * as ensure from '.'; test('exports all checkers', async () => { const ignore = ['types']; - const expected = (await glob('*.ts')) + const expected = _glob('*.ts') .map((f) => camelCase(f)) .sort() .filter((item) => !ignore.includes(item)); @@ -18,8 +18,8 @@ test('rules export functions', () => { expect(actual.every((rule) => typeof rule === 'function')).toBe(true); }); -async function glob(pattern: string): Promise { - const files = await globby(pattern, { +function _glob(pattern: string): string[] { + const files = glob.sync(pattern, { ignore: ['**/index.ts', '**/*.test.ts'], cwd: __dirname, }); diff --git a/@commitlint/rules/package.json b/@commitlint/rules/package.json index bf61654469..cadd1acf39 100644 --- a/@commitlint/rules/package.json +++ b/@commitlint/rules/package.json @@ -39,7 +39,7 @@ "@commitlint/test": "^17.2.0", "@commitlint/utils": "^17.0.0", "conventional-changelog-angular": "5.0.13", - "globby": "^11.0.0" + "glob": "^8.0.3" }, "dependencies": { "@commitlint/ensure": "^17.3.0", diff --git a/@commitlint/rules/src/index.test.ts b/@commitlint/rules/src/index.test.ts index 1eaf0010e3..e31802ebd8 100644 --- a/@commitlint/rules/src/index.test.ts +++ b/@commitlint/rules/src/index.test.ts @@ -1,10 +1,10 @@ import path from 'path'; import fs from 'fs'; -import globby from 'globby'; +import glob from 'glob'; import rules from '.'; -test('exports all rules', async () => { - const expected = (await glob('*.ts')).sort(); +test('exports all rules', () => { + const expected = _glob('*.ts').sort(); const actual = Object.keys(rules).sort(); expect(actual).toEqual(expected); }); @@ -27,8 +27,8 @@ test('all rules are present in documentation', () => { expect(Object.keys(rules)).toEqual(expect.arrayContaining(results)); }); -async function glob(pattern: string | string[]) { - const files = await globby(pattern, { +function _glob(pattern: string) { + const files = glob.sync(pattern, { ignore: ['**/index.ts', '**/*.test.ts'], cwd: __dirname, }); diff --git a/yarn.lock b/yarn.lock index a7040932d3..796f32ca77 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6155,7 +6155,7 @@ glob@7.2.3, glob@^7.1.3, glob@^7.1.4: once "^1.3.0" path-is-absolute "^1.0.0" -glob@^8.0.1: +glob@^8.0.1, glob@^8.0.3: version "8.0.3" resolved "https://registry.npmjs.org/glob/-/glob-8.0.3.tgz#415c6eb2deed9e502c68fa44a272e6da6eeca42e" integrity sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ== @@ -6212,7 +6212,7 @@ globals@^13.15.0: dependencies: type-fest "^0.20.2" -globby@^11.0.0, globby@^11.0.1, globby@^11.0.2, globby@^11.1.0: +globby@^11.0.1, globby@^11.0.2, globby@^11.1.0: version "11.1.0" resolved "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b" integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==