From 51be9cd24976c5c4d92db1b9ac4f563aea83f0f6 Mon Sep 17 00:00:00 2001 From: gwansikk Date: Tue, 3 Dec 2024 16:29:12 +0900 Subject: [PATCH] refactor: simplify loadModule --- packages/react-query/src/bin/utils/package.ts | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/packages/react-query/src/bin/utils/package.ts b/packages/react-query/src/bin/utils/package.ts index c763e232a..4306c3472 100644 --- a/packages/react-query/src/bin/utils/package.ts +++ b/packages/react-query/src/bin/utils/package.ts @@ -1,12 +1,11 @@ import fs from 'node:fs' import path from 'node:path' -type LoadModuleResult = { exports: T; isSuccess: true } - -export function loadModule(name: string): LoadModuleResult { +// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters +export function loadModule(name: string): T { try { // eslint-disable-next-line @typescript-eslint/no-require-imports - return { exports: require(name) as T, isSuccess: true } + return require(name) as T } catch { throw new Error(`${name} is not found.`) } @@ -19,19 +18,15 @@ type PackageJson = { } export function getPackageJson(): PackageJson { - const module = loadModule('@suspensive/react-query/package.json') - - return module.exports + return loadModule('@suspensive/react-query/package.json') } export function getTanStackReactQueryPackageJson(): PackageJson { - const module = loadModule('@tanstack/react-query/package.json') - - return module.exports + return loadModule('@tanstack/react-query/package.json') } export function getSuspensiveReactQueryPackageJson(targetVersion: string): PackageJson { - let module: LoadModuleResult + let module: PackageJson switch (targetVersion) { case '5': @@ -44,7 +39,7 @@ export function getSuspensiveReactQueryPackageJson(targetVersion: string): Packa throw new Error(`@suspensive/react-query-${targetVersion} is not found.`) } - return module.exports + return module } export function getIndexFileContent(...paths: string[]): string { @@ -71,8 +66,7 @@ export function getTargetSuspensiveReactQueryAPIs(): string[] { for (const [, moduleName] of modules) { const module = loadModule>(moduleName) - - results.push(...Object.keys(module.exports).reverse()) + results.push(...Object.keys(module).reverse()) } return results