import * as fs from "fs" ; import * as path from "path" ; param dirname export function sourceDir ( dirname ) { if ( ! path . isAbsolute ( dirname ) ) { throw new Error ( `'${ dirname } is not an absolute path` ) ; } return dirname . replace ( path . sep + "dist" , "" ) ; } param dirname export function findPackageDirs ( dirname ) { let root = null ; let repoRoot = null ; dirname = path . resolve ( dirname ) ; do { if ( root == null ) { const pkgJson = path . join ( dirname , "package.json" ) ; if ( fs . existsSync ( pkgJson ) ) root = dirname ; } const dotGit = path . join ( dirname , ".git" ) ; if ( fs . existsSync ( dotGit ) ) { repoRoot = dirname ; break ; } const parent = path . dirname ( dirname ) ; if ( parent === dirname ) { break ; } dirname = parent ; } while ( true ) ; if ( root == null ) { throw new Error ( `Error finding package directories` ) ; } return { root , repoRoot : repoRoot || "/dev/null" , test : path . join ( root , "test" ) , dist : path . join ( root , "dist" ) , } ; } export const utilsDirs = findPackageDirs ( __dirname ) ; export const repoRootDir = utilsDirs . repoRoot ; export const repoDirs = { "core" : path . join ( repoRootDir , "core" ) , "cli" : path . join ( repoRootDir , "cli" ) , "cloud" : path . join ( repoRootDir , "cloud" ) , "dom-parser" : path . join ( repoRootDir , "dom-parser" ) , "testutils" : path . join ( repoRootDir , "testutils" ) , "utils" : path . join ( repoRootDir , "utils" ) , } ; export function normalizeWithDrive ( p , cwd = process . cwd ( ) ) { const root = path . parse ( cwd ) . root ; return path . normalize ( path . join ( root , p ) ) ; } param p export function posixPath ( p ) { if ( process . platform !== "win32" ) return p ; return path . posix . join ( ... p . split ( path . sep ) ) ; }