@vuepress/utils 2.0.0-beta.67 → 2.0.0-beta.68

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
@@ -8,30 +8,11 @@ export { default as colors } from 'picocolors';
8
8
  export { default as path } from 'upath';
9
9
  import { HeadConfig, HeadAttrsConfig } from '@vuepress/shared';
10
10
 
11
- declare const getDirname: (importMetaUrl: string) => string;
12
-
13
- /**
14
- * A helper for dynamically importing a file path
15
- *
16
- * We need to use `pathToFileURL` to transform file path wo compat with windows
17
- */
18
- declare const importFile: <T>(filePath: string) => Promise<T>;
19
- /**
20
- * A wrapper of `importFile` and returns the default export
21
- */
22
- declare const importFileDefault: <T>(filePath: string) => Promise<T>;
23
-
24
11
  /**
25
12
  * Format millisecond
26
13
  */
27
14
  declare const formatMs: (ms: number) => string;
28
15
 
29
- /**
30
- * Check if `child` is a sub path of `parent` or not. Return `true` if
31
- * they are the same path
32
- */
33
- declare const isChildPath: (child: string, parent: string) => boolean;
34
-
35
16
  declare const info: (...args: any[]) => void;
36
17
  declare const tip: (...args: any[]) => void;
37
18
  declare const success: (...args: any[]) => void;
@@ -47,6 +28,29 @@ declare const logger: {
47
28
  createError: (message?: string | undefined) => Error;
48
29
  };
49
30
 
31
+ declare const withSpinner: (msg: string) => <T>(target: (spinner?: Ora) => Promise<T>) => Promise<T>;
32
+
33
+ declare const getDirname: (importMetaUrl: string) => string;
34
+
35
+ /**
36
+ * A helper for dynamically importing a file path
37
+ *
38
+ * We need to use `pathToFileURL` to transform file path wo compat with windows
39
+ */
40
+ declare const importFile: <T>(filePath: string) => Promise<T>;
41
+ /**
42
+ * A wrapper of `importFile` and returns the default export
43
+ */
44
+ declare const importFileDefault: <T>(filePath: string) => Promise<T>;
45
+
46
+ /**
47
+ * Check if `child` is a sub path of `parent` or not. Return `true` if
48
+ * they are the same path
49
+ */
50
+ declare const isChildPath: (child: string, parent: string) => boolean;
51
+
52
+ declare const sanitizeFileName: (name: string) => string;
53
+
50
54
  /**
51
55
  * Render head config to string
52
56
  */
@@ -57,8 +61,63 @@ declare const renderHead: ([tag, attrs, innerHTML,]: HeadConfig) => string;
57
61
  */
58
62
  declare const renderHeadAttrs: (attrs: HeadAttrsConfig) => string;
59
63
 
60
- declare const sanitizeFileName: (name: string) => string;
61
-
62
- declare const withSpinner: (msg: string) => <T>(target: (spinner?: Ora) => Promise<T>) => Promise<T>;
64
+ /**
65
+ * HTML outlets of the template renderer
66
+ */
67
+ declare const TEMPLATE_RENDERER_OUTLETS: {
68
+ CONTENT: string;
69
+ HEAD: string;
70
+ LANG: string;
71
+ PREFETCH: string;
72
+ PRELOAD: string;
73
+ SCRIPTS: string;
74
+ STYLES: string;
75
+ VERSION: string;
76
+ };
77
+ /**
78
+ * Context type of the template renderer
79
+ */
80
+ interface TemplateRendererContext {
81
+ /**
82
+ * The rendered page content. Typically to be put inside `<div id="app"></div>`
83
+ */
84
+ content: string;
85
+ /**
86
+ * The rendered page head. Typically to be put inside `<head></head>`
87
+ */
88
+ head: string;
89
+ /**
90
+ * The language of the page. Typically to be put inside `<html lang="{{ lang }}">`
91
+ */
92
+ lang: string;
93
+ /**
94
+ * The rendered prefetch links. Typically to be put inside `<head></head>`
95
+ */
96
+ prefetch: string;
97
+ /**
98
+ * The rendered preload links. Typically to be put inside `<head></head>`
99
+ */
100
+ preload: string;
101
+ /**
102
+ * The rendered scripts. Typically to be put before `</body>`
103
+ */
104
+ scripts: string;
105
+ /**
106
+ * The rendered styles. Typically to be put inside `<head></head>`
107
+ */
108
+ styles: string;
109
+ /**
110
+ * The version of VuePress
111
+ */
112
+ version: string;
113
+ }
114
+ /**
115
+ * Type of the template renderer function
116
+ */
117
+ type TemplateRenderer = (template: string, context: TemplateRendererContext) => string | Promise<string>;
118
+ /**
119
+ * The default template renderer implementation
120
+ */
121
+ declare const templateRenderer: TemplateRenderer;
63
122
 
64
- export { createError, error, formatMs, getDirname, importFile, importFileDefault, info, isChildPath, logger, renderHead, renderHeadAttrs, sanitizeFileName, success, tip, warn, withSpinner };
123
+ export { TEMPLATE_RENDERER_OUTLETS, TemplateRenderer, TemplateRendererContext, createError, error, formatMs, getDirname, importFile, importFileDefault, info, isChildPath, logger, renderHead, renderHeadAttrs, sanitizeFileName, success, templateRenderer, tip, warn, withSpinner };
package/dist/index.js CHANGED
@@ -7,36 +7,14 @@ import ora2 from "ora";
7
7
  import colors2 from "picocolors";
8
8
  import path3 from "upath";
9
9
 
10
- // src/getDirname.ts
11
- import { fileURLToPath } from "url";
12
- import path from "upath";
13
- var getDirname = (importMetaUrl) => path.dirname(fileURLToPath(importMetaUrl));
14
-
15
- // src/importFile.ts
16
- import { pathToFileURL } from "url";
17
- var importFile = (filePath) => import(pathToFileURL(filePath).toString());
18
- var importFileDefault = (filePath) => importFile(filePath).then((m) => m.default);
19
-
20
- // src/formatMs.ts
10
+ // src/console/formatMs.ts
21
11
  var formatMs = (ms) => {
22
12
  if (ms < 1e3)
23
13
  return `${ms}ms`;
24
14
  return `${(ms / 1e3).toFixed(2)}s`;
25
15
  };
26
16
 
27
- // src/isChildPath.ts
28
- import path2 from "upath";
29
- var isChildPath = (child, parent) => {
30
- const childPath = path2.normalize(child);
31
- const parentPath = path2.normalize(parent);
32
- if (!path2.win32.isAbsolute(childPath) || !path2.win32.isAbsolute(parentPath)) {
33
- return false;
34
- }
35
- const relativePath = path2.relative(parentPath, childPath);
36
- return relativePath === "" || !relativePath.startsWith("..");
37
- };
38
-
39
- // src/logger.ts
17
+ // src/console/logger.ts
40
18
  import colors from "picocolors";
41
19
  var info = (...args) => {
42
20
  console.log(colors.cyan("info"), ...args);
@@ -66,33 +44,7 @@ var logger = {
66
44
  createError
67
45
  };
68
46
 
69
- // src/renderHeadAttrs.ts
70
- var renderHeadAttrs = (attrs) => Object.entries(attrs).filter((item) => item[1] !== false).map(
71
- ([key, value]) => value === true ? ` ${key}` : ` ${key}="${attrs[key]}"`
72
- ).join("");
73
-
74
- // src/renderHead.ts
75
- var renderHead = ([
76
- tag,
77
- attrs,
78
- innerHTML = ""
79
- ]) => {
80
- const openTag = `<${tag}${renderHeadAttrs(attrs)}>`;
81
- if (tag === "link" || tag === "meta" || tag === "base") {
82
- return openTag;
83
- }
84
- return `${openTag}${innerHTML}</${tag}>`;
85
- };
86
-
87
- // src/sanitizeFileName.ts
88
- var INVALID_CHAR_REGEX = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g;
89
- var DRIVE_LETTER_REGEX = /^[a-z]:/i;
90
- var sanitizeFileName = (name) => {
91
- const driveLetter = DRIVE_LETTER_REGEX.exec(name)?.[0] || "";
92
- return driveLetter + name.substring(driveLetter.length).replace(INVALID_CHAR_REGEX, "_").replace(/^_+/, "");
93
- };
94
-
95
- // src/withSpinner.ts
47
+ // src/console/withSpinner.ts
96
48
  import process from "process";
97
49
  import ora from "ora";
98
50
  var withSpinner = (msg) => async (target) => {
@@ -111,7 +63,69 @@ var withSpinner = (msg) => async (target) => {
111
63
  throw e;
112
64
  }
113
65
  };
66
+
67
+ // src/module/getDirname.ts
68
+ import { fileURLToPath } from "url";
69
+ import path from "upath";
70
+ var getDirname = (importMetaUrl) => path.dirname(fileURLToPath(importMetaUrl));
71
+
72
+ // 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);
76
+
77
+ // src/module/isChildPath.ts
78
+ import path2 from "upath";
79
+ var isChildPath = (child, parent) => {
80
+ const childPath = path2.normalize(child);
81
+ const parentPath = path2.normalize(parent);
82
+ if (!path2.win32.isAbsolute(childPath) || !path2.win32.isAbsolute(parentPath)) {
83
+ return false;
84
+ }
85
+ const relativePath = path2.relative(parentPath, childPath);
86
+ return relativePath === "" || !relativePath.startsWith("..");
87
+ };
88
+
89
+ // src/module/sanitizeFileName.ts
90
+ var INVALID_CHAR_REGEX = /[\x00-\x1F\x7F<>*#"{}|^[\]`;?:&=+$,]/g;
91
+ var DRIVE_LETTER_REGEX = /^[a-z]:/i;
92
+ var sanitizeFileName = (name) => {
93
+ const driveLetter = DRIVE_LETTER_REGEX.exec(name)?.[0] || "";
94
+ return driveLetter + name.substring(driveLetter.length).replace(INVALID_CHAR_REGEX, "_").replace(/^_+/, "");
95
+ };
96
+
97
+ // src/ssr/renderHeadAttrs.ts
98
+ var renderHeadAttrs = (attrs) => Object.entries(attrs).filter((item) => item[1] !== false).map(
99
+ ([key, value]) => value === true ? ` ${key}` : ` ${key}="${attrs[key]}"`
100
+ ).join("");
101
+
102
+ // src/ssr/renderHead.ts
103
+ var renderHead = ([
104
+ tag,
105
+ attrs,
106
+ innerHTML = ""
107
+ ]) => {
108
+ const openTag = `<${tag}${renderHeadAttrs(attrs)}>`;
109
+ if (tag === "link" || tag === "meta" || tag === "base") {
110
+ return openTag;
111
+ }
112
+ return `${openTag}${innerHTML}</${tag}>`;
113
+ };
114
+
115
+ // src/ssr/templateRenderer.ts
116
+ var TEMPLATE_RENDERER_OUTLETS = {
117
+ CONTENT: "<!--vuepress-ssr-content-->",
118
+ HEAD: "<!--vuepress-ssr-head-->",
119
+ LANG: "{{ lang }}",
120
+ PREFETCH: "<!--vuepress-ssr-prefetch-->",
121
+ PRELOAD: "<!--vuepress-ssr-preload-->",
122
+ SCRIPTS: "<!--vuepress-ssr-scripts-->",
123
+ STYLES: "<!--vuepress-ssr-styles-->",
124
+ VERSION: "{{ version }}"
125
+ };
126
+ var templateRenderer = (template, { content, head, lang, prefetch, preload, scripts, styles, version }) => template.replace(TEMPLATE_RENDERER_OUTLETS.CONTENT, () => content).replace(TEMPLATE_RENDERER_OUTLETS.HEAD, head).replace(TEMPLATE_RENDERER_OUTLETS.LANG, lang).replace(TEMPLATE_RENDERER_OUTLETS.PREFETCH, prefetch).replace(TEMPLATE_RENDERER_OUTLETS.PRELOAD, preload).replace(TEMPLATE_RENDERER_OUTLETS.SCRIPTS, scripts).replace(TEMPLATE_RENDERER_OUTLETS.STYLES, styles).replace(TEMPLATE_RENDERER_OUTLETS.VERSION, version);
114
127
  export {
128
+ TEMPLATE_RENDERER_OUTLETS,
115
129
  colors2 as colors,
116
130
  createError,
117
131
  debug,
@@ -132,6 +146,7 @@ export {
132
146
  renderHeadAttrs,
133
147
  sanitizeFileName,
134
148
  success,
149
+ templateRenderer,
135
150
  tip,
136
151
  warn,
137
152
  withSpinner
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/utils",
3
- "version": "2.0.0-beta.67",
3
+ "version": "2.0.0-beta.68",
4
4
  "description": "Utils package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -27,17 +27,17 @@
27
27
  "dist"
28
28
  ],
29
29
  "dependencies": {
30
- "@types/debug": "^4.1.8",
31
- "@types/fs-extra": "^11.0.1",
32
- "@types/hash-sum": "^1.0.0",
30
+ "@types/debug": "^4.1.12",
31
+ "@types/fs-extra": "^11.0.4",
32
+ "@types/hash-sum": "^1.0.2",
33
33
  "debug": "^4.3.4",
34
34
  "fs-extra": "^11.1.1",
35
- "globby": "^13.2.2",
35
+ "globby": "^14.0.0",
36
36
  "hash-sum": "^2.0.0",
37
37
  "ora": "^7.0.1",
38
38
  "picocolors": "^1.0.0",
39
39
  "upath": "^2.0.1",
40
- "@vuepress/shared": "2.0.0-beta.67"
40
+ "@vuepress/shared": "2.0.0-beta.68"
41
41
  },
42
42
  "publishConfig": {
43
43
  "access": "public"
@@ -53,7 +53,7 @@
53
53
  ],
54
54
  "outDir": "./dist",
55
55
  "sourcemap": false,
56
- "target": "es2020",
56
+ "target": "es2022",
57
57
  "tsconfig": "../tsconfig.dts.json"
58
58
  },
59
59
  "scripts": {