@bhsd/nodejs 0.0.1 → 0.1.0

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
@@ -1,3 +1,4 @@
1
+ export declare const profile: (callback: () => void | Promise<void>, dir: string) => Promise<void>;
1
2
  /**
2
3
  * 刷新屏幕输出
3
4
  * @param str 要输出的字符串
package/dist/index.js CHANGED
@@ -1,6 +1,52 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.refreshStdout = void 0;
6
+ exports.refreshStdout = exports.profile = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const promises_1 = require("inspector/promises"); // eslint-disable-line n/no-unsupported-features/node-builtins
10
+ /**
11
+ * Adds the ticks to the myTicks object.
12
+ * @param myTicks ticks记录对象
13
+ * @param positionTicks positionTicks数组
14
+ */
15
+ const addTicks = (myTicks, positionTicks) => {
16
+ if (positionTicks) {
17
+ for (const { line, ticks } of positionTicks) {
18
+ myTicks[line] = (myTicks[line] ?? 0) + ticks;
19
+ }
20
+ }
21
+ };
22
+ const profile = async (callback, dir) => {
23
+ const session = new promises_1.Session();
24
+ session.connect();
25
+ await session.post('Profiler.enable');
26
+ await session.post('Profiler.start');
27
+ await callback();
28
+ const { profile: { nodes } } = await session.post('Profiler.stop');
29
+ const useful = nodes.filter(({ callFrame: { url }, hitCount, children }) => url.startsWith('file:///')
30
+ && (hitCount || children)), summary = [];
31
+ for (const { callFrame, hitCount, positionTicks } of useful) {
32
+ const existing = summary.find(({ callFrame: { scriptId, lineNumber, columnNumber } }) => callFrame.scriptId === scriptId
33
+ && callFrame.lineNumber === lineNumber && callFrame.columnNumber === columnNumber), myTicks = {};
34
+ addTicks(myTicks, positionTicks);
35
+ if (existing) {
36
+ if (hitCount) {
37
+ existing.hitCount = (existing.hitCount ?? 0) + hitCount;
38
+ }
39
+ addTicks(existing.positionTicks, positionTicks);
40
+ }
41
+ else {
42
+ summary.push({ callFrame, hitCount, positionTicks: myTicks });
43
+ }
44
+ }
45
+ fs_1.default.writeFileSync(path_1.default.join(dir, 'prof.json'), `${JSON.stringify(useful, null, '\t')}\n`);
46
+ fs_1.default.writeFileSync(path_1.default.join(dir, 'prof-summary.json'), `${JSON.stringify(summary, null, '\t')}\n`);
47
+ session.disconnect();
48
+ };
49
+ exports.profile = profile;
4
50
  /**
5
51
  * 刷新屏幕输出
6
52
  * @param str 要输出的字符串
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhsd/nodejs",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "homepage": "https://github.com/bhsd-harry/nodejs#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/bhsd-harry/nodejs/issues"
@@ -19,20 +19,20 @@
19
19
  "lint": "npm run lint:ts"
20
20
  },
21
21
  "devDependencies": {
22
- "@bhsd/code-standard": "^1.0.1",
23
- "@stylistic/eslint-plugin": "^3.1.0",
24
- "@types/node": "^24.0.10",
25
- "@typescript-eslint/eslint-plugin": "^8.35.1",
26
- "@typescript-eslint/parser": "^8.35.1",
27
- "eslint": "^8.57.1",
22
+ "@bhsd/code-standard": "^1.3.1",
23
+ "@stylistic/eslint-plugin": "^5.5.0",
24
+ "@types/node": "^24.9.2",
25
+ "@typescript-eslint/eslint-plugin": "^8.46.2",
26
+ "@typescript-eslint/parser": "^8.46.2",
27
+ "eslint": "^9.38.0",
28
28
  "eslint-plugin-eslint-comments": "^3.2.0",
29
- "eslint-plugin-jsdoc": "^52.0.2",
30
- "eslint-plugin-json-es": "^1.6.0",
31
- "eslint-plugin-n": "^17.20.0",
29
+ "eslint-plugin-jsdoc": "^61.1.11",
30
+ "eslint-plugin-jsonc": "^2.21.0",
31
+ "eslint-plugin-n": "^17.23.1",
32
32
  "eslint-plugin-promise": "^7.2.1",
33
- "eslint-plugin-regexp": "^2.9.0",
34
- "eslint-plugin-unicorn": "^56.0.1",
35
- "typescript": "^5.8.2"
33
+ "eslint-plugin-regexp": "^2.10.0",
34
+ "eslint-plugin-unicorn": "^62.0.0",
35
+ "typescript": "^5.9.3"
36
36
  },
37
37
  "engines": {
38
38
  "node": ">=18.17.0"