@driveflux/env 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export declare const loadEnv: (path: string, overwriteEnv?: boolean) => void;
1
2
  export declare const loadAllEnv: (basePath?: string, overwriteEnv?: boolean) => void;
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,UAAU,qDAWtB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,OAAO,SAAU,MAAM,iCAYnC,CAAA;AAED,eAAO,MAAM,UAAU,qDAoBtB,CAAA"}
package/dist/index.js CHANGED
@@ -1,27 +1,29 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import dotenv from 'dotenv';
4
- var loadEnv = function(path) {
5
- var overwriteEnv = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
6
- console.log('Loading env file: ', path);
7
- if (!fs.existsSync(path)) {
8
- console.log('Skipping env file "'.concat(path, '", not found'));
9
- return;
10
- }
11
- var newEnv = dotenv.parse(fs.readFileSync(path));
12
- for(var k in newEnv){
13
- if (overwriteEnv || typeof process.env[k] === 'undefined') {
14
- process.env[k] = newEnv[k];
4
+ export const loadEnv = (path, overwriteEnv = true)=>{
5
+ try {
6
+ console.log('Loading env file: ', path);
7
+ const newEnv = dotenv.parse(fs.readFileSync(path));
8
+ for(const k in newEnv){
9
+ if (overwriteEnv || typeof process.env[k] === 'undefined') {
10
+ process.env[k] = newEnv[k];
11
+ }
15
12
  }
13
+ } catch (e) {
14
+ console.log(`Skipping env file "${path}", not found`);
16
15
  }
17
16
  };
18
- export var loadAllEnv = function() {
19
- var basePath = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.cwd(), overwriteEnv = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
17
+ export const loadAllEnv = (basePath = process.cwd(), overwriteEnv = true)=>{
20
18
  // Load standard env files
21
19
  loadEnv(path.join(basePath, '.env'), overwriteEnv);
22
20
  loadEnv(path.join(basePath, '.env.local'), overwriteEnv);
21
+ // Default USE_ENV is development
22
+ if (!process.env.USE_ENV && (process.env.NODE_ENV === 'development' || !process.env.NODE_ENV)) {
23
+ process.env.USE_ENV = 'development';
24
+ }
23
25
  if (process.env.USE_ENV) {
24
- loadEnv(path.join(basePath, ".env.".concat(process.env.USE_ENV)), overwriteEnv);
25
- loadEnv(path.join(basePath, ".env.".concat(process.env.USE_ENV, ".local")), overwriteEnv);
26
+ loadEnv(path.join(basePath, `.env.${process.env.USE_ENV}`), overwriteEnv);
27
+ loadEnv(path.join(basePath, `.env.${process.env.USE_ENV}.local`), overwriteEnv);
26
28
  }
27
29
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@driveflux/env",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -15,14 +15,14 @@
15
15
  "dotenv": "^16.4.5"
16
16
  },
17
17
  "devDependencies": {
18
- "@driveflux/fab": "2.3.0",
18
+ "@driveflux/fab": "2.3.3",
19
19
  "@driveflux/tsconfig": "1.3.0",
20
- "@swc/cli": "^0.4.0",
21
- "@swc/core": "1.7.2",
22
- "@types/lodash": "^4.17.7",
23
- "@types/node": "^20.14.12",
24
- "del-cli": "^5.1.0",
25
- "typescript": "^5.5.4"
20
+ "@swc/cli": "0.4.1-nightly.20240914",
21
+ "@swc/core": "1.7.39",
22
+ "@types/lodash": "^4.17.12",
23
+ "@types/node": "^22.7.8",
24
+ "del-cli": "^6.0.0",
25
+ "typescript": "^5.6.3"
26
26
  },
27
27
  "scripts": {
28
28
  "build": "fab",