fix(core): update

This commit is contained in:
2023-11-09 16:20:20 +01:00
parent ddcf52de19
commit 590ed5b180
4 changed files with 247 additions and 147 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartenv',
version: '5.0.10',
version: '5.0.11',
description: 'store things about your environment and let them travel across modules'
}

View File

@ -30,13 +30,17 @@ export class Smartenv {
}
}
public async getSafeNodeModule<T = any>(moduleNameArg: string): Promise<T> {
public async getSafeNodeModule<T = any>(moduleNameArg: string, runAfterFunc: (moduleArg: T) => Promise<any>): Promise<T> {
if (!this.isNode) {
console.error(`You tried to load a node module in a wrong context: ${moduleNameArg}`);
return;
}
// tslint:disable-next-line: function-constructor
return new Function(`return import('${moduleNameArg}')`)() as Promise<T>;
const returnValue: T = await (new Function(`return import('${moduleNameArg}')`)() as Promise<T>);
if (runAfterFunc) {
await runAfterFunc(returnValue);
}
return returnValue;
}
public loadedScripts: string[] = [];