Skip to content

Commit

Permalink
src: update to standard@14
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Oct 2, 2019
1 parent 6f39fd4 commit 3555ff4
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 57 deletions.
2 changes: 1 addition & 1 deletion bin/node-gyp.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function errorMessage () {

function issueMessage () {
errorMessage()
log.error('', [ 'This is a bug in `node-gyp`.',
log.error('', ['This is a bug in `node-gyp`.',
'Try to update node-gyp and file an Issue if it does not help:',
' <https://github.com/nodejs/node-gyp/issues>'
].join('\n'))
Expand Down
22 changes: 11 additions & 11 deletions lib/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (win) {
function configure (gyp, argv, callback) {
var python
var buildDir = path.resolve('build')
var configNames = [ 'config.gypi', 'common.gypi' ]
var configNames = ['config.gypi', 'common.gypi']
var configs = []
var nodeDir
var release = processRelease(argv, gyp, process.version, process.release)
Expand Down Expand Up @@ -60,7 +60,7 @@ function configure (gyp, argv, callback) {
// into devdir. Otherwise only install if they're not already there.
gyp.opts.ensure = !gyp.opts.tarball

gyp.commands.install([ release.version ], function (err) {
gyp.commands.install([release.version], function (err) {
if (err) {
return callback(err)
}
Expand Down Expand Up @@ -132,7 +132,7 @@ function configure (gyp, argv, callback) {
// set the target_arch variable
variables.target_arch = gyp.opts.arch || process.arch || 'ia32'
if (variables.target_arch === 'arm64') {
defaults['msvs_configuration_platform'] = 'ARM64'
defaults.msvs_configuration_platform = 'ARM64'
}

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

if (win) {
process.env['GYP_MSVS_VERSION'] = Math.min(vsInfo.versionYear, 2015)
process.env['GYP_MSVS_OVERRIDE_PATH'] = vsInfo.path
defaults['msbuild_toolset'] = vsInfo.toolset
process.env.GYP_MSVS_VERSION = Math.min(vsInfo.versionYear, 2015)
process.env.GYP_MSVS_OVERRIDE_PATH = vsInfo.path
defaults.msbuild_toolset = vsInfo.toolset
if (vsInfo.sdk) {
defaults['msvs_windows_target_platform_version'] = vsInfo.sdk
defaults.msvs_windows_target_platform_version = vsInfo.sdk
}
if (variables.target_arch === 'arm64') {
if (vsInfo.versionMajor > 15 ||
(vsInfo.versionMajor === 15 && vsInfo.versionMajor >= 9)) {
defaults['msvs_enable_marmasm'] = 1
defaults.msvs_enable_marmasm = 1
} else {
log.warn('Compiling ARM64 assembly is only available in\n' +
'Visual Studio 2017 version 15.9 and above')
}
}
variables['msbuild_path'] = vsInfo.msBuild
variables.msbuild_path = vsInfo.msBuild
}

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

function findConfigs (err) {
Expand Down Expand Up @@ -335,7 +335,7 @@ function configure (gyp, argv, callback) {
argv.unshift(gypScript)

// make sure python uses files that came with this particular node package
var pypath = [ path.join(__dirname, '..', 'gyp', 'pylib') ]
var pypath = [path.join(__dirname, '..', 'gyp', 'pylib')]
if (process.env.PYTHONPATH) {
pypath.push(process.env.PYTHONPATH)
}
Expand Down
12 changes: 6 additions & 6 deletions lib/find-python.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function PythonFinder (configPython, callback) {

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

// These can be overridden for testing:
Expand Down Expand Up @@ -45,7 +45,7 @@ PythonFinder.prototype = {

function getChecks () {
if (this.env.NODE_GYP_FORCE_PYTHON) {
return [ {
return [{
before: () => {
this.addLog(
'checking Python explicitly set from NODE_GYP_FORCE_PYTHON')
Expand All @@ -54,7 +54,7 @@ PythonFinder.prototype = {
},
check: this.checkCommand,
arg: this.env.NODE_GYP_FORCE_PYTHON
} ]
}]
}

var checks = [
Expand Down Expand Up @@ -144,7 +144,7 @@ PythonFinder.prototype = {
return this.fail()
}

const args = [ runChecks.bind(this) ]
const args = [runChecks.bind(this)]
if (check.arg) {
args.unshift(check.arg)
}
Expand Down Expand Up @@ -196,7 +196,7 @@ PythonFinder.prototype = {
checkPyLauncher: function checkPyLauncher (errorCallback) {
this.log.verbose(
`- executing "${this.pyLauncher}" to get Python 2 executable path`)
this.run(this.pyLauncher, [ '-2', ...this.argsExecutable ], false,
this.run(this.pyLauncher, ['-2', ...this.argsExecutable], false,
function (err, execPath) {
// Possible outcomes: same as checkCommand
if (err) {
Expand Down
6 changes: 3 additions & 3 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function install (fs, gyp, argv, callback) {
if (err) {
log.warn('install', 'got an error, rolling back install')
// roll-back the install if anything went wrong
gyp.commands.remove([ release.versionDir ], function () {
gyp.commands.remove([release.versionDir], function () {
callback(err)
})
} else {
Expand Down Expand Up @@ -298,7 +298,7 @@ function install (fs, gyp, argv, callback) {

function downloadNodeLib (done) {
log.verbose('on Windows; need to download `' + release.name + '.lib`...')
var archs = [ 'ia32', 'x64', 'arm64' ]
var archs = ['ia32', 'x64', 'arm64']
var async = archs.length
archs.forEach(function (arch) {
var dir = path.resolve(devDir, arch)
Expand Down Expand Up @@ -400,7 +400,7 @@ function download (gyp, env, url) {
uri: url,
headers: {
'User-Agent': 'node-gyp v' + gyp.version + ' (node ' + process.version + ')',
'Connection': 'keep-alive'
Connection: 'keep-alive'
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/node-gyp.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const commands = [
'remove'
]
const aliases = {
'ls': 'list',
'rm': 'remove'
ls: 'list',
rm: 'remove'
}

// differentiate node-gyp's logs from npm's
Expand Down Expand Up @@ -72,7 +72,7 @@ proto.configDefs = {
loglevel: String, // everywhere
python: String, // 'configure'
'dist-url': String, // 'install'
'tarball': String, // 'install'
tarball: String, // 'install'
jobs: String, // 'build'
thin: String // 'configure'
}
Expand Down Expand Up @@ -167,7 +167,7 @@ proto.spawn = function spawn (command, args, opts) {
opts = {}
}
if (!opts.silent && !opts.stdio) {
opts.stdio = [ 0, 1, 2 ]
opts.stdio = [0, 1, 2]
}
var cp = childProcess.spawn(command, args, opts)
log.info('spawn', command)
Expand Down
2 changes: 2 additions & 0 deletions lib/process-release.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable node/no-deprecated-api */

'use strict'

const semver = require('semver')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"bindings": "~1.2.1",
"nan": "^2.0.0",
"require-inject": "~1.3.0",
"standard": "~12.0.1",
"standard": "~14.3.1",
"tap": "~12.7.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test/process-exec-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function processExecSync (file, args, options) {
}
}

[ 'stdout', 'stderr', 'status' ].forEach(function (file) {
['stdout', 'stderr', 'status'].forEach(function (file) {
child[file] = fs.readFileSync(tmpdir + '/' + file, options.encoding)
setTimeout(unlinkFile, 500, tmpdir + '/' + file)
})
Expand Down
16 changes: 8 additions & 8 deletions test/test-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ function runHello (hostProcess) {
hostProcess = process.execPath
}
var testCode = "console.log(require('hello_world').hello())"
return execFileSync(hostProcess, [ '-e', testCode ], { cwd: __dirname }).toString()
return execFileSync(hostProcess, ['-e', testCode], { cwd: __dirname }).toString()
}

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

function checkCharmapValid () {
var data
try {
data = execFileSync('python', [ 'fixtures/test-charmap.py' ],
data = execFileSync('python', ['fixtures/test-charmap.py'],
{ cwd: __dirname })
} catch (err) {
return false
Expand All @@ -39,7 +39,7 @@ test('build simple addon', function (t) {
t.plan(3)

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

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

var cmd = [ nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose' ]
var cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose']
var proc = execFile(process.execPath, cmd, function (err, stdout, stderr) {
var logLines = stderr.toString().trim().split(/\r?\n/)
var lastLine = logLines[logLines.length - 1]
Expand Down
18 changes: 9 additions & 9 deletions test/test-configure-python.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const gyp = require('../lib/node-gyp')
const requireInject = require('require-inject')
const configure = requireInject('../lib/configure', {
'graceful-fs': {
'openSync': function () { return 0 },
'closeSync': function () { },
'writeFile': function (file, data, cb) { cb() },
'stat': function (file, cb) { cb(null, {}) }
openSync: function () { return 0 },
closeSync: function () { },
writeFile: function (file, data, cb) { cb() },
stat: function (file, cb) { cb(null, {}) }
}
})

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

var dirs = process.env.PYTHONPATH.split(SEPARATOR)
t.deepEqual(dirs, [ EXPECTED_PYPATH, existingPath ])
t.deepEqual(dirs, [EXPECTED_PYPATH, existingPath])

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

var pythonDir1 = path.join('a', 'b')
var pythonDir2 = path.join('b', 'c')
var existingPath = [ pythonDir1, pythonDir2 ].join(SEPARATOR)
var existingPath = [pythonDir1, pythonDir2].join(SEPARATOR)
process.env.PYTHONPATH = existingPath

var prog = gyp()
prog.parseArgv([])
prog.spawn = function () {
t.equal(process.env.PYTHONPATH, [ EXPECTED_PYPATH, existingPath ].join(SEPARATOR))
t.equal(process.env.PYTHONPATH, [EXPECTED_PYPATH, existingPath].join(SEPARATOR))

var dirs = process.env.PYTHONPATH.split(SEPARATOR)
t.deepEqual(dirs, [ EXPECTED_PYPATH, pythonDir1, pythonDir2 ])
t.deepEqual(dirs, [EXPECTED_PYPATH, pythonDir1, pythonDir2])

return SPAWN_RESULT
}
Expand Down
16 changes: 8 additions & 8 deletions test/test-find-accessible-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const path = require('path')
const requireInject = require('require-inject')
const configure = requireInject('../lib/configure', {
'graceful-fs': {
'closeSync': function () { return undefined },
'openSync': function (path) {
closeSync: function () { return undefined },
openSync: function (path) {
if (readableFiles.some(function (f) { return f === path })) {
return 0
} else {
Expand Down Expand Up @@ -38,47 +38,47 @@ test('find accessible - empty array', function (t) {
test('find accessible - single item array, readable', function (t) {
t.plan(1)

var candidates = [ readableFile ]
var candidates = [readableFile]
var found = configure.test.findAccessibleSync('test', dir, candidates)
t.strictEqual(found, path.resolve(dir, readableFile))
})

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

var candidates = [ readableFileInDir ]
var candidates = [readableFileInDir]
var found = configure.test.findAccessibleSync('test', dir, candidates)
t.strictEqual(found, path.resolve(dir, readableFileInDir))
})

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

var candidates = [ 'unreadable_file' ]
var candidates = ['unreadable_file']
var found = configure.test.findAccessibleSync('test', dir, candidates)
t.strictEqual(found, undefined)
})

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

var candidates = [ 'non_existent_file', 'unreadable_file' ]
var candidates = ['non_existent_file', 'unreadable_file']
var found = configure.test.findAccessibleSync('test', dir, candidates)
t.strictEqual(found, undefined)
})

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

var candidates = [ 'non_existent_file', readableFile ]
var candidates = ['non_existent_file', readableFile]
var found = configure.test.findAccessibleSync('test', dir, candidates)
t.strictEqual(found, path.resolve(dir, readableFile))
})

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

var candidates = [ 'non_existent_file', anotherReadableFile, readableFile ]
var candidates = ['non_existent_file', anotherReadableFile, readableFile]
var found = configure.test.findAccessibleSync('test', dir, candidates)
t.strictEqual(found, path.resolve(dir, anotherReadableFile))
})
8 changes: 5 additions & 3 deletions test/test-find-node-directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const test = require('tap').test
const path = require('path')
const findNodeDirectory = require('../lib/find-node-directory')

const platforms = [ 'darwin', 'freebsd', 'linux', 'sunos', 'win32', 'aix' ]
const platforms = ['darwin', 'freebsd', 'linux', 'sunos', 'win32', 'aix']

// we should find the directory based on the directory
// the script is running in and it should match the layout
Expand Down Expand Up @@ -62,8 +62,10 @@ test('test find-node-directory - node in build release dir', function (t) {
if (platforms[next] === 'win32') {
processObj = { execPath: '/x/y/Release/node', platform: platforms[next] }
} else {
processObj = { execPath: '/x/y/out/Release/node',
platform: platforms[next] }
processObj = {
execPath: '/x/y/out/Release/node',
platform: platforms[next]
}
}

t.equal(
Expand Down
Loading

0 comments on commit 3555ff4

Please sign in to comment.