From e0631a51154bd92d375240bab49b6547c3a212ef Mon Sep 17 00:00:00 2001 From: ForgeCore Date: Tue, 7 Jul 2026 03:50:22 +0800 Subject: [PATCH] fix: protect method names from token registration collisions Prevent token registration from overwriting module methods (token, format, compile) by making them non-writable. Previously, calling morgan.token('token', fn) would overwrite the morgan.token() method, breaking subsequent token registrations. Fixes #265 --- index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.js b/index.js index 313f5dc..5d81b14 100644 --- a/index.js +++ b/index.js @@ -19,6 +19,13 @@ module.exports.compile = compile module.exports.format = format module.exports.token = token +// Protect method names from being overwritten by token registrations +Object.defineProperties(module.exports, { + compile: { writable: false, configurable: false }, + format: { writable: false, configurable: false }, + token: { writable: false, configurable: false } +}) + /** * Module dependencies. * @private