Simplify code since alias is no longer used

This commit is contained in:
Alexandru Dima 2019-12-18 12:09:59 +01:00
parent 5c82c65ae8
commit 8aa2205ff3
No known key found for this signature in database
GPG key ID: 6E58D7B045760DA0

View file

@ -12,7 +12,6 @@ const EDITOR_MODULE = {
output: 'editor.worker.js', output: 'editor.worker.js',
fallback: undefined fallback: undefined
}, },
alias: undefined,
}; };
const LANGUAGES = require('./languages'); const LANGUAGES = require('./languages');
const FEATURES = require('./features'); const FEATURES = require('./features');
@ -21,11 +20,7 @@ function resolveMonacoPath(filePath) {
return require.resolve(path.join('monaco-editor/esm', filePath)); return require.resolve(path.join('monaco-editor/esm', filePath));
} }
const languagesById = fromPairs( const languagesById = mapValues(LANGUAGES, (language, id) => mixin({ label: id }, language));
flatMap(toPairs(LANGUAGES), ([id, language]) =>
[id].concat(language.alias || []).map((label) => [label, mixin({ label }, language)])
)
);
const featuresById = mapValues(FEATURES, (feature, key) => mixin({ label: key }, feature)) const featuresById = mapValues(FEATURES, (feature, key) => mixin({ label: key }, feature))
function getFeaturesIds(userFeatures, predefinedFeaturesById) { function getFeaturesIds(userFeatures, predefinedFeaturesById) {
@ -66,7 +61,7 @@ class MonacoWebpackPlugin {
const publicPath = getPublicPath(compiler); const publicPath = getPublicPath(compiler);
const modules = [EDITOR_MODULE].concat(languages).concat(features); const modules = [EDITOR_MODULE].concat(languages).concat(features);
const workers = modules.map( const workers = modules.map(
({ label, alias, worker }) => worker && (mixin({ label, alias }, worker)) ({ label, worker }) => worker && (mixin({ label }, worker))
).filter(Boolean); ).filter(Boolean);
const rules = createLoaderRules(languages, features, workers, output, publicPath); const rules = createLoaderRules(languages, features, workers, output, publicPath);
const plugins = createPlugins(workers, output); const plugins = createPlugins(workers, output);
@ -156,10 +151,6 @@ function createPlugins(workers, outputPath) {
); );
} }
function flatMap(items, iteratee) {
return items.map(iteratee).reduce((acc, item) => [].concat(acc).concat(item), []);
}
function flatArr(items) { function flatArr(items) {
return items.reduce((acc, item) => { return items.reduce((acc, item) => {
if (Array.isArray(item)) { if (Array.isArray(item)) {
@ -169,10 +160,6 @@ function flatArr(items) {
}, []); }, []);
} }
function toPairs(object) {
return Object.keys(object).map((key) => [key, object[key]]);
}
function fromPairs(values) { function fromPairs(values) {
return values.reduce((acc, [key, value]) => Object.assign(acc, { [key]: value }), {}); return values.reduce((acc, [key, value]) => Object.assign(acc, { [key]: value }), {});
} }