Skip to content

Commit ab2a4cc

Browse files
committed
src: update to standard@14
PR-URL: #1899 Reviewed-By: João Reis <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent 6f39fd4 commit ab2a4cc

13 files changed

+61
-57
lines changed

bin/node-gyp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function errorMessage () {
131131

132132
function issueMessage () {
133133
errorMessage()
134-
log.error('', [ 'This is a bug in `node-gyp`.',
134+
log.error('', ['This is a bug in `node-gyp`.',
135135
'Try to update node-gyp and file an Issue if it does not help:',
136136
' <https://github.com/nodejs/node-gyp/issues>'
137137
].join('\n'))

lib/configure.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (win) {
1717
function configure (gyp, argv, callback) {
1818
var python
1919
var buildDir = path.resolve('build')
20-
var configNames = [ 'config.gypi', 'common.gypi' ]
20+
var configNames = ['config.gypi', 'common.gypi']
2121
var configs = []
2222
var nodeDir
2323
var release = processRelease(argv, gyp, process.version, process.release)
@@ -60,7 +60,7 @@ function configure (gyp, argv, callback) {
6060
// into devdir. Otherwise only install if they're not already there.
6161
gyp.opts.ensure = !gyp.opts.tarball
6262

63-
gyp.commands.install([ release.version ], function (err) {
63+
gyp.commands.install([release.version], function (err) {
6464
if (err) {
6565
return callback(err)
6666
}
@@ -132,7 +132,7 @@ function configure (gyp, argv, callback) {
132132
// set the target_arch variable
133133
variables.target_arch = gyp.opts.arch || process.arch || 'ia32'
134134
if (variables.target_arch === 'arm64') {
135-
defaults['msvs_configuration_platform'] = 'ARM64'
135+
defaults.msvs_configuration_platform = 'ARM64'
136136
}
137137

138138
// set the node development directory
@@ -142,22 +142,22 @@ function configure (gyp, argv, callback) {
142142
variables.standalone_static_library = gyp.opts.thin ? 0 : 1
143143

144144
if (win) {
145-
process.env['GYP_MSVS_VERSION'] = Math.min(vsInfo.versionYear, 2015)
146-
process.env['GYP_MSVS_OVERRIDE_PATH'] = vsInfo.path
147-
defaults['msbuild_toolset'] = vsInfo.toolset
145+
process.env.GYP_MSVS_VERSION = Math.min(vsInfo.versionYear, 2015)
146+
process.env.GYP_MSVS_OVERRIDE_PATH = vsInfo.path
147+
defaults.msbuild_toolset = vsInfo.toolset
148148
if (vsInfo.sdk) {
149-
defaults['msvs_windows_target_platform_version'] = vsInfo.sdk
149+
defaults.msvs_windows_target_platform_version = vsInfo.sdk
150150
}
151151
if (variables.target_arch === 'arm64') {
152152
if (vsInfo.versionMajor > 15 ||
153153
(vsInfo.versionMajor === 15 && vsInfo.versionMajor >= 9)) {
154-
defaults['msvs_enable_marmasm'] = 1
154+
defaults.msvs_enable_marmasm = 1
155155
} else {
156156
log.warn('Compiling ARM64 assembly is only available in\n' +
157157
'Visual Studio 2017 version 15.9 and above')
158158
}
159159
}
160-
variables['msbuild_path'] = vsInfo.msBuild
160+
variables.msbuild_path = vsInfo.msBuild
161161
}
162162

163163
// loop through the rest of the opts and add the unknown ones as variables.
@@ -190,7 +190,7 @@ function configure (gyp, argv, callback) {
190190
var json = JSON.stringify(config, boolsToString, 2)
191191
log.verbose('build/' + configFilename, 'writing out config file: %s', configPath)
192192
configs.push(configPath)
193-
fs.writeFile(configPath, [ prefix, json, '' ].join('\n'), findConfigs)
193+
fs.writeFile(configPath, [prefix, json, ''].join('\n'), findConfigs)
194194
}
195195

196196
function findConfigs (err) {
@@ -335,7 +335,7 @@ function configure (gyp, argv, callback) {
335335
argv.unshift(gypScript)
336336

337337
// make sure python uses files that came with this particular node package
338-
var pypath = [ path.join(__dirname, '..', 'gyp', 'pylib') ]
338+
var pypath = [path.join(__dirname, '..', 'gyp', 'pylib')]
339339
if (process.env.PYTHONPATH) {
340340
pypath.push(process.env.PYTHONPATH)
341341
}

lib/find-python.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ function PythonFinder (configPython, callback) {
1616

1717
PythonFinder.prototype = {
1818
log: logWithPrefix(log, 'find Python'),
19-
argsExecutable: [ '-c', 'import sys; print(sys.executable);' ],
20-
argsVersion: [ '-c', 'import sys; print("%s.%s.%s" % sys.version_info[:3]);' ],
19+
argsExecutable: ['-c', 'import sys; print(sys.executable);'],
20+
argsVersion: ['-c', 'import sys; print("%s.%s.%s" % sys.version_info[:3]);'],
2121
semverRange: '2.7.x || >=3.5.0',
2222

2323
// These can be overridden for testing:
@@ -45,7 +45,7 @@ PythonFinder.prototype = {
4545

4646
function getChecks () {
4747
if (this.env.NODE_GYP_FORCE_PYTHON) {
48-
return [ {
48+
return [{
4949
before: () => {
5050
this.addLog(
5151
'checking Python explicitly set from NODE_GYP_FORCE_PYTHON')
@@ -54,7 +54,7 @@ PythonFinder.prototype = {
5454
},
5555
check: this.checkCommand,
5656
arg: this.env.NODE_GYP_FORCE_PYTHON
57-
} ]
57+
}]
5858
}
5959

6060
var checks = [
@@ -144,7 +144,7 @@ PythonFinder.prototype = {
144144
return this.fail()
145145
}
146146

147-
const args = [ runChecks.bind(this) ]
147+
const args = [runChecks.bind(this)]
148148
if (check.arg) {
149149
args.unshift(check.arg)
150150
}
@@ -196,7 +196,7 @@ PythonFinder.prototype = {
196196
checkPyLauncher: function checkPyLauncher (errorCallback) {
197197
this.log.verbose(
198198
`- executing "${this.pyLauncher}" to get Python 2 executable path`)
199-
this.run(this.pyLauncher, [ '-2', ...this.argsExecutable ], false,
199+
this.run(this.pyLauncher, ['-2', ...this.argsExecutable], false,
200200
function (err, execPath) {
201201
// Possible outcomes: same as checkCommand
202202
if (err) {

lib/install.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function install (fs, gyp, argv, callback) {
2424
if (err) {
2525
log.warn('install', 'got an error, rolling back install')
2626
// roll-back the install if anything went wrong
27-
gyp.commands.remove([ release.versionDir ], function () {
27+
gyp.commands.remove([release.versionDir], function () {
2828
callback(err)
2929
})
3030
} else {
@@ -298,7 +298,7 @@ function install (fs, gyp, argv, callback) {
298298

299299
function downloadNodeLib (done) {
300300
log.verbose('on Windows; need to download `' + release.name + '.lib`...')
301-
var archs = [ 'ia32', 'x64', 'arm64' ]
301+
var archs = ['ia32', 'x64', 'arm64']
302302
var async = archs.length
303303
archs.forEach(function (arch) {
304304
var dir = path.resolve(devDir, arch)
@@ -400,7 +400,7 @@ function download (gyp, env, url) {
400400
uri: url,
401401
headers: {
402402
'User-Agent': 'node-gyp v' + gyp.version + ' (node ' + process.version + ')',
403-
'Connection': 'keep-alive'
403+
Connection: 'keep-alive'
404404
}
405405
}
406406

lib/node-gyp.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ const commands = [
1818
'remove'
1919
]
2020
const aliases = {
21-
'ls': 'list',
22-
'rm': 'remove'
21+
ls: 'list',
22+
rm: 'remove'
2323
}
2424

2525
// differentiate node-gyp's logs from npm's
@@ -72,7 +72,7 @@ proto.configDefs = {
7272
loglevel: String, // everywhere
7373
python: String, // 'configure'
7474
'dist-url': String, // 'install'
75-
'tarball': String, // 'install'
75+
tarball: String, // 'install'
7676
jobs: String, // 'build'
7777
thin: String // 'configure'
7878
}
@@ -167,7 +167,7 @@ proto.spawn = function spawn (command, args, opts) {
167167
opts = {}
168168
}
169169
if (!opts.silent && !opts.stdio) {
170-
opts.stdio = [ 0, 1, 2 ]
170+
opts.stdio = [0, 1, 2]
171171
}
172172
var cp = childProcess.spawn(command, args, opts)
173173
log.info('spawn', command)

lib/process-release.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable node/no-deprecated-api */
2+
13
'use strict'
24

35
const semver = require('semver')

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"bindings": "~1.2.1",
4242
"nan": "^2.0.0",
4343
"require-inject": "~1.3.0",
44-
"standard": "~12.0.1",
44+
"standard": "~14.3.1",
4545
"tap": "~12.7.0"
4646
},
4747
"scripts": {

test/process-exec-sync.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function processExecSync (file, args, options) {
6767
}
6868
}
6969

70-
[ 'stdout', 'stderr', 'status' ].forEach(function (file) {
70+
['stdout', 'stderr', 'status'].forEach(function (file) {
7171
child[file] = fs.readFileSync(tmpdir + '/' + file, options.encoding)
7272
setTimeout(unlinkFile, 500, tmpdir + '/' + file)
7373
})

test/test-addon.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ function runHello (hostProcess) {
1515
hostProcess = process.execPath
1616
}
1717
var testCode = "console.log(require('hello_world').hello())"
18-
return execFileSync(hostProcess, [ '-e', testCode ], { cwd: __dirname }).toString()
18+
return execFileSync(hostProcess, ['-e', testCode], { cwd: __dirname }).toString()
1919
}
2020

2121
function getEncoding () {
2222
var code = 'import locale;print(locale.getdefaultlocale()[1])'
23-
return execFileSync('python', [ '-c', code ]).toString().trim()
23+
return execFileSync('python', ['-c', code]).toString().trim()
2424
}
2525

2626
function checkCharmapValid () {
2727
var data
2828
try {
29-
data = execFileSync('python', [ 'fixtures/test-charmap.py' ],
29+
data = execFileSync('python', ['fixtures/test-charmap.py'],
3030
{ cwd: __dirname })
3131
} catch (err) {
3232
return false
@@ -39,7 +39,7 @@ test('build simple addon', function (t) {
3939
t.plan(3)
4040

4141
// Set the loglevel otherwise the output disappears when run via 'npm test'
42-
var cmd = [ nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose' ]
42+
var cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose']
4343
var proc = execFile(process.execPath, cmd, function (err, stdout, stderr) {
4444
var logLines = stderr.toString().trim().split(/\r?\n/)
4545
var lastLine = logLines[logLines.length - 1]
@@ -59,9 +59,9 @@ test('build simple addon in path with non-ascii characters', function (t) {
5959
}
6060

6161
var testDirNames = {
62-
'cp936': '文件夹',
63-
'cp1252': 'Latīna',
64-
'cp932': 'フォルダ'
62+
cp936: '文件夹',
63+
cp1252: 'Latīna',
64+
cp932: 'フォルダ'
6565
}
6666
// Select non-ascii characters by current encoding
6767
var testDirName = testDirNames[getEncoding()]
@@ -136,7 +136,7 @@ test('addon works with renamed host executable', function (t) {
136136
var notNodePath = path.join(os.tmpdir(), 'notnode' + path.extname(process.execPath))
137137
fs.copyFileSync(process.execPath, notNodePath)
138138

139-
var cmd = [ nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose' ]
139+
var cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose']
140140
var proc = execFile(process.execPath, cmd, function (err, stdout, stderr) {
141141
var logLines = stderr.toString().trim().split(/\r?\n/)
142142
var lastLine = logLines[logLines.length - 1]

test/test-configure-python.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const gyp = require('../lib/node-gyp')
66
const requireInject = require('require-inject')
77
const configure = requireInject('../lib/configure', {
88
'graceful-fs': {
9-
'openSync': function () { return 0 },
10-
'closeSync': function () { },
11-
'writeFile': function (file, data, cb) { cb() },
12-
'stat': function (file, cb) { cb(null, {}) }
9+
openSync: function () { return 0 },
10+
closeSync: function () { },
11+
writeFile: function (file, data, cb) { cb() },
12+
stat: function (file, cb) { cb(null, {}) }
1313
}
1414
})
1515

@@ -42,10 +42,10 @@ test('configure PYTHONPATH with existing env of one dir', function (t) {
4242
var prog = gyp()
4343
prog.parseArgv([])
4444
prog.spawn = function () {
45-
t.equal(process.env.PYTHONPATH, [ EXPECTED_PYPATH, existingPath ].join(SEPARATOR))
45+
t.equal(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR))
4646

4747
var dirs = process.env.PYTHONPATH.split(SEPARATOR)
48-
t.deepEqual(dirs, [ EXPECTED_PYPATH, existingPath ])
48+
t.deepEqual(dirs, [EXPECTED_PYPATH, existingPath])
4949

5050
return SPAWN_RESULT
5151
}
@@ -57,16 +57,16 @@ test('configure PYTHONPATH with existing env of multiple dirs', function (t) {
5757

5858
var pythonDir1 = path.join('a', 'b')
5959
var pythonDir2 = path.join('b', 'c')
60-
var existingPath = [ pythonDir1, pythonDir2 ].join(SEPARATOR)
60+
var existingPath = [pythonDir1, pythonDir2].join(SEPARATOR)
6161
process.env.PYTHONPATH = existingPath
6262

6363
var prog = gyp()
6464
prog.parseArgv([])
6565
prog.spawn = function () {
66-
t.equal(process.env.PYTHONPATH, [ EXPECTED_PYPATH, existingPath ].join(SEPARATOR))
66+
t.equal(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR))
6767

6868
var dirs = process.env.PYTHONPATH.split(SEPARATOR)
69-
t.deepEqual(dirs, [ EXPECTED_PYPATH, pythonDir1, pythonDir2 ])
69+
t.deepEqual(dirs, [EXPECTED_PYPATH, pythonDir1, pythonDir2])
7070

7171
return SPAWN_RESULT
7272
}

test/test-find-accessible-sync.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const path = require('path')
55
const requireInject = require('require-inject')
66
const configure = requireInject('../lib/configure', {
77
'graceful-fs': {
8-
'closeSync': function () { return undefined },
9-
'openSync': function (path) {
8+
closeSync: function () { return undefined },
9+
openSync: function (path) {
1010
if (readableFiles.some(function (f) { return f === path })) {
1111
return 0
1212
} else {
@@ -38,47 +38,47 @@ test('find accessible - empty array', function (t) {
3838
test('find accessible - single item array, readable', function (t) {
3939
t.plan(1)
4040

41-
var candidates = [ readableFile ]
41+
var candidates = [readableFile]
4242
var found = configure.test.findAccessibleSync('test', dir, candidates)
4343
t.strictEqual(found, path.resolve(dir, readableFile))
4444
})
4545

4646
test('find accessible - single item array, readable in subdir', function (t) {
4747
t.plan(1)
4848

49-
var candidates = [ readableFileInDir ]
49+
var candidates = [readableFileInDir]
5050
var found = configure.test.findAccessibleSync('test', dir, candidates)
5151
t.strictEqual(found, path.resolve(dir, readableFileInDir))
5252
})
5353

5454
test('find accessible - single item array, unreadable', function (t) {
5555
t.plan(1)
5656

57-
var candidates = [ 'unreadable_file' ]
57+
var candidates = ['unreadable_file']
5858
var found = configure.test.findAccessibleSync('test', dir, candidates)
5959
t.strictEqual(found, undefined)
6060
})
6161

6262
test('find accessible - multi item array, no matches', function (t) {
6363
t.plan(1)
6464

65-
var candidates = [ 'non_existent_file', 'unreadable_file' ]
65+
var candidates = ['non_existent_file', 'unreadable_file']
6666
var found = configure.test.findAccessibleSync('test', dir, candidates)
6767
t.strictEqual(found, undefined)
6868
})
6969

7070
test('find accessible - multi item array, single match', function (t) {
7171
t.plan(1)
7272

73-
var candidates = [ 'non_existent_file', readableFile ]
73+
var candidates = ['non_existent_file', readableFile]
7474
var found = configure.test.findAccessibleSync('test', dir, candidates)
7575
t.strictEqual(found, path.resolve(dir, readableFile))
7676
})
7777

7878
test('find accessible - multi item array, return first match', function (t) {
7979
t.plan(1)
8080

81-
var candidates = [ 'non_existent_file', anotherReadableFile, readableFile ]
81+
var candidates = ['non_existent_file', anotherReadableFile, readableFile]
8282
var found = configure.test.findAccessibleSync('test', dir, candidates)
8383
t.strictEqual(found, path.resolve(dir, anotherReadableFile))
8484
})

test/test-find-node-directory.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const test = require('tap').test
44
const path = require('path')
55
const findNodeDirectory = require('../lib/find-node-directory')
66

7-
const platforms = [ 'darwin', 'freebsd', 'linux', 'sunos', 'win32', 'aix' ]
7+
const platforms = ['darwin', 'freebsd', 'linux', 'sunos', 'win32', 'aix']
88

99
// we should find the directory based on the directory
1010
// the script is running in and it should match the layout
@@ -62,8 +62,10 @@ test('test find-node-directory - node in build release dir', function (t) {
6262
if (platforms[next] === 'win32') {
6363
processObj = { execPath: '/x/y/Release/node', platform: platforms[next] }
6464
} else {
65-
processObj = { execPath: '/x/y/out/Release/node',
66-
platform: platforms[next] }
65+
processObj = {
66+
execPath: '/x/y/out/Release/node',
67+
platform: platforms[next]
68+
}
6769
}
6870

6971
t.equal(

0 commit comments

Comments
 (0)