UNPKG

@jsenv/util

Version:

Set of functions often needed when using Node.js.

26 lines (23 loc) 901 B
import { readlink } from "fs" import { replaceBackSlashesWithSlashes } from "./internal/replaceBackSlashesWithSlashes.js" import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" import { urlToFileSystemPath } from "./urlToFileSystemPath.js" import { fileSystemPathToUrl } from "./fileSystemPathToUrl.js" import { isFileSystemPath } from "./isFileSystemPath.js" export const readSymbolicLink = (url) => { const symbolicLinkUrl = assertAndNormalizeFileUrl(url) const symbolicLinkPath = urlToFileSystemPath(symbolicLinkUrl) return new Promise((resolve, reject) => { readlink(symbolicLinkPath, (error, resolvedPath) => { if (error) { reject(error) } else { resolve( isFileSystemPath(resolvedPath) ? fileSystemPathToUrl(resolvedPath) : replaceBackSlashesWithSlashes(resolvedPath), ) } }) }) }