miaoda-game-devkit 0.2.13 → 0.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  该开发工具包提供:
6
6
 
7
- - React 游戏的生产/手动时钟、Strict Mode 安全 Session ownership、JSDOM
7
+ - React 游戏的生产/手动时钟、Strict Mode 安全 Controller ownership、JSDOM
8
8
  Vitest 配置和自动收集运行错误的 Testing Library setup,分别从 `miaoda-game-devkit/react`、
9
9
  `miaoda-game-devkit/react/testing` 和 `miaoda-game-devkit/react/vitest-config` 导入;
10
10
 
@@ -139,7 +139,9 @@ DOM 到 Phaser 的输入、命中测试和游戏状态变化,不验证 Canvas/
139
139
 
140
140
  ## 发布顺序
141
141
 
142
- 1. 在开发工具包中运行类型检查和测试。
142
+ 1. 在开发工具包中运行类型检查和测试。`pnpm test` 会额外生成经过
143
+ `clean-publish` 清理的 tarball,在隔离项目中按发布目录结构解包,并以
144
+ `NODE_ENV=production` 运行真实 React DOM 输入测试。
143
145
  2. 使用 `pnpm run release:dry-run` 检查将要发布的文件和清理后的 `package.json`。
144
146
  3. 根据版本类型运行 `pnpm run release:patch`、`release:minor` 或 `release:major`。
145
147
  发布脚本会先测试和构建,再通过 `clean-publish` 从临时目录发布;发布包会移除
@@ -1,13 +1,13 @@
1
1
  export { G as GameClock, a as GameFrameCallback, b as browserGameClock } from '../game-clock-suUidZdT.mjs';
2
2
 
3
- interface DisposableGameSession {
3
+ interface DisposableGameController {
4
4
  destroy(): void;
5
5
  }
6
6
  /**
7
- * 创建由当前组件拥有的 Session,并在真实卸载后销毁。
8
- * 微任务检查避免 React Strict Mode effect 探测误销毁仍在使用的 Session。
9
- * createSession 必须只创建内存状态;监听器、定时器等外部资源应在订阅或操作时启用。
7
+ * Creates a Controller owned by the current component and destroys it after a
8
+ * real unmount. The microtask check ignores React Strict Mode effect probing.
9
+ * Construction must not start external work; controls or subscriptions may do so.
10
10
  */
11
- declare function useOwnedGameSession<TSession extends DisposableGameSession>(createSession: () => TSession): TSession;
11
+ declare function useOwnedGameController<TController extends DisposableGameController>(createController: () => TController): TController;
12
12
 
13
- export { type DisposableGameSession, useOwnedGameSession };
13
+ export { type DisposableGameController, useOwnedGameController };
@@ -1,13 +1,13 @@
1
1
  export { G as GameClock, a as GameFrameCallback, b as browserGameClock } from '../game-clock-suUidZdT.js';
2
2
 
3
- interface DisposableGameSession {
3
+ interface DisposableGameController {
4
4
  destroy(): void;
5
5
  }
6
6
  /**
7
- * 创建由当前组件拥有的 Session,并在真实卸载后销毁。
8
- * 微任务检查避免 React Strict Mode effect 探测误销毁仍在使用的 Session。
9
- * createSession 必须只创建内存状态;监听器、定时器等外部资源应在订阅或操作时启用。
7
+ * Creates a Controller owned by the current component and destroys it after a
8
+ * real unmount. The microtask check ignores React Strict Mode effect probing.
9
+ * Construction must not start external work; controls or subscriptions may do so.
10
10
  */
11
- declare function useOwnedGameSession<TSession extends DisposableGameSession>(createSession: () => TSession): TSession;
11
+ declare function useOwnedGameController<TController extends DisposableGameController>(createController: () => TController): TController;
12
12
 
13
- export { type DisposableGameSession, useOwnedGameSession };
13
+ export { type DisposableGameController, useOwnedGameController };
@@ -21,7 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var react_exports = {};
22
22
  __export(react_exports, {
23
23
  browserGameClock: () => browserGameClock,
24
- useOwnedGameSession: () => useOwnedGameSession
24
+ useOwnedGameController: () => useOwnedGameController
25
25
  });
26
26
  module.exports = __toCommonJS(react_exports);
27
27
 
@@ -34,24 +34,24 @@ var browserGameClock = {
34
34
  clearTimeout: (id) => window.clearTimeout(id)
35
35
  };
36
36
 
37
- // src/react/use-owned-game-session.ts
37
+ // src/react/use-owned-game-controller.ts
38
38
  var import_react = require("react");
39
- function useOwnedGameSession(createSession) {
40
- const [session] = (0, import_react.useState)(createSession);
39
+ function useOwnedGameController(createController) {
40
+ const [controller] = (0, import_react.useState)(createController);
41
41
  const mounted = (0, import_react.useRef)(false);
42
42
  (0, import_react.useEffect)(() => {
43
43
  mounted.current = true;
44
44
  return () => {
45
45
  mounted.current = false;
46
46
  queueMicrotask(() => {
47
- if (!mounted.current) session.destroy();
47
+ if (!mounted.current) controller.destroy();
48
48
  });
49
49
  };
50
- }, [session]);
51
- return session;
50
+ }, [controller]);
51
+ return controller;
52
52
  }
53
53
  // Annotate the CommonJS export names for ESM import in node:
54
54
  0 && (module.exports = {
55
55
  browserGameClock,
56
- useOwnedGameSession
56
+ useOwnedGameController
57
57
  });
@@ -7,23 +7,23 @@ var browserGameClock = {
7
7
  clearTimeout: (id) => window.clearTimeout(id)
8
8
  };
9
9
 
10
- // src/react/use-owned-game-session.ts
10
+ // src/react/use-owned-game-controller.ts
11
11
  import { useEffect, useRef, useState } from "react";
12
- function useOwnedGameSession(createSession) {
13
- const [session] = useState(createSession);
12
+ function useOwnedGameController(createController) {
13
+ const [controller] = useState(createController);
14
14
  const mounted = useRef(false);
15
15
  useEffect(() => {
16
16
  mounted.current = true;
17
17
  return () => {
18
18
  mounted.current = false;
19
19
  queueMicrotask(() => {
20
- if (!mounted.current) session.destroy();
20
+ if (!mounted.current) controller.destroy();
21
21
  });
22
22
  };
23
- }, [session]);
24
- return session;
23
+ }, [controller]);
24
+ return controller;
25
25
  }
26
26
  export {
27
27
  browserGameClock,
28
- useOwnedGameSession
28
+ useOwnedGameController
29
29
  };
@@ -60,6 +60,9 @@ function defineReactGameVitestConfig(options) {
60
60
  }
61
61
  },
62
62
  test: {
63
+ env: {
64
+ NODE_ENV: "test"
65
+ },
63
66
  include: [
64
67
  "src/**/*.{test,spec}.{ts,tsx}",
65
68
  "tests/**/*.{test,spec}.{ts,tsx}"
@@ -36,6 +36,9 @@ function defineReactGameVitestConfig(options) {
36
36
  }
37
37
  },
38
38
  test: {
39
+ env: {
40
+ NODE_ENV: "test"
41
+ },
39
42
  include: [
40
43
  "src/**/*.{test,spec}.{ts,tsx}",
41
44
  "tests/**/*.{test,spec}.{ts,tsx}"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miaoda-game-devkit",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "description": "Shared React and Phaser game lint plus deterministic testing tools for Miaoda games",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
@@ -108,7 +108,7 @@
108
108
  "build"
109
109
  ],
110
110
  "options": {
111
- "command": "vitest run --config dist/lint/contracts.config.mjs",
111
+ "command": "pnpm run test:contracts && pnpm run test:published",
112
112
  "cwd": "packages/game-devkit"
113
113
  }
114
114
  }