@bhsd/nodejs 0.0.1 → 0.1.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.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +50 -2
- package/package.json +14 -14
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,11 +1,59 @@
|
|
|
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");
|
|
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 { nodes } = (await session.post('Profiler.stop')).profile;
|
|
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 要输出的字符串
|
|
7
53
|
*/
|
|
8
54
|
const refreshStdout = (str) => {
|
|
9
|
-
process.stdout.
|
|
55
|
+
process.stdout.moveCursor(-process.stdout.columns, 0);
|
|
56
|
+
process.stdout.clearLine(0);
|
|
57
|
+
process.stdout.write(`\x1B[?7l${str}\x1B[?7h\r`);
|
|
10
58
|
};
|
|
11
59
|
exports.refreshStdout = refreshStdout;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bhsd/nodejs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"homepage": "https://github.com/bhsd-harry/nodejs#readme",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/bhsd-harry/nodejs/issues"
|
|
@@ -19,22 +19,22 @@
|
|
|
19
19
|
"lint": "npm run lint:ts"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@bhsd/code-standard": "^1.0
|
|
23
|
-
"@stylistic/eslint-plugin": "^
|
|
24
|
-
"@types/node": "^24.0
|
|
25
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
26
|
-
"@typescript-eslint/parser": "^8.
|
|
27
|
-
"eslint": "^
|
|
22
|
+
"@bhsd/code-standard": "^2.1.0",
|
|
23
|
+
"@stylistic/eslint-plugin": "^5.9.0",
|
|
24
|
+
"@types/node": "^24.11.0",
|
|
25
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
26
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
27
|
+
"eslint": "^9.39.3",
|
|
28
28
|
"eslint-plugin-eslint-comments": "^3.2.0",
|
|
29
|
-
"eslint-plugin-jsdoc": "^
|
|
30
|
-
"eslint-plugin-
|
|
31
|
-
"eslint-plugin-n": "^17.
|
|
29
|
+
"eslint-plugin-jsdoc": "^62.7.1",
|
|
30
|
+
"eslint-plugin-jsonc": "^3.1.1",
|
|
31
|
+
"eslint-plugin-n": "^17.24.0",
|
|
32
32
|
"eslint-plugin-promise": "^7.2.1",
|
|
33
|
-
"eslint-plugin-regexp": "^
|
|
34
|
-
"eslint-plugin-unicorn": "^
|
|
35
|
-
"typescript": "^5.
|
|
33
|
+
"eslint-plugin-regexp": "^3.0.0",
|
|
34
|
+
"eslint-plugin-unicorn": "^63.0.0",
|
|
35
|
+
"typescript": "^5.9.3"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
|
-
"node": ">=
|
|
38
|
+
"node": ">=20.19.0"
|
|
39
39
|
}
|
|
40
40
|
}
|