@cabloy/dotenv 1.1.12 → 1.1.13

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,4 +1,4 @@
1
1
  import type { DotenvParseOutput } from 'dotenv';
2
- export declare function loadEnvs(meta: object, dir: string, prefix?: string, postfix?: string): DotenvParseOutput | undefined;
2
+ export declare function loadEnvs(meta: object, dir: string, prefix?: string, postfixes?: string | string[]): DotenvParseOutput | undefined;
3
3
  export declare function metaToScope(meta: object): {};
4
- export declare function getEnvFiles(meta: object, dir: string, prefix: string, postfix?: string): string[] | undefined;
4
+ export declare function getEnvFiles(meta: object, dir: string, prefix: string, postfixes?: string | string[]): string[] | undefined;
package/dist/index.js CHANGED
@@ -4,9 +4,9 @@ import dotenv from 'dotenv';
4
4
  import dotenvExpand from 'dotenv-expand';
5
5
  import { globbySync } from 'globby';
6
6
 
7
- function loadEnvs(meta, dir, prefix = '.env', postfix) {
7
+ function loadEnvs(meta, dir, prefix = '.env', postfixes) {
8
8
  // envfiles
9
- const envFiles = getEnvFiles(meta, dir, prefix, postfix);
9
+ const envFiles = getEnvFiles(meta, dir, prefix, postfixes);
10
10
  if (!envFiles) return undefined;
11
11
  // dotenv
12
12
  const result = dotenv.config({
@@ -27,21 +27,23 @@ function metaToScope(meta) {
27
27
  }
28
28
  return scope;
29
29
  }
30
- function getEnvFiles(meta, dir, prefix, postfix) {
30
+ function getEnvFiles(meta, dir, prefix, postfixes) {
31
+ if (typeof postfixes === 'string') postfixes = [postfixes];
31
32
  // files
32
33
  let files = globbySync(`${prefix}*`, {
33
34
  cwd: dir
34
35
  });
35
- const fileNames = files.map(item => {
36
- if (postfix) {
37
- item = item.substring(0, item.length - postfix.length);
38
- }
39
- return item;
40
- });
41
36
  // source
42
37
  const source = {};
43
- for (const fileName of fileNames) {
44
- source[fileName] = true;
38
+ for (const file of files) {
39
+ if (!postfixes) {
40
+ source[file] = undefined;
41
+ } else {
42
+ const postfix = postfixes.find(postfix => file.endsWith(postfix));
43
+ if (postfix) {
44
+ source[file.substring(0, file.length - postfix.length)] = postfix;
45
+ }
46
+ }
45
47
  }
46
48
  // scope
47
49
  const scope = metaToScope(meta);
@@ -53,8 +55,8 @@ function getEnvFiles(meta, dir, prefix, postfix) {
53
55
  // files
54
56
  files = keys.map(key => {
55
57
  let file = path.join(dir, key);
56
- if (postfix) {
57
- file = `${file}${postfix}`;
58
+ if (source[key]) {
59
+ file = `${file}${source[key]}`;
58
60
  }
59
61
  return file;
60
62
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cabloy/dotenv",
3
3
  "type": "module",
4
- "version": "1.1.12",
4
+ "version": "1.1.13",
5
5
  "description": "cabloy dotenv",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -25,7 +25,7 @@
25
25
  "dist"
26
26
  ],
27
27
  "dependencies": {
28
- "cascade-extend": "^2.1.11",
28
+ "cascade-extend": "^2.1.12",
29
29
  "dotenv": "^16.4.5",
30
30
  "dotenv-expand": "^11.0.6",
31
31
  "globby": "^16.0.0"