Skip to content

Commit

Permalink
feat: type check template
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-lefebvre committed Jul 17, 2024
1 parent a0eca34 commit 7ca185e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/astro/dev-only.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// IMPORTANT: do not publish this file! It's only intended for development within the monorepo

declare module 'virtual:astro:env/internal' {
export const schema: import('./src/env/schema.js').EnvSchema;
}
13 changes: 7 additions & 6 deletions packages/astro/templates/env/module.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// @ts-check
import { schema } from 'virtual:astro:env/internal';
import {
createInvalidVariableError,
createInvalidVariablesError,
getEnv,
setOnSetGetEnv,
validateEnvVariables,
getEnvFieldType
validateEnvVariable,
getEnvFieldType,
} from 'astro/env/runtime';

export const getSecret = (key) => {
Expand All @@ -16,12 +17,12 @@ const _internalGetSecret = (key) => {
const variable = rawVariable === '' ? undefined : rawVariable;
const options = schema[key];

const result = validateEnvVariables(variable, options);
const result = validateEnvVariable(variable, options);
if (result.ok) {
return result.value;
}
const type = getEnvFieldType(options)
throw createInvalidVariableError(key, type, result);
const type = getEnvFieldType(options);
throw createInvalidVariablesError(key, type, result);
};

setOnSetGetEnv((reset) => {
Expand Down

0 comments on commit 7ca185e

Please sign in to comment.