Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deprecated should print to stdout #281

Merged
merged 2 commits into from
Dec 31, 2024
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
2 changes: 1 addition & 1 deletion src/egg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Lifecycle } from './lifecycle.js';
import { EggLoader } from './loader/egg_loader.js';
import utils from './utils/index.js';

const debug = debuglog('@eggjs/core:egg');
const debug = debuglog('@eggjs/core/egg');

export const EGG_LOADER = Symbol.for('egg#loader');

Expand Down
16 changes: 8 additions & 8 deletions src/loader/egg_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class EggLoader {
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('tsconfig-paths').register({ cwd: this.options.baseDir });
} else {
this.logger.info('[@eggjs/core:egg_loader] skip register "tsconfig-paths" because tsconfig.json not exists at %s',
this.logger.info('[@eggjs/core/egg_loader] skip register "tsconfig-paths" because tsconfig.json not exists at %s',
tsConfigFile);
}
}
Expand Down Expand Up @@ -639,14 +639,14 @@ export class EggLoader {

const logger = this.options.logger;
if (!config) {
logger.warn(`[@eggjs/core:egg_loader] pkg.eggPlugin is missing in ${pluginPackage}`);
logger.warn(`[@eggjs/core/egg_loader] pkg.eggPlugin is missing in ${pluginPackage}`);
return;
}

if (config.name && config.strict !== false && config.name !== plugin.name) {
// pluginName is configured in config/plugin.js
// pluginConfigName is pkg.eggPlugin.name
logger.warn(`[@eggjs/core:egg_loader] pluginName(${plugin.name}) is different from pluginConfigName(${config.name})`);
logger.warn(`[@eggjs/core/egg_loader] pluginName(${plugin.name}) is different from pluginConfigName(${config.name})`);
}

// dep compatible
Expand Down Expand Up @@ -1184,7 +1184,7 @@ export class EggLoader {
this.lifecycle.addFunctionAsBootHook(bootHook, bootFilePath);
debug('[loadBootHook] add bootHookFunction from %o', bootFilePath);
} else {
this.options.logger.warn('[@eggjs/core:egg_loader] %s must exports a boot class', bootFilePath);
this.options.logger.warn('[@eggjs/core/egg_loader] %s must exports a boot class', bootFilePath);
}
}
// init boots
Expand Down Expand Up @@ -1295,13 +1295,13 @@ export class EggLoader {
}
app.use(mw);
debug('[loadMiddleware] Use middleware: %s with options: %j', name, options);
this.options.logger.info('[@eggjs/core:egg_loader] Use middleware: %s', name);
this.options.logger.info('[@eggjs/core/egg_loader] Use middleware: %s', name);
} else {
this.options.logger.info('[@eggjs/core:egg_loader] Disable middleware: %s', name);
this.options.logger.info('[@eggjs/core/egg_loader] Disable middleware: %s', name);
}
}

this.options.logger.info('[@eggjs/core:egg_loader] Loaded middleware from %j', middlewarePaths);
this.options.logger.info('[@eggjs/core/egg_loader] Loaded middleware from %j', middlewarePaths);
this.timing.end('Load Middleware');

// add router middleware, make sure router is the last middleware
Expand Down Expand Up @@ -1359,7 +1359,7 @@ export class EggLoader {
};
await this.loadToApp(controllerBase, 'controller', opt as FileLoaderOptions);
debug('[loadController] app.controller => %o', this.app.controller);
this.options.logger.info('[@eggjs/core:egg_loader] Controller loaded: %s', controllerBase);
this.options.logger.info('[@eggjs/core/egg_loader] Controller loaded: %s', controllerBase);
this.timing.end('Load Controller');
}
/** end Controller loader */
Expand Down
8 changes: 4 additions & 4 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import BuiltinModule from 'node:module';
import { importResolve, importModule } from '@eggjs/utils';

const debug = debuglog('@eggjs/core:utils');
const debug = debuglog('@eggjs/core/utils');

export type Fun = (...args: any[]) => any;

Expand Down Expand Up @@ -55,10 +55,10 @@
export default {
deprecated(message: string) {
if (debug.enabled) {
console.trace('[@eggjs/core:deprecated] %s', message);
console.trace('[@eggjs/core/deprecated] %s', message);

Check warning on line 58 in src/utils/index.ts

View check run for this annotation

Codecov / codecov/patch

src/utils/index.ts#L58

Added line #L58 was not covered by tests
} else {
console.warn('[@eggjs/core:deprecated] %s', message);
console.warn('[@eggjs/core:deprecated] set NODE_DEBUG=@eggjs/core:utils can show call stack');
console.log('[@eggjs/core/deprecated] %s', message);
console.log('[@eggjs/core/deprecated] set NODE_DEBUG=@eggjs/core/utils can show call stack');
}
},

Expand Down
2 changes: 1 addition & 1 deletion src/utils/sequencify.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { debuglog } from 'node:util';

const debug = debuglog('@eggjs/core:utils:sequencify');
const debug = debuglog('@eggjs/core/utils/sequencify');

export interface SequencifyResult {
sequence: string[];
Expand Down
2 changes: 1 addition & 1 deletion src/utils/timing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EOL } from 'node:os';
import { debuglog } from 'node:util';
import assert from 'node:assert';

const debug = debuglog('@eggjs/core:utils:timing');
const debug = debuglog('@eggjs/core/utils/timing');

export interface TimingItem {
name: string;
Expand Down
6 changes: 3 additions & 3 deletions test/loader/mixin/load_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ describe('test/loader/mixin/load_plugin.test.ts', () => {
let message = '';
app = createApp('plugin');
mm(app.console, 'warn', function(m: string) {
if (!m.startsWith('[@eggjs/core:egg_loader] eggPlugin is missing') && !message) {
if (!m.startsWith('[@eggjs/core/egg_loader] eggPlugin is missing') && !message) {
message = m;
}
});
const loader = app.loader;
await loader.loadPlugin();
await loader.loadConfig();

assert.equal(message, '[@eggjs/core:egg_loader] pluginName(e) is different from pluginConfigName(wrong-name)');
assert.equal(message, '[@eggjs/core/egg_loader] pluginName(e) is different from pluginConfigName(wrong-name)');
});

it('should not warn when the config.strict is false', async () => {
Expand Down Expand Up @@ -496,7 +496,7 @@ describe('test/loader/mixin/load_plugin.test.ts', () => {
await loader.loadPlugin();
const plugin = loader.plugins.a;
assert.equal(plugin.name, 'a');
assert.equal(plugin.path, getFilepath('realpath/a'));
assert.equal(plugin.path, getFilepath('realpath/node_modules/a'));
});

it('should get the defining plugin path in every plugin', async () => {
Expand Down
Loading