@bhsd/nodejs 0.2.0 → 1.0.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.
Files changed (2) hide show
  1. package/dist/index.js +13 -29
  2. package/package.json +3 -2
package/dist/index.js CHANGED
@@ -1,13 +1,7 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.blue = exports.red = exports.yellow = exports.green = 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
- const util_1 = __importDefault(require("util"));
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { Session } from 'inspector/promises';
4
+ import { styleText } from 'util';
11
5
  /**
12
6
  * Adds the ticks to the myTicks object.
13
7
  * @param myTicks ticks记录对象
@@ -25,8 +19,8 @@ const addTicks = (myTicks, positionTicks) => {
25
19
  * @param callback 要分析的函数
26
20
  * @param dir 输出文件夹路径
27
21
  */
28
- const profile = async (callback, dir) => {
29
- const session = new promises_1.Session();
22
+ export const profile = async (callback, dir) => {
23
+ const session = new Session();
30
24
  session.connect();
31
25
  await session.post('Profiler.enable');
32
26
  await session.post('Profiler.start');
@@ -48,46 +42,36 @@ const profile = async (callback, dir) => {
48
42
  summary.push({ callFrame, hitCount, positionTicks: myTicks });
49
43
  }
50
44
  }
51
- fs_1.default.writeFileSync(path_1.default.join(dir, 'prof.json'), `${JSON.stringify(useful, null, '\t')}\n`);
52
- fs_1.default.writeFileSync(path_1.default.join(dir, 'prof-summary.json'), `${JSON.stringify(summary, null, '\t')}\n`);
45
+ fs.writeFileSync(path.join(dir, 'prof.json'), `${JSON.stringify(useful, null, '\t')}\n`);
46
+ fs.writeFileSync(path.join(dir, 'prof-summary.json'), `${JSON.stringify(summary, null, '\t')}\n`);
53
47
  session.disconnect();
54
48
  };
55
- exports.profile = profile;
56
49
  /**
57
50
  * 刷新屏幕输出
58
51
  * @param str 要输出的字符串
59
52
  */
60
- const refreshStdout = (str) => {
53
+ export const refreshStdout = (str) => {
61
54
  process.stdout.moveCursor(-process.stdout.columns, 0);
62
55
  process.stdout.clearLine(0);
63
56
  process.stdout.write(`\x1B[?7l${str}\x1B[?7h\r`);
64
57
  };
65
- exports.refreshStdout = refreshStdout;
66
58
  /**
67
59
  * 将字符串以绿色显示
68
60
  * @param str 要显示的字符串
69
61
  */
70
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
71
- const green = (str) => util_1.default.styleText?.('green', str) ?? str;
72
- exports.green = green;
62
+ export const green = (str) => styleText('green', str);
73
63
  /**
74
64
  * 将字符串以黄色显示
75
65
  * @param str 要显示的字符串
76
66
  */
77
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
78
- const yellow = (str) => util_1.default.styleText?.('yellow', str) ?? str;
79
- exports.yellow = yellow;
67
+ export const yellow = (str) => styleText('yellow', str);
80
68
  /**
81
69
  * 将字符串以红色显示
82
70
  * @param str 要显示的字符串
83
71
  */
84
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
85
- const red = (str) => util_1.default.styleText?.('red', str) ?? str;
86
- exports.red = red;
72
+ export const red = (str) => styleText('red', str);
87
73
  /**
88
74
  * 将字符串以蓝色显示
89
75
  * @param str 要显示的字符串
90
76
  */
91
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
92
- const blue = (str) => util_1.default.styleText?.('blue', str) ?? str;
93
- exports.blue = blue;
77
+ export const blue = (str) => styleText('blue', str);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhsd/nodejs",
3
- "version": "0.2.0",
3
+ "version": "1.0.0",
4
4
  "homepage": "https://github.com/bhsd-harry/nodejs#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/bhsd-harry/nodejs/issues"
@@ -12,6 +12,7 @@
12
12
  ],
13
13
  "main": "./dist/index.js",
14
14
  "types": "./dist/index.d.ts",
15
+ "type": "module",
15
16
  "scripts": {
16
17
  "prepublishOnly": "npm run build",
17
18
  "build": "tsc",
@@ -35,6 +36,6 @@
35
36
  "typescript": "^5.9.3"
36
37
  },
37
38
  "engines": {
38
- "node": ">=20.19.0"
39
+ "node": "^20.19.0 || ^22.13.0 || >=24.11.0"
39
40
  }
40
41
  }