-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnode.js
49 lines (40 loc) · 1.22 KB
/
node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import {promisify} from 'node:util';
import {execFile as execFileCallback, execFileSync as execFileSyncOriginal} from 'node:child_process';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
const execFileOriginal = promisify(execFileCallback);
export function toPath(urlOrPath) {
return urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
}
export function rootDirectory(pathInput) {
return path.parse(toPath(pathInput)).root;
}
export function traversePathUp(startPath) {
return {
* [Symbol.iterator]() {
let currentPath = path.resolve(toPath(startPath));
let previousPath;
while (previousPath !== currentPath) {
yield currentPath;
previousPath = currentPath;
currentPath = path.resolve(currentPath, '..');
}
},
};
}
const TEN_MEGABYTES_IN_BYTES = 10 * 1024 * 1024;
export async function execFile(file, arguments_, options = {}) {
return execFileOriginal(file, arguments_, {
maxBuffer: TEN_MEGABYTES_IN_BYTES,
...options,
});
}
export function execFileSync(file, arguments_ = [], options = {}) {
return execFileSyncOriginal(file, arguments_, {
maxBuffer: TEN_MEGABYTES_IN_BYTES,
encoding: 'utf8',
stdio: 'pipe',
...options,
});
}
export * from './default.js';