ph-utils 0.9.6 → 0.9.8
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/lib/server.d.ts +2 -2
- package/lib/server.js +8 -6
- package/package.json +1 -1
package/lib/server.d.ts
CHANGED
@@ -22,9 +22,9 @@ export declare function exec(command: string, args?: string[], options?: SpawnOp
|
|
22
22
|
*
|
23
23
|
* ```js
|
24
24
|
* // test.js
|
25
|
-
*
|
25
|
+
* parseEnvs();
|
26
26
|
* ```
|
27
27
|
*
|
28
28
|
* @returns
|
29
29
|
*/
|
30
|
-
export declare function parseEnvs():
|
30
|
+
export declare function parseEnvs(): Record<string, string>;
|
package/lib/server.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { spawn } from "node:child_process";
|
2
2
|
import { parseEnv, parseArgs } from "node:util";
|
3
|
-
import {
|
3
|
+
import { readFileSync } from "node:fs";
|
4
4
|
/**
|
5
5
|
* 执行命令
|
6
6
|
* @param cmd 执行的命令
|
@@ -66,12 +66,12 @@ export function exec(command, ...params) {
|
|
66
66
|
*
|
67
67
|
* ```js
|
68
68
|
* // test.js
|
69
|
-
*
|
69
|
+
* parseEnvs();
|
70
70
|
* ```
|
71
71
|
*
|
72
72
|
* @returns
|
73
73
|
*/
|
74
|
-
export
|
74
|
+
export function parseEnvs() {
|
75
75
|
// development, test, production
|
76
76
|
const files = [".env", ".env.local"];
|
77
77
|
let nodeEnv = process.env.NODE_ENV;
|
@@ -82,8 +82,9 @@ export async function parseEnvs() {
|
|
82
82
|
short: "n",
|
83
83
|
},
|
84
84
|
},
|
85
|
+
strict: false,
|
85
86
|
});
|
86
|
-
if (values.NODE_ENV != null) {
|
87
|
+
if (values.NODE_ENV != null && typeof values.NODE_ENV === "string") {
|
87
88
|
nodeEnv = values.NODE_ENV;
|
88
89
|
}
|
89
90
|
else {
|
@@ -94,11 +95,12 @@ export async function parseEnvs() {
|
|
94
95
|
let envParsed = {};
|
95
96
|
for (let i = 0, len = files.length; i < len; i++) {
|
96
97
|
const file = files[i];
|
97
|
-
|
98
|
-
|
98
|
+
try {
|
99
|
+
const envContent = readFileSync(file, { encoding: "utf-8" });
|
99
100
|
const envValue = parseEnv(envContent);
|
100
101
|
envParsed = { ...envParsed, ...envValue };
|
101
102
|
}
|
103
|
+
catch (err) { }
|
102
104
|
}
|
103
105
|
for (const key in envParsed) {
|
104
106
|
process.env[key] = envParsed[key];
|