@rsdoctor/graph 0.3.3 → 0.3.5-beta.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.
@@ -18,15 +18,17 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var graph_exports = {};
20
20
  __export(graph_exports, {
21
- PackageGraph: () => PackageGraph
21
+ PackageGraph: () => PackageGraph,
22
+ readPackageJson: () => import_utils2.readPackageJson
22
23
  });
23
24
  module.exports = __toCommonJS(graph_exports);
24
25
  var import_lodash = require("lodash");
25
26
  var import_path = require("path");
26
27
  var import_types = require("@rsdoctor/types");
27
- var import_common = require("@rsdoctor/utils/common");
28
28
  var import_package = require("./package");
29
29
  var import_dependency = require("./dependency");
30
+ var import_utils = require("./utils");
31
+ var import_utils2 = require("./utils");
30
32
  class PackageGraph {
31
33
  constructor(root) {
32
34
  this._dependencies = [];
@@ -39,6 +41,9 @@ class PackageGraph {
39
41
  const pkgGraph = new PackageGraph(root);
40
42
  const modules = graph.getModules().filter((item) => item.kind === import_types.SDK.ModuleKind.Normal);
41
43
  for (const item of modules) {
44
+ const itemChunks = item.getChunks();
45
+ if (!itemChunks)
46
+ continue;
42
47
  const pkg = pkgGraph.getPackageByModule(item, getPackageFile);
43
48
  if (pkg) {
44
49
  pkgGraph.addPackage(pkg);
@@ -73,40 +78,12 @@ class PackageGraph {
73
78
  pkgsMap.set(file, pkg2);
74
79
  return pkg2;
75
80
  }
76
- const readPackageJson = (file2, readFile2) => {
77
- let result;
78
- let current = file2;
79
- while (current !== "/" && !result) {
80
- if ((0, import_path.dirname)(current) === current) {
81
- break;
82
- }
83
- current = (0, import_path.dirname)(current);
84
- if (readFile2) {
85
- result = readFile2((0, import_path.join)(current, "package.json"));
86
- }
87
- if (!readFile2) {
88
- result = import_common.Package.getPackageMetaFromModulePath(file2);
89
- } else if (!result?.name) {
90
- result = void 0;
91
- }
92
- }
93
- if (!result) {
94
- return;
95
- }
96
- if (readFile2 && (!result.name || !result.version)) {
97
- return readPackageJson((0, import_path.dirname)(current), readFile2);
98
- }
99
- return {
100
- ...result,
101
- root: current
102
- };
103
- };
104
81
  const cache = this.getPackageContainFile(file);
105
82
  if (cache) {
106
83
  pkgsMap.set(file, cache);
107
84
  return cache;
108
85
  }
109
- const data = readPackageJson(file, readFile);
86
+ const data = (0, import_utils.readPackageJson)(file, readFile);
110
87
  if (!data) {
111
88
  return;
112
89
  }
@@ -171,5 +148,6 @@ class PackageGraph {
171
148
  }
172
149
  // Annotate the CommonJS export names for ESM import in node:
173
150
  0 && (module.exports = {
174
- PackageGraph
151
+ PackageGraph,
152
+ readPackageJson
175
153
  });
@@ -18,13 +18,45 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var utils_exports = {};
20
20
  __export(utils_exports, {
21
- isPackagePath: () => isPackagePath
21
+ isPackagePath: () => isPackagePath,
22
+ readPackageJson: () => readPackageJson
22
23
  });
23
24
  module.exports = __toCommonJS(utils_exports);
25
+ var import_path = require("path");
26
+ var import_common = require("@rsdoctor/utils/common");
24
27
  function isPackagePath(path) {
25
28
  return /(^|[/\\])node_modules[/\\]/.test(path);
26
29
  }
30
+ const readPackageJson = (file, readFile) => {
31
+ let result;
32
+ let current = file;
33
+ while (current !== "/" && !result) {
34
+ if ((0, import_path.dirname)(current) === current) {
35
+ break;
36
+ }
37
+ current = (0, import_path.dirname)(current);
38
+ if (readFile) {
39
+ result = readFile((0, import_path.join)(current, "package.json"));
40
+ }
41
+ if (!readFile) {
42
+ result = import_common.Package.getPackageMetaFromModulePath(file);
43
+ } else if (!result?.name) {
44
+ result = void 0;
45
+ }
46
+ }
47
+ if (!result) {
48
+ return;
49
+ }
50
+ if (readFile && (!result.name || !result.version)) {
51
+ return readPackageJson((0, import_path.dirname)(current), readFile);
52
+ }
53
+ return {
54
+ ...result,
55
+ root: current
56
+ };
57
+ };
27
58
  // Annotate the CommonJS export names for ESM import in node:
28
59
  0 && (module.exports = {
29
- isPackagePath
60
+ isPackagePath,
61
+ readPackageJson
30
62
  });
@@ -1,9 +1,10 @@
1
1
  import { unionBy } from "lodash";
2
- import { dirname, join, resolve } from "path";
2
+ import { resolve } from "path";
3
3
  import { SDK } from "@rsdoctor/types";
4
- import { Package as PackageUtil } from "@rsdoctor/utils/common";
5
4
  import { Package } from "./package";
6
5
  import { PackageDependency } from "./dependency";
6
+ import { readPackageJson } from "./utils";
7
+ import { readPackageJson as readPackageJson2 } from "./utils";
7
8
  class PackageGraph {
8
9
  constructor(root) {
9
10
  this._dependencies = [];
@@ -16,6 +17,9 @@ class PackageGraph {
16
17
  const pkgGraph = new PackageGraph(root);
17
18
  const modules = graph.getModules().filter((item) => item.kind === SDK.ModuleKind.Normal);
18
19
  for (const item of modules) {
20
+ const itemChunks = item.getChunks();
21
+ if (!itemChunks)
22
+ continue;
19
23
  const pkg = pkgGraph.getPackageByModule(item, getPackageFile);
20
24
  if (pkg) {
21
25
  pkgGraph.addPackage(pkg);
@@ -50,34 +54,6 @@ class PackageGraph {
50
54
  pkgsMap.set(file, pkg2);
51
55
  return pkg2;
52
56
  }
53
- const readPackageJson = (file2, readFile2) => {
54
- let result;
55
- let current = file2;
56
- while (current !== "/" && !result) {
57
- if (dirname(current) === current) {
58
- break;
59
- }
60
- current = dirname(current);
61
- if (readFile2) {
62
- result = readFile2(join(current, "package.json"));
63
- }
64
- if (!readFile2) {
65
- result = PackageUtil.getPackageMetaFromModulePath(file2);
66
- } else if (!result?.name) {
67
- result = void 0;
68
- }
69
- }
70
- if (!result) {
71
- return;
72
- }
73
- if (readFile2 && (!result.name || !result.version)) {
74
- return readPackageJson(dirname(current), readFile2);
75
- }
76
- return {
77
- ...result,
78
- root: current
79
- };
80
- };
81
57
  const cache = this.getPackageContainFile(file);
82
58
  if (cache) {
83
59
  pkgsMap.set(file, cache);
@@ -147,5 +123,6 @@ class PackageGraph {
147
123
  }
148
124
  }
149
125
  export {
150
- PackageGraph
126
+ PackageGraph,
127
+ readPackageJson2 as readPackageJson
151
128
  };
@@ -1,6 +1,37 @@
1
+ import { dirname, join } from "path";
2
+ import { Package as PackageUtil } from "@rsdoctor/utils/common";
1
3
  function isPackagePath(path) {
2
4
  return /(^|[/\\])node_modules[/\\]/.test(path);
3
5
  }
6
+ const readPackageJson = (file, readFile) => {
7
+ let result;
8
+ let current = file;
9
+ while (current !== "/" && !result) {
10
+ if (dirname(current) === current) {
11
+ break;
12
+ }
13
+ current = dirname(current);
14
+ if (readFile) {
15
+ result = readFile(join(current, "package.json"));
16
+ }
17
+ if (!readFile) {
18
+ result = PackageUtil.getPackageMetaFromModulePath(file);
19
+ } else if (!result?.name) {
20
+ result = void 0;
21
+ }
22
+ }
23
+ if (!result) {
24
+ return;
25
+ }
26
+ if (readFile && (!result.name || !result.version)) {
27
+ return readPackageJson(dirname(current), readFile);
28
+ }
29
+ return {
30
+ ...result,
31
+ root: current
32
+ };
33
+ };
4
34
  export {
5
- isPackagePath
35
+ isPackagePath,
36
+ readPackageJson
6
37
  };
@@ -2,6 +2,7 @@ import { SDK } from '@rsdoctor/types';
2
2
  import type { ModuleGraph, Module } from '../module-graph';
3
3
  import { Package } from './package';
4
4
  import { PackageDependency } from './dependency';
5
+ export { readPackageJson } from './utils';
5
6
  export declare class PackageGraph implements SDK.PackageGraphInstance {
6
7
  static fromModuleGraph(graph: ModuleGraph, root: string, getPackageFile?: SDK.GetPackageFile): PackageGraph;
7
8
  private _root;
@@ -1 +1 @@
1
- {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../../../src/graph/package-graph/graph.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAEtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,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e,EAAE,MAAM,SAAS,CAAC;AAE1C,qBAAa,YAAa,YAAW,GAAG,CAAC,oBAAoB;IAC3D,MAAM,CAAC,eAAe,CACpB,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,MAAM,EACZ,cAAc,CAAC,EAAE,GAAG,CAAC,cAAc,GAClC,YAAY;IAmCf,OAAO,CAAC,KAAK,CAAS;IAEtB,OAAO,CAAC,aAAa,CAA2B;IAEhD,OAAO,CAAC,SAAS,CAAiB;IAElC,OAAO,CAAC,WAAW,CAAgC;IAEnD,OAAO,CAAC,WAAW,CAA8B;gBAErC,IAAI,EAAE,MAAM;IAIxB,WAAW;IAIX,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG,CAAC,cAAc;IA2ChE,gBAAgB,CAAC,IAAI,EAAE,MAAM;IAI7B,qBAAqB,CAAC,IAAI,EAAE,MAAM;IAIlC,iBAAiB,CAAC,IAAI,EAAE,MAAM;IAI9B,gBAAgB,CAAC,IAAI,EAAE,GAAG,CAAC,gBAAgB;IAQ3C,UAAU,CAAC,GAAG,EAAE,OAAO;IAcvB,0BAA0B,CAAC,GAAG,EAAE,OAAO;IAIvC,aAAa,CAAC,GAAG,EAAE,iBAAiB;IAMpC,yBAAyB;IAIzB,oBAAoB,IAAI,OAAO,EAAE,EAAE;IAWnC,MAAM,IAAI,GAAG,CAAC,gBAAgB;CAM/B"}
@@ -1,2 +1,4 @@
1
+ import { SDK } from '@rsdoctor/types';
1
2
  export declare function isPackagePath(path: string): boolean;
3
+ export declare const readPackageJson: (file: string, readFile?: SDK.GetPackageFile) => SDK.PackageBasicData | undefined;
2
4
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/graph/package-graph/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,WAEzC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/graph/package-graph/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAGtC,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,WAEzC;AAGD,eAAO,MAAM,eAAe,SACpB,MAAM,aACD,IAAI,cAAc,KAC5B,IAAI,gBAAgB,GAAG,SAgCzB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/graph",
3
- "version": "0.3.3",
3
+ "version": "0.3.5-beta.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/rsdoctor",
@@ -17,14 +17,15 @@
17
17
  "lodash": "^4.17.21",
18
18
  "socket.io": "4.7.2",
19
19
  "source-map": "^0.7.4",
20
- "@rsdoctor/types": "0.3.3",
21
- "@rsdoctor/utils": "0.3.3"
20
+ "@rsdoctor/types": "0.3.5-beta.0",
21
+ "@rsdoctor/utils": "0.3.5-beta.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/body-parser": "1.19.2",
25
25
  "@types/estree": "1.0.0",
26
26
  "@types/lodash": "^4.17.0",
27
27
  "@types/node": "^16",
28
+ "fs-extra": "^11.1.1",
28
29
  "tslib": "2.4.1",
29
30
  "typescript": "^5.2.2"
30
31
  },