From 4487924ab0ab508a20f1a619a91b6b1fd491566b Mon Sep 17 00:00:00 2001 From: "Micael Levi (@micalevisk)" Date: Thu, 2 Jun 2022 18:51:37 -0400 Subject: [PATCH] fix(core): prevents renaming global providers and modules --- packages/core/repl/repl-context.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/core/repl/repl-context.ts b/packages/core/repl/repl-context.ts index cf0e81ce2dc..e40abf9dc20 100644 --- a/packages/core/repl/repl-context.ts +++ b/packages/core/repl/repl-context.ts @@ -59,7 +59,6 @@ export class ReplContext { } private initializeContext() { - const globalRef = globalThis; const modules = this.container.getModules(); modules.forEach(moduleRef => { @@ -67,14 +66,18 @@ export class ReplContext { if (moduleName === InternalCoreModule.name) { return; } - if (globalRef[moduleName]) { + if (globalThis[moduleName]) { moduleName += ` (${moduleRef.token})`; } this.introspectCollection(moduleRef, moduleName, 'providers'); this.introspectCollection(moduleRef, moduleName, 'controllers'); - globalRef[moduleName] = moduleRef.metatype; + // For in REPL auto-complete functionality + Object.defineProperty(globalThis, moduleName, { + value: moduleRef.metatype, + configurable: false, + }); }); } @@ -93,7 +96,10 @@ export class ReplContext { return; } // For in REPL auto-complete functionality - globalThis[stringifiedToken] = token; + Object.defineProperty(globalThis, stringifiedToken, { + value: token, + configurable: false, + }); if (stringifiedToken === ModuleRef.name) { return;