Skip to content
Open
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
1 change: 1 addition & 0 deletions src/cli/facade/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ const dev = ({ local, logger }: { logger: Logger; local: Local }) =>
hotReloading,
liveReloadPort: liveReload.port,
local: true,
componentConsole: console,
postRequestPayloadSize,
components: opts.components,
path: path.resolve(componentsDir),
Expand Down
5 changes: 5 additions & 0 deletions src/registry/domain/options-sanitiser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -174,6 +175,10 @@ export default function optionsSanitiser(input: RegistryOptions): Config {
options.tarExtractMode = 766;
}

if (!options.componentConsole) {
options.componentConsole = createNoopConsole();
}

if (
typeof options.fallbackRegistryUrl !== 'undefined' &&
!options.fallbackRegistryUrl.endsWith('/')
Expand Down
6 changes: 1 addition & 5 deletions src/registry/routes/helpers/get-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -676,7 +672,7 @@ export default function getComponent(conf: Config, repository: Repository) {
exports: {} as Record<string, (...args: any[]) => any>
},
exports: {} as Record<string, (...args: any[]) => any>,
console: conf.local ? console : noopConsole,
console: conf.componentConsole,
setTimeout,
Buffer,
AbortController: globalThis?.AbortController,
Expand Down
18 changes: 18 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,24 @@ export interface Config<T = any> {
* system (`true`) or from the remote storage (`false`).
*/
local: boolean;
/**
* 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.
*
* @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
*/
componentConsole: Partial<Console>;
/**
* File and directory mode (octal) applied when extracting tarballs during
* publishing.
Expand Down
12 changes: 12 additions & 0 deletions src/utils/noop-console.ts
Original file line number Diff line number Diff line change
@@ -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<Console> {
const noop = () => {};
return Object.fromEntries(Object.keys(console).map((key) => [key, noop]));
}

export default createNoopConsole;