diff --git a/CHANGELOG.md b/CHANGELOG.md index f9a28f1..a27facc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ All notable changes to `hy-event-store` are documented in this file. actions, and action return values, plus compile-time regression coverage. - Allow off to cancel a pending once listener by using the original callback reference. +- Document the supported package-name import path for WeChat Mini Programs and + add a package-root entry-point regression test. ## 1.4.0 - 2026-08-19 diff --git a/README.md b/README.md index f29436f..c2e8fe7 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,20 @@ const store = new HYEventStore({ }) ~~~ +### Mini Program projects + +The package currently uses CommonJS. In WeChat DevTools, enable **Use npm +modules**, run **Build npm**, and then import the package by its package name: + +~~~js +const { HYEventStore } = require("hy-event-store") +~~~ + +Do not import `src/event-store.js` or a path such as `store/hy-event-store.js`. +Those paths refer to source files and are not the built Mini Program module +entry. If you use another bundler, configure it to resolve CommonJS packages +from `node_modules` and keep the same package-name import. + ## Quick start ### Event bus diff --git a/README.zh-CN.md b/README.zh-CN.md index 2851ba3..af4965c 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -45,6 +45,19 @@ const store = new HYEventStore({ }) ~~~ +### 小程序项目接入 + +当前发布包使用 CommonJS。在微信开发者工具中,请启用**使用 npm 模块**, +执行**构建 npm**,然后使用包名导入: + +~~~js +const { HYEventStore } = require("hy-event-store") +~~~ + +不要直接导入 `src/event-store.js` 或 `store/hy-event-store.js` 这类路径。 +这些路径指向源码文件,并不是构建后的小程序模块入口。如果使用其他构建 +工具,请配置它从 `node_modules` 解析 CommonJS 包,并保持使用包名导入。 + ## 快速开始 ### 事件总线 diff --git a/ROADMAP.md b/ROADMAP.md index 8a84108..5ad183c 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -23,7 +23,8 @@ These items need API design or compatibility research before implementation: - Add first-party TypeScript declarations and compile-time coverage ([#25](https://github.com/coderwhy/hy-event-store/issues/25)). -- Document and test CommonJS, ESM, and Mini Program import paths +- Document and test CommonJS and Mini Program import paths; native ESM remains + a separate compatibility item ([#27](https://github.com/coderwhy/hy-event-store/issues/27)). - Evaluate a read-only state getter ([#26](https://github.com/coderwhy/hy-event-store/issues/26)). diff --git a/Test/event-store.test.js b/Test/event-store.test.js index 7b85e8d..9ab3c8e 100644 --- a/Test/event-store.test.js +++ b/Test/event-store.test.js @@ -3,6 +3,13 @@ const assert = require("node:assert/strict") const { HYEventStore } = require("../src") +test("package root exposes the public constructors", () => { + const pkg = require("..") + + assert.equal(typeof pkg.HYEventBus, "function") + assert.equal(typeof pkg.HYEventStore, "function") +}) + test("constructor validates options, state, and actions", () => { assert.throws(() => new HYEventStore(), /options must be object/) assert.throws(() => new HYEventStore({}), /state must be object/)