js-code-detector 0.0.26 → 0.0.28

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/dist/cjs/index.js CHANGED
@@ -49,6 +49,7 @@ var import_await_to_js = __toESM(require("await-to-js"));
49
49
  var import_generateGitDiffReport = require("./util/report_util/generateGitDiffReport");
50
50
  var import_parseGitLabDiffUril = require("./util/parseGitLabDiffUril");
51
51
  var import_getRepoSupportFlag = require("./util/shared/getRepoSupportFlag");
52
+ var import_handleExecaError = require("./util/shared/handleExecaError");
52
53
  var gitDiffFileName = "git_diff.txt";
53
54
  var eslintJsonName = "eslint-report.json";
54
55
  var eslintFinalJsonName = "eslint-final-report.json";
@@ -134,8 +135,8 @@ async function getEslintCheckResult(today) {
134
135
  import_utils.logger.info(`${eslintFinalJsonName} 文件生成`);
135
136
  }
136
137
  async function gitDiffDetectByUrl(inputUrl) {
137
- const today = (0, import_dayjs.default)().format("YYYYMDD_HHmmss");
138
- const { gitRepoUrl: gitUrl, targetBranch: branchName, baseBranch } = (0, import_parseGitLabDiffUril.parseGitLabCompareUrl)(inputUrl);
138
+ const today = (0, import_dayjs.default)().format("YYYYMDD_HHmmss") + Math.random().toString(36).slice(-5);
139
+ const { gitRepoUrl: gitUrl, targetBranch: branchName, baseBranch, projectPathPart } = (0, import_parseGitLabDiffUril.parseGitLabCompareUrl)(inputUrl);
139
140
  import_utils.logger.ready("准备生成临时工作目录...");
140
141
  const [err] = await (0, import_await_to_js.default)(import_utils.execa.execa(`rm -rf ${today}`, { shell: "/bin/bash" }));
141
142
  if (err) {
@@ -143,41 +144,53 @@ async function gitDiffDetectByUrl(inputUrl) {
143
144
  }
144
145
  await import_utils.execa.execa(`mkdir -p ${today}`, { shell: "/bin/bash" });
145
146
  import_utils.logger.info("临时目录建立完成");
146
- import_utils.logger.ready(`准备clone源代码到临时目录下的 ${import_constants.TARGET} 文件夹`);
147
- await import_utils.execa.execa(`git clone ${gitUrl} ${today}/${import_constants.TARGET}`, { shell: "/bin/bash" });
148
- import_utils.logger.info("源代码clone完成");
149
- const supportFlag = (0, import_getRepoSupportFlag.getRepoSupportFlag)((0, import_path.join)(process.cwd(), today, import_constants.TARGET, "package.json"));
150
- if (!supportFlag) {
151
- import_utils.logger.error("该项目不支持检测");
147
+ try {
148
+ import_utils.logger.ready(`准备clone ${projectPathPart} 源代码到临时目录下的 ${import_constants.TARGET} 文件夹`);
149
+ let stderr, failed;
150
+ ({ stderr, failed } = await import_utils.execa.execa(`git clone ${gitUrl} ${today}/${import_constants.TARGET}`, { shell: "/bin/bash" }));
151
+ (0, import_handleExecaError.handleExecaError)({ failed, stderr });
152
+ import_utils.logger.info("源代码clone完成");
153
+ const supportFlag = (0, import_getRepoSupportFlag.getRepoSupportFlag)((0, import_path.join)(process.cwd(), today, import_constants.TARGET, "package.json"));
154
+ if (!supportFlag) {
155
+ import_utils.logger.error("该项目不支持检测");
156
+ (0, import_utils.rimraf)((0, import_path.join)(process.cwd(), today), () => {
157
+ import_utils.logger.info("临时目录已删除");
158
+ });
159
+ return;
160
+ }
161
+ import_utils.logger.ready(`准备clone ${projectPathPart} 源代码到临时目录下的 ${import_constants.SOURCE} 文件夹`);
162
+ ({ stderr, failed } = await import_utils.execa.execa(`git clone ${gitUrl} ${today}/${import_constants.SOURCE}`, { shell: "/bin/bash" }));
163
+ (0, import_handleExecaError.handleExecaError)({ failed, stderr });
164
+ import_utils.logger.info("源代码clone完成");
165
+ if (baseBranch !== "master") {
166
+ import_utils.logger.ready("准备切换到基准分支");
167
+ ({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.SOURCE} && git fetch origin ${baseBranch}:${baseBranch} && git checkout ${baseBranch}`, { shell: "/bin/bash" }));
168
+ (0, import_handleExecaError.handleExecaError)({ failed, stderr });
169
+ import_utils.logger.info("源代码切换到基准分支完成");
170
+ }
171
+ import_utils.logger.ready("准备切换到目标分支");
172
+ ({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git fetch origin ${branchName}:${branchName} && git checkout ${branchName}`, { shell: "/bin/bash" }));
173
+ (0, import_handleExecaError.handleExecaError)({ failed, stderr });
174
+ import_utils.logger.info("分支切换完成");
175
+ import_utils.logger.ready("准备生成git_diff.txt文件");
176
+ ({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git diff ${baseBranch}..${branchName} --unified=0 --output=${gitDiffFileName}`, { shell: "/bin/bash" }));
177
+ (0, import_handleExecaError.handleExecaError)({ failed, stderr });
178
+ import_utils.logger.info("git_diff.txt文件生成完成");
179
+ import_utils.logger.wait("准备生成 入口文件");
180
+ ({ stderr, failed } = await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && npx max setup`, { shell: "/bin/bash" }));
181
+ (0, import_handleExecaError.handleExecaError)({ failed, stderr });
182
+ import_utils.logger.info("入口文件 生成完成!");
183
+ import_utils.logger.ready("准备生成报告");
184
+ const res = await (0, import_generateGitDiffReport.generateGitDiffReport)({ targetDirPath: (0, import_path.join)(process.cwd(), today, import_constants.TARGET), generateFile: [] });
185
+ import_utils.logger.info("报告完成");
186
+ return res;
187
+ } catch (error) {
188
+ import_utils.logger.error(error.message);
189
+ } finally {
152
190
  (0, import_utils.rimraf)((0, import_path.join)(process.cwd(), today), () => {
153
191
  import_utils.logger.info("临时目录已删除");
154
192
  });
155
- return;
156
- }
157
- import_utils.logger.ready(`准备clone源代码到临时目录下的 ${import_constants.SOURCE} 文件夹`);
158
- await import_utils.execa.execa(`git clone ${gitUrl} ${today}/${import_constants.SOURCE}`, { shell: "/bin/bash" });
159
- import_utils.logger.info("源代码clone完成");
160
- if (baseBranch !== "master") {
161
- import_utils.logger.ready("准备切换到基准分支");
162
- await import_utils.execa.execa(`cd ${today}/${import_constants.SOURCE} && git fetch origin ${baseBranch}:${baseBranch} && git checkout ${baseBranch}`, { shell: "/bin/bash" });
163
- import_utils.logger.info("源代码切换到基准分支完成");
164
193
  }
165
- import_utils.logger.ready("准备切换到目标分支");
166
- await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git fetch origin ${branchName}:${branchName} && git checkout ${branchName}`, { shell: "/bin/bash" });
167
- import_utils.logger.info("分支切换完成");
168
- import_utils.logger.ready("准备生成git_diff.txt文件");
169
- await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && git diff ${baseBranch}..${branchName} --unified=0 --output=${gitDiffFileName}`, { shell: "/bin/bash" });
170
- import_utils.logger.info("git_diff.txt文件生成完成");
171
- import_utils.logger.wait("准备生成 入口文件");
172
- await import_utils.execa.execa(`cd ${today}/${import_constants.TARGET} && npx max setup`, { shell: "/bin/bash" });
173
- import_utils.logger.info("入口文件 生成完成!");
174
- import_utils.logger.ready("准备生成报告");
175
- const res = await (0, import_generateGitDiffReport.generateGitDiffReport)({ targetDirPath: (0, import_path.join)(process.cwd(), today, import_constants.TARGET), generateFile: [] });
176
- import_utils.logger.info("报告完成");
177
- (0, import_utils.rimraf)((0, import_path.join)(process.cwd(), today), () => {
178
- import_utils.logger.info("临时目录已删除");
179
- });
180
- return res;
181
194
  }
182
195
  // Annotate the CommonJS export names for ESM import in node:
183
196
  0 && (module.exports = {
@@ -203,6 +203,13 @@ var _AstUtil = class {
203
203
  target = { sourcePath: sourceValue, members: [] };
204
204
  importedMember.push(target);
205
205
  }
206
+ if (specifier.type === "ImportNamespaceSpecifier") {
207
+ target.members.push({
208
+ localName: local.name,
209
+ importedName: "*"
210
+ });
211
+ return;
212
+ }
206
213
  target.members.push({
207
214
  localName: local.name,
208
215
  importedName: (imported == null ? void 0 : imported.name) || "default"
@@ -5,6 +5,7 @@
5
5
  * @throws 当输入链接格式不符合要求时抛出错误
6
6
  */
7
7
  export declare function parseGitLabCompareUrl(compareUrl: string): {
8
+ projectPathPart: string;
8
9
  gitRepoUrl: string;
9
10
  baseBranch: string;
10
11
  targetBranch: string;
@@ -51,6 +51,7 @@ function parseGitLabCompareUrl(compareUrl) {
51
51
  const targetBranch = decodeURIComponent(encodedTargetBranch);
52
52
  const gitRepoUrl = `${urlObj.origin}${projectPathPart}.git`;
53
53
  return {
54
+ projectPathPart,
54
55
  gitRepoUrl,
55
56
  baseBranch,
56
57
  targetBranch
@@ -25,10 +25,19 @@ module.exports = __toCommonJS(getRepoSupportFlag_exports);
25
25
  var import_fs = require("fs");
26
26
  function getRepoSupportFlag(jsonPath) {
27
27
  var _a;
28
+ const isExist = (0, import_fs.existsSync)(jsonPath);
29
+ if (!isExist)
30
+ return false;
28
31
  const packageJson = (0, import_fs.readFileSync)(jsonPath, "utf-8");
29
- const packageJsonObj = JSON.parse(packageJson);
30
- const supportFlag = !!((_a = packageJsonObj.dependencies) == null ? void 0 : _a["@umijs/max"]);
31
- return supportFlag;
32
+ if (!packageJson)
33
+ return false;
34
+ try {
35
+ const packageJsonObj = JSON.parse(packageJson);
36
+ const supportFlag = !!((_a = packageJsonObj.dependencies) == null ? void 0 : _a["@umijs/max"]);
37
+ return supportFlag;
38
+ } catch (e) {
39
+ return false;
40
+ }
32
41
  }
33
42
  // Annotate the CommonJS export names for ESM import in node:
34
43
  0 && (module.exports = {
@@ -0,0 +1,4 @@
1
+ export declare function handleExecaError({ failed, stderr }: {
2
+ failed: boolean;
3
+ stderr: string;
4
+ }): void;
@@ -0,0 +1,35 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/util/shared/handleExecaError.ts
20
+ var handleExecaError_exports = {};
21
+ __export(handleExecaError_exports, {
22
+ handleExecaError: () => handleExecaError
23
+ });
24
+ module.exports = __toCommonJS(handleExecaError_exports);
25
+ var import_utils = require("@umijs/utils");
26
+ function handleExecaError({ failed, stderr }) {
27
+ if (failed) {
28
+ import_utils.logger.error(stderr);
29
+ throw new Error(stderr);
30
+ }
31
+ }
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ handleExecaError
35
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-code-detector",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/cjs/index.d.ts",