Browse Source

Merge pull request #2937 from overleaf/as-remove-global-lodash

Replace global Lodash with explicit imports in frontend

GitOrigin-RevId: b092647039975ac594b69ce1fa145fd03552cc60
Alasdair Smith 6 years ago
parent
commit
0d2a768e1e
42 changed files with 87 additions and 42 deletions
  1. 0 2
      services/web/frontend/js/base.js
  2. 2 1
      services/web/frontend/js/directives/bookmarkableTabset.js
  3. 1 0
      services/web/frontend/js/directives/complexPassword.js
  4. 1 0
      services/web/frontend/js/directives/eventTracking.js
  5. 1 0
      services/web/frontend/js/directives/mathjax.js
  6. 1 0
      services/web/frontend/js/ide/editor/Document.js
  7. 1 0
      services/web/frontend/js/ide/editor/EditorManager.js
  8. 1 0
      services/web/frontend/js/ide/editor/directives/aceEditor.js
  9. 1 0
      services/web/frontend/js/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.js
  10. 1 0
      services/web/frontend/js/ide/editor/directives/aceEditor/auto-complete/CommandManager.js
  11. 1 0
      services/web/frontend/js/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.js
  12. 1 1
      services/web/frontend/js/ide/editor/directives/aceEditor/highlights/HighlightsManager.js
  13. 1 0
      services/web/frontend/js/ide/editor/directives/aceEditor/metadata/MetadataManager.js
  14. 1 0
      services/web/frontend/js/ide/editor/directives/aceEditor/spell-check/HighlightedWordManager.js
  15. 1 0
      services/web/frontend/js/ide/file-tree/controllers/FileTreeController.js
  16. 1 0
      services/web/frontend/js/ide/files/services/files.js
  17. 1 0
      services/web/frontend/js/ide/graphics/services/graphics.js
  18. 1 0
      services/web/frontend/js/ide/history/HistoryV2Manager.js
  19. 1 1
      services/web/frontend/js/ide/history/components/historyEntriesList.js
  20. 2 1
      services/web/frontend/js/ide/history/components/historyEntry.js
  21. 2 1
      services/web/frontend/js/ide/history/components/historyFileTree.js
  22. 1 1
      services/web/frontend/js/ide/history/components/historyLabel.js
  23. 2 1
      services/web/frontend/js/ide/history/components/historyLabelsList.js
  24. 1 0
      services/web/frontend/js/ide/history/controllers/HistoryListController.js
  25. 1 0
      services/web/frontend/js/ide/metadata/services/metadata.js
  26. 1 0
      services/web/frontend/js/ide/pdfng/directives/pdfViewer.js
  27. 1 0
      services/web/frontend/js/ide/references/ReferencesManager.js
  28. 2 1
      services/web/frontend/js/ide/review-panel/directives/resolvedCommentsDropdown.js
  29. 2 2
      services/web/frontend/js/ide/settings/controllers/SettingsController.js
  30. 1 0
      services/web/frontend/js/ide/share/controllers/ShareProjectModalController.js
  31. 1 0
      services/web/frontend/js/main/affiliations/components/affiliationForm.js
  32. 2 2
      services/web/frontend/js/main/affiliations/controllers/UserAffiliationsController.js
  33. 2 1
      services/web/frontend/js/main/affiliations/factories/UserAffiliationsDataService.js
  34. 2 6
      services/web/frontend/js/main/learn.js
  35. 1 0
      services/web/frontend/js/main/new-subscription.js
  36. 1 0
      services/web/frontend/js/main/project-list/project-list.js
  37. 1 0
      services/web/frontend/js/main/register-users.js
  38. 1 0
      services/web/frontend/js/main/subscription-dashboard.js
  39. 1 0
      services/web/frontend/js/main/user-membership.js
  40. 0 11
      services/web/frontend/js/utils/underscore.js
  41. 40 0
      services/web/transform-lodash-global.sh
  42. 0 10
      services/web/webpack.config.js

+ 0 - 2
services/web/frontend/js/base.js

@@ -22,7 +22,6 @@ import './modules/recursionHelper'
 import './modules/errorCatcher'
 import './modules/localStorage'
 import './modules/sessionStorage'
-import './utils/underscore'
 // Configure dynamically loaded assets (via webpack) to be downloaded from CDN
 // See: https://webpack.js.org/guides/public-path/#on-the-fly
 // eslint-disable-next-line no-undef
@@ -34,7 +33,6 @@ const App = angular
     'autocomplete',
     'RecursionHelper',
     'ng-context-menu',
-    'underscore',
     'ngSanitize',
     'ipCookie',
     'ErrorCatcher',

+ 2 - 1
services/web/frontend/js/directives/bookmarkableTabset.js

@@ -1,5 +1,6 @@
+import _ from 'lodash'
 import App from '../base'
-App.directive('bookmarkableTabset', ($location, _) => ({
+App.directive('bookmarkableTabset', $location => ({
   restrict: 'A',
   require: 'tabset',
   link(scope, el, attrs, tabset) {

+ 1 - 0
services/web/frontend/js/directives/complexPassword.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* global PassField */
 
 /* eslint-disable

+ 1 - 0
services/web/frontend/js/directives/eventTracking.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     camelcase,
     max-len,

+ 1 - 0
services/web/frontend/js/directives/mathjax.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* global MathJax */
 
 import App from '../base'

+ 1 - 0
services/web/frontend/js/ide/editor/Document.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     camelcase,
     handle-callback-err,

+ 1 - 0
services/web/frontend/js/ide/editor/EditorManager.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     camelcase,
     handle-callback-err,

+ 1 - 0
services/web/frontend/js/ide/editor/directives/aceEditor.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     camelcase,
     max-len

+ 1 - 0
services/web/frontend/js/ide/editor/directives/aceEditor/auto-complete/AutoCompleteManager.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 import CommandManager from './CommandManager'
 import EnvironmentManager from './EnvironmentManager'
 import PackageManager from './PackageManager'

+ 1 - 0
services/web/frontend/js/ide/editor/directives/aceEditor/auto-complete/CommandManager.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     max-len,
     no-return-assign,

+ 1 - 0
services/web/frontend/js/ide/editor/directives/aceEditor/auto-complete/EnvironmentManager.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     max-len,
 */

+ 1 - 1
services/web/frontend/js/ide/editor/directives/aceEditor/highlights/HighlightsManager.js

@@ -15,7 +15,7 @@
  * DS207: Consider shorter variations of null checks
  * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  */
-import _ from 'ace/ace'
+import 'ace/ace'
 import ColorManager from '../../../../colors/ColorManager'
 let HighlightsManager
 const { Range } = ace.require('ace/range')

+ 1 - 0
services/web/frontend/js/ide/editor/directives/aceEditor/metadata/MetadataManager.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     max-len,
     no-cond-assign,

+ 1 - 0
services/web/frontend/js/ide/editor/directives/aceEditor/spell-check/HighlightedWordManager.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     max-len,
     no-return-assign,

+ 1 - 0
services/web/frontend/js/ide/file-tree/controllers/FileTreeController.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     camelcase,
     handle-callback-err,

+ 1 - 0
services/web/frontend/js/ide/files/services/files.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 import App from '../../../base'
 
 export default App.factory('files', function(ide) {

+ 1 - 0
services/web/frontend/js/ide/graphics/services/graphics.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     max-len,
 */

+ 1 - 0
services/web/frontend/js/ide/history/HistoryV2Manager.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     camelcase,
     max-len,

+ 1 - 1
services/web/frontend/js/ide/history/components/historyEntriesList.js

@@ -10,7 +10,7 @@
  * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  */
 import App from '../../../base'
-const historyEntriesListController = function($scope, $element, $attrs, _) {
+const historyEntriesListController = function($scope, $element, $attrs) {
   const ctrl = this
   ctrl.$entryListViewportEl = null
   ctrl.isDragging = false

+ 2 - 1
services/web/frontend/js/ide/history/components/historyEntry.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     max-len,
 */
@@ -12,7 +13,7 @@
 import App from '../../../base'
 import ColorManager from '../../colors/ColorManager'
 import displayNameForUser from '../util/displayNameForUser'
-const historyEntryController = function($scope, $element, $attrs, _) {
+const historyEntryController = function($scope, $element, $attrs) {
   const ctrl = this
   // This method (and maybe the one below) will be removed soon. User details data will be
   // injected into the history API responses, so we won't need to fetch user data from other

+ 2 - 1
services/web/frontend/js/ide/history/components/historyFileTree.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
 */
 // TODO: This file was created by bulk-decaffeinate.
@@ -8,7 +9,7 @@
  * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  */
 import App from '../../../base'
-const historyFileTreeController = function($scope, $element, $attrs, _) {
+const historyFileTreeController = function($scope, $element, $attrs) {
   const ctrl = this
   ctrl.handleEntityClick = file => ctrl.onSelectedFileChange({ file })
   ctrl._fileTree = []

+ 1 - 1
services/web/frontend/js/ide/history/components/historyLabel.js

@@ -10,7 +10,7 @@
  * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  */
 import App from '../../../base'
-const historyLabelController = function($scope, $element, $attrs, $filter, _) {
+const historyLabelController = function($scope, $element, $attrs, $filter) {
   const ctrl = this
   ctrl.$onInit = () => {
     if (ctrl.showTooltip == null) {

+ 2 - 1
services/web/frontend/js/ide/history/components/historyLabelsList.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     max-len,
 */
@@ -12,7 +13,7 @@
 import App from '../../../base'
 import ColorManager from '../../colors/ColorManager'
 import displayNameForUser from '../util/displayNameForUser'
-const historyLabelsListController = function($scope, $element, $attrs, _) {
+const historyLabelsListController = function($scope, $element, $attrs) {
   const ctrl = this
   ctrl.isDragging = false
   ctrl.versionsWithLabels = []

+ 1 - 0
services/web/frontend/js/ide/history/controllers/HistoryListController.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     camelcase,
     max-len,

+ 1 - 0
services/web/frontend/js/ide/metadata/services/metadata.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     no-return-assign,
 */

+ 1 - 0
services/web/frontend/js/ide/pdfng/directives/pdfViewer.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     handle-callback-err,
     max-len,

+ 1 - 0
services/web/frontend/js/ide/references/ReferencesManager.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     max-len,
     no-return-assign,

+ 2 - 1
services/web/frontend/js/ide/review-panel/directives/resolvedCommentsDropdown.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     max-len,
     no-return-assign,
@@ -13,7 +14,7 @@
  */
 import App from '../../../base'
 
-export default App.directive('resolvedCommentsDropdown', _ => ({
+export default App.directive('resolvedCommentsDropdown', () => ({
   restrict: 'E',
   templateUrl: 'resolvedCommentsDropdownTemplate',
   scope: {

+ 2 - 2
services/web/frontend/js/ide/settings/controllers/SettingsController.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     camelcase,
     max-len,
@@ -17,8 +18,7 @@ export default App.controller('SettingsController', function(
   $scope,
   ExposedSettings,
   settings,
-  ide,
-  _
+  ide
 ) {
   const validRootDocExtensions = ExposedSettings.validRootDocExtensions
   const validRootDocRegExp = new RegExp(

+ 1 - 0
services/web/frontend/js/ide/share/controllers/ShareProjectModalController.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 import App from '../../../base'
 App.controller('ShareProjectModalController', function(
   $scope,

+ 1 - 0
services/web/frontend/js/main/affiliations/components/affiliationForm.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     max-len,
     no-return-assign,

+ 2 - 2
services/web/frontend/js/main/affiliations/controllers/UserAffiliationsController.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     max-len,
     no-return-assign,
@@ -10,8 +11,7 @@ export default App.controller('UserAffiliationsController', function(
   $scope,
   UserAffiliationsDataService,
   $q,
-  $window,
-  _
+  $window
 ) {
   $scope.userEmails = []
   $scope.linkedInstitutionIds = []

+ 2 - 1
services/web/frontend/js/main/affiliations/factories/UserAffiliationsDataService.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 import App from '../../../base'
 const countriesList = [
   { code: 'af', name: 'Afghanistan' },
@@ -405,7 +406,7 @@ for (let domain of commonDomains) {
   }
 }
 
-App.factory('UserAffiliationsDataService', function($http, $q, _) {
+App.factory('UserAffiliationsDataService', function($http, $q) {
   const getCountries = () => $q.resolve(countriesList)
 
   const getDefaultRoleHints = () => $q.resolve(defaultRoleHints)

+ 2 - 6
services/web/frontend/js/main/learn.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     camelcase,
     handle-callback-err,
@@ -16,12 +17,7 @@
 import App from '../base'
 import '../directives/mathjax'
 import '../services/algolia-search'
-App.controller('SearchWikiController', function(
-  $scope,
-  algoliaSearch,
-  _,
-  $modal
-) {
+App.controller('SearchWikiController', function($scope, algoliaSearch, $modal) {
   $scope.hits = []
   $scope.hits_total = 0
   $scope.config_hits_per_page = 20

+ 1 - 0
services/web/frontend/js/main/new-subscription.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     camelcase,
     max-len,

+ 1 - 0
services/web/frontend/js/main/project-list/project-list.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 import App from '../../base'
 import './services/project-list'
 App.controller('ProjectPageController', function(

+ 1 - 0
services/web/frontend/js/main/register-users.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     max-len,
     no-return-assign,

+ 1 - 0
services/web/frontend/js/main/subscription-dashboard.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* global recurly */
 
 /* eslint-disable

+ 1 - 0
services/web/frontend/js/main/user-membership.js

@@ -1,3 +1,4 @@
+import _ from 'lodash'
 /* eslint-disable
     max-len,
     no-return-assign,

+ 0 - 11
services/web/frontend/js/utils/underscore.js

@@ -1,11 +0,0 @@
-/* eslint-disable
-*/
-// TODO: This file was created by bulk-decaffeinate.
-// Fix any style issues and re-enable lint.
-/*
- * decaffeinate suggestions:
- * DS102: Remove unnecessary code created because of implicit returns
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
- */
-import '../libraries'
-export default angular.module('underscore', []).factory('_', () => window._)

+ 40 - 0
services/web/transform-lodash-global.sh

@@ -0,0 +1,40 @@
+npx jscodeshift \
+  -t https://gist.githack.com/40thieves/0b495af3fb0ad5fe08915ce5159a2b7b/raw/9c583c0a5b0cbd83a66538a07591b41332efda6a/transform-lodash.js \
+  --ignore-pattern frontend/js/vendor \
+  --noSemi=true \
+  frontend/js
+
+npx jscodeshift \
+  -t https://gist.githack.com/40thieves/0b495af3fb0ad5fe08915ce5159a2b7b/raw/9c583c0a5b0cbd83a66538a07591b41332efda6a/transform-lodash.js \
+  --noSemi=true \
+  test/frontend
+
+for MODULE in admin-panel cms dropbox git-bridge github-sync launchpad metrics open-in-overleaf overleaf-integration portals references-search support templates tpr-webmodule two-factor-authentication v2-templates	
+do	
+  npx jscodeshift \
+    -t https://gist.githack.com/40thieves/0b495af3fb0ad5fe08915ce5159a2b7b/raw/9c583c0a5b0cbd83a66538a07591b41332efda6a/transform-lodash.js \
+    --noSemi=true \
+  modules/$MODULE/frontend/js
+done
+
+npx jscodeshift \
+  -t https://gist.githack.com/40thieves/0b495af3fb0ad5fe08915ce5159a2b7b/raw/9c583c0a5b0cbd83a66538a07591b41332efda6a/transform-lodash.js \
+  --noSemi=true \
+  modules/rich-text/frontend/js
+
+npx jscodeshift \
+  -t https://gist.githack.com/40thieves/0b495af3fb0ad5fe08915ce5159a2b7b/raw/9c583c0a5b0cbd83a66538a07591b41332efda6a/transform-lodash.js \
+  --noSemi=true \
+  modules/rich-text/test/frontend
+
+npx jscodeshift \
+  -t https://gist.githack.com/40thieves/0b495af3fb0ad5fe08915ce5159a2b7b/raw/9c583c0a5b0cbd83a66538a07591b41332efda6a/transform-lodash.js \
+  --noSemi=true \
+  modules/publish-modal/frontend/js
+
+npx jscodeshift \
+  -t https://gist.githack.com/40thieves/0b495af3fb0ad5fe08915ce5159a2b7b/raw/9c583c0a5b0cbd83a66538a07591b41332efda6a/transform-lodash.js \
+  --noSemi=true \
+  modules/publish-modal/test/frontend
+
+make format_fix

+ 0 - 10
services/web/webpack.config.js

@@ -181,16 +181,6 @@ module.exports = {
             options: 'angular'
           }
         ]
-      },
-      {
-        // Expose lodash global variable
-        test: require.resolve('lodash'),
-        use: [
-          {
-            loader: 'expose-loader',
-            options: '_'
-          }
-        ]
       }
     ]
   },