Skip to content

Commit f76d4f2

Browse files
wraithgarlukekarrys
authored andcommitted
fix: consolidate is-windows code
1 parent d8dcc02 commit f76d4f2

File tree

16 files changed

+63
-70
lines changed

16 files changed

+63
-70
lines changed

lib/commands/completion.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const nopt = require('nopt')
3737
const configNames = Object.keys(definitions)
3838
const shorthandNames = Object.keys(shorthands)
3939
const allConfs = configNames.concat(shorthandNames)
40-
const isWindowsShell = require('../utils/is-windows-shell.js')
40+
const { isWindowsShell } = require('../utils/is-windows.js')
4141
const fileExists = require('../utils/file-exists.js')
4242

4343
const { promisify } = require('util')

lib/commands/run-script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { isServerPackage } = runScript
55
const rpj = require('read-package-json-fast')
66
const log = require('../utils/log-shim.js')
77
const didYouMean = require('../utils/did-you-mean.js')
8-
const isWindowsShell = require('../utils/is-windows-shell.js')
8+
const { isWindowsShell } = require('../utils/is-windows.js')
99

1010
const cmdList = [
1111
'publish',

lib/utils/config/definitions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { version: npmVersion } = require('../../../package.json')
77
const ciDetect = require('@npmcli/ci-detect')
88
const ciName = ciDetect()
99
const querystring = require('querystring')
10-
const isWindows = require('../is-windows.js')
10+
const { isWindows } = require('../is-windows.js')
1111
const { join } = require('path')
1212

1313
// used by cafile flattening to flatOptions.ca

lib/utils/error-message.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports = (er, npm) => {
6060
npm.config.loaded &&
6161
er.dest.startsWith(npm.config.get('cache'))
6262

63-
const isWindows = require('./is-windows.js')
63+
const { isWindows } = require('./is-windows.js')
6464

6565
if (!isWindows && (isCachePath || isCacheDest)) {
6666
// user probably doesn't need this, but still add it to the debug log

lib/utils/is-windows-bash.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

lib/utils/is-windows-shell.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

lib/utils/is-windows.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
module.exports = process.platform === 'win32'
1+
const isWindows = process.platform === 'win32'
2+
const isWindowsShell = isWindows &&
3+
!/^MINGW(32|64)$/.test(process.env.MSYSTEM) && process.env.TERM !== 'cygwin'
4+
5+
exports.isWindows = isWindows
6+
exports.isWindowsShell = isWindowsShell

lib/utils/path.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// return the PATH array in a cross-platform way
2+
// TODO this is only used in a single place
23
const PATH = process.env.PATH || process.env.Path || process.env.path
34
const { delimiter } = require('path')
45
module.exports = PATH.split(delimiter)

test/lib/commands/completion.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const loadMockCompletion = async (t, o = {}) => {
1717
}
1818
const res = await _loadMockNpm(t, {
1919
mocks: {
20-
'../../lib/utils/is-windows-shell.js': !!windows,
20+
'../../lib/utils/is-windows.js': { isWindowsShell: !!windows },
2121
...options.mocks,
2222
},
2323
...options,

test/lib/commands/explore.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ const output = []
4747
const logs = []
4848
const getExplore = (windows) => {
4949
const Explore = t.mock('../../../lib/commands/explore.js', {
50-
'../../../lib/utils/is-windows.js': windows,
5150
path: require('path')[windows ? 'win32' : 'posix'],
5251
'read-package-json-fast': mockRPJ,
5352
'@npmcli/run-script': mockRunScript,

0 commit comments

Comments
 (0)