Skip to content

Commit

Permalink
remove dependency on kleur
Browse files Browse the repository at this point in the history
  • Loading branch information
idleberg committed Dec 8, 2024
1 parent cb7ddc1 commit af8c162
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"test": "uvu tests --require tsm --ignore \"fixtures\" --ignore \"helper.ts\""
},
"dependencies": {
"kleur": "^4.1.5",
"log-symbols": "^7.0.0"
},
"devDependencies": {
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { bgRed } from 'kleur/colors';
import logSymbols from 'log-symbols';
import { resolve } from 'node:path';
import { cwd, exit } from 'node:process';
import { safeParse, type InferIssue, type ObjectSchema } from 'valibot';
import { loadEnv, normalizePath, type Plugin } from 'vite';

// TYPES

type PluginOptions = {
/**
* Setting this to `true` will include unprefixed environment variables in the validation. This is useful
Expand Down Expand Up @@ -40,6 +41,8 @@ type PluginOptions = {
throwError?: boolean;
};

// EXPORT

/**
* Exports a Vite plugin that validates environment variables against a schema.
* @param schema
Expand Down Expand Up @@ -123,6 +126,20 @@ export default function ValibotEnvPlugin<T extends ObjectSchema<any, any> = Obje
};
}

// HELPERS

const open = '\u001B[41m';
const close = `\u001B[49m`;

/**
* Wrap string in ANSI escape sequences for red background colour.
* @param input
* @returns
*/
export function bgRed(input: string): string {
return `${open}${input}${close}`;
}

/**
* Logger for printing well-formed schema issues.
* @param issue
Expand Down

0 comments on commit af8c162

Please sign in to comment.