silgi 0.8.25 → 0.8.27
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/_chunks/index.mjs +1 -1
- package/dist/cli/prepare.mjs +51 -27
- package/dist/meta/index.d.mts +1 -1
- package/dist/meta/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/_chunks/index.mjs
CHANGED
package/dist/cli/prepare.mjs
CHANGED
|
@@ -1044,11 +1044,13 @@ async function scanModules$1(silgi) {
|
|
|
1044
1044
|
function createDependencyGraph(modules) {
|
|
1045
1045
|
const graph = /* @__PURE__ */ new Map();
|
|
1046
1046
|
const inDegree = /* @__PURE__ */ new Map();
|
|
1047
|
+
const dependencyRelations = /* @__PURE__ */ new Map();
|
|
1047
1048
|
modules.forEach((module) => {
|
|
1048
1049
|
const key = module.meta?.configKey;
|
|
1049
1050
|
if (key) {
|
|
1050
1051
|
graph.set(key, /* @__PURE__ */ new Set());
|
|
1051
1052
|
inDegree.set(key, 0);
|
|
1053
|
+
dependencyRelations.set(key, { before: [], after: [] });
|
|
1052
1054
|
logger$1.debug(`Module registered: ${key}`);
|
|
1053
1055
|
}
|
|
1054
1056
|
});
|
|
@@ -1058,51 +1060,64 @@ function createDependencyGraph(modules) {
|
|
|
1058
1060
|
return;
|
|
1059
1061
|
const beforeDeps = module.meta?.beforeDependencies || [];
|
|
1060
1062
|
const afterDeps = module.meta?.afterDependencies || [];
|
|
1061
|
-
|
|
1062
|
-
if (
|
|
1063
|
-
logger$1.
|
|
1064
|
-
|
|
1065
|
-
|
|
1063
|
+
const missingDeps = [...beforeDeps, ...afterDeps].filter((dep) => !graph.has(dep));
|
|
1064
|
+
if (missingDeps.length > 0) {
|
|
1065
|
+
logger$1.error(`Module ${key} has missing dependencies: ${missingDeps.join(", ")}`);
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
modules.forEach((module) => {
|
|
1069
|
+
const key = module.meta?.configKey;
|
|
1070
|
+
if (!key)
|
|
1071
|
+
return;
|
|
1072
|
+
const beforeDeps = module.meta?.beforeDependencies || [];
|
|
1073
|
+
const afterDeps = module.meta?.afterDependencies || [];
|
|
1074
|
+
logger$1.debug(`
|
|
1075
|
+
Analyzing dependencies for module ${key}:`);
|
|
1066
1076
|
beforeDeps.forEach((dep) => {
|
|
1067
1077
|
if (graph.has(dep)) {
|
|
1068
1078
|
graph.get(dep)?.add(key);
|
|
1069
1079
|
inDegree.set(key, (inDegree.get(key) || 0) + 1);
|
|
1080
|
+
logger$1.debug(` ${key} must run after ${dep}`);
|
|
1070
1081
|
}
|
|
1071
1082
|
});
|
|
1072
1083
|
afterDeps.forEach((dep) => {
|
|
1073
|
-
if (graph.has(
|
|
1084
|
+
if (graph.has(dep)) {
|
|
1074
1085
|
graph.get(key)?.add(dep);
|
|
1075
1086
|
inDegree.set(dep, (inDegree.get(dep) || 0) + 1);
|
|
1087
|
+
logger$1.debug(` ${key} must run before ${dep}`);
|
|
1076
1088
|
}
|
|
1077
1089
|
});
|
|
1078
1090
|
});
|
|
1091
|
+
logger$1.debug("\nDependency Graph:");
|
|
1092
|
+
for (const [module, deps] of graph.entries()) {
|
|
1093
|
+
logger$1.debug(`${module} -> ${Array.from(deps).join(", ")} (in-degree: ${inDegree.get(module)})`);
|
|
1094
|
+
}
|
|
1079
1095
|
return { graph, inDegree };
|
|
1080
1096
|
}
|
|
1081
1097
|
function findCyclicDependencies(graph) {
|
|
1082
|
-
const visited = /* @__PURE__ */ new
|
|
1098
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1099
|
+
const recursionStack = /* @__PURE__ */ new Set();
|
|
1083
1100
|
const cycles = [];
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1101
|
+
function dfs(node, path = []) {
|
|
1102
|
+
visited.add(node);
|
|
1103
|
+
recursionStack.add(node);
|
|
1104
|
+
path.push(node);
|
|
1105
|
+
for (const neighbor of graph.get(node) || []) {
|
|
1106
|
+
if (recursionStack.has(neighbor)) {
|
|
1107
|
+
const cycleStart = path.indexOf(neighbor);
|
|
1089
1108
|
if (cycleStart !== -1) {
|
|
1090
|
-
cycles.push([...path.slice(cycleStart),
|
|
1109
|
+
cycles.push([...path.slice(cycleStart), neighbor]);
|
|
1091
1110
|
}
|
|
1111
|
+
} else if (!visited.has(neighbor)) {
|
|
1112
|
+
dfs(neighbor, [...path]);
|
|
1092
1113
|
}
|
|
1093
|
-
return;
|
|
1094
|
-
}
|
|
1095
|
-
visited.set(node, false);
|
|
1096
|
-
path.push(node);
|
|
1097
|
-
for (const neighbor of graph.get(node) || []) {
|
|
1098
|
-
visit(neighbor);
|
|
1099
1114
|
}
|
|
1115
|
+
recursionStack.delete(node);
|
|
1100
1116
|
path.pop();
|
|
1101
|
-
visited.set(node, true);
|
|
1102
1117
|
}
|
|
1103
1118
|
for (const node of graph.keys()) {
|
|
1104
1119
|
if (!visited.has(node)) {
|
|
1105
|
-
|
|
1120
|
+
dfs(node, []);
|
|
1106
1121
|
}
|
|
1107
1122
|
}
|
|
1108
1123
|
return cycles;
|
|
@@ -1111,36 +1126,45 @@ function topologicalSort(graphData) {
|
|
|
1111
1126
|
const { graph, inDegree } = graphData;
|
|
1112
1127
|
const order = [];
|
|
1113
1128
|
const queue = [];
|
|
1114
|
-
logger$1.debug("\
|
|
1129
|
+
logger$1.debug("\nStarting topological sort:");
|
|
1115
1130
|
logger$1.debug("Initial in-degrees:", Object.fromEntries(inDegree));
|
|
1116
1131
|
for (const [node, degree] of inDegree.entries()) {
|
|
1117
1132
|
if (degree === 0) {
|
|
1118
1133
|
queue.push(node);
|
|
1119
|
-
logger$1.debug(`
|
|
1134
|
+
logger$1.debug(`Adding initial module: ${node} (no dependencies)`);
|
|
1120
1135
|
}
|
|
1121
1136
|
}
|
|
1137
|
+
if (queue.length === 0) {
|
|
1138
|
+
logger$1.warn("No modules without dependencies found - possible circular reference");
|
|
1139
|
+
}
|
|
1122
1140
|
while (queue.length > 0) {
|
|
1123
1141
|
const node = queue.shift();
|
|
1124
1142
|
order.push(node);
|
|
1125
|
-
logger$1.debug(`
|
|
1143
|
+
logger$1.debug(`
|
|
1144
|
+
Processing: ${node}`);
|
|
1126
1145
|
for (const neighbor of graph.get(node) || []) {
|
|
1127
1146
|
const newDegree = (inDegree.get(neighbor) || 0) - 1;
|
|
1128
1147
|
inDegree.set(neighbor, newDegree);
|
|
1129
|
-
logger$1.debug(`
|
|
1148
|
+
logger$1.debug(` ${neighbor} dependencies remaining: ${newDegree}`);
|
|
1130
1149
|
if (newDegree === 0) {
|
|
1131
1150
|
queue.push(neighbor);
|
|
1132
|
-
logger$1.debug(`
|
|
1151
|
+
logger$1.debug(` Queuing: ${neighbor}`);
|
|
1133
1152
|
}
|
|
1134
1153
|
}
|
|
1135
1154
|
}
|
|
1136
1155
|
if (order.length !== graph.size) {
|
|
1137
1156
|
const cycles = findCyclicDependencies(graph);
|
|
1157
|
+
logger$1.debug("\nDependency graph state:");
|
|
1158
|
+
graph.forEach((deps, module) => {
|
|
1159
|
+
logger$1.debug(`${module} -> ${Array.from(deps).join(", ")}`);
|
|
1160
|
+
});
|
|
1138
1161
|
if (cycles.length > 0) {
|
|
1139
1162
|
const cycleStr = cycles.map((cycle) => ` ${cycle.join(" -> ")}`).join("\n");
|
|
1140
1163
|
throw new Error(`Circular dependencies detected:
|
|
1141
1164
|
${cycleStr}`);
|
|
1142
1165
|
} else {
|
|
1143
|
-
|
|
1166
|
+
const unresolvedModules = Array.from(graph.keys()).filter((key) => !order.includes(key));
|
|
1167
|
+
throw new Error(`Unable to resolve dependencies for modules: ${unresolvedModules.join(", ")}`);
|
|
1144
1168
|
}
|
|
1145
1169
|
}
|
|
1146
1170
|
logger$1.debug("\nFinal module order:", order.join(" -> "));
|
package/dist/meta/index.d.mts
CHANGED
package/dist/meta/index.d.ts
CHANGED