From 545bfce1ab602044041b370b413df62ae0cb9363 Mon Sep 17 00:00:00 2001 From: cha0s Date: Mon, 28 Feb 2022 10:29:56 -0600 Subject: [PATCH] feat: rich debugging --- packages/core/src/build/webpack.config.js | 2 +- packages/core/src/cli.js | 2 +- packages/core/src/debug.js | 28 +++++++++++++++++++ packages/core/src/flecks.js | 2 +- packages/core/src/index.js | 1 + packages/core/src/server/commands.js | 3 +- packages/core/src/server/flecks.js | 2 +- packages/db/package.json | 1 - packages/db/src/connection.js | 3 +- packages/docker/src/start-container.js | 2 +- .../src/server/build/fleck.neutrinorc.js | 2 +- packages/fleck/src/server/commands.js | 2 +- packages/http/package.json | 1 - packages/http/src/entry.js | 3 +- packages/http/src/progress.js | 2 +- .../http/src/server/build/http.neutrinorc.js | 2 +- packages/http/src/server/build/runtime.js | 2 +- packages/http/src/server/http.js | 2 +- packages/http/src/server/index.js | 3 +- packages/react/package.json | 1 - packages/react/src/client.js | 3 +- packages/react/src/root.js | 2 +- packages/redis/package.json | 1 - packages/redis/src/session/server.js | 3 +- packages/redux/src/server.js | 3 +- packages/repl/src/commands.js | 2 +- packages/repl/src/repl.js | 2 +- packages/server/src/entry.js | 3 +- .../src/server/build/server.neutrinorc.js | 2 +- packages/socket/package.json | 1 - packages/socket/src/client/socket.js | 4 +-- packages/socket/src/packet/acceptor.js | 2 +- packages/socket/src/server/create-intercom.js | 2 +- packages/socket/src/server/socket.js | 3 +- packages/socket/src/server/sockets.js | 2 +- packages/socket/src/socket.js | 3 +- packages/user/package.json | 1 - packages/user/src/server/index.js | 3 +- packages/user/src/session/server.js | 3 +- 39 files changed, 61 insertions(+), 50 deletions(-) create mode 100644 packages/core/src/debug.js diff --git a/packages/core/src/build/webpack.config.js b/packages/core/src/build/webpack.config.js index fd1bebd..aa9db41 100644 --- a/packages/core/src/build/webpack.config.js +++ b/packages/core/src/build/webpack.config.js @@ -10,13 +10,13 @@ if ('production' !== process.env.NODE_ENV) { catch (error) {} } -import D from 'debug'; import flatten from 'lodash.flatten'; import intersection from 'lodash.intersection'; import neutrino from 'neutrino'; import {targetNeutrino} from '../server/commands'; import Flecks from '../server/flecks'; +import D from '../debug'; const debug = D('@flecks/core/build/webpack.config.js'); diff --git a/packages/core/src/cli.js b/packages/core/src/cli.js index 97aa486..e29a960 100755 --- a/packages/core/src/cli.js +++ b/packages/core/src/cli.js @@ -2,8 +2,8 @@ import {fork} from 'child_process'; import {join, resolve, sep} from 'path'; import {Command} from 'commander'; -import D from 'debug'; +import D from './debug'; import Flecks from './server/flecks'; const { diff --git a/packages/core/src/debug.js b/packages/core/src/debug.js new file mode 100644 index 0000000..16636c4 --- /dev/null +++ b/packages/core/src/debug.js @@ -0,0 +1,28 @@ +import D from 'debug'; + +const { + VSCODE_INSPECTOR_OPTIONS, +} = process.env; + +let hasInitialized; +export default (name) => { + if (!hasInitialized) { + // VSCode has a problem showing colors when formatting objects. + if (VSCODE_INSPECTOR_OPTIONS) { + const {formatArgs} = D; + D.formatArgs = function formatObjectsWithoutColor(args) { + const {useColors} = this; + if (args[0].match(/%[oO]/)) { + this.useColors = false; + } + formatArgs.call(this, args); + this.useColors = useColors; + }; + D.formatters.o = undefined; + D.formatters.O = undefined; + } + // eslint-disable-next-line no-console + D.log = console.debug.bind(console); + } + return D(name); +}; diff --git a/packages/core/src/flecks.js b/packages/core/src/flecks.js index 5874dc9..4e6aa6e 100644 --- a/packages/core/src/flecks.js +++ b/packages/core/src/flecks.js @@ -6,11 +6,11 @@ import { join, } from 'path'; -import D from 'debug'; import get from 'lodash.get'; import set from 'lodash.set'; import without from 'lodash.without'; +import D from './debug'; import Middleware from './middleware'; const debug = D('@flecks/core/flecks'); diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 9c445fe..41f4f62 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -3,6 +3,7 @@ import {Hooks} from './flecks'; export {default as autoentry} from './bootstrap/autoentry'; export {default as fleck} from './bootstrap/fleck'; export {default as compose} from './compose'; +export {default as D} from './debug'; export {default as ensureUniqueReduction} from './ensure-unique-reduction'; export {default as EventEmitter} from './event-emitter'; export { diff --git a/packages/core/src/server/commands.js b/packages/core/src/server/commands.js index 08ac955..ffc3076 100644 --- a/packages/core/src/server/commands.js +++ b/packages/core/src/server/commands.js @@ -2,10 +2,11 @@ import {spawn} from 'child_process'; import {join, normalize} from 'path'; import {Argument} from 'commander'; -import D from 'debug'; import flatten from 'lodash.flatten'; import rimraf from 'rimraf'; +import D from '../debug'; + const { FLECKS_CORE_ROOT = process.cwd(), } = process.env; diff --git a/packages/core/src/server/flecks.js b/packages/core/src/server/flecks.js index 2f5d0a8..017a11d 100644 --- a/packages/core/src/server/flecks.js +++ b/packages/core/src/server/flecks.js @@ -13,9 +13,9 @@ import { import babelmerge from 'babel-merge'; import compileLoader from '@neutrinojs/compile-loader'; -import D from 'debug'; import R from '../bootstrap/require'; +import D from '../debug'; import Flecks from '../flecks'; const { diff --git a/packages/db/package.json b/packages/db/package.json index 700101c..4fbcc5f 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -19,7 +19,6 @@ ], "dependencies": { "@flecks/core": "^1.0.1", - "debug": "4.3.1", "sequelize": "^6.3.5", "sqlite3": "^5.0.2" }, diff --git a/packages/db/src/connection.js b/packages/db/src/connection.js index 8bfc92d..28d63cb 100644 --- a/packages/db/src/connection.js +++ b/packages/db/src/connection.js @@ -1,5 +1,4 @@ -import {ByType} from '@flecks/core'; -import D from 'debug'; +import {ByType, D} from '@flecks/core'; import Sequelize from 'sequelize'; const debug = D('@flecks/db/server/connection'); diff --git a/packages/docker/src/start-container.js b/packages/docker/src/start-container.js index c713877..0684cdb 100644 --- a/packages/docker/src/start-container.js +++ b/packages/docker/src/start-container.js @@ -3,7 +3,7 @@ import {mkdir} from 'fs/promises'; import {tmpdir} from 'os'; import {join} from 'path'; -import D from 'debug'; +import {D} from '@flecks/core'; const debug = D('@flecks/docker/container'); diff --git a/packages/fleck/src/server/build/fleck.neutrinorc.js b/packages/fleck/src/server/build/fleck.neutrinorc.js index 9d4f34d..d2205ee 100644 --- a/packages/fleck/src/server/build/fleck.neutrinorc.js +++ b/packages/fleck/src/server/build/fleck.neutrinorc.js @@ -1,9 +1,9 @@ const {join} = require('path'); +const {D} = require('@flecks/core'); const {Flecks} = require('@flecks/core/server'); const node = require('@neutrinojs/node'); const babelmerge = require('babel-merge'); -const D = require('debug'); const glob = require('glob'); const { diff --git a/packages/fleck/src/server/commands.js b/packages/fleck/src/server/commands.js index 51a6404..180f70e 100644 --- a/packages/fleck/src/server/commands.js +++ b/packages/fleck/src/server/commands.js @@ -1,8 +1,8 @@ import {stat, unlink} from 'fs/promises'; import {join} from 'path'; +import {D} from '@flecks/core'; import chokidar from 'chokidar'; -import D from 'debug'; import glob from 'glob'; import { diff --git a/packages/http/package.json b/packages/http/package.json index 145c48e..2a0e387 100644 --- a/packages/http/package.json +++ b/packages/http/package.json @@ -37,7 +37,6 @@ "@flecks/core": "^1.0.1", "@neutrinojs/web": "^9.1.0", "compression": "^1.7.4", - "debug": "4.3.1", "express": "^4.17.1", "glob": "^7.2.0", "html-webpack-plugin": "^4.5.0", diff --git a/packages/http/src/entry.js b/packages/http/src/entry.js index 046a877..2a126d2 100644 --- a/packages/http/src/entry.js +++ b/packages/http/src/entry.js @@ -1,5 +1,4 @@ -import D from 'debug'; -import {Flecks} from '@flecks/core'; +import {D, Flecks} from '@flecks/core'; import Progress from './progress'; diff --git a/packages/http/src/progress.js b/packages/http/src/progress.js index f0b9332..b9fefa5 100644 --- a/packages/http/src/progress.js +++ b/packages/http/src/progress.js @@ -1,4 +1,4 @@ -import D from 'debug'; +import {D} from '@flecks/core'; const debug = D('@flecks/http/progress'); diff --git a/packages/http/src/server/build/http.neutrinorc.js b/packages/http/src/server/build/http.neutrinorc.js index 5a91b05..838d376 100644 --- a/packages/http/src/server/build/http.neutrinorc.js +++ b/packages/http/src/server/build/http.neutrinorc.js @@ -1,6 +1,6 @@ +const {D} = require('@flecks/core'); const {Flecks} = require('@flecks/core/server'); const web = require('@neutrinojs/web'); -const D = require('debug'); const {EnvironmentPlugin} = require('webpack'); const devServer = require('./dev-server'); diff --git a/packages/http/src/server/build/runtime.js b/packages/http/src/server/build/runtime.js index a3e5624..c180218 100644 --- a/packages/http/src/server/build/runtime.js +++ b/packages/http/src/server/build/runtime.js @@ -4,8 +4,8 @@ const { join, } = require('path'); +const {D} = require('@flecks/core'); const {Flecks, require: R} = require('@flecks/core/server'); -const D = require('debug'); const glob = require('glob'); const debug = D('@flecks/http/runtime'); diff --git a/packages/http/src/server/http.js b/packages/http/src/server/http.js index 13340a3..15d47c2 100644 --- a/packages/http/src/server/http.js +++ b/packages/http/src/server/http.js @@ -2,8 +2,8 @@ import {createReadStream} from 'fs'; import {createServer, ServerResponse} from 'http'; import {join} from 'path'; +import {D} from '@flecks/core'; import compression from 'compression'; -import D from 'debug'; import express from 'express'; import httpProxy from 'http-proxy'; import flatten from 'lodash.flatten'; diff --git a/packages/http/src/server/index.js b/packages/http/src/server/index.js index 63cf89f..276f6a7 100644 --- a/packages/http/src/server/index.js +++ b/packages/http/src/server/index.js @@ -1,6 +1,5 @@ -import {Hooks} from '@flecks/core'; +import {D, Hooks} from '@flecks/core'; import {Flecks, spawnWith} from '@flecks/core/server'; -import D from 'debug'; import {configSource, inlineConfig} from './config'; import {createHttpServer} from './http'; diff --git a/packages/react/package.json b/packages/react/package.json index 2004bc9..ac3a6ad 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -40,7 +40,6 @@ "@hot-loader/react-dom": "^17.0.1", "@neutrinojs/react": "^9.4.0", "classnames": "^2.3.1", - "debug": "4.3.1", "history": "^5.3.0", "prop-types": "^15.7.2", "react": "^17.0.1", diff --git a/packages/react/src/client.js b/packages/react/src/client.js index 8d8142e..a53b9c2 100644 --- a/packages/react/src/client.js +++ b/packages/react/src/client.js @@ -1,6 +1,5 @@ -import {Hooks} from '@flecks/core'; +import {D, Hooks} from '@flecks/core'; import {hydrate, render} from '@hot-loader/react-dom'; -import D from 'debug'; import React from 'react'; // eslint-disable-next-line import/no-extraneous-dependencies diff --git a/packages/react/src/root.js b/packages/react/src/root.js index e08decc..b1436cb 100644 --- a/packages/react/src/root.js +++ b/packages/react/src/root.js @@ -1,4 +1,4 @@ -import D from 'debug'; +import {D} from '@flecks/core'; import React from 'react'; // eslint-disable-next-line import/no-extraneous-dependencies diff --git a/packages/redis/package.json b/packages/redis/package.json index b0b6506..358b1ce 100644 --- a/packages/redis/package.json +++ b/packages/redis/package.json @@ -23,7 +23,6 @@ "@flecks/core": "^1.0.1", "@socket.io/redis-adapter": "7.1.0", "connect-redis": "^5.0.0", - "debug": "4.3.1", "express-session": "^1.17.1", "redis": "4.0.3" }, diff --git a/packages/redis/src/session/server.js b/packages/redis/src/session/server.js index 39c7730..f5a7e7a 100644 --- a/packages/redis/src/session/server.js +++ b/packages/redis/src/session/server.js @@ -1,7 +1,6 @@ -import {Hooks} from '@flecks/core'; +import {D, Hooks} from '@flecks/core'; import redisAdapter from '@socket.io/redis-adapter'; import ConnectRedis from 'connect-redis'; -import D from 'debug'; import session from 'express-session'; import createClient from '../create-client'; diff --git a/packages/redux/src/server.js b/packages/redux/src/server.js index c2e3e97..ddfee16 100644 --- a/packages/redux/src/server.js +++ b/packages/redux/src/server.js @@ -1,5 +1,4 @@ -import {ensureUniqueReduction, Hooks} from '@flecks/core'; -import D from 'debug'; +import {D, ensureUniqueReduction, Hooks} from '@flecks/core'; import {Provider} from 'react-redux'; import {hydrateServer} from './actions'; diff --git a/packages/repl/src/commands.js b/packages/repl/src/commands.js index e761806..be347db 100644 --- a/packages/repl/src/commands.js +++ b/packages/repl/src/commands.js @@ -3,8 +3,8 @@ import {readdir} from 'fs/promises'; import {tmpdir} from 'os'; import {join} from 'path'; +import {D} from '@flecks/core'; import commandExists from 'command-exists'; -import D from 'debug'; const debug = D('@flecks/repl/commands'); diff --git a/packages/repl/src/repl.js b/packages/repl/src/repl.js index 7e60204..f5c6133 100644 --- a/packages/repl/src/repl.js +++ b/packages/repl/src/repl.js @@ -4,7 +4,7 @@ import {tmpdir} from 'os'; import {join} from 'path'; import {start} from 'repl'; -import D from 'debug'; +import {D} from '@flecks/core'; const debug = D('@flecks/repl'); diff --git a/packages/server/src/entry.js b/packages/server/src/entry.js index c7e077a..633495e 100644 --- a/packages/server/src/entry.js +++ b/packages/server/src/entry.js @@ -2,8 +2,7 @@ import {mkdir} from 'fs/promises'; import {tmpdir} from 'os'; import {join} from 'path'; -import D from 'debug'; -import {Flecks} from '@flecks/core'; +import {D, Flecks} from '@flecks/core'; const {version} = require('../package.json'); diff --git a/packages/server/src/server/build/server.neutrinorc.js b/packages/server/src/server/build/server.neutrinorc.js index 8e462b9..b2af31b 100644 --- a/packages/server/src/server/build/server.neutrinorc.js +++ b/packages/server/src/server/build/server.neutrinorc.js @@ -1,10 +1,10 @@ const {join} = require('path'); +const {D} = require('@flecks/core'); const {Flecks} = require('@flecks/core/server'); const banner = require('@neutrinojs/banner'); const node = require('@neutrinojs/node'); const startServer = require('@neutrinojs/start-server'); -const D = require('debug'); const runtime = require('./runtime'); diff --git a/packages/socket/package.json b/packages/socket/package.json index 8f73e5f..1833904 100644 --- a/packages/socket/package.json +++ b/packages/socket/package.json @@ -24,7 +24,6 @@ ], "dependencies": { "@flecks/core": "^1.0.1", - "debug": "4.3.1", "msgpack-lite": "^0.1.26", "proxy-addr": "^2.0.6", "schemapack": "^1.4.2", diff --git a/packages/socket/src/client/socket.js b/packages/socket/src/client/socket.js index a6225a1..60f1676 100644 --- a/packages/socket/src/client/socket.js +++ b/packages/socket/src/client/socket.js @@ -1,10 +1,8 @@ import {promisify} from 'util'; -import D from 'debug'; +import {compose, D, EventEmitter} from '@flecks/core'; import io from 'socket.io-client'; -import {compose, EventEmitter} from '@flecks/core'; - import Socket from '../socket'; const debug = D('@flecks/socket/client/socket'); diff --git a/packages/socket/src/packet/acceptor.js b/packages/socket/src/packet/acceptor.js index ad6a817..e3d7251 100644 --- a/packages/socket/src/packet/acceptor.js +++ b/packages/socket/src/packet/acceptor.js @@ -1,4 +1,4 @@ -import D from 'debug'; +import {D} from '@flecks/core'; const { NODE_ENV, diff --git a/packages/socket/src/server/create-intercom.js b/packages/socket/src/server/create-intercom.js index 6fcf2f4..bbbcc8d 100644 --- a/packages/socket/src/server/create-intercom.js +++ b/packages/socket/src/server/create-intercom.js @@ -1,4 +1,4 @@ -import D from 'debug'; +import {D} from '@flecks/core'; const debug = D('@flecks/socket/intercom'); diff --git a/packages/socket/src/server/socket.js b/packages/socket/src/server/socket.js index 9bc6469..7ff8226 100644 --- a/packages/socket/src/server/socket.js +++ b/packages/socket/src/server/socket.js @@ -1,7 +1,6 @@ import {promisify} from 'util'; -import {compose, EventEmitter} from '@flecks/core'; -import D from 'debug'; +import {compose, D, EventEmitter} from '@flecks/core'; import Socket from '../socket'; diff --git a/packages/socket/src/server/sockets.js b/packages/socket/src/server/sockets.js index aca1791..5837f84 100644 --- a/packages/socket/src/server/sockets.js +++ b/packages/socket/src/server/sockets.js @@ -1,4 +1,4 @@ -import D from 'debug'; +import {D} from '@flecks/core'; import proxyaddr from 'proxy-addr'; import SocketIoServer from 'socket.io'; diff --git a/packages/socket/src/socket.js b/packages/socket/src/socket.js index de9b1ab..a146998 100644 --- a/packages/socket/src/socket.js +++ b/packages/socket/src/socket.js @@ -1,5 +1,4 @@ -import {ByType} from '@flecks/core'; -import D from 'debug'; +import {ByType, D} from '@flecks/core'; import normalize from './normalize'; import acceptor from './packet/acceptor'; diff --git a/packages/user/package.json b/packages/user/package.json index 825e95b..483c54e 100644 --- a/packages/user/package.json +++ b/packages/user/package.json @@ -33,7 +33,6 @@ "@flecks/react": "^1.0.2", "@flecks/redux": "^1.0.2", "bcrypt": "^5.0.0", - "debug": "4.3.1", "express": "^4.17.1", "express-session": "1.17.1", "passport": "0.4.1", diff --git a/packages/user/src/server/index.js b/packages/user/src/server/index.js index 5247066..57e3c11 100644 --- a/packages/user/src/server/index.js +++ b/packages/user/src/server/index.js @@ -1,5 +1,4 @@ -import {Flecks, Hooks} from '@flecks/core'; -import D from 'debug'; +import {D, Flecks, Hooks} from '@flecks/core'; import passport from 'passport'; import LogOps from 'passport/lib/http/request'; diff --git a/packages/user/src/session/server.js b/packages/user/src/session/server.js index 5dfc27f..5f5d9c9 100644 --- a/packages/user/src/session/server.js +++ b/packages/user/src/session/server.js @@ -1,5 +1,4 @@ -import {Hooks} from '@flecks/core'; -import D from 'debug'; +import {D, Hooks} from '@flecks/core'; import express from 'express'; import expressSession from 'express-session';