Skip to content

Commit

Permalink
fix: Fix post build logs processing
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Nov 13, 2024
1 parent de1d419 commit 066844f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
15 changes: 2 additions & 13 deletions src/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {Lang, Stage, YFM_CONFIG_FILENAME} from '~/constants';
import {Command, Config, configPath, defined, valuable} from '~/config';
import {OutputFormat, options} from './config';
import {Run} from './run';
import {handler} from './handler';

import {
Templating,
Expand Down Expand Up @@ -273,8 +274,6 @@ export class Build

run.logger.pipe(this.logger);

// console.log(run.config);

shell.mkdir('-p', run.originalOutput);

// Create temporary input/output folders
Expand All @@ -283,7 +282,7 @@ export class Build

await this.hooks.BeforeAnyRun.promise(run);
await this.hooks.BeforeRun.for(this.config.outputFormat).promise(run);
await Promise.all([this.handler(run), this.hooks.Run.promise(run)]);
await Promise.all([handler(run), this.hooks.Run.promise(run)]);
await this.hooks.AfterRun.for(this.config.outputFormat).promise(run);
await this.hooks.AfterAnyRun.promise(run);

Expand All @@ -296,14 +295,4 @@ export class Build

shell.rm('-rf', run.input, run.output);
}

/**
* Loads handler in async mode to not initialise all deps on startup.
*/
private async handler(run: Run) {
// @ts-ignore
const {handler} = await import('./handler');

return handler(run);
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (require.main === module) {

if (message) {
// eslint-disable-next-line no-console
console.error(error.stack || error.message || error);
console.error(error.message || error);
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/program/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {AsyncSeriesWaterfallHook, Hook, HookMap, SyncHook} from 'tapable';
import {isAbsolute, resolve} from 'node:path';
import {once} from 'lodash';
import {Logger} from '~/logger';
import log from '@diplodoc/transform/lib/log';
import {
resolveConfig,
scope as scopeConfig,
Expand Down Expand Up @@ -151,9 +152,13 @@ export const BaseProgram = <
}

private async post() {
const {error, warn} = this.logger;
if (error.count || (this.config.strict && warn.count)) {
throw new HandledError('There is some errors.');
if (this.logger.error.count || (this.config.strict && this.logger.warn.count)) {
throw new HandledError('There is some processing errors.');
}

const {error, warn} = log.get();
if (error.length || (this.config.strict && warn.length)) {
throw new HandledError('There is some processing errors.');
}
}

Expand Down

0 comments on commit 066844f

Please sign in to comment.