@rsdoctor/sdk 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 SDK
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 intermediate data layer of Rsdoctor.
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).
@@ -37,13 +37,14 @@ var import_build = require("@rsdoctor/utils/build");
37
37
  var import_common = require("@rsdoctor/utils/common");
38
38
  var import_assert = __toESM(require("assert"));
39
39
  var import_body_parser = __toESM(require("body-parser"));
40
- var import_open = __toESM(require("open"));
41
40
  var import_ip = __toESM(require("ip"));
42
41
  var import_cors = __toESM(require("cors"));
43
42
  var import_stream = require("stream");
44
43
  var import_socket = require("./socket");
45
44
  var import_router = require("./router");
46
45
  var APIs = __toESM(require("./apis"));
46
+ var import_logger = require("@rsdoctor/utils/logger");
47
+ var import_openBrowser = require("../utils/openBrowser");
47
48
  __reExport(server_exports, require("./utils"), module.exports);
48
49
  class RsdoctorServer {
49
50
  constructor(sdk, port = import_build.Server.defaultPort) {
@@ -167,8 +168,8 @@ class RsdoctorServer {
167
168
  const url = this.getClientUrl(
168
169
  ...args
169
170
  );
170
- await (0, import_open.default)(url);
171
- console.log(`Rsdoctor analyze run at: ${url}`);
171
+ await (0, import_openBrowser.openBrowser)(url);
172
+ import_logger.logger.info(`Rsdoctor analyze server running on: ${import_logger.chalk.cyan(url)}`);
172
173
  }
173
174
  sendAPIDataToClient(api, msg) {
174
175
  this._socket?.sendAPIData(api, msg);
@@ -0,0 +1,92 @@
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 openBrowser_exports = {};
30
+ __export(openBrowser_exports, {
31
+ openBrowser: () => openBrowser
32
+ });
33
+ module.exports = __toCommonJS(openBrowser_exports);
34
+ var import_node_child_process = require("node:child_process");
35
+ var import_node_util = require("node:util");
36
+ var import_logger = require("@rsdoctor/utils/logger");
37
+ var import_open = __toESM(require("open"));
38
+ var import_node_path = require("node:path");
39
+ const execAsync = (0, import_node_util.promisify)(import_node_child_process.exec);
40
+ const supportedChromiumBrowsers = [
41
+ "Google Chrome Canary",
42
+ "Google Chrome Dev",
43
+ "Google Chrome Beta",
44
+ "Google Chrome",
45
+ "Microsoft Edge",
46
+ "Brave Browser",
47
+ "Vivaldi",
48
+ "Chromium"
49
+ ];
50
+ const getTargetBrowser = async () => {
51
+ let targetBrowser = process.env.BROWSER;
52
+ if (!targetBrowser || !supportedChromiumBrowsers.includes(targetBrowser)) {
53
+ const { stdout: ps } = await execAsync("ps cax");
54
+ targetBrowser = supportedChromiumBrowsers.find((b) => ps.includes(b));
55
+ }
56
+ return targetBrowser;
57
+ };
58
+ async function openBrowser(url) {
59
+ const shouldTryOpenChromeWithAppleScript = process.platform === "darwin";
60
+ if (shouldTryOpenChromeWithAppleScript) {
61
+ try {
62
+ const targetBrowser = await getTargetBrowser();
63
+ if (targetBrowser) {
64
+ await execAsync(
65
+ `osascript openChrome.applescript "${encodeURI(
66
+ url
67
+ )}" "${targetBrowser}"`,
68
+ {
69
+ cwd: (0, import_node_path.join)(__dirname, "../../../../static")
70
+ }
71
+ );
72
+ return true;
73
+ }
74
+ import_logger.logger.debug("Failed to find the target browser.");
75
+ } catch (err) {
76
+ import_logger.logger.debug("Failed to open Rsdoctor URL with apple script.");
77
+ import_logger.logger.debug(err);
78
+ }
79
+ }
80
+ try {
81
+ await (0, import_open.default)(url);
82
+ return true;
83
+ } catch (err) {
84
+ import_logger.logger.error("Failed to open Rsdoctor URL.");
85
+ import_logger.logger.error(err);
86
+ return false;
87
+ }
88
+ }
89
+ // Annotate the CommonJS export names for ESM import in node:
90
+ 0 && (module.exports = {
91
+ openBrowser
92
+ });
@@ -3,13 +3,14 @@ import { Server } from "@rsdoctor/utils/build";
3
3
  import { Bundle } from "@rsdoctor/utils/common";
4
4
  import assert from "assert";
5
5
  import bodyParser from "body-parser";
6
- import open from "open";
7
6
  import ip from "ip";
8
7
  import cors from "cors";
9
8
  import { PassThrough } from "stream";
10
9
  import { Socket } from "./socket";
11
10
  import { Router } from "./router";
12
11
  import * as APIs from "./apis";
12
+ import { chalk, logger } from "@rsdoctor/utils/logger";
13
+ import { openBrowser } from "../utils/openBrowser";
13
14
  export * from "./utils";
14
15
  class RsdoctorServer {
15
16
  constructor(sdk, port = Server.defaultPort) {
@@ -133,8 +134,8 @@ class RsdoctorServer {
133
134
  const url = this.getClientUrl(
134
135
  ...args
135
136
  );
136
- await open(url);
137
- console.log(`Rsdoctor analyze run at: ${url}`);
137
+ await openBrowser(url);
138
+ logger.info(`Rsdoctor analyze server running on: ${chalk.cyan(url)}`);
138
139
  }
139
140
  sendAPIDataToClient(api, msg) {
140
141
  this._socket?.sendAPIData(api, msg);
@@ -0,0 +1,58 @@
1
+ import { exec } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ import { logger } from "@rsdoctor/utils/logger";
4
+ import open from "open";
5
+ import { join } from "node:path";
6
+ const execAsync = promisify(exec);
7
+ const supportedChromiumBrowsers = [
8
+ "Google Chrome Canary",
9
+ "Google Chrome Dev",
10
+ "Google Chrome Beta",
11
+ "Google Chrome",
12
+ "Microsoft Edge",
13
+ "Brave Browser",
14
+ "Vivaldi",
15
+ "Chromium"
16
+ ];
17
+ const getTargetBrowser = async () => {
18
+ let targetBrowser = process.env.BROWSER;
19
+ if (!targetBrowser || !supportedChromiumBrowsers.includes(targetBrowser)) {
20
+ const { stdout: ps } = await execAsync("ps cax");
21
+ targetBrowser = supportedChromiumBrowsers.find((b) => ps.includes(b));
22
+ }
23
+ return targetBrowser;
24
+ };
25
+ async function openBrowser(url) {
26
+ const shouldTryOpenChromeWithAppleScript = process.platform === "darwin";
27
+ if (shouldTryOpenChromeWithAppleScript) {
28
+ try {
29
+ const targetBrowser = await getTargetBrowser();
30
+ if (targetBrowser) {
31
+ await execAsync(
32
+ `osascript openChrome.applescript "${encodeURI(
33
+ url
34
+ )}" "${targetBrowser}"`,
35
+ {
36
+ cwd: join(__dirname, "../../../../static")
37
+ }
38
+ );
39
+ return true;
40
+ }
41
+ logger.debug("Failed to find the target browser.");
42
+ } catch (err) {
43
+ logger.debug("Failed to open Rsdoctor URL with apple script.");
44
+ logger.debug(err);
45
+ }
46
+ }
47
+ try {
48
+ await open(url);
49
+ return true;
50
+ } catch (err) {
51
+ logger.error("Failed to open Rsdoctor URL.");
52
+ logger.error(err);
53
+ return false;
54
+ }
55
+ }
56
+ export {
57
+ openBrowser
58
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Reads the BROWSER environment variable and decides what to do with it.
3
+ */
4
+ export declare function openBrowser(url: string): Promise<boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/sdk",
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",
@@ -11,7 +11,8 @@
11
11
  "module": "dist/esm/index.js",
12
12
  "types": "dist/type/index.d.ts",
13
13
  "files": [
14
- "dist"
14
+ "dist",
15
+ "static"
15
16
  ],
16
17
  "dependencies": {
17
18
  "body-parser": "1.20.1",
@@ -24,10 +25,10 @@
24
25
  "socket.io": "4.7.2",
25
26
  "source-map": "^0.7.4",
26
27
  "tapable": "2.2.1",
27
- "@rsdoctor/client": "0.1.0",
28
- "@rsdoctor/graph": "0.1.0",
29
- "@rsdoctor/utils": "0.1.0",
30
- "@rsdoctor/types": "0.1.0"
28
+ "@rsdoctor/client": "0.1.1",
29
+ "@rsdoctor/utils": "0.1.1",
30
+ "@rsdoctor/graph": "0.1.1",
31
+ "@rsdoctor/types": "0.1.1"
31
32
  },
32
33
  "devDependencies": {
33
34
  "@types/body-parser": "1.19.2",
@@ -0,0 +1,95 @@
1
+ (*
2
+ Copyright (c) 2015-present, Facebook, Inc.
3
+
4
+ This source code is licensed under the MIT license found in the
5
+ LICENSE file at
6
+ https://github.com/facebookincubator/create-react-app/blob/master/LICENSE
7
+ *)
8
+
9
+ property targetTab: null
10
+ property targetTabIndex: -1
11
+ property targetWindow: null
12
+ property theProgram: "Google Chrome"
13
+
14
+ on run argv
15
+ set theURL to item 1 of argv
16
+
17
+ -- Allow requested program to be optional,
18
+ -- default to Google Chrome
19
+ if (count of argv) > 1 then
20
+ set theProgram to item 2 of argv
21
+ end if
22
+
23
+ using terms from application "Google Chrome"
24
+ tell application theProgram
25
+
26
+ if (count every window) = 0 then
27
+ make new window
28
+ end if
29
+
30
+ -- 1: Looking for tab running debugger
31
+ -- then, Reload debugging tab if found
32
+ -- then return
33
+ set found to my lookupTabWithUrl(theURL)
34
+ if found then
35
+ set targetWindow's active tab index to targetTabIndex
36
+ tell targetTab to reload
37
+ tell targetWindow to activate
38
+ set index of targetWindow to 1
39
+ return
40
+ end if
41
+
42
+ -- 2: Looking for Empty tab
43
+ -- In case debugging tab was not found
44
+ -- We try to find an empty tab instead
45
+ set found to my lookupTabWithUrl("chrome://newtab/")
46
+ if found then
47
+ set targetWindow's active tab index to targetTabIndex
48
+ set URL of targetTab to theURL
49
+ tell targetWindow to activate
50
+ return
51
+ end if
52
+
53
+ -- 3: Create new tab
54
+ -- both debugging and empty tab were not found
55
+ -- make a new tab with url
56
+ tell window 1
57
+ activate
58
+ make new tab with properties {URL:theURL}
59
+ end tell
60
+ end tell
61
+ end using terms from
62
+ end run
63
+
64
+ -- Function:
65
+ -- Lookup tab with given url
66
+ -- if found, store tab, index, and window in properties
67
+ -- (properties were declared on top of file)
68
+ on lookupTabWithUrl(lookupUrl)
69
+ using terms from application "Google Chrome"
70
+ tell application theProgram
71
+ -- Find a tab with the given url
72
+ set found to false
73
+ set theTabIndex to -1
74
+ repeat with theWindow in every window
75
+ set theTabIndex to 0
76
+ repeat with theTab in every tab of theWindow
77
+ set theTabIndex to theTabIndex + 1
78
+ if (theTab's URL as string) contains lookupUrl then
79
+ -- assign tab, tab index, and window to properties
80
+ set targetTab to theTab
81
+ set targetTabIndex to theTabIndex
82
+ set targetWindow to theWindow
83
+ set found to true
84
+ exit repeat
85
+ end if
86
+ end repeat
87
+
88
+ if found then
89
+ exit repeat
90
+ end if
91
+ end repeat
92
+ end tell
93
+ end using terms from
94
+ return found
95
+ end lookupTabWithUrl