create-koishi-ce 1.8.0 → 1.9.1

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
@@ -29,7 +29,7 @@ npm create koishi-ce my-app
29
29
 
30
30
  - **package.json**:`type: module`、`packageManager` 钉 Bun、workspaces 含 `plugins/*` 与 `external/*`;dependencies 预装全套 `@koishi-ce` 常用插件(console、config、market、auth、admin、help、sandbox、database-sqlite 等),并预置六行 npm alias 钉住上游名——`koishi` / `@koishijs/core` / `@koishijs/loader` 指向 `@koishi-ce/koishi-shim`、`@koishijs/plugin-console` 指向 `@koishi-ce/console-shim`、`@koishijs/client` / `@koishijs/components` 分别指向 `@koishi-ce/client-shim` / `@koishi-ce/components-shim`,社区插件(含把上游前端库写进 dependencies 的 webui 插件)由此全部解析到 CE 对应包;
31
31
  - **koishi.yml**:按 server(端口 5140-5149)/ basic / console(自动打开、市场指向 registry.koishi.chat 镜像)/ storage / adapter / develop(开发模式启用热重载)分组预写;官方 adapter 插件以 `~` 停用条目预写、不预装,装好后在控制台按需启用;数据库开箱即用——`database-sqlite` 默认启用,mongo / mysql / postgres 等其余 database 不预写占位条目,市场安装后自动出现;
32
- - **开发工具链**:devDependencies 预置 `@koishi-ce/client`、`@koishi-ce/plugin-hmr` 与 `@koishi-ce/scripts`(`koishi-scripts setup` 可在 external/ 下继续创建插件项目)。
32
+ - **开发工具链**:devDependencies 预置 `@koishi-ce/client`、`@koishi-ce/console-app`(宿主 SPA 源码,devMode 的 vite root)、`@koishi-ce/console-builder`(控制台 devMode 的 Vite 开发服务器)、`@koishi-ce/plugin-hmr` 与 `@koishi-ce/scripts`(`koishi-scripts setup` 可在 external/ 下继续创建插件项目)。
33
33
 
34
34
  不预装任何 adapter——官方 adapter 可后续从市场安装,peer 已被 alias 钉住不会形成双实例;数据库已由默认启用的 `database-sqlite` 覆盖,其他官方 database 同样可从市场安装。
35
35
 
@@ -68,7 +68,7 @@ Interactive flow: project name; confirm cleaning a non-empty target directory; c
68
68
 
69
69
  - **package.json** — `type: module`, `packageManager` pinned to Bun, workspaces covering `plugins/*` and `external/*`; dependencies preinstall the common `@koishi-ce` plugin set (console, config, market, auth, admin, help, sandbox, database-sqlite, etc.) plus the four npm-alias lines pinning the upstream names (`koishi` / `@koishijs/core` / `@koishijs/loader` to `@koishi-ce/koishi-shim`, `@koishijs/plugin-console` to `@koishi-ce/console-shim`), so community plugins all resolve to the CE framework.
70
70
  - **koishi.yml** — grouped prewrites for server (ports 5140-5149), basic, console (auto-open, market pointed at the registry.koishi.chat mirror), storage, adapter and develop (HMR in development mode); official adapter plugins are prewritten as `~`-disabled entries without being installed — enable them in the console after installing; the database works out of the box (`database-sqlite` enabled by default), while other official databases (mongo / mysql / postgres, ...) leave no placeholder entries and appear automatically once installed from the market.
71
- - **Toolchain** — devDependencies include `@koishi-ce/client`, `@koishi-ce/plugin-hmr` and `@koishi-ce/scripts` (`koishi-scripts setup` scaffolds further plugin projects under external/).
71
+ - **Toolchain** — devDependencies include `@koishi-ce/client`, `@koishi-ce/console-app` (the host SPA source serving as the devMode vite root), `@koishi-ce/console-builder` (the Vite dev server behind the console devMode), `@koishi-ce/plugin-hmr` and `@koishi-ce/scripts` (`koishi-scripts setup` scaffolds further plugin projects under external/).
72
72
 
73
73
  No adapter is preinstalled — official adapters can be installed from the market later, with their peers already pinned by the aliases; the database is covered by the default-enabled `database-sqlite`, and other official databases are equally one market install away.
74
74
 
package/lib/bin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bun
2
- import { t as start } from "./src-D36TrO6G.mjs";
2
+ import { t as start } from "./src-B2UEAnHe.mjs";
3
3
  //#region src/bin.ts
4
4
  /**
5
5
  * create-koishi-ce 的 CLI 可执行入口:shebang 由 rolldown 原样保留到
package/lib/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { a as renderManifest, i as readNpmrcRegistry, n as detectAgent, r as getLocalRegistry, t as start } from "./src-D36TrO6G.mjs";
1
+ import { a as renderManifest, i as readNpmrcRegistry, n as detectAgent, r as getLocalRegistry, t as start } from "./src-B2UEAnHe.mjs";
2
2
  export { detectAgent, getLocalRegistry, readNpmrcRegistry, renderManifest, start };
@@ -1,15 +1,15 @@
1
- import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
1
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { basename, join, relative } from "node:path";
3
3
  import { parseArgs } from "node:util";
4
4
  import * as p from "@clack/prompts";
5
5
  import pc from "picocolors";
6
6
  import { getLocalRegistry, readNpmrcRegistry } from "@koishi-ce/utils";
7
- import { downloadTemplate } from "giget";
7
+ import { tmpdir } from "node:os";
8
8
  //#region package.json
9
9
  var package_default = {
10
10
  name: "create-koishi-ce",
11
11
  description: "Setup a Koishi application",
12
- version: "1.8.0",
12
+ version: "1.9.1",
13
13
  type: "module",
14
14
  main: "./lib/index.mjs",
15
15
  module: "./lib/index.mjs",
@@ -41,8 +41,7 @@ var package_default = {
41
41
  dependencies: {
42
42
  "@clack/prompts": "^1.7.0",
43
43
  "@koishi-ce/utils": "workspace:*",
44
- "picocolors": "^1.1.1",
45
- "giget": "^3.3.1"
44
+ "picocolors": "^1.1.1"
46
45
  },
47
46
  exports: {
48
47
  ".": {
@@ -75,7 +74,7 @@ function renderManifest(source, project, prod) {
75
74
  //#region src/remote.ts
76
75
  /**
77
76
  * 远程模板分支(--template <包名>)的下载-解包-改写全流程:拉取 npm
78
- * registry 包元数据解析目标版本,经 giget 下载 tarball 并解包到目标
77
+ * registry 包元数据解析目标版本,经 Bun.Archive 下载 tarball 并解包到目标
79
78
  * 目录,最后改写 package.json。HttpError 与 RegistryMeta 只在本流程
80
79
  * 消费,就近定义不另立文件;本机 registry 配置探测见 registry.ts。
81
80
  *
@@ -97,9 +96,8 @@ var HttpError = class extends Error {
97
96
  /**
98
97
  * 远程模板下载与解包:
99
98
  * 1. 拉取模板包元数据,按 dist-tags 解析目标版本(ref,默认 latest);
100
- * 2. 下载 tarball 并解包到目标目录(解包走 giget,其按 npm tarball 惯例
101
- * 剥离顶层 package/ 目录,等价于 strip: 1),网络错误统一以 HttpError
102
- * 提示后退出;
99
+ * 2. 下载 tarball 并解包到目标目录(Bun.Archive 负责 tar/gzip 解包,按 npm
100
+ * tarball 惯例剥离顶层 package/ 目录),网络错误统一以 HttpError 提示后退出;
103
101
  * 3. 最后改写 package.json。
104
102
  */
105
103
  async function scaffoldRemote({ registry, template, ref, prod, project, rootDir }) {
@@ -111,19 +109,21 @@ async function scaffoldRemote({ registry, template, ref, prod, project, rootDir
111
109
  if (version === void 0) throw new HttpError(404, `模板 ${template}@${ref} 不存在`);
112
110
  const url = remote.versions[version]?.dist?.tarball;
113
111
  if (url === void 0) throw new HttpError(404, `模板 ${template}@${ref} 不存在`);
114
- await downloadTemplate(template, {
115
- provider: "npm",
116
- providers: { npm: async () => ({
117
- name: template,
118
- version,
119
- tar: async () => {
120
- const tarballRes = await fetch(url);
121
- if (!tarballRes.ok || !tarballRes.body) throw new HttpError(tarballRes.status, tarballRes.statusText);
122
- return tarballRes.body;
123
- }
124
- }) },
125
- dir: rootDir
126
- });
112
+ const tarballRes = await fetch(url);
113
+ if (!tarballRes.ok || !tarballRes.body) throw new HttpError(tarballRes.status, tarballRes.statusText);
114
+ const archive = new Bun.Archive(await tarballRes.blob());
115
+ const tempDir = mkdtempSync(join(tmpdir(), "create-koishi-ce-"));
116
+ try {
117
+ await archive.extract(tempDir);
118
+ const packageDir = join(tempDir, "package");
119
+ if (!existsSync(packageDir)) throw new Error("远程模板归档缺少 package/ 目录");
120
+ for (const entry of readdirSync(packageDir)) renameSync(join(packageDir, entry), join(rootDir, entry));
121
+ } finally {
122
+ rmSync(tempDir, {
123
+ recursive: true,
124
+ force: true
125
+ });
126
+ }
127
127
  } catch (err) {
128
128
  if (!(err instanceof HttpError)) throw err;
129
129
  console.log(`${pc.red("error")} 请求失败:HTTP ${err.status} ${err.statusText}`);
@@ -332,10 +332,12 @@ function baseManifest() {
332
332
  overrides: buildUpstreamOverrides(),
333
333
  devDependencies: {
334
334
  "@koishi-ce/client": "^1.0.0",
335
+ "@koishi-ce/console-app": "^1.0.0",
336
+ "@koishi-ce/console-builder": "^1.0.0",
335
337
  "@koishi-ce/plugin-hmr": "^1.0.0",
336
338
  "@koishi-ce/plugin-mock": "^1.0.0",
337
339
  "@koishi-ce/scripts": "^1.0.0",
338
- "bun-types": "^1.4.0"
340
+ "@types/bun": "^1.4.0"
339
341
  }
340
342
  };
341
343
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "create-koishi-ce",
3
3
  "description": "Setup a Koishi application",
4
- "version": "1.8.0",
4
+ "version": "1.9.1",
5
5
  "type": "module",
6
6
  "main": "./lib/index.mjs",
7
7
  "module": "./lib/index.mjs",
@@ -44,9 +44,8 @@
44
44
  ],
45
45
  "dependencies": {
46
46
  "@clack/prompts": "^1.7.0",
47
- "@koishi-ce/utils": "^1.1.0",
48
- "picocolors": "^1.1.1",
49
- "giget": "^3.3.1"
47
+ "@koishi-ce/utils": "^1.1.1",
48
+ "picocolors": "^1.1.1"
50
49
  },
51
50
  "exports": {
52
51
  ".": {
@@ -18,7 +18,7 @@ import {
18
18
  rmSync,
19
19
  writeFileSync,
20
20
  } from "node:fs";
21
- import { homedir, tmpdir } from "node:os";
21
+ import { tmpdir } from "node:os";
22
22
  import { join } from "node:path";
23
23
  import { tarPack } from "./tar-pack.ts";
24
24
 
@@ -29,7 +29,7 @@ import { tarPack } from "./tar-pack.ts";
29
29
  * 场景(正常 / 元数据 404 / dist-tag 缺失 / tarball 404 / tarball 损坏);
30
30
  * tarball 由 __tests__/tar-pack.ts 的 tarPack 打包(ustar + gzip,与真实
31
31
  * npm tarball 同构),scaffoldRemote 的下载-解包-改写全链路真实执行
32
- * (解包走 giget,含超长名 pax 条目的端到端验证)。
32
+ * (解包走 Bun.Archive,含超长名 pax 条目的端到端验证)。
33
33
  *
34
34
  * 覆盖率口径说明:bun 的覆盖率对同一路径的多个 query 实例只统计最后
35
35
  * 求值的那份,本文件是 koishi-create 全部测试中最后加载的实例,因此
@@ -180,7 +180,7 @@ beforeAll(async () => {
180
180
  },
181
181
  {
182
182
  // 124 字符 > ustar 的 100 字节 name 上限:tarPack 前置 pax
183
- // 扩展头,giget(tar 库)经 pax 还原后同样能正确落盘
183
+ // 扩展头,Bun.Archive 经 pax 还原后同样能正确落盘
184
184
  path: `package/${longName}.txt`,
185
185
  data: encoder.encode("pax"),
186
186
  },
@@ -203,19 +203,6 @@ function reset(sc: typeof scenario): void {
203
203
  recursive: true,
204
204
  force: true,
205
205
  });
206
- // giget 缓存位置随平台而异(win32 为 tmpdir()/giget,POSIX 跟随
207
- // XDG_CACHE_HOME——默认 ~/.cache);逐用例清理,避免上一场景的缓存
208
- // (tarball-404 的缺失或 corrupt 的损坏归档)被 giget 的
209
- // 「下载失败回退缓存」吞掉
210
- const cacheRoot =
211
- process.env["XDG_CACHE_HOME"] ??
212
- join(homedir(), ".cache");
213
- for (const dir of [
214
- join(tmpdir(), "giget"),
215
- join(cacheRoot, "giget"),
216
- ]) {
217
- rmSync(dir, { recursive: true, force: true });
218
- }
219
206
  }
220
207
 
221
208
  describe("create-koishi-ce 远程模板", () => {
@@ -224,7 +211,7 @@ describe("create-koishi-ce 远程模板", () => {
224
211
  await start();
225
212
  const dir = join(workspaceRoot, "myapp");
226
213
  expect(existsSync(join(dir, "index.js"))).toBe(true);
227
- // 超长名文件经 pax 扩展头正常落盘(tarPack 打包 → giget 解包全链路)
214
+ // 超长名文件经 pax 扩展头正常落盘(tarPack 打包 → Bun.Archive 解包全链路)
228
215
  expect(
229
216
  readFileSync(join(dir, `${longName}.txt`), "utf8"),
230
217
  ).toBe("pax");
@@ -4,10 +4,10 @@
4
4
  /**
5
5
  * 测试专用 .tgz fixture 构造器(ustar + 超长名 pax 兜底 + gzip)。
6
6
  *
7
- * 生产代码的远程模板解包已改走 giget(见 src/index.ts scaffoldRemote),
7
+ * 生产代码的远程模板解包已改走 Bun.Archive(见 src/index.ts scaffoldRemote),
8
8
  * 这里只保留「打包」一侧供测试构造伪 registry 的 tarball 响应。tar
9
9
  * 归档格式稳定,此工具不随业务演进,故不再单独维护解析逻辑与单测
10
- * ——其正确性由 __tests__/run-remote.test.ts 的「打包 → giget 解包」
10
+ * ——其正确性由 __tests__/run-remote.test.ts 的「打包 → Bun.Archive 解包」
11
11
  * 端到端链路间接验证。
12
12
  */
13
13
 
@@ -29,7 +29,7 @@ test("内置模板依赖纯度:不含任何 @koishijs / koishi-plugin 官方
29
29
  }
30
30
  for (const key of Object.keys(devDependencies ?? {})) {
31
31
  expect(
32
- key === "bun-types" || key.startsWith("@koishi-ce/"),
32
+ key === "@types/bun" || key.startsWith("@koishi-ce/"),
33
33
  ).toBe(true);
34
34
  }
35
35
  });
package/src/remote.ts CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  /**
5
5
  * 远程模板分支(--template <包名>)的下载-解包-改写全流程:拉取 npm
6
- * registry 包元数据解析目标版本,经 giget 下载 tarball 并解包到目标
6
+ * registry 包元数据解析目标版本,经 Bun.Archive 下载 tarball 并解包到目标
7
7
  * 目录,最后改写 package.json。HttpError 与 RegistryMeta 只在本流程
8
8
  * 消费,就近定义不另立文件;本机 registry 配置探测见 registry.ts。
9
9
  *
@@ -12,9 +12,17 @@
12
12
  * 经 RemoteOptions 显式传入,由 index.ts 的 scaffold 组装,避免子模块
13
13
  * 与顶层状态的隐式耦合。
14
14
  */
15
- import { readFileSync, writeFileSync } from "node:fs";
15
+ import {
16
+ existsSync,
17
+ mkdtempSync,
18
+ readdirSync,
19
+ readFileSync,
20
+ renameSync,
21
+ rmSync,
22
+ writeFileSync,
23
+ } from "node:fs";
24
+ import { tmpdir } from "node:os";
16
25
  import { join } from "node:path";
17
- import { downloadTemplate } from "giget";
18
26
  import pc from "picocolors";
19
27
  import {
20
28
  type Manifest,
@@ -57,9 +65,8 @@ interface RemoteOptions {
57
65
  /**
58
66
  * 远程模板下载与解包:
59
67
  * 1. 拉取模板包元数据,按 dist-tags 解析目标版本(ref,默认 latest);
60
- * 2. 下载 tarball 并解包到目标目录(解包走 giget,其按 npm tarball 惯例
61
- * 剥离顶层 package/ 目录,等价于 strip: 1),网络错误统一以 HttpError
62
- * 提示后退出;
68
+ * 2. 下载 tarball 并解包到目标目录(Bun.Archive 负责 tar/gzip 解包,按 npm
69
+ * tarball 惯例剥离顶层 package/ 目录),网络错误统一以 HttpError 提示后退出;
63
70
  * 3. 最后改写 package.json。
64
71
  */
65
72
  export async function scaffoldRemote({
@@ -93,30 +100,34 @@ export async function scaffoldRemote({
93
100
  );
94
101
  }
95
102
 
96
- // 解包交给 giget:provider 的 tar 字段是函数,giget 需要时才发起
97
- // 下载(HttpError 在下载阶段抛出,不经 giget 包装可直接识别);
98
- // giget 先把 tarball 落入本地缓存再解压到 rootDir,解压失败
99
- // (gzip 损坏 / 归档截断)走下方非 HttpError 分支原样上抛。
100
- await downloadTemplate(template, {
101
- provider: "npm",
102
- providers: {
103
- npm: async () => ({
104
- name: template,
105
- version,
106
- tar: async () => {
107
- const tarballRes = await fetch(url);
108
- if (!tarballRes.ok || !tarballRes.body) {
109
- throw new HttpError(
110
- tarballRes.status,
111
- tarballRes.statusText,
112
- );
113
- }
114
- return tarballRes.body;
115
- },
116
- }),
117
- },
118
- dir: rootDir,
119
- });
103
+ const tarballRes = await fetch(url);
104
+ if (!tarballRes.ok || !tarballRes.body) {
105
+ throw new HttpError(
106
+ tarballRes.status,
107
+ tarballRes.statusText,
108
+ );
109
+ }
110
+ const archive = new Bun.Archive(
111
+ await tarballRes.blob(),
112
+ );
113
+ const tempDir = mkdtempSync(
114
+ join(tmpdir(), "create-koishi-ce-"),
115
+ );
116
+ try {
117
+ await archive.extract(tempDir);
118
+ const packageDir = join(tempDir, "package");
119
+ if (!existsSync(packageDir)) {
120
+ throw new Error("远程模板归档缺少 package/ 目录");
121
+ }
122
+ for (const entry of readdirSync(packageDir)) {
123
+ renameSync(
124
+ join(packageDir, entry),
125
+ join(rootDir, entry),
126
+ );
127
+ }
128
+ } finally {
129
+ rmSync(tempDir, { recursive: true, force: true });
130
+ }
120
131
  } catch (err) {
121
132
  if (!(err instanceof HttpError)) throw err;
122
133
  console.log(
@@ -1,16 +1,23 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "module": "ESNext",
5
- "moduleResolution": "bundler",
6
- "lib": ["ESNext"],
7
- "types": ["bun-types"],
8
- "strict": true,
9
- "skipLibCheck": true,
10
- "noEmit": true,
11
- "allowImportingTsExtensions": true,
12
- "verbatimModuleSyntax": true,
13
- "erasableSyntaxOnly": true
14
- },
15
- "include": ["plugins/*/src", "external/*/src"]
16
- }
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": [
7
+ "ESNext"
8
+ ],
9
+ "types": [
10
+ "bun"
11
+ ],
12
+ "strict": true,
13
+ "skipLibCheck": true,
14
+ "noEmit": true,
15
+ "allowImportingTsExtensions": true,
16
+ "verbatimModuleSyntax": true,
17
+ "erasableSyntaxOnly": true
18
+ },
19
+ "include": [
20
+ "plugins/*/src",
21
+ "external/*/src"
22
+ ]
23
+ }
package/src/template.ts CHANGED
@@ -274,10 +274,12 @@ export function baseManifest(): Manifest {
274
274
  overrides: buildUpstreamOverrides(),
275
275
  devDependencies: {
276
276
  "@koishi-ce/client": "^1.0.0",
277
+ "@koishi-ce/console-app": "^1.0.0",
278
+ "@koishi-ce/console-builder": "^1.0.0",
277
279
  "@koishi-ce/plugin-hmr": "^1.0.0",
278
280
  "@koishi-ce/plugin-mock": "^1.0.0",
279
281
  "@koishi-ce/scripts": "^1.0.0",
280
- "bun-types": "^1.4.0",
282
+ "@types/bun": "^1.4.0",
281
283
  },
282
284
  };
283
285
  }