Compare commits

...

2 Commits

Author SHA1 Message Date
github-actions[bot]
094133a71a chore: release packages (#403)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-12-30 20:55:04 +08:00
YHH
3e5b7783be fix(ecs): resolve ESM require is not defined error (#402)
- Add RuntimeConfig module as standalone runtime environment storage
- Core.runtimeEnvironment and Scene.runtimeEnvironment now read from RuntimeConfig
- Remove require() call in Scene.ts to fix Node.js ESM compatibility

Fixes ReferenceError: require is not defined when using scene.isServer in ESM environment
2025-12-30 20:52:29 +08:00
25 changed files with 158 additions and 18 deletions

View File

@@ -1,5 +1,12 @@
# @esengine/behavior-tree # @esengine/behavior-tree
## 4.1.1
### Patch Changes
- Updated dependencies [[`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8)]:
- @esengine/ecs-framework@2.7.1
## 4.1.0 ## 4.1.0
### Minor Changes ### Minor Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@esengine/behavior-tree", "name": "@esengine/behavior-tree",
"version": "4.1.0", "version": "4.1.1",
"description": "ECS-based AI behavior tree system - works with any ECS framework (ESEngine, Cocos, Laya, etc.)", "description": "ECS-based AI behavior tree system - works with any ECS framework (ESEngine, Cocos, Laya, etc.)",
"main": "dist/index.js", "main": "dist/index.js",
"module": "dist/index.js", "module": "dist/index.js",

View File

@@ -1,5 +1,12 @@
# @esengine/blueprint # @esengine/blueprint
## 4.0.1
### Patch Changes
- Updated dependencies [[`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8)]:
- @esengine/ecs-framework@2.7.1
## 4.0.0 ## 4.0.0
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@esengine/blueprint", "name": "@esengine/blueprint",
"version": "4.0.0", "version": "4.0.1",
"description": "Visual scripting system - works with any ECS framework (ESEngine, Cocos, Laya, etc.)", "description": "Visual scripting system - works with any ECS framework (ESEngine, Cocos, Laya, etc.)",
"main": "dist/index.js", "main": "dist/index.js",
"module": "dist/index.js", "module": "dist/index.js",

View File

@@ -1,5 +1,16 @@
# @esengine/ecs-framework # @esengine/ecs-framework
## 2.7.1
### Patch Changes
- [#402](https://github.com/esengine/esengine/pull/402) [`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8) Thanks [@esengine](https://github.com/esengine)! - fix(ecs): 修复 ESM 环境下 require 不存在的问题
- 新增 `RuntimeConfig` 模块,作为运行时环境配置的独立存储
- `Core.runtimeEnvironment``Scene.runtimeEnvironment` 现在都从 `RuntimeConfig` 读取
- 移除 `Scene.ts` 中的 `require()` 调用,解决 Node.js ESM 环境下的兼容性问题
此修复解决了在 Node.js ESM 环境(如游戏服务端)中使用 `scene.isServer` 时报错 `ReferenceError: require is not defined` 的问题。
## 2.7.0 ## 2.7.0
### Minor Changes ### Minor Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@esengine/ecs-framework", "name": "@esengine/ecs-framework",
"version": "2.7.0", "version": "2.7.1",
"description": "用于Laya、Cocos Creator等JavaScript游戏引擎的高性能ECS框架", "description": "用于Laya、Cocos Creator等JavaScript游戏引擎的高性能ECS框架",
"main": "dist/index.cjs", "main": "dist/index.cjs",
"module": "dist/index.mjs", "module": "dist/index.mjs",

View File

@@ -16,6 +16,7 @@ import { IPlugin } from './Core/Plugin';
import { WorldManager } from './ECS/WorldManager'; import { WorldManager } from './ECS/WorldManager';
import { DebugConfigService } from './Utils/Debug/DebugConfigService'; import { DebugConfigService } from './Utils/Debug/DebugConfigService';
import { createInstance } from './Core/DI/Decorators'; import { createInstance } from './Core/DI/Decorators';
import { RuntimeConfig } from './RuntimeConfig';
/** /**
* @zh 游戏引擎核心类 * @zh 游戏引擎核心类
@@ -86,14 +87,20 @@ export class Core {
* Core.create({ runtimeEnvironment: 'server' }); * Core.create({ runtimeEnvironment: 'server' });
* ``` * ```
*/ */
public static runtimeEnvironment: RuntimeEnvironment = 'standalone'; public static get runtimeEnvironment(): RuntimeEnvironment {
return RuntimeConfig.runtimeEnvironment;
}
public static set runtimeEnvironment(value: RuntimeEnvironment) {
RuntimeConfig.runtimeEnvironment = value;
}
/** /**
* @zh 是否在服务端运行 * @zh 是否在服务端运行
* @en Whether running on server * @en Whether running on server
*/ */
public static get isServer(): boolean { public static get isServer(): boolean {
return Core.runtimeEnvironment === 'server'; return RuntimeConfig.isServer;
} }
/** /**
@@ -101,7 +108,7 @@ export class Core {
* @en Whether running on client * @en Whether running on client
*/ */
public static get isClient(): boolean { public static get isClient(): boolean {
return Core.runtimeEnvironment === 'client'; return RuntimeConfig.isClient;
} }
/** /**

View File

@@ -13,6 +13,7 @@ import { QuerySystem } from './Core/QuerySystem';
import { TypeSafeEventSystem } from './Core/EventSystem'; import { TypeSafeEventSystem } from './Core/EventSystem';
import { ReferenceTracker } from './Core/ReferenceTracker'; import { ReferenceTracker } from './Core/ReferenceTracker';
import { IScene, ISceneConfig, RuntimeEnvironment } from './IScene'; import { IScene, ISceneConfig, RuntimeEnvironment } from './IScene';
import { RuntimeConfig } from '../RuntimeConfig';
import { getComponentInstanceTypeName, getSystemInstanceTypeName, getSystemMetadata, getSystemInstanceMetadata } from './Decorators'; import { getComponentInstanceTypeName, getSystemInstanceTypeName, getSystemMetadata, getSystemInstanceMetadata } from './Decorators';
import { TypedQueryBuilder } from './Core/Query/TypedQuery'; import { TypedQueryBuilder } from './Core/Query/TypedQuery';
import { import {
@@ -200,10 +201,7 @@ export class Scene implements IScene {
if (this._runtimeEnvironmentOverride) { if (this._runtimeEnvironmentOverride) {
return this._runtimeEnvironmentOverride; return this._runtimeEnvironmentOverride;
} }
// 动态导入避免循环依赖 return RuntimeConfig.runtimeEnvironment;
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { Core } = require('../Core') as typeof import('../Core');
return Core.runtimeEnvironment;
} }
/** /**

View File

@@ -0,0 +1,50 @@
import type { RuntimeEnvironment } from './Types';
/**
* @zh 全局运行时配置
* @en Global runtime configuration
*
* @zh 独立模块,避免 Core 和 Scene 之间的循环依赖
* @en Standalone module to avoid circular dependency between Core and Scene
*/
class RuntimeConfigClass {
private _runtimeEnvironment: RuntimeEnvironment = 'standalone';
/**
* @zh 获取运行时环境
* @en Get runtime environment
*/
get runtimeEnvironment(): RuntimeEnvironment {
return this._runtimeEnvironment;
}
/**
* @zh 设置运行时环境
* @en Set runtime environment
*/
set runtimeEnvironment(value: RuntimeEnvironment) {
this._runtimeEnvironment = value;
}
/**
* @zh 是否在服务端运行
* @en Whether running on server
*/
get isServer(): boolean {
return this._runtimeEnvironment === 'server';
}
/**
* @zh 是否在客户端运行
* @en Whether running on client
*/
get isClient(): boolean {
return this._runtimeEnvironment === 'client';
}
}
/**
* @zh 全局运行时配置单例
* @en Global runtime configuration singleton
*/
export const RuntimeConfig = new RuntimeConfigClass();

View File

@@ -5,6 +5,7 @@
// 核心模块 // 核心模块
export { Core } from './Core'; export { Core } from './Core';
export { RuntimeConfig } from './RuntimeConfig';
export { ServiceContainer, ServiceLifetime } from './Core/ServiceContainer'; export { ServiceContainer, ServiceLifetime } from './Core/ServiceContainer';
export type { IService, ServiceType, ServiceIdentifier } from './Core/ServiceContainer'; export type { IService, ServiceType, ServiceIdentifier } from './Core/ServiceContainer';

View File

@@ -1,5 +1,13 @@
# @esengine/fsm # @esengine/fsm
## 4.0.1
### Patch Changes
- Updated dependencies [[`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8)]:
- @esengine/ecs-framework@2.7.1
- @esengine/blueprint@4.0.1
## 4.0.0 ## 4.0.0
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@esengine/fsm", "name": "@esengine/fsm",
"version": "4.0.0", "version": "4.0.1",
"description": "Finite State Machine for ECS Framework / ECS 框架的有限状态机", "description": "Finite State Machine for ECS Framework / ECS 框架的有限状态机",
"type": "module", "type": "module",
"main": "./dist/index.js", "main": "./dist/index.js",

View File

@@ -1,5 +1,13 @@
# @esengine/network # @esengine/network
## 5.0.1
### Patch Changes
- Updated dependencies [[`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8)]:
- @esengine/ecs-framework@2.7.1
- @esengine/blueprint@4.0.1
## 5.0.0 ## 5.0.0
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@esengine/network", "name": "@esengine/network",
"version": "5.0.0", "version": "5.0.1",
"description": "Network synchronization for multiplayer games", "description": "Network synchronization for multiplayer games",
"esengine": { "esengine": {
"plugin": true, "plugin": true,

View File

@@ -1,5 +1,13 @@
# @esengine/pathfinding # @esengine/pathfinding
## 4.0.1
### Patch Changes
- Updated dependencies [[`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8)]:
- @esengine/ecs-framework@2.7.1
- @esengine/blueprint@4.0.1
## 4.0.0 ## 4.0.0
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@esengine/pathfinding", "name": "@esengine/pathfinding",
"version": "4.0.0", "version": "4.0.1",
"description": "寻路系统 | Pathfinding System - A*, Grid, NavMesh", "description": "寻路系统 | Pathfinding System - A*, Grid, NavMesh",
"type": "module", "type": "module",
"main": "./dist/index.js", "main": "./dist/index.js",

View File

@@ -1,5 +1,13 @@
# @esengine/procgen # @esengine/procgen
## 4.0.1
### Patch Changes
- Updated dependencies [[`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8)]:
- @esengine/ecs-framework@2.7.1
- @esengine/blueprint@4.0.1
## 4.0.0 ## 4.0.0
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@esengine/procgen", "name": "@esengine/procgen",
"version": "4.0.0", "version": "4.0.1",
"description": "Procedural generation tools for ECS Framework / ECS 框架的程序化生成工具", "description": "Procedural generation tools for ECS Framework / ECS 框架的程序化生成工具",
"type": "module", "type": "module",
"main": "./dist/index.js", "main": "./dist/index.js",

View File

@@ -51,7 +51,7 @@
"peerDependencies": { "peerDependencies": {
"ws": ">=8.0.0", "ws": ">=8.0.0",
"jsonwebtoken": ">=9.0.0", "jsonwebtoken": ">=9.0.0",
"@esengine/ecs-framework": ">=2.7.0" "@esengine/ecs-framework": ">=2.7.1"
}, },
"peerDependenciesMeta": { "peerDependenciesMeta": {
"jsonwebtoken": { "jsonwebtoken": {

View File

@@ -1,5 +1,13 @@
# @esengine/spatial # @esengine/spatial
## 4.0.1
### Patch Changes
- Updated dependencies [[`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8)]:
- @esengine/ecs-framework@2.7.1
- @esengine/blueprint@4.0.1
## 4.0.0 ## 4.0.0
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@esengine/spatial", "name": "@esengine/spatial",
"version": "4.0.0", "version": "4.0.1",
"description": "Spatial query and indexing system for ECS Framework / ECS 框架的空间查询和索引系统", "description": "Spatial query and indexing system for ECS Framework / ECS 框架的空间查询和索引系统",
"type": "module", "type": "module",
"main": "./dist/index.js", "main": "./dist/index.js",

View File

@@ -1,5 +1,13 @@
# @esengine/timer # @esengine/timer
## 4.0.1
### Patch Changes
- Updated dependencies [[`3e5b778`](https://github.com/esengine/esengine/commit/3e5b7783beec08e247f7525184935401923ecde8)]:
- @esengine/ecs-framework@2.7.1
- @esengine/blueprint@4.0.1
## 4.0.0 ## 4.0.0
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@esengine/timer", "name": "@esengine/timer",
"version": "4.0.0", "version": "4.0.1",
"description": "Timer and cooldown system for ECS Framework / ECS 框架的定时器和冷却系统", "description": "Timer and cooldown system for ECS Framework / ECS 框架的定时器和冷却系统",
"type": "module", "type": "module",
"main": "./dist/index.js", "main": "./dist/index.js",

View File

@@ -1,5 +1,16 @@
# @esengine/demos # @esengine/demos
## 1.0.10
### Patch Changes
- Updated dependencies []:
- @esengine/fsm@4.0.1
- @esengine/pathfinding@4.0.1
- @esengine/procgen@4.0.1
- @esengine/spatial@4.0.1
- @esengine/timer@4.0.1
## 1.0.9 ## 1.0.9
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@esengine/demos", "name": "@esengine/demos",
"version": "1.0.9", "version": "1.0.10",
"private": true, "private": true,
"description": "Demo tests for ESEngine modules documentation", "description": "Demo tests for ESEngine modules documentation",
"type": "module", "type": "module",