@kylincloud/flamegraph 0.35.7 → 0.35.8

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/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # @kylincloud/flamegraph
2
2
 
3
- 一个可复用的 **火焰图 / 差分火焰图 React 组件库**,基于 Pyroscope 的 flamegraph 思路进行了工程化封装,方便在任意前端应用中渲染 CPU / 内存等采样型 Profiling 数据。:contentReference[oaicite:1]{index=1}
3
+ 一个可复用的 **火焰图 / 差分火焰图 React 组件库**,基于 Pyroscope 的 flamegraph 思路进行了工程化封装,方便在任意前端应用中渲染 CPU / 内存等采样型 Profiling 数据。
4
4
 
5
5
  > ⚠️ 说明
6
- > 本仓库主要服务于麒麟内部项目(如性能观测 / 智算平台等),API 在 0.x 阶段可能会有不兼容调整,请以当前版本导出的实际 API 为准。
6
+ > 本仓库主要服务于麒麟内部项目(如性能观测 / 智算平台等),API 在 0.x 阶段可能会有不兼容调整,请以当前版本导出的实际 API 为准。
7
+ > 从 `0.35.7` 起,构建方式已切换为 **Rollup + PostCSS + Sass**,并支持自动注入样式。
7
8
 
8
9
  ---
9
10
 
@@ -37,18 +38,19 @@ pnpm add @kylincloud/flamegraph
37
38
  yarn add @kylincloud/flamegraph
38
39
  ````
39
40
 
40
- 本库对 React peer 依赖:
41
+ 本库对 React 及部分基础库有 peer 依赖,请确保工程中已安装并满足版本要求。例如:
41
42
 
42
43
  * `"react": ">=16.14.0"`
43
- * `"react-dom": ">=16.14.0"`
44
-
45
- 确保你的工程中 React 版本满足要求。
44
+ * `"react-dom": ">=16.14.0"`
45
+ * `"graphviz-react": "^1.2.5"`
46
+ * `"true-myth": "^5.1.2"`
47
+ * `"zod": "^3.11.6"`
46
48
 
47
49
  ---
48
50
 
49
51
  ## 3. 快速上手(React 示例)
50
52
 
51
- 当前包的入口文件导出了一些核心组件 / 工具函数 / i18n 能力,形态大致如下:
53
+ 当前包的入口文件导出了一些核心组件 / 工具函数 / i18n 能力,大致包括:
52
54
 
53
55
  * 组件与工具:
54
56
 
@@ -58,6 +60,7 @@ yarn add @kylincloud/flamegraph
58
60
  * `DefaultPalette`
59
61
  * `convertJaegerTraceToProfile`
60
62
  * `diffTwoProfiles`
63
+
61
64
  * i18n 导出:
62
65
 
63
66
  * `flamegraphDefaultMessages`
@@ -65,23 +68,18 @@ yarn add @kylincloud/flamegraph
65
68
  * `FlamegraphI18nProvider`
66
69
  * 类型 `FlamegraphMessages`
67
70
 
68
- ### 3.1 引入样式与组件
71
+ ### 3.1 引入组件(样式自动注入)
69
72
 
70
- 构建后会输出 ESM / CJS 两套 JS 以及对应的 CSS 文件:
73
+ `0.35.7` 起,本库在浏览器入口中会自动导入并注入全局样式:
71
74
 
72
- * `dist/index.esm.js`(ESM,`"module"`)
73
- * `dist/index.cjs.js`(CJS,`"main"`)
74
- * `dist/index.esm.css` / `dist/index.cjs.css`(样式)
75
+ * 源码中 `src/index.tsx` 内部已执行:`import './sass/flamegraph.scss'`
76
+ * Rollup 使用 `rollup-plugin-postcss` 将 Sass 编译为 CSS,并在运行时通过 `<style>` 标签自动注入
75
77
 
76
- 在业务工程中建议按 ESM 方式引入:
78
+ 因此,在业务工程中只需要正常导入组件即可,**无需再单独引入 CSS 文件**:
77
79
 
78
80
  ```tsx
79
81
  import React from 'react'
80
82
 
81
- // 必须:引入打包好的 CSS(推荐使用 ESM 版本)
82
- import '@kylincloud/flamegraph/dist/index.esm.css'
83
-
84
- // 典型用法:只用渲染器
85
83
  import {
86
84
  FlamegraphRenderer,
87
85
  Flamegraph,
@@ -97,15 +95,13 @@ import {
97
95
 
98
96
  > ✅ 提示:
99
97
  >
100
- > * CSS 路径请使用 `dist/index.esm.css` 或 `dist/index.cjs.css`,与当前打包结果一致。
101
- > * 若你的打包器不支持从 `exports` CSS 子路径,可使用显式路径
102
- > `@kylincloud/flamegraph/dist/index.esm.css`。
98
+ > * 对于浏览器端渲染:只要导入任意来自 `@kylincloud/flamegraph` 的组件,样式就会自动注入。
99
+ > * 对于 SSR 场景:Node 侧入口为 `dist/index.node.cjs.js` / `dist/index.node.esm.js`,不会在服务端注入样式,CSS 注入会在浏览器端 hydration 时发生。
103
100
 
104
101
  ### 3.2 最小可用示例:渲染单个 Flamebearer profile
105
102
 
106
103
  ```tsx
107
104
  import React from 'react'
108
- import '@kylincloud/flamegraph/dist/index.esm.css'
109
105
  import { FlamegraphRenderer } from '@kylincloud/flamegraph'
110
106
 
111
107
  const simpleProfile = {
@@ -149,7 +145,6 @@ export default function App() {
149
145
 
150
146
  ```tsx
151
147
  import React from 'react'
152
- import '@kylincloud/flamegraph/dist/index.esm.css'
153
148
  import {
154
149
  FlamegraphRenderer,
155
150
  FlamegraphI18nProvider,
@@ -178,13 +173,13 @@ export default function App() {
178
173
  > ✅ 建议:
179
174
  >
180
175
  > * 将容器高度固定(如 400–800px),避免页面滚动条与内部滚动冲突
181
- > * App 入口处只需引入一次 CSS;组件可在各处复用
176
+ > * App 入口处只需导入一次本库(样式会自动注入);组件可在任何页面复用
182
177
 
183
178
  ---
184
179
 
185
180
  ## 4. 数据格式说明(Flamebearer 简要约定)
186
181
 
187
- 组件默认消费的数据结构与 Pyroscope 的 **Flamebearer** 格式保持兼容,整体上可理解为:
182
+ 组件默认消费的数据结构与 Pyroscope 的 **Flamebearer** 格式保持兼容,可以理解为:
188
183
 
189
184
  ```ts
190
185
  type FlamebearerProfile = {
@@ -251,11 +246,13 @@ type FlamebearerProfile = {
251
246
 
252
247
  ## 6. 样式与主题
253
248
 
254
- * 核心样式文件为:`src/sass/flamegraph.scss`,打包后输出为:
249
+ * 核心样式源文件为:`src/sass/flamegraph.scss`
250
+ * 浏览器入口 `src/index.tsx` 中默认会导入该样式文件:
251
+
252
+ * `import './sass/flamegraph.scss'`
253
+ * Rollup + PostCSS + Sass 会在构建时将其编译为 CSS,并在运行时自动注入 `<style>` 标签,不再额外生成独立的 `dist/index.css` / `dist/index.esm.css` 等文件。
255
254
 
256
- * `dist/index.esm.css`
257
- * `dist/index.cjs.css`
258
- * 打包配置中已将 `*.css` / `*.scss` 标记为 `sideEffects`,确保在使用方构建时不会被错误 Tree-Shaking 掉。
255
+ `package.json` 中已将 `*.css` / `*.scss` 标记为 `sideEffects`,确保在使用方构建时不会被错误 Tree-Shaking 掉。
259
256
 
260
257
  如需与业务系统整体主题统一,可以:
261
258
 
@@ -275,9 +272,10 @@ type FlamebearerProfile = {
275
272
  {
276
273
  "scripts": {
277
274
  "clean": "rm -rf dist",
278
- "build": "pnpm run clean && pnpm run build:types && pnpm run build:js",
275
+ "build": "pnpm run clean && pnpm run build:types && pnpm run build:js && pnpm run build:assets",
279
276
  "build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly",
280
- "build:js": "node scripts/build-esbuild.mjs",
277
+ "build:js": "rollup -c",
278
+ "build:assets": "cp src/logo-v3-small.svg dist/logo-v3-small.svg || true",
281
279
  "type-check": "tsc -p tsconfig.build.json --noEmit",
282
280
  "lint": "eslint ./ --cache --fix"
283
281
  }
@@ -292,18 +290,31 @@ type FlamebearerProfile = {
292
290
 
293
291
  输出:`dist/**/*.d.ts`(由 `tsconfig.build.json` 控制)。
294
292
 
295
- * **构建 JS & CSS**
293
+ * **构建 JS & 样式**
296
294
 
297
295
  ```bash
298
296
  pnpm run build:js
299
297
  ```
300
298
 
301
- 基于 esbuild + sass 插件,将 TSX + Sass 打包成:
299
+ 基于 **Rollup + PostCSS + Sass** 构建,生成:
300
+
301
+ * 浏览器入口:
302
+
303
+ * `dist/index.esm.js`(ESM 入口,对应 `"module"`)
304
+ * `dist/index.cjs.js`(CJS 入口)
305
+ * 内部包含自动注入样式逻辑
306
+ * Node 入口:
307
+
308
+ * `dist/index.node.cjs.js`(CJS,给 Node / SSR 使用)
309
+ * `dist/index.node.esm.js`(ESM)
302
310
 
303
- * `dist/index.esm.js`(ESM 入口,对应 `module`)
304
- * `dist/index.cjs.js`(CJS 入口,对应 `main`)
305
- * `dist/index.esm.css`
306
- * `dist/index.cjs.css`
311
+ * **拷贝静态资源**
312
+
313
+ ```bash
314
+ pnpm run build:assets
315
+ ```
316
+
317
+ 将 `src/logo-v3-small.svg` 拷贝到 `dist/`,以便在组件内部引用。
307
318
 
308
319
  * **完整构建**
309
320
 
@@ -311,7 +322,7 @@ type FlamebearerProfile = {
311
322
  pnpm run build
312
323
  ```
313
324
 
314
- 等价于:清理 `dist` → 生成类型声明 → 生成 JS/CSS。
325
+ 等价于:清理 `dist` → 生成类型声明 → 生成 JS(含样式)→ 拷贝静态资源。
315
326
 
316
327
  * **类型检查**
317
328
 
@@ -325,10 +336,13 @@ type FlamebearerProfile = {
325
336
  pnpm run lint
326
337
  ```
327
338
 
328
- > ✅ 建议:
339
+ > ✅ 说明:
340
+ >
341
+ > * 旧版本使用的 esbuild 构建脚本已移除,当前仓库仅保留 rollup 方案,避免多套构建链路带来的维护成本。
342
+ > * 若需要在 CI 中校验,可至少执行:
329
343
  >
330
- > * 在 CI 中至少执行 `pnpm run build` 与 `pnpm run type-check`,保证包的构建与类型安全。
331
- > * 本项目使用 TypeScript 5.x 与 esbuild 进行打包,建议 Node 版本与麒麟内部前端工程保持一致。
344
+ > * `pnpm run type-check`
345
+ > * `pnpm run build`
332
346
 
333
347
  ---
334
348
 
@@ -338,7 +352,8 @@ type FlamebearerProfile = {
338
352
  * 主要差异点集中在:
339
353
 
340
354
  * 包名与发布渠道:使用 `@kylincloud/flamegraph`
341
- * 构建链路与样式组织适配麒麟内部前端工程(ESM/CJS 双入口、CSS 独立导出)
355
+ * 构建链路调整为 Rollup + PostCSS + Sass,自动注入样式,兼容 ESM / CJS / Node 侧入口
356
+ * 在类型声明与 i18n 导出上进行了补充,便于在 TypeScript 环境中使用
342
357
  * 后续可能增加针对麒麟项目的定制功能(如与内部监控体系联动)
343
358
 
344
359
  如需回溯或对比实现细节,可以参考源码中的注释与 commit 记录。