fix(core): update
This commit is contained in:
parent
7aa9637826
commit
be2adaf259
@ -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",
|
||||
|
@ -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<boolean> {
|
||||
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<boolean> {
|
||||
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<boolean> {
|
||||
if (this.isNode) {
|
||||
const os = await import('os');
|
||||
const os = this.getSafeNodeModule('os');
|
||||
return os.platform() === 'linux';
|
||||
} else {
|
||||
return false;
|
||||
|
@ -3,10 +3,3 @@ import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
export { smartparam, smartpromise };
|
||||
|
||||
// third party scope
|
||||
|
||||
import isWsl from 'is-wsl';
|
||||
|
||||
export {
|
||||
isWsl
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user