fix: runPluginStaticImports (#6528)

This commit is contained in:
chenos 2025-03-23 08:59:28 +08:00 committed by GitHub
parent 437e9dba52
commit 436af4b9f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 30 additions and 13 deletions

View File

@ -61,8 +61,8 @@ function customLogger(queryString, queryObject) {
export async function createMockDatabase(options: IDatabaseOptions = {}) {
try {
// @ts-ignore
const { staticImport } = await import('@nocobase/plugin-data-source-external-mssql/server/static-import');
await staticImport();
const { runPluginStaticImports } = await import('@nocobase/server');
await runPluginStaticImports();
} catch (error) {
// error
}

View File

@ -10,8 +10,8 @@
import winston, { LeveledLogMethod, Logger as WinstonLogger } from 'winston';
import 'winston-daily-rotate-file';
import { getLoggerLevel } from './config';
import { getTransports } from './transports';
import { consoleFormat } from './format';
import { getTransports } from './transports';
interface Logger extends WinstonLogger {
trace: LeveledLogMethod;

View File

@ -7,11 +7,12 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import winston, { format } from 'winston';
import { createLogger, levels, Logger, LoggerOptions } from './logger';
import Transport from 'winston-transport';
import { SPLAT } from 'triple-beam';
import winston, { format } from 'winston';
import Transport from 'winston-transport';
import { getLoggerFilePath } from './config';
import { getFormat } from './format';
import { createLogger, levels, Logger, LoggerOptions } from './logger';
export interface SystemLoggerOptions extends LoggerOptions {
seperateError?: boolean; // print error seperately, default true
@ -138,3 +139,12 @@ export const createSystemLogger = (options: SystemLoggerOptions): SystemLogger =
},
});
};
export const logger = createSystemLogger({
dirname: getLoggerFilePath('main'),
filename: 'system',
defaultMeta: {
app: 'main',
module: 'cli',
},
});

View File

@ -6,18 +6,22 @@
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { logger } from '@nocobase/logger';
import { findAllPlugins, PluginManager } from '@nocobase/server';
import { importModule } from '@nocobase/utils';
export async function runPluginStaticImports() {
const packages = await findAllPlugins();
for (const name of packages) {
const { packageName } = await PluginManager.parseName(name);
try {
const plugin = require(packageName);
const plugin = await importModule(packageName);
if (plugin && plugin.staticImport) {
logger.info('run static import', { packageName });
await plugin.staticImport();
}
} catch (error) {
logger.error(error, { packageName });
continue;
}
}

View File

@ -1,5 +1,13 @@
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
export * from './interfaces/async-task-manager';
export * from './task-type';
export * from './static-import';
export { default } from './plugin';

View File

@ -1,5 +0,0 @@
import { appendToBuiltInPlugins } from '@nocobase/server';
export async function staticImport() {
await appendToBuiltInPlugins('@nocobase/plugin-async-task-manager');
}