js: Replace underscore with lodash and remove it from globals.

Tweaked by tabbott to bump PROVISION_VERSION.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-07-24 17:02:35 -07:00 committed by Tim Abbott
parent 9c7a3cc0f4
commit d2520cd7e0
60 changed files with 100 additions and 28 deletions

View File

@ -109,7 +109,6 @@
"UserSearch": false,
"WinChan": false,
"XDate": false,
"_": false,
"activity": false,
"admin": false,
"alert_words": false,

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const _page_params = {};
set_global("page_params", _page_params);

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
set_global("$", global.make_zjquery());
zrequire("people");
zrequire("buddy_data");

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
set_global("$", {});
set_global("reload", {});

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
zrequire("keydown_util");
zrequire("components");

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const emoji = zrequire("emoji", "shared/js/emoji");
zrequire("emoji_picker");

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
set_global("$", global.make_zjquery());
set_global("document", "document-stub");

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
set_global("$", global.make_zjquery());
set_global("document", "document-stub");

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
zrequire("people");
set_global("message_store", {});
set_global("page_params", {});

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
zrequire("user_pill");
zrequire("settings_user_groups");

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
set_global("page_params", {
is_admin: false,
realm_users: [],

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
set_global("narrow_state", {});
set_global("unread", {});
set_global("muting", {});

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
zrequire("muting");
zrequire("people");
zrequire("stream_data");

View File

@ -1,4 +1,5 @@
const {JSDOM} = require("jsdom");
const _ = require("lodash");
set_global("$", global.make_zjquery());
set_global("DOMParser", new JSDOM().window.DOMParser);

View File

@ -1,7 +1,7 @@
const fs = require("fs");
const path = require("path");
const _ = require("underscore/underscore.js");
const _ = require("lodash");
exports.find_files_to_run = function () {
let oneFileFilter = [];

View File

@ -2,7 +2,7 @@ const fs = require("fs");
const Module = require("module");
const path = require("path");
const escapeRegExp = require("lodash/escapeRegExp");
const _ = require("lodash");
const finder = require("./finder.js");
const handlebars = require("./handlebars.js");
@ -15,18 +15,15 @@ const zjquery = require("./zjquery.js");
require("@babel/register")({
extensions: [".es6", ".es", ".jsx", ".js", ".mjs", ".ts"],
only: [
new RegExp("^" + escapeRegExp(path.resolve(__dirname, "../../static/js")) + path.sep),
new RegExp("^" + _.escapeRegExp(path.resolve(__dirname, "../../static/js")) + path.sep),
new RegExp(
"^" + escapeRegExp(path.resolve(__dirname, "../../static/shared/js")) + path.sep,
"^" + _.escapeRegExp(path.resolve(__dirname, "../../static/shared/js")) + path.sep,
),
],
plugins: ["rewire-ts"],
});
global.assert = require("assert").strict;
global._ = require("underscore/underscore.js");
const _ = global._;
// Create a helper function to avoid sneaky delays in tests.
function immediate(f) {

View File

@ -21,7 +21,7 @@
*/
const {JSDOM} = require("jsdom");
const _ = require("underscore");
const _ = require("lodash");
const mdiff = require("./mdiff.js");

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const requires = [];
const new_globals = new Set();
let old_globals = {};

View File

@ -42,6 +42,7 @@
"jquery-validation": "^1.19.0",
"js-yaml": "^3.13.1",
"katex": "^0.12.0",
"lodash": "^4.17.19",
"mini-css-extract-plugin": "^0.9.0",
"moment": "^2.24.0",
"moment-timezone": "^0.5.25",
@ -67,7 +68,6 @@
"style-loader": "^1.0.0",
"terser-webpack-plugin": "^3.0.3",
"turndown": "^6.0.0",
"underscore": "^1.9.1",
"unorm": "^1.6.0",
"webfonts-loader": "^5.0.0",
"webpack": "^4.33.0",
@ -84,7 +84,6 @@
"@types/node": "^14.0.11",
"@types/optimize-css-assets-webpack-plugin": "^5.0.1",
"@types/terser-webpack-plugin": "^3.0.0",
"@types/underscore": "^1.8.18",
"@types/webpack": "^4.4.32",
"@types/webpack-dev-server": "^3.1.6",
"@typescript-eslint/eslint-plugin": "^3.1.0",

View File

@ -1,3 +1,4 @@
const _ = require("lodash");
/*
Helpers for detecting user activity and managing user idle states
*/

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const render_archive_message_group = require("../templates/archive_message_group.hbs");
function should_separate_into_groups(current_msg_time, next_msg_time) {

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const bots = new Map();
const bot_fields = [

View File

@ -2,7 +2,6 @@ import "core-js/features/promise";
import "core-js/features/symbol";
import "../../../tools/debug-require";
import "jquery/dist/jquery.js";
import "underscore/underscore.js";
import "../page_params.js";
import "../csrf.js";
import "../blueslip.js";

View File

@ -1,3 +1,4 @@
const _ = require("lodash");
// You won't find every click handler here, but it's a good place to start!
const render_buddy_list_tooltip = require("../templates/buddy_list_tooltip.hbs");

View File

@ -1,3 +1,4 @@
const _ = require("lodash");
// These colors are used now for streams.
const stream_colors = [
"#76ce90",

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const util = require("./util");
let focused_recipient;

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const util = require("./util");
function zephyr_stream_name_match(message, operand) {

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const render_hotspot_overlay = require("../templates/hotspot_overlay.hbs");
const render_intro_reply_hotspot = require("../templates/intro_reply_hotspot.hbs");

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const huddle_timestamps = new Map();
exports.process_loaded_messages = function (messages) {

View File

@ -1,4 +1,5 @@
const katex = require("katex/dist/katex.min.js");
const _ = require("lodash");
const fenced_code = require("../shared/js/fenced_code");

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
function send_flag_update(message, flag, op) {
channel.post({
url: "/json/messages/flags",

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const util = require("./util");
function MessageListData(opts) {

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const render_bookend = require("../templates/bookend.hbs");
const render_message_group = require("../templates/message_group.hbs");
const render_recipient_row = require("../templates/recipient_row.hbs");
@ -475,7 +477,7 @@ MessageListView.prototype = {
// rerender the last message
message_actions.rerender_messages_next_same_sender.push(prev_msg_container);
message_actions.append_messages = _.first(new_message_groups).message_containers;
new_message_groups = _.rest(new_message_groups);
new_message_groups = _.tail(new_message_groups);
} else if (first_group !== undefined && second_group !== undefined) {
if (same_day(prev_msg_container, curr_msg_container)) {
clear_group_date_divider(second_group);

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
let actively_scrolling = false;
// Tracks whether the next scroll that will complete is initiated by

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const render_compose_notification = require("../templates/compose_notification.hbs");
const render_notification = require("../templates/notification.hbs");

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
require("unorm"); // String.prototype.normalize polyfill for IE11
const typeahead = require("../shared/js/typeahead");

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const render_pm_list_item = require("../templates/pm_list_item.hbs");
exports.keyed_pm_li = (convo) => {

View File

@ -1,3 +1,5 @@
import _ from "lodash";
import blueslip from "./../blueslip";
import * as google_analytics from "./google-analytics.js";
import {path_parts} from "./landing-page";

View File

@ -1,3 +1,5 @@
import _ from "lodash";
const contributors_list = page_params.contributors;
const repo_name_to_tab_name = {

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const emoji = require("../shared/js/emoji");
const render_message_reaction = require("../templates/message_reaction.hbs");

View File

@ -1,3 +1,4 @@
const _ = require("lodash");
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/events-system.html
let waiting_on_homeview_load = true;

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const render_settings_api_key_modal = require("../templates/settings/api_key_modal.hbs");
const render_settings_custom_user_profile_field = require("../templates/settings/custom_user_profile_field.hbs");
const render_settings_dev_env_email_access = require("../templates/settings/dev_env_email_access.hbs");

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const render_admin_user_group_list = require("../templates/admin_user_group_list.hbs");
const render_confirm_delete_user = require("../templates/confirm_delete_user.hbs");

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
exports.default_color = "#c2c2c2";
// Classes which could be returned by get_color_class.

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const render_stream_privacy = require("../templates/stream_privacy.hbs");
const render_stream_sidebar_row = require("../templates/stream_sidebar_row.hbs");

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const render_subscription = require("../templates/subscription.hbs");
const render_subscription_settings = require("../templates/subscription_settings.hbs");
const render_subscription_table_body = require("../templates/subscription_table_body.hbs");

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const render_more_topics = require("../templates/more_topics.hbs");
const render_more_topics_spinner = require("../templates/more_topics_spinner.hbs");
const render_topic_list_item = require("../templates/topic_list_item.hbs");

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const util = require("./util");
// See docs/subsystems/typing-indicators.md for details on typing indicators.
@ -46,7 +48,7 @@ exports.get_group_typists = function (group) {
exports.get_all_typists = function () {
let typists = [].concat(...Array.from(typist_dct.values()));
typists = util.sorted_ids(typists);
typists = _.uniq(typists, true);
typists = _.sortedUniq(typists);
return typists;
};

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
const generated_emoji_codes = require("../generated/emoji/emoji_codes.json");
const emoji = require("../shared/js/emoji");

View File

@ -1,3 +1,4 @@
const _ = require("lodash");
/* Arguments used in the report_* functions are,
response- response that we want to display
status_box- element being used to display the response

View File

@ -1,3 +1,4 @@
const _ = require("lodash");
// From MDN: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math/random
exports.random_int = function random_int(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
@ -229,7 +230,7 @@ exports.sorted_ids = function (ids) {
// it also makes sure we don't mutate the list.
let id_list = ids.map(to_int);
id_list.sort((a, b) => a - b);
id_list = _.uniq(id_list, true);
id_list = _.sortedUniq(id_list);
return id_list;
};

View File

@ -1,3 +1,5 @@
const _ = require("lodash");
exports.eq_array = (a, b, eq) => {
if (a === b) {
// either both are undefined, or they

View File

@ -1,5 +1,5 @@
import katex from "katex/dist/katex.min.js";
import _ from "underscore";
import _ from "lodash";
// Parsing routine that can be dropped in to message parsing
// and formats code blocks

View File

@ -1,4 +1,4 @@
import _ from "underscore";
import _ from "lodash";
// The following constants are tuned to work with
// TYPING_STARTED_EXPIRY_PERIOD, which is what the other

View File

@ -4,6 +4,6 @@
"license": "Apache-2.0",
"dependencies": {
"katex": "^0.12.0",
"underscore": "^1.9.1"
"lodash": "^4.17.19"
}
}

View File

@ -120,7 +120,7 @@
<div id="tab-terminal" class="contributors"></div>
</div>
<!-- Compiled using underscore -->
<!-- Compiled using lodash -->
<script type="text/template" id="contributors-template">
<div class="person">
<a href="<%= profile_url %>" target="_blank" rel="noopener noreferrer" class="no-underline">

View File

@ -45,7 +45,7 @@ def check_html_templates(templates: Iterable[str], all_dups: bool, fix: bool) ->
# so we exclude them from our linter.
logging.basicConfig(format='%(levelname)s:%(message)s')
templates = sorted(fn for fn in templates if 'casperjs' not in fn)
# Use of underscore templates <%= %>.
# Use of lodash templates <%= %>.
if 'templates/zerver/team.html' in templates:
templates.remove('templates/zerver/team.html')

View File

@ -240,7 +240,7 @@ export default (env?: string): webpack.Configuration[] => {
};
// Expose Global variables for third party libraries to webpack modules
// Use the unminified versions of jquery and underscore so that
// Use the unminified version of jquery so that
// Good error messages show up in production and development in the source maps
const exposeOptions = [
{path: "./debug-require.js", name: "require"},
@ -250,7 +250,6 @@ export default (env?: string): webpack.Configuration[] => {
{path: "../static/third/marked/lib/marked.js"},
{path: "../static/js/debug.js"},
{path: "jquery/dist/jquery.js", name: ["$", "jQuery"]},
{path: "underscore/underscore.js", name: "_"},
{path: "handlebars/dist/cjs/handlebars.runtime.js", name: "Handlebars"},
{path: "sortablejs/Sortable.js"},
{path: "winchan/winchan.js", name: "WinChan"},

View File

@ -44,4 +44,4 @@ API_FEATURE_LEVEL = 27
# historical commits sharing the same major version, in which case a
# minor version bump suffices.
PROVISION_VERSION = '91.3'
PROVISION_VERSION = '92.0'

View File

@ -1261,11 +1261,6 @@
dependencies:
source-map "^0.6.1"
"@types/underscore@^1.8.18":
version "1.10.9"
resolved "https://registry.yarnpkg.com/@types/underscore/-/underscore-1.10.9.tgz#ba7a9cfc15873e67821611503a34a7c26bf7264f"
integrity sha512-mKzbGzZ02nXKSV2VJdY92KNzwV7x4Zq626/4qR+7nJEceyKGk5gJXCi0mQqp3tEUa3GTc8uiuxqm4QyIaP0I1Q==
"@types/unist@^2.0.0", "@types/unist@^2.0.2":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e"