@jsenv/filesystem 3.2.0 → 4.0.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 -16
- package/main.js +0 -28
- package/package.json +11 -32
- package/src/assertAndNormalizeDirectoryUrl.js +6 -4
- package/src/assertAndNormalizeFileUrl.js +1 -2
- package/src/assertDirectoryPresence.js +2 -2
- package/src/assertFilePresence.js +2 -2
- package/src/collectDirectoryMatchReport.js +10 -17
- package/src/collectFiles.js +7 -15
- package/src/copyDirectoryContent.js +1 -2
- package/src/copyEntry.js +9 -7
- package/src/ensureEmptyDirectory.js +2 -2
- package/src/ensureParentDirectories.js +1 -1
- package/src/ensureWindowsDriveLetter.js +1 -1
- package/src/getRealFileSystemUrlSync.js +1 -3
- package/src/listFilesMatching.js +1 -5
- package/src/moveDirectoryContent.js +1 -2
- package/src/moveEntry.js +1 -2
- package/src/readDirectory.js +2 -2
- package/src/readEntryPermissions.js +1 -1
- package/src/readEntryStat.js +1 -1
- package/src/readFile.js +9 -3
- package/src/readSymbolicLink.js +3 -7
- package/src/registerDirectoryLifecycle.js +14 -21
- package/src/registerFileLifecycle.js +2 -2
- package/src/removeEntry.js +6 -4
- package/src/testEntryPermissions.js +1 -3
- package/src/writeDirectory.js +2 -2
- package/src/writeEntryModificationTime.js +1 -3
- package/src/writeEntryPermissions.js +1 -7
- package/src/writeFile.js +15 -6
- package/src/writeSymbolicLink.js +6 -4
- package/LICENSE +0 -21
- package/src/fileSystemPathToUrl.js +0 -9
- package/src/internal/ensureUrlTrailingSlash.js +0 -3
- package/src/internal/getCommonPathname.js +0 -42
- package/src/internal/getCommonPathname.test.js +0 -62
- package/src/internal/pathnameToParentPathname.js +0 -8
- package/src/internal/replaceBackSlashesWithSlashes.js +0 -2
- package/src/isFileSystemPath.js +0 -23
- package/src/memoize.js +0 -24
- package/src/moveUrl.js +0 -10
- package/src/resolveDirectoryUrl.js +0 -7
- package/src/resolveUrl.js +0 -7
- package/src/urlIsInsideOf.js +0 -17
- package/src/urlToBasename.js +0 -9
- package/src/urlToExtension.js +0 -19
- package/src/urlToFileSystemPath.js +0 -12
- package/src/urlToFilename.js +0 -14
- package/src/urlToOrigin.js +0 -7
- package/src/urlToParentUrl.js +0 -31
- package/src/urlToPathname.js +0 -19
- package/src/urlToRelativeUrl.js +0 -49
- package/src/urlToRessource.js +0 -21
- package/src/urlToScheme.js +0 -10
package/README.md
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
# Jsenv filesystem [](https://www.npmjs.com/package/@jsenv/filesystem)
|
|
1
|
+
# Jsenv filesystem [](https://www.npmjs.com/package/@jsenv/filesystem)
|
|
2
2
|
|
|
3
3
|
Collection of functions to interact with filesystem in Node.js
|
|
4
4
|
|
|
5
|
-
## Get a relative url
|
|
6
|
-
|
|
7
|
-
```js
|
|
8
|
-
import { urlToRelativeUrl } from "@jsenv/filesystem"
|
|
9
|
-
|
|
10
|
-
const projectDirectoryUrl = "file:///project/"
|
|
11
|
-
const jsFileUrl = "file:///project/src/file.js"
|
|
12
|
-
const relativeUrl = urlToRelativeUrl(jsFileUrl, projectDirectoryUrl)
|
|
13
|
-
console.log(relativeUrl) // "src/file.js"
|
|
14
|
-
```
|
|
15
|
-
|
|
16
5
|
## List files using pattern matching
|
|
17
6
|
|
|
18
7
|
```js
|
|
@@ -87,7 +76,3 @@ unregister() // stop watching the directory changes
|
|
|
87
76
|
```console
|
|
88
77
|
npm install @jsenv/filesystem
|
|
89
78
|
```
|
|
90
|
-
|
|
91
|
-
# Development
|
|
92
|
-
|
|
93
|
-
If you are part or want to be part of the developpers of this package, check [docs/development.md](./docs/development.md)
|
package/main.js
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
// we won't internalize @jsenv/url-meta
|
|
2
|
-
// so that @jsenv/url-meta does not becomes nodejs specific
|
|
3
|
-
// but these functions could be inside this repository
|
|
4
|
-
export {
|
|
5
|
-
applyPatternMatching,
|
|
6
|
-
normalizeStructuredMetaMap,
|
|
7
|
-
urlCanContainsMetaMatching,
|
|
8
|
-
urlToMeta,
|
|
9
|
-
} from "@jsenv/url-meta"
|
|
10
|
-
|
|
11
1
|
export { assertAndNormalizeDirectoryUrl } from "./src/assertAndNormalizeDirectoryUrl.js"
|
|
12
2
|
export { assertAndNormalizeFileUrl } from "./src/assertAndNormalizeFileUrl.js"
|
|
13
3
|
export { assertDirectoryPresence } from "./src/assertDirectoryPresence.js"
|
|
@@ -21,16 +11,11 @@ export { ensureParentDirectories } from "./src/ensureParentDirectories.js"
|
|
|
21
11
|
export { ensureWindowsDriveLetter } from "./src/ensureWindowsDriveLetter.js"
|
|
22
12
|
export { copyEntry } from "./src/copyEntry.js"
|
|
23
13
|
export { copyDirectoryContent } from "./src/copyDirectoryContent.js"
|
|
24
|
-
export { fileSystemPathToUrl } from "./src/fileSystemPathToUrl.js"
|
|
25
|
-
export { fileSystemRootUrl } from "./src/fileSystemRootUrl.js"
|
|
26
14
|
export { getRealFileSystemUrlSync } from "./src/getRealFileSystemUrlSync.js"
|
|
27
15
|
export { grantPermissionsOnEntry } from "./src/grantPermissionsOnEntry.js"
|
|
28
|
-
export { isFileSystemPath } from "./src/isFileSystemPath.js"
|
|
29
16
|
export { listFilesMatching } from "./src/listFilesMatching.js"
|
|
30
|
-
export { memoize } from "./src/memoize.js"
|
|
31
17
|
export { moveDirectoryContent } from "./src/moveDirectoryContent.js"
|
|
32
18
|
export { moveEntry } from "./src/moveEntry.js"
|
|
33
|
-
export { moveUrl } from "./src/moveUrl.js"
|
|
34
19
|
export { readDirectory } from "./src/readDirectory.js"
|
|
35
20
|
export { readFile } from "./src/readFile.js"
|
|
36
21
|
export { readFileSync } from "./src/readFileSync.js"
|
|
@@ -41,20 +26,7 @@ export { readSymbolicLink } from "./src/readSymbolicLink.js"
|
|
|
41
26
|
export { registerDirectoryLifecycle } from "./src/registerDirectoryLifecycle.js"
|
|
42
27
|
export { registerFileLifecycle } from "./src/registerFileLifecycle.js"
|
|
43
28
|
export { removeEntry } from "./src/removeEntry.js"
|
|
44
|
-
export { resolveDirectoryUrl } from "./src/resolveDirectoryUrl.js"
|
|
45
|
-
export { resolveUrl } from "./src/resolveUrl.js"
|
|
46
29
|
export { testEntryPermissions } from "./src/testEntryPermissions.js"
|
|
47
|
-
export { urlIsInsideOf } from "./src/urlIsInsideOf.js"
|
|
48
|
-
export { urlToBasename } from "./src/urlToBasename.js"
|
|
49
|
-
export { urlToExtension } from "./src/urlToExtension.js"
|
|
50
|
-
export { urlToFilename } from "./src/urlToFilename.js"
|
|
51
|
-
export { urlToFileSystemPath } from "./src/urlToFileSystemPath.js"
|
|
52
|
-
export { urlToOrigin } from "./src/urlToOrigin.js"
|
|
53
|
-
export { urlToParentUrl } from "./src/urlToParentUrl.js"
|
|
54
|
-
export { urlToPathname } from "./src/urlToPathname.js"
|
|
55
|
-
export { urlToRelativeUrl } from "./src/urlToRelativeUrl.js"
|
|
56
|
-
export { urlToRessource } from "./src/urlToRessource.js"
|
|
57
|
-
export { urlToScheme } from "./src/urlToScheme.js"
|
|
58
30
|
export { writeDirectory } from "./src/writeDirectory.js"
|
|
59
31
|
export { writeFile } from "./src/writeFile.js"
|
|
60
32
|
export { writeFileSync } from "./src/writeFileSync.js"
|
package/package.json
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/filesystem",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Collection of functions to interact with filesystem in Node.js",
|
|
3
|
+
"version": "4.0.0",
|
|
5
4
|
"license": "MIT",
|
|
6
|
-
"author": {
|
|
7
|
-
"name": "dmail",
|
|
8
|
-
"email": "dmaillard06@gmail.com",
|
|
9
|
-
"url": "https://twitter.com/damienmaillard"
|
|
10
|
-
},
|
|
11
5
|
"repository": {
|
|
12
6
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/jsenv/
|
|
14
|
-
|
|
15
|
-
"engines": {
|
|
16
|
-
"node": ">=16.13.0"
|
|
7
|
+
"url": "https://github.com/jsenv/jsenv-core",
|
|
8
|
+
"directory": "packages/filesystem"
|
|
17
9
|
},
|
|
18
10
|
"publishConfig": {
|
|
19
11
|
"access": "public"
|
|
20
12
|
},
|
|
13
|
+
"author": {
|
|
14
|
+
"name": "dmail",
|
|
15
|
+
"email": "dmaillard06@gmail.com",
|
|
16
|
+
"url": "https://twitter.com/damienmaillard"
|
|
17
|
+
},
|
|
21
18
|
"type": "module",
|
|
22
19
|
"exports": {
|
|
23
20
|
".": {
|
|
@@ -25,34 +22,16 @@
|
|
|
25
22
|
},
|
|
26
23
|
"./*": "./*"
|
|
27
24
|
},
|
|
28
|
-
"main": "./main.js",
|
|
29
25
|
"files": [
|
|
30
26
|
"/src/",
|
|
31
27
|
"/main.js"
|
|
32
28
|
],
|
|
33
29
|
"scripts": {
|
|
34
|
-
"
|
|
35
|
-
"importmap": "node ./script/importmap/importmap.mjs",
|
|
36
|
-
"performance": "node --expose-gc ./script/performance/performance.mjs --log",
|
|
37
|
-
"test": "node ./script/test/test.mjs",
|
|
38
|
-
"test-with-coverage": "npm run test -- --coverage",
|
|
39
|
-
"prettier": "prettier --write ."
|
|
30
|
+
"test": "node --conditions=development ./test.mjs"
|
|
40
31
|
},
|
|
41
32
|
"dependencies": {
|
|
33
|
+
"@jsenv/urls": "1.1.0",
|
|
42
34
|
"@jsenv/abort": "4.1.2",
|
|
43
|
-
"@jsenv/
|
|
44
|
-
},
|
|
45
|
-
"devDependencies": {
|
|
46
|
-
"@jsenv/assert": "2.4.1",
|
|
47
|
-
"@jsenv/core": "25.2.1",
|
|
48
|
-
"@jsenv/eslint-config": "16.0.9",
|
|
49
|
-
"@jsenv/github-release-package": "1.2.3",
|
|
50
|
-
"@jsenv/importmap-eslint-resolver": "5.2.2",
|
|
51
|
-
"@jsenv/importmap-node-module": "5.1.0",
|
|
52
|
-
"@jsenv/package-publish": "1.6.2",
|
|
53
|
-
"@jsenv/performance-impact": "2.2.1",
|
|
54
|
-
"eslint": "8.7.0",
|
|
55
|
-
"eslint-plugin-import": "2.25.4",
|
|
56
|
-
"prettier": "2.5.1"
|
|
35
|
+
"@jsenv/log": "1.6.3"
|
|
57
36
|
}
|
|
58
37
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
fileSystemPathToUrl,
|
|
3
|
+
isFileSystemPath,
|
|
4
|
+
ensurePathnameTrailingSlash,
|
|
5
|
+
} from "@jsenv/urls"
|
|
4
6
|
|
|
5
7
|
export const assertAndNormalizeDirectoryUrl = (value) => {
|
|
6
8
|
let urlString
|
|
@@ -29,5 +31,5 @@ export const assertAndNormalizeDirectoryUrl = (value) => {
|
|
|
29
31
|
throw new Error(`directoryUrl must starts with file://, received ${value}`)
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
return
|
|
34
|
+
return ensurePathnameTrailingSlash(urlString)
|
|
33
35
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { isFileSystemPath } from "
|
|
2
|
-
import { fileSystemPathToUrl } from "./fileSystemPathToUrl.js"
|
|
1
|
+
import { fileSystemPathToUrl, isFileSystemPath } from "@jsenv/urls"
|
|
3
2
|
|
|
4
3
|
export const assertAndNormalizeFileUrl = (value, baseUrl) => {
|
|
5
4
|
let urlString
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { urlToFileSystemPath } from "@jsenv/urls"
|
|
2
2
|
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js"
|
|
3
|
-
import {
|
|
3
|
+
import { statsToType } from "./internal/statsToType.js"
|
|
4
4
|
import { readEntryStat } from "./readEntryStat.js"
|
|
5
5
|
|
|
6
6
|
export const assertDirectoryPresence = async (source) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { urlToFileSystemPath } from "@jsenv/urls"
|
|
2
2
|
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js"
|
|
3
|
-
import {
|
|
3
|
+
import { statsToType } from "./internal/statsToType.js"
|
|
4
4
|
import { readEntryStat } from "./readEntryStat.js"
|
|
5
5
|
|
|
6
6
|
export const assertFilePresence = async (source) => {
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
import { Abort } from "@jsenv/abort"
|
|
2
|
-
import {
|
|
3
|
-
normalizeStructuredMetaMap,
|
|
4
|
-
urlCanContainsMetaMatching,
|
|
5
|
-
urlToMeta,
|
|
6
|
-
} from "@jsenv/url-meta"
|
|
7
2
|
|
|
8
|
-
import {
|
|
3
|
+
import { URL_META, urlToRelativeUrl } from "@jsenv/urls"
|
|
9
4
|
import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js"
|
|
10
5
|
import { readDirectory } from "./readDirectory.js"
|
|
11
6
|
import { readEntryStat } from "./readEntryStat.js"
|
|
12
|
-
import { urlToRelativeUrl } from "./urlToRelativeUrl.js"
|
|
13
7
|
import { comparePathnames } from "./comparePathnames.js"
|
|
14
8
|
|
|
15
9
|
export const collectDirectoryMatchReport = async ({
|
|
16
10
|
signal = new AbortController().signal,
|
|
17
11
|
directoryUrl,
|
|
18
|
-
|
|
12
|
+
associations,
|
|
19
13
|
predicate,
|
|
20
14
|
}) => {
|
|
21
15
|
const matchingArray = []
|
|
@@ -25,10 +19,7 @@ export const collectDirectoryMatchReport = async ({
|
|
|
25
19
|
if (typeof predicate !== "function") {
|
|
26
20
|
throw new TypeError(`predicate must be a function, got ${predicate}`)
|
|
27
21
|
}
|
|
28
|
-
|
|
29
|
-
structuredMetaMap,
|
|
30
|
-
rootDirectoryUrl,
|
|
31
|
-
)
|
|
22
|
+
associations = URL_META.resolveAssociations(associations, rootDirectoryUrl)
|
|
32
23
|
|
|
33
24
|
const collectOperation = Abort.startOperation()
|
|
34
25
|
collectOperation.addAbortSignal(signal)
|
|
@@ -63,14 +54,16 @@ export const collectDirectoryMatchReport = async ({
|
|
|
63
54
|
const subDirectoryUrl = `${directoryChildNodeUrl}/`
|
|
64
55
|
|
|
65
56
|
if (
|
|
66
|
-
!
|
|
57
|
+
!URL_META.urlChildMayMatch({
|
|
67
58
|
url: subDirectoryUrl,
|
|
68
|
-
|
|
59
|
+
associations,
|
|
69
60
|
predicate,
|
|
70
61
|
})
|
|
71
62
|
) {
|
|
72
63
|
ignoredArray.push({
|
|
73
|
-
relativeUrl:
|
|
64
|
+
relativeUrl: relativeUrl.endsWith("/")
|
|
65
|
+
? relativeUrl
|
|
66
|
+
: `${relativeUrl}/`,
|
|
74
67
|
fileStats: directoryChildNodeStats,
|
|
75
68
|
})
|
|
76
69
|
|
|
@@ -82,9 +75,9 @@ export const collectDirectoryMatchReport = async ({
|
|
|
82
75
|
}
|
|
83
76
|
|
|
84
77
|
if (directoryChildNodeStats.isFile()) {
|
|
85
|
-
const meta =
|
|
78
|
+
const meta = URL_META.applyAssociations({
|
|
86
79
|
url: directoryChildNodeUrl,
|
|
87
|
-
|
|
80
|
+
associations,
|
|
88
81
|
})
|
|
89
82
|
if (!predicate(meta)) {
|
|
90
83
|
ignoredArray.push({
|
package/src/collectFiles.js
CHANGED
|
@@ -1,30 +1,22 @@
|
|
|
1
1
|
import { Abort } from "@jsenv/abort"
|
|
2
|
-
import {
|
|
3
|
-
normalizeStructuredMetaMap,
|
|
4
|
-
urlCanContainsMetaMatching,
|
|
5
|
-
urlToMeta,
|
|
6
|
-
} from "@jsenv/url-meta"
|
|
2
|
+
import { URL_META, urlToRelativeUrl } from "@jsenv/urls"
|
|
7
3
|
|
|
8
4
|
import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js"
|
|
9
5
|
import { readDirectory } from "./readDirectory.js"
|
|
10
6
|
import { readEntryStat } from "./readEntryStat.js"
|
|
11
|
-
import { urlToRelativeUrl } from "./urlToRelativeUrl.js"
|
|
12
7
|
import { comparePathnames } from "./comparePathnames.js"
|
|
13
8
|
|
|
14
9
|
export const collectFiles = async ({
|
|
15
10
|
signal = new AbortController().signal,
|
|
16
11
|
directoryUrl,
|
|
17
|
-
|
|
12
|
+
associations,
|
|
18
13
|
predicate,
|
|
19
14
|
}) => {
|
|
20
15
|
const rootDirectoryUrl = assertAndNormalizeDirectoryUrl(directoryUrl)
|
|
21
16
|
if (typeof predicate !== "function") {
|
|
22
17
|
throw new TypeError(`predicate must be a function, got ${predicate}`)
|
|
23
18
|
}
|
|
24
|
-
|
|
25
|
-
structuredMetaMap,
|
|
26
|
-
rootDirectoryUrl,
|
|
27
|
-
)
|
|
19
|
+
associations = URL_META.resolveAssociations(associations, rootDirectoryUrl)
|
|
28
20
|
|
|
29
21
|
const collectOperation = Abort.startOperation()
|
|
30
22
|
collectOperation.addAbortSignal(signal)
|
|
@@ -56,9 +48,9 @@ export const collectFiles = async ({
|
|
|
56
48
|
const subDirectoryUrl = `${directoryChildNodeUrl}/`
|
|
57
49
|
|
|
58
50
|
if (
|
|
59
|
-
!
|
|
51
|
+
!URL_META.urlChildMayMatch({
|
|
60
52
|
url: subDirectoryUrl,
|
|
61
|
-
|
|
53
|
+
associations,
|
|
62
54
|
predicate,
|
|
63
55
|
})
|
|
64
56
|
) {
|
|
@@ -70,9 +62,9 @@ export const collectFiles = async ({
|
|
|
70
62
|
}
|
|
71
63
|
|
|
72
64
|
if (directoryChildNodeStats.isFile()) {
|
|
73
|
-
const meta =
|
|
65
|
+
const meta = URL_META.applyAssociations({
|
|
74
66
|
url: directoryChildNodeUrl,
|
|
75
|
-
|
|
67
|
+
associations,
|
|
76
68
|
})
|
|
77
69
|
if (!predicate(meta)) return
|
|
78
70
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Abort } from "@jsenv/abort"
|
|
2
|
+
import { urlToFileSystemPath, resolveUrl } from "@jsenv/urls"
|
|
2
3
|
|
|
3
4
|
import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js"
|
|
4
5
|
import { readEntryStat } from "./readEntryStat.js"
|
|
5
|
-
import { urlToFileSystemPath } from "./urlToFileSystemPath.js"
|
|
6
6
|
import { readSymbolicLink } from "./readSymbolicLink.js"
|
|
7
|
-
import { resolveUrl } from "./resolveUrl.js"
|
|
8
7
|
import { readDirectory } from "./readDirectory.js"
|
|
9
8
|
import { copyEntry } from "./copyEntry.js"
|
|
10
9
|
import { urlTargetsSameFileSystemPath } from "./internal/urlTargetsSameFileSystemPath.js"
|
package/src/copyEntry.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { copyFile as copyFileNode } from "node:fs"
|
|
2
2
|
import { Abort } from "@jsenv/abort"
|
|
3
|
+
import {
|
|
4
|
+
resolveUrl,
|
|
5
|
+
urlToRelativeUrl,
|
|
6
|
+
ensurePathnameTrailingSlash,
|
|
7
|
+
urlIsInsideOf,
|
|
8
|
+
urlToFileSystemPath,
|
|
9
|
+
} from "@jsenv/urls"
|
|
3
10
|
|
|
4
11
|
import { urlTargetsSameFileSystemPath } from "./internal/urlTargetsSameFileSystemPath.js"
|
|
5
12
|
import { statsToType } from "./internal/statsToType.js"
|
|
6
|
-
import { ensureUrlTrailingSlash } from "./internal/ensureUrlTrailingSlash.js"
|
|
7
|
-
import { resolveUrl } from "./resolveUrl.js"
|
|
8
13
|
import { binaryFlagsToPermissions } from "./internal/permissions.js"
|
|
9
14
|
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js"
|
|
10
15
|
import { writeDirectory } from "./writeDirectory.js"
|
|
11
|
-
import { urlToRelativeUrl } from "./urlToRelativeUrl.js"
|
|
12
16
|
import { readEntryStat } from "./readEntryStat.js"
|
|
13
17
|
import { ensureParentDirectories } from "./ensureParentDirectories.js"
|
|
14
18
|
import { writeEntryPermissions } from "./writeEntryPermissions.js"
|
|
@@ -16,9 +20,7 @@ import { writeEntryModificationTime } from "./writeEntryModificationTime.js"
|
|
|
16
20
|
import { readDirectory } from "./readDirectory.js"
|
|
17
21
|
import { readSymbolicLink } from "./readSymbolicLink.js"
|
|
18
22
|
import { writeSymbolicLink } from "./writeSymbolicLink.js"
|
|
19
|
-
import { urlIsInsideOf } from "./urlIsInsideOf.js"
|
|
20
23
|
import { removeEntry } from "./removeEntry.js"
|
|
21
|
-
import { urlToFileSystemPath } from "./urlToFileSystemPath.js"
|
|
22
24
|
|
|
23
25
|
export const copyEntry = async ({
|
|
24
26
|
signal = new AbortController().signal,
|
|
@@ -70,7 +72,7 @@ export const copyEntry = async ({
|
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
if (sourceStats.isDirectory()) {
|
|
73
|
-
toUrl =
|
|
75
|
+
toUrl = ensurePathnameTrailingSlash(toUrl)
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
const copyOperation = Abort.startOperation()
|
|
@@ -83,7 +85,7 @@ export const copyEntry = async ({
|
|
|
83
85
|
} else if (stats.isSymbolicLink()) {
|
|
84
86
|
await visitSymbolicLink(url, stats)
|
|
85
87
|
} else if (stats.isDirectory()) {
|
|
86
|
-
await visitDirectory(
|
|
88
|
+
await visitDirectory(ensurePathnameTrailingSlash(url), stats)
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { urlToFileSystemPath } from "@jsenv/urls"
|
|
2
2
|
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js"
|
|
3
|
-
import {
|
|
3
|
+
import { statsToType } from "./internal/statsToType.js"
|
|
4
4
|
import { writeDirectory } from "./writeDirectory.js"
|
|
5
5
|
import { readEntryStat } from "./readEntryStat.js"
|
|
6
6
|
import { removeEntry } from "./removeEntry.js"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { dirname } from "node:path"
|
|
2
|
+
import { urlToFileSystemPath } from "@jsenv/urls"
|
|
2
3
|
|
|
3
4
|
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js"
|
|
4
|
-
import { urlToFileSystemPath } from "./urlToFileSystemPath.js"
|
|
5
5
|
import { writeDirectory } from "./writeDirectory.js"
|
|
6
6
|
|
|
7
7
|
export const ensureParentDirectories = async (destination) => {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { readdirSync, realpathSync } from "node:fs"
|
|
2
|
-
|
|
3
|
-
import { fileSystemPathToUrl } from "./fileSystemPathToUrl.js"
|
|
4
|
-
import { urlToFileSystemPath } from "./urlToFileSystemPath.js"
|
|
2
|
+
import { fileSystemPathToUrl, urlToFileSystemPath } from "@jsenv/urls"
|
|
5
3
|
|
|
6
4
|
export const getRealFileSystemUrlSync = (
|
|
7
5
|
fileUrl,
|
package/src/listFilesMatching.js
CHANGED
|
@@ -8,15 +8,11 @@ export const listFilesMatching = async ({
|
|
|
8
8
|
if (typeof patterns !== "object" || patterns === null) {
|
|
9
9
|
throw new TypeError(`patterns must be an object, got ${patterns}`)
|
|
10
10
|
}
|
|
11
|
-
|
|
12
11
|
const fileDatas = await collectFiles({
|
|
13
12
|
signal,
|
|
14
13
|
directoryUrl,
|
|
15
|
-
|
|
16
|
-
matches: patterns,
|
|
17
|
-
},
|
|
14
|
+
associations: { matches: patterns },
|
|
18
15
|
predicate: ({ matches }) => matches,
|
|
19
16
|
})
|
|
20
|
-
|
|
21
17
|
return fileDatas.map(({ url }) => url)
|
|
22
18
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Abort } from "@jsenv/abort"
|
|
2
|
+
import { urlToFileSystemPath, resolveUrl } from "@jsenv/urls"
|
|
2
3
|
|
|
3
4
|
import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js"
|
|
4
5
|
import { readEntryStat } from "./readEntryStat.js"
|
|
5
|
-
import { urlToFileSystemPath } from "./urlToFileSystemPath.js"
|
|
6
6
|
import { readSymbolicLink } from "./readSymbolicLink.js"
|
|
7
|
-
import { resolveUrl } from "./resolveUrl.js"
|
|
8
7
|
import { readDirectory } from "./readDirectory.js"
|
|
9
8
|
import { moveEntry } from "./moveEntry.js"
|
|
10
9
|
import { urlTargetsSameFileSystemPath } from "./internal/urlTargetsSameFileSystemPath.js"
|
package/src/moveEntry.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { rename } from "node:fs"
|
|
2
2
|
import { Abort } from "@jsenv/abort"
|
|
3
|
+
import { urlToFileSystemPath, resolveUrl } from "@jsenv/urls"
|
|
3
4
|
|
|
4
5
|
import { urlTargetsSameFileSystemPath } from "./internal/urlTargetsSameFileSystemPath.js"
|
|
5
6
|
import { statsToType } from "./internal/statsToType.js"
|
|
6
7
|
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js"
|
|
7
|
-
import { urlToFileSystemPath } from "./urlToFileSystemPath.js"
|
|
8
|
-
import { resolveUrl } from "./resolveUrl.js"
|
|
9
8
|
import { ensureParentDirectories } from "./ensureParentDirectories.js"
|
|
10
9
|
import { removeEntry } from "./removeEntry.js"
|
|
11
10
|
import { copyEntry } from "./copyEntry.js"
|
package/src/readDirectory.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { readdir } from "fs"
|
|
1
|
+
import { readdir } from "node:fs"
|
|
2
|
+
import { urlToFileSystemPath } from "@jsenv/urls"
|
|
2
3
|
import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js"
|
|
3
|
-
import { urlToFileSystemPath } from "./urlToFileSystemPath.js"
|
|
4
4
|
|
|
5
5
|
export const readDirectory = async (url, { emfileMaxWait = 1000 } = {}) => {
|
|
6
6
|
const directoryUrl = assertAndNormalizeDirectoryUrl(url)
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { promises } from "node:fs"
|
|
7
|
+
import { urlToFileSystemPath } from "@jsenv/urls"
|
|
7
8
|
|
|
8
9
|
import { binaryFlagsToPermissions } from "./internal/permissions.js"
|
|
9
10
|
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js"
|
|
10
|
-
import { urlToFileSystemPath } from "./urlToFileSystemPath.js"
|
|
11
11
|
|
|
12
12
|
const { stat } = promises
|
|
13
13
|
|
package/src/readEntryStat.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { lstat, stat } from "node:fs"
|
|
7
|
+
import { urlToFileSystemPath } from "@jsenv/urls"
|
|
7
8
|
|
|
8
9
|
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js"
|
|
9
|
-
import { urlToFileSystemPath } from "./urlToFileSystemPath.js"
|
|
10
10
|
import { writeEntryPermissions } from "./writeEntryPermissions.js"
|
|
11
11
|
|
|
12
12
|
const isWindows = process.platform === "win32"
|
package/src/readFile.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import { promisify } from "node:util"
|
|
2
1
|
import { readFile as readFileNode } from "node:fs"
|
|
3
2
|
|
|
4
3
|
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js"
|
|
5
4
|
|
|
6
|
-
const readFilePromisified = promisify(readFileNode)
|
|
7
5
|
export const readFile = async (value, { as = "buffer" } = {}) => {
|
|
8
6
|
const fileUrl = assertAndNormalizeFileUrl(value)
|
|
9
|
-
const buffer = await
|
|
7
|
+
const buffer = await new Promise((resolve, reject) => {
|
|
8
|
+
readFileNode(new URL(fileUrl), (error, buffer) => {
|
|
9
|
+
if (error) {
|
|
10
|
+
reject(error)
|
|
11
|
+
} else {
|
|
12
|
+
resolve(buffer)
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
})
|
|
10
16
|
if (as === "buffer") {
|
|
11
17
|
return buffer
|
|
12
18
|
}
|
package/src/readSymbolicLink.js
CHANGED
|
@@ -4,26 +4,22 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { readlink } from "node:fs"
|
|
7
|
+
import { isFileSystemPath, fileSystemPathToUrl } from "@jsenv/urls"
|
|
7
8
|
|
|
8
|
-
import { replaceBackSlashesWithSlashes } from "./internal/replaceBackSlashesWithSlashes.js"
|
|
9
9
|
import { assertAndNormalizeFileUrl } from "./assertAndNormalizeFileUrl.js"
|
|
10
|
-
import { urlToFileSystemPath } from "./urlToFileSystemPath.js"
|
|
11
|
-
import { fileSystemPathToUrl } from "./fileSystemPathToUrl.js"
|
|
12
|
-
import { isFileSystemPath } from "./isFileSystemPath.js"
|
|
13
10
|
|
|
14
11
|
export const readSymbolicLink = (url) => {
|
|
15
12
|
const symbolicLinkUrl = assertAndNormalizeFileUrl(url)
|
|
16
|
-
const symbolicLinkPath = urlToFileSystemPath(symbolicLinkUrl)
|
|
17
13
|
|
|
18
14
|
return new Promise((resolve, reject) => {
|
|
19
|
-
readlink(
|
|
15
|
+
readlink(new URL(symbolicLinkUrl), (error, resolvedPath) => {
|
|
20
16
|
if (error) {
|
|
21
17
|
reject(error)
|
|
22
18
|
} else {
|
|
23
19
|
resolve(
|
|
24
20
|
isFileSystemPath(resolvedPath)
|
|
25
21
|
? fileSystemPathToUrl(resolvedPath)
|
|
26
|
-
:
|
|
22
|
+
: resolvedPath.replace(/\\/g, "/"), // replace back slashes with slashes
|
|
27
23
|
)
|
|
28
24
|
}
|
|
29
25
|
})
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { readdirSync, statSync } from "node:fs"
|
|
2
|
-
import {
|
|
3
|
-
normalizeStructuredMetaMap,
|
|
4
|
-
urlCanContainsMetaMatching,
|
|
5
|
-
urlToMeta,
|
|
6
|
-
} from "@jsenv/url-meta"
|
|
2
|
+
import { URL_META, urlToFileSystemPath, urlToRelativeUrl } from "@jsenv/urls"
|
|
7
3
|
|
|
8
4
|
import { assertAndNormalizeDirectoryUrl } from "./assertAndNormalizeDirectoryUrl.js"
|
|
9
5
|
import { statsToType } from "./internal/statsToType.js"
|
|
10
6
|
import { guardTooFastSecondCall } from "./internal/guard_second_call.js"
|
|
11
|
-
import { replaceBackSlashesWithSlashes } from "./internal/replaceBackSlashesWithSlashes.js"
|
|
12
7
|
import { createWatcher } from "./internal/createWatcher.js"
|
|
13
8
|
import { trackRessources } from "./internal/trackRessources.js"
|
|
14
|
-
import { urlToFileSystemPath } from "./urlToFileSystemPath.js"
|
|
15
|
-
import { urlToRelativeUrl } from "./urlToRelativeUrl.js"
|
|
16
9
|
|
|
17
10
|
const isLinux = process.platform === "linux"
|
|
18
11
|
// linux does not support recursive option
|
|
@@ -65,16 +58,16 @@ export const registerDirectoryLifecycle = (
|
|
|
65
58
|
}
|
|
66
59
|
}
|
|
67
60
|
|
|
68
|
-
const
|
|
61
|
+
const associations = URL_META.resolveAssociations(
|
|
69
62
|
{ watch: watchPatterns },
|
|
70
63
|
sourceUrl,
|
|
71
64
|
)
|
|
72
65
|
const getWatchPatternValue = ({ url, type }) => {
|
|
73
66
|
if (type === "directory") {
|
|
74
67
|
let firstMeta = false
|
|
75
|
-
|
|
68
|
+
URL_META.urlChildMayMatch({
|
|
76
69
|
url: `${url}/`,
|
|
77
|
-
|
|
70
|
+
associations,
|
|
78
71
|
predicate: ({ watch }) => {
|
|
79
72
|
if (watch) {
|
|
80
73
|
firstMeta = watch
|
|
@@ -84,11 +77,8 @@ export const registerDirectoryLifecycle = (
|
|
|
84
77
|
})
|
|
85
78
|
return firstMeta
|
|
86
79
|
}
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
structuredMetaMap,
|
|
90
|
-
})
|
|
91
|
-
return filesystemEntryMeta.watch
|
|
80
|
+
const { watch } = URL_META.applyAssociations({ url, associations })
|
|
81
|
+
return watch
|
|
92
82
|
}
|
|
93
83
|
const tracker = trackRessources()
|
|
94
84
|
const infoMap = new Map()
|
|
@@ -245,8 +235,8 @@ export const registerDirectoryLifecycle = (
|
|
|
245
235
|
readdirSync(new URL(directoryUrl)).forEach((entryName) => {
|
|
246
236
|
const childEntryUrl = new URL(entryName, directoryUrl).href
|
|
247
237
|
const childEntryInfo = readEntryInfo(childEntryUrl)
|
|
248
|
-
if (childEntryInfo) {
|
|
249
|
-
handleEntryFound(childEntryInfo)
|
|
238
|
+
if (childEntryInfo && childEntryInfo.patternValue) {
|
|
239
|
+
handleEntryFound(childEntryInfo, { notify })
|
|
250
240
|
}
|
|
251
241
|
})
|
|
252
242
|
// we must watch manually every directory we find
|
|
@@ -260,7 +250,10 @@ export const registerDirectoryLifecycle = (
|
|
|
260
250
|
watcher.on("change", (eventType, filename) => {
|
|
261
251
|
handleDirectoryEvent({
|
|
262
252
|
directoryRelativeUrl: entryInfo.relativeUrl,
|
|
263
|
-
filename: filename
|
|
253
|
+
filename: filename
|
|
254
|
+
? // replace back slashes with slashes
|
|
255
|
+
filename.replace(/\\/g, "/")
|
|
256
|
+
: "",
|
|
264
257
|
eventType,
|
|
265
258
|
})
|
|
266
259
|
})
|
|
@@ -302,7 +295,7 @@ export const registerDirectoryLifecycle = (
|
|
|
302
295
|
readdirSync(new URL(sourceUrl)).forEach((entry) => {
|
|
303
296
|
const entryUrl = new URL(entry, sourceUrl).href
|
|
304
297
|
const entryInfo = readEntryInfo(entryUrl)
|
|
305
|
-
if (entryInfo) {
|
|
298
|
+
if (entryInfo && entryInfo.patternValue) {
|
|
306
299
|
handleEntryFound(entryInfo, {
|
|
307
300
|
notify: notifyExistent,
|
|
308
301
|
})
|
|
@@ -348,7 +341,7 @@ const fileSystemPathToDirectoryRelativeUrlAndFilename = (path) => {
|
|
|
348
341
|
}
|
|
349
342
|
}
|
|
350
343
|
|
|
351
|
-
const normalizedPath =
|
|
344
|
+
const normalizedPath = path.replace(/\\/g, "/") // replace back slashes with slashes
|
|
352
345
|
const slashLastIndex = normalizedPath.lastIndexOf("/")
|
|
353
346
|
if (slashLastIndex === -1) {
|
|
354
347
|
return {
|