@koishi-ce/plugin-market 1.0.2 → 1.0.3

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/lib/index.mjs CHANGED
@@ -5,7 +5,7 @@ import { compare, gt, satisfies, valid } from "semver";
5
5
  import { DataService } from "@koishi-ce/console";
6
6
  import { readFileSync } from "node:fs";
7
7
  import { homedir } from "node:os";
8
- import Scanner from "@koishi-ce/registry";
8
+ import Scanner, { resolvePackageJson } from "@koishi-ce/registry";
9
9
  import spawn from "execa";
10
10
  import pMap from "p-map";
11
11
  import messageZhCN from "./assets/message.zh-CN-B_nH77kB.yml";
@@ -67,7 +67,7 @@ const levelMap = {
67
67
  error: "warn"
68
68
  };
69
69
  function loadManifest(name) {
70
- const filename = __require.resolve(`${name}/package.json`);
70
+ const filename = resolvePackageJson(name);
71
71
  const meta = JSON.parse(readFileSync(filename, "utf8"));
72
72
  meta.dependencies ||= {};
73
73
  defineProperty(meta, "$workspace", !filename.includes("node_modules"));
@@ -224,10 +224,14 @@ var Installer = class extends Service {
224
224
  }
225
225
  async override(deps) {
226
226
  const filename = resolve(this.cwd, "package.json");
227
- for (const key in deps) if (deps[key]) this.manifest.dependencies[key] = deps[key];
228
- else delete this.manifest.dependencies[key];
227
+ this.manifest = JSON.parse(readFileSync(filename, "utf8"));
228
+ this.manifest.dependencies ||= {};
229
+ for (const key in deps) if (deps[key]) {
230
+ if (this.manifest.dependencies[key]?.startsWith("workspace:")) continue;
231
+ this.manifest.dependencies[key] = deps[key];
232
+ } else if (!this.manifest.dependencies[key]?.startsWith("workspace:")) delete this.manifest.dependencies[key];
229
233
  this.manifest.dependencies = Object.fromEntries(Object.entries(this.manifest.dependencies).sort((a, b) => a[0].localeCompare(b[0])));
230
- await Bun.write(filename, `${JSON.stringify(this.manifest, null, 2)}\n`);
234
+ await Bun.write(filename, `${JSON.stringify(this.manifest, null, " ")}\n`);
231
235
  }
232
236
  _install() {
233
237
  const args = [];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@koishi-ce/plugin-market",
3
3
  "description": "Manage your bots and plugins with console",
4
- "version": "1.0.2",
4
+ "version": "1.0.3",
5
5
  "type": "module",
6
6
  "main": "lib/index.mjs",
7
7
  "typings": "lib/index.d.ts",
@@ -62,14 +62,14 @@
62
62
  "devDependencies": {
63
63
  "@koishi-ce/client": "^1.0.1",
64
64
  "@koishi-ce/loader": "^1.0.1",
65
- "@koishi-ce/plugin-config": "^1.0.1",
65
+ "@koishi-ce/plugin-config": "^1.0.2",
66
66
  "@koishijs/market": "^4.2.10",
67
67
  "@types/semver": "^7.5.8",
68
68
  "vue": "^3.5.12"
69
69
  },
70
70
  "dependencies": {
71
71
  "@koishi-ce/console": "^1.0.0",
72
- "@koishi-ce/registry": "^1.0.1",
72
+ "@koishi-ce/registry": "^1.0.2",
73
73
  "execa": "^5.1.1",
74
74
  "p-map": "^4.0.0",
75
75
  "semver": "^7.6.3",
@@ -22,6 +22,7 @@ import Scanner, {
22
22
  type PackageJson,
23
23
  type Registry,
24
24
  type RemotePackage,
25
+ resolvePackageJson,
25
26
  } from "@koishi-ce/registry";
26
27
  import spawn from "execa";
27
28
  import pMap from "p-map";
@@ -111,7 +112,9 @@ export interface LocalPackage extends PackageJson {
111
112
  }
112
113
 
113
114
  export function loadManifest(name: string) {
114
- const filename = require.resolve(`${name}/package.json`);
115
+ // resolvePackageJson 兜底:安装前对 `pkg/package.json` 形态的
116
+ // 探测会被 Bun 记入进程内负缓存,装完后主路径仍解析失败
117
+ const filename = resolvePackageJson(name);
115
118
  const meta: LocalPackage = JSON.parse(readFileSync(filename, "utf8"));
116
119
  meta.dependencies ||= {};
117
120
  defineProperty(meta, "$workspace", !filename.includes("node_modules"));
@@ -323,10 +326,20 @@ class Installer extends Service {
323
326
 
324
327
  async override(deps: Dict<string | null>) {
325
328
  const filename = resolve(this.cwd, "package.json");
329
+ // 现读现写:this.manifest 原为构造期的启动快照,运行期间根
330
+ // package.json 可能已被外部更新,基于快照整体重写会抹掉变更
331
+ this.manifest = JSON.parse(readFileSync(filename, "utf8")) as LocalPackage;
332
+ this.manifest.dependencies ||= {};
326
333
  for (const key in deps) {
327
334
  if (deps[key]) {
335
+ // workspace: 声明是本仓库对上游裸名的归属(如 koishi 裸名
336
+ // shim,见 packages/node/koishi),不可被安装清单覆盖成
337
+ // npm 版本,否则会拉下官方包形成第二份框架副本
338
+ if (this.manifest.dependencies[key]?.startsWith("workspace:")) {
339
+ continue;
340
+ }
328
341
  this.manifest.dependencies[key] = deps[key];
329
- } else {
342
+ } else if (!this.manifest.dependencies[key]?.startsWith("workspace:")) {
330
343
  delete this.manifest.dependencies[key];
331
344
  }
332
345
  }
@@ -335,7 +348,9 @@ class Installer extends Service {
335
348
  a[0].localeCompare(b[0]),
336
349
  ),
337
350
  );
338
- await Bun.write(filename, `${JSON.stringify(this.manifest, null, 2)}\n`);
351
+ // 仓库格式权威是 biome(tab 缩进),按 tab 写出避免装插件后
352
+ // package.json 被重排成空格、lint 报格式漂移
353
+ await Bun.write(filename, `${JSON.stringify(this.manifest, null, "\t")}\n`);
339
354
  }
340
355
 
341
356
  private _install() {