Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/change-env-names-to-short-format.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@baseplate-dev/fastify-generators': patch
'@baseplate-dev/react-generators': patch
---

Change environment names from long format to short abbreviations (development→dev, staging→stage, production→prod)
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ const [setupTask, configServiceProvider, configServiceConfigValuesProvider] =
APP_ENVIRONMENT: {
comment: 'Environment the app is running in',
validator: tsCodeFragment(
`z.enum(['development', 'test', 'staging', 'production'])`,
`z.enum(['dev', 'test', 'stage', 'prod'])`,
tsImportBuilder().named('z').from('zod'),
),
exampleValue: 'development',
exampleValue: 'dev',
},
}),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fp from 'fastify-plugin';
import { logError } from '../services/error-logger.js';
import { HttpError, NotFoundError } from '../utils/http-errors.js';

const IS_DEVELOPMENT = config.APP_ENVIRONMENT === 'development';
const IS_DEVELOPMENT = config.APP_ENVIRONMENT === 'dev';

/**
* Handles errors from Fastify route handlers, sending the correct code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { createYoga } from 'graphql-yoga';

TPL_SIDE_EFFECT_IMPORTS;

const IS_DEVELOPMENT = config.APP_ENVIRONMENT === 'development';
const IS_DEVELOPMENT = config.APP_ENVIRONMENT === 'dev';

const schema = TPL_SCHEMA;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ export const reactConfigGenerator = createGenerator({
reactConfig.configEntries.set('VITE_ENVIRONMENT', {
comment: 'Environment the app is running in',
validator: tsCodeFragment(
`z.enum(['development', 'test', 'staging', 'production'])`,
`z.enum(['dev', 'test', 'stage', 'prod'])`,
tsImportBuilder(['z']).from('zod'),
),
devDefaultValue: 'development',
devDefaultValue: 'dev',
});
},
),
Expand Down Expand Up @@ -134,6 +134,9 @@ export const reactConfigGenerator = createGenerator({
id: 'development-env',
destination: '.env.development',
contents: developmentEnvFile,
options: {
shouldNeverOverwrite: true,
},
});
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface SessionCookieValue {
const COOKIE_OPTIONS: CookieSerializeOptions = {
httpOnly: true,
sameSite: 'lax',
secure: config.APP_ENVIRONMENT !== 'development',
secure: config.APP_ENVIRONMENT !== 'dev',
maxAge: USER_SESSION_DURATION_SEC,
path: '/',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const COOKIE_NAME = 'user-session';

/**
* Retrieves the name of the session cookie based on the provided request.
* If the application environment is not 'development', the cookie name will be prefixed with '__Host-'.
* If the application environment is not 'dev', the cookie name will be prefixed with '__Host-'.
* In development, the cookie name will be suffixed with the port number.
*
* @param req - The FastifyRequest object representing the incoming request.
Expand All @@ -17,7 +17,7 @@ const COOKIE_NAME = 'user-session';
export function getUserSessionCookieName(
headers: FastifyRequest['headers'],
): string {
if (config.APP_ENVIRONMENT !== 'development') {
if (config.APP_ENVIRONMENT !== 'dev') {
return `__Host-${COOKIE_NAME}`;
}
// in development, localhost does not support the __Host prefix and should be scoped to port
Expand Down
2 changes: 1 addition & 1 deletion tests/simple/packages/backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
APP_ENVIRONMENT=development
APP_ENVIRONMENT=dev
DATABASE_URL=postgres://postgres:simple-backend-password@localhost:3432/postgres?schema=public
SENTRY_DSN=
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
APP_ENVIRONMENT=development
APP_ENVIRONMENT=dev
DATABASE_URL=postgres://postgres:simple-backend-password@localhost:3432/postgres?schema=public
SENTRY_DSN=
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { config } from '../services/config.js';
import { logError } from '../services/error-logger.js';
import { HttpError, NotFoundError } from '../utils/http-errors.js';

const IS_DEVELOPMENT = config.APP_ENVIRONMENT === 'development';
const IS_DEVELOPMENT = config.APP_ENVIRONMENT === 'dev';

/**
* Handles errors from Fastify route handlers, sending the correct code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useSentry } from './use-sentry.js';

import '@src/modules/index.js';

const IS_DEVELOPMENT = config.APP_ENVIRONMENT === 'development';
const IS_DEVELOPMENT = config.APP_ENVIRONMENT === 'dev';

const schema = builder.toSchema();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from 'zod';

const configSchema = z.object({
// Environment the app is running in
APP_ENVIRONMENT: z.enum(['development', 'test', 'staging', 'production']),
APP_ENVIRONMENT: z.enum(['dev', 'test', 'stage', 'prod']),
// Connection URL of the database
DATABASE_URL: z.string().min(1),
// Sentry DSN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ import { BadRequestError } from './http-errors.js';
*/
export const handleZodRequestValidationError = (error: unknown): never => {
if (error instanceof ZodError) {
throw new BadRequestError('Validation failed', 'ZOD_VALIDATION_ERROR', {
errors: error.errors,
const formattedErrors = error.errors.map((err) => ({
path: err.path.join('.'),
message: err.message,
code: err.code,
}));

throw new BadRequestError('Validation failed', 'VALIDATION_ERROR', {
errors: formattedErrors,
});
}

Expand Down
2 changes: 1 addition & 1 deletion tests/simple/packages/backend/src/plugins/error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { config } from '../services/config.js';
import { logError } from '../services/error-logger.js';
import { HttpError, NotFoundError } from '../utils/http-errors.js';

const IS_DEVELOPMENT = config.APP_ENVIRONMENT === 'development';
const IS_DEVELOPMENT = config.APP_ENVIRONMENT === 'dev';

/**
* Handles errors from Fastify route handlers, sending the correct code
Expand Down
2 changes: 1 addition & 1 deletion tests/simple/packages/backend/src/plugins/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useSentry } from './use-sentry.js';

import '@src/modules/index.js';

const IS_DEVELOPMENT = config.APP_ENVIRONMENT === 'development';
const IS_DEVELOPMENT = config.APP_ENVIRONMENT === 'dev';

const schema = builder.toSchema();

Expand Down
2 changes: 1 addition & 1 deletion tests/simple/packages/backend/src/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from 'zod';

const configSchema = z.object({
// Environment the app is running in
APP_ENVIRONMENT: z.enum(['development', 'test', 'staging', 'production']),
APP_ENVIRONMENT: z.enum(['dev', 'test', 'stage', 'prod']),
// Connection URL of the database
DATABASE_URL: z.string().min(1),
// Sentry DSN
Expand Down
10 changes: 8 additions & 2 deletions tests/simple/packages/backend/src/utils/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ import { BadRequestError } from './http-errors.js';
*/
export const handleZodRequestValidationError = (error: unknown): never => {
if (error instanceof ZodError) {
throw new BadRequestError('Validation failed', 'ZOD_VALIDATION_ERROR', {
errors: error.errors,
const formattedErrors = error.errors.map((err) => ({
path: err.path.join('.'),
message: err.message,
code: err.code,
}));

throw new BadRequestError('Validation failed', 'VALIDATION_ERROR', {
errors: formattedErrors,
});
}

Expand Down
2 changes: 1 addition & 1 deletion tests/simple/packages/web/.env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VITE_ENVIRONMENT=development
VITE_ENVIRONMENT=dev
VITE_GRAPH_API_ENDPOINT=/api/graphql
VITE_SENTRY_DSN=
DEV_BACKEND_HOST=http://localhost:3001
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VITE_ENVIRONMENT=development
VITE_ENVIRONMENT=dev
VITE_GRAPH_API_ENDPOINT=/api/graphql
VITE_SENTRY_DSN=
DEV_BACKEND_HOST=http://localhost:3001
2 changes: 1 addition & 1 deletion tests/simple/packages/web/baseplate/generated/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"react-day-picker": "9.7.0",
"react-dom": "19.1.0",
"react-error-boundary": "6.0.0",
"react-hook-form": "7.56.3",
"react-hook-form": "7.60.0",
"react-icons": "5.5.0",
"sonner": "2.0.3",
"zod": "3.24.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from 'zod';

const configSchema = z.object({
// Environment the app is running in
VITE_ENVIRONMENT: z.enum(['development', 'test', 'staging', 'production']),
VITE_ENVIRONMENT: z.enum(['dev', 'test', 'stage', 'prod']),
// URL for the GraphQL API endpoint
VITE_GRAPH_API_ENDPOINT: z.string().min(1),
// DSN for Sentry (optional)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logError } from './error-logger';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function getFormattedErrorSuffix(error: unknown): string {
function getFormattedErrorSuffix(_error: unknown): string {
return 'Please try again later.';
}

Expand Down
2 changes: 1 addition & 1 deletion tests/simple/packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"react-day-picker": "9.7.0",
"react-dom": "19.1.0",
"react-error-boundary": "6.0.0",
"react-hook-form": "7.56.3",
"react-hook-form": "7.60.0",
"react-icons": "5.5.0",
"sonner": "2.0.3",
"zod": "3.24.1",
Expand Down
2 changes: 1 addition & 1 deletion tests/simple/packages/web/src/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { z } from 'zod';

const configSchema = z.object({
// Environment the app is running in
VITE_ENVIRONMENT: z.enum(['development', 'test', 'staging', 'production']),
VITE_ENVIRONMENT: z.enum(['dev', 'test', 'stage', 'prod']),
// URL for the GraphQL API endpoint
VITE_GRAPH_API_ENDPOINT: z.string().min(1),
// DSN for Sentry (optional)
Expand Down
2 changes: 1 addition & 1 deletion tests/simple/packages/web/src/services/error-formatter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { logError } from './error-logger';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function getFormattedErrorSuffix(error: unknown): string {
function getFormattedErrorSuffix(_error: unknown): string {
return 'Please try again later.';
}

Expand Down
16 changes: 8 additions & 8 deletions tests/simple/pnpm-lock.yaml

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