@jsenv/filesystem 4.15.6 → 4.15.8
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/filesystem",
|
|
3
|
-
"version": "4.15.
|
|
3
|
+
"version": "4.15.8",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/jsenv/core",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@jsenv/abort": "4.3.1",
|
|
28
28
|
"@jsenv/url-meta": "8.5.7",
|
|
29
|
-
"@jsenv/urls": "2.9.
|
|
29
|
+
"@jsenv/urls": "2.9.2",
|
|
30
30
|
"@jsenv/utils": "2.3.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
@@ -49,14 +49,23 @@ export const createLookupPackageDirectory = () => {
|
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
export const readPackageAtOrNull = (packageDirectoryUrl) => {
|
|
52
|
+
const packageJsonFileUrl = new URL("./package.json", packageDirectoryUrl);
|
|
53
|
+
let packageJsonFileContentBuffer;
|
|
52
54
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
packageJsonFileContentBuffer = readFileSync(packageJsonFileUrl, "utf8");
|
|
56
|
+
} catch (e) {
|
|
57
|
+
if (e.code === "ENOENT") {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
throw e;
|
|
61
|
+
}
|
|
62
|
+
const packageJsonFileContentString = String(packageJsonFileContentBuffer);
|
|
63
|
+
try {
|
|
64
|
+
const packageJsonFileContentObject = JSON.parse(
|
|
65
|
+
packageJsonFileContentString,
|
|
56
66
|
);
|
|
57
|
-
|
|
58
|
-
return packageJSON;
|
|
67
|
+
return packageJsonFileContentObject;
|
|
59
68
|
} catch {
|
|
60
|
-
|
|
69
|
+
throw new Error(`Invalid package configuration at ${packageJsonFileUrl}`);
|
|
61
70
|
}
|
|
62
71
|
};
|
|
@@ -9,7 +9,13 @@ import { assertAndNormalizeFileUrl } from "../path_and_url/file_url_validation.j
|
|
|
9
9
|
|
|
10
10
|
export const readSymbolicLinkSync = (url) => {
|
|
11
11
|
const symbolicLinkUrl = assertAndNormalizeFileUrl(url);
|
|
12
|
-
const resolvedPath = readlinkSync(
|
|
12
|
+
const resolvedPath = readlinkSync(
|
|
13
|
+
new URL(
|
|
14
|
+
symbolicLinkUrl.endsWith("/")
|
|
15
|
+
? symbolicLinkUrl.slice(0, -1)
|
|
16
|
+
: symbolicLinkUrl,
|
|
17
|
+
),
|
|
18
|
+
);
|
|
13
19
|
return isFileSystemPath(resolvedPath)
|
|
14
20
|
? fileSystemPathToUrl(resolvedPath)
|
|
15
21
|
: resolvedPath.replace(/\\/g, "/"); // replace back slashes with slashes
|
|
@@ -28,9 +28,20 @@ export const writeSymbolicLinkSync = ({
|
|
|
28
28
|
type,
|
|
29
29
|
allowUseless = false,
|
|
30
30
|
allowOverwrite = false,
|
|
31
|
+
throwWhenTargetNotFound = true,
|
|
31
32
|
}) => {
|
|
32
33
|
const fromUrl = assertAndNormalizeFileUrl(from);
|
|
33
34
|
const toInfo = getToInfo(to, fromUrl);
|
|
35
|
+
if (throwWhenTargetNotFound) {
|
|
36
|
+
const toStats = readEntryStatSync(toInfo.url, {
|
|
37
|
+
nullIfNotFound: true,
|
|
38
|
+
});
|
|
39
|
+
if (toStats === null) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`symbolic link target not found: ${toInfo.url} (from: ${fromUrl})`,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
34
45
|
// Node.js doc at https://nodejs.org/api/fs.html#fssymlinktarget-path-type-callback
|
|
35
46
|
// states the following:
|
|
36
47
|
// "If the type argument is not set, Node.js will autodetect
|