diff --git a/src/cli/runCli.ts b/src/cli/runCli.ts index e598d757c..174257ba6 100644 --- a/src/cli/runCli.ts +++ b/src/cli/runCli.ts @@ -63,7 +63,7 @@ export const runCli = async ( let result: TypeStatResult; try { - result = await runtime.mainRunner(rawOptions, runtime.output); + result = await runtime.mainRunner(rawOptions.config, runtime.output); } catch (error) { result = { error: error instanceof Error ? error : new Error(error as string), diff --git a/src/collectFileNames.test.ts b/src/collectFileNames.test.ts new file mode 100644 index 000000000..22e98b1a6 --- /dev/null +++ b/src/collectFileNames.test.ts @@ -0,0 +1,23 @@ +import path from "node:path"; +import { describe, expect, it } from "vitest"; + +import { collectFileNames } from "./collectFileNames.js"; + +describe("collectFileNames", () => { + it("should collect files with wildcard when collection succeeds", async () => { + const cwd = path.resolve(import.meta.dirname, ".."); + const fileNames = await collectFileNames( + path.resolve(import.meta.dirname), + ["*"], + ); + expect(fileNames).toContain(`${cwd}/src/collectFileNames.test.ts`); + }); + + it("should return error if node_modules are implicitly included", async () => { + const cwd = path.resolve(import.meta.dirname, ".."); + const fileNames = await collectFileNames(cwd, ["*"]); + expect(fileNames).toEqual( + `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).`, + ); + }); +}); diff --git a/src/collectFileNames.ts b/src/collectFileNames.ts index b58812106..3dff3157b 100644 --- a/src/collectFileNames.ts +++ b/src/collectFileNames.ts @@ -1,14 +1,11 @@ import { glob } from "glob"; import * as path from "node:path"; -import { TypeStatArgv } from "./index.js"; - export const collectFileNames = async ( - argv: TypeStatArgv, cwd: string, include: readonly string[] | undefined, ): Promise => { - const globsAndNames = await collectFileNamesFromGlobs(argv, cwd, include); + const globsAndNames = await collectFileNamesFromGlobs(cwd, include); if (!globsAndNames) { return undefined; } @@ -27,14 +24,9 @@ export const collectFileNames = async ( }; const collectFileNamesFromGlobs = async ( - argv: TypeStatArgv, cwd: string, include: readonly string[] | undefined, ): Promise<[readonly string[], readonly string[]] | undefined> => { - if (argv.args.length) { - return [argv.args, await glob(argv.args)]; - } - if (include === undefined) { return undefined; } diff --git a/src/index.ts b/src/index.ts index 12ee31279..71685c1df 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,10 +44,10 @@ export interface SucceededResult { } export const typeStat = async ( - argv: TypeStatArgv, + configPath: string | undefined, output: ProcessOutput, ): Promise => { - const allPendingOptions = await tryLoadingPendingOptions(argv, output); + const allPendingOptions = await tryLoadingPendingOptions(configPath, output); if ( allPendingOptions instanceof Error || typeof allPendingOptions === "string" @@ -82,7 +82,7 @@ export const typeStat = async ( chalk.green( ` options ${pluralize(allPendingOptions.length, "object")} specified in `, ), - chalk.greenBright(argv.config), + chalk.greenBright(configPath), chalk.green(` to modify your source code.`), ].join(""), ); @@ -91,7 +91,6 @@ export const typeStat = async ( for (let i = 0; i < allPendingOptions.length; i += 1) { // Collect all files to be run on this option iteration from the include glob(s) const fileNames = await collectFileNames( - argv, process.cwd(), allPendingOptions[i].include, ); @@ -146,11 +145,11 @@ export const typeStat = async ( }; const tryLoadingPendingOptions = async ( - argv: TypeStatArgv, + configPath: string | undefined, output: ProcessOutput, ): Promise => { try { - return await loadPendingOptions(argv, output); + return await loadPendingOptions(configPath, output); } catch (error) { return error instanceof Error ? error : new Error(error as string); } diff --git a/src/options/fillOutRawOptions.ts b/src/options/fillOutRawOptions.ts index 6fc796100..688a8d3ba 100644 --- a/src/options/fillOutRawOptions.ts +++ b/src/options/fillOutRawOptions.ts @@ -1,4 +1,3 @@ -import { TypeStatArgv } from "../index.js"; import { ProcessOutput } from "../output/types.js"; import { collectOptionals } from "../shared/arrays.js"; import { ReactPropTypesHint, ReactPropTypesOptionality } from "./enums.js"; @@ -12,7 +11,6 @@ import { collectStrictNullChecks } from "./parsing/collectStrictNullChecks.js"; import { PendingTypeStatOptions, RawTypeStatOptions } from "./types.js"; export interface OptionsFromRawOptionsSettings { - argv: TypeStatArgv; compilerOptions: Readonly; cwd: string; output: ProcessOutput; diff --git a/src/options/loadPendingOptions.ts b/src/options/loadPendingOptions.ts index aee74384e..083fd3ad6 100644 --- a/src/options/loadPendingOptions.ts +++ b/src/options/loadPendingOptions.ts @@ -1,6 +1,5 @@ import * as path from "node:path"; -import { TypeStatArgv } from "../index.js"; import { ProcessOutput } from "../output/types.js"; import { normalizeAndSlashify } from "../shared/paths.js"; import { fillOutRawOptions } from "./fillOutRawOptions.js"; @@ -11,20 +10,18 @@ import { PendingTypeStatOptions, RawTypeStatOptions } from "./types.js"; /** * Reads pre-file-rename TypeStat options using a config path. - * @param argv Root arguments passed to TypeStat. - * @param output Wraps process and logfile output. * @returns Promise for filled-out TypeStat options, or a string complaint from failing to make them. */ export const loadPendingOptions = async ( - argv: TypeStatArgv, + configPath: string | undefined, output: ProcessOutput, ): Promise => { - if (argv.config === undefined) { + if (configPath === undefined) { return "-c/--config file must be provided."; } const cwd = process.cwd(); - const foundRawOptions = findRawOptions(cwd, argv.config); + const foundRawOptions = findRawOptions(cwd, configPath); if (typeof foundRawOptions === "string") { return foundRawOptions; } @@ -40,7 +37,6 @@ export const loadPendingOptions = async ( const compilerOptions = await parseRawCompilerOptions(cwd, projectPath); const filledOutOptions = fillOutRawOptions({ - argv, compilerOptions, cwd, output, diff --git a/src/tests/testSetup.ts b/src/tests/testSetup.ts index c87cbfcb3..0514782bf 100644 --- a/src/tests/testSetup.ts +++ b/src/tests/testSetup.ts @@ -49,7 +49,6 @@ export const runMutationTest = async ( }; const pendingOptions = fillOutRawOptions({ - argv: { args: [] }, compilerOptions, cwd: dirPath, output,