@vuepress/utils 2.0.0-beta.49 → 2.0.0-beta.50-pre.1

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.
@@ -0,0 +1,56 @@
1
+ export { default as chalk } from 'chalk';
2
+ export { default as debug } from 'debug';
3
+ export { default as fs } from 'fs-extra';
4
+ export { globby } from 'globby';
5
+ export { default as hash } from 'hash-sum';
6
+ export { default as ora } from 'ora';
7
+ export { default as path } from 'upath';
8
+ import { HeadConfig, HeadAttrsConfig } from '@vuepress/shared';
9
+
10
+ declare const getDirname: (importMetaUrl: string) => string;
11
+
12
+ /**
13
+ * A helper for dynamically importing a file path
14
+ *
15
+ * We need to use `pathToFileURL` to transform file path wo compat with windows
16
+ */
17
+ declare const importFile: <T>(filePath: string) => Promise<T>;
18
+ /**
19
+ * A wrapper of `importFile` and returns the default export
20
+ */
21
+ declare const importFileDefault: <T>(filePath: string) => Promise<T>;
22
+
23
+ /**
24
+ * Check if `child` is a sub path of `parent` or not. Return `true` if
25
+ * they are the same path
26
+ */
27
+ declare const isChildPath: (child: string, parent: string) => boolean;
28
+
29
+ declare const info: (...args: any[]) => void;
30
+ declare const tip: (...args: any[]) => void;
31
+ declare const success: (...args: any[]) => void;
32
+ declare const warn: (...args: any[]) => void;
33
+ declare const error: (...args: any[]) => void;
34
+ declare const createError: (message?: string | undefined) => Error;
35
+ declare const logger: {
36
+ info: (...args: any[]) => void;
37
+ tip: (...args: any[]) => void;
38
+ success: (...args: any[]) => void;
39
+ warn: (...args: any[]) => void;
40
+ error: (...args: any[]) => void;
41
+ createError: (message?: string | undefined) => Error;
42
+ };
43
+
44
+ /**
45
+ * Render head config to string
46
+ */
47
+ declare const renderHead: ([tag, attrs, innerHTML,]: HeadConfig) => string;
48
+
49
+ /**
50
+ * Render head attrs config to string
51
+ */
52
+ declare const renderHeadAttrs: (attrs: HeadAttrsConfig) => string;
53
+
54
+ declare const withSpinner: (msg: string) => <T>(target: () => Promise<T>) => Promise<T>;
55
+
56
+ export { createError, error, getDirname, importFile, importFileDefault, info, isChildPath, logger, renderHead, renderHeadAttrs, success, tip, warn, withSpinner };
package/dist/index.js ADDED
@@ -0,0 +1,120 @@
1
+ // src/index.ts
2
+ import chalk2 from "chalk";
3
+ import debug from "debug";
4
+ import fs from "fs-extra";
5
+ import { globby } from "globby";
6
+ import hash from "hash-sum";
7
+ import ora2 from "ora";
8
+ import path3 from "upath";
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/isChildPath.ts
21
+ import path2 from "upath";
22
+ var isChildPath = (child, parent) => {
23
+ const childPath = path2.normalize(child);
24
+ const parentPath = path2.normalize(parent);
25
+ if (!path2.win32.isAbsolute(childPath) || !path2.win32.isAbsolute(parentPath)) {
26
+ return false;
27
+ }
28
+ const relativePath = path2.relative(parentPath, childPath);
29
+ return relativePath === "" || !relativePath.startsWith("..");
30
+ };
31
+
32
+ // src/logger.ts
33
+ import chalk from "chalk";
34
+ var info = (...args) => {
35
+ console.log(chalk.cyan("info"), ...args);
36
+ };
37
+ var tip = (...args) => {
38
+ console.log(chalk.blue("tip"), ...args);
39
+ };
40
+ var success = (...args) => {
41
+ console.log(chalk.green("success"), ...args);
42
+ };
43
+ var warn = (...args) => {
44
+ console.warn(chalk.yellow("warning"), ...args);
45
+ };
46
+ var error = (...args) => {
47
+ console.error(chalk.red("error"), ...args);
48
+ };
49
+ var createError = (message) => {
50
+ error(message);
51
+ return new Error(message);
52
+ };
53
+ var logger = {
54
+ info,
55
+ tip,
56
+ success,
57
+ warn,
58
+ error,
59
+ createError
60
+ };
61
+
62
+ // src/renderHeadAttrs.ts
63
+ var renderHeadAttrs = (attrs) => Object.entries(attrs).filter((item) => item[1] !== false).map(
64
+ ([key, value]) => value === true ? ` ${key}` : ` ${key}="${attrs[key]}"`
65
+ ).join("");
66
+
67
+ // src/renderHead.ts
68
+ var renderHead = ([
69
+ tag,
70
+ attrs,
71
+ innerHTML = ""
72
+ ]) => {
73
+ const openTag = `<${tag}${renderHeadAttrs(attrs)}>`;
74
+ if (tag === "link" || tag === "meta" || tag === "base") {
75
+ return openTag;
76
+ }
77
+ return `${openTag}${innerHTML}</${tag}>`;
78
+ };
79
+
80
+ // src/withSpinner.ts
81
+ import process from "process";
82
+ import ora from "ora";
83
+ var withSpinner = (msg) => async (target) => {
84
+ if (process.env.DEBUG) {
85
+ return target();
86
+ }
87
+ const spinner = ora();
88
+ try {
89
+ spinner.start(msg);
90
+ const result = await target();
91
+ spinner.succeed(`${msg} - done`);
92
+ return result;
93
+ } catch (e) {
94
+ spinner.fail(`${msg} - failed`);
95
+ throw e;
96
+ }
97
+ };
98
+ export {
99
+ chalk2 as chalk,
100
+ createError,
101
+ debug,
102
+ error,
103
+ fs,
104
+ getDirname,
105
+ globby,
106
+ hash,
107
+ importFile,
108
+ importFileDefault,
109
+ info,
110
+ isChildPath,
111
+ logger,
112
+ ora2 as ora,
113
+ path3 as path,
114
+ renderHead,
115
+ renderHeadAttrs,
116
+ success,
117
+ tip,
118
+ warn,
119
+ withSpinner
120
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vuepress/utils",
3
- "version": "2.0.0-beta.49",
3
+ "version": "2.0.0-beta.50-pre.1",
4
4
  "description": "Utils package of VuePress",
5
5
  "keywords": [
6
6
  "vuepress",
@@ -16,28 +16,48 @@
16
16
  },
17
17
  "license": "MIT",
18
18
  "author": "meteorlxy",
19
- "main": "lib/index.js",
20
- "types": "lib/index.d.ts",
19
+ "type": "module",
20
+ "exports": {
21
+ ".": "./dist/index.js",
22
+ "./package.json": "./package.json"
23
+ },
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
21
26
  "files": [
22
- "lib"
27
+ "dist"
23
28
  ],
24
29
  "dependencies": {
25
30
  "@types/debug": "^4.1.7",
26
31
  "@types/fs-extra": "^9.0.13",
27
- "@vuepress/shared": "2.0.0-beta.49",
28
- "chalk": "^4.1.2",
32
+ "@types/hash-sum": "^1.0.0",
33
+ "@vuepress/shared": "2.0.0-beta.50-pre.1",
34
+ "chalk": "^5.0.1",
29
35
  "debug": "^4.3.4",
30
36
  "fs-extra": "^10.1.0",
31
- "globby": "^11.0.4",
37
+ "globby": "^13.1.2",
32
38
  "hash-sum": "^2.0.0",
33
- "ora": "^5.4.1",
39
+ "ora": "^6.1.2",
34
40
  "upath": "^2.0.1"
35
41
  },
36
42
  "publishConfig": {
37
43
  "access": "public"
38
44
  },
45
+ "tsup": {
46
+ "clean": true,
47
+ "dts": "./src/index.ts",
48
+ "entry": [
49
+ "./src/index.ts"
50
+ ],
51
+ "format": [
52
+ "esm"
53
+ ],
54
+ "outDir": "./dist",
55
+ "sourcemap": false,
56
+ "target": "es2020",
57
+ "tsconfig": "../tsconfig.dts.json"
58
+ },
39
59
  "scripts": {
40
- "build": "tsc -b tsconfig.build.json",
41
- "clean": "rimraf lib *.tsbuildinfo"
60
+ "build": "tsup",
61
+ "clean": "rimraf dist"
42
62
  }
43
63
  }
@@ -1,6 +0,0 @@
1
- /**
2
- * Check if a module is esm with `export default`
3
- */
4
- export declare const hasExportDefault: <T = any>(mod: unknown) => mod is {
5
- default: T;
6
- };
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasExportDefault = void 0;
4
- const shared_1 = require("@vuepress/shared");
5
- /**
6
- * Check if a module is esm with `export default`
7
- */
8
- const hasExportDefault = (mod) => (0, shared_1.isPlainObject)(mod) &&
9
- !!mod.__esModule &&
10
- Object.prototype.hasOwnProperty.call(mod, 'default');
11
- exports.hasExportDefault = hasExportDefault;
package/lib/hash.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare const hash: (val: unknown) => string;
package/lib/hash.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hash = void 0;
4
- const hashSum = require("hash-sum");
5
- exports.hash = hashSum;
package/lib/index.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import * as chalk from 'chalk';
2
- import * as debug from 'debug';
3
- import * as globby from 'globby';
4
- import * as ora from 'ora';
5
- export { debug, chalk, globby, ora };
6
- export * as fs from 'fs-extra';
7
- export * as path from 'upath';
8
- export * from './hasExportDefault';
9
- export * from './hash';
10
- export * from './isChildPath';
11
- export * from './logger';
12
- export * from './renderHead';
13
- export * from './renderHeadAttrs';
14
- export * from './withSpinner';
package/lib/index.js DELETED
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.path = exports.fs = exports.ora = exports.globby = exports.chalk = exports.debug = void 0;
18
- const chalk = require("chalk");
19
- exports.chalk = chalk;
20
- const debug = require("debug");
21
- exports.debug = debug;
22
- const globby = require("globby");
23
- exports.globby = globby;
24
- const ora = require("ora");
25
- exports.ora = ora;
26
- exports.fs = require("fs-extra");
27
- exports.path = require("upath");
28
- __exportStar(require("./hasExportDefault"), exports);
29
- __exportStar(require("./hash"), exports);
30
- __exportStar(require("./isChildPath"), exports);
31
- __exportStar(require("./logger"), exports);
32
- __exportStar(require("./renderHead"), exports);
33
- __exportStar(require("./renderHeadAttrs"), exports);
34
- __exportStar(require("./withSpinner"), exports);
@@ -1,5 +0,0 @@
1
- /**
2
- * Check if `child` is a sub path of `parent` or not. Return `true` if
3
- * they are the same path
4
- */
5
- export declare const isChildPath: (child: string, parent: string) => boolean;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isChildPath = void 0;
4
- const path = require("upath");
5
- /**
6
- * Check if `child` is a sub path of `parent` or not. Return `true` if
7
- * they are the same path
8
- */
9
- const isChildPath = (child, parent) => {
10
- const childPath = path.normalize(child);
11
- const parentPath = path.normalize(parent);
12
- // path.win32.isAbsolute could check both win32 and posix absolute path correctly
13
- if (!path.win32.isAbsolute(childPath) || !path.win32.isAbsolute(parentPath)) {
14
- return false;
15
- }
16
- const relativePath = path.relative(parentPath, childPath);
17
- return relativePath === '' || !relativePath.startsWith('..');
18
- };
19
- exports.isChildPath = isChildPath;
package/lib/logger.d.ts DELETED
@@ -1,14 +0,0 @@
1
- export declare const info: (...args: any[]) => void;
2
- export declare const tip: (...args: any[]) => void;
3
- export declare const success: (...args: any[]) => void;
4
- export declare const warn: (...args: any[]) => void;
5
- export declare const error: (...args: any[]) => void;
6
- export declare const createError: (message?: string | undefined) => Error;
7
- export declare const logger: {
8
- info: (...args: any[]) => void;
9
- tip: (...args: any[]) => void;
10
- success: (...args: any[]) => void;
11
- warn: (...args: any[]) => void;
12
- error: (...args: any[]) => void;
13
- createError: (message?: string | undefined) => Error;
14
- };
package/lib/logger.js DELETED
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logger = exports.createError = exports.error = exports.warn = exports.success = exports.tip = exports.info = void 0;
4
- const chalk = require("chalk");
5
- const info = (...args) => {
6
- console.log(chalk.cyan('info'), ...args);
7
- };
8
- exports.info = info;
9
- const tip = (...args) => {
10
- console.log(chalk.blue('tip'), ...args);
11
- };
12
- exports.tip = tip;
13
- const success = (...args) => {
14
- console.log(chalk.green('success'), ...args);
15
- };
16
- exports.success = success;
17
- const warn = (...args) => {
18
- console.warn(chalk.yellow('warning'), ...args);
19
- };
20
- exports.warn = warn;
21
- const error = (...args) => {
22
- console.error(chalk.red('error'), ...args);
23
- };
24
- exports.error = error;
25
- const createError = (message) => {
26
- (0, exports.error)(message);
27
- return new Error(message);
28
- };
29
- exports.createError = createError;
30
- exports.logger = {
31
- info: exports.info,
32
- tip: exports.tip,
33
- success: exports.success,
34
- warn: exports.warn,
35
- error: exports.error,
36
- createError: exports.createError,
37
- };
@@ -1,5 +0,0 @@
1
- import type { HeadConfig } from '@vuepress/shared';
2
- /**
3
- * Render head config to string
4
- */
5
- export declare const renderHead: ([tag, attrs, innerHTML,]: HeadConfig) => string;
package/lib/renderHead.js DELETED
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.renderHead = void 0;
4
- const renderHeadAttrs_1 = require("./renderHeadAttrs");
5
- /**
6
- * Render head config to string
7
- */
8
- const renderHead = ([tag, attrs, innerHTML = '',]) => {
9
- const openTag = `<${tag}${(0, renderHeadAttrs_1.renderHeadAttrs)(attrs)}>`;
10
- if (tag === 'link' || tag === 'meta' || tag === 'base') {
11
- return openTag;
12
- }
13
- return `${openTag}${innerHTML}</${tag}>`;
14
- };
15
- exports.renderHead = renderHead;
@@ -1,5 +0,0 @@
1
- import type { HeadAttrsConfig } from '@vuepress/shared';
2
- /**
3
- * Render head attrs config to string
4
- */
5
- export declare const renderHeadAttrs: (attrs: HeadAttrsConfig) => string;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.renderHeadAttrs = void 0;
4
- /**
5
- * Render head attrs config to string
6
- */
7
- const renderHeadAttrs = (attrs) => Object.entries(attrs)
8
- .filter((item) => item[1] !== false)
9
- .map(([key, value]) => value === true ? ` ${key}` : ` ${key}="${attrs[key]}"`)
10
- .join('');
11
- exports.renderHeadAttrs = renderHeadAttrs;
@@ -1 +0,0 @@
1
- export declare const withSpinner: (msg: string) => <T>(target: () => Promise<T>) => Promise<T>;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withSpinner = void 0;
4
- const ora = require("ora");
5
- const withSpinner = (msg) => async (target) => {
6
- if (process.env.DEBUG) {
7
- return target();
8
- }
9
- const spinner = ora();
10
- try {
11
- spinner.start(msg);
12
- const result = await target();
13
- spinner.succeed(`${msg} - done`);
14
- return result;
15
- }
16
- catch (e) {
17
- spinner.fail(`${msg} - failed`);
18
- throw e;
19
- }
20
- };
21
- exports.withSpinner = withSpinner;