@jsenv/filesystem 4.2.2 → 4.2.4
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 +17 -17
- package/package.json +4 -4
- package/src/assertDirectoryPresence.js +10 -10
- package/src/assertFilePresence.js +10 -10
- package/src/bufferToEtag.js +11 -11
- package/src/collectDirectoryMatchReport.js +38 -38
- package/src/collectFiles.js +35 -35
- package/src/comparePathnames.js +23 -23
- package/src/copyDirectoryContent.js +37 -37
- package/src/copyEntry.js +88 -88
- package/src/directory_url_validation.js +14 -14
- package/src/ensureEmptyDirectory.js +13 -13
- package/src/ensureParentDirectories.js +9 -9
- package/src/ensureWindowsDriveLetter.js +19 -19
- package/src/fileSystemRootUrl.js +1 -1
- package/src/file_url_validation.js +14 -14
- package/src/getRealFileSystemUrlSync.js +24 -24
- package/src/grantPermissionsOnEntry.js +9 -9
- package/src/internal/createWatcher.js +12 -12
- package/src/internal/getCommandArgument.js +7 -7
- package/src/internal/guard_second_call.js +20 -20
- package/src/internal/permissions.js +26 -26
- package/src/internal/read_entry_info.js +8 -8
- package/src/internal/statsToType.js +9 -9
- package/src/internal/track_resources.js +12 -12
- package/src/internal/urlTargetsSameFileSystemPath.js +4 -4
- package/src/listFilesMatching.js +5 -5
- package/src/main.js +35 -35
- package/src/moveDirectoryContent.js +37 -37
- package/src/moveEntry.js +44 -44
- package/src/readDirectory.js +21 -21
- package/src/readEntryModificationTime.js +4 -4
- package/src/readEntryPermissions.js +10 -10
- package/src/readEntryStat.js +27 -27
- package/src/readFile.js +12 -12
- package/src/readFileSync.js +9 -9
- package/src/readSymbolicLink.js +9 -9
- package/src/registerDirectoryLifecycle.js +118 -118
- package/src/registerFileLifecycle.js +66 -66
- package/src/removeEntry.js +81 -81
- package/src/testEntryPermissions.js +15 -15
- package/src/writeDirectory.js +17 -17
- package/src/writeEntryModificationTime.js +10 -10
- package/src/writeEntryPermissions.js +26 -26
- package/src/writeFile.js +16 -16
- package/src/writeFileSync.js +10 -10
- package/src/writeSymbolicLink.js +39 -39
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { fileSystemPathToUrl, isFileSystemPath } from "@jsenv/urls"
|
|
1
|
+
import { fileSystemPathToUrl, isFileSystemPath } from "@jsenv/urls";
|
|
2
2
|
|
|
3
3
|
export const validateFileUrl = (value, baseUrl) => {
|
|
4
|
-
let urlString
|
|
4
|
+
let urlString;
|
|
5
5
|
|
|
6
6
|
if (value instanceof URL) {
|
|
7
|
-
urlString = value.href
|
|
7
|
+
urlString = value.href;
|
|
8
8
|
} else if (typeof value === "string") {
|
|
9
9
|
if (isFileSystemPath(value)) {
|
|
10
|
-
urlString = fileSystemPathToUrl(value)
|
|
10
|
+
urlString = fileSystemPathToUrl(value);
|
|
11
11
|
} else {
|
|
12
12
|
try {
|
|
13
|
-
urlString = String(new URL(value, baseUrl))
|
|
13
|
+
urlString = String(new URL(value, baseUrl));
|
|
14
14
|
} catch (e) {
|
|
15
15
|
return {
|
|
16
16
|
valid: false,
|
|
17
17
|
value,
|
|
18
18
|
message: "must be a valid url",
|
|
19
|
-
}
|
|
19
|
+
};
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
} else {
|
|
@@ -24,7 +24,7 @@ export const validateFileUrl = (value, baseUrl) => {
|
|
|
24
24
|
valid: false,
|
|
25
25
|
value,
|
|
26
26
|
message: "must be a string or an url",
|
|
27
|
-
}
|
|
27
|
+
};
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
if (!urlString.startsWith("file://")) {
|
|
@@ -32,23 +32,23 @@ export const validateFileUrl = (value, baseUrl) => {
|
|
|
32
32
|
valid: false,
|
|
33
33
|
value,
|
|
34
34
|
message: 'must start with "file://"',
|
|
35
|
-
}
|
|
35
|
+
};
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
return {
|
|
39
39
|
valid: true,
|
|
40
40
|
value: urlString,
|
|
41
|
-
}
|
|
42
|
-
}
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
43
|
|
|
44
44
|
export const assertAndNormalizeFileUrl = (
|
|
45
45
|
fileUrl,
|
|
46
46
|
baseUrl,
|
|
47
47
|
name = "fileUrl",
|
|
48
48
|
) => {
|
|
49
|
-
const { valid, message, value } = validateFileUrl(fileUrl, baseUrl)
|
|
49
|
+
const { valid, message, value } = validateFileUrl(fileUrl, baseUrl);
|
|
50
50
|
if (!valid) {
|
|
51
|
-
throw new TypeError(`${name} ${message}, got ${fileUrl}`)
|
|
51
|
+
throw new TypeError(`${name} ${message}, got ${fileUrl}`);
|
|
52
52
|
}
|
|
53
|
-
return value
|
|
54
|
-
}
|
|
53
|
+
return value;
|
|
54
|
+
};
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { readdirSync, realpathSync } from "node:fs"
|
|
2
|
-
import { fileSystemPathToUrl, urlToFileSystemPath } from "@jsenv/urls"
|
|
1
|
+
import { readdirSync, realpathSync } from "node:fs";
|
|
2
|
+
import { fileSystemPathToUrl, urlToFileSystemPath } from "@jsenv/urls";
|
|
3
3
|
|
|
4
4
|
export const getRealFileSystemUrlSync = (
|
|
5
5
|
fileUrl,
|
|
6
6
|
{ followLink = true } = {},
|
|
7
7
|
) => {
|
|
8
|
-
const pathname = new URL(fileUrl).pathname
|
|
9
|
-
const parts = pathname.slice(1).split("/")
|
|
10
|
-
let reconstructedFileUrl = `file
|
|
8
|
+
const pathname = new URL(fileUrl).pathname;
|
|
9
|
+
const parts = pathname.slice(1).split("/");
|
|
10
|
+
let reconstructedFileUrl = `file:///`;
|
|
11
11
|
if (process.platform === "win32") {
|
|
12
|
-
const windowsDriveLetter = parts.shift()
|
|
13
|
-
reconstructedFileUrl += `${windowsDriveLetter}
|
|
12
|
+
const windowsDriveLetter = parts.shift();
|
|
13
|
+
reconstructedFileUrl += `${windowsDriveLetter}/`;
|
|
14
14
|
}
|
|
15
|
-
let i = 0
|
|
15
|
+
let i = 0;
|
|
16
16
|
// eslint-disable-next-line no-constant-condition
|
|
17
17
|
while (true) {
|
|
18
|
-
const name = parts[i]
|
|
19
|
-
i
|
|
20
|
-
let namesOnFileSystem
|
|
18
|
+
const name = parts[i];
|
|
19
|
+
i++;
|
|
20
|
+
let namesOnFileSystem;
|
|
21
21
|
try {
|
|
22
22
|
namesOnFileSystem = readdirSync(
|
|
23
23
|
// When Node.js receives "C:/" on windows it returns
|
|
24
24
|
// the process.cwd() directory content...
|
|
25
25
|
// This can be fixed by passing "file:///C:/" directly but as a url object
|
|
26
26
|
new URL(reconstructedFileUrl),
|
|
27
|
-
)
|
|
27
|
+
);
|
|
28
28
|
} catch (e) {
|
|
29
29
|
if (e && e.code === "ENOENT") {
|
|
30
|
-
return null
|
|
30
|
+
return null;
|
|
31
31
|
}
|
|
32
|
-
throw e
|
|
32
|
+
throw e;
|
|
33
33
|
}
|
|
34
|
-
const foundOnFilesystem = namesOnFileSystem.includes(name)
|
|
34
|
+
const foundOnFilesystem = namesOnFileSystem.includes(name);
|
|
35
35
|
if (foundOnFilesystem) {
|
|
36
|
-
reconstructedFileUrl += name
|
|
36
|
+
reconstructedFileUrl += name;
|
|
37
37
|
} else {
|
|
38
38
|
const nameOnFileSystem = namesOnFileSystem.find(
|
|
39
39
|
(nameCandidate) => nameCandidate.toLowerCase() === name.toLowerCase(),
|
|
40
|
-
)
|
|
40
|
+
);
|
|
41
41
|
if (!nameOnFileSystem) {
|
|
42
|
-
return null
|
|
42
|
+
return null;
|
|
43
43
|
}
|
|
44
|
-
reconstructedFileUrl += nameOnFileSystem
|
|
44
|
+
reconstructedFileUrl += nameOnFileSystem;
|
|
45
45
|
}
|
|
46
46
|
if (i === parts.length) {
|
|
47
47
|
if (followLink) {
|
|
48
48
|
const realPath = realpathSync.native(
|
|
49
49
|
urlToFileSystemPath(reconstructedFileUrl),
|
|
50
|
-
)
|
|
51
|
-
return fileSystemPathToUrl(realPath)
|
|
50
|
+
);
|
|
51
|
+
return fileSystemPathToUrl(realPath);
|
|
52
52
|
}
|
|
53
|
-
return reconstructedFileUrl
|
|
53
|
+
return reconstructedFileUrl;
|
|
54
54
|
}
|
|
55
|
-
reconstructedFileUrl += "/"
|
|
55
|
+
reconstructedFileUrl += "/";
|
|
56
56
|
}
|
|
57
|
-
}
|
|
57
|
+
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { assertAndNormalizeFileUrl } from "./file_url_validation.js"
|
|
2
|
-
import { readEntryPermissions } from "./readEntryPermissions.js"
|
|
3
|
-
import { writeEntryPermissions } from "./writeEntryPermissions.js"
|
|
1
|
+
import { assertAndNormalizeFileUrl } from "./file_url_validation.js";
|
|
2
|
+
import { readEntryPermissions } from "./readEntryPermissions.js";
|
|
3
|
+
import { writeEntryPermissions } from "./writeEntryPermissions.js";
|
|
4
4
|
|
|
5
5
|
export const grantPermissionsOnEntry = async (
|
|
6
6
|
source,
|
|
7
7
|
{ read = false, write = false, execute = false },
|
|
8
8
|
) => {
|
|
9
|
-
const sourceUrl = assertAndNormalizeFileUrl(source)
|
|
9
|
+
const sourceUrl = assertAndNormalizeFileUrl(source);
|
|
10
10
|
|
|
11
|
-
const filePermissions = await readEntryPermissions(sourceUrl)
|
|
11
|
+
const filePermissions = await readEntryPermissions(sourceUrl);
|
|
12
12
|
await writeEntryPermissions(sourceUrl, {
|
|
13
13
|
owner: { read, write, execute },
|
|
14
14
|
group: { read, write, execute },
|
|
15
15
|
others: { read, write, execute },
|
|
16
|
-
})
|
|
16
|
+
});
|
|
17
17
|
return async () => {
|
|
18
|
-
await writeEntryPermissions(sourceUrl, filePermissions)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
18
|
+
await writeEntryPermissions(sourceUrl, filePermissions);
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { watch, openSync, closeSync } from "node:fs"
|
|
1
|
+
import { watch, openSync, closeSync } from "node:fs";
|
|
2
2
|
|
|
3
|
-
const isWindows = process.platform === "win32"
|
|
3
|
+
const isWindows = process.platform === "win32";
|
|
4
4
|
|
|
5
5
|
export const createWatcher = (sourcePath, options) => {
|
|
6
|
-
const watcher = watch(sourcePath, options)
|
|
6
|
+
const watcher = watch(sourcePath, options);
|
|
7
7
|
|
|
8
8
|
if (isWindows) {
|
|
9
9
|
watcher.on("error", async (error) => {
|
|
10
10
|
// https://github.com/joyent/node/issues/4337
|
|
11
11
|
if (error.code === "EPERM") {
|
|
12
12
|
try {
|
|
13
|
-
const fd = openSync(sourcePath, "r")
|
|
14
|
-
closeSync(fd)
|
|
13
|
+
const fd = openSync(sourcePath, "r");
|
|
14
|
+
closeSync(fd);
|
|
15
15
|
} catch (e) {
|
|
16
16
|
if (e.code === "ENOENT") {
|
|
17
|
-
return
|
|
17
|
+
return;
|
|
18
18
|
}
|
|
19
|
-
console.error(`error while fixing windows eperm: ${e.stack}`)
|
|
20
|
-
throw error
|
|
19
|
+
console.error(`error while fixing windows eperm: ${e.stack}`);
|
|
20
|
+
throw error;
|
|
21
21
|
}
|
|
22
22
|
} else {
|
|
23
|
-
throw error
|
|
23
|
+
throw error;
|
|
24
24
|
}
|
|
25
|
-
})
|
|
25
|
+
});
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
return watcher
|
|
29
|
-
}
|
|
28
|
+
return watcher;
|
|
29
|
+
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export const getCommandArgument = (argv, name) => {
|
|
2
|
-
let i = 0
|
|
2
|
+
let i = 0;
|
|
3
3
|
|
|
4
4
|
while (i < argv.length) {
|
|
5
|
-
const arg = argv[i]
|
|
5
|
+
const arg = argv[i];
|
|
6
6
|
|
|
7
7
|
if (arg === name) {
|
|
8
8
|
return {
|
|
9
9
|
name,
|
|
10
10
|
index: i,
|
|
11
11
|
value: "",
|
|
12
|
-
}
|
|
12
|
+
};
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
if (arg.startsWith(`${name}=`)) {
|
|
@@ -17,11 +17,11 @@ export const getCommandArgument = (argv, name) => {
|
|
|
17
17
|
name,
|
|
18
18
|
index: i,
|
|
19
19
|
value: arg.slice(`${name}=`.length),
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
i
|
|
23
|
+
i++;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
return null
|
|
27
|
-
}
|
|
26
|
+
return null;
|
|
27
|
+
};
|
|
@@ -2,38 +2,38 @@ export const guardTooFastSecondCall = (
|
|
|
2
2
|
callback,
|
|
3
3
|
cooldownBetweenFileEvents = 40,
|
|
4
4
|
) => {
|
|
5
|
-
let previousCallMs
|
|
5
|
+
let previousCallMs;
|
|
6
6
|
return (...args) => {
|
|
7
|
-
const nowMs = Date.now()
|
|
7
|
+
const nowMs = Date.now();
|
|
8
8
|
if (previousCallMs) {
|
|
9
|
-
const msEllapsed = nowMs - previousCallMs
|
|
9
|
+
const msEllapsed = nowMs - previousCallMs;
|
|
10
10
|
if (msEllapsed < cooldownBetweenFileEvents) {
|
|
11
|
-
previousCallMs = null
|
|
12
|
-
return
|
|
11
|
+
previousCallMs = null;
|
|
12
|
+
return;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
previousCallMs = nowMs
|
|
16
|
-
callback(...args)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
15
|
+
previousCallMs = nowMs;
|
|
16
|
+
callback(...args);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
19
|
|
|
20
20
|
export const guardTooFastSecondCallPerFile = (
|
|
21
21
|
callback,
|
|
22
22
|
cooldownBetweenFileEvents = 40,
|
|
23
23
|
) => {
|
|
24
|
-
const previousCallMsMap = new Map()
|
|
24
|
+
const previousCallMsMap = new Map();
|
|
25
25
|
return (fileEvent) => {
|
|
26
|
-
const { relativeUrl } = fileEvent
|
|
27
|
-
const previousCallMs = previousCallMsMap.get(relativeUrl)
|
|
28
|
-
const nowMs = Date.now()
|
|
26
|
+
const { relativeUrl } = fileEvent;
|
|
27
|
+
const previousCallMs = previousCallMsMap.get(relativeUrl);
|
|
28
|
+
const nowMs = Date.now();
|
|
29
29
|
if (previousCallMs) {
|
|
30
|
-
const msEllapsed = nowMs - previousCallMs
|
|
30
|
+
const msEllapsed = nowMs - previousCallMs;
|
|
31
31
|
if (msEllapsed < cooldownBetweenFileEvents) {
|
|
32
|
-
previousCallMsMap.delete(relativeUrl)
|
|
33
|
-
return
|
|
32
|
+
previousCallMsMap.delete(relativeUrl);
|
|
33
|
+
return;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
previousCallMsMap.set(relativeUrl, nowMs)
|
|
37
|
-
callback(fileEvent)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
36
|
+
previousCallMsMap.set(relativeUrl, nowMs);
|
|
37
|
+
callback(fileEvent);
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
// https://github.com/TooTallNate/stat-mode
|
|
4
4
|
|
|
5
5
|
// cannot get from fs.constants because they are not available on windows
|
|
6
|
-
const S_IRUSR = 256 /* 0000400 read permission, owner */
|
|
7
|
-
const S_IWUSR = 128 /* 0000200 write permission, owner */
|
|
8
|
-
const S_IXUSR = 64 /* 0000100 execute/search permission, owner */
|
|
9
|
-
const S_IRGRP = 32 /* 0000040 read permission, group */
|
|
10
|
-
const S_IWGRP = 16 /* 0000020 write permission, group */
|
|
11
|
-
const S_IXGRP = 8 /* 0000010 execute/search permission, group */
|
|
12
|
-
const S_IROTH = 4 /* 0000004 read permission, others */
|
|
13
|
-
const S_IWOTH = 2 /* 0000002 write permission, others */
|
|
14
|
-
const S_IXOTH = 1 /* 0000001 execute/search permission, others */
|
|
6
|
+
const S_IRUSR = 256; /* 0000400 read permission, owner */
|
|
7
|
+
const S_IWUSR = 128; /* 0000200 write permission, owner */
|
|
8
|
+
const S_IXUSR = 64; /* 0000100 execute/search permission, owner */
|
|
9
|
+
const S_IRGRP = 32; /* 0000040 read permission, group */
|
|
10
|
+
const S_IWGRP = 16; /* 0000020 write permission, group */
|
|
11
|
+
const S_IXGRP = 8; /* 0000010 execute/search permission, group */
|
|
12
|
+
const S_IROTH = 4; /* 0000004 read permission, others */
|
|
13
|
+
const S_IWOTH = 2; /* 0000002 write permission, others */
|
|
14
|
+
const S_IXOTH = 1; /* 0000001 execute/search permission, others */
|
|
15
15
|
|
|
16
16
|
/*
|
|
17
17
|
here we could warn that on windows only 0o444 or 0o666 will work
|
|
@@ -35,41 +35,41 @@ export const binaryFlagsToPermissions = (binaryFlags) => {
|
|
|
35
35
|
read: Boolean(binaryFlags & S_IRUSR),
|
|
36
36
|
write: Boolean(binaryFlags & S_IWUSR),
|
|
37
37
|
execute: Boolean(binaryFlags & S_IXUSR),
|
|
38
|
-
}
|
|
38
|
+
};
|
|
39
39
|
|
|
40
40
|
const group = {
|
|
41
41
|
read: Boolean(binaryFlags & S_IRGRP),
|
|
42
42
|
write: Boolean(binaryFlags & S_IWGRP),
|
|
43
43
|
execute: Boolean(binaryFlags & S_IXGRP),
|
|
44
|
-
}
|
|
44
|
+
};
|
|
45
45
|
|
|
46
46
|
const others = {
|
|
47
47
|
read: Boolean(binaryFlags & S_IROTH),
|
|
48
48
|
write: Boolean(binaryFlags & S_IWOTH),
|
|
49
49
|
execute: Boolean(binaryFlags & S_IXOTH),
|
|
50
|
-
}
|
|
50
|
+
};
|
|
51
51
|
|
|
52
52
|
return {
|
|
53
53
|
owner,
|
|
54
54
|
group,
|
|
55
55
|
others,
|
|
56
|
-
}
|
|
57
|
-
}
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
58
|
|
|
59
59
|
export const permissionsToBinaryFlags = ({ owner, group, others }) => {
|
|
60
|
-
let binaryFlags = 0
|
|
60
|
+
let binaryFlags = 0;
|
|
61
61
|
|
|
62
|
-
if (owner.read) binaryFlags |= S_IRUSR
|
|
63
|
-
if (owner.write) binaryFlags |= S_IWUSR
|
|
64
|
-
if (owner.execute) binaryFlags |= S_IXUSR
|
|
62
|
+
if (owner.read) binaryFlags |= S_IRUSR;
|
|
63
|
+
if (owner.write) binaryFlags |= S_IWUSR;
|
|
64
|
+
if (owner.execute) binaryFlags |= S_IXUSR;
|
|
65
65
|
|
|
66
|
-
if (group.read) binaryFlags |= S_IRGRP
|
|
67
|
-
if (group.write) binaryFlags |= S_IWGRP
|
|
68
|
-
if (group.execute) binaryFlags |= S_IXGRP
|
|
66
|
+
if (group.read) binaryFlags |= S_IRGRP;
|
|
67
|
+
if (group.write) binaryFlags |= S_IWGRP;
|
|
68
|
+
if (group.execute) binaryFlags |= S_IXGRP;
|
|
69
69
|
|
|
70
|
-
if (others.read) binaryFlags |= S_IROTH
|
|
71
|
-
if (others.write) binaryFlags |= S_IWOTH
|
|
72
|
-
if (others.execute) binaryFlags |= S_IXOTH
|
|
70
|
+
if (others.read) binaryFlags |= S_IROTH;
|
|
71
|
+
if (others.write) binaryFlags |= S_IWOTH;
|
|
72
|
+
if (others.execute) binaryFlags |= S_IXOTH;
|
|
73
73
|
|
|
74
|
-
return binaryFlags
|
|
75
|
-
}
|
|
74
|
+
return binaryFlags;
|
|
75
|
+
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { statSync } from "node:fs"
|
|
1
|
+
import { statSync } from "node:fs";
|
|
2
2
|
|
|
3
|
-
import { statsToType } from "./statsToType.js"
|
|
3
|
+
import { statsToType } from "./statsToType.js";
|
|
4
4
|
|
|
5
5
|
export const readEntryInfo = (url) => {
|
|
6
6
|
try {
|
|
7
|
-
const stats = statSync(new URL(url))
|
|
8
|
-
const type = statsToType(stats)
|
|
7
|
+
const stats = statSync(new URL(url));
|
|
8
|
+
const type = statsToType(stats);
|
|
9
9
|
return {
|
|
10
10
|
type,
|
|
11
11
|
atimeMs: stats.atimeMs,
|
|
12
12
|
mtimeMs: stats.mtimeMs,
|
|
13
|
-
}
|
|
13
|
+
};
|
|
14
14
|
} catch (e) {
|
|
15
15
|
if (e.code === "ENOENT") {
|
|
16
|
-
return null
|
|
16
|
+
return null;
|
|
17
17
|
}
|
|
18
|
-
throw e
|
|
18
|
+
throw e;
|
|
19
19
|
}
|
|
20
|
-
}
|
|
20
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export const statsToType = (stats) => {
|
|
2
|
-
if (stats.isFile()) return "file"
|
|
3
|
-
if (stats.isDirectory()) return "directory"
|
|
4
|
-
if (stats.isSymbolicLink()) return "symbolic-link"
|
|
5
|
-
if (stats.isFIFO()) return "fifo"
|
|
6
|
-
if (stats.isSocket()) return "socket"
|
|
7
|
-
if (stats.isCharacterDevice()) return "character-device"
|
|
8
|
-
if (stats.isBlockDevice()) return "block-device"
|
|
9
|
-
return undefined
|
|
10
|
-
}
|
|
2
|
+
if (stats.isFile()) return "file";
|
|
3
|
+
if (stats.isDirectory()) return "directory";
|
|
4
|
+
if (stats.isSymbolicLink()) return "symbolic-link";
|
|
5
|
+
if (stats.isFIFO()) return "fifo";
|
|
6
|
+
if (stats.isSocket()) return "socket";
|
|
7
|
+
if (stats.isCharacterDevice()) return "character-device";
|
|
8
|
+
if (stats.isBlockDevice()) return "block-device";
|
|
9
|
+
return undefined;
|
|
10
|
+
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
export const trackResources = () => {
|
|
2
|
-
const callbackArray = []
|
|
2
|
+
const callbackArray = [];
|
|
3
3
|
|
|
4
4
|
const registerCleanupCallback = (callback) => {
|
|
5
5
|
if (typeof callback !== "function")
|
|
6
6
|
throw new TypeError(`callback must be a function
|
|
7
|
-
callback: ${callback}`)
|
|
8
|
-
callbackArray.push(callback)
|
|
7
|
+
callback: ${callback}`);
|
|
8
|
+
callbackArray.push(callback);
|
|
9
9
|
return () => {
|
|
10
|
-
const index = callbackArray.indexOf(callback)
|
|
11
|
-
if (index > -1) callbackArray.splice(index, 1)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
10
|
+
const index = callbackArray.indexOf(callback);
|
|
11
|
+
if (index > -1) callbackArray.splice(index, 1);
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
14
|
|
|
15
15
|
const cleanup = async (reason) => {
|
|
16
|
-
const localCallbackArray = callbackArray.slice()
|
|
17
|
-
await Promise.all(localCallbackArray.map((callback) => callback(reason)))
|
|
18
|
-
}
|
|
16
|
+
const localCallbackArray = callbackArray.slice();
|
|
17
|
+
await Promise.all(localCallbackArray.map((callback) => callback(reason)));
|
|
18
|
+
};
|
|
19
19
|
|
|
20
|
-
return { registerCleanupCallback, cleanup }
|
|
21
|
-
}
|
|
20
|
+
return { registerCleanupCallback, cleanup };
|
|
21
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const urlTargetsSameFileSystemPath = (leftUrl, rightUrl) => {
|
|
2
|
-
if (leftUrl.endsWith("/")) leftUrl = leftUrl.slice(0, -1)
|
|
3
|
-
if (rightUrl.endsWith("/")) rightUrl = rightUrl.slice(0, -1)
|
|
4
|
-
return leftUrl === rightUrl
|
|
5
|
-
}
|
|
2
|
+
if (leftUrl.endsWith("/")) leftUrl = leftUrl.slice(0, -1);
|
|
3
|
+
if (rightUrl.endsWith("/")) rightUrl = rightUrl.slice(0, -1);
|
|
4
|
+
return leftUrl === rightUrl;
|
|
5
|
+
};
|
package/src/listFilesMatching.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { collectFiles } from "./collectFiles.js"
|
|
1
|
+
import { collectFiles } from "./collectFiles.js";
|
|
2
2
|
|
|
3
3
|
export const listFilesMatching = async ({
|
|
4
4
|
directoryUrl = process.cwd(),
|
|
@@ -6,13 +6,13 @@ export const listFilesMatching = async ({
|
|
|
6
6
|
signal,
|
|
7
7
|
}) => {
|
|
8
8
|
if (typeof patterns !== "object" || patterns === null) {
|
|
9
|
-
throw new TypeError(`patterns must be an object, got ${patterns}`)
|
|
9
|
+
throw new TypeError(`patterns must be an object, got ${patterns}`);
|
|
10
10
|
}
|
|
11
11
|
const fileDatas = await collectFiles({
|
|
12
12
|
signal,
|
|
13
13
|
directoryUrl,
|
|
14
14
|
associations: { matches: patterns },
|
|
15
15
|
predicate: ({ matches }) => matches,
|
|
16
|
-
})
|
|
17
|
-
return fileDatas.map(({ url }) => url)
|
|
18
|
-
}
|
|
16
|
+
});
|
|
17
|
+
return fileDatas.map(({ url }) => url);
|
|
18
|
+
};
|
package/src/main.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
export {
|
|
2
2
|
validateDirectoryUrl,
|
|
3
3
|
assertAndNormalizeDirectoryUrl,
|
|
4
|
-
} from "./directory_url_validation.js"
|
|
4
|
+
} from "./directory_url_validation.js";
|
|
5
5
|
export {
|
|
6
6
|
validateFileUrl,
|
|
7
7
|
assertAndNormalizeFileUrl,
|
|
8
|
-
} from "./file_url_validation.js"
|
|
9
|
-
export { assertDirectoryPresence } from "./assertDirectoryPresence.js"
|
|
10
|
-
export { assertFilePresence } from "./assertFilePresence.js"
|
|
11
|
-
export { bufferToEtag } from "./bufferToEtag.js"
|
|
12
|
-
export { collectDirectoryMatchReport } from "./collectDirectoryMatchReport.js"
|
|
13
|
-
export { collectFiles } from "./collectFiles.js"
|
|
14
|
-
export { comparePathnames } from "./comparePathnames.js"
|
|
15
|
-
export { ensureEmptyDirectory } from "./ensureEmptyDirectory.js"
|
|
16
|
-
export { ensureParentDirectories } from "./ensureParentDirectories.js"
|
|
17
|
-
export { ensureWindowsDriveLetter } from "./ensureWindowsDriveLetter.js"
|
|
18
|
-
export { copyEntry } from "./copyEntry.js"
|
|
19
|
-
export { copyDirectoryContent } from "./copyDirectoryContent.js"
|
|
20
|
-
export { getRealFileSystemUrlSync } from "./getRealFileSystemUrlSync.js"
|
|
21
|
-
export { grantPermissionsOnEntry } from "./grantPermissionsOnEntry.js"
|
|
22
|
-
export { listFilesMatching } from "./listFilesMatching.js"
|
|
23
|
-
export { moveDirectoryContent } from "./moveDirectoryContent.js"
|
|
24
|
-
export { moveEntry } from "./moveEntry.js"
|
|
25
|
-
export { readDirectory } from "./readDirectory.js"
|
|
26
|
-
export { readFile } from "./readFile.js"
|
|
27
|
-
export { readFileSync } from "./readFileSync.js"
|
|
28
|
-
export { readEntryModificationTime } from "./readEntryModificationTime.js"
|
|
29
|
-
export { readEntryPermissions } from "./readEntryPermissions.js"
|
|
30
|
-
export { readEntryStat } from "./readEntryStat.js"
|
|
31
|
-
export { readSymbolicLink } from "./readSymbolicLink.js"
|
|
32
|
-
export { registerDirectoryLifecycle } from "./registerDirectoryLifecycle.js"
|
|
33
|
-
export { registerFileLifecycle } from "./registerFileLifecycle.js"
|
|
34
|
-
export { removeEntry } from "./removeEntry.js"
|
|
35
|
-
export { testEntryPermissions } from "./testEntryPermissions.js"
|
|
36
|
-
export { writeDirectory } from "./writeDirectory.js"
|
|
37
|
-
export { writeFile } from "./writeFile.js"
|
|
38
|
-
export { writeFileSync } from "./writeFileSync.js"
|
|
39
|
-
export { writeEntryModificationTime } from "./writeEntryModificationTime.js"
|
|
40
|
-
export { writeEntryPermissions } from "./writeEntryPermissions.js"
|
|
41
|
-
export { writeSymbolicLink } from "./writeSymbolicLink.js"
|
|
8
|
+
} from "./file_url_validation.js";
|
|
9
|
+
export { assertDirectoryPresence } from "./assertDirectoryPresence.js";
|
|
10
|
+
export { assertFilePresence } from "./assertFilePresence.js";
|
|
11
|
+
export { bufferToEtag } from "./bufferToEtag.js";
|
|
12
|
+
export { collectDirectoryMatchReport } from "./collectDirectoryMatchReport.js";
|
|
13
|
+
export { collectFiles } from "./collectFiles.js";
|
|
14
|
+
export { comparePathnames } from "./comparePathnames.js";
|
|
15
|
+
export { ensureEmptyDirectory } from "./ensureEmptyDirectory.js";
|
|
16
|
+
export { ensureParentDirectories } from "./ensureParentDirectories.js";
|
|
17
|
+
export { ensureWindowsDriveLetter } from "./ensureWindowsDriveLetter.js";
|
|
18
|
+
export { copyEntry } from "./copyEntry.js";
|
|
19
|
+
export { copyDirectoryContent } from "./copyDirectoryContent.js";
|
|
20
|
+
export { getRealFileSystemUrlSync } from "./getRealFileSystemUrlSync.js";
|
|
21
|
+
export { grantPermissionsOnEntry } from "./grantPermissionsOnEntry.js";
|
|
22
|
+
export { listFilesMatching } from "./listFilesMatching.js";
|
|
23
|
+
export { moveDirectoryContent } from "./moveDirectoryContent.js";
|
|
24
|
+
export { moveEntry } from "./moveEntry.js";
|
|
25
|
+
export { readDirectory } from "./readDirectory.js";
|
|
26
|
+
export { readFile } from "./readFile.js";
|
|
27
|
+
export { readFileSync } from "./readFileSync.js";
|
|
28
|
+
export { readEntryModificationTime } from "./readEntryModificationTime.js";
|
|
29
|
+
export { readEntryPermissions } from "./readEntryPermissions.js";
|
|
30
|
+
export { readEntryStat } from "./readEntryStat.js";
|
|
31
|
+
export { readSymbolicLink } from "./readSymbolicLink.js";
|
|
32
|
+
export { registerDirectoryLifecycle } from "./registerDirectoryLifecycle.js";
|
|
33
|
+
export { registerFileLifecycle } from "./registerFileLifecycle.js";
|
|
34
|
+
export { removeEntry } from "./removeEntry.js";
|
|
35
|
+
export { testEntryPermissions } from "./testEntryPermissions.js";
|
|
36
|
+
export { writeDirectory } from "./writeDirectory.js";
|
|
37
|
+
export { writeFile } from "./writeFile.js";
|
|
38
|
+
export { writeFileSync } from "./writeFileSync.js";
|
|
39
|
+
export { writeEntryModificationTime } from "./writeEntryModificationTime.js";
|
|
40
|
+
export { writeEntryPermissions } from "./writeEntryPermissions.js";
|
|
41
|
+
export { writeSymbolicLink } from "./writeSymbolicLink.js";
|