From 8d8c1a8080930064e871c034d8aa4223a54dc02a Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Sun, 20 May 2018 00:36:05 +0100 Subject: [PATCH] Add getting webpack modules as properties of the WebpackModules object `WebpackModules.React` instead of `WebpackModules.getModuleByName('React')` --- client/src/modules/pluginapi.js | 11 +++++++---- client/src/modules/webpackmodules.js | 10 +++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/client/src/modules/pluginapi.js b/client/src/modules/pluginapi.js index 34c4c8df..15ae9991 100644 --- a/client/src/modules/pluginapi.js +++ b/client/src/modules/pluginapi.js @@ -437,7 +437,7 @@ export default class PluginApi { return WebpackModules.getModuleByPrototypes(props, false); } get WebpackModules() { - return Object.defineProperty({ + return new Proxy({ getModule: this.getWebpackModule.bind(this), getModuleByName: this.getWebpackModuleByName.bind(this), getModuleByDisplayName: this.getWebpackModuleByName.bind(this), @@ -447,9 +447,12 @@ export default class PluginApi { getModuleByPrototypeFields: this.getWebpackModuleByPrototypeFields.bind(this), getModulesByProperties: this.getWebpackModulesByProperties.bind(this), getModulesByPrototypeFields: this.getWebpackModulesByPrototypeFields.bind(this), - KnownModules: WebpackModules.KnownModules - }, 'require', { - get: () => this.webpackRequire + get KnownModules() { return WebpackModules.KnownModules }, + get require() { return WebpackModules.require } + }, { + get(WebpackModules, property) { + return WebpackModules[property] || WebpackModules.getModuleByName(property); + } }); } diff --git a/client/src/modules/webpackmodules.js b/client/src/modules/webpackmodules.js index d9078087..d6f9678b 100644 --- a/client/src/modules/webpackmodules.js +++ b/client/src/modules/webpackmodules.js @@ -179,7 +179,7 @@ const KnownModules = { ExternalLink: Filters.byCode(/\.trusted\b/) }; -export class WebpackModules { +class WebpackModules { /** * Finds a module using a filter function. @@ -303,3 +303,11 @@ export class WebpackModules { static get KnownModules() { return KnownModules } } + +const WebpackModulesProxy = new Proxy(WebpackModules, { + get(WebpackModules, property) { + return WebpackModules[property] || WebpackModules.getModuleByName(property); + } +}); + +export { WebpackModulesProxy as WebpackModules };