@cabloy/dotenv 1.1.12 → 1.2.1
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/LICENSE +0 -0
- package/README.md +0 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +16 -14
- package/package.json +21 -18
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
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,
|
|
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,
|
|
4
|
+
export declare function getEnvFiles(meta: object, dir: string, prefix: string, postfixes?: string | string[]): string[] | undefined;
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
1
|
import { cascadeExtendKeys } from 'cascade-extend';
|
|
3
2
|
import dotenv from 'dotenv';
|
|
4
3
|
import dotenvExpand from 'dotenv-expand';
|
|
5
4
|
import { globbySync } from 'globby';
|
|
5
|
+
import path from 'node:path';
|
|
6
6
|
|
|
7
|
-
function loadEnvs(meta, dir, prefix = '.env',
|
|
7
|
+
function loadEnvs(meta, dir, prefix = '.env', postfixes) {
|
|
8
8
|
// envfiles
|
|
9
|
-
const envFiles = getEnvFiles(meta, dir, prefix,
|
|
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,
|
|
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
|
|
44
|
-
|
|
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 (
|
|
57
|
-
file = `${file}${
|
|
58
|
+
if (source[key]) {
|
|
59
|
+
file = `${file}${source[key]}`;
|
|
58
60
|
}
|
|
59
61
|
return file;
|
|
60
62
|
});
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cabloy/dotenv",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"version": "1.2.1",
|
|
4
|
+
"gitHead": "991189da4443b789fcf77872990b901ccf43bccb",
|
|
5
5
|
"description": "cabloy dotenv",
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"access": "public"
|
|
8
|
-
},
|
|
9
|
-
"author": "zhennann",
|
|
10
6
|
"keywords": [
|
|
11
|
-
"
|
|
12
|
-
"
|
|
7
|
+
"cabloy",
|
|
8
|
+
"framework"
|
|
13
9
|
],
|
|
10
|
+
"author": "zhennann",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
14
15
|
"exports": {
|
|
15
16
|
".": {
|
|
16
17
|
"types": [
|
|
@@ -21,18 +22,20 @@
|
|
|
21
22
|
},
|
|
22
23
|
"./package.json": "./package.json"
|
|
23
24
|
},
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"clean": "rimraf dist tsconfig.build.tsbuildinfo",
|
|
30
|
+
"tsc:publish": "npm run clean && vona :bin:buildGeneral && tsc -p tsconfig.build.json",
|
|
31
|
+
"prepublishOnly": "npm run tsc:publish",
|
|
32
|
+
"prepack": "clean-package",
|
|
33
|
+
"postpack": "clean-package restore"
|
|
34
|
+
},
|
|
27
35
|
"dependencies": {
|
|
28
|
-
"cascade-extend": "^2.1
|
|
36
|
+
"cascade-extend": "^2.2.1",
|
|
29
37
|
"dotenv": "^16.4.5",
|
|
30
38
|
"dotenv-expand": "^11.0.6",
|
|
31
39
|
"globby": "^16.0.0"
|
|
32
|
-
},
|
|
33
|
-
"gitHead": "0eab9dc4a5622caffe89e7b1b3f02c08ccbc4c4b",
|
|
34
|
-
"scripts": {
|
|
35
|
-
"clean": "rimraf dist tsconfig.build.tsbuildinfo",
|
|
36
|
-
"tsc:publish": "npm run clean && vona :bin:buildGeneral && tsc -p tsconfig.build.json"
|
|
37
40
|
}
|
|
38
|
-
}
|
|
41
|
+
}
|