Skip to content

Commit

Permalink
src: bring code up to standard@6 compatibility
Browse files Browse the repository at this point in the history
Credit: @othiym23
PR-URL: npm/npm#11444
Reviewed-By: @zkat
Reviewed-By: @iarna
Reviewed-By: @othiym23
  • Loading branch information
othiym23 authored and iarna committed May 3, 2016
1 parent ef0dd74 commit e498dcb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 31 deletions.
1 change: 0 additions & 1 deletion bin/npm-cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env node
;(function () { // wrapper in case we're in module_context mode

// windows: running "npm blah" in this folder will invoke WSH, not node.
/*global WScript*/
if (typeof WScript !== 'undefined') {
Expand Down
1 change: 0 additions & 1 deletion lib/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ access.completion = function (opts, cb) {
} else {
return cb(null, [])
}
break
case 'public':
case 'restricted':
case 'ls-packages':
Expand Down
2 changes: 1 addition & 1 deletion lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
npm.command = c
if (commandCache[a]) return commandCache[a]

var cmd = require(__dirname + '/' + a + '.js')
var cmd = require(path.join(__dirname, a + '.js'))

commandCache[a] = function () {
var args = Array.prototype.slice.call(arguments, 0)
Expand Down
6 changes: 4 additions & 2 deletions lib/utils/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ function exit (code, noLog) {
}
})
rollbacks.length = 0
} else if (code && !noLog) {
writeLogFile(reallyExit)
} else {
rm('npm-debug.log', reallyExit)
}
else if (code && !noLog) writeLogFile(reallyExit)
else rm('npm-debug.log', reallyExit)

function reallyExit (er) {
if (er && !code) code = typeof er.errno === 'number' ? er.errno : 1
Expand Down
56 changes: 30 additions & 26 deletions lib/utils/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,10 @@ function makeEnv (data, prefix, env) {
prefix = prefix || 'npm_package_'
if (!env) {
env = {}
for (var i in process.env) if (!i.match(/^npm_/)) {
env[i] = process.env[i]
for (var i in process.env) {
if (!i.match(/^npm_/)) {
env[i] = process.env[i]
}
}

// npat asks for tap output
Expand All @@ -311,31 +313,33 @@ function makeEnv (data, prefix, env) {
)
}

for (i in data) if (i.charAt(0) !== '_') {
var envKey = (prefix + i).replace(/[^a-zA-Z0-9_]/g, '_')
if (i === 'readme') {
continue
}
if (data[i] && typeof data[i] === 'object') {
try {
// quick and dirty detection for cyclical structures
JSON.stringify(data[i])
makeEnv(data[i], envKey + '_', env)
} catch (ex) {
// usually these are package objects.
// just get the path and basic details.
var d = data[i]
makeEnv(
{ name: d.name, version: d.version, path: d.path },
envKey + '_',
env
)
for (i in data) {
if (i.charAt(0) !== '_') {
var envKey = (prefix + i).replace(/[^a-zA-Z0-9_]/g, '_')
if (i === 'readme') {
continue
}
if (data[i] && typeof data[i] === 'object') {
try {
// quick and dirty detection for cyclical structures
JSON.stringify(data[i])
makeEnv(data[i], envKey + '_', env)
} catch (ex) {
// usually these are package objects.
// just get the path and basic details.
var d = data[i]
makeEnv(
{ name: d.name, version: d.version, path: d.path },
envKey + '_',
env
)
}
} else {
env[envKey] = String(data[i])
env[envKey] = env[envKey].indexOf('\n') !== -1
? JSON.stringify(env[envKey])
: env[envKey]
}
} else {
env[envKey] = String(data[i])
env[envKey] = env[envKey].indexOf('\n') !== -1
? JSON.stringify(env[envKey])
: env[envKey]
}
}

Expand Down

0 comments on commit e498dcb

Please sign in to comment.