Skip to content

Commit 7f6e980

Browse files
committed
fixup!
1 parent 7bc65cb commit 7f6e980

File tree

1 file changed

+18
-31
lines changed

1 file changed

+18
-31
lines changed

scripts/compare-builds/web.mjs

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -102,52 +102,39 @@ const changedFiles = allFiles.filter(
102102
);
103103

104104
if (changedFiles.length) {
105-
// Separate HTML/JS pairs from other files
106-
const pairs = [];
105+
// Separate HTML files and their matching JS files from other files
106+
const pages = changedFiles.filter(f => path.extname(f) === '.html');
107107
const other = [];
108-
const processed = new Set();
109108

110-
for (const file of changedFiles) {
111-
if (processed.has(file)) {
112-
continue;
113-
}
109+
// Get all HTML base names
110+
const htmlBaseNames = new Set(pages.map(f => path.basename(f, '.html')));
114111

115-
const basename = path.basename(file, path.extname(file));
116-
const hasHtml = changedFiles.some(
117-
f =>
118-
path.basename(f, path.extname(f)) === basename &&
119-
path.extname(f) === '.html'
120-
);
121-
const hasJs = changedFiles.some(
122-
f =>
123-
path.basename(f, path.extname(f)) === basename &&
124-
path.extname(f) === '.js'
125-
);
112+
for (const file of changedFiles) {
113+
const ext = path.extname(file);
114+
const basename = path.basename(file, ext);
126115

127-
if (hasHtml && hasJs) {
128-
changedFiles
129-
.filter(f => path.basename(f, path.extname(f)) === basename)
130-
.forEach(f => {
131-
pairs.push(f);
132-
processed.add(f);
133-
});
116+
if (ext === '.js' && htmlBaseNames.has(basename)) {
117+
// JS files go to pages only if they have a matching HTML file
118+
pages.push(file);
134119
} else {
135120
other.push(file);
136-
processed.add(file);
137121
}
138122
}
139123

140-
pairs.sort();
124+
pages.sort();
141125
other.sort();
142126

143127
console.log('## Web Generator\n');
144-
console.log(generateTable(other, baseStats, headStats));
145128

146-
if (pairs.length) {
129+
if (other.length) {
130+
console.log(generateTable(other, baseStats, headStats));
131+
}
132+
133+
if (pages.length) {
147134
console.log(
148135
details(
149-
`Pages (${pairs.length / 2})`,
150-
generateTable(pairs, baseStats, headStats)
136+
`Pages (${pages.filter(f => path.extname(f) === '.html').length})`,
137+
generateTable(pages, baseStats, headStats)
151138
)
152139
);
153140
}

0 commit comments

Comments
 (0)