Skip to content

Commit 774bd13

Browse files
committed
sort builds to prioritize most recent
1 parent 6ad6b1b commit 774bd13

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"devDependencies": {
3434
"@types/mocha": "^7.0.2",
35-
"@types/node": "^12.20.37",
35+
"@types/node": "^14.18.26",
3636
"ava": "^4.0.0",
3737
"c8": "^7.10.0",
3838
"code-style": "github:OpenZeppelin/code-style",

src/hardhat/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { extendConfig, task } from 'hardhat/config';
22
import { BuildInfo } from 'hardhat/types';
3+
import fs from 'fs/promises';
34

45
import './type-extensions';
56

@@ -20,9 +21,15 @@ task('docgen', async (_, hre) => {
2021
const { main } = await import('../main');
2122

2223
const buildInfoPaths = await hre.artifacts.getBuildInfoPaths();
23-
const builds: BuildInfo[] = await Promise.all(
24-
buildInfoPaths.map(async p => JSON.parse(await fs.readFile(p, 'utf8'))),
24+
const builds = await Promise.all(
25+
buildInfoPaths.map(async p => ({
26+
mtime: (await fs.stat(p)).mtimeMs,
27+
data: JSON.parse(await fs.readFile(p, 'utf8')) as BuildInfo,
28+
})),
2529
);
2630

27-
await main(builds, hre.config.docgen);
31+
// Sort most recently modified first
32+
builds.sort((a, b) => b.mtime - a.mtime);
33+
34+
await main(builds.map(b => b.data), hre.config.docgen);
2835
});

src/site.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
5656

5757
const seen = new Set<string>();
5858
const allItems: DocItemWithContext[] = [];
59-
const topLevelItems: DocItemWithContext[] = [];
6059
const pages: Record<string, DocItemWithContext[]> = {};
6160

6261
for (let { input, output } of builds) {
@@ -67,8 +66,7 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
6766
const build = { input, output, deref };
6867

6968
for (const { ast: file } of Object.values(output.sources)) {
70-
// Some files may appear in different builds but we only use one.
71-
if (seen.has(file.src)) continue;
69+
const isNewItem = !seen.has(file.src);
7270
seen.add(file.src);
7371

7472
for (const topLevelItem of file.nodes) {
@@ -80,18 +78,16 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
8078
__item_context: { page, item: topLevelItem as DocItemWithContext, file, build },
8179
});
8280

83-
topLevelItems.push(withContext);
84-
allItems.push(withContext);
85-
8681
if (page !== undefined) {
8782
(pages[page] ??= []).push(withContext);
8883
}
8984

9085
for (const item of findAll(docItemTypes, topLevelItem)) {
86+
if (isNewItem) allItems.push(item as DocItemWithContext);
9187
if (item === topLevelItem) continue;
9288
const contract = topLevelItem.nodeType === 'ContractDefinition' ? topLevelItem : undefined;
93-
const __item_context: DocItemContext = { page, item: item as DocItemWithContext, contract, file, build };
94-
allItems.push(Object.assign(item, { __item_context }));
89+
const __item_context: DocItemContext = { page, item: item as DocItemWithContext, contract, file, build };
90+
Object.assign(item, { __item_context });
9591
}
9692
}
9793
}
@@ -105,7 +101,7 @@ export function buildSite(builds: Build[], siteConfig: SiteConfig, properties: P
105101
}
106102

107103
return {
108-
items: topLevelItems,
104+
items: allItems.filter(i => i[DOC_ITEM_CONTEXT].contract === undefined),
109105
pages: Object.entries(pages).map(([id, items]) => ({ id, items })),
110106
};
111107
}

0 commit comments

Comments
 (0)