Skip to content

Commit 3176f6f

Browse files
authored
refactor(core): Move dependencies of Logger to standalone packages (#15338)
1 parent 3840cba commit 3176f6f

27 files changed

+58
-59
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
export * from './license-state';
22
export * from './types';
3+
4+
const { NODE_ENV } = process.env;
5+
6+
export const inTest = NODE_ENV === 'test';
7+
export const inProduction = NODE_ENV === 'production';
8+
export const inDevelopment = !NODE_ENV || NODE_ENV === 'development';

packages/cli/src/__tests__/controller.registry.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
jest.mock('@/constants', () => ({
2-
inProduction: true,
3-
}));
1+
jest.mock('@n8n/backend-common', () => {
2+
return {
3+
...jest.requireActual('@n8n/backend-common'),
4+
inProduction: true,
5+
};
6+
});
47

58
import type { GlobalConfig } from '@n8n/config';
69
import { ControllerRegistryMetadata } from '@n8n/decorators';

packages/cli/src/abstract-server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inTest, inDevelopment } from '@n8n/backend-common';
12
import { GlobalConfig } from '@n8n/config';
23
import { OnShutdown } from '@n8n/decorators';
34
import { Container, Service } from '@n8n/di';
@@ -10,7 +11,7 @@ import isbot from 'isbot';
1011
import { Logger } from 'n8n-core';
1112

1213
import config from '@/config';
13-
import { N8N_VERSION, TEMPLATES_DIR, inDevelopment, inTest } from '@/constants';
14+
import { N8N_VERSION, TEMPLATES_DIR } from '@/constants';
1415
import { DbConnection } from '@/databases/db-connection';
1516
import { ServiceUnavailableError } from '@/errors/response-errors/service-unavailable.error';
1617
import { ExternalHooks } from '@/external-hooks';

packages/cli/src/commands/base-command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'reflect-metadata';
2-
import { LicenseState } from '@n8n/backend-common';
2+
import { inDevelopment, inTest, LicenseState } from '@n8n/backend-common';
33
import { GlobalConfig } from '@n8n/config';
44
import { LICENSE_FEATURES } from '@n8n/constants';
55
import { Container } from '@n8n/di';
@@ -17,7 +17,7 @@ import { ensureError, sleep, UserError } from 'n8n-workflow';
1717

1818
import type { AbstractServer } from '@/abstract-server';
1919
import config from '@/config';
20-
import { N8N_VERSION, N8N_RELEASE_DATE, inDevelopment, inTest } from '@/constants';
20+
import { N8N_VERSION, N8N_RELEASE_DATE } from '@/constants';
2121
import * as CrashJournal from '@/crash-journal';
2222
import { DbConnection } from '@/databases/db-connection';
2323
import { getDataDeduplicationService } from '@/deduplication';

packages/cli/src/commands/worker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { inTest } from '@n8n/backend-common';
12
import { Container } from '@n8n/di';
23
import { Flags, type Config } from '@oclif/core';
34

45
import config from '@/config';
5-
import { N8N_VERSION, inTest } from '@/constants';
6+
import { N8N_VERSION } from '@/constants';
67
import { EventMessageGeneric } from '@/eventbus/event-message-classes/event-message-generic';
78
import { MessageEventBus } from '@/eventbus/message-event-bus/message-event-bus';
89
import { LogStreamingEventRelay } from '@/events/relays/log-streaming.event-relay';

packages/cli/src/config/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inTest } from '@n8n/backend-common';
12
import { GlobalConfig } from '@n8n/config';
23
import { Container } from '@n8n/di';
34
import convict from 'convict';
@@ -8,7 +9,7 @@ import { Logger } from 'n8n-core';
89
import { setGlobalState, UserError } from 'n8n-workflow';
910
import assert from 'node:assert';
1011

11-
import { inTest, inE2ETests } from '@/constants';
12+
import { inE2ETests } from '@/constants';
1213

1314
const globalConfig = Container.get(GlobalConfig);
1415

packages/cli/src/constants.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import type { ITaskDataConnections } from 'n8n-workflow';
44
import { jsonParse, TRIMMED_TASK_DATA_CONNECTIONS_KEY } from 'n8n-workflow';
55
import { resolve, join, dirname } from 'path';
66

7-
const { NODE_ENV, E2E_TESTS } = process.env;
8-
export const inProduction = NODE_ENV === 'production';
9-
export const inDevelopment = !NODE_ENV || NODE_ENV === 'development';
10-
export const inTest = NODE_ENV === 'test';
7+
const { E2E_TESTS } = process.env;
118
export const inE2ETests = E2E_TESTS === 'true';
129

1310
export const CUSTOM_API_CALL_NAME = 'Custom API Call';

packages/cli/src/controller.registry.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { inProduction } from '@n8n/backend-common';
12
import { GlobalConfig } from '@n8n/config';
2-
import type { BooleanLicenseFeature } from '@n8n/constants';
3+
import { type BooleanLicenseFeature } from '@n8n/constants';
34
import { ControllerRegistryMetadata } from '@n8n/decorators';
45
import type { AccessScope, Controller, RateLimit } from '@n8n/decorators';
56
import { Container, Service } from '@n8n/di';
@@ -10,7 +11,7 @@ import { UnexpectedError } from 'n8n-workflow';
1011
import type { ZodClass } from 'zod-class';
1112

1213
import { AuthService } from '@/auth/auth.service';
13-
import { inProduction, RESPONSE_ERROR_MESSAGES } from '@/constants';
14+
import { RESPONSE_ERROR_MESSAGES } from '@/constants';
1415
import { UnauthenticatedError } from '@/errors/response-errors/unauthenticated.error';
1516
import { License } from '@/license';
1617
import { userHasScopes } from '@/permissions.ee/check-access';

packages/cli/src/crash-journal.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
import { inProduction } from '@n8n/backend-common';
12
import { Container } from '@n8n/di';
23
import { existsSync } from 'fs';
34
import { mkdir, utimes, open, rm } from 'fs/promises';
45
import { InstanceSettings, Logger } from 'n8n-core';
56
import { sleep } from 'n8n-workflow';
67
import { join, dirname } from 'path';
78

8-
import { inProduction } from '@/constants';
9-
109
export const touchFile = async (filePath: string): Promise<void> => {
1110
await mkdir(dirname(filePath), { recursive: true });
1211
const time = new Date();

packages/cli/src/databases/db-connection.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
import { inTest } from '@n8n/backend-common';
12
import { Memoized } from '@n8n/decorators';
23
import { Container, Service } from '@n8n/di';
34
import { DataSource } from '@n8n/typeorm';
45
import { ErrorReporter } from 'n8n-core';
56
import { DbConnectionTimeoutError, ensureError } from 'n8n-workflow';
67

7-
import { inTest } from '@/constants';
8-
98
import { DbConnectionOptions } from './db-connection-options';
109
import type { Migration } from './types';
1110
import { wrapMigration } from './utils/migration-helpers';

packages/cli/src/databases/utils/migration-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inTest } from '@n8n/backend-common';
12
import { GlobalConfig } from '@n8n/config';
23
import { Container } from '@n8n/di';
34
import type { ObjectLiteral } from '@n8n/typeorm';
@@ -6,7 +7,6 @@ import { readFileSync, rmSync } from 'fs';
67
import { InstanceSettings, Logger } from 'n8n-core';
78
import { jsonParse, UnexpectedError } from 'n8n-workflow';
89

9-
import { inTest } from '@/constants';
1010
import { createSchemaBuilder } from '@/databases/dsl';
1111
import type { BaseMigration, Migration, MigrationContext, MigrationFn } from '@/databases/types';
1212

packages/cli/src/eventbus/message-event-bus-writer/message-event-bus-log-writer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
22

3+
import { inTest } from '@n8n/backend-common';
34
import { GlobalConfig } from '@n8n/config';
45
import { Container } from '@n8n/di';
56
import { once as eventOnce } from 'events';
@@ -11,8 +12,6 @@ import path, { parse } from 'path';
1112
import readline from 'readline';
1213
import { Worker } from 'worker_threads';
1314

14-
import { inTest } from '@/constants';
15-
1615
import type { EventMessageTypes } from '../event-message-classes';
1716
import { isEventMessageOptions } from '../event-message-classes/abstract-event-message';
1817
import type { AbstractEventMessageOptions } from '../event-message-classes/abstract-event-message-options';

packages/cli/src/load-nodes-and-credentials.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inTest } from '@n8n/backend-common';
12
import { GlobalConfig } from '@n8n/config';
23
import { Container, Service } from '@n8n/di';
34
import glob from 'fast-glob';
@@ -29,13 +30,7 @@ import { deepCopy, NodeConnectionTypes, UnexpectedError, UserError } from 'n8n-w
2930
import path from 'path';
3031
import picocolors from 'picocolors';
3132

32-
import {
33-
CUSTOM_API_CALL_KEY,
34-
CUSTOM_API_CALL_NAME,
35-
inTest,
36-
CLI_DIR,
37-
inE2ETests,
38-
} from '@/constants';
33+
import { CUSTOM_API_CALL_KEY, CUSTOM_API_CALL_NAME, CLI_DIR, inE2ETests } from '@/constants';
3934
import { isContainedWithin } from '@/utils/path-util';
4035

4136
@Service()

packages/cli/src/push/__tests__/index.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ jest.mock('ws', () => ({
1818
Server: jest.fn(),
1919
}));
2020
jest.unmock('@/push');
21-
jest.mock('@/constants', () => ({
22-
inProduction: true,
23-
}));
21+
jest.mock('@n8n/backend-common', () => {
22+
return {
23+
...jest.requireActual('@n8n/backend-common'),
24+
inProduction: true,
25+
};
26+
});
2427

2528
describe('Push', () => {
2629
const pushRef = 'valid-push-ref';

packages/cli/src/push/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { PushMessage } from '@n8n/api-types';
2+
import { inProduction } from '@n8n/backend-common';
23
import type { User } from '@n8n/db';
34
import { OnShutdown } from '@n8n/decorators';
45
import { Container, Service } from '@n8n/di';
@@ -11,7 +12,7 @@ import { parse as parseUrl } from 'url';
1112
import { Server as WSServer } from 'ws';
1213

1314
import { AuthService } from '@/auth/auth.service';
14-
import { inProduction, TRIMMED_TASK_DATA_CONNECTIONS } from '@/constants';
15+
import { TRIMMED_TASK_DATA_CONNECTIONS } from '@/constants';
1516
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
1617
import { Publisher } from '@/scaling/pubsub/publisher.service';
1718
import { TypedEmitter } from '@/typed-emitter';

packages/cli/src/response-helper.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
2+
import { inDevelopment } from '@n8n/backend-common';
23
import { Container } from '@n8n/di';
34
import type { Request, Response } from 'express';
45
import { ErrorReporter, Logger } from 'n8n-core';
56
import { FORM_TRIGGER_PATH_IDENTIFIER, NodeApiError } from 'n8n-workflow';
67
import { Readable } from 'node:stream';
78
import picocolors from 'picocolors';
89

9-
import { inDevelopment } from '@/constants';
10-
1110
import { ResponseError } from './errors/response-errors/abstract/response.error';
1211

1312
export function sendSuccessResponse(

packages/cli/src/security-audit/risk-reporters/instance-risk-reporter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inDevelopment } from '@n8n/backend-common';
12
import { GlobalConfig } from '@n8n/config';
23
import { separate } from '@n8n/db';
34
import { Service } from '@n8n/di';
@@ -6,7 +7,7 @@ import { InstanceSettings, Logger } from 'n8n-core';
67
import type { IWorkflowBase } from 'n8n-workflow';
78

89
import config from '@/config';
9-
import { inDevelopment, N8N_VERSION } from '@/constants';
10+
import { N8N_VERSION } from '@/constants';
1011
import { isApiEnabled } from '@/public-api';
1112
import {
1213
ENV_VARS_DOCS_URL,

packages/cli/src/server.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inDevelopment, inProduction } from '@n8n/backend-common';
12
import { SecurityConfig } from '@n8n/config';
23
import { Container, Service } from '@n8n/di';
34
import cookieParser from 'cookie-parser';
@@ -11,15 +12,7 @@ import { resolve } from 'path';
1112

1213
import { AbstractServer } from '@/abstract-server';
1314
import config from '@/config';
14-
import {
15-
CLI_DIR,
16-
EDITOR_UI_DIST_DIR,
17-
inDevelopment,
18-
inE2ETests,
19-
inProduction,
20-
N8N_VERSION,
21-
Time,
22-
} from '@/constants';
15+
import { CLI_DIR, EDITOR_UI_DIST_DIR, inE2ETests, N8N_VERSION, Time } from '@/constants';
2316
import { ControllerRegistry } from '@/controller.registry';
2417
import { CredentialsOverwrites } from '@/credentials-overwrites';
2518
import { MessageEventBus } from '@/eventbus/message-event-bus/message-event-bus';

packages/cli/src/task-runners/task-broker/task-broker-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inTest } from '@n8n/backend-common';
12
import { GlobalConfig } from '@n8n/config';
23
import { Service } from '@n8n/di';
34
import compression from 'compression';
@@ -11,7 +12,6 @@ import type { AddressInfo, Socket } from 'node:net';
1112
import { parse as parseUrl } from 'node:url';
1213
import { Server as WSServer } from 'ws';
1314

14-
import { inTest } from '@/constants';
1515
import { bodyParser, rawBodyReader } from '@/middlewares';
1616
import { send } from '@/response-helper';
1717
import { TaskBrokerAuthController } from '@/task-runners/task-broker/auth/task-broker-auth.controller';

packages/cli/src/user-management/email/user-management-mailer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inTest } from '@n8n/backend-common';
12
import { GlobalConfig } from '@n8n/config';
23
import type { User } from '@n8n/db';
34
import { UserRepository } from '@n8n/db';
@@ -9,7 +10,6 @@ import { Logger } from 'n8n-core';
910
import type { IWorkflowBase } from 'n8n-workflow';
1011
import { join as pathJoin } from 'path';
1112

12-
import { inTest } from '@/constants';
1313
import { InternalServerError } from '@/errors/response-errors/internal-server.error';
1414
import { EventService } from '@/events/event.service';
1515
import { UrlService } from '@/services/url.service';

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"dependencies": {
3939
"@aws-sdk/client-s3": "3.808.0",
4040
"@langchain/core": "catalog:",
41+
"@n8n/backend-common": "workspace:^",
4142
"@n8n/client-oauth2": "workspace:*",
4243
"@n8n/config": "workspace:*",
4344
"@n8n/decorators": "workspace:*",

packages/core/src/constants.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
const { NODE_ENV } = process.env;
2-
export const inProduction = NODE_ENV === 'production';
3-
export const inDevelopment = !NODE_ENV || NODE_ENV === 'development';
4-
export const inTest = NODE_ENV === 'test';
5-
61
export const CUSTOM_EXTENSION_ENV = 'N8N_CUSTOM_EXTENSIONS';
72
export const PLACEHOLDER_EMPTY_EXECUTION_ID = '__UNKNOWN__';
83
export const PLACEHOLDER_EMPTY_WORKFLOW_ID = '__EMPTY__';

packages/core/src/instance-settings/instance-settings.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inTest } from '@n8n/backend-common';
12
import { InstanceSettingsConfig } from '@n8n/config';
23
import { Memoized } from '@n8n/decorators';
34
import { Service } from '@n8n/di';
@@ -27,8 +28,6 @@ type InstanceRole = 'unset' | 'leader' | 'follower';
2728

2829
export type InstanceType = 'main' | 'webhook' | 'worker';
2930

30-
const inTest = process.env.NODE_ENV === 'test';
31-
3231
@Service()
3332
export class InstanceSettings {
3433
/** The path to the n8n folder in which all n8n related data gets saved */

packages/core/src/logging/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inDevelopment, inProduction } from '@n8n/backend-common';
12
import type { LogScope } from '@n8n/config';
23
import { GlobalConfig, InstanceSettingsConfig } from '@n8n/config';
34
import { Service } from '@n8n/di';
@@ -14,7 +15,6 @@ import path, { basename } from 'node:path';
1415
import pc from 'picocolors';
1516
import winston from 'winston';
1617

17-
import { inDevelopment, inProduction } from '@/constants';
1818
import { isObjectLiteral } from '@/utils/is-object-literal';
1919

2020
const noOp = () => {};

packages/core/src/nodes-loader/__tests__/load-class-in-isolation.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ import vm from 'vm';
22

33
import { loadClassInIsolation } from '../load-class-in-isolation';
44

5-
jest.mock('@/constants', () => ({
6-
inTest: false,
7-
}));
5+
jest.mock('@n8n/backend-common', () => {
6+
return {
7+
...jest.requireActual('@n8n/backend-common'),
8+
inTest: false,
9+
};
10+
});
811

912
describe('loadClassInIsolation', () => {
1013
const filePath = '/path/to/TestClass.js';

packages/core/src/nodes-loader/load-class-in-isolation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import { inTest } from '@n8n/backend-common';
12
import { createContext, Script } from 'vm';
23

3-
import { inTest } from '@/constants';
4-
54
const context = createContext({ require });
65
export const loadClassInIsolation = <T>(filePath: string, className: string) => {
76
if (process.platform === 'win32') {

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)