Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dependencies): Remove direct debug dependency #2296

Merged
merged 2 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
496 changes: 231 additions & 265 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions packages/authentication-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
"@feathersjs/authentication": "^5.0.0-pre.2",
"@feathersjs/commons": "^5.0.0-pre.2",
"@feathersjs/errors": "^5.0.0-pre.2",
"@feathersjs/feathers": "^5.0.0-pre.2",
"debug": "^4.3.1"
"@feathersjs/feathers": "^5.0.0-pre.2"
},
"devDependencies": {
"@feathersjs/adapter-memory": "^5.0.0-pre.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication-local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
},
"dependencies": {
"@feathersjs/authentication": "^5.0.0-pre.2",
"@feathersjs/commons": "^5.0.0-pre.2",
"@feathersjs/errors": "^5.0.0-pre.2",
"@feathersjs/feathers": "^5.0.0-pre.2",
"bcryptjs": "^2.4.3",
"debug": "^4.3.1",
"lodash": "^4.17.21"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/authentication-local/src/hooks/hash-password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import get from 'lodash/get';
import set from 'lodash/set';
import cloneDeep from 'lodash/cloneDeep';
import { BadRequest } from '@feathersjs/errors';
import Debug from 'debug';
import { createDebug } from '@feathersjs/commons';
import { HookContext } from '@feathersjs/feathers';
import { LocalStrategy } from '../strategy';

const debug = Debug('@feathersjs/authentication-local/hooks/hash-password');
const debug = createDebug('@feathersjs/authentication-local/hooks/hash-password');

export interface HashPasswordOptions {
authentication?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/authentication-local/src/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import bcrypt from 'bcryptjs';
import get from 'lodash/get';
import omit from 'lodash/omit';
import Debug from 'debug';
import { NotAuthenticated } from '@feathersjs/errors';
import { Query, Params } from '@feathersjs/feathers';
import {
AuthenticationRequest, AuthenticationBaseStrategy
} from '@feathersjs/authentication';
import { createDebug } from '@feathersjs/commons';

const debug = Debug('@feathersjs/authentication-local/strategy');
const debug = createDebug('@feathersjs/authentication-local/strategy');

export class LocalStrategy extends AuthenticationBaseStrategy {
verifyConfiguration () {
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication-oauth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
},
"dependencies": {
"@feathersjs/authentication": "^5.0.0-pre.2",
"@feathersjs/commons": "^5.0.0-pre.2",
"@feathersjs/errors": "^5.0.0-pre.2",
"@feathersjs/express": "^5.0.0-pre.2",
"@feathersjs/feathers": "^5.0.0-pre.2",
"debug": "^4.3.1",
"express-session": "^1.17.1",
"grant": "^5.4.12",
"lodash": "^4.17.21"
Expand Down
4 changes: 2 additions & 2 deletions packages/authentication-oauth/src/express.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import grant from 'grant';
import Debug from 'debug';
import session from 'express-session';
import { createDebug } from '@feathersjs/commons';
import { Application } from '@feathersjs/feathers';
import { AuthenticationResult } from '@feathersjs/authentication';
import {
Expand All @@ -11,7 +11,7 @@ import { OauthSetupSettings } from './utils';
import { OAuthStrategy } from './strategy';

const grantInstance = grant.express();
const debug = Debug('@feathersjs/authentication-oauth/express');
const debug = createDebug('@feathersjs/authentication-oauth/express');

declare module 'express-session' {
interface SessionData {
Expand Down
4 changes: 2 additions & 2 deletions packages/authentication-oauth/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Debug from 'debug';
import merge from 'lodash/merge';
import each from 'lodash/each';
import omit from 'lodash/omit';
import { createDebug } from '@feathersjs/commons';
import { Application } from '@feathersjs/feathers';
import { OAuthStrategy, OAuthProfile } from './strategy';
import { default as setupExpress } from './express';
import { OauthSetupSettings, getDefaultSettings } from './utils';

const debug = Debug('@feathersjs/authentication-oauth');
const debug = createDebug('@feathersjs/authentication-oauth');

export { OauthSetupSettings, OAuthStrategy, OAuthProfile };

Expand Down
4 changes: 2 additions & 2 deletions packages/authentication-oauth/src/strategy.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
// @ts-ignore
import querystring from 'querystring';
import Debug from 'debug';
import {
AuthenticationRequest, AuthenticationBaseStrategy, AuthenticationResult
} from '@feathersjs/authentication';
import { Params } from '@feathersjs/feathers';
import { NotAuthenticated } from '@feathersjs/errors';
import { createDebug } from '@feathersjs/commons';

const debug = Debug('@feathersjs/authentication-oauth/strategy');
const debug = createDebug('@feathersjs/authentication-oauth/strategy');

export interface OAuthProfile {
id?: string|number;
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
"access": "public"
},
"dependencies": {
"@feathersjs/commons": "^5.0.0-pre.2",
"@feathersjs/errors": "^5.0.0-pre.2",
"@feathersjs/feathers": "^5.0.0-pre.2",
"@feathersjs/transport-commons": "^5.0.0-pre.2",
"@types/jsonwebtoken": "^8.5.1",
"debug": "^4.3.1",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21",
"long-timeout": "^0.1.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/authentication/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import merge from 'lodash/merge';
import jsonwebtoken, { SignOptions, Secret, VerifyOptions } from 'jsonwebtoken';
import { v4 as uuidv4 } from 'uuid';
import { NotAuthenticated } from '@feathersjs/errors';
import Debug from 'debug';
import { createDebug } from '@feathersjs/commons';
import { Application, Params } from '@feathersjs/feathers';
import { IncomingMessage, ServerResponse } from 'http';
import defaultOptions from './options';

const debug = Debug('@feathersjs/authentication/base');
const debug = createDebug('@feathersjs/authentication/base');

export interface AuthenticationResult {
[key: string]: any;
Expand Down
4 changes: 2 additions & 2 deletions packages/authentication/src/hooks/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import flatten from 'lodash/flatten';
import omit from 'lodash/omit';
import { HookContext } from '@feathersjs/feathers';
import { NotAuthenticated } from '@feathersjs/errors';
import Debug from 'debug';
import { createDebug } from '@feathersjs/commons';

const debug = Debug('@feathersjs/authentication/hooks/authenticate');
const debug = createDebug('@feathersjs/authentication/hooks/authenticate');

export interface AuthenticateHookSettings {
service?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/authentication/src/hooks/event.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Debug from 'debug';
import { HookContext } from '@feathersjs/feathers';
import { createDebug } from '@feathersjs/commons';
import { ConnectionEvent } from '../core';

const debug = Debug('@feathersjs/authentication/hooks/connection');
const debug = createDebug('@feathersjs/authentication/hooks/connection');

export default (event: ConnectionEvent) => async (context: HookContext) => {
const { app, result, params } = context;
Expand Down
4 changes: 2 additions & 2 deletions packages/authentication/src/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import Debug from 'debug';
import omit from 'lodash/omit';
import { IncomingMessage } from 'http';
import { NotAuthenticated } from '@feathersjs/errors';
import { Params } from '@feathersjs/feathers';
import { createDebug } from '@feathersjs/commons';
// @ts-ignore
import lt from 'long-timeout';

import { AuthenticationBaseStrategy } from './strategy';
import { AuthenticationRequest, AuthenticationResult, ConnectionEvent } from './core';

const debug = Debug('@feathersjs/authentication/jwt');
const debug = createDebug('@feathersjs/authentication/jwt');
const SPLIT_HEADER = /(\S+)\s+(\S+)/;

export class JWTStrategy extends AuthenticationBaseStrategy {
Expand Down
4 changes: 2 additions & 2 deletions packages/authentication/src/service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Debug from 'debug';
import merge from 'lodash/merge';
import { NotAuthenticated } from '@feathersjs/errors';
import { AuthenticationBase, AuthenticationResult, AuthenticationRequest } from './core';
import { connection, event } from './hooks';
import '@feathersjs/transport-commons';
import { createDebug } from '@feathersjs/commons';
import { Params, ServiceMethods, ServiceAddons } from '@feathersjs/feathers';
import jsonwebtoken from 'jsonwebtoken';

const debug = Debug('@feathersjs/authentication/service');
const debug = createDebug('@feathersjs/authentication/service');

declare module '@feathersjs/feathers/lib/declarations' {
interface FeathersApplication<ServiceTypes, AppSettings> { // eslint-disable-line
Expand Down
26 changes: 26 additions & 0 deletions packages/commons/src/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export type DebugFunction = (...args: any[]) => void;
export type DebugInitializer = (name: string) => DebugFunction;

const debuggers: { [key: string]: DebugFunction } = {};

export function noopDebug (): DebugFunction {
return () => {}
}

let defaultInitializer: DebugInitializer = noopDebug;

export function setDebug (debug: DebugInitializer) {
defaultInitializer = debug;

Object.keys(debuggers).forEach(name => {
debuggers[name] = debug(name);
});
}

export function createDebug (name: string) {
if (!debuggers[name]) {
debuggers[name] = defaultInitializer(name);
}

return (...args: any[]) => debuggers[name](...args);
}
2 changes: 2 additions & 0 deletions packages/commons/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,5 @@ export function isPromise (result: any) {
export function createSymbol (name: string) {
return typeof Symbol !== 'undefined' ? Symbol(name) : name;
}

export * from './debug';
30 changes: 30 additions & 0 deletions packages/commons/test/debug.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { strict as assert } from 'assert';
import { createDebug, setDebug, noopDebug } from '../src';

const myDebug = createDebug('hello test');

describe('debug', () => {
it('default debug does nothing', () => {
assert.equal(myDebug('hi', 'there'), undefined);
});

it('can set custom debug later', () => {
let call;

const customDebug = (name: string) => (...args: any[]) => {
call = [ name ].concat(args);
}

setDebug(customDebug);

assert.equal(myDebug('hi', 'there'), undefined);
assert.deepEqual(call, [ 'hello test', 'hi', 'there' ]);

const newDebug = createDebug('other test');

assert.equal(newDebug('other', 'there'), undefined);
assert.deepEqual(call, [ 'other test', 'other', 'there' ]);

setDebug(noopDebug);
});
});
4 changes: 2 additions & 2 deletions packages/configuration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
"access": "public"
},
"dependencies": {
"@feathersjs/commons": "^5.0.0-pre.2",
"@feathersjs/feathers": "^5.0.0-pre.2",
"config": "^3.3.6",
"debug": "^4.3.1"
"config": "^3.3.6"
},
"devDependencies": {
"@types/config": "^0.0.38",
Expand Down
4 changes: 2 additions & 2 deletions packages/configuration/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Application } from '@feathersjs/feathers';
import Debug from 'debug';
import { createDebug } from '@feathersjs/commons';
import config from 'config';

const debug = Debug('@feathersjs/configuration');
const debug = createDebug('@feathersjs/configuration');

export = function init () {
return (app?: Application) => {
Expand Down
1 change: 0 additions & 1 deletion packages/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"@feathersjs/commons": "^5.0.0-pre.2",
"@feathersjs/errors": "^5.0.0-pre.2",
"@types/express": "^4.17.11",
"debug": "^4.3.1",
"express": "^4.17.1",
"lodash": "^4.17.21"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/express/src/authentication.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Debug from 'debug';
import { createDebug } from '@feathersjs/commons';
import { merge, flatten } from 'lodash';
import { NextFunction, RequestHandler } from 'express';

const debug = Debug('@feathersjs/express/authentication');
const debug = createDebug('@feathersjs/express/authentication');

type StrategyOptions = {
service?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/express/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Debug from 'debug';
import express, {
Express, static as _static, json, raw, text, urlencoded, query
} from 'express';
import {
Application as FeathersApplication, defaultServiceMethods
} from '@feathersjs/feathers';
import { createDebug } from '@feathersjs/commons';

import { Application } from './declarations';
import { errorHandler, notFound } from './handlers';
Expand All @@ -19,7 +19,7 @@ export {
export * from './rest';
export * from './declarations';

const debug = Debug('@feathersjs/express');
const debug = createDebug('@feathersjs/express');

export default function feathersExpress<S = any, C = any> (feathersApp?: FeathersApplication<S, C>, expressApp: Express = express()): Application<S, C> {
if (!feathersApp) {
Expand Down
4 changes: 2 additions & 2 deletions packages/express/src/rest.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Debug from 'debug';
import { MethodNotAllowed } from '@feathersjs/errors';
import { HookContext } from '@feathersjs/hooks';
import { createDebug } from '@feathersjs/commons';
import { createContext, defaultServiceMethods, getServiceOptions, NullableId, Params } from '@feathersjs/feathers';
import { Request, Response, NextFunction, RequestHandler, Router } from 'express';

import { parseAuthentication } from './authentication';

const debug = Debug('@feathersjs/express/rest');
const debug = createDebug('@feathersjs/express/rest');

export const METHOD_HEADER = 'x-service-method';

Expand Down
1 change: 0 additions & 1 deletion packages/feathers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"dependencies": {
"@feathersjs/commons": "^5.0.0-pre.2",
"@feathersjs/hooks": "^0.6.3",
"debug": "^4.3.1",
"events": "^3.3.0"
},
"devDependencies": {
Expand Down
5 changes: 2 additions & 3 deletions packages/feathers/src/application.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Debug from 'debug';
import { EventEmitter } from 'events';
import { stripSlashes } from '@feathersjs/commons';
import { stripSlashes, createDebug } from '@feathersjs/commons';
import { HOOKS } from '@feathersjs/hooks';

import version from './version';
Expand All @@ -21,7 +20,7 @@ import {
} from './declarations';
import { enableLegacyHooks } from './hooks/legacy';

const debug = Debug('@feathersjs/feathers');
const debug = createDebug('@feathersjs/feathers');

export class Feathers<ServiceTypes, AppSettings> extends EventEmitter implements FeathersApplication<ServiceTypes, AppSettings> {
services: ServiceTypes = ({} as ServiceTypes);
Expand Down
4 changes: 2 additions & 2 deletions packages/feathers/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function eventHook (context: HookContext, next: NextFunction) {
// This is used for custom events and for client services receiving event from the server
if (typeof context.event === 'string' && !events.includes(context.event)) {
const results = Array.isArray(context.result) ? context.result : [ context.result ];

results.forEach(element => (context as any).self.emit(context.event, element, context));
}
});
Expand All @@ -28,6 +28,6 @@ export function eventMixin<A> (service: FeathersService<A>) {
if (!isEmitter) {
Object.assign(service, EventEmitter.prototype);
}

return service;
}
Loading