Socket
Socket
Sign inDemoInstall

@jsenv/filesystem

Package Overview
Dependencies
Maintainers
2
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jsenv/filesystem - npm Package Compare versions

Comparing version 2.1.1 to 2.2.0

src/copyDirectoryContent.js

1

main.js

@@ -25,2 +25,3 @@ /* eslint-disable import/max-dependencies */

export { copyFileSystemNode } from "./src/copyFileSystemNode.js"
export { copyDirectoryContent } from "./src/copyDirectoryContent.js"
export { fileSystemPathToUrl } from "./src/fileSystemPathToUrl.js"

@@ -27,0 +28,0 @@ export { grantPermissionsOnFileSystemNode } from "./src/grantPermissionsOnFileSystemNode.js"

21

package.json
{
"name": "@jsenv/filesystem",
"version": "2.1.1",
"version": "2.2.0",
"description": "Collection of functions to interact with filesystem in Node.js",

@@ -19,4 +19,3 @@ "license": "MIT",

"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
"access": "public"
},

@@ -52,12 +51,14 @@ "type": "module",

"@jsenv/cancellation": "3.0.0",
"@jsenv/url-meta": "6.0.0"
"@jsenv/url-meta": "6.0.1"
},
"devDependencies": {
"@babel/core": "7.15.5",
"@babel/eslint-parser": "7.15.7",
"@jsenv/assert": "2.2.7",
"@jsenv/codecov-upload": "3.5.0",
"@jsenv/core": "19.6.2",
"@jsenv/eslint-config": "15.0.2",
"@jsenv/core": "20.3.0",
"@jsenv/eslint-config": "16.0.3",
"@jsenv/github-release-package": "1.2.3",
"@jsenv/importmap-eslint-resolver": "5.1.0",
"@jsenv/importmap-node-module": "1.0.1",
"@jsenv/importmap-eslint-resolver": "5.1.2",
"@jsenv/importmap-node-module": "2.2.1",
"@jsenv/package-publish": "1.6.2",

@@ -67,5 +68,5 @@ "@jsenv/performance-impact": "1.7.0",

"eslint": "7.32.0",
"eslint-plugin-import": "2.24.0",
"prettier": "2.3.2"
"eslint-plugin-import": "2.24.2",
"prettier": "2.4.1"
}
}

@@ -1,13 +0,5 @@

# Jsenv filesystem
# Jsenv filesystem [![npm package](https://img.shields.io/npm/v/@jsenv/filesystem.svg?logo=npm&label=package)](https://www.npmjs.com/package/@jsenv/filesystem) [![github main](https://github.com/jsenv/filesystem/workflows/main/badge.svg)](https://github.com/jsenv/filesystem/actions?workflow=main) [![codecov coverage](https://codecov.io/gh/jsenv/filesystem/branch/main/graph/badge.svg)](https://codecov.io/gh/jsenv/filesystem)
Collection of functions to interact with filesystem in Node.js.
Collection of functions to interact with filesystem in Node.js
[![npm package](https://img.shields.io/npm/v/@jsenv/filesystem.svg?logo=npm&label=package)](https://www.npmjs.com/package/@jsenv/filesystem)
[![github main](https://github.com/jsenv/filesystem/workflows/main/badge.svg)](https://github.com/jsenv/filesystem/actions?workflow=main)
[![codecov coverage](https://codecov.io/gh/jsenv/filesystem/branch/main/graph/badge.svg)](https://codecov.io/gh/jsenv/filesystem)
# Presentation
`@jsenv/filesystem` provides functions needed to work with files.
## Get a relative url

@@ -44,3 +36,3 @@

## Watch a specific file change
## Watch a specific file changes

@@ -68,3 +60,3 @@ ```js

## Watch many file change
## Watch many files changes

@@ -71,0 +63,0 @@ ```js

@@ -17,7 +17,11 @@ import { ensureUrlTrailingSlash } from "./internal/ensureUrlTrailingSlash.js"

} catch (e) {
throw new TypeError(`directoryUrl must be a valid url, received ${value}`)
throw new TypeError(
`directoryUrl must be a valid url, received ${value}`,
)
}
}
} else {
throw new TypeError(`directoryUrl must be a string or an url, received ${value}`)
throw new TypeError(
`directoryUrl must be a string or an url, received ${value}`,
)
}

@@ -24,0 +28,0 @@

@@ -18,5 +18,7 @@ import { statsToType } from "./internal/statsToType.js"

throw new Error(
`directory expected at ${sourcePath} and found ${statsToType(sourceStats)} instead`,
`directory expected at ${sourcePath} and found ${statsToType(
sourceStats,
)} instead`,
)
}
}

@@ -17,4 +17,8 @@ import { statsToType } from "./internal/statsToType.js"

if (!sourceStats.isFile()) {
throw new Error(`file expected at ${sourcePath} and found ${statsToType(sourceStats)} instead`)
throw new Error(
`file expected at ${sourcePath} and found ${statsToType(
sourceStats,
)} instead`,
)
}
}
import { createCancellationToken, createOperation } from "@jsenv/cancellation"
import { normalizeStructuredMetaMap, urlCanContainsMetaMatching, urlToMeta } from "@jsenv/url-meta"
import {
normalizeStructuredMetaMap,
urlCanContainsMetaMatching,
urlToMeta,
} from "@jsenv/url-meta"

@@ -38,3 +42,6 @@ import { ensureUrlTrailingSlash } from "./internal/ensureUrlTrailingSlash.js"

const directoryChildNodeUrl = `${directoryUrl}${directoryItem}`
const relativeUrl = urlToRelativeUrl(directoryChildNodeUrl, rootDirectoryUrl)
const relativeUrl = urlToRelativeUrl(
directoryChildNodeUrl,
rootDirectoryUrl,
)

@@ -83,7 +90,15 @@ const directoryChildNodeStats = await createOperation({

if (!predicate(meta)) {
ignoredArray.push({ relativeUrl, meta, fileStats: directoryChildNodeStats })
ignoredArray.push({
relativeUrl,
meta,
fileStats: directoryChildNodeStats,
})
return
}
matchingArray.push({ relativeUrl, meta, fileStats: directoryChildNodeStats })
matchingArray.push({
relativeUrl,
meta,
fileStats: directoryChildNodeStats,
})
return

@@ -90,0 +105,0 @@ }

import { createCancellationToken, createOperation } from "@jsenv/cancellation"
import { normalizeStructuredMetaMap, urlCanContainsMetaMatching, urlToMeta } from "@jsenv/url-meta"
import {
normalizeStructuredMetaMap,
urlCanContainsMetaMatching,
urlToMeta,
} from "@jsenv/url-meta"

@@ -22,3 +26,5 @@ import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js"

if (typeof matchingFileOperation !== "function") {
throw new TypeError(`matchingFileOperation must be a function, got ${matchingFileOperation}`)
throw new TypeError(
`matchingFileOperation must be a function, got ${matchingFileOperation}`,
)
}

@@ -79,3 +85,6 @@ const structuredMetaMapNormalized = normalizeStructuredMetaMap(

const relativeUrl = urlToRelativeUrl(directoryChildNodeUrl, rootDirectoryUrl)
const relativeUrl = urlToRelativeUrl(
directoryChildNodeUrl,
rootDirectoryUrl,
)
const operationResult = await createOperation({

@@ -82,0 +91,0 @@ cancellationToken,

@@ -57,3 +57,5 @@ /* eslint-disable import/max-dependencies */

toPath = urlToFileSystemPath(toUrl)
destinationStats = await readFileSystemNodeStat(toUrl, { nullIfNotFound: true })
destinationStats = await readFileSystemNodeStat(toUrl, {
nullIfNotFound: true,
})
}

@@ -65,3 +67,5 @@

}
throw new Error(`cannot copy ${fromPath} because destination and source are the same`)
throw new Error(
`cannot copy ${fromPath} because destination and source are the same`,
)
}

@@ -108,3 +112,6 @@

await copyFileContentNaive(urlToFileSystemPath(fileUrl), urlToFileSystemPath(fileCopyUrl))
await copyFileContentNaive(
urlToFileSystemPath(fileUrl),
urlToFileSystemPath(fileCopyUrl),
)
await copyStats(fileCopyUrl, fileStats)

@@ -116,5 +123,9 @@ }

const symbolicLinkTarget = await readSymbolicLink(symbolicLinkUrl)
const symbolicLinkTargetUrl = resolveUrl(symbolicLinkTarget, symbolicLinkUrl)
const symbolicLinkTargetUrl = resolveUrl(
symbolicLinkTarget,
symbolicLinkUrl,
)
const linkIsRelative =
symbolicLinkTarget.startsWith("./") || symbolicLinkTarget.startsWith("../")
symbolicLinkTarget.startsWith("./") ||
symbolicLinkTarget.startsWith("../")

@@ -127,3 +138,6 @@ let symbolicLinkCopyTarget

// reflects it inside the copied directory structure
const linkCopyTargetRelative = urlToRelativeUrl(symbolicLinkTargetUrl, fromUrl)
const linkCopyTargetRelative = urlToRelativeUrl(
symbolicLinkTargetUrl,
fromUrl,
)
symbolicLinkCopyTarget = linkIsRelative

@@ -158,3 +172,6 @@ ? `./${linkCopyTargetRelative}`

if (preservePermissions) {
await writeFileSystemNodePermissions(toUrl, binaryFlagsToPermissions(mode))
await writeFileSystemNodePermissions(
toUrl,
binaryFlagsToPermissions(mode),
)
}

@@ -181,3 +198,5 @@ if (preserveMtime) {

const fileSystemNodeUrl = resolveUrl(name, directoryUrl)
const stats = await readFileSystemNodeStat(fileSystemNodeUrl, { followLink: false })
const stats = await readFileSystemNodeStat(fileSystemNodeUrl, {
followLink: false,
})
await visit(fileSystemNodeUrl, stats)

@@ -184,0 +203,0 @@ }),

@@ -9,3 +9,6 @@ import { statsToType } from "./internal/statsToType.js"

export const ensureEmptyDirectory = async (source) => {
const stats = await readFileSystemNodeStat(source, { nullIfNotFound: true, followLink: false })
const stats = await readFileSystemNodeStat(source, {
nullIfNotFound: true,
followLink: false,
})
if (stats === null) {

@@ -12,0 +15,0 @@ // if there is nothing, create a directory

@@ -11,3 +11,6 @@ import { dirname } from "path"

return writeDirectory(destinationParentPath, { recursive: true, allowUseless: true })
return writeDirectory(destinationParentPath, {
recursive: true,
allowUseless: true,
})
}

@@ -48,4 +48,8 @@ import { fileSystemPathToUrl } from "./fileSystemPathToUrl.js"

// drive letter was lost, restore it
const baseUrlOrFallback = baseUrl.startsWith("file://") ? baseUrl : baseUrlFallback
const driveLetter = extractDriveLetter(baseUrlOrFallback.slice("file://".length))
const baseUrlOrFallback = baseUrl.startsWith("file://")
? baseUrl
: baseUrlFallback
const driveLetter = extractDriveLetter(
baseUrlOrFallback.slice("file://".length),
)
if (!driveLetter) {

@@ -52,0 +56,0 @@ throw new Error(

export const getCommonPathname = (pathname, otherPathname) => {
const firstDifferentCharacterIndex = findFirstDifferentCharacterIndex(pathname, otherPathname)
const firstDifferentCharacterIndex = findFirstDifferentCharacterIndex(
pathname,
otherPathname,
)

@@ -4,0 +7,0 @@ // pathname and otherpathname are exactly the same

@@ -1,1 +0,2 @@

export const replaceBackSlashesWithSlashes = (string) => string.replace(/\\/g, "/")
export const replaceBackSlashesWithSlashes = (string) =>
string.replace(/\\/g, "/")
export const isFileSystemPath = (value) => {
if (typeof value !== "string") {
throw new TypeError(`isFileSystemPath first arg must be a string, got ${value}`)
throw new TypeError(
`isFileSystemPath first arg must be a string, got ${value}`,
)
}

@@ -5,0 +7,0 @@

@@ -12,3 +12,8 @@ import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js"

export const moveDirectoryContent = async ({ from, to, overwrite, followLink = true } = {}) => {
export const moveDirectoryContent = async ({
from,
to,
overwrite,
followLink = true,
} = {}) => {
const fromUrl = assertAndNormalizeDirectoryUrl(from)

@@ -28,3 +33,5 @@ const fromPath = urlToFileSystemPath(fromUrl)

const sourceType = statsToType(sourceStats)
throw new Error(`found a ${sourceType} instead of a directory at ${fromPath}`)
throw new Error(
`found a ${sourceType} instead of a directory at ${fromPath}`,
)
}

@@ -42,3 +49,5 @@

toPath = urlToFileSystemPath(toUrl)
destinationStats = await readFileSystemNodeStat(toUrl, { nullIfNotFound: true })
destinationStats = await readFileSystemNodeStat(toUrl, {
nullIfNotFound: true,
})
}

@@ -51,3 +60,5 @@

const destinationType = statsToType(destinationStats)
throw new Error(`destination leads to a ${destinationType} instead of a directory at ${toPath}`)
throw new Error(
`destination leads to a ${destinationType} instead of a directory at ${toPath}`,
)
}

@@ -54,0 +65,0 @@

@@ -46,3 +46,5 @@ /* eslint-disable import/max-dependencies */

toPath = urlToFileSystemPath(toUrl)
destinationStats = await readFileSystemNodeStat(toUrl, { nullIfNotFound: true })
destinationStats = await readFileSystemNodeStat(toUrl, {
nullIfNotFound: true,
})
}

@@ -54,3 +56,5 @@

}
throw new Error(`no move needed for ${fromPath} because destination and source are the same`)
throw new Error(
`no move needed for ${fromPath} because destination and source are the same`,
)
}

@@ -91,3 +95,7 @@

const moveNaive = (fromPath, destinationPath, { handleCrossDeviceError = null } = {}) => {
const moveNaive = (
fromPath,
destinationPath,
{ handleCrossDeviceError = null } = {},
) => {
return new Promise((resolve, reject) => {

@@ -94,0 +102,0 @@ rename(fromPath, destinationPath, (error) => {

@@ -33,3 +33,6 @@ import { readdir } from "fs"

const readdirNaive = (directoryPath, { handleTooManyFilesOpenedError = null } = {}) => {
const readdirNaive = (
directoryPath,
{ handleTooManyFilesOpenedError = null } = {},
) => {
return new Promise((resolve, reject) => {

@@ -39,3 +42,6 @@ readdir(directoryPath, (error, names) => {

// https://nodejs.org/dist/latest-v13.x/docs/api/errors.html#errors_common_system_errors
if (handleTooManyFilesOpenedError && (error.code === "EMFILE" || error.code === "ENFILE")) {
if (
handleTooManyFilesOpenedError &&
(error.code === "EMFILE" || error.code === "ENFILE")
) {
resolve(handleTooManyFilesOpenedError(error))

@@ -42,0 +48,0 @@ } else {

@@ -36,3 +36,5 @@ /*

handlePermissionDeniedError: async (error) => {
console.error(`trying to fix windows EPERM after stats on ${sourcePath}`)
console.error(
`trying to fix windows EPERM after stats on ${sourcePath}`,
)

@@ -68,3 +70,7 @@ try {

sourcePath,
{ followLink, handleNotFoundError = null, handlePermissionDeniedError = null } = {},
{
followLink,
handleNotFoundError = null,
handlePermissionDeniedError = null,
} = {},
) => {

@@ -71,0 +77,0 @@ const nodeMethod = followLink ? stat : lstat

/* eslint-disable import/max-dependencies */
import { readdirSync } from "fs"
import { normalizeStructuredMetaMap, urlCanContainsMetaMatching, urlToMeta } from "@jsenv/url-meta"
import {
normalizeStructuredMetaMap,
urlCanContainsMetaMatching,
urlToMeta,
} from "@jsenv/url-meta"
import { replaceBackSlashesWithSlashes } from "./internal/replaceBackSlashesWithSlashes.js"

@@ -37,9 +41,16 @@ import { fileSystemNodeToTypeOrNull } from "./internal/fileSystemNodeToTypeOrNull.js"

if (!undefinedOrFunction(updated)) {
throw new TypeError(`updated must be a function or undefined, got ${updated}`)
throw new TypeError(
`updated must be a function or undefined, got ${updated}`,
)
}
if (!undefinedOrFunction(removed)) {
throw new TypeError(`removed must be a function or undefined, got ${removed}`)
throw new TypeError(
`removed must be a function or undefined, got ${removed}`,
)
}
const structuredMetaMap = normalizeStructuredMetaMap({ watch: watchDescription }, sourceUrl)
const structuredMetaMap = normalizeStructuredMetaMap(
{ watch: watchDescription },
sourceUrl,
)
const entryShouldBeWatched = ({ relativeUrl, type }) => {

@@ -69,3 +80,7 @@ const entryUrl = resolveUrl(relativeUrl, sourceUrl)

const handleDirectoryEvent = ({ directoryRelativeUrl, filename, eventType }) => {
const handleDirectoryEvent = ({
directoryRelativeUrl,
filename,
eventType,
}) => {
if (filename) {

@@ -84,25 +99,32 @@ if (directoryRelativeUrl) {

if (recursive && !fsWatchSupportsRecursive) {
relativeUrlCandidateArray = relativeUrlCandidateArray.filter((relativeUrlCandidate) => {
if (!directoryRelativeUrl) {
// ensure entry is top level
if (relativeUrlCandidate.includes("/")) return false
return true
}
relativeUrlCandidateArray = relativeUrlCandidateArray.filter(
(relativeUrlCandidate) => {
if (!directoryRelativeUrl) {
// ensure entry is top level
if (relativeUrlCandidate.includes("/")) return false
return true
}
// entry not inside this directory
if (!relativeUrlCandidate.startsWith(directoryRelativeUrl)) return false
// entry not inside this directory
if (!relativeUrlCandidate.startsWith(directoryRelativeUrl))
return false
const afterDirectory = relativeUrlCandidate.slice(directoryRelativeUrl.length + 1)
// deep inside this directory
if (afterDirectory.includes("/")) return false
const afterDirectory = relativeUrlCandidate.slice(
directoryRelativeUrl.length + 1,
)
// deep inside this directory
if (afterDirectory.includes("/")) return false
return true
})
return true
},
)
}
const removedEntryRelativeUrl = relativeUrlCandidateArray.find((relativeUrlCandidate) => {
const entryUrl = resolveUrl(relativeUrlCandidate, sourceUrl)
const type = fileSystemNodeToTypeOrNull(entryUrl)
return type === null
})
const removedEntryRelativeUrl = relativeUrlCandidateArray.find(
(relativeUrlCandidate) => {
const entryUrl = resolveUrl(relativeUrlCandidate, sourceUrl)
const type = fileSystemNodeToTypeOrNull(entryUrl)
return type === null
},
)

@@ -207,3 +229,5 @@ if (removedEntryRelativeUrl) {

if (!fsWatchSupportsRecursive && type === "directory") {
const watcher = createWatcher(urlToFileSystemPath(entryUrl), { persistent: keepProcessAlive })
const watcher = createWatcher(urlToFileSystemPath(entryUrl), {
persistent: keepProcessAlive,
})
tracker.registerCleanupCallback(() => {

@@ -253,3 +277,4 @@ watcher.close()

const undefinedOrFunction = (value) => typeof value === "undefined" || typeof value === "function"
const undefinedOrFunction = (value) =>
typeof value === "undefined" || typeof value === "function"

@@ -256,0 +281,0 @@ const visitDirectory = ({ directoryUrl, entryFound }) => {

@@ -17,6 +17,10 @@ import { dirname, basename } from "path"

if (!undefinedOrFunction(updated)) {
throw new TypeError(`updated must be a function or undefined, got ${updated}`)
throw new TypeError(
`updated must be a function or undefined, got ${updated}`,
)
}
if (!undefinedOrFunction(removed)) {
throw new TypeError(`removed must be a function or undefined, got ${removed}`)
throw new TypeError(
`removed must be a function or undefined, got ${removed}`,
)
}

@@ -38,3 +42,5 @@

})
const fileMutationStopTracking = tracker.registerCleanupCallback(fileMutationStopWatching)
const fileMutationStopTracking = tracker.registerCleanupCallback(
fileMutationStopWatching,
)

@@ -61,3 +67,5 @@ if (added) {

)
const fileCreationgStopTracking = tracker.registerCleanupCallback(fileCreationStopWatching)
const fileCreationgStopTracking = tracker.registerCleanupCallback(
fileCreationStopWatching,
)
}

@@ -70,3 +78,5 @@

} else {
throw new Error(`${urlToFileSystemPath(sourceUrl)} must lead to a file, found nothing`)
throw new Error(
`${urlToFileSystemPath(sourceUrl)} must lead to a file, found nothing`,
)
}

@@ -76,3 +86,7 @@ } else if (sourceType === "file") {

} else {
throw new Error(`${urlToFileSystemPath(sourceUrl)} must lead to a file, type found instead`)
throw new Error(
`${urlToFileSystemPath(
sourceUrl,
)} must lead to a file, type found instead`,
)
}

@@ -83,3 +97,4 @@

const undefinedOrFunction = (value) => typeof value === "undefined" || typeof value === "function"
const undefinedOrFunction = (value) =>
typeof value === "undefined" || typeof value === "function"

@@ -90,3 +105,5 @@ const watchFileCreation = (source, callback, keepProcessAlive) => {

const directoryPath = dirname(sourcePath)
let directoryWatcher = createWatcher(directoryPath, { persistent: keepProcessAlive })
let directoryWatcher = createWatcher(directoryPath, {
persistent: keepProcessAlive,
})
directoryWatcher.on("change", (eventType, filename) => {

@@ -112,4 +129,9 @@ if (filename && filename !== sourceFilename) return

const watchFileMutation = (sourceUrl, { updated, removed, keepProcessAlive }) => {
let watcher = createWatcher(urlToFileSystemPath(sourceUrl), { persistent: keepProcessAlive })
const watchFileMutation = (
sourceUrl,
{ updated, removed, keepProcessAlive },
) => {
let watcher = createWatcher(urlToFileSystemPath(sourceUrl), {
persistent: keepProcessAlive,
})

@@ -116,0 +138,0 @@ watcher.on("change", () => {

@@ -42,6 +42,9 @@ import { unlink, rmdir, openSync, closeSync } from "node:fs"

) {
await removeNonDirectory(sourceUrl.endsWith("/") ? sourceUrl.slice(0, -1) : sourceUrl, {
maxRetries,
retryDelay,
})
await removeNonDirectory(
sourceUrl.endsWith("/") ? sourceUrl.slice(0, -1) : sourceUrl,
{
maxRetries,
retryDelay,
},
)
} else if (sourceStats.isDirectory()) {

@@ -119,3 +122,7 @@ await removeDirectory(ensureUrlTrailingSlash(sourceUrl), {

if (sourceStats.isFile() || sourceStats.isCharacterDevice() || sourceStats.isBlockDevice()) {
if (
sourceStats.isFile() ||
sourceStats.isCharacterDevice() ||
sourceStats.isBlockDevice()
) {
await visitFile(sourceUrl)

@@ -145,3 +152,5 @@ } else if (sourceStats.isSymbolicLink()) {

handlePermissionError: async (error) => {
console.error(`trying to fix windows EPERM after readir on ${directoryPath}`)
console.error(
`trying to fix windows EPERM after readir on ${directoryPath}`,
)

@@ -166,3 +175,5 @@ let openOrCloseError

await removeDirectoryNaive(directoryPath, { ...optionsFromRecursive })
await removeDirectoryNaive(directoryPath, {
...optionsFromRecursive,
})
},

@@ -169,0 +180,0 @@ }

@@ -15,3 +15,8 @@ import { promises, constants } from "fs"

source,
{ read = false, write = false, execute = false, allowedIfNotFound = false } = {},
{
read = false,
write = false,
execute = false,
allowedIfNotFound = false,
} = {},
) => {

@@ -18,0 +23,0 @@ const sourceUrl = assertAndNormalizeFileUrl(source)

@@ -6,4 +6,5 @@ import { urlToFilename } from "./urlToFilename.js"

const dotLastIndex = filename.lastIndexOf(".")
const basename = dotLastIndex === -1 ? filename : filename.slice(0, dotLastIndex)
const basename =
dotLastIndex === -1 ? filename : filename.slice(0, dotLastIndex)
return basename
}

@@ -5,3 +5,5 @@ import { urlToPathname } from "./urlToPathname.js"

const pathname = urlToPathname(url)
const pathnameBeforeLastSlash = pathname.endsWith("/") ? pathname.slice(0, -1) : pathname
const pathnameBeforeLastSlash = pathname.endsWith("/")
? pathname.slice(0, -1)
: pathname
const slashLastIndex = pathnameBeforeLastSlash.lastIndexOf("/")

@@ -8,0 +10,0 @@ const filename =

@@ -14,3 +14,6 @@ import { urlToOrigin } from "./urlToOrigin.js"

if (slashLastIndex === lastCharacterIndex) {
const slashPreviousIndex = ressource.lastIndexOf("/", lastCharacterIndex - 1)
const slashPreviousIndex = ressource.lastIndexOf(
"/",
lastCharacterIndex - 1,
)
if (slashPreviousIndex === -1) {

@@ -17,0 +20,0 @@ const urlAsString = String(url)

@@ -11,3 +11,5 @@ import { urlToRessource } from "./urlToRessource.js"

const searchSeparatorIndex = ressource.indexOf("?")
return searchSeparatorIndex === -1 ? ressource : ressource.slice(0, searchSeparatorIndex)
return searchSeparatorIndex === -1
? ressource
: ressource.slice(0, searchSeparatorIndex)
}

@@ -38,4 +38,8 @@ import { getCommonPathname } from "./internal/getCommonPathname.js"

if (baseSpecificPathname.includes("/")) {
const baseSpecificParentPathname = pathnameToParentPathname(baseSpecificPathname)
const relativeDirectoriesNotation = baseSpecificParentPathname.replace(/.*?\//g, "../")
const baseSpecificParentPathname =
pathnameToParentPathname(baseSpecificPathname)
const relativeDirectoriesNotation = baseSpecificParentPathname.replace(
/.*?\//g,
"../",
)
const relativeUrl = `${relativeDirectoriesNotation}${specificPathname}${search}${hash}`

@@ -42,0 +46,0 @@ return relativeUrl

@@ -8,3 +8,4 @@ import { utimes } from "fs"

const sourcePath = urlToFileSystemPath(sourceUrl)
const mtimeValue = typeof mtime === "number" ? new Date(Math.floor(mtime)) : mtime
const mtimeValue =
typeof mtime === "number" ? new Date(Math.floor(mtime)) : mtime
// reading atime mutates its value so there is no use case I can think of

@@ -11,0 +12,0 @@ // where we want to modify it

@@ -26,3 +26,7 @@ import { chmod } from "fs"

write: getPermissionOrComputeDefault("write", "others", permissions),
execute: getPermissionOrComputeDefault("execute", "others", permissions),
execute: getPermissionOrComputeDefault(
"execute",
"others",
permissions,
),
},

@@ -29,0 +33,0 @@ }

@@ -38,3 +38,5 @@ import { promises } from "node:fs"

// you later get EPERM when doing stat on the symlink
const toStats = await readFileSystemNodeStat(toInfo.url, { nullIfNotFound: true })
const toStats = await readFileSystemNodeStat(toInfo.url, {
nullIfNotFound: true,
})
type = toStats && toStats.isDirectory() ? "dir" : "file"

@@ -109,3 +111,5 @@ }

throw new TypeError(`symbolic link to must be a string or an url, received ${to}`)
throw new TypeError(
`symbolic link to must be a string or an url, received ${to}`,
)
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc