From c647e6020b9dc6498c48e1e4ced61da9a82ea7df Mon Sep 17 00:00:00 2001 From: Guz013 <43732358+Guz013@users.noreply.github.com> Date: Fri, 21 Jul 2023 16:56:20 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20remove=20unnecessary=20ts?= =?UTF-8?q?configs.js=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/config/src/tsconfigs.js | 87 -------------------------------- 1 file changed, 87 deletions(-) delete mode 100644 packages/config/src/tsconfigs.js diff --git a/packages/config/src/tsconfigs.js b/packages/config/src/tsconfigs.js deleted file mode 100644 index 2811c05..0000000 --- a/packages/config/src/tsconfigs.js +++ /dev/null @@ -1,87 +0,0 @@ -import { existsSync } from 'node:fs'; -import { readFile } from 'node:fs/promises'; -import { join, normalize } from 'node:path'; - -/** @type {(...path: string[]) => string} */ -function toPath(...path) { - return normalize(join(...path)); -} - -/** @type {(...path: string[]) => boolean} */ -function exists(...path) { - return existsSync(toPath(...path)); -} - -/** - * @param {string} directory what the root directory to detect an workspace/monorepo configuration file - * @returns {Promise} list of possible paths of packages' tsconfig.json and jsconfig.json files - */ -async function getMonorepoConfigs(directory) { - - /** @type {string[]} */ - const paths = []; - - if (exists(directory, 'pnpm-workspace.yaml') || exists(directory, 'pnpm-workspace.yml')) { - - const YAML = await import('yaml'); - - const yamlFilePath = exists(directory, 'pnpm-workspace.yaml') - ? join(directory, 'pnpm-workspace.yaml') - : join(directory, 'pnpm-workspace.yml'); - - /** @type {{packages?: string[], [properties: string]: unknown}} */ - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const pnpmWorkspaces = YAML.parse(await readFile(yamlFilePath, 'utf-8')); - - const files = pnpmWorkspaces.packages?.map(w => [ - toPath(directory, w, 'tsconfig.json'), - toPath(directory, w, 'jsconfig.json'), - ]).flat() ?? []; - - paths.push(...files); - - } - else if (exists(directory, 'package.json')) { - /** @type {{workspaces?: string[], [properties: string]: unknown}} */ - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const packageJson = JSON.parse(await readFile(join(directory, 'package.json'), 'utf-8')); - - const files = packageJson.workspaces?.map(w => [ - toPath(directory, w, 'tsconfig.json'), - toPath(directory, w, 'jsconfig.json'), - ]).flat() ?? []; - - paths.push(...files); - - } - - return paths; - -} - -/** - * @param {string} directory what the root directory to work on - * @returns {Promise} list of tsconfig.json and jsconfig.json file paths - */ -export async function getTsConfigs(directory) { - - const rootTSConfig = exists(directory, 'tsconfig.eslint.json') - ? toPath(directory, 'tsconfig.eslint.json') - : exists(directory, 'tsconfig.json') - ? toPath(directory, 'tsconfig.json') - : undefined; - - const rootJSConfig = exists(directory, 'jsconfig.eslint.json') - ? toPath(directory, 'jsconfig.eslint.json') - : exists(directory, 'jsconfig.json') - ? toPath(directory, 'jsconfig.json') - : undefined; - - const monorepoConfigs = await getMonorepoConfigs(directory); - - const paths = /** @type {string[]} */ - ([rootTSConfig, rootJSConfig, ...monorepoConfigs]).filter(p => p); - - return paths; - -}