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