qdmp-cli 0.1.18 → 0.1.20

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
@@ -55,13 +55,24 @@ export const request = async (
55
55
  if (response.status === 403) {
56
56
  throw new Error("你没有该小程序的开发权限,请联系管理员开通后重试");
57
57
  }
58
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
58
+
59
+ const responseBody = await response.text();
60
+ let detail = responseBody.trim();
61
+ try {
62
+ const parsedBody = JSON.parse(responseBody);
63
+ detail = parsedBody?.message || parsedBody?.error || detail;
64
+ } catch {
65
+ // 非 JSON 响应直接使用文本内容
66
+ }
67
+
68
+ const status = `HTTP ${response.status}: ${response.statusText}`;
69
+ throw new Error(detail ? `${status} - ${detail}` : status);
59
70
  }
60
71
 
61
72
  const data = await response.json();
62
73
  return data;
63
74
  } catch (error) {
64
- throw new Error(error);
75
+ throw error instanceof Error ? error : new Error(String(error));
65
76
  }
66
77
  };
67
78
 
@@ -104,6 +115,23 @@ export const getUserInfo = async (env = "prod") => {
104
115
  throw new Error(error?.message);
105
116
  }
106
117
  };
118
+
119
+ /**
120
+ * 获取当前开发者 DID
121
+ * @returns {Promise<string>} 开发者 DID
122
+ */
123
+ export const getDeveloperId = async (env = "prod") => {
124
+ try {
125
+ const result = await request("/mp/v1/user/me", {}, env);
126
+ const did = result?.data?.did;
127
+ if (!did) {
128
+ throw new Error("未获取到当前开发者 DID,请重新登录");
129
+ }
130
+ return did;
131
+ } catch (error) {
132
+ throw new Error(error?.message);
133
+ }
134
+ };
107
135
  /**
108
136
  * 获取版本包 PostPolicy 直传凭证
109
137
  * @returns {Promise} PostPolicy 参数
@@ -177,7 +205,7 @@ export const getAppInfo = async (appId, env = "prod") => {
177
205
  const result = await request("/mp/v1/lookup/app/" + appId, {}, env);
178
206
  return result?.data;
179
207
  } catch (error) {
180
- throw new Error(error?.message);
208
+ throw new Error(`获取应用 ${appId} 失败:${error?.message}`);
181
209
  }
182
210
  };
183
211
  /**
@@ -186,12 +214,14 @@ export const getAppInfo = async (appId, env = "prod") => {
186
214
  * @params {string} downloadUrl - 上传链接
187
215
  * @params {string} env - 环境
188
216
  * @params {string} description - 版本描述
217
+ * @params {string} did - 开发者 DID
189
218
  */
190
219
  export const uploadVersion = async (
191
220
  appId,
192
221
  downloadUrl,
193
222
  env = "prod",
194
223
  description = "",
224
+ did,
195
225
  ) => {
196
226
  try {
197
227
  const normalizedDescription = description.trim();
@@ -208,6 +238,7 @@ export const uploadVersion = async (
208
238
  ...(normalizedDescription
209
239
  ? { description: normalizedDescription }
210
240
  : {}),
241
+ ...(did ? { did } : {}),
211
242
  }),
212
243
  },
213
244
  env
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qdmp-cli",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "qdmp-cli",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -9,11 +9,11 @@
9
9
  "api.js",
10
10
  "constants.js",
11
11
  "index.js",
12
- "npm-shrinkwrap.json",
13
12
  "utils/"
14
13
  ],
15
14
  "scripts": {
16
- "test": "echo \"Error: no test specified\" && exit 1"
15
+ "test": "node --test",
16
+ "postinstall": "node utils/compilerRuntime.js"
17
17
  },
18
18
  "bin": {
19
19
  "qdmp": "index.js",
@@ -26,7 +26,7 @@
26
26
  "author": "zhangyanran",
27
27
  "license": "ISC",
28
28
  "dependencies": {
29
- "@dimina/compiler": "1.1.1",
29
+ "@dimina/compiler": "1.0.17",
30
30
  "adm-zip": "^0.5.16",
31
31
  "chalk": "^5.4.1",
32
32
  "commander": "^14.0.0",
@@ -38,6 +38,6 @@
38
38
  "table": "^6.9.0"
39
39
  },
40
40
  "engines": {
41
- "node": "^22.12.0 || ^24.11.0 || >=26.0.0"
41
+ "node": "^20.19.0 || >=22.12.0"
42
42
  }
43
43
  }
@@ -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 === 20 && minor >= 19) ||
9
+ (major === 22 && minor >= 12) ||
10
+ major > 22
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 20.19+ 或 22.12+,再重新安装 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
+ }