HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/quadcode.com/node_modules/@sveltejs/kit/src/core/sync/write_ambient.js
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { get_env } from '../../exports/vite/utils.js';
import { GENERATED_COMMENT } from '../../constants.js';
import { create_dynamic_types, create_static_types } from '../env.js';
import { write_if_changed } from './utils.js';

// TODO these types should be described in a neutral place, rather than
// inside either `packages/kit` or `kit.svelte.dev`
const descriptions_dir = fileURLToPath(new URL('../../../src/types/synthetic', import.meta.url));

/** @param {string} filename */
function read_description(filename) {
	const content = fs.readFileSync(`${descriptions_dir}/${filename}`, 'utf8');
	return `/**\n${content
		.trim()
		.split('\n')
		.map((line) => ` * ${line}`)
		.join('\n')}\n */`;
}

/**
 * @param {import('types').Env} env
 * @param {{
 * 	public_prefix: string;
 * 	private_prefix: string;
 * }} prefixes
 */
const template = (env, prefixes) => `
${GENERATED_COMMENT}

/// <reference types="@sveltejs/kit" />

${read_description('$env+static+private.md')}
${create_static_types('private', env)}

${read_description('$env+static+public.md')}
${create_static_types('public', env)}

${read_description('$env+dynamic+private.md')}
${create_dynamic_types('private', env, prefixes)}

${read_description('$env+dynamic+public.md')}
${create_dynamic_types('public', env, prefixes)}
`;

/**
 * Writes ambient declarations including types reference to @sveltejs/kit,
 * and the existing environment variables in process.env to
 * $env/static/private and $env/static/public
 * @param {import('types').ValidatedKitConfig} config
 * @param {string} mode The Vite mode
 */
export function write_ambient(config, mode) {
	const env = get_env(config.env, mode);
	const { publicPrefix: public_prefix, privatePrefix: private_prefix } = config.env;

	write_if_changed(
		path.join(config.outDir, 'ambient.d.ts'),
		template(env, { public_prefix, private_prefix })
	);
}