mirror of https://github.com/buster-so/buster.git
revert env.mjs back
This commit is contained in:
parent
6ae9f6c3cc
commit
5157b4a44a
|
@ -52,8 +52,8 @@ jobs:
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: pnpm install --frozen-lockfile
|
run: pnpm install --frozen-lockfile
|
||||||
|
|
||||||
- name: Build all packages
|
- name: Build all packages (excluding web)
|
||||||
run: pnpm build
|
run: pnpm build --filter='!@buster-app/web'
|
||||||
env:
|
env:
|
||||||
NODE_ENV: production
|
NODE_ENV: production
|
||||||
|
|
||||||
|
|
|
@ -5,127 +5,101 @@ if (!isServer) {
|
||||||
throw new Error('env.mjs is only meant to be used on the server');
|
throw new Error('env.mjs is only meant to be used on the server');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize env variable that will be exported
|
const clientEnvSchema = z.object({
|
||||||
let env;
|
// Node environment
|
||||||
|
NODE_ENV: z
|
||||||
|
.enum(['development', 'production', 'test'], {
|
||||||
|
errorMap: () => ({ message: 'NODE_ENV must be development, production, or test' })
|
||||||
|
})
|
||||||
|
.default('development'),
|
||||||
|
|
||||||
// Skip validation during CI/CD builds or production builds
|
// API URLs
|
||||||
if (process.env.CI === 'true' || process.env.DOCKER_BUILD || process.env.NODE_ENV === 'production') {
|
NEXT_PUBLIC_API_URL: z
|
||||||
console.log('🐳 CI/Docker/Production build detected - skipping environment validation');
|
.string()
|
||||||
|
.min(1, { message: 'NEXT_PUBLIC_API_URL is required' })
|
||||||
|
.url({ message: 'NEXT_PUBLIC_API_URL must be a valid URL' }),
|
||||||
|
NEXT_PUBLIC_API2_URL: z
|
||||||
|
.string()
|
||||||
|
.min(1, { message: 'NEXT_PUBLIC_API2_URL is required' })
|
||||||
|
.url({ message: 'NEXT_PUBLIC_API2_URL must be a valid URL' }),
|
||||||
|
NEXT_PUBLIC_WEB_SOCKET_URL: z
|
||||||
|
.string()
|
||||||
|
.min(1, { message: 'NEXT_PUBLIC_WEB_SOCKET_URL is required' })
|
||||||
|
.url({ message: 'NEXT_PUBLIC_WEB_SOCKET_URL must be a valid URL' })
|
||||||
|
.optional(),
|
||||||
|
NEXT_PUBLIC_URL: z
|
||||||
|
.string()
|
||||||
|
.min(1, { message: 'NEXT_PUBLIC_URL is required' })
|
||||||
|
.url({ message: 'NEXT_PUBLIC_URL must be a valid URL' }),
|
||||||
|
|
||||||
// Set env object with default values for CI builds
|
// Supabase configuration
|
||||||
env = {
|
NEXT_PUBLIC_SUPABASE_URL: z
|
||||||
NODE_ENV: process.env.NODE_ENV || 'development',
|
.string()
|
||||||
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000',
|
.min(1, { message: 'NEXT_PUBLIC_SUPABASE_URL is required' })
|
||||||
NEXT_PUBLIC_API2_URL: process.env.NEXT_PUBLIC_API2_URL || 'http://localhost:3001',
|
.url({ message: 'NEXT_PUBLIC_SUPABASE_URL must be a valid URL' }),
|
||||||
NEXT_PUBLIC_WEB_SOCKET_URL: process.env.NEXT_PUBLIC_WEB_SOCKET_URL || 'ws://localhost:3000',
|
NEXT_PUBLIC_SUPABASE_ANON_KEY: z
|
||||||
NEXT_PUBLIC_URL: process.env.NEXT_PUBLIC_URL || 'http://localhost:3002',
|
.string()
|
||||||
NEXT_PUBLIC_SUPABASE_URL: process.env.NEXT_PUBLIC_SUPABASE_URL || 'http://localhost:54321',
|
.min(1, { message: 'NEXT_PUBLIC_SUPABASE_ANON_KEY is required' }),
|
||||||
NEXT_PUBLIC_SUPABASE_ANON_KEY: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || 'placeholder-anon-key',
|
|
||||||
NEXT_PUBLIC_POSTHOG_KEY: process.env.NEXT_PUBLIC_POSTHOG_KEY || '',
|
|
||||||
NEXT_PUBLIC_POSTHOG_HOST: process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://app.posthog.com',
|
|
||||||
POSTHOG_API_KEY: process.env.POSTHOG_API_KEY || '',
|
|
||||||
POSTHOG_ENV_ID: process.env.POSTHOG_ENV_ID || '',
|
|
||||||
NEXT_PUBLIC_USER: process.env.NEXT_PUBLIC_USER || '',
|
|
||||||
NEXT_PUBLIC_USER_PASSWORD: process.env.NEXT_PUBLIC_USER_PASSWORD || '',
|
|
||||||
NEXT_PUBLIC_ENABLE_TANSTACK_PANEL: process.env.NEXT_PUBLIC_ENABLE_TANSTACK_PANEL || ''
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
const clientEnvSchema = z.object({
|
|
||||||
// Node environment
|
|
||||||
NODE_ENV: z
|
|
||||||
.enum(['development', 'production', 'test'], {
|
|
||||||
errorMap: () => ({ message: 'NODE_ENV must be development, production, or test' })
|
|
||||||
})
|
|
||||||
.default('development'),
|
|
||||||
|
|
||||||
// API URLs
|
// PostHog analytics
|
||||||
NEXT_PUBLIC_API_URL: z
|
NEXT_PUBLIC_POSTHOG_KEY: z.string().optional(),
|
||||||
.string()
|
NEXT_PUBLIC_POSTHOG_HOST: z
|
||||||
.min(1, { message: 'NEXT_PUBLIC_API_URL is required' })
|
.string()
|
||||||
.url({ message: 'NEXT_PUBLIC_API_URL must be a valid URL' }),
|
.url({ message: 'NEXT_PUBLIC_POSTHOG_HOST must be a valid URL' })
|
||||||
NEXT_PUBLIC_API2_URL: z
|
.optional(),
|
||||||
.string()
|
POSTHOG_API_KEY: z.string().optional(),
|
||||||
.min(1, { message: 'NEXT_PUBLIC_API2_URL is required' })
|
POSTHOG_ENV_ID: z.string().optional(),
|
||||||
.url({ message: 'NEXT_PUBLIC_API2_URL must be a valid URL' }),
|
|
||||||
NEXT_PUBLIC_WEB_SOCKET_URL: z
|
|
||||||
.string()
|
|
||||||
.min(1, { message: 'NEXT_PUBLIC_WEB_SOCKET_URL is required' })
|
|
||||||
.url({ message: 'NEXT_PUBLIC_WEB_SOCKET_URL must be a valid URL' })
|
|
||||||
.optional(),
|
|
||||||
NEXT_PUBLIC_URL: z
|
|
||||||
.string()
|
|
||||||
.min(1, { message: 'NEXT_PUBLIC_URL is required' })
|
|
||||||
.url({ message: 'NEXT_PUBLIC_URL must be a valid URL' }),
|
|
||||||
|
|
||||||
// Supabase configuration
|
// Development/Testing credentials
|
||||||
NEXT_PUBLIC_SUPABASE_URL: z
|
NEXT_PUBLIC_USER: z.string().optional(),
|
||||||
.string()
|
NEXT_PUBLIC_USER_PASSWORD: z.string().optional(),
|
||||||
.min(1, { message: 'NEXT_PUBLIC_SUPABASE_URL is required' })
|
NEXT_PUBLIC_ENABLE_TANSTACK_PANEL: z.string().optional()
|
||||||
.url({ message: 'NEXT_PUBLIC_SUPABASE_URL must be a valid URL' }),
|
});
|
||||||
NEXT_PUBLIC_SUPABASE_ANON_KEY: z
|
|
||||||
.string()
|
|
||||||
.min(1, { message: 'NEXT_PUBLIC_SUPABASE_ANON_KEY is required' }),
|
|
||||||
|
|
||||||
// PostHog analytics
|
const serverEnvSchema = z.object({});
|
||||||
NEXT_PUBLIC_POSTHOG_KEY: z.string().optional(),
|
|
||||||
NEXT_PUBLIC_POSTHOG_HOST: z
|
|
||||||
.string()
|
|
||||||
.url({ message: 'NEXT_PUBLIC_POSTHOG_HOST must be a valid URL' })
|
|
||||||
.optional(),
|
|
||||||
POSTHOG_API_KEY: z.string().optional(),
|
|
||||||
POSTHOG_ENV_ID: z.string().optional(),
|
|
||||||
|
|
||||||
// Development/Testing credentials
|
// Parse and validate server-only environment variables
|
||||||
NEXT_PUBLIC_USER: z.string().optional(),
|
let serverEnv;
|
||||||
NEXT_PUBLIC_USER_PASSWORD: z.string().optional(),
|
let clientEnv;
|
||||||
NEXT_PUBLIC_ENABLE_TANSTACK_PANEL: z.string().optional()
|
|
||||||
});
|
|
||||||
|
|
||||||
const serverEnvSchema = z.object({});
|
try {
|
||||||
|
serverEnv = serverEnvSchema.parse(process.env);
|
||||||
|
console.log('Successfully parsed server environment variables');
|
||||||
|
clientEnv = clientEnvSchema.parse(process.env);
|
||||||
|
console.log('Successfully parsed client environment variables');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Server environment validation failed!');
|
||||||
|
console.error('');
|
||||||
|
|
||||||
// Parse and validate server-only environment variables
|
if (error instanceof z.ZodError) {
|
||||||
let serverEnv;
|
console.error('The following private environment variables are invalid or missing:');
|
||||||
let clientEnv;
|
|
||||||
|
|
||||||
try {
|
|
||||||
serverEnv = serverEnvSchema.parse(process.env);
|
|
||||||
console.log('Successfully parsed server environment variables');
|
|
||||||
clientEnv = clientEnvSchema.parse(process.env);
|
|
||||||
console.log('Successfully parsed client environment variables');
|
|
||||||
} catch (error) {
|
|
||||||
console.error('❌ Server environment validation failed!');
|
|
||||||
console.error('');
|
console.error('');
|
||||||
|
|
||||||
if (error instanceof z.ZodError) {
|
error.errors.forEach((err) => {
|
||||||
console.error('The following private environment variables are invalid or missing:');
|
const path = err.path.join('.');
|
||||||
console.error('');
|
console.error(` • ${path}: ${err.message}`);
|
||||||
|
});
|
||||||
error.errors.forEach((err) => {
|
|
||||||
const path = err.path.join('.');
|
|
||||||
console.error(` • ${path}: ${err.message}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
console.error('');
|
|
||||||
console.error(
|
|
||||||
'Please check your .env file and ensure all required private variables are set correctly.'
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.error('Unexpected error during server environment validation:', error);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.error('');
|
console.error('');
|
||||||
console.error('Build cannot continue with invalid server environment configuration.');
|
console.error(
|
||||||
|
'Please check your .env file and ensure all required private variables are set correctly.'
|
||||||
// Throw error to prevent build from continuing
|
);
|
||||||
process.exit(1);
|
} else {
|
||||||
|
console.error('Unexpected error during server environment validation:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Combine client and server environment variables
|
console.error('');
|
||||||
env = {
|
console.error('Build cannot continue with invalid server environment configuration.');
|
||||||
...clientEnv,
|
|
||||||
...serverEnv
|
// Throw error to prevent build from continuing
|
||||||
};
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Combine client and server environment variables
|
||||||
|
const env = {
|
||||||
|
...clientEnv,
|
||||||
|
...serverEnv
|
||||||
|
};
|
||||||
|
|
||||||
export { env };
|
export { env };
|
||||||
export default env;
|
export default env;
|
||||||
|
|
Loading…
Reference in New Issue