Skip to content

Commit 7c92800

Browse files
RobertJGabrielisaacs
authored and
isaacs
committedJul 10, 2019
Replace var with const for unbuild.js
Credit: @RobertJGabriel PR-URL: #210 Close: #210 Reviewed-by: @isaacs
1 parent f52673f commit 7c92800

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed
 

‎lib/unbuild.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ module.exports = unbuild
22
module.exports.rmStuff = rmStuff
33
unbuild.usage = 'npm unbuild <folder>\n(this is plumbing)'
44

5-
var readJson = require('read-package-json')
6-
var gentlyRm = require('./utils/gently-rm.js')
7-
var npm = require('./npm.js')
8-
var path = require('path')
9-
var isInside = require('path-is-inside')
10-
var lifecycle = require('./utils/lifecycle.js')
11-
var asyncMap = require('slide').asyncMap
12-
var chain = require('slide').chain
13-
var log = require('npmlog')
14-
var build = require('./build.js')
15-
var output = require('./utils/output.js')
5+
const readJson = require('read-package-json')
6+
const gentlyRm = require('./utils/gently-rm.js')
7+
const npm = require('./npm.js')
8+
const path = require('path')
9+
const isInside = require('path-is-inside')
10+
const lifecycle = require('./utils/lifecycle.js')
11+
const asyncMap = require('slide').asyncMap
12+
const chain = require('slide').chain
13+
const log = require('npmlog')
14+
const build = require('./build.js')
15+
const output = require('./utils/output.js')
1616

1717
// args is a list of folders.
1818
// remove any bins/etc, and then delete the folder.
@@ -30,7 +30,7 @@ function unbuild_ (silent) {
3030
cb_(er, path.relative(npm.root, folder))
3131
}
3232
folder = path.resolve(folder)
33-
var base = isInside(folder, npm.prefix) ? npm.prefix : folder
33+
const base = isInside(folder, npm.prefix) ? npm.prefix : folder
3434
delete build._didBuild[folder]
3535
log.verbose('unbuild', folder.substr(npm.prefix.length + 1))
3636
readJson(path.resolve(folder, 'package.json'), function (er, pkg) {
@@ -58,13 +58,13 @@ function rmStuff (pkg, folder, cb) {
5858
// if it's global, and folder is in {prefix}/node_modules,
5959
// then bins are in {prefix}/bin
6060
// otherwise, then bins are in folder/../.bin
61-
var dir = path.dirname(folder)
62-
var scope = path.basename(dir)
63-
var parent = scope.charAt(0) === '@' ? path.dirname(dir) : dir
64-
var gnm = npm.dir
61+
const dir = path.dirname(folder)
62+
const scope = path.basename(dir)
63+
const parent = scope.charAt(0) === '@' ? path.dirname(dir) : dir
64+
const gnm = npm.dir
6565
// gnm might be an absolute path, parent might be relative
6666
// this checks they're the same directory regardless
67-
var top = path.relative(gnm, parent) === ''
67+
const top = path.relative(gnm, parent) === ''
6868

6969
log.verbose('unbuild rmStuff', pkg._id, 'from', gnm)
7070
if (!top) log.verbose('unbuild rmStuff', 'in', parent)
@@ -75,7 +75,7 @@ function rmStuff (pkg, folder, cb) {
7575

7676
function rmBins (pkg, folder, parent, top, cb) {
7777
if (!pkg.bin) return cb()
78-
var binRoot = top ? npm.bin : path.resolve(parent, '.bin')
78+
const binRoot = top ? npm.bin : path.resolve(parent, '.bin')
7979
asyncMap(Object.keys(pkg.bin), function (b, cb) {
8080
if (process.platform === 'win32') {
8181
chain([ [gentlyRm, path.resolve(binRoot, b) + '.cmd', true, folder],
@@ -98,7 +98,7 @@ function rmMans (pkg, folder, parent, top, cb) {
9898
!npm.config.get('global')) {
9999
return cb()
100100
}
101-
var manRoot = path.resolve(npm.config.get('prefix'), 'share', 'man')
101+
const manRoot = path.resolve(npm.config.get('prefix'), 'share', 'man')
102102
log.verbose('rmMans', 'man files are', pkg.man, 'in', manRoot)
103103
asyncMap(pkg.man, function (man, cb) {
104104
if (Array.isArray(man)) {
@@ -109,7 +109,7 @@ function rmMans (pkg, folder, parent, top, cb) {
109109

110110
function rmMan (man) {
111111
log.silly('rmMan', 'preparing to remove', man)
112-
var parseMan = man.match(/(.*\.([0-9]+)(\.gz)?)$/)
112+
const parseMan = man.match(/(.*\.([0-9]+)(\.gz)?)$/)
113113
if (!parseMan) {
114114
log.error(
115115
'rmMan', man, 'is not a valid name for a man file.',
@@ -119,11 +119,11 @@ function rmMans (pkg, folder, parent, top, cb) {
119119
return cb()
120120
}
121121

122-
var stem = parseMan[1]
123-
var sxn = parseMan[2]
124-
var gz = parseMan[3] || ''
125-
var bn = path.basename(stem)
126-
var manDest = path.join(
122+
const stem = parseMan[1]
123+
const sxn = parseMan[2]
124+
const gz = parseMan[3] || ''
125+
const bn = path.basename(stem)
126+
const manDest = path.join(
127127
manRoot,
128128
'man' + sxn,
129129
(bn.indexOf(pkg.name) === 0 ? bn : pkg.name + '-' + bn) + '.' + sxn + gz

0 commit comments

Comments
 (0)
Please sign in to comment.