Compare commits

...

19 Commits

Author SHA1 Message Date
b4897d238f update description 2024-05-29 14:12:50 +02:00
df69e46697 update tsconfig 2024-04-14 17:32:19 +02:00
1493430d9f update npmextra.json: githost 2024-04-01 21:34:47 +02:00
78afde963b update npmextra.json: githost 2024-04-01 19:58:07 +02:00
a4a633e936 update npmextra.json: githost 2024-03-30 21:47:05 +01:00
27fbe00cb0 5.0.12 2023-11-09 16:37:53 +01:00
f3cc468eda fix(core): update 2023-11-09 16:37:52 +01:00
b303799b8d 5.0.11 2023-11-09 16:20:20 +01:00
590ed5b180 fix(core): update 2023-11-09 16:20:20 +01:00
ddcf52de19 5.0.10 2023-10-03 23:40:15 +02:00
c1b3af09ef fix(core): update 2023-10-03 23:40:15 +02:00
a1e2cda010 5.0.9 2023-10-03 18:55:37 +02:00
d409d3a532 fix(core): update 2023-10-03 18:55:36 +02:00
b4dae84835 5.0.8 2023-10-03 18:55:17 +02:00
20e27c93d9 fix(core): update 2023-10-03 18:55:16 +02:00
117dc6013c 5.0.7 2023-10-03 18:54:52 +02:00
c6bc433a73 fix(core): update 2023-10-03 18:54:51 +02:00
299815838c switch to new org scheme 2023-07-11 00:36:49 +02:00
e8318cbf2f switch to new org scheme 2023-07-10 02:48:52 +02:00
13 changed files with 3219 additions and 1748 deletions

View File

@ -0,0 +1,66 @@
name: Default (not tags)
on:
push:
tags-ignore:
- '**'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Install pnpm and npmci
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
- name: Run npm prepare
run: npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build

View File

@ -0,0 +1,124 @@
name: Default (tags)
on:
push:
tags:
- '*'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build
release:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Release
run: |
npmci node install stable
npmci npm publish
metadata:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Code quality
run: |
npmci command npm install -g typescript
npmci npm install
- name: Trigger
run: npmci trigger
- name: Build docs and upload artifacts
run: |
npmci node install stable
npmci npm install
pnpm install -g @git.zone/tsdoc
npmci command tsdoc
continue-on-error: true

View File

@ -1,128 +0,0 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
before_script:
- pnpm install -g pnpm
- pnpm install -g @shipzone/npmci
- npmci npm prepare
# ====================
# security stage
# ====================
# ====================
# security stage
# ====================
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --prod
tags:
- lossless
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --dev
tags:
- lossless
- docker
allow_failure: true
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testBuild:
stage: test
script:
- npmci node install stable
- npmci npm install
- npmci npm build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install stable
- npmci npm install
- npmci command npm run buildDocs
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

View File

@ -6,12 +6,27 @@
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartenv",
"description": "store things about your environment and let them travel across modules",
"npmPackagename": "@pushrocks/smartenv",
"license": "MIT"
"description": "A module for storing and accessing environment details across different platforms.",
"npmPackagename": "@push.rocks/smartenv",
"license": "MIT",
"keywords": [
"environment detection",
"cross-platform",
"node.js",
"browser",
"module loading",
"CI detection",
"OS detection",
"runtime environment",
"typescript",
"async"
]
}
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
}
}

View File

@ -1,7 +1,7 @@
{
"name": "@pushrocks/smartenv",
"version": "5.0.6",
"description": "store things about your environment and let them travel across modules",
"name": "@push.rocks/smartenv",
"version": "5.0.12",
"description": "A module for storing and accessing environment details across different platforms.",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
@ -13,28 +13,37 @@
},
"repository": {
"type": "git",
"url": "https://gitlab.com/pushrocks/smartenv.git"
"url": "https://code.foss.global/push.rocks/smartenv.git"
},
"keywords": [
"environment"
"environment detection",
"cross-platform",
"node.js",
"browser",
"module loading",
"CI detection",
"OS detection",
"runtime environment",
"typescript",
"async"
],
"author": "Lossless GmbH <hello@lossless.support> (https://lossless.com)",
"license": "MIT",
"bugs": {
"url": "https://gitlab.com/pushrocks/smartenv/issues"
},
"homepage": "https://gitlab.com/pushrocks/smartenv",
"homepage": "https://code.foss.global/push.rocks/smartenv",
"dependencies": {
"@pushrocks/smartpromise": "^3.1.7"
"@push.rocks/smartpromise": "^4.0.2"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.56",
"@gitzone/tsbundle": "^2.0.7",
"@gitzone/tsrun": "^1.2.31",
"@gitzone/tstest": "^1.0.68",
"@pushrocks/tapbundle": "^5.0.2",
"@types/node": "^18.13.0",
"@types/npm": "^7.19.0"
"@git.zone/tsbuild": "^2.1.72",
"@git.zone/tsbundle": "^2.0.15",
"@git.zone/tsrun": "^1.2.44",
"@git.zone/tstest": "^1.0.86",
"@push.rocks/tapbundle": "^5.0.8",
"@types/node": "^20.11.24",
"@types/npm": "^7.19.3"
},
"private": false,
"files": [
@ -52,4 +61,4 @@
"browserslist": [
"last 1 chrome versions"
]
}
}

4419
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

138
readme.md
View File

@ -1,37 +1,123 @@
# @pushrocks/smartenv
# @push.rocks/smartenv
store things about your environment and let them travel across modules
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartenv)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartenv)
* [github.com (source mirror)](https://github.com/pushrocks/smartenv)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartenv/)
## Install
## Status for master
To install `@push.rocks/smartenv`, you need Node.js and npm installed. Then, run the following command:
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartenv/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartenv/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartenv)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartenv)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartenv)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartenv)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartenv)](https://lossless.cloud)
```bash
npm install @push.rocks/smartenv --save
```
## Usage
Use TypeScript for best in class instellisense.
`@push.rocks/smartenv` is a valuable utility for managing and accessing environment-specific information within your application, enabling your code to adapt to different environments, such as development, testing, and production seamlessly. Here we delve into how to utilize `@push.rocks/smartenv` effectively within a TypeScript project. We'll cover initializing the package, checking the execution environment, loading modules conditionally based on the environment, and accessing environment variables securely.
## Contribution
### Getting Started
First, ensure to import `Smartenv` from the package:
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
```typescript
import { Smartenv } from '@push.rocks/smartenv';
```
For further information read the linked docs at the top of this readme.
### Initializing Smartenv
You can begin by creating an instance of `Smartenv`. This instance will be your gateway to accessing and managing the environment properties throughout your application.
## Legal
> MIT licensed | **&copy;** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
```typescript
const smartEnv = new Smartenv();
```
### Checking Execution Environment
`Smartenv` offers straightforward methods to determine whether your code is running in a Node.js or browser environment. This can be particularly useful for isomorphic code.
```typescript
// Check if running in a Node.js environment
console.log(`Is Node: ${smartEnv.isNode}`);
// Check if running in a browser environment
console.log(`Is Browser: ${smartEnv.isBrowser}`);
```
### Loading Modules Conditionally
One of the core functionalities of `@push.rocks/smartenv` is to load modules based on the execution environment. This feature is immensely useful for isomorphic applications that need to run both in the browser and Node.js environments.
```typescript
// Node.js module and equivalent browser module URLs
const nodeModuleName = 'example-node-module';
const browserModuleUrl = 'https://example.com/example-browser-module.js';
// Function to access the module in the browser
const getBrowserModule = () => window.exampleBrowserModule;
const module = await smartEnv.getEnvAwareModule({
nodeModuleName: nodeModuleName,
webUrlArg: browserModuleUrl,
getFunction: getBrowserModule
});
console.log(module);
```
### Accessing Environment Variables Securely
For Node.js environments, accessing environment variables is a common task. `Smartenv` does not directly manipulate environment variables but encourages best practices for accessing them, ensuring your application remains secure and performs optimally.
```typescript
if(smartEnv.isNode) {
console.log(`Your environment variable value: ${process.env.YOUR_ENV_VAR}`);
}
```
### Detecting CI Environments
Detect if your application is running in a Continuous Integration (CI) environment. This can be useful for modifying behavior during testing or deployment.
```typescript
console.log(`Is CI: ${smartEnv.isCI}`);
```
### Platform-Specific Checks
`Smartenv` enables you to perform checks for specific operating systems when running in a Node.js environment, which can be particularly useful for tasks that depend on OS-specific features or paths.
```typescript
const isMac = await smartEnv.isMacAsync();
const isWindows = await smartEnv.isWindowsAsync();
const isLinux = await smartEnv.isLinuxAsync();
console.log(`Is Mac: ${isMac}, Is Windows: ${isWindows}, Is Linux: ${isLinux}`);
```
### Printing Environment for Debugging
To assist with debugging, `Smartenv` offers a method to print the current environment and some relevant information to the console. This feature is particularly useful during development or when troubleshooting environment-specific issues.
```typescript
smartEnv.printEnv();
```
### Usage within Browser
While `Smartenv` primarily facilitates handling different environments in server-side applications, it also provides functionalities to manage and load scripts dynamically in the browser. This allows for more flexible and environment-aware code sharing between server and client-side.
For instance, using `getSafeWebModule` to dynamically load a script only if it hasn't been already and then utilizing a globally available function or object that the script provides.
### Conclusion
`@push.rocks/smartenv` is a comprehensive solution for managing environment-specific logic and configurations in your JavaScript and TypeScript projects. By leveraging its functionalities, developers can create more robust, flexible, and maintainable applications that seamlessly adapt to different execution contexts, whether in Node.js, the browser, or CI environments.
Always refer to the official documentation and source code for the most up-to-date usage examples and features.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

View File

@ -1,4 +1,4 @@
import { tap, expect } from '@pushrocks/tapbundle';
import { tap, expect } from '@push.rocks/tapbundle';
import * as smartenv from '../ts/index.js';
let testEnv: smartenv.Smartenv;

View File

@ -2,7 +2,7 @@
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartenv',
version: '5.0.6',
name: '@push.rocks/smartenv',
version: '5.0.12',
description: 'store things about your environment and let them travel across modules'
}

View File

@ -30,13 +30,17 @@ export class Smartenv {
}
}
public async getSafeNodeModule<T = any>(moduleNameArg: string): Promise<T> {
public async getSafeNodeModule<T = any>(moduleNameArg: string, runAfterFunc?: (moduleArg: T) => Promise<any>): Promise<T> {
if (!this.isNode) {
console.error(`You tried to load a node module in a wrong context: ${moduleNameArg}`);
return;
}
// tslint:disable-next-line: function-constructor
return new Function(`return import('${moduleNameArg}')`)() as Promise<T>;
const returnValue: T = await (new Function(`return import('${moduleNameArg}')`)() as Promise<T>);
if (runAfterFunc) {
await runAfterFunc(returnValue);
}
return returnValue;
}
public loadedScripts: string[] = [];

View File

@ -1,3 +1,3 @@
import * as smartpromise from '@pushrocks/smartpromise';
import * as smartpromise from '@push.rocks/smartpromise';
export { smartpromise };

View File

@ -3,7 +3,12 @@
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext"
}
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}