0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-03 22:29:08 -05:00

feat: address reviews

This commit is contained in:
Florian Lefebvre 2024-08-15 14:17:53 +02:00
parent 24e9150078
commit e181f3fa6a
3 changed files with 14 additions and 17 deletions

View file

@ -10,12 +10,12 @@ To upgrade, update your Astro config:
import { defineConfig, envField } from 'astro/config' import { defineConfig, envField } from 'astro/config'
export default defineConfig({ export default defineConfig({
- experimental: { - experimental: {
env: { env: {
schema: { schema: {
FOO: envField.string({ /* ... */ }) FOO: envField.string({ /* ... */ })
} }
} }
- } - }
}) })
``` ```

View file

@ -3,32 +3,29 @@ import { ENV_TYPES_FILE } from './constants.js';
import { getEnvFieldType } from './validators.js'; import { getEnvFieldType } from './validators.js';
export function syncAstroEnv(settings: AstroSettings): void { export function syncAstroEnv(settings: AstroSettings): void {
let client: string | null = null; let client = '';
let server: string | null = null; let server = '';
for (const [key, options] of Object.entries(settings.config.env.schema)) { for (const [key, options] of Object.entries(settings.config.env.schema)) {
const str = ` export const ${key}: ${getEnvFieldType(options)}; \n`; const str = ` export const ${key}: ${getEnvFieldType(options)}; \n`;
if (options.context === 'client') { if (options.context === 'client') {
client ??= '';
client += str; client += str;
} else { } else {
server ??= '';
server += str; server += str;
} }
} }
let content: string | null = null; let content = '';
if (client !== null) { if (client !== '') {
content = `declare module 'astro:env/client' { content = `declare module 'astro:env/client' {
${client}}`; ${client}}`;
} }
if (server !== null) { if (server !== '') {
content ??= '';
content += `declare module 'astro:env/server' { content += `declare module 'astro:env/server' {
${server}}`; ${server}}`;
} }
if (content) { if (content !== '') {
settings.injectedTypes.push({ settings.injectedTypes.push({
filename: ENV_TYPES_FILE, filename: ENV_TYPES_FILE,
content, content,

View file

@ -9,8 +9,8 @@ import {
ASTRO_PATH_PARAM, ASTRO_PATH_PARAM,
} from './adapter.js'; } from './adapter.js';
setGetEnv((key) => process.env[key]);
applyPolyfills(); applyPolyfills();
setGetEnv((key) => process.env[key]);
export const createExports = ( export const createExports = (
manifest: SSRManifest, manifest: SSRManifest,