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.
- package/package.json +1 -1
- package/src/index.js +18 -2
package/package.json
CHANGED
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
|
-
|
|
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
|