[Pkg-javascript-commits] [node-depd] 02/06: Imported Upstream version 1.0.0
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sat Oct 11 19:31:07 UTC 2014
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to branch master
in repository node-depd.
commit f101465313d5799bdcbdede5d8848b9b06b334c4
Author: Andrew Kelley <superjoe30 at gmail.com>
Date: Sat Oct 11 19:26:31 2014 +0000
Imported Upstream version 1.0.0
---
.npmignore | 4 --
.travis.yml | 1 +
History.md | 11 +++++
Readme.md | 55 +++++++++++-----------
benchmark/index.js | 28 +++++++++++
benchmark/wrapfunction.js | 44 +++++++++++++++++
benchmark/wrapproperty.js | 38 +++++++++++++++
index.js | 8 ++--
lib/compat/buffer-concat.js | 33 +++++++++++++
lib/compat/callsite-tostring.js | 101 ++++++++++++++++++++++++++++++++++++++++
lib/compat/index.js | 69 +++++++++++++++++++++++++++
package.json | 18 +++++--
test/fixtures/my-lib.js | 3 ++
test/test.js | 43 ++++++++++-------
14 files changed, 400 insertions(+), 56 deletions(-)
diff --git a/.npmignore b/.npmignore
deleted file mode 100644
index 0c7e391..0000000
--- a/.npmignore
+++ /dev/null
@@ -1,4 +0,0 @@
-coverage/
-files/
-test/
-.travis.yml
diff --git a/.travis.yml b/.travis.yml
index 1ff243c..9c3778a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,6 @@
language: node_js
node_js:
+ - "0.6"
- "0.8"
- "0.10"
- "0.11"
diff --git a/History.md b/History.md
index ba1af12..bdbcf58 100644
--- a/History.md
+++ b/History.md
@@ -1,3 +1,14 @@
+1.0.0 / 2014-09-17
+==================
+
+ * No changes
+
+0.4.5 / 2014-09-09
+==================
+
+ * Improve call speed to functions using the function wrapper
+ * Support Node.js 0.6
+
0.4.4 / 2014-07-27
==================
diff --git a/Readme.md b/Readme.md
index 47a53a1..9fb2737 100644
--- a/Readme.md
+++ b/Readme.md
@@ -1,9 +1,11 @@
# depd
-[![NPM version](https://badge.fury.io/js/depd.svg)](http://badge.fury.io/js/depd)
-[![Build Status](https://travis-ci.org/dougwilson/nodejs-depd.svg?branch=master)](https://travis-ci.org/dougwilson/nodejs-depd)
-[![Coverage Status](https://img.shields.io/coveralls/dougwilson/nodejs-depd.svg?branch=master)](https://coveralls.io/r/dougwilson/nodejs-depd)
-[![Gittip](http://img.shields.io/gittip/dougwilson.svg)](https://www.gittip.com/dougwilson/)
+[![NPM Version][npm-version-image]][npm-url]
+[![NPM Downloads][npm-downloads-image]][npm-url]
+[![Node.js Version][node-image]][node-url]
+[![Build Status][travis-image]][travis-url]
+[![Coverage Status][coveralls-image]][coveralls-url]
+[![Gratipay][gratipay-image]][gratipay-url]
Deprecate all the things
@@ -23,7 +25,7 @@ var deprecate = require('depd')('my-module')
This library allows you to display deprecation messages to your users.
This library goes above and beyond with deprecation warnings by
-introspecting the call stack (but only the bits that it is interested
+introspection of the call stack (but only the bits that it is interested
in).
Instead of just warning on the first invocation of a deprecated
@@ -36,6 +38,11 @@ The deprecation warnings from this module also include the file and line
information for the call into the module that the deprecated function was
in.
+**NOTE** this library has a similar interface to the `debug` module, and
+this module uses the calling file to get the boundary for the call stacks,
+so you should always create a new `deprecate` object in each file and not
+within some central file.
+
### depd(namespace)
Create a new deprecate function that uses the given namespace name in the
@@ -115,7 +122,7 @@ The value is a list of comma-separated namespaces. To suppress every warning
across all namespaces, use the value `*` for a namespace.
Providing the argument `--no-deprecation` to the `node` executable will suppress
-all deprecations.
+all deprecations (only available in Node.js 0.8 or higher).
**NOTE** This will not suppress the deperecations given to any "deprecation"
event listeners, just the output to STDERR.
@@ -136,7 +143,7 @@ This will include stack traces for deprecations being output for "my-module" and
warning across all namespaces, use the value `*` for a namespace.
Providing the argument `--trace-deprecation` to the `node` executable will trace
-all deprecations.
+all deprecations (only available in Node.js 0.8 or higher).
**NOTE** This will not trace the deperecations silenced by `NO_DEPRECATION`.
@@ -249,24 +256,16 @@ deprecate.property(exports, 'oldprop', 'oldprop >= 0.10')
## License
-The MIT License (MIT)
-
-Copyright (c) 2014 Douglas Christopher Wilson
-
-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.
+[MIT](LICENSE)
+
+[npm-version-image]: https://img.shields.io/npm/v/depd.svg?style=flat
+[npm-downloads-image]: https://img.shields.io/npm/dm/depd.svg?style=flat
+[npm-url]: https://npmjs.org/package/depd
+[travis-image]: https://img.shields.io/travis/dougwilson/nodejs-depd.svg?style=flat
+[travis-url]: https://travis-ci.org/dougwilson/nodejs-depd
+[coveralls-image]: https://img.shields.io/coveralls/dougwilson/nodejs-depd.svg?style=flat
+[coveralls-url]: https://coveralls.io/r/dougwilson/nodejs-depd?branch=master
+[node-image]: https://img.shields.io/node/v/depd.svg?style=flat
+[node-url]: http://nodejs.org/download/
+[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg?style=flat
+[gratipay-url]: https://www.gratipay.com/dougwilson/
diff --git a/benchmark/index.js b/benchmark/index.js
new file mode 100644
index 0000000..2fbd813
--- /dev/null
+++ b/benchmark/index.js
@@ -0,0 +1,28 @@
+var fs = require('fs');
+var path = require('path');
+var spawn = require('child_process').spawn;
+
+var exe = process.argv[0];
+var cwd = process.cwd();
+
+runScripts(fs.readdirSync(__dirname));
+
+function runScripts(fileNames) {
+ var fileName = fileNames.shift();
+
+ if (!fileName) return;
+ if (!/\.js$/i.test(fileName)) return runScripts(fileNames);
+ if (fileName.toLowerCase() === 'index.js') return runScripts(fileNames);
+
+ var fullPath = path.join(__dirname, fileName);
+
+ console.log('> %s %s', exe, path.relative(cwd, fullPath));
+
+ var proc = spawn(exe, [fullPath], {
+ 'stdio': 'inherit'
+ });
+
+ proc.on('exit', function () {
+ runScripts(fileNames);
+ });
+}
diff --git a/benchmark/wrapfunction.js b/benchmark/wrapfunction.js
new file mode 100644
index 0000000..405a83d
--- /dev/null
+++ b/benchmark/wrapfunction.js
@@ -0,0 +1,44 @@
+
+/**
+ * Module dependencies.
+ */
+
+var benchmark = require('benchmark')
+var benchmarks = require('beautify-benchmark')
+
+/**
+ * Globals for benchmark.js
+ */
+
+process.env.NO_DEPRECATION = 'my-lib'
+global.mylib = require('../test/fixtures/my-lib')
+
+var suite = new benchmark.Suite
+
+suite.add({
+ name: 'function',
+ minSamples: 100,
+ fn: 'mylib.fn()'
+})
+
+suite.add({
+ name: 'wrapped',
+ minSamples: 100,
+ fn: 'mylib.oldfn()'
+})
+
+suite.add({
+ name: 'call log',
+ minSamples: 100,
+ fn: 'mylib.old()'
+})
+
+suite.on('cycle', function onCycle(event) {
+ benchmarks.add(event.target);
+})
+
+suite.on('complete', function onComplete() {
+ benchmarks.log();
+})
+
+suite.run({async: false})
diff --git a/benchmark/wrapproperty.js b/benchmark/wrapproperty.js
new file mode 100644
index 0000000..188536b
--- /dev/null
+++ b/benchmark/wrapproperty.js
@@ -0,0 +1,38 @@
+
+/**
+ * Module dependencies.
+ */
+
+var benchmark = require('benchmark')
+var benchmarks = require('beautify-benchmark')
+
+/**
+ * Globals for benchmark.js
+ */
+
+process.env.NO_DEPRECATION = 'my-lib'
+global.mylib = require('../test/fixtures/my-lib')
+
+var suite = new benchmark.Suite
+
+suite.add({
+ name: 'property',
+ minSamples: 100,
+ fn: 'mylib.prop = mylib.prop'
+})
+
+suite.add({
+ name: 'wrapped',
+ minSamples: 100,
+ fn: 'mylib.propa = mylib.propa'
+})
+
+suite.on('cycle', function onCycle(event) {
+ benchmarks.add(event.target);
+})
+
+suite.on('complete', function onComplete() {
+ benchmarks.log();
+})
+
+suite.run({async: false})
diff --git a/index.js b/index.js
index a6fb372..4fee4d9 100644
--- a/index.js
+++ b/index.js
@@ -8,6 +8,7 @@
* Module dependencies.
*/
+var callSiteToString = require('./lib/compat').callSiteToString
var EventEmitter = require('events').EventEmitter
var relative = require('path').relative
@@ -100,7 +101,7 @@ function createStackString(stack) {
}
for (var i = 0; i < stack.length; i++) {
- str += '\n at ' + stack[i].toString()
+ str += '\n at ' + callSiteToString(stack[i])
}
return str
@@ -310,7 +311,7 @@ function formatPlain(msg, caller, stack) {
// add stack trace
if (this._traced) {
for (var i = 0; i < stack.length; i++) {
- formatted += '\n at ' + stack[i].toString()
+ formatted += '\n at ' + callSiteToString(stack[i])
}
return formatted
@@ -335,7 +336,7 @@ function formatColor(msg, caller, stack) {
// add stack trace
if (this._traced) {
for (var i = 0; i < stack.length; i++) {
- formatted += '\n \x1b[36mat ' + stack[i].toString() + '\x1b[39m' // cyan
+ formatted += '\n \x1b[36mat ' + callSiteToString(stack[i]) + '\x1b[39m' // cyan
}
return formatted
@@ -407,6 +408,7 @@ function wrapfunction(fn, message) {
site.name = fn.name
var deprecatedfn = eval('(function (' + args + ') {\n'
+ + '"use strict"\n'
+ 'log.call(deprecate, message, site)\n'
+ 'return fn.apply(this, arguments)\n'
+ '})')
diff --git a/lib/compat/buffer-concat.js b/lib/compat/buffer-concat.js
new file mode 100644
index 0000000..09d9721
--- /dev/null
+++ b/lib/compat/buffer-concat.js
@@ -0,0 +1,33 @@
+/*!
+ * depd
+ * Copyright(c) 2014 Douglas Christopher Wilson
+ * MIT Licensed
+ */
+
+/**
+ * Module exports.
+ */
+
+module.exports = bufferConcat
+
+/**
+ * Concatenate an array of Buffers.
+ */
+
+function bufferConcat(bufs) {
+ var length = 0
+
+ for (var i = 0, len = bufs.length; i < len; i++) {
+ length += bufs[i].length
+ }
+
+ var buf = new Buffer(length)
+ var pos = 0
+
+ for (var i = 0, len = bufs.length; i < len; i++) {
+ bufs[i].copy(buf, pos)
+ pos += bufs[i].length
+ }
+
+ return buf
+}
diff --git a/lib/compat/callsite-tostring.js b/lib/compat/callsite-tostring.js
new file mode 100644
index 0000000..17cf7ed
--- /dev/null
+++ b/lib/compat/callsite-tostring.js
@@ -0,0 +1,101 @@
+/*!
+ * depd
+ * Copyright(c) 2014 Douglas Christopher Wilson
+ * MIT Licensed
+ */
+
+/**
+ * Module exports.
+ */
+
+module.exports = callSiteToString
+
+/**
+ * Format a CallSite file location to a string.
+ */
+
+function callSiteFileLocation(callSite) {
+ var fileName
+ var fileLocation = ''
+
+ if (callSite.isNative()) {
+ fileLocation = 'native'
+ } else if (callSite.isEval()) {
+ fileName = callSite.getScriptNameOrSourceURL()
+ if (!fileName) {
+ fileLocation = callSite.getEvalOrigin()
+ }
+ } else {
+ fileName = callSite.getFileName()
+ }
+
+ if (fileName) {
+ fileLocation += fileName
+
+ var lineNumber = callSite.getLineNumber()
+ if (lineNumber != null) {
+ fileLocation += ':' + lineNumber
+
+ var columnNumber = callSite.getColumnNumber()
+ if (columnNumber) {
+ fileLocation += ':' + columnNumber
+ }
+ }
+ }
+
+ return fileLocation || 'unknown source'
+}
+
+/**
+ * Format a CallSite to a string.
+ */
+
+function callSiteToString(callSite) {
+ var addSuffix = true
+ var fileLocation = callSiteFileLocation(callSite)
+ var functionName = callSite.getFunctionName()
+ var isConstructor = callSite.isConstructor()
+ var isMethodCall = !(callSite.isToplevel() || isConstructor)
+ var line = ''
+
+ if (isMethodCall) {
+ var methodName = callSite.getMethodName()
+ var typeName = getConstructorName(callSite)
+
+ if (functionName) {
+ if (typeName && functionName.indexOf(typeName) !== 0) {
+ line += typeName + '.'
+ }
+
+ line += functionName
+
+ if (methodName && functionName.lastIndexOf('.' + methodName) !== functionName.length - methodName.length - 1) {
+ line += ' [as ' + methodName + ']'
+ }
+ } else {
+ line += typeName + '.' + (methodName || '<anonymous>')
+ }
+ } else if (isConstructor) {
+ line += 'new ' + (functionName || '<anonymous>')
+ } else if (functionName) {
+ line += functionName
+ } else {
+ addSuffix = false
+ line += fileLocation
+ }
+
+ if (addSuffix) {
+ line += ' (' + fileLocation + ')'
+ }
+
+ return line
+}
+
+/**
+ * Get constructor name of reviver.
+ */
+
+function getConstructorName(obj) {
+ var receiver = obj.receiver
+ return (receiver.constructor && receiver.constructor.name) || null
+}
diff --git a/lib/compat/index.js b/lib/compat/index.js
new file mode 100644
index 0000000..7fee026
--- /dev/null
+++ b/lib/compat/index.js
@@ -0,0 +1,69 @@
+/*!
+ * depd
+ * Copyright(c) 2014 Douglas Christopher Wilson
+ * MIT Licensed
+ */
+
+/**
+ * Module exports.
+ */
+
+lazyProperty(module.exports, 'bufferConcat', function bufferConcat() {
+ return Buffer.concat || require('./buffer-concat')
+})
+
+lazyProperty(module.exports, 'callSiteToString', function callSiteToString() {
+ var limit = Error.stackTraceLimit
+ var obj = {}
+ var prep = Error.prepareStackTrace
+
+ function prepareObjectStackTrace(obj, stack) {
+ return stack
+ }
+
+ Error.prepareStackTrace = prepareObjectStackTrace
+ Error.stackTraceLimit = 2
+
+ // capture the stack
+ Error.captureStackTrace(obj)
+
+ // slice the stack
+ var stack = obj.stack.slice()
+
+ Error.prepareStackTrace = prep
+ Error.stackTraceLimit = limit
+
+ return stack[0].toString ? toString : require('./callsite-tostring')
+})
+
+/**
+ * Define a lazy property.
+ */
+
+function lazyProperty(obj, prop, getter) {
+ function get() {
+ var val = getter()
+
+ Object.defineProperty(obj, prop, {
+ configurable: true,
+ enumerable: true,
+ value: val
+ })
+
+ return val
+ }
+
+ Object.defineProperty(obj, prop, {
+ configurable: true,
+ enumerable: true,
+ get: get
+ })
+}
+
+/**
+ * Call toString() on the obj
+ */
+
+function toString(obj) {
+ return obj.toString()
+}
diff --git a/package.json b/package.json
index 5623078..dd38015 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "depd",
"description": "Deprecate all the things",
- "version": "0.4.4",
+ "version": "1.0.0",
"author": "Douglas Christopher Wilson <doug at somethingdoug.com>",
"license": "MIT",
"keywords": [
@@ -10,14 +10,24 @@
],
"repository": "dougwilson/nodejs-depd",
"devDependencies": {
- "istanbul": "0.3.0",
- "mocha": "~1.20.1",
+ "benchmark": "1.0.0",
+ "beautify-benchmark": "0.2.4",
+ "istanbul": "0.3.2",
+ "mocha": "~1.21.4",
"should": "~4.0.4"
},
+ "files": [
+ "lib/",
+ "History.md",
+ "LICENSE",
+ "index.js",
+ "Readme.md"
+ ],
"engines": {
- "node": ">= 0.8.0"
+ "node": ">= 0.6"
},
"scripts": {
+ "bench": "node benchmark/index.js",
"test": "mocha --reporter spec --bail --require should test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --require should test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --require should test/"
diff --git a/test/fixtures/my-lib.js b/test/fixtures/my-lib.js
index 1b1821f..d45a903 100644
--- a/test/fixtures/my-lib.js
+++ b/test/fixtures/my-lib.js
@@ -1,6 +1,9 @@
var deprecate = require('../..')('my-lib')
+exports.fn = fn
+exports.prop = 'thingie'
+
exports.old = function () {
deprecate('old')
}
diff --git a/test/test.js b/test/test.js
index 02fcfaf..33e79d3 100644
--- a/test/test.js
+++ b/test/test.js
@@ -1,5 +1,6 @@
var basename = require('path').basename
+var bufferConcat = require('../lib/compat').bufferConcat
var depd = require('..')
var mylib = require('./fixtures/my-lib')
var path = require('path')
@@ -604,26 +605,34 @@ describe('node script.js', function () {
})
})
-describe('node --no-deprecation script.js', function () {
- it('should suppress deprecation message', function (done) {
- captureChildStderr(['--no-deprecation', script], function (err, stderr) {
- if (err) return done(err)
- stderr.should.be.empty
- done()
+;(function () {
+ // --*-deprecation switches are 0.8+
+ // no good way to feature detect this sync
+ var describe = /^v0\.6\./.test(process.version)
+ ? global.describe.skip
+ : global.describe
+
+ describe('node --no-deprecation script.js', function () {
+ it('should suppress deprecation message', function (done) {
+ captureChildStderr(['--no-deprecation', script], function (err, stderr) {
+ if (err) return done(err)
+ stderr.should.be.empty
+ done()
+ })
})
})
-})
-describe('node --trace-deprecation script.js', function () {
- it('should suppress deprecation message', function (done) {
- captureChildStderr(['--trace-deprecation', script], function (err, stderr) {
- if (err) return done(err)
- stderr = stderr.replace(/\w+, \d+ \w+ \d+ \d+:\d+:\d+ \w+/, '__timestamp__')
- stderr.should.startWith('__timestamp__ my-cool-module deprecated oldfunction\n at run (' + script + ':7:10)\n at')
- done()
+ describe('node --trace-deprecation script.js', function () {
+ it('should suppress deprecation message', function (done) {
+ captureChildStderr(['--trace-deprecation', script], function (err, stderr) {
+ if (err) return done(err)
+ stderr = stderr.replace(/\w+, \d+ \w+ \d+ \d+:\d+:\d+ \w+/, '__timestamp__')
+ stderr.should.startWith('__timestamp__ my-cool-module deprecated oldfunction\n at run (' + script + ':7:10)\n at')
+ done()
+ })
})
})
-})
+}())
function captureChildStderr(args, callback) {
var chunks = []
@@ -640,7 +649,7 @@ function captureChildStderr(args, callback) {
proc.on('error', callback)
proc.on('exit', function () {
- var stderr = Buffer.concat(chunks).toString('utf8')
+ var stderr = bufferConcat(chunks).toString('utf8')
callback(null, stderr)
})
}
@@ -662,5 +671,5 @@ function captureStderr(fn, color) {
process.stderr.write = write
}
- return Buffer.concat(chunks).toString('utf8')
+ return bufferConcat(chunks).toString('utf8')
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-depd.git
More information about the Pkg-javascript-commits
mailing list