Skip to content
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

chore: change globby library to glob #3438

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions @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 = {
Expand All @@ -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)));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the part that needed some more modification - glob does not accept an array of strings, I decided to loop over the workspaces array. The flapMap is needed because glob.sync returns an array.

Copy link
Member

Choose a reason for hiding this comment

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

Tbh I rely on the tests here. If all tests still pass we should be able to expect we're good.

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);
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/config-lerna-scopes/package.json
Expand Up @@ -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"
Expand Down
8 changes: 3 additions & 5 deletions @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) {
Expand All @@ -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'), {
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/config-patternplate/package.json
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/ensure/package.json
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions @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));
Expand All @@ -18,8 +18,8 @@ test('rules export functions', () => {
expect(actual.every((rule) => typeof rule === 'function')).toBe(true);
});

async function glob(pattern: string): Promise<string[]> {
const files = await globby(pattern, {
function _glob(pattern: string): string[] {
const files = glob.sync(pattern, {
ignore: ['**/index.ts', '**/*.test.ts'],
cwd: __dirname,
});
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/rules/package.json
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions @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);
});
Expand All @@ -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,
});
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Expand Up @@ -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==
Expand Down Expand Up @@ -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==
Expand Down