Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@compas/stdlib

Package Overview
Dependencies
Maintainers
1
Versions
220
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@compas/stdlib - npm Package Compare versions

Comparing version
0.19.4
to
0.20.0
+1
-1
index.d.ts

@@ -15,5 +15,5 @@ export { uuid } from "./src/datatypes.js";

export { getSecondsSinceEpoch, gc, mainFn, noop, filenameForModule, dirnameForModule } from "./src/utils.js";
export { newLogger, loggerGetGlobalDestination, loggerSetGlobalDestination, loggerGetPrettyPrinter, loggerExtendGlobalContext, loggerDetermineDefaultDestination } from "./src/logger.js";
export { newLogger, loggerGetGlobalDestination, loggerSetGlobalDestination, loggerGetPrettyPrinter, loggerExtendGlobalContext, loggerDetermineDefaultDestination, asyncLocalStorageLogger, contextAwarelogger } from "./src/logger.js";
export { bytesToHumanReadable, printProcessMemoryUsage } from "./src/memory.js";
export { newEvent, eventStart, eventRename, eventStop, newEventFromEvent } from "./src/events.js";
export { _compasSentryExport, compasWithSentry, _compasSentryEnableQuerySpans } from "./src/sentry.js";

@@ -84,2 +84,4 @@ /// <reference path="./types/advanced-types.d.ts">

loggerDetermineDefaultDestination,
asyncLocalStorageLogger,
contextAwarelogger,
} from "./src/logger.js";

@@ -86,0 +88,0 @@

{
"name": "@compas/stdlib",
"version": "0.19.4",
"version": "0.20.0",
"description": "All kinds of utility functions",

@@ -21,6 +21,6 @@ "exports": {

"dependencies": {
"@types/node": "24.5.2",
"dotenv": "17.2.2",
"@types/node": "24.9.1",
"dotenv": "17.2.3",
"lodash.merge": "4.6.2",
"pino": "9.11.0"
"pino": "10.1.0"
},

@@ -51,4 +51,4 @@ "devDependencies": {

"engines": {
"node": ">=18"
"node": ">=24"
}
}

@@ -8,4 +8,4 @@ # @compas/stdlib

<a href="https://github.com/compasjs/compas/actions/workflows/main-checks.yml" target="_blank">
<img src="https://github.com/compasjs/compas/actions/workflows/main-checks.yml/badge.svg" alt="CI status badge">
<a href="https://github.com/compasjs/compas/actions/workflows/checks.yml" target="_blank">
<img src="https://github.com/compasjs/compas/actions/workflows/checks.yml/badge.svg" alt="CI status badge">
</a>

@@ -21,1 +21,8 @@ <a href="https://codecov.io/gh/compasjs/compas" target="_blank">

[documentation](https://compasjs.com/getting-started.html).
## Maintenance mode
Compas is in maintenance mode. The packages will be maintained for the
foreseeable future. New features might be added, but some will also be dropped
in favor of other ecosystem-available libraries. Please don't start new projects
using Compas.
/**
* This should only be necessary when you or a package mutates the environment variables.
* The `mainFn` / `mainTestFn` / `mainBenchFn` / ... will call this function by default
* The `mainFn` and `mainTestFn` will call this function by default
* after loading your `.env` file.

@@ -5,0 +5,0 @@ *

@@ -10,3 +10,3 @@ /**

* This should only be necessary when you or a package mutates the environment variables.
* The `mainFn` / `mainTestFn` / `mainBenchFn` / ... will call this function by default
* The `mainFn` and `mainTestFn` will call this function by default
* after loading your `.env` file.

@@ -13,0 +13,0 @@ *

@@ -67,2 +67,18 @@ /**

/**
* Control the ALS for the logger.
*
* @type {AsyncLocalStorage<{ log: Logger }>}
*/
export const asyncLocalStorageLogger: AsyncLocalStorage<{
log: Logger;
}>;
/**
* Log via the current async local logger.
*
* All Compas internal usages
*
* @type {Logger}
*/
export const contextAwarelogger: Logger;
/**
* The logger only has two severities:

@@ -84,1 +100,2 @@ * - info

};
import { AsyncLocalStorage } from "node:async_hooks";

@@ -0,1 +1,2 @@

import { AsyncLocalStorage } from "node:async_hooks";
import { pino, destination } from "pino";

@@ -42,2 +43,39 @@ import { environment, isProduction } from "./env.js";

/**
* Control the ALS for the logger.
*
* @type {AsyncLocalStorage<{ log: Logger }>}
*/
export const asyncLocalStorageLogger = new AsyncLocalStorage();
/**
* Log via the current async local logger.
*
* All Compas internal usages
*
* @type {Logger}
*/
export const contextAwarelogger = {
info: (...args) => {
const store = asyncLocalStorageLogger.getStore();
if (store) {
store.log.info(...args);
} else {
throw new Error(
`No logger found in AsyncLocalStorage. Did you forget to call 'asyncLocalStorageLogger.run()'?`,
);
}
},
error: (...args) => {
const store = asyncLocalStorageLogger.getStore();
if (store) {
store.log.info(...args);
} else {
throw new Error(
`No logger found in AsyncLocalStorage. Did you forget to call 'asyncLocalStorageLogger.run()'?`,
);
}
},
};
/**
* Deeply update the global logger context. This only affects newly created loggers

@@ -44,0 +82,0 @@ *

@@ -38,2 +38,3 @@ /**

* @returns {string}
* @deprecated use `import.meta.filename`.
*/

@@ -48,2 +49,3 @@ export function filenameForModule(meta: ImportMeta): string;

* @returns {string}
* @deprecated Use `import.meta.dirname`.
*/

@@ -50,0 +52,0 @@ export function dirnameForModule(meta: ImportMeta): string;

@@ -176,5 +176,6 @@ import { lstatSync, realpathSync } from "node:fs";

* @returns {string}
* @deprecated use `import.meta.filename`.
*/
export function filenameForModule(meta) {
return fileURLToPath(meta.url);
return meta.filename;
}

@@ -189,5 +190,6 @@

* @returns {string}
* @deprecated Use `import.meta.dirname`.
*/
export function dirnameForModule(meta) {
return path.dirname(filenameForModule(meta));
return meta.dirname;
}

@@ -194,0 +196,0 @@