| ; | |
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | |
| if (k2 === undefined) k2 = k; | |
| var desc = Object.getOwnPropertyDescriptor(m, k); | |
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | |
| desc = { enumerable: true, get: function() { return m[k]; } }; | |
| } | |
| Object.defineProperty(o, k2, desc); | |
| }) : (function(o, m, k, k2) { | |
| if (k2 === undefined) k2 = k; | |
| o[k2] = m[k]; | |
| })); | |
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | |
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | |
| }) : function(o, v) { | |
| o["default"] = v; | |
| }); | |
| var __importStar = (this && this.__importStar) || (function () { | |
| var ownKeys = function(o) { | |
| ownKeys = Object.getOwnPropertyNames || function (o) { | |
| var ar = []; | |
| for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | |
| return ar; | |
| }; | |
| return ownKeys(o); | |
| }; | |
| return function (mod) { | |
| if (mod && mod.__esModule) return mod; | |
| var result = {}; | |
| if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | |
| __setModuleDefault(result, mod); | |
| return result; | |
| }; | |
| })(); | |
| var __importDefault = (this && this.__importDefault) || function (mod) { | |
| return (mod && mod.__esModule) ? mod : { "default": mod }; | |
| }; | |
| Object.defineProperty(exports, "__esModule", { value: true }); | |
| exports.getEnvironmentVariables = void 0; | |
| const node_fs_1 = __importStar(require("node:fs")); | |
| const node_path_1 = __importDefault(require("node:path")); | |
| const renderer_1 = require("@remotion/renderer"); | |
| const client_1 = require("@remotion/renderer/client"); | |
| const studio_server_1 = require("@remotion/studio-server"); | |
| const dotenv_1 = __importDefault(require("dotenv")); | |
| const chalk_1 = require("./chalk"); | |
| const make_link_1 = require("./hyperlinks/make-link"); | |
| const log_1 = require("./log"); | |
| const parsed_cli_1 = require("./parsed-cli"); | |
| const { envFileOption } = client_1.BrowserSafeApis.options; | |
| function getProcessEnv() { | |
| const env = {}; | |
| const validKeys = Object.keys(process.env).filter((key) => key.startsWith('REMOTION_')); | |
| for (const key of validKeys) { | |
| env[key] = process.env[key]; | |
| } | |
| return env; | |
| } | |
| const watchEnvFile = ({ processEnv, envFile, onUpdate, logLevel, }) => { | |
| const { unwatch } = studio_server_1.StudioServerInternals.installFileWatcher({ | |
| file: envFile, | |
| existenceOnly: false, | |
| onChange: async (event) => { | |
| try { | |
| if (event.type === 'deleted') { | |
| log_1.Log.warn({ indent: false, logLevel }, `${envFile} was deleted.`); | |
| } | |
| else { | |
| onUpdate({ | |
| ...processEnv, | |
| ...dotenv_1.default.parse(event.content), | |
| }); | |
| log_1.Log.info({ indent: false, logLevel }, chalk_1.chalk.blueBright(event.type === 'created' | |
| ? `Created env file ${envFile}` | |
| : `Updated env file ${envFile}`)); | |
| } | |
| } | |
| catch (err) { | |
| log_1.Log.error({ indent: false, logLevel }, `${envFile} update failed with error ${err.stack}`); | |
| } | |
| }, | |
| }); | |
| return unwatch; | |
| }; | |
| const getEnvForEnvFile = ({ processEnv, envFile, onUpdate, logLevel, indent, }) => { | |
| try { | |
| const envFileData = (0, node_fs_1.readFileSync)(envFile); | |
| if (onUpdate) { | |
| if (typeof node_fs_1.default.watchFile === 'undefined') { | |
| log_1.Log.warn({ indent: false, logLevel }, 'Unsupported feature (fs.watchFile): .env file will not hot reload.'); | |
| } | |
| else { | |
| watchEnvFile({ processEnv, envFile, onUpdate, logLevel }); | |
| } | |
| } | |
| const relativeEnvFile = node_path_1.default.relative(process.cwd(), envFile); | |
| log_1.Log.verbose({ indent, logLevel }, `Loaded env file from ${(0, make_link_1.makeHyperlink)({ fallback: envFile, text: relativeEnvFile, url: 'file://' + envFile })}.`); | |
| return { | |
| ...processEnv, | |
| ...dotenv_1.default.parse(envFileData), | |
| }; | |
| } | |
| catch (err) { | |
| log_1.Log.error({ indent: false, logLevel }, `Your .env file at ${envFile} could not not be parsed.`); | |
| log_1.Log.error({ indent: false, logLevel }, err); | |
| process.exit(1); | |
| } | |
| }; | |
| const findDotEnvFile = (remotionRoot) => { | |
| const defaultEnvFile = node_path_1.default.resolve(remotionRoot, '.env'); | |
| const paths = [defaultEnvFile, node_path_1.default.resolve(remotionRoot, '.env.local')]; | |
| for (const p of paths) { | |
| if (node_fs_1.default.existsSync(p)) { | |
| return { found: p, defaultEnvFile }; | |
| } | |
| } | |
| return { found: null, defaultEnvFile }; | |
| }; | |
| const getEnvironmentVariables = (onUpdate, logLevel, indent) => { | |
| const processEnv = getProcessEnv(); | |
| const { value: envFileValue, source: envFileSource } = envFileOption.getValue({ | |
| commandLine: parsed_cli_1.parsedCli, | |
| }); | |
| const remotionRoot = renderer_1.RenderInternals.findRemotionRoot(); | |
| if (envFileValue && envFileSource !== 'default') { | |
| const baseDir = envFileSource === 'cli' ? process.cwd() : remotionRoot; | |
| const envFile = node_path_1.default.resolve(baseDir, envFileValue); | |
| if (!node_fs_1.default.existsSync(envFile)) { | |
| log_1.Log.error({ indent: false, logLevel }, envFileSource === 'cli' | |
| ? 'You passed a --env-file but it could not be found.' | |
| : 'You specified a custom .env file using `Config.setDotEnvLocation()` in the config file but it could not be found'); | |
| log_1.Log.error({ indent: false, logLevel }, 'We looked for the file at:', envFile); | |
| log_1.Log.error({ indent: false, logLevel }, 'Check that your path is correct and try again.'); | |
| process.exit(1); | |
| } | |
| return getEnvForEnvFile({ processEnv, envFile, onUpdate, logLevel, indent }); | |
| } | |
| const { defaultEnvFile, found } = findDotEnvFile(remotionRoot); | |
| if (!found) { | |
| if (onUpdate) { | |
| if (typeof node_fs_1.default.watchFile === 'undefined') { | |
| log_1.Log.warn({ indent: false, logLevel }, 'Unsupported Bun feature: .env file will not hot reload.'); | |
| } | |
| else { | |
| watchEnvFile({ | |
| processEnv, | |
| envFile: defaultEnvFile, | |
| onUpdate, | |
| logLevel, | |
| }); | |
| } | |
| } | |
| return processEnv; | |
| } | |
| return getEnvForEnvFile({ | |
| processEnv, | |
| envFile: found, | |
| onUpdate, | |
| logLevel, | |
| indent, | |
| }); | |
| }; | |
| exports.getEnvironmentVariables = getEnvironmentVariables; | |
Xet Storage Details
- Size:
- 6.97 kB
- Xet hash:
- d42dfacfac0c0c5a488ed06399422cc2e3625f5899d87908098ba37c53da19c0
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.