refactor: reorganize package structure and decouple framework packages (#338)

* refactor: reorganize package structure and decouple framework packages

## Package Structure Reorganization
- Reorganized 55 packages into categorized subdirectories:
  - packages/framework/ - Generic framework (Laya/Cocos compatible)
  - packages/engine/ - ESEngine core modules
  - packages/rendering/ - Rendering modules (WASM dependent)
  - packages/physics/ - Physics modules
  - packages/streaming/ - World streaming
  - packages/network-ext/ - Network extensions
  - packages/editor/ - Editor framework and plugins
  - packages/rust/ - Rust WASM engine
  - packages/tools/ - Build tools and SDK

## Framework Package Decoupling
- Decoupled behavior-tree and blueprint packages from ESEngine dependencies
- Created abstracted interfaces (IBTAssetManager, IBehaviorTreeAssetContent)
- ESEngine-specific code moved to esengine/ subpath exports
- Framework packages now usable with Cocos/Laya without ESEngine

## CI Configuration
- Updated CI to only type-check and lint framework packages
- Added type-check:framework and lint:framework scripts

## Breaking Changes
- Package import paths changed due to directory reorganization
- ESEngine integrations now use subpath imports (e.g., '@esengine/behavior-tree/esengine')

* fix: update es-engine file path after directory reorganization

* docs: update README to focus on framework over engine

* ci: only build framework packages, remove Rust/WASM dependencies

* fix: remove esengine subpath from behavior-tree and blueprint builds

ESEngine integration code will only be available in full engine builds.
Framework packages are now purely engine-agnostic.

* fix: move network-protocols to framework, build both in CI

* fix: update workflow paths from packages/core to packages/framework/core

* fix: exclude esengine folder from type-check in behavior-tree and blueprint

* fix: update network tsconfig references to new paths

* fix: add test:ci:framework to only test framework packages in CI

* fix: only build core and math npm packages in CI

* fix: exclude test files from CodeQL and fix string escaping security issue
This commit is contained in:
YHH
2025-12-26 14:50:35 +08:00
committed by GitHub
parent a84ff902e4
commit 155411e743
1936 changed files with 4147 additions and 11578 deletions

View File

@@ -0,0 +1,100 @@
/**
* Block Editor Plugin
* 阻止编辑器代码泄漏插件
*
* 在运行时构建中检测并阻止编辑器代码被打包
* Detects and blocks editor code from being bundled in runtime builds
*/
import type { Plugin } from 'vite';
export interface BlockEditorOptions {
/** 是否为运行时构建 */
bIsRuntimeBuild: boolean;
/** 要阻止的模块模式 */
blockedPatterns?: (string | RegExp)[];
/** 是否只警告而不报错 */
bWarnOnly?: boolean;
}
const DEFAULT_BLOCKED_PATTERNS: (string | RegExp)[] = [
// React 相关
/^react$/,
/^react-dom$/,
/^react\/jsx-runtime$/,
/^lucide-react$/,
// 编辑器包
/@esengine\/editor-core/,
/@esengine\/node-editor/,
// 编辑器子路径
/\/editor$/,
/\/editor\//,
];
/**
* 创建阻止编辑器代码泄漏的插件
*
* @example
* ```typescript
* import { blockEditorPlugin } from '@esengine/build-config/plugins';
*
* // 在运行时构建中使用
* export default defineConfig({
* plugins: [
* blockEditorPlugin({ bIsRuntimeBuild: true })
* ]
* });
* ```
*/
export function blockEditorPlugin(options: BlockEditorOptions): Plugin {
const {
bIsRuntimeBuild,
blockedPatterns = DEFAULT_BLOCKED_PATTERNS,
bWarnOnly = false
} = options;
if (!bIsRuntimeBuild) {
// 非运行时构建不需要此插件
return { name: 'esengine:block-editor-noop' };
}
const isBlocked = (source: string): boolean => {
return blockedPatterns.some(pattern => {
if (typeof pattern === 'string') {
return source === pattern || source.startsWith(pattern + '/');
}
return pattern.test(source);
});
};
return {
name: 'esengine:block-editor',
enforce: 'pre',
resolveId(source: string, importer: string | undefined) {
if (isBlocked(source)) {
const message = `[block-editor] Editor dependency detected in runtime build:\n` +
` Source: ${source}\n` +
` Importer: ${importer || 'entry'}\n` +
`\n` +
` This usually means:\n` +
` 1. A runtime module is importing from a non-/runtime path\n` +
` 2. An editor-only dependency leaked into the dependency chain\n` +
`\n` +
` Fix: Change the import to use /runtime subpath, e.g.:\n` +
` import { X } from '@esengine/ui/runtime' // ✓\n` +
` import { X } from '@esengine/ui' // ✗`;
if (bWarnOnly) {
console.warn('\x1b[33m' + message + '\x1b[0m');
return { id: source, external: true };
} else {
throw new Error(message);
}
}
return null;
}
};
}

View File

@@ -0,0 +1,71 @@
/**
* CSS Inject Plugin
* CSS 注入插件
*
* 将 CSS 内联到 JS 中,避免单独的 CSS 文件
* Inlines CSS into JS to avoid separate CSS files
*/
import type { Plugin } from 'vite';
import type { OutputBundle, NormalizedOutputOptions, OutputAsset, OutputChunk } from 'rollup';
/**
* 创建 CSS 注入插件
*
* @example
* ```typescript
* import { cssInjectPlugin } from '@esengine/build-config/plugins';
*
* export default defineConfig({
* plugins: [cssInjectPlugin()]
* });
* ```
*/
export function cssInjectPlugin(): Plugin {
return {
name: 'esengine:css-inject',
apply: 'build',
generateBundle(_options: NormalizedOutputOptions, bundle: OutputBundle) {
// 收集所有 CSS 内容
const cssChunks: string[] = [];
const cssFileNames: string[] = [];
for (const [fileName, chunk] of Object.entries(bundle)) {
if (fileName.endsWith('.css') && chunk.type === 'asset') {
cssChunks.push(chunk.source as string);
cssFileNames.push(fileName);
}
}
if (cssChunks.length === 0) return;
// 合并所有 CSS
const combinedCSS = cssChunks.join('\n');
// 创建注入代码
const injectCode = `
(function() {
if (typeof document === 'undefined') return;
var style = document.createElement('style');
style.setAttribute('data-esengine', 'true');
style.textContent = ${JSON.stringify(combinedCSS)};
document.head.appendChild(style);
})();
`;
// 找到主入口 JS 文件并注入
for (const chunk of Object.values(bundle)) {
if (chunk.type === 'chunk' && chunk.isEntry) {
chunk.code = injectCode + chunk.code;
break;
}
}
// 删除独立的 CSS 文件
for (const fileName of cssFileNames) {
delete bundle[fileName];
}
}
};
}

View File

@@ -0,0 +1,7 @@
/**
* Shared Vite Plugins
* 共享 Vite 插件
*/
export { cssInjectPlugin } from './css-inject';
export { blockEditorPlugin, type BlockEditorOptions } from './block-editor';