Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

astro-env

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

astro-env

Validate and type your environment variables automatically using zod

  • 0.0.3
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

astro-env

This is an Astro integration that allows you to validate and type your environement variables automatically using zod.

Usage

Installation

Install the integration automatically using the Astro CLI:

pnpm astro add astro-env
npm astro add astro-env
yarn astro add astro-env

Or install it manually:

  1. Install the required dependencies
pnpm add astro-env
npm install astro-env
yarn add astro-env
  1. Add the integration to your astro config
+import astroEnv from "astro-env";

export default defineConfig({
  integrations: [
+    astroEnv({ ... }),
  ],
});

Configuration

Here is the TypeScript type:

export type Options = {
    schema: AnyZodObject;
    generateTypes?: boolean;
    generateEnvTemplate?: boolean;
}
schema

Zod schema used to validate your environment variables. You can import zod from astro/zod:

import astroEnv from "astro-env";
import { defineConfig } from "astro/config";
import { z } from "astro/zod";

// https://astro.build/config
export default defineConfig({
	integrations: [
		astroEnv({
			schema: z.object({
				ABC: z.string(),
			}),
		}),
	],
});

When using generateTypes, make sure that the schema doesn't contain any transform and that all values are strings (they can be z.string().url() for example).

Interested in supporting more data types? Open an issue!

generateTypes

If set to true, generates .astro/astro-env.d.ts with types based on the schema and updates src/env.d.ts. Defaults to true.

generateEnvTemplate

If set to true, generates a .env.template with keys based on the schema. Defaults to false

Contributing

This package is structured as a monorepo:

  • playground contains code for testing the package
  • package contains the actual package

Install dependencies using pnpm:

pnpm i --frozen-lockfile

Start the playground:

pnpm playground:dev

You can now edit files in package. Please note that making changes to those files may require restarting the playground dev server.

Licensing

MIT Licensed. Made with ❤️ by Florian Lefebvre.

Keywords

FAQs

Package last updated on 22 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc