Skip to content

Commit

Permalink
Merged from upstream/master. I left the dist/debug in place because m…
Browse files Browse the repository at this point in the history
…y hook now updates it automatically, but I removed the babelrc file since we don't need it anymore.
  • Loading branch information
yamikuronue committed Dec 20, 2016
1 parent 6a8d525 commit 2a01c6c
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"node": true
},
"rules": {
"no-console": 0
"no-console": 0,
"no-empty": [1, { "allowEmptyCatch": true }]
},
"extends": "eslint:recommended"
}
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@

2.4.5 / 2016-12-17
==================

* Fix: `navigator` undefined in Rhino (#376, @jochenberger)
* Fix: custom log function (#379, @hsiliev)
* Improvement: bit of cleanup + linting fixes (@thebigredgeek)
* Improvement: rm non-maintainted `dist/` dir (#375, @freewil)
* Docs: simplified language in the opening paragraph. (#373, @yamikuronue)

2.4.4 / 2016-12-14
==================

* Fix: work around debug being loaded in preload scripts for electron (#368, @paulcbetts)

2.4.3 / 2016-12-14
==================

* Fix: navigation.userAgent error for react native (#364, @escwald)

2.4.2 / 2016-12-14
==================

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ node_modules: package.json
@touch node_modules

lint: .FORCE
eslint debug.js
eslint browser.js debug.js index.js node.js

test: .FORCE
istanbul cover node_modules/mocha/bin/_mocha -- test/**.js
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,13 @@ debug('this is hex: %h', new Buffer('hello world'))
```

## Browser support
You can build a browser-ready script using [browserify](https://github.com/substack/node-browserify),
or just use the [browserify-as-a-service](https://wzrd.in/) [build](https://wzrd.in/standalone/debug@latest),
if you don't want to build it yourself.

Debug works in the browser as well, currently persisted by `localStorage`. Consider the situation shown below where you have `worker:a` and `worker:b`, and wish to debug both. You can enable this using `localStorage.debug`:
Debug's enable state is currently persisted by `localStorage`.
Consider the situation shown below where you have `worker:a` and `worker:b`,
and wish to debug both. You can enable this using `localStorage.debug`:

```js
localStorage.debug = 'worker:*'
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "debug",
"repo": "visionmedia/debug",
"description": "small debugging utility",
"version": "2.4.2",
"version": "2.4.5",
"keywords": [
"debug",
"log",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "debug",
"version": "2.4.2",
"version": "2.4.5",
"repository": {
"type": "git",
"url": "git://github.com/visionmedia/debug.git"
Expand Down
18 changes: 12 additions & 6 deletions src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ exports.formatArgs = formatArgs;
exports.save = save;
exports.load = load;
exports.useColors = useColors;
exports.storage = 'undefined' != typeof chrome
&& 'undefined' != typeof chrome.storage
? chrome.storage.local
exports.storage = 'undefined' != typeof window.chrome
&& 'undefined' != typeof window.chrome.storage
? window.chrome.storage.local
: localstorage();

/**
Expand All @@ -37,16 +37,23 @@ exports.colors = [
*/

function useColors() {
// NB: In an Electron preload script, document will be defined but not fully
// initialized. Since we know we're in Chrome, we'll just detect this case
// explicitly
if (typeof window !== 'undefined' && 'process' in window && window.process.type === 'renderer') {
return true;
}

// is webkit? http://stackoverflow.com/a/16459606/376773
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
return (typeof document !== 'undefined' && 'WebkitAppearance' in document.documentElement.style) ||
// is firebug? http://stackoverflow.com/a/398120/376773
(typeof window !== 'undefined' && window.console && (console.firebug || (console.exception && console.table))) ||
// is firefox >= v31?
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
(navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
(navigator && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
// double check webkit in userAgent just in case we are in a worker
(navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
(navigator && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
}

/**
Expand Down Expand Up @@ -141,7 +148,6 @@ function save(namespaces) {
*/

function load() {
var r;
try {
return exports.storage.debug;
} catch(e) {}
Expand Down
2 changes: 1 addition & 1 deletion src/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function createDebug(namespace) {
// apply env-specific formatting (colors, etc.)
exports.formatArgs.call(self, args);

var logFn = enabled.log || exports.log || console.log.bind(console);
var logFn = debug.log || exports.log || console.log.bind(console);
logFn.apply(self, args);
}

Expand Down
22 changes: 22 additions & 0 deletions test/debug_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,26 @@ describe('debug', function () {
log('Hello world');
//expect(dummyConsole.log).to.have.been.called;
});
<<<<<<< HEAD
=======
});

describe('custom functions', () => {
let log;

beforeEach(() => {
debug.enable('test');
log = debug('test');
});

context('with log function', () => {
it('uses it', () => {
log.log = spy();
log('using custom log function');

assert.calledOnce(log.log);
});
});
});
>>>>>>> upstream/master
});

0 comments on commit 2a01c6c

Please sign in to comment.