@eggjs/tegg-common-util 4.0.2-beta.2 → 4.0.2-beta.22

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/dist/Graph.d.ts CHANGED
@@ -37,8 +37,17 @@ declare class Graph<T extends GraphNodeObj, M extends EdgeMeta = EdgeMeta> {
37
37
  addVertex(node: GraphNode<T, M>): boolean;
38
38
  addEdge(from: GraphNode<T, M>, to: GraphNode<T, M>, meta?: M): boolean;
39
39
  findToNode(id: string, meta: M): GraphNode<T, M> | undefined;
40
+ /**
41
+ * @deprecated Use loopPath() instead. This method is kept for compatibility.
42
+ */
40
43
  appendVertexToPath(node: GraphNode<T, M>, accessPath: GraphPath<T, M>, meta?: M): boolean;
44
+ private buildLoopPath;
45
+ private findLoopPath;
41
46
  loopPath(): GraphPath<T, M> | undefined;
47
+ private accessNodeWithSet;
48
+ /**
49
+ * @deprecated Prefer sort(), which uses Set-based traversal directly.
50
+ */
42
51
  accessNode(node: GraphNode<T, M>, nodes: Array<GraphNode<T, M>>, accessed: boolean[], res: Array<GraphNode<T, M>>): void;
43
52
  sort(): Array<GraphNode<T, M>>;
44
53
  }
package/dist/Graph.js CHANGED
@@ -82,37 +82,74 @@ var Graph = class {
82
82
  if (!node) return void 0;
83
83
  for (const { node: toNode, meta: edgeMeta } of node.toNodeMap.values()) if (edgeMeta && meta.equal(edgeMeta)) return toNode;
84
84
  }
85
+ /**
86
+ * @deprecated Use loopPath() instead. This method is kept for compatibility.
87
+ */
85
88
  appendVertexToPath(node, accessPath, meta) {
86
89
  if (!accessPath.pushVertex(node, meta)) return false;
87
90
  for (const toNode of node.toNodeMap.values()) if (!this.appendVertexToPath(toNode.node, accessPath, toNode.meta)) return false;
88
91
  accessPath.popVertex();
89
92
  return true;
90
93
  }
91
- loopPath() {
94
+ buildLoopPath(stack, node, meta) {
92
95
  const accessPath = new GraphPath();
96
+ for (const pathNode of stack) accessPath.pushVertex(pathNode.node, pathNode.meta);
97
+ accessPath.pushVertex(node, meta);
98
+ return accessPath;
99
+ }
100
+ findLoopPath(node, visiting, visited, stack, meta) {
101
+ if (visited.has(node.id)) return;
102
+ if (visiting.has(node.id)) return this.buildLoopPath(stack, node, meta);
103
+ visiting.add(node.id);
104
+ stack.push({
105
+ node,
106
+ meta
107
+ });
108
+ for (const toNode of node.toNodeMap.values()) {
109
+ const loopPath = this.findLoopPath(toNode.node, visiting, visited, stack, toNode.meta);
110
+ if (loopPath) return loopPath;
111
+ }
112
+ stack.pop();
113
+ visiting.delete(node.id);
114
+ visited.add(node.id);
115
+ }
116
+ loopPath() {
117
+ const visiting = /* @__PURE__ */ new Set();
118
+ const visited = /* @__PURE__ */ new Set();
119
+ const stack = [];
93
120
  const nodes = Array.from(this.nodes.values());
94
- for (const node of nodes) if (!this.appendVertexToPath(node, accessPath)) return accessPath;
121
+ for (const node of nodes) {
122
+ const loopPath = this.findLoopPath(node, visiting, visited, stack);
123
+ if (loopPath) return loopPath;
124
+ }
95
125
  }
96
- accessNode(node, nodes, accessed, res) {
97
- if (accessed[nodes.indexOf(node)]) return;
98
- if (!node.toNodeMap.size) {
99
- accessed[nodes.indexOf(node)] = true;
100
- res.push(node);
101
- return;
126
+ accessNodeWithSet(node, accessed, visiting, res) {
127
+ if (accessed.has(node)) return;
128
+ if (visiting.has(node)) throw new Error("graph has recursive deps: " + node);
129
+ visiting.add(node);
130
+ try {
131
+ for (const toNode of node.toNodeMap.values()) this.accessNodeWithSet(toNode.node, accessed, visiting, res);
132
+ } finally {
133
+ visiting.delete(node);
102
134
  }
103
- for (const toNode of node.toNodeMap.values()) this.accessNode(toNode.node, nodes, accessed, res);
104
- accessed[nodes.indexOf(node)] = true;
135
+ accessed.add(node);
105
136
  res.push(node);
106
137
  }
138
+ /**
139
+ * @deprecated Prefer sort(), which uses Set-based traversal directly.
140
+ */
141
+ accessNode(node, nodes, accessed, res) {
142
+ const accessedSet = /* @__PURE__ */ new Set();
143
+ for (let i = 0; i < nodes.length; ++i) if (accessed[i]) accessedSet.add(nodes[i]);
144
+ this.accessNodeWithSet(node, accessedSet, /* @__PURE__ */ new Set(), res);
145
+ for (let i = 0; i < nodes.length; ++i) accessed[i] = accessedSet.has(nodes[i]);
146
+ }
107
147
  sort() {
108
148
  const res = [];
109
149
  const nodes = Array.from(this.nodes.values());
110
- const accessed = [];
111
- for (let i = 0; i < nodes.length; ++i) accessed.push(false);
112
- for (let i = 0; i < nodes.length; ++i) {
113
- const node = nodes[i];
114
- this.accessNode(node, nodes, accessed, res);
115
- }
150
+ const accessed = /* @__PURE__ */ new Set();
151
+ const visiting = /* @__PURE__ */ new Set();
152
+ for (const node of nodes) this.accessNodeWithSet(node, accessed, visiting, res);
116
153
  return res;
117
154
  }
118
155
  };
@@ -7,7 +7,8 @@ declare class ModuleReferenceConfigHelp {
7
7
  }
8
8
  declare class ModuleConfigUtil {
9
9
  #private;
10
- static configNames: string[] | undefined;
10
+ static get configNames(): string[] | undefined;
11
+ static set configNames(configNames: string[] | undefined);
11
12
  static setConfigNames(configNames: string[] | undefined): void;
12
13
  static readModuleReference(baseDir: string, options?: ReadModuleReferenceOptions): readonly ModuleReference[];
13
14
  private static readModuleReferenceFromModuleJson;
@@ -2,6 +2,7 @@ import { FSUtil } from "./FSUtil.js";
2
2
  import assert from "node:assert";
3
3
  import fs, { promises } from "node:fs";
4
4
  import path from "node:path";
5
+ import { TeggScope } from "@eggjs/tegg-types";
5
6
  import { importResolve } from "@eggjs/utils";
6
7
  import { extend } from "extend2";
7
8
  import globby from "globby";
@@ -17,8 +18,14 @@ var ModuleReferenceConfigHelp = class {
17
18
  }
18
19
  };
19
20
  const DEFAULT_READ_MODULE_REF_OPTS = { deep: 10 };
21
+ const CONFIG_NAMES_SLOT = Symbol("tegg:common-util:moduleConfigNames");
20
22
  var ModuleConfigUtil = class ModuleConfigUtil {
21
- static configNames;
23
+ static get configNames() {
24
+ return TeggScope.getOr(CONFIG_NAMES_SLOT, () => void 0, "ModuleConfigUtil.configNames");
25
+ }
26
+ static set configNames(configNames) {
27
+ TeggScope.set(CONFIG_NAMES_SLOT, configNames);
28
+ }
22
29
  static setConfigNames(configNames) {
23
30
  ModuleConfigUtil.configNames = configNames;
24
31
  }
package/dist/StackUtil.js CHANGED
@@ -51,7 +51,7 @@ var StackUtil = class {
51
51
  let callSite = stacks[stackIndex];
52
52
  if (callSite) {
53
53
  const fileName$1 = callSite.scriptName;
54
- if (fileName$1.includes("/@oxc-project/runtime/") || fileName$1.includes("\\@oxc-project\\runtime\\")) callSite = stacks[stackIndex + 1];
54
+ if (fileName$1.includes("/@oxc-project/runtime/") || fileName$1.includes("\\@oxc-project\\runtime\\") || fileName$1.includes("@oxc-project+runtime@")) callSite = stacks[stackIndex + 1];
55
55
  }
56
56
  let fileName = "";
57
57
  if (callSite) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eggjs/tegg-common-util",
3
- "version": "4.0.2-beta.2",
3
+ "version": "4.0.2-beta.22",
4
4
  "description": "common util for tegg",
5
5
  "keywords": [
6
6
  "collection",
@@ -31,15 +31,22 @@
31
31
  "./package.json": "./package.json"
32
32
  },
33
33
  "publishConfig": {
34
- "access": "public"
34
+ "access": "public",
35
+ "exports": {
36
+ ".": "./dist/index.js",
37
+ "./package.json": "./package.json"
38
+ }
39
+ },
40
+ "scripts": {
41
+ "typecheck": "tsgo --noEmit"
35
42
  },
36
43
  "dependencies": {
44
+ "@eggjs/tegg-types": "4.0.2-beta.22",
45
+ "@eggjs/utils": "5.0.2-beta.22",
37
46
  "extend2": "^4.0.0",
38
47
  "globby": "^11.0.2",
39
48
  "js-yaml": "^4.1.1",
40
- "reflect-metadata": "^0.2.2",
41
- "@eggjs/tegg-types": "4.0.2-beta.2",
42
- "@eggjs/utils": "5.0.2-beta.2"
49
+ "reflect-metadata": "^0.2.2"
43
50
  },
44
51
  "devDependencies": {
45
52
  "@types/js-yaml": "^4.0.9",
@@ -48,8 +55,5 @@
48
55
  },
49
56
  "engines": {
50
57
  "node": ">=22.18.0"
51
- },
52
- "scripts": {
53
- "typecheck": "tsgo --noEmit"
54
58
  }
55
- }
59
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2017-present Alibaba Group Holding Limited and other contributors.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.