File size: 1,501 Bytes
f0c5c01 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | /**
* Custom environment loader that prioritizes system environment variables
* over .env file values. This ensures that Manus platform-injected variables
* are not overridden by placeholder values in .env
*/
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const envPath = path.resolve(process.cwd(), ".env");
if (fs.existsSync(envPath)) {
const envContent = fs.readFileSync(envPath, "utf8");
const lines = envContent.split("\n");
lines.forEach((line) => {
// Skip comments and empty lines
if (!line || line.trim().startsWith("#")) return;
const match = line.match(/^([^=]+)=(.*)$/);
if (match) {
const key = match[1].trim();
const value = match[2].trim().replace(/^["']|["']$/g, ""); // Remove quotes
// Only set if not already defined in environment
if (!process.env[key]) {
process.env[key] = value;
}
}
});
}
// Map system variables to Expo public variables
const mappings = {
VITE_APP_ID: "EXPO_PUBLIC_APP_ID",
VITE_OAUTH_PORTAL_URL: "EXPO_PUBLIC_OAUTH_PORTAL_URL",
OAUTH_SERVER_URL: "EXPO_PUBLIC_OAUTH_SERVER_URL",
OWNER_OPEN_ID: "EXPO_PUBLIC_OWNER_OPEN_ID",
OWNER_NAME: "EXPO_PUBLIC_OWNER_NAME",
};
for (const [systemVar, expoVar] of Object.entries(mappings)) {
if (process.env[systemVar] && !process.env[expoVar]) {
process.env[expoVar] = process.env[systemVar];
}
}
|