@prexjs/depd
v1.0.0
Published
Deprecate all the things! Mark functions, properties, and messages as deprecated with call-site stack traces.
Readme
@prexjs/depd
Deprecate all the things! Mark functions, properties, and messages as deprecated with call-site stack traces.
@prexjs/depd provides API deprecation notifications for libraries and modules. It identifies the exact caller line and file, emits one warning per callsite, and supports the standard process.on('deprecation') event.
Features
- Deprecate functions, methods, and object properties cleanly.
- Automatic call-site discovery so developers know which line in their code invoked the deprecated feature.
- Emits each unique warning only once per callsite to avoid terminal flooding.
- Respects
NO_DEPRECATIONandTRACE_DEPRECATIONenvironment variables. - Emits structured
deprecationevents onprocess. - Safe no-op implementation in browser environments.
- Dual ES Module (
.mjs) and CommonJS (.cjs) support with TypeScript definitions.
Installation
Install using your preferred package manager:
# npm
npm install @prexjs/depd
# pnpm
pnpm add @prexjs/depd
# Yarn
yarn add @prexjs/depd
# Bun
bun add @prexjs/depdQuick start
import depd from '@prexjs/depd';
const deprecate = depd('my-package');
// Emit a direct deprecation warning
function oldMethod() {
deprecate('oldMethod() is deprecated. Use newMethod() instead.');
}Both default and named exports are supported:
import depd, { type DeprecateFunction } from '@prexjs/depd';Examples
Deprecating a function wrapper
import depd from '@prexjs/depd';
const deprecate = depd('my-package');
function calculateOld(a: number, b: number) {
return a + b;
}
// Automatically logs a warning on first call from each location
export const calculate = deprecate.function(
calculateOld,
'calculate() is deprecated, use add() instead',
);Deprecating an object property
import depd from '@prexjs/depd';
const deprecate = depd('my-package');
export const config = {
active: true,
legacySetting: 'old-value',
};
deprecate.property(config, 'legacySetting', 'config.legacySetting is deprecated');Compatibility
@prexjs/depd is designed for Node.js, Deno, Bun, and browser environments. In browsers, deprecation warnings safely no-op to avoid breaking frontend builds.
License
This project is licensed under the MIT License. See LICENSE for the full license text.
Related projects
- prex.js — prex.js monorepo and ecosystem.
