Skip to content

Commit e47ddf7

Browse files
committed
deep
1 parent 8af030b commit e47ddf7

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

dist/index.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,27 @@ function generateIndexFiles(abisDir, contracts) {
407407
}
408408
contractsByDir.get(dir).push(contract);
409409
}
410-
const sortedDirs = Array.from(contractsByDir.keys()).sort();
410+
const allDirs = /* @__PURE__ */ new Set();
411+
for (const contract of contracts) {
412+
const dir = path4.dirname(contract.srcPath);
413+
const parts = dir.split(path4.sep);
414+
for (let i = 1; i <= parts.length; i++) {
415+
const parentDir = parts.slice(0, i).join(path4.sep);
416+
if (parentDir !== ".") {
417+
allDirs.add(parentDir);
418+
}
419+
}
420+
}
421+
const sortedDirs = Array.from(allDirs).sort((a, b) => {
422+
const depthA = a.split(path4.sep).length;
423+
const depthB = b.split(path4.sep).length;
424+
if (depthA !== depthB) {
425+
return depthB - depthA;
426+
}
427+
return a.localeCompare(b);
428+
});
411429
for (const dir of sortedDirs) {
412-
if (dir === ".") continue;
413-
const dirContracts = contractsByDir.get(dir);
430+
const dirContracts = contractsByDir.get(dir) || [];
414431
generateDirectoryIndex(abisDir, dir, dirContracts, contracts);
415432
}
416433
generateRootIndex(abisDir, contractsByDir, sortedDirs);

src/transform-abi.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,35 @@ function generateIndexFiles(abisDir: string, contracts: ContractInfo[]): void {
121121
contractsByDir.get(dir)!.push(contract);
122122
}
123123

124-
// Sort directories for consistent output
125-
const sortedDirs = Array.from(contractsByDir.keys()).sort();
124+
// Find all directories that need index files (including intermediate ones)
125+
const allDirs = new Set<string>();
126126

127-
// Generate index.ts for each directory that has contracts
128-
for (const dir of sortedDirs) {
129-
if (dir === '.') continue; // Skip root directory for now
127+
for (const contract of contracts) {
128+
const dir = path.dirname(contract.srcPath);
129+
const parts = dir.split(path.sep);
130+
131+
// Add all parent directories
132+
for (let i = 1; i <= parts.length; i++) {
133+
const parentDir = parts.slice(0, i).join(path.sep);
134+
if (parentDir !== '.') {
135+
allDirs.add(parentDir);
136+
}
137+
}
138+
}
130139

131-
const dirContracts = contractsByDir.get(dir)!;
140+
// Sort directories by depth (deepest first) to ensure subdirectories are processed before parents
141+
const sortedDirs = Array.from(allDirs).sort((a, b) => {
142+
const depthA = a.split(path.sep).length;
143+
const depthB = b.split(path.sep).length;
144+
if (depthA !== depthB) {
145+
return depthB - depthA; // Deeper directories first
146+
}
147+
return a.localeCompare(b);
148+
});
149+
150+
// Generate index.ts for each directory
151+
for (const dir of sortedDirs) {
152+
const dirContracts = contractsByDir.get(dir) || [];
132153
generateDirectoryIndex(abisDir, dir, dirContracts, contracts);
133154
}
134155

0 commit comments

Comments
 (0)