Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebpackModules rewrite + remove external moment.js dependency #28

Merged
merged 4 commits into from
Jan 21, 2018
Merged

Conversation

zerebos
Copy link
Member

@zerebos zerebos commented Jan 21, 2018

This is for #11

  • Rewrite the WebpackModules module (both Sync and Async).
  • Adds a list of about ~100 known modules.
  • Added Filters to Utils (this will be used by WebpackModules as well as the modules Samogot will write)
  • Remove dependency on moment.js inclusion (package.json, index.js and Utils)
  • Add gulp script to core package.json allowing us to do npm run gulp babel without a global gulp install

@Jiiks Jiiks merged commit 623aaeb into master Jan 21, 2018
Copy link

@samogot samogot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's was already merged, while I was sleeping, but I'll leave this comments anyway.

@@ -42,7 +42,7 @@ if (window.BetterDiscord) {
'vendor': {
jQuery: require('jquery'),
$: require('jquery'),
moment: require('moment')
moment: window.wpm.getModuleByNameSync('Moment')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use local scope requires (WebpackModules) instead of global scope variables (window.wpm) as much as possible. To be honest I don't understand why we need window.wpm at all

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep nothing will be left in the window namespace in the end. It's there for debugging at the moment.

const component = selector(module);
if (!component) return false;
if (!component.prototype) return false;
for (const field of fields) {
Copy link

@samogot samogot Jan 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use fields.every here as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. I'll change that for this and the other one you mentioned


static combine(...filters) {
return module => {
for (const filter of filters) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.

OnlineWatcher: Filters.byProperties(['isOnline']),
CurrentUserIdle: Filters.byProperties(['getIdleTime']),
RelationshipStore: Filters.byProperties(['isBlocked']),
MentionStore: Filters.byProperties(["getMentions"]),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about UserSettingsStore?

UserSettingsStore: Filters.byProperties(['developerMode', 'locale']);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's a better name haha, I have it in the list as CurrentUserState but it is the same object

ContextMenuItem: Filters.byCode(/\.label\b.*\.hint\b.*\.action\b/),

/* In-Message Links */
ExternalLink: Filters.byCode(/\.trusted\b/)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of such list, but keeping unused stuff is dangerous. We definitely need to develop some kind of integration tests, to know when something from this list stops working on canary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we will definitely need some tests and such to see when things stop working. But I believe plugins that want to rely on it should check if the return is null so they don't error out

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, it might be the case of async versions. They might reject instead of resolve with null if there is no such module. But this isn't the case in current implementation. Btw look at new comment below

const { exports } = module;
static getModuleByDisplayNameSync(name) {
return this.getModuleSync(Filters.byDisplayName(name), true);
}
Copy link

@samogot samogot Jan 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost useless. AFAICS most of react components already either don't have DisplayName or aren't exported from it's modules.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still some with display name such as emoji picker, and several popouts

return Cache[name] = await this.getModule(fallback, first);
}

static async getModuleByDisplayNameSync(name) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sync?

return await this.getModule(Filters.byDisplayName(name), true);
}

static async getModuleByRegexSync(regex, first = true) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sync?

@@ -99,6 +224,49 @@ class WebpackModules {
return __webpack_require__.c;
}

/* Asynchronous */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we even need Async and Sync versions? Isn't webpackJsonp itself synchronous? AFAICS we won't get any benefit from making in looks like asynchronous.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree the asynchronous won't have much benefit. I just did it because Jiiks had both in the original version so I assumed they wanted both in the rewrite

}
return first ? rm[0].exports : rm;
return rm;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intentional that we will return empty array if no such module found, regardless of first parameter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I will fix this as well

@samogot
Copy link

samogot commented Jan 21, 2018

Btw, if you had written "Fixes #11" in commit message, Issue #11 would have automatically closed upon PR merging)

@zerebos
Copy link
Member Author

zerebos commented Jan 21, 2018

Yes I know but I wasn't sure it was complete yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants