minecraft-dev-starter 0.1.1 → 0.1.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/package.json +1 -1
  2. package/src/index.js +18 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minecraft-dev-starter",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
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
@@ -6,6 +6,7 @@
6
6
  * @module minecraft-dev-starter
7
7
  */
8
8
 
9
+ import { readFileSync } from 'node:fs'
9
10
  import { createApi } from './lib/api.js'
10
11
  import { createLaunchService } from './lib/launches.js'
11
12
  import { applyTools } from './tools.js'
@@ -22,8 +23,23 @@ export const name = 'mcdev-host'
22
23
  */
23
24
  export const inject = ['sessions', 'tools']
24
25
 
25
- /** 插件版本;客户端会显示,用来确认两边同一份代码。 */
26
- const VERSION = '0.1.0'
26
+ /**
27
+ * 插件版本;客户端会显示,用来确认两边同一份代码。
28
+ *
29
+ * 从 package.json 读,不再手写——手写的常量在发版后必然忘记同步,
30
+ * 面板上就会出现"装了 0.1.1、显示 0.1.0"的假版本。
31
+ */
32
+ const VERSION = readPackageVersion()
33
+
34
+ /** @returns {string} */
35
+ function readPackageVersion() {
36
+ try {
37
+ const url = new URL('../package.json', import.meta.url)
38
+ return String(JSON.parse(readFileSync(url, 'utf8')).version)
39
+ } catch {
40
+ return '0.0.0-unknown'
41
+ }
42
+ }
27
43
 
28
44
  /**
29
45
  * @param {import('node:http').IncomingMessage} req