feat: support build erros dump (#1069)
Reviewed-on: daoyoucloud/tachybase#1069
This commit is contained in:
		
							parent
							
								
									09ce4996e4
								
							
						
					
					
						commit
						1273e55e9b
					
				@ -1,44 +1,31 @@
 | 
			
		||||
import { EventEmitter } from 'events';
 | 
			
		||||
import path from 'path';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import type { Project } from '@pnpm/workspace.find-packages';
 | 
			
		||||
import chalk from 'chalk';
 | 
			
		||||
import execa from 'execa';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import { buildCjs } from './buildCjs';
 | 
			
		||||
import { buildClient } from './buildClient';
 | 
			
		||||
import { buildDeclaration } from './buildDeclaration';
 | 
			
		||||
import { buildEsm } from './buildEsm';
 | 
			
		||||
import { buildPlugin } from './buildPlugin';
 | 
			
		||||
import {
 | 
			
		||||
  CORE_APP,
 | 
			
		||||
  CORE_CLIENT,
 | 
			
		||||
  ESM_PACKAGES,
 | 
			
		||||
  getCjsPackages,
 | 
			
		||||
  getPluginPackages,
 | 
			
		||||
  getPresetsPackages,
 | 
			
		||||
  PACKAGES_PATH,
 | 
			
		||||
  ROOT_PATH,
 | 
			
		||||
} from './constant';
 | 
			
		||||
import { CORE_APP, CORE_CLIENT, ESM_PACKAGES, getCjsPackages, getPluginPackages, getPresetsPackages, PACKAGES_PATH, ROOT_PATH } from './constant';
 | 
			
		||||
import { signals } from './stats';
 | 
			
		||||
import { tarPlugin } from './tarPlugin';
 | 
			
		||||
import {
 | 
			
		||||
  getPackageJson,
 | 
			
		||||
  getPkgLog,
 | 
			
		||||
  getUserConfig,
 | 
			
		||||
  PkgLog,
 | 
			
		||||
  readFromCache,
 | 
			
		||||
  toUnixPath,
 | 
			
		||||
  UserConfig,
 | 
			
		||||
  writeToCache,
 | 
			
		||||
} from './utils';
 | 
			
		||||
import { getPackageJson, getPkgLog, getUserConfig, PkgLog, readFromCache, toUnixPath, UserConfig, writeToCache } from './utils';
 | 
			
		||||
import { getPackages } from './utils/getPackages';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const BUILD_ERROR = 'build-error';
 | 
			
		||||
global.__bus = new EventEmitter();
 | 
			
		||||
 | 
			
		||||
export async function build(pkgs: string[]) {
 | 
			
		||||
  const messages = [];
 | 
			
		||||
  (global.__bus as EventEmitter).on('build:errors', (message) => {
 | 
			
		||||
  signals.on('build:errors', (message) => {
 | 
			
		||||
    messages.push(message);
 | 
			
		||||
  });
 | 
			
		||||
  const isDev = process.argv.includes('--development');
 | 
			
		||||
@ -86,7 +73,7 @@ export async function build(pkgs: string[]) {
 | 
			
		||||
      APP_ROOT: path.join(CORE_APP, 'client'),
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
  writeToCache(BUILD_ERROR, {});
 | 
			
		||||
  writeToCache(BUILD_ERROR, { messages });
 | 
			
		||||
  if (messages.length > 0) {
 | 
			
		||||
    console.log('❌ build errors:');
 | 
			
		||||
    messages.forEach((message) => {
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,3 @@
 | 
			
		||||
import type { EventEmitter } from 'events';
 | 
			
		||||
import path from 'path';
 | 
			
		||||
 | 
			
		||||
import fg from 'fast-glob';
 | 
			
		||||
@ -6,6 +5,7 @@ import fs from 'fs-extra';
 | 
			
		||||
import ts from 'typescript';
 | 
			
		||||
 | 
			
		||||
import { globExcludeFiles, ROOT_PATH } from './constant';
 | 
			
		||||
import { signals } from './stats';
 | 
			
		||||
 | 
			
		||||
export const buildDeclaration = (cwd: string, targetDir: string) => {
 | 
			
		||||
  return new Promise<{ exitCode: 1 | 0; messages: string[] }>((resolve, reject) => {
 | 
			
		||||
@ -42,21 +42,14 @@ export const buildDeclaration = (cwd: string, targetDir: string) => {
 | 
			
		||||
    const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
 | 
			
		||||
    const messages = [];
 | 
			
		||||
    allDiagnostics.forEach((diagnostic) => {
 | 
			
		||||
      try {
 | 
			
		||||
        if (diagnostic.file) {
 | 
			
		||||
          const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
 | 
			
		||||
          const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
 | 
			
		||||
          (global.__bus as EventEmitter).emit(
 | 
			
		||||
            'build:errors',
 | 
			
		||||
            `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`,
 | 
			
		||||
          );
 | 
			
		||||
          console.error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
 | 
			
		||||
        } else {
 | 
			
		||||
          (global.__bus as EventEmitter).emit('build:errors', ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'));
 | 
			
		||||
          console.error(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'));
 | 
			
		||||
        }
 | 
			
		||||
      } catch (e) {
 | 
			
		||||
        console.log(e);
 | 
			
		||||
      if (diagnostic.file) {
 | 
			
		||||
        const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start);
 | 
			
		||||
        const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n');
 | 
			
		||||
        signals.emit('build:errors', `${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
 | 
			
		||||
        console.error(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
 | 
			
		||||
      } else {
 | 
			
		||||
        signals.emit('build:errors', ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'));
 | 
			
		||||
        console.error(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'));
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										3
									
								
								packages/core/build/src/stats.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								packages/core/build/src/stats.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
			
		||||
import { EventEmitter } from 'events';
 | 
			
		||||
 | 
			
		||||
export const signals = new EventEmitter();
 | 
			
		||||
@ -7,9 +7,10 @@
 | 
			
		||||
    "antd": "^5.16.1"
 | 
			
		||||
  },
 | 
			
		||||
  "peerDependencies": {
 | 
			
		||||
    "@tachybase/client": "0.x",
 | 
			
		||||
    "@tachybase/database": "0.x",
 | 
			
		||||
    "@tachybase/server": "0.x",
 | 
			
		||||
    "@tachybase/test": "0.x"
 | 
			
		||||
    "@tachybase/client": "workspace:*",
 | 
			
		||||
    "@tachybase/database": "workspace:*",
 | 
			
		||||
    "@tachybase/server": "workspace:*",
 | 
			
		||||
    "@tachybase/test": "workspace:*",
 | 
			
		||||
    "@tachybase/utils": "workspace:*"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1668,17 +1668,20 @@ importers:
 | 
			
		||||
  packages/plugins/@hera/plugin-homepage:
 | 
			
		||||
    dependencies:
 | 
			
		||||
      '@tachybase/client':
 | 
			
		||||
        specifier: 0.x
 | 
			
		||||
        specifier: workspace:*
 | 
			
		||||
        version: link:../../../core/client
 | 
			
		||||
      '@tachybase/database':
 | 
			
		||||
        specifier: 0.x
 | 
			
		||||
        specifier: workspace:*
 | 
			
		||||
        version: link:../../../core/database
 | 
			
		||||
      '@tachybase/server':
 | 
			
		||||
        specifier: 0.x
 | 
			
		||||
        specifier: workspace:*
 | 
			
		||||
        version: link:../../../core/server
 | 
			
		||||
      '@tachybase/test':
 | 
			
		||||
        specifier: 0.x
 | 
			
		||||
        specifier: workspace:*
 | 
			
		||||
        version: link:../../../core/test
 | 
			
		||||
      '@tachybase/utils':
 | 
			
		||||
        specifier: workspace:*
 | 
			
		||||
        version: link:../../../core/utils
 | 
			
		||||
    devDependencies:
 | 
			
		||||
      antd:
 | 
			
		||||
        specifier: ^5.16.1
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user