Skip to content

Commit

Permalink
Merge pull request #14 from SimeonC/main
Browse files Browse the repository at this point in the history
feat: add output for debugging CI
  • Loading branch information
Julien-R44 committed Nov 25, 2023
2 parents 3b9eeea + 8204a6d commit f48f8bc
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 72 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ export default defineConfig({
})
```

If you want to see what values are being evaluated for the build, for example when running in CI. You can pass the `debug` option as follows:
```ts
import { defineConfig } from "vite";
import { Schema, ValidateEnv } from "@julr/vite-plugin-validate-env";

export default defineConfig({
plugins: [
ValidateEnv({
debug: true,
schema: {
VITE_MY_VAR: Schema.string()
}
}),
],
})
```

### Built-in validator

```ts
Expand Down
2 changes: 2 additions & 0 deletions bin/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { assert } from '@japa/assert'
import { fileSystem } from '@japa/file-system'
import { configure, processCLIArgs, run } from '@japa/runner'

process.env.NODE_ENV = 'testing'

/*
|--------------------------------------------------------------------------
| Configure tests
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
}
},
"dependencies": {
"@poppinss/colors": "^4.1.1",
"@poppinss/cliui": "^6.2.1",
"@poppinss/validator-lite": "^1.0.3",
"unconfig": "^0.3.11"
},
Expand Down
42 changes: 22 additions & 20 deletions playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@ import { Schema, ValidateEnv } from '../src/index.js'
export default defineConfig({
root: __dirname,
plugins: [
// ValidateEnv({
// VITE_STRING: Schema.string(),
// VITE_NUMBER: Schema.number(),
// VITE_BOOLEAN: Schema.boolean(),
// }),
ValidateEnv({
validator: 'zod',
validator: 'builtin',
debug: true,
schema: {
VITE_STRING: z.string(),
VITE_NUMBER: z.preprocess((value) => Number(value), z.number()),
VITE_BOOLEAN: z.preprocess((value) => value === 'true' || value === '1', z.boolean()),

VITE_OBJECT: z.preprocess(
(value) => {
console.log(value)
return JSON.parse(value as string)
},
z.object({
a: z.string(),
b: z.number(),
}),
),
VITE_STRING: Schema.string(),
VITE_NUMBER: Schema.number(),
VITE_BOOLEAN: Schema.boolean(),
},
}),
// ValidateEnv({
// validator: 'zod',
// debug: true,
// schema: {
// VITE_STRING: z.string(),
// VITE_NUMBER: z.preprocess((value) => Number(value), z.number()),
// VITE_BOOLEAN: z.preprocess((value) => value === 'true' || value === '1', z.boolean()),

// VITE_OBJECT: z.preprocess(
// (value) => JSON.parse(value as string),
// z.object({
// a: z.string(),
// b: z.number(),
// }),
// ),
// },
// }),
],
})
39 changes: 3 additions & 36 deletions pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions src/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export type RecordViteKeys<T> = Record<`${string}_${string}`, T>
export type PluginOptions = Schema | FullPluginOptions

export type FullPluginOptions =
| { validator: 'builtin'; schema: PoppinsSchema }
| { validator: 'zod'; schema: ZodSchema }
| { validator: 'builtin'; schema: PoppinsSchema; debug?: boolean }
| { validator: 'zod'; schema: ZodSchema; debug?: boolean }

/**
* Contract for schema definition for poppins validator
Expand Down

0 comments on commit f48f8bc

Please sign in to comment.