silgi 0.8.22 → 0.8.24

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.
@@ -1,4 +1,4 @@
1
- const version = "0.8.22";
1
+ const version = "0.8.24";
2
2
  const devDependencies = {
3
3
  "@antfu/eslint-config": "^4.2.0",
4
4
  "@fastify/deepmerge": "^2.0.2",
@@ -1053,18 +1053,52 @@ function createDependencyGraph(modules) {
1053
1053
  });
1054
1054
  modules.forEach((module) => {
1055
1055
  const key = module.meta?.configKey;
1056
- const deps = module.meta?.dependencies || [];
1057
- if (key && deps.length > 0) {
1058
- deps.forEach((dep) => {
1059
- if (graph.has(dep)) {
1060
- graph.get(dep)?.add(key);
1061
- inDegree.set(key, (inDegree.get(key) || 0) + 1);
1062
- }
1063
- });
1064
- }
1056
+ if (!key)
1057
+ return;
1058
+ const beforeDeps = module.meta?.beforeDependencies || [];
1059
+ beforeDeps.forEach((dep) => {
1060
+ if (graph.has(dep)) {
1061
+ graph.get(dep)?.add(key);
1062
+ inDegree.set(key, (inDegree.get(key) || 0) + 1);
1063
+ }
1064
+ });
1065
+ const afterDeps = module.meta?.afterDependencies || [];
1066
+ afterDeps.forEach((dep) => {
1067
+ if (graph.has(key)) {
1068
+ graph.get(key)?.add(dep);
1069
+ inDegree.set(dep, (inDegree.get(dep) || 0) + 1);
1070
+ }
1071
+ });
1065
1072
  });
1066
1073
  return { graph, inDegree };
1067
1074
  }
1075
+ function findCyclicDependencies(graph) {
1076
+ const visited = /* @__PURE__ */ new Set();
1077
+ const recursionStack = /* @__PURE__ */ new Set();
1078
+ const cycles = [];
1079
+ 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
+ visited.add(node);
1088
+ recursionStack.add(node);
1089
+ path.push(node);
1090
+ for (const neighbor of graph.get(node) || []) {
1091
+ dfs(neighbor, [...path]);
1092
+ }
1093
+ recursionStack.delete(node);
1094
+ }
1095
+ for (const node of graph.keys()) {
1096
+ if (!visited.has(node)) {
1097
+ dfs(node);
1098
+ }
1099
+ }
1100
+ return cycles;
1101
+ }
1068
1102
  function topologicalSort(graphData) {
1069
1103
  const { graph, inDegree } = graphData;
1070
1104
  const order = [];
@@ -1082,8 +1116,12 @@ function topologicalSort(graphData) {
1082
1116
  queue.push(neighbor);
1083
1117
  }
1084
1118
  }
1085
- if (order.length !== graph.size)
1086
- throw new Error("Circular dependency detected");
1119
+ if (order.length !== graph.size) {
1120
+ const cycles = findCyclicDependencies(graph);
1121
+ const cycleStr = cycles.map((cycle) => cycle.join(" -> ")).join("\n");
1122
+ throw new Error(`Circular dependencies detected:
1123
+ ${cycleStr}`);
1124
+ }
1087
1125
  return order;
1088
1126
  }
1089
1127
 
@@ -1,4 +1,4 @@
1
- const version = "0.8.22";
1
+ const version = "0.8.24";
2
2
  const devDependencies = {
3
3
  "@antfu/eslint-config": "^4.2.0",
4
4
  "@fastify/deepmerge": "^2.0.2",
@@ -1,4 +1,4 @@
1
- const version = "0.8.22";
1
+ const version = "0.8.24";
2
2
  const devDependencies = {
3
3
  "@antfu/eslint-config": "^4.2.0",
4
4
  "@fastify/deepmerge": "^2.0.2",
@@ -467,7 +467,8 @@ interface ModuleMeta {
467
467
  * @private
468
468
  */
469
469
  _packageName?: string;
470
- readonly dependencies?: ReadonlyArray<string>;
470
+ readonly afterDependencies?: ReadonlyArray<string>;
471
+ readonly beforeDependencies?: ReadonlyArray<string>;
471
472
  [key: string]: unknown;
472
473
  }
473
474
  interface ResolvedModuleMeta extends ModuleMeta {
@@ -503,7 +504,7 @@ interface ModuleDefinition<TOptions extends ModuleOptionsCustom, TOptionsDefault
503
504
  meta?: ModuleMeta;
504
505
  defaults?: TOptionsDefaults | ((silgi: SilgiCLI) => Awaitable<TOptionsDefaults>);
505
506
  hooks?: Partial<SilgiCLIHooks>;
506
- setup?: (this: void, resolvedOptions: TWith extends true ? ResolvedModuleOptions<TOptions, TOptionsDefaults> : TOptions, silgi: SilgiCLI) => ModuleSetupReturn;
507
+ setup?: (this: void, resolvedOptions: TWith extends true ? ResolvedModuleOptions<TOptions, TOptionsDefaults> : TOptions, silgi: SilgiCLI & SilgiModuleOptions) => ModuleSetupReturn;
507
508
  }
508
509
  interface ModuleSetupInstallResult {
509
510
  /**
@@ -467,7 +467,8 @@ interface ModuleMeta {
467
467
  * @private
468
468
  */
469
469
  _packageName?: string;
470
- readonly dependencies?: ReadonlyArray<string>;
470
+ readonly afterDependencies?: ReadonlyArray<string>;
471
+ readonly beforeDependencies?: ReadonlyArray<string>;
471
472
  [key: string]: unknown;
472
473
  }
473
474
  interface ResolvedModuleMeta extends ModuleMeta {
@@ -503,7 +504,7 @@ interface ModuleDefinition<TOptions extends ModuleOptionsCustom, TOptionsDefault
503
504
  meta?: ModuleMeta;
504
505
  defaults?: TOptionsDefaults | ((silgi: SilgiCLI) => Awaitable<TOptionsDefaults>);
505
506
  hooks?: Partial<SilgiCLIHooks>;
506
- setup?: (this: void, resolvedOptions: TWith extends true ? ResolvedModuleOptions<TOptions, TOptionsDefaults> : TOptions, silgi: SilgiCLI) => ModuleSetupReturn;
507
+ setup?: (this: void, resolvedOptions: TWith extends true ? ResolvedModuleOptions<TOptions, TOptionsDefaults> : TOptions, silgi: SilgiCLI & SilgiModuleOptions) => ModuleSetupReturn;
507
508
  }
508
509
  interface ModuleSetupInstallResult {
509
510
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.8.22",
4
+ "version": "0.8.24",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {