Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

js: Convert residual require() calls to import in ES6 modules.

Anders Kaseorgb38712d8d269
diff --git a/static/js/archive.js b/static/js/archive.js
index 894cd0442d5..1fb95b068b1 100644
--- a/static/js/archive.js
+++ b/static/js/archive.js
@@ -1,3 +1,4 @@
+import {format, isSameDay} from "date-fns";
import _ from "lodash";
import render_archive_message_group from "../templates/archive_message_group.hbs";
@@ -6,8 +7,6 @@ import * as color_data from "./color_data";
import * as floating_recipient_bar from "./floating_recipient_bar";
import * as timerender from "./timerender";
-const {format, isSameDay} = require("date-fns");
-
function should_separate_into_groups(current_msg_time, next_msg_time) {
return isSameDay(current_msg_time * 1000, next_msg_time * 1000);
}
diff --git a/static/js/message_edit_history.js b/static/js/message_edit_history.js
index c0f1ae5b265..6bd80974dea 100644
--- a/static/js/message_edit_history.js
+++ b/static/js/message_edit_history.js
@@ -1,3 +1,5 @@
+import {format, isSameDay} from "date-fns";
+
import render_message_edit_history from "../templates/message_edit_history.hbs";
import * as channel from "./channel";
@@ -5,8 +7,6 @@ import * as people from "./people";
import * as timerender from "./timerender";
import * as ui_report from "./ui_report";
-const {format, isSameDay} = require("date-fns");
-
export function fetch_and_render_message_history(message) {
channel.get({
url: "/json/messages/" + message.id + "/history",
diff --git a/static/js/peer_data.js b/static/js/peer_data.js
index d96839f3466..67b1ab96866 100644
--- a/static/js/peer_data.js
+++ b/static/js/peer_data.js
@@ -1,8 +1,7 @@
+import {LazySet} from "./lazy_set";
+import * as people from "./people";
import * as stream_data from "./stream_data";
-const {LazySet} = require("./lazy_set");
-const people = require("./people");
-
// This maps a stream_id to a LazySet of user_ids who are subscribed.
const stream_subscribers = new Map();
diff --git a/static/js/popovers.js b/static/js/popovers.js
index b6db3025f05..78454d06e64 100644
--- a/static/js/popovers.js
+++ b/static/js/popovers.js
@@ -1,4 +1,5 @@
import ClipboardJS from "clipboard";
+import {parseISO, formatISO, add, set} from "date-fns";
import ConfirmDatePlugin from "flatpickr/dist/plugins/confirmDate/confirmDate";
import render_actions_popover_content from "../templates/actions_popover_content.hbs";
@@ -40,8 +41,6 @@ import * as user_status from "./user_status";
import * as user_status_ui from "./user_status_ui";
import * as util from "./util";
-const {parseISO, formatISO, add, set} = require("date-fns");
-
let current_actions_popover_elem;
let current_flatpickr_instance;
let current_message_info_popover_elem;
diff --git a/static/js/rendered_markdown.js b/static/js/rendered_markdown.js
index 46c419f167c..4c7240ffb35 100644
--- a/static/js/rendered_markdown.js
+++ b/static/js/rendered_markdown.js
@@ -1,4 +1,5 @@
import ClipboardJS from "clipboard";
+import {parseISO, isValid} from "date-fns";
import copy_code_button from "../templates/copy_code_button.hbs";
import view_code_in_playground from "../templates/view_code_in_playground.hbs";
@@ -10,8 +11,6 @@ import * as stream_data from "./stream_data";
import * as timerender from "./timerender";
import * as user_groups from "./user_groups";
-const {parseISO, isValid} = require("date-fns");
-
/*
rendered_markdown
diff --git a/static/js/settings_account.js b/static/js/settings_account.js
index 1880f1aace8..93782bd2374 100644
--- a/static/js/settings_account.js
+++ b/static/js/settings_account.js
@@ -397,7 +397,7 @@ export function set_up() {
}
});
- $("#change_password").on("click", (e) => {
+ $("#change_password").on("click", async (e) => {
e.preventDefault();
e.stopPropagation();
overlays.open_modal("#change_password_modal");
@@ -405,10 +405,9 @@ export function set_up() {
if (page_params.realm_password_auth_enabled !== false) {
// zxcvbn.js is pretty big, and is only needed on password
// change, so load it asynchronously.
- require(["zxcvbn"], (zxcvbn) => {
- window.zxcvbn = zxcvbn;
- $("#pw_strength .bar").removeClass("fade");
- });
+ const {default: zxcvbn} = await import("zxcvbn");
+ window.zxcvbn = zxcvbn;
+ $("#pw_strength .bar").removeClass("fade");
}
});
diff --git a/static/js/stats/stats.js b/static/js/stats/stats.js
index 428aebe2740..78116a95253 100644
--- a/static/js/stats/stats.js
+++ b/static/js/stats/stats.js
@@ -1,6 +1,8 @@
+import PlotlyBar from "plotly.js/lib/bar";
import Plotly from "plotly.js/lib/core";
+import PlotlyPie from "plotly.js/lib/pie";
-Plotly.register([require("plotly.js/lib/bar"), require("plotly.js/lib/pie")]);
+Plotly.register([PlotlyBar, PlotlyPie]);
const font_14pt = {
family: "Source Sans 3",
diff --git a/static/js/timerender.js b/static/js/timerender.js
index ade05d02058..71f447d1033 100644
--- a/static/js/timerender.js
+++ b/static/js/timerender.js
@@ -1,4 +1,4 @@
-const {
+import {
differenceInMinutes,
differenceInCalendarDays,
format,
@@ -6,7 +6,7 @@ const {
isValid,
parseISO,
startOfToday,
-} = require("date-fns");
+} from "date-fns";
let next_timerender_id = 0;