@rsdoctor/utils 0.1.0 → 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/README.md CHANGED
@@ -1,11 +1,18 @@
1
- # Rsdoctor
1
+ # Rsdoctor Utils
2
2
 
3
- Rsdoctor is a tool for diagnosing and analyzing the build process and build artifacts to help developers quickly identify and solve problems.
3
+ This package is the Rsdoctor‘s tools package.
4
4
 
5
- It also supports Webpack and Rspack builders, as well as various build frameworks, such as Rsbuild.
5
+ ## features
6
+
7
+ - Rsdoctor is a one-stop tool for diagnosing and analyzing the build process and build artifacts.
8
+ - Rsdoctor is a tool that supports Webpack and Rspack build analysis.
9
+ - Rsdoctor is an analysis tool that can display the time-consuming and behavioral details of the compilation.
10
+ - Rsdoctor is a tool that provides bundle Diff and other anti-degradation capabilities simultaneously.
6
11
 
7
12
  ## Documentation
8
13
 
14
+ https://rsdoctor.dev/
15
+
9
16
  ## Contributing
10
17
 
11
18
  Please read the [Contributing Guide](https://github.com/web-infra-dev/rsdoctor/blob/main/CONTRIBUTING.md).
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,24 +17,35 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var debug_exports = {};
20
- __export(debug_exports, {
21
- debug: () => debug
29
+ var logger_exports = {};
30
+ __export(logger_exports, {
31
+ chalk: () => import_chalk.default,
32
+ debug: () => debug,
33
+ logger: () => import_rslog.logger
22
34
  });
23
- module.exports = __toCommonJS(debug_exports);
35
+ module.exports = __toCommonJS(logger_exports);
36
+ var import_chalk = __toESM(require("chalk"));
37
+ var import_rslog = require("rslog");
24
38
  var import_types = require("@rsdoctor/types");
25
- var import_logger = require("./logger");
26
- let debugLogger;
27
39
  function debug(getMsg, prefix = "") {
28
- if (!process.env[import_types.Constants.RsdoctorProcessEnvDebugKey])
40
+ if (!process.env[import_types.Constants.RsdoctorProcessEnvDebugKey]) {
29
41
  return;
30
- if (!debugLogger) {
31
- debugLogger = (0, import_logger.createLogger)({ level: "Debug" });
32
42
  }
33
- debugLogger.debug(prefix, getMsg());
43
+ import_rslog.logger.level = "verbose";
44
+ import_rslog.logger.debug(`${prefix} ${getMsg()}`);
34
45
  }
35
46
  // Annotate the CommonJS export names for ESM import in node:
36
47
  0 && (module.exports = {
37
- debug
48
+ chalk,
49
+ debug,
50
+ logger
38
51
  });
@@ -0,0 +1,15 @@
1
+ import chalk from "chalk";
2
+ import { logger } from "rslog";
3
+ import { Constants } from "@rsdoctor/types";
4
+ function debug(getMsg, prefix = "") {
5
+ if (!process.env[Constants.RsdoctorProcessEnvDebugKey]) {
6
+ return;
7
+ }
8
+ logger.level = "verbose";
9
+ logger.debug(`${prefix} ${getMsg()}`);
10
+ }
11
+ export {
12
+ chalk,
13
+ debug,
14
+ logger
15
+ };
@@ -13,7 +13,7 @@ export declare class DevToolError extends Error implements Err.DevToolErrorInsta
13
13
  private _controller;
14
14
  private readonly _level;
15
15
  constructor(title: string, message: string, opts?: Err.DevToolErrorParams);
16
- get level(): "Error" | "Ignore" | "Warn";
16
+ get level(): "Ignore" | "Warn" | "Error";
17
17
  get path(): string | undefined;
18
18
  set path(file: string | undefined);
19
19
  get codeFrame(): Err.CodeFrameOption | undefined;
@@ -0,0 +1,7 @@
1
+ import chalk from 'chalk';
2
+ import { logger } from 'rslog';
3
+ /**
4
+ * log debug message
5
+ */
6
+ export declare function debug(getMsg: () => string, prefix?: string): void;
7
+ export { chalk, logger };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/utils",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/rsdoctor",
@@ -34,9 +34,9 @@
34
34
  "import": "./dist/esm/rule-utils/index.js"
35
35
  },
36
36
  "./logger": {
37
- "types": "./dist/type/logger/index.d.ts",
38
- "require": "./dist/cjs/logger/index.js",
39
- "import": "./dist/esm/logger/index.js"
37
+ "types": "./dist/type/logger.d.ts",
38
+ "require": "./dist/cjs/logger.js",
39
+ "import": "./dist/esm/logger.js"
40
40
  }
41
41
  },
42
42
  "main": "dist/index.js",
@@ -60,8 +60,9 @@
60
60
  "json-stream-stringify": "3.0.1",
61
61
  "lines-and-columns": "2.0.4",
62
62
  "lodash": "^4.17.21",
63
+ "rslog": "^1.2.0",
63
64
  "strip-ansi": "^6.0.1",
64
- "@rsdoctor/types": "0.1.0"
65
+ "@rsdoctor/types": "0.1.1"
65
66
  },
66
67
  "devDependencies": {
67
68
  "@types/deep-eql": "4.0.0",
@@ -1,24 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var logger_exports = {};
17
- module.exports = __toCommonJS(logger_exports);
18
- __reExport(logger_exports, require("./logger"), module.exports);
19
- __reExport(logger_exports, require("./debug"), module.exports);
20
- // Annotate the CommonJS export names for ESM import in node:
21
- 0 && (module.exports = {
22
- ...require("./logger"),
23
- ...require("./debug")
24
- });
@@ -1,118 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var logger_exports = {};
30
- __export(logger_exports, {
31
- Logger: () => Logger,
32
- createLogger: () => createLogger,
33
- getLogLevel: () => getLogLevel
34
- });
35
- module.exports = __toCommonJS(logger_exports);
36
- var import_chalk = __toESM(require("chalk"));
37
- var import_types = require("@rsdoctor/types");
38
- const NUM_OF_MILLISEC_IN_SEC = BigInt(1e6);
39
- class Logger {
40
- constructor(opts) {
41
- this.opts = opts;
42
- this.times = /* @__PURE__ */ new Map();
43
- this.timesLog = /* @__PURE__ */ new Map();
44
- }
45
- output(level, ...message) {
46
- if (getLogLevel(this.opts.level ?? "Info") < getLogLevel(level)) {
47
- return;
48
- }
49
- const format = () => {
50
- if (this.opts.timestamp) {
51
- return [
52
- `${import_chalk.default.dim((/* @__PURE__ */ new Date()).toLocaleTimeString())} ${message.join(" ")}`
53
- ];
54
- }
55
- return message;
56
- };
57
- console.log(...format());
58
- }
59
- info(...msg) {
60
- this.output(
61
- "Info",
62
- this.opts?.prefix ? import_chalk.default.bold.blue(this.opts?.prefix) : "",
63
- import_chalk.default.bold.blue("INFO"),
64
- ...msg
65
- );
66
- }
67
- warn(...msg) {
68
- this.output(
69
- "Warning",
70
- this.opts?.prefix ? import_chalk.default.bold.yellow(this.opts?.prefix) : "",
71
- import_chalk.default.bold.yellow("WARN"),
72
- ...msg
73
- );
74
- }
75
- error(...msg) {
76
- this.output(
77
- "Error",
78
- this.opts?.prefix ? import_chalk.default.bold.red(this.opts?.prefix) : "",
79
- import_chalk.default.bold.red("ERROR"),
80
- ...msg
81
- );
82
- }
83
- debug(...info) {
84
- this.output(
85
- "Debug",
86
- this.opts?.prefix ? import_chalk.default.bold.magentaBright(this.opts?.prefix) : "",
87
- import_chalk.default.bold.magentaBright("DEBUG"),
88
- ...info
89
- );
90
- }
91
- time(label) {
92
- this.times.set(label, process.hrtime.bigint());
93
- }
94
- timeEnd(label) {
95
- const time = process.hrtime.bigint();
96
- const start = this.times.get(label);
97
- if (!start) {
98
- throw new Error(`Time label '${label}' not found for Logger.timeEnd()`);
99
- }
100
- this.times.delete(label);
101
- const diff = time - start;
102
- const diffMs = Number(diff / NUM_OF_MILLISEC_IN_SEC);
103
- this.timesLog.set(label, diffMs);
104
- this.debug(`Time label ${label} took ${diffMs}ms`);
105
- }
106
- }
107
- function createLogger(options = { level: "Info", timestamp: false, prefix: "" }) {
108
- return new Logger(options);
109
- }
110
- function getLogLevel(logLevel) {
111
- return import_types.Logger.LogLevel[logLevel];
112
- }
113
- // Annotate the CommonJS export names for ESM import in node:
114
- 0 && (module.exports = {
115
- Logger,
116
- createLogger,
117
- getLogLevel
118
- });
@@ -1,14 +0,0 @@
1
- import { Constants } from "@rsdoctor/types";
2
- import { createLogger } from "./logger";
3
- let debugLogger;
4
- function debug(getMsg, prefix = "") {
5
- if (!process.env[Constants.RsdoctorProcessEnvDebugKey])
6
- return;
7
- if (!debugLogger) {
8
- debugLogger = createLogger({ level: "Debug" });
9
- }
10
- debugLogger.debug(prefix, getMsg());
11
- }
12
- export {
13
- debug
14
- };
@@ -1,2 +0,0 @@
1
- export * from "./logger";
2
- export * from "./debug";
@@ -1,82 +0,0 @@
1
- import chalk from "chalk";
2
- import { Logger as L } from "@rsdoctor/types";
3
- const NUM_OF_MILLISEC_IN_SEC = BigInt(1e6);
4
- class Logger {
5
- constructor(opts) {
6
- this.opts = opts;
7
- this.times = /* @__PURE__ */ new Map();
8
- this.timesLog = /* @__PURE__ */ new Map();
9
- }
10
- output(level, ...message) {
11
- if (getLogLevel(this.opts.level ?? "Info") < getLogLevel(level)) {
12
- return;
13
- }
14
- const format = () => {
15
- if (this.opts.timestamp) {
16
- return [
17
- `${chalk.dim((/* @__PURE__ */ new Date()).toLocaleTimeString())} ${message.join(" ")}`
18
- ];
19
- }
20
- return message;
21
- };
22
- console.log(...format());
23
- }
24
- info(...msg) {
25
- this.output(
26
- "Info",
27
- this.opts?.prefix ? chalk.bold.blue(this.opts?.prefix) : "",
28
- chalk.bold.blue("INFO"),
29
- ...msg
30
- );
31
- }
32
- warn(...msg) {
33
- this.output(
34
- "Warning",
35
- this.opts?.prefix ? chalk.bold.yellow(this.opts?.prefix) : "",
36
- chalk.bold.yellow("WARN"),
37
- ...msg
38
- );
39
- }
40
- error(...msg) {
41
- this.output(
42
- "Error",
43
- this.opts?.prefix ? chalk.bold.red(this.opts?.prefix) : "",
44
- chalk.bold.red("ERROR"),
45
- ...msg
46
- );
47
- }
48
- debug(...info) {
49
- this.output(
50
- "Debug",
51
- this.opts?.prefix ? chalk.bold.magentaBright(this.opts?.prefix) : "",
52
- chalk.bold.magentaBright("DEBUG"),
53
- ...info
54
- );
55
- }
56
- time(label) {
57
- this.times.set(label, process.hrtime.bigint());
58
- }
59
- timeEnd(label) {
60
- const time = process.hrtime.bigint();
61
- const start = this.times.get(label);
62
- if (!start) {
63
- throw new Error(`Time label '${label}' not found for Logger.timeEnd()`);
64
- }
65
- this.times.delete(label);
66
- const diff = time - start;
67
- const diffMs = Number(diff / NUM_OF_MILLISEC_IN_SEC);
68
- this.timesLog.set(label, diffMs);
69
- this.debug(`Time label ${label} took ${diffMs}ms`);
70
- }
71
- }
72
- function createLogger(options = { level: "Info", timestamp: false, prefix: "" }) {
73
- return new Logger(options);
74
- }
75
- function getLogLevel(logLevel) {
76
- return L.LogLevel[logLevel];
77
- }
78
- export {
79
- Logger,
80
- createLogger,
81
- getLogLevel
82
- };
@@ -1,4 +0,0 @@
1
- /**
2
- * log debug message
3
- */
4
- export declare function debug(getMsg: () => string, prefix?: string): void;
@@ -1,2 +0,0 @@
1
- export * from './logger';
2
- export * from './debug';
@@ -1,16 +0,0 @@
1
- import { Logger as L } from '@rsdoctor/types';
2
- export declare class Logger implements L.LoggerInstance {
3
- opts: L.LoggerOptions;
4
- constructor(opts: L.LoggerOptions);
5
- private times;
6
- timesLog: Map<string, number>;
7
- protected output(level: L.LogLevelName, ...message: string[]): void;
8
- info(...msg: string[]): void;
9
- warn(...msg: string[]): void;
10
- error(...msg: string[]): void;
11
- debug(...info: string[]): void;
12
- time(label: string): void;
13
- timeEnd(label: string): void;
14
- }
15
- export declare function createLogger(options?: L.LoggerOptions): Logger;
16
- export declare function getLogLevel(logLevel: L.LogLevelName): number;