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

View File

@ -1,5 +1,5 @@
import { tap, expect } from '@pushrocks/tapbundle'; import { tap, expect } from '@pushrocks/tapbundle';
import * as smartenv from '../ts/index'; import * as smartenv from '../ts/index.js';
let testEnv: smartenv.Smartenv; let testEnv: smartenv.Smartenv;
@ -17,20 +17,20 @@ tap.test('should get os', async () => {
const resultWindows = await testEnv.isWindowsAsync(); const resultWindows = await testEnv.isWindowsAsync();
const osModule = await import('os'); const osModule = await import('os');
if (resultMac) { if (resultMac) {
expect(osModule.platform()).to.equal('darwin'); expect(osModule.platform()).toEqual('darwin');
console.log('platform is Mac!'); console.log('platform is Mac!');
} else if (resultLinux) { } else if (resultLinux) {
expect(osModule.platform()).to.equal('linux'); expect(osModule.platform()).toEqual('linux');
console.log('platform is Linux!'); console.log('platform is Linux!');
} else { } else {
expect(osModule.platform()).to.equal('win32'); expect(osModule.platform()).toEqual('win32');
console.log('platform is Windows!'); console.log('platform is Windows!');
} }
}); });
tap.test('should state wether we are in CI', async () => { tap.test('should state wether we are in CI', async () => {
if (process.env.CI) { 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 plugins from './smartenv.plugins.js';
import * as interfaces from './interfaces'; import * as interfaces from './interfaces/index.js';
// interfaces // interfaces
export interface IEnvObject { 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) { if (!this.isNode) {
console.error('You tried to load a node module in a wrong context'); console.error('You tried to load a node module in a wrong context');
return; return;
} }
// tslint:disable-next-line: function-constructor // tslint:disable-next-line: function-constructor
return new Function( return (new Function(`return import('${moduleNameArg}')`))() as Promise<T>;
'exports',
'require',
'module',
'__filename',
'__dirname',
`return require('${moduleNameArg}')`
)(exports, require, module, __filename, __dirname);
} }
public loadedScripts: string[] = []; public loadedScripts: string[] = [];
@ -114,7 +107,7 @@ export class Smartenv {
public async isMacAsync(): Promise<boolean> { public async isMacAsync(): Promise<boolean> {
if (this.isNode) { if (this.isNode) {
const os = this.getSafeNodeModule('os'); const os = await this.getSafeNodeModule('os');
return os.platform() === 'darwin'; return os.platform() === 'darwin';
} else { } else {
return false; return false;
@ -123,7 +116,7 @@ export class Smartenv {
public async isWindowsAsync(): Promise<boolean> { public async isWindowsAsync(): Promise<boolean> {
if (this.isNode) { if (this.isNode) {
const os = this.getSafeNodeModule('os'); const os = await this.getSafeNodeModule('os');
return os.platform() === 'win32'; return os.platform() === 'win32';
} else { } else {
return false; return false;
@ -132,7 +125,7 @@ export class Smartenv {
public async isLinuxAsync(): Promise<boolean> { public async isLinuxAsync(): Promise<boolean> {
if (this.isNode) { if (this.isNode) {
const os = this.getSafeNodeModule('os'); const os = await this.getSafeNodeModule('os');
return os.platform() === 'linux'; return os.platform() === 'linux';
} else { } else {
return false; return false;
@ -145,9 +138,8 @@ export class Smartenv {
public async printEnv() { public async printEnv() {
if (this.isNode) { if (this.isNode) {
console.log('running on NODE'); console.log('running on NODE');
const smartenvVersion = require('../package.json').version;
console.log( console.log(
'node version is ' + this.nodeVersion + ' and smartenv version is ' + smartenvVersion 'node version is ' + this.nodeVersion
); );
} else { } else {
console.log('running on BROWSER'); console.log('running on BROWSER');