From aed4583ba6da91aa5fc5a69fe3aa550359f385eb Mon Sep 17 00:00:00 2001 From: Marcos Spessatto Defendi Date: Wed, 16 Jan 2019 10:43:02 -0200 Subject: [PATCH] Remove dependency between RocketChat namespace and migrations (#13133) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Remove rocketchat:ui package dependency of RocketChat namespace * Remove lib dependency in rocketchat:ui-sidenav * Remove dependency between lib and ui-vrecord * Add logger dependency in file-upload * Convert rocketchat:ui to main module structure * import variables that was broken due to conversion of rocketchat:ui * Remove globals variables from eslintrc and add some to the eslintrc of livechat app * Remove dependency between RocketChat namespace and migrations * Revert commented test file --- .../rocketchat-authorization/client/index.js | 2 +- packages/rocketchat-metrics/package.js | 1 - .../rocketchat-metrics/server/lib/metrics.js | 8 +++++-- packages/rocketchat-migrations/package.js | 1 + .../server/migrations.js | 23 ++++++++++--------- .../client/lib/openedRoom.js | 1 - 6 files changed, 20 insertions(+), 16 deletions(-) delete mode 100644 packages/rocketchat-ui-utils/client/lib/openedRoom.js diff --git a/packages/rocketchat-authorization/client/index.js b/packages/rocketchat-authorization/client/index.js index ea4af1b20769..a45f3463243a 100644 --- a/packages/rocketchat-authorization/client/index.js +++ b/packages/rocketchat-authorization/client/index.js @@ -11,7 +11,7 @@ import './views/permissionsRole'; export { hasAllPermission, - hasPermission, hasAtLeastOnePermission, hasRole, + hasPermission, }; diff --git a/packages/rocketchat-metrics/package.js b/packages/rocketchat-metrics/package.js index af04b090f290..f90c54eff23b 100644 --- a/packages/rocketchat-metrics/package.js +++ b/packages/rocketchat-metrics/package.js @@ -8,7 +8,6 @@ Package.describe({ Package.onUse(function(api) { api.use([ 'ecmascript', - 'rocketchat:migrations', 'rocketchat:version', ]); api.mainModule('server/index.js', 'server'); diff --git a/packages/rocketchat-metrics/server/lib/metrics.js b/packages/rocketchat-metrics/server/lib/metrics.js index 052334bf3b09..6aad0919775a 100644 --- a/packages/rocketchat-metrics/server/lib/metrics.js +++ b/packages/rocketchat-metrics/server/lib/metrics.js @@ -1,5 +1,4 @@ import { Meteor } from 'meteor/meteor'; -import { Migrations } from 'meteor/rocketchat:migrations'; import client from 'prom-client'; import connect from 'connect'; import http from 'http'; @@ -9,6 +8,7 @@ client.collectDefaultMetrics(); export const metrics = {}; let Info; +let _Migrations; // one sample metrics only - a counter @@ -87,6 +87,10 @@ const setPrometheusData = async() => { const Utils = await import('meteor/rocketchat:utils'); Info = Utils.Info; } + if (!_Migrations) { + const { Migrations } = await import('meteor/rocketchat:migrations'); + _Migrations = Migrations; + } client.register.setDefaultLabels({ unique_id: settings.get('uniqueID'), @@ -111,7 +115,7 @@ const setPrometheusData = async() => { } metrics.version.set({ version: statistics.version }, 1, date); - metrics.migration.set(Migrations._getControl().version, date); + metrics.migration.set(_Migrations._getControl().version, date); metrics.instanceCount.set(statistics.instanceCount, date); metrics.oplogEnabled.set({ enabled: statistics.oplogEnabled }, 1, date); diff --git a/packages/rocketchat-migrations/package.js b/packages/rocketchat-migrations/package.js index 311865258ed1..309485a6127d 100644 --- a/packages/rocketchat-migrations/package.js +++ b/packages/rocketchat-migrations/package.js @@ -9,6 +9,7 @@ Package.onUse(function(api) { api.use([ 'ecmascript', 'rocketchat:version', + 'rocketchat:utils', 'logging', 'check', 'mongo', diff --git a/packages/rocketchat-migrations/server/migrations.js b/packages/rocketchat-migrations/server/migrations.js index 8ee7902fe2fd..5896319c1584 100644 --- a/packages/rocketchat-migrations/server/migrations.js +++ b/packages/rocketchat-migrations/server/migrations.js @@ -3,6 +3,7 @@ import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; import { Mongo } from 'meteor/mongo'; import { Log } from 'meteor/logging'; +import { Info } from 'meteor/rocketchat:utils'; import _ from 'underscore'; import s from 'underscore.string'; import moment from 'moment'; @@ -202,14 +203,14 @@ Migrations.migrateTo = function(command) { 'Please make sure you are running the latest version and try again.', 'If the problem persists, please contact support.', '', - `This Rocket.Chat version: ${ RocketChat.Info.version }`, + `This Rocket.Chat version: ${ Info.version }`, `Database locked at version: ${ control.version }`, `Database target version: ${ version === 'latest' ? _.last(this._list).version : version }`, '', - `Commit: ${ RocketChat.Info.commit.hash }`, - `Date: ${ RocketChat.Info.commit.date }`, - `Branch: ${ RocketChat.Info.commit.branch }`, - `Tag: ${ RocketChat.Info.commit.tag }`, + `Commit: ${ Info.commit.hash }`, + `Date: ${ Info.commit.date }`, + `Branch: ${ Info.commit.branch }`, + `Tag: ${ Info.commit.tag }`, ])); process.exit(1); } @@ -284,14 +285,14 @@ Migrations._migrateTo = function(version, rerun) { 'Please make sure you are running the latest version and try again.', 'If the problem persists, please contact support.', '', - `This Rocket.Chat version: ${ RocketChat.Info.version }`, + `This Rocket.Chat version: ${ Info.version }`, `Database locked at version: ${ control.version }`, `Database target version: ${ version }`, '', - `Commit: ${ RocketChat.Info.commit.hash }`, - `Date: ${ RocketChat.Info.commit.date }`, - `Branch: ${ RocketChat.Info.commit.branch }`, - `Tag: ${ RocketChat.Info.commit.tag }`, + `Commit: ${ Info.commit.hash }`, + `Date: ${ Info.commit.date }`, + `Branch: ${ Info.commit.branch }`, + `Tag: ${ Info.commit.tag }`, ])); process.exit(1); } @@ -301,7 +302,7 @@ Migrations._migrateTo = function(version, rerun) { function lock() { const date = new Date(); const dateMinusInterval = moment(date).subtract(self.options.lockExpiration, 'minutes').toDate(); - const build = RocketChat.Info ? RocketChat.Info.build.date : date; + const build = Info ? Info.build.date : date; // This is atomic. The selector ensures only one caller at a time will see // the unlocked control, and locking occurs in the same update's modifier. diff --git a/packages/rocketchat-ui-utils/client/lib/openedRoom.js b/packages/rocketchat-ui-utils/client/lib/openedRoom.js deleted file mode 100644 index 469e8f59523f..000000000000 --- a/packages/rocketchat-ui-utils/client/lib/openedRoom.js +++ /dev/null @@ -1 +0,0 @@ -export let openedRoom; //eslint-disable-line