From 08edddf0dfff14f6f3fe9f2d68f02209201f8e74 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Mon, 31 Jul 2017 15:51:34 +1000 Subject: [PATCH 1/9] adds support for babel-plugin-transform-runtime --- bin/templates/plugin/client/.babelrc | 3 ++- client/.babelrc | 3 ++- client/coral-embed/src/index.js | 5 +++++ docs/_docs/04-03-plugins-client.md | 3 ++- package.json | 2 ++ plugin-api/.babelrc | 3 ++- plugins/talk-plugin-auth/client/.babelrc | 3 ++- .../talk-plugin-comment-content/client/.babelrc | 3 ++- .../talk-plugin-featured-comments/client/.babelrc | 3 ++- .../client/components/.babelrc | 3 ++- plugins/talk-plugin-like/client/.babelrc | 3 ++- plugins/talk-plugin-love/client/.babelrc | 3 ++- plugins/talk-plugin-offtopic/client/.babelrc | 3 ++- plugins/talk-plugin-permalink/client/.babelrc | 3 ++- plugins/talk-plugin-respect/client/.babelrc | 3 ++- .../talk-plugin-viewing-options/client/.babelrc | 3 ++- webpack.config.js | 14 +++++++------- yarn.lock | 13 +++++++++++++ 18 files changed, 55 insertions(+), 21 deletions(-) diff --git a/bin/templates/plugin/client/.babelrc b/bin/templates/plugin/client/.babelrc index 60be246eb..1b77acb76 100644 --- a/bin/templates/plugin/client/.babelrc +++ b/bin/templates/plugin/client/.babelrc @@ -9,6 +9,7 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx" + "transform-react-jsx", + ["transform-runtime", {"polyfill": false}] ] } \ No newline at end of file diff --git a/client/.babelrc b/client/.babelrc index 63b1c53de..87bd31a04 100644 --- a/client/.babelrc +++ b/client/.babelrc @@ -9,6 +9,7 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx" + "transform-react-jsx", + ["transform-runtime", {"polyfill": false}] ] } diff --git a/client/coral-embed/src/index.js b/client/coral-embed/src/index.js index 64c274660..dd44e72cd 100644 --- a/client/coral-embed/src/index.js +++ b/client/coral-embed/src/index.js @@ -267,6 +267,11 @@ Talk.render = function(el, opts) { console.warn( 'This page does not include a canonical link tag. Talk has inferred this asset_url from the window object. Query params have been stripped, which may cause a single thread to be present across multiple pages.' ); + + if (!window.location.origin) { + window.location.origin = `${window.location.protocol}//${window.location.hostname}${window.location.port ? `:${window.location.port}` : ''}`; + } + query.asset_url = window.location.origin + window.location.pathname; } } diff --git a/docs/_docs/04-03-plugins-client.md b/docs/_docs/04-03-plugins-client.md index 052b90873..d3975913e 100644 --- a/docs/_docs/04-03-plugins-client.md +++ b/docs/_docs/04-03-plugins-client.md @@ -325,7 +325,8 @@ While building your plugin you need to specify a `.eslintrc.json` file and a`.ba "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx" + "transform-react-jsx", + ["transform-runtime", {"polyfill": false}] ] } ``` diff --git a/package.json b/package.json index 476e7eda5..5f0c1cf10 100644 --- a/package.json +++ b/package.json @@ -150,10 +150,12 @@ "babel-plugin-transform-object-assign": "^6.8.0", "babel-plugin-transform-object-rest-spread": "^6.23.0", "babel-plugin-transform-react-jsx": "^6.23.0", + "babel-plugin-transform-runtime": "^6.23.0", "babel-polyfill": "^6.23.0", "babel-preset-es2015": "^6.24.0", "babel-preset-react": "^6.23.0", "babel-preset-stage-0": "^6.16.0", + "babel-runtime": "^6.25.0", "chai": "^3.5.0", "chai-as-promised": "^6.0.0", "chai-http": "^3.0.0", diff --git a/plugin-api/.babelrc b/plugin-api/.babelrc index 63b1c53de..87bd31a04 100644 --- a/plugin-api/.babelrc +++ b/plugin-api/.babelrc @@ -9,6 +9,7 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx" + "transform-react-jsx", + ["transform-runtime", {"polyfill": false}] ] } diff --git a/plugins/talk-plugin-auth/client/.babelrc b/plugins/talk-plugin-auth/client/.babelrc index 60be246eb..1b77acb76 100644 --- a/plugins/talk-plugin-auth/client/.babelrc +++ b/plugins/talk-plugin-auth/client/.babelrc @@ -9,6 +9,7 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx" + "transform-react-jsx", + ["transform-runtime", {"polyfill": false}] ] } \ No newline at end of file diff --git a/plugins/talk-plugin-comment-content/client/.babelrc b/plugins/talk-plugin-comment-content/client/.babelrc index 60be246eb..1b77acb76 100644 --- a/plugins/talk-plugin-comment-content/client/.babelrc +++ b/plugins/talk-plugin-comment-content/client/.babelrc @@ -9,6 +9,7 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx" + "transform-react-jsx", + ["transform-runtime", {"polyfill": false}] ] } \ No newline at end of file diff --git a/plugins/talk-plugin-featured-comments/client/.babelrc b/plugins/talk-plugin-featured-comments/client/.babelrc index 60be246eb..1b77acb76 100644 --- a/plugins/talk-plugin-featured-comments/client/.babelrc +++ b/plugins/talk-plugin-featured-comments/client/.babelrc @@ -9,6 +9,7 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx" + "transform-react-jsx", + ["transform-runtime", {"polyfill": false}] ] } \ No newline at end of file diff --git a/plugins/talk-plugin-featured-comments/client/components/.babelrc b/plugins/talk-plugin-featured-comments/client/components/.babelrc index 60be246eb..1b77acb76 100644 --- a/plugins/talk-plugin-featured-comments/client/components/.babelrc +++ b/plugins/talk-plugin-featured-comments/client/components/.babelrc @@ -9,6 +9,7 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx" + "transform-react-jsx", + ["transform-runtime", {"polyfill": false}] ] } \ No newline at end of file diff --git a/plugins/talk-plugin-like/client/.babelrc b/plugins/talk-plugin-like/client/.babelrc index 60be246eb..1b77acb76 100644 --- a/plugins/talk-plugin-like/client/.babelrc +++ b/plugins/talk-plugin-like/client/.babelrc @@ -9,6 +9,7 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx" + "transform-react-jsx", + ["transform-runtime", {"polyfill": false}] ] } \ No newline at end of file diff --git a/plugins/talk-plugin-love/client/.babelrc b/plugins/talk-plugin-love/client/.babelrc index 60be246eb..f70104134 100644 --- a/plugins/talk-plugin-love/client/.babelrc +++ b/plugins/talk-plugin-love/client/.babelrc @@ -9,6 +9,7 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx" + ["transform-react-jsx": {"polyfill": false}], + ["transform-runtime", {"polyfill": false}] ] } \ No newline at end of file diff --git a/plugins/talk-plugin-offtopic/client/.babelrc b/plugins/talk-plugin-offtopic/client/.babelrc index 60be246eb..1b77acb76 100644 --- a/plugins/talk-plugin-offtopic/client/.babelrc +++ b/plugins/talk-plugin-offtopic/client/.babelrc @@ -9,6 +9,7 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx" + "transform-react-jsx", + ["transform-runtime", {"polyfill": false}] ] } \ No newline at end of file diff --git a/plugins/talk-plugin-permalink/client/.babelrc b/plugins/talk-plugin-permalink/client/.babelrc index 60be246eb..1b77acb76 100644 --- a/plugins/talk-plugin-permalink/client/.babelrc +++ b/plugins/talk-plugin-permalink/client/.babelrc @@ -9,6 +9,7 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx" + "transform-react-jsx", + ["transform-runtime", {"polyfill": false}] ] } \ No newline at end of file diff --git a/plugins/talk-plugin-respect/client/.babelrc b/plugins/talk-plugin-respect/client/.babelrc index 60be246eb..1b77acb76 100644 --- a/plugins/talk-plugin-respect/client/.babelrc +++ b/plugins/talk-plugin-respect/client/.babelrc @@ -9,6 +9,7 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx" + "transform-react-jsx", + ["transform-runtime", {"polyfill": false}] ] } \ No newline at end of file diff --git a/plugins/talk-plugin-viewing-options/client/.babelrc b/plugins/talk-plugin-viewing-options/client/.babelrc index 60be246eb..1b77acb76 100644 --- a/plugins/talk-plugin-viewing-options/client/.babelrc +++ b/plugins/talk-plugin-viewing-options/client/.babelrc @@ -9,6 +9,7 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx" + "transform-react-jsx", + ["transform-runtime", {"polyfill": false}] ] } \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 1b3c4b763..94d9ccc44 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -33,6 +33,7 @@ const buildEmbeds = [ const config = { devtool: 'cheap-module-source-map', + target: 'web', output: { path: path.join(__dirname, 'dist'), publicPath: '/client/', @@ -154,11 +155,7 @@ if (process.env.NODE_ENV === 'production') { // Applies the base configuration to the following entries. const applyConfig = (entries, root = {}) => _.merge({}, config, { entry: entries.reduce((entry, {name, path}) => { - entry[name] = [ - 'babel-polyfill', - path - ]; - + entry[name] = path; return entry; }, {}) }, root); @@ -183,7 +180,7 @@ module.exports = [ // All framework targets/embeds/plugins. applyConfig([ - // // Load in all the targets. + // Load in all the targets. ...buildTargets.map((target) => ({ name: `${target}/bundle`, path: path.join(__dirname, 'client/', target, '/src/index') @@ -192,7 +189,10 @@ module.exports = [ // Load in all the embeds. ...buildEmbeds.map((embed) => ({ name: `embed/${embed}/bundle`, - path: path.join(__dirname, 'client/', `coral-embed-${embed}`, '/src/index') + path: [ + 'babel-polyfill', + path.join(__dirname, 'client/', `coral-embed-${embed}`, '/src/index') + ] })), // Load in all the plugin entries. diff --git a/yarn.lock b/yarn.lock index 255dc7415..c4aa9206d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -989,6 +989,12 @@ babel-plugin-transform-regenerator@^6.24.1: dependencies: regenerator-transform "0.9.11" +babel-plugin-transform-runtime@^6.23.0: + version "6.23.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-runtime/-/babel-plugin-transform-runtime-6.23.0.tgz#88490d446502ea9b8e7efb0fe09ec4d99479b1ee" + dependencies: + babel-runtime "^6.22.0" + babel-plugin-transform-strict-mode@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758" @@ -1110,6 +1116,13 @@ babel-runtime@^6.11.6, babel-runtime@^6.18.0, babel-runtime@^6.2.0, babel-runtim core-js "^2.4.0" regenerator-runtime "^0.10.0" +babel-runtime@^6.25.0: + version "6.25.0" + resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.25.0.tgz#33b98eaa5d482bb01a8d1aa6b437ad2b01aec41c" + dependencies: + core-js "^2.4.0" + regenerator-runtime "^0.10.0" + babel-template@^6.16.0, babel-template@^6.24.1, babel-template@^6.3.0: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.24.1.tgz#04ae514f1f93b3a2537f2a0f60a5a45fb8308333" From fc3acecf614fd83370829b252ee64ff97cd9958f Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Mon, 31 Jul 2017 20:09:16 +0700 Subject: [PATCH 2/9] Refactor isCommentActive logic --- client/coral-embed-stream/src/components/Comment.js | 4 ++-- client/coral-embed-stream/src/components/Stream.js | 3 ++- client/coral-framework/utils/index.js | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/client/coral-embed-stream/src/components/Comment.js b/client/coral-embed-stream/src/components/Comment.js index 8bece5dc5..96a93728c 100644 --- a/client/coral-embed-stream/src/components/Comment.js +++ b/client/coral-embed-stream/src/components/Comment.js @@ -21,7 +21,7 @@ import CommentContent from './CommentContent'; import Slot from 'coral-framework/components/Slot'; import IgnoredCommentTombstone from './IgnoredCommentTombstone'; import {EditableCommentContent} from './EditableCommentContent'; -import {getActionSummary, iPerformedThisAction, forEachError} from 'coral-framework/utils'; +import {getActionSummary, iPerformedThisAction, forEachError, isCommentActive} from 'coral-framework/utils'; import t from 'coral-framework/services/i18n'; const isStaff = (tags) => !tags.every((t) => t.tag.name !== 'STAFF'); @@ -317,7 +317,7 @@ export default class Comment extends React.Component { } = this.props; const view = this.getVisibileReplies(); - const isActive = ['NONE', 'ACCEPTED'].indexOf(comment.status) >= 0; + const isActive = isCommentActive(comment.status); const {loadingState} = this.state; const isPending = comment.id.indexOf('pending') >= 0; const isHighlighted = highlighted === comment.id; diff --git a/client/coral-embed-stream/src/components/Stream.js b/client/coral-embed-stream/src/components/Stream.js index 66ffc0fc8..667b57a8a 100644 --- a/client/coral-embed-stream/src/components/Stream.js +++ b/client/coral-embed-stream/src/components/Stream.js @@ -13,6 +13,7 @@ import t, {timeago} from 'coral-framework/services/i18n'; import {getSlotComponents} from 'coral-framework/helpers/plugins'; import CommentBox from 'talk-plugin-commentbox/CommentBox'; import QuestionBox from 'talk-plugin-questionbox/QuestionBox'; +import {isCommentActive} from 'coral-framework/utils'; import {Button, TabBar, Tab, TabCount, TabContent, TabPane} from 'coral-ui'; import cn from 'classnames'; @@ -105,7 +106,7 @@ class Stream extends React.Component { // even though the permalinked comment is the highlighted one, we're displaying its parent + replies let highlightedComment = comment && getTopLevelParent(comment); if (highlightedComment) { - const isInactive = ['NONE', 'ACCEPTED'].indexOf(comment.status) === -1; + const isInactive = !isCommentActive(comment.status); if (comment.parent && isInactive) { // the highlighted comment is not active and as such not in the replies, so we diff --git a/client/coral-framework/utils/index.js b/client/coral-framework/utils/index.js index 3768b3940..96d9ed629 100644 --- a/client/coral-framework/utils/index.js +++ b/client/coral-framework/utils/index.js @@ -187,3 +187,7 @@ export function buildUrl({protocol, hostname, port, pathname, search, hash} = wi export function getSlotFragmentSpreads(slots, resource) { return `...${slots.map((s) => `TalkSlot_${capitalize(s)}_${resource}`).join('\n...')}\n`; } + +export function isCommentActive(commentStatus) { + return ['NONE', 'ACCEPTED'].indexOf(commentStatus) >= 0; +} From 97c75be60439e876dc871ac33629ede1771abe57 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Mon, 31 Jul 2017 20:17:06 +0700 Subject: [PATCH 3/9] Comments explaining why we have inactive comments in the stream --- client/coral-embed-stream/src/components/Comment.js | 3 +++ client/coral-embed-stream/src/components/Stream.js | 2 ++ 2 files changed, 5 insertions(+) diff --git a/client/coral-embed-stream/src/components/Comment.js b/client/coral-embed-stream/src/components/Comment.js index 96a93728c..67fc8ee5a 100644 --- a/client/coral-embed-stream/src/components/Comment.js +++ b/client/coral-embed-stream/src/components/Comment.js @@ -317,7 +317,10 @@ export default class Comment extends React.Component { } = this.props; const view = this.getVisibileReplies(); + + // Inactive comments can be viewed by moderators and admins (e.g. using permalinks). const isActive = isCommentActive(comment.status); + const {loadingState} = this.state; const isPending = comment.id.indexOf('pending') >= 0; const isHighlighted = highlighted === comment.id; diff --git a/client/coral-embed-stream/src/components/Stream.js b/client/coral-embed-stream/src/components/Stream.js index 667b57a8a..421a0cf7a 100644 --- a/client/coral-embed-stream/src/components/Stream.js +++ b/client/coral-embed-stream/src/components/Stream.js @@ -106,6 +106,8 @@ class Stream extends React.Component { // even though the permalinked comment is the highlighted one, we're displaying its parent + replies let highlightedComment = comment && getTopLevelParent(comment); if (highlightedComment) { + + // Inactive comments can be viewed by moderators and admins (e.g. using permalinks). const isInactive = !isCommentActive(comment.status); if (comment.parent && isInactive) { From 3954b7a268152e04d035ffb24dda1d4a8a25046e Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Mon, 31 Jul 2017 22:37:08 +0700 Subject: [PATCH 4/9] Label for inactive comments --- .../src/components/Comment.js | 6 +++- .../src/components/InactiveCommentLabel.css | 32 +++++++++++++++++ .../src/components/InactiveCommentLabel.js | 36 +++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 client/coral-embed-stream/src/components/InactiveCommentLabel.css create mode 100644 client/coral-embed-stream/src/components/InactiveCommentLabel.js diff --git a/client/coral-embed-stream/src/components/Comment.js b/client/coral-embed-stream/src/components/Comment.js index 67fc8ee5a..34f672d8a 100644 --- a/client/coral-embed-stream/src/components/Comment.js +++ b/client/coral-embed-stream/src/components/Comment.js @@ -20,6 +20,7 @@ import {TopRightMenu} from './TopRightMenu'; import CommentContent from './CommentContent'; import Slot from 'coral-framework/components/Slot'; import IgnoredCommentTombstone from './IgnoredCommentTombstone'; +import InactiveCommentLabel from './InactiveCommentLabel'; import {EditableCommentContent} from './EditableCommentContent'; import {getActionSummary, iPerformedThisAction, forEachError, isCommentActive} from 'coral-framework/utils'; import t from 'coral-framework/services/i18n'; @@ -438,7 +439,7 @@ export default class Comment extends React.Component { } } - { (currentUser && (comment.user.id !== currentUser.id)) && + { isActive && (currentUser && (comment.user.id !== currentUser.id)) && /* TopRightMenu allows currentUser to ignore other users' comments */ @@ -448,6 +449,9 @@ export default class Comment extends React.Component { addNotification={addNotification} /> } + { !isActive && + + }
{ diff --git a/client/coral-embed-stream/src/components/InactiveCommentLabel.css b/client/coral-embed-stream/src/components/InactiveCommentLabel.css new file mode 100644 index 000000000..01ba197b5 --- /dev/null +++ b/client/coral-embed-stream/src/components/InactiveCommentLabel.css @@ -0,0 +1,32 @@ +.root { + display: inline-block; + color: white; + background: grey; + height: 22px; + box-sizing: border-box; + line-height: 19px; + padding: 2px 6px 2px 4px; + border-radius: 2px; + font-size: 12px; + text-transform: capitalize; +} + +.icon { + font-size: 14px; + vertical-align: text-top; + margin: 0; + margin-right: 4px; +} + +.label { + display: inline-block; +} + +.premod { + background: #063B9A; +} + +.rejected { + background: #d03235; +} + diff --git a/client/coral-embed-stream/src/components/InactiveCommentLabel.js b/client/coral-embed-stream/src/components/InactiveCommentLabel.js new file mode 100644 index 000000000..824692558 --- /dev/null +++ b/client/coral-embed-stream/src/components/InactiveCommentLabel.js @@ -0,0 +1,36 @@ +import React, {PropTypes} from 'react'; +import t from 'coral-framework/services/i18n'; +import styles from './InactiveCommentLabel.css'; +import {Icon} from 'coral-ui'; +import cn from 'classnames'; + +const InactiveCommentLabel = ({status, className, ...rest}) => { + let label; + let icon; + + switch (status) { + case 'PREMOD': + label = t('modqueue.premod'); + icon = 'query_builder'; + break; + case 'REJECTED': + label = t('modqueue.rejected'); + icon = 'close'; + break; + default: + throw new Error(`Unknown inactive status ${status}`); + } + + return ( + + + {label} + + ); +}; + +InactiveCommentLabel.propTypes = { + status: PropTypes.string.isRequired, +}; + +export default InactiveCommentLabel; From 83762b880ff622092e082499ad8bc80f7f08d1d4 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 1 Aug 2017 09:52:18 +1000 Subject: [PATCH 5/9] Added support for reconfiguring the comment count cache expiry --- config.js | 6 ++++++ docs/_docs/02-01-configuration.md | 5 +++++ graph/loaders/comments.js | 10 +++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/config.js b/config.js index c6ea774a3..02b40681d 100644 --- a/config.js +++ b/config.js @@ -78,6 +78,12 @@ const CONFIG = { // messages through the websocket to keep the socket alive. KEEP_ALIVE: process.env.TALK_KEEP_ALIVE || '30s', + //------------------------------------------------------------------------------ + // Cache configuration + //------------------------------------------------------------------------------ + + CACHE_EXPIRY_COMMENT_COUNT: process.env.TALK_CACHE_EXPIRY_COMMENT_COUNT || '1hr', + //------------------------------------------------------------------------------ // Recaptcha configuration //------------------------------------------------------------------------------ diff --git a/docs/_docs/02-01-configuration.md b/docs/_docs/02-01-configuration.md index ab644e5e3..d35257983 100644 --- a/docs/_docs/02-01-configuration.md +++ b/docs/_docs/02-01-configuration.md @@ -127,6 +127,11 @@ The default could be read as: - At the moment of writing, beheviour is not attached to the flagging reliability, but it is recorded. +### Cache + +- `TALK_CACHE_EXPIRY_COMMENT_COUNT` (_optional_) - configure the duration for which + comment counts are cached for. (Default `1hr`) + ### Plugins Plugins configuration can be found on the [Plugins]({{ "/docs/running/plugins/" | absolute_url }}) page. \ No newline at end of file diff --git a/graph/loaders/comments.js b/graph/loaders/comments.js index 16d2101f7..7a17cfabd 100644 --- a/graph/loaders/comments.js +++ b/graph/loaders/comments.js @@ -8,6 +8,10 @@ const { SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS, SEARCH_OTHERS_COMMENTS } = require('../../perms/constants'); +const { + CACHE_EXPIRY_COMMENT_COUNT +} = require('../../config'); +const ms = require('ms'); const CommentModel = require('../../models/comment'); const UsersService = require('../../services/users'); @@ -481,11 +485,11 @@ module.exports = (context) => ({ get: new DataLoader((ids) => getComments(context, ids)), getByQuery: (query) => getCommentsByQuery(context, query), getCountByQuery: (query) => getCommentCountByQuery(context, query), - countByAssetID: new SharedCounterDataLoader('Comments.totalCommentCount', 3600, (ids) => getCountsByAssetID(context, ids)), + countByAssetID: new SharedCounterDataLoader('Comments.totalCommentCount', ms(CACHE_EXPIRY_COMMENT_COUNT), (ids) => getCountsByAssetID(context, ids)), countByAssetIDPersonalized: (query) => getCountsByAssetIDPersonalized(context, query), - parentCountByAssetID: new SharedCounterDataLoader('Comments.countByAssetID', 3600, (ids) => getParentCountsByAssetID(context, ids)), + parentCountByAssetID: new SharedCounterDataLoader('Comments.countByAssetID', ms(CACHE_EXPIRY_COMMENT_COUNT), (ids) => getParentCountsByAssetID(context, ids)), parentCountByAssetIDPersonalized: (query) => getParentCountByAssetIDPersonalized(context, query), - countByParentID: new SharedCounterDataLoader('Comments.countByParentID', 3600, (ids) => getCountsByParentID(context, ids)), + countByParentID: new SharedCounterDataLoader('Comments.countByParentID', ms(CACHE_EXPIRY_COMMENT_COUNT), (ids) => getCountsByParentID(context, ids)), countByParentIDPersonalized: (query) => getCountByParentIDPersonalized(context, query), genRecentReplies: new DataLoader((ids) => genRecentReplies(context, ids)), genRecentComments: new DataLoader((ids) => genRecentComments(context, ids)) From de97ad59ec3a22d11f70a4d1f054140906c4835c Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 1 Aug 2017 19:14:26 +1000 Subject: [PATCH 6/9] Added configuration for the babel polyfill --- docs/_docs/02-01-configuration.md | 1 + webpack.config.js | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/docs/_docs/02-01-configuration.md b/docs/_docs/02-01-configuration.md index ab644e5e3..fd2ee0478 100644 --- a/docs/_docs/02-01-configuration.md +++ b/docs/_docs/02-01-configuration.md @@ -45,6 +45,7 @@ These are only used during the webpack build. thread. (Default `3`) - `TALK_DEFAULT_STREAM_TAB` (_optional_) - specify the default stream tab in the admin. (Default `all`) +- `TALK_DISABLE_EMBED_POLYFILL` (_optional_) - when set to `TRUE`, the build process will not include the [babel-polyfill](https://babeljs.io/docs/usage/polyfill/) in the embed.js target. (Default `FALSE`) ### Database diff --git a/webpack.config.js b/webpack.config.js index 94d9ccc44..873d20472 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -154,8 +154,16 @@ if (process.env.NODE_ENV === 'production') { // Applies the base configuration to the following entries. const applyConfig = (entries, root = {}) => _.merge({}, config, { - entry: entries.reduce((entry, {name, path}) => { - entry[name] = path; + entry: entries.reduce((entry, {name, path, disablePolyfill = false}) => { + if (disablePolyfill) { + entry[name] = path; + } else { + entry[name] = [ + 'babel-polyfill', + path + ]; + } + return entry; }, {}) }, root); @@ -168,7 +176,8 @@ module.exports = [ // Load in the root embed. { name: 'embed', - path: path.join(__dirname, 'client/coral-embed/src/index') + path: path.join(__dirname, 'client/coral-embed/src/index'), + disablePolyfill: process.env.TALK_DISABLE_EMBED_POLYFILL === 'TRUE' } ], { @@ -189,10 +198,7 @@ module.exports = [ // Load in all the embeds. ...buildEmbeds.map((embed) => ({ name: `embed/${embed}/bundle`, - path: [ - 'babel-polyfill', - path.join(__dirname, 'client/', `coral-embed-${embed}`, '/src/index') - ] + path: path.join(__dirname, 'client/', `coral-embed-${embed}`, '/src/index') })), // Load in all the plugin entries. From 2ac6a9d82928e13df4bb53d1db9305a466c82003 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 1 Aug 2017 22:12:02 +1000 Subject: [PATCH 7/9] changes to babelrc --- bin/templates/plugin/client/.babelrc | 3 +-- client/.babelrc | 5 ++--- client/coral-embed/.babelrc | 15 +++++++++++++++ docs/_docs/04-03-plugins-client.md | 3 +-- plugin-api/.babelrc | 3 +-- plugins/talk-plugin-auth/client/.babelrc | 3 +-- .../talk-plugin-comment-content/client/.babelrc | 3 +-- .../talk-plugin-featured-comments/client/.babelrc | 3 +-- .../client/components/.babelrc | 3 +-- plugins/talk-plugin-like/client/.babelrc | 3 +-- plugins/talk-plugin-love/client/.babelrc | 3 +-- plugins/talk-plugin-offtopic/client/.babelrc | 3 +-- plugins/talk-plugin-permalink/client/.babelrc | 3 +-- plugins/talk-plugin-respect/client/.babelrc | 3 +-- .../talk-plugin-viewing-options/client/.babelrc | 3 +-- 15 files changed, 30 insertions(+), 29 deletions(-) create mode 100644 client/coral-embed/.babelrc diff --git a/bin/templates/plugin/client/.babelrc b/bin/templates/plugin/client/.babelrc index 1b77acb76..60be246eb 100644 --- a/bin/templates/plugin/client/.babelrc +++ b/bin/templates/plugin/client/.babelrc @@ -9,7 +9,6 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx", - ["transform-runtime", {"polyfill": false}] + "transform-react-jsx" ] } \ No newline at end of file diff --git a/client/.babelrc b/client/.babelrc index 87bd31a04..60be246eb 100644 --- a/client/.babelrc +++ b/client/.babelrc @@ -9,7 +9,6 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx", - ["transform-runtime", {"polyfill": false}] + "transform-react-jsx" ] -} +} \ No newline at end of file diff --git a/client/coral-embed/.babelrc b/client/coral-embed/.babelrc new file mode 100644 index 000000000..1b77acb76 --- /dev/null +++ b/client/coral-embed/.babelrc @@ -0,0 +1,15 @@ +{ + "presets": [ + "es2015" + ], + "plugins": [ + "add-module-exports", + "transform-class-properties", + "transform-decorators-legacy", + "transform-object-assign", + "transform-object-rest-spread", + "transform-async-to-generator", + "transform-react-jsx", + ["transform-runtime", {"polyfill": false}] + ] +} \ No newline at end of file diff --git a/docs/_docs/04-03-plugins-client.md b/docs/_docs/04-03-plugins-client.md index d3975913e..052b90873 100644 --- a/docs/_docs/04-03-plugins-client.md +++ b/docs/_docs/04-03-plugins-client.md @@ -325,8 +325,7 @@ While building your plugin you need to specify a `.eslintrc.json` file and a`.ba "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx", - ["transform-runtime", {"polyfill": false}] + "transform-react-jsx" ] } ``` diff --git a/plugin-api/.babelrc b/plugin-api/.babelrc index 87bd31a04..63b1c53de 100644 --- a/plugin-api/.babelrc +++ b/plugin-api/.babelrc @@ -9,7 +9,6 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx", - ["transform-runtime", {"polyfill": false}] + "transform-react-jsx" ] } diff --git a/plugins/talk-plugin-auth/client/.babelrc b/plugins/talk-plugin-auth/client/.babelrc index 1b77acb76..60be246eb 100644 --- a/plugins/talk-plugin-auth/client/.babelrc +++ b/plugins/talk-plugin-auth/client/.babelrc @@ -9,7 +9,6 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx", - ["transform-runtime", {"polyfill": false}] + "transform-react-jsx" ] } \ No newline at end of file diff --git a/plugins/talk-plugin-comment-content/client/.babelrc b/plugins/talk-plugin-comment-content/client/.babelrc index 1b77acb76..60be246eb 100644 --- a/plugins/talk-plugin-comment-content/client/.babelrc +++ b/plugins/talk-plugin-comment-content/client/.babelrc @@ -9,7 +9,6 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx", - ["transform-runtime", {"polyfill": false}] + "transform-react-jsx" ] } \ No newline at end of file diff --git a/plugins/talk-plugin-featured-comments/client/.babelrc b/plugins/talk-plugin-featured-comments/client/.babelrc index 1b77acb76..60be246eb 100644 --- a/plugins/talk-plugin-featured-comments/client/.babelrc +++ b/plugins/talk-plugin-featured-comments/client/.babelrc @@ -9,7 +9,6 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx", - ["transform-runtime", {"polyfill": false}] + "transform-react-jsx" ] } \ No newline at end of file diff --git a/plugins/talk-plugin-featured-comments/client/components/.babelrc b/plugins/talk-plugin-featured-comments/client/components/.babelrc index 1b77acb76..60be246eb 100644 --- a/plugins/talk-plugin-featured-comments/client/components/.babelrc +++ b/plugins/talk-plugin-featured-comments/client/components/.babelrc @@ -9,7 +9,6 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx", - ["transform-runtime", {"polyfill": false}] + "transform-react-jsx" ] } \ No newline at end of file diff --git a/plugins/talk-plugin-like/client/.babelrc b/plugins/talk-plugin-like/client/.babelrc index 1b77acb76..60be246eb 100644 --- a/plugins/talk-plugin-like/client/.babelrc +++ b/plugins/talk-plugin-like/client/.babelrc @@ -9,7 +9,6 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx", - ["transform-runtime", {"polyfill": false}] + "transform-react-jsx" ] } \ No newline at end of file diff --git a/plugins/talk-plugin-love/client/.babelrc b/plugins/talk-plugin-love/client/.babelrc index f70104134..60be246eb 100644 --- a/plugins/talk-plugin-love/client/.babelrc +++ b/plugins/talk-plugin-love/client/.babelrc @@ -9,7 +9,6 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - ["transform-react-jsx": {"polyfill": false}], - ["transform-runtime", {"polyfill": false}] + "transform-react-jsx" ] } \ No newline at end of file diff --git a/plugins/talk-plugin-offtopic/client/.babelrc b/plugins/talk-plugin-offtopic/client/.babelrc index 1b77acb76..60be246eb 100644 --- a/plugins/talk-plugin-offtopic/client/.babelrc +++ b/plugins/talk-plugin-offtopic/client/.babelrc @@ -9,7 +9,6 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx", - ["transform-runtime", {"polyfill": false}] + "transform-react-jsx" ] } \ No newline at end of file diff --git a/plugins/talk-plugin-permalink/client/.babelrc b/plugins/talk-plugin-permalink/client/.babelrc index 1b77acb76..60be246eb 100644 --- a/plugins/talk-plugin-permalink/client/.babelrc +++ b/plugins/talk-plugin-permalink/client/.babelrc @@ -9,7 +9,6 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx", - ["transform-runtime", {"polyfill": false}] + "transform-react-jsx" ] } \ No newline at end of file diff --git a/plugins/talk-plugin-respect/client/.babelrc b/plugins/talk-plugin-respect/client/.babelrc index 1b77acb76..60be246eb 100644 --- a/plugins/talk-plugin-respect/client/.babelrc +++ b/plugins/talk-plugin-respect/client/.babelrc @@ -9,7 +9,6 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx", - ["transform-runtime", {"polyfill": false}] + "transform-react-jsx" ] } \ No newline at end of file diff --git a/plugins/talk-plugin-viewing-options/client/.babelrc b/plugins/talk-plugin-viewing-options/client/.babelrc index 1b77acb76..60be246eb 100644 --- a/plugins/talk-plugin-viewing-options/client/.babelrc +++ b/plugins/talk-plugin-viewing-options/client/.babelrc @@ -9,7 +9,6 @@ "transform-object-assign", "transform-object-rest-spread", "transform-async-to-generator", - "transform-react-jsx", - ["transform-runtime", {"polyfill": false}] + "transform-react-jsx" ] } \ No newline at end of file From a99ffa122859254c8406cc20e01c2a9686c06138 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 1 Aug 2017 22:18:56 +1000 Subject: [PATCH 8/9] removed all traces of transform-runtime --- client/coral-embed/.babelrc | 15 --------------- package.json | 1 - yarn.lock | 6 ------ 3 files changed, 22 deletions(-) delete mode 100644 client/coral-embed/.babelrc diff --git a/client/coral-embed/.babelrc b/client/coral-embed/.babelrc deleted file mode 100644 index 1b77acb76..000000000 --- a/client/coral-embed/.babelrc +++ /dev/null @@ -1,15 +0,0 @@ -{ - "presets": [ - "es2015" - ], - "plugins": [ - "add-module-exports", - "transform-class-properties", - "transform-decorators-legacy", - "transform-object-assign", - "transform-object-rest-spread", - "transform-async-to-generator", - "transform-react-jsx", - ["transform-runtime", {"polyfill": false}] - ] -} \ No newline at end of file diff --git a/package.json b/package.json index 5f0c1cf10..7124bde76 100644 --- a/package.json +++ b/package.json @@ -150,7 +150,6 @@ "babel-plugin-transform-object-assign": "^6.8.0", "babel-plugin-transform-object-rest-spread": "^6.23.0", "babel-plugin-transform-react-jsx": "^6.23.0", - "babel-plugin-transform-runtime": "^6.23.0", "babel-polyfill": "^6.23.0", "babel-preset-es2015": "^6.24.0", "babel-preset-react": "^6.23.0", diff --git a/yarn.lock b/yarn.lock index c4aa9206d..ed2aadd8b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -989,12 +989,6 @@ babel-plugin-transform-regenerator@^6.24.1: dependencies: regenerator-transform "0.9.11" -babel-plugin-transform-runtime@^6.23.0: - version "6.23.0" - resolved "https://registry.yarnpkg.com/babel-plugin-transform-runtime/-/babel-plugin-transform-runtime-6.23.0.tgz#88490d446502ea9b8e7efb0fe09ec4d99479b1ee" - dependencies: - babel-runtime "^6.22.0" - babel-plugin-transform-strict-mode@^6.24.1: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758" From dbeb31f0a71f4fce42144716bb7d97202445cbe1 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Tue, 1 Aug 2017 22:22:03 +1000 Subject: [PATCH 9/9] removed more babel-runtime --- package.json | 1 - yarn.lock | 7 ------- 2 files changed, 8 deletions(-) diff --git a/package.json b/package.json index 7124bde76..476e7eda5 100644 --- a/package.json +++ b/package.json @@ -154,7 +154,6 @@ "babel-preset-es2015": "^6.24.0", "babel-preset-react": "^6.23.0", "babel-preset-stage-0": "^6.16.0", - "babel-runtime": "^6.25.0", "chai": "^3.5.0", "chai-as-promised": "^6.0.0", "chai-http": "^3.0.0", diff --git a/yarn.lock b/yarn.lock index ed2aadd8b..255dc7415 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1110,13 +1110,6 @@ babel-runtime@^6.11.6, babel-runtime@^6.18.0, babel-runtime@^6.2.0, babel-runtim core-js "^2.4.0" regenerator-runtime "^0.10.0" -babel-runtime@^6.25.0: - version "6.25.0" - resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.25.0.tgz#33b98eaa5d482bb01a8d1aa6b437ad2b01aec41c" - dependencies: - core-js "^2.4.0" - regenerator-runtime "^0.10.0" - babel-template@^6.16.0, babel-template@^6.24.1, babel-template@^6.3.0: version "6.24.1" resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.24.1.tgz#04ae514f1f93b3a2537f2a0f60a5a45fb8308333"