Skip to content

Commit

Permalink
fix(dts-fix): handle findBase corner cases
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jan 31, 2024
1 parent 4fee230 commit 0b60bcd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
15 changes: 9 additions & 6 deletions src/main/ts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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
},
Expand All @@ -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))))
}

8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0b60bcd

Please sign in to comment.