@jsenv/filesystem 2.7.2 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/main.js +14 -12
- package/package.json +3 -4
- package/src/assertDirectoryPresence.js +2 -2
- package/src/assertFilePresence.js +2 -2
- package/src/collectDirectoryMatchReport.js +2 -2
- package/src/collectFiles.js +2 -2
- package/src/copyDirectoryContent.js +6 -6
- package/src/{copyFileSystemNode.js → copyEntry.js} +15 -18
- package/src/ensureEmptyDirectory.js +4 -4
- package/src/ensureParentDirectories.js +2 -1
- package/src/fileSystemRootUrl.js +2 -0
- package/src/grantPermissionsOnEntry.js +20 -0
- package/src/internal/createWatcher.js +1 -1
- package/src/internal/guard_second_call.js +20 -0
- package/src/internal/read_entry_info.js +20 -0
- package/src/moveDirectoryContent.js +6 -6
- package/src/{moveFileSystemNode.js → moveEntry.js} +10 -10
- package/src/moveUrl.js +10 -0
- package/src/readEntryModificationTime.js +6 -0
- package/src/{readFileSystemNodePermissions.js → readEntryPermissions.js} +1 -1
- package/src/{readFileSystemNodeStat.js → readEntryStat.js} +3 -3
- package/src/readFile.js +8 -7
- package/src/readFileSync.js +20 -0
- package/src/registerDirectoryLifecycle.js +201 -151
- package/src/registerFileLifecycle.js +39 -6
- package/src/{removeFileSystemNode.js → removeEntry.js} +4 -4
- package/src/{testFileSystemNodePermissions.js → testEntryPermissions.js} +3 -2
- package/src/writeDirectory.js +4 -3
- package/src/{writeFileSystemNodeModificationTime.js → writeEntryModificationTime.js} +3 -2
- package/src/{writeFileSystemNodePermissions.js → writeEntryPermissions.js} +3 -2
- package/src/writeFile.js +5 -6
- package/src/writeFileSync.js +20 -0
- package/src/writeSymbolicLink.js +4 -4
- package/src/grantPermissionsOnFileSystemNode.js +0 -20
- package/src/internal/fileSystemNodeToTypeOrNull.js +0 -18
- package/src/readFileSystemNodeModificationTime.js +0 -6
package/src/writeFile.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { promises } from "fs"
|
|
1
|
+
import { promises } from "node:fs"
|
|
2
|
+
|
|
2
3
|
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js"
|
|
3
|
-
import { urlToFileSystemPath } from "./urlToFileSystemPath.js"
|
|
4
4
|
import { ensureParentDirectories } from "./ensureParentDirectories.js"
|
|
5
5
|
|
|
6
6
|
// https://nodejs.org/dist/latest-v13.x/docs/api/fs.html#fs_fspromises_writefile_file_data_options
|
|
@@ -8,14 +8,13 @@ const { writeFile: writeFileNode } = promises
|
|
|
8
8
|
|
|
9
9
|
export const writeFile = async (destination, content = "") => {
|
|
10
10
|
const destinationUrl = assertAndNormalizeFileUrl(destination)
|
|
11
|
-
|
|
12
|
-
const destinationPath = urlToFileSystemPath(destinationUrl)
|
|
11
|
+
const destinationUrlObject = new URL(destinationUrl)
|
|
13
12
|
try {
|
|
14
|
-
await writeFileNode(
|
|
13
|
+
await writeFileNode(destinationUrlObject, content)
|
|
15
14
|
} catch (error) {
|
|
16
15
|
if (error.code === "ENOENT") {
|
|
17
16
|
await ensureParentDirectories(destinationUrl)
|
|
18
|
-
await writeFileNode(
|
|
17
|
+
await writeFileNode(destinationUrlObject, content)
|
|
19
18
|
return
|
|
20
19
|
}
|
|
21
20
|
throw error
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { writeFileSync as writeFileSyncNode, mkdirSync } from "node:fs"
|
|
2
|
+
|
|
3
|
+
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js"
|
|
4
|
+
|
|
5
|
+
export const writeFileSync = (destination, content = "") => {
|
|
6
|
+
const destinationUrl = assertAndNormalizeFileUrl(destination)
|
|
7
|
+
const destinationUrlObject = new URL(destinationUrl)
|
|
8
|
+
try {
|
|
9
|
+
writeFileSyncNode(destinationUrlObject, content)
|
|
10
|
+
} catch (error) {
|
|
11
|
+
if (error.code === "ENOENT") {
|
|
12
|
+
mkdirSync(new URL("./", destinationUrlObject), {
|
|
13
|
+
recursive: true,
|
|
14
|
+
})
|
|
15
|
+
writeFileSyncNode(destinationUrlObject, content)
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
throw error
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/writeSymbolicLink.js
CHANGED
|
@@ -6,9 +6,9 @@ import { urlToFileSystemPath } from "./urlToFileSystemPath.js"
|
|
|
6
6
|
import { resolveUrl } from "./resolveUrl.js"
|
|
7
7
|
import { isFileSystemPath } from "./isFileSystemPath.js"
|
|
8
8
|
import { ensureParentDirectories } from "./ensureParentDirectories.js"
|
|
9
|
-
import {
|
|
9
|
+
import { readEntryStat } from "./readEntryStat.js"
|
|
10
10
|
import { readSymbolicLink } from "./readSymbolicLink.js"
|
|
11
|
-
import {
|
|
11
|
+
import { removeEntry } from "./removeEntry.js"
|
|
12
12
|
|
|
13
13
|
// https://nodejs.org/dist/latest-v13.x/docs/api/fs.html#fs_fspromises_symlink_target_path_type
|
|
14
14
|
const { symlink } = promises
|
|
@@ -38,7 +38,7 @@ export const writeSymbolicLink = async ({
|
|
|
38
38
|
// In practice, if code don't specify "type" on windows, you later get EPERM errors
|
|
39
39
|
// when doing operation on the symlink such as "fs.stat"
|
|
40
40
|
if (isWindows && typeof type === "undefined") {
|
|
41
|
-
const toStats = await
|
|
41
|
+
const toStats = await readEntryStat(toInfo.url, {
|
|
42
42
|
nullIfNotFound: true,
|
|
43
43
|
})
|
|
44
44
|
type = toStats && toStats.isDirectory() ? "dir" : "file"
|
|
@@ -60,7 +60,7 @@ export const writeSymbolicLink = async ({
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
if (allowOverwrite) {
|
|
63
|
-
await
|
|
63
|
+
await removeEntry(fromUrl)
|
|
64
64
|
await symlink(toInfo.value, symbolicLinkPath, type)
|
|
65
65
|
return
|
|
66
66
|
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js"
|
|
2
|
-
import { readFileSystemNodePermissions } from "./readFileSystemNodePermissions.js"
|
|
3
|
-
import { writeFileSystemNodePermissions } from "./writeFileSystemNodePermissions.js"
|
|
4
|
-
|
|
5
|
-
export const grantPermissionsOnFileSystemNode = async (
|
|
6
|
-
source,
|
|
7
|
-
{ read = false, write = false, execute = false },
|
|
8
|
-
) => {
|
|
9
|
-
const sourceUrl = assertAndNormalizeFileUrl(source)
|
|
10
|
-
|
|
11
|
-
const filePermissions = await readFileSystemNodePermissions(sourceUrl)
|
|
12
|
-
await writeFileSystemNodePermissions(sourceUrl, {
|
|
13
|
-
owner: { read, write, execute },
|
|
14
|
-
group: { read, write, execute },
|
|
15
|
-
others: { read, write, execute },
|
|
16
|
-
})
|
|
17
|
-
return async () => {
|
|
18
|
-
await writeFileSystemNodePermissions(sourceUrl, filePermissions)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { statSync } from "node:fs"
|
|
2
|
-
|
|
3
|
-
import { urlToFileSystemPath } from "../urlToFileSystemPath.js"
|
|
4
|
-
|
|
5
|
-
import { statsToType } from "./statsToType.js"
|
|
6
|
-
|
|
7
|
-
export const fileSystemNodeToTypeOrNull = (url) => {
|
|
8
|
-
const path = urlToFileSystemPath(url)
|
|
9
|
-
try {
|
|
10
|
-
const stats = statSync(path)
|
|
11
|
-
return statsToType(stats)
|
|
12
|
-
} catch (e) {
|
|
13
|
-
if (e.code === "ENOENT") {
|
|
14
|
-
return null
|
|
15
|
-
}
|
|
16
|
-
throw e
|
|
17
|
-
}
|
|
18
|
-
}
|