forked from LeDDGroup/typescript-transform-paths
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: OSX paths can be rewritten improperly (fixes LeDDGroup#167)
- Loading branch information
1 parent
04fd73c
commit 8b663a3
Showing
2 changed files
with
20 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,30 @@ | ||
import url from "url"; | ||
import path from "path"; | ||
import { realpathSync } from "fs"; | ||
|
||
/* ****************************************************************************************************************** * | ||
* General Utilities & Helpers | ||
* ****************************************************************************************************************** */ | ||
|
||
export const isURL = (s: string): boolean => !!s && (!!url.parse(s).host || !!url.parse(s).hostname); | ||
|
||
export const cast = <T>(v: any): T => v; | ||
|
||
export const isBaseDir = (baseDir: string, testDir: string): boolean => { | ||
const relative = path.relative(baseDir, testDir); | ||
return relative ? !relative.startsWith("..") && !path.isAbsolute(relative) : true; | ||
}; | ||
|
||
export const maybeAddRelativeLocalPrefix = (p: string) => (p[0] === "." ? p : `./${p}`); | ||
|
||
export function tryRealpathNative(value: string) { | ||
try { | ||
return realpathSync.native(value); | ||
} catch { | ||
return value; | ||
} | ||
} | ||
|
||
export function nativeRelativePath(from: string, to: string) { | ||
return path.relative(tryRealpathNative(from), tryRealpathNative(to)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters