@vuepress/utils 2.0.0-rc.30 → 2.0.0-rc.32
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 +28 -51
- package/dist/index.js +11 -22
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -7,80 +7,58 @@ import picomatch from "picomatch";
|
|
|
7
7
|
import * as tinyglobby from "tinyglobby";
|
|
8
8
|
import path from "upath";
|
|
9
9
|
import { HeadAttrsConfig, HeadConfig } from "@vuepress/shared";
|
|
10
|
-
|
|
11
|
-
//#region src/console/formatMs.d.ts
|
|
12
10
|
/**
|
|
13
11
|
* Format millisecond
|
|
14
12
|
*/
|
|
15
|
-
declare const formatMs: (ms: number) => string;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
declare const
|
|
19
|
-
declare const
|
|
20
|
-
declare const
|
|
21
|
-
declare const
|
|
22
|
-
declare const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
error: (...args: unknown[]) => void;
|
|
30
|
-
createError: (message?: string) => Error;
|
|
13
|
+
export declare const formatMs: (ms: number) => string;
|
|
14
|
+
export declare const info: (...args: unknown[]) => void;
|
|
15
|
+
export declare const tip: (...args: unknown[]) => void;
|
|
16
|
+
export declare const success: (...args: unknown[]) => void;
|
|
17
|
+
export declare const warn: (...args: unknown[]) => void;
|
|
18
|
+
export declare const error: (...args: unknown[]) => void;
|
|
19
|
+
export declare const createError: (message?: string) => Error;
|
|
20
|
+
export declare const logger: {
|
|
21
|
+
info: typeof info;
|
|
22
|
+
tip: typeof tip;
|
|
23
|
+
success: typeof success;
|
|
24
|
+
warn: typeof warn;
|
|
25
|
+
error: typeof error;
|
|
26
|
+
createError: typeof createError;
|
|
31
27
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
declare const withSpinner: (msg: string) => <T>(target: (spinner?: Ora) => Promise<T>) => Promise<T>;
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/module/getDirname.d.ts
|
|
37
|
-
declare const getDirname: (importMetaUrl: string) => string;
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region src/module/importFile.d.ts
|
|
28
|
+
export declare const withSpinner: (msg: string) => <T>(target: (spinner?: Ora) => Promise<T>) => Promise<T>;
|
|
29
|
+
export declare const getDirname: (importMetaUrl: string) => string;
|
|
40
30
|
/**
|
|
41
31
|
* A helper for dynamically importing a file path
|
|
42
32
|
*
|
|
43
33
|
* We need to use `pathToFileURL` to transform file path wo compat with windows
|
|
44
34
|
*/
|
|
45
|
-
declare const importFile: <T>(filePath: string) => Promise<T>;
|
|
35
|
+
export declare const importFile: <T>(filePath: string) => Promise<T>;
|
|
46
36
|
/**
|
|
47
37
|
* A wrapper of `importFile` and returns the default export
|
|
48
38
|
*/
|
|
49
|
-
declare const importFileDefault: <T>(filePath: string) => Promise<T>;
|
|
50
|
-
//#endregion
|
|
51
|
-
//#region src/module/isChildPath.d.ts
|
|
39
|
+
export declare const importFileDefault: <T>(filePath: string) => Promise<T>;
|
|
52
40
|
/**
|
|
53
41
|
* Check if `child` is a sub path of `parent` or not. Return `true` if
|
|
54
42
|
* they are the same path
|
|
55
43
|
*/
|
|
56
|
-
declare const isChildPath: (child: string, parent: string) => boolean;
|
|
57
|
-
|
|
58
|
-
//#region src/module/sanitizeFileName.d.ts
|
|
59
|
-
declare const sanitizeFileName: (name: string) => string;
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region src/module/transformPathToFileName.d.ts
|
|
44
|
+
export declare const isChildPath: (child: string, parent: string) => boolean;
|
|
45
|
+
export declare const sanitizeFileName: (name: string) => string;
|
|
62
46
|
/**
|
|
63
47
|
* Transforms a path to a file name, replacing slashes with underscores
|
|
64
48
|
*/
|
|
65
|
-
declare const transformPathToFileName: (rawPath: string) => string;
|
|
66
|
-
//#endregion
|
|
67
|
-
//#region src/ssr/renderHead.d.ts
|
|
49
|
+
export declare const transformPathToFileName: (rawPath: string) => string;
|
|
68
50
|
/**
|
|
69
51
|
* Render head config to string
|
|
70
52
|
*/
|
|
71
|
-
declare const renderHead: ([tag, attrs, innerHTML]: HeadConfig) => string;
|
|
72
|
-
//#endregion
|
|
73
|
-
//#region src/ssr/renderHeadAttrs.d.ts
|
|
53
|
+
export declare const renderHead: ([tag, attrs, innerHTML]: HeadConfig) => string;
|
|
74
54
|
/**
|
|
75
55
|
* Render head attrs config to string
|
|
76
56
|
*/
|
|
77
|
-
declare const renderHeadAttrs: (attrs: HeadAttrsConfig) => string;
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/ssr/templateRenderer.d.ts
|
|
57
|
+
export declare const renderHeadAttrs: (attrs: HeadAttrsConfig) => string;
|
|
80
58
|
/**
|
|
81
59
|
* HTML outlets of the template renderer
|
|
82
60
|
*/
|
|
83
|
-
declare enum TemplateRendererOutlet {
|
|
61
|
+
export declare enum TemplateRendererOutlet {
|
|
84
62
|
Content = "<!--vuepress-ssr-content-->",
|
|
85
63
|
Head = "<!--vuepress-ssr-head-->",
|
|
86
64
|
Lang = "{{ lang }}",
|
|
@@ -93,7 +71,7 @@ declare enum TemplateRendererOutlet {
|
|
|
93
71
|
/**
|
|
94
72
|
* Context type of the template renderer
|
|
95
73
|
*/
|
|
96
|
-
interface TemplateRendererContext {
|
|
74
|
+
export interface TemplateRendererContext {
|
|
97
75
|
/**
|
|
98
76
|
* The rendered page content. Typically to be put inside `<div id="app"></div>`
|
|
99
77
|
*/
|
|
@@ -130,10 +108,9 @@ interface TemplateRendererContext {
|
|
|
130
108
|
/**
|
|
131
109
|
* Type of the template renderer function
|
|
132
110
|
*/
|
|
133
|
-
type TemplateRenderer = (template: string, context: TemplateRendererContext) => Promise<string> | string;
|
|
111
|
+
export type TemplateRenderer = (template: string, context: TemplateRendererContext) => Promise<string> | string;
|
|
134
112
|
/**
|
|
135
113
|
* The default template renderer implementation
|
|
136
114
|
*/
|
|
137
|
-
declare const templateRenderer: TemplateRenderer;
|
|
138
|
-
|
|
139
|
-
export { TemplateRenderer, TemplateRendererContext, TemplateRendererOutlet, colors, createError, debug, error, formatMs, fs, getDirname, hash, importFile, importFileDefault, info, isChildPath, logger, ora, path, picomatch, renderHead, renderHeadAttrs, sanitizeFileName, success, templateRenderer, tinyglobby, tip, transformPathToFileName, warn, withSpinner };
|
|
115
|
+
export declare const templateRenderer: TemplateRenderer;
|
|
116
|
+
export { colors, debug, fs, hash, ora, path, picomatch, tinyglobby };
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import * as tinyglobby from "tinyglobby";
|
|
|
8
8
|
import path, { default as path$1 } from "upath";
|
|
9
9
|
import process from "node:process";
|
|
10
10
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
11
|
-
|
|
11
|
+
// src/console/formatMs.ts
|
|
12
12
|
/**
|
|
13
13
|
* Format millisecond
|
|
14
14
|
*/
|
|
@@ -16,8 +16,7 @@ const formatMs = (ms) => {
|
|
|
16
16
|
if (ms < 1e3) return `${ms}ms`;
|
|
17
17
|
return `${(ms / 1e3).toFixed(2)}s`;
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
//#region src/console/logger.ts
|
|
19
|
+
// src/console/logger.ts
|
|
21
20
|
const info = (...args) => {
|
|
22
21
|
console.log(colors$1.cyan("info"), ...args);
|
|
23
22
|
};
|
|
@@ -45,8 +44,7 @@ const logger = {
|
|
|
45
44
|
error,
|
|
46
45
|
createError
|
|
47
46
|
};
|
|
48
|
-
|
|
49
|
-
//#region src/console/withSpinner.ts
|
|
47
|
+
// src/console/withSpinner.ts
|
|
50
48
|
const withSpinner = (msg) => async (target) => {
|
|
51
49
|
if (process.env.DEBUG) return target();
|
|
52
50
|
const start = Date.now();
|
|
@@ -61,11 +59,9 @@ const withSpinner = (msg) => async (target) => {
|
|
|
61
59
|
throw e;
|
|
62
60
|
}
|
|
63
61
|
};
|
|
64
|
-
|
|
65
|
-
//#region src/module/getDirname.ts
|
|
62
|
+
// src/module/getDirname.ts
|
|
66
63
|
const getDirname = (importMetaUrl) => path$1.dirname(fileURLToPath(importMetaUrl));
|
|
67
|
-
|
|
68
|
-
//#region src/module/importFile.ts
|
|
64
|
+
// src/module/importFile.ts
|
|
69
65
|
/**
|
|
70
66
|
* A helper for dynamically importing a file path
|
|
71
67
|
*
|
|
@@ -76,8 +72,7 @@ const importFile = async (filePath) => import(pathToFileURL(filePath).toString()
|
|
|
76
72
|
* A wrapper of `importFile` and returns the default export
|
|
77
73
|
*/
|
|
78
74
|
const importFileDefault = async (filePath) => importFile(filePath).then((m) => m.default);
|
|
79
|
-
|
|
80
|
-
//#region src/module/isChildPath.ts
|
|
75
|
+
// src/module/isChildPath.ts
|
|
81
76
|
/**
|
|
82
77
|
* Check if `child` is a sub path of `parent` or not. Return `true` if
|
|
83
78
|
* they are the same path
|
|
@@ -89,28 +84,24 @@ const isChildPath = (child, parent) => {
|
|
|
89
84
|
const relativePath = path$1.relative(parentPath, childPath);
|
|
90
85
|
return relativePath === "" || !relativePath.startsWith("..");
|
|
91
86
|
};
|
|
92
|
-
|
|
93
|
-
//#region src/module/sanitizeFileName.ts
|
|
87
|
+
// src/module/sanitizeFileName.ts
|
|
94
88
|
const INVALID_CHAR_REGEX = /[\u0000-\u001F"#$%&*+,:;<=>?[\]^`{|}\u007F]/g;
|
|
95
89
|
const DRIVE_LETTER_REGEX = /^[a-z]:/i;
|
|
96
90
|
const sanitizeFileName = (name) => {
|
|
97
91
|
const driveLetter = DRIVE_LETTER_REGEX.exec(name)?.[0] || "";
|
|
98
92
|
return driveLetter + name.slice(driveLetter.length).replace(INVALID_CHAR_REGEX, "_").replace(/^_+/, "");
|
|
99
93
|
};
|
|
100
|
-
|
|
101
|
-
//#region src/module/transformPathToFileName.ts
|
|
94
|
+
// src/module/transformPathToFileName.ts
|
|
102
95
|
/**
|
|
103
96
|
* Transforms a path to a file name, replacing slashes with underscores
|
|
104
97
|
*/
|
|
105
98
|
const transformPathToFileName = (rawPath) => sanitizeFileName(rawPath.replace(/\//g, "_"));
|
|
106
|
-
|
|
107
|
-
//#region src/ssr/renderHeadAttrs.ts
|
|
99
|
+
// src/ssr/renderHeadAttrs.ts
|
|
108
100
|
/**
|
|
109
101
|
* Render head attrs config to string
|
|
110
102
|
*/
|
|
111
103
|
const renderHeadAttrs = (attrs) => Object.entries(attrs).filter((item) => item[1] !== false).map(([key, value]) => value === true ? ` ${key}` : ` ${key}="${attrs[key]}"`).join("");
|
|
112
|
-
|
|
113
|
-
//#region src/ssr/renderHead.ts
|
|
104
|
+
// src/ssr/renderHead.ts
|
|
114
105
|
/**
|
|
115
106
|
* Render head config to string
|
|
116
107
|
*/
|
|
@@ -119,8 +110,7 @@ const renderHead = ([tag, attrs, innerHTML = ""]) => {
|
|
|
119
110
|
if (tag === "link" || tag === "meta" || tag === "base") return openTag;
|
|
120
111
|
return `${openTag}${innerHTML}</${tag}>`;
|
|
121
112
|
};
|
|
122
|
-
|
|
123
|
-
//#region src/ssr/templateRenderer.ts
|
|
113
|
+
// src/ssr/templateRenderer.ts
|
|
124
114
|
/**
|
|
125
115
|
* HTML outlets of the template renderer
|
|
126
116
|
*/
|
|
@@ -139,5 +129,4 @@ let TemplateRendererOutlet = /* @__PURE__ */ function(TemplateRendererOutlet) {
|
|
|
139
129
|
* The default template renderer implementation
|
|
140
130
|
*/
|
|
141
131
|
const templateRenderer = (template, { content, head, lang, prefetch, preload, scripts, styles, version }) => template.replace("<!--vuepress-ssr-content-->", () => content).replace("<!--vuepress-ssr-head-->", head).replace("{{ lang }}", lang).replace("<!--vuepress-ssr-prefetch-->", prefetch).replace("<!--vuepress-ssr-preload-->", preload).replace("<!--vuepress-ssr-scripts-->", scripts).replace("<!--vuepress-ssr-styles-->", styles).replace("{{ version }}", version);
|
|
142
|
-
//#endregion
|
|
143
132
|
export { TemplateRendererOutlet, colors, createError, debug, error, formatMs, fs, getDirname, hash, importFile, importFileDefault, info, isChildPath, logger, ora, path, picomatch, renderHead, renderHeadAttrs, sanitizeFileName, success, templateRenderer, tinyglobby, tip, transformPathToFileName, warn, withSpinner };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vuepress/utils",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.32",
|
|
4
4
|
"description": "Utils package of VuePress",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"utils",
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
"@types/fs-extra": "^11.0.4",
|
|
36
36
|
"@types/hash-sum": "^1.0.2",
|
|
37
37
|
"@types/picomatch": "^4.0.3",
|
|
38
|
+
"@vuepress/shared": "2.0.0-rc.32",
|
|
38
39
|
"debug": "^4.4.3",
|
|
39
|
-
"fs-extra": "^11.
|
|
40
|
+
"fs-extra": "^11.4.1",
|
|
40
41
|
"hash-sum": "^2.0.0",
|
|
41
|
-
"ora": "^
|
|
42
|
+
"ora": "^10.0.0",
|
|
42
43
|
"picocolors": "^1.1.1",
|
|
43
|
-
"picomatch": "^4.0.
|
|
44
|
-
"tinyglobby": "^0.2.
|
|
45
|
-
"upath": "^3.0.
|
|
46
|
-
"@vuepress/shared": "2.0.0-rc.30"
|
|
44
|
+
"picomatch": "^4.0.7",
|
|
45
|
+
"tinyglobby": "^0.2.17",
|
|
46
|
+
"upath": "^3.0.8"
|
|
47
47
|
},
|
|
48
48
|
"tsdown": {
|
|
49
49
|
"dts": true,
|