fix(next-utils): restore optional argument with robust types to satisfy linter
Some checks failed
Monorepo Pipeline / 🚀 Release (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Directus (Base) (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Gatekeeper (Product) (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Build-Base (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Production Runtime (push) Has been cancelled
Monorepo Pipeline / 🧪 Quality Assurance (push) Has been cancelled
Some checks failed
Monorepo Pipeline / 🚀 Release (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Directus (Base) (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Gatekeeper (Product) (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Build-Base (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Production Runtime (push) Has been cancelled
Monorepo Pipeline / 🧪 Quality Assurance (push) Has been cancelled
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mintel/next-utils",
|
"name": "@mintel/next-utils",
|
||||||
"version": "1.7.1",
|
"version": "1.7.2",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public",
|
"access": "public",
|
||||||
"registry": "https://npm.infra.mintel.me"
|
"registry": "https://npm.infra.mintel.me"
|
||||||
|
|||||||
@@ -50,7 +50,12 @@ export const mintelEnvSchema = {
|
|||||||
INTERNAL_DIRECTUS_URL: z.string().url().optional(),
|
INTERNAL_DIRECTUS_URL: z.string().url().optional(),
|
||||||
};
|
};
|
||||||
|
|
||||||
export function validateMintelEnv<T extends z.ZodRawShape>(schemaExtension: T) {
|
export type MintelEnv<T extends z.ZodRawShape = Record<string, never>> =
|
||||||
|
z.infer<z.ZodObject<typeof mintelEnvSchema & T>>;
|
||||||
|
|
||||||
|
export function validateMintelEnv<
|
||||||
|
T extends z.ZodRawShape = Record<string, never>,
|
||||||
|
>(schemaExtension: T = {} as T): MintelEnv<T> {
|
||||||
const fullSchema = z.object({
|
const fullSchema = z.object({
|
||||||
...mintelEnvSchema,
|
...mintelEnvSchema,
|
||||||
...schemaExtension,
|
...schemaExtension,
|
||||||
@@ -67,8 +72,8 @@ export function validateMintelEnv<T extends z.ZodRawShape>(schemaExtension: T) {
|
|||||||
console.warn(
|
console.warn(
|
||||||
"⚠️ Some environment variables are missing during build, but skipping strict validation.",
|
"⚠️ Some environment variables are missing during build, but skipping strict validation.",
|
||||||
);
|
);
|
||||||
// Return process.env casted to ensure types match, even if data is missing during build
|
// Return process.env casted to the full schema type to unblock builds
|
||||||
return process.env as unknown as z.infer<typeof fullSchema>;
|
return process.env as unknown as MintelEnv<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.error(
|
console.error(
|
||||||
@@ -78,5 +83,5 @@ export function validateMintelEnv<T extends z.ZodRawShape>(schemaExtension: T) {
|
|||||||
throw new Error("Invalid environment variables");
|
throw new Error("Invalid environment variables");
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.data;
|
return result.data as MintelEnv<T>;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user