@cjser/is-filesystem-case-sensitive 0.1.0-cjser.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/dist-cjser/index.cjs +236 -0
- package/index.d.ts +33 -0
- package/index.js +257 -0
- package/license +9 -0
- package/package.json +77 -0
- package/readme.md +46 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// packages/@cjser/is-filesystem-case-sensitive.tmp-26-1778152554483/index.js
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
isFileSystemCaseSensitive: () => isFileSystemCaseSensitive,
|
|
33
|
+
isFileSystemCaseSensitiveSync: () => isFileSystemCaseSensitiveSync
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
var import_node_process = __toESM(require("node:process"), 1);
|
|
37
|
+
var import_node_crypto = __toESM(require("node:crypto"), 1);
|
|
38
|
+
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
39
|
+
var import_promises = __toESM(require("node:fs/promises"), 1);
|
|
40
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
41
|
+
async function isFileSystemCaseSensitive(pathToCheck = import_node_process.default.cwd()) {
|
|
42
|
+
if (typeof pathToCheck !== "string") {
|
|
43
|
+
throw new TypeError("Expected a string path");
|
|
44
|
+
}
|
|
45
|
+
const resolvedInputPath = import_node_path.default.resolve(pathToCheck);
|
|
46
|
+
const existingDirectoryPath = await findExistingDirectoryPath(resolvedInputPath);
|
|
47
|
+
const canonicalDirectoryPath = await import_promises.default.realpath(existingDirectoryPath);
|
|
48
|
+
const fastPathResult = await tryFastPathByInvertingPathCasing(canonicalDirectoryPath);
|
|
49
|
+
if (fastPathResult !== void 0) {
|
|
50
|
+
return fastPathResult;
|
|
51
|
+
}
|
|
52
|
+
return probeByExclusiveCreate(canonicalDirectoryPath);
|
|
53
|
+
}
|
|
54
|
+
function isFileSystemCaseSensitiveSync(pathToCheck = import_node_process.default.cwd()) {
|
|
55
|
+
if (typeof pathToCheck !== "string") {
|
|
56
|
+
throw new TypeError("Expected a string path");
|
|
57
|
+
}
|
|
58
|
+
const resolvedInputPath = import_node_path.default.resolve(pathToCheck);
|
|
59
|
+
const existingDirectoryPath = findExistingDirectoryPathSync(resolvedInputPath);
|
|
60
|
+
const canonicalDirectoryPath = import_node_fs.default.realpathSync(existingDirectoryPath);
|
|
61
|
+
const fastPathResult = tryFastPathByInvertingPathCasingSync(canonicalDirectoryPath);
|
|
62
|
+
if (fastPathResult !== void 0) {
|
|
63
|
+
return fastPathResult;
|
|
64
|
+
}
|
|
65
|
+
return probeByExclusiveCreateSync(canonicalDirectoryPath);
|
|
66
|
+
}
|
|
67
|
+
async function tryFastPathByInvertingPathCasing(canonicalDirectoryPath) {
|
|
68
|
+
const parentPath = import_node_path.default.dirname(canonicalDirectoryPath);
|
|
69
|
+
const baseName = import_node_path.default.basename(canonicalDirectoryPath);
|
|
70
|
+
const invertedBaseName = invertAsciiLetterCase(baseName);
|
|
71
|
+
if (invertedBaseName === baseName) {
|
|
72
|
+
return void 0;
|
|
73
|
+
}
|
|
74
|
+
const invertedDirectoryPath = import_node_path.default.join(parentPath, invertedBaseName);
|
|
75
|
+
try {
|
|
76
|
+
await import_promises.default.access(invertedDirectoryPath);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (error.code === "ENOENT") {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
return void 0;
|
|
82
|
+
}
|
|
83
|
+
const invertedCanonicalDirectoryPath = await import_promises.default.realpath(invertedDirectoryPath);
|
|
84
|
+
if (invertedCanonicalDirectoryPath === canonicalDirectoryPath) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
return void 0;
|
|
88
|
+
}
|
|
89
|
+
function tryFastPathByInvertingPathCasingSync(canonicalDirectoryPath) {
|
|
90
|
+
const parentPath = import_node_path.default.dirname(canonicalDirectoryPath);
|
|
91
|
+
const baseName = import_node_path.default.basename(canonicalDirectoryPath);
|
|
92
|
+
const invertedBaseName = invertAsciiLetterCase(baseName);
|
|
93
|
+
if (invertedBaseName === baseName) {
|
|
94
|
+
return void 0;
|
|
95
|
+
}
|
|
96
|
+
const invertedDirectoryPath = import_node_path.default.join(parentPath, invertedBaseName);
|
|
97
|
+
try {
|
|
98
|
+
import_node_fs.default.accessSync(invertedDirectoryPath);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (error.code === "ENOENT") {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
return void 0;
|
|
104
|
+
}
|
|
105
|
+
const invertedCanonicalDirectoryPath = import_node_fs.default.realpathSync(invertedDirectoryPath);
|
|
106
|
+
if (invertedCanonicalDirectoryPath === canonicalDirectoryPath) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return void 0;
|
|
110
|
+
}
|
|
111
|
+
async function probeByExclusiveCreate(directoryPath) {
|
|
112
|
+
const uniqueIdentifier = import_node_crypto.default.randomUUID();
|
|
113
|
+
const baseNameLowercase = `case-sensitivity-test-${uniqueIdentifier}`;
|
|
114
|
+
const baseNameUppercase = baseNameLowercase.toUpperCase();
|
|
115
|
+
const lowerPath = import_node_path.default.join(directoryPath, baseNameLowercase);
|
|
116
|
+
const upperPath = import_node_path.default.join(directoryPath, baseNameUppercase);
|
|
117
|
+
await import_promises.default.writeFile(lowerPath, "", { flag: "wx" });
|
|
118
|
+
try {
|
|
119
|
+
await import_promises.default.writeFile(upperPath, "", { flag: "wx" });
|
|
120
|
+
await safeUnlink(upperPath);
|
|
121
|
+
return true;
|
|
122
|
+
} catch (error) {
|
|
123
|
+
if (error.code === "EEXIST") {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
throw error;
|
|
127
|
+
} finally {
|
|
128
|
+
await safeUnlink(lowerPath);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function probeByExclusiveCreateSync(directoryPath) {
|
|
132
|
+
const uniqueIdentifier = import_node_crypto.default.randomUUID();
|
|
133
|
+
const baseNameLowercase = `case-sensitivity-test-${uniqueIdentifier}`;
|
|
134
|
+
const baseNameUppercase = baseNameLowercase.toUpperCase();
|
|
135
|
+
const lowerPath = import_node_path.default.join(directoryPath, baseNameLowercase);
|
|
136
|
+
const upperPath = import_node_path.default.join(directoryPath, baseNameUppercase);
|
|
137
|
+
import_node_fs.default.writeFileSync(lowerPath, "", { flag: "wx" });
|
|
138
|
+
try {
|
|
139
|
+
import_node_fs.default.writeFileSync(upperPath, "", { flag: "wx" });
|
|
140
|
+
safeUnlinkSync(upperPath);
|
|
141
|
+
return true;
|
|
142
|
+
} catch (error) {
|
|
143
|
+
if (error.code === "EEXIST") {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
throw error;
|
|
147
|
+
} finally {
|
|
148
|
+
safeUnlinkSync(lowerPath);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async function findExistingDirectoryPath(inputPath) {
|
|
152
|
+
let currentPath = inputPath;
|
|
153
|
+
while (true) {
|
|
154
|
+
try {
|
|
155
|
+
const fileStatus = await import_promises.default.stat(currentPath);
|
|
156
|
+
if (fileStatus.isDirectory()) {
|
|
157
|
+
return currentPath;
|
|
158
|
+
}
|
|
159
|
+
return import_node_path.default.dirname(await import_promises.default.realpath(currentPath));
|
|
160
|
+
} catch (error) {
|
|
161
|
+
if (error.code !== "ENOENT") {
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const parentPath = import_node_path.default.dirname(currentPath);
|
|
166
|
+
if (parentPath === currentPath) {
|
|
167
|
+
throw new Error(`No existing parent directory found for path: ${inputPath}`);
|
|
168
|
+
}
|
|
169
|
+
currentPath = parentPath;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function findExistingDirectoryPathSync(inputPath) {
|
|
173
|
+
let currentPath = inputPath;
|
|
174
|
+
while (true) {
|
|
175
|
+
try {
|
|
176
|
+
const fileStatus = import_node_fs.default.statSync(currentPath);
|
|
177
|
+
if (fileStatus.isDirectory()) {
|
|
178
|
+
return currentPath;
|
|
179
|
+
}
|
|
180
|
+
return import_node_path.default.dirname(import_node_fs.default.realpathSync(currentPath));
|
|
181
|
+
} catch (error) {
|
|
182
|
+
if (error.code !== "ENOENT") {
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const parentPath = import_node_path.default.dirname(currentPath);
|
|
187
|
+
if (parentPath === currentPath) {
|
|
188
|
+
throw new Error(`No existing parent directory found for path: ${inputPath}`);
|
|
189
|
+
}
|
|
190
|
+
currentPath = parentPath;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function invertAsciiLetterCase(text) {
|
|
194
|
+
let result = "";
|
|
195
|
+
for (const character of text) {
|
|
196
|
+
const codePoint = character.codePointAt(0);
|
|
197
|
+
if (codePoint >= 65 && codePoint <= 90) {
|
|
198
|
+
result += character.toLowerCase();
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
if (codePoint >= 97 && codePoint <= 122) {
|
|
202
|
+
result += character.toUpperCase();
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
result += character;
|
|
206
|
+
}
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
async function safeUnlink(filePath) {
|
|
210
|
+
try {
|
|
211
|
+
await import_promises.default.unlink(filePath);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
if (isIgnorableUnlinkErrorCode(error.code)) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function safeUnlinkSync(filePath) {
|
|
220
|
+
try {
|
|
221
|
+
import_node_fs.default.unlinkSync(filePath);
|
|
222
|
+
} catch (error) {
|
|
223
|
+
if (isIgnorableUnlinkErrorCode(error.code)) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
function isIgnorableUnlinkErrorCode(code) {
|
|
230
|
+
return code === "ENOENT" || code === "EPERM" || code === "EACCES" || code === "EBUSY";
|
|
231
|
+
}
|
|
232
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
233
|
+
0 && (module.exports = {
|
|
234
|
+
isFileSystemCaseSensitive,
|
|
235
|
+
isFileSystemCaseSensitiveSync
|
|
236
|
+
});
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Detect whether the filesystem backing `path` is case-sensitive.
|
|
3
|
+
|
|
4
|
+
Returns `true` for case-sensitive and `false` for case-insensitive.
|
|
5
|
+
|
|
6
|
+
May throw if it needs to probe by creating files and the directory is not writable.
|
|
7
|
+
|
|
8
|
+
@param path The path to check. Can be a file, directory, or non-existent path. Non-existent paths walk up to the nearest existing parent directory. Default: `process.cwd()`.
|
|
9
|
+
|
|
10
|
+
@example
|
|
11
|
+
```
|
|
12
|
+
import {isFileSystemCaseSensitive} from '@cjser/is-filesystem-case-sensitive';
|
|
13
|
+
|
|
14
|
+
await isFileSystemCaseSensitive('/some/path');
|
|
15
|
+
//=> true
|
|
16
|
+
```
|
|
17
|
+
*/
|
|
18
|
+
export function isFileSystemCaseSensitive(path?: string): Promise<boolean>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
Sync variant of {@link isFileSystemCaseSensitive}.
|
|
22
|
+
|
|
23
|
+
@param path The path to check. Can be a file, directory, or non-existent path. Non-existent paths walk up to the nearest existing parent directory. Default: `process.cwd()`.
|
|
24
|
+
|
|
25
|
+
@example
|
|
26
|
+
```
|
|
27
|
+
import {isFileSystemCaseSensitiveSync} from '@cjser/is-filesystem-case-sensitive';
|
|
28
|
+
|
|
29
|
+
isFileSystemCaseSensitiveSync('/some/path');
|
|
30
|
+
//=> true
|
|
31
|
+
```
|
|
32
|
+
*/
|
|
33
|
+
export function isFileSystemCaseSensitiveSync(path?: string): boolean;
|
package/index.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import crypto from 'node:crypto';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import fsPromises from 'node:fs/promises';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
|
|
7
|
+
export async function isFileSystemCaseSensitive(pathToCheck = process.cwd()) {
|
|
8
|
+
if (typeof pathToCheck !== 'string') {
|
|
9
|
+
throw new TypeError('Expected a string path');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const resolvedInputPath = path.resolve(pathToCheck);
|
|
13
|
+
const existingDirectoryPath = await findExistingDirectoryPath(resolvedInputPath);
|
|
14
|
+
const canonicalDirectoryPath = await fsPromises.realpath(existingDirectoryPath);
|
|
15
|
+
|
|
16
|
+
const fastPathResult = await tryFastPathByInvertingPathCasing(canonicalDirectoryPath);
|
|
17
|
+
if (fastPathResult !== undefined) {
|
|
18
|
+
return fastPathResult;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return probeByExclusiveCreate(canonicalDirectoryPath);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function isFileSystemCaseSensitiveSync(pathToCheck = process.cwd()) {
|
|
25
|
+
if (typeof pathToCheck !== 'string') {
|
|
26
|
+
throw new TypeError('Expected a string path');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const resolvedInputPath = path.resolve(pathToCheck);
|
|
30
|
+
const existingDirectoryPath = findExistingDirectoryPathSync(resolvedInputPath);
|
|
31
|
+
const canonicalDirectoryPath = fs.realpathSync(existingDirectoryPath);
|
|
32
|
+
|
|
33
|
+
const fastPathResult = tryFastPathByInvertingPathCasingSync(canonicalDirectoryPath);
|
|
34
|
+
if (fastPathResult !== undefined) {
|
|
35
|
+
return fastPathResult;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return probeByExclusiveCreateSync(canonicalDirectoryPath);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function tryFastPathByInvertingPathCasing(canonicalDirectoryPath) {
|
|
42
|
+
const parentPath = path.dirname(canonicalDirectoryPath);
|
|
43
|
+
const baseName = path.basename(canonicalDirectoryPath);
|
|
44
|
+
const invertedBaseName = invertAsciiLetterCase(baseName);
|
|
45
|
+
if (invertedBaseName === baseName) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const invertedDirectoryPath = path.join(parentPath, invertedBaseName);
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
await fsPromises.access(invertedDirectoryPath);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (error.code === 'ENOENT') {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const invertedCanonicalDirectoryPath = await fsPromises.realpath(invertedDirectoryPath);
|
|
62
|
+
if (invertedCanonicalDirectoryPath === canonicalDirectoryPath) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function tryFastPathByInvertingPathCasingSync(canonicalDirectoryPath) {
|
|
70
|
+
const parentPath = path.dirname(canonicalDirectoryPath);
|
|
71
|
+
const baseName = path.basename(canonicalDirectoryPath);
|
|
72
|
+
const invertedBaseName = invertAsciiLetterCase(baseName);
|
|
73
|
+
if (invertedBaseName === baseName) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const invertedDirectoryPath = path.join(parentPath, invertedBaseName);
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
fs.accessSync(invertedDirectoryPath);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
if (error.code === 'ENOENT') {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const invertedCanonicalDirectoryPath = fs.realpathSync(invertedDirectoryPath);
|
|
90
|
+
if (invertedCanonicalDirectoryPath === canonicalDirectoryPath) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function probeByExclusiveCreate(directoryPath) {
|
|
98
|
+
const uniqueIdentifier = crypto.randomUUID();
|
|
99
|
+
const baseNameLowercase = `case-sensitivity-test-${uniqueIdentifier}`;
|
|
100
|
+
const baseNameUppercase = baseNameLowercase.toUpperCase();
|
|
101
|
+
|
|
102
|
+
const lowerPath = path.join(directoryPath, baseNameLowercase);
|
|
103
|
+
const upperPath = path.join(directoryPath, baseNameUppercase);
|
|
104
|
+
|
|
105
|
+
await fsPromises.writeFile(lowerPath, '', {flag: 'wx'});
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
await fsPromises.writeFile(upperPath, '', {flag: 'wx'});
|
|
109
|
+
await safeUnlink(upperPath);
|
|
110
|
+
return true;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (error.code === 'EEXIST') {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
throw error;
|
|
117
|
+
} finally {
|
|
118
|
+
await safeUnlink(lowerPath);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function probeByExclusiveCreateSync(directoryPath) {
|
|
123
|
+
const uniqueIdentifier = crypto.randomUUID();
|
|
124
|
+
const baseNameLowercase = `case-sensitivity-test-${uniqueIdentifier}`;
|
|
125
|
+
const baseNameUppercase = baseNameLowercase.toUpperCase();
|
|
126
|
+
|
|
127
|
+
const lowerPath = path.join(directoryPath, baseNameLowercase);
|
|
128
|
+
const upperPath = path.join(directoryPath, baseNameUppercase);
|
|
129
|
+
|
|
130
|
+
fs.writeFileSync(lowerPath, '', {flag: 'wx'});
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
fs.writeFileSync(upperPath, '', {flag: 'wx'});
|
|
134
|
+
safeUnlinkSync(upperPath);
|
|
135
|
+
return true;
|
|
136
|
+
} catch (error) {
|
|
137
|
+
if (error.code === 'EEXIST') {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
throw error;
|
|
142
|
+
} finally {
|
|
143
|
+
safeUnlinkSync(lowerPath);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function findExistingDirectoryPath(inputPath) {
|
|
148
|
+
let currentPath = inputPath;
|
|
149
|
+
|
|
150
|
+
while (true) {
|
|
151
|
+
try {
|
|
152
|
+
// eslint-disable-next-line no-await-in-loop
|
|
153
|
+
const fileStatus = await fsPromises.stat(currentPath);
|
|
154
|
+
|
|
155
|
+
if (fileStatus.isDirectory()) {
|
|
156
|
+
return currentPath;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// eslint-disable-next-line no-await-in-loop
|
|
160
|
+
return path.dirname(await fsPromises.realpath(currentPath));
|
|
161
|
+
} catch (error) {
|
|
162
|
+
if (error.code !== 'ENOENT') {
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const parentPath = path.dirname(currentPath);
|
|
168
|
+
if (parentPath === currentPath) {
|
|
169
|
+
throw new Error(`No existing parent directory found for path: ${inputPath}`);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
currentPath = parentPath;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function findExistingDirectoryPathSync(inputPath) {
|
|
177
|
+
let currentPath = inputPath;
|
|
178
|
+
|
|
179
|
+
while (true) {
|
|
180
|
+
try {
|
|
181
|
+
const fileStatus = fs.statSync(currentPath);
|
|
182
|
+
|
|
183
|
+
if (fileStatus.isDirectory()) {
|
|
184
|
+
return currentPath;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return path.dirname(fs.realpathSync(currentPath));
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (error.code !== 'ENOENT') {
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const parentPath = path.dirname(currentPath);
|
|
195
|
+
if (parentPath === currentPath) {
|
|
196
|
+
throw new Error(`No existing parent directory found for path: ${inputPath}`);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
currentPath = parentPath;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function invertAsciiLetterCase(text) {
|
|
204
|
+
let result = '';
|
|
205
|
+
|
|
206
|
+
for (const character of text) {
|
|
207
|
+
const codePoint = character.codePointAt(0);
|
|
208
|
+
|
|
209
|
+
if (codePoint >= 65 && codePoint <= 90) {
|
|
210
|
+
result += character.toLowerCase();
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (codePoint >= 97 && codePoint <= 122) {
|
|
215
|
+
result += character.toUpperCase();
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
result += character;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async function safeUnlink(filePath) {
|
|
226
|
+
try {
|
|
227
|
+
await fsPromises.unlink(filePath);
|
|
228
|
+
} catch (error) {
|
|
229
|
+
if (isIgnorableUnlinkErrorCode(error.code)) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function safeUnlinkSync(filePath) {
|
|
238
|
+
try {
|
|
239
|
+
fs.unlinkSync(filePath);
|
|
240
|
+
} catch (error) {
|
|
241
|
+
if (isIgnorableUnlinkErrorCode(error.code)) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
throw error;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function isIgnorableUnlinkErrorCode(code) {
|
|
250
|
+
/*
|
|
251
|
+
Best-effort cleanup. Probe files are non-essential, so cleanup failures should not hide the main result.
|
|
252
|
+
*/
|
|
253
|
+
return code === 'ENOENT'
|
|
254
|
+
|| code === 'EPERM'
|
|
255
|
+
|| code === 'EACCES'
|
|
256
|
+
|| code === 'EBUSY';
|
|
257
|
+
}
|
package/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cjser/is-filesystem-case-sensitive",
|
|
3
|
+
"version": "0.1.0-cjser.2",
|
|
4
|
+
"description": "Detect whether the filesystem backing a path is case-sensitive",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://code.moenext.com/3rdeye/cjser.git"
|
|
9
|
+
},
|
|
10
|
+
"funding": "https://github.com/sponsors/sindresorhus",
|
|
11
|
+
"author": {
|
|
12
|
+
"name": "Sindre Sorhus",
|
|
13
|
+
"email": "sindresorhus@gmail.com",
|
|
14
|
+
"url": "https://sindresorhus.com"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
"types": "./index.d.ts",
|
|
19
|
+
"require": "./dist-cjser/index.cjs",
|
|
20
|
+
"default": "./index.js"
|
|
21
|
+
},
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "xo && node --test test.js && tsc index.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"index.js",
|
|
31
|
+
"index.d.ts",
|
|
32
|
+
"dist-cjser"
|
|
33
|
+
],
|
|
34
|
+
"keywords": [
|
|
35
|
+
"filesystem",
|
|
36
|
+
"fs",
|
|
37
|
+
"case",
|
|
38
|
+
"sensitive",
|
|
39
|
+
"insensitive",
|
|
40
|
+
"path",
|
|
41
|
+
"detect",
|
|
42
|
+
"check",
|
|
43
|
+
"mount",
|
|
44
|
+
"volume"
|
|
45
|
+
],
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"typescript": "^6.0.2",
|
|
48
|
+
"xo": "^2.0.2"
|
|
49
|
+
},
|
|
50
|
+
"xo": {
|
|
51
|
+
"rules": {
|
|
52
|
+
"@stylistic/curly-newline": "off"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"types": "./index.d.ts",
|
|
56
|
+
"main": "./dist-cjser/index.cjs",
|
|
57
|
+
"cjser": {
|
|
58
|
+
"sourceVersion": "0.1.0",
|
|
59
|
+
"cjserVersion": 2,
|
|
60
|
+
"original": {
|
|
61
|
+
"name": "is-filesystem-case-sensitive",
|
|
62
|
+
"version": "0.1.0",
|
|
63
|
+
"exports": {
|
|
64
|
+
"types": "./index.d.ts",
|
|
65
|
+
"default": "./index.js"
|
|
66
|
+
},
|
|
67
|
+
"repository": "sindresorhus/is-filesystem-case-sensitive",
|
|
68
|
+
"files": [
|
|
69
|
+
"index.js",
|
|
70
|
+
"index.d.ts"
|
|
71
|
+
],
|
|
72
|
+
"scripts": {
|
|
73
|
+
"test": "xo && node --test test.js && tsc index.d.ts"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# is-filesystem-case-sensitive
|
|
2
|
+
|
|
3
|
+
> Detect whether the filesystem backing a path is case-sensitive
|
|
4
|
+
|
|
5
|
+
Mount-point aware. No OS heuristics.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install is-filesystem-case-sensitive
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import {isFileSystemCaseSensitive} from 'is-filesystem-case-sensitive';
|
|
17
|
+
|
|
18
|
+
await isFileSystemCaseSensitive('/some/path');
|
|
19
|
+
//=> true/false
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## API
|
|
23
|
+
|
|
24
|
+
May create and delete a temporary file in the target directory.
|
|
25
|
+
|
|
26
|
+
### isFileSystemCaseSensitive(path?)
|
|
27
|
+
|
|
28
|
+
Returns `Promise<boolean>` — `true` if case-sensitive, `false` otherwise.
|
|
29
|
+
|
|
30
|
+
### isFileSystemCaseSensitiveSync(path?)
|
|
31
|
+
|
|
32
|
+
Sync version of `isFileSystemCaseSensitive`.
|
|
33
|
+
|
|
34
|
+
Returns `boolean`.
|
|
35
|
+
|
|
36
|
+
#### path
|
|
37
|
+
|
|
38
|
+
Type: `string`\
|
|
39
|
+
Default: `process.cwd()`
|
|
40
|
+
|
|
41
|
+
The path to check. Can be a file, directory, or non-existent path. Non-existent paths walk up to the nearest existing parent directory.
|
|
42
|
+
|
|
43
|
+
## cjser
|
|
44
|
+
|
|
45
|
+
This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
|
|
46
|
+
Original repository: https://github.com/sindresorhus/is-filesystem-case-sensitive
|