提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
2.7 KiB

  1. import { Plugin } from 'vite';
  2. import { StackFrame } from 'error-stack-parser-es';
  3. import { V as ViteInspectOptions } from './shared/vite-plugin-inspect.CtoQ7j4S.mjs';
  4. export { F as FilterPattern } from './shared/vite-plugin-inspect.CtoQ7j4S.mjs';
  5. interface TransformInfo {
  6. name: string;
  7. result?: string;
  8. start: number;
  9. end: number;
  10. order?: string;
  11. sourcemaps?: any;
  12. error?: ParsedError;
  13. }
  14. interface ParsedError {
  15. message: string;
  16. stack: StackFrame[];
  17. raw?: any;
  18. }
  19. interface ModuleInfo {
  20. id: string;
  21. plugins: {
  22. name: string;
  23. transform?: number;
  24. resolveId?: number;
  25. }[];
  26. deps: string[];
  27. importers: string[];
  28. virtual: boolean;
  29. totalTime: number;
  30. invokeCount: number;
  31. sourceSize: number;
  32. distSize: number;
  33. }
  34. type ModulesList = ModuleInfo[];
  35. interface ModuleTransformInfo {
  36. resolvedId: string;
  37. transforms: TransformInfo[];
  38. }
  39. interface PluginMetricInfo {
  40. name: string;
  41. enforce?: string;
  42. transform: {
  43. invokeCount: number;
  44. totalTime: number;
  45. };
  46. resolveId: {
  47. invokeCount: number;
  48. totalTime: number;
  49. };
  50. }
  51. interface ServerMetrics {
  52. middleware?: Record<string, {
  53. name: string;
  54. self: number;
  55. total: number;
  56. }[]>;
  57. }
  58. interface SerializedPlugin {
  59. name: string;
  60. enforce?: string;
  61. resolveId: string;
  62. load: string;
  63. transform: string;
  64. generateBundle: string;
  65. handleHotUpdate: string;
  66. api: string;
  67. }
  68. interface InstanceInfo {
  69. root: string;
  70. /**
  71. * Vite instance ID
  72. */
  73. vite: string;
  74. /**
  75. * Environment names
  76. */
  77. environments: string[];
  78. /**
  79. * Plugins
  80. */
  81. plugins: SerializedPlugin[];
  82. /**
  83. * Environment plugins, the index of the plugin in the `plugins` array
  84. */
  85. environmentPlugins: Record<string, number[]>;
  86. }
  87. interface Metadata {
  88. instances: InstanceInfo[];
  89. embedded?: boolean;
  90. }
  91. interface RpcFunctions {
  92. getMetadata: () => Promise<Metadata>;
  93. getModulesList: (query: QueryEnv) => Promise<ModulesList>;
  94. getModuleTransformInfo: (query: QueryEnv, id: string, clear?: boolean) => Promise<ModuleTransformInfo>;
  95. getPluginMetrics: (query: QueryEnv) => Promise<PluginMetricInfo[]>;
  96. getServerMetrics: (query: QueryEnv) => Promise<ServerMetrics>;
  97. resolveId: (query: QueryEnv, id: string) => Promise<string>;
  98. onModuleUpdated: () => Promise<void>;
  99. }
  100. interface QueryEnv {
  101. /**
  102. * Vite instance ID
  103. */
  104. vite: string;
  105. /**
  106. * Environment name
  107. */
  108. env: string;
  109. }
  110. interface ViteInspectAPI {
  111. rpc: RpcFunctions;
  112. }
  113. declare function PluginInspect(options?: ViteInspectOptions): Plugin;
  114. export { ViteInspectOptions, PluginInspect as default };
  115. export type { ViteInspectAPI };