Lingui working with NODE ENV=production again (#10067)

Lingui now offers an option to disable stripping even in prod mode so we
can bring it back
This commit is contained in:
Félix Malfait
2025-02-07 10:05:07 +01:00
committed by GitHub
parent 12cec01d80
commit 8df59c085d
21 changed files with 56 additions and 45 deletions

View File

@ -206,7 +206,7 @@
"@graphql-codegen/typescript-operations": "^3.0.4",
"@graphql-codegen/typescript-react-apollo": "^3.3.7",
"@lingui/cli": "^5.1.2",
"@lingui/swc-plugin": "^5.0.2",
"@lingui/swc-plugin": "^5.1.0",
"@lingui/vite-plugin": "^5.1.2",
"@microsoft/microsoft-graph-types": "^2.40.0",
"@nestjs/cli": "^9.0.0",

View File

@ -41,10 +41,6 @@ resource "kubernetes_deployment" "twentycrm_server" {
name = "PORT"
value = "3000"
}
# env {
# name = "DEBUG_MODE"
# value = false
# }
env {
name = "SERVER_URL"

View File

@ -1,19 +1,16 @@
# Use this for local setup
NODE_ENV=development
PG_DATABASE_URL=postgres://postgres:postgres@localhost:5432/default
REDIS_URL=redis://localhost:6379
APP_SECRET=replace_me_with_a_random_string
SIGN_IN_PREFILLED=true
ACCESS_TOKEN_SECRET=replace_me_with_a_random_string_access
FRONT_PROTOCOL=http
FRONT_DOMAIN=localhost
FRONT_PORT=3001
# ———————— Optional ————————
# PORT=3000
# DEBUG_MODE=true
# ACCESS_TOKEN_EXPIRES_IN=30m
# LOGIN_TOKEN_EXPIRES_IN=15m
# REFRESH_TOKEN_EXPIRES_IN=90d

View File

@ -1,7 +1,6 @@
PG_DATABASE_URL=postgres://postgres:postgres@localhost:5432/test
REDIS_URL=redis://localhost:6379
DEBUG_MODE=true
APP_SECRET=replace_me_with_a_random_string
SIGN_IN_PREFILLED=true
EXCEPTION_HANDLER_DRIVER=console

View File

@ -10,7 +10,9 @@
"baseUrl": "./../../",
"experimental": {
"plugins": [
["@lingui/swc-plugin", {}]
["@lingui/swc-plugin", {
"stripNonEssentialFields": false
}]
]
}
},

View File

@ -21,7 +21,14 @@ const jestConfig = {
decoratorMetadata: true,
},
experimental: {
plugins: [['@lingui/swc-plugin', {}]],
plugins: [
[
'@lingui/swc-plugin',
{
stripNonEssentialFields: false,
},
],
],
},
},
},

View File

@ -2,6 +2,8 @@ import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import { DataSource } from 'typeorm';
import { NodeEnvironment } from 'src/engine/core-modules/environment/interfaces/node-environment.interface';
import { AppToken } from 'src/engine/core-modules/app-token/app-token.entity';
import { BillingCustomer } from 'src/engine/core-modules/billing/entities/billing-customer.entity';
import { BillingEntitlement } from 'src/engine/core-modules/billing/entities/billing-entitlement.entity';
@ -106,9 +108,10 @@ export class TypeORMService implements OnModuleInit, OnModuleDestroy {
const workspaceDataSource = new DataSource({
url: dataSource.url ?? this.environmentService.get('PG_DATABASE_URL'),
type: 'postgres',
logging: this.environmentService.get('DEBUG_MODE')
? ['query', 'error']
: ['error'],
logging:
this.environmentService.get('NODE_ENV') === NodeEnvironment.development
? ['query', 'error']
: ['error'],
schema,
ssl: this.environmentService.get('PG_SSL_ALLOW_SELF_SIGNED')
? {

View File

@ -12,6 +12,8 @@ import GraphQLJSON from 'graphql-type-json';
import { GraphQLSchemaWithContext, YogaInitialContext } from 'graphql-yoga';
import { JsonWebTokenError, TokenExpiredError } from 'jsonwebtoken';
import { NodeEnvironment } from 'src/engine/core-modules/environment/interfaces/node-environment.interface';
import { useThrottler } from 'src/engine/api/graphql/graphql-config/hooks/use-throttler';
import { WorkspaceSchemaFactory } from 'src/engine/api/graphql/workspace-schema.factory';
import { AuthContext } from 'src/engine/core-modules/auth/types/auth-context.type';
@ -41,7 +43,8 @@ export class GraphQLConfigService
) {}
createGqlOptions(): YogaDriverConfig {
const isDebugMode = this.environmentService.get('DEBUG_MODE');
const isDebugMode =
this.environmentService.get('NODE_ENV') === NodeEnvironment.development;
const plugins = [
useThrottler({
ttl: this.environmentService.get('API_RATE_LIMITING_TTL'),

View File

@ -47,7 +47,7 @@ export const metadataModuleFactory = async (
}),
};
if (environmentService.get('DEBUG_MODE')) {
if (environmentService.get('NODE_ENV') === 'development') {
config.renderGraphiQL = () => {
return renderApolloPlayground({ path: 'metadata' });
};

View File

@ -1,5 +1,7 @@
import { Query, Resolver } from '@nestjs/graphql';
import { NodeEnvironment } from 'src/engine/core-modules/environment/interfaces/node-environment.interface';
import { DomainManagerService } from 'src/engine/core-modules/domain-manager/services/domain-manager.service';
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
import { PUBLIC_FEATURE_FLAGS } from 'src/engine/core-modules/feature-flag/constants/public-feature-flag.const';
@ -50,7 +52,7 @@ export class ClientConfigResolver {
),
defaultSubdomain: this.environmentService.get('DEFAULT_SUBDOMAIN'),
frontDomain: this.domainManagerService.getFrontUrl().hostname,
debugMode: this.environmentService.get('DEBUG_MODE'),
debugMode: this.environmentService.get('NODE_ENV') === 'development',
support: {
supportDriver: this.environmentService.get('SUPPORT_DRIVER'),
supportFrontChatId: this.environmentService.get(
@ -74,7 +76,8 @@ export class ClientConfigResolver {
},
analyticsEnabled: this.environmentService.get('ANALYTICS_ENABLED'),
canManageFeatureFlags:
this.environmentService.get('DEBUG_MODE') ||
this.environmentService.get('NODE_ENV') ===
NodeEnvironment.development ||
this.environmentService.get('IS_BILLING_ENABLED'),
publicFeatureFlags: PUBLIC_FEATURE_FLAGS,
isMicrosoftMessagingEnabled: this.environmentService.get(

View File

@ -795,22 +795,13 @@ export class EnvironmentVariables {
})
REDIS_URL: string;
@EnvironmentVariablesMetadata({
group: EnvironmentVariablesGroup.ServerConfig,
description: 'Enable or disable debug mode for the application',
})
@CastToBoolean()
@IsOptional()
@IsBoolean()
DEBUG_MODE = false;
@EnvironmentVariablesMetadata({
group: EnvironmentVariablesGroup.ServerConfig,
description: 'Node environment (development, production, etc.)',
})
@IsEnum(NodeEnvironment)
@IsString()
NODE_ENV: NodeEnvironment = NodeEnvironment.development;
NODE_ENV: NodeEnvironment = NodeEnvironment.production;
@EnvironmentVariablesMetadata({
group: EnvironmentVariablesGroup.ServerConfig,

View File

@ -30,7 +30,7 @@ export const exceptionHandlerModuleFactory = async (
release: environmentService.get('SENTRY_RELEASE'),
dsn: environmentService.get('SENTRY_DSN') ?? '',
serverInstance: adapterHost.httpAdapter?.getInstance(),
debug: environmentService.get('DEBUG_MODE'),
debug: environmentService.get('NODE_ENV') === 'development',
},
};
}

View File

@ -1,3 +1,5 @@
import { NodeEnvironment } from 'src/engine/core-modules/environment/interfaces/node-environment.interface';
import {
BaseGraphQLError,
ErrorCode,
@ -9,7 +11,7 @@ export const generateGraphQLErrorFromError = (error: Error) => {
ErrorCode.INTERNAL_SERVER_ERROR,
);
if (process.env.NODE_ENV === 'development') {
if (process.env.NODE_ENV === NodeEnvironment.development) {
graphqlError.stack = error.stack;
graphqlError.extensions['response'] = error.message;
}

View File

@ -2,6 +2,8 @@ import { Injectable, Logger } from '@nestjs/common';
import { EntitySchema } from 'typeorm';
import { NodeEnvironment } from 'src/engine/core-modules/environment/interfaces/node-environment.interface';
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
import { WorkspaceMetadataCacheService } from 'src/engine/metadata-modules/workspace-metadata-cache/services/workspace-metadata-cache.service';
@ -135,9 +137,11 @@ export class WorkspaceDatasourceFactory {
dataSourceMetadata.url ??
this.environmentService.get('PG_DATABASE_URL'),
type: 'postgres',
logging: this.environmentService.get('DEBUG_MODE')
? ['query', 'error']
: ['error'],
logging:
this.environmentService.get('NODE_ENV') ===
NodeEnvironment.development
? ['query', 'error']
: ['error'],
schema: dataSourceMetadata.schema,
entities: cachedEntitySchemas,
ssl: this.environmentService.get('PG_SSL_ALLOW_SELF_SIGNED')

View File

@ -2,6 +2,7 @@ import { HttpException } from '@nestjs/common';
import { GraphQLError } from 'graphql';
import { NodeEnvironment } from 'src/engine/core-modules/environment/interfaces/node-environment.interface';
import { ExceptionHandlerUser } from 'src/engine/core-modules/exception-handler/interfaces/exception-handler-user.interface';
import { ExceptionHandlerWorkspace } from 'src/engine/core-modules/exception-handler/interfaces/exception-handler-workspace.interface';
@ -114,7 +115,7 @@ const convertHttpExceptionToGraphql = (exception: HttpException) => {
}
// Only show the stack trace in development mode
if (process.env.NODE_ENV === 'development') {
if (process.env.NODE_ENV === NodeEnvironment.development) {
error.stack = exception.stack;
error.extensions['response'] = exception.getResponse();
}

View File

@ -1,6 +1,8 @@
import * as Sentry from '@sentry/nestjs';
import { nodeProfilingIntegration } from '@sentry/profiling-node';
import { NodeEnvironment } from 'src/engine/core-modules/environment/interfaces/node-environment.interface';
import { ExceptionHandlerDriver } from 'src/engine/core-modules/exception-handler/interfaces';
import { WorkspaceCacheKeys } from 'src/engine/workspace-cache-storage/workspace-cache-storage.service';
@ -24,6 +26,6 @@ if (process.env.EXCEPTION_HANDLER_DRIVER === ExceptionHandlerDriver.Sentry) {
],
tracesSampleRate: 0.1,
profilesSampleRate: 0.3,
debug: process.env.DEBUG_MODE === 'true',
debug: process.env.NODE_ENV === NodeEnvironment.development,
});
}

View File

@ -9,6 +9,8 @@ import { useContainer, ValidationError } from 'class-validator';
import session from 'express-session';
import { graphqlUploadExpress } from 'graphql-upload';
import { NodeEnvironment } from 'src/engine/core-modules/environment/interfaces/node-environment.interface';
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
import { LoggerService } from 'src/engine/core-modules/logger/logger.service';
import { getSessionStorageOptions } from 'src/engine/core-modules/session-storage/session-storage.module-factory';
@ -25,7 +27,7 @@ const bootstrap = async () => {
cors: true,
bufferLogs: process.env.LOGGER_IS_BUFFER_ENABLED === 'true',
rawBody: true,
snapshot: process.env.DEBUG_MODE === 'true',
snapshot: process.env.NODE_ENV === NodeEnvironment.development,
...(process.env.SSL_KEY_PATH && process.env.SSL_CERT_PATH
? {
httpsOptions: {

View File

@ -1,7 +1,7 @@
import { ReactElement } from 'react';
import fs from 'fs';
import { compileMDX } from 'next-mdx-remote/rsc';
import path from 'path';
import { ReactElement } from 'react';
import gfm from 'remark-gfm';
import ArticleEditContent from '@/app/_components/ui/layout/articles/ArticleEditContent';

View File

@ -1,7 +1,7 @@
import { JSXElementConstructor, ReactElement } from 'react';
import fs from 'fs';
import matter from 'gray-matter';
import { compileMDX } from 'next-mdx-remote/rsc';
import { JSXElementConstructor, ReactElement } from 'react';
import gfm from 'remark-gfm';
import { ReleaseNote } from '@/app/releases/api/route';

View File

@ -328,7 +328,6 @@ This feature is WIP and is not yet useful for most users.
### Debug / Development
<ArticleTable options={[
['DEBUG_MODE', 'true', 'Activate debug mode'],
['SIGN_IN_PREFILLED', 'true', 'Prefill the Sign in form for usage in a demo or dev environment'],
]}></ArticleTable>

View File

@ -7142,9 +7142,9 @@ __metadata:
languageName: node
linkType: hard
"@lingui/swc-plugin@npm:^5.0.2":
version: 5.0.2
resolution: "@lingui/swc-plugin@npm:5.0.2"
"@lingui/swc-plugin@npm:^5.1.0":
version: 5.1.0
resolution: "@lingui/swc-plugin@npm:5.1.0"
peerDependencies:
"@lingui/core": 5
peerDependenciesMeta:
@ -7152,7 +7152,7 @@ __metadata:
optional: true
next:
optional: true
checksum: 10c0/5f7ca68349b642f7034800f6080c4f28f33d97059a8611144b9d78878cf14727b9293e4f5aec5c82a4930617f4bcacd2c25618e6d39ded7ceac15465f3b5aed2
checksum: 10c0/ca514c4fcc2d6d1ca62e7063fe4dc8ef2b29d328bbe22184b4773149a86448335c39f72faccfe41f10ca2081df379cfcb7f9e70337a27aec2568571c0118c0d6
languageName: node
linkType: hard
@ -46056,7 +46056,7 @@ __metadata:
"@lingui/cli": "npm:^5.1.2"
"@lingui/core": "npm:^5.1.2"
"@lingui/react": "npm:^5.1.2"
"@lingui/swc-plugin": "npm:^5.0.2"
"@lingui/swc-plugin": "npm:^5.1.0"
"@lingui/vite-plugin": "npm:^5.1.2"
"@mdx-js/react": "npm:^3.0.0"
"@microsoft/microsoft-graph-client": "npm:^3.0.7"