GeezerVison is showing github.com — lib: refactor `platform` utility methods · nodejs/node@0a01abb
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/fs.js +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -94,6 +94,8 @@ const { | 94 | 94 | }, | 95 | 95 | SideEffectFreeRegExpPrototypeExec, | 96 | 96 | defineLazyProperties, | | 97 | + isWindows, | | 98 | + isMacOS, | 97 | 99 | } = require('internal/util'); | 98 | 100 | const { | 99 | 101 | constants: { | @@ -166,9 +168,6 @@ let kResistStopPropagation; | 166 | 168 | let FileReadStream; | 167 | 169 | let FileWriteStream; | 168 | 170 |
| 169 | | -const isWindows = process.platform === 'win32'; | 170 | | -const isOSX = process.platform === 'darwin'; | 171 | | - | 172 | 171 | function showTruncateDeprecation() { | 173 | 172 | if (truncateWarn) { | 174 | 173 | process.emitWarning( | @@ -2457,7 +2456,7 @@ function watch(filename, options, listener) { | 2457 | 2456 | // TODO(anonrig): Remove non-native watcher when/if libuv supports recursive. | 2458 | 2457 | // As of November 2022, libuv does not support recursive file watch on all platforms, | 2459 | 2458 | // e.g. Linux due to the limitations of inotify. | 2460 | | - if (options.recursive && !isOSX && !isWindows) { | | 2459 | + if (options.recursive && !isMacOS && !isWindows) { | 2461 | 2460 | const nonNativeWatcher = require('internal/fs/recursive_watch'); | 2462 | 2461 | watcher = new nonNativeWatcher.FSWatcher(options); | 2463 | 2462 | watcher[watchers.kFSWatchStart](path); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/fs/glob.js +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,6 +20,8 @@ const { join, resolve, basename, isAbsolute } = require('path'); | 20 | 20 |
| 21 | 21 | const { | 22 | 22 | kEmptyObject, | | 23 | + isWindows, | | 24 | + isMacOS, | 23 | 25 | } = require('internal/util'); | 24 | 26 | const { | 25 | 27 | validateFunction, | @@ -35,9 +37,6 @@ function lazyMinimatch() { | 35 | 37 | return minimatch; | 36 | 38 | } | 37 | 39 |
| 38 | | -const isWindows = process.platform === 'win32'; | 39 | | -const isOSX = process.platform === 'darwin'; | 40 | | - | 41 | 40 | /** | 42 | 41 | * @param {string} path | 43 | 42 | * @returns {Promise<DirentFromStats|null>} | @@ -217,7 +216,7 @@ class Glob { | 217 | 216 | } | 218 | 217 | this.matchers = ArrayPrototypeMap(patterns, (pattern) => new (lazyMinimatch().Minimatch)(pattern, { | 219 | 218 | __proto__: null, | 220 | | - nocase: isWindows || isOSX, | | 219 | + nocase: isWindows || isMacOS, | 221 | 220 | windowsPathsNoEscape: true, | 222 | 221 | nonegate: true, | 223 | 222 | nocomment: true, | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/fs/promises.js +4-5Lines changed: 4 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -97,6 +97,8 @@ const { | 97 | 97 | kEmptyObject, | 98 | 98 | lazyDOMException, | 99 | 99 | promisify, | | 100 | + isWindows, | | 101 | + isMacOS, | 100 | 102 | } = require('internal/util'); | 101 | 103 | const EventEmitter = require('events'); | 102 | 104 | const { StringDecoder } = require('string_decoder'); | @@ -126,9 +128,6 @@ const { | 126 | 128 | const getDirectoryEntriesPromise = promisify(getDirents); | 127 | 129 | const validateRmOptionsPromise = promisify(validateRmOptions); | 128 | 130 |
| 129 | | -const isWindows = process.platform === 'win32'; | 130 | | -const isOSX = process.platform === 'darwin'; | 131 | | - | 132 | 131 | let cpPromises; | 133 | 132 | function lazyLoadCpPromises() { | 134 | 133 | return cpPromises ??= require('internal/fs/cp/cp').cpFn; | @@ -1256,7 +1255,7 @@ async function* _watch(filename, options = kEmptyObject) { | 1256 | 1255 | // TODO(anonrig): Remove non-native watcher when/if libuv supports recursive. | 1257 | 1256 | // As of November 2022, libuv does not support recursive file watch on all platforms, | 1258 | 1257 | // e.g. Linux due to the limitations of inotify. | 1259 | | - if (options.recursive && !isOSX && !isWindows) { | | 1258 | + if (options.recursive && !isMacOS && !isWindows) { | 1260 | 1259 | const watcher = new nonNativeWatcher.FSWatcher(options); | 1261 | 1260 | watcher[kFSWatchStart](filename); | 1262 | 1261 | yield* watcher; | @@ -1306,7 +1305,7 @@ module.exports = { | 1306 | 1305 | writeFile, | 1307 | 1306 | appendFile, | 1308 | 1307 | readFile, | 1309 | | - watch: !isOSX && !isWindows ? _watch : watch, | | 1308 | + watch: !isMacOS && !isWindows ? _watch : watch, | 1310 | 1309 | constants, | 1311 | 1310 | }, | 1312 | 1311 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/fs/rimraf.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -30,11 +30,10 @@ const { | 30 | 30 | } = fs; | 31 | 31 | const { sep } = require('path'); | 32 | 32 | const { setTimeout } = require('timers'); | 33 | | -const { sleep } = require('internal/util'); | | 33 | +const { sleep, isWindows } = require('internal/util'); | 34 | 34 | const notEmptyErrorCodes = new SafeSet(['ENOTEMPTY', 'EEXIST', 'EPERM']); | 35 | 35 | const retryErrorCodes = new SafeSet( | 36 | 36 | ['EBUSY', 'EMFILE', 'ENFILE', 'ENOTEMPTY', 'EPERM']); | 37 | | -const isWindows = process.platform === 'win32'; | 38 | 37 | const epermHandler = isWindows ? fixWinEPERM : _rmdir; | 39 | 38 | const epermHandlerSync = isWindows ? fixWinEPERMSync : _rmdirSync; | 40 | 39 | const readdirEncoding = 'buffer'; | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/fs/utils.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -49,6 +49,7 @@ const { | 49 | 49 | kEmptyObject, | 50 | 50 | once, | 51 | 51 | deprecate, | | 52 | + isWindows, | 52 | 53 | } = require('internal/util'); | 53 | 54 | const { toPathIfFileURL } = require('internal/url'); | 54 | 55 | const { | @@ -145,8 +146,6 @@ const kWriteFileMaxChunkSize = 512 * 1024; | 145 | 146 |
| 146 | 147 | const kMaxUserId = 2 ** 32 - 1; | 147 | 148 |
| 148 | | -const isWindows = process.platform === 'win32'; | 149 | | - | 150 | 149 | let fs; | 151 | 150 | function lazyLoadFs() { | 152 | 151 | if (!fs) { | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -127,6 +127,7 @@ const { | 127 | 127 | kEmptyObject, | 128 | 128 | setOwnProperty, | 129 | 129 | getLazy, | | 130 | + isWindows, | 130 | 131 | } = require('internal/util'); | 131 | 132 | const { | 132 | 133 | makeContextifyScript, | @@ -193,8 +194,6 @@ let { startTimer, endTimer } = debugWithTimer('module_timer', (start, end) => { | 193 | 194 | const { tracingChannel } = require('diagnostics_channel'); | 194 | 195 | const onRequire = getLazy(() => tracingChannel('module.require')); | 195 | 196 |
| 196 | | -const isWindows = process.platform === 'win32'; | 197 | | - | 198 | 197 | const relativeResolveCache = { __proto__: null }; | 199 | 198 |
| 200 | 199 | let requireDepth = 0; | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/esm/translators.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -52,7 +52,7 @@ const { fileURLToPath, pathToFileURL, URL } = require('internal/url'); | 52 | 52 | let debug = require('internal/util/debuglog').debuglog('esm', (fn) => { | 53 | 53 | debug = fn; | 54 | 54 | }); | 55 | | -const { emitExperimentalWarning, kEmptyObject, setOwnProperty } = require('internal/util'); | | 55 | +const { emitExperimentalWarning, kEmptyObject, setOwnProperty, isWindows } = require('internal/util'); | 56 | 56 | const { | 57 | 57 | ERR_UNKNOWN_BUILTIN_MODULE, | 58 | 58 | ERR_INVALID_RETURN_PROPERTY_VALUE, | @@ -416,7 +416,6 @@ translators.set('builtin', function builtinStrategy(url) { | 416 | 416 | }); | 417 | 417 |
| 418 | 418 | // Strategy for loading a JSON file | 419 | | -const isWindows = process.platform === 'win32'; | 420 | 419 | translators.set('json', function jsonStrategy(url, source) { | 421 | 420 | emitExperimentalWarning('Importing JSON modules'); | 422 | 421 | assertBufferSource(source, true, 'load'); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/url.js +2-4Lines changed: 2 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -46,6 +46,7 @@ const { | 46 | 46 | kEnumerableProperty, | 47 | 47 | kEmptyObject, | 48 | 48 | SideEffectFreeRegExpPrototypeSymbolReplace, | | 49 | + isWindows, | 49 | 50 | } = require('internal/util'); | 50 | 51 |
| 51 | 52 | const { | @@ -85,9 +86,6 @@ const { | 85 | 86 |
| 86 | 87 | const querystring = require('querystring'); | 87 | 88 |
| 88 | | -const { platform } = process; | 89 | | -const isWindows = platform === 'win32'; | 90 | | - | 91 | 89 | const bindingUrl = internalBinding('url'); | 92 | 90 |
| 93 | 91 | const FORWARD_SLASH = /\//g; | @@ -1471,7 +1469,7 @@ function getPathFromURLWin32(url) { | 1471 | 1469 |
| 1472 | 1470 | function getPathFromURLPosix(url) { | 1473 | 1471 | if (url.hostname !== '') { | 1474 | | - throw new ERR_INVALID_FILE_URL_HOST(platform); | | 1472 | + throw new ERR_INVALID_FILE_URL_HOST(process.platform); | 1475 | 1473 | } | 1476 | 1474 | const pathname = url.pathname; | 1477 | 1475 | for (let n = 0; n < pathname.length; n++) { | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/util.js +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -71,6 +71,9 @@ const { encodings } = internalBinding('string_decoder'); | 71 | 71 |
| 72 | 72 | const noCrypto = !process.versions.openssl; | 73 | 73 |
| | 74 | +const isWindows = process.platform === 'win32'; | | 75 | +const isMacOS = process.platform === 'darwin'; | | 76 | + | 74 | 77 | const experimentalWarnings = new SafeSet(); | 75 | 78 |
| 76 | 79 | const colorRegExp = /\u001b\[\d\d?m/g; // eslint-disable-line no-control-regex | @@ -917,6 +920,8 @@ module.exports = { | 917 | 920 | isArrayBufferDetached, | 918 | 921 | isError, | 919 | 922 | isInsideNodeModules, | | 923 | + isMacOS, | | 924 | + isWindows, | 920 | 925 | join, | 921 | 926 | lazyDOMException, | 922 | 927 | lazyDOMExceptionClass, | |
Collapse file Copy file name to clipboardExpand all lines: lib/net.js +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -115,7 +115,7 @@ const { | 115 | 115 | } = require('internal/errors'); | 116 | 116 | const { isUint8Array } = require('internal/util/types'); | 117 | 117 | const { queueMicrotask } = require('internal/process/task_queues'); | 118 | | -const { kEmptyObject, guessHandleType, promisify } = require('internal/util'); | | 118 | +const { kEmptyObject, guessHandleType, promisify, isWindows } = require('internal/util'); | 119 | 119 | const { | 120 | 120 | validateAbortSignal, | 121 | 121 | validateBoolean, | @@ -142,8 +142,6 @@ const { kTimeout } = require('internal/timers'); | 142 | 142 | const DEFAULT_IPV4_ADDR = '0.0.0.0'; | 143 | 143 | const DEFAULT_IPV6_ADDR = '::'; | 144 | 144 |
| 145 | | -const isWindows = process.platform === 'win32'; | 146 | | - | 147 | 145 | const noop = () => {}; | 148 | 146 |
| 149 | 147 | const kPerfHooksNetConnectContext = Symbol('kPerfHooksNetConnectContext'); | |
|