fix(core): update
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
			
		||||
import * as plugins from './smartenv.plugins';
 | 
			
		||||
import * as interfaces from './interfaces';
 | 
			
		||||
import * as plugins from './smartenv.plugins.js';
 | 
			
		||||
import * as interfaces from './interfaces/index.js';
 | 
			
		||||
 | 
			
		||||
// interfaces
 | 
			
		||||
export interface IEnvObject {
 | 
			
		||||
@@ -26,20 +26,13 @@ export class Smartenv {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public getSafeNodeModule<T = any>(moduleNameArg: string): T {
 | 
			
		||||
  public async getSafeNodeModule<T = any>(moduleNameArg: string): Promise<T> {
 | 
			
		||||
    if (!this.isNode) {
 | 
			
		||||
      console.error('You tried to load a node module in a wrong context');
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    // tslint:disable-next-line: function-constructor
 | 
			
		||||
    return new Function(
 | 
			
		||||
      'exports',
 | 
			
		||||
      'require',
 | 
			
		||||
      'module',
 | 
			
		||||
      '__filename',
 | 
			
		||||
      '__dirname',
 | 
			
		||||
      `return require('${moduleNameArg}')`
 | 
			
		||||
    )(exports, require, module, __filename, __dirname);
 | 
			
		||||
    return (new Function(`return import('${moduleNameArg}')`))() as Promise<T>;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public loadedScripts: string[] = [];
 | 
			
		||||
@@ -114,7 +107,7 @@ export class Smartenv {
 | 
			
		||||
 | 
			
		||||
  public async isMacAsync(): Promise<boolean> {
 | 
			
		||||
    if (this.isNode) {
 | 
			
		||||
      const os = this.getSafeNodeModule('os');
 | 
			
		||||
      const os = await this.getSafeNodeModule('os');
 | 
			
		||||
      return os.platform() === 'darwin';
 | 
			
		||||
    } else {
 | 
			
		||||
      return false;
 | 
			
		||||
@@ -123,7 +116,7 @@ export class Smartenv {
 | 
			
		||||
 | 
			
		||||
  public async isWindowsAsync(): Promise<boolean> {
 | 
			
		||||
    if (this.isNode) {
 | 
			
		||||
      const os = this.getSafeNodeModule('os');
 | 
			
		||||
      const os = await this.getSafeNodeModule('os');
 | 
			
		||||
      return os.platform() === 'win32';
 | 
			
		||||
    } else {
 | 
			
		||||
      return false;
 | 
			
		||||
@@ -132,7 +125,7 @@ export class Smartenv {
 | 
			
		||||
 | 
			
		||||
  public async isLinuxAsync(): Promise<boolean> {
 | 
			
		||||
    if (this.isNode) {
 | 
			
		||||
      const os = this.getSafeNodeModule('os');
 | 
			
		||||
      const os = await this.getSafeNodeModule('os');
 | 
			
		||||
      return os.platform() === 'linux';
 | 
			
		||||
    } else {
 | 
			
		||||
      return false;
 | 
			
		||||
@@ -145,9 +138,8 @@ export class Smartenv {
 | 
			
		||||
  public async printEnv() {
 | 
			
		||||
    if (this.isNode) {
 | 
			
		||||
      console.log('running on NODE');
 | 
			
		||||
      const smartenvVersion = require('../package.json').version;
 | 
			
		||||
      console.log(
 | 
			
		||||
        'node version is ' + this.nodeVersion + ' and smartenv version is ' + smartenvVersion
 | 
			
		||||
        'node version is ' + this.nodeVersion
 | 
			
		||||
      );
 | 
			
		||||
    } else {
 | 
			
		||||
      console.log('running on BROWSER');
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user