@vuepress/utils 2.0.0-rc.31 → 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 CHANGED
@@ -7,79 +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
- //#region src/console/formatMs.d.ts
11
10
  /**
12
11
  * Format millisecond
13
12
  */
14
- declare const formatMs: (ms: number) => string;
15
- //#endregion
16
- //#region src/console/logger.d.ts
17
- declare const info: (...args: unknown[]) => void;
18
- declare const tip: (...args: unknown[]) => void;
19
- declare const success: (...args: unknown[]) => void;
20
- declare const warn: (...args: unknown[]) => void;
21
- declare const error: (...args: unknown[]) => void;
22
- declare const createError: (message?: string) => Error;
23
- declare const logger: {
24
- info: (...args: unknown[]) => void;
25
- tip: (...args: unknown[]) => void;
26
- success: (...args: unknown[]) => void;
27
- warn: (...args: unknown[]) => void;
28
- error: (...args: unknown[]) => void;
29
- 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;
30
27
  };
31
- //#endregion
32
- //#region src/console/withSpinner.d.ts
33
- declare const withSpinner: (msg: string) => <T>(target: (spinner?: Ora) => Promise<T>) => Promise<T>;
34
- //#endregion
35
- //#region src/module/getDirname.d.ts
36
- declare const getDirname: (importMetaUrl: string) => string;
37
- //#endregion
38
- //#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;
39
30
  /**
40
31
  * A helper for dynamically importing a file path
41
32
  *
42
33
  * We need to use `pathToFileURL` to transform file path wo compat with windows
43
34
  */
44
- declare const importFile: <T>(filePath: string) => Promise<T>;
35
+ export declare const importFile: <T>(filePath: string) => Promise<T>;
45
36
  /**
46
37
  * A wrapper of `importFile` and returns the default export
47
38
  */
48
- declare const importFileDefault: <T>(filePath: string) => Promise<T>;
49
- //#endregion
50
- //#region src/module/isChildPath.d.ts
39
+ export declare const importFileDefault: <T>(filePath: string) => Promise<T>;
51
40
  /**
52
41
  * Check if `child` is a sub path of `parent` or not. Return `true` if
53
42
  * they are the same path
54
43
  */
55
- declare const isChildPath: (child: string, parent: string) => boolean;
56
- //#endregion
57
- //#region src/module/sanitizeFileName.d.ts
58
- declare const sanitizeFileName: (name: string) => string;
59
- //#endregion
60
- //#region src/module/transformPathToFileName.d.ts
44
+ export declare const isChildPath: (child: string, parent: string) => boolean;
45
+ export declare const sanitizeFileName: (name: string) => string;
61
46
  /**
62
47
  * Transforms a path to a file name, replacing slashes with underscores
63
48
  */
64
- declare const transformPathToFileName: (rawPath: string) => string;
65
- //#endregion
66
- //#region src/ssr/renderHead.d.ts
49
+ export declare const transformPathToFileName: (rawPath: string) => string;
67
50
  /**
68
51
  * Render head config to string
69
52
  */
70
- declare const renderHead: ([tag, attrs, innerHTML]: HeadConfig) => string;
71
- //#endregion
72
- //#region src/ssr/renderHeadAttrs.d.ts
53
+ export declare const renderHead: ([tag, attrs, innerHTML]: HeadConfig) => string;
73
54
  /**
74
55
  * Render head attrs config to string
75
56
  */
76
- declare const renderHeadAttrs: (attrs: HeadAttrsConfig) => string;
77
- //#endregion
78
- //#region src/ssr/templateRenderer.d.ts
57
+ export declare const renderHeadAttrs: (attrs: HeadAttrsConfig) => string;
79
58
  /**
80
59
  * HTML outlets of the template renderer
81
60
  */
82
- declare enum TemplateRendererOutlet {
61
+ export declare enum TemplateRendererOutlet {
83
62
  Content = "<!--vuepress-ssr-content-->",
84
63
  Head = "<!--vuepress-ssr-head-->",
85
64
  Lang = "{{ lang }}",
@@ -92,7 +71,7 @@ declare enum TemplateRendererOutlet {
92
71
  /**
93
72
  * Context type of the template renderer
94
73
  */
95
- interface TemplateRendererContext {
74
+ export interface TemplateRendererContext {
96
75
  /**
97
76
  * The rendered page content. Typically to be put inside `<div id="app"></div>`
98
77
  */
@@ -129,10 +108,9 @@ interface TemplateRendererContext {
129
108
  /**
130
109
  * Type of the template renderer function
131
110
  */
132
- type TemplateRenderer = (template: string, context: TemplateRendererContext) => Promise<string> | string;
111
+ export type TemplateRenderer = (template: string, context: TemplateRendererContext) => Promise<string> | string;
133
112
  /**
134
113
  * The default template renderer implementation
135
114
  */
136
- declare const templateRenderer: TemplateRenderer;
137
- //#endregion
138
- 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
- //#region src/console/formatMs.ts
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
- //#endregion
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
- //#endregion
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
- //#endregion
65
- //#region src/module/getDirname.ts
62
+ // src/module/getDirname.ts
66
63
  const getDirname = (importMetaUrl) => path$1.dirname(fileURLToPath(importMetaUrl));
67
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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
- //#endregion
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.31",
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.3.6",
40
+ "fs-extra": "^11.4.1",
40
41
  "hash-sum": "^2.0.0",
41
- "ora": "^9.4.1",
42
+ "ora": "^10.0.0",
42
43
  "picocolors": "^1.1.1",
43
- "picomatch": "^4.0.5",
44
+ "picomatch": "^4.0.7",
44
45
  "tinyglobby": "^0.2.17",
45
- "upath": "^3.0.8",
46
- "@vuepress/shared": "2.0.0-rc.31"
46
+ "upath": "^3.0.8"
47
47
  },
48
48
  "tsdown": {
49
49
  "dts": true,