@jsenv/filesystem
Advanced tools
Comparing version
{ | ||
"name": "@jsenv/filesystem", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "Collection of functions to interact with filesystem in Node.js", | ||
@@ -19,3 +19,4 @@ "license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org" | ||
}, | ||
@@ -22,0 +23,0 @@ "type": "module", |
@@ -33,4 +33,3 @@ import { promises } from "node:fs" | ||
const fromUrl = assertAndNormalizeFileUrl(from) | ||
const toUrl = getToAsUrl(to, fromUrl) | ||
const toPath = urlToFileSystemPath(toUrl) | ||
const toInfo = getToInfo(to, fromUrl) | ||
@@ -40,3 +39,3 @@ if (isWindows && typeof type === "undefined") { | ||
// you later get EPERM when doing stat on the symlink | ||
const toStats = await readFileSystemNodeStat(toUrl, { nullIfNotFound: true }) | ||
const toStats = await readFileSystemNodeStat(toInfo.url, { nullIfNotFound: true }) | ||
type = toStats && toStats.isDirectory() ? "dir" : "file" | ||
@@ -47,7 +46,7 @@ } | ||
try { | ||
await symlink(toPath, symbolicLinkPath, type) | ||
await symlink(toInfo.value, symbolicLinkPath, type) | ||
} catch (error) { | ||
if (error.code === "ENOENT") { | ||
await ensureParentDirectories(fromUrl) | ||
await symlink(toPath, symbolicLinkPath, type) | ||
await symlink(toInfo.value, symbolicLinkPath, type) | ||
return | ||
@@ -58,3 +57,3 @@ } | ||
const existingSymbolicLinkUrl = await readSymbolicLink(fromUrl) | ||
if (existingSymbolicLinkUrl === toUrl) { | ||
if (existingSymbolicLinkUrl === toInfo.url) { | ||
return | ||
@@ -65,3 +64,3 @@ } | ||
await removeFileSystemNode(fromUrl) | ||
await symlink(toPath, symbolicLinkPath, type) | ||
await symlink(toInfo.value, symbolicLinkPath, type) | ||
return | ||
@@ -74,7 +73,12 @@ } | ||
const getToAsUrl = (to, fromUrl) => { | ||
const getToInfo = (to, fromUrl) => { | ||
if (typeof to === "string") { | ||
// absolute filesystem path | ||
if (isFileSystemPath(to)) { | ||
return fileSystemPathToUrl(to) | ||
const url = fileSystemPathToUrl(to) | ||
const value = to | ||
return { | ||
url, | ||
value, | ||
} | ||
} | ||
@@ -84,12 +88,26 @@ | ||
if (to.startsWith("./") || to.startsWith("../")) { | ||
return resolveUrl(to, fromUrl) | ||
const url = resolveUrl(to, fromUrl) | ||
const value = to | ||
return { | ||
url, | ||
value, | ||
} | ||
} | ||
// absolute url | ||
return resolveUrl(to, fromUrl) | ||
const url = resolveUrl(to, fromUrl) | ||
const value = urlToFileSystemPath(url) | ||
return { | ||
url, | ||
value, | ||
} | ||
} | ||
if (to instanceof URL) { | ||
return String(to) | ||
const url = String(to) | ||
const value = urlToFileSystemPath(url) | ||
return { | ||
url, | ||
value, | ||
} | ||
} | ||
@@ -96,0 +114,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
326210
0.45%4563
0.84%