@jsenv/filesystem
Advanced tools
Comparing version 3.2.2 to 4.0.0
28
main.js
@@ -1,11 +0,1 @@ | ||
// we won't internalize @jsenv/url-meta | ||
// so that @jsenv/url-meta does not becomes nodejs specific | ||
// but these functions could be inside this repository | ||
export { | ||
applyPatternMatching, | ||
normalizeStructuredMetaMap, | ||
urlCanContainsMetaMatching, | ||
urlToMeta, | ||
} from "@jsenv/url-meta" | ||
export { assertAndNormalizeDirectoryUrl } from "./src/assertAndNormalizeDirectoryUrl.js" | ||
@@ -24,12 +14,7 @@ export { assertAndNormalizeFileUrl } from "./src/assertAndNormalizeFileUrl.js" | ||
export { copyDirectoryContent } from "./src/copyDirectoryContent.js" | ||
export { fileSystemPathToUrl } from "./src/fileSystemPathToUrl.js" | ||
export { fileSystemRootUrl } from "./src/fileSystemRootUrl.js" | ||
export { getRealFileSystemUrlSync } from "./src/getRealFileSystemUrlSync.js" | ||
export { grantPermissionsOnEntry } from "./src/grantPermissionsOnEntry.js" | ||
export { isFileSystemPath } from "./src/isFileSystemPath.js" | ||
export { listFilesMatching } from "./src/listFilesMatching.js" | ||
export { memoize } from "./src/memoize.js" | ||
export { moveDirectoryContent } from "./src/moveDirectoryContent.js" | ||
export { moveEntry } from "./src/moveEntry.js" | ||
export { moveUrl } from "./src/moveUrl.js" | ||
export { readDirectory } from "./src/readDirectory.js" | ||
@@ -45,16 +30,3 @@ export { readFile } from "./src/readFile.js" | ||
export { removeEntry } from "./src/removeEntry.js" | ||
export { resolveDirectoryUrl } from "./src/resolveDirectoryUrl.js" | ||
export { resolveUrl } from "./src/resolveUrl.js" | ||
export { testEntryPermissions } from "./src/testEntryPermissions.js" | ||
export { urlIsInsideOf } from "./src/urlIsInsideOf.js" | ||
export { urlToBasename } from "./src/urlToBasename.js" | ||
export { urlToExtension } from "./src/urlToExtension.js" | ||
export { urlToFilename } from "./src/urlToFilename.js" | ||
export { urlToFileSystemPath } from "./src/urlToFileSystemPath.js" | ||
export { urlToOrigin } from "./src/urlToOrigin.js" | ||
export { urlToParentUrl } from "./src/urlToParentUrl.js" | ||
export { urlToPathname } from "./src/urlToPathname.js" | ||
export { urlToRelativeUrl } from "./src/urlToRelativeUrl.js" | ||
export { urlToRessource } from "./src/urlToRessource.js" | ||
export { urlToScheme } from "./src/urlToScheme.js" | ||
export { writeDirectory } from "./src/writeDirectory.js" | ||
@@ -61,0 +33,0 @@ export { writeFile } from "./src/writeFile.js" |
{ | ||
"name": "@jsenv/filesystem", | ||
"version": "3.2.2", | ||
"description": "Collection of functions to interact with filesystem in Node.js", | ||
"version": "4.0.0", | ||
"license": "MIT", | ||
"author": { | ||
"name": "dmail", | ||
"email": "dmaillard06@gmail.com", | ||
"url": "https://twitter.com/damienmaillard" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/jsenv/filesystem" | ||
"url": "https://github.com/jsenv/jsenv-core", | ||
"directory": "packages/filesystem" | ||
}, | ||
"engines": { | ||
"node": ">=16.13.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"author": { | ||
"name": "dmail", | ||
"email": "dmaillard06@gmail.com", | ||
"url": "https://twitter.com/damienmaillard" | ||
}, | ||
"type": "module", | ||
@@ -28,3 +25,2 @@ "exports": { | ||
}, | ||
"main": "./main.js", | ||
"files": [ | ||
@@ -35,26 +31,9 @@ "/src/", | ||
"scripts": { | ||
"eslint": "node ./node_modules/eslint/bin/eslint.js .", | ||
"importmap": "node ./script/importmap/importmap.mjs", | ||
"performance": "node --expose-gc ./script/performance/performance.mjs --log", | ||
"test": "node ./script/test/test.mjs", | ||
"test-with-coverage": "npm run test -- --coverage", | ||
"prettier": "prettier --write ." | ||
"test": "node --conditions=development ./test.mjs" | ||
}, | ||
"dependencies": { | ||
"@jsenv/urls": "1.1.0", | ||
"@jsenv/abort": "4.1.2", | ||
"@jsenv/url-meta": "6.0.3" | ||
}, | ||
"devDependencies": { | ||
"@jsenv/assert": "2.4.1", | ||
"@jsenv/core": "25.2.1", | ||
"@jsenv/eslint-config": "16.0.9", | ||
"@jsenv/github-release-package": "1.2.3", | ||
"@jsenv/importmap-eslint-resolver": "5.2.2", | ||
"@jsenv/importmap-node-module": "5.1.0", | ||
"@jsenv/package-publish": "1.6.2", | ||
"@jsenv/performance-impact": "2.2.1", | ||
"eslint": "8.7.0", | ||
"eslint-plugin-import": "2.25.4", | ||
"prettier": "2.5.1" | ||
"@jsenv/log": "1.6.3" | ||
} | ||
} |
@@ -1,16 +0,5 @@ | ||
# 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) | ||
# Jsenv filesystem [![npm package](https://img.shields.io/npm/v/@jsenv/filesystem.svg?logo=npm&label=package)](https://www.npmjs.com/package/@jsenv/filesystem) | ||
Collection of functions to interact with filesystem in Node.js | ||
## Get a relative url | ||
```js | ||
import { urlToRelativeUrl } from "@jsenv/filesystem" | ||
const projectDirectoryUrl = "file:///project/" | ||
const jsFileUrl = "file:///project/src/file.js" | ||
const relativeUrl = urlToRelativeUrl(jsFileUrl, projectDirectoryUrl) | ||
console.log(relativeUrl) // "src/file.js" | ||
``` | ||
## List files using pattern matching | ||
@@ -90,5 +79,1 @@ | ||
``` | ||
# Development | ||
If you are part or want to be part of the developpers of this package, check [docs/development.md](./docs/development.md) |
@@ -1,4 +0,6 @@ | ||
import { ensureUrlTrailingSlash } from "./internal/ensureUrlTrailingSlash.js" | ||
import { isFileSystemPath } from "./isFileSystemPath.js" | ||
import { fileSystemPathToUrl } from "./fileSystemPathToUrl.js" | ||
import { | ||
fileSystemPathToUrl, | ||
isFileSystemPath, | ||
ensurePathnameTrailingSlash, | ||
} from "@jsenv/urls" | ||
@@ -32,3 +34,3 @@ export const assertAndNormalizeDirectoryUrl = (value) => { | ||
return ensureUrlTrailingSlash(urlString) | ||
return ensurePathnameTrailingSlash(urlString) | ||
} |
@@ -1,3 +0,2 @@ | ||
import { isFileSystemPath } from "./isFileSystemPath.js" | ||
import { fileSystemPathToUrl } from "./fileSystemPathToUrl.js" | ||
import { fileSystemPathToUrl, isFileSystemPath } from "@jsenv/urls" | ||
@@ -4,0 +3,0 @@ export const assertAndNormalizeFileUrl = (value, baseUrl) => { |
@@ -0,4 +1,4 @@ | ||
import { urlToFileSystemPath } from "@jsenv/urls" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { statsToType } from "./internal/statsToType.js" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
import { readEntryStat } from "./readEntryStat.js" | ||
@@ -5,0 +5,0 @@ |
@@ -0,4 +1,4 @@ | ||
import { urlToFileSystemPath } from "@jsenv/urls" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { statsToType } from "./internal/statsToType.js" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
import { readEntryStat } from "./readEntryStat.js" | ||
@@ -5,0 +5,0 @@ |
import { Abort } from "@jsenv/abort" | ||
import { | ||
normalizeStructuredMetaMap, | ||
urlCanContainsMetaMatching, | ||
urlToMeta, | ||
} from "@jsenv/url-meta" | ||
import { ensureUrlTrailingSlash } from "./internal/ensureUrlTrailingSlash.js" | ||
import { URL_META, urlToRelativeUrl } from "@jsenv/urls" | ||
import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js" | ||
import { readDirectory } from "./readDirectory.js" | ||
import { readEntryStat } from "./readEntryStat.js" | ||
import { urlToRelativeUrl } from "./urlToRelativeUrl.js" | ||
import { comparePathnames } from "./comparePathnames.js" | ||
@@ -18,3 +12,3 @@ | ||
directoryUrl, | ||
structuredMetaMap, | ||
associations, | ||
predicate, | ||
@@ -29,6 +23,3 @@ }) => { | ||
} | ||
const structuredMetaMapNormalized = normalizeStructuredMetaMap( | ||
structuredMetaMap, | ||
rootDirectoryUrl, | ||
) | ||
associations = URL_META.resolveAssociations(associations, rootDirectoryUrl) | ||
@@ -68,5 +59,5 @@ const collectOperation = Abort.startOperation() | ||
if ( | ||
!urlCanContainsMetaMatching({ | ||
!URL_META.urlChildMayMatch({ | ||
url: subDirectoryUrl, | ||
structuredMetaMap: structuredMetaMapNormalized, | ||
associations, | ||
predicate, | ||
@@ -76,3 +67,5 @@ }) | ||
ignoredArray.push({ | ||
relativeUrl: ensureUrlTrailingSlash(relativeUrl), | ||
relativeUrl: relativeUrl.endsWith("/") | ||
? relativeUrl | ||
: `${relativeUrl}/`, | ||
fileStats: directoryChildNodeStats, | ||
@@ -89,5 +82,5 @@ }) | ||
if (directoryChildNodeStats.isFile()) { | ||
const meta = urlToMeta({ | ||
const meta = URL_META.applyAssociations({ | ||
url: directoryChildNodeUrl, | ||
structuredMetaMap: structuredMetaMapNormalized, | ||
associations, | ||
}) | ||
@@ -94,0 +87,0 @@ if (!predicate(meta)) { |
import { Abort } from "@jsenv/abort" | ||
import { | ||
normalizeStructuredMetaMap, | ||
urlCanContainsMetaMatching, | ||
urlToMeta, | ||
} from "@jsenv/url-meta" | ||
import { URL_META, urlToRelativeUrl } from "@jsenv/urls" | ||
@@ -11,3 +7,2 @@ import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js" | ||
import { readEntryStat } from "./readEntryStat.js" | ||
import { urlToRelativeUrl } from "./urlToRelativeUrl.js" | ||
import { comparePathnames } from "./comparePathnames.js" | ||
@@ -18,3 +13,3 @@ | ||
directoryUrl, | ||
structuredMetaMap, | ||
associations, | ||
predicate, | ||
@@ -26,6 +21,3 @@ }) => { | ||
} | ||
const structuredMetaMapNormalized = normalizeStructuredMetaMap( | ||
structuredMetaMap, | ||
rootDirectoryUrl, | ||
) | ||
associations = URL_META.resolveAssociations(associations, rootDirectoryUrl) | ||
@@ -62,5 +54,5 @@ const collectOperation = Abort.startOperation() | ||
if ( | ||
!urlCanContainsMetaMatching({ | ||
!URL_META.urlChildMayMatch({ | ||
url: subDirectoryUrl, | ||
structuredMetaMap: structuredMetaMapNormalized, | ||
associations, | ||
predicate, | ||
@@ -77,5 +69,5 @@ }) | ||
if (directoryChildNodeStats.isFile()) { | ||
const meta = urlToMeta({ | ||
const meta = URL_META.applyAssociations({ | ||
url: directoryChildNodeUrl, | ||
structuredMetaMap: structuredMetaMapNormalized, | ||
associations, | ||
}) | ||
@@ -82,0 +74,0 @@ if (!predicate(meta)) return |
import { Abort } from "@jsenv/abort" | ||
import { urlToFileSystemPath, resolveUrl } from "@jsenv/urls" | ||
import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js" | ||
import { readEntryStat } from "./readEntryStat.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
import { readSymbolicLink } from "./readSymbolicLink.js" | ||
import { resolveUrl } from "./resolveUrl.js" | ||
import { readDirectory } from "./readDirectory.js" | ||
@@ -9,0 +8,0 @@ import { copyEntry } from "./copyEntry.js" |
import { copyFile as copyFileNode } from "node:fs" | ||
import { Abort } from "@jsenv/abort" | ||
import { | ||
resolveUrl, | ||
urlToRelativeUrl, | ||
ensurePathnameTrailingSlash, | ||
urlIsInsideOf, | ||
urlToFileSystemPath, | ||
} from "@jsenv/urls" | ||
import { urlTargetsSameFileSystemPath } from "./internal/urlTargetsSameFileSystemPath.js" | ||
import { statsToType } from "./internal/statsToType.js" | ||
import { ensureUrlTrailingSlash } from "./internal/ensureUrlTrailingSlash.js" | ||
import { resolveUrl } from "./resolveUrl.js" | ||
import { binaryFlagsToPermissions } from "./internal/permissions.js" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { writeDirectory } from "./writeDirectory.js" | ||
import { urlToRelativeUrl } from "./urlToRelativeUrl.js" | ||
import { readEntryStat } from "./readEntryStat.js" | ||
@@ -19,5 +23,3 @@ import { ensureParentDirectories } from "./ensureParentDirectories.js" | ||
import { writeSymbolicLink } from "./writeSymbolicLink.js" | ||
import { urlIsInsideOf } from "./urlIsInsideOf.js" | ||
import { removeEntry } from "./removeEntry.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
@@ -74,3 +76,3 @@ export const copyEntry = async ({ | ||
if (sourceStats.isDirectory()) { | ||
toUrl = ensureUrlTrailingSlash(toUrl) | ||
toUrl = ensurePathnameTrailingSlash(toUrl) | ||
} | ||
@@ -88,3 +90,3 @@ | ||
} else if (stats.isDirectory()) { | ||
await visitDirectory(ensureUrlTrailingSlash(url), stats) | ||
await visitDirectory(ensurePathnameTrailingSlash(url), stats) | ||
} | ||
@@ -91,0 +93,0 @@ } |
@@ -0,4 +1,4 @@ | ||
import { urlToFileSystemPath } from "@jsenv/urls" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { statsToType } from "./internal/statsToType.js" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
import { writeDirectory } from "./writeDirectory.js" | ||
@@ -5,0 +5,0 @@ import { readEntryStat } from "./readEntryStat.js" |
import { dirname } from "node:path" | ||
import { urlToFileSystemPath } from "@jsenv/urls" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
import { writeDirectory } from "./writeDirectory.js" | ||
@@ -6,0 +6,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { fileSystemPathToUrl } from "./fileSystemPathToUrl.js" | ||
import { fileSystemPathToUrl } from "@jsenv/urls" | ||
@@ -3,0 +3,0 @@ const isWindows = process.platform === "win32" |
import { readdirSync, realpathSync } from "node:fs" | ||
import { fileSystemPathToUrl, urlToFileSystemPath } from "@jsenv/urls" | ||
import { fileSystemPathToUrl } from "./fileSystemPathToUrl.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
export const getRealFileSystemUrlSync = ( | ||
@@ -7,0 +5,0 @@ fileUrl, |
@@ -11,13 +11,9 @@ import { collectFiles } from "./collectFiles.js" | ||
} | ||
const fileDatas = await collectFiles({ | ||
signal, | ||
directoryUrl, | ||
structuredMetaMap: { | ||
matches: patterns, | ||
}, | ||
associations: { matches: patterns }, | ||
predicate: ({ matches }) => matches, | ||
}) | ||
return fileDatas.map(({ url }) => url) | ||
} |
import { Abort } from "@jsenv/abort" | ||
import { urlToFileSystemPath, resolveUrl } from "@jsenv/urls" | ||
import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js" | ||
import { readEntryStat } from "./readEntryStat.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
import { readSymbolicLink } from "./readSymbolicLink.js" | ||
import { resolveUrl } from "./resolveUrl.js" | ||
import { readDirectory } from "./readDirectory.js" | ||
@@ -9,0 +8,0 @@ import { moveEntry } from "./moveEntry.js" |
import { rename } from "node:fs" | ||
import { Abort } from "@jsenv/abort" | ||
import { urlToFileSystemPath, resolveUrl } from "@jsenv/urls" | ||
@@ -7,4 +8,2 @@ import { urlTargetsSameFileSystemPath } from "./internal/urlTargetsSameFileSystemPath.js" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
import { resolveUrl } from "./resolveUrl.js" | ||
import { ensureParentDirectories } from "./ensureParentDirectories.js" | ||
@@ -11,0 +10,0 @@ import { removeEntry } from "./removeEntry.js" |
@@ -1,4 +0,4 @@ | ||
import { readdir } from "fs" | ||
import { readdir } from "node:fs" | ||
import { urlToFileSystemPath } from "@jsenv/urls" | ||
import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
@@ -5,0 +5,0 @@ export const readDirectory = async (url, { emfileMaxWait = 1000 } = {}) => { |
@@ -7,6 +7,6 @@ /* | ||
import { promises } from "node:fs" | ||
import { urlToFileSystemPath } from "@jsenv/urls" | ||
import { binaryFlagsToPermissions } from "./internal/permissions.js" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
@@ -13,0 +13,0 @@ const { stat } = promises |
@@ -7,5 +7,5 @@ /* | ||
import { lstat, stat } from "node:fs" | ||
import { urlToFileSystemPath } from "@jsenv/urls" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
import { writeEntryPermissions } from "./writeEntryPermissions.js" | ||
@@ -12,0 +12,0 @@ |
@@ -1,2 +0,1 @@ | ||
import { promisify } from "node:util" | ||
import { readFile as readFileNode } from "node:fs" | ||
@@ -6,6 +5,13 @@ | ||
const readFilePromisified = promisify(readFileNode) | ||
export const readFile = async (value, { as = "buffer" } = {}) => { | ||
const fileUrl = assertAndNormalizeFileUrl(value) | ||
const buffer = await readFilePromisified(new URL(fileUrl)) | ||
const buffer = await new Promise((resolve, reject) => { | ||
readFileNode(new URL(fileUrl), (error, buffer) => { | ||
if (error) { | ||
reject(error) | ||
} else { | ||
resolve(buffer) | ||
} | ||
}) | ||
}) | ||
if (as === "buffer") { | ||
@@ -12,0 +18,0 @@ return buffer |
@@ -7,15 +7,11 @@ /* | ||
import { readlink } from "node:fs" | ||
import { isFileSystemPath, fileSystemPathToUrl } from "@jsenv/urls" | ||
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) => { | ||
readlink(new URL(symbolicLinkUrl), (error, resolvedPath) => { | ||
if (error) { | ||
@@ -27,3 +23,3 @@ reject(error) | ||
? fileSystemPathToUrl(resolvedPath) | ||
: replaceBackSlashesWithSlashes(resolvedPath), | ||
: resolvedPath.replace(/\\/g, "/"), // replace back slashes with slashes | ||
) | ||
@@ -30,0 +26,0 @@ } |
import { readdirSync, statSync } from "node:fs" | ||
import { | ||
normalizeStructuredMetaMap, | ||
urlCanContainsMetaMatching, | ||
urlToMeta, | ||
} from "@jsenv/url-meta" | ||
import { URL_META, urlToFileSystemPath, urlToRelativeUrl } from "@jsenv/urls" | ||
@@ -11,7 +7,4 @@ import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js" | ||
import { guardTooFastSecondCall } from "./internal/guard_second_call.js" | ||
import { replaceBackSlashesWithSlashes } from "./internal/replaceBackSlashesWithSlashes.js" | ||
import { createWatcher } from "./internal/createWatcher.js" | ||
import { trackRessources } from "./internal/trackRessources.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
import { urlToRelativeUrl } from "./urlToRelativeUrl.js" | ||
@@ -69,3 +62,3 @@ const isLinux = process.platform === "linux" | ||
const structuredMetaMap = normalizeStructuredMetaMap( | ||
const associations = URL_META.resolveAssociations( | ||
{ watch: watchPatterns }, | ||
@@ -77,5 +70,5 @@ sourceUrl, | ||
let firstMeta = false | ||
urlCanContainsMetaMatching({ | ||
URL_META.urlChildMayMatch({ | ||
url: `${url}/`, | ||
structuredMetaMap, | ||
associations, | ||
predicate: ({ watch }) => { | ||
@@ -90,7 +83,4 @@ if (watch) { | ||
} | ||
const filesystemEntryMeta = urlToMeta({ | ||
url, | ||
structuredMetaMap, | ||
}) | ||
return filesystemEntryMeta.watch | ||
const { watch } = URL_META.applyAssociations({ url, associations }) | ||
return watch | ||
} | ||
@@ -267,3 +257,6 @@ const tracker = trackRessources() | ||
directoryRelativeUrl: entryInfo.relativeUrl, | ||
filename: filename ? replaceBackSlashesWithSlashes(filename) : "", | ||
filename: filename | ||
? // replace back slashes with slashes | ||
filename.replace(/\\/g, "/") | ||
: "", | ||
eventType, | ||
@@ -356,3 +349,3 @@ }) | ||
const normalizedPath = replaceBackSlashesWithSlashes(path) | ||
const normalizedPath = path.replace(/\\/g, "/") // replace back slashes with slashes | ||
const slashLastIndex = normalizedPath.lastIndexOf("/") | ||
@@ -359,0 +352,0 @@ if (slashLastIndex === -1) { |
import { statSync } from "node:fs" | ||
import { dirname, basename } from "node:path" | ||
import { urlToFileSystemPath } from "@jsenv/urls" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { guardTooFastSecondCall } from "./internal/guard_second_call.js" | ||
@@ -8,4 +10,2 @@ import { statsToType } from "./internal/statsToType.js" | ||
import { trackRessources } from "./internal/trackRessources.js" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
@@ -12,0 +12,0 @@ export const registerFileLifecycle = ( |
import { unlink, rmdir, openSync, closeSync } from "node:fs" | ||
import { Abort } from "@jsenv/abort" | ||
import { | ||
ensurePathnameTrailingSlash, | ||
urlToFileSystemPath, | ||
resolveUrl, | ||
} from "@jsenv/urls" | ||
import { ensureUrlTrailingSlash } from "./internal/ensureUrlTrailingSlash.js" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
import { readEntryStat } from "./readEntryStat.js" | ||
import { readDirectory } from "./readDirectory.js" | ||
import { resolveUrl } from "./resolveUrl.js" | ||
@@ -57,3 +59,3 @@ export const removeEntry = async ( | ||
} else if (sourceStats.isDirectory()) { | ||
await removeDirectory(ensureUrlTrailingSlash(sourceUrl), { | ||
await removeDirectory(ensurePathnameTrailingSlash(sourceUrl), { | ||
signal: removeOperation.signal, | ||
@@ -60,0 +62,0 @@ recursive, |
import { promises, constants } from "node:fs" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
@@ -24,3 +23,2 @@ const { access } = promises | ||
const sourceUrl = assertAndNormalizeFileUrl(source) | ||
const sourcePath = urlToFileSystemPath(sourceUrl) | ||
let binaryFlags = 0 | ||
@@ -34,3 +32,3 @@ | ||
try { | ||
await access(sourcePath, binaryFlags) | ||
await access(new URL(sourceUrl), binaryFlags) | ||
return true | ||
@@ -37,0 +35,0 @@ } catch (error) { |
import { promises } from "node:fs" | ||
import { urlToFileSystemPath } from "@jsenv/urls" | ||
import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js" | ||
import { statsToType } from "./internal/statsToType.js" | ||
import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
import { readEntryStat } from "./readEntryStat.js" | ||
@@ -7,0 +7,0 @@ |
import { utimes } from "node:fs" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
export const writeEntryModificationTime = (source, mtime) => { | ||
const sourceUrl = assertAndNormalizeFileUrl(source) | ||
const sourcePath = urlToFileSystemPath(sourceUrl) | ||
const mtimeValue = | ||
@@ -16,3 +14,3 @@ typeof mtime === "number" ? new Date(Math.floor(mtime)) : mtime | ||
return new Promise((resolve, reject) => { | ||
utimes(sourcePath, atimeValue, mtimeValue, (error) => { | ||
utimes(new URL(sourceUrl), atimeValue, mtimeValue, (error) => { | ||
if (error) { | ||
@@ -19,0 +17,0 @@ reject(error) |
@@ -5,7 +5,5 @@ import { chmod } from "node:fs" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
export const writeEntryPermissions = async (source, permissions) => { | ||
const sourceUrl = assertAndNormalizeFileUrl(source) | ||
const sourcePath = urlToFileSystemPath(sourceUrl) | ||
@@ -40,8 +38,4 @@ let binaryFlags | ||
return chmodNaive(sourcePath, binaryFlags) | ||
} | ||
const chmodNaive = (fileSystemPath, binaryFlags) => { | ||
return new Promise((resolve, reject) => { | ||
chmod(fileSystemPath, binaryFlags, (error) => { | ||
chmod(new URL(sourceUrl), binaryFlags, (error) => { | ||
if (error) { | ||
@@ -48,0 +42,0 @@ reject(error) |
@@ -1,2 +0,2 @@ | ||
import { promises } from "node:fs" | ||
import { writeFile as writeFileNode } from "node:fs" | ||
@@ -6,5 +6,2 @@ import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
// https://nodejs.org/dist/latest-v13.x/docs/api/fs.html#fs_fspromises_writefile_file_data_options | ||
const { writeFile: writeFileNode } = promises | ||
export const writeFile = async (destination, content = "") => { | ||
@@ -14,7 +11,7 @@ const destinationUrl = assertAndNormalizeFileUrl(destination) | ||
try { | ||
await writeFileNode(destinationUrlObject, content) | ||
await writeFileNaive(destinationUrlObject, content) | ||
} catch (error) { | ||
if (error.code === "ENOENT") { | ||
await ensureParentDirectories(destinationUrl) | ||
await writeFileNode(destinationUrlObject, content) | ||
await writeFileNaive(destinationUrlObject, content) | ||
return | ||
@@ -25,1 +22,13 @@ } | ||
} | ||
const writeFileNaive = (urlObject, content) => { | ||
return new Promise((resolve, reject) => { | ||
writeFileNode(urlObject, content, (error) => { | ||
if (error) { | ||
reject(error) | ||
} else { | ||
resolve() | ||
} | ||
}) | ||
}) | ||
} |
import { promises } from "node:fs" | ||
import { | ||
fileSystemPathToUrl, | ||
urlToFileSystemPath, | ||
resolveUrl, | ||
isFileSystemPath, | ||
} from "@jsenv/urls" | ||
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js" | ||
import { fileSystemPathToUrl } from "./fileSystemPathToUrl.js" | ||
import { urlToFileSystemPath } from "./urlToFileSystemPath.js" | ||
import { resolveUrl } from "./resolveUrl.js" | ||
import { isFileSystemPath } from "./isFileSystemPath.js" | ||
import { ensureParentDirectories } from "./ensureParentDirectories.js" | ||
@@ -9,0 +11,0 @@ import { readEntryStat } from "./readEntryStat.js" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
0
86440
3
47
2540
79
1
+ Added@jsenv/log@1.6.3
+ Added@jsenv/urls@1.1.0
+ Added@jsenv/log@1.6.3(transitive)
+ Added@jsenv/urls@1.1.0(transitive)
+ Addedansi-escapes@5.0.0(transitive)
+ Addedansi-regex@6.1.0(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@9.2.2(transitive)
+ Addedis-unicode-supported@1.1.0(transitive)
+ Addedstring-width@5.1.2(transitive)
+ Addedstrip-ansi@7.1.0(transitive)
+ Addedsupports-color@9.2.2(transitive)
+ Addedtype-fest@1.4.0(transitive)
- Removed@jsenv/url-meta@6.0.3
- Removed@jsenv/url-meta@6.0.3(transitive)