ph-utils 0.9.5 → 0.9.7

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 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
@@ -18,6 +18,10 @@
18
18
  "types": "./lib/date.d.ts",
19
19
  "import": "./lib/date.js"
20
20
  },
21
+ "./server": {
22
+ "types": "./lib/server.d.ts",
23
+ "import": "./lib/server.js"
24
+ },
21
25
  "./validator": {
22
26
  "types": "./lib/validator.d.ts",
23
27
  "import": "./lib/validator.js"
@@ -64,7 +68,7 @@
64
68
  },
65
69
  "./*": "./lib/*"
66
70
  },
67
- "version": "0.9.5",
71
+ "version": "0.9.7",
68
72
  "type": "module",
69
73
  "repository": {
70
74
  "type": "git",