check-disk-space 3.3.0 → 3.3.1
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.
|
@@ -49,9 +49,20 @@ function getFirstExistingParentPath(directoryPath, dependencies) {
|
|
|
49
49
|
*
|
|
50
50
|
* @param release - OS Release number
|
|
51
51
|
*/
|
|
52
|
-
function hasPowerShell3(
|
|
53
|
-
const major = parseInt(release.split('.')[0], 10);
|
|
54
|
-
|
|
52
|
+
function hasPowerShell3(dependencies) {
|
|
53
|
+
const major = parseInt(dependencies.release.split('.')[0], 10);
|
|
54
|
+
if (major > 6) {
|
|
55
|
+
try {
|
|
56
|
+
dependencies.cpExecFileSync('powershell');
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
55
66
|
}
|
|
56
67
|
|
|
57
68
|
/**
|
|
@@ -67,6 +78,7 @@ function checkDiskSpace(directoryPath, dependencies = {
|
|
|
67
78
|
pathNormalize: path.normalize,
|
|
68
79
|
pathSep: path.sep,
|
|
69
80
|
cpExecFile: child_process.execFile,
|
|
81
|
+
cpExecFileSync: child_process.execFileSync,
|
|
70
82
|
}) {
|
|
71
83
|
// Note: This function contains other functions in order
|
|
72
84
|
// to wrap them in a common context and make unit tests easier
|
|
@@ -142,7 +154,7 @@ function checkDiskSpace(directoryPath, dependencies = {
|
|
|
142
154
|
'get',
|
|
143
155
|
'size,freespace,caption',
|
|
144
156
|
];
|
|
145
|
-
const cmd = hasPowerShell3(dependencies
|
|
157
|
+
const cmd = hasPowerShell3(dependencies) ? powershellCmd : wmicCmd;
|
|
146
158
|
return check(cmd, driveData => {
|
|
147
159
|
// Only get the drive which match the path
|
|
148
160
|
const driveLetter = driveData[0];
|
|
@@ -20,6 +20,7 @@ declare type Dependencies = {
|
|
|
20
20
|
pathNormalize: typeof normalize;
|
|
21
21
|
pathSep: typeof sep;
|
|
22
22
|
cpExecFile: (file: string, args: ReadonlyArray<string> | undefined | null, callback: (error: ExecFileException | null, stdout: string, stderr: string) => void) => ChildProcess;
|
|
23
|
+
cpExecFileSync: (command: string) => Buffer;
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execFile } from 'child_process';
|
|
1
|
+
import { execFile, execFileSync } from 'child_process';
|
|
2
2
|
import { existsSync } from 'fs';
|
|
3
3
|
import { release } from 'os';
|
|
4
4
|
import { normalize, sep } from 'path';
|
|
@@ -45,9 +45,20 @@ function getFirstExistingParentPath(directoryPath, dependencies) {
|
|
|
45
45
|
*
|
|
46
46
|
* @param release - OS Release number
|
|
47
47
|
*/
|
|
48
|
-
function hasPowerShell3(
|
|
49
|
-
const major = parseInt(release.split('.')[0], 10);
|
|
50
|
-
|
|
48
|
+
function hasPowerShell3(dependencies) {
|
|
49
|
+
const major = parseInt(dependencies.release.split('.')[0], 10);
|
|
50
|
+
if (major > 6) {
|
|
51
|
+
try {
|
|
52
|
+
dependencies.cpExecFileSync('powershell');
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
51
62
|
}
|
|
52
63
|
|
|
53
64
|
/**
|
|
@@ -63,6 +74,7 @@ function checkDiskSpace(directoryPath, dependencies = {
|
|
|
63
74
|
pathNormalize: normalize,
|
|
64
75
|
pathSep: sep,
|
|
65
76
|
cpExecFile: execFile,
|
|
77
|
+
cpExecFileSync: execFileSync,
|
|
66
78
|
}) {
|
|
67
79
|
// Note: This function contains other functions in order
|
|
68
80
|
// to wrap them in a common context and make unit tests easier
|
|
@@ -138,7 +150,7 @@ function checkDiskSpace(directoryPath, dependencies = {
|
|
|
138
150
|
'get',
|
|
139
151
|
'size,freespace,caption',
|
|
140
152
|
];
|
|
141
|
-
const cmd = hasPowerShell3(dependencies
|
|
153
|
+
const cmd = hasPowerShell3(dependencies) ? powershellCmd : wmicCmd;
|
|
142
154
|
return check(cmd, driveData => {
|
|
143
155
|
// Only get the drive which match the path
|
|
144
156
|
const driveLetter = driveData[0];
|