mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
deps: upgrade npm to 8.17.0
PR-URL: https://github.com/nodejs/node/pull/44205 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Ruy Adorno <ruyadorno@google.com>
This commit is contained in:
1 parent
4d26cb9bb2
commit
b1590bbca2
81 files changed
+1666
-711
No files matched your search
+1
-1
@@ -165,4 +165,4 @@ arb.loadActual((tree) => {
|
||||
## See Also
|
||||
|
||||
* [npm query](/commands/npm-query)
|
||||
* [@npmcli/arborist](https://npm.im/@npmcli/arborist]
|
||||
* [@npmcli/arborist](https://npm.im/@npmcli/arborist)
|
||||
+1
-1
@@ -166,7 +166,7 @@ tree at all, use <a href="../commands/npm-explain.html"><code>npm explain</code>
|
||||
the results to only the paths to the packages named. Note that nested
|
||||
packages will <em>also</em> show the paths to the specified packages. For
|
||||
example, running <code>npm ls promzard</code> in npm's source tree will show:</p>
|
||||
<pre lang="bash"><code>npm@8.16.0 /path/to/npm
|
||||
<pre lang="bash"><code>npm@8.17.0 /path/to/npm
|
||||
└─┬ init-package-json@0.0.4
|
||||
└── promzard@0.1.5
|
||||
</code></pre>
|
||||
|
||||
+1
-1
@@ -149,7 +149,7 @@ npm command-line interface
|
||||
<!-- raw HTML omitted -->
|
||||
<!-- raw HTML omitted -->
|
||||
<h3 id="version">Version</h3>
|
||||
<p>8.16.0</p>
|
||||
<p>8.17.0</p>
|
||||
<h3 id="description">Description</h3>
|
||||
<p>npm is the package manager for the Node JavaScript platform. It puts
|
||||
modules in place so that node can find them, and manages dependency
|
||||
|
||||
@@ -282,7 +282,7 @@ arb.loadActual((tree) => {
|
||||
<h2 id="see-also">See Also</h2>
|
||||
<ul>
|
||||
<li><a href="../commands/npm-query.html">npm query</a></li>
|
||||
<li>[@npmcli/arborist](<a href="https://npm.im/@npmcli/arborist%5D">https://npm.im/@npmcli/arborist]</a></li>
|
||||
<li><a href="https://npm.im/@npmcli/arborist">@npmcli/arborist</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
Vendored
+8
-1
@@ -34,6 +34,7 @@ class Exec extends BaseCommand {
|
||||
|
||||
const args = [..._args]
|
||||
const call = this.npm.config.get('call')
|
||||
let globalPath
|
||||
const {
|
||||
flatOptions,
|
||||
localBin,
|
||||
@@ -44,6 +45,12 @@ class Exec extends BaseCommand {
|
||||
const scriptShell = this.npm.config.get('script-shell') || undefined
|
||||
const packages = this.npm.config.get('package')
|
||||
const yes = this.npm.config.get('yes')
|
||||
// --prefix sets both of these to the same thing, meaning the global prefix
|
||||
// is invalid (i.e. no lib/node_modules). This is not a trivial thing to
|
||||
// untangle and fix so we work around it here.
|
||||
if (this.npm.localPrefix !== this.npm.globalPrefix) {
|
||||
globalPath = path.resolve(globalDir, '..')
|
||||
}
|
||||
|
||||
if (call && _args.length) {
|
||||
throw this.usageError()
|
||||
@@ -59,7 +66,7 @@ class Exec extends BaseCommand {
|
||||
localBin,
|
||||
locationMsg,
|
||||
globalBin,
|
||||
globalPath: path.resolve(globalDir, '..'),
|
||||
globalPath,
|
||||
output,
|
||||
packages,
|
||||
path: localPrefix,
|
||||
|
||||
Vendored
+1
@@ -58,6 +58,7 @@ class Query extends BaseCommand {
|
||||
const opts = {
|
||||
...this.npm.flatOptions,
|
||||
path: where,
|
||||
forceActual: true,
|
||||
}
|
||||
const arb = new Arborist(opts)
|
||||
const tree = await arb.loadActual(opts)
|
||||
|
||||
Vendored
+1
-1
@@ -26,7 +26,7 @@ example, running \fBnpm ls promzard\fP in npm's source tree will show:
|
||||
.P
|
||||
.RS 2
|
||||
.nf
|
||||
npm@8\.16\.0 /path/to/npm
|
||||
npm@8\.17\.0 /path/to/npm
|
||||
└─┬ init\-package\-json@0\.0\.4
|
||||
└── promzard@0\.1\.5
|
||||
.fi
|
||||
|
||||
Vendored
+1
-1
@@ -4,7 +4,7 @@
|
||||
.SS Synopsis
|
||||
.SS Version
|
||||
.P
|
||||
8\.16\.0
|
||||
8\.17\.0
|
||||
.SS Description
|
||||
.P
|
||||
npm is the package manager for the Node JavaScript platform\. It puts
|
||||
|
||||
+1
-1
@@ -240,6 +240,6 @@ arb\.loadActual((tree) => {
|
||||
.IP \(bu 2
|
||||
npm help query
|
||||
.IP \(bu 2
|
||||
[@npmcli/arborist](https://npm\.im/@npmcli/arborist]
|
||||
@npmcli/arborist \fIhttps://npm\.im/@npmcli/arborist\fR
|
||||
|
||||
.RE
|
||||
+20
-15
@@ -115,6 +115,7 @@ module.exports = cls => class ActualLoader extends cls {
|
||||
root = null,
|
||||
transplantFilter = () => true,
|
||||
ignoreMissing = false,
|
||||
forceActual = false,
|
||||
} = options
|
||||
this[_filter] = filter
|
||||
this[_transplantFilter] = transplantFilter
|
||||
@@ -141,26 +142,30 @@ module.exports = cls => class ActualLoader extends cls {
|
||||
|
||||
this[_actualTree].assertRootOverrides()
|
||||
|
||||
// Note: hidden lockfile will be rejected if it's not the latest thing
|
||||
// in the folder, or if any of the entries in the hidden lockfile are
|
||||
// missing.
|
||||
const meta = await Shrinkwrap.load({
|
||||
path: this[_actualTree].path,
|
||||
hiddenLockfile: true,
|
||||
resolveOptions: this.options,
|
||||
})
|
||||
if (meta.loadedFromDisk) {
|
||||
this[_actualTree].meta = meta
|
||||
return this[_loadActualVirtually]({ root })
|
||||
} else {
|
||||
// if forceActual is set, don't even try the hidden lockfile
|
||||
if (!forceActual) {
|
||||
// Note: hidden lockfile will be rejected if it's not the latest thing
|
||||
// in the folder, or if any of the entries in the hidden lockfile are
|
||||
// missing.
|
||||
const meta = await Shrinkwrap.load({
|
||||
path: this[_actualTree].path,
|
||||
lockfileVersion: this.options.lockfileVersion,
|
||||
hiddenLockfile: true,
|
||||
resolveOptions: this.options,
|
||||
})
|
||||
this[_actualTree].meta = meta
|
||||
return this[_loadActualActually]({ root, ignoreMissing })
|
||||
|
||||
if (meta.loadedFromDisk) {
|
||||
this[_actualTree].meta = meta
|
||||
return this[_loadActualVirtually]({ root })
|
||||
}
|
||||
}
|
||||
|
||||
const meta = await Shrinkwrap.load({
|
||||
path: this[_actualTree].path,
|
||||
lockfileVersion: this.options.lockfileVersion,
|
||||
resolveOptions: this.options,
|
||||
})
|
||||
this[_actualTree].meta = meta
|
||||
return this[_loadActualActually]({ root, ignoreMissing })
|
||||
}
|
||||
|
||||
async [_loadActualVirtually] ({ root }) {
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@npmcli/arborist",
|
||||
"version": "5.4.0",
|
||||
"version": "5.5.0",
|
||||
"description": "Manage node_modules trees",
|
||||
"dependencies": {
|
||||
"@isaacs/string-locale-compare": "^1.1.0",
|
||||
@@ -21,7 +21,7 @@
|
||||
"minimatch": "^5.1.0",
|
||||
"mkdirp": "^1.0.4",
|
||||
"mkdirp-infer-owner": "^2.0.0",
|
||||
"nopt": "^5.0.0",
|
||||
"nopt": "^6.0.0",
|
||||
"npm-install-checks": "^5.0.0",
|
||||
"npm-package-arg": "^9.0.0",
|
||||
"npm-pick-manifest": "^7.0.0",
|
||||
|
||||
+7
-9
@@ -296,6 +296,7 @@ class Config {
|
||||
// might be a security hazard, which was the intention.
|
||||
try {
|
||||
this.setCredentialsByURI(reg, creds)
|
||||
// eslint-disable-next-line no-empty
|
||||
} catch (_) {}
|
||||
process.emit('timeEnd', 'config:load:credentials')
|
||||
|
||||
@@ -366,9 +367,11 @@ class Config {
|
||||
if (!/^npm_config_/i.test(envKey) || envVal === '') {
|
||||
continue
|
||||
}
|
||||
const key = envKey.slice('npm_config_'.length)
|
||||
.replace(/(?!^)_/g, '-') // don't replace _ at the start of the key
|
||||
.toLowerCase()
|
||||
let key = envKey.slice('npm_config_'.length)
|
||||
if (!key.startsWith('//')) { // don't normalize nerf-darted keys
|
||||
key = key.replace(/(?!^)_/g, '-') // don't replace _ at the start of the key
|
||||
.toLowerCase()
|
||||
}
|
||||
conf[key] = envVal
|
||||
}
|
||||
this[_loadObject](conf, 'env', 'environment')
|
||||
@@ -654,6 +657,7 @@ class Config {
|
||||
// saved back to the .npmrc file, so we're good.
|
||||
try {
|
||||
this.setCredentialsByURI(reg, creds)
|
||||
// eslint-disable-next-line no-empty
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
@@ -691,8 +695,6 @@ class Config {
|
||||
this.delete(`_password`, 'user')
|
||||
this.delete(`username`, 'user')
|
||||
}
|
||||
this.delete(`${nerfed}:-authtoken`, 'user')
|
||||
this.delete(`${nerfed}:_authtoken`, 'user')
|
||||
this.delete(`${nerfed}:_authToken`, 'user')
|
||||
this.delete(`${nerfed}:_auth`, 'user')
|
||||
this.delete(`${nerfed}:_password`, 'user')
|
||||
@@ -732,8 +734,6 @@ class Config {
|
||||
// send auth if we have it, only to the URIs under the nerf dart.
|
||||
this.delete(`${nerfed}:always-auth`, 'user')
|
||||
|
||||
this.delete(`${nerfed}:-authtoken`, 'user')
|
||||
this.delete(`${nerfed}:_authtoken`, 'user')
|
||||
this.delete(`${nerfed}:email`, 'user')
|
||||
if (certfile && keyfile) {
|
||||
this.set(`${nerfed}:certfile`, certfile, 'user')
|
||||
@@ -781,8 +781,6 @@ class Config {
|
||||
}
|
||||
|
||||
const tokenReg = this.get(`${nerfed}:_authToken`) ||
|
||||
this.get(`${nerfed}:_authtoken`) ||
|
||||
this.get(`${nerfed}:-authtoken`) ||
|
||||
nerfed === nerfDart(this.get('registry')) && this.get('_authToken')
|
||||
|
||||
if (tokenReg) {
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@npmcli/config",
|
||||
"version": "4.2.0",
|
||||
"version": "4.2.1",
|
||||
"files": [
|
||||
"bin/",
|
||||
"lib/"
|
||||
@@ -38,7 +38,7 @@
|
||||
"@npmcli/map-workspaces": "^2.0.2",
|
||||
"ini": "^3.0.0",
|
||||
"mkdirp-infer-owner": "^2.0.0",
|
||||
"nopt": "^5.0.0",
|
||||
"nopt": "^6.0.0",
|
||||
"proc-log": "^2.0.0",
|
||||
"read-package-json-fast": "^2.0.3",
|
||||
"semver": "^7.3.5",
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ function appendNegatedPatterns (patterns) {
|
||||
for (let pattern of patterns) {
|
||||
const excl = pattern.match(/^!+/)
|
||||
if (excl) {
|
||||
pattern = pattern.substr(excl[0].length)
|
||||
pattern = pattern.slice(excl[0].length)
|
||||
}
|
||||
|
||||
// strip off any / from the start of the pattern. /foo => foo
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@npmcli/map-workspaces",
|
||||
"version": "2.0.3",
|
||||
"version": "2.0.4",
|
||||
"main": "lib/index.js",
|
||||
"files": [
|
||||
"bin/",
|
||||
@@ -42,7 +42,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^3.0.1",
|
||||
"@npmcli/template-oss": "3.4.1",
|
||||
"@npmcli/template-oss": "3.5.0",
|
||||
"tap": "^16.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -53,6 +53,6 @@
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"version": "3.4.1"
|
||||
"version": "3.5.0"
|
||||
}
|
||||
}
|
||||
+2
-11
@@ -36,14 +36,11 @@ const cmd = (input, doubleEscape) => {
|
||||
}
|
||||
|
||||
// and finally, prefix shell meta chars with a ^
|
||||
result = result.replace(/[ !^&()<>|"]/g, '^$&')
|
||||
result = result.replace(/[ !%^&()<>|"]/g, '^$&')
|
||||
if (doubleEscape) {
|
||||
result = result.replace(/[ !^&()<>|"]/g, '^$&')
|
||||
result = result.replace(/[ !%^&()<>|"]/g, '^$&')
|
||||
}
|
||||
|
||||
// except for % which is escaped with another %, and only once
|
||||
result = result.replace(/%/g, '%%')
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -65,13 +62,7 @@ const sh = (input) => {
|
||||
return result
|
||||
}
|
||||
|
||||
// disabling the no-control-regex rule for this line as we very specifically _do_ want to
|
||||
// replace those characters if they somehow exist at this point, which is highly unlikely
|
||||
// eslint-disable-next-line no-control-regex
|
||||
const filename = (input) => input.replace(/[<>:"/\\|?*\x00-\x1F]/g, '')
|
||||
|
||||
module.exports = {
|
||||
cmd,
|
||||
sh,
|
||||
filename,
|
||||
}
|
||||
+11
-40
@@ -1,19 +1,10 @@
|
||||
/* eslint camelcase: "off" */
|
||||
const isWindows = require('./is-windows.js')
|
||||
const setPATH = require('./set-path.js')
|
||||
const { unlinkSync: unlink, writeFileSync: writeFile } = require('fs')
|
||||
const { tmpdir } = require('os')
|
||||
const { resolve } = require('path')
|
||||
const which = require('which')
|
||||
const npm_config_node_gyp = require.resolve('node-gyp/bin/node-gyp.js')
|
||||
const escape = require('./escape.js')
|
||||
const { randomBytes } = require('crypto')
|
||||
|
||||
const translateWinPathToPosix = (path) => {
|
||||
return path
|
||||
.replace(/^([A-z]):/, '/$1')
|
||||
.replace(/\\/g, '/')
|
||||
}
|
||||
|
||||
const makeSpawnArgs = options => {
|
||||
const {
|
||||
@@ -38,10 +29,7 @@ const makeSpawnArgs = options => {
|
||||
npm_config_node_gyp,
|
||||
})
|
||||
|
||||
const fileName = escape.filename(`${event}-${randomBytes(4).toString('hex')}`)
|
||||
let scriptFile
|
||||
let script = ''
|
||||
|
||||
let doubleEscape = false
|
||||
const isCmd = /(?:^|\\)cmd(?:\.exe)?$/i.test(scriptShell)
|
||||
if (isCmd) {
|
||||
let initialCmd = ''
|
||||
@@ -68,26 +56,18 @@ const makeSpawnArgs = options => {
|
||||
pathToInitial = initialCmd.toLowerCase()
|
||||
}
|
||||
|
||||
const doubleEscape = pathToInitial.endsWith('.cmd') || pathToInitial.endsWith('.bat')
|
||||
|
||||
scriptFile = resolve(tmpdir(), `${fileName}.cmd`)
|
||||
script += '@echo off\n'
|
||||
script += cmd
|
||||
if (args.length) {
|
||||
script += ` ${args.map((arg) => escape.cmd(arg, doubleEscape)).join(' ')}`
|
||||
}
|
||||
} else {
|
||||
scriptFile = resolve(tmpdir(), `${fileName}.sh`)
|
||||
script = cmd
|
||||
if (args.length) {
|
||||
script += ` ${args.map((arg) => escape.sh(arg)).join(' ')}`
|
||||
}
|
||||
doubleEscape = pathToInitial.endsWith('.cmd') || pathToInitial.endsWith('.bat')
|
||||
}
|
||||
|
||||
writeFile(scriptFile, script)
|
||||
let script = cmd
|
||||
for (const arg of args) {
|
||||
script += isCmd
|
||||
? ` ${escape.cmd(arg, doubleEscape)}`
|
||||
: ` ${escape.sh(arg)}`
|
||||
}
|
||||
const spawnArgs = isCmd
|
||||
? ['/d', '/s', '/c', escape.cmd(scriptFile)]
|
||||
: [isWindows ? translateWinPathToPosix(scriptFile) : scriptFile]
|
||||
? ['/d', '/s', '/c', script]
|
||||
: ['-c', '--', script]
|
||||
|
||||
const spawnOpts = {
|
||||
env: spawnEnv,
|
||||
@@ -97,16 +77,7 @@ const makeSpawnArgs = options => {
|
||||
...(isCmd ? { windowsVerbatimArguments: true } : {}),
|
||||
}
|
||||
|
||||
const cleanup = () => {
|
||||
// delete the script, this is just a best effort
|
||||
try {
|
||||
unlink(scriptFile)
|
||||
} catch (err) {
|
||||
// ignore errors
|
||||
}
|
||||
}
|
||||
|
||||
return [scriptShell, spawnArgs, spawnOpts, cleanup]
|
||||
return [scriptShell, spawnArgs, spawnOpts]
|
||||
}
|
||||
|
||||
module.exports = makeSpawnArgs
|
||||
+14
-5
@@ -6,8 +6,17 @@ const signalManager = require('./signal-manager.js')
|
||||
const isServerPackage = require('./is-server-package.js')
|
||||
|
||||
// you wouldn't like me when I'm angry...
|
||||
const bruce = (id, event, cmd) =>
|
||||
`\n> ${id ? id + ' ' : ''}${event}\n> ${cmd.trim().replace(/\n/g, '\n> ')}\n`
|
||||
const bruce = (id, event, cmd, args) => {
|
||||
let banner = id
|
||||
? `\n> ${id} ${event}\n`
|
||||
: `\n> ${event}\n`
|
||||
banner += `> ${cmd.trim().replace(/\n/g, '\n> ')}`
|
||||
if (args.length) {
|
||||
banner += ` ${args.join(' ')}`
|
||||
}
|
||||
banner += '\n'
|
||||
return banner
|
||||
}
|
||||
|
||||
const runScriptPkg = async options => {
|
||||
const {
|
||||
@@ -52,10 +61,10 @@ const runScriptPkg = async options => {
|
||||
|
||||
if (stdio === 'inherit' && banner !== false) {
|
||||
// we're dumping to the parent's stdout, so print the banner
|
||||
console.log(bruce(pkg._id, event, cmd))
|
||||
console.log(bruce(pkg._id, event, cmd, args))
|
||||
}
|
||||
|
||||
const [spawnShell, spawnArgs, spawnOpts, cleanup] = makeSpawnArgs({
|
||||
const [spawnShell, spawnArgs, spawnOpts] = makeSpawnArgs({
|
||||
event,
|
||||
path,
|
||||
scriptShell,
|
||||
@@ -93,7 +102,7 @@ const runScriptPkg = async options => {
|
||||
} else {
|
||||
throw er
|
||||
}
|
||||
}).finally(cleanup)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = runScriptPkg
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@npmcli/run-script",
|
||||
"version": "4.2.0",
|
||||
"version": "4.2.1",
|
||||
"description": "Run a lifecycle script for a package (descendant of npm-lifecycle)",
|
||||
"author": "GitHub Inc.",
|
||||
"license": "ISC",
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ TrackerGroup.prototype.finish = function () {
|
||||
var buffer = ' '
|
||||
TrackerGroup.prototype.debug = function (depth) {
|
||||
depth = depth || 0
|
||||
var indent = depth ? buffer.substr(0, depth) : ''
|
||||
var indent = depth ? buffer.slice(0, depth) : ''
|
||||
var output = indent + (this.name || 'top') + ': ' + this.completed() + '\n'
|
||||
this.trackers.forEach(function (tracker) {
|
||||
if (tracker instanceof TrackerGroup) {
|
||||
|
||||
+12
-13
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "are-we-there-yet",
|
||||
"version": "3.0.0",
|
||||
"version": "3.0.1",
|
||||
"description": "Keep track of the overall completion of many disparate processes",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"test": "tap",
|
||||
"npmclilint": "npmcli-lint",
|
||||
"lint": "eslint '**/*.js'",
|
||||
"lint": "eslint \"**/*.js\"",
|
||||
"lintfix": "npm run lint -- --fix",
|
||||
"posttest": "npm run lint",
|
||||
"postsnap": "npm run lintfix --",
|
||||
@@ -14,8 +14,8 @@
|
||||
"postversion": "npm publish",
|
||||
"prepublishOnly": "git push origin --follow-tags",
|
||||
"snap": "tap",
|
||||
"postlint": "npm-template-check",
|
||||
"template-copy": "npm-template-copy --force"
|
||||
"postlint": "template-oss-check",
|
||||
"template-oss-apply": "template-oss-apply --force"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -28,22 +28,20 @@
|
||||
},
|
||||
"homepage": "https://github.com/npm/are-we-there-yet",
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^2.0.0",
|
||||
"@npmcli/template-oss": "^2.7.1",
|
||||
"eslint": "^8.8.0",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"tap": "^15.0.9"
|
||||
"@npmcli/eslint-config": "^3.0.1",
|
||||
"@npmcli/template-oss": "3.5.0",
|
||||
"tap": "^16.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"delegates": "^1.0.0",
|
||||
"readable-stream": "^3.6.0"
|
||||
},
|
||||
"files": [
|
||||
"bin",
|
||||
"lib"
|
||||
"bin/",
|
||||
"lib/"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^12.13.0 || ^14.15.0 || >=16"
|
||||
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
|
||||
},
|
||||
"tap": {
|
||||
"branches": 68,
|
||||
@@ -52,6 +50,7 @@
|
||||
"lines": 92
|
||||
},
|
||||
"templateOSS": {
|
||||
"version": "2.7.1"
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"version": "3.5.0"
|
||||
}
|
||||
}
|
||||
+54
-59
@@ -1,24 +1,24 @@
|
||||
var ip = exports;
|
||||
var { Buffer } = require('buffer');
|
||||
var os = require('os');
|
||||
const ip = exports;
|
||||
const { Buffer } = require('buffer');
|
||||
const os = require('os');
|
||||
|
||||
ip.toBuffer = function (ip, buff, offset) {
|
||||
offset = ~~offset;
|
||||
|
||||
var result;
|
||||
let result;
|
||||
|
||||
if (this.isV4Format(ip)) {
|
||||
result = buff || new Buffer(offset + 4);
|
||||
result = buff || Buffer.alloc(offset + 4);
|
||||
ip.split(/\./g).map((byte) => {
|
||||
result[offset++] = parseInt(byte, 10) & 0xff;
|
||||
});
|
||||
} else if (this.isV6Format(ip)) {
|
||||
var sections = ip.split(':', 8);
|
||||
const sections = ip.split(':', 8);
|
||||
|
||||
var i;
|
||||
let i;
|
||||
for (i = 0; i < sections.length; i++) {
|
||||
var isv4 = this.isV4Format(sections[i]);
|
||||
var v4Buffer;
|
||||
const isv4 = this.isV4Format(sections[i]);
|
||||
let v4Buffer;
|
||||
|
||||
if (isv4) {
|
||||
v4Buffer = this.toBuffer(sections[i]);
|
||||
@@ -36,16 +36,16 @@ ip.toBuffer = function (ip, buff, offset) {
|
||||
while (sections.length < 8) sections.push('0');
|
||||
} else if (sections.length < 8) {
|
||||
for (i = 0; i < sections.length && sections[i] !== ''; i++);
|
||||
var argv = [i, 1];
|
||||
const argv = [i, 1];
|
||||
for (i = 9 - sections.length; i > 0; i--) {
|
||||
argv.push('0');
|
||||
}
|
||||
sections.splice.apply(sections, argv);
|
||||
sections.splice(...argv);
|
||||
}
|
||||
|
||||
result = buff || new Buffer(offset + 16);
|
||||
result = buff || Buffer.alloc(offset + 16);
|
||||
for (i = 0; i < sections.length; i++) {
|
||||
var word = parseInt(sections[i], 16);
|
||||
const word = parseInt(sections[i], 16);
|
||||
result[offset++] = (word >> 8) & 0xff;
|
||||
result[offset++] = word & 0xff;
|
||||
}
|
||||
@@ -62,17 +62,16 @@ ip.toString = function (buff, offset, length) {
|
||||
offset = ~~offset;
|
||||
length = length || (buff.length - offset);
|
||||
|
||||
var result = [];
|
||||
var i;
|
||||
let result = [];
|
||||
if (length === 4) {
|
||||
// IPv4
|
||||
for (i = 0; i < length; i++) {
|
||||
for (let i = 0; i < length; i++) {
|
||||
result.push(buff[offset + i]);
|
||||
}
|
||||
result = result.join('.');
|
||||
} else if (length === 16) {
|
||||
// IPv6
|
||||
for (i = 0; i < length; i += 2) {
|
||||
for (let i = 0; i < length; i += 2) {
|
||||
result.push(buff.readUInt16BE(offset + i).toString(16));
|
||||
}
|
||||
result = result.join(':');
|
||||
@@ -83,8 +82,8 @@ ip.toString = function (buff, offset, length) {
|
||||
return result;
|
||||
};
|
||||
|
||||
var ipv4Regex = /^(\d{1,3}\.){3,3}\d{1,3}$/;
|
||||
var ipv6Regex = /^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;
|
||||
const ipv4Regex = /^(\d{1,3}\.){3,3}\d{1,3}$/;
|
||||
const ipv6Regex = /^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i;
|
||||
|
||||
ip.isV4Format = function (ip) {
|
||||
return ipv4Regex.test(ip);
|
||||
@@ -111,14 +110,14 @@ ip.fromPrefixLen = function (prefixlen, family) {
|
||||
family = _normalizeFamily(family);
|
||||
}
|
||||
|
||||
var len = 4;
|
||||
let len = 4;
|
||||
if (family === 'ipv6') {
|
||||
len = 16;
|
||||
}
|
||||
var buff = new Buffer(len);
|
||||
const buff = Buffer.alloc(len);
|
||||
|
||||
for (var i = 0, n = buff.length; i < n; ++i) {
|
||||
var bits = 8;
|
||||
for (let i = 0, n = buff.length; i < n; ++i) {
|
||||
let bits = 8;
|
||||
if (prefixlen < 8) {
|
||||
bits = prefixlen;
|
||||
}
|
||||
@@ -134,10 +133,10 @@ ip.mask = function (addr, mask) {
|
||||
addr = ip.toBuffer(addr);
|
||||
mask = ip.toBuffer(mask);
|
||||
|
||||
var result = new Buffer(Math.max(addr.length, mask.length));
|
||||
const result = Buffer.alloc(Math.max(addr.length, mask.length));
|
||||
|
||||
// Same protocol - do bitwise and
|
||||
var i;
|
||||
let i;
|
||||
if (addr.length === mask.length) {
|
||||
for (i = 0; i < addr.length; i++) {
|
||||
result[i] = addr[i] & mask[i];
|
||||
@@ -170,30 +169,30 @@ ip.mask = function (addr, mask) {
|
||||
};
|
||||
|
||||
ip.cidr = function (cidrString) {
|
||||
var cidrParts = cidrString.split('/');
|
||||
const cidrParts = cidrString.split('/');
|
||||
|
||||
var addr = cidrParts[0];
|
||||
const addr = cidrParts[0];
|
||||
if (cidrParts.length !== 2) {
|
||||
throw new Error(`invalid CIDR subnet: ${addr}`);
|
||||
}
|
||||
|
||||
var mask = ip.fromPrefixLen(parseInt(cidrParts[1], 10));
|
||||
const mask = ip.fromPrefixLen(parseInt(cidrParts[1], 10));
|
||||
|
||||
return ip.mask(addr, mask);
|
||||
};
|
||||
|
||||
ip.subnet = function (addr, mask) {
|
||||
var networkAddress = ip.toLong(ip.mask(addr, mask));
|
||||
const networkAddress = ip.toLong(ip.mask(addr, mask));
|
||||
|
||||
// Calculate the mask's length.
|
||||
var maskBuffer = ip.toBuffer(mask);
|
||||
var maskLength = 0;
|
||||
const maskBuffer = ip.toBuffer(mask);
|
||||
let maskLength = 0;
|
||||
|
||||
for (var i = 0; i < maskBuffer.length; i++) {
|
||||
for (let i = 0; i < maskBuffer.length; i++) {
|
||||
if (maskBuffer[i] === 0xff) {
|
||||
maskLength += 8;
|
||||
} else {
|
||||
var octet = maskBuffer[i] & 0xff;
|
||||
let octet = maskBuffer[i] & 0xff;
|
||||
while (octet) {
|
||||
octet = (octet << 1) & 0xff;
|
||||
maskLength++;
|
||||
@@ -201,7 +200,7 @@ ip.subnet = function (addr, mask) {
|
||||
}
|
||||
}
|
||||
|
||||
var numberOfAddresses = Math.pow(2, 32 - maskLength);
|
||||
const numberOfAddresses = 2 ** (32 - maskLength);
|
||||
|
||||
return {
|
||||
networkAddress: ip.fromLong(networkAddress),
|
||||
@@ -224,50 +223,48 @@ ip.subnet = function (addr, mask) {
|
||||
};
|
||||
|
||||
ip.cidrSubnet = function (cidrString) {
|
||||
var cidrParts = cidrString.split('/');
|
||||
const cidrParts = cidrString.split('/');
|
||||
|
||||
var addr = cidrParts[0];
|
||||
const addr = cidrParts[0];
|
||||
if (cidrParts.length !== 2) {
|
||||
throw new Error(`invalid CIDR subnet: ${addr}`);
|
||||
}
|
||||
|
||||
var mask = ip.fromPrefixLen(parseInt(cidrParts[1], 10));
|
||||
const mask = ip.fromPrefixLen(parseInt(cidrParts[1], 10));
|
||||
|
||||
return ip.subnet(addr, mask);
|
||||
};
|
||||
|
||||
ip.not = function (addr) {
|
||||
var buff = ip.toBuffer(addr);
|
||||
for (var i = 0; i < buff.length; i++) {
|
||||
const buff = ip.toBuffer(addr);
|
||||
for (let i = 0; i < buff.length; i++) {
|
||||
buff[i] = 0xff ^ buff[i];
|
||||
}
|
||||
return ip.toString(buff);
|
||||
};
|
||||
|
||||
ip.or = function (a, b) {
|
||||
var i;
|
||||
|
||||
a = ip.toBuffer(a);
|
||||
b = ip.toBuffer(b);
|
||||
|
||||
// same protocol
|
||||
if (a.length === b.length) {
|
||||
for (i = 0; i < a.length; ++i) {
|
||||
for (let i = 0; i < a.length; ++i) {
|
||||
a[i] |= b[i];
|
||||
}
|
||||
return ip.toString(a);
|
||||
|
||||
// mixed protocols
|
||||
}
|
||||
var buff = a;
|
||||
var other = b;
|
||||
let buff = a;
|
||||
let other = b;
|
||||
if (b.length > a.length) {
|
||||
buff = b;
|
||||
other = a;
|
||||
}
|
||||
|
||||
var offset = buff.length - other.length;
|
||||
for (i = offset; i < buff.length; ++i) {
|
||||
const offset = buff.length - other.length;
|
||||
for (let i = offset; i < buff.length; ++i) {
|
||||
buff[i] |= other[i - offset];
|
||||
}
|
||||
|
||||
@@ -275,14 +272,12 @@ ip.or = function (a, b) {
|
||||
};
|
||||
|
||||
ip.isEqual = function (a, b) {
|
||||
var i;
|
||||
|
||||
a = ip.toBuffer(a);
|
||||
b = ip.toBuffer(b);
|
||||
|
||||
// Same protocol
|
||||
if (a.length === b.length) {
|
||||
for (i = 0; i < a.length; i++) {
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (a[i] !== b[i]) return false;
|
||||
}
|
||||
return true;
|
||||
@@ -290,20 +285,20 @@ ip.isEqual = function (a, b) {
|
||||
|
||||
// Swap
|
||||
if (b.length === 4) {
|
||||
var t = b;
|
||||
const t = b;
|
||||
b = a;
|
||||
a = t;
|
||||
}
|
||||
|
||||
// a - IPv4, b - IPv6
|
||||
for (i = 0; i < 10; i++) {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
if (b[i] !== 0) return false;
|
||||
}
|
||||
|
||||
var word = b.readUInt16BE(10);
|
||||
const word = b.readUInt16BE(10);
|
||||
if (word !== 0 && word !== 0xffff) return false;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (let i = 0; i < 4; i++) {
|
||||
if (a[i] !== b[i + 12]) return false;
|
||||
}
|
||||
|
||||
@@ -365,7 +360,7 @@ ip.loopback = function (family) {
|
||||
// * undefined: First address with `ipv4` or loopback address `127.0.0.1`.
|
||||
//
|
||||
ip.address = function (name, family) {
|
||||
var interfaces = os.networkInterfaces();
|
||||
const interfaces = os.networkInterfaces();
|
||||
|
||||
//
|
||||
// Default to `ipv4`
|
||||
@@ -377,8 +372,8 @@ ip.address = function (name, family) {
|
||||
// return the address.
|
||||
//
|
||||
if (name && name !== 'private' && name !== 'public') {
|
||||
var res = interfaces[name].filter((details) => {
|
||||
var itemFamily = _normalizeFamily(details.family);
|
||||
const res = interfaces[name].filter((details) => {
|
||||
const itemFamily = _normalizeFamily(details.family);
|
||||
return itemFamily === family;
|
||||
});
|
||||
if (res.length === 0) {
|
||||
@@ -387,12 +382,12 @@ ip.address = function (name, family) {
|
||||
return res[0].address;
|
||||
}
|
||||
|
||||
var all = Object.keys(interfaces).map((nic) => {
|
||||
const all = Object.keys(interfaces).map((nic) => {
|
||||
//
|
||||
// Note: name will only be `public` or `private`
|
||||
// when this is called.
|
||||
//
|
||||
var addresses = interfaces[nic].filter((details) => {
|
||||
const addresses = interfaces[nic].filter((details) => {
|
||||
details.family = _normalizeFamily(details.family);
|
||||
if (details.family !== family || ip.isLoopback(details.address)) {
|
||||
return false;
|
||||
@@ -411,7 +406,7 @@ ip.address = function (name, family) {
|
||||
};
|
||||
|
||||
ip.toLong = function (ip) {
|
||||
var ipl = 0;
|
||||
let ipl = 0;
|
||||
ip.split('.').forEach((octet) => {
|
||||
ipl <<= 8;
|
||||
ipl += parseInt(octet);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ip",
|
||||
"version": "1.1.8",
|
||||
"version": "2.0.0",
|
||||
"author": "Fedor Indutny <fedor@indutny.com>",
|
||||
"homepage": "https://github.com/indutny/node-ip",
|
||||
"repository": {
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@
|
||||
"node:string_decoder": [">= 14.18 && < 15", ">= 16"],
|
||||
"sys": [">= 0.4 && < 0.7", ">= 0.8"],
|
||||
"node:sys": [">= 14.18 && < 15", ">= 16"],
|
||||
"node:test": ">= 18",
|
||||
"node:test": [">= 16.17 && < 17", ">= 18"],
|
||||
"timers": true,
|
||||
"node:timers": [">= 14.18 && < 15", ">= 16"],
|
||||
"timers/promises": ">= 15",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "is-core-module",
|
||||
"version": "2.9.0",
|
||||
"version": "2.10.0",
|
||||
"description": "Is this specifier a node.js core module?",
|
||||
"main": "index.js",
|
||||
"sideEffects": false,
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ test('core modules', function (t) {
|
||||
t.test('core via repl module', { skip: !data.repl }, function (st) {
|
||||
var libs = require('repl')._builtinLibs; // eslint-disable-line no-underscore-dangle
|
||||
if (!libs) {
|
||||
st.skip('module.builtinModules does not exist');
|
||||
st.skip('repl._builtinLibs does not exist');
|
||||
} else {
|
||||
for (var i = 0; i < libs.length; ++i) {
|
||||
var mod = libs[i];
|
||||
|
||||
+5
-3
@@ -1,14 +1,16 @@
|
||||
{
|
||||
"name": "just-diff-apply",
|
||||
"version": "5.3.1",
|
||||
"version": "5.4.1",
|
||||
"description": "Apply a diff to an object. Optionally supports jsonPatch protocol",
|
||||
"main": "index.js",
|
||||
"module": "index.mjs",
|
||||
"exports": {
|
||||
".": {
|
||||
"require": "./index.js",
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.mjs"
|
||||
}
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"types": "index.d.ts",
|
||||
"scripts": {
|
||||
@@ -29,4 +31,4 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/angus-c/just/issues"
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-3
@@ -1,14 +1,16 @@
|
||||
{
|
||||
"name": "just-diff",
|
||||
"version": "5.0.3",
|
||||
"version": "5.1.1",
|
||||
"description": "Return an object representing the diffs between two objects. Supports jsonPatch protocol",
|
||||
"main": "index.js",
|
||||
"module": "index.mjs",
|
||||
"exports": {
|
||||
".": {
|
||||
"require": "./index.js",
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.mjs"
|
||||
}
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"types": "index.d.ts",
|
||||
"scripts": {
|
||||
@@ -28,4 +30,4 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/angus-c/just/issues"
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
-27
@@ -28,7 +28,7 @@ const binPaths = []
|
||||
const manifests = new Map()
|
||||
|
||||
const getManifest = async (spec, flatOptions) => {
|
||||
if (!manifests.get(spec.raw)) {
|
||||
if (!manifests.has(spec.raw)) {
|
||||
const manifest = await pacote.manifest(spec, { ...flatOptions, preferOnline: true })
|
||||
manifests.set(spec.raw, manifest)
|
||||
}
|
||||
@@ -36,6 +36,7 @@ const getManifest = async (spec, flatOptions) => {
|
||||
}
|
||||
|
||||
// Returns the required manifest if the spec is missing from the tree
|
||||
// Returns the found node if it is in the tree
|
||||
const missingFromTree = async ({ spec, tree, flatOptions }) => {
|
||||
if (spec.registry && (spec.rawSpec === '' || spec.type !== 'tag')) {
|
||||
// registry spec that is not a specific tag.
|
||||
@@ -43,20 +44,21 @@ const missingFromTree = async ({ spec, tree, flatOptions }) => {
|
||||
for (const node of nodesBySpec) {
|
||||
if (spec.type === 'tag') {
|
||||
// package requested by name only
|
||||
return
|
||||
return { node }
|
||||
} else if (spec.type === 'version') {
|
||||
// package requested by specific version
|
||||
if (node.pkgid === spec.raw) {
|
||||
return
|
||||
return { node }
|
||||
}
|
||||
} else {
|
||||
// package requested by version range, only remaining registry type
|
||||
if (semver.satisfies(node.package.version, spec.rawSpec)) {
|
||||
return
|
||||
return { node }
|
||||
}
|
||||
}
|
||||
}
|
||||
return await getManifest(spec, flatOptions)
|
||||
const manifest = await getManifest(spec, flatOptions)
|
||||
return { manifest }
|
||||
} else {
|
||||
// non-registry spec, or a specific tag. Look up manifest and check
|
||||
// resolved to see if it's in the tree.
|
||||
@@ -65,10 +67,10 @@ const missingFromTree = async ({ spec, tree, flatOptions }) => {
|
||||
for (const node of nodesByManifest) {
|
||||
if (node.package.resolved === manifest._resolved) {
|
||||
// we have a package by the same name and the same resolved destination, nothing to add.
|
||||
return
|
||||
return { node }
|
||||
}
|
||||
}
|
||||
return manifest
|
||||
return { manifest }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +82,7 @@ const exec = async (opts) => {
|
||||
localBin = resolve('./node_modules/.bin'),
|
||||
locationMsg = undefined,
|
||||
globalBin = '',
|
||||
globalPath = '',
|
||||
globalPath,
|
||||
output,
|
||||
// dereference values because we manipulate it later
|
||||
packages: [...packages] = [],
|
||||
@@ -118,7 +120,7 @@ const exec = async (opts) => {
|
||||
if (localBinPath) {
|
||||
binPaths.push(localBinPath)
|
||||
return await run()
|
||||
} else if (await fileExists(`${globalBin}/${args[0]}`)) {
|
||||
} else if (globalPath && await fileExists(`${globalBin}/${args[0]}`)) {
|
||||
binPaths.push(globalBin)
|
||||
return await run()
|
||||
}
|
||||
@@ -132,35 +134,37 @@ const exec = async (opts) => {
|
||||
|
||||
// Find anything that isn't installed locally
|
||||
const needInstall = []
|
||||
await Promise.all(packages.map(async pkg => {
|
||||
let commandManifest
|
||||
await Promise.all(packages.map(async (pkg, i) => {
|
||||
const spec = npa(pkg, path)
|
||||
const manifest = await missingFromTree({ spec, tree: localTree, flatOptions })
|
||||
const { manifest, node } = await missingFromTree({ spec, tree: localTree, flatOptions })
|
||||
if (manifest) {
|
||||
// Package does not exist in the local tree
|
||||
needInstall.push({ spec, manifest })
|
||||
if (i === 0) {
|
||||
commandManifest = manifest
|
||||
}
|
||||
} else if (i === 0) {
|
||||
// The node.package has enough to look up the bin
|
||||
commandManifest = node.package
|
||||
}
|
||||
}))
|
||||
|
||||
if (needPackageCommandSwap) {
|
||||
// Either we have a scoped package or the bin of our package we inferred
|
||||
// from arg[0] might not be identical to the package name
|
||||
const spec = npa(args[0])
|
||||
let commandManifest
|
||||
if (needInstall.length === 0) {
|
||||
commandManifest = await getManifest(spec, flatOptions)
|
||||
} else {
|
||||
commandManifest = needInstall[0].manifest
|
||||
}
|
||||
|
||||
args[0] = getBinFromManifest(commandManifest)
|
||||
|
||||
// See if the package is installed globally, and run the translated bin
|
||||
const globalArb = new Arborist({ ...flatOptions, path: globalPath, global: true })
|
||||
const globalTree = await globalArb.loadActual()
|
||||
const globalManifest = await missingFromTree({ spec, tree: globalTree, flatOptions })
|
||||
if (!globalManifest) {
|
||||
binPaths.push(globalBin)
|
||||
return await run()
|
||||
if (needInstall.length > 0 && globalPath) {
|
||||
// See if the package is installed globally, and run the translated bin
|
||||
const globalArb = new Arborist({ ...flatOptions, path: globalPath, global: true })
|
||||
const globalTree = await globalArb.loadActual()
|
||||
const { manifest: globalManifest } =
|
||||
await missingFromTree({ spec, tree: globalTree, flatOptions })
|
||||
if (!globalManifest && await fileExists(`${globalBin}/${args[0]}`)) {
|
||||
binPaths.push(globalBin)
|
||||
return await run()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +187,7 @@ const exec = async (opts) => {
|
||||
})
|
||||
const npxTree = await npxArb.loadActual()
|
||||
await Promise.all(needInstall.map(async ({ spec }) => {
|
||||
const manifest = await missingFromTree({ spec, tree: npxTree, flatOptions })
|
||||
const { manifest } = await missingFromTree({ spec, tree: npxTree, flatOptions })
|
||||
if (manifest) {
|
||||
// Manifest is not in npxCache, we need to install it there
|
||||
if (!spec.registry) {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "libnpmexec",
|
||||
"version": "4.0.9",
|
||||
"version": "4.0.10",
|
||||
"files": [
|
||||
"bin/",
|
||||
"lib/"
|
||||
|
||||
+3
-4
@@ -1,4 +1,3 @@
|
||||
// Type definitions for lru-cache 7.10.0
|
||||
// Project: https://github.com/isaacs/node-lru-cache
|
||||
// Based initially on @types/lru-cache
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
@@ -32,7 +31,6 @@
|
||||
// Changes by Isaac Z. Schlueter released under the terms found in the
|
||||
// LICENSE file within this project.
|
||||
|
||||
/// <reference lib="DOM" />
|
||||
//tslint:disable:member-access
|
||||
declare class LRUCache<K, V> implements Iterable<[K, V]> {
|
||||
constructor(options: LRUCache.Options<K, V>)
|
||||
@@ -569,10 +567,11 @@ declare namespace LRUCache {
|
||||
/**
|
||||
* options which override the options set in the LRUCache constructor
|
||||
* when making `cache.fetch()` calls.
|
||||
* This is the union of GetOptions and SetOptions, plus the
|
||||
* `noDeleteOnFetchRejection` and `fetchContext` fields.
|
||||
* This is the union of GetOptions and SetOptions, plus
|
||||
* `noDeleteOnFetchRejection`, `forceRefresh`, and `fetchContext`
|
||||
*/
|
||||
interface FetchOptions<K, V> extends FetcherFetchOptions<K, V> {
|
||||
forceRefresh?: boolean
|
||||
fetchContext?: any
|
||||
}
|
||||
|
||||
|
||||
+28
-11
@@ -364,8 +364,10 @@ class LRUCache {
|
||||
initializeSizeTracking() {
|
||||
this.calculatedSize = 0
|
||||
this.sizes = new ZeroArray(this.max)
|
||||
this.removeItemSize = index =>
|
||||
(this.calculatedSize -= this.sizes[index])
|
||||
this.removeItemSize = index => {
|
||||
this.calculatedSize -= this.sizes[index]
|
||||
this.sizes[index] = 0
|
||||
}
|
||||
this.requireSize = (k, v, size, sizeCalculation) => {
|
||||
if (!isPosInt(size)) {
|
||||
if (sizeCalculation) {
|
||||
@@ -386,7 +388,7 @@ class LRUCache {
|
||||
}
|
||||
return size
|
||||
}
|
||||
this.addItemSize = (index, v, k, size) => {
|
||||
this.addItemSize = (index, size) => {
|
||||
this.sizes[index] = size
|
||||
const maxSize = this.maxSize - this.sizes[index]
|
||||
while (this.calculatedSize > maxSize) {
|
||||
@@ -396,7 +398,7 @@ class LRUCache {
|
||||
}
|
||||
}
|
||||
removeItemSize(index) {}
|
||||
addItemSize(index, v, k, size) {}
|
||||
addItemSize(index, size) {}
|
||||
requireSize(k, v, size, sizeCalculation) {
|
||||
if (size || sizeCalculation) {
|
||||
throw new TypeError(
|
||||
@@ -523,7 +525,9 @@ class LRUCache {
|
||||
for (const i of this.indexes({ allowStale: true })) {
|
||||
const key = this.keyList[i]
|
||||
const v = this.valList[i]
|
||||
const value = this.isBackgroundFetch(v) ? v.__staleWhileFetching : v
|
||||
const value = this.isBackgroundFetch(v)
|
||||
? v.__staleWhileFetching
|
||||
: v
|
||||
const entry = { value }
|
||||
if (this.ttls) {
|
||||
entry.ttl = this.ttls[i]
|
||||
@@ -569,6 +573,10 @@ class LRUCache {
|
||||
} = {}
|
||||
) {
|
||||
size = this.requireSize(k, v, size, sizeCalculation)
|
||||
// if the item doesn't fit, don't do anything
|
||||
if (this.maxSize && size > this.maxSize) {
|
||||
return this
|
||||
}
|
||||
let index = this.size === 0 ? undefined : this.keyMap.get(k)
|
||||
if (index === undefined) {
|
||||
// addition
|
||||
@@ -580,7 +588,7 @@ class LRUCache {
|
||||
this.prev[index] = this.tail
|
||||
this.tail = index
|
||||
this.size++
|
||||
this.addItemSize(index, v, k, size)
|
||||
this.addItemSize(index, size)
|
||||
noUpdateTTL = false
|
||||
} else {
|
||||
// update
|
||||
@@ -598,7 +606,7 @@ class LRUCache {
|
||||
}
|
||||
this.removeItemSize(index)
|
||||
this.valList[index] = v
|
||||
this.addItemSize(index, v, k, size)
|
||||
this.addItemSize(index, size)
|
||||
}
|
||||
this.moveToTail(index)
|
||||
}
|
||||
@@ -680,7 +688,9 @@ class LRUCache {
|
||||
peek(k, { allowStale = this.allowStale } = {}) {
|
||||
const index = this.keyMap.get(k)
|
||||
if (index !== undefined && (allowStale || !this.isStale(index))) {
|
||||
return this.valList[index]
|
||||
const v = this.valList[index]
|
||||
// either stale and allowed, or forcing a refresh of non-stale value
|
||||
return this.isBackgroundFetch(v) ? v.__staleWhileFetching : v
|
||||
}
|
||||
}
|
||||
|
||||
@@ -763,10 +773,15 @@ class LRUCache {
|
||||
// fetch exclusive options
|
||||
noDeleteOnFetchRejection = this.noDeleteOnFetchRejection,
|
||||
fetchContext = this.fetchContext,
|
||||
forceRefresh = false,
|
||||
} = {}
|
||||
) {
|
||||
if (!this.fetchMethod) {
|
||||
return this.get(k, { allowStale, updateAgeOnGet, noDeleteOnStaleGet })
|
||||
return this.get(k, {
|
||||
allowStale,
|
||||
updateAgeOnGet,
|
||||
noDeleteOnStaleGet,
|
||||
})
|
||||
}
|
||||
|
||||
const options = {
|
||||
@@ -794,7 +809,9 @@ class LRUCache {
|
||||
: (v.__returned = v)
|
||||
}
|
||||
|
||||
if (!this.isStale(index)) {
|
||||
// if we force a refresh, that means do NOT serve the cached value,
|
||||
// unless we are already in the process of refreshing the cache.
|
||||
if (!forceRefresh && !this.isStale(index)) {
|
||||
this.moveToTail(index)
|
||||
if (updateAgeOnGet) {
|
||||
this.updateItemAge(index)
|
||||
@@ -802,7 +819,7 @@ class LRUCache {
|
||||
return v
|
||||
}
|
||||
|
||||
// ok, it is stale, and not already fetching
|
||||
// ok, it is stale or a forced refresh, and not already fetching.
|
||||
// refresh the cache.
|
||||
const p = this.backgroundFetch(k, index, options, fetchContext)
|
||||
return allowStale && p.__staleWhileFetching !== undefined
|
||||
|
||||
+3
-2
@@ -1,13 +1,14 @@
|
||||
{
|
||||
"name": "lru-cache",
|
||||
"description": "A cache object that deletes the least-recently-used items.",
|
||||
"version": "7.12.0",
|
||||
"version": "7.13.2",
|
||||
"author": "Isaac Z. Schlueter <i@izs.me>",
|
||||
"keywords": [
|
||||
"mru",
|
||||
"lru",
|
||||
"cache"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"build": "",
|
||||
"size": "size-limit",
|
||||
@@ -26,7 +27,7 @@
|
||||
"@types/tap": "^15.0.6",
|
||||
"benchmark": "^2.1.4",
|
||||
"c8": "^7.11.2",
|
||||
"clock-mock": "^1.0.4",
|
||||
"clock-mock": "^1.0.6",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"prettier": "^2.6.2",
|
||||
"size-limit": "^7.0.8",
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ name: release-please
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
|
||||
jobs:
|
||||
release-please:
|
||||
|
||||
+16
-9
@@ -1,45 +1,52 @@
|
||||
# TODO: Line 43, enable pytest --doctest-modules
|
||||
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
|
||||
# TODO: Line 48, enable pytest --doctest-modules
|
||||
|
||||
name: Tests
|
||||
on: [push, pull_request]
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
jobs:
|
||||
Tests:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 15
|
||||
matrix:
|
||||
node: [12.x, 14.x, 16.x]
|
||||
node: [14.x, 16.x, 18.x]
|
||||
python: ["3.6", "3.8", "3.10"]
|
||||
os: [macos-latest, ubuntu-latest, windows-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: Use Node.js ${{ matrix.node }}
|
||||
uses: actions/setup-node@v2
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node }}
|
||||
- name: Use Python ${{ matrix.python }}
|
||||
uses: actions/setup-python@v2
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: ${{ matrix.python }}
|
||||
env:
|
||||
PYTHON_VERSION: ${{ matrix.python }}
|
||||
PYTHON_VERSION: ${{ matrix.python }} # Why do this?
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
npm install --no-progress
|
||||
pip install flake8 pytest
|
||||
- name: Set Windows environment
|
||||
if: matrix.os == 'windows-latest'
|
||||
if: startsWith(matrix.os, 'windows')
|
||||
run: |
|
||||
echo 'GYP_MSVS_VERSION=2015' >> $Env:GITHUB_ENV
|
||||
echo 'GYP_MSVS_OVERRIDE_PATH=C:\\Dummy' >> $Env:GITHUB_ENV
|
||||
- name: Lint Python
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
if: startsWith(matrix.os, 'ubuntu')
|
||||
run: flake8 . --ignore=E203,W503 --max-complexity=101 --max-line-length=88 --show-source --statistics
|
||||
- name: Run Python tests
|
||||
run: python -m pytest
|
||||
# - name: Run doctests with pytest
|
||||
# run: python -m pytest --doctest-modules
|
||||
- name: Environment Information
|
||||
run: npx envinfo
|
||||
- name: Run Node tests
|
||||
run: npm test
|
||||
+16
-8
@@ -1,23 +1,31 @@
|
||||
name: Tests on Windows
|
||||
on: [push, pull_request]
|
||||
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
|
||||
|
||||
name: visual-studio
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
jobs:
|
||||
Tests:
|
||||
visual-studio:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 15
|
||||
max-parallel: 8
|
||||
matrix:
|
||||
os: [windows-2022]
|
||||
os: [windows-latest]
|
||||
msvs-version: [2016, 2019, 2022] # https://github.com/actions/virtual-environments/tree/main/images/win
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v3
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
npm install --no-progress
|
||||
# npm audit fix --force
|
||||
- name: Set Windows environment
|
||||
if: matrix.os == 'windows-latest'
|
||||
if: startsWith(matrix.os, 'windows')
|
||||
run: |
|
||||
echo 'GYP_MSVS_VERSION=2015' >> $Env:GITHUB_ENV
|
||||
echo 'GYP_MSVS_VERSION=${{ matrix.msvs-version }}' >> $Env:GITHUB_ENV
|
||||
echo 'GYP_MSVS_OVERRIDE_PATH=C:\\Dummy' >> $Env:GITHUB_ENV
|
||||
- name: Environment Information
|
||||
run: npx envinfo
|
||||
|
||||
+32
@@ -1,5 +1,37 @@
|
||||
# Changelog
|
||||
|
||||
## [9.1.0](https://www.github.com/nodejs/node-gyp/compare/v9.0.0...v9.1.0) (2022-07-13)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Update function getSDK() to support Windows 11 SDK ([#2565](https://www.github.com/nodejs/node-gyp/issues/2565)) ([ea8520e](https://www.github.com/nodejs/node-gyp/commit/ea8520e3855374bd15b6d001fe112d58a8d7d737))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* extend tap timeout length to allow for slow CI ([6f74c76](https://www.github.com/nodejs/node-gyp/commit/6f74c762fe3c19bdd20245cb5c02e2dfa65d9451))
|
||||
* new ca & server certs, bundle in .js file and unpack for testing ([147e3d3](https://www.github.com/nodejs/node-gyp/commit/147e3d34f44a97deb7aa507207680cf0f4e662a2))
|
||||
* re-label ([#2689](https://www.github.com/nodejs/node-gyp/issues/2689)) ([f0b7863](https://www.github.com/nodejs/node-gyp/commit/f0b7863dadfa365afc173025ae95351aec79abd9))
|
||||
* typo on readme ([bf81cd4](https://www.github.com/nodejs/node-gyp/commit/bf81cd452b931dd4dfa82762c23dd530a075d992))
|
||||
|
||||
|
||||
### Doc
|
||||
|
||||
* update docs/README.md with latest version number ([62d2815](https://www.github.com/nodejs/node-gyp/commit/62d28151bf8266a34e1bcceeb25b4e6e2ae5ca5d))
|
||||
|
||||
|
||||
### Core
|
||||
|
||||
* update due to rename of primary branch ([ca1f068](https://www.github.com/nodejs/node-gyp/commit/ca1f0681a5567ca8cd51acebccd37a633f19bc6a))
|
||||
|
||||
|
||||
### Tests
|
||||
|
||||
* Try msvs-version: [2016, 2019, 2022] ([#2700](https://www.github.com/nodejs/node-gyp/issues/2700)) ([68b5b5b](https://www.github.com/nodejs/node-gyp/commit/68b5b5be9c94ac20c55e88654ff6f55234d7130a))
|
||||
* Upgrade GitHub Actions ([#2623](https://www.github.com/nodejs/node-gyp/issues/2623)) ([245cd5b](https://www.github.com/nodejs/node-gyp/commit/245cd5bbe4441d4f05e88f2fa20a86425419b6af))
|
||||
* Upgrade GitHub Actions ([#2701](https://www.github.com/nodejs/node-gyp/issues/2701)) ([1c64ca7](https://www.github.com/nodejs/node-gyp/commit/1c64ca7f4702c6eb43ecd16fbd67b5d939041621))
|
||||
|
||||
## [9.0.0](https://www.github.com/nodejs/node-gyp/compare/v8.4.1...v9.0.0) (2022-02-24)
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -37,7 +37,7 @@ Depending on your operating system, you will need to install:
|
||||
|
||||
### On macOS
|
||||
|
||||
**ATTENTION**: If your Mac has been _upgraded_ to macOS Catalina (10.15), please read [macOS_Catalina.md](macOS_Catalina.md).
|
||||
**ATTENTION**: If your Mac has been _upgraded_ to macOS Catalina (10.15) or higher, please read [macOS_Catalina.md](macOS_Catalina.md).
|
||||
|
||||
* Python v3.7, v3.8, v3.9, or v3.10
|
||||
* `XCode Command Line Tools` which will install `clang`, `clang++`, and `make`.
|
||||
@@ -89,7 +89,7 @@ searching will be done.
|
||||
|
||||
### Build for Third Party Node.js Runtimes
|
||||
|
||||
When building modules for thid party Node.js runtimes like Electron, which have
|
||||
When building modules for third party Node.js runtimes like Electron, which have
|
||||
different build configurations from the official Node.js distribution, you
|
||||
should use `--dist-url` or `--nodedir` flags to specify the headers of the
|
||||
runtime to build for.
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
## Versions of `node-gyp` that are earlier than v8.x.x
|
||||
## Versions of `node-gyp` that are earlier than v9.x.x
|
||||
|
||||
Please look thru your error log for the string `gyp info using node-gyp@` and if that version number is less than the [current release of node-gyp](https://github.com/nodejs/node-gyp/releases) then __please upgrade__ using [these instructions](https://github.com/nodejs/node-gyp/blob/master/docs/Updating-npm-bundled-node-gyp.md) and then try your command again.
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
|
||||
**Note: These instructions will be undone if you reinstall or upgrade npm or node! For a more permanent (and simpler) solution, see [Force-npm-to-use-global-node-gyp.md](Force-npm-to-use-global-node-gyp.md). (npm 6 or older only!)**
|
||||
|
||||
[Many issues](https://github.com/nodejs/node-gyp/labels/ERR%21%20node-gyp%20-v%20%3C%3D%20v5.1.0) are opened by users who are
|
||||
[Many issues](https://github.com/nodejs/node-gyp/issues?q=label%3A"ERR!+node-gyp+-v+<%3D+v9.x.x") are opened by users who are
|
||||
not running a [current version of node-gyp](https://github.com/nodejs/node-gyp/releases).
|
||||
|
||||
`npm` bundles its own, internal, copy of `node-gyp`. This internal copy is independent of any globally installed copy of node-gyp that
|
||||
|
||||
+7
@@ -185,6 +185,13 @@ function build (gyp, argv, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!win) {
|
||||
// Add build-time dependency symlinks (such as Python) to PATH
|
||||
const buildBinsDir = path.resolve('build', 'node_gyp_bins')
|
||||
process.env.PATH = `${buildBinsDir}:${process.env.PATH}`
|
||||
log.verbose('bin symlinks', `adding symlinks (such as Python), at "${buildBinsDir}", to PATH`)
|
||||
}
|
||||
|
||||
var proc = gyp.spawn(command, argv)
|
||||
proc.on('exit', onExit)
|
||||
}
|
||||
|
||||
+24
-1
@@ -17,6 +17,7 @@ if (win) {
|
||||
function configure (gyp, argv, callback) {
|
||||
var python
|
||||
var buildDir = path.resolve('build')
|
||||
var buildBinsDir = path.join(buildDir, 'node_gyp_bins')
|
||||
var configNames = ['config.gypi', 'common.gypi']
|
||||
var configs = []
|
||||
var nodeDir
|
||||
@@ -73,7 +74,9 @@ function configure (gyp, argv, callback) {
|
||||
|
||||
function createBuildDir () {
|
||||
log.verbose('build dir', 'attempting to create "build" dir: %s', buildDir)
|
||||
fs.mkdir(buildDir, { recursive: true }, function (err, isNew) {
|
||||
|
||||
const deepestBuildDirSubdirectory = win ? buildDir : buildBinsDir
|
||||
fs.mkdir(deepestBuildDirSubdirectory, { recursive: true }, function (err, isNew) {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
}
|
||||
@@ -84,11 +87,31 @@ function configure (gyp, argv, callback) {
|
||||
findVisualStudio(release.semver, gyp.opts.msvs_version,
|
||||
createConfigFile)
|
||||
} else {
|
||||
createPythonSymlink()
|
||||
createConfigFile()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function createPythonSymlink () {
|
||||
const symlinkDestination = path.join(buildBinsDir, 'python3')
|
||||
|
||||
log.verbose('python symlink', `creating symlink to "${python}" at "${symlinkDestination}"`)
|
||||
|
||||
fs.unlink(symlinkDestination, function (err) {
|
||||
if (err && err.code !== 'ENOENT') {
|
||||
log.verbose('python symlink', 'error when attempting to remove existing symlink')
|
||||
log.verbose('python symlink', err.stack, 'errno: ' + err.errno)
|
||||
}
|
||||
fs.symlink(python, symlinkDestination, function (err) {
|
||||
if (err) {
|
||||
log.verbose('python symlink', 'error when attempting to create Python symlink')
|
||||
log.verbose('python symlink', err.stack, 'errno: ' + err.errno)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function createConfigFile (err, vsInfo) {
|
||||
if (err) {
|
||||
return callback(err)
|
||||
|
||||
+9
-8
@@ -314,29 +314,30 @@ VisualStudioFinder.prototype = {
|
||||
getSDK: function getSDK (info) {
|
||||
const win8SDK = 'Microsoft.VisualStudio.Component.Windows81SDK'
|
||||
const win10SDKPrefix = 'Microsoft.VisualStudio.Component.Windows10SDK.'
|
||||
const win11SDKPrefix = 'Microsoft.VisualStudio.Component.Windows11SDK.'
|
||||
|
||||
var Win10SDKVer = 0
|
||||
var Win10or11SDKVer = 0
|
||||
info.packages.forEach((pkg) => {
|
||||
if (!pkg.startsWith(win10SDKPrefix)) {
|
||||
if (!pkg.startsWith(win10SDKPrefix) && !pkg.startsWith(win11SDKPrefix)) {
|
||||
return
|
||||
}
|
||||
const parts = pkg.split('.')
|
||||
if (parts.length > 5 && parts[5] !== 'Desktop') {
|
||||
this.log.silly('- ignoring non-Desktop Win10SDK:', pkg)
|
||||
this.log.silly('- ignoring non-Desktop Win10/11SDK:', pkg)
|
||||
return
|
||||
}
|
||||
const foundSdkVer = parseInt(parts[4], 10)
|
||||
if (isNaN(foundSdkVer)) {
|
||||
// Microsoft.VisualStudio.Component.Windows10SDK.IpOverUsb
|
||||
this.log.silly('- failed to parse Win10SDK number:', pkg)
|
||||
this.log.silly('- failed to parse Win10/11SDK number:', pkg)
|
||||
return
|
||||
}
|
||||
this.log.silly('- found Win10SDK:', foundSdkVer)
|
||||
Win10SDKVer = Math.max(Win10SDKVer, foundSdkVer)
|
||||
this.log.silly('- found Win10/11SDK:', foundSdkVer)
|
||||
Win10or11SDKVer = Math.max(Win10or11SDKVer, foundSdkVer)
|
||||
})
|
||||
|
||||
if (Win10SDKVer !== 0) {
|
||||
return `10.0.${Win10SDKVer}.0`
|
||||
if (Win10or11SDKVer !== 0) {
|
||||
return `10.0.${Win10or11SDKVer}.0`
|
||||
} else if (info.packages.indexOf(win8SDK) !== -1) {
|
||||
this.log.silly('- found Win8SDK')
|
||||
return '8.1'
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ If `ProductVersion` is less then `10.15` then this document is not for you. Norm
|
||||
### The acid test
|
||||
To see if `Xcode Command Line Tools` is installed in a way that will work with `node-gyp`, run:
|
||||
```
|
||||
curl -sL https://github.com/nodejs/node-gyp/raw/master/macOS_Catalina_acid_test.sh | bash
|
||||
curl -sL https://github.com/nodejs/node-gyp/raw/main/macOS_Catalina_acid_test.sh | bash
|
||||
```
|
||||
|
||||
If test succeeded, _you are done_! You should be ready to [install](https://github.com/nodejs/node-gyp#installation) `node-gyp`.
|
||||
|
||||
Generated
Vendored
File renamed without changes.
+15
@@ -0,0 +1,15 @@
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
+213
@@ -0,0 +1,213 @@
|
||||
If you want to write an option parser, and have it be good, there are
|
||||
two ways to do it. The Right Way, and the Wrong Way.
|
||||
|
||||
The Wrong Way is to sit down and write an option parser. We've all done
|
||||
that.
|
||||
|
||||
The Right Way is to write some complex configurable program with so many
|
||||
options that you hit the limit of your frustration just trying to
|
||||
manage them all, and defer it with duct-tape solutions until you see
|
||||
exactly to the core of the problem, and finally snap and write an
|
||||
awesome option parser.
|
||||
|
||||
If you want to write an option parser, don't write an option parser.
|
||||
Write a package manager, or a source control system, or a service
|
||||
restarter, or an operating system. You probably won't end up with a
|
||||
good one of those, but if you don't give up, and you are relentless and
|
||||
diligent enough in your procrastination, you may just end up with a very
|
||||
nice option parser.
|
||||
|
||||
## USAGE
|
||||
|
||||
```javascript
|
||||
// my-program.js
|
||||
var nopt = require("nopt")
|
||||
, Stream = require("stream").Stream
|
||||
, path = require("path")
|
||||
, knownOpts = { "foo" : [String, null]
|
||||
, "bar" : [Stream, Number]
|
||||
, "baz" : path
|
||||
, "bloo" : [ "big", "medium", "small" ]
|
||||
, "flag" : Boolean
|
||||
, "pick" : Boolean
|
||||
, "many1" : [String, Array]
|
||||
, "many2" : [path, Array]
|
||||
}
|
||||
, shortHands = { "foofoo" : ["--foo", "Mr. Foo"]
|
||||
, "b7" : ["--bar", "7"]
|
||||
, "m" : ["--bloo", "medium"]
|
||||
, "p" : ["--pick"]
|
||||
, "f" : ["--flag"]
|
||||
}
|
||||
// everything is optional.
|
||||
// knownOpts and shorthands default to {}
|
||||
// arg list defaults to process.argv
|
||||
// slice defaults to 2
|
||||
, parsed = nopt(knownOpts, shortHands, process.argv, 2)
|
||||
console.log(parsed)
|
||||
```
|
||||
|
||||
This would give you support for any of the following:
|
||||
|
||||
```console
|
||||
$ node my-program.js --foo "blerp" --no-flag
|
||||
{ "foo" : "blerp", "flag" : false }
|
||||
|
||||
$ node my-program.js ---bar 7 --foo "Mr. Hand" --flag
|
||||
{ bar: 7, foo: "Mr. Hand", flag: true }
|
||||
|
||||
$ node my-program.js --foo "blerp" -f -----p
|
||||
{ foo: "blerp", flag: true, pick: true }
|
||||
|
||||
$ node my-program.js -fp --foofoo
|
||||
{ foo: "Mr. Foo", flag: true, pick: true }
|
||||
|
||||
$ node my-program.js --foofoo -- -fp # -- stops the flag parsing.
|
||||
{ foo: "Mr. Foo", argv: { remain: ["-fp"] } }
|
||||
|
||||
$ node my-program.js --blatzk -fp # unknown opts are ok.
|
||||
{ blatzk: true, flag: true, pick: true }
|
||||
|
||||
$ node my-program.js --blatzk=1000 -fp # but you need to use = if they have a value
|
||||
{ blatzk: 1000, flag: true, pick: true }
|
||||
|
||||
$ node my-program.js --no-blatzk -fp # unless they start with "no-"
|
||||
{ blatzk: false, flag: true, pick: true }
|
||||
|
||||
$ node my-program.js --baz b/a/z # known paths are resolved.
|
||||
{ baz: "/Users/isaacs/b/a/z" }
|
||||
|
||||
# if Array is one of the types, then it can take many
|
||||
# values, and will always be an array. The other types provided
|
||||
# specify what types are allowed in the list.
|
||||
|
||||
$ node my-program.js --many1 5 --many1 null --many1 foo
|
||||
{ many1: ["5", "null", "foo"] }
|
||||
|
||||
$ node my-program.js --many2 foo --many2 bar
|
||||
{ many2: ["/path/to/foo", "path/to/bar"] }
|
||||
```
|
||||
|
||||
Read the tests at the bottom of `lib/nopt.js` for more examples of
|
||||
what this puppy can do.
|
||||
|
||||
## Types
|
||||
|
||||
The following types are supported, and defined on `nopt.typeDefs`
|
||||
|
||||
* String: A normal string. No parsing is done.
|
||||
* path: A file system path. Gets resolved against cwd if not absolute.
|
||||
* url: A url. If it doesn't parse, it isn't accepted.
|
||||
* Number: Must be numeric.
|
||||
* Date: Must parse as a date. If it does, and `Date` is one of the options,
|
||||
then it will return a Date object, not a string.
|
||||
* Boolean: Must be either `true` or `false`. If an option is a boolean,
|
||||
then it does not need a value, and its presence will imply `true` as
|
||||
the value. To negate boolean flags, do `--no-whatever` or `--whatever
|
||||
false`
|
||||
* NaN: Means that the option is strictly not allowed. Any value will
|
||||
fail.
|
||||
* Stream: An object matching the "Stream" class in node. Valuable
|
||||
for use when validating programmatically. (npm uses this to let you
|
||||
supply any WriteStream on the `outfd` and `logfd` config options.)
|
||||
* Array: If `Array` is specified as one of the types, then the value
|
||||
will be parsed as a list of options. This means that multiple values
|
||||
can be specified, and that the value will always be an array.
|
||||
|
||||
If a type is an array of values not on this list, then those are
|
||||
considered valid values. For instance, in the example above, the
|
||||
`--bloo` option can only be one of `"big"`, `"medium"`, or `"small"`,
|
||||
and any other value will be rejected.
|
||||
|
||||
When parsing unknown fields, `"true"`, `"false"`, and `"null"` will be
|
||||
interpreted as their JavaScript equivalents.
|
||||
|
||||
You can also mix types and values, or multiple types, in a list. For
|
||||
instance `{ blah: [Number, null] }` would allow a value to be set to
|
||||
either a Number or null. When types are ordered, this implies a
|
||||
preference, and the first type that can be used to properly interpret
|
||||
the value will be used.
|
||||
|
||||
To define a new type, add it to `nopt.typeDefs`. Each item in that
|
||||
hash is an object with a `type` member and a `validate` method. The
|
||||
`type` member is an object that matches what goes in the type list. The
|
||||
`validate` method is a function that gets called with `validate(data,
|
||||
key, val)`. Validate methods should assign `data[key]` to the valid
|
||||
value of `val` if it can be handled properly, or return boolean
|
||||
`false` if it cannot.
|
||||
|
||||
You can also call `nopt.clean(data, types, typeDefs)` to clean up a
|
||||
config object and remove its invalid properties.
|
||||
|
||||
## Error Handling
|
||||
|
||||
By default, nopt outputs a warning to standard error when invalid values for
|
||||
known options are found. You can change this behavior by assigning a method
|
||||
to `nopt.invalidHandler`. This method will be called with
|
||||
the offending `nopt.invalidHandler(key, val, types)`.
|
||||
|
||||
If no `nopt.invalidHandler` is assigned, then it will console.error
|
||||
its whining. If it is assigned to boolean `false` then the warning is
|
||||
suppressed.
|
||||
|
||||
## Abbreviations
|
||||
|
||||
Yes, they are supported. If you define options like this:
|
||||
|
||||
```javascript
|
||||
{ "foolhardyelephants" : Boolean
|
||||
, "pileofmonkeys" : Boolean }
|
||||
```
|
||||
|
||||
Then this will work:
|
||||
|
||||
```bash
|
||||
node program.js --foolhar --pil
|
||||
node program.js --no-f --pileofmon
|
||||
# etc.
|
||||
```
|
||||
|
||||
## Shorthands
|
||||
|
||||
Shorthands are a hash of shorter option names to a snippet of args that
|
||||
they expand to.
|
||||
|
||||
If multiple one-character shorthands are all combined, and the
|
||||
combination does not unambiguously match any other option or shorthand,
|
||||
then they will be broken up into their constituent parts. For example:
|
||||
|
||||
```json
|
||||
{ "s" : ["--loglevel", "silent"]
|
||||
, "g" : "--global"
|
||||
, "f" : "--force"
|
||||
, "p" : "--parseable"
|
||||
, "l" : "--long"
|
||||
}
|
||||
```
|
||||
|
||||
```bash
|
||||
npm ls -sgflp
|
||||
# just like doing this:
|
||||
npm ls --loglevel silent --global --force --long --parseable
|
||||
```
|
||||
|
||||
## The Rest of the args
|
||||
|
||||
The config object returned by nopt is given a special member called
|
||||
`argv`, which is an object with the following fields:
|
||||
|
||||
* `remain`: The remaining args after all the parsing has occurred.
|
||||
* `original`: The args as they originally appeared.
|
||||
* `cooked`: The args after flags and shorthands are expanded.
|
||||
|
||||
## Slicing
|
||||
|
||||
Node programs are called with more or less the exact argv as it appears
|
||||
in C land, after the v8 and node-specific options have been plucked off.
|
||||
As such, `argv[0]` is always `node` and `argv[1]` is always the
|
||||
JavaScript program being run.
|
||||
|
||||
That's usually not very useful to you. So they're sliced off by
|
||||
default. If you want them, then you can pass in `0` as the last
|
||||
argument, or any other number that you'd like to slice off the start of
|
||||
the list.
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env node
|
||||
var nopt = require("../lib/nopt")
|
||||
, path = require("path")
|
||||
, types = { num: Number
|
||||
, bool: Boolean
|
||||
, help: Boolean
|
||||
, list: Array
|
||||
, "num-list": [Number, Array]
|
||||
, "str-list": [String, Array]
|
||||
, "bool-list": [Boolean, Array]
|
||||
, str: String
|
||||
, clear: Boolean
|
||||
, config: Boolean
|
||||
, length: Number
|
||||
, file: path
|
||||
}
|
||||
, shorthands = { s: [ "--str", "astring" ]
|
||||
, b: [ "--bool" ]
|
||||
, nb: [ "--no-bool" ]
|
||||
, tft: [ "--bool-list", "--no-bool-list", "--bool-list", "true" ]
|
||||
, "?": ["--help"]
|
||||
, h: ["--help"]
|
||||
, H: ["--help"]
|
||||
, n: [ "--num", "125" ]
|
||||
, c: ["--config"]
|
||||
, l: ["--length"]
|
||||
, f: ["--file"]
|
||||
}
|
||||
, parsed = nopt( types
|
||||
, shorthands
|
||||
, process.argv
|
||||
, 2 )
|
||||
|
||||
console.log("parsed", parsed)
|
||||
|
||||
if (parsed.help) {
|
||||
console.log("")
|
||||
console.log("nopt cli tester")
|
||||
console.log("")
|
||||
console.log("types")
|
||||
console.log(Object.keys(types).map(function M (t) {
|
||||
var type = types[t]
|
||||
if (Array.isArray(type)) {
|
||||
return [t, type.map(function (type) { return type.name })]
|
||||
}
|
||||
return [t, type && type.name]
|
||||
}).reduce(function (s, i) {
|
||||
s[i[0]] = i[1]
|
||||
return s
|
||||
}, {}))
|
||||
console.log("")
|
||||
console.log("shorthands")
|
||||
console.log(shorthands)
|
||||
}
|
||||
+441
@@ -0,0 +1,441 @@
|
||||
// info about each config option.
|
||||
|
||||
var debug = process.env.DEBUG_NOPT || process.env.NOPT_DEBUG
|
||||
? function () { console.error.apply(console, arguments) }
|
||||
: function () {}
|
||||
|
||||
var url = require("url")
|
||||
, path = require("path")
|
||||
, Stream = require("stream").Stream
|
||||
, abbrev = require("abbrev")
|
||||
, os = require("os")
|
||||
|
||||
module.exports = exports = nopt
|
||||
exports.clean = clean
|
||||
|
||||
exports.typeDefs =
|
||||
{ String : { type: String, validate: validateString }
|
||||
, Boolean : { type: Boolean, validate: validateBoolean }
|
||||
, url : { type: url, validate: validateUrl }
|
||||
, Number : { type: Number, validate: validateNumber }
|
||||
, path : { type: path, validate: validatePath }
|
||||
, Stream : { type: Stream, validate: validateStream }
|
||||
, Date : { type: Date, validate: validateDate }
|
||||
}
|
||||
|
||||
function nopt (types, shorthands, args, slice) {
|
||||
args = args || process.argv
|
||||
types = types || {}
|
||||
shorthands = shorthands || {}
|
||||
if (typeof slice !== "number") slice = 2
|
||||
|
||||
debug(types, shorthands, args, slice)
|
||||
|
||||
args = args.slice(slice)
|
||||
var data = {}
|
||||
, key
|
||||
, argv = {
|
||||
remain: [],
|
||||
cooked: args,
|
||||
original: args.slice(0)
|
||||
}
|
||||
|
||||
parse(args, data, argv.remain, types, shorthands)
|
||||
// now data is full
|
||||
clean(data, types, exports.typeDefs)
|
||||
data.argv = argv
|
||||
Object.defineProperty(data.argv, 'toString', { value: function () {
|
||||
return this.original.map(JSON.stringify).join(" ")
|
||||
}, enumerable: false })
|
||||
return data
|
||||
}
|
||||
|
||||
function clean (data, types, typeDefs) {
|
||||
typeDefs = typeDefs || exports.typeDefs
|
||||
var remove = {}
|
||||
, typeDefault = [false, true, null, String, Array]
|
||||
|
||||
Object.keys(data).forEach(function (k) {
|
||||
if (k === "argv") return
|
||||
var val = data[k]
|
||||
, isArray = Array.isArray(val)
|
||||
, type = types[k]
|
||||
if (!isArray) val = [val]
|
||||
if (!type) type = typeDefault
|
||||
if (type === Array) type = typeDefault.concat(Array)
|
||||
if (!Array.isArray(type)) type = [type]
|
||||
|
||||
debug("val=%j", val)
|
||||
debug("types=", type)
|
||||
val = val.map(function (val) {
|
||||
// if it's an unknown value, then parse false/true/null/numbers/dates
|
||||
if (typeof val === "string") {
|
||||
debug("string %j", val)
|
||||
val = val.trim()
|
||||
if ((val === "null" && ~type.indexOf(null))
|
||||
|| (val === "true" &&
|
||||
(~type.indexOf(true) || ~type.indexOf(Boolean)))
|
||||
|| (val === "false" &&
|
||||
(~type.indexOf(false) || ~type.indexOf(Boolean)))) {
|
||||
val = JSON.parse(val)
|
||||
debug("jsonable %j", val)
|
||||
} else if (~type.indexOf(Number) && !isNaN(val)) {
|
||||
debug("convert to number", val)
|
||||
val = +val
|
||||
} else if (~type.indexOf(Date) && !isNaN(Date.parse(val))) {
|
||||
debug("convert to date", val)
|
||||
val = new Date(val)
|
||||
}
|
||||
}
|
||||
|
||||
if (!types.hasOwnProperty(k)) {
|
||||
return val
|
||||
}
|
||||
|
||||
// allow `--no-blah` to set 'blah' to null if null is allowed
|
||||
if (val === false && ~type.indexOf(null) &&
|
||||
!(~type.indexOf(false) || ~type.indexOf(Boolean))) {
|
||||
val = null
|
||||
}
|
||||
|
||||
var d = {}
|
||||
d[k] = val
|
||||
debug("prevalidated val", d, val, types[k])
|
||||
if (!validate(d, k, val, types[k], typeDefs)) {
|
||||
if (exports.invalidHandler) {
|
||||
exports.invalidHandler(k, val, types[k], data)
|
||||
} else if (exports.invalidHandler !== false) {
|
||||
debug("invalid: "+k+"="+val, types[k])
|
||||
}
|
||||
return remove
|
||||
}
|
||||
debug("validated val", d, val, types[k])
|
||||
return d[k]
|
||||
}).filter(function (val) { return val !== remove })
|
||||
|
||||
// if we allow Array specifically, then an empty array is how we
|
||||
// express 'no value here', not null. Allow it.
|
||||
if (!val.length && type.indexOf(Array) === -1) {
|
||||
debug('VAL HAS NO LENGTH, DELETE IT', val, k, type.indexOf(Array))
|
||||
delete data[k]
|
||||
}
|
||||
else if (isArray) {
|
||||
debug(isArray, data[k], val)
|
||||
data[k] = val
|
||||
} else data[k] = val[0]
|
||||
|
||||
debug("k=%s val=%j", k, val, data[k])
|
||||
})
|
||||
}
|
||||
|
||||
function validateString (data, k, val) {
|
||||
data[k] = String(val)
|
||||
}
|
||||
|
||||
function validatePath (data, k, val) {
|
||||
if (val === true) return false
|
||||
if (val === null) return true
|
||||
|
||||
val = String(val)
|
||||
|
||||
var isWin = process.platform === 'win32'
|
||||
, homePattern = isWin ? /^~(\/|\\)/ : /^~\//
|
||||
, home = os.homedir()
|
||||
|
||||
if (home && val.match(homePattern)) {
|
||||
data[k] = path.resolve(home, val.substr(2))
|
||||
} else {
|
||||
data[k] = path.resolve(val)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function validateNumber (data, k, val) {
|
||||
debug("validate Number %j %j %j", k, val, isNaN(val))
|
||||
if (isNaN(val)) return false
|
||||
data[k] = +val
|
||||
}
|
||||
|
||||
function validateDate (data, k, val) {
|
||||
var s = Date.parse(val)
|
||||
debug("validate Date %j %j %j", k, val, s)
|
||||
if (isNaN(s)) return false
|
||||
data[k] = new Date(val)
|
||||
}
|
||||
|
||||
function validateBoolean (data, k, val) {
|
||||
if (val instanceof Boolean) val = val.valueOf()
|
||||
else if (typeof val === "string") {
|
||||
if (!isNaN(val)) val = !!(+val)
|
||||
else if (val === "null" || val === "false") val = false
|
||||
else val = true
|
||||
} else val = !!val
|
||||
data[k] = val
|
||||
}
|
||||
|
||||
function validateUrl (data, k, val) {
|
||||
val = url.parse(String(val))
|
||||
if (!val.host) return false
|
||||
data[k] = val.href
|
||||
}
|
||||
|
||||
function validateStream (data, k, val) {
|
||||
if (!(val instanceof Stream)) return false
|
||||
data[k] = val
|
||||
}
|
||||
|
||||
function validate (data, k, val, type, typeDefs) {
|
||||
// arrays are lists of types.
|
||||
if (Array.isArray(type)) {
|
||||
for (var i = 0, l = type.length; i < l; i ++) {
|
||||
if (type[i] === Array) continue
|
||||
if (validate(data, k, val, type[i], typeDefs)) return true
|
||||
}
|
||||
delete data[k]
|
||||
return false
|
||||
}
|
||||
|
||||
// an array of anything?
|
||||
if (type === Array) return true
|
||||
|
||||
// NaN is poisonous. Means that something is not allowed.
|
||||
if (type !== type) {
|
||||
debug("Poison NaN", k, val, type)
|
||||
delete data[k]
|
||||
return false
|
||||
}
|
||||
|
||||
// explicit list of values
|
||||
if (val === type) {
|
||||
debug("Explicitly allowed %j", val)
|
||||
// if (isArray) (data[k] = data[k] || []).push(val)
|
||||
// else data[k] = val
|
||||
data[k] = val
|
||||
return true
|
||||
}
|
||||
|
||||
// now go through the list of typeDefs, validate against each one.
|
||||
var ok = false
|
||||
, types = Object.keys(typeDefs)
|
||||
for (var i = 0, l = types.length; i < l; i ++) {
|
||||
debug("test type %j %j %j", k, val, types[i])
|
||||
var t = typeDefs[types[i]]
|
||||
if (t &&
|
||||
((type && type.name && t.type && t.type.name) ? (type.name === t.type.name) : (type === t.type))) {
|
||||
var d = {}
|
||||
ok = false !== t.validate(d, k, val)
|
||||
val = d[k]
|
||||
if (ok) {
|
||||
// if (isArray) (data[k] = data[k] || []).push(val)
|
||||
// else data[k] = val
|
||||
data[k] = val
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
debug("OK? %j (%j %j %j)", ok, k, val, types[i])
|
||||
|
||||
if (!ok) delete data[k]
|
||||
return ok
|
||||
}
|
||||
|
||||
function parse (args, data, remain, types, shorthands) {
|
||||
debug("parse", args, data, remain)
|
||||
|
||||
var key = null
|
||||
, abbrevs = abbrev(Object.keys(types))
|
||||
, shortAbbr = abbrev(Object.keys(shorthands))
|
||||
|
||||
for (var i = 0; i < args.length; i ++) {
|
||||
var arg = args[i]
|
||||
debug("arg", arg)
|
||||
|
||||
if (arg.match(/^-{2,}$/)) {
|
||||
// done with keys.
|
||||
// the rest are args.
|
||||
remain.push.apply(remain, args.slice(i + 1))
|
||||
args[i] = "--"
|
||||
break
|
||||
}
|
||||
var hadEq = false
|
||||
if (arg.charAt(0) === "-" && arg.length > 1) {
|
||||
var at = arg.indexOf('=')
|
||||
if (at > -1) {
|
||||
hadEq = true
|
||||
var v = arg.substr(at + 1)
|
||||
arg = arg.substr(0, at)
|
||||
args.splice(i, 1, arg, v)
|
||||
}
|
||||
|
||||
// see if it's a shorthand
|
||||
// if so, splice and back up to re-parse it.
|
||||
var shRes = resolveShort(arg, shorthands, shortAbbr, abbrevs)
|
||||
debug("arg=%j shRes=%j", arg, shRes)
|
||||
if (shRes) {
|
||||
debug(arg, shRes)
|
||||
args.splice.apply(args, [i, 1].concat(shRes))
|
||||
if (arg !== shRes[0]) {
|
||||
i --
|
||||
continue
|
||||
}
|
||||
}
|
||||
arg = arg.replace(/^-+/, "")
|
||||
var no = null
|
||||
while (arg.toLowerCase().indexOf("no-") === 0) {
|
||||
no = !no
|
||||
arg = arg.substr(3)
|
||||
}
|
||||
|
||||
if (abbrevs[arg]) arg = abbrevs[arg]
|
||||
|
||||
var argType = types[arg]
|
||||
var isTypeArray = Array.isArray(argType)
|
||||
if (isTypeArray && argType.length === 1) {
|
||||
isTypeArray = false
|
||||
argType = argType[0]
|
||||
}
|
||||
|
||||
var isArray = argType === Array ||
|
||||
isTypeArray && argType.indexOf(Array) !== -1
|
||||
|
||||
// allow unknown things to be arrays if specified multiple times.
|
||||
if (!types.hasOwnProperty(arg) && data.hasOwnProperty(arg)) {
|
||||
if (!Array.isArray(data[arg]))
|
||||
data[arg] = [data[arg]]
|
||||
isArray = true
|
||||
}
|
||||
|
||||
var val
|
||||
, la = args[i + 1]
|
||||
|
||||
var isBool = typeof no === 'boolean' ||
|
||||
argType === Boolean ||
|
||||
isTypeArray && argType.indexOf(Boolean) !== -1 ||
|
||||
(typeof argType === 'undefined' && !hadEq) ||
|
||||
(la === "false" &&
|
||||
(argType === null ||
|
||||
isTypeArray && ~argType.indexOf(null)))
|
||||
|
||||
if (isBool) {
|
||||
// just set and move along
|
||||
val = !no
|
||||
// however, also support --bool true or --bool false
|
||||
if (la === "true" || la === "false") {
|
||||
val = JSON.parse(la)
|
||||
la = null
|
||||
if (no) val = !val
|
||||
i ++
|
||||
}
|
||||
|
||||
// also support "foo":[Boolean, "bar"] and "--foo bar"
|
||||
if (isTypeArray && la) {
|
||||
if (~argType.indexOf(la)) {
|
||||
// an explicit type
|
||||
val = la
|
||||
i ++
|
||||
} else if ( la === "null" && ~argType.indexOf(null) ) {
|
||||
// null allowed
|
||||
val = null
|
||||
i ++
|
||||
} else if ( !la.match(/^-{2,}[^-]/) &&
|
||||
!isNaN(la) &&
|
||||
~argType.indexOf(Number) ) {
|
||||
// number
|
||||
val = +la
|
||||
i ++
|
||||
} else if ( !la.match(/^-[^-]/) && ~argType.indexOf(String) ) {
|
||||
// string
|
||||
val = la
|
||||
i ++
|
||||
}
|
||||
}
|
||||
|
||||
if (isArray) (data[arg] = data[arg] || []).push(val)
|
||||
else data[arg] = val
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if (argType === String) {
|
||||
if (la === undefined) {
|
||||
la = ""
|
||||
} else if (la.match(/^-{1,2}[^-]+/)) {
|
||||
la = ""
|
||||
i --
|
||||
}
|
||||
}
|
||||
|
||||
if (la && la.match(/^-{2,}$/)) {
|
||||
la = undefined
|
||||
i --
|
||||
}
|
||||
|
||||
val = la === undefined ? true : la
|
||||
if (isArray) (data[arg] = data[arg] || []).push(val)
|
||||
else data[arg] = val
|
||||
|
||||
i ++
|
||||
continue
|
||||
}
|
||||
remain.push(arg)
|
||||
}
|
||||
}
|
||||
|
||||
function resolveShort (arg, shorthands, shortAbbr, abbrevs) {
|
||||
// handle single-char shorthands glommed together, like
|
||||
// npm ls -glp, but only if there is one dash, and only if
|
||||
// all of the chars are single-char shorthands, and it's
|
||||
// not a match to some other abbrev.
|
||||
arg = arg.replace(/^-+/, '')
|
||||
|
||||
// if it's an exact known option, then don't go any further
|
||||
if (abbrevs[arg] === arg)
|
||||
return null
|
||||
|
||||
// if it's an exact known shortopt, same deal
|
||||
if (shorthands[arg]) {
|
||||
// make it an array, if it's a list of words
|
||||
if (shorthands[arg] && !Array.isArray(shorthands[arg]))
|
||||
shorthands[arg] = shorthands[arg].split(/\s+/)
|
||||
|
||||
return shorthands[arg]
|
||||
}
|
||||
|
||||
// first check to see if this arg is a set of single-char shorthands
|
||||
var singles = shorthands.___singles
|
||||
if (!singles) {
|
||||
singles = Object.keys(shorthands).filter(function (s) {
|
||||
return s.length === 1
|
||||
}).reduce(function (l,r) {
|
||||
l[r] = true
|
||||
return l
|
||||
}, {})
|
||||
shorthands.___singles = singles
|
||||
debug('shorthand singles', singles)
|
||||
}
|
||||
|
||||
var chrs = arg.split("").filter(function (c) {
|
||||
return singles[c]
|
||||
})
|
||||
|
||||
if (chrs.join("") === arg) return chrs.map(function (c) {
|
||||
return shorthands[c]
|
||||
}).reduce(function (l, r) {
|
||||
return l.concat(r)
|
||||
}, [])
|
||||
|
||||
|
||||
// if it's an arg abbrev, and not a literal shorthand, then prefer the arg
|
||||
if (abbrevs[arg] && !shorthands[arg])
|
||||
return null
|
||||
|
||||
// if it's an abbr for a shorthand, then use that
|
||||
if (shortAbbr[arg])
|
||||
arg = shortAbbr[arg]
|
||||
|
||||
// make it an array, if it's a list of words
|
||||
if (shorthands[arg] && !Array.isArray(shorthands[arg]))
|
||||
shorthands[arg] = shorthands[arg].split(/\s+/)
|
||||
|
||||
return shorthands[arg]
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "nopt",
|
||||
"version": "5.0.0",
|
||||
"description": "Option parsing for Node, supporting types, shorthands, etc. Used by npm.",
|
||||
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
|
||||
"main": "lib/nopt.js",
|
||||
"scripts": {
|
||||
"preversion": "npm test",
|
||||
"postversion": "npm publish",
|
||||
"prepublishOnly": "git push origin --follow-tags",
|
||||
"test": "tap test/*.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/npm/nopt.git"
|
||||
},
|
||||
"bin": {
|
||||
"nopt": "bin/nopt.js"
|
||||
},
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"abbrev": "1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tap": "^14.10.6"
|
||||
},
|
||||
"files": [
|
||||
"bin",
|
||||
"lib"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -11,7 +11,7 @@
|
||||
"bindings",
|
||||
"gyp"
|
||||
],
|
||||
"version": "9.0.0",
|
||||
"version": "9.1.0",
|
||||
"installVersion": 9,
|
||||
"author": "Nathan Rajlich <nathan@tootallnate.net> (http://tootallnate.net)",
|
||||
"repository": {
|
||||
@@ -45,6 +45,6 @@
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "standard */*.js test/**/*.js",
|
||||
"test": "npm run lint && tap --timeout=120 test/test-*"
|
||||
"test": "npm run lint && tap --timeout=600 test/test-*"
|
||||
}
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
-----BEGIN CERTIFIC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N2o8YTWsCefSRl6ti4ToPZqulU4hhRKYrEGtMJcRzi3IN7s200JaO3UH
|
||||
01Su8ruO0NESb5zEU1Ykfh8Lub8TGEAINmgI61d/5d5Aq3kDjUHQJt1Ekw03Ylnu
|
||||
juQyCGZxLxnngu0mIvwzyL/UeeUgsfQLzvppUk6In7tC1zzMjSPWo0c8qu6KvrW4
|
||||
bKYnkZkzdQifzbpO5ERMEsh5HWq0uHa6+dgcVHFvlhdqF4Uat87ygNplVf0txsZB
|
||||
MNVqbz1k6xkZYMnzDoydAgMBAAEwDQYJKoZIhvcNAQELBQADggEBADspZGtKpWxy
|
||||
J1W3FA1aeQhMvequQTcMRz4avkm4K4HfTdV1iVD4CbvdezBphouBlyLVLDFJP7RZ
|
||||
m7dBJVgBwnxufoFLne8cR2MGqDRoySbFT1AtDJdxabE6Fg+QGUpgOQfeBJ6ANlSB
|
||||
+qJ+HG4QA+Ouh5hxz9mgYwkIsMUABHiwENdZ/kT8Edw4xKgd3uH0YP4iiePMD66c
|
||||
rzW3uXH5J1jnKgBlpxtog4P6dHCcoq+PZJ17W5bdXNyqC1LPzQqniZ2BNcEZ4ix3
|
||||
slAZAOWD1zLLGJhBPMV1fa0sHNBWc6oicr3YK/IDb0cp9kiLvnUu1pHy+LWQGqtC
|
||||
rceJuGsnJEQ=
|
||||
-----END CERTIFICATE-----
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
module.exports['ca.key'] = `
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEowIBAAKCAQEAtTbG0k2UFUyCdZuip0TTEtXRHh57qosegrpHPBreSNTxt7OT
|
||||
KfOUZp2rToTHeN9w0ZbV2eKRI5AuFx8Cmlm73/KIHKzSNTBATGMeeHnGaxvL/W/s
|
||||
KJdTDRNf7/qCXHQ+gsuEWWCFzOZuHmmAQa2IBX2HAQTqXJI8+2iJ9gytFfJLxjqy
|
||||
6O4u9ugZVHSyQJWs49tGRcWMlNm7EMStADFvJn3S11xe/kwIA2mSI/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noeQWcQKBgQCVBCuQZu5SSM/zTkTTnU0sy0lf1qflI9IMD92B
|
||||
+JVqg8HDnAR0KF+x38a9MVP7ixgXCuy19t+XxfY269HmLjTlArWV671D4GCSPRGy
|
||||
plwZ6nr72ieCo3y57+q94jxL3jh3+bozlpnUG/q6tTKBLGs7JDjsWDSsuxOu8tO6
|
||||
RBttXQKBgB6LQFOTjDMfsFHKsnQXFUZId3GG/iLg3WCWxEo88T5Rq3JIR0zDpW8H
|
||||
cKhl/sPY+JVHsxizNCMPtp7Hn7GrB6D/v9LbO0jpG2U0BFiJ6zhiDopbP9B0EAW4
|
||||
5JJ+JGKRKoCxs3DmSVyns0gU4j4rVte97UWyVy5TZ8Acr/qrgOA1
|
||||
-----END RSA PRIVATE KEY-----
|
||||
`
|
||||
|
||||
module.exports['ca.crt'] = `
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDmzCCAoOgAwIBAgIUDA0GrvcnG41XT6LYFeNwvq8YV1UwDQYJKoZIhvcNAQEL
|
||||
BQAwXTELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRAwDgYDVQQKDAdOb2RlLmpz
|
||||
MREwDwYDVQQLDAhub2RlLWd5cDEcMBoGA1UEAwwTbm9kZS1neXAubm9kZWpzLm9y
|
||||
ZzAeFw0yMjA1MTEwNDIyMjRaFw00OTA5MjUwNDIyMjRaMF0xCzAJBgNVBAYTAlVT
|
||||
MQswCQYDVQQIDAJDQTEQMA4GA1UECgwHTm9kZS5qczERMA8GA1UECwwIbm9kZS1n
|
||||
eXAxHDAaBgNVBAMME25vZGUtZ3lwLm5vZGVqcy5vcmcwggEiMA0GCSqGSIb3DQEB
|
||||
AQUAA4IBDwAwggEKAoIBAQC1NsbSTZQVTIJ1m6KnRNMS1dEeHnuqix6Cukc8Gt5I
|
||||
1PG3s5Mp85RmnatOhMd433DRltXZ4pEjkC4XHwKaWbvf8ogcrNI1MEBMYx54ecZr
|
||||
G8v9b+wol1MNE1/v+oJcdD6Cy4RZYIXM5m4eaYBBrYgFfYcBBOpckjz7aIn2DK0V
|
||||
8kvGOrLo7i726BlUdLJAlazj20ZFxYyU2bsQxK0AMW8mfdLXXF7+TAgDaZIj9510
|
||||
OfMvQzECRH11AEvrrE4AEsvm/dBB2GKl8eW5foctsN3/ViwVO46mC8tGWvvatMAW
|
||||
tBkKiRWFc+Kqy2fnMkVblqsdqS8xHT449ogIXl96H/ipAgMBAAGjUzBRMB0GA1Ud
|
||||
DgQWBBT6LcYYABEOAMv4hI/5bC82rGlD/DAfBgNVHSMEGDAWgBT6LcYYABEOAMv4
|
||||
hI/5bC82rGlD/DAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQA9
|
||||
D+qoKw0njub+NaFRS2DFbSiKb5JKTxVjU5aNusFONFLSXBuRpnYyjjkXpJy8JMWz
|
||||
g8GFDEPP6kiSb8xaPNrFcUzb4PFzJabNTuaLJpBpd2gNBj5AeYwwpRa2DPv/b4yw
|
||||
y2mfULuCWS09ZAguI2OcaARlAsFxYN0IuQ6pN1AvGFGee67ve9l2VF/hhwEi4lCk
|
||||
MM0CWlP6COJ8TX7X0MTtexVOgo9m3hBuTSYEZClYFIdSOk10xkPl8Y3Iz/x6mzfK
|
||||
Uu2l2ZtYvSdAX1CQMds3ZWt0ChNNEjOKPv4g2QSDhGkiqrmi4wUS81g68wKqOpqn
|
||||
GbN8uKxIfyMjqZKaujPR
|
||||
-----END CERTIFICATE-----
|
||||
`
|
||||
|
||||
module.exports['server.key'] = `
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEpAIBAAKCAQEAvPM99BkYrBcTM355dhz4XzhSDRGxa9qttUlBSgEsbu2UjsRm
|
||||
XjDS+60XXd66tWpPwLeUd2uvlC/ltv5ekv+EBu35j1KfA1+K1rtFzb1i40kMCsns
|
||||
OoXjgpsN2wvkxMdFkT2bkqKCS6X0xzlWea1t4poKh9iG7n3otk4RzPNawfwQ9W5n
|
||||
o9/8i6AUwD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HgZIXv83lF1SE2o1ATKpCHqzFx9
|
||||
K8vK9e22PZUJPGaOhqjEA13TAoGAEPipSJFw38/6NmInfkjd84EFxmkAoBI5k/vV
|
||||
36aOoyl7s40MTYEPXavCF3fLPVfuwUXhmKUcbkiXhlIX4De3y15e1n66fjDc8EVY
|
||||
qqTmzQKCpBwMlI5Ld65yjoo6VW0SsiABIlRSfIY5NHXd7YiV4ZXNj6+aMUIRxyWu
|
||||
Mzfpk1ECgYBZw8lML+F8XbcmCLGYuicf0V/wgFaJr8nnPeW7AiQrv13Ju1ItEaC8
|
||||
Tz8F7OfC+FoUb0MGjXHKquDVBDs4xSuS+Ol+rlZEK68ALpm8sUgp6YjARYiXlprs
|
||||
6o4kN0P5F+DVU2SP6fo9zKLCxaTH9VAQ9C3VUViGAFLBt4DVDmj77g==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
`
|
||||
|
||||
module.exports['server.crt'] = `
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDNzCCAh8CFBg1Ph5t5rBlAbCrEn/PexNy9WunMA0GCSqGSIb3DQEBCwUAMF0x
|
||||
CzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEQMA4GA1UECgwHTm9kZS5qczERMA8G
|
||||
A1UECwwIbm9kZS1neXAxHDAaBgNVBAMME25vZGUtZ3lwLm5vZGVqcy5vcmcwHhcN
|
||||
MjIwNTExMDQyMjI0WhcNMjMwOTIzMDQyMjI0WjBTMQswCQYDVQQGEwJVUzELMAkG
|
||||
A1UECAwCQ0ExEDAOBgNVBAoMB05vZGUuanMxETAPBgNVBAsMCG5vZGUtZ3lwMRIw
|
||||
EAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB
|
||||
AQC88z30GRisFxMzfnl2HPhfOFINEbFr2q21SUFKASxu7ZSOxGZeMNL7rRdd3rq1
|
||||
ak/At5R3a6+UL+W2/l6S/4QG7fmPUp8DX4rWu0XNvWLjSQwKyew6heOCmw3bC+TE
|
||||
x0WRPZuSooJLpfTHOVZ5rW3imgqH2Ibufei2ThHM81rB/BD1bmej3/yLoBTANu4r
|
||||
h2EAh38ifDZoqszJD4CJK+wMzbBQyr6lXuc/jp/syFHjGIbPXjMBMV2Mzc6j/U0q
|
||||
uvRaBUzqLR40C24gOoizxgTtJ84N79LOknJLF7C619iLrY5ouH+GZYHKP+kXlKg0
|
||||
wvIkfGfgbIor5CV700kBOEuLAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAEhaNEye
|
||||
JsE4eG1xaGmHq7w9eV0neOaZ58XCuF1sSEMIy9uMnl3aOdctxh/1SYkqJyMct79q
|
||||
Ra2UZ6mauRlOeqdHb+HZKrFYYUOtd1HOWWJ44Gaya2EQMiTbd/Ns9Th2KTbTOCbL
|
||||
CHFNska9Ty2ioT7VcrVuIEXFPMua5T4lnCkNJQla800pHHOak2baN/c66Io+8XI2
|
||||
xiqaVrLT3qvpzdiiEjo4POeRnWMIgJJshy77Am5JlhaJiAqP1AHfh/tYpliGkjXF
|
||||
8DSgSoLHSQfalJ4VQvP4XLc/XnmF5Zt6bvwUxCllEBFRneU74bW7/euYX/TpYobr
|
||||
Y+YM7fGiCqwHdUs=
|
||||
-----END CERTIFICATE-----
|
||||
`
|
||||
|
||||
module.exports['ca-bundle.crt'] = `
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDJjCCAg4CAhnOMA0GCSqGSIb3DQEBBQUAMH0xCzAJBgNVBAYTAlVTMQswCQYD
|
||||
VQQIDAJDQTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzEZMBcGA1UECgwQU3Ryb25n
|
||||
TG9vcCwgSW5jLjESMBAGA1UECwwJU3Ryb25nT3BzMRowGAYDVQQDDBFjYS5zdHJv
|
||||
bmdsb29wLmNvbTAeFw0xNTEyMDgyMzM1MzNaFw00MzA0MjQyMzM1MzNaMBkxFzAV
|
||||
BgNVBAMMDnN0cm9uZ2xvb3AuY29tMIIBIjANBgkqhki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
||||
3t1r+deC3TJuHlNVSeKeT7wIfFnh2FW5riGV0q/w6eXPLTHjuiS6YmpAAbdNUgX/
|
||||
sq64FqI2RLpX6pgY5yB0SKopMcJxMLKqmF4zHpIHxtYN5EmN3PR0vehneBR/nZ2T
|
||||
3ikvWD5JeXlm7Dfw+tjijdxM/sEoDWErGup4mMKMd1s5s830p+ITJUa50d0DLFdH
|
||||
mqPSbUZF8mMPwGJd+nu1Ht3gTLtK7+gYJgGtXMJmGC0Qg77EJHDB2NbotgDGNmSU
|
||||
1H9BpAeFHHIcbh2Rr7kkTvnh/c03vFe+CsDZmezcmRpRzW1fKj3YbfqBxU4XwJrL
|
||||
a5T/N9xU
|
||||
-----END CERTIFICATE-----
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEowIBAAKCAQEA6S1E2WchgmbJYqCnpN7310ZgHjIOqeJe6MpSue2u6z6mTNd5
|
||||
izgvQNaANmn3xLFCS5zsuZaTvdPYPkcmSQzb1YcZSUYnAxZifjYARc6kb5GSBl3q
|
||||
+O70ELyFrimXfZ4JI+bdIG9KiHY17DlvZZZj/csGYVWWg0mkeH3O5LPX6/DXQVh/
|
||||
9+gZ02/cdIBCAtZHQwqx7tF/qZA/kD4GZNFpU1DYHzf9H6g9htoCqmNHQWrV2T9y
|
||||
Fybt6mbZp9kglBmyKYCc7hmQnb7N/mHn1yIuwhBsirCJTfKH86gN81u8M3+SVHA2
|
||||
VUHDllcNhpDWlmInXA+ItHdGZHCp95ohqpCPgQIDAQABAoIBABW8R4ewalo6dJlB
|
||||
+n6O3jFt+PW3mtBRLqGqgm2cb0q0a1IMX+MPWLBFjmwEErl+AH0F4rcmBx2Ryr17
|
||||
amEy1qcf0caXyHksNAApznqzWXag7iizxnxv4cZRnHBwphNqkNWM5p3oYd04j6w2
|
||||
amDg1O9KZozaKo6QZclpiMiezwjKG+PVZLT8p7afswjv+yDWPDByhlcGiye9QD1T
|
||||
VuZ0QC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wyp9+VeSif8wJ+MHQoGdGxvAQP80R3EjF
|
||||
-----END RSA PRIVATE KEY-----
|
||||
+3
-1
@@ -14,7 +14,9 @@ const configure = requireInject('../lib/configure', {
|
||||
mkdir: function (dir, options, cb) { cb() },
|
||||
promises: {
|
||||
writeFile: function (file, data) { return Promise.resolve(null) }
|
||||
}
|
||||
},
|
||||
unlink: function (path, cb) { cb() },
|
||||
symlink: function (target, path, cb) { cb() }
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
+17
-7
@@ -12,6 +12,7 @@ const devDir = require('./common').devDir()
|
||||
const rimraf = require('rimraf')
|
||||
const gyp = require('../lib/node-gyp')
|
||||
const log = require('npmlog')
|
||||
const certs = require('./fixtures/certs')
|
||||
|
||||
log.level = 'warn'
|
||||
|
||||
@@ -40,12 +41,12 @@ test('download over http', async (t) => {
|
||||
test('download over https with custom ca', async (t) => {
|
||||
t.plan(3)
|
||||
|
||||
const cafile = path.join(__dirname, '/fixtures/ca.crt')
|
||||
const [cert, key, ca] = await Promise.all([
|
||||
fs.promises.readFile(path.join(__dirname, 'fixtures/server.crt'), 'utf8'),
|
||||
fs.promises.readFile(path.join(__dirname, 'fixtures/server.key'), 'utf8'),
|
||||
install.test.readCAFile(cafile)
|
||||
])
|
||||
const cafile = path.join(__dirname, 'fixtures/ca.crt')
|
||||
const cacontents = certs['ca.crt']
|
||||
const cert = certs['server.crt']
|
||||
const key = certs['server.key']
|
||||
await fs.promises.writeFile(cafile, cacontents, 'utf8')
|
||||
const ca = await install.test.readCAFile(cafile)
|
||||
|
||||
t.strictEqual(ca.length, 1)
|
||||
|
||||
@@ -55,7 +56,10 @@ test('download over https with custom ca', async (t) => {
|
||||
res.end('ok')
|
||||
})
|
||||
|
||||
t.tearDown(() => new Promise((resolve) => server.close(resolve)))
|
||||
t.tearDown(async () => {
|
||||
await new Promise((resolve) => server.close(resolve))
|
||||
await fs.promises.unlink(cafile)
|
||||
})
|
||||
|
||||
server.on('clientError', (err) => { throw err })
|
||||
|
||||
@@ -150,6 +154,12 @@ test('download with missing cafile', async (t) => {
|
||||
})
|
||||
|
||||
test('check certificate splitting', async (t) => {
|
||||
const cafile = path.join(__dirname, 'fixtures/ca-bundle.crt')
|
||||
const cacontents = certs['ca-bundle.crt']
|
||||
await fs.promises.writeFile(cafile, cacontents, 'utf8')
|
||||
t.tearDown(async () => {
|
||||
await fs.promises.unlink(cafile)
|
||||
})
|
||||
const cas = await install.test.readCAFile(path.join(__dirname, 'fixtures/ca-bundle.crt'))
|
||||
t.plan(2)
|
||||
t.strictEqual(cas.length, 2)
|
||||
|
||||
+41
-39
@@ -1,54 +1,56 @@
|
||||
#!/usr/bin/env node
|
||||
var nopt = require("../lib/nopt")
|
||||
, path = require("path")
|
||||
, types = { num: Number
|
||||
, bool: Boolean
|
||||
, help: Boolean
|
||||
, list: Array
|
||||
, "num-list": [Number, Array]
|
||||
, "str-list": [String, Array]
|
||||
, "bool-list": [Boolean, Array]
|
||||
, str: String
|
||||
, clear: Boolean
|
||||
, config: Boolean
|
||||
, length: Number
|
||||
, file: path
|
||||
}
|
||||
, shorthands = { s: [ "--str", "astring" ]
|
||||
, b: [ "--bool" ]
|
||||
, nb: [ "--no-bool" ]
|
||||
, tft: [ "--bool-list", "--no-bool-list", "--bool-list", "true" ]
|
||||
, "?": ["--help"]
|
||||
, h: ["--help"]
|
||||
, H: ["--help"]
|
||||
, n: [ "--num", "125" ]
|
||||
, c: ["--config"]
|
||||
, l: ["--length"]
|
||||
, f: ["--file"]
|
||||
}
|
||||
, parsed = nopt( types
|
||||
, shorthands
|
||||
, process.argv
|
||||
, 2 )
|
||||
var nopt = require('../lib/nopt')
|
||||
var path = require('path')
|
||||
var types = { num: Number,
|
||||
bool: Boolean,
|
||||
help: Boolean,
|
||||
list: Array,
|
||||
'num-list': [Number, Array],
|
||||
'str-list': [String, Array],
|
||||
'bool-list': [Boolean, Array],
|
||||
str: String,
|
||||
clear: Boolean,
|
||||
config: Boolean,
|
||||
length: Number,
|
||||
file: path,
|
||||
}
|
||||
var shorthands = { s: ['--str', 'astring'],
|
||||
b: ['--bool'],
|
||||
nb: ['--no-bool'],
|
||||
tft: ['--bool-list', '--no-bool-list', '--bool-list', 'true'],
|
||||
'?': ['--help'],
|
||||
h: ['--help'],
|
||||
H: ['--help'],
|
||||
n: ['--num', '125'],
|
||||
c: ['--config'],
|
||||
l: ['--length'],
|
||||
f: ['--file'],
|
||||
}
|
||||
var parsed = nopt(types
|
||||
, shorthands
|
||||
, process.argv
|
||||
, 2)
|
||||
|
||||
console.log("parsed", parsed)
|
||||
console.log('parsed', parsed)
|
||||
|
||||
if (parsed.help) {
|
||||
console.log("")
|
||||
console.log("nopt cli tester")
|
||||
console.log("")
|
||||
console.log("types")
|
||||
console.log('')
|
||||
console.log('nopt cli tester')
|
||||
console.log('')
|
||||
console.log('types')
|
||||
console.log(Object.keys(types).map(function M (t) {
|
||||
var type = types[t]
|
||||
if (Array.isArray(type)) {
|
||||
return [t, type.map(function (type) { return type.name })]
|
||||
return [t, type.map(function (mappedType) {
|
||||
return mappedType.name
|
||||
})]
|
||||
}
|
||||
return [t, type && type.name]
|
||||
}).reduce(function (s, i) {
|
||||
s[i[0]] = i[1]
|
||||
return s
|
||||
}, {}))
|
||||
console.log("")
|
||||
console.log("shorthands")
|
||||
console.log('')
|
||||
console.log('shorthands')
|
||||
console.log(shorthands)
|
||||
}
|
||||
+221
-147
@@ -1,130 +1,147 @@
|
||||
// info about each config option.
|
||||
|
||||
var debug = process.env.DEBUG_NOPT || process.env.NOPT_DEBUG
|
||||
? function () { console.error.apply(console, arguments) }
|
||||
? function () {
|
||||
console.error.apply(console, arguments)
|
||||
}
|
||||
: function () {}
|
||||
|
||||
var url = require("url")
|
||||
, path = require("path")
|
||||
, Stream = require("stream").Stream
|
||||
, abbrev = require("abbrev")
|
||||
, os = require("os")
|
||||
var url = require('url')
|
||||
var path = require('path')
|
||||
var Stream = require('stream').Stream
|
||||
var abbrev = require('abbrev')
|
||||
var os = require('os')
|
||||
|
||||
module.exports = exports = nopt
|
||||
exports.clean = clean
|
||||
|
||||
exports.typeDefs =
|
||||
{ String : { type: String, validate: validateString }
|
||||
, Boolean : { type: Boolean, validate: validateBoolean }
|
||||
, url : { type: url, validate: validateUrl }
|
||||
, Number : { type: Number, validate: validateNumber }
|
||||
, path : { type: path, validate: validatePath }
|
||||
, Stream : { type: Stream, validate: validateStream }
|
||||
, Date : { type: Date, validate: validateDate }
|
||||
{ String: { type: String, validate: validateString },
|
||||
Boolean: { type: Boolean, validate: validateBoolean },
|
||||
url: { type: url, validate: validateUrl },
|
||||
Number: { type: Number, validate: validateNumber },
|
||||
path: { type: path, validate: validatePath },
|
||||
Stream: { type: Stream, validate: validateStream },
|
||||
Date: { type: Date, validate: validateDate },
|
||||
}
|
||||
|
||||
function nopt (types, shorthands, args, slice) {
|
||||
args = args || process.argv
|
||||
types = types || {}
|
||||
shorthands = shorthands || {}
|
||||
if (typeof slice !== "number") slice = 2
|
||||
if (typeof slice !== 'number') {
|
||||
slice = 2
|
||||
}
|
||||
|
||||
debug(types, shorthands, args, slice)
|
||||
|
||||
args = args.slice(slice)
|
||||
var data = {}
|
||||
, key
|
||||
, argv = {
|
||||
remain: [],
|
||||
cooked: args,
|
||||
original: args.slice(0)
|
||||
}
|
||||
var argv = {
|
||||
remain: [],
|
||||
cooked: args,
|
||||
original: args.slice(0),
|
||||
}
|
||||
|
||||
parse(args, data, argv.remain, types, shorthands)
|
||||
// now data is full
|
||||
clean(data, types, exports.typeDefs)
|
||||
data.argv = argv
|
||||
Object.defineProperty(data.argv, 'toString', { value: function () {
|
||||
return this.original.map(JSON.stringify).join(" ")
|
||||
}, enumerable: false })
|
||||
return this.original.map(JSON.stringify).join(' ')
|
||||
},
|
||||
enumerable: false })
|
||||
return data
|
||||
}
|
||||
|
||||
function clean (data, types, typeDefs) {
|
||||
typeDefs = typeDefs || exports.typeDefs
|
||||
var remove = {}
|
||||
, typeDefault = [false, true, null, String, Array]
|
||||
var typeDefault = [false, true, null, String, Array]
|
||||
|
||||
Object.keys(data).forEach(function (k) {
|
||||
if (k === "argv") return
|
||||
if (k === 'argv') {
|
||||
return
|
||||
}
|
||||
var val = data[k]
|
||||
, isArray = Array.isArray(val)
|
||||
, type = types[k]
|
||||
if (!isArray) val = [val]
|
||||
if (!type) type = typeDefault
|
||||
if (type === Array) type = typeDefault.concat(Array)
|
||||
if (!Array.isArray(type)) type = [type]
|
||||
var isArray = Array.isArray(val)
|
||||
var type = types[k]
|
||||
if (!isArray) {
|
||||
val = [val]
|
||||
}
|
||||
if (!type) {
|
||||
type = typeDefault
|
||||
}
|
||||
if (type === Array) {
|
||||
type = typeDefault.concat(Array)
|
||||
}
|
||||
if (!Array.isArray(type)) {
|
||||
type = [type]
|
||||
}
|
||||
|
||||
debug("val=%j", val)
|
||||
debug("types=", type)
|
||||
val = val.map(function (val) {
|
||||
debug('val=%j', val)
|
||||
debug('types=', type)
|
||||
val = val.map(function (v) {
|
||||
// if it's an unknown value, then parse false/true/null/numbers/dates
|
||||
if (typeof val === "string") {
|
||||
debug("string %j", val)
|
||||
val = val.trim()
|
||||
if ((val === "null" && ~type.indexOf(null))
|
||||
|| (val === "true" &&
|
||||
if (typeof v === 'string') {
|
||||
debug('string %j', v)
|
||||
v = v.trim()
|
||||
if ((v === 'null' && ~type.indexOf(null))
|
||||
|| (v === 'true' &&
|
||||
(~type.indexOf(true) || ~type.indexOf(Boolean)))
|
||||
|| (val === "false" &&
|
||||
|| (v === 'false' &&
|
||||
(~type.indexOf(false) || ~type.indexOf(Boolean)))) {
|
||||
val = JSON.parse(val)
|
||||
debug("jsonable %j", val)
|
||||
} else if (~type.indexOf(Number) && !isNaN(val)) {
|
||||
debug("convert to number", val)
|
||||
val = +val
|
||||
} else if (~type.indexOf(Date) && !isNaN(Date.parse(val))) {
|
||||
debug("convert to date", val)
|
||||
val = new Date(val)
|
||||
v = JSON.parse(v)
|
||||
debug('jsonable %j', v)
|
||||
} else if (~type.indexOf(Number) && !isNaN(v)) {
|
||||
debug('convert to number', v)
|
||||
v = +v
|
||||
} else if (~type.indexOf(Date) && !isNaN(Date.parse(v))) {
|
||||
debug('convert to date', v)
|
||||
v = new Date(v)
|
||||
}
|
||||
}
|
||||
|
||||
if (!types.hasOwnProperty(k)) {
|
||||
return val
|
||||
if (!Object.prototype.hasOwnProperty.call(types, k)) {
|
||||
return v
|
||||
}
|
||||
|
||||
// allow `--no-blah` to set 'blah' to null if null is allowed
|
||||
if (val === false && ~type.indexOf(null) &&
|
||||
if (v === false && ~type.indexOf(null) &&
|
||||
!(~type.indexOf(false) || ~type.indexOf(Boolean))) {
|
||||
val = null
|
||||
v = null
|
||||
}
|
||||
|
||||
var d = {}
|
||||
d[k] = val
|
||||
debug("prevalidated val", d, val, types[k])
|
||||
if (!validate(d, k, val, types[k], typeDefs)) {
|
||||
d[k] = v
|
||||
debug('prevalidated val', d, v, types[k])
|
||||
if (!validate(d, k, v, types[k], typeDefs)) {
|
||||
if (exports.invalidHandler) {
|
||||
exports.invalidHandler(k, val, types[k], data)
|
||||
exports.invalidHandler(k, v, types[k], data)
|
||||
} else if (exports.invalidHandler !== false) {
|
||||
debug("invalid: "+k+"="+val, types[k])
|
||||
debug('invalid: ' + k + '=' + v, types[k])
|
||||
}
|
||||
return remove
|
||||
}
|
||||
debug("validated val", d, val, types[k])
|
||||
debug('validated v', d, v, types[k])
|
||||
return d[k]
|
||||
}).filter(function (val) { return val !== remove })
|
||||
}).filter(function (v) {
|
||||
return v !== remove
|
||||
})
|
||||
|
||||
// if we allow Array specifically, then an empty array is how we
|
||||
// express 'no value here', not null. Allow it.
|
||||
if (!val.length && type.indexOf(Array) === -1) {
|
||||
debug('VAL HAS NO LENGTH, DELETE IT', val, k, type.indexOf(Array))
|
||||
delete data[k]
|
||||
}
|
||||
else if (isArray) {
|
||||
} else if (isArray) {
|
||||
debug(isArray, data[k], val)
|
||||
data[k] = val
|
||||
} else data[k] = val[0]
|
||||
} else {
|
||||
data[k] = val[0]
|
||||
}
|
||||
|
||||
debug("k=%s val=%j", k, val, data[k])
|
||||
debug('k=%s val=%j', k, val, data[k])
|
||||
})
|
||||
}
|
||||
|
||||
@@ -133,17 +150,21 @@ function validateString (data, k, val) {
|
||||
}
|
||||
|
||||
function validatePath (data, k, val) {
|
||||
if (val === true) return false
|
||||
if (val === null) return true
|
||||
if (val === true) {
|
||||
return false
|
||||
}
|
||||
if (val === null) {
|
||||
return true
|
||||
}
|
||||
|
||||
val = String(val)
|
||||
|
||||
var isWin = process.platform === 'win32'
|
||||
, homePattern = isWin ? /^~(\/|\\)/ : /^~\//
|
||||
, home = os.homedir()
|
||||
var isWin = process.platform === 'win32'
|
||||
var homePattern = isWin ? /^~(\/|\\)/ : /^~\//
|
||||
var home = os.homedir()
|
||||
|
||||
if (home && val.match(homePattern)) {
|
||||
data[k] = path.resolve(home, val.substr(2))
|
||||
data[k] = path.resolve(home, val.slice(2))
|
||||
} else {
|
||||
data[k] = path.resolve(val)
|
||||
}
|
||||
@@ -151,63 +172,92 @@ function validatePath (data, k, val) {
|
||||
}
|
||||
|
||||
function validateNumber (data, k, val) {
|
||||
debug("validate Number %j %j %j", k, val, isNaN(val))
|
||||
if (isNaN(val)) return false
|
||||
debug('validate Number %j %j %j', k, val, isNaN(val))
|
||||
if (isNaN(val)) {
|
||||
return false
|
||||
}
|
||||
data[k] = +val
|
||||
}
|
||||
|
||||
function validateDate (data, k, val) {
|
||||
var s = Date.parse(val)
|
||||
debug("validate Date %j %j %j", k, val, s)
|
||||
if (isNaN(s)) return false
|
||||
debug('validate Date %j %j %j', k, val, s)
|
||||
if (isNaN(s)) {
|
||||
return false
|
||||
}
|
||||
data[k] = new Date(val)
|
||||
}
|
||||
|
||||
function validateBoolean (data, k, val) {
|
||||
if (val instanceof Boolean) val = val.valueOf()
|
||||
else if (typeof val === "string") {
|
||||
if (!isNaN(val)) val = !!(+val)
|
||||
else if (val === "null" || val === "false") val = false
|
||||
else val = true
|
||||
} else val = !!val
|
||||
if (val instanceof Boolean) {
|
||||
val = val.valueOf()
|
||||
} else if (typeof val === 'string') {
|
||||
if (!isNaN(val)) {
|
||||
val = !!(+val)
|
||||
} else if (val === 'null' || val === 'false') {
|
||||
val = false
|
||||
} else {
|
||||
val = true
|
||||
}
|
||||
} else {
|
||||
val = !!val
|
||||
}
|
||||
data[k] = val
|
||||
}
|
||||
|
||||
function validateUrl (data, k, val) {
|
||||
// Changing this would be a breaking change in the npm cli
|
||||
/* eslint-disable-next-line node/no-deprecated-api */
|
||||
val = url.parse(String(val))
|
||||
if (!val.host) return false
|
||||
if (!val.host) {
|
||||
return false
|
||||
}
|
||||
data[k] = val.href
|
||||
}
|
||||
|
||||
function validateStream (data, k, val) {
|
||||
if (!(val instanceof Stream)) return false
|
||||
if (!(val instanceof Stream)) {
|
||||
return false
|
||||
}
|
||||
data[k] = val
|
||||
}
|
||||
|
||||
function validate (data, k, val, type, typeDefs) {
|
||||
// arrays are lists of types.
|
||||
if (Array.isArray(type)) {
|
||||
for (var i = 0, l = type.length; i < l; i ++) {
|
||||
if (type[i] === Array) continue
|
||||
if (validate(data, k, val, type[i], typeDefs)) return true
|
||||
for (let i = 0, l = type.length; i < l; i++) {
|
||||
if (type[i] === Array) {
|
||||
continue
|
||||
}
|
||||
if (validate(data, k, val, type[i], typeDefs)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
delete data[k]
|
||||
return false
|
||||
}
|
||||
|
||||
// an array of anything?
|
||||
if (type === Array) return true
|
||||
if (type === Array) {
|
||||
return true
|
||||
}
|
||||
|
||||
// Original comment:
|
||||
// NaN is poisonous. Means that something is not allowed.
|
||||
// New comment: Changing this to an isNaN check breaks a lot of tests.
|
||||
// Something is being assumed here that is not actually what happens in
|
||||
// practice. Fixing it is outside the scope of getting linting to pass in
|
||||
// this repo. Leaving as-is for now.
|
||||
/* eslint-disable-next-line no-self-compare */
|
||||
if (type !== type) {
|
||||
debug("Poison NaN", k, val, type)
|
||||
debug('Poison NaN', k, val, type)
|
||||
delete data[k]
|
||||
return false
|
||||
}
|
||||
|
||||
// explicit list of values
|
||||
if (val === type) {
|
||||
debug("Explicitly allowed %j", val)
|
||||
debug('Explicitly allowed %j', val)
|
||||
// if (isArray) (data[k] = data[k] || []).push(val)
|
||||
// else data[k] = val
|
||||
data[k] = val
|
||||
@@ -216,14 +266,17 @@ function validate (data, k, val, type, typeDefs) {
|
||||
|
||||
// now go through the list of typeDefs, validate against each one.
|
||||
var ok = false
|
||||
, types = Object.keys(typeDefs)
|
||||
for (var i = 0, l = types.length; i < l; i ++) {
|
||||
debug("test type %j %j %j", k, val, types[i])
|
||||
var types = Object.keys(typeDefs)
|
||||
for (let i = 0, l = types.length; i < l; i++) {
|
||||
debug('test type %j %j %j', k, val, types[i])
|
||||
var t = typeDefs[types[i]]
|
||||
if (t &&
|
||||
((type && type.name && t.type && t.type.name) ? (type.name === t.type.name) : (type === t.type))) {
|
||||
if (t && (
|
||||
(type && type.name && t.type && t.type.name) ?
|
||||
(type.name === t.type.name) :
|
||||
(type === t.type)
|
||||
)) {
|
||||
var d = {}
|
||||
ok = false !== t.validate(d, k, val)
|
||||
ok = t.validate(d, k, val) !== false
|
||||
val = d[k]
|
||||
if (ok) {
|
||||
// if (isArray) (data[k] = data[k] || []).push(val)
|
||||
@@ -233,60 +286,63 @@ function validate (data, k, val, type, typeDefs) {
|
||||
}
|
||||
}
|
||||
}
|
||||
debug("OK? %j (%j %j %j)", ok, k, val, types[i])
|
||||
debug('OK? %j (%j %j %j)', ok, k, val, types[types.length - 1])
|
||||
|
||||
if (!ok) delete data[k]
|
||||
if (!ok) {
|
||||
delete data[k]
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
function parse (args, data, remain, types, shorthands) {
|
||||
debug("parse", args, data, remain)
|
||||
debug('parse', args, data, remain)
|
||||
|
||||
var key = null
|
||||
, abbrevs = abbrev(Object.keys(types))
|
||||
, shortAbbr = abbrev(Object.keys(shorthands))
|
||||
var abbrevs = abbrev(Object.keys(types))
|
||||
var shortAbbr = abbrev(Object.keys(shorthands))
|
||||
|
||||
for (var i = 0; i < args.length; i ++) {
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
var arg = args[i]
|
||||
debug("arg", arg)
|
||||
debug('arg', arg)
|
||||
|
||||
if (arg.match(/^-{2,}$/)) {
|
||||
// done with keys.
|
||||
// the rest are args.
|
||||
remain.push.apply(remain, args.slice(i + 1))
|
||||
args[i] = "--"
|
||||
args[i] = '--'
|
||||
break
|
||||
}
|
||||
var hadEq = false
|
||||
if (arg.charAt(0) === "-" && arg.length > 1) {
|
||||
if (arg.charAt(0) === '-' && arg.length > 1) {
|
||||
var at = arg.indexOf('=')
|
||||
if (at > -1) {
|
||||
hadEq = true
|
||||
var v = arg.substr(at + 1)
|
||||
arg = arg.substr(0, at)
|
||||
var v = arg.slice(at + 1)
|
||||
arg = arg.slice(0, at)
|
||||
args.splice(i, 1, arg, v)
|
||||
}
|
||||
|
||||
// see if it's a shorthand
|
||||
// if so, splice and back up to re-parse it.
|
||||
var shRes = resolveShort(arg, shorthands, shortAbbr, abbrevs)
|
||||
debug("arg=%j shRes=%j", arg, shRes)
|
||||
debug('arg=%j shRes=%j', arg, shRes)
|
||||
if (shRes) {
|
||||
debug(arg, shRes)
|
||||
args.splice.apply(args, [i, 1].concat(shRes))
|
||||
if (arg !== shRes[0]) {
|
||||
i --
|
||||
i--
|
||||
continue
|
||||
}
|
||||
}
|
||||
arg = arg.replace(/^-+/, "")
|
||||
arg = arg.replace(/^-+/, '')
|
||||
var no = null
|
||||
while (arg.toLowerCase().indexOf("no-") === 0) {
|
||||
while (arg.toLowerCase().indexOf('no-') === 0) {
|
||||
no = !no
|
||||
arg = arg.substr(3)
|
||||
arg = arg.slice(3)
|
||||
}
|
||||
|
||||
if (abbrevs[arg]) arg = abbrevs[arg]
|
||||
if (abbrevs[arg]) {
|
||||
arg = abbrevs[arg]
|
||||
}
|
||||
|
||||
var argType = types[arg]
|
||||
var isTypeArray = Array.isArray(argType)
|
||||
@@ -299,20 +355,24 @@ function parse (args, data, remain, types, shorthands) {
|
||||
isTypeArray && argType.indexOf(Array) !== -1
|
||||
|
||||
// allow unknown things to be arrays if specified multiple times.
|
||||
if (!types.hasOwnProperty(arg) && data.hasOwnProperty(arg)) {
|
||||
if (!Array.isArray(data[arg]))
|
||||
if (
|
||||
!Object.prototype.hasOwnProperty.call(types, arg) &&
|
||||
Object.prototype.hasOwnProperty.call(data, arg)
|
||||
) {
|
||||
if (!Array.isArray(data[arg])) {
|
||||
data[arg] = [data[arg]]
|
||||
}
|
||||
isArray = true
|
||||
}
|
||||
|
||||
var val
|
||||
, la = args[i + 1]
|
||||
var la = args[i + 1]
|
||||
|
||||
var isBool = typeof no === 'boolean' ||
|
||||
argType === Boolean ||
|
||||
isTypeArray && argType.indexOf(Boolean) !== -1 ||
|
||||
(typeof argType === 'undefined' && !hadEq) ||
|
||||
(la === "false" &&
|
||||
(la === 'false' &&
|
||||
(argType === null ||
|
||||
isTypeArray && ~argType.indexOf(null)))
|
||||
|
||||
@@ -320,11 +380,13 @@ function parse (args, data, remain, types, shorthands) {
|
||||
// just set and move along
|
||||
val = !no
|
||||
// however, also support --bool true or --bool false
|
||||
if (la === "true" || la === "false") {
|
||||
if (la === 'true' || la === 'false') {
|
||||
val = JSON.parse(la)
|
||||
la = null
|
||||
if (no) val = !val
|
||||
i ++
|
||||
if (no) {
|
||||
val = !val
|
||||
}
|
||||
i++
|
||||
}
|
||||
|
||||
// also support "foo":[Boolean, "bar"] and "--foo bar"
|
||||
@@ -332,49 +394,55 @@ function parse (args, data, remain, types, shorthands) {
|
||||
if (~argType.indexOf(la)) {
|
||||
// an explicit type
|
||||
val = la
|
||||
i ++
|
||||
} else if ( la === "null" && ~argType.indexOf(null) ) {
|
||||
i++
|
||||
} else if (la === 'null' && ~argType.indexOf(null)) {
|
||||
// null allowed
|
||||
val = null
|
||||
i ++
|
||||
} else if ( !la.match(/^-{2,}[^-]/) &&
|
||||
i++
|
||||
} else if (!la.match(/^-{2,}[^-]/) &&
|
||||
!isNaN(la) &&
|
||||
~argType.indexOf(Number) ) {
|
||||
~argType.indexOf(Number)) {
|
||||
// number
|
||||
val = +la
|
||||
i ++
|
||||
} else if ( !la.match(/^-[^-]/) && ~argType.indexOf(String) ) {
|
||||
i++
|
||||
} else if (!la.match(/^-[^-]/) && ~argType.indexOf(String)) {
|
||||
// string
|
||||
val = la
|
||||
i ++
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
if (isArray) (data[arg] = data[arg] || []).push(val)
|
||||
else data[arg] = val
|
||||
if (isArray) {
|
||||
(data[arg] = data[arg] || []).push(val)
|
||||
} else {
|
||||
data[arg] = val
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
if (argType === String) {
|
||||
if (la === undefined) {
|
||||
la = ""
|
||||
la = ''
|
||||
} else if (la.match(/^-{1,2}[^-]+/)) {
|
||||
la = ""
|
||||
i --
|
||||
la = ''
|
||||
i--
|
||||
}
|
||||
}
|
||||
|
||||
if (la && la.match(/^-{2,}$/)) {
|
||||
la = undefined
|
||||
i --
|
||||
i--
|
||||
}
|
||||
|
||||
val = la === undefined ? true : la
|
||||
if (isArray) (data[arg] = data[arg] || []).push(val)
|
||||
else data[arg] = val
|
||||
if (isArray) {
|
||||
(data[arg] = data[arg] || []).push(val)
|
||||
} else {
|
||||
data[arg] = val
|
||||
}
|
||||
|
||||
i ++
|
||||
i++
|
||||
continue
|
||||
}
|
||||
remain.push(arg)
|
||||
@@ -389,14 +457,16 @@ function resolveShort (arg, shorthands, shortAbbr, abbrevs) {
|
||||
arg = arg.replace(/^-+/, '')
|
||||
|
||||
// if it's an exact known option, then don't go any further
|
||||
if (abbrevs[arg] === arg)
|
||||
if (abbrevs[arg] === arg) {
|
||||
return null
|
||||
}
|
||||
|
||||
// if it's an exact known shortopt, same deal
|
||||
if (shorthands[arg]) {
|
||||
// make it an array, if it's a list of words
|
||||
if (shorthands[arg] && !Array.isArray(shorthands[arg]))
|
||||
if (shorthands[arg] && !Array.isArray(shorthands[arg])) {
|
||||
shorthands[arg] = shorthands[arg].split(/\s+/)
|
||||
}
|
||||
|
||||
return shorthands[arg]
|
||||
}
|
||||
@@ -406,7 +476,7 @@ function resolveShort (arg, shorthands, shortAbbr, abbrevs) {
|
||||
if (!singles) {
|
||||
singles = Object.keys(shorthands).filter(function (s) {
|
||||
return s.length === 1
|
||||
}).reduce(function (l,r) {
|
||||
}).reduce(function (l, r) {
|
||||
l[r] = true
|
||||
return l
|
||||
}, {})
|
||||
@@ -414,28 +484,32 @@ function resolveShort (arg, shorthands, shortAbbr, abbrevs) {
|
||||
debug('shorthand singles', singles)
|
||||
}
|
||||
|
||||
var chrs = arg.split("").filter(function (c) {
|
||||
var chrs = arg.split('').filter(function (c) {
|
||||
return singles[c]
|
||||
})
|
||||
|
||||
if (chrs.join("") === arg) return chrs.map(function (c) {
|
||||
return shorthands[c]
|
||||
}).reduce(function (l, r) {
|
||||
return l.concat(r)
|
||||
}, [])
|
||||
|
||||
if (chrs.join('') === arg) {
|
||||
return chrs.map(function (c) {
|
||||
return shorthands[c]
|
||||
}).reduce(function (l, r) {
|
||||
return l.concat(r)
|
||||
}, [])
|
||||
}
|
||||
|
||||
// if it's an arg abbrev, and not a literal shorthand, then prefer the arg
|
||||
if (abbrevs[arg] && !shorthands[arg])
|
||||
if (abbrevs[arg] && !shorthands[arg]) {
|
||||
return null
|
||||
}
|
||||
|
||||
// if it's an abbr for a shorthand, then use that
|
||||
if (shortAbbr[arg])
|
||||
if (shortAbbr[arg]) {
|
||||
arg = shortAbbr[arg]
|
||||
}
|
||||
|
||||
// make it an array, if it's a list of words
|
||||
if (shorthands[arg] && !Array.isArray(shorthands[arg]))
|
||||
if (shorthands[arg] && !Array.isArray(shorthands[arg])) {
|
||||
shorthands[arg] = shorthands[arg].split(/\s+/)
|
||||
}
|
||||
|
||||
return shorthands[arg]
|
||||
}
|
||||
+27
-8
@@ -1,14 +1,20 @@
|
||||
{
|
||||
"name": "nopt",
|
||||
"version": "5.0.0",
|
||||
"version": "6.0.0",
|
||||
"description": "Option parsing for Node, supporting types, shorthands, etc. Used by npm.",
|
||||
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
|
||||
"author": "GitHub Inc.",
|
||||
"main": "lib/nopt.js",
|
||||
"scripts": {
|
||||
"preversion": "npm test",
|
||||
"postversion": "npm publish",
|
||||
"prepublishOnly": "git push origin --follow-tags",
|
||||
"test": "tap test/*.js"
|
||||
"test": "tap",
|
||||
"lint": "eslint \"**/*.js\"",
|
||||
"postlint": "template-oss-check",
|
||||
"template-oss-apply": "template-oss-apply --force",
|
||||
"lintfix": "npm run lint -- --fix",
|
||||
"snap": "tap",
|
||||
"posttest": "npm run lint"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -19,16 +25,29 @@
|
||||
},
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"abbrev": "1"
|
||||
"abbrev": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tap": "^14.10.6"
|
||||
"@npmcli/eslint-config": "^3.0.1",
|
||||
"@npmcli/template-oss": "3.5.0",
|
||||
"tap": "^16.3.0"
|
||||
},
|
||||
"tap": {
|
||||
"lines": 87,
|
||||
"functions": 91,
|
||||
"branches": 81,
|
||||
"statements": 87
|
||||
},
|
||||
"files": [
|
||||
"bin",
|
||||
"lib"
|
||||
"bin/",
|
||||
"lib/"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"windowsCI": false,
|
||||
"version": "3.5.0"
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -45,6 +45,7 @@ class SocksClient extends events_1.EventEmitter {
|
||||
catch (err) {
|
||||
if (typeof callback === 'function') {
|
||||
callback(err);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return resolve(err); // Resolves pending promise (prevents memory leaks).
|
||||
}
|
||||
else {
|
||||
@@ -68,6 +69,7 @@ class SocksClient extends events_1.EventEmitter {
|
||||
client.removeAllListeners();
|
||||
if (typeof callback === 'function') {
|
||||
callback(err);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
resolve(err); // Resolves pending promise (prevents memory leaks).
|
||||
}
|
||||
else {
|
||||
@@ -86,6 +88,7 @@ class SocksClient extends events_1.EventEmitter {
|
||||
* @returns { Promise }
|
||||
*/
|
||||
static createConnectionChain(options, callback) {
|
||||
// eslint-disable-next-line no-async-promise-executor
|
||||
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
||||
// Validate SocksClientChainOptions
|
||||
try {
|
||||
@@ -94,6 +97,7 @@ class SocksClient extends events_1.EventEmitter {
|
||||
catch (err) {
|
||||
if (typeof callback === 'function') {
|
||||
callback(err);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return resolve(err); // Resolves pending promise (prevents memory leaks).
|
||||
}
|
||||
else {
|
||||
@@ -106,7 +110,6 @@ class SocksClient extends events_1.EventEmitter {
|
||||
(0, util_1.shuffleArray)(options.proxies);
|
||||
}
|
||||
try {
|
||||
// tslint:disable-next-line:no-increment-decrement
|
||||
for (let i = 0; i < options.proxies.length; i++) {
|
||||
const nextProxy = options.proxies[i];
|
||||
// If we've reached the last proxy in the chain, the destination is the actual destination, otherwise it's the next proxy.
|
||||
@@ -140,6 +143,7 @@ class SocksClient extends events_1.EventEmitter {
|
||||
catch (err) {
|
||||
if (typeof callback === 'function') {
|
||||
callback(err);
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
resolve(err); // Resolves pending promise (prevents memory leaks).
|
||||
}
|
||||
else {
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"socksclient.js","sourceRoot":"","sources":["../../src/client/socksclient.ts"],"names":[],"mappings":";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AAG,IAAI,CAAC,MAAM,EAAE;YACxB,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;SACH;QAED,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;QACjE,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC;QAEtB,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAEO,sCAAa"}
|
||||
-1
@@ -16,7 +16,6 @@ exports.SocksClientError = SocksClientError;
|
||||
* @param array The array to shuffle.
|
||||
*/
|
||||
function shuffleArray(array) {
|
||||
// tslint:disable-next-line:no-increment-decrement
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/common/util.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAM,gBAAiB,SAAQ,KAAK;IAClC,YACE,OAAe,EACR,OAAqD;QAE5D,KAAK,CAAC,OAAO,CAAC,CAAC;QAFR,YAAO,GAAP,OAAO,CAA8C;IAG9D,CAAC;CACF;AAwBuB,4CAAgB;AAtBxC;;;GAGG;AACH,SAAS,YAAY,CAAC,KAAY;IAChC,kDAAkD;IAClD,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;QACzC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9C,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7C;AACH,CAAC;AAYyC,oCAAY"}
|
||||
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/common/util.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAM,gBAAiB,SAAQ,KAAK;IAClC,YACE,OAAe,EACR,OAAqD;QAE5D,KAAK,CAAC,OAAO,CAAC,CAAC;QAFR,YAAO,GAAP,OAAO,CAA8C;IAG9D,CAAC;CACF;AAuBuB,4CAAgB;AArBxC;;;GAGG;AACH,SAAS,YAAY,CAAC,KAAgB;IACpC,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;QACzC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9C,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7C;AACH,CAAC;AAYyC,oCAAY"}
|
||||
+5
-1
@@ -1,7 +1,11 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAqC"}
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC"}
|
||||
+12
-37
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "socks",
|
||||
"private": false,
|
||||
"version": "2.6.2",
|
||||
"version": "2.7.0",
|
||||
"description": "Fully featured SOCKS proxy client supporting SOCKSv4, SOCKSv4a, and SOCKSv5. Includes Bind and Associate functionality.",
|
||||
"main": "build/index.js",
|
||||
"typings": "typings/index.d.ts",
|
||||
@@ -34,50 +34,25 @@
|
||||
"readmeFilename": "README.md",
|
||||
"devDependencies": {
|
||||
"@types/ip": "1.1.0",
|
||||
"@types/mocha": "^9.1.0",
|
||||
"@types/node": "^17.0.15",
|
||||
"coveralls": "^3.1.1",
|
||||
"mocha": "^9.2.0",
|
||||
"nyc": "15.1.0",
|
||||
"prettier": "^2.5.1",
|
||||
"socks5-server": "^0.1.1",
|
||||
"ts-node": "^10.4.0",
|
||||
"typescript": "^4.5.5"
|
||||
"@types/mocha": "^9.1.1",
|
||||
"@types/node": "^18.0.6",
|
||||
"@typescript-eslint/eslint-plugin": "^5.30.6",
|
||||
"@typescript-eslint/parser": "^5.30.6",
|
||||
"eslint": "^8.20.0",
|
||||
"mocha": "^10.0.0",
|
||||
"prettier": "^2.7.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.7.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"ip": "^1.1.5",
|
||||
"ip": "^2.0.0",
|
||||
"smart-buffer": "^4.2.0"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublish": "npm install -g typescript && npm run build",
|
||||
"test": "NODE_ENV=test mocha --recursive --require ts-node/register test/**/*.ts",
|
||||
"prettier": "prettier --write ./src/**/*.ts --config .prettierrc.yaml",
|
||||
"coverage": "NODE_ENV=test nyc npm test",
|
||||
"coveralls": "NODE_ENV=test nyc npm test && nyc report --reporter=text-lcov | coveralls",
|
||||
"lint": "tslint --project tsconfig.json 'src/**/*.ts'",
|
||||
"lint": "eslint 'src/**/*.ts'",
|
||||
"build": "rm -rf build typings && prettier --write ./src/**/*.ts --config .prettierrc.yaml && tsc -p ."
|
||||
},
|
||||
"nyc": {
|
||||
"extension": [
|
||||
".ts",
|
||||
".tsx"
|
||||
],
|
||||
"include": [
|
||||
"src/*.ts",
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"**.*.d.ts",
|
||||
"node_modules",
|
||||
"typings"
|
||||
],
|
||||
"require": [
|
||||
"ts-node/register"
|
||||
],
|
||||
"reporter": [
|
||||
"json",
|
||||
"html"
|
||||
],
|
||||
"all": true
|
||||
}
|
||||
}
|
||||
+6
-4
@@ -1,4 +1,6 @@
|
||||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
import { EventEmitter } from 'events';
|
||||
import { SocksClientOptions, SocksClientChainOptions, SocksRemoteHost, SocksProxy, SocksClientBoundEvent, SocksClientEstablishedEvent, SocksUDPFrameDetails } from '../common/constants';
|
||||
import { SocksClientError } from '../common/util';
|
||||
@@ -7,11 +9,11 @@ declare interface SocksClient {
|
||||
on(event: 'error', listener: (err: SocksClientError) => void): this;
|
||||
on(event: 'bound', listener: (info: SocksClientBoundEvent) => void): this;
|
||||
on(event: 'established', listener: (info: SocksClientEstablishedEvent) => void): this;
|
||||
once(event: string, listener: (...args: any[]) => void): this;
|
||||
once(event: string, listener: (...args: unknown[]) => void): this;
|
||||
once(event: 'error', listener: (err: SocksClientError) => void): this;
|
||||
once(event: 'bound', listener: (info: SocksClientBoundEvent) => void): this;
|
||||
once(event: 'established', listener: (info: SocksClientEstablishedEvent) => void): this;
|
||||
emit(event: string | symbol, ...args: any[]): boolean;
|
||||
emit(event: string | symbol, ...args: unknown[]): boolean;
|
||||
emit(event: 'error', err: SocksClientError): boolean;
|
||||
emit(event: 'bound', info: SocksClientBoundEvent): boolean;
|
||||
emit(event: 'established', info: SocksClientEstablishedEvent): boolean;
|
||||
@@ -36,7 +38,7 @@ declare class SocksClient extends EventEmitter implements SocksClient {
|
||||
* @param callback { Function } An optional callback function.
|
||||
* @returns { Promise }
|
||||
*/
|
||||
static createConnection(options: SocksClientOptions, callback?: Function): Promise<SocksClientEstablishedEvent>;
|
||||
static createConnection(options: SocksClientOptions, callback?: (error: Error | null, info?: SocksClientEstablishedEvent) => void): Promise<SocksClientEstablishedEvent>;
|
||||
/**
|
||||
* Creates a new SOCKS connection chain to a destination host through 2 or more SOCKS proxies.
|
||||
*
|
||||
@@ -46,7 +48,7 @@ declare class SocksClient extends EventEmitter implements SocksClient {
|
||||
* @param callback { Function } An optional callback function.
|
||||
* @returns { Promise }
|
||||
*/
|
||||
static createConnectionChain(options: SocksClientChainOptions, callback?: Function): Promise<SocksClientEstablishedEvent>;
|
||||
static createConnectionChain(options: SocksClientChainOptions, callback?: (error: Error | null, socket?: SocksClientEstablishedEvent) => void): Promise<SocksClientEstablishedEvent>;
|
||||
/**
|
||||
* Creates a SOCKS UDP Frame.
|
||||
* @param options
|
||||
|
||||
+2
@@ -1,4 +1,6 @@
|
||||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
import { Duplex } from 'stream';
|
||||
import { Socket, SocketConnectOpts } from 'net';
|
||||
import { RequireOnlyOne } from './util';
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ declare class SocksClientError extends Error {
|
||||
* Shuffles a given array.
|
||||
* @param array The array to shuffle.
|
||||
*/
|
||||
declare function shuffleArray(array: any[]): void;
|
||||
declare function shuffleArray(array: unknown[]): void;
|
||||
declare type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
|
||||
[K in Keys]?: Required<Pick<T, K>> & Partial<Record<Exclude<Keys, K>, undefined>>;
|
||||
}[Keys];
|
||||
|
||||
Vendored
+5
-5
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "8.16.0",
|
||||
"version": "8.17.0",
|
||||
"name": "npm",
|
||||
"description": "a package manager for JavaScript",
|
||||
"workspaces": [
|
||||
@@ -58,11 +58,11 @@
|
||||
"@isaacs/string-locale-compare": "^1.1.0",
|
||||
"@npmcli/arborist": "^5.0.4",
|
||||
"@npmcli/ci-detect": "^2.0.0",
|
||||
"@npmcli/config": "^4.2.0",
|
||||
"@npmcli/config": "^4.2.1",
|
||||
"@npmcli/fs": "^2.1.0",
|
||||
"@npmcli/map-workspaces": "^2.0.3",
|
||||
"@npmcli/package-json": "^2.0.0",
|
||||
"@npmcli/run-script": "^4.2.0",
|
||||
"@npmcli/run-script": "^4.2.1",
|
||||
"abbrev": "~1.1.1",
|
||||
"archy": "~1.0.0",
|
||||
"cacache": "^16.1.1",
|
||||
@@ -96,8 +96,8 @@
|
||||
"mkdirp": "^1.0.4",
|
||||
"mkdirp-infer-owner": "^2.0.0",
|
||||
"ms": "^2.1.2",
|
||||
"node-gyp": "^9.0.0",
|
||||
"nopt": "^5.0.0",
|
||||
"node-gyp": "^9.1.0",
|
||||
"nopt": "^6.0.0",
|
||||
"npm-audit-report": "^3.0.0",
|
||||
"npm-install-checks": "^5.0.0",
|
||||
"npm-package-arg": "^9.1.0",
|
||||
|
||||
-2
@@ -34,9 +34,7 @@ t.test('simple login', async t => {
|
||||
'_authtoken=user',
|
||||
'-authtoken=user',
|
||||
'_authToken=user',
|
||||
'//registry.npmjs.org/:-authtoken=user',
|
||||
'//registry.npmjs.org/:_authToken=user',
|
||||
'//registry.npmjs.org/:_authtoken=user',
|
||||
'//registry.npmjs.org/:always-auth=user',
|
||||
'//registry.npmjs.org/:email=test-email-old@npmjs.org',
|
||||
].join('\n'),
|
||||
|
||||
Vendored
+6
-40
@@ -1,5 +1,4 @@
|
||||
const t = require('tap')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const tspawk = require('../../fixtures/tspawk')
|
||||
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
|
||||
@@ -39,24 +38,13 @@ t.test('npm edit', async t => {
|
||||
const { npm, joinedOutput } = await loadMockNpm(t, npmConfig)
|
||||
|
||||
const semverPath = path.resolve(npm.prefix, 'node_modules', 'semver')
|
||||
const [scriptShell] = makeSpawnArgs({
|
||||
const [scriptShell, scriptArgs] = makeSpawnArgs({
|
||||
event: 'install',
|
||||
path: npm.prefix,
|
||||
cmd: 'testinstall',
|
||||
})
|
||||
spawk.spawn('testeditor', [semverPath])
|
||||
spawk.spawn(
|
||||
scriptShell,
|
||||
args => {
|
||||
const lastArg = args[args.length - 1]
|
||||
const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')
|
||||
const rightFilename = path.basename(lastArg).startsWith('install')
|
||||
const rightContents = fs.readFileSync(lastArg, { encoding: 'utf8' })
|
||||
.trim().endsWith('testinstall')
|
||||
return rightExtension && rightFilename && rightContents
|
||||
},
|
||||
{ cwd: semverPath }
|
||||
)
|
||||
spawk.spawn(scriptShell, scriptArgs, { cwd: semverPath })
|
||||
await npm.exec('edit', ['semver'])
|
||||
t.match(joinedOutput(), 'rebuilt dependencies successfully')
|
||||
})
|
||||
@@ -64,24 +52,13 @@ t.test('npm edit', async t => {
|
||||
t.test('rebuild failure', async t => {
|
||||
const { npm } = await loadMockNpm(t, npmConfig)
|
||||
const semverPath = path.resolve(npm.prefix, 'node_modules', 'semver')
|
||||
const [scriptShell] = makeSpawnArgs({
|
||||
const [scriptShell, scriptArgs] = makeSpawnArgs({
|
||||
event: 'install',
|
||||
path: npm.prefix,
|
||||
cmd: 'testinstall',
|
||||
})
|
||||
spawk.spawn('testeditor', [semverPath])
|
||||
spawk.spawn(
|
||||
scriptShell,
|
||||
args => {
|
||||
const lastArg = args[args.length - 1]
|
||||
const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')
|
||||
const rightFilename = path.basename(lastArg).startsWith('install')
|
||||
const rightContents = fs.readFileSync(lastArg, { encoding: 'utf8' })
|
||||
.trim().endsWith('testinstall')
|
||||
return rightExtension && rightFilename && rightContents
|
||||
},
|
||||
{ cwd: semverPath }
|
||||
).exit(1).stdout('test error')
|
||||
spawk.spawn(scriptShell, scriptArgs, { cwd: semverPath }).exit(1).stdout('test error')
|
||||
await t.rejects(
|
||||
npm.exec('edit', ['semver']),
|
||||
{ message: 'command failed' }
|
||||
@@ -108,24 +85,13 @@ t.test('npm edit editor has flags', async t => {
|
||||
})
|
||||
|
||||
const semverPath = path.resolve(npm.prefix, 'node_modules', 'semver')
|
||||
const [scriptShell] = makeSpawnArgs({
|
||||
const [scriptShell, scriptArgs] = makeSpawnArgs({
|
||||
event: 'install',
|
||||
path: npm.prefix,
|
||||
cmd: 'testinstall',
|
||||
})
|
||||
spawk.spawn('testeditor', ['--flag', semverPath])
|
||||
spawk.spawn(
|
||||
scriptShell,
|
||||
args => {
|
||||
const lastArg = args[args.length - 1]
|
||||
const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')
|
||||
const rightFilename = path.basename(lastArg).startsWith('install')
|
||||
const rightContents = fs.readFileSync(lastArg, { encoding: 'utf8' })
|
||||
.trim().endsWith('testinstall')
|
||||
return rightExtension && rightFilename && rightContents
|
||||
},
|
||||
{ cwd: semverPath }
|
||||
)
|
||||
spawk.spawn(scriptShell, scriptArgs, { cwd: semverPath })
|
||||
await npm.exec('edit', ['semver'])
|
||||
})
|
||||
|
||||
|
||||
Vendored
+42
-1
@@ -28,6 +28,7 @@ t.test('registry package', async t => {
|
||||
|
||||
const { npm } = await loadMockNpm(t, {
|
||||
config: {
|
||||
audit: false,
|
||||
yes: true,
|
||||
},
|
||||
prefixDir: {
|
||||
@@ -43,7 +44,46 @@ t.test('registry package', async t => {
|
||||
})
|
||||
|
||||
await registry.package({
|
||||
times: 2,
|
||||
manifest,
|
||||
tarballs: {
|
||||
'1.0.0': path.join(npm.prefix, 'npm-exec-test'),
|
||||
} })
|
||||
|
||||
await npm.exec('exec', ['@npmcli/npx-test'])
|
||||
const exists = await fs.stat(path.join(npm.prefix, 'npm-exec-test-success'))
|
||||
t.ok(exists.isFile(), 'bin ran, creating file')
|
||||
})
|
||||
|
||||
t.test('--prefix', async t => {
|
||||
const registry = new MockRegistry({
|
||||
tap: t,
|
||||
registry: 'https://registry.npmjs.org/',
|
||||
})
|
||||
|
||||
const manifest = registry.manifest({ name: '@npmcli/npx-test' })
|
||||
manifest.versions['1.0.0'].bin = { 'npx-test': 'index.js' }
|
||||
|
||||
const { npm } = await loadMockNpm(t, {
|
||||
config: {
|
||||
audit: false,
|
||||
yes: true,
|
||||
},
|
||||
prefixDir: {
|
||||
'npm-exec-test': {
|
||||
'package.json': JSON.stringify(manifest),
|
||||
'index.js': `#!/usr/bin/env node
|
||||
require('fs').writeFileSync('npm-exec-test-success', '')`,
|
||||
},
|
||||
},
|
||||
globals: ({ prefix }) => ({
|
||||
'process.cwd': () => prefix,
|
||||
}),
|
||||
})
|
||||
|
||||
// This is what `--prefix` does
|
||||
npm.globalPrefix = npm.localPrefix
|
||||
|
||||
await registry.package({
|
||||
manifest,
|
||||
tarballs: {
|
||||
'1.0.0': path.join(npm.prefix, 'npm-exec-test'),
|
||||
@@ -65,6 +105,7 @@ t.test('workspaces', async t => {
|
||||
|
||||
const { npm } = await loadMockNpm(t, {
|
||||
config: {
|
||||
audit: false,
|
||||
yes: true,
|
||||
workspace: ['workspace-a'],
|
||||
},
|
||||
|
||||
Vendored
+1
-1
@@ -371,7 +371,7 @@ t.test('workspaces', t => {
|
||||
})
|
||||
const init = new Init(npm)
|
||||
await init.execWorkspaces([], ['a'])
|
||||
const output = npm._mockOutputs.map(arr => arr.map(i => i.replace(/[0-9]*ms$/, '100ms')))
|
||||
const output = npm._mockOutputs.map(arr => arr.map(i => i.replace(/[0-9]*m?s$/, '100ms')))
|
||||
t.matchSnapshot(output, 'should print helper info')
|
||||
const lockFilePath = resolve(npm.localPrefix, 'package-lock.json')
|
||||
const lockFile = fs.readFileSync(lockFilePath, { encoding: 'utf8' })
|
||||
|
||||
+7
-10
@@ -1,5 +1,3 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const t = require('tap')
|
||||
const tspawk = require('../../fixtures/tspawk')
|
||||
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
|
||||
@@ -26,15 +24,14 @@ t.test('should run restart script from package.json', async t => {
|
||||
loglevel: 'silent',
|
||||
},
|
||||
})
|
||||
const [scriptShell] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-restart.js' })
|
||||
const script = spawk.spawn(scriptShell, (args) => {
|
||||
const lastArg = args[args.length - 1]
|
||||
const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')
|
||||
const rightFilename = path.basename(lastArg).startsWith('restart')
|
||||
const rightContents = fs.readFileSync(lastArg, { encoding: 'utf8' })
|
||||
.trim().endsWith('foo')
|
||||
return rightExtension && rightFilename && rightContents
|
||||
const [scriptShell, scriptArgs] = makeSpawnArgs({
|
||||
path: npm.prefix,
|
||||
cmd: 'node ./test-restart.js',
|
||||
})
|
||||
let scriptContent = scriptArgs.pop()
|
||||
scriptContent += ' foo'
|
||||
scriptArgs.push(scriptContent)
|
||||
const script = spawk.spawn(scriptShell, scriptArgs)
|
||||
await npm.exec('restart', ['foo'])
|
||||
t.ok(script.called, 'script ran')
|
||||
})
|
||||
Vendored
+6
-11
@@ -1,5 +1,3 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const t = require('tap')
|
||||
const tspawk = require('../../fixtures/tspawk')
|
||||
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
|
||||
@@ -26,15 +24,12 @@ t.test('should run start script from package.json', async t => {
|
||||
loglevel: 'silent',
|
||||
},
|
||||
})
|
||||
const [scriptShell] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-start.js' })
|
||||
const script = spawk.spawn(scriptShell, (args) => {
|
||||
const lastArg = args[args.length - 1]
|
||||
const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')
|
||||
const rightFilename = path.basename(lastArg).startsWith('start')
|
||||
const rightContents = fs.readFileSync(lastArg, { encoding: 'utf8' })
|
||||
.trim().endsWith('foo')
|
||||
return rightExtension && rightFilename && rightContents
|
||||
})
|
||||
const [scriptShell, scriptArgs] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-start.js' })
|
||||
// we're calling the script with 'foo' as an argument, so add that to the script
|
||||
let scriptContent = scriptArgs.pop()
|
||||
scriptContent += ' foo'
|
||||
scriptArgs.push(scriptContent)
|
||||
const script = spawk.spawn(scriptShell, scriptArgs)
|
||||
await npm.exec('start', ['foo'])
|
||||
t.ok(script.called, 'script ran')
|
||||
})
|
||||
Vendored
+5
-11
@@ -1,5 +1,3 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const t = require('tap')
|
||||
const tspawk = require('../../fixtures/tspawk')
|
||||
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
|
||||
@@ -26,15 +24,11 @@ t.test('should run stop script from package.json', async t => {
|
||||
loglevel: 'silent',
|
||||
},
|
||||
})
|
||||
const [scriptShell] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-stop.js' })
|
||||
const script = spawk.spawn(scriptShell, (args) => {
|
||||
const lastArg = args[args.length - 1]
|
||||
const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')
|
||||
const rightFilename = path.basename(lastArg).startsWith('stop')
|
||||
const rightContents = fs.readFileSync(lastArg, { encoding: 'utf8' })
|
||||
.trim().endsWith('foo')
|
||||
return rightExtension && rightFilename && rightContents
|
||||
})
|
||||
const [scriptShell, scriptArgs] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-stop.js' })
|
||||
let scriptContent = scriptArgs.pop()
|
||||
scriptContent += ' foo'
|
||||
scriptArgs.push(scriptContent)
|
||||
const script = spawk.spawn(scriptShell, scriptArgs)
|
||||
await npm.exec('stop', ['foo'])
|
||||
t.ok(script.called, 'script ran')
|
||||
})
|
||||
Vendored
+5
-11
@@ -1,5 +1,3 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const t = require('tap')
|
||||
const tspawk = require('../../fixtures/tspawk')
|
||||
const { load: loadMockNpm } = require('../../fixtures/mock-npm')
|
||||
@@ -26,15 +24,11 @@ t.test('should run test script from package.json', async t => {
|
||||
loglevel: 'silent',
|
||||
},
|
||||
})
|
||||
const [scriptShell] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-test.js' })
|
||||
const script = spawk.spawn(scriptShell, (args) => {
|
||||
const lastArg = args[args.length - 1]
|
||||
const rightExtension = lastArg.endsWith('.cmd') || lastArg.endsWith('.sh')
|
||||
const rightFilename = path.basename(lastArg).startsWith('test')
|
||||
const rightContents = fs.readFileSync(lastArg, { encoding: 'utf8' })
|
||||
.trim().endsWith('foo')
|
||||
return rightExtension && rightFilename && rightContents
|
||||
})
|
||||
const [scriptShell, scriptArgs] = makeSpawnArgs({ path: npm.prefix, cmd: 'node ./test-test.js' })
|
||||
let scriptContent = scriptArgs.pop()
|
||||
scriptContent += ' foo'
|
||||
scriptArgs.push(scriptContent)
|
||||
const script = spawk.spawn(scriptShell, scriptArgs)
|
||||
await npm.exec('test', ['foo'])
|
||||
t.ok(script.called, 'script ran')
|
||||
})
|
||||
Reference in new issue
Block a user