Added remote folder

This commit is contained in:
Kasper Rynning-Tønnesen
2015-11-29 13:30:54 +01:00
parent 97e7dfd7c4
commit 95bb0c3919
3521 changed files with 331825 additions and 0 deletions

20
server/node_modules/gulp-util/LICENSE generated vendored Executable file
View File

@@ -0,0 +1,20 @@
Copyright (c) 2014 Fractal <contact@wearefractal.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,32 @@
'use strict';
// WARNING: This undocumented API is subject to change.
module.exports = function (process) {
var unhandledRejections = [];
process.on('unhandledRejection', function (reason, p) {
unhandledRejections.push({reason: reason, promise: p});
});
process.on('rejectionHandled', function (p) {
var index = unhandledRejections.reduce(function (result, item, idx) {
return (item.promise === p ? idx : result);
}, -1);
unhandledRejections.splice(index, 1);
});
function currentlyUnhandled() {
return unhandledRejections.map(function (entry) {
return {
reason: entry.reason,
promise: entry.promise
};
});
}
return {
currentlyUnhandled: currentlyUnhandled
};
};

View File

@@ -0,0 +1,37 @@
'use strict';
var onExit = require('signal-exit');
var api = require('./api');
var installed = false;
function outputRejectedMessage(err) {
if (err instanceof Error) {
console.error(err.stack);
} else if (typeof err === 'undefined') {
console.error('Promise rejected no value');
} else {
console.error('Promise rejected with value:', err);
}
}
module.exports = function () {
if (installed) {
console.trace('WARN: loud rejection called more than once');
return;
}
installed = true;
var tracker = api(process);
onExit(function () {
var unhandledRejections = tracker.currentlyUnhandled();
if (unhandledRejections.length > 0) {
unhandledRejections.forEach(function (x) {
outputRejectedMessage(x.reason);
});
process.exitCode = 1;
}
});
};

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,4 @@
node_modules
.DS_Store
nyc_output
coverage

View File

@@ -0,0 +1,7 @@
sudo: false
language: node_js
node_js:
- '0.12'
- '0.10'
- iojs
after_success: npm run coverage

View File

@@ -0,0 +1,14 @@
Copyright (c) 2015, 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.

View File

@@ -0,0 +1,38 @@
# signal-exit
[![Build Status](https://travis-ci.org/bcoe/signal-exit.png)](https://travis-ci.org/bcoe/signal-exit)
[![Coverage Status](https://coveralls.io/repos/bcoe/signal-exit/badge.svg?branch=)](https://coveralls.io/r/bcoe/signal-exit?branch=)
[![NPM version](https://img.shields.io/npm/v/signal-exit.svg)](https://www.npmjs.com/package/signal-exit)
When you want to fire an event no matter how a process exits:
* reaching the end of execution.
* explicitly having `process.exit(code)` called.
* having `process.kill(pid, sig)` called.
* receiving a fatal signal from outside the process
Use `signal-exit`.
```js
var onExit = require('signal-exit')
onExit(function (code, signal) {
console.log('process exited!')
})
```
## API
`var remove = onExit(function (code, signal) {}, options)`
The return value of the function is a function that will remove the
handler.
Note that the function *only* fires for signals if the signal would
cause the proces to exit. That is, there are no other listeners, and
it is a fatal signal.
## Options
* `alwaysLast`: Run this handler after any other signal or exit
handlers. This causes `process.emit` to be monkeypatched.

View File

@@ -0,0 +1,148 @@
// Note: since nyc uses this module to output coverage, any lines
// that are in the direct sync flow of nyc's outputCoverage are
// ignored, since we can never get coverage for them.
var assert = require('assert')
var signals = require('./signals.js')
var EE = require('events')
/* istanbul ignore if */
if (typeof EE !== 'function') {
EE = EE.EventEmitter
}
var emitter
if (process.__signal_exit_emitter__) {
emitter = process.__signal_exit_emitter__
} else {
emitter = process.__signal_exit_emitter__ = new EE()
emitter.count = 0
emitter.emitted = {}
}
module.exports = function (cb, opts) {
assert.equal(typeof cb, 'function', 'a callback must be provided for exit handler')
if (loaded === false) {
load()
}
var ev = 'exit'
if (opts && opts.alwaysLast) {
ev = 'afterexit'
}
var remove = function () {
emitter.removeListener(ev, cb)
if (emitter.listeners('exit').length === 0 &&
emitter.listeners('afterexit').length === 0) {
unload()
}
}
emitter.on(ev, cb)
return remove
}
module.exports.unload = unload
function unload () {
if (!loaded) {
return
}
loaded = false
signals.forEach(function (sig) {
try {
process.removeListener(sig, sigListeners[sig])
} catch (er) {}
})
process.emit = originalProcessEmit
process.reallyExit = originalProcessReallyExit
emitter.count -= 1
}
function emit (event, code, signal) {
if (emitter.emitted[event]) {
return
}
emitter.emitted[event] = true
emitter.emit(event, code, signal)
}
// { <signal>: <listener fn>, ... }
var sigListeners = {}
signals.forEach(function (sig) {
sigListeners[sig] = function listener () {
// If there are no other listeners, an exit is coming!
// Simplest way: remove us and then re-send the signal.
// We know that this will kill the process, so we can
// safely emit now.
var listeners = process.listeners(sig)
if (listeners.length === emitter.count) {
unload()
emit('exit', null, sig)
/* istanbul ignore next */
emit('afterexit', null, sig)
/* istanbul ignore next */
process.kill(process.pid, sig)
}
}
})
module.exports.signals = function () {
return signals
}
module.exports.load = load
var loaded = false
function load () {
if (loaded) {
return
}
loaded = true
// This is the number of onSignalExit's that are in play.
// It's important so that we can count the correct number of
// listeners on signals, and don't wait for the other one to
// handle it instead of us.
emitter.count += 1
signals = signals.filter(function (sig) {
try {
process.on(sig, sigListeners[sig])
return true
} catch (er) {
return false
}
})
process.emit = processEmit
process.reallyExit = processReallyExit
}
var originalProcessReallyExit = process.reallyExit
function processReallyExit (code) {
process.exitCode = code || 0
emit('exit', process.exitCode, null)
/* istanbul ignore next */
emit('afterexit', process.exitCode, null)
/* istanbul ignore next */
originalProcessReallyExit.call(process, process.exitCode)
}
var originalProcessEmit = process.emit
function processEmit (ev, arg) {
if (ev === 'exit') {
if (arg !== undefined) {
process.exitCode = arg
}
var ret = originalProcessEmit.apply(this, arguments)
emit('exit', process.exitCode, null)
/* istanbul ignore next */
emit('afterexit', process.exitCode, null)
return ret
} else {
return originalProcessEmit.apply(this, arguments)
}
}

View File

@@ -0,0 +1,61 @@
{
"name": "signal-exit",
"version": "2.1.2",
"description": "when you want to fire an event no matter how a process exits.",
"main": "index.js",
"scripts": {
"test": "standard && nyc tap --timeout=240 ./test/*.js",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},
"repository": {
"type": "git",
"url": "git+https://github.com/bcoe/signal-exit.git"
},
"keywords": [
"signal",
"exit"
],
"author": {
"name": "Ben Coe",
"email": "ben@npmjs.com"
},
"license": "ISC",
"bugs": {
"url": "https://github.com/bcoe/signal-exit/issues"
},
"homepage": "https://github.com/bcoe/signal-exit",
"devDependencies": {
"chai": "^2.3.0",
"coveralls": "^2.11.2",
"nyc": "^2.1.2",
"standard": "^3.9.0",
"tap": "1.0.4"
},
"gitHead": "8d50231bda6d0d1c4d39de20fc09d11487eb9951",
"_id": "signal-exit@2.1.2",
"_shasum": "375879b1f92ebc3b334480d038dc546a6d558564",
"_from": "signal-exit@^2.1.2",
"_npmVersion": "2.9.0",
"_nodeVersion": "2.0.2",
"_npmUser": {
"name": "bcoe",
"email": "ben@npmjs.com"
},
"dist": {
"shasum": "375879b1f92ebc3b334480d038dc546a6d558564",
"tarball": "http://registry.npmjs.org/signal-exit/-/signal-exit-2.1.2.tgz"
},
"maintainers": [
{
"name": "bcoe",
"email": "ben@npmjs.com"
},
{
"name": "isaacs",
"email": "isaacs@npmjs.com"
}
],
"directories": {},
"_resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-2.1.2.tgz",
"readme": "ERROR: No README data found!"
}

View File

@@ -0,0 +1,47 @@
// This is not the set of all possible signals.
//
// It IS, however, the set of all signals that trigger
// an exit on either Linux or BSD systems. Linux is a
// superset of the signal names supported on BSD, and
// the unknown signals just fail to register, so we can
// catch that easily enough.
//
// Don't bother with SIGKILL. It's uncatchable, which
// means that we can't fire any callbacks anyway.
//
// If a user does happen to register a handler on a non-
// fatal signal like SIGWINCH or something, and then
// exit, it'll end up firing `process.emit('exit')`, so
// the handler will be fired anyway.
module.exports = [
'SIGABRT',
'SIGALRM',
'SIGBUS',
'SIGFPE',
'SIGHUP',
'SIGILL',
'SIGINT',
'SIGIOT',
'SIGPIPE',
'SIGPROF',
'SIGQUIT',
'SIGSEGV',
'SIGSYS',
'SIGTERM',
'SIGTRAP',
'SIGUSR2',
'SIGVTALRM',
'SIGXCPU',
'SIGXFSZ'
]
if (process.platform === 'linux') {
module.exports.push(
'SIGIO',
'SIGPOLL',
'SIGPWR',
'SIGSTKFLT',
'SIGUNUSED'
)
}

View File

@@ -0,0 +1,94 @@
/* global describe, it */
var exec = require('child_process').exec,
assert = require('assert')
require('chai').should()
require('tap').mochaGlobals()
var onSignalExit = require('../')
describe('all-signals-integration-test', function () {
// These are signals that are aliases for other signals, so
// the result will sometimes be one of the others. For these,
// we just verify that we GOT a signal, not what it is.
function weirdSignal (sig) {
return sig === 'SIGIOT' ||
sig === 'SIGIO' ||
sig === 'SIGSYS' ||
sig === 'SIGIOT' ||
sig === 'SIGABRT' ||
sig === 'SIGPOLL' ||
sig === 'SIGUNUSED'
}
// Exhaustively test every signal, and a few numbers.
var signals = onSignalExit.signals()
signals.concat('', 0, 1, 2, 3, 54).forEach(function (sig) {
var node = process.execPath
var js = require.resolve('./fixtures/exiter.js')
it('exits properly: ' + sig, function (done) {
// travis has issues with SIGUSR1 on Node 0.x.10.
if (process.env.TRAVIS && sig === 'SIGUSR1') return done()
exec(node + ' ' + js + ' ' + sig, function (err, stdout, stderr) {
if (sig) {
assert(err)
if (!isNaN(sig)) {
assert.equal(err.code, sig)
} else if (!weirdSignal(sig)) {
if (!process.env.TRAVIS) err.signal.should.equal(sig)
} else if (sig) {
if (!process.env.TRAVIS) assert(err.signal)
}
} else {
assert.ifError(err)
}
try {
var data = JSON.parse(stdout)
} catch (er) {
console.error('invalid json: %j', stdout, stderr)
throw er
}
if (weirdSignal(sig)) {
data.wanted[1] = true
data.found[1] = !!data.found[1]
}
assert.deepEqual(data.found, data.wanted)
done()
})
})
})
signals.forEach(function (sig) {
var node = process.execPath
var js = require.resolve('./fixtures/parent.js')
it('exits properly: (external sig) ' + sig, function (done) {
// travis has issues with SIGUSR1 on Node 0.x.10.
if (process.env.TRAVIS && sig === 'SIGUSR1') return done()
var cmd = node + ' ' + js + ' ' + sig
exec(cmd, function (err, stdout, stderr) {
assert.ifError(err)
try {
var data = JSON.parse(stdout)
} catch (er) {
console.error('invalid json: %j', stdout, stderr)
throw er
}
if (weirdSignal(sig)) {
data.wanted[1] = true
data.found[1] = !!data.found[1]
data.external[1] = !!data.external[1]
}
assert.deepEqual(data.found, data.wanted)
assert.deepEqual(data.external, data.wanted)
done()
})
})
})
})

View File

@@ -0,0 +1,35 @@
var expectSignal = process.argv[2]
if (!expectSignal || !isNaN(expectSignal)) {
throw new Error('signal not provided')
}
var onSignalExit = require('../../')
onSignalExit(function (code, signal) {
// some signals don't always get recognized properly, because
// they have the same numeric code.
if (wanted[1] === true) {
signal = !!signal
}
console.log('%j', {
found: [ code, signal ],
wanted: wanted
})
})
var wanted
switch (expectSignal) {
case 'SIGIOT':
case 'SIGUNUSED':
case 'SIGPOLL':
wanted = [ null, true ]
break
default:
wanted = [ null, expectSignal ]
break
}
console.error('want', wanted)
setTimeout(function () {}, 1000)

View File

@@ -0,0 +1,800 @@
{
"explicit 0 nochange sigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 0,
"actualSignal": null,
"stderr": [
"first code=0",
"second code=0"
]
},
"explicit 0 nochange nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 0,
"actualSignal": null,
"stderr": [
"first code=0",
"second code=0"
]
},
"explicit 0 change sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"explicit 0 change nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"explicit 0 code sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"second code=0"
]
},
"explicit 0 code nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"second code=0"
]
},
"explicit 0 twice sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"explicit 0 twice nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"explicit 0 twicecode sigexit": {
"code": 6,
"signal": null,
"exitCode": 6,
"actualCode": 6,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"set code from 5 to 6"
]
},
"explicit 0 twicecode nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 6,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"set code from 5 to 6"
]
},
"explicit 2 nochange sigexit": {
"code": 2,
"signal": null,
"exitCode": 2,
"actualCode": 2,
"actualSignal": null,
"stderr": [
"first code=2",
"second code=2"
]
},
"explicit 2 nochange nosigexit": {
"code": 2,
"signal": null,
"exitCode": 2,
"actualCode": 2,
"actualSignal": null,
"stderr": [
"first code=2",
"second code=2"
]
},
"explicit 2 change sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=2",
"set code from 2 to 5"
]
},
"explicit 2 change nosigexit": {
"code": 2,
"signal": null,
"exitCode": 2,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=2",
"set code from 2 to 5"
]
},
"explicit 2 code sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=2",
"set code from 2 to 5",
"second code=2"
]
},
"explicit 2 code nosigexit": {
"code": 2,
"signal": null,
"exitCode": 2,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=2",
"set code from 2 to 5",
"second code=2"
]
},
"explicit 2 twice sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=2",
"set code from 2 to 5"
]
},
"explicit 2 twice nosigexit": {
"code": 2,
"signal": null,
"exitCode": 2,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=2",
"set code from 2 to 5"
]
},
"explicit 2 twicecode sigexit": {
"code": 6,
"signal": null,
"exitCode": 6,
"actualCode": 6,
"actualSignal": null,
"stderr": [
"first code=2",
"set code from 2 to 5",
"set code from 5 to 6"
]
},
"explicit 2 twicecode nosigexit": {
"code": 2,
"signal": null,
"exitCode": 2,
"actualCode": 6,
"actualSignal": null,
"stderr": [
"first code=2",
"set code from 2 to 5",
"set code from 5 to 6"
]
},
"explicit null nochange sigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 0,
"actualSignal": null,
"stderr": [
"first code=0",
"second code=0"
]
},
"explicit null nochange nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 0,
"actualSignal": null,
"stderr": [
"first code=0",
"second code=0"
]
},
"explicit null change sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"explicit null change nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"explicit null code sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"second code=0"
]
},
"explicit null code nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"second code=0"
]
},
"explicit null twice sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"explicit null twice nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"explicit null twicecode sigexit": {
"code": 6,
"signal": null,
"exitCode": 6,
"actualCode": 6,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"set code from 5 to 6"
]
},
"explicit null twicecode nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 6,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"set code from 5 to 6"
]
},
"code 0 nochange sigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 0,
"actualSignal": null,
"stderr": [
"first code=0",
"second code=0"
]
},
"code 0 nochange nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 0,
"actualSignal": null,
"stderr": [
"first code=0",
"second code=0"
]
},
"code 0 change sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"code 0 change nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"code 0 code sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"second code=0"
]
},
"code 0 code nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"second code=0"
]
},
"code 0 twice sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"code 0 twice nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"code 0 twicecode sigexit": {
"code": 6,
"signal": null,
"exitCode": 6,
"actualCode": 6,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"set code from 5 to 6"
]
},
"code 0 twicecode nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 6,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"set code from 5 to 6"
]
},
"code 2 nochange sigexit": {
"code": 2,
"signal": null,
"exitCode": 2,
"actualCode": 2,
"actualSignal": null,
"stderr": [
"first code=2",
"second code=2"
]
},
"code 2 nochange nosigexit": {
"code": 2,
"signal": null,
"exitCode": 2,
"actualCode": 2,
"actualSignal": null,
"stderr": [
"first code=2",
"second code=2"
]
},
"code 2 change sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=2",
"set code from 2 to 5"
]
},
"code 2 change nosigexit": {
"code": 2,
"signal": null,
"exitCode": 2,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=2",
"set code from 2 to 5"
]
},
"code 2 code sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=2",
"set code from 2 to 5",
"second code=2"
]
},
"code 2 code nosigexit": {
"code": 2,
"signal": null,
"exitCode": 2,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=2",
"set code from 2 to 5",
"second code=2"
]
},
"code 2 twice sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=2",
"set code from 2 to 5"
]
},
"code 2 twice nosigexit": {
"code": 2,
"signal": null,
"exitCode": 2,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=2",
"set code from 2 to 5"
]
},
"code 2 twicecode sigexit": {
"code": 6,
"signal": null,
"exitCode": 6,
"actualCode": 6,
"actualSignal": null,
"stderr": [
"first code=2",
"set code from 2 to 5",
"set code from 5 to 6"
]
},
"code 2 twicecode nosigexit": {
"code": 2,
"signal": null,
"exitCode": 2,
"actualCode": 6,
"actualSignal": null,
"stderr": [
"first code=2",
"set code from 2 to 5",
"set code from 5 to 6"
]
},
"code null nochange sigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 0,
"actualSignal": null,
"stderr": [
"first code=0",
"second code=0"
]
},
"code null nochange nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 0,
"actualSignal": null,
"stderr": [
"first code=0",
"second code=0"
]
},
"code null change sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"code null change nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"code null code sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"second code=0"
]
},
"code null code nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"second code=0"
]
},
"code null twice sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"code null twice nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"code null twicecode sigexit": {
"code": 6,
"signal": null,
"exitCode": 6,
"actualCode": 6,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"set code from 5 to 6"
]
},
"code null twicecode nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 6,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"set code from 5 to 6"
]
},
"normal 0 nochange sigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 0,
"actualSignal": null,
"stderr": [
"first code=0",
"second code=0"
]
},
"normal 0 nochange nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 0,
"actualSignal": null,
"stderr": [
"first code=0",
"second code=0"
]
},
"normal 0 change sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"normal 0 change nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"normal 0 code sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"second code=0"
]
},
"normal 0 code nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"second code=0"
]
},
"normal 0 twice sigexit": {
"code": 5,
"signal": null,
"exitCode": 5,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"normal 0 twice nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 5,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5"
]
},
"normal 0 twicecode sigexit": {
"code": 6,
"signal": null,
"exitCode": 6,
"actualCode": 6,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"set code from 5 to 6"
]
},
"normal 0 twicecode nosigexit": {
"code": 0,
"signal": null,
"exitCode": 0,
"actualCode": 6,
"actualSignal": null,
"stderr": [
"first code=0",
"set code from 0 to 5",
"set code from 5 to 6"
]
}
}

View File

@@ -0,0 +1,96 @@
if (process.argv.length === 2) {
var types = [ 'explicit', 'code', 'normal' ]
var codes = [ 0, 2, 'null' ]
var changes = [ 'nochange', 'change', 'code', 'twice', 'twicecode']
var handlers = [ 'sigexit', 'nosigexit' ]
var opts = []
types.forEach(function (type) {
var testCodes = type === 'normal' ? [ 0 ] : codes
testCodes.forEach(function (code) {
changes.forEach(function (change) {
handlers.forEach(function (handler) {
opts.push([type, code, change, handler].join(' '))
})
})
})
})
var results = {}
var exec = require('child_process').exec
run(opts.shift())
} else {
var type = process.argv[2]
var code = +process.argv[3]
var change = process.argv[4]
var sigexit = process.argv[5] !== 'nosigexit'
if (sigexit) {
var onSignalExit = require('../../')
onSignalExit(listener)
} else {
process.on('exit', listener)
}
process.on('exit', function (code) {
console.error('first code=%j', code)
})
if (change !== 'nochange') {
process.once('exit', function (code) {
console.error('set code from %j to %j', code, 5)
if (change === 'code' || change === 'twicecode') {
process.exitCode = 5
} else {
process.exit(5)
}
})
if (change === 'twicecode' || change === 'twice') {
process.once('exit', function (code) {
code = process.exitCode || code
console.error('set code from %j to %j', code, code + 1)
process.exit(code + 1)
})
}
}
process.on('exit', function (code) {
console.error('second code=%j', code)
})
if (type === 'explicit') {
if (code || code === 0) {
process.exit(code)
} else {
process.exit()
}
} else if (type === 'code') {
process.exitCode = +code || 0
}
}
function listener (code, signal) {
signal = signal || null
console.log('%j', { code: code, signal: signal, exitCode: process.exitCode || 0 })
}
function run (opt) {
console.error(opt)
exec(process.execPath + ' ' + __filename + ' ' + opt, function (err, stdout, stderr) {
var res = JSON.parse(stdout)
if (err) {
res.actualCode = err.code
res.actualSignal = err.signal
} else {
res.actualCode = 0
res.actualSignal = null
}
res.stderr = stderr.trim().split('\n')
results[opt] = res
if (opts.length) {
run(opts.shift())
} else {
console.log(JSON.stringify(results, null, 2))
}
})
}

View File

@@ -0,0 +1,5 @@
var onSignalExit = require('../../')
onSignalExit(function (code, signal) {
console.log('reached end of execution, ' + code + ', ' + signal)
})

View File

@@ -0,0 +1,14 @@
var onSignalExit = require('../../')
var counter = 0
onSignalExit(function (code, signal) {
counter++
console.log('last counter=%j, code=%j, signal=%j',
counter, code, signal)
}, {alwaysLast: true})
onSignalExit(function (code, signal) {
counter++
console.log('first counter=%j, code=%j, signal=%j',
counter, code, signal)
})

View File

@@ -0,0 +1,7 @@
var onSignalExit = require('../../')
onSignalExit(function (code, signal) {
console.log('exited with process.exit(), ' + code + ', ' + signal)
})
process.exit(32)

View File

@@ -0,0 +1,45 @@
var exit = process.argv[2] || 0
var onSignalExit = require('../../')
onSignalExit(function (code, signal) {
// some signals don't always get recognized properly, because
// they have the same numeric code.
if (wanted[1] === true) {
signal = !!signal
}
console.log('%j', {
found: [ code, signal ],
wanted: wanted
})
})
var wanted
if (isNaN(exit)) {
switch (exit) {
case 'SIGIOT':
case 'SIGUNUSED':
case 'SIGPOLL':
wanted = [ null, true ]
break
default:
wanted = [ null, exit ]
break
}
try {
process.kill(process.pid, exit)
setTimeout(function () {}, 1000)
} catch (er) {
wanted = [ 0, null ]
}
} else {
exit = +exit
wanted = [ exit, null ]
// If it's explicitly requested 0, then explicitly call it.
// "no arg" = "exit naturally"
if (exit || process.argv[2]) {
process.exit(exit)
}
}

View File

@@ -0,0 +1,7 @@
// just be silly with calling these functions a bunch
// mostly just to get coverage of the guard branches
var onSignalExit = require('../../')
onSignalExit.load()
onSignalExit.load()
onSignalExit.unload()
onSignalExit.unload()

View File

@@ -0,0 +1,52 @@
// simulate cases where the module could be loaded from multiple places
var onSignalExit = require('../../')
var counter = 0
onSignalExit(function (code, signal) {
counter++
console.log('last counter=%j, code=%j, signal=%j',
counter, code, signal)
}, {alwaysLast: true})
onSignalExit(function (code, signal) {
counter++
console.log('first counter=%j, code=%j, signal=%j',
counter, code, signal)
})
delete require('module')._cache[require.resolve('../../')]
var onSignalExit = require('../../')
onSignalExit(function (code, signal) {
counter++
console.log('last counter=%j, code=%j, signal=%j',
counter, code, signal)
}, {alwaysLast: true})
onSignalExit(function (code, signal) {
counter++
console.log('first counter=%j, code=%j, signal=%j',
counter, code, signal)
})
// Lastly, some that should NOT be shown
delete require('module')._cache[require.resolve('../../')]
var onSignalExit = require('../../')
var unwrap = onSignalExit(function (code, signal) {
counter++
console.log('last counter=%j, code=%j, signal=%j',
counter, code, signal)
}, {alwaysLast: true})
unwrap()
unwrap = onSignalExit(function (code, signal) {
counter++
console.log('first counter=%j, code=%j, signal=%j',
counter, code, signal)
})
unwrap()
process.kill(process.pid, 'SIGHUP')
setTimeout(function () {}, 1000)

View File

@@ -0,0 +1,51 @@
var signal = process.argv[2]
var gens = +process.argv[3] || 0
if (!signal || !isNaN(signal)) {
throw new Error('signal not provided')
}
var spawn = require('child_process').spawn
var file = require.resolve('./awaiter.js')
console.error(process.pid, signal, gens)
if (gens > 0) {
file = __filename
}
var child = spawn(process.execPath, [file, signal, gens - 1], {
stdio: [ 0, 'pipe', 'pipe' ]
})
if (!gens) {
child.stderr.on('data', function () {
child.kill(signal)
})
}
var result = ''
child.stdout.on('data', function (c) {
result += c
})
child.on('close', function (code, sig) {
try {
result = JSON.parse(result)
} catch (er) {
console.log('%j', {
error: 'failed to parse json\n' + er.message,
result: result,
pid: process.pid,
child: child.pid,
gens: gens,
expect: [ null, signal ],
actual: [ code, sig ]
})
return
}
if (result.wanted[1] === true) {
sig = !!sig
}
result.external = result.external || [ code, sig ]
console.log('%j', result)
})

View File

@@ -0,0 +1,11 @@
var onSignalExit = require('../../')
onSignalExit(function (code, signal) {
console.log('exited with sigint, ' + code + ', ' + signal)
})
// For some reason, signals appear to not always be fast enough
// to come in before the process exits. Just a few ticks needed.
setTimeout(function () {}, 1000)
process.kill(process.pid, 'SIGINT')

View File

@@ -0,0 +1,19 @@
// SIGKILL can't be caught, and in fact, even trying to add the
// listener will throw an error.
// We handle that nicely.
//
// This is just here to get another few more lines of test
// coverage. That's also why it lies about being on a linux
// platform so that we pull in those other event types.
Object.defineProperty(process, 'platform', {
value: 'linux',
writable: false,
enumerable: true,
configurable: true
})
var signals = require('../../signals.js')
signals.push('SIGKILL')
var onSignalExit = require('../../')
onSignalExit.load()

View File

@@ -0,0 +1,99 @@
// This fixture is not used in any tests. It is here merely as a way to
// do research into the various signal behaviors on Linux and Darwin.
// Run with no args to cycle through every signal type. Run with a signal
// arg to learn about how that signal behaves.
if (process.argv[2]) {
child(process.argv[2])
} else {
var signals = [
'SIGABRT',
'SIGALRM',
'SIGBUS',
'SIGCHLD',
'SIGCLD',
'SIGCONT',
'SIGEMT',
'SIGFPE',
'SIGHUP',
'SIGILL',
'SIGINFO',
'SIGINT',
'SIGIO',
'SIGIOT',
'SIGKILL',
'SIGLOST',
'SIGPIPE',
'SIGPOLL',
'SIGPROF',
'SIGPWR',
'SIGQUIT',
'SIGSEGV',
'SIGSTKFLT',
'SIGSTOP',
'SIGSYS',
'SIGTERM',
'SIGTRAP',
'SIGTSTP',
'SIGTTIN',
'SIGTTOU',
'SIGUNUSED',
'SIGURG',
'SIGUSR1',
'SIGUSR2',
'SIGVTALRM',
'SIGWINCH',
'SIGXCPU',
'SIGXFSZ'
]
var spawn = require('child_process').spawn
;(function test (signal) {
if (!signal) {
return
}
var child = spawn(process.execPath, [__filename, signal], { stdio: 'inherit' })
var timer = setTimeout(function () {
console.log('requires SIGCONT')
process.kill(child.pid, 'SIGCONT')
}, 750)
child.on('close', function (code, signal) {
console.log('code=%j signal=%j\n', code, signal)
clearTimeout(timer)
test(signals.pop())
})
})(signals.pop())
}
function child (signal) {
console.log('signal=%s', signal)
// set a timeout so we know whether or not the process terminated.
setTimeout(function () {
console.log('not terminated')
}, 200)
process.on('exit', function (code) {
console.log('emit exit code=%j', code)
})
try {
process.on(signal, function fn () {
console.log('signal is catchable', signal)
process.removeListener(signal, fn)
setTimeout(function () {
console.error('signal again')
process.kill(process.pid, signal)
})
})
} catch (er) {
console.log('not listenable')
}
try {
process.kill(process.pid, signal)
} catch (er) {
console.log('not issuable')
}
}

View File

@@ -0,0 +1,17 @@
var onSignalExit = require('../../')
var counter = 0
onSignalExit(function (code, signal) {
counter++
console.log('last counter=%j, code=%j, signal=%j',
counter, code, signal)
}, {alwaysLast: true})
onSignalExit(function (code, signal) {
counter++
console.log('first counter=%j, code=%j, signal=%j',
counter, code, signal)
})
process.kill(process.pid, 'SIGHUP')
setTimeout(function () {}, 1000)

View File

@@ -0,0 +1,23 @@
var onSignalExit = require('../../')
setTimeout(function () {})
var calledListener = 0
onSignalExit(function (code, signal) {
console.log('exited calledListener=%j, code=%j, signal=%j',
calledListener, code, signal)
})
process.on('SIGHUP', listener)
process.kill(process.pid, 'SIGHUP')
function listener () {
calledListener++
if (calledListener > 3) {
process.removeListener('SIGHUP', listener)
}
setTimeout(function () {
process.kill(process.pid, 'SIGHUP')
})
}

View File

@@ -0,0 +1,8 @@
var onSignalExit = require('../..')
onSignalExit(function (code, signal) {
console.error('onSignalExit(%j,%j)', code, signal)
})
setTimeout(function () {
console.log('hello')
})
process.kill(process.pid, 'SIGPIPE')

View File

@@ -0,0 +1,9 @@
var onSignalExit = require('../../')
onSignalExit(function (code, signal) {
console.log('exited with sigterm, ' + code + ', ' + signal)
})
setTimeout(function () {}, 1000)
process.kill(process.pid, 'SIGTERM')

View File

@@ -0,0 +1,37 @@
// simulate cases where the module could be loaded from multiple places
// Need to lie about this a little bit, since nyc uses this module
// for its coverage wrap-up handling
if (process.env.NYC_CWD) {
var emitter = process.__signal_exit_emitter__
var listeners = emitter.listeners('afterexit')
process.removeAllListeners('SIGHUP')
delete process.__signal_exit_emitter__
delete require('module')._cache[require.resolve('../../')]
}
var onSignalExit = require('../../')
var counter = 0
var unwrap = onSignalExit(function (code, signal) {
counter++
console.log('last counter=%j, code=%j, signal=%j',
counter, code, signal)
}, {alwaysLast: true})
unwrap()
unwrap = onSignalExit(function (code, signal) {
counter++
console.log('first counter=%j, code=%j, signal=%j',
counter, code, signal)
})
unwrap()
if (global.__coverage__ && listeners && listeners.length) {
listeners.forEach(function (fn) {
onSignalExit(fn, { alwaysLast: true })
})
}
process.kill(process.pid, 'SIGHUP')
setTimeout(function () {}, 1000)

View File

@@ -0,0 +1,58 @@
var exec = require('child_process').exec,
t = require('tap')
var fixture = require.resolve('./fixtures/change-code.js')
var expect = require('./fixtures/change-code-expect.json')
// process.exitCode has problems prior to:
// https://github.com/joyent/node/commit/c0d81f90996667a658aa4403123e02161262506a
function isZero10 () {
return /^v0\.10\..+$/.test(process.version)
}
// process.exit(code), process.exitCode = code, normal exit
var types = [ 'explicit', 'normal' ]
if (!isZero10()) types.push('code')
// initial code that is set. Note, for 'normal' exit, there's no
// point doing these, because we just exit without modifying code
var codes = [ 0, 2, 'null' ]
// do not change, change to 5 with exit(), change to 5 with exitCode,
// change to 5 and then to 2 with exit(), change twice with exitcode
var changes = [ 'nochange', 'change', 'twice']
if (!isZero10()) changes.push('code', 'twicecode')
// use signal-exit, use process.on('exit')
var handlers = [ 'sigexit', 'nosigexit' ]
var opts = []
types.forEach(function (type) {
var testCodes = type === 'normal' ? [0] : codes
testCodes.forEach(function (code) {
changes.forEach(function (change) {
handlers.forEach(function (handler) {
opts.push([type, code, change, handler].join(' '))
})
})
})
})
opts.forEach(function (opt) {
t.test(opt, function (t) {
var cmd = process.execPath + ' ' + fixture + ' ' + opt
exec(cmd, function (err, stdout, stderr) {
var res = JSON.parse(stdout)
if (err) {
res.actualCode = err.code
res.actualSignal = err.signal
} else {
res.actualCode = 0
res.actualSignal = null
}
res.stderr = stderr.trim().split('\n')
t.same(res, expect[opt])
t.end()
})
})
})

View File

@@ -0,0 +1,108 @@
/* global describe, it */
var exec = require('child_process').exec,
expect = require('chai').expect,
assert = require('assert')
require('chai').should()
require('tap').mochaGlobals()
describe('signal-exit', function () {
it('receives an exit event when a process exits normally', function (done) {
exec(process.execPath + ' ./test/fixtures/end-of-execution.js', function (err, stdout, stderr) {
expect(err).to.equal(null)
stdout.should.match(/reached end of execution, 0, null/)
done()
})
})
it('receives an exit event when a process is terminated with sigint', function (done) {
exec(process.execPath + ' ./test/fixtures/sigint.js', function (err, stdout, stderr) {
assert(err)
stdout.should.match(/exited with sigint, null, SIGINT/)
done()
})
})
it('receives an exit event when a process is terminated with sigterm', function (done) {
exec(process.execPath + ' ./test/fixtures/sigterm.js', function (err, stdout, stderr) {
assert(err)
stdout.should.match(/exited with sigterm, null, SIGTERM/)
done()
})
})
it('receives an exit event when process.exit() is called', function (done) {
exec(process.execPath + ' ./test/fixtures/exit.js', function (err, stdout, stderr) {
err.code.should.equal(32)
stdout.should.match(/exited with process\.exit\(\), 32, null/)
done()
})
})
it('does not exit if user handles signal', function (done) {
exec(process.execPath + ' ./test/fixtures/signal-listener.js', function (err, stdout, stderr) {
assert(err)
assert.equal(stdout, 'exited calledListener=4, code=null, signal="SIGHUP"\n')
done()
})
})
it('ensures that if alwaysLast=true, the handler is run last (signal)', function (done) {
exec(process.execPath + ' ./test/fixtures/signal-last.js', function (err, stdout, stderr) {
assert(err)
stdout.should.match(/first counter=1/)
stdout.should.match(/last counter=2/)
done()
})
})
it('ensures that if alwaysLast=true, the handler is run last (normal exit)', function (done) {
exec(process.execPath + ' ./test/fixtures/exit-last.js', function (err, stdout, stderr) {
assert.ifError(err)
stdout.should.match(/first counter=1/)
stdout.should.match(/last counter=2/)
done()
})
})
it('works when loaded multiple times', function (done) {
exec(process.execPath + ' ./test/fixtures/multiple-load.js', function (err, stdout, stderr) {
assert(err)
stdout.should.match(/first counter=1, code=null, signal="SIGHUP"/)
stdout.should.match(/first counter=2, code=null, signal="SIGHUP"/)
stdout.should.match(/last counter=3, code=null, signal="SIGHUP"/)
stdout.should.match(/last counter=4, code=null, signal="SIGHUP"/)
done()
})
})
// TODO: test on a few non-OSX machines.
it('removes handlers when fully unwrapped', function (done) {
exec(process.execPath + ' ./test/fixtures/unwrap.js', function (err, stdout, stderr) {
// on Travis CI no err.signal is populated but
// err.code is 129 (which I think tends to be SIGHUP).
var expectedCode = process.env.TRAVIS ? 129 : null
assert(err)
if (!process.env.TRAVIS) err.signal.should.equal('SIGHUP')
expect(err.code).to.equal(expectedCode)
done()
})
})
it('does not load() or unload() more than once', function (done) {
exec(process.execPath + ' ./test/fixtures/load-unload.js', function (err, stdout, stderr) {
assert.ifError(err)
done()
})
})
it('handles uncatchable signals with grace and poise', function (done) {
exec(process.execPath + ' ./test/fixtures/sigkill.js', function (err, stdout, stderr) {
assert.ifError(err)
done()
})
})
})

View File

@@ -0,0 +1,96 @@
{
"name": "loud-rejection",
"version": "1.2.0",
"description": "Make unhandled promise rejections fail loudly instead of the default silent fail",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/sindresorhus/loud-rejection"
},
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "xo && nyc ava",
"coveralls": "nyc report --reporter=text-lcov | coveralls"
},
"files": [
"index.js",
"register.js",
"api.js"
],
"keywords": [
"promise",
"promises",
"unhandled",
"uncaught",
"rejection",
"loud",
"fail",
"catch",
"throw",
"handler",
"exit",
"debug",
"debugging",
"verbose"
],
"dependencies": {
"signal-exit": "^2.1.2"
},
"devDependencies": {
"ava": "*",
"bluebird": "^3.0.5",
"coveralls": "^2.11.4",
"delay": "^1.0.0",
"get-stream": "^1.0.0",
"nyc": "^3.2.2",
"xo": "*"
},
"xo": {
"ignores": [
"test.js"
]
},
"config": {
"nyc": {
"exclude": [
"node_modules",
"test.js",
"fixture.js"
]
}
},
"gitHead": "5ed228786d1ae9a603deafb4c751410ece432802",
"bugs": {
"url": "https://github.com/sindresorhus/loud-rejection/issues"
},
"homepage": "https://github.com/sindresorhus/loud-rejection",
"_id": "loud-rejection@1.2.0",
"_shasum": "f4f87db6abec3b7fe47834531ecf6a011143e58d",
"_from": "loud-rejection@^1.0.0",
"_npmVersion": "2.14.7",
"_nodeVersion": "4.2.1",
"_npmUser": {
"name": "sindresorhus",
"email": "sindresorhus@gmail.com"
},
"dist": {
"shasum": "f4f87db6abec3b7fe47834531ecf6a011143e58d",
"tarball": "http://registry.npmjs.org/loud-rejection/-/loud-rejection-1.2.0.tgz"
},
"maintainers": [
{
"name": "sindresorhus",
"email": "sindresorhus@gmail.com"
}
],
"directories": {},
"_resolved": "https://registry.npmjs.org/loud-rejection/-/loud-rejection-1.2.0.tgz",
"readme": "ERROR: No README data found!"
}

View File

@@ -0,0 +1,55 @@
# loud-rejection [![Build Status](https://travis-ci.org/sindresorhus/loud-rejection.svg?branch=master)](https://travis-ci.org/sindresorhus/loud-rejection) [![Coverage Status](https://coveralls.io/repos/sindresorhus/loud-rejection/badge.svg?branch=master&service=github)](https://coveralls.io/github/sindresorhus/loud-rejection?branch=master)
> Make unhandled promise rejections fail loudly instead of the default [silent fail](https://gist.github.com/benjamingr/0237932cee84712951a2)
By default, promises fail silently if you don't attach a `.catch()` handler to them.
Use it in top-level things like tests, CLI tools, apps, etc, **but not in reusable modules.**
## Install
```
$ npm install --save loud-rejection
```
## Usage
```js
const loudRejection = require('loud-rejection');
const promiseFn = require('promise-fn');
// Install the unhandledRejection listeners
loudRejection();
promiseFn();
```
Without this module it's more verbose and you might even miss some that will fail silently:
```js
const promiseFn = require('promise-fn');
function error(err) {
console.error(err.stack);
process.exit(1);
}
promiseFn().catch(error);
```
### Register script
Alternatively to the above, you may simply require `loud-rejection/register` and the unhandledRejection listener will be automagically installed for you.
This is handy for ES2015 imports:
```js
import 'loud-rejection/register';
```
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)

View File

@@ -0,0 +1,3 @@
'use strict';
require('./')();

View File

@@ -0,0 +1,3 @@
language: node_js
node_js:
- "0.10"

View File

@@ -0,0 +1,4 @@
# Names sorted by how much code was originally theirs.
Isaac Z. Schlueter <i@izs.me>
Meryn Stol <merynstol@gmail.com>
Robert Kowalski <rok@kowalski.gd>

View File

@@ -0,0 +1,30 @@
This package contains code originally written by Isaac Z. Schlueter.
Used with permission.
Copyright (c) Meryn Stol ("Author")
All rights reserved.
The BSD License
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -0,0 +1,107 @@
# normalize-package-data [![Build Status](https://travis-ci.org/npm/normalize-package-data.png?branch=master)](https://travis-ci.org/npm/normalize-package-data)
normalize-package data exports a function that normalizes package metadata. This data is typically found in a package.json file, but in principle could come from any source - for example the npm registry.
normalize-package-data is used by [read-package-json](https://npmjs.org/package/read-package-json) to normalize the data it reads from a package.json file. In turn, read-package-json is used by [npm](https://npmjs.org/package/npm) and various npm-related tools.
## Installation
```
npm install normalize-package-data
```
## Usage
Basic usage is really simple. You call the function that normalize-package-data exports. Let's call it `normalizeData`.
```javascript
normalizeData = require('normalize-package-data')
packageData = fs.readFileSync("package.json")
normalizeData(packageData)
// packageData is now normalized
```
#### Strict mode
You may activate strict validation by passing true as the second argument.
```javascript
normalizeData = require('normalize-package-data')
packageData = fs.readFileSync("package.json")
warnFn = function(msg) { console.error(msg) }
normalizeData(packageData, true)
// packageData is now normalized
```
If strict mode is activated, only Semver 2.0 version strings are accepted. Otherwise, Semver 1.0 strings are accepted as well. Packages must have a name, and the name field must not have contain leading or trailing whitespace.
#### Warnings
Optionally, you may pass a "warning" function. It gets called whenever the `normalizeData` function encounters something that doesn't look right. It indicates less than perfect input data.
```javascript
normalizeData = require('normalize-package-data')
packageData = fs.readFileSync("package.json")
warnFn = function(msg) { console.error(msg) }
normalizeData(packageData, warnFn)
// packageData is now normalized. Any number of warnings may have been logged.
```
You may combine strict validation with warnings by passing `true` as the second argument, and `warnFn` as third.
When `private` field is set to `true`, warnings will be suppressed.
### Potential exceptions
If the supplied data has an invalid name or version vield, `normalizeData` will throw an error. Depending on where you call `normalizeData`, you may want to catch these errors so can pass them to a callback.
## What normalization (currently) entails
* The value of `name` field gets trimmed (unless in strict mode).
* The value of the `version` field gets cleaned by `semver.clean`. See [documentation for the semver module](https://github.com/isaacs/node-semver).
* If `name` and/or `version` fields are missing, they are set to empty strings.
* If `files` field is not an array, it will be removed.
* If `bin` field is a string, then `bin` field will become an object with `name` set to the value of the `name` field, and `bin` set to the original string value.
* If `man` field is a string, it will become an array with the original string as its sole member.
* If `keywords` field is string, it is considered to be a list of keywords separated by one or more white-space characters. It gets converted to an array by splitting on `\s+`.
* All people fields (`author`, `maintainers`, `contributors`) get converted into objects with name, email and url properties.
* If `bundledDependencies` field (a typo) exists and `bundleDependencies` field does not, `bundledDependencies` will get renamed to `bundleDependencies`.
* If the value of any of the dependencies fields (`dependencies`, `devDependencies`, `optionalDependencies`) is a string, it gets converted into an object with familiar `name=>value` pairs.
* The values in `optionalDependencies` get added to `dependencies`. The `optionalDependencies` array is left untouched.
* As of v2: Dependencies that point at known hosted git providers (currently: github, bitbucket, gitlab) will have their URLs canonicalized, but protocols will be preserved.
* As of v2: Dependencies that use shortcuts for hosted git providers (`org/proj`, `github:org/proj`, `bitbucket:org/proj`, `gitlab:org/proj`, `gist:docid`) will have the shortcut left in place. (In the case of github, the `org/proj` form will be expanded to `github:org/proj`.) THIS MARKS A BREAKING CHANGE FROM V1, where the shorcut was previously expanded to a URL.
* If `description` field does not exist, but `readme` field does, then (more or less) the first paragraph of text that's found in the readme is taken as value for `description`.
* If `repository` field is a string, it will become an object with `url` set to the original string value, and `type` set to `"git"`.
* If `repository.url` is not a valid url, but in the style of "[owner-name]/[repo-name]", `repository.url` will be set to git+https://github.com/[owner-name]/[repo-name].git
* If `bugs` field is a string, the value of `bugs` field is changed into an object with `url` set to the original string value.
* If `bugs` field does not exist, but `repository` field points to a repository hosted on GitHub, the value of the `bugs` field gets set to an url in the form of https://github.com/[owner-name]/[repo-name]/issues . If the repository field points to a GitHub Gist repo url, the associated http url is chosen.
* If `bugs` field is an object, the resulting value only has email and url properties. If email and url properties are not strings, they are ignored. If no valid values for either email or url is found, bugs field will be removed.
* If `homepage` field is not a string, it will be removed.
* If the url in the `homepage` field does not specify a protocol, then http is assumed. For example, `myproject.org` will be changed to `http://myproject.org`.
* If `homepage` field does not exist, but `repository` field points to a repository hosted on GitHub, the value of the `homepage` field gets set to an url in the form of https://github.com/[owner-name]/[repo-name]/ . If the repository field points to a GitHub Gist repo url, the associated http url is chosen.
### Rules for name field
If `name` field is given, the value of the name field must be a string. The string may not:
* start with a period.
* contain the following characters: `/@\s+%`
* contain and characters that would need to be encoded for use in urls.
* resemble the word `node_modules` or `favicon.ico` (case doesn't matter).
### Rules for version field
If `version` field is given, the value of the version field must be a valid *semver* string, as determined by the `semver.valid` method. See [documentation for the semver module](https://github.com/isaacs/node-semver).
### Rules for license field
The `license` field should be a valid *SPDX license expression* or one of the special values allowed by [validate-npm-package-license](https://npmjs.com/packages/validate-npm-package-license). See [documentation for the license field in package.json](https://docs.npmjs.com/files/package.json#license).
## Credits
This package contains code based on read-package-json written by Isaac Z. Schlueter. Used with permisson.
## License
normalize-package-data is released under the [BSD 2-Clause License](http://opensource.org/licenses/MIT).
Copyright (c) 2013 Meryn Stol

View File

@@ -0,0 +1,14 @@
module.exports = extractDescription
// Extracts description from contents of a readme file in markdown format
function extractDescription (d) {
if (!d) return;
if (d === "ERROR: No README data found!") return;
// the first block of text before the first heading
// that isn't the first line heading
d = d.trim().split('\n')
for (var s = 0; d[s] && d[s].trim().match(/^(#|$)/); s ++);
var l = d.length
for (var e = s + 1; e < l && d[e].trim(); e ++);
return d.slice(s, e).join(' ').trim()
}

View File

@@ -0,0 +1,418 @@
var semver = require("semver")
var validateLicense = require('validate-npm-package-license');
var hostedGitInfo = require("hosted-git-info")
var isBuiltinModule = require("is-builtin-module")
var depTypes = ["dependencies","devDependencies","optionalDependencies"]
var extractDescription = require("./extract_description")
var url = require("url")
var typos = require("./typos")
var fixer = module.exports = {
// default warning function
warn: function() {},
fixRepositoryField: function(data) {
if (data.repositories) {
this.warn("repositories");
data.repository = data.repositories[0]
}
if (!data.repository) return this.warn("missingRepository")
if (typeof data.repository === "string") {
data.repository = {
type: "git",
url: data.repository
}
}
var r = data.repository.url || ""
if (r) {
var hosted = hostedGitInfo.fromUrl(r)
if (hosted) {
r = data.repository.url
= hosted.getDefaultRepresentation() == "shortcut" ? hosted.https() : hosted.toString()
}
}
if (r.match(/github.com\/[^\/]+\/[^\/]+\.git\.git$/)) {
this.warn("brokenGitUrl", r)
}
}
, fixTypos: function(data) {
Object.keys(typos.topLevel).forEach(function (d) {
if (data.hasOwnProperty(d)) {
this.warn("typo", d, typos.topLevel[d])
}
}, this)
}
, fixScriptsField: function(data) {
if (!data.scripts) return
if (typeof data.scripts !== "object") {
this.warn("nonObjectScripts")
delete data.scripts
return
}
Object.keys(data.scripts).forEach(function (k) {
if (typeof data.scripts[k] !== "string") {
this.warn("nonStringScript")
delete data.scripts[k]
} else if (typos.script[k] && !data.scripts[typos.script[k]]) {
this.warn("typo", k, typos.script[k], "scripts")
}
}, this)
}
, fixFilesField: function(data) {
var files = data.files
if (files && !Array.isArray(files)) {
this.warn("nonArrayFiles")
delete data.files
} else if (data.files) {
data.files = data.files.filter(function(file) {
if (!file || typeof file !== "string") {
this.warn("invalidFilename", file)
return false
} else {
return true
}
}, this)
}
}
, fixBinField: function(data) {
if (!data.bin) return;
if (typeof data.bin === "string") {
var b = {}
var match
if (match = data.name.match(/^@[^/]+[/](.*)$/)) {
b[match[1]] = data.bin
} else {
b[data.name] = data.bin
}
data.bin = b
}
}
, fixManField: function(data) {
if (!data.man) return;
if (typeof data.man === "string") {
data.man = [ data.man ]
}
}
, fixBundleDependenciesField: function(data) {
var bdd = "bundledDependencies"
var bd = "bundleDependencies"
if (data[bdd] && !data[bd]) {
data[bd] = data[bdd]
delete data[bdd]
}
if (data[bd] && !Array.isArray(data[bd])) {
this.warn("nonArrayBundleDependencies")
delete data[bd]
} else if (data[bd]) {
data[bd] = data[bd].filter(function(bd) {
if (!bd || typeof bd !== 'string') {
this.warn("nonStringBundleDependency", bd)
return false
} else {
if (!data.dependencies) {
data.dependencies = {}
}
if (!data.dependencies.hasOwnProperty(bd)) {
this.warn("nonDependencyBundleDependency", bd)
data.dependencies[bd] = "*"
}
return true
}
}, this)
}
}
, fixDependencies: function(data, strict) {
var loose = !strict
objectifyDeps(data, this.warn)
addOptionalDepsToDeps(data, this.warn)
this.fixBundleDependenciesField(data)
;['dependencies','devDependencies'].forEach(function(deps) {
if (!(deps in data)) return
if (!data[deps] || typeof data[deps] !== "object") {
this.warn("nonObjectDependencies", deps)
delete data[deps]
return
}
Object.keys(data[deps]).forEach(function (d) {
var r = data[deps][d]
if (typeof r !== 'string') {
this.warn("nonStringDependency", d, JSON.stringify(r))
delete data[deps][d]
}
var hosted = hostedGitInfo.fromUrl(data[deps][d])
if (hosted) data[deps][d] = hosted.toString()
}, this)
}, this)
}
, fixModulesField: function (data) {
if (data.modules) {
this.warn("deprecatedModules")
delete data.modules
}
}
, fixKeywordsField: function (data) {
if (typeof data.keywords === "string") {
data.keywords = data.keywords.split(/,\s+/)
}
if (data.keywords && !Array.isArray(data.keywords)) {
delete data.keywords
this.warn("nonArrayKeywords")
} else if (data.keywords) {
data.keywords = data.keywords.filter(function(kw) {
if (typeof kw !== "string" || !kw) {
this.warn("nonStringKeyword");
return false
} else {
return true
}
}, this)
}
}
, fixVersionField: function(data, strict) {
// allow "loose" semver 1.0 versions in non-strict mode
// enforce strict semver 2.0 compliance in strict mode
var loose = !strict
if (!data.version) {
data.version = ""
return true
}
if (!semver.valid(data.version, loose)) {
throw new Error('Invalid version: "'+ data.version + '"')
}
data.version = semver.clean(data.version, loose)
return true
}
, fixPeople: function(data) {
modifyPeople(data, unParsePerson)
modifyPeople(data, parsePerson)
}
, fixNameField: function(data, options) {
if (typeof options === "boolean") options = {strict: options}
else if (typeof options === "undefined") options = {}
var strict = options.strict
if (!data.name && !strict) {
data.name = ""
return
}
if (typeof data.name !== "string") {
throw new Error("name field must be a string.")
}
if (!strict)
data.name = data.name.trim()
ensureValidName(data.name, strict, options.allowLegacyCase)
if (isBuiltinModule(data.name))
this.warn("conflictingName", data.name)
}
, fixDescriptionField: function (data) {
if (data.description && typeof data.description !== 'string') {
this.warn("nonStringDescription")
delete data.description
}
if (data.readme && !data.description)
data.description = extractDescription(data.readme)
if(data.description === undefined) delete data.description;
if (!data.description) this.warn("missingDescription")
}
, fixReadmeField: function (data) {
if (!data.readme) {
this.warn("missingReadme")
data.readme = "ERROR: No README data found!"
}
}
, fixBugsField: function(data) {
if (!data.bugs && data.repository && data.repository.url) {
var hosted = hostedGitInfo.fromUrl(data.repository.url)
if(hosted && hosted.bugs()) {
data.bugs = {url: hosted.bugs()}
}
}
else if(data.bugs) {
var emailRe = /^.+@.*\..+$/
if(typeof data.bugs == "string") {
if(emailRe.test(data.bugs))
data.bugs = {email:data.bugs}
else if(url.parse(data.bugs).protocol)
data.bugs = {url: data.bugs}
else
this.warn("nonEmailUrlBugsString")
}
else {
bugsTypos(data.bugs, this.warn)
var oldBugs = data.bugs
data.bugs = {}
if(oldBugs.url) {
if(typeof(oldBugs.url) == "string" && url.parse(oldBugs.url).protocol)
data.bugs.url = oldBugs.url
else
this.warn("nonUrlBugsUrlField")
}
if(oldBugs.email) {
if(typeof(oldBugs.email) == "string" && emailRe.test(oldBugs.email))
data.bugs.email = oldBugs.email
else
this.warn("nonEmailBugsEmailField")
}
}
if(!data.bugs.email && !data.bugs.url) {
delete data.bugs
this.warn("emptyNormalizedBugs")
}
}
}
, fixHomepageField: function(data) {
if (!data.homepage && data.repository && data.repository.url) {
var hosted = hostedGitInfo.fromUrl(data.repository.url)
if (hosted && hosted.docs()) data.homepage = hosted.docs()
}
if (!data.homepage) return
if(typeof data.homepage !== "string") {
this.warn("nonUrlHomepage")
return delete data.homepage
}
if(!url.parse(data.homepage).protocol) {
this.warn("missingProtocolHomepage")
data.homepage = "http://" + data.homepage
}
}
, fixLicenseField: function(data) {
if (!data.license) {
return this.warn("missingLicense")
} else{
if (
typeof(data.license) !== 'string' ||
data.license.length < 1
) {
this.warn("invalidLicense")
} else {
if (!validateLicense(data.license).validForNewPackages)
this.warn("invalidLicense")
}
}
}
}
function isValidScopedPackageName(spec) {
if (spec.charAt(0) !== '@') return false
var rest = spec.slice(1).split('/')
if (rest.length !== 2) return false
return rest[0] && rest[1] &&
rest[0] === encodeURIComponent(rest[0]) &&
rest[1] === encodeURIComponent(rest[1])
}
function isCorrectlyEncodedName(spec) {
return !spec.match(/[\/@\s\+%:]/) &&
spec === encodeURIComponent(spec)
}
function ensureValidName (name, strict, allowLegacyCase) {
if (name.charAt(0) === "." ||
!(isValidScopedPackageName(name) || isCorrectlyEncodedName(name)) ||
(strict && (!allowLegacyCase) && name !== name.toLowerCase()) ||
name.toLowerCase() === "node_modules" ||
name.toLowerCase() === "favicon.ico") {
throw new Error("Invalid name: " + JSON.stringify(name))
}
}
function modifyPeople (data, fn) {
if (data.author) data.author = fn(data.author)
;["maintainers", "contributors"].forEach(function (set) {
if (!Array.isArray(data[set])) return;
data[set] = data[set].map(fn)
})
return data
}
function unParsePerson (person) {
if (typeof person === "string") return person
var name = person.name || ""
var u = person.url || person.web
var url = u ? (" ("+u+")") : ""
var e = person.email || person.mail
var email = e ? (" <"+e+">") : ""
return name+email+url
}
function parsePerson (person) {
if (typeof person !== "string") return person
var name = person.match(/^([^\(<]+)/)
var url = person.match(/\(([^\)]+)\)/)
var email = person.match(/<([^>]+)>/)
var obj = {}
if (name && name[0].trim()) obj.name = name[0].trim()
if (email) obj.email = email[1];
if (url) obj.url = url[1];
return obj
}
function addOptionalDepsToDeps (data, warn) {
var o = data.optionalDependencies
if (!o) return;
var d = data.dependencies || {}
Object.keys(o).forEach(function (k) {
d[k] = o[k]
})
data.dependencies = d
}
function depObjectify (deps, type, warn) {
if (!deps) return {}
if (typeof deps === "string") {
deps = deps.trim().split(/[\n\r\s\t ,]+/)
}
if (!Array.isArray(deps)) return deps
warn("deprecatedArrayDependencies", type)
var o = {}
deps.filter(function (d) {
return typeof d === "string"
}).forEach(function(d) {
d = d.trim().split(/(:?[@\s><=])/)
var dn = d.shift()
var dv = d.join("")
dv = dv.trim()
dv = dv.replace(/^@/, "")
o[dn] = dv
})
return o
}
function objectifyDeps (data, warn) {
depTypes.forEach(function (type) {
if (!data[type]) return;
data[type] = depObjectify(data[type], type, warn)
})
}
function bugsTypos(bugs, warn) {
if (!bugs) return
Object.keys(bugs).forEach(function (k) {
if (typos.bugs[k]) {
warn("typo", k, typos.bugs[k], "bugs")
bugs[typos.bugs[k]] = bugs[k]
delete bugs[k]
}
})
}

View File

@@ -0,0 +1,23 @@
var util = require("util")
var messages = require("./warning_messages.json")
module.exports = function() {
var args = Array.prototype.slice.call(arguments, 0)
var warningName = args.shift()
if (warningName == "typo") {
return makeTypoWarning.apply(null,args)
}
else {
var msgTemplate = messages[warningName] ? messages[warningName] : warningName + ": '%s'"
args.unshift(msgTemplate)
return util.format.apply(null, args)
}
}
function makeTypoWarning (providedName, probableName, field) {
if (field) {
providedName = field + "['" + providedName + "']"
probableName = field + "['" + probableName + "']"
}
return util.format(messages.typo, providedName, probableName)
}

View File

@@ -0,0 +1,39 @@
module.exports = normalize
var fixer = require("./fixer")
normalize.fixer = fixer
var makeWarning = require("./make_warning")
var fieldsToFix = ['name','version','description','repository','modules','scripts'
,'files','bin','man','bugs','keywords','readme','homepage','license']
var otherThingsToFix = ['dependencies','people', 'typos']
var thingsToFix = fieldsToFix.map(function(fieldName) {
return ucFirst(fieldName) + "Field"
})
// two ways to do this in CoffeeScript on only one line, sub-70 chars:
// thingsToFix = fieldsToFix.map (name) -> ucFirst(name) + "Field"
// thingsToFix = (ucFirst(name) + "Field" for name in fieldsToFix)
thingsToFix = thingsToFix.concat(otherThingsToFix)
function normalize (data, warn, strict) {
if(warn === true) warn = null, strict = true
if(!strict) strict = false
if(!warn || data.private) warn = function(msg) { /* noop */ }
if (data.scripts &&
data.scripts.install === "node-gyp rebuild" &&
!data.scripts.preinstall) {
data.gypfile = true
}
fixer.warn = function() { warn(makeWarning.apply(null, arguments)) }
thingsToFix.forEach(function(thingName) {
fixer["fix" + ucFirst(thingName)](data, strict)
})
data._id = data.name + "@" + data.version
}
function ucFirst (string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}

View File

@@ -0,0 +1,9 @@
var util = require('util')
module.exports = function() {
var args = Array.prototype.slice.call(arguments, 0)
args.forEach(function(arg) {
if (!arg) throw new TypeError('Bad arguments.')
})
return util.format.apply(null, arguments)
}

View File

@@ -0,0 +1,25 @@
{
"topLevel": {
"dependancies": "dependencies"
,"dependecies": "dependencies"
,"depdenencies": "dependencies"
,"devEependencies": "devDependencies"
,"depends": "dependencies"
,"dev-dependencies": "devDependencies"
,"devDependences": "devDependencies"
,"devDepenencies": "devDependencies"
,"devdependencies": "devDependencies"
,"repostitory": "repository"
,"repo": "repository"
,"prefereGlobal": "preferGlobal"
,"hompage": "homepage"
,"hampage": "homepage"
,"autohr": "author"
,"autor": "author"
,"contributers": "contributors"
,"publicationConfig": "publishConfig"
,"script": "scripts"
},
"bugs": { "web": "url", "name": "url" },
"script": { "server": "start", "tests": "test" }
}

View File

@@ -0,0 +1,31 @@
{
"repositories": "'repositories' (plural) Not supported. Please pick one as the 'repository' field"
,"missingRepository": "No repository field."
,"brokenGitUrl": "Probably broken git url: %s"
,"nonObjectScripts": "scripts must be an object"
,"nonStringScript": "script values must be string commands"
,"nonArrayFiles": "Invalid 'files' member"
,"invalidFilename": "Invalid filename in 'files' list: %s"
,"nonArrayBundleDependencies": "Invalid 'bundleDependencies' list. Must be array of package names"
,"nonStringBundleDependency": "Invalid bundleDependencies member: %s"
,"nonDependencyBundleDependency": "Non-dependency in bundleDependencies: %s"
,"nonObjectDependencies": "%s field must be an object"
,"nonStringDependency": "Invalid dependency: %s %s"
,"deprecatedArrayDependencies": "specifying %s as array is deprecated"
,"deprecatedModules": "modules field is deprecated"
,"nonArrayKeywords": "keywords should be an array of strings"
,"nonStringKeyword": "keywords should be an array of strings"
,"conflictingName": "%s is also the name of a node core module."
,"nonStringDescription": "'description' field should be a string"
,"missingDescription": "No description"
,"missingReadme": "No README data"
,"missingLicense": "No license field."
,"nonEmailUrlBugsString": "Bug string field must be url, email, or {email,url}"
,"nonUrlBugsUrlField": "bugs.url field must be a string url. Deleted."
,"nonEmailBugsEmailField": "bugs.email field must be a string email. Deleted."
,"emptyNormalizedBugs": "Normalized value of bugs field is an empty object. Deleted."
,"nonUrlHomepage": "homepage field must be a string url. Deleted."
,"invalidLicense": "license should be a valid SPDX license expression"
,"missingProtocolHomepage": "homepage field must start with a protocol."
,"typo": "%s should probably be %s."
}

View File

@@ -0,0 +1,5 @@
language: node_js
node_js:
- "0.11"
- "0.10"
script: "npm test"

View File

@@ -0,0 +1,13 @@
Copyright (c) 2015, Rebecca Turner
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.

View File

@@ -0,0 +1,99 @@
# hosted-git-info
This will let you identify and transform various git hosts URLs between
protocols. It also can tell you what the URL is for the raw path for
particular file for direct access without git.
## Usage
```javascript
var hostedGitInfo = require("hosted-git-info")
var info = hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git")
/* info looks like:
{
type: "github",
domain: "github.com",
user: "npm",
project: "hosted-git-info"
}
*/
```
If the URL can't be matched with a git host, `null` will be returned. We
can match git, ssh and https urls. Additionally, we can match ssh connect
strings (`git@github.com:npm/hosted-git-info`) and shortcuts (eg,
`github:npm/hosted-git-info`). Github specifically, is detected in the case
of a third, unprefixed, form: `npm/hosted-git-info`.
If it does match, the returned object has properties of:
* info.type -- The short name of the service
* info.domain -- The domain for git protocol use
* info.user -- The name of the user/org on the git host
* info.project -- The name of the project on the git host
And methods of:
* info.file(path)
Given the path of a file relative to the repository, returns a URL for
directly fetching it from the githost. If no committish was set then
`master` will be used as the default.
For example `hostedGitInfo.fromUrl("git@github.com:npm/hosted-git-info.git#v1.0.0").file("package.json")`
would return `https://raw.githubusercontent.com/npm/hosted-git-info/v1.0.0/package.json`
* info.shortcut()
eg, `github:npm/hosted-git-info`
* info.browse()
eg, `https://github.com/npm/hosted-git-info/tree/v1.2.0`
* info.bugs()
eg, `https://github.com/npm/hosted-git-info/issues`
* info.docs()
eg, `https://github.com/npm/hosted-git-info/tree/v1.2.0#readme`
* info.https()
eg, `git+https://github.com/npm/hosted-git-info.git`
* info.sshurl()
eg, `git+ssh://git@github.com/npm/hosted-git-info.git`
* info.ssh()
eg, `git@github.com:npm/hosted-git-info.git`
* info.path()
eg, `npm/hosted-git-info`
* info.getDefaultRepresentation()
Returns the default output type. The default output type is based on the
string you passed in to be parsed
* info.toString()
Uses the getDefaultRepresentation to call one of the other methods to get a URL for
this resource. As such `hostedGitInfo.fromUrl(url).toString()` will give
you a normalized version of the URL that still uses the same protocol.
Shortcuts will still be returned as shortcuts, but the special case github
form of `org/project` will be normalized to `github:org/project`.
SSH connect strings will be normalized into `git+ssh` URLs.
## Supported hosts
Currently this supports Github, Bitbucket and Gitlab. Pull requests for
additional hosts welcome.

View File

@@ -0,0 +1,64 @@
'use strict'
var gitHosts = module.exports = {
github: {
// First two are insecure and generally shouldn't be used any more, but
// they are still supported.
'protocols': [ 'git', 'http', 'git+ssh', 'git+https', 'ssh', 'https' ],
'domain': 'github.com',
'treepath': 'tree',
'filetemplate': 'https://{auth@}raw.githubusercontent.com/{user}/{project}/{committish}/{path}',
'bugstemplate': 'https://{domain}/{user}/{project}/issues',
'gittemplate': 'git://{auth@}{domain}/{user}/{project}.git{#committish}'
},
bitbucket: {
'protocols': [ 'git+ssh', 'git+https', 'ssh', 'https' ],
'domain': 'bitbucket.org',
'treepath': 'src'
},
gitlab: {
'protocols': [ 'git+ssh', 'git+https', 'ssh', 'https' ],
'domain': 'gitlab.com',
'treepath': 'tree',
'docstemplate': 'https://{domain}/{user}/{project}{/tree/committish}#README',
'bugstemplate': 'https://{domain}/{user}/{project}/issues'
},
gist: {
'protocols': [ 'git', 'git+ssh', 'git+https', 'ssh', 'https' ],
'domain': 'gist.github.com',
'pathmatch': /^[/](?:([^/]+)[/])?([a-z0-9]+)(?:[.]git)?$/,
'filetemplate': 'https://gist.githubusercontent.com/{user}/{project}/raw{/committish}/{path}',
'bugstemplate': 'https://{domain}/{project}',
'gittemplate': 'git://{domain}/{project}.git{#committish}',
'sshtemplate': 'git@{domain}:/{project}.git{#committish}',
'sshurltemplate': 'git+ssh://git@{domain}/{project}.git{#committish}',
'browsetemplate': 'https://{domain}/{project}{/committish}',
'docstemplate': 'https://{domain}/{project}{/committish}',
'httpstemplate': 'git+https://{domain}/{project}.git{#committish}',
'shortcuttemplate': '{type}:{project}{#committish}',
'pathtemplate': '{project}{#committish}'
}
}
var gitHostDefaults = {
'sshtemplate': 'git@{domain}:{user}/{project}.git{#committish}',
'sshurltemplate': 'git+ssh://git@{domain}/{user}/{project}.git{#committish}',
'browsetemplate': 'https://{domain}/{user}/{project}{/tree/committish}',
'docstemplate': 'https://{domain}/{user}/{project}{/tree/committish}#readme',
'httpstemplate': 'git+https://{auth@}{domain}/{user}/{project}.git{#committish}',
'filetemplate': 'https://{domain}/{user}/{project}/raw/{committish}/{path}',
'shortcuttemplate': '{type}:{user}/{project}{#committish}',
'pathtemplate': '{user}/{project}{#committish}',
'pathmatch': /^[/]([^/]+)[/]([^/]+?)(?:[.]git)?$/
}
Object.keys(gitHosts).forEach(function (name) {
Object.keys(gitHostDefaults).forEach(function (key) {
if (gitHosts[name][key]) return
gitHosts[name][key] = gitHostDefaults[key]
})
gitHosts[name].protocols_re = RegExp('^(' +
gitHosts[name].protocols.map(function (protocol) {
return protocol.replace(/([\\+*{}()\[\]$^|])/g, '\\$1')
}).join('|') + '):$')
})

View File

@@ -0,0 +1,96 @@
'use strict'
var gitHosts = require('./git-host-info.js')
var GitHost = module.exports = function (type, user, auth, project, committish, defaultRepresentation) {
var gitHostInfo = this
gitHostInfo.type = type
Object.keys(gitHosts[type]).forEach(function (key) {
gitHostInfo[key] = gitHosts[type][key]
})
gitHostInfo.user = user
gitHostInfo.auth = auth
gitHostInfo.project = project
gitHostInfo.committish = committish
gitHostInfo.default = defaultRepresentation
}
GitHost.prototype = {}
GitHost.prototype.hash = function () {
return this.committish ? '#' + this.committish : ''
}
GitHost.prototype._fill = function (template, vars) {
if (!template) return
if (!vars) vars = {}
var self = this
Object.keys(this).forEach(function (key) {
if (self[key] != null && vars[key] == null) vars[key] = self[key]
})
var rawAuth = vars.auth
var rawComittish = vars.committish
Object.keys(vars).forEach(function (key) {
vars[key] = encodeURIComponent(vars[key])
})
vars['auth@'] = rawAuth ? rawAuth + '@' : ''
vars['#committish'] = rawComittish ? '#' + rawComittish : ''
vars['/tree/committish'] = vars.committish
? '/' + vars.treepath + '/' + vars.committish
: ''
vars['/committish'] = vars.committish ? '/' + vars.committish : ''
vars.committish = vars.committish || 'master'
var res = template
Object.keys(vars).forEach(function (key) {
res = res.replace(new RegExp('[{]' + key + '[}]', 'g'), vars[key])
})
return res
}
GitHost.prototype.ssh = function () {
return this._fill(this.sshtemplate)
}
GitHost.prototype.sshurl = function () {
return this._fill(this.sshurltemplate)
}
GitHost.prototype.browse = function () {
return this._fill(this.browsetemplate)
}
GitHost.prototype.docs = function () {
return this._fill(this.docstemplate)
}
GitHost.prototype.bugs = function () {
return this._fill(this.bugstemplate)
}
GitHost.prototype.https = function () {
return this._fill(this.httpstemplate)
}
GitHost.prototype.git = function () {
return this._fill(this.gittemplate)
}
GitHost.prototype.shortcut = function () {
return this._fill(this.shortcuttemplate)
}
GitHost.prototype.path = function () {
return this._fill(this.pathtemplate)
}
GitHost.prototype.file = function (P) {
return this._fill(this.filetemplate, {
path: P.replace(/^[/]+/g, '')
})
}
GitHost.prototype.getDefaultRepresentation = function () {
return this.default
}
GitHost.prototype.toString = function () {
return (this[this.default] || this.sshurl).call(this)
}

View File

@@ -0,0 +1,103 @@
'use strict'
var url = require('url')
var gitHosts = require('./git-host-info.js')
var GitHost = module.exports = require('./git-host.js')
var protocolToRepresentationMap = {
'git+ssh': 'sshurl',
'git+https': 'https',
'ssh': 'sshurl',
'git': 'git'
}
function protocolToRepresentation (protocol) {
if (protocol.substr(-1) === ':') protocol = protocol.slice(0, -1)
return protocolToRepresentationMap[protocol] || protocol
}
var authProtocols = {
'git:': true,
'https:': true,
'git+https:': true,
'http:': true,
'git+http:': true
}
module.exports.fromUrl = function (giturl) {
if (giturl == null || giturl === '') return
var url = fixupUnqualifiedGist(
isGitHubShorthand(giturl) ? 'github:' + giturl : giturl
)
var parsed = parseGitUrl(url)
var matches = Object.keys(gitHosts).map(function (gitHostName) {
var gitHostInfo = gitHosts[gitHostName]
var auth = null
if (parsed.auth && authProtocols[parsed.protocol]) {
auth = decodeURIComponent(parsed.auth)
}
var committish = parsed.hash ? decodeURIComponent(parsed.hash.substr(1)) : null
var user = null
var project = null
var defaultRepresentation = null
if (parsed.protocol === gitHostName + ':') {
user = decodeURIComponent(parsed.host)
project = parsed.path && decodeURIComponent(parsed.path.replace(/^[/](.*?)(?:[.]git)?$/, '$1'))
defaultRepresentation = 'shortcut'
} else {
if (parsed.host !== gitHostInfo.domain) return
if (!gitHostInfo.protocols_re.test(parsed.protocol)) return
var pathmatch = gitHostInfo.pathmatch
var matched = parsed.path.match(pathmatch)
if (!matched) return
if (matched[1] != null) user = decodeURIComponent(matched[1])
if (matched[2] != null) project = decodeURIComponent(matched[2])
defaultRepresentation = protocolToRepresentation(parsed.protocol)
}
return new GitHost(gitHostName, user, auth, project, committish, defaultRepresentation)
}).filter(function (gitHostInfo) { return gitHostInfo })
if (matches.length !== 1) return
return matches[0]
}
function isGitHubShorthand (arg) {
// Note: This does not fully test the git ref format.
// See https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
//
// The only way to do this properly would be to shell out to
// git-check-ref-format, and as this is a fast sync function,
// we don't want to do that. Just let git fail if it turns
// out that the commit-ish is invalid.
// GH usernames cannot start with . or -
return /^[^:@%/\s.-][^:@%/\s]*[/][^:@\s/%]+(?:#.*)?$/.test(arg)
}
function fixupUnqualifiedGist (giturl) {
// necessary for round-tripping gists
var parsed = url.parse(giturl)
if (parsed.protocol === 'gist:' && parsed.host && !parsed.path) {
return parsed.protocol + '/' + parsed.host
} else {
return giturl
}
}
function parseGitUrl (giturl) {
if (typeof giturl !== 'string') giturl = '' + giturl
var matched = giturl.match(/^([^@]+)@([^:]+):[/]?((?:[^/]+[/])?[^/]+?)(?:[.]git)?(#.*)?$/)
if (!matched) return url.parse(giturl)
return {
protocol: 'git+ssh:',
slashes: true,
auth: matched[1],
host: matched[2],
port: null,
hostname: matched[2],
hash: matched[4],
search: null,
query: null,
pathname: '/' + matched[3],
path: '/' + matched[3],
href: 'git+ssh://' + matched[1] + '@' + matched[2] +
'/' + matched[3] + (matched[4] || '')
}
}

View File

@@ -0,0 +1,60 @@
{
"name": "hosted-git-info",
"version": "2.1.4",
"description": "Provides metadata and conversions from repository urls for Github, Bitbucket and Gitlab",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/npm/hosted-git-info.git"
},
"keywords": [
"git",
"github",
"bitbucket",
"gitlab"
],
"author": {
"name": "Rebecca Turner",
"email": "me@re-becca.org",
"url": "http://re-becca.org"
},
"license": "ISC",
"bugs": {
"url": "https://github.com/npm/hosted-git-info/issues"
},
"homepage": "https://github.com/npm/hosted-git-info",
"scripts": {
"test": "standard && tap test/*.js"
},
"devDependencies": {
"standard": "^3.3.2",
"tap": "^0.4.13"
},
"gitHead": "9e1a36df8eb050a663713c79e56d89dadba2bd8d",
"_id": "hosted-git-info@2.1.4",
"_shasum": "d9e953b26988be88096c46e926494d9604c300f8",
"_from": "hosted-git-info@^2.1.4",
"_npmVersion": "2.10.1",
"_nodeVersion": "2.0.2",
"_npmUser": {
"name": "othiym23",
"email": "ogd@aoaioxxysz.net"
},
"dist": {
"shasum": "d9e953b26988be88096c46e926494d9604c300f8",
"tarball": "http://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.1.4.tgz"
},
"maintainers": [
{
"name": "iarna",
"email": "me@re-becca.org"
},
{
"name": "othiym23",
"email": "ogd@aoaioxxysz.net"
}
],
"directories": {},
"_resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.1.4.tgz",
"readme": "ERROR: No README data found!"
}

View File

@@ -0,0 +1,15 @@
'use strict'
var HostedGit = require('../index')
var test = require('tap').test
test('basic', function (t) {
t.is(HostedGit.fromUrl('https://google.com'), undefined, 'null on failure')
t.is(HostedGit.fromUrl('https://github.com/abc/def').getDefaultRepresentation(), 'https', 'match https urls')
t.is(HostedGit.fromUrl('ssh://git@github.com/abc/def').getDefaultRepresentation(), 'sshurl', 'match ssh urls')
t.is(HostedGit.fromUrl('git+ssh://git@github.com/abc/def').getDefaultRepresentation(), 'sshurl', 'match git+ssh urls')
t.is(HostedGit.fromUrl('git+https://github.com/abc/def').getDefaultRepresentation(), 'https', 'match git+https urls')
t.is(HostedGit.fromUrl('git@github.com:abc/def').getDefaultRepresentation(), 'sshurl', 'match ssh connect strings')
t.is(HostedGit.fromUrl('git://github.com/abc/def').getDefaultRepresentation(), 'git', 'match git urls')
t.is(HostedGit.fromUrl('github:abc/def').getDefaultRepresentation(), 'shortcut', 'match shortcuts')
t.end()
})

View File

@@ -0,0 +1,27 @@
'use strict'
var HostedGit = require('../index')
var test = require('tap').test
test('Bitbucket HTTPS URLs with embedded auth', function (t) {
t.is(
HostedGit.fromUrl('https://user:pass@bitbucket.org/user/repo.git').toString(),
'git+https://user:pass@bitbucket.org/user/repo.git',
'credentials were included in URL'
)
t.is(
HostedGit.fromUrl('https://user:pass@bitbucket.org/user/repo').toString(),
'git+https://user:pass@bitbucket.org/user/repo.git',
'credentials were included in URL'
)
t.is(
HostedGit.fromUrl('git+https://user:pass@bitbucket.org/user/repo.git').toString(),
'git+https://user:pass@bitbucket.org/user/repo.git',
'credentials were included in URL'
)
t.is(
HostedGit.fromUrl('git+https://user:pass@bitbucket.org/user/repo').toString(),
'git+https://user:pass@bitbucket.org/user/repo.git',
'credentials were included in URL'
)
t.end()
})

View File

@@ -0,0 +1,23 @@
'use strict'
var HostedGit = require('../index')
var test = require('tap').test
test('fromUrl(bitbucket url)', function (t) {
function verify (host, label, branch) {
var hostinfo = HostedGit.fromUrl(host)
var hash = branch ? '#' + branch : ''
t.ok(hostinfo, label)
if (!hostinfo) return
t.is(hostinfo.https(), 'git+https://bitbucket.org/111/222.git' + hash, label + ' -> https')
t.is(hostinfo.browse(), 'https://bitbucket.org/111/222' + (branch ? '/src/' + branch : ''), label + ' -> browse')
t.is(hostinfo.docs(), 'https://bitbucket.org/111/222' + (branch ? '/src/' + branch : '') + '#readme', label + ' -> docs')
t.is(hostinfo.ssh(), 'git@bitbucket.org:111/222.git' + hash, label + ' -> ssh')
t.is(hostinfo.sshurl(), 'git+ssh://git@bitbucket.org/111/222.git' + hash, label + ' -> sshurl')
t.is(hostinfo.shortcut(), 'bitbucket:111/222' + hash, label + ' -> shortcut')
t.is(hostinfo.file('C'), 'https://bitbucket.org/111/222/raw/' + (branch || 'master') + '/C', label + ' -> file')
}
require('./lib/standard-tests')(verify, 'bitbucket.org', 'bitbucket')
t.end()
})

View File

@@ -0,0 +1,41 @@
'use strict'
var HostedGit = require('../index')
var test = require('tap').test
test('fromUrl(gist url)', function (t) {
function verify (host, label, branch) {
var hostinfo = HostedGit.fromUrl(host)
var hash = branch ? '#' + branch : ''
t.ok(hostinfo, label)
if (!hostinfo) return
t.is(hostinfo.https(), 'git+https://gist.github.com/222.git' + hash, label + ' -> https')
t.is(hostinfo.git(), 'git://gist.github.com/222.git' + hash, label + ' -> git')
t.is(hostinfo.browse(), 'https://gist.github.com/222' + (branch ? '/' + branch : ''), label + ' -> browse')
t.is(hostinfo.bugs(), 'https://gist.github.com/222', label + ' -> bugs')
t.is(hostinfo.docs(), 'https://gist.github.com/222' + (branch ? '/' + branch : ''), label + ' -> docs')
t.is(hostinfo.ssh(), 'git@gist.github.com:/222.git' + hash, label + ' -> ssh')
t.is(hostinfo.sshurl(), 'git+ssh://git@gist.github.com/222.git' + hash, label + ' -> sshurl')
t.is(hostinfo.shortcut(), 'gist:222' + hash, label + ' -> shortcut')
if (hostinfo.user) {
t.is(hostinfo.file('C'), 'https://gist.githubusercontent.com/111/222/raw/' + (branch ? branch + '/' : '') + 'C', label + ' -> file')
}
}
verify('git@gist.github.com:222.git', 'git@')
var hostinfo = HostedGit.fromUrl('git@gist.github.com:/ef860c7z5e0de3179341.git')
if (t.ok(hostinfo, 'git@hex')) {
t.is(hostinfo.https(), 'git+https://gist.github.com/ef860c7z5e0de3179341.git', 'git@hex -> https')
}
verify('git@gist.github.com:/222.git', 'git@/')
verify('git://gist.github.com/222', 'git')
verify('git://gist.github.com/222.git', 'git.git')
verify('git://gist.github.com/222#branch', 'git#branch', 'branch')
verify('git://gist.github.com/222.git#branch', 'git.git#branch', 'branch')
require('./lib/standard-tests')(verify, 'gist.github.com', 'gist')
verify(HostedGit.fromUrl('gist:111/222').toString(), 'round-tripped shortcut')
verify('gist:222', 'shortened shortcut')
t.end()
})

View File

@@ -0,0 +1,40 @@
'use strict'
var HostedGit = require('../index')
var test = require('tap').test
test('fromUrl(github url)', function (t) {
function verify (host, label, branch) {
var hostinfo = HostedGit.fromUrl(host)
var hash = branch ? '#' + branch : ''
t.ok(hostinfo, label)
if (!hostinfo) return
t.is(hostinfo.https(), 'git+https://github.com/111/222.git' + hash, label + ' -> https')
t.is(hostinfo.git(), 'git://github.com/111/222.git' + hash, label + ' -> git')
t.is(hostinfo.browse(), 'https://github.com/111/222' + (branch ? '/tree/' + branch : ''), label + ' -> browse')
t.is(hostinfo.bugs(), 'https://github.com/111/222/issues', label + ' -> bugs')
t.is(hostinfo.docs(), 'https://github.com/111/222' + (branch ? '/tree/' + branch : '') + '#readme', label + ' -> docs')
t.is(hostinfo.ssh(), 'git@github.com:111/222.git' + hash, label + ' -> ssh')
t.is(hostinfo.sshurl(), 'git+ssh://git@github.com/111/222.git' + hash, label + ' -> sshurl')
t.is(hostinfo.shortcut(), 'github:111/222' + hash, label + ' -> shortcut')
t.is(hostinfo.file('C'), 'https://raw.githubusercontent.com/111/222/' + (branch || 'master') + '/C', label + ' -> file')
}
// github shorturls
verify('111/222', 'github-short')
verify('111/222#branch', 'github-short#branch', 'branch')
// insecure protocols
verify('git://github.com/111/222', 'git')
verify('git://github.com/111/222.git', 'git.git')
verify('git://github.com/111/222#branch', 'git#branch', 'branch')
verify('git://github.com/111/222.git#branch', 'git.git#branch', 'branch')
verify('http://github.com/111/222', 'http')
verify('http://github.com/111/222.git', 'http.git')
verify('http://github.com/111/222#branch', 'http#branch', 'branch')
verify('http://github.com/111/222.git#branch', 'http.git#branch', 'branch')
require('./lib/standard-tests')(verify, 'github.com', 'github')
t.end()
})

View File

@@ -0,0 +1,23 @@
'use strict'
var HostedGit = require('../index')
var test = require('tap').test
test('fromUrl(gitlab url)', function (t) {
function verify (host, label, branch) {
var hostinfo = HostedGit.fromUrl(host)
var hash = branch ? '#' + branch : ''
t.ok(hostinfo, label)
if (!hostinfo) return
t.is(hostinfo.https(), 'git+https://gitlab.com/111/222.git' + hash, label + ' -> https')
t.is(hostinfo.browse(), 'https://gitlab.com/111/222' + (branch ? '/tree/' + branch : ''), label + ' -> browse')
t.is(hostinfo.docs(), 'https://gitlab.com/111/222' + (branch ? '/tree/' + branch : '') + '#README', label + ' -> docs')
t.is(hostinfo.ssh(), 'git@gitlab.com:111/222.git' + hash, label + ' -> ssh')
t.is(hostinfo.sshurl(), 'git+ssh://git@gitlab.com/111/222.git' + hash, label + ' -> sshurl')
t.is(hostinfo.shortcut(), 'gitlab:111/222' + hash, label + ' -> shortcut')
t.is(hostinfo.file('C'), 'https://gitlab.com/111/222/raw/' + (branch || 'master') + '/C', label + ' -> file')
}
require('./lib/standard-tests')(verify, 'gitlab.com', 'gitlab')
t.end()
})

View File

@@ -0,0 +1,39 @@
'use strict'
var HostedGit = require('../index')
var test = require('tap').test
test('HTTPS GitHub URL with embedded auth -- generally not a good idea', function (t) {
function verify (host, label, branch) {
var hostinfo = HostedGit.fromUrl(host)
var hash = branch ? '#' + branch : ''
t.ok(hostinfo, label)
if (!hostinfo) return
t.is(hostinfo.https(), 'git+https://user:pass@github.com/111/222.git' + hash, label + ' -> https')
t.is(hostinfo.git(), 'git://user:pass@github.com/111/222.git' + hash, label + ' -> git')
t.is(hostinfo.browse(), 'https://github.com/111/222' + (branch ? '/tree/' + branch : ''), label + ' -> browse')
t.is(hostinfo.bugs(), 'https://github.com/111/222/issues', label + ' -> bugs')
t.is(hostinfo.docs(), 'https://github.com/111/222' + (branch ? '/tree/' + branch : '') + '#readme', label + ' -> docs')
t.is(hostinfo.ssh(), 'git@github.com:111/222.git' + hash, label + ' -> ssh')
t.is(hostinfo.sshurl(), 'git+ssh://git@github.com/111/222.git' + hash, label + ' -> sshurl')
t.is(hostinfo.shortcut(), 'github:111/222' + hash, label + ' -> shortcut')
t.is(hostinfo.file('C'), 'https://user:pass@raw.githubusercontent.com/111/222/' + (branch || 'master') + '/C', label + ' -> file')
}
// insecure protocols
verify('git://user:pass@github.com/111/222', 'git')
verify('git://user:pass@github.com/111/222.git', 'git.git')
verify('git://user:pass@github.com/111/222#branch', 'git#branch', 'branch')
verify('git://user:pass@github.com/111/222.git#branch', 'git.git#branch', 'branch')
verify('https://user:pass@github.com/111/222', 'https')
verify('https://user:pass@github.com/111/222.git', 'https.git')
verify('https://user:pass@github.com/111/222#branch', 'https#branch', 'branch')
verify('https://user:pass@github.com/111/222.git#branch', 'https.git#branch', 'branch')
verify('http://user:pass@github.com/111/222', 'http')
verify('http://user:pass@github.com/111/222.git', 'http.git')
verify('http://user:pass@github.com/111/222#branch', 'http#branch', 'branch')
verify('http://user:pass@github.com/111/222.git#branch', 'http.git#branch', 'branch')
t.end()
})

View File

@@ -0,0 +1,27 @@
'use strict'
module.exports = function (verify, domain, shortname) {
verify('https://' + domain + '/111/222', 'https')
verify('https://' + domain + '/111/222.git', 'https.git')
verify('https://' + domain + '/111/222#branch', 'https#branch', 'branch')
verify('https://' + domain + '/111/222.git#branch', 'https.git#branch', 'branch')
verify('git+https://' + domain + '/111/222', 'git+https')
verify('git+https://' + domain + '/111/222.git', 'git+https.git')
verify('git+https://' + domain + '/111/222#branch', 'git+https#branch', 'branch')
verify('git+https://' + domain + '/111/222.git#branch', 'git+https.git#branch', 'branch')
verify('git@' + domain + ':111/222', 'ssh')
verify('git@' + domain + ':111/222.git', 'ssh.git')
verify('git@' + domain + ':111/222#branch', 'ssh', 'branch')
verify('git@' + domain + ':111/222.git#branch', 'ssh.git', 'branch')
verify('git+ssh://git@' + domain + '/111/222', 'ssh url')
verify('git+ssh://git@' + domain + '/111/222.git', 'ssh url.git')
verify('git+ssh://git@' + domain + '/111/222#branch', 'ssh url#branch', 'branch')
verify('git+ssh://git@' + domain + '/111/222.git#branch', 'ssh url.git#branch', 'branch')
verify(shortname + ':111/222', 'shortcut')
verify(shortname + ':111/222.git', 'shortcut.git')
verify(shortname + ':111/222#branch', 'shortcut#branch', 'branch')
verify(shortname + ':111/222.git#branch', 'shortcut.git#branch', 'branch')
}

View File

@@ -0,0 +1,10 @@
'use strict';
var builtinModules = require('builtin-modules');
module.exports = function (str) {
if (typeof str !== 'string') {
throw new TypeError('Expected a string');
}
return builtinModules.indexOf(str) !== -1;
};

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,35 @@
[
"assert",
"buffer",
"child_process",
"cluster",
"console",
"constants",
"crypto",
"dgram",
"dns",
"domain",
"events",
"fs",
"http",
"https",
"module",
"net",
"os",
"path",
"process",
"punycode",
"querystring",
"readline",
"repl",
"stream",
"string_decoder",
"timers",
"tls",
"tty",
"url",
"util",
"v8",
"vm",
"zlib"
]

View File

@@ -0,0 +1,10 @@
'use strict';
var blacklist = [
'freelist',
'sys'
];
module.exports = Object.keys(process.binding('natives')).filter(function (el) {
return !/^_|^internal/.test(el) && blacklist.indexOf(el) === -1;
}).sort();

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,70 @@
{
"name": "builtin-modules",
"version": "1.1.0",
"description": "List of the Node.js builtin modules",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/sindresorhus/builtin-modules.git"
},
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "xo && ava",
"make": "node make.js"
},
"files": [
"index.js",
"static.js",
"builtin-modules.json"
],
"keywords": [
"builtin",
"built-in",
"builtins",
"node",
"modules",
"core",
"bundled",
"list",
"array",
"names"
],
"devDependencies": {
"ava": "*",
"xo": "*"
},
"gitHead": "d317be16fab701f2ac73bc9aa771f60ec052ed66",
"bugs": {
"url": "https://github.com/sindresorhus/builtin-modules/issues"
},
"homepage": "https://github.com/sindresorhus/builtin-modules#readme",
"_id": "builtin-modules@1.1.0",
"_shasum": "1053955fd994a5746e525e4ac717b81caf07491c",
"_from": "builtin-modules@^1.0.0",
"_npmVersion": "2.13.3",
"_nodeVersion": "3.0.0",
"_npmUser": {
"name": "sindresorhus",
"email": "sindresorhus@gmail.com"
},
"dist": {
"shasum": "1053955fd994a5746e525e4ac717b81caf07491c",
"tarball": "http://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.0.tgz"
},
"maintainers": [
{
"name": "sindresorhus",
"email": "sindresorhus@gmail.com"
}
],
"directories": {},
"_resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.0.tgz",
"readme": "ERROR: No README data found!"
}

View File

@@ -0,0 +1,41 @@
# builtin-modules [![Build Status](https://travis-ci.org/sindresorhus/builtin-modules.svg?branch=master)](https://travis-ci.org/sindresorhus/builtin-modules)
> List of the Node.js builtin modules
The list is just a [JSON file](builtin-modules.json) and can be used wherever.
## Install
```
$ npm install --save builtin-modules
```
## Usage
```js
var builtinModules = require('builtin-modules');
console.log(builinModules);
//=> ['assert', 'buffer', ...]
```
## API
Returns an array of builtin modules fetched from the running Node.js version.
### Static list
This module also comes bundled with a static array of builtin modules generated from the latest Node.js version. You can get it with `require('builtin-modules/static');`
## Related
- [is-builtin-module](https://github.com/sindresorhus/is-builtin-module) - Check if a string matches the name of a Node.js builtin module
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)

View File

@@ -0,0 +1,2 @@
'use strict';
module.exports = require('./builtin-modules.json');

View File

@@ -0,0 +1,73 @@
{
"name": "is-builtin-module",
"version": "1.0.0",
"description": "Check if a string matches the name of a Node.js builtin module",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/sindresorhus/is-builtin-module"
},
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "node test.js"
},
"files": [
"index.js"
],
"keywords": [
"builtin",
"built-in",
"builtins",
"node",
"modules",
"core",
"bundled",
"list",
"array",
"names",
"is",
"detect",
"check",
"match"
],
"dependencies": {
"builtin-modules": "^1.0.0"
},
"devDependencies": {
"ava": "0.0.4"
},
"gitHead": "da55ebf031f3864c5d309e25e49ed816957d70a2",
"bugs": {
"url": "https://github.com/sindresorhus/is-builtin-module/issues"
},
"homepage": "https://github.com/sindresorhus/is-builtin-module",
"_id": "is-builtin-module@1.0.0",
"_shasum": "540572d34f7ac3119f8f76c30cbc1b1e037affbe",
"_from": "is-builtin-module@^1.0.0",
"_npmVersion": "2.7.4",
"_nodeVersion": "0.12.2",
"_npmUser": {
"name": "sindresorhus",
"email": "sindresorhus@gmail.com"
},
"dist": {
"shasum": "540572d34f7ac3119f8f76c30cbc1b1e037affbe",
"tarball": "http://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz"
},
"maintainers": [
{
"name": "sindresorhus",
"email": "sindresorhus@gmail.com"
}
],
"directories": {},
"_resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz",
"readme": "ERROR: No README data found!"
}

View File

@@ -0,0 +1,33 @@
# is-builtin-module [![Build Status](https://travis-ci.org/sindresorhus/is-builtin-module.svg?branch=master)](https://travis-ci.org/sindresorhus/is-builtin-module)
> Check if a string matches the name of a Node.js builtin module
## Install
```
$ npm install --save is-builtin-module
```
## Usage
```js
var isBuiltinModule = require('is-builtin-module');
isBuiltinModule('fs');
//=> true
isBuiltinModule('unicorn');
//=> false :(
```
## Related
- [builtin-modules](https://github.com/sindresorhus/builtin-modules) - List of the Node.js builtin modules
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)

View File

@@ -0,0 +1,4 @@
node_modules/
coverage/
.nyc_output/
nyc_output/

View File

@@ -0,0 +1,5 @@
language: node_js
node_js:
- '0.10'
- '0.12'
- 'iojs'

View File

@@ -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.

View File

@@ -0,0 +1,327 @@
semver(1) -- The semantic versioner for npm
===========================================
## Usage
$ npm install semver
semver.valid('1.2.3') // '1.2.3'
semver.valid('a.b.c') // null
semver.clean(' =v1.2.3 ') // '1.2.3'
semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') // true
semver.gt('1.2.3', '9.8.7') // false
semver.lt('1.2.3', '9.8.7') // true
As a command-line utility:
$ semver -h
Usage: semver <version> [<version> [...]] [-r <range> | -i <inc> | --preid <identifier> | -l | -rv]
Test if version(s) satisfy the supplied range(s), and sort them.
Multiple versions or ranges may be supplied, unless increment
option is specified. In that case, only a single version may
be used, and it is incremented by the specified level
Program exits successfully if any valid version satisfies
all supplied ranges, and prints all satisfying versions.
If no versions are valid, or ranges are not satisfied,
then exits failure.
Versions are printed in ascending order, so supplying
multiple versions to the utility will just sort them.
## Versions
A "version" is described by the `v2.0.0` specification found at
<http://semver.org/>.
A leading `"="` or `"v"` character is stripped off and ignored.
## Ranges
A `version range` is a set of `comparators` which specify versions
that satisfy the range.
A `comparator` is composed of an `operator` and a `version`. The set
of primitive `operators` is:
* `<` Less than
* `<=` Less than or equal to
* `>` Greater than
* `>=` Greater than or equal to
* `=` Equal. If no operator is specified, then equality is assumed,
so this operator is optional, but MAY be included.
For example, the comparator `>=1.2.7` would match the versions
`1.2.7`, `1.2.8`, `2.5.3`, and `1.3.9`, but not the versions `1.2.6`
or `1.1.0`.
Comparators can be joined by whitespace to form a `comparator set`,
which is satisfied by the **intersection** of all of the comparators
it includes.
A range is composed of one or more comparator sets, joined by `||`. A
version matches a range if and only if every comparator in at least
one of the `||`-separated comparator sets is satisfied by the version.
For example, the range `>=1.2.7 <1.3.0` would match the versions
`1.2.7`, `1.2.8`, and `1.2.99`, but not the versions `1.2.6`, `1.3.0`,
or `1.1.0`.
The range `1.2.7 || >=1.2.9 <2.0.0` would match the versions `1.2.7`,
`1.2.9`, and `1.4.6`, but not the versions `1.2.8` or `2.0.0`.
### Prerelease Tags
If a version has a prerelease tag (for example, `1.2.3-alpha.3`) then
it will only be allowed to satisfy comparator sets if at least one
comparator with the same `[major, minor, patch]` tuple also has a
prerelease tag.
For example, the range `>1.2.3-alpha.3` would be allowed to match the
version `1.2.3-alpha.7`, but it would *not* be satisfied by
`3.4.5-alpha.9`, even though `3.4.5-alpha.9` is technically "greater
than" `1.2.3-alpha.3` according to the SemVer sort rules. The version
range only accepts prerelease tags on the `1.2.3` version. The
version `3.4.5` *would* satisfy the range, because it does not have a
prerelease flag, and `3.4.5` is greater than `1.2.3-alpha.7`.
The purpose for this behavior is twofold. First, prerelease versions
frequently are updated very quickly, and contain many breaking changes
that are (by the author's design) not yet fit for public consumption.
Therefore, by default, they are excluded from range matching
semantics.
Second, a user who has opted into using a prerelease version has
clearly indicated the intent to use *that specific* set of
alpha/beta/rc versions. By including a prerelease tag in the range,
the user is indicating that they are aware of the risk. However, it
is still not appropriate to assume that they have opted into taking a
similar risk on the *next* set of prerelease versions.
#### Prerelease Identifiers
The method `.inc` takes an additional `identifier` string argument that
will append the value of the string as a prerelease identifier:
```javascript
> semver.inc('1.2.3', 'prerelease', 'beta')
'1.2.4-beta.0'
```
command-line example:
```shell
$ semver 1.2.3 -i prerelease --preid beta
1.2.4-beta.0
```
Which then can be used to increment further:
```shell
$ semver 1.2.4-beta.0 -i prerelease
1.2.4-beta.1
```
### Advanced Range Syntax
Advanced range syntax desugars to primitive comparators in
deterministic ways.
Advanced ranges may be combined in the same way as primitive
comparators using white space or `||`.
#### Hyphen Ranges `X.Y.Z - A.B.C`
Specifies an inclusive set.
* `1.2.3 - 2.3.4` := `>=1.2.3 <=2.3.4`
If a partial version is provided as the first version in the inclusive
range, then the missing pieces are replaced with zeroes.
* `1.2 - 2.3.4` := `>=1.2.0 <=2.3.4`
If a partial version is provided as the second version in the
inclusive range, then all versions that start with the supplied parts
of the tuple are accepted, but nothing that would be greater than the
provided tuple parts.
* `1.2.3 - 2.3` := `>=1.2.3 <2.4.0`
* `1.2.3 - 2` := `>=1.2.3 <3.0.0`
#### X-Ranges `1.2.x` `1.X` `1.2.*` `*`
Any of `X`, `x`, or `*` may be used to "stand in" for one of the
numeric values in the `[major, minor, patch]` tuple.
* `*` := `>=0.0.0` (Any version satisfies)
* `1.x` := `>=1.0.0 <2.0.0` (Matching major version)
* `1.2.x` := `>=1.2.0 <1.3.0` (Matching major and minor versions)
A partial version range is treated as an X-Range, so the special
character is in fact optional.
* `""` (empty string) := `*` := `>=0.0.0`
* `1` := `1.x.x` := `>=1.0.0 <2.0.0`
* `1.2` := `1.2.x` := `>=1.2.0 <1.3.0`
#### Tilde Ranges `~1.2.3` `~1.2` `~1`
Allows patch-level changes if a minor version is specified on the
comparator. Allows minor-level changes if not.
* `~1.2.3` := `>=1.2.3 <1.(2+1).0` := `>=1.2.3 <1.3.0`
* `~1.2` := `>=1.2.0 <1.(2+1).0` := `>=1.2.0 <1.3.0` (Same as `1.2.x`)
* `~1` := `>=1.0.0 <(1+1).0.0` := `>=1.0.0 <2.0.0` (Same as `1.x`)
* `~0.2.3` := `>=0.2.3 <0.(2+1).0` := `>=0.2.3 <0.3.0`
* `~0.2` := `>=0.2.0 <0.(2+1).0` := `>=0.2.0 <0.3.0` (Same as `0.2.x`)
* `~0` := `>=0.0.0 <(0+1).0.0` := `>=0.0.0 <1.0.0` (Same as `0.x`)
* `~1.2.3-beta.2` := `>=1.2.3-beta.2 <1.3.0` Note that prereleases in
the `1.2.3` version will be allowed, if they are greater than or
equal to `beta.2`. So, `1.2.3-beta.4` would be allowed, but
`1.2.4-beta.2` would not, because it is a prerelease of a
different `[major, minor, patch]` tuple.
#### Caret Ranges `^1.2.3` `^0.2.5` `^0.0.4`
Allows changes that do not modify the left-most non-zero digit in the
`[major, minor, patch]` tuple. In other words, this allows patch and
minor updates for versions `1.0.0` and above, patch updates for
versions `0.X >=0.1.0`, and *no* updates for versions `0.0.X`.
Many authors treat a `0.x` version as if the `x` were the major
"breaking-change" indicator.
Caret ranges are ideal when an author may make breaking changes
between `0.2.4` and `0.3.0` releases, which is a common practice.
However, it presumes that there will *not* be breaking changes between
`0.2.4` and `0.2.5`. It allows for changes that are presumed to be
additive (but non-breaking), according to commonly observed practices.
* `^1.2.3` := `>=1.2.3 <2.0.0`
* `^0.2.3` := `>=0.2.3 <0.3.0`
* `^0.0.3` := `>=0.0.3 <0.0.4`
* `^1.2.3-beta.2` := `>=1.2.3-beta.2 <2.0.0` Note that prereleases in
the `1.2.3` version will be allowed, if they are greater than or
equal to `beta.2`. So, `1.2.3-beta.4` would be allowed, but
`1.2.4-beta.2` would not, because it is a prerelease of a
different `[major, minor, patch]` tuple.
* `^0.0.3-beta` := `>=0.0.3-beta <0.0.4` Note that prereleases in the
`0.0.3` version *only* will be allowed, if they are greater than or
equal to `beta`. So, `0.0.3-pr.2` would be allowed.
When parsing caret ranges, a missing `patch` value desugars to the
number `0`, but will allow flexibility within that value, even if the
major and minor versions are both `0`.
* `^1.2.x` := `>=1.2.0 <2.0.0`
* `^0.0.x` := `>=0.0.0 <0.1.0`
* `^0.0` := `>=0.0.0 <0.1.0`
A missing `minor` and `patch` values will desugar to zero, but also
allow flexibility within those values, even if the major version is
zero.
* `^1.x` := `>=1.0.0 <2.0.0`
* `^0.x` := `>=0.0.0 <1.0.0`
### Range Grammar
Putting all this together, here is a Backus-Naur grammar for ranges,
for the benefit of parser authors:
```bnf
range-set ::= range ( logical-or range ) *
logical-or ::= ( ' ' ) * '||' ( ' ' ) *
range ::= hyphen | simple ( ' ' simple ) * | ''
hyphen ::= partial ' - ' partial
simple ::= primitive | partial | tilde | caret
primitive ::= ( '<' | '>' | '>=' | '<=' | '=' | ) partial
partial ::= xr ( '.' xr ( '.' xr qualifier ? )? )?
xr ::= 'x' | 'X' | '*' | nr
nr ::= '0' | ['1'-'9']['0'-'9']+
tilde ::= '~' partial
caret ::= '^' partial
qualifier ::= ( '-' pre )? ( '+' build )?
pre ::= parts
build ::= parts
parts ::= part ( '.' part ) *
part ::= nr | [-0-9A-Za-z]+
```
## Functions
All methods and classes take a final `loose` boolean argument that, if
true, will be more forgiving about not-quite-valid semver strings.
The resulting output will always be 100% strict, of course.
Strict-mode Comparators and Ranges will be strict about the SemVer
strings that they parse.
* `valid(v)`: Return the parsed version, or null if it's not valid.
* `inc(v, release)`: Return the version incremented by the release
type (`major`, `premajor`, `minor`, `preminor`, `patch`,
`prepatch`, or `prerelease`), or null if it's not valid
* `premajor` in one call will bump the version up to the next major
version and down to a prerelease of that major version.
`preminor`, and `prepatch` work the same way.
* If called from a non-prerelease version, the `prerelease` will work the
same as `prepatch`. It increments the patch version, then makes a
prerelease. If the input version is already a prerelease it simply
increments it.
* `major(v)`: Return the major version number.
* `minor(v)`: Return the minor version number.
* `patch(v)`: Return the patch version number.
### Comparison
* `gt(v1, v2)`: `v1 > v2`
* `gte(v1, v2)`: `v1 >= v2`
* `lt(v1, v2)`: `v1 < v2`
* `lte(v1, v2)`: `v1 <= v2`
* `eq(v1, v2)`: `v1 == v2` This is true if they're logically equivalent,
even if they're not the exact same string. You already know how to
compare strings.
* `neq(v1, v2)`: `v1 != v2` The opposite of `eq`.
* `cmp(v1, comparator, v2)`: Pass in a comparison string, and it'll call
the corresponding function above. `"==="` and `"!=="` do simple
string comparison, but are included for completeness. Throws if an
invalid comparison string is provided.
* `compare(v1, v2)`: Return `0` if `v1 == v2`, or `1` if `v1` is greater, or `-1` if
`v2` is greater. Sorts in ascending order if passed to `Array.sort()`.
* `rcompare(v1, v2)`: The reverse of compare. Sorts an array of versions
in descending order when passed to `Array.sort()`.
* `diff(v1, v2)`: Returns difference between two versions by the release type
(`major`, `premajor`, `minor`, `preminor`, `patch`, `prepatch`, or `prerelease`),
or null if the versions are the same.
### Ranges
* `validRange(range)`: Return the valid range or null if it's not valid
* `satisfies(version, range)`: Return true if the version satisfies the
range.
* `maxSatisfying(versions, range)`: Return the highest version in the list
that satisfies the range, or `null` if none of them do.
* `gtr(version, range)`: Return `true` if version is greater than all the
versions possible in the range.
* `ltr(version, range)`: Return `true` if version is less than all the
versions possible in the range.
* `outside(version, range, hilo)`: Return true if the version is outside
the bounds of the range in either the high or low direction. The
`hilo` argument must be either the string `'>'` or `'<'`. (This is
the function called by `gtr` and `ltr`.)
Note that, since ranges may be non-contiguous, a version might not be
greater than a range, less than a range, *or* satisfy a range! For
example, the range `1.2 <1.2.9 || >2.0.0` would have a hole from `1.2.9`
until `2.0.0`, so the version `1.2.10` would not be greater than the
range (because `2.0.1` satisfies, which is higher), nor less than the
range (since `1.2.8` satisfies, which is lower), and it also does not
satisfy the range.
If you want to know if a version satisfies or does not satisfy a
range, use the `satisfies(version, range)` function.

View File

@@ -0,0 +1,133 @@
#!/usr/bin/env node
// Standalone semver comparison program.
// Exits successfully and prints matching version(s) if
// any supplied version is valid and passes all tests.
var argv = process.argv.slice(2)
, versions = []
, range = []
, gt = []
, lt = []
, eq = []
, inc = null
, version = require("../package.json").version
, loose = false
, identifier = undefined
, semver = require("../semver")
, reverse = false
main()
function main () {
if (!argv.length) return help()
while (argv.length) {
var a = argv.shift()
var i = a.indexOf('=')
if (i !== -1) {
a = a.slice(0, i)
argv.unshift(a.slice(i + 1))
}
switch (a) {
case "-rv": case "-rev": case "--rev": case "--reverse":
reverse = true
break
case "-l": case "--loose":
loose = true
break
case "-v": case "--version":
versions.push(argv.shift())
break
case "-i": case "--inc": case "--increment":
switch (argv[0]) {
case "major": case "minor": case "patch": case "prerelease":
case "premajor": case "preminor": case "prepatch":
inc = argv.shift()
break
default:
inc = "patch"
break
}
break
case "--preid":
identifier = argv.shift()
break
case "-r": case "--range":
range.push(argv.shift())
break
case "-h": case "--help": case "-?":
return help()
default:
versions.push(a)
break
}
}
versions = versions.filter(function (v) {
return semver.valid(v, loose)
})
if (!versions.length) return fail()
if (inc && (versions.length !== 1 || range.length))
return failInc()
for (var i = 0, l = range.length; i < l ; i ++) {
versions = versions.filter(function (v) {
return semver.satisfies(v, range[i], loose)
})
if (!versions.length) return fail()
}
return success(versions)
}
function failInc () {
console.error("--inc can only be used on a single version with no range")
fail()
}
function fail () { process.exit(1) }
function success () {
var compare = reverse ? "rcompare" : "compare"
versions.sort(function (a, b) {
return semver[compare](a, b, loose)
}).map(function (v) {
return semver.clean(v, loose)
}).map(function (v) {
return inc ? semver.inc(v, inc, loose, identifier) : v
}).forEach(function (v,i,_) { console.log(v) })
}
function help () {
console.log(["SemVer " + version
,""
,"A JavaScript implementation of the http://semver.org/ specification"
,"Copyright Isaac Z. Schlueter"
,""
,"Usage: semver [options] <version> [<version> [...]]"
,"Prints valid versions sorted by SemVer precedence"
,""
,"Options:"
,"-r --range <range>"
," Print versions that match the specified range."
,""
,"-i --increment [<level>]"
," Increment a version by the specified level. Level can"
," be one of: major, minor, patch, premajor, preminor,"
," prepatch, or prerelease. Default level is 'patch'."
," Only one version may be specified."
,""
,"--preid <identifier>"
," Identifier to be used to prefix premajor, preminor,"
," prepatch or prerelease version increments."
,""
,"-l --loose"
," Interpret versions and ranges loosely"
,""
,"Program exits successfully if any valid version satisfies"
,"all supplied ranges, and prints all satisfying versions."
,""
,"If no satisfying versions are found, then exits failure."
,""
,"Versions are printed in ascending order, so supplying"
,"multiple versions to the utility will just sort them."
].join("\n"))
}

View File

@@ -0,0 +1,51 @@
{
"name": "semver",
"version": "5.1.0",
"description": "The semantic version parser used by npm.",
"main": "semver.js",
"scripts": {
"test": "tap test/*.js"
},
"devDependencies": {
"tap": "^2.0.0"
},
"license": "ISC",
"repository": {
"type": "git",
"url": "git+https://github.com/npm/node-semver.git"
},
"bin": {
"semver": "./bin/semver"
},
"gitHead": "8e33a30e62e40e4983d1c5f55e794331b861aadc",
"bugs": {
"url": "https://github.com/npm/node-semver/issues"
},
"homepage": "https://github.com/npm/node-semver#readme",
"_id": "semver@5.1.0",
"_shasum": "85f2cf8550465c4df000cf7d86f6b054106ab9e5",
"_from": "semver@2 || 3 || 4 || 5",
"_npmVersion": "3.3.2",
"_nodeVersion": "4.0.0",
"_npmUser": {
"name": "isaacs",
"email": "i@izs.me"
},
"dist": {
"shasum": "85f2cf8550465c4df000cf7d86f6b054106ab9e5",
"tarball": "http://registry.npmjs.org/semver/-/semver-5.1.0.tgz"
},
"maintainers": [
{
"name": "isaacs",
"email": "isaacs@npmjs.com"
},
{
"name": "othiym23",
"email": "ogd@aoaioxxysz.net"
}
],
"directories": {},
"_resolved": "https://registry.npmjs.org/semver/-/semver-5.1.0.tgz",
"readme": "ERROR: No README data found!"
}

View File

@@ -0,0 +1,16 @@
range-set ::= range ( logical-or range ) *
logical-or ::= ( ' ' ) * '||' ( ' ' ) *
range ::= hyphen | simple ( ' ' simple ) * | ''
hyphen ::= partial ' - ' partial
simple ::= primitive | partial | tilde | caret
primitive ::= ( '<' | '>' | '>=' | '<=' | '=' | ) partial
partial ::= xr ( '.' xr ( '.' xr qualifier ? )? )?
xr ::= 'x' | 'X' | '*' | nr
nr ::= '0' | ['1'-'9']['0'-'9']+
tilde ::= '~' partial
caret ::= '^' partial
qualifier ::= ( '-' pre )? ( '+' build )?
pre ::= parts
build ::= parts
parts ::= part ( '.' part ) *
part ::= nr | [-0-9A-Za-z]+

View File

@@ -0,0 +1,31 @@
var test = require('tap').test
var semver = require('../')
test('long version is too long', function (t) {
var v = '1.2.' + new Array(256).join('1')
t.throws(function () {
new semver.SemVer(v)
})
t.equal(semver.valid(v, false), null)
t.equal(semver.valid(v, true), null)
t.equal(semver.inc(v, 'patch'), null)
t.end()
})
test('big number is like too long version', function (t) {
var v = '1.2.' + new Array(100).join('1')
t.throws(function () {
new semver.SemVer(v)
})
t.equal(semver.valid(v, false), null)
t.equal(semver.valid(v, true), null)
t.equal(semver.inc(v, 'patch'), null)
t.end()
})
test('parsing null does not throw', function (t) {
t.equal(semver.parse(null), null)
t.equal(semver.parse({}), null)
t.equal(semver.parse(new semver.SemVer('1.2.3')).version, '1.2.3')
t.end()
})

View File

@@ -0,0 +1,29 @@
var tap = require('tap');
var test = tap.test;
var semver = require('../semver.js');
var clean = semver.clean;
test('\nclean tests', function(t) {
// [range, version]
// Version should be detectable despite extra characters
[
['1.2.3', '1.2.3'],
[' 1.2.3 ', '1.2.3'],
[' 1.2.3-4 ', '1.2.3-4'],
[' 1.2.3-pre ', '1.2.3-pre'],
[' =v1.2.3 ', '1.2.3'],
['v1.2.3', '1.2.3'],
[' v1.2.3 ', '1.2.3'],
['\t1.2.3', '1.2.3'],
['>1.2.3', null],
['~1.2.3', null],
['<=1.2.3', null],
['1.2.x', null]
].forEach(function(tuple) {
var range = tuple[0];
var version = tuple[1];
var msg = 'clean(' + range + ') = ' + version;
t.equal(clean(range), version, msg);
});
t.end();
});

View File

@@ -0,0 +1,173 @@
var tap = require('tap');
var test = tap.test;
var semver = require('../semver.js');
var gtr = semver.gtr;
test('\ngtr tests', function(t) {
// [range, version, loose]
// Version should be greater than range
[
['~1.2.2', '1.3.0'],
['~0.6.1-1', '0.7.1-1'],
['1.0.0 - 2.0.0', '2.0.1'],
['1.0.0', '1.0.1-beta1'],
['1.0.0', '2.0.0'],
['<=2.0.0', '2.1.1'],
['<=2.0.0', '3.2.9'],
['<2.0.0', '2.0.0'],
['0.1.20 || 1.2.4', '1.2.5'],
['2.x.x', '3.0.0'],
['1.2.x', '1.3.0'],
['1.2.x || 2.x', '3.0.0'],
['2.*.*', '5.0.1'],
['1.2.*', '1.3.3'],
['1.2.* || 2.*', '4.0.0'],
['2', '3.0.0'],
['2.3', '2.4.2'],
['~2.4', '2.5.0'], // >=2.4.0 <2.5.0
['~2.4', '2.5.5'],
['~>3.2.1', '3.3.0'], // >=3.2.1 <3.3.0
['~1', '2.2.3'], // >=1.0.0 <2.0.0
['~>1', '2.2.4'],
['~> 1', '3.2.3'],
['~1.0', '1.1.2'], // >=1.0.0 <1.1.0
['~ 1.0', '1.1.0'],
['<1.2', '1.2.0'],
['< 1.2', '1.2.1'],
['1', '2.0.0beta', true],
['~v0.5.4-pre', '0.6.0'],
['~v0.5.4-pre', '0.6.1-pre'],
['=0.7.x', '0.8.0'],
['=0.7.x', '0.8.0-asdf'],
['<0.7.x', '0.7.0'],
['~1.2.2', '1.3.0'],
['1.0.0 - 2.0.0', '2.2.3'],
['1.0.0', '1.0.1'],
['<=2.0.0', '3.0.0'],
['<=2.0.0', '2.9999.9999'],
['<=2.0.0', '2.2.9'],
['<2.0.0', '2.9999.9999'],
['<2.0.0', '2.2.9'],
['2.x.x', '3.1.3'],
['1.2.x', '1.3.3'],
['1.2.x || 2.x', '3.1.3'],
['2.*.*', '3.1.3'],
['1.2.*', '1.3.3'],
['1.2.* || 2.*', '3.1.3'],
['2', '3.1.2'],
['2.3', '2.4.1'],
['~2.4', '2.5.0'], // >=2.4.0 <2.5.0
['~>3.2.1', '3.3.2'], // >=3.2.1 <3.3.0
['~1', '2.2.3'], // >=1.0.0 <2.0.0
['~>1', '2.2.3'],
['~1.0', '1.1.0'], // >=1.0.0 <1.1.0
['<1', '1.0.0'],
['1', '2.0.0beta', true],
['<1', '1.0.0beta', true],
['< 1', '1.0.0beta', true],
['=0.7.x', '0.8.2'],
['<0.7.x', '0.7.2']
].forEach(function(tuple) {
var range = tuple[0];
var version = tuple[1];
var loose = tuple[2] || false;
var msg = 'gtr(' + version + ', ' + range + ', ' + loose + ')';
t.ok(gtr(version, range, loose), msg);
});
t.end();
});
test('\nnegative gtr tests', function(t) {
// [range, version, loose]
// Version should NOT be greater than range
[
['~0.6.1-1', '0.6.1-1'],
['1.0.0 - 2.0.0', '1.2.3'],
['1.0.0 - 2.0.0', '0.9.9'],
['1.0.0', '1.0.0'],
['>=*', '0.2.4'],
['', '1.0.0', true],
['*', '1.2.3'],
['*', 'v1.2.3-foo'],
['>=1.0.0', '1.0.0'],
['>=1.0.0', '1.0.1'],
['>=1.0.0', '1.1.0'],
['>1.0.0', '1.0.1'],
['>1.0.0', '1.1.0'],
['<=2.0.0', '2.0.0'],
['<=2.0.0', '1.9999.9999'],
['<=2.0.0', '0.2.9'],
['<2.0.0', '1.9999.9999'],
['<2.0.0', '0.2.9'],
['>= 1.0.0', '1.0.0'],
['>= 1.0.0', '1.0.1'],
['>= 1.0.0', '1.1.0'],
['> 1.0.0', '1.0.1'],
['> 1.0.0', '1.1.0'],
['<= 2.0.0', '2.0.0'],
['<= 2.0.0', '1.9999.9999'],
['<= 2.0.0', '0.2.9'],
['< 2.0.0', '1.9999.9999'],
['<\t2.0.0', '0.2.9'],
['>=0.1.97', 'v0.1.97'],
['>=0.1.97', '0.1.97'],
['0.1.20 || 1.2.4', '1.2.4'],
['0.1.20 || >1.2.4', '1.2.4'],
['0.1.20 || 1.2.4', '1.2.3'],
['0.1.20 || 1.2.4', '0.1.20'],
['>=0.2.3 || <0.0.1', '0.0.0'],
['>=0.2.3 || <0.0.1', '0.2.3'],
['>=0.2.3 || <0.0.1', '0.2.4'],
['||', '1.3.4'],
['2.x.x', '2.1.3'],
['1.2.x', '1.2.3'],
['1.2.x || 2.x', '2.1.3'],
['1.2.x || 2.x', '1.2.3'],
['x', '1.2.3'],
['2.*.*', '2.1.3'],
['1.2.*', '1.2.3'],
['1.2.* || 2.*', '2.1.3'],
['1.2.* || 2.*', '1.2.3'],
['1.2.* || 2.*', '1.2.3'],
['*', '1.2.3'],
['2', '2.1.2'],
['2.3', '2.3.1'],
['~2.4', '2.4.0'], // >=2.4.0 <2.5.0
['~2.4', '2.4.5'],
['~>3.2.1', '3.2.2'], // >=3.2.1 <3.3.0
['~1', '1.2.3'], // >=1.0.0 <2.0.0
['~>1', '1.2.3'],
['~> 1', '1.2.3'],
['~1.0', '1.0.2'], // >=1.0.0 <1.1.0
['~ 1.0', '1.0.2'],
['>=1', '1.0.0'],
['>= 1', '1.0.0'],
['<1.2', '1.1.1'],
['< 1.2', '1.1.1'],
['1', '1.0.0beta', true],
['~v0.5.4-pre', '0.5.5'],
['~v0.5.4-pre', '0.5.4'],
['=0.7.x', '0.7.2'],
['>=0.7.x', '0.7.2'],
['=0.7.x', '0.7.0-asdf'],
['>=0.7.x', '0.7.0-asdf'],
['<=0.7.x', '0.6.2'],
['>0.2.3 >0.2.4 <=0.2.5', '0.2.5'],
['>=0.2.3 <=0.2.4', '0.2.4'],
['1.0.0 - 2.0.0', '2.0.0'],
['^1', '0.0.0-0'],
['^3.0.0', '2.0.0'],
['^1.0.0 || ~2.0.1', '2.0.0'],
['^0.1.0 || ~3.0.1 || 5.0.0', '3.2.0'],
['^0.1.0 || ~3.0.1 || 5.0.0', '1.0.0beta', true],
['^0.1.0 || ~3.0.1 || 5.0.0', '5.0.0-0', true],
['^0.1.0 || ~3.0.1 || >4 <=5.0.0', '3.5.0']
].forEach(function(tuple) {
var range = tuple[0];
var version = tuple[1];
var loose = tuple[2] || false;
var msg = '!gtr(' + version + ', ' + range + ', ' + loose + ')';
t.notOk(gtr(version, range, loose), msg);
});
t.end();
});

View File

@@ -0,0 +1,698 @@
'use strict';
var tap = require('tap');
var test = tap.test;
var semver = require('../semver.js');
var eq = semver.eq;
var gt = semver.gt;
var lt = semver.lt;
var neq = semver.neq;
var cmp = semver.cmp;
var gte = semver.gte;
var lte = semver.lte;
var satisfies = semver.satisfies;
var validRange = semver.validRange;
var inc = semver.inc;
var diff = semver.diff;
var replaceStars = semver.replaceStars;
var toComparators = semver.toComparators;
var SemVer = semver.SemVer;
var Range = semver.Range;
test('\ncomparison tests', function(t) {
// [version1, version2]
// version1 should be greater than version2
[['0.0.0', '0.0.0-foo'],
['0.0.1', '0.0.0'],
['1.0.0', '0.9.9'],
['0.10.0', '0.9.0'],
['0.99.0', '0.10.0'],
['2.0.0', '1.2.3'],
['v0.0.0', '0.0.0-foo', true],
['v0.0.1', '0.0.0', true],
['v1.0.0', '0.9.9', true],
['v0.10.0', '0.9.0', true],
['v0.99.0', '0.10.0', true],
['v2.0.0', '1.2.3', true],
['0.0.0', 'v0.0.0-foo', true],
['0.0.1', 'v0.0.0', true],
['1.0.0', 'v0.9.9', true],
['0.10.0', 'v0.9.0', true],
['0.99.0', 'v0.10.0', true],
['2.0.0', 'v1.2.3', true],
['1.2.3', '1.2.3-asdf'],
['1.2.3', '1.2.3-4'],
['1.2.3', '1.2.3-4-foo'],
['1.2.3-5-foo', '1.2.3-5'],
['1.2.3-5', '1.2.3-4'],
['1.2.3-5-foo', '1.2.3-5-Foo'],
['3.0.0', '2.7.2+asdf'],
['1.2.3-a.10', '1.2.3-a.5'],
['1.2.3-a.b', '1.2.3-a.5'],
['1.2.3-a.b', '1.2.3-a'],
['1.2.3-a.b.c.10.d.5', '1.2.3-a.b.c.5.d.100'],
['1.2.3-r2', '1.2.3-r100'],
['1.2.3-r100', '1.2.3-R2']
].forEach(function(v) {
var v0 = v[0];
var v1 = v[1];
var loose = v[2];
t.ok(gt(v0, v1, loose), "gt('" + v0 + "', '" + v1 + "')");
t.ok(lt(v1, v0, loose), "lt('" + v1 + "', '" + v0 + "')");
t.ok(!gt(v1, v0, loose), "!gt('" + v1 + "', '" + v0 + "')");
t.ok(!lt(v0, v1, loose), "!lt('" + v0 + "', '" + v1 + "')");
t.ok(eq(v0, v0, loose), "eq('" + v0 + "', '" + v0 + "')");
t.ok(eq(v1, v1, loose), "eq('" + v1 + "', '" + v1 + "')");
t.ok(neq(v0, v1, loose), "neq('" + v0 + "', '" + v1 + "')");
t.ok(cmp(v1, '==', v1, loose), "cmp('" + v1 + "' == '" + v1 + "')");
t.ok(cmp(v0, '>=', v1, loose), "cmp('" + v0 + "' >= '" + v1 + "')");
t.ok(cmp(v1, '<=', v0, loose), "cmp('" + v1 + "' <= '" + v0 + "')");
t.ok(cmp(v0, '!=', v1, loose), "cmp('" + v0 + "' != '" + v1 + "')");
});
t.end();
});
test('\nequality tests', function(t) {
// [version1, version2]
// version1 should be equivalent to version2
[['1.2.3', 'v1.2.3', true],
['1.2.3', '=1.2.3', true],
['1.2.3', 'v 1.2.3', true],
['1.2.3', '= 1.2.3', true],
['1.2.3', ' v1.2.3', true],
['1.2.3', ' =1.2.3', true],
['1.2.3', ' v 1.2.3', true],
['1.2.3', ' = 1.2.3', true],
['1.2.3-0', 'v1.2.3-0', true],
['1.2.3-0', '=1.2.3-0', true],
['1.2.3-0', 'v 1.2.3-0', true],
['1.2.3-0', '= 1.2.3-0', true],
['1.2.3-0', ' v1.2.3-0', true],
['1.2.3-0', ' =1.2.3-0', true],
['1.2.3-0', ' v 1.2.3-0', true],
['1.2.3-0', ' = 1.2.3-0', true],
['1.2.3-1', 'v1.2.3-1', true],
['1.2.3-1', '=1.2.3-1', true],
['1.2.3-1', 'v 1.2.3-1', true],
['1.2.3-1', '= 1.2.3-1', true],
['1.2.3-1', ' v1.2.3-1', true],
['1.2.3-1', ' =1.2.3-1', true],
['1.2.3-1', ' v 1.2.3-1', true],
['1.2.3-1', ' = 1.2.3-1', true],
['1.2.3-beta', 'v1.2.3-beta', true],
['1.2.3-beta', '=1.2.3-beta', true],
['1.2.3-beta', 'v 1.2.3-beta', true],
['1.2.3-beta', '= 1.2.3-beta', true],
['1.2.3-beta', ' v1.2.3-beta', true],
['1.2.3-beta', ' =1.2.3-beta', true],
['1.2.3-beta', ' v 1.2.3-beta', true],
['1.2.3-beta', ' = 1.2.3-beta', true],
['1.2.3-beta+build', ' = 1.2.3-beta+otherbuild', true],
['1.2.3+build', ' = 1.2.3+otherbuild', true],
['1.2.3-beta+build', '1.2.3-beta+otherbuild'],
['1.2.3+build', '1.2.3+otherbuild'],
[' v1.2.3+build', '1.2.3+otherbuild']
].forEach(function(v) {
var v0 = v[0];
var v1 = v[1];
var loose = v[2];
t.ok(eq(v0, v1, loose), "eq('" + v0 + "', '" + v1 + "')");
t.ok(!neq(v0, v1, loose), "!neq('" + v0 + "', '" + v1 + "')");
t.ok(cmp(v0, '==', v1, loose), 'cmp(' + v0 + '==' + v1 + ')');
t.ok(!cmp(v0, '!=', v1, loose), '!cmp(' + v0 + '!=' + v1 + ')');
t.ok(!cmp(v0, '===', v1, loose), '!cmp(' + v0 + '===' + v1 + ')');
t.ok(cmp(v0, '!==', v1, loose), 'cmp(' + v0 + '!==' + v1 + ')');
t.ok(!gt(v0, v1, loose), "!gt('" + v0 + "', '" + v1 + "')");
t.ok(gte(v0, v1, loose), "gte('" + v0 + "', '" + v1 + "')");
t.ok(!lt(v0, v1, loose), "!lt('" + v0 + "', '" + v1 + "')");
t.ok(lte(v0, v1, loose), "lte('" + v0 + "', '" + v1 + "')");
});
t.end();
});
test('\nrange tests', function(t) {
// [range, version]
// version should be included by range
[['1.0.0 - 2.0.0', '1.2.3'],
['^1.2.3+build', '1.2.3'],
['^1.2.3+build', '1.3.0'],
['1.2.3-pre+asdf - 2.4.3-pre+asdf', '1.2.3'],
['1.2.3pre+asdf - 2.4.3-pre+asdf', '1.2.3', true],
['1.2.3-pre+asdf - 2.4.3pre+asdf', '1.2.3', true],
['1.2.3pre+asdf - 2.4.3pre+asdf', '1.2.3', true],
['1.2.3-pre+asdf - 2.4.3-pre+asdf', '1.2.3-pre.2'],
['1.2.3-pre+asdf - 2.4.3-pre+asdf', '2.4.3-alpha'],
['1.2.3+asdf - 2.4.3+asdf', '1.2.3'],
['1.0.0', '1.0.0'],
['>=*', '0.2.4'],
['', '1.0.0'],
['*', '1.2.3'],
['*', 'v1.2.3', true],
['>=1.0.0', '1.0.0'],
['>=1.0.0', '1.0.1'],
['>=1.0.0', '1.1.0'],
['>1.0.0', '1.0.1'],
['>1.0.0', '1.1.0'],
['<=2.0.0', '2.0.0'],
['<=2.0.0', '1.9999.9999'],
['<=2.0.0', '0.2.9'],
['<2.0.0', '1.9999.9999'],
['<2.0.0', '0.2.9'],
['>= 1.0.0', '1.0.0'],
['>= 1.0.0', '1.0.1'],
['>= 1.0.0', '1.1.0'],
['> 1.0.0', '1.0.1'],
['> 1.0.0', '1.1.0'],
['<= 2.0.0', '2.0.0'],
['<= 2.0.0', '1.9999.9999'],
['<= 2.0.0', '0.2.9'],
['< 2.0.0', '1.9999.9999'],
['<\t2.0.0', '0.2.9'],
['>=0.1.97', 'v0.1.97', true],
['>=0.1.97', '0.1.97'],
['0.1.20 || 1.2.4', '1.2.4'],
['>=0.2.3 || <0.0.1', '0.0.0'],
['>=0.2.3 || <0.0.1', '0.2.3'],
['>=0.2.3 || <0.0.1', '0.2.4'],
['||', '1.3.4'],
['2.x.x', '2.1.3'],
['1.2.x', '1.2.3'],
['1.2.x || 2.x', '2.1.3'],
['1.2.x || 2.x', '1.2.3'],
['x', '1.2.3'],
['2.*.*', '2.1.3'],
['1.2.*', '1.2.3'],
['1.2.* || 2.*', '2.1.3'],
['1.2.* || 2.*', '1.2.3'],
['*', '1.2.3'],
['2', '2.1.2'],
['2.3', '2.3.1'],
['~2.4', '2.4.0'], // >=2.4.0 <2.5.0
['~2.4', '2.4.5'],
['~>3.2.1', '3.2.2'], // >=3.2.1 <3.3.0,
['~1', '1.2.3'], // >=1.0.0 <2.0.0
['~>1', '1.2.3'],
['~> 1', '1.2.3'],
['~1.0', '1.0.2'], // >=1.0.0 <1.1.0,
['~ 1.0', '1.0.2'],
['~ 1.0.3', '1.0.12'],
['>=1', '1.0.0'],
['>= 1', '1.0.0'],
['<1.2', '1.1.1'],
['< 1.2', '1.1.1'],
['~v0.5.4-pre', '0.5.5'],
['~v0.5.4-pre', '0.5.4'],
['=0.7.x', '0.7.2'],
['<=0.7.x', '0.7.2'],
['>=0.7.x', '0.7.2'],
['<=0.7.x', '0.6.2'],
['~1.2.1 >=1.2.3', '1.2.3'],
['~1.2.1 =1.2.3', '1.2.3'],
['~1.2.1 1.2.3', '1.2.3'],
['~1.2.1 >=1.2.3 1.2.3', '1.2.3'],
['~1.2.1 1.2.3 >=1.2.3', '1.2.3'],
['~1.2.1 1.2.3', '1.2.3'],
['>=1.2.1 1.2.3', '1.2.3'],
['1.2.3 >=1.2.1', '1.2.3'],
['>=1.2.3 >=1.2.1', '1.2.3'],
['>=1.2.1 >=1.2.3', '1.2.3'],
['>=1.2', '1.2.8'],
['^1.2.3', '1.8.1'],
['^0.1.2', '0.1.2'],
['^0.1', '0.1.2'],
['^1.2', '1.4.2'],
['^1.2 ^1', '1.4.2'],
['^1.2.3-alpha', '1.2.3-pre'],
['^1.2.0-alpha', '1.2.0-pre'],
['^0.0.1-alpha', '0.0.1-beta']
].forEach(function(v) {
var range = v[0];
var ver = v[1];
var loose = v[2];
t.ok(satisfies(ver, range, loose), range + ' satisfied by ' + ver);
});
t.end();
});
test('\nnegative range tests', function(t) {
// [range, version]
// version should not be included by range
[['1.0.0 - 2.0.0', '2.2.3'],
['1.2.3+asdf - 2.4.3+asdf', '1.2.3-pre.2'],
['1.2.3+asdf - 2.4.3+asdf', '2.4.3-alpha'],
['^1.2.3+build', '2.0.0'],
['^1.2.3+build', '1.2.0'],
['^1.2.3', '1.2.3-pre'],
['^1.2', '1.2.0-pre'],
['>1.2', '1.3.0-beta'],
['<=1.2.3', '1.2.3-beta'],
['^1.2.3', '1.2.3-beta'],
['=0.7.x', '0.7.0-asdf'],
['>=0.7.x', '0.7.0-asdf'],
['1', '1.0.0beta', true],
['<1', '1.0.0beta', true],
['< 1', '1.0.0beta', true],
['1.0.0', '1.0.1'],
['>=1.0.0', '0.0.0'],
['>=1.0.0', '0.0.1'],
['>=1.0.0', '0.1.0'],
['>1.0.0', '0.0.1'],
['>1.0.0', '0.1.0'],
['<=2.0.0', '3.0.0'],
['<=2.0.0', '2.9999.9999'],
['<=2.0.0', '2.2.9'],
['<2.0.0', '2.9999.9999'],
['<2.0.0', '2.2.9'],
['>=0.1.97', 'v0.1.93', true],
['>=0.1.97', '0.1.93'],
['0.1.20 || 1.2.4', '1.2.3'],
['>=0.2.3 || <0.0.1', '0.0.3'],
['>=0.2.3 || <0.0.1', '0.2.2'],
['2.x.x', '1.1.3'],
['2.x.x', '3.1.3'],
['1.2.x', '1.3.3'],
['1.2.x || 2.x', '3.1.3'],
['1.2.x || 2.x', '1.1.3'],
['2.*.*', '1.1.3'],
['2.*.*', '3.1.3'],
['1.2.*', '1.3.3'],
['1.2.* || 2.*', '3.1.3'],
['1.2.* || 2.*', '1.1.3'],
['2', '1.1.2'],
['2.3', '2.4.1'],
['~2.4', '2.5.0'], // >=2.4.0 <2.5.0
['~2.4', '2.3.9'],
['~>3.2.1', '3.3.2'], // >=3.2.1 <3.3.0
['~>3.2.1', '3.2.0'], // >=3.2.1 <3.3.0
['~1', '0.2.3'], // >=1.0.0 <2.0.0
['~>1', '2.2.3'],
['~1.0', '1.1.0'], // >=1.0.0 <1.1.0
['<1', '1.0.0'],
['>=1.2', '1.1.1'],
['1', '2.0.0beta', true],
['~v0.5.4-beta', '0.5.4-alpha'],
['=0.7.x', '0.8.2'],
['>=0.7.x', '0.6.2'],
['<0.7.x', '0.7.2'],
['<1.2.3', '1.2.3-beta'],
['=1.2.3', '1.2.3-beta'],
['>1.2', '1.2.8'],
['^1.2.3', '2.0.0-alpha'],
['^1.2.3', '1.2.2'],
['^1.2', '1.1.9'],
['*', 'v1.2.3-foo', true],
// invalid ranges never satisfied!
['blerg', '1.2.3'],
['git+https://user:password0123@github.com/foo', '123.0.0', true],
['^1.2.3', '2.0.0-pre']
].forEach(function(v) {
var range = v[0];
var ver = v[1];
var loose = v[2];
var found = satisfies(ver, range, loose);
t.ok(!found, ver + ' not satisfied by ' + range);
});
t.end();
});
test('\nincrement versions test', function(t) {
// [version, inc, result, identifier]
// inc(version, inc) -> result
[['1.2.3', 'major', '2.0.0'],
['1.2.3', 'minor', '1.3.0'],
['1.2.3', 'patch', '1.2.4'],
['1.2.3tag', 'major', '2.0.0', true],
['1.2.3-tag', 'major', '2.0.0'],
['1.2.3', 'fake', null],
['1.2.0-0', 'patch', '1.2.0'],
['fake', 'major', null],
['1.2.3-4', 'major', '2.0.0'],
['1.2.3-4', 'minor', '1.3.0'],
['1.2.3-4', 'patch', '1.2.3'],
['1.2.3-alpha.0.beta', 'major', '2.0.0'],
['1.2.3-alpha.0.beta', 'minor', '1.3.0'],
['1.2.3-alpha.0.beta', 'patch', '1.2.3'],
['1.2.4', 'prerelease', '1.2.5-0'],
['1.2.3-0', 'prerelease', '1.2.3-1'],
['1.2.3-alpha.0', 'prerelease', '1.2.3-alpha.1'],
['1.2.3-alpha.1', 'prerelease', '1.2.3-alpha.2'],
['1.2.3-alpha.2', 'prerelease', '1.2.3-alpha.3'],
['1.2.3-alpha.0.beta', 'prerelease', '1.2.3-alpha.1.beta'],
['1.2.3-alpha.1.beta', 'prerelease', '1.2.3-alpha.2.beta'],
['1.2.3-alpha.2.beta', 'prerelease', '1.2.3-alpha.3.beta'],
['1.2.3-alpha.10.0.beta', 'prerelease', '1.2.3-alpha.10.1.beta'],
['1.2.3-alpha.10.1.beta', 'prerelease', '1.2.3-alpha.10.2.beta'],
['1.2.3-alpha.10.2.beta', 'prerelease', '1.2.3-alpha.10.3.beta'],
['1.2.3-alpha.10.beta.0', 'prerelease', '1.2.3-alpha.10.beta.1'],
['1.2.3-alpha.10.beta.1', 'prerelease', '1.2.3-alpha.10.beta.2'],
['1.2.3-alpha.10.beta.2', 'prerelease', '1.2.3-alpha.10.beta.3'],
['1.2.3-alpha.9.beta', 'prerelease', '1.2.3-alpha.10.beta'],
['1.2.3-alpha.10.beta', 'prerelease', '1.2.3-alpha.11.beta'],
['1.2.3-alpha.11.beta', 'prerelease', '1.2.3-alpha.12.beta'],
['1.2.0', 'prepatch', '1.2.1-0'],
['1.2.0-1', 'prepatch', '1.2.1-0'],
['1.2.0', 'preminor', '1.3.0-0'],
['1.2.3-1', 'preminor', '1.3.0-0'],
['1.2.0', 'premajor', '2.0.0-0'],
['1.2.3-1', 'premajor', '2.0.0-0'],
['1.2.0-1', 'minor', '1.2.0'],
['1.0.0-1', 'major', '1.0.0'],
['1.2.3', 'major', '2.0.0', false, 'dev'],
['1.2.3', 'minor', '1.3.0', false, 'dev'],
['1.2.3', 'patch', '1.2.4', false, 'dev'],
['1.2.3tag', 'major', '2.0.0', true, 'dev'],
['1.2.3-tag', 'major', '2.0.0', false, 'dev'],
['1.2.3', 'fake', null, false, 'dev'],
['1.2.0-0', 'patch', '1.2.0', false, 'dev'],
['fake', 'major', null, false, 'dev'],
['1.2.3-4', 'major', '2.0.0', false, 'dev'],
['1.2.3-4', 'minor', '1.3.0', false, 'dev'],
['1.2.3-4', 'patch', '1.2.3', false, 'dev'],
['1.2.3-alpha.0.beta', 'major', '2.0.0', false, 'dev'],
['1.2.3-alpha.0.beta', 'minor', '1.3.0', false, 'dev'],
['1.2.3-alpha.0.beta', 'patch', '1.2.3', false, 'dev'],
['1.2.4', 'prerelease', '1.2.5-dev.0', false, 'dev'],
['1.2.3-0', 'prerelease', '1.2.3-dev.0', false, 'dev'],
['1.2.3-alpha.0', 'prerelease', '1.2.3-dev.0', false, 'dev'],
['1.2.3-alpha.0', 'prerelease', '1.2.3-alpha.1', false, 'alpha'],
['1.2.3-alpha.0.beta', 'prerelease', '1.2.3-dev.0', false, 'dev'],
['1.2.3-alpha.0.beta', 'prerelease', '1.2.3-alpha.1.beta', false, 'alpha'],
['1.2.3-alpha.10.0.beta', 'prerelease', '1.2.3-dev.0', false, 'dev'],
['1.2.3-alpha.10.0.beta', 'prerelease', '1.2.3-alpha.10.1.beta', false, 'alpha'],
['1.2.3-alpha.10.1.beta', 'prerelease', '1.2.3-alpha.10.2.beta', false, 'alpha'],
['1.2.3-alpha.10.2.beta', 'prerelease', '1.2.3-alpha.10.3.beta', false, 'alpha'],
['1.2.3-alpha.10.beta.0', 'prerelease', '1.2.3-dev.0', false, 'dev'],
['1.2.3-alpha.10.beta.0', 'prerelease', '1.2.3-alpha.10.beta.1', false, 'alpha'],
['1.2.3-alpha.10.beta.1', 'prerelease', '1.2.3-alpha.10.beta.2', false, 'alpha'],
['1.2.3-alpha.10.beta.2', 'prerelease', '1.2.3-alpha.10.beta.3', false, 'alpha'],
['1.2.3-alpha.9.beta', 'prerelease', '1.2.3-dev.0', false, 'dev'],
['1.2.3-alpha.9.beta', 'prerelease', '1.2.3-alpha.10.beta', false, 'alpha'],
['1.2.3-alpha.10.beta', 'prerelease', '1.2.3-alpha.11.beta', false, 'alpha'],
['1.2.3-alpha.11.beta', 'prerelease', '1.2.3-alpha.12.beta', false, 'alpha'],
['1.2.0', 'prepatch', '1.2.1-dev.0', false, 'dev'],
['1.2.0-1', 'prepatch', '1.2.1-dev.0', false, 'dev'],
['1.2.0', 'preminor', '1.3.0-dev.0', false, 'dev'],
['1.2.3-1', 'preminor', '1.3.0-dev.0', false, 'dev'],
['1.2.0', 'premajor', '2.0.0-dev.0', false, 'dev'],
['1.2.3-1', 'premajor', '2.0.0-dev.0', false, 'dev'],
['1.2.0-1', 'minor', '1.2.0', false, 'dev'],
['1.0.0-1', 'major', '1.0.0', false, 'dev'],
['1.2.3-dev.bar', 'prerelease', '1.2.3-dev.0', false, 'dev']
].forEach(function(v) {
var pre = v[0];
var what = v[1];
var wanted = v[2];
var loose = v[3];
var id = v[4];
var found = inc(pre, what, loose, id);
var cmd = 'inc(' + pre + ', ' + what + ', ' + id + ')';
t.equal(found, wanted, cmd + ' === ' + wanted);
var parsed = semver.parse(pre, loose);
if (wanted) {
parsed.inc(what, id);
t.equal(parsed.version, wanted, cmd + ' object version updated');
t.equal(parsed.raw, wanted, cmd + ' object raw field updated');
} else if (parsed) {
t.throws(function () {
parsed.inc(what, id)
})
} else {
t.equal(parsed, null)
}
});
t.end();
});
test('\ndiff versions test', function(t) {
// [version1, version2, result]
// diff(version1, version2) -> result
[['1.2.3', '0.2.3', 'major'],
['1.4.5', '0.2.3', 'major'],
['1.2.3', '2.0.0-pre', 'premajor'],
['1.2.3', '1.3.3', 'minor'],
['1.0.1', '1.1.0-pre', 'preminor'],
['1.2.3', '1.2.4', 'patch'],
['1.2.3', '1.2.4-pre', 'prepatch'],
['0.0.1', '0.0.1-pre', 'prerelease'],
['0.0.1', '0.0.1-pre-2', 'prerelease'],
['1.1.0', '1.1.0-pre', 'prerelease'],
['1.1.0-pre-1', '1.1.0-pre-2', 'prerelease'],
['1.0.0', '1.0.0', null]
].forEach(function(v) {
var version1 = v[0];
var version2 = v[1];
var wanted = v[2];
var found = diff(version1, version2);
var cmd = 'diff(' + version1 + ', ' + version2 + ')';
t.equal(found, wanted, cmd + ' === ' + wanted);
});
t.end();
});
test('\nvalid range test', function(t) {
// [range, result]
// validRange(range) -> result
// translate ranges into their canonical form
[['1.0.0 - 2.0.0', '>=1.0.0 <=2.0.0'],
['1.0.0', '1.0.0'],
['>=*', '*'],
['', '*'],
['*', '*'],
['*', '*'],
['>=1.0.0', '>=1.0.0'],
['>1.0.0', '>1.0.0'],
['<=2.0.0', '<=2.0.0'],
['1', '>=1.0.0 <2.0.0'],
['<=2.0.0', '<=2.0.0'],
['<=2.0.0', '<=2.0.0'],
['<2.0.0', '<2.0.0'],
['<2.0.0', '<2.0.0'],
['>= 1.0.0', '>=1.0.0'],
['>= 1.0.0', '>=1.0.0'],
['>= 1.0.0', '>=1.0.0'],
['> 1.0.0', '>1.0.0'],
['> 1.0.0', '>1.0.0'],
['<= 2.0.0', '<=2.0.0'],
['<= 2.0.0', '<=2.0.0'],
['<= 2.0.0', '<=2.0.0'],
['< 2.0.0', '<2.0.0'],
['< 2.0.0', '<2.0.0'],
['>=0.1.97', '>=0.1.97'],
['>=0.1.97', '>=0.1.97'],
['0.1.20 || 1.2.4', '0.1.20||1.2.4'],
['>=0.2.3 || <0.0.1', '>=0.2.3||<0.0.1'],
['>=0.2.3 || <0.0.1', '>=0.2.3||<0.0.1'],
['>=0.2.3 || <0.0.1', '>=0.2.3||<0.0.1'],
['||', '||'],
['2.x.x', '>=2.0.0 <3.0.0'],
['1.2.x', '>=1.2.0 <1.3.0'],
['1.2.x || 2.x', '>=1.2.0 <1.3.0||>=2.0.0 <3.0.0'],
['1.2.x || 2.x', '>=1.2.0 <1.3.0||>=2.0.0 <3.0.0'],
['x', '*'],
['2.*.*', '>=2.0.0 <3.0.0'],
['1.2.*', '>=1.2.0 <1.3.0'],
['1.2.* || 2.*', '>=1.2.0 <1.3.0||>=2.0.0 <3.0.0'],
['*', '*'],
['2', '>=2.0.0 <3.0.0'],
['2.3', '>=2.3.0 <2.4.0'],
['~2.4', '>=2.4.0 <2.5.0'],
['~2.4', '>=2.4.0 <2.5.0'],
['~>3.2.1', '>=3.2.1 <3.3.0'],
['~1', '>=1.0.0 <2.0.0'],
['~>1', '>=1.0.0 <2.0.0'],
['~> 1', '>=1.0.0 <2.0.0'],
['~1.0', '>=1.0.0 <1.1.0'],
['~ 1.0', '>=1.0.0 <1.1.0'],
['^0', '>=0.0.0 <1.0.0'],
['^ 1', '>=1.0.0 <2.0.0'],
['^0.1', '>=0.1.0 <0.2.0'],
['^1.0', '>=1.0.0 <2.0.0'],
['^1.2', '>=1.2.0 <2.0.0'],
['^0.0.1', '>=0.0.1 <0.0.2'],
['^0.0.1-beta', '>=0.0.1-beta <0.0.2'],
['^0.1.2', '>=0.1.2 <0.2.0'],
['^1.2.3', '>=1.2.3 <2.0.0'],
['^1.2.3-beta.4', '>=1.2.3-beta.4 <2.0.0'],
['<1', '<1.0.0'],
['< 1', '<1.0.0'],
['>=1', '>=1.0.0'],
['>= 1', '>=1.0.0'],
['<1.2', '<1.2.0'],
['< 1.2', '<1.2.0'],
['1', '>=1.0.0 <2.0.0'],
['>01.02.03', '>1.2.3', true],
['>01.02.03', null],
['~1.2.3beta', '>=1.2.3-beta <1.3.0', true],
['~1.2.3beta', null],
['^ 1.2 ^ 1', '>=1.2.0 <2.0.0 >=1.0.0 <2.0.0']
].forEach(function(v) {
var pre = v[0];
var wanted = v[1];
var loose = v[2];
var found = validRange(pre, loose);
t.equal(found, wanted, 'validRange(' + pre + ') === ' + wanted);
});
t.end();
});
test('\ncomparators test', function(t) {
// [range, comparators]
// turn range into a set of individual comparators
[['1.0.0 - 2.0.0', [['>=1.0.0', '<=2.0.0']]],
['1.0.0', [['1.0.0']]],
['>=*', [['']]],
['', [['']]],
['*', [['']]],
['*', [['']]],
['>=1.0.0', [['>=1.0.0']]],
['>=1.0.0', [['>=1.0.0']]],
['>=1.0.0', [['>=1.0.0']]],
['>1.0.0', [['>1.0.0']]],
['>1.0.0', [['>1.0.0']]],
['<=2.0.0', [['<=2.0.0']]],
['1', [['>=1.0.0', '<2.0.0']]],
['<=2.0.0', [['<=2.0.0']]],
['<=2.0.0', [['<=2.0.0']]],
['<2.0.0', [['<2.0.0']]],
['<2.0.0', [['<2.0.0']]],
['>= 1.0.0', [['>=1.0.0']]],
['>= 1.0.0', [['>=1.0.0']]],
['>= 1.0.0', [['>=1.0.0']]],
['> 1.0.0', [['>1.0.0']]],
['> 1.0.0', [['>1.0.0']]],
['<= 2.0.0', [['<=2.0.0']]],
['<= 2.0.0', [['<=2.0.0']]],
['<= 2.0.0', [['<=2.0.0']]],
['< 2.0.0', [['<2.0.0']]],
['<\t2.0.0', [['<2.0.0']]],
['>=0.1.97', [['>=0.1.97']]],
['>=0.1.97', [['>=0.1.97']]],
['0.1.20 || 1.2.4', [['0.1.20'], ['1.2.4']]],
['>=0.2.3 || <0.0.1', [['>=0.2.3'], ['<0.0.1']]],
['>=0.2.3 || <0.0.1', [['>=0.2.3'], ['<0.0.1']]],
['>=0.2.3 || <0.0.1', [['>=0.2.3'], ['<0.0.1']]],
['||', [[''], ['']]],
['2.x.x', [['>=2.0.0', '<3.0.0']]],
['1.2.x', [['>=1.2.0', '<1.3.0']]],
['1.2.x || 2.x', [['>=1.2.0', '<1.3.0'], ['>=2.0.0', '<3.0.0']]],
['1.2.x || 2.x', [['>=1.2.0', '<1.3.0'], ['>=2.0.0', '<3.0.0']]],
['x', [['']]],
['2.*.*', [['>=2.0.0', '<3.0.0']]],
['1.2.*', [['>=1.2.0', '<1.3.0']]],
['1.2.* || 2.*', [['>=1.2.0', '<1.3.0'], ['>=2.0.0', '<3.0.0']]],
['1.2.* || 2.*', [['>=1.2.0', '<1.3.0'], ['>=2.0.0', '<3.0.0']]],
['*', [['']]],
['2', [['>=2.0.0', '<3.0.0']]],
['2.3', [['>=2.3.0', '<2.4.0']]],
['~2.4', [['>=2.4.0', '<2.5.0']]],
['~2.4', [['>=2.4.0', '<2.5.0']]],
['~>3.2.1', [['>=3.2.1', '<3.3.0']]],
['~1', [['>=1.0.0', '<2.0.0']]],
['~>1', [['>=1.0.0', '<2.0.0']]],
['~> 1', [['>=1.0.0', '<2.0.0']]],
['~1.0', [['>=1.0.0', '<1.1.0']]],
['~ 1.0', [['>=1.0.0', '<1.1.0']]],
['~ 1.0.3', [['>=1.0.3', '<1.1.0']]],
['~> 1.0.3', [['>=1.0.3', '<1.1.0']]],
['<1', [['<1.0.0']]],
['< 1', [['<1.0.0']]],
['>=1', [['>=1.0.0']]],
['>= 1', [['>=1.0.0']]],
['<1.2', [['<1.2.0']]],
['< 1.2', [['<1.2.0']]],
['1', [['>=1.0.0', '<2.0.0']]],
['1 2', [['>=1.0.0', '<2.0.0', '>=2.0.0', '<3.0.0']]],
['1.2 - 3.4.5', [['>=1.2.0', '<=3.4.5']]],
['1.2.3 - 3.4', [['>=1.2.3', '<3.5.0']]],
['1.2.3 - 3', [['>=1.2.3', '<4.0.0']]],
['>*', [['<0.0.0']]],
['<*', [['<0.0.0']]]
].forEach(function(v) {
var pre = v[0];
var wanted = v[1];
var found = toComparators(v[0]);
var jw = JSON.stringify(wanted);
t.equivalent(found, wanted, 'toComparators(' + pre + ') === ' + jw);
});
t.end();
});
test('\ninvalid version numbers', function(t) {
['1.2.3.4',
'NOT VALID',
1.2,
null,
'Infinity.NaN.Infinity'
].forEach(function(v) {
t.throws(function() {
new SemVer(v);
}, {name:'TypeError', message:'Invalid Version: ' + v});
});
t.end();
});
test('\nstrict vs loose version numbers', function(t) {
[['=1.2.3', '1.2.3'],
['01.02.03', '1.2.3'],
['1.2.3-beta.01', '1.2.3-beta.1'],
[' =1.2.3', '1.2.3'],
['1.2.3foo', '1.2.3-foo']
].forEach(function(v) {
var loose = v[0];
var strict = v[1];
t.throws(function() {
new SemVer(loose);
});
var lv = new SemVer(loose, true);
t.equal(lv.version, strict);
t.ok(eq(loose, strict, true));
t.throws(function() {
eq(loose, strict);
});
t.throws(function() {
new SemVer(strict).compare(loose);
});
});
t.end();
});
test('\nstrict vs loose ranges', function(t) {
[['>=01.02.03', '>=1.2.3'],
['~1.02.03beta', '>=1.2.3-beta <1.3.0']
].forEach(function(v) {
var loose = v[0];
var comps = v[1];
t.throws(function() {
new Range(loose);
});
t.equal(new Range(loose, true).range, comps);
});
t.end();
});
test('\nmax satisfying', function(t) {
[[['1.2.3', '1.2.4'], '1.2', '1.2.4'],
[['1.2.4', '1.2.3'], '1.2', '1.2.4'],
[['1.2.3', '1.2.4', '1.2.5', '1.2.6'], '~1.2.3', '1.2.6'],
[['1.1.0', '1.2.0', '1.2.1', '1.3.0', '2.0.0b1', '2.0.0b2', '2.0.0b3', '2.0.0', '2.1.0'], '~2.0.0', '2.0.0', true]
].forEach(function(v) {
var versions = v[0];
var range = v[1];
var expect = v[2];
var loose = v[3];
var actual = semver.maxSatisfying(versions, range, loose);
t.equal(actual, expect);
});
t.end();
});

View File

@@ -0,0 +1,181 @@
var tap = require('tap');
var test = tap.test;
var semver = require('../semver.js');
var ltr = semver.ltr;
test('\nltr tests', function(t) {
// [range, version, loose]
// Version should be less than range
[
['~1.2.2', '1.2.1'],
['~0.6.1-1', '0.6.1-0'],
['1.0.0 - 2.0.0', '0.0.1'],
['1.0.0-beta.2', '1.0.0-beta.1'],
['1.0.0', '0.0.0'],
['>=2.0.0', '1.1.1'],
['>=2.0.0', '1.2.9'],
['>2.0.0', '2.0.0'],
['0.1.20 || 1.2.4', '0.1.5'],
['2.x.x', '1.0.0'],
['1.2.x', '1.1.0'],
['1.2.x || 2.x', '1.0.0'],
['2.*.*', '1.0.1'],
['1.2.*', '1.1.3'],
['1.2.* || 2.*', '1.1.9999'],
['2', '1.0.0'],
['2.3', '2.2.2'],
['~2.4', '2.3.0'], // >=2.4.0 <2.5.0
['~2.4', '2.3.5'],
['~>3.2.1', '3.2.0'], // >=3.2.1 <3.3.0
['~1', '0.2.3'], // >=1.0.0 <2.0.0
['~>1', '0.2.4'],
['~> 1', '0.2.3'],
['~1.0', '0.1.2'], // >=1.0.0 <1.1.0
['~ 1.0', '0.1.0'],
['>1.2', '1.2.0'],
['> 1.2', '1.2.1'],
['1', '0.0.0beta', true],
['~v0.5.4-pre', '0.5.4-alpha'],
['~v0.5.4-pre', '0.5.4-alpha'],
['=0.7.x', '0.6.0'],
['=0.7.x', '0.6.0-asdf'],
['>=0.7.x', '0.6.0'],
['~1.2.2', '1.2.1'],
['1.0.0 - 2.0.0', '0.2.3'],
['1.0.0', '0.0.1'],
['>=2.0.0', '1.0.0'],
['>=2.0.0', '1.9999.9999'],
['>=2.0.0', '1.2.9'],
['>2.0.0', '2.0.0'],
['>2.0.0', '1.2.9'],
['2.x.x', '1.1.3'],
['1.2.x', '1.1.3'],
['1.2.x || 2.x', '1.1.3'],
['2.*.*', '1.1.3'],
['1.2.*', '1.1.3'],
['1.2.* || 2.*', '1.1.3'],
['2', '1.9999.9999'],
['2.3', '2.2.1'],
['~2.4', '2.3.0'], // >=2.4.0 <2.5.0
['~>3.2.1', '2.3.2'], // >=3.2.1 <3.3.0
['~1', '0.2.3'], // >=1.0.0 <2.0.0
['~>1', '0.2.3'],
['~1.0', '0.0.0'], // >=1.0.0 <1.1.0
['>1', '1.0.0'],
['2', '1.0.0beta', true],
['>1', '1.0.0beta', true],
['> 1', '1.0.0beta', true],
['=0.7.x', '0.6.2'],
['=0.7.x', '0.7.0-asdf'],
['^1', '1.0.0-0'],
['>=0.7.x', '0.7.0-asdf'],
['1', '1.0.0beta', true],
['>=0.7.x', '0.6.2'],
['>1.2.3', '1.3.0-alpha']
].forEach(function(tuple) {
var range = tuple[0];
var version = tuple[1];
var loose = tuple[2] || false;
var msg = 'ltr(' + version + ', ' + range + ', ' + loose + ')';
t.ok(ltr(version, range, loose), msg);
});
t.end();
});
test('\nnegative ltr tests', function(t) {
// [range, version, loose]
// Version should NOT be less than range
[
['~ 1.0', '1.1.0'],
['~0.6.1-1', '0.6.1-1'],
['1.0.0 - 2.0.0', '1.2.3'],
['1.0.0 - 2.0.0', '2.9.9'],
['1.0.0', '1.0.0'],
['>=*', '0.2.4'],
['', '1.0.0', true],
['*', '1.2.3'],
['>=1.0.0', '1.0.0'],
['>=1.0.0', '1.0.1'],
['>=1.0.0', '1.1.0'],
['>1.0.0', '1.0.1'],
['>1.0.0', '1.1.0'],
['<=2.0.0', '2.0.0'],
['<=2.0.0', '1.9999.9999'],
['<=2.0.0', '0.2.9'],
['<2.0.0', '1.9999.9999'],
['<2.0.0', '0.2.9'],
['>= 1.0.0', '1.0.0'],
['>= 1.0.0', '1.0.1'],
['>= 1.0.0', '1.1.0'],
['> 1.0.0', '1.0.1'],
['> 1.0.0', '1.1.0'],
['<= 2.0.0', '2.0.0'],
['<= 2.0.0', '1.9999.9999'],
['<= 2.0.0', '0.2.9'],
['< 2.0.0', '1.9999.9999'],
['<\t2.0.0', '0.2.9'],
['>=0.1.97', 'v0.1.97'],
['>=0.1.97', '0.1.97'],
['0.1.20 || 1.2.4', '1.2.4'],
['0.1.20 || >1.2.4', '1.2.4'],
['0.1.20 || 1.2.4', '1.2.3'],
['0.1.20 || 1.2.4', '0.1.20'],
['>=0.2.3 || <0.0.1', '0.0.0'],
['>=0.2.3 || <0.0.1', '0.2.3'],
['>=0.2.3 || <0.0.1', '0.2.4'],
['||', '1.3.4'],
['2.x.x', '2.1.3'],
['1.2.x', '1.2.3'],
['1.2.x || 2.x', '2.1.3'],
['1.2.x || 2.x', '1.2.3'],
['x', '1.2.3'],
['2.*.*', '2.1.3'],
['1.2.*', '1.2.3'],
['1.2.* || 2.*', '2.1.3'],
['1.2.* || 2.*', '1.2.3'],
['1.2.* || 2.*', '1.2.3'],
['*', '1.2.3'],
['2', '2.1.2'],
['2.3', '2.3.1'],
['~2.4', '2.4.0'], // >=2.4.0 <2.5.0
['~2.4', '2.4.5'],
['~>3.2.1', '3.2.2'], // >=3.2.1 <3.3.0
['~1', '1.2.3'], // >=1.0.0 <2.0.0
['~>1', '1.2.3'],
['~> 1', '1.2.3'],
['~1.0', '1.0.2'], // >=1.0.0 <1.1.0
['~ 1.0', '1.0.2'],
['>=1', '1.0.0'],
['>= 1', '1.0.0'],
['<1.2', '1.1.1'],
['< 1.2', '1.1.1'],
['~v0.5.4-pre', '0.5.5'],
['~v0.5.4-pre', '0.5.4'],
['=0.7.x', '0.7.2'],
['>=0.7.x', '0.7.2'],
['<=0.7.x', '0.6.2'],
['>0.2.3 >0.2.4 <=0.2.5', '0.2.5'],
['>=0.2.3 <=0.2.4', '0.2.4'],
['1.0.0 - 2.0.0', '2.0.0'],
['^3.0.0', '4.0.0'],
['^1.0.0 || ~2.0.1', '2.0.0'],
['^0.1.0 || ~3.0.1 || 5.0.0', '3.2.0'],
['^0.1.0 || ~3.0.1 || 5.0.0', '1.0.0beta', true],
['^0.1.0 || ~3.0.1 || 5.0.0', '5.0.0-0', true],
['^0.1.0 || ~3.0.1 || >4 <=5.0.0', '3.5.0'],
['^1.0.0alpha', '1.0.0beta', true],
['~1.0.0alpha', '1.0.0beta', true],
['^1.0.0-alpha', '1.0.0beta', true],
['~1.0.0-alpha', '1.0.0beta', true],
['^1.0.0-alpha', '1.0.0-beta'],
['~1.0.0-alpha', '1.0.0-beta'],
['=0.1.0', '1.0.0']
].forEach(function(tuple) {
var range = tuple[0];
var version = tuple[1];
var loose = tuple[2] || false;
var msg = '!ltr(' + version + ', ' + range + ', ' + loose + ')';
t.notOk(ltr(version, range, loose), msg);
});
t.end();
});

Some files were not shown because too many files have changed in this diff Show More