From c1513b69d3a4b6ceb4e9a569b3b5ab0f0e7c8260 Mon Sep 17 00:00:00 2001 From: Leandro W Osorio Date: Wed, 7 Jan 2026 15:54:05 -0500 Subject: [PATCH 1/3] Creating `enableComponentConsoleOutput` option to allow components to enable/disable console output explicitly --- src/registry/routes/helpers/get-component.ts | 4 +++- src/types.ts | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/registry/routes/helpers/get-component.ts b/src/registry/routes/helpers/get-component.ts index cd7afe81..d68c6a23 100644 --- a/src/registry/routes/helpers/get-component.ts +++ b/src/registry/routes/helpers/get-component.ts @@ -676,7 +676,9 @@ export default function getComponent(conf: Config, repository: Repository) { exports: {} as Record any> }, exports: {} as Record any>, - console: conf.local ? console : noopConsole, + console: conf.enableComponentConsoleOutput + ? console + : noopConsole, setTimeout, Buffer, AbortController: globalThis?.AbortController, diff --git a/src/types.ts b/src/types.ts index 234f4d2e..279f2638 100644 --- a/src/types.ts +++ b/src/types.ts @@ -289,6 +289,14 @@ export interface Config { * system (`true`) or from the remote storage (`false`). */ local: boolean; + /** + * Enables component console output (console.log, console.error, etc.) + * during component execution. Useful for debugging in development and + * lower environments. + * + * @default false + */ + enableComponentConsoleOutput: boolean; /** * File and directory mode (octal) applied when extracting tarballs during * publishing. From 13ed32fd6c22f5a10cc22ce7fc2f36aaa5967f05 Mon Sep 17 00:00:00 2001 From: Leandro W Osorio Date: Wed, 7 Jan 2026 15:54:53 -0500 Subject: [PATCH 2/3] Set `enableComponentConsoleOutput` as `true` for dev mode --- src/cli/facade/dev.ts | 1 + src/registry/domain/options-sanitiser.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/cli/facade/dev.ts b/src/cli/facade/dev.ts index f2fda0f5..2b595874 100644 --- a/src/cli/facade/dev.ts +++ b/src/cli/facade/dev.ts @@ -204,6 +204,7 @@ const dev = ({ local, logger }: { logger: Logger; local: Local }) => hotReloading, liveReloadPort: liveReload.port, local: true, + enableComponentConsoleOutput: true, postRequestPayloadSize, components: opts.components, path: path.resolve(componentsDir), diff --git a/src/registry/domain/options-sanitiser.ts b/src/registry/domain/options-sanitiser.ts index 5c4a0d00..fa54eb0a 100644 --- a/src/registry/domain/options-sanitiser.ts +++ b/src/registry/domain/options-sanitiser.ts @@ -174,6 +174,10 @@ export default function optionsSanitiser(input: RegistryOptions): Config { options.tarExtractMode = 766; } + if (typeof options.enableComponentConsoleOutput === 'undefined') { + options.enableComponentConsoleOutput = false; + } + if ( typeof options.fallbackRegistryUrl !== 'undefined' && !options.fallbackRegistryUrl.endsWith('/') From 196b8b130855b1a461b863939b31f86df1955ace Mon Sep 17 00:00:00 2001 From: Leandro W Osorio Date: Wed, 14 Jan 2026 09:47:43 -0500 Subject: [PATCH 3/3] Refactor: Decouple component logging from local storage flag --- src/cli/facade/dev.ts | 2 +- src/registry/domain/options-sanitiser.ts | 5 +++-- src/registry/routes/helpers/get-component.ts | 8 +------- src/types.ts | 20 +++++++++++++++----- src/utils/noop-console.ts | 12 ++++++++++++ 5 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 src/utils/noop-console.ts diff --git a/src/cli/facade/dev.ts b/src/cli/facade/dev.ts index 2b595874..03619e62 100644 --- a/src/cli/facade/dev.ts +++ b/src/cli/facade/dev.ts @@ -204,7 +204,7 @@ const dev = ({ local, logger }: { logger: Logger; local: Local }) => hotReloading, liveReloadPort: liveReload.port, local: true, - enableComponentConsoleOutput: true, + componentConsole: console, postRequestPayloadSize, components: opts.components, path: path.resolve(componentsDir), diff --git a/src/registry/domain/options-sanitiser.ts b/src/registry/domain/options-sanitiser.ts index fa54eb0a..c830c4c1 100644 --- a/src/registry/domain/options-sanitiser.ts +++ b/src/registry/domain/options-sanitiser.ts @@ -2,6 +2,7 @@ import zlib from 'node:zlib'; import { compileSync } from 'oc-client-browser'; import settings from '../../resources/settings'; import type { Config } from '../../types'; +import createNoopConsole from '../../utils/noop-console'; import * as auth from './authentication'; const DEFAULT_NODE_KEEPALIVE_MS = 5000; @@ -174,8 +175,8 @@ export default function optionsSanitiser(input: RegistryOptions): Config { options.tarExtractMode = 766; } - if (typeof options.enableComponentConsoleOutput === 'undefined') { - options.enableComponentConsoleOutput = false; + if (!options.componentConsole) { + options.componentConsole = createNoopConsole(); } if ( diff --git a/src/registry/routes/helpers/get-component.ts b/src/registry/routes/helpers/get-component.ts index d68c6a23..7134f70a 100644 --- a/src/registry/routes/helpers/get-component.ts +++ b/src/registry/routes/helpers/get-component.ts @@ -70,10 +70,6 @@ export interface GetComponentResult { } export const stream = Symbol('stream'); -const noop = () => {}; -const noopConsole = Object.fromEntries( - Object.keys(console).map((key) => [key, noop]) -); /** * Converts the plugins to a function that returns a record of plugins with the context applied @@ -676,9 +672,7 @@ export default function getComponent(conf: Config, repository: Repository) { exports: {} as Record any> }, exports: {} as Record any>, - console: conf.enableComponentConsoleOutput - ? console - : noopConsole, + console: conf.componentConsole, setTimeout, Buffer, AbortController: globalThis?.AbortController, diff --git a/src/types.ts b/src/types.ts index 279f2638..6e92aeb9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -290,13 +290,23 @@ export interface Config { */ local: boolean; /** - * Enables component console output (console.log, console.error, etc.) - * during component execution. Useful for debugging in development and - * lower environments. + * Console interface provided to components during execution. + * Allows for flexible logging strategies: pass the real console, a custom + * implementation that sends logs to a monitoring provider, or a no-op console. * - * @default false + * @example + * // Log to console + * componentConsole: console + * @example + * // Log to monitoring provider + * componentConsole: createCustomConsole(monitoringClient) + * @example + * // Disable component logs + * componentConsole: createNoopConsole() + * + * @default createNoopConsole() - a no-op console that discards all logs */ - enableComponentConsoleOutput: boolean; + componentConsole: Partial; /** * File and directory mode (octal) applied when extracting tarballs during * publishing. diff --git a/src/utils/noop-console.ts b/src/utils/noop-console.ts new file mode 100644 index 00000000..d8bea511 --- /dev/null +++ b/src/utils/noop-console.ts @@ -0,0 +1,12 @@ +/** + * Creates a no-op console object that silently discards all logging calls. + * Useful as a default console implementation when component logging is disabled. + * + * @returns Console object with all methods mapped to no-op functions + */ +export function createNoopConsole(): Partial { + const noop = () => {}; + return Object.fromEntries(Object.keys(console).map((key) => [key, noop])); +} + +export default createNoopConsole;