diff --git a/README.md b/README.md index 5d6ac27..0a45c1a 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Tiny debug tool (~500 bytes) for terminal and browser inspired by [debug-js/debu ## Motivation `@wbe/debug` was built in order to be as light as possible for terminal and browser, -as the same way as the great visionmedia/debug tool. +as the same way as the great debug-js/debug tool. ## Installation diff --git a/examples/browser/vite.config.ts b/examples/browser/vite.config.ts index 3254c0d..a43d0e0 100644 --- a/examples/browser/vite.config.ts +++ b/examples/browser/vite.config.ts @@ -6,6 +6,6 @@ console.log("isProd", isProd) export default defineConfig({ esbuild: { pure: isProd ? ["console.log"] : [], - //drop: isProd ? ["console"] : [], + //drop: ["console"], }, }) diff --git a/examples/node/index.js b/examples/node/index.js index d26a16c..3bbeb4d 100644 --- a/examples/node/index.js +++ b/examples/node/index.js @@ -1,4 +1,4 @@ -const debug = require("@wbe/debug") +import debug from "@wbe/debug" const str = "hello debug!" debug("01-namespace")(str) diff --git a/examples/node/package.json b/examples/node/package.json index 443935e..9bcb853 100644 --- a/examples/node/package.json +++ b/examples/node/package.json @@ -1,14 +1,11 @@ { "name": "node", - "version": "1.0.0", - "description": "", "main": "index.js", + "type": "module", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node index.js" }, - "keywords": [], - "author": "", - "license": "ISC", "dependencies": { "@wbe/debug": "workspace:*" } diff --git a/package.json b/package.json index b89cad5..b529a6d 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,16 @@ { "name": "@wbe/debug", "version": "1.2.0", - "description": "Tiny debug tool (~500 bytes) for terminal and browser inspired by visionmedia/debug API.", + "description": "Tiny debug tool (~500 bytes) for terminal and browser inspired by debug-js/debug API.", "author": "Willy Brauner", "license": "MIT", "type": "module", - "main": "./dist/index.cjs", - "module": "./dist/index.js", - "types": "./dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + } + }, "sideEffects": false, "repository": { "type": "git", diff --git a/src/debug.ts b/src/debug.ts index 83feb83..0fe183d 100644 --- a/src/debug.ts +++ b/src/debug.ts @@ -5,8 +5,7 @@ import { isBrowser, stringToRgb } from "./helpers" * debug */ // prettier-ignore -export const debug = (namespace?: string) => (...rest: any[]): void => -{ +export const debug = (namespace?: string) => (...rest: any[]): void => { const rgb = stringToRgb(namespace) const showLog = (value: string): boolean => @@ -14,20 +13,25 @@ export const debug = (namespace?: string) => (...rest: any[]): void => ? namespace.startsWith( value.split(":*")[0]) : value === namespace || value === "*" + // Allow to bypass dropping of console.log from the build process + // tested with esbuild config: pure: ["console.log"] or drop: ["console"] + const log = console['log'] + if (isBrowser) { showLog(localStorage.getItem("debug")) && - console.log( + log( namespace && `%c${namespace}`, `color: rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]})`, ...rest ) } + else - { +{ showLog(process.env.DEBUG) && - console.log( + log( namespace && couleur.bold(couleur.rgb(rgb[0], rgb[1], rgb[2])(namespace)), ...rest )