Skip to content

Commit 67b0d5c

Browse files
fix(deps): replace glob with tinyglobby
1 parent dd16cfe commit 67b0d5c

7 files changed

Lines changed: 49 additions & 60 deletions

File tree

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"chalk": "5.6.2",
4646
"commander": "14.0.3",
4747
"enquirer": "2.4.1",
48-
"glob": "13.0.6",
4948
"ts-api-utils": "2.5.0"
5049
},
5150
"devDependencies": {

pnpm-lock.yaml

Lines changed: 0 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/collectFileNames.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ describe("collectFileNames", () => {
2020
`At least one path including node_modules was included implicitly: '${cwd}/node_modules'. Either adjust TypeStat's included files to not include node_modules (recommended) or explicitly include node_modules/ (not recommended).`,
2121
);
2222
});
23+
24+
it("should NOT return error if node_modules are explicitly included", async () => {
25+
const cwd = path.resolve(import.meta.dirname, "..");
26+
const fileNames = await collectFileNames(cwd, ["node_modules"]);
27+
expect(fileNames?.length).toBeGreaterThan(0);
28+
});
2329
});

src/collectFileNames.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import { glob } from "glob";
2-
import * as path from "node:path";
1+
import path from "node:path";
2+
import { glob } from "node:fs/promises";
33

44
export const collectFileNames = async (
55
cwd: string,
66
include: readonly string[] | undefined,
77
): Promise<readonly string[] | string | undefined> => {
8-
const globsAndNames = await collectFileNamesFromGlobs(cwd, include);
9-
if (!globsAndNames) {
8+
if (include === undefined) {
109
return undefined;
1110
}
1211

13-
const [fileGlobs, fileNames] = globsAndNames;
12+
const fileNames = await collectFileNamesFromGlobs(cwd, include);
1413
const implicitNodeModulesInclude = implicitNodeModulesIncluded(
15-
fileGlobs,
14+
include,
1615
fileNames,
1716
);
1817

@@ -25,24 +24,21 @@ export const collectFileNames = async (
2524

2625
const collectFileNamesFromGlobs = async (
2726
cwd: string,
28-
include: readonly string[] | undefined,
29-
): Promise<[readonly string[], readonly string[]] | undefined> => {
30-
if (include === undefined) {
31-
return undefined;
27+
include: readonly string[],
28+
): Promise<readonly string[]> => {
29+
let fileNames: string[] = [];
30+
for await (const entry of glob(include, { cwd, withFileTypes: true })) {
31+
fileNames.push(path.join(entry.parentPath, entry.name));
3232
}
33-
34-
return [
35-
include,
36-
await glob(include.map((subInclude) => path.join(cwd, subInclude))),
37-
];
33+
return fileNames;
3834
};
3935

4036
const implicitNodeModulesIncluded = (
4137
fileGlobs: readonly string[],
42-
fileNames: readonly string[] | undefined,
43-
) => {
38+
fileNames: readonly string[],
39+
): boolean => {
4440
return (
4541
!fileGlobs.some((glob) => glob.includes("node_modules")) &&
46-
fileNames?.find((fileName) => fileName.includes("node_modules"))
42+
fileNames.some((fileName) => fileName.includes("node_modules"))
4743
);
4844
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, it } from "vitest";
2+
import { getTsConfigPaths } from "./index.js";
3+
4+
describe("getTsConfigPaths", () => {
5+
it("should collect list of tsconfig files", async () => {
6+
const cwd = process.cwd();
7+
const fileNames = await getTsConfigPaths();
8+
expect(fileNames).toHaveLength(2);
9+
expect(fileNames).toContain(`${cwd}/tsconfig.eslint.json`);
10+
expect(fileNames).toContain(`${cwd}/tsconfig.json`);
11+
});
12+
});

src/initialization/initializeProject/index.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import enquirer from "enquirer";
2-
import * as fs from "fs";
3-
import { glob } from "glob";
2+
import { existsSync } from "node:fs";
3+
import { glob } from "node:fs/promises";
4+
import path from "node:path";
45

56
import { uniquify } from "../../shared/arrays.js";
67
import { initializeNewProject } from "./initializeNewProject.js";
@@ -32,7 +33,7 @@ const initializeBuiltInProject = async () => {
3233
...uniquify(
3334
TSConfigLocation.Root,
3435
TSConfigLocation.UnderSrc,
35-
...(await glob(["./tsconfig*json", "./*/tsconfig*json"])),
36+
...(await getTsConfigPaths()),
3637
),
3738
TSConfigLocationSuggestion.Custom,
3839
TSConfigLocationSuggestion.DoesNotExist,
@@ -47,7 +48,7 @@ const initializeBuiltInProject = async () => {
4748
initial: Math.max(
4849
0,
4950
[TSConfigLocation.Root, TSConfigLocation.UnderSrc].findIndex((choice) =>
50-
fs.existsSync(choice),
51+
existsSync(choice),
5152
),
5253
),
5354
type: "select",
@@ -57,6 +58,15 @@ const initializeBuiltInProject = async () => {
5758
return project;
5859
};
5960

61+
export const getTsConfigPaths = async (): Promise<string[]> => {
62+
const cwd = process.cwd();
63+
let fileNames: string[] = [];
64+
for await (const entry of glob(["./tsconfig*json", "./*/tsconfig*json"])) {
65+
fileNames.push(path.join(cwd, entry));
66+
}
67+
return fileNames;
68+
};
69+
6070
const initializeCustomProject = async (): Promise<ProjectDescription> => {
6171
const { project } = await prompt<{ project: string }>([
6272
{

src/mutators/builtIn/fixImportExtensions/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TextInsertMutation } from "automutate";
2-
import { glob } from "glob";
3-
import * as path from "node:path";
2+
import path from "node:path";
3+
import { globSync } from "node:fs";
44
import ts from "typescript";
55

66
import {
@@ -58,7 +58,7 @@ const visitExportOrImportDeclaration = (
5858

5959
for (const filePath of [basePath, path.join(basePath, "index")]) {
6060
// If no files exist under that path, ignore this possibility
61-
const possibilities = glob.sync(filePath + ".*");
61+
const possibilities = globSync(filePath + ".*");
6262
if (possibilities.length === 0) {
6363
continue;
6464
}

0 commit comments

Comments
 (0)