Skip to content

Commit 7169bd4

Browse files
committed
lib: refactor platform utility methods
1 parent a7b3648 commit 7169bd4

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

lib/internal/fs/glob.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const { join, resolve, basename, isAbsolute } = require('path');
2020

2121
const {
2222
kEmptyObject,
23+
isWindows,
24+
isMacOS,
2325
} = require('internal/util');
2426
const {
2527
validateFunction,
@@ -35,9 +37,6 @@ function lazyMicromatch() {
3537
return micromatch;
3638
}
3739

38-
const isWindows = process.platform === 'win32';
39-
const isOSX = process.platform === 'darwin';
40-
4140
async function getDirent(path) {
4241
return new DirentFromStats(basename(path), await lstat(path), path);
4342
}
@@ -203,7 +202,7 @@ class Glob {
203202
patterns = [pattern];
204203
}
205204
this.matchers = ArrayPrototypeMap(patterns, (pattern) => lazyMicromatch()(pattern, {
206-
nocase: isWindows || isOSX,
205+
nocase: isWindows || isMacOS,
207206
nonegate: true,
208207
}));
209208

lib/internal/fs/utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ const kWriteFileMaxChunkSize = 512 * 1024;
145145
const kMaxUserId = 2 ** 32 - 1;
146146

147147
const isWindows = process.platform === 'win32';
148+
const isMacOS = process.platform === 'darwin';
148149

149150
let fs;
150151
function lazyLoadFs() {
@@ -970,6 +971,8 @@ module.exports = {
970971
getValidatedFd,
971972
getValidatedPath,
972973
handleErrorFromBinding,
974+
isMacOS,
975+
isWindows,
973976
preprocessSymlinkDestination,
974977
realpathCacheKey: Symbol('realpathCacheKey'),
975978
getStatFsFromBinding,

lib/path.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ const {
5050
const {
5151
getLazy,
5252
emitExperimentalWarning,
53+
isWindows,
54+
isMacOS,
5355
} = require('internal/util');
5456

5557
const lazyMinimatch = getLazy(() => require('internal/deps/minimatch/index'));
5658

57-
const platformIsWin32 = (process.platform === 'win32');
58-
const platformIsOSX = (process.platform === 'darwin');
5959

6060
function isPathSeparator(code) {
6161
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
@@ -167,7 +167,7 @@ function glob(path, pattern, windows) {
167167
validateString(pattern, 'pattern');
168168
return lazyMinimatch().minimatch(path, pattern, {
169169
__proto__: null,
170-
nocase: platformIsOSX || platformIsWin32,
170+
nocase: isWindows || isMacOS,
171171
windowsPathsNoEscape: true,
172172
nonegate: true,
173173
nocomment: true,
@@ -1100,7 +1100,7 @@ const win32 = {
11001100
};
11011101

11021102
const posixCwd = (() => {
1103-
if (platformIsWin32) {
1103+
if (isWindows) {
11041104
// Converts Windows' backslash path separators to POSIX forward slashes
11051105
// and truncates any drive indicator
11061106
const regexp = /\\/g;
@@ -1575,4 +1575,4 @@ posix.posix = win32.posix = posix;
15751575
win32._makeLong = win32.toNamespacedPath;
15761576
posix._makeLong = posix.toNamespacedPath;
15771577

1578-
module.exports = platformIsWin32 ? win32 : posix;
1578+
module.exports = isWindows ? win32 : posix;

0 commit comments

Comments
 (0)