From 0c34f3a31324dae12157dfe86e872661ae76cc30 Mon Sep 17 00:00:00 2001 From: Crawl Date: Wed, 5 Jul 2017 11:53:53 +0200 Subject: [PATCH] Update dependencies & make webpack great again --- package.json | 15 ++- src/client/Client.js | 2 +- src/client/ClientDataResolver.js | 10 +- src/structures/GroupDMChannel.js | 2 +- src/structures/Guild.js | 96 +++++++++---------- src/structures/GuildMember.js | 12 +-- src/structures/MessageCollector.js | 1 - src/structures/ReactionCollector.js | 1 - src/structures/Role.js | 8 +- src/structures/User.js | 7 +- src/structures/interfaces/TextBasedChannel.js | 52 +++++----- webpack.config.js | 3 +- 12 files changed, 103 insertions(+), 106 deletions(-) diff --git a/package.json b/package.json index 594c2f506..d4657de1b 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "dependencies": { "long": "^3.2.0", "prism-media": "^0.0.1", - "snekfetch": "^3.1.0", + "snekfetch": "^3.2.0", "tweetnacl": "^1.0.0", "ws": "^3.0.0" }, @@ -45,16 +45,15 @@ "opusscript": "^0.0.3", "sodium": "^2.0.1", "libsodium-wrappers": "^0.5.1", - "uws": "^0.14.1" + "uws": "^8.14.0" }, "devDependencies": { - "@types/node": "^7.0.0", + "@types/node": "^8.0.0", "discord.js-docgen": "hydrabolt/discord.js-docgen", - "eslint": "^3.19.0", - "parallel-webpack": "^1.6.0", - "uglify-js": "mishoo/UglifyJS2#harmony-v2.8.22", - "uglifyjs-webpack-plugin": "^0.4.3", - "webpack": "^2.2.0" + "eslint": "^4.0.0", + "parallel-webpack": "^2.0.0", + "uglifyjs-webpack-plugin": "iCrawl/uglifyjs-webpack-plugin", + "webpack": "^3.0.0" }, "engines": { "node": ">=8.0.0" diff --git a/src/client/Client.js b/src/client/Client.js index e2748fc67..2c0645614 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -415,7 +415,7 @@ class Client extends EventEmitter { */ fetchApplication(id = '@me') { return this.api.oauth2.applications[id].get() - .then(app => new OAuth2Application(this, app)); + .then(app => new OAuth2Application(this, app)); } /** diff --git a/src/client/ClientDataResolver.js b/src/client/ClientDataResolver.js index 4de4c7dee..edb8a015f 100644 --- a/src/client/ClientDataResolver.js +++ b/src/client/ClientDataResolver.js @@ -193,11 +193,11 @@ class ClientDataResolver { return new Promise((resolve, reject) => { if (/^https?:\/\//.test(resource)) { snekfetch.get(resource) - .end((err, res) => { - if (err) return reject(err); - if (!(res.body instanceof Buffer)) return reject(new TypeError('REQ_BODY_TYPE')); - return resolve(res.body); - }); + .end((err, res) => { + if (err) return reject(err); + if (!(res.body instanceof Buffer)) return reject(new TypeError('REQ_BODY_TYPE')); + return resolve(res.body); + }); } else { const file = path.resolve(resource); fs.stat(file, (err, stats) => { diff --git a/src/structures/GroupDMChannel.js b/src/structures/GroupDMChannel.js index 5e1ba6dcb..7211a6275 100644 --- a/src/structures/GroupDMChannel.js +++ b/src/structures/GroupDMChannel.js @@ -136,7 +136,7 @@ class GroupDMChannel extends Channel { { nick, access_token: accessTokenOrUser } : { recipient: id }; return this.client.api.channels[this.id].recipients[id].put({ data }) - .then(() => this); + .then(() => this); } /** diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 5be248bdd..d4436dc0b 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -394,14 +394,14 @@ class Guild { */ fetchInvites() { return this.client.api.guilds[this.id].invites.get() - .then(inviteItems => { - const invites = new Collection(); - for (const inviteItem of inviteItems) { - const invite = new Invite(this.client, inviteItem); - invites.set(invite.code, invite); - } - return invites; - }); + .then(inviteItems => { + const invites = new Collection(); + for (const inviteItem of inviteItems) { + const invite = new Invite(this.client, inviteItem); + invites.set(invite.code, invite); + } + return invites; + }); } /** @@ -490,10 +490,10 @@ class Guild { if (!user) return Promise.reject(new Error('User is not cached. Use Client.fetchUser first.')); if (this.members.has(user.id)) return Promise.resolve(this.members.get(user.id)); return this.client.api.guilds[this.id].members[user.id].get() - .then(data => { - if (cache) return this.client.actions.GuildMemberGet.handle(this, data).member; - else return new GuildMember(this, data); - }); + .then(data => { + if (cache) return this.client.actions.GuildMemberGet.handle(this, data).member; + else return new GuildMember(this, data); + }); } /** @@ -594,7 +594,7 @@ class Guild { _data.explicit_content_filter = Number(data.explicitContentFilter); } return this.client.api.guilds[this.id].patch({ data: _data, reason }) - .then(newData => this.client.actions.GuildUpdate.handle(newData).updated); + .then(newData => this.client.actions.GuildUpdate.handle(newData).updated); } /** @@ -739,11 +739,11 @@ class Guild { */ acknowledge() { return this.client.api.guilds[this.id].ack - .post({ data: { token: this.client.rest._ackToken } }) - .then(res => { - if (res.token) this.client.rest._ackToken = res.token; - return this; - }); + .post({ data: { token: this.client.rest._ackToken } }) + .then(res => { + if (res.token) this.client.rest._ackToken = res.token; + return this; + }); } /** @@ -778,15 +778,15 @@ class Guild { const id = this.client.resolver.resolveUserID(user); if (!id) return Promise.reject(new Error('Couldn\'t resolve the user ID to ban.')); return this.client.api.guilds[this.id].bans[id].put({ query: options }) - .then(() => { - if (user instanceof GuildMember) return user; - const _user = this.client.resolver.resolveUser(id); - if (_user) { - const member = this.client.resolver.resolveGuildMember(this, _user); - return member || _user; - } - return id; - }); + .then(() => { + if (user instanceof GuildMember) return user; + const _user = this.client.resolver.resolveUser(id); + if (_user) { + const member = this.client.resolver.resolveGuildMember(this, _user); + return member || _user; + } + return id; + }); } /** @@ -965,10 +965,10 @@ class Guild { .then(emoji => this.client.actions.GuildEmojiCreate.handle(this, emoji).emoji); } else { return this.client.resolver.resolveBuffer(attachment) - .then(data => { - const dataURI = this.client.resolver.resolveBase64(data); - return this.createEmoji(dataURI, name, roles); - }); + .then(data => { + const dataURI = this.client.resolver.resolveBase64(data); + return this.createEmoji(dataURI, name, roles); + }); } } @@ -980,7 +980,7 @@ class Guild { deleteEmoji(emoji) { if (!(emoji instanceof Emoji)) emoji = this.emojis.get(emoji); return this.client.api.guilds(this.id).emojis[emoji.id].delete() - .then(() => this.client.actions.GuildEmojiDelete.handle(emoji).data); + .then(() => this.client.actions.GuildEmojiDelete.handle(emoji).data); } /** @@ -995,7 +995,7 @@ class Guild { leave() { if (this.ownerID === this.client.user.id) return Promise.reject(new Error('Guild is owned by the client.')); return this.client.api.users['@me'].guilds[this.id].delete() - .then(() => this.client.actions.GuildDelete.handle({ id: this.id }).guild); + .then(() => this.client.actions.GuildDelete.handle({ id: this.id }).guild); } /** @@ -1009,7 +1009,7 @@ class Guild { */ delete() { return this.client.api.guilds[this.id].delete() - .then(() => this.client.actions.GuildDelete.handle({ id: this.id }).guild); + .then(() => this.client.actions.GuildDelete.handle({ id: this.id }).guild); } /** @@ -1167,12 +1167,12 @@ class Guild { updatedRoles = updatedRoles.map((r, i) => ({ id: r.id, position: i })); return this.client.api.guilds[this.id].roles.patch({ data: updatedRoles }) - .then(() => - this.client.actions.GuildRolesPositionUpdate.handle({ - guild_id: this.id, - roles: updatedRoles, - }).guild - ); + .then(() => + this.client.actions.GuildRolesPositionUpdate.handle({ + guild_id: this.id, + roles: updatedRoles, + }).guild + ); } /** @@ -1197,12 +1197,12 @@ class Guild { updatedChannels = updatedChannels.map((r, i) => ({ id: r.id, position: i })); return this.client.api.guilds[this.id].channels.patch({ data: updatedChannels }) - .then(() => - this.client.actions.GuildChannelsPositionUpdate.handle({ - guild_id: this.id, - roles: updatedChannels, - }).guild - ); + .then(() => + this.client.actions.GuildChannelsPositionUpdate.handle({ + guild_id: this.id, + roles: updatedChannels, + }).guild + ); } /** @@ -1229,8 +1229,8 @@ class Guild { _sortPositionWithID(collection) { return collection.sort((a, b) => a.position !== b.position ? - a.position - b.position : - Long.fromString(a.id).sub(Long.fromString(b.id)).toNumber() + a.position - b.position : + Long.fromString(a.id).sub(Long.fromString(b.id)).toNumber() ); } } diff --git a/src/structures/GuildMember.js b/src/structures/GuildMember.js index 777fc93fe..8ffea8627 100644 --- a/src/structures/GuildMember.js +++ b/src/structures/GuildMember.js @@ -485,12 +485,12 @@ class GuildMember { */ kick(reason) { return this.client.api.guilds[this.guild.id].members[this.user.id].delete({ reason }) - .then(() => - this.client.actions.GuildMemberRemove.handle({ - guild_id: this.guild.id, - user: this.user, - }).member - ); + .then(() => + this.client.actions.GuildMemberRemove.handle({ + guild_id: this.guild.id, + user: this.user, + }).member + ); } /** diff --git a/src/structures/MessageCollector.js b/src/structures/MessageCollector.js index 8895ea2c1..0a0a8d405 100644 --- a/src/structures/MessageCollector.js +++ b/src/structures/MessageCollector.js @@ -11,7 +11,6 @@ const Collector = require('./interfaces/Collector'); * @extends {Collector} */ class MessageCollector extends Collector { - /** * @param {TextChannel|DMChannel|GroupDMChannel} channel The channel * @param {CollectorFilter} filter The filter to be applied to this collector diff --git a/src/structures/ReactionCollector.js b/src/structures/ReactionCollector.js index 5e0b7d5a1..a54687d32 100644 --- a/src/structures/ReactionCollector.js +++ b/src/structures/ReactionCollector.js @@ -13,7 +13,6 @@ const Collection = require('../util/Collection'); * @extends {Collector} */ class ReactionCollector extends Collector { - /** * @param {Message} message The message upon which to collect reactions * @param {CollectorFilter} filter The filter to apply to this collector diff --git a/src/structures/Role.js b/src/structures/Role.js index 079e90ca9..4ba915674 100644 --- a/src/structures/Role.js +++ b/src/structures/Role.js @@ -212,7 +212,7 @@ class Role { }, reason, }) - .then(role => this.client.actions.GuildRoleUpdate.handle({ role, guild_id: this.guild.id }).updated); + .then(role => this.client.actions.GuildRoleUpdate.handle({ role, guild_id: this.guild.id }).updated); } /** @@ -312,9 +312,9 @@ class Role { */ delete(reason) { return this.client.api.guilds[this.guild.id].roles[this.id].delete({ reason }) - .then(() => - this.client.actions.GuildRoleDelete.handle({ guild_id: this.guild.id, role_id: this.id }).role - ); + .then(() => + this.client.actions.GuildRoleDelete.handle({ guild_id: this.guild.id, role_id: this.id }).role + ); } /** diff --git a/src/structures/User.js b/src/structures/User.js index 5d9ed47dd..8550344b3 100644 --- a/src/structures/User.js +++ b/src/structures/User.js @@ -204,7 +204,7 @@ class User { return this.client.api.users[this.client.user.id].channels.post({ data: { recipient_id: this.id, } }) - .then(data => this.client.actions.ChannelCreate.handle(data).channel); + .then(data => this.client.actions.ChannelCreate.handle(data).channel); } /** @@ -213,9 +213,8 @@ class User { */ deleteDM() { if (!this.dmChannel) return Promise.reject(new Error('No DM Channel exists!')); - return this.client.api.channels[this.dmChannel.id].delete().then(data => - this.client.actions.ChannelDelete.handle(data).channel - ); + return this.client.api.channels[this.dmChannel.id].delete() + .then(data => this.client.actions.ChannelDelete.handle(data).channel); } /** diff --git a/src/structures/interfaces/TextBasedChannel.js b/src/structures/interfaces/TextBasedChannel.js index 5b1936597..f7e3224dc 100644 --- a/src/structures/interfaces/TextBasedChannel.js +++ b/src/structures/interfaces/TextBasedChannel.js @@ -133,18 +133,18 @@ class TextBasedChannel { const Message = require('../Message'); if (!this.client.user.bot) { return this.fetchMessages({ limit: 1, around: messageID }) - .then(messages => { - const msg = messages.get(messageID); - if (!msg) throw new Error('MESSAGE_MISSING'); - return msg; - }); + .then(messages => { + const msg = messages.get(messageID); + if (!msg) throw new Error('MESSAGE_MISSING'); + return msg; + }); } return this.client.api.channels[this.id].messages[messageID].get() - .then(data => { - const msg = data instanceof Message ? data : new Message(this, data, this.client); - this._cacheMessage(msg); - return msg; - }); + .then(data => { + const msg = data instanceof Message ? data : new Message(this, data, this.client); + this._cacheMessage(msg); + return msg; + }); } /** @@ -170,15 +170,15 @@ class TextBasedChannel { fetchMessages(options = {}) { const Message = require('../Message'); return this.client.api.channels[this.id].messages.get({ query: options }) - .then(data => { - const messages = new Collection(); - for (const message of data) { - const msg = new Message(this, message, this.client); - messages.set(message.id, msg); - this._cacheMessage(msg); - } - return messages; - }); + .then(data => { + const messages = new Collection(); + for (const message of data) { + const msg = new Message(this, message, this.client); + messages.set(message.id, msg); + this._cacheMessage(msg); + } + return messages; + }); } /** @@ -350,13 +350,13 @@ class TextBasedChannel { ); } return this.client.api.channels[this.id].messages['bulk-delete'] - .post({ data: { messages: messageIDs } }) - .then(() => - this.client.actions.MessageDeleteBulk.handle({ - channel_id: this.id, - ids: messageIDs, - }).messages - ); + .post({ data: { messages: messageIDs } }) + .then(() => + this.client.actions.MessageDeleteBulk.handle({ + channel_id: this.id, + ids: messageIDs, + }).messages + ); } throw new TypeError('MESSAGE_BULK_DELETE_TYPE'); } diff --git a/webpack.config.js b/webpack.config.js index dd4000fd9..55d0e12f6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -11,9 +11,10 @@ const version = require('./package.json').version; const createConfig = options => { const plugins = [ new webpack.DefinePlugin({ 'global.GENTLY': false }), + new webpack.optimize.ModuleConcatenationPlugin(), ]; - if (options.minify) plugins.push(new UglifyJSPlugin({ minimize: true })); + if (options.minify) plugins.push(new UglifyJSPlugin({ uglifyOptions: { output: { comments: false } } })); const filename = `./webpack/discord${process.env.VERSIONED === 'false' ? '' : '.' + version}${options.minify ? '.min' : ''}.js`; // eslint-disable-line