minecraft-dev-starter 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +35 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minecraft-dev-starter",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "private": false,
5
5
  "description": "DSH plugin that detects Minecraft mod projects and launches the client from the session header, with live logs in the sidebar",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -14,7 +14,13 @@ import { applyTools } from './tools.js'
14
14
  export const name = 'mcdev-host'
15
15
 
16
16
  /** 依赖的宿主服务。 */
17
- export const inject = ['webServer', 'sessions', 'tools']
17
+ /**
18
+ * 必需服务:会话(取工作区)与工具注册表。
19
+ *
20
+ * `webServer` 不在这里——它是可选的(纯 CLI profile 没有 web 层),
21
+ * 由 `apply` 里的 `ctx.inject(['webServer'], …)` 单独等。
22
+ */
23
+ export const inject = ['sessions', 'tools']
18
24
 
19
25
  /** 插件版本;客户端会显示,用来确认两边同一份代码。 */
20
26
  const VERSION = '0.1.0'
@@ -119,9 +125,14 @@ export function apply(ctx, config = {}) {
119
125
  // 面板与模型共用同一套服务;工具只是薄封装(M5)
120
126
  applyTools(ctx, { api })
121
127
 
122
- ctx.effect(
123
- () =>
124
- ctx.webServer.register({
128
+ // webServer 是**可选**的:纯 CLI / headless profile 里没有它,
129
+ // 这时插件应当照常激活(工具可用),只是没有 HTTP 路由。
130
+ // 早期把它写进 inject 会让整个 profile 加载失败("pending: waiting for service")。
131
+ ctx.effect(() => {
132
+ const mount = (scoped) => {
133
+ const webServer = scoped?.webServer
134
+ if (webServer === undefined || typeof webServer.register !== 'function') return undefined
135
+ const dispose = webServer.register({
125
136
  kind: 'prefix',
126
137
  path: '/mcdev/api',
127
138
  handler: async (req, res) => {
@@ -157,9 +168,26 @@ export function apply(ctx, config = {}) {
157
168
  writeJson(res, 500, { ok: false, error: { code: 'internal', message } })
158
169
  }
159
170
  },
160
- }),
161
- 'mcdev: /mcdev/api routes',
162
- )
171
+ })
172
+ console.log('[mcdev] http routes mounted at /mcdev/api')
173
+ return () => {
174
+ try {
175
+ dispose?.()
176
+ } catch {
177
+ /* 已经在卸载 */
178
+ }
179
+ }
180
+ }
181
+
182
+ if (typeof ctx.inject === 'function') {
183
+ return ctx.inject(['webServer'], (scoped) => mount(scoped))
184
+ }
185
+ try {
186
+ return mount(ctx)
187
+ } catch {
188
+ return undefined
189
+ }
190
+ }, 'mcdev: /mcdev/api routes')
163
191
 
164
192
  console.log(`[mcdev] host ready (${VERSION}) — /mcdev/api/{projects.scan,projects.detail,state.info}`)
165
193
  }