@rsdoctor/utils 1.1.0 → 1.1.2

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.
@@ -382,7 +382,12 @@ class APIDataLoader {
382
382
  case import_types.SDK.ServerAPI.API.GetModuleIssuerPath:
383
383
  return this.loader.loadData("moduleGraph").then((moduleGraph) => {
384
384
  const { moduleId } = body;
385
- return moduleGraph?.modules.find((m) => String(m.id) === moduleId)?.issuerPath || [];
385
+ const modules = moduleGraph?.modules || [];
386
+ const issuerPath = modules.find((m) => String(m.id) === moduleId)?.issuerPath || [];
387
+ if (Array.isArray(issuerPath) && issuerPath.length > 0 && typeof issuerPath[0] === "number") {
388
+ return issuerPath.map((id) => modules.find((m) => m.id === id)?.path).filter(Boolean);
389
+ }
390
+ return issuerPath;
386
391
  });
387
392
  case import_types.SDK.ServerAPI.API.GetPackageInfo:
388
393
  return this.loader.loadData("packageGraph").then((packageGraph) => {
@@ -409,6 +414,9 @@ class APIDataLoader {
409
414
  const chunkInfo = chunks.find(
410
415
  (c) => c.id === chunkId
411
416
  );
417
+ if (!chunkInfo) {
418
+ return null;
419
+ }
412
420
  const chunkModules = modules.filter((m) => chunkInfo.modules.includes(m.id)).map((module2) => {
413
421
  return {
414
422
  id: module2.id,
@@ -0,0 +1,68 @@
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 global_config_exports = {};
30
+ __export(global_config_exports, {
31
+ getMcpConfigPath: () => getMcpConfigPath,
32
+ writeMcpPort: () => writeMcpPort
33
+ });
34
+ module.exports = __toCommonJS(global_config_exports);
35
+ var import_fs = __toESM(require("fs"));
36
+ var import_path = __toESM(require("path"));
37
+ var import_os = __toESM(require("os"));
38
+ function writeMcpPort(port, builderName) {
39
+ const homeDir = import_os.default.homedir();
40
+ const rsdoctorDir = import_path.default.join(homeDir, ".cache/rsdoctor");
41
+ const mcpPortFilePath = import_path.default.join(rsdoctorDir, "mcp.json");
42
+ if (!import_fs.default.existsSync(rsdoctorDir)) {
43
+ import_fs.default.mkdirSync(rsdoctorDir, { recursive: true });
44
+ }
45
+ let mcpJson = {
46
+ portList: {},
47
+ port: 0
48
+ };
49
+ if (import_fs.default.existsSync(mcpPortFilePath)) {
50
+ mcpJson = JSON.parse(import_fs.default.readFileSync(mcpPortFilePath, "utf8"));
51
+ }
52
+ if (!mcpJson.portList)
53
+ mcpJson.portList = {};
54
+ mcpJson.portList[builderName || "builder"] = port;
55
+ mcpJson.port = port;
56
+ import_fs.default.writeFileSync(mcpPortFilePath, JSON.stringify(mcpJson, null, 2), "utf8");
57
+ }
58
+ function getMcpConfigPath() {
59
+ const homeDir = import_os.default.homedir();
60
+ const rsdoctorDir = import_path.default.join(homeDir, ".cache/rsdoctor");
61
+ const mcpPortFilePath = import_path.default.join(rsdoctorDir, "mcp.json");
62
+ return mcpPortFilePath;
63
+ }
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {
66
+ getMcpConfigPath,
67
+ writeMcpPort
68
+ });
@@ -33,6 +33,7 @@ __export(common_exports, {
33
33
  Bundle: () => Bundle,
34
34
  Crypto: () => Crypto,
35
35
  Data: () => Data,
36
+ GlobalConfig: () => GlobalConfig,
36
37
  Graph: () => Graph,
37
38
  Loader: () => Loader,
38
39
  Lodash: () => Lodash,
@@ -62,6 +63,7 @@ var Alerts = __toESM(require("./alerts"));
62
63
  var Rspack = __toESM(require("./rspack"));
63
64
  var Package = __toESM(require("./package"));
64
65
  var Lodash = __toESM(require("./lodash"));
66
+ var GlobalConfig = __toESM(require("./global-config"));
65
67
  // Annotate the CommonJS export names for ESM import in node:
66
68
  0 && (module.exports = {
67
69
  Alerts,
@@ -69,6 +71,7 @@ var Lodash = __toESM(require("./lodash"));
69
71
  Bundle,
70
72
  Crypto,
71
73
  Data,
74
+ GlobalConfig,
72
75
  Graph,
73
76
  Loader,
74
77
  Lodash,
@@ -349,7 +349,12 @@ class APIDataLoader {
349
349
  case SDK.ServerAPI.API.GetModuleIssuerPath:
350
350
  return this.loader.loadData("moduleGraph").then((moduleGraph) => {
351
351
  const { moduleId } = body;
352
- return moduleGraph?.modules.find((m) => String(m.id) === moduleId)?.issuerPath || [];
352
+ const modules = moduleGraph?.modules || [];
353
+ const issuerPath = modules.find((m) => String(m.id) === moduleId)?.issuerPath || [];
354
+ if (Array.isArray(issuerPath) && issuerPath.length > 0 && typeof issuerPath[0] === "number") {
355
+ return issuerPath.map((id) => modules.find((m) => m.id === id)?.path).filter(Boolean);
356
+ }
357
+ return issuerPath;
353
358
  });
354
359
  case SDK.ServerAPI.API.GetPackageInfo:
355
360
  return this.loader.loadData("packageGraph").then((packageGraph) => {
@@ -376,6 +381,9 @@ class APIDataLoader {
376
381
  const chunkInfo = chunks.find(
377
382
  (c) => c.id === chunkId
378
383
  );
384
+ if (!chunkInfo) {
385
+ return null;
386
+ }
379
387
  const chunkModules = modules.filter((m) => chunkInfo.modules.includes(m.id)).map((module) => {
380
388
  return {
381
389
  id: module.id,
@@ -0,0 +1,33 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import os from "os";
4
+ function writeMcpPort(port, builderName) {
5
+ const homeDir = os.homedir();
6
+ const rsdoctorDir = path.join(homeDir, ".cache/rsdoctor");
7
+ const mcpPortFilePath = path.join(rsdoctorDir, "mcp.json");
8
+ if (!fs.existsSync(rsdoctorDir)) {
9
+ fs.mkdirSync(rsdoctorDir, { recursive: true });
10
+ }
11
+ let mcpJson = {
12
+ portList: {},
13
+ port: 0
14
+ };
15
+ if (fs.existsSync(mcpPortFilePath)) {
16
+ mcpJson = JSON.parse(fs.readFileSync(mcpPortFilePath, "utf8"));
17
+ }
18
+ if (!mcpJson.portList)
19
+ mcpJson.portList = {};
20
+ mcpJson.portList[builderName || "builder"] = port;
21
+ mcpJson.port = port;
22
+ fs.writeFileSync(mcpPortFilePath, JSON.stringify(mcpJson, null, 2), "utf8");
23
+ }
24
+ function getMcpConfigPath() {
25
+ const homeDir = os.homedir();
26
+ const rsdoctorDir = path.join(homeDir, ".cache/rsdoctor");
27
+ const mcpPortFilePath = path.join(rsdoctorDir, "mcp.json");
28
+ return mcpPortFilePath;
29
+ }
30
+ export {
31
+ getMcpConfigPath,
32
+ writeMcpPort
33
+ };
@@ -14,12 +14,14 @@ import * as Alerts from "./alerts";
14
14
  import * as Rspack from "./rspack";
15
15
  import * as Package from "./package";
16
16
  import * as Lodash from "./lodash";
17
+ import * as GlobalConfig from "./global-config";
17
18
  export {
18
19
  Alerts,
19
20
  Algorithm,
20
21
  Bundle,
21
22
  Crypto,
22
23
  Data,
24
+ GlobalConfig,
23
25
  Graph,
24
26
  Loader,
25
27
  Lodash,
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/data/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,GAAG,EAAE,QAAQ,EAAa,MAAM,iBAAiB,CAAC;AASjE;;GAEG;AACH,qBAAa,aAAa;IACZ,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,kBAAkB;gBAAnC,MAAM,EAAE,QAAQ,CAAC,kBAAkB;IAIlD,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAItB,OAAO,CACZ,CAAC,SAAS,GAAG,CAAC,SAAS,CAAC,GAAG,EAC3B,CAAC,SACC,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAC/E,CAAC,SACC,GAAG,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAEzE,GAAG,IAAI,EAAE,CAAC,SAAS,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GACrD,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAye/C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/common/data/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,GAAG,EAAE,QAAQ,EAAa,MAAM,iBAAiB,CAAC;AASjE;;GAEG;AACH,qBAAa,aAAa;IACZ,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,kBAAkB;gBAAnC,MAAM,EAAE,QAAQ,CAAC,kBAAkB;IAIlD,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAItB,OAAO,CACZ,CAAC,SAAS,GAAG,CAAC,SAAS,CAAC,GAAG,EAC3B,CAAC,SACC,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAC/E,CAAC,SACC,GAAG,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAEzE,GAAG,IAAI,EAAE,CAAC,SAAS,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GACrD,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAwf/C"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @description Writes the builder port information to mcp.json.
3
+ *
4
+ * The mcp.json file uses the following format:
5
+ * {
6
+ * portList: {
7
+ * builder1: portNumber,
8
+ * builder2: portNumber,
9
+ * },
10
+ * port: portNumber // The port of the last builder is used by default
11
+ * }
12
+ *
13
+ * @param {number} port - The port number to write.
14
+ * @param {string} [builderName] - The name of the builder.
15
+ */
16
+ export declare function writeMcpPort(port: number, builderName?: string): void;
17
+ /**
18
+ * @description Gets the path to the mcp.json file.
19
+ * @returns {string} The path to the mcp.json file.
20
+ */
21
+ export declare function getMcpConfigPath(): string;
22
+ //# sourceMappingURL=global-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-config.d.ts","sourceRoot":"","sources":["../../../src/common/global-config.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,QAwB9D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,WAK/B"}
@@ -14,4 +14,5 @@ export * as Alerts from './alerts';
14
14
  export * as Rspack from './rspack';
15
15
  export * as Package from './package';
16
16
  export * as Lodash from './lodash';
17
+ export * as GlobalConfig from './global-config';
17
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAC7B,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,YAAY,MAAM,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/utils",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/rsdoctor",
@@ -83,7 +83,7 @@
83
83
  "lines-and-columns": "2.0.4",
84
84
  "rslog": "^1.2.3",
85
85
  "strip-ansi": "^6.0.1",
86
- "@rsdoctor/types": "1.1.0"
86
+ "@rsdoctor/types": "1.1.2"
87
87
  },
88
88
  "devDependencies": {
89
89
  "@types/babel__code-frame": "7.0.6",