koishi-plugin-eula-regen 1.0.1 → 1.0.2

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.
Files changed (2) hide show
  1. package/lib/index.js +11 -1
  2. package/package.json +3 -2
package/lib/index.js CHANGED
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const jsx_runtime_1 = require("@satorijs/element/jsx-runtime");
3
+ // 动态导入 ES Module - 使用 Promise 缓存
4
+ let jsx_runtime_1_promise = import("@satorijs/element/jsx-runtime");
5
+ let jsx_runtime_1;
6
+ // 立即开始加载,并在加载完成后缓存
7
+ jsx_runtime_1_promise.then(mod => {
8
+ jsx_runtime_1 = mod;
9
+ });
4
10
  const koishi_1 = require("koishi");
5
11
  const module_1 = require("module");
6
12
  const path_1 = require("path");
@@ -46,6 +52,10 @@ class Eula extends koishi_1.Service {
46
52
  .action((_) => this.eula(_));
47
53
  }
48
54
  async eula(argv) {
55
+ // 确保 jsx_runtime 已加载
56
+ if (!jsx_runtime_1) {
57
+ jsx_runtime_1 = await jsx_runtime_1_promise;
58
+ }
49
59
  const session = argv.session;
50
60
  const userLocale = session.user.locale || session.user.locales[0] || 'zh';
51
61
  const accept = koishi_1.Random.pick(this.configs.accept) ?? session.text('eula.defaultAccept');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-eula-regen",
3
3
  "description": "EULA(End-user licence agreement) for your koishi bot.",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "repository": "https://github.com/Lipraty/koishi-plugin-eula",
6
6
  "author": "Lipraty <i@lonay.me>",
7
7
  "main": "lib/index.js",
@@ -12,7 +12,8 @@
12
12
  ],
13
13
  "license": "MIT",
14
14
  "scripts": {
15
- "build": "tsc && cp -r src/locales lib/"
15
+ "build": "tsc && cp -r src/locales lib/ || true",
16
+ "postbuild": "node -e \"const fs=require('fs');const p='lib/index.js';let c=fs.readFileSync(p,'utf8');if(c.includes('require(\\\"@satorijs/element/jsx-runtime\\\")')){c=c.replace(/const jsx_runtime_1 = require\\(\"@satorijs\\\\/element\\\\/jsx-runtime\"\\);?/,'');c=c.replace(/('use strict';\\\\nObject\\\\.defineProperty\\(exports, '__esModule', \\\\{ value: true \\\\}\\);)/,'$1\\\\nlet jsx_runtime_1_promise = import(\\\"@satorijs/element/jsx-runtime\\\");\\\\nlet jsx_runtime_1;\\\\njsx_runtime_1_promise.then(mod=>{jsx_runtime_1=mod;});\\\\n');c=c.replace(/(async eula\\(argv\\) \\{)/,'$1\\\\nif(!jsx_runtime_1){jsx_runtime_1=await jsx_runtime_1_promise;}\\\\n');fs.writeFileSync(p,c);}\""
16
17
  },
17
18
  "devDependencies": {
18
19
  "@types/node": "^20.0.0",