diff --git a/packages/core/build/src/build.ts b/packages/core/build/src/build.ts index c1e0704b8..48f28524c 100755 --- a/packages/core/build/src/build.ts +++ b/packages/core/build/src/build.ts @@ -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) => { diff --git a/packages/core/build/src/buildDeclaration.ts b/packages/core/build/src/buildDeclaration.ts index 74816c24e..39e3bad33 100644 --- a/packages/core/build/src/buildDeclaration.ts +++ b/packages/core/build/src/buildDeclaration.ts @@ -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')); } }); diff --git a/packages/core/build/src/stats.ts b/packages/core/build/src/stats.ts new file mode 100644 index 000000000..20757966f --- /dev/null +++ b/packages/core/build/src/stats.ts @@ -0,0 +1,3 @@ +import { EventEmitter } from 'events'; + +export const signals = new EventEmitter(); diff --git a/packages/plugins/@hera/plugin-homepage/package.json b/packages/plugins/@hera/plugin-homepage/package.json index 3d9023c0b..a69a5a9dc 100644 --- a/packages/plugins/@hera/plugin-homepage/package.json +++ b/packages/plugins/@hera/plugin-homepage/package.json @@ -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:*" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 983360aaf..c89ef10b5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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