fix(core): update

This commit is contained in:
Philipp Kunz 2022-03-16 16:09:24 +01:00
parent a014dcf1ab
commit c17ebca309
6 changed files with 15105 additions and 7645 deletions

View File

@ -9,7 +9,7 @@
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartenv",
"shortDescription": "store things about your environment and let them travel across modules",
"description": "store things about your environment and let them travel across modules",
"npmPackagename": "@pushrocks/smartenv",
"license": "MIT"
}

22693
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,9 +4,10 @@
"description": "store things about your environment and let them travel across modules",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"scripts": {
"test": "(tstest test/ --web)",
"build": "(tsbuild --web && tsbundle npm)",
"build": "(tsbuild --web --allowimplicitany && tsbundle npm)",
"testbrowser": "(npm test) && (node testbrowser.js)"
},
"repository": {
@ -23,16 +24,16 @@
},
"homepage": "https://gitlab.com/pushrocks/smartenv",
"dependencies": {
"@pushrocks/smartpromise": "^3.0.6",
"@types/node": "^14.11.2"
"@pushrocks/smartpromise": "^3.1.7",
"@types/node": "^17.0.21"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsbundle": "^1.0.78",
"@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.48",
"@pushrocks/tapbundle": "^3.2.9",
"@types/npm": "^2.0.31",
"@gitzone/tsbuild": "^2.1.56",
"@gitzone/tsbundle": "^1.0.98",
"@gitzone/tsrun": "^1.2.31",
"@gitzone/tstest": "^1.0.68",
"@pushrocks/tapbundle": "^5.0.2",
"@types/npm": "^7.19.0",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},

View File

@ -1,5 +1,5 @@
import { tap, expect } from '@pushrocks/tapbundle';
import * as smartenv from '../ts/index';
import * as smartenv from '../ts/index.js';
let testEnv: smartenv.Smartenv;
@ -17,20 +17,20 @@ tap.test('should get os', async () => {
const resultWindows = await testEnv.isWindowsAsync();
const osModule = await import('os');
if (resultMac) {
expect(osModule.platform()).to.equal('darwin');
expect(osModule.platform()).toEqual('darwin');
console.log('platform is Mac!');
} else if (resultLinux) {
expect(osModule.platform()).to.equal('linux');
expect(osModule.platform()).toEqual('linux');
console.log('platform is Linux!');
} else {
expect(osModule.platform()).to.equal('win32');
expect(osModule.platform()).toEqual('win32');
console.log('platform is Windows!');
}
});
tap.test('should state wether we are in CI', async () => {
if (process.env.CI) {
expect(testEnv.isCI).to.be.true;
expect(testEnv.isCI).toBeTrue();
}
});

View File

@ -1 +1 @@
export * from './smartenv.classes.smartenv';
export * from './smartenv.classes.smartenv.js';

View File

@ -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');