fix(core): update

This commit is contained in:
Philipp Kunz 2020-06-25 23:00:32 +00:00
parent 7aa9637826
commit be2adaf259
3 changed files with 17 additions and 16 deletions

View File

@ -25,11 +25,11 @@
"dependencies": { "dependencies": {
"@pushrocks/smartparam": "^1.1.6", "@pushrocks/smartparam": "^1.1.6",
"@pushrocks/smartpromise": "^3.0.6", "@pushrocks/smartpromise": "^3.0.6",
"@types/node": "^14.0.14", "@types/node": "^14.0.14"
"is-wsl": "^2.2.0"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.24", "@gitzone/tsbuild": "^2.1.24",
"@gitzone/tsbundle": "^1.0.69",
"@gitzone/tsrun": "^1.2.12", "@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.33", "@gitzone/tstest": "^1.0.33",
"@pushrocks/tapbundle": "^3.2.1", "@pushrocks/tapbundle": "^3.2.1",

View File

@ -11,6 +11,18 @@ export interface IEnvObject {
* Smartenv class that makes it easy * Smartenv class that makes it easy
*/ */
export class Smartenv { 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() { public get runtimeEnv() {
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
return 'browser'; return 'browser';
@ -36,10 +48,6 @@ export class Smartenv {
return this.runtimeEnv === 'node'; return this.runtimeEnv === 'node';
} }
public get isWsl(): boolean {
return plugins.isWsl;
}
public get nodeVersion(): string { public get nodeVersion(): string {
return process.version; return process.version;
} }
@ -58,7 +66,7 @@ export class Smartenv {
public async isMacAsync(): Promise<boolean> { public async isMacAsync(): Promise<boolean> {
if (this.isNode) { if (this.isNode) {
const os = await import('os'); const os = this.getSafeNodeModule('os');
return os.platform() === 'darwin'; return os.platform() === 'darwin';
} else { } else {
return false; return false;
@ -67,7 +75,7 @@ export class Smartenv {
public async isWindowsAsync(): Promise<boolean> { public async isWindowsAsync(): Promise<boolean> {
if (this.isNode) { if (this.isNode) {
const os = await import('os'); const os = this.getSafeNodeModule('os');
return os.platform() === 'win32'; return os.platform() === 'win32';
} else { } else {
return false; return false;
@ -76,7 +84,7 @@ export class Smartenv {
public async isLinuxAsync(): Promise<boolean> { public async isLinuxAsync(): Promise<boolean> {
if (this.isNode) { if (this.isNode) {
const os = await import('os'); const os = this.getSafeNodeModule('os');
return os.platform() === 'linux'; return os.platform() === 'linux';
} else { } else {
return false; return false;

View File

@ -3,10 +3,3 @@ import * as smartpromise from '@pushrocks/smartpromise';
export { smartparam, smartpromise }; export { smartparam, smartpromise };
// third party scope
import isWsl from 'is-wsl';
export {
isWsl
};