Skip to content

Commit

Permalink
Add a lightweight browser version of "depd"
Browse files Browse the repository at this point in the history
The module "depd" does not support browser and it is not trivial
to fix that. This commits adds a lightweight implementation
of the depd "deprecate" function.
  • Loading branch information
Miroslav Bajtoš committed Feb 27, 2015
1 parent 844c067 commit edc52f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/browser.depd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// A lightweight alternative to "depd" that works in the browser
module.exports = function depd(namespace) {
var warned = {};
return function deprecate(message) {
if (warned[message]) return;
warned[message] = true;

if (process.noDeprecation) {
return;
} else if (process.traceDeprecation) {
console.trace(namespace, 'deprecated', message);
} else {
console.warn(namespace, 'deprecated', message);
}
};
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"url": "https://github.com/strongloop/loopback-datasource-juggler"
},
"main": "index.js",
"browser": {
"depd": "./lib/browser.depd.js"
},
"scripts": {
"test": "make test"
},
Expand Down

2 comments on commit edc52f1

@bajtos
Copy link
Member

@bajtos bajtos commented on edc52f1 Feb 27, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two major problems with depd:

  • it uses process.stderr which is not available in the browser
  • it uses Error.captureStackTrace, which is Chrome-specific and does not work in PhantomJS (for example)

@bajtos
Copy link
Member

@bajtos bajtos commented on edc52f1 Feb 27, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.