fix(next-utils): use z.extend() for robust type inference in validateMintelEnv
Some checks failed
Monorepo Pipeline / 🧪 Quality Assurance (push) Successful in 2m33s
Monorepo Pipeline / 🐳 Build Directus (Base) (push) Successful in 33s
Monorepo Pipeline / 🐳 Build Build-Base (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Production Runtime (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Gatekeeper (Product) (push) Has been cancelled
Monorepo Pipeline / 🚀 Release (push) Has been cancelled
Some checks failed
Monorepo Pipeline / 🧪 Quality Assurance (push) Successful in 2m33s
Monorepo Pipeline / 🐳 Build Directus (Base) (push) Successful in 33s
Monorepo Pipeline / 🐳 Build Build-Base (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Production Runtime (push) Has been cancelled
Monorepo Pipeline / 🐳 Build Gatekeeper (Product) (push) Has been cancelled
Monorepo Pipeline / 🚀 Release (push) Has been cancelled
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mintel/next-utils",
|
"name": "@mintel/next-utils",
|
||||||
"version": "1.7.2",
|
"version": "1.7.3",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public",
|
"access": "public",
|
||||||
"registry": "https://npm.infra.mintel.me"
|
"registry": "https://npm.infra.mintel.me"
|
||||||
|
|||||||
@@ -50,16 +50,10 @@ export const mintelEnvSchema = {
|
|||||||
INTERNAL_DIRECTUS_URL: z.string().url().optional(),
|
INTERNAL_DIRECTUS_URL: z.string().url().optional(),
|
||||||
};
|
};
|
||||||
|
|
||||||
export type MintelEnv<T extends z.ZodRawShape = Record<string, never>> =
|
|
||||||
z.infer<z.ZodObject<typeof mintelEnvSchema & T>>;
|
|
||||||
|
|
||||||
export function validateMintelEnv<
|
export function validateMintelEnv<
|
||||||
T extends z.ZodRawShape = Record<string, never>,
|
T extends z.ZodRawShape = Record<string, never>,
|
||||||
>(schemaExtension: T = {} as T): MintelEnv<T> {
|
>(schemaExtension: T = {} as T) {
|
||||||
const fullSchema = z.object({
|
const fullSchema = z.object(mintelEnvSchema).extend(schemaExtension);
|
||||||
...mintelEnvSchema,
|
|
||||||
...schemaExtension,
|
|
||||||
});
|
|
||||||
|
|
||||||
const isBuildTime =
|
const isBuildTime =
|
||||||
process.env.NEXT_PHASE === "phase-production-build" ||
|
process.env.NEXT_PHASE === "phase-production-build" ||
|
||||||
@@ -73,7 +67,7 @@ export function validateMintelEnv<
|
|||||||
"⚠️ 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 the full schema type to unblock builds
|
// Return process.env casted to the full schema type to unblock builds
|
||||||
return process.env as unknown as MintelEnv<T>;
|
return process.env as unknown as z.infer<typeof fullSchema>;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.error(
|
console.error(
|
||||||
@@ -83,5 +77,5 @@ export function validateMintelEnv<
|
|||||||
throw new Error("Invalid environment variables");
|
throw new Error("Invalid environment variables");
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.data as MintelEnv<T>;
|
return result.data;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user