custom: fix import leak

This commit is contained in:
Alex Gleason 2022-03-03 23:38:59 -06:00
parent afb7827f40
commit 8d64bf2697
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 14 additions and 10 deletions

11
app/soapbox/custom.js Normal file
View file

@ -0,0 +1,11 @@
/**
* Functions for dealing with custom build configuration.
*/
/** Require a custom JSON file if it exists */
export const custom = (filename, fallback = {}) => {
const context = require.context('custom', false, /\.json$/);
const path = `./${filename}.json`;
return context.keys().includes(path) ? context(path) : fallback;
};

View file

@ -4,19 +4,12 @@ import { createSelector } from 'reselect';
import gte from 'semver/functions/gte';
import lt from 'semver/functions/lt';
// FIXME: We have to use a dynamic import to trick Webpack into treating it as
// optional, but this causes custom locales to become part of the main chunk.
const importCustom = path => {
try {
return require(`custom/${path}.json`);
} catch(e) {
return {};
}
};
import { custom } from 'soapbox/custom';
// Import custom overrides, if exists
const overrides = importCustom('features');
const overrides = custom('features');
// Truthy array convenience function
const any = arr => arr.some(Boolean);
// For uglification