Merge pull request #33 from JsSucks/webpack
Remove async from WebpackModules, update filters and known modules
This commit is contained in:
commit
8a7320baab
|
@ -42,7 +42,7 @@ if (window.BetterDiscord) {
|
||||||
'vendor': {
|
'vendor': {
|
||||||
jQuery: require('jquery'),
|
jQuery: require('jquery'),
|
||||||
$: require('jquery'),
|
$: require('jquery'),
|
||||||
moment: window.wpm.getModuleByNameSync('Moment')
|
moment: WebpackModules.getModuleByName('Moment')
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -188,7 +188,7 @@ class Filters {
|
||||||
const component = selector(module);
|
const component = selector(module);
|
||||||
if (!component) return false;
|
if (!component) return false;
|
||||||
return props.every(property => component[property] !== undefined);
|
return props.every(property => component[property] !== undefined);
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static byPrototypeFields(fields, selector = m => m) {
|
static byPrototypeFields(fields, selector = m => m) {
|
||||||
|
@ -196,11 +196,8 @@ class Filters {
|
||||||
const component = selector(module);
|
const component = selector(module);
|
||||||
if (!component) return false;
|
if (!component) return false;
|
||||||
if (!component.prototype) return false;
|
if (!component.prototype) return false;
|
||||||
for (const field of fields) {
|
return fields.every(field => component.prototype[field] !== undefined);
|
||||||
if (!component.prototype[field]) return false;
|
};
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static byCode(search, selector = m => m) {
|
static byCode(search, selector = m => m) {
|
||||||
|
@ -208,22 +205,19 @@ class Filters {
|
||||||
const method = selector(module);
|
const method = selector(module);
|
||||||
if (!method) return false;
|
if (!method) return false;
|
||||||
return method.toString().search(search) !== -1;
|
return method.toString().search(search) !== -1;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static byDisplayName(name) {
|
static byDisplayName(name) {
|
||||||
return module => {
|
return module => {
|
||||||
return module && module.displayName === name;
|
return module && module.displayName === name;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static combine(...filters) {
|
static combine(...filters) {
|
||||||
return module => {
|
return module => {
|
||||||
for (const filter of filters) {
|
return filters.every(filter => filter(module));
|
||||||
if (!filter(module)) return false;
|
};
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,8 @@ const KnownModules = {
|
||||||
ChannelActions: Filters.byProperties(["selectChannel"]),
|
ChannelActions: Filters.byProperties(["selectChannel"]),
|
||||||
|
|
||||||
/* Current User Info, State and Settings */
|
/* Current User Info, State and Settings */
|
||||||
CurrentUserInfo: Filters.byProperties(["getToken"]),
|
UserInfoStore: Filters.byProperties(["getToken"]),
|
||||||
CurrentUserState: Filters.byProperties(["guildPositions"]),
|
UserSettingsStore: Filters.byProperties(["guildPositions"]),
|
||||||
AccountManager: Filters.byProperties(['register', 'login']),
|
AccountManager: Filters.byProperties(['register', 'login']),
|
||||||
UserSettingsUpdater: Filters.byProperties(['updateRemoteSettings']),
|
UserSettingsUpdater: Filters.byProperties(['updateRemoteSettings']),
|
||||||
OnlineWatcher: Filters.byProperties(['isOnline']),
|
OnlineWatcher: Filters.byProperties(['isOnline']),
|
||||||
|
@ -169,31 +169,31 @@ const Cache = {};
|
||||||
class WebpackModules {
|
class WebpackModules {
|
||||||
|
|
||||||
/* Synchronous */
|
/* Synchronous */
|
||||||
static getModuleByNameSync(name, fallback) {
|
static getModuleByName(name, fallback) {
|
||||||
if (Cache.hasOwnProperty(name)) return Cache[name];
|
if (Cache.hasOwnProperty(name)) return Cache[name];
|
||||||
if (KnownModules.hasOwnProperty(name)) fallback = KnownModules[name];
|
if (KnownModules.hasOwnProperty(name)) fallback = KnownModules[name];
|
||||||
if (!fallback) return null;
|
if (!fallback) return null;
|
||||||
return Cache[name] = this.getModuleSync(fallback, true);
|
return Cache[name] = this.getModule(fallback, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getModuleByDisplayNameSync(name) {
|
static getModuleByDisplayName(name) {
|
||||||
return this.getModuleSync(Filters.byDisplayName(name), true);
|
return this.getModule(Filters.byDisplayName(name), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getModuleByRegexSync(regex, first = true) {
|
static getModuleByRegex(regex, first = true) {
|
||||||
return this.getModuleSync(Filters.byCode(regex), first);
|
return this.getModule(Filters.byCode(regex), first);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getModuleByPrototypesSync(prototypes, first = true) {
|
static getModuleByPrototypes(prototypes, first = true) {
|
||||||
return this.getModuleSync(Filters.byPrototypeFields(prototypes), first);
|
return this.getModule(Filters.byPrototypeFields(prototypes), first);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getModuleByPropsSync(props, first = true) {
|
static getModuleByProps(props, first = true) {
|
||||||
return this.getModuleSync(Filters.byProperties(props), first);
|
return this.getModule(Filters.byProperties(props), first);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getModuleSync(filter, first = true) {
|
static getModule(filter, first = true) {
|
||||||
const modules = this.getAllModulesSync();
|
const modules = this.getAllModules();
|
||||||
const rm = [];
|
const rm = [];
|
||||||
for (let index in modules) {
|
for (let index in modules) {
|
||||||
if (!modules.hasOwnProperty(index)) continue;
|
if (!modules.hasOwnProperty(index)) continue;
|
||||||
|
@ -208,11 +208,11 @@ class WebpackModules {
|
||||||
if (first) return foundModule;
|
if (first) return foundModule;
|
||||||
rm.push(foundModule);
|
rm.push(foundModule);
|
||||||
}
|
}
|
||||||
return rm;
|
return first || rm.length == 0 ? null : rm;
|
||||||
}
|
}
|
||||||
|
|
||||||
static getAllModulesSync() {
|
static getAllModules() {
|
||||||
const id = 'bd-webpackmodulessync';
|
const id = 'bd-webpackmodules';
|
||||||
const __webpack_require__ = window['webpackJsonp'](
|
const __webpack_require__ = window['webpackJsonp'](
|
||||||
[],
|
[],
|
||||||
{
|
{
|
||||||
|
@ -223,67 +223,6 @@ class WebpackModules {
|
||||||
delete __webpack_require__.c[id];
|
delete __webpack_require__.c[id];
|
||||||
return __webpack_require__.c;
|
return __webpack_require__.c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Asynchronous */
|
|
||||||
static async getModuleByName(name, first = true, fallback) {
|
|
||||||
if (Cache.hasOwnProperty(name)) return Cache[name];
|
|
||||||
if (KnownModules.hasOwnProperty(name)) fallback = KnownModules[name];
|
|
||||||
if (!fallback) return null;
|
|
||||||
return Cache[name] = await this.getModule(fallback, first);
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getModuleByDisplayNameSync(name) {
|
|
||||||
return await this.getModule(Filters.byDisplayName(name), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getModuleByRegexSync(regex, first = true) {
|
|
||||||
return await this.getModule(Filters.byCode(regex), first);
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getModuleByPrototypes(prototypes, first = true) {
|
|
||||||
return await this.getModule(Filters.byPrototypeFields(prototypes), first);
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getModuleByProps(props, first = true) {
|
|
||||||
return await this.getModule(Filters.byProperties(props), first);
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getModule(filter, first = true) {
|
|
||||||
const modules = await this.getAllModules();
|
|
||||||
const rm = [];
|
|
||||||
for (let index in modules) {
|
|
||||||
if (!modules.hasOwnProperty(index)) continue;
|
|
||||||
const module = modules[index];
|
|
||||||
const { exports } = module;
|
|
||||||
let foundModule = null;
|
|
||||||
|
|
||||||
if (!exports) continue;
|
|
||||||
if (exports.__esModule && exports.default && filter(exports.default)) foundModule = exports.default;
|
|
||||||
if (filter(exports)) foundModule = exports;
|
|
||||||
if (!foundModule) continue;
|
|
||||||
if (first) return foundModule;
|
|
||||||
rm.push(foundModule);
|
|
||||||
}
|
|
||||||
return rm;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getAllModules() {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
const id = 'bd-webpackmodules';
|
|
||||||
window['webpackJsonp'](
|
|
||||||
[],
|
|
||||||
{
|
|
||||||
[id]: (module, exports, __webpack_require__) => {
|
|
||||||
delete __webpack_require__.c[id];
|
|
||||||
delete __webpack_require__.m[id];
|
|
||||||
resolve(__webpack_require__.c);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[id]
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { WebpackModules };
|
module.exports = { WebpackModules };
|
Loading…
Reference in New Issue