Julien-R44 / vite-plugin-validate-env

✅ Vite plugin for validating your environment variables
MIT License
164 stars 6 forks source link

Validation for optionals is broken. #10

Closed JarvisH closed 1 year ago

JarvisH commented 1 year ago

When an optional string schema is processed, the builtInValidationMethod exits early via return.

The loop should not exit early but continue via continue.

This bug currently breaks all validation of schemas with an optional value.

function builtinValidation(env, schema) {
  const errors = [];
  for (const [key, validator] of Object.entries(schema)) {
    try {
      const res = validator(key, env[key]);
      if (typeof res === "undefined") {
        delete process.env[key];
        return; //  should be continue;
      }
      process.env[key] = res;
    } catch (err) {
      errors.push({ key, err });
    }
  }
  if (errors.length) {
    throw new Error(errorReporter$1(errors));
  }
}
Julien-R44 commented 1 year ago

Ooops,was introduced with #9 . I didn't catch this

Julien-R44 commented 1 year ago

Released fix with 0.2.4. Thanks for the issue !