From be2adaf259d1678c78fc74f72860682020562d4f Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Thu, 25 Jun 2020 23:00:32 +0000 Subject: [PATCH] fix(core): update --- package.json | 4 ++-- ts/smartenv.classes.smartenv.ts | 22 +++++++++++++++------- ts/smartenv.plugins.ts | 7 ------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 9e4a2ac..4f664ef 100644 --- a/package.json +++ b/package.json @@ -25,11 +25,11 @@ "dependencies": { "@pushrocks/smartparam": "^1.1.6", "@pushrocks/smartpromise": "^3.0.6", - "@types/node": "^14.0.14", - "is-wsl": "^2.2.0" + "@types/node": "^14.0.14" }, "devDependencies": { "@gitzone/tsbuild": "^2.1.24", + "@gitzone/tsbundle": "^1.0.69", "@gitzone/tsrun": "^1.2.12", "@gitzone/tstest": "^1.0.33", "@pushrocks/tapbundle": "^3.2.1", diff --git a/ts/smartenv.classes.smartenv.ts b/ts/smartenv.classes.smartenv.ts index 4efd4f9..8f12fa0 100644 --- a/ts/smartenv.classes.smartenv.ts +++ b/ts/smartenv.classes.smartenv.ts @@ -11,6 +11,18 @@ export interface IEnvObject { * Smartenv class that makes it easy */ export class Smartenv { + public getSafeNodeModule(moduleNameArg: string) { + // tslint:disable-next-line: function-constructor + return new Function( + 'exports', + 'require', + 'module', + '__filename', + '__dirname', + `return require('${moduleNameArg}')` + )(exports,require,module,__filename,__dirname); + } + public get runtimeEnv() { if (typeof window !== 'undefined') { return 'browser'; @@ -36,10 +48,6 @@ export class Smartenv { return this.runtimeEnv === 'node'; } - public get isWsl(): boolean { - return plugins.isWsl; - } - public get nodeVersion(): string { return process.version; } @@ -58,7 +66,7 @@ export class Smartenv { public async isMacAsync(): Promise { if (this.isNode) { - const os = await import('os'); + const os = this.getSafeNodeModule('os'); return os.platform() === 'darwin'; } else { return false; @@ -67,7 +75,7 @@ export class Smartenv { public async isWindowsAsync(): Promise { if (this.isNode) { - const os = await import('os'); + const os = this.getSafeNodeModule('os'); return os.platform() === 'win32'; } else { return false; @@ -76,7 +84,7 @@ export class Smartenv { public async isLinuxAsync(): Promise { if (this.isNode) { - const os = await import('os'); + const os = this.getSafeNodeModule('os'); return os.platform() === 'linux'; } else { return false; diff --git a/ts/smartenv.plugins.ts b/ts/smartenv.plugins.ts index 8fe6fe4..6027724 100644 --- a/ts/smartenv.plugins.ts +++ b/ts/smartenv.plugins.ts @@ -3,10 +3,3 @@ import * as smartpromise from '@pushrocks/smartpromise'; export { smartparam, smartpromise }; -// third party scope - -import isWsl from 'is-wsl'; - -export { - isWsl -};