Make sure non-existing icons do break the build
Summary: Builds didn't fail when using non-existing icons, and the error message was not very clear Also added verification that, before automatically adding an icon to the prefetcher, that icon does exists Reviewed By: jknoxville Differential Revision: D19264063 fbshipit-source-id: 4320d5b960e85e3f15bbca13d69f3063b983a511
This commit is contained in:
committed by
Facebook Github Bot
parent
b7c8d5b996
commit
8a84bcbe29
@@ -67,12 +67,31 @@ function buildIconURL(name, size, density) {
|
||||
if (!isProduction) {
|
||||
const existing = ICONS[name] || (ICONS[name] = []);
|
||||
if (!existing.includes(size)) {
|
||||
existing.push(size);
|
||||
existing.sort();
|
||||
fs.writeFileSync(iconsPath, JSON.stringify(ICONS, null, 2), 'utf8');
|
||||
console.warn(
|
||||
`Added uncached icon "${name}: [${size}]" to /static/icons.json. Restart Flipper to apply the change.`,
|
||||
);
|
||||
// Check if that icon actually exists!
|
||||
fetch(url)
|
||||
.then(res => {
|
||||
if (res.status === 200) {
|
||||
// the icon exists
|
||||
existing.push(size);
|
||||
existing.sort();
|
||||
fs.writeFileSync(
|
||||
iconsPath,
|
||||
JSON.stringify(ICONS, null, 2),
|
||||
'utf8',
|
||||
);
|
||||
console.warn(
|
||||
`Added uncached icon "${name}: [${size}]" to /static/icons.json. Restart Flipper to apply the change.`,
|
||||
);
|
||||
} else {
|
||||
throw new Error(
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
`Trying to use icon '${name}' with size ${size} and density ${density}, however the icon doesn't seem to exists at ${url}: ${
|
||||
res.status
|
||||
}`,
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch(e => console.error(e));
|
||||
}
|
||||
} else {
|
||||
console.warn(
|
||||
|
||||
Reference in New Issue
Block a user