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:
parent
24e9150078
commit
e181f3fa6a
3 changed files with 14 additions and 17 deletions
|
@ -10,12 +10,12 @@ To upgrade, update your Astro config:
|
|||
import { defineConfig, envField } from 'astro/config'
|
||||
|
||||
export default defineConfig({
|
||||
- experimental: {
|
||||
env: {
|
||||
schema: {
|
||||
FOO: envField.string({ /* ... */ })
|
||||
}
|
||||
}
|
||||
- }
|
||||
- experimental: {
|
||||
env: {
|
||||
schema: {
|
||||
FOO: envField.string({ /* ... */ })
|
||||
}
|
||||
}
|
||||
- }
|
||||
})
|
||||
```
|
15
packages/astro/src/env/sync.ts
vendored
15
packages/astro/src/env/sync.ts
vendored
|
@ -3,32 +3,29 @@ import { ENV_TYPES_FILE } from './constants.js';
|
|||
import { getEnvFieldType } from './validators.js';
|
||||
|
||||
export function syncAstroEnv(settings: AstroSettings): void {
|
||||
let client: string | null = null;
|
||||
let server: string | null = null;
|
||||
let client = '';
|
||||
let server = '';
|
||||
|
||||
for (const [key, options] of Object.entries(settings.config.env.schema)) {
|
||||
const str = ` export const ${key}: ${getEnvFieldType(options)}; \n`;
|
||||
if (options.context === 'client') {
|
||||
client ??= '';
|
||||
client += str;
|
||||
} else {
|
||||
server ??= '';
|
||||
server += str;
|
||||
}
|
||||
}
|
||||
|
||||
let content: string | null = null;
|
||||
if (client !== null) {
|
||||
let content = '';
|
||||
if (client !== '') {
|
||||
content = `declare module 'astro:env/client' {
|
||||
${client}}`;
|
||||
}
|
||||
if (server !== null) {
|
||||
content ??= '';
|
||||
if (server !== '') {
|
||||
content += `declare module 'astro:env/server' {
|
||||
${server}}`;
|
||||
}
|
||||
|
||||
if (content) {
|
||||
if (content !== '') {
|
||||
settings.injectedTypes.push({
|
||||
filename: ENV_TYPES_FILE,
|
||||
content,
|
||||
|
|
|
@ -9,8 +9,8 @@ import {
|
|||
ASTRO_PATH_PARAM,
|
||||
} from './adapter.js';
|
||||
|
||||
setGetEnv((key) => process.env[key]);
|
||||
applyPolyfills();
|
||||
setGetEnv((key) => process.env[key]);
|
||||
|
||||
export const createExports = (
|
||||
manifest: SSRManifest,
|
||||
|
|
Loading…
Add table
Reference in a new issue