ph-utils 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
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
- * await parseEnvs();
25
+ * parseEnvs();
26
26
  * ```
27
27
  *
28
28
  * @returns
29
29
  */
30
- export declare function parseEnvs(): Promise<Record<string, string>>;
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 { read } from "./file.js";
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
- * await parseEnvs();
69
+ * parseEnvs();
70
70
  * ```
71
71
  *
72
72
  * @returns
73
73
  */
74
- export async function parseEnvs() {
74
+ export function parseEnvs() {
75
75
  // development, test, production
76
76
  const files = [".env", ".env.local"];
77
77
  let nodeEnv = process.env.NODE_ENV;
@@ -94,11 +94,12 @@ export async function parseEnvs() {
94
94
  let envParsed = {};
95
95
  for (let i = 0, len = files.length; i < len; i++) {
96
96
  const file = files[i];
97
- const envContent = await read(file, "");
98
- if (envContent !== "") {
97
+ try {
98
+ const envContent = readFileSync(file, { encoding: "utf-8" });
99
99
  const envValue = parseEnv(envContent);
100
100
  envParsed = { ...envParsed, ...envValue };
101
101
  }
102
+ catch (err) { }
102
103
  }
103
104
  for (const key in envParsed) {
104
105
  process.env[key] = envParsed[key];
package/package.json CHANGED
@@ -68,7 +68,7 @@
68
68
  },
69
69
  "./*": "./lib/*"
70
70
  },
71
- "version": "0.9.6",
71
+ "version": "0.9.7",
72
72
  "type": "module",
73
73
  "repository": {
74
74
  "type": "git",