custom: fix import leak
This commit is contained in:
parent
afb7827f40
commit
8d64bf2697
2 changed files with 14 additions and 10 deletions
11
app/soapbox/custom.js
Normal file
11
app/soapbox/custom.js
Normal 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;
|
||||
};
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue