@umijs/utils 4.0.57 → 4.0.59

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.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
20
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
24
 
22
25
  // src/BaseGenerator/generateFile.ts
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
20
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
24
 
22
25
  // src/getDevBanner.ts
@@ -29,26 +32,34 @@ var import_address = __toESM(require("../compiled/address"));
29
32
  var import_chalk = __toESM(require("../compiled/chalk"));
30
33
  var import_strip_ansi = __toESM(require("../compiled/strip-ansi"));
31
34
  var BORDERS = {
32
- TL: import_chalk.default.gray.dim("\u2554"),
33
- TR: import_chalk.default.gray.dim("\u2557"),
34
- BL: import_chalk.default.gray.dim("\u255A"),
35
- BR: import_chalk.default.gray.dim("\u255D"),
36
- V: import_chalk.default.gray.dim("\u2551"),
37
- H_PURE: "\u2550"
35
+ TL: import_chalk.default.gray.dim(""),
36
+ TR: import_chalk.default.gray.dim(""),
37
+ BL: import_chalk.default.gray.dim(""),
38
+ BR: import_chalk.default.gray.dim(""),
39
+ V: import_chalk.default.gray.dim(""),
40
+ H_PURE: ""
38
41
  };
39
42
  function getDevBanner(protocol, host = "0.0.0.0", port, offset = 8) {
40
43
  const header = " App listening at:";
41
- const footer = import_chalk.default.bold(" Now you can open browser with the above addresses\u2191 ");
42
- const local = ` ${import_chalk.default.gray(">")} Local: ${import_chalk.default.green(`${protocol}//${host === "0.0.0.0" ? "localhost" : host}:${port}`)} `;
44
+ const footer = import_chalk.default.bold(
45
+ " Now you can open browser with the above addresses↑ "
46
+ );
47
+ const local = ` ${import_chalk.default.gray(">")} Local: ${import_chalk.default.green(
48
+ `${protocol}//${host === "0.0.0.0" ? "localhost" : host}:${port}`
49
+ )} `;
43
50
  const ip = import_address.default.ip();
44
51
  const network = ` ${import_chalk.default.gray(">")} Network: ${ip ? import_chalk.default.green(`${protocol}//${ip}:${port}`) : import_chalk.default.gray("Not available")} `;
45
- const maxLen = Math.max(...[header, footer, local, network].map((x) => (0, import_strip_ansi.default)(x).length));
52
+ const maxLen = Math.max(
53
+ ...[header, footer, local, network].map((x) => (0, import_strip_ansi.default)(x).length)
54
+ );
46
55
  const beforeLines = [
47
56
  `${BORDERS.TL}${import_chalk.default.gray.dim("".padStart(maxLen, BORDERS.H_PURE))}${BORDERS.TR}`,
48
57
  `${BORDERS.V}${header}${"".padStart(maxLen - header.length)}${BORDERS.V}`,
49
58
  `${BORDERS.V}${local}${"".padStart(maxLen - (0, import_strip_ansi.default)(local).length)}${BORDERS.V}`
50
59
  ];
51
- const mainLine = `${BORDERS.V}${network}${"".padStart(maxLen - (0, import_strip_ansi.default)(network).length)}${BORDERS.V}`;
60
+ const mainLine = `${BORDERS.V}${network}${"".padStart(
61
+ maxLen - (0, import_strip_ansi.default)(network).length
62
+ )}${BORDERS.V}`;
52
63
  const afterLines = [
53
64
  `${BORDERS.V}${"".padStart(maxLen)}${BORDERS.V}`,
54
65
  `${BORDERS.V}${footer}${"".padStart(maxLen - (0, import_strip_ansi.default)(footer).length)}${BORDERS.V}`,
@@ -0,0 +1,47 @@
1
+ export interface ICreateInfo {
2
+ createTime?: string;
3
+ creator?: string;
4
+ creatorEmail?: string;
5
+ createSince?: string;
6
+ }
7
+ export interface IModifyInfo {
8
+ modifyTime?: string;
9
+ modifier?: string;
10
+ modifierEmail?: string;
11
+ modifySince?: string;
12
+ }
13
+ /**
14
+ * 获取文件创建信息
15
+ * @param filePath 文件路径,绝对或相对 .git
16
+ * @param gitDirPath .git路径
17
+ * @returns
18
+ */
19
+ export declare const getFileCreateInfo: (filePath: string, gitDirPath?: string) => Promise<{
20
+ createTime: string | undefined;
21
+ creator: string | undefined;
22
+ creatorEmail: string | undefined;
23
+ createSince: string | undefined;
24
+ } | {
25
+ createTime?: undefined;
26
+ creator?: undefined;
27
+ creatorEmail?: undefined;
28
+ createSince?: undefined;
29
+ }>;
30
+ /**
31
+ * 获取文件最新修改信息
32
+ * @param filePath 文件路径,绝对或相对 .git
33
+ * @param gitDirPath .git路径
34
+ * @returns
35
+ */
36
+ export declare const getFileLastModifyInfo: (filePath: string, gitDirPath?: string) => Promise<{
37
+ modifyTime: string | undefined;
38
+ modifier: string | undefined;
39
+ modifierEmail: string | undefined;
40
+ modifySince: string | undefined;
41
+ } | {
42
+ modifyTime?: undefined;
43
+ modifier?: undefined;
44
+ modifierEmail?: undefined;
45
+ modifySince?: undefined;
46
+ }>;
47
+ export declare const isGitRepo: () => Promise<boolean>;
@@ -0,0 +1,130 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/getFileGitIno.ts
30
+ var getFileGitIno_exports = {};
31
+ __export(getFileGitIno_exports, {
32
+ getFileCreateInfo: () => getFileCreateInfo,
33
+ getFileLastModifyInfo: () => getFileLastModifyInfo,
34
+ isGitRepo: () => isGitRepo
35
+ });
36
+ module.exports = __toCommonJS(getFileGitIno_exports);
37
+ var import_cross_spawn = __toESM(require("../compiled/cross-spawn"));
38
+ var import_execa = require("../compiled/execa");
39
+ var promisifySpawn = (cmd, args, {
40
+ onlyOnce,
41
+ ...rest
42
+ }) => new Promise((resolve, reject) => {
43
+ var _a;
44
+ const cp = (0, import_cross_spawn.default)(cmd, args, rest);
45
+ const error = [];
46
+ const stdout = [];
47
+ (_a = cp.stdout) == null ? void 0 : _a.on("data", (data) => {
48
+ stdout.push(data.toString());
49
+ if (onlyOnce) {
50
+ cp.kill("SIGKILL");
51
+ }
52
+ });
53
+ cp.on("error", (e) => {
54
+ error.push(e.toString());
55
+ });
56
+ cp.on("close", () => {
57
+ if (error.length) {
58
+ reject(error.join(""));
59
+ } else {
60
+ resolve(stdout);
61
+ }
62
+ });
63
+ });
64
+ var getFileCreateInfo = async (filePath, gitDirPath) => {
65
+ try {
66
+ const info = await promisifySpawn(
67
+ "git",
68
+ // time|name|email|since
69
+ ["log", "--reverse", "-1000000", "--pretty='%ad|%an|%ae|%ar'", filePath],
70
+ {
71
+ cwd: gitDirPath,
72
+ onlyOnce: true,
73
+ shell: true
74
+ }
75
+ );
76
+ if (info.length && info[0]) {
77
+ const firstCommit = info[0].slice(0, info[0].indexOf("\n")).split("|");
78
+ return {
79
+ createTime: firstCommit.at(0),
80
+ creator: firstCommit.at(1),
81
+ creatorEmail: firstCommit.at(2),
82
+ createSince: firstCommit.at(3)
83
+ };
84
+ } else {
85
+ return {};
86
+ }
87
+ } catch (err) {
88
+ throw new Error(`get file ${filePath} git info failed`);
89
+ }
90
+ };
91
+ var getFileLastModifyInfo = async (filePath, gitDirPath) => {
92
+ try {
93
+ const info = await promisifySpawn(
94
+ "git",
95
+ ["log", "-1", "--pretty='%ad|%an|%ae|%ar'", filePath],
96
+ {
97
+ cwd: gitDirPath,
98
+ onlyOnce: true,
99
+ shell: true
100
+ }
101
+ );
102
+ if (info.length && info[0]) {
103
+ const firstCommit = info[0].slice(0, info[0].indexOf("\n")).split("|");
104
+ return {
105
+ modifyTime: firstCommit.at(0),
106
+ modifier: firstCommit.at(1),
107
+ modifierEmail: firstCommit.at(2),
108
+ modifySince: firstCommit.at(3)
109
+ };
110
+ } else {
111
+ return {};
112
+ }
113
+ } catch (err) {
114
+ throw new Error(`get file ${filePath} git info failed`);
115
+ }
116
+ };
117
+ var isGitRepo = async () => {
118
+ try {
119
+ const res = await (0, import_execa.execa)("git", ["rev-parse", "--is-inside-work-tree"]);
120
+ return res.stdout.includes("true");
121
+ } catch (e) {
122
+ return false;
123
+ }
124
+ };
125
+ // Annotate the CommonJS export names for ESM import in node:
126
+ 0 && (module.exports = {
127
+ getFileCreateInfo,
128
+ getFileLastModifyInfo,
129
+ isGitRepo
130
+ });
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
20
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
24
 
22
25
  // src/getGitInfo.ts
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
20
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
24
 
22
25
  // src/importLazy.ts
@@ -27,7 +30,9 @@ __export(importLazy_exports, {
27
30
  module.exports = __toCommonJS(importLazy_exports);
28
31
  var import_import_lazy = __toESM(require("../compiled/import-lazy"));
29
32
  function importLazy(moduleName, requireFn) {
30
- const importLazyLocal = (0, import_import_lazy.default)(requireFn || require);
33
+ const importLazyLocal = (0, import_import_lazy.default)(
34
+ requireFn || require
35
+ );
31
36
  return importLazyLocal(moduleName);
32
37
  }
33
38
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.d.ts CHANGED
@@ -38,6 +38,7 @@ import updatePackageJSON from './updatePackageJSON';
38
38
  export * as aliasUtils from './aliasUtils';
39
39
  export * from './getCorejsVersion';
40
40
  export * from './getDevBanner';
41
+ export * as git from './getFileGitIno';
41
42
  export * from './importLazy';
42
43
  export * from './isLocalDev';
43
44
  export * from './isMonorepo';
package/dist/index.js CHANGED
@@ -50,6 +50,7 @@ __export(src_exports, {
50
50
  fsExtra: () => import_fs_extra.default,
51
51
  generateFile: () => import_generateFile.default,
52
52
  getGitInfo: () => import_getGitInfo.default,
53
+ git: () => git,
53
54
  glob: () => import_glob.default,
54
55
  gzipSize: () => gzipSize,
55
56
  installDeps: () => import_installDeps.default,
@@ -111,6 +112,7 @@ var import_updatePackageJSON = __toESM(require("./updatePackageJSON"));
111
112
  var aliasUtils = __toESM(require("./aliasUtils"));
112
113
  __reExport(src_exports, require("./getCorejsVersion"), module.exports);
113
114
  __reExport(src_exports, require("./getDevBanner"), module.exports);
115
+ var git = __toESM(require("./getFileGitIno"));
114
116
  __reExport(src_exports, require("./importLazy"), module.exports);
115
117
  __reExport(src_exports, require("./isLocalDev"), module.exports);
116
118
  __reExport(src_exports, require("./isMonorepo"), module.exports);
@@ -146,6 +148,7 @@ __reExport(src_exports, require("./zod/zod2string"), module.exports);
146
148
  fsExtra,
147
149
  generateFile,
148
150
  getGitInfo,
151
+ git,
149
152
  glob,
150
153
  gzipSize,
151
154
  installDeps,
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
20
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
24
 
22
25
  // src/installDeps.ts
@@ -40,15 +43,18 @@ function installDeps({
40
43
  const devTag = useYarn || usePnpm ? "--D" : "--save-dev";
41
44
  const installDependencies = (deps, npmStr, insStr, devStr) => {
42
45
  console.log(`${npmStr} install dependencies packages:${deps.join(" ")}`);
43
- execa.execaCommandSync([npmStr, insStr, devStr].concat(deps).filter((n) => n).join(" "), {
44
- encoding: "utf8",
45
- cwd,
46
- env: {
47
- ...process.env
48
- },
49
- stderr: "pipe",
50
- stdout: "pipe"
51
- });
46
+ execa.execaCommandSync(
47
+ [npmStr, insStr, devStr].concat(deps).filter((n) => n).join(" "),
48
+ {
49
+ encoding: "utf8",
50
+ cwd,
51
+ env: {
52
+ ...process.env
53
+ },
54
+ stderr: "pipe",
55
+ stdout: "pipe"
56
+ }
57
+ );
52
58
  console.log(`install dependencies packages success`);
53
59
  };
54
60
  if (dependencies) {
package/dist/printHelp.js CHANGED
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
20
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
24
 
22
25
  // src/printHelp.ts
@@ -33,7 +36,9 @@ function exit() {
33
36
  logger.fatal("A complete log of this run can be found in:");
34
37
  logger.fatal(loggerPath);
35
38
  }
36
- logger.fatal("Consider reporting a GitHub issue on https://github.com/umijs/umi/issues");
39
+ logger.fatal(
40
+ "Consider reporting a GitHub issue on https://github.com/umijs/umi/issues"
41
+ );
37
42
  }
38
43
  function runtime(e) {
39
44
  logger.error(e);
@@ -16,7 +16,10 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
20
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
24
 
22
25
  // src/randomColor/randomColor.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/utils",
3
- "version": "4.0.57",
3
+ "version": "4.0.59",
4
4
  "homepage": "https://github.com/umijs/umi/tree/master/packages/utils#readme",
5
5
  "bugs": "https://github.com/umijs/umi/issues",
6
6
  "repository": {
@@ -14,12 +14,6 @@
14
14
  "dist",
15
15
  "compiled"
16
16
  ],
17
- "scripts": {
18
- "build": "umi-scripts father build",
19
- "build:deps": "umi-scripts bundleDeps",
20
- "dev": "umi-scripts father dev",
21
- "test": "umi-scripts jest-turbo"
22
- },
23
17
  "dependencies": {
24
18
  "chokidar": "3.5.3",
25
19
  "pino": "7.11.0"
@@ -132,5 +126,11 @@
132
126
  "@hapi/joi": "$$LOCAL",
133
127
  "tsconfig-paths": "$$LOCAL"
134
128
  }
129
+ },
130
+ "scripts": {
131
+ "build": "umi-scripts father build",
132
+ "build:deps": "umi-scripts bundleDeps",
133
+ "dev": "umi-scripts father dev",
134
+ "test": "umi-scripts jest-turbo"
135
135
  }
136
- }
136
+ }