Skip to content

Commit

Permalink
Use debug (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt committed Feb 10, 2021
1 parent 7a02205 commit 74f05a7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"lint": "tsdx lint",
"prepack": "tsc"
},
"peerDependencies": {},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
Expand Down Expand Up @@ -57,6 +56,7 @@
"url": "https://github.com/blitz-js/superjson"
},
"devDependencies": {
"@types/debug": "^4.1.5",
"@types/lodash": "^4.14.168",
"@types/mongodb": "^3.6.3",
"benchmark": "^2.1.4",
Expand All @@ -66,7 +66,9 @@
"tsdx": "^0.14.1",
"typescript": "^4.1.3"
},
"dependencies": {},
"dependencies": {
"debug": "^4.3.1"
},
"resolutions": {
"**/@typescript-eslint/eslint-plugin": "^4.11.1",
"**/@typescript-eslint/parser": "^4.11.1",
Expand Down
7 changes: 5 additions & 2 deletions src/registry.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import debug from 'debug';
import { Registry } from './registry';
import { Class } from './types';

Expand All @@ -16,10 +17,12 @@ test('class registry', () => {

expect(() => registry.register(Car)).not.toThrow();

const warnSpy = jest.spyOn(console, 'warn');
debug.enable('superjson');
const warnSpy = jest.spyOn(process.stderr, 'write');

registry.register(class Car {});
expect(warnSpy).toHaveBeenCalledWith(
expect(warnSpy).toHaveBeenCalledTimes(1);
expect(warnSpy.mock.calls[0][0]).toContain(
'Ambiguous class "Car", provide a unique identifier.'
);

Expand Down
7 changes: 4 additions & 3 deletions src/registry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { DoubleIndexedKV } from './double-indexed-kv';
import createDebug from 'debug';

const debug = createDebug('superjson');

export class Registry<T> {
private kv = new DoubleIndexedKV<string, T>();
Expand All @@ -17,9 +20,7 @@ export class Registry<T> {
if (process.env.NODE_ENV !== 'production') {
const alreadyRegistered = this.kv.getByKey(identifier);
if (alreadyRegistered && alreadyRegistered !== value) {
console.warn(
`Ambiguous class "${identifier}", provide a unique identifier.`
);
debug(`Ambiguous class "${identifier}", provide a unique identifier.`);
}
}

Expand Down
14 changes: 13 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,11 @@
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz"
integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==

"@types/debug@^4.1.5":
version "4.1.5"
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.5.tgz#b14efa8852b7768d898906613c23f688713e02cd"
integrity sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==

"@types/estree@*":
version "0.0.45"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.45.tgz"
Expand Down Expand Up @@ -2509,6 +2514,13 @@ debug@^4.0.1, debug@^4.1.0, debug@^4.1.1:
dependencies:
ms "^2.1.1"

debug@^4.3.1:
version "4.3.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee"
integrity sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==
dependencies:
ms "2.1.2"

decamelize@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz"
Expand Down Expand Up @@ -4815,7 +4827,7 @@ ms@2.0.0:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz"
integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=

ms@^2.1.1:
ms@2.1.2, ms@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
Expand Down

0 comments on commit 74f05a7

Please sign in to comment.