From 0b60bcd8d8968bab28e2c228fe38703ca7bc53e9 Mon Sep 17 00:00:00 2001 From: Anton Golub Date: Wed, 31 Jan 2024 22:08:43 +0300 Subject: [PATCH] fix(dts-fix): handle findBase corner cases --- package.json | 2 +- src/main/ts/util.ts | 15 +++++++++------ yarn.lock | 8 ++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index bdd67b1..f567b59 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "meow": "^11.0.0", "pkg-dir": "^7.0.0", "tempy": "^3.1.0", - "tsc-dts-fix": "^0.0.7", + "tsc-dts-fix": "^0.0.8", "tslib": "^2.6.2" }, "devDependencies": { diff --git a/src/main/ts/util.ts b/src/main/ts/util.ts index d2b789f..2609500 100644 --- a/src/main/ts/util.ts +++ b/src/main/ts/util.ts @@ -2,7 +2,7 @@ /** */ import cp, { StdioOptions } from 'node:child_process' -import { dirname, resolve } from 'node:path' +import path from 'node:path' import { fileURLToPath } from 'node:url' import chalk from 'chalk' @@ -11,7 +11,7 @@ import { packageDirectorySync } from 'pkg-dir' import { ICmdInvokeOptions, TFlags } from './interface.js' -const __dirname = dirname(fileURLToPath(import.meta.url)) +const __dirname = path.dirname(fileURLToPath(import.meta.url)) export const STDIO_INHERIT: StdioOptions = ['inherit', 'inherit', 'inherit'] export const STDIO_NULL: StdioOptions = [null, null, null] // eslint-disable-line @@ -92,7 +92,7 @@ export const formatArgs = ( export const findBin = (cmd: string, cwd: string) => findUpSync( (dir) => { - const ref = resolve(dir, 'node_modules', '.bin', cmd) + const ref = path.resolve(dir, 'node_modules', '.bin', cmd) return pathExistsSync(ref) ? ref : undefined }, @@ -107,11 +107,14 @@ export const getClosestBin = ( findBin(cmd, packageDirectorySync({ cwd: __dirname }) as string) || cmd -export const findCommon = (files: string[]) => { +const dirname = (f: string) => f.endsWith('/') ? f : path.dirname(f) + '/' +export const findBase = (files: string[]) => { + const first = files[0] + if (files.length === 0) return '' + if (files.length === 1) return dirname(first) - const first = files[0] // eslint-disable-next-line - return first.slice(0, first.split('').findIndex((c, i) => files.some(f => f.charAt(i) !== c))) + return dirname(first.slice(0, first.split('').findIndex((c, i) => files.some(f => f.charAt(i) !== c)))) } diff --git a/yarn.lock b/yarn.lock index b0bf761..f3cd683 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4054,10 +4054,10 @@ ts-jest@^29.1.2: semver "^7.5.3" yargs-parser "^21.0.1" -tsc-dts-fix@^0.0.7: - version "0.0.7" - resolved "https://registry.yarnpkg.com/tsc-dts-fix/-/tsc-dts-fix-0.0.7.tgz#f1315a52b9e87bcffc2c00ad27eb00a0b1d64641" - integrity sha512-9hLXK7+dQFmGDcbDR2Sm0sBWwZRMg8jR/lBWnGgoEKWamcTBRtmLuAx0TqMcWKI3xkEgaVuK+07Zlp4exb+Aww== +tsc-dts-fix@^0.0.8: + version "0.0.8" + resolved "https://registry.yarnpkg.com/tsc-dts-fix/-/tsc-dts-fix-0.0.8.tgz#be0870fcf2f2f530677cfce183b3a871d303ecbd" + integrity sha512-As8cFCXPgrr9gjf/hblApNfY1u/95lxSz1MC1Sxe25/BnJYXcGuPY3Wfj2j9fq8Z2I6AlR636UCbUnKY2XwupQ== dependencies: "@topoconfig/extends" "0.1.9" depseek "0.2.4"