Skip to content

Commit

Permalink
fix: prefer fast-glob to globby
Browse files Browse the repository at this point in the history
  • Loading branch information
exKAZUu committed Jan 19, 2025
1 parent a22b576 commit c83c3b6
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 22 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
"dependencies": {
"@octokit/core": "6.1.3",
"@willbooster/shared-lib": "5.2.8",
"@willbooster/shared-lib-node": "6.0.6",
"deepmerge": "4.3.1",
"dotenv": "16.4.7",
"fast-glob": "3.3.3",
"fastest-levenshtein": "1.0.16",
"globby": "14.0.2",
"js-yaml": "4.1.0",
"libsodium-wrappers": "0.7.15",
"lodash.clonedeep": "4.5.0",
Expand Down
5 changes: 3 additions & 2 deletions src/fixers/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import fs from 'node:fs/promises';
import path from 'node:path';

import { globby } from 'globby';
import fg from 'fast-glob';

import { logger } from '../logger.js';
import type { PackageConfig } from '../packageConfig.js';
import { globIgnore } from '../utils/globUtil.js';

export async function fixPrismaEnvFiles(config: PackageConfig): Promise<void> {
return logger.functionIgnoringException('fixPrismaEnvFiles', async () => {
const envFiles = await globby(['*.env', '*.env.*'], { dot: true, cwd: config.dirPath });
const envFiles = await fg.glob(['*.env', '*.env.*'], { dot: true, cwd: config.dirPath, ignore: globIgnore });
for (const envFile of envFiles) {
const envFilePath = path.resolve(config.dirPath, envFile);
const content = await fs.readFile(envFilePath, 'utf8');
Expand Down
13 changes: 7 additions & 6 deletions src/fixers/typos.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import fs from 'node:fs';
import path from 'node:path';

import { globby } from 'globby';
import fg from 'fast-glob';

import { logger } from '../logger.js';
import { options } from '../options.js';
import type { PackageConfig } from '../packageConfig.js';
import { fsUtil } from '../utils/fsUtil.js';
import { globIgnore } from '../utils/globUtil.js';
import { promisePool } from '../utils/promisePool.js';

export async function fixTypos(packageConfig: PackageConfig): Promise<void> {
return logger.functionIgnoringException('fixTypos', async () => {
const dirPath = packageConfig.dirPath;
const docFiles = await globby('**/*.md', { dot: true, cwd: dirPath, gitignore: true });
const docFiles = await fg.glob('**/*.md', { dot: true, cwd: dirPath, ignore: globIgnore });
if (options.isVerbose) {
console.info(`Found ${docFiles.length} markdown files in ${dirPath}`);
}
Expand All @@ -28,12 +29,12 @@ export async function fixTypos(packageConfig: PackageConfig): Promise<void> {
});
}

const tsFiles = await globby(
const tsFiles = await fg.glob(
[
'{app,src,tests,scripts}/**/*.{cjs,mjs,js,jsx,cts,mts,ts,tsx}',
'packages/**/{app,src,tests,scripts}/**/*.{cjs,mjs,js,jsx,cts,mts,ts,tsx}',
],
{ dot: true, cwd: dirPath, gitignore: true }
{ dot: true, cwd: dirPath, ignore: globIgnore }
);
if (options.isVerbose) {
console.info(`Found ${tsFiles.length} TypeScript files in ${dirPath}`);
Expand All @@ -48,10 +49,10 @@ export async function fixTypos(packageConfig: PackageConfig): Promise<void> {
await fsUtil.generateFile(filePath, newContent);
}

const textBasedFiles = await globby('**/*.{csv,htm,html,tsv,xml,yaml,yml}', {
const textBasedFiles = await fg.glob('**/*.{csv,htm,html,tsv,xml,yaml,yml}', {
dot: true,
cwd: dirPath,
gitignore: true,
ignore: globIgnore,
});
if (options.isVerbose) {
console.info(`Found ${textBasedFiles.length} text-based files in ${dirPath}`);
Expand Down
16 changes: 8 additions & 8 deletions src/generators/packageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'node:fs';
import path from 'node:path';

import merge from 'deepmerge';
import { globby, globbySync } from 'globby';
import fg from 'fast-glob';
import type { PackageJson, SetRequired } from 'type-fest';

import { getLatestCommitHash } from '../github/commit.js';
Expand All @@ -11,6 +11,7 @@ import type { EslintExtensionBase, PackageConfig } from '../packageConfig.js';
import { EslintUtil } from '../utils/eslintUtil.js';
import { extensions } from '../utils/extensions.js';
import { gitHubUtil } from '../utils/githubUtil.js';
import { globIgnore } from '../utils/globUtil.js';
import { ignoreFileUtil } from '../utils/ignoreFileUtil.js';
import { combineMerge } from '../utils/mergeUtil.js';
import { promisePool } from '../utils/promisePool.js';
Expand Down Expand Up @@ -174,10 +175,10 @@ async function core(config: PackageConfig, rootConfig: PackageConfig, skipAdding
} else if (Array.isArray(jsonObj.workspaces)) {
jsonObj.workspaces = jsonObj.workspaces.filter(
(workspace) =>
globbySync(workspace, {
fg.globSync(workspace, {
dot: true,
cwd: config.dirPath,
gitignore: true,
ignore: globIgnore,
}).length > 0
);
if (jsonObj.workspaces.length === 0) {
Expand Down Expand Up @@ -285,11 +286,10 @@ async function core(config: PackageConfig, rootConfig: PackageConfig, skipAdding
if (jsonObj.scripts.postinstall === 'poetry install') {
delete jsonObj.scripts.postinstall;
}
const pythonFiles = await globby('**/*.py', {
const pythonFiles = await fg.glob('**/*.py', {
cwd: config.dirPath,
dot: true,
gitignore: true,
ignore: ['test-fixtures'],
ignore: globIgnore,
});
const dirNameSet = new Set<string>();
for (const pythonFile of pythonFiles) {
Expand Down Expand Up @@ -514,10 +514,10 @@ async function fixScriptNames(
for (const [oldName, newName] of oldAndNewScriptNames) {
newJsonText = newJsonText.replaceAll(oldName, newName);
}
const files = await globby(['**/*.{md,cjs,mjs,js,jsx,cts,mts,ts,tsx}', '**/Dockerfile'], {
const files = await fg.glob(['**/*.{md,cjs,mjs,js,jsx,cts,mts,ts,tsx}', '**/Dockerfile'], {
cwd: config.dirPath,
dot: true,
gitignore: true,
ignore: globIgnore,
});
for (const file of files) {
await promisePool.run(async () => {
Expand Down
5 changes: 3 additions & 2 deletions src/packageConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import fs from 'node:fs';
import fsp from 'node:fs/promises';
import path from 'node:path';

import { globbySync } from 'globby';
import fg from 'fast-glob';
import { simpleGit } from 'simple-git';
import type { PackageJson } from 'type-fest';
import { z } from 'zod';

import { gitHubUtil, octokit } from './utils/githubUtil.js';
import { globIgnore } from './utils/globUtil.js';

export interface PackageConfig {
dirPath: string;
Expand Down Expand Up @@ -233,7 +234,7 @@ export async function getPackageConfig(
}

function containsAny(pattern: string, dirPath: string): boolean {
return globbySync(pattern, { dot: true, cwd: dirPath }).length > 0;
return fg.globSync(pattern, { dot: true, cwd: dirPath, ignore: globIgnore }).length > 0;
}

export type EslintExtensionBase =
Expand Down
10 changes: 10 additions & 0 deletions src/utils/globUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const globIgnore = [
'**/node_modules/**',
'**/.venv/**',
'**/test-fixtures/**',
'**/dist/**',
'**/build/**',
'**/target/**',
'**/temp/**',
'**/tmp/**',
];
7 changes: 4 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6103,7 +6103,7 @@ __metadata:
languageName: node
linkType: hard

"fast-glob@npm:^3.2.2, fast-glob@npm:^3.3.2":
"fast-glob@npm:3.3.3, fast-glob@npm:^3.2.2, fast-glob@npm:^3.3.2":
version: 3.3.3
resolution: "fast-glob@npm:3.3.3"
dependencies:
Expand Down Expand Up @@ -6611,7 +6611,7 @@ __metadata:
languageName: node
linkType: hard

"globby@npm:14.0.2, globby@npm:^14.0.0":
"globby@npm:^14.0.0":
version: 14.0.2
resolution: "globby@npm:14.0.2"
dependencies:
Expand Down Expand Up @@ -12187,6 +12187,7 @@ __metadata:
"@willbooster/eslint-config-ts": "npm:10.6.1"
"@willbooster/prettier-config": "npm:9.1.3"
"@willbooster/shared-lib": "npm:5.2.8"
"@willbooster/shared-lib-node": "npm:6.0.6"
"@yarnpkg/core": "npm:4.2.0"
build-ts: "npm:13.1.12"
conventional-changelog-conventionalcommits: "npm:8.0.0"
Expand All @@ -12199,8 +12200,8 @@ __metadata:
eslint-plugin-sort-class-members: "npm:1.21.0"
eslint-plugin-sort-destructure-keys: "npm:2.0.0"
eslint-plugin-unicorn: "npm:56.0.1"
fast-glob: "npm:3.3.3"
fastest-levenshtein: "npm:1.0.16"
globby: "npm:14.0.2"
husky: "npm:9.1.7"
jest: "npm:29.7.0"
js-yaml: "npm:4.1.0"
Expand Down

0 comments on commit c83c3b6

Please sign in to comment.