Skip to content

Commit

Permalink
feat(Console): provide a mean to log only in dev (#794)
Browse files Browse the repository at this point in the history
  • Loading branch information
pylafleur authored Mar 30, 2024
1 parent a17ddec commit 78bdf72
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// eslint-disable-next-line no-underscore-dangle, no-var, vars-on-top
declare global { var __DS_DEV__: boolean; }
// eslint-disable-next-line no-underscore-dangle
global.__DS_DEV__ = process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test';

// Buttons
export { Button } from './components/buttons/button';
export { IconButton } from './components/buttons/icon-button';
Expand Down
15 changes: 15 additions & 0 deletions packages/react/src/utils/dev-console.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
type DevConsole = Pick<Console, 'log' | 'info' | 'warn' | 'error'>;

// eslint-disable-next-line no-underscore-dangle
const inDevMode = globalThis.__DS_DEV__;

// eslint-disable-next-line @typescript-eslint/no-empty-function
function noop(): void {}

/* eslint-disable no-console */
export const devConsole: DevConsole = {
log: inDevMode ? console.log : noop,
info: inDevMode ? console.info : noop,
warn: inDevMode ? console.warn : noop,
error: inDevMode ? console.error : noop,
};

0 comments on commit 78bdf72

Please sign in to comment.