@vuepress/utils 2.0.0-rc.2 → 2.0.0-rc.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
@@ -5,7 +5,7 @@
5
5
 
6
6
  ## Documentation
7
7
 
8
- https://v2.vuepress.vuejs.org
8
+ https://vuepress.vuejs.org
9
9
 
10
10
  ## License
11
11
 
package/dist/index.d.ts CHANGED
@@ -13,19 +13,19 @@ import { HeadConfig, HeadAttrsConfig } from '@vuepress/shared';
13
13
  */
14
14
  declare const formatMs: (ms: number) => string;
15
15
 
16
- declare const info: (...args: any[]) => void;
17
- declare const tip: (...args: any[]) => void;
18
- declare const success: (...args: any[]) => void;
19
- declare const warn: (...args: any[]) => void;
20
- declare const error: (...args: any[]) => void;
21
- declare const createError: (message?: string | undefined) => Error;
16
+ declare const info: (...args: unknown[]) => void;
17
+ declare const tip: (...args: unknown[]) => void;
18
+ declare const success: (...args: unknown[]) => void;
19
+ declare const warn: (...args: unknown[]) => void;
20
+ declare const error: (...args: unknown[]) => void;
21
+ declare const createError: (message?: string) => Error;
22
22
  declare const logger: {
23
- info: (...args: any[]) => void;
24
- tip: (...args: any[]) => void;
25
- success: (...args: any[]) => void;
26
- warn: (...args: any[]) => void;
27
- error: (...args: any[]) => void;
28
- createError: (message?: string | undefined) => Error;
23
+ info: (...args: unknown[]) => void;
24
+ tip: (...args: unknown[]) => void;
25
+ success: (...args: unknown[]) => void;
26
+ warn: (...args: unknown[]) => void;
27
+ error: (...args: unknown[]) => void;
28
+ createError: (message?: string) => Error;
29
29
  };
30
30
 
31
31
  declare const withSpinner: (msg: string) => <T>(target: (spinner?: Ora) => Promise<T>) => Promise<T>;
@@ -51,6 +51,11 @@ declare const isChildPath: (child: string, parent: string) => boolean;
51
51
 
52
52
  declare const sanitizeFileName: (name: string) => string;
53
53
 
54
+ /**
55
+ * Transforms a path to a file name, replacing slashes with underscores
56
+ */
57
+ declare const transformPathToFileName: (rawPath: string) => string;
58
+
54
59
  /**
55
60
  * Render head config to string
56
61
  */
@@ -114,10 +119,10 @@ interface TemplateRendererContext {
114
119
  /**
115
120
  * Type of the template renderer function
116
121
  */
117
- type TemplateRenderer = (template: string, context: TemplateRendererContext) => string | Promise<string>;
122
+ type TemplateRenderer = (template: string, context: TemplateRendererContext) => Promise<string> | string;
118
123
  /**
119
124
  * The default template renderer implementation
120
125
  */
121
126
  declare const templateRenderer: TemplateRenderer;
122
127
 
123
- export { TEMPLATE_RENDERER_OUTLETS, type TemplateRenderer, type TemplateRendererContext, createError, error, formatMs, getDirname, importFile, importFileDefault, info, isChildPath, logger, renderHead, renderHeadAttrs, sanitizeFileName, success, templateRenderer, tip, warn, withSpinner };
128
+ export { TEMPLATE_RENDERER_OUTLETS, type TemplateRenderer, type TemplateRendererContext, createError, error, formatMs, getDirname, importFile, importFileDefault, info, isChildPath, logger, renderHead, renderHeadAttrs, sanitizeFileName, success, templateRenderer, tip, transformPathToFileName, warn, withSpinner };
package/dist/index.js CHANGED
@@ -9,8 +9,7 @@ import path3 from "upath";
9
9
 
10
10
  // src/console/formatMs.ts
11
11
  var formatMs = (ms) => {
12
- if (ms < 1e3)
13
- return `${ms}ms`;
12
+ if (ms < 1e3) return `${ms}ms`;
14
13
  return `${(ms / 1e3).toFixed(2)}s`;
15
14
  };
16
15
 
@@ -45,7 +44,7 @@ var logger = {
45
44
  };
46
45
 
47
46
  // src/console/withSpinner.ts
48
- import process from "process";
47
+ import process from "node:process";
49
48
  import ora from "ora";
50
49
  var withSpinner = (msg) => async (target) => {
51
50
  if (process.env.DEBUG) {
@@ -65,14 +64,14 @@ var withSpinner = (msg) => async (target) => {
65
64
  };
66
65
 
67
66
  // src/module/getDirname.ts
68
- import { fileURLToPath } from "url";
67
+ import { fileURLToPath } from "node:url";
69
68
  import path from "upath";
70
69
  var getDirname = (importMetaUrl) => path.dirname(fileURLToPath(importMetaUrl));
71
70
 
72
71
  // src/module/importFile.ts
73
- import { pathToFileURL } from "url";
74
- var importFile = (filePath) => import(pathToFileURL(filePath).toString());
75
- var importFileDefault = (filePath) => importFile(filePath).then((m) => m.default);
72
+ import { pathToFileURL } from "node:url";
73
+ var importFile = async (filePath) => import(pathToFileURL(filePath).toString());
74
+ var importFileDefault = async (filePath) => importFile(filePath).then((m) => m.default);
76
75
 
77
76
  // src/module/isChildPath.ts
78
77
  import path2 from "upath";
@@ -87,13 +86,16 @@ var isChildPath = (child, parent) => {
87
86
  };
88
87
 
89
88
  // src/module/sanitizeFileName.ts
90
- var INVALID_CHAR_REGEX = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g;
89
+ var INVALID_CHAR_REGEX = /[\u0000-\u001F"#$%&*+,:;<=>?[\]^`{|}\u007F]/g;
91
90
  var DRIVE_LETTER_REGEX = /^[a-z]:/i;
92
91
  var sanitizeFileName = (name) => {
93
92
  const driveLetter = DRIVE_LETTER_REGEX.exec(name)?.[0] || "";
94
- return driveLetter + name.substring(driveLetter.length).replace(INVALID_CHAR_REGEX, "_").replace(/^_+/, "");
93
+ return driveLetter + name.slice(driveLetter.length).replace(INVALID_CHAR_REGEX, "_").replace(/^_+/, "");
95
94
  };
96
95
 
96
+ // src/module/transformPathToFileName.ts
97
+ var transformPathToFileName = (rawPath) => sanitizeFileName(rawPath.replace(/\//g, "_"));
98
+
97
99
  // src/ssr/renderHeadAttrs.ts
98
100
  var renderHeadAttrs = (attrs) => Object.entries(attrs).filter((item) => item[1] !== false).map(
99
101
  ([key, value]) => value === true ? ` ${key}` : ` ${key}="${attrs[key]}"`
@@ -148,6 +150,7 @@ export {
148
150
  success,
149
151
  templateRenderer,
150
152
  tip,
153
+ transformPathToFileName,
151
154
  warn,
152
155
  withSpinner
153
156
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/utils",
3
- "version": "2.0.0-rc.2",
3
+ "version": "2.0.0-rc.20",
4
4
  "description": "Utils package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -30,14 +30,14 @@
30
30
  "@types/debug": "^4.1.12",
31
31
  "@types/fs-extra": "^11.0.4",
32
32
  "@types/hash-sum": "^1.0.2",
33
- "debug": "^4.3.4",
34
- "fs-extra": "^11.2.0",
35
- "globby": "^14.0.0",
33
+ "debug": "^4.4.0",
34
+ "fs-extra": "^11.3.0",
35
+ "globby": "^14.1.0",
36
36
  "hash-sum": "^2.0.0",
37
- "ora": "^8.0.1",
38
- "picocolors": "^1.0.0",
37
+ "ora": "^8.2.0",
38
+ "picocolors": "^1.1.1",
39
39
  "upath": "^2.0.1",
40
- "@vuepress/shared": "2.0.0-rc.2"
40
+ "@vuepress/shared": "2.0.0-rc.20"
41
41
  },
42
42
  "publishConfig": {
43
43
  "access": "public"