@jsenv/filesystem 4.1.1 → 4.1.2
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/package.json +1 -1
- package/src/collectFiles.js +0 -1
- package/src/ensureWindowsDriveLetter.js +3 -3
- package/src/internal/{trackRessources.js → track_resources.js} +1 -1
- package/src/readDirectory.js +22 -37
- package/src/registerDirectoryLifecycle.js +3 -3
- package/src/registerFileLifecycle.js +2 -2
package/package.json
CHANGED
package/src/collectFiles.js
CHANGED
|
@@ -30,7 +30,6 @@ export const collectFiles = async ({
|
|
|
30
30
|
await Promise.all(
|
|
31
31
|
directoryItems.map(async (directoryItem) => {
|
|
32
32
|
const directoryChildNodeUrl = `${directoryUrl}${directoryItem}`
|
|
33
|
-
|
|
34
33
|
collectOperation.throwIfAborted()
|
|
35
34
|
const directoryChildNodeStats = await readEntryStat(
|
|
36
35
|
directoryChildNodeUrl,
|
|
@@ -59,10 +59,10 @@ export const ensureWindowsDriveLetter = (url, baseUrl) => {
|
|
|
59
59
|
return `file:///${driveLetter}:${afterProtocol}`
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
const extractDriveLetter = (
|
|
62
|
+
const extractDriveLetter = (resource) => {
|
|
63
63
|
// we still have the windows drive letter
|
|
64
|
-
if (/[a-zA-Z]/.test(
|
|
65
|
-
return
|
|
64
|
+
if (/[a-zA-Z]/.test(resource[1]) && resource[2] === ":") {
|
|
65
|
+
return resource[1]
|
|
66
66
|
}
|
|
67
67
|
return null
|
|
68
68
|
}
|
package/src/readDirectory.js
CHANGED
|
@@ -1,54 +1,39 @@
|
|
|
1
1
|
import { readdir } from "node:fs"
|
|
2
|
-
import { urlToFileSystemPath } from "@jsenv/urls"
|
|
3
2
|
import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js"
|
|
4
3
|
|
|
5
4
|
export const readDirectory = async (url, { emfileMaxWait = 1000 } = {}) => {
|
|
6
5
|
const directoryUrl = assertAndNormalizeDirectoryUrl(url)
|
|
7
|
-
const
|
|
6
|
+
const directoryUrlObject = new URL(directoryUrl)
|
|
8
7
|
const startMs = Date.now()
|
|
9
8
|
let attemptCount = 0
|
|
10
9
|
|
|
11
|
-
const attempt = () => {
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const attempt = async () => {
|
|
11
|
+
try {
|
|
12
|
+
const names = await new Promise((resolve, reject) => {
|
|
13
|
+
readdir(directoryUrlObject, (error, names) => {
|
|
14
|
+
if (error) {
|
|
15
|
+
reject(error)
|
|
16
|
+
} else {
|
|
17
|
+
resolve(names)
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
return names.map(encodeURIComponent)
|
|
22
|
+
} catch (e) {
|
|
23
|
+
// https://nodejs.org/dist/latest-v13.x/docs/api/errors.html#errors_common_system_errors
|
|
24
|
+
if (e.code === "EMFILE" || e.code === "ENFILE") {
|
|
14
25
|
attemptCount++
|
|
15
26
|
const nowMs = Date.now()
|
|
16
27
|
const timeSpentWaiting = nowMs - startMs
|
|
17
28
|
if (timeSpentWaiting > emfileMaxWait) {
|
|
18
|
-
throw
|
|
29
|
+
throw e
|
|
19
30
|
}
|
|
20
|
-
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})
|
|
26
|
-
},
|
|
27
|
-
})
|
|
31
|
+
await new Promise((resolve) => setTimeout(resolve), attemptCount)
|
|
32
|
+
return await attempt()
|
|
33
|
+
}
|
|
34
|
+
throw e
|
|
35
|
+
}
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
return attempt()
|
|
31
39
|
}
|
|
32
|
-
|
|
33
|
-
const readdirNaive = (
|
|
34
|
-
directoryPath,
|
|
35
|
-
{ handleTooManyFilesOpenedError = null } = {},
|
|
36
|
-
) => {
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
readdir(directoryPath, (error, names) => {
|
|
39
|
-
if (error) {
|
|
40
|
-
// https://nodejs.org/dist/latest-v13.x/docs/api/errors.html#errors_common_system_errors
|
|
41
|
-
if (
|
|
42
|
-
handleTooManyFilesOpenedError &&
|
|
43
|
-
(error.code === "EMFILE" || error.code === "ENFILE")
|
|
44
|
-
) {
|
|
45
|
-
resolve(handleTooManyFilesOpenedError(error))
|
|
46
|
-
} else {
|
|
47
|
-
reject(error)
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
resolve(names)
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
-
}
|
|
@@ -6,7 +6,7 @@ import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl
|
|
|
6
6
|
import { statsToType } from "./internal/statsToType.js"
|
|
7
7
|
import { guardTooFastSecondCallPerFile } from "./internal/guard_second_call.js"
|
|
8
8
|
import { createWatcher } from "./internal/createWatcher.js"
|
|
9
|
-
import {
|
|
9
|
+
import { trackResources } from "./internal/track_resources.js"
|
|
10
10
|
|
|
11
11
|
const isLinux = process.platform === "linux"
|
|
12
12
|
// linux does not support recursive option
|
|
@@ -87,7 +87,7 @@ export const registerDirectoryLifecycle = (
|
|
|
87
87
|
const { watch } = URL_META.applyAssociations({ url, associations })
|
|
88
88
|
return watch
|
|
89
89
|
}
|
|
90
|
-
const tracker =
|
|
90
|
+
const tracker = trackResources()
|
|
91
91
|
const infoMap = new Map()
|
|
92
92
|
const readEntryInfo = (url) => {
|
|
93
93
|
try {
|
|
@@ -205,7 +205,7 @@ export const registerDirectoryLifecycle = (
|
|
|
205
205
|
}
|
|
206
206
|
if (entryInfo.type !== previousInfo.type) {
|
|
207
207
|
// it existed and was replaced by something else
|
|
208
|
-
// we don't handle this as an update. We rather say the
|
|
208
|
+
// we don't handle this as an update. We rather say the resource
|
|
209
209
|
// is lost and something else is found (call removed() then added())
|
|
210
210
|
handleEntryLost(previousInfo)
|
|
211
211
|
handleEntryFound(entryInfo)
|
|
@@ -6,7 +6,7 @@ import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js"
|
|
|
6
6
|
import { guardTooFastSecondCall } from "./internal/guard_second_call.js"
|
|
7
7
|
import { statsToType } from "./internal/statsToType.js"
|
|
8
8
|
import { createWatcher } from "./internal/createWatcher.js"
|
|
9
|
-
import {
|
|
9
|
+
import { trackResources } from "./internal/track_resources.js"
|
|
10
10
|
|
|
11
11
|
export const registerFileLifecycle = (
|
|
12
12
|
source,
|
|
@@ -45,7 +45,7 @@ export const registerFileLifecycle = (
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const tracker =
|
|
48
|
+
const tracker = trackResources()
|
|
49
49
|
|
|
50
50
|
const handleFileFound = ({ existent }) => {
|
|
51
51
|
const fileMutationStopWatching = watchFileMutation(sourceUrl, {
|