qdmp-cli 0.1.18 → 0.1.19

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
@@ -6,6 +6,8 @@
6
6
 
7
7
  使用 Node.js `22.12+`、`24.11+` 或 `26+`,推荐使用最新 LTS 版本。
8
8
 
9
+ 使用 NVM 切换 Node.js 后,请在新版本环境中重新全局安装 `qdmp-cli`,避免继续使用旧版本 Node.js 目录中的依赖。
10
+
9
11
  ## ✨ 功能特性
10
12
  - 项目初始化与模板选择
11
13
  - 用户认证与权限管理
package/actions.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  inquirerAccountPassword,
10
10
  inquirerVersionDescription,
11
11
  } from "./utils/interactive.js";
12
- import { login, getUserInfo } from "./api.js";
12
+ import { login, getDeveloperId, getUserInfo } from "./api.js";
13
13
  import fs from "fs";
14
14
  import path from "path";
15
15
  import { createRequire } from "module";
@@ -21,6 +21,7 @@ import {
21
21
  preUpload,
22
22
  cleanWorkSpaceFolder,
23
23
  } from "./utils/common.js";
24
+ import { assertCompilerRuntime } from "./utils/compilerRuntime.js";
24
25
  import { getAppInfo, uploadVersion, uploadApp } from "./api.js";
25
26
 
26
27
  function createProject(appName, template) {
@@ -105,6 +106,7 @@ export const getMyInfoAction = async (option) => {
105
106
 
106
107
  export async function uploadAction(option) {
107
108
  try {
109
+ const did = await getDeveloperId(option.env);
108
110
  const appId = await getAppId(option.env);
109
111
  if (!appId) {
110
112
  error("未授权应用,请在根目录下qdmp.json配置对应的appId");
@@ -139,7 +141,7 @@ export async function uploadAction(option) {
139
141
  error("上传链接不可用,请检查网络是否正常");
140
142
  }
141
143
  // 更新远端版本信息;
142
- await uploadVersion(appId, url, option.env, description);
144
+ await uploadVersion(appId, url, option.env, description, did);
143
145
  // 清理工作文件夹;
144
146
  await cleanWorkSpaceFolder();
145
147
  success(
@@ -174,20 +176,6 @@ export const initConfigAction = async (option) => {
174
176
  error(e.message);
175
177
  }
176
178
  };
177
- const assertCompilerNodeVersion = (version = process.versions.node) => {
178
- const [major, minor] = version.split(".").map(Number);
179
- const supported =
180
- (major === 22 && minor >= 12) ||
181
- (major === 24 && minor >= 11) ||
182
- major >= 26;
183
-
184
- if (!supported) {
185
- throw new Error(
186
- `当前 Node.js ${version} 不受 EMP 编译器支持,请使用 Node.js 22.12+、24.11+ 或 26+`,
187
- );
188
- }
189
- };
190
-
191
179
  export const buildAction = async () => {
192
180
  try {
193
181
  const qdmpJsonPath = `${process.cwd()}/qdmp.json`;
@@ -198,7 +186,7 @@ export const buildAction = async () => {
198
186
  const config = JSON.parse(fs.readFileSync(qdmpJsonPath, "utf8"));
199
187
  switch (config.loader) {
200
188
  case "EMP":
201
- assertCompilerNodeVersion();
189
+ await assertCompilerRuntime();
202
190
  info("开始构建...");
203
191
  const buildResult = shell.exec("npm run build");
204
192
  if (buildResult.code !== 0) {
package/api.js CHANGED
@@ -104,6 +104,23 @@ export const getUserInfo = async (env = "prod") => {
104
104
  throw new Error(error?.message);
105
105
  }
106
106
  };
107
+
108
+ /**
109
+ * 获取当前开发者 DID
110
+ * @returns {Promise<string>} 开发者 DID
111
+ */
112
+ export const getDeveloperId = async (env = "prod") => {
113
+ try {
114
+ const result = await request("/mp/v1/user/me", {}, env);
115
+ const did = result?.data?.did;
116
+ if (!did) {
117
+ throw new Error("未获取到当前开发者 DID,请重新登录");
118
+ }
119
+ return did;
120
+ } catch (error) {
121
+ throw new Error(error?.message);
122
+ }
123
+ };
107
124
  /**
108
125
  * 获取版本包 PostPolicy 直传凭证
109
126
  * @returns {Promise} PostPolicy 参数
@@ -186,12 +203,14 @@ export const getAppInfo = async (appId, env = "prod") => {
186
203
  * @params {string} downloadUrl - 上传链接
187
204
  * @params {string} env - 环境
188
205
  * @params {string} description - 版本描述
206
+ * @params {string} did - 开发者 DID
189
207
  */
190
208
  export const uploadVersion = async (
191
209
  appId,
192
210
  downloadUrl,
193
211
  env = "prod",
194
212
  description = "",
213
+ did,
195
214
  ) => {
196
215
  try {
197
216
  const normalizedDescription = description.trim();
@@ -208,6 +227,7 @@ export const uploadVersion = async (
208
227
  ...(normalizedDescription
209
228
  ? { description: normalizedDescription }
210
229
  : {}),
230
+ ...(did ? { did } : {}),
211
231
  }),
212
232
  },
213
233
  env
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "qdmp-cli",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "qdmp-cli",
9
- "version": "0.1.18",
9
+ "version": "0.1.19",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
12
  "@dimina/compiler": "1.1.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qdmp-cli",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "qdmp-cli",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -13,7 +13,8 @@
13
13
  "utils/"
14
14
  ],
15
15
  "scripts": {
16
- "test": "echo \"Error: no test specified\" && exit 1"
16
+ "test": "echo \"Error: no test specified\" && exit 1",
17
+ "postinstall": "node utils/compilerRuntime.js"
17
18
  },
18
19
  "bin": {
19
20
  "qdmp": "index.js",
@@ -0,0 +1,45 @@
1
+ import { createRequire } from "node:module";
2
+ import { realpathSync } from "node:fs";
3
+ import { fileURLToPath, pathToFileURL } from "node:url";
4
+
5
+ const supportedNodeVersion = (version) => {
6
+ const [major, minor] = version.split(".").map(Number);
7
+ return (
8
+ (major === 22 && minor >= 12) ||
9
+ (major === 24 && minor >= 11) ||
10
+ major >= 26
11
+ );
12
+ };
13
+
14
+ export const assertCompilerRuntime = async (version = process.versions.node) => {
15
+ if (!supportedNodeVersion(version)) {
16
+ throw new Error(
17
+ `当前 Node.js ${version} 不受 EMP 编译器支持,请先切换到 Node.js 22.12+、24.11+ 或 26+,再重新安装 qdmp-cli`,
18
+ );
19
+ }
20
+
21
+ try {
22
+ const require = createRequire(import.meta.url);
23
+ const compilerRequire = createRequire(require.resolve("@dimina/compiler"));
24
+ const parserPath = compilerRequire.resolve("oxc-parser");
25
+ await import(pathToFileURL(parserPath).href);
26
+ } catch (cause) {
27
+ throw new Error(
28
+ `EMP 编译器原生依赖安装不完整。请在当前 Node.js ${version} 环境下卸载并重新安装 qdmp-cli(npm uninstall -g qdmp-cli && npm install -g qdmp-cli@latest --include=optional)`,
29
+ { cause },
30
+ );
31
+ }
32
+ };
33
+
34
+ const isDirectExecution =
35
+ process.argv[1] &&
36
+ realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
37
+
38
+ if (isDirectExecution) {
39
+ try {
40
+ await assertCompilerRuntime();
41
+ } catch (error) {
42
+ console.error(`qdmp-cli 安装失败:${error.message}`);
43
+ process.exitCode = 1;
44
+ }
45
+ }