@vuepress/utils 2.0.0-beta.50 → 2.0.0-beta.52

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/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { default as debug } from 'debug';
3
3
  export { default as fs } from 'fs-extra';
4
4
  export { globby } from 'globby';
5
5
  export { default as hash } from 'hash-sum';
6
+ import { Ora } from 'ora';
6
7
  export { default as ora } from 'ora';
7
8
  export { default as path } from 'upath';
8
9
  import { HeadConfig, HeadAttrsConfig } from '@vuepress/shared';
@@ -20,6 +21,11 @@ declare const importFile: <T>(filePath: string) => Promise<T>;
20
21
  */
21
22
  declare const importFileDefault: <T>(filePath: string) => Promise<T>;
22
23
 
24
+ /**
25
+ * Format millisecond
26
+ */
27
+ declare const formatMs: (ms: number) => string;
28
+
23
29
  /**
24
30
  * Check if `child` is a sub path of `parent` or not. Return `true` if
25
31
  * they are the same path
@@ -51,6 +57,6 @@ declare const renderHead: ([tag, attrs, innerHTML,]: HeadConfig) => string;
51
57
  */
52
58
  declare const renderHeadAttrs: (attrs: HeadAttrsConfig) => string;
53
59
 
54
- declare const withSpinner: (msg: string) => <T>(target: () => Promise<T>) => Promise<T>;
60
+ declare const withSpinner: (msg: string) => <T>(target: (spinner?: Ora) => Promise<T>) => Promise<T>;
55
61
 
56
- export { createError, error, getDirname, importFile, importFileDefault, info, isChildPath, logger, renderHead, renderHeadAttrs, success, tip, warn, withSpinner };
62
+ export { createError, error, formatMs, getDirname, importFile, importFileDefault, info, isChildPath, logger, renderHead, renderHeadAttrs, success, tip, warn, withSpinner };
package/dist/index.js CHANGED
@@ -17,6 +17,13 @@ import { pathToFileURL } from "url";
17
17
  var importFile = (filePath) => import(pathToFileURL(filePath).toString());
18
18
  var importFileDefault = (filePath) => importFile(filePath).then((m) => m.default);
19
19
 
20
+ // src/formatMs.ts
21
+ var formatMs = (ms) => {
22
+ if (ms < 1e3)
23
+ return `${ms}ms`;
24
+ return `${(ms / 1e3).toFixed(2)}s`;
25
+ };
26
+
20
27
  // src/isChildPath.ts
21
28
  import path2 from "upath";
22
29
  var isChildPath = (child, parent) => {
@@ -84,14 +91,15 @@ var withSpinner = (msg) => async (target) => {
84
91
  if (process.env.DEBUG) {
85
92
  return target();
86
93
  }
94
+ const start = Date.now();
87
95
  const spinner = ora();
88
96
  try {
89
97
  spinner.start(msg);
90
- const result = await target();
91
- spinner.succeed(`${msg} - done`);
98
+ const result = await target(spinner);
99
+ spinner.succeed(`${msg} - done in ${formatMs(Date.now() - start)}`);
92
100
  return result;
93
101
  } catch (e) {
94
- spinner.fail(`${msg} - failed`);
102
+ spinner.fail(`${msg} - failed in ${formatMs(Date.now() - start)}`);
95
103
  throw e;
96
104
  }
97
105
  };
@@ -100,6 +108,7 @@ export {
100
108
  createError,
101
109
  debug,
102
110
  error,
111
+ formatMs,
103
112
  fs,
104
113
  getDirname,
105
114
  globby,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/utils",
3
- "version": "2.0.0-beta.50",
3
+ "version": "2.0.0-beta.52",
4
4
  "description": "Utils package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -30,8 +30,8 @@
30
30
  "@types/debug": "^4.1.7",
31
31
  "@types/fs-extra": "^9.0.13",
32
32
  "@types/hash-sum": "^1.0.0",
33
- "@vuepress/shared": "2.0.0-beta.50",
34
- "chalk": "^5.0.1",
33
+ "@vuepress/shared": "2.0.0-beta.52",
34
+ "chalk": "^5.1.2",
35
35
  "debug": "^4.3.4",
36
36
  "fs-extra": "^10.1.0",
37
37
  "globby": "^13.1.2",