Skip to content
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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ yarn-debug.log*
yarn-error.log*
pnpm-debug.log*


# environment variables
.env
.env.production

# macOS-specific files
**/*/.DS_Store
**/**/.DS_Store

# ignore .astro directory
.astro
Expand Down
216 changes: 108 additions & 108 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export const LOGO_IMAGE = {
};

export const SOCIALS: SocialObjects = [
{
name: "LinkedIn",
href: "https://www.linkedin.com/in/acanimal",
linkTitle: `${SITE.title} on LinkedIn`,
active: true,
},
{
name: "Github",
href: "https://github.com/acanimal",
Expand All @@ -45,112 +51,106 @@ export const SOCIALS: SocialObjects = [
linkTitle: `${SITE.title} on GitLab`,
active: true,
},
{
name: "Facebook",
href: "https://github.com/acanimal",
linkTitle: `${SITE.title} on Facebook`,
active: false,
},
{
name: "Instagram",
href: "https://www.instagram.com/acuriousanimal",
linkTitle: `${SITE.title} on Instagram`,
active: false,
},
{
name: "LinkedIn",
href: "https://www.linkedin.com/in/acanimal",
linkTitle: `${SITE.title} on LinkedIn`,
active: true,
},
{
name: "Mail",
href: "mailto:asantiagop+website@gmail.com",
linkTitle: `Send an email to ${SITE.title}`,
active: true,
},
{
name: "X",
href: "https://github.com/acanimal",
linkTitle: `${SITE.title} on X`,
active: false,
},
{
name: "Mastodon",
href: "https://github.com/acanimal",
linkTitle: `${SITE.title} on Mastodon`,
active: false,
},
{
name: "Twitch",
href: "https://github.com/acanimal",
linkTitle: `${SITE.title} on Twitch`,
active: false,
},
{
name: "YouTube",
href: "https://github.com/acanimal",
linkTitle: `${SITE.title} on YouTube`,
active: false,
},
{
name: "WhatsApp",
href: "https://github.com/acanimal",
linkTitle: `${SITE.title} on WhatsApp`,
active: false,
},
{
name: "Snapchat",
href: "https://github.com/acanimal",
linkTitle: `${SITE.title} on Snapchat`,
active: false,
},
{
name: "Pinterest",
href: "https://github.com/acanimal",
linkTitle: `${SITE.title} on Pinterest`,
active: false,
},
{
name: "TikTok",
href: "https://github.com/acanimal",
linkTitle: `${SITE.title} on TikTok`,
active: false,
},
{
name: "CodePen",
href: "https://github.com/acanimal",
linkTitle: `${SITE.title} on CodePen`,
active: false,
},
{
name: "Discord",
href: "https://github.com/acanimal",
linkTitle: `${SITE.title} on Discord`,
active: false,
},
{
name: "Reddit",
href: "https://github.com/acanimal",
linkTitle: `${SITE.title} on Reddit`,
active: false,
},
{
name: "Skype",
href: "https://github.com/acanimal",
linkTitle: `${SITE.title} on Skype`,
active: false,
},
{
name: "Steam",
href: "https://github.com/acanimal",
linkTitle: `${SITE.title} on Steam`,
active: false,
},
{
name: "Telegram",
href: "https://github.com/acanimal",
linkTitle: `${SITE.title} on Telegram`,
active: false,
},
// {
// name: "Facebook",
// href: "https://github.com/acanimal",
// linkTitle: `${SITE.title} on Facebook`,
// active: false,
// },
// {
// name: "Instagram",
// href: "https://www.instagram.com/acuriousanimal",
// linkTitle: `${SITE.title} on Instagram`,
// active: false,
// },
// {
// name: "Mail",
// href: "mailto:asantiagop+website@gmail.com",
// linkTitle: `Send an email to ${SITE.title}`,
// active: true,
// },
// {
// name: "X",
// href: "https://github.com/acanimal",
// linkTitle: `${SITE.title} on X`,
// active: false,
// },
// {
// name: "Mastodon",
// href: "https://github.com/acanimal",
// linkTitle: `${SITE.title} on Mastodon`,
// active: false,
// },
// {
// name: "Twitch",
// href: "https://github.com/acanimal",
// linkTitle: `${SITE.title} on Twitch`,
// active: false,
// },
// {
// name: "YouTube",
// href: "https://github.com/acanimal",
// linkTitle: `${SITE.title} on YouTube`,
// active: false,
// },
// {
// name: "WhatsApp",
// href: "https://github.com/acanimal",
// linkTitle: `${SITE.title} on WhatsApp`,
// active: false,
// },
// {
// name: "Snapchat",
// href: "https://github.com/acanimal",
// linkTitle: `${SITE.title} on Snapchat`,
// active: false,
// },
// {
// name: "Pinterest",
// href: "https://github.com/acanimal",
// linkTitle: `${SITE.title} on Pinterest`,
// active: false,
// },
// {
// name: "TikTok",
// href: "https://github.com/acanimal",
// linkTitle: `${SITE.title} on TikTok`,
// active: false,
// },
// {
// name: "CodePen",
// href: "https://github.com/acanimal",
// linkTitle: `${SITE.title} on CodePen`,
// active: false,
// },
// {
// name: "Discord",
// href: "https://github.com/acanimal",
// linkTitle: `${SITE.title} on Discord`,
// active: false,
// },
// {
// name: "Reddit",
// href: "https://github.com/acanimal",
// linkTitle: `${SITE.title} on Reddit`,
// active: false,
// },
// {
// name: "Skype",
// href: "https://github.com/acanimal",
// linkTitle: `${SITE.title} on Skype`,
// active: false,
// },
// {
// name: "Steam",
// href: "https://github.com/acanimal",
// linkTitle: `${SITE.title} on Steam`,
// active: false,
// },
// {
// name: "Telegram",
// href: "https://github.com/acanimal",
// linkTitle: `${SITE.title} on Telegram`,
// active: false,
// },
];
85 changes: 85 additions & 0 deletions src/content/blog/2025-11-30-deprecated-in-node.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
title: Cómo gestionar código obsoleto en Node.js con `deprecated`
pubDatetime: 2025-11-30T09:28:00Z
description: Todo evoluciona y tu código tampoco se libra de ello. Si has escrito o mantenido alguna vez una librería o código que usan otras personas ya sabrás que es comun que los nuevos cambios dejen obsoletas otras partes de tu código. En este artículo te explico la mejor forma de marcar como "deprecated" aquellas partes de tu codigo, de forma que tus usuarios sean concientes de ello y se muevan a utilizar las nuevas funcionalidades.
tags:
- programación
- tips
language: spanish
---

Todo evoluciona y el código no es una excepción. Si has escrito o mantenido alguna vez una librería o código que usan otras personas ya sabrás que es comun que los nuevos cambios dejen obsoletas otras partes de tu código. En este artículo te explico la mejor forma de marcar como "deprecated" aquellas partes de tu codigo, de forma que tus usuarios sean concientes de ello y se muevan a utilizar las nuevas funcionalidades.

Supon que has desarrollado una libraría que ayuda a realizar ciertos cálculos y tienes una función `calcularTotal` que por motivos varios pasar a llamarse simplemente `calcular`. Fácil, no? cambias el nombre y listo. No, en la vida real, donde tu librería ya ha sido publicada en un repositorio y cientos de personas hacen uso de ella, la cosa no es tan simple.

## Paso 1: El buen hábito de la documentación

Efectivamente, documenta tu función. Se "organizado" e indica a otros programadores que una funcion está obsoleta y, potencial, será borrada en una futura versión con la etiqueta `@deprecated` de JSDoc.

```typescript
/**
* @deprecated Usa 'calcular' en lugar 'calcularTotal'. Esta funcion será eliminada en próximas versions.
* @param {number} cantidad El valor a procesar.
* @returns {number} El resultado del cálculo antiguo.
*/
function calcularTotal(cantidad: number): number {
return cantidad * 1.05; // 5% de impuesto
}

/**
* @param {number} cantidad El valor a procesar.
* @param {number} impuesto Incremento en el precio
* @returns {number} El resultado del cálculo antiguo.
*/
function calcular(cantidad: number, impuesto: number): number {
return cantidad * (1 + impuesto);
}
```

Simple y deonata preocupación por ser pulido. Gracias a la etiqueta `@deprecated` el editor de código (debe ser uno muy simple para que no lo haga) avisará visualmente a los usuarios que quieran usar la función obsoleta `calculoTotal`. Eso si, ten en cuenta que solo es un "aviso visual", y que el editor no evita que quien quiera usarla la use.

![deprecated tag](@content/blog/images/2025-11-30-deprecated.png)

## Paso 2: Informa en tiempo de ejecución

Hay otro forma de notificar a tus usuarios que una funcion ha quedado obsoleta y no hay necesidad de usen el editor para ello. Basta con usar la función nativa de Node.js `util.deprecated()`.

### ¿Qué hace `util.deprecated`?

La funcion `util.deprecated` es un _wrapper_ (debe envolver) a tu función obsoleta. De esta forma, en tiempo de ejecución, cuando `util.deprecated` se ejecuta hace dos cosas:

- Advertencia en la consola: La primera vez que el código llama a la función _envuelta_, Node.js emitirá la advertencia en la salida de error estándar (stderr), informando al usuario sobre el cambio.

- Advertencia única: la advertencia solo se emite una vez, evitando inundar la consola si la función obsoleta se llama miles de veces.

```typescript
/**
* @deprecated Usa 'calcular' en lugar 'calcularTotal'. Esta funcion será eliminada en próximas versions.
* @param {number} cantidad El valor a procesar.
* @returns {number} El resultado del cálculo antiguo.
*/
function _calcularTotal(cantidad: number): number {
return cantidad * 1.05; // 5% de impuesto
}

// Creamos wrapper
export const calcularTotal = deprecated(
_calcularTotal,
'La función "calcularTotal" está obsoleta. Usa "calcular" en su lugar. La funcion "calcularTotal" sera eliminada en la proxima version.'
);
```

El resultado por consola sería algo como:

```bash:dark
(node:21682) DeprecationWarning: La función "calcularTotal" está obsoleta. Usa "calcular" en su lugar. La funcion "calcularTotal" sera eliminada en la proxima version.
(Use `node --trace-deprecation ...` to show where the warning was created)
```

## Conclusión

La combinación de `@deprecated` en la documentación y `util.deprecated` en el código es el estándar de oro para la migración de APIs.

Usa `@deprecated` para advertir al desarrollador en su editor y utilizas `util.deprecated` para advertir al usuario cuando su código realmente se esté ejecutando en producción o pruebas.

De esta manera, facilitas la vida de tus usuarios y mantienes tu código base listo para el futuro.
Binary file added src/content/blog/images/2025-11-30-deprecated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.