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