vite-plugin-performance 2.0.0 → 2.0.2

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.mts CHANGED
@@ -1,33 +1,51 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
+ /**
4
+ * @description Vite 插件 hook 名称
5
+ */
3
6
  type PluginHookName = Extract<keyof Plugin, string>;
7
+ /**
8
+ * @description hook 执行上下文
9
+ */
4
10
  interface HookExecutionContext {
5
11
  pluginName: string;
6
12
  hookName: PluginHookName;
7
13
  args: unknown[];
8
14
  duration: number;
9
15
  }
16
+ /**
17
+ * @description 日志输出函数
18
+ */
10
19
  type HookLogger = (message: string, context: HookExecutionContext) => void;
20
+ /**
21
+ * @description 日志格式化函数
22
+ */
11
23
  type HookFormatter = (context: HookExecutionContext) => string;
24
+ /**
25
+ * @description 自定义计时函数
26
+ */
12
27
  type HookClock = () => number;
13
28
  interface WrapPluginOptions {
14
- /** Wrap only these hooks. Use `all` to wrap every function hook on the plugin. */
29
+ /** 仅包裹这些 hooks;传入 `all` 表示包裹插件上的所有函数 hook。 */
15
30
  hooks?: PluginHookName[] | 'all';
16
- /** Minimum duration (ms) required to log or emit notifications. */
31
+ /** 触发日志/通知的最小耗时(毫秒)。 */
17
32
  threshold?: number;
18
- /** Disable the default logger output. */
33
+ /** 关闭默认日志输出。 */
19
34
  silent?: boolean;
20
- /** Custom logger called with the formatted message. Defaults to `console.log`. */
35
+ /** 自定义日志函数,默认使用 `console.log`。 */
21
36
  logger?: HookLogger;
22
- /** Custom formatter for the log message. */
37
+ /** 自定义日志格式化函数。 */
23
38
  formatter?: HookFormatter;
24
- /** Lifecycle callback invoked after a hook has completed. */
39
+ /** hook 执行完成后的回调。 */
25
40
  onHookExecution?: (context: HookExecutionContext) => void;
26
- /** Provide a custom high-resolution clock implementation. */
41
+ /** 自定义高精度计时函数。 */
27
42
  clock?: HookClock;
28
- /** @deprecated backwards compatibility typo */
43
+ /** @deprecated 兼容旧拼写 */
29
44
  slient?: boolean;
30
45
  }
46
+ /**
47
+ * @description 解析后的插件配置
48
+ */
31
49
  interface ResolvedWrapPluginOptions {
32
50
  hooks: PluginHookName[] | 'all';
33
51
  threshold: number;
@@ -38,9 +56,18 @@ interface ResolvedWrapPluginOptions {
38
56
  clock: HookClock;
39
57
  }
40
58
 
59
+ /**
60
+ * @description 默认需要包裹的插件 hooks
61
+ */
41
62
  declare const DEFAULT_PLUGIN_HOOKS: PluginHookName[];
63
+ /**
64
+ * @description 默认耗时阈值(毫秒)
65
+ */
42
66
  declare const DEFAULT_THRESHOLD = 0;
43
67
 
68
+ /**
69
+ * @description 解析插件配置并补全默认值
70
+ */
44
71
  declare function resolveOptions(options?: Partial<WrapPluginOptions>): ResolvedWrapPluginOptions;
45
72
 
46
73
  declare function wrapPlugin(maybePlugin: Plugin, options?: Partial<WrapPluginOptions>): Plugin;
package/dist/index.d.ts CHANGED
@@ -1,33 +1,51 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
+ /**
4
+ * @description Vite 插件 hook 名称
5
+ */
3
6
  type PluginHookName = Extract<keyof Plugin, string>;
7
+ /**
8
+ * @description hook 执行上下文
9
+ */
4
10
  interface HookExecutionContext {
5
11
  pluginName: string;
6
12
  hookName: PluginHookName;
7
13
  args: unknown[];
8
14
  duration: number;
9
15
  }
16
+ /**
17
+ * @description 日志输出函数
18
+ */
10
19
  type HookLogger = (message: string, context: HookExecutionContext) => void;
20
+ /**
21
+ * @description 日志格式化函数
22
+ */
11
23
  type HookFormatter = (context: HookExecutionContext) => string;
24
+ /**
25
+ * @description 自定义计时函数
26
+ */
12
27
  type HookClock = () => number;
13
28
  interface WrapPluginOptions {
14
- /** Wrap only these hooks. Use `all` to wrap every function hook on the plugin. */
29
+ /** 仅包裹这些 hooks;传入 `all` 表示包裹插件上的所有函数 hook。 */
15
30
  hooks?: PluginHookName[] | 'all';
16
- /** Minimum duration (ms) required to log or emit notifications. */
31
+ /** 触发日志/通知的最小耗时(毫秒)。 */
17
32
  threshold?: number;
18
- /** Disable the default logger output. */
33
+ /** 关闭默认日志输出。 */
19
34
  silent?: boolean;
20
- /** Custom logger called with the formatted message. Defaults to `console.log`. */
35
+ /** 自定义日志函数,默认使用 `console.log`。 */
21
36
  logger?: HookLogger;
22
- /** Custom formatter for the log message. */
37
+ /** 自定义日志格式化函数。 */
23
38
  formatter?: HookFormatter;
24
- /** Lifecycle callback invoked after a hook has completed. */
39
+ /** hook 执行完成后的回调。 */
25
40
  onHookExecution?: (context: HookExecutionContext) => void;
26
- /** Provide a custom high-resolution clock implementation. */
41
+ /** 自定义高精度计时函数。 */
27
42
  clock?: HookClock;
28
- /** @deprecated backwards compatibility typo */
43
+ /** @deprecated 兼容旧拼写 */
29
44
  slient?: boolean;
30
45
  }
46
+ /**
47
+ * @description 解析后的插件配置
48
+ */
31
49
  interface ResolvedWrapPluginOptions {
32
50
  hooks: PluginHookName[] | 'all';
33
51
  threshold: number;
@@ -38,9 +56,18 @@ interface ResolvedWrapPluginOptions {
38
56
  clock: HookClock;
39
57
  }
40
58
 
59
+ /**
60
+ * @description 默认需要包裹的插件 hooks
61
+ */
41
62
  declare const DEFAULT_PLUGIN_HOOKS: PluginHookName[];
63
+ /**
64
+ * @description 默认耗时阈值(毫秒)
65
+ */
42
66
  declare const DEFAULT_THRESHOLD = 0;
43
67
 
68
+ /**
69
+ * @description 解析插件配置并补全默认值
70
+ */
44
71
  declare function resolveOptions(options?: Partial<WrapPluginOptions>): ResolvedWrapPluginOptions;
45
72
 
46
73
  declare function wrapPlugin(maybePlugin: Plugin, options?: Partial<WrapPluginOptions>): Plugin;
package/dist/index.mjs CHANGED
@@ -56,11 +56,28 @@ function isPromiseLike(value) {
56
56
  return typeof value === "object" && value !== null && "then" in value;
57
57
  }
58
58
 
59
- function wrapPlugin(maybePlugin, options) {
60
- const resolvedOptions = resolveOptions(options);
61
- const plugins = ensureArray(maybePlugin);
62
- const wrapped = plugins.map((plugin) => wrapSinglePlugin(plugin, resolvedOptions));
63
- return Array.isArray(maybePlugin) ? wrapped : wrapped[0];
59
+ function resolveHooks(plugin, hooks) {
60
+ if (hooks === "all") {
61
+ return Object.keys(plugin).filter((key) => typeof plugin[key] === "function");
62
+ }
63
+ return [...hooks];
64
+ }
65
+ function reportExecution(params) {
66
+ const { pluginName, hookName, args, start, options } = params;
67
+ const duration = Math.max(0, options.clock() - start);
68
+ const context = {
69
+ pluginName,
70
+ hookName,
71
+ args,
72
+ duration
73
+ };
74
+ if (duration >= options.threshold) {
75
+ if (!options.silent) {
76
+ const message = options.formatter(context);
77
+ options.logger(message, context);
78
+ }
79
+ options.onHookExecution?.(context);
80
+ }
64
81
  }
65
82
  function wrapSinglePlugin(plugin, options) {
66
83
  const wrapped = { ...plugin };
@@ -95,28 +112,11 @@ function wrapSinglePlugin(plugin, options) {
95
112
  }
96
113
  return wrapped;
97
114
  }
98
- function resolveHooks(plugin, hooks) {
99
- if (hooks === "all") {
100
- return Object.keys(plugin).filter((key) => typeof plugin[key] === "function");
101
- }
102
- return [...hooks];
103
- }
104
- function reportExecution(params) {
105
- const { pluginName, hookName, args, start, options } = params;
106
- const duration = Math.max(0, options.clock() - start);
107
- const context = {
108
- pluginName,
109
- hookName,
110
- args,
111
- duration
112
- };
113
- if (duration >= options.threshold) {
114
- if (!options.silent) {
115
- const message = options.formatter(context);
116
- options.logger(message, context);
117
- }
118
- options.onHookExecution?.(context);
119
- }
115
+ function wrapPlugin(maybePlugin, options) {
116
+ const resolvedOptions = resolveOptions(options);
117
+ const plugins = ensureArray(maybePlugin);
118
+ const wrapped = plugins.map((plugin) => wrapSinglePlugin(plugin, resolvedOptions));
119
+ return Array.isArray(maybePlugin) ? wrapped : wrapped[0];
120
120
  }
121
121
 
122
122
  export { DEFAULT_PLUGIN_HOOKS, DEFAULT_THRESHOLD, resolveOptions, wrapPlugin };
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "vite-plugin-performance",
3
3
  "type": "module",
4
- "version": "2.0.0",
5
- "description": "vite-plugin-performance",
4
+ "version": "2.0.2",
5
+ "description": "vite-plugin-performance tools and runtime components for modern WeChat and multi-platform mini-program development.",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
8
+ "homepage": "https://github.com/weapp-vite/weapp-vite#readme",
8
9
  "repository": {
9
10
  "type": "git",
10
11
  "url": "git+https://github.com/weapp-vite/weapp-vite.git",
@@ -13,7 +14,15 @@
13
14
  "bugs": {
14
15
  "url": "https://github.com/weapp-vite/weapp-vite/issues"
15
16
  },
16
- "keywords": [],
17
+ "keywords": [
18
+ "weapp-vite",
19
+ "weapp",
20
+ "wechat",
21
+ "mini-program",
22
+ "miniprogram",
23
+ "vite",
24
+ "runtime"
25
+ ],
17
26
  "sideEffects": false,
18
27
  "exports": {
19
28
  ".": {
@@ -30,12 +39,17 @@
30
39
  "engines": {
31
40
  "node": "^20.19.0 || >=22.12.0"
32
41
  },
42
+ "publishConfig": {
43
+ "access": "public",
44
+ "registry": "https://registry.npmjs.org"
45
+ },
33
46
  "scripts": {
34
47
  "dev": "unbuild --stub",
35
48
  "build:watch": "unbuild --watch --sourcemap",
36
49
  "build": "unbuild",
37
50
  "test": "vitest run",
38
51
  "test:dev": "vitest",
52
+ "typecheck": "tsc --noEmit",
39
53
  "release": "pnpm publish",
40
54
  "lint": "eslint .",
41
55
  "lint:fix": "eslint . --fix"