Skip to content

Commit

Permalink
fix(core): prevents renaming global providers and modules
Browse files Browse the repository at this point in the history
  • Loading branch information
micalevisk committed Jun 2, 2022
1 parent 018fd6b commit 4487924
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/core/repl/repl-context.ts
Expand Up @@ -59,22 +59,25 @@ export class ReplContext {
}

private initializeContext() {
const globalRef = globalThis;
const modules = this.container.getModules();

modules.forEach(moduleRef => {
let moduleName = moduleRef.metatype.name;
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,
});
});
}

Expand All @@ -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;
Expand Down

0 comments on commit 4487924

Please sign in to comment.