@shophost/rest-api 2.0.22 → 2.0.24

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shophost/rest-api",
3
- "version": "2.0.22",
3
+ "version": "2.0.24",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "shophost-rest-api": "./scripts/shophost-rest-api.mjs"
package/prisma.config.ts CHANGED
@@ -2,7 +2,15 @@ import "dotenv/config";
2
2
  import { defineConfig } from "prisma/config";
3
3
 
4
4
  function firstDefined(...names: string[]) {
5
- return names.find((name) => process.env[name])?.trim();
5
+ for (const name of names) {
6
+ const value = process.env[name]?.trim();
7
+
8
+ if (value) {
9
+ return value;
10
+ }
11
+ }
12
+
13
+ return undefined;
6
14
  }
7
15
 
8
16
  export default defineConfig({
@@ -59,6 +59,34 @@ function getDbPushArgs(argv) {
59
59
  return argv.slice(2);
60
60
  }
61
61
 
62
+ function expandEnvValue(value, env) {
63
+ return value.replace(
64
+ /\\?\$(?:\{([A-Za-z_][A-Za-z0-9_]*)\}|([A-Za-z_][A-Za-z0-9_]*))/g,
65
+ (match, bracedName, plainName) => {
66
+ if (match.startsWith("\\")) {
67
+ return match.slice(1);
68
+ }
69
+
70
+ const variableName = bracedName ?? plainName;
71
+ return env[variableName] ?? "";
72
+ }
73
+ );
74
+ }
75
+
76
+ function applyParsedEnv(parsed, shouldOverride) {
77
+ if (!parsed) {
78
+ return;
79
+ }
80
+
81
+ for (const [key, rawValue] of Object.entries(parsed)) {
82
+ if (!shouldOverride && process.env[key] !== undefined) {
83
+ continue;
84
+ }
85
+
86
+ process.env[key] = expandEnvValue(rawValue, process.env);
87
+ }
88
+ }
89
+
62
90
  function loadEnvFiles() {
63
91
  for (const envFile of [".env", ".env.local"]) {
64
92
  const envPath = join(process.cwd(), envFile);
@@ -67,10 +95,12 @@ function loadEnvFiles() {
67
95
  continue;
68
96
  }
69
97
 
70
- dotenv.config({
98
+ const result = dotenv.config({
71
99
  path: envPath,
72
100
  override: envFile === ".env.local",
73
101
  });
102
+
103
+ applyParsedEnv(result.parsed, envFile === ".env.local");
74
104
  }
75
105
  }
76
106