From 1b94733953c5d2afa28c3073917a0dbbcfc0c6a8 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 20 Jun 2019 16:59:21 -0700 Subject: [PATCH] webpack: Remove resolve.modules override. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The minimal syntactic sugar it might provide isn’t worth the unexpected side effects (including side effects on third party modules). For now, we allow zrequire to emulate the previous syntax in the Node test suite, even though stealing part of the NPM namespace is confusing. Signed-off-by: Anders Kaseorg --- frontend_tests/zjsunit/index.js | 2 +- frontend_tests/zjsunit/namespace.js | 5 +- static/js/bundles/app.js | 418 ++++++++++++++-------------- static/js/bundles/commons.js | 18 +- tools/test-js-with-node | 1 - tools/webpack.config.ts | 5 - 6 files changed, 223 insertions(+), 226 deletions(-) diff --git a/frontend_tests/zjsunit/index.js b/frontend_tests/zjsunit/index.js index a107ef1401..f19b661e1a 100644 --- a/frontend_tests/zjsunit/index.js +++ b/frontend_tests/zjsunit/index.js @@ -27,7 +27,7 @@ global.window = _.extend({}, windowObj, { }, }); -global.Dict = require('js/dict').Dict; +global.Dict = require('../../static/js/dict').Dict; // Create a helper function to avoid sneaky delays in tests. function immediate(f) { diff --git a/frontend_tests/zjsunit/namespace.js b/frontend_tests/zjsunit/namespace.js index 5ea59ac687..0fd723f943 100644 --- a/frontend_tests/zjsunit/namespace.js +++ b/frontend_tests/zjsunit/namespace.js @@ -21,7 +21,10 @@ exports.patch_builtin = function (name, val) { exports.zrequire = function (name, fn) { if (fn === undefined) { - fn = 'js/' + name; + fn = '../../static/js/' + name; + } else if (/generated\/|js\/|third\//.test(fn)) { + // FIXME: Stealing part of the NPM namespace is confusing. + fn = '../../static/' + fn; } delete require.cache[require.resolve(fn)]; var obj = require(fn); diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js index 870493aa44..6637fd25a8 100644 --- a/static/js/bundles/app.js +++ b/static/js/bundles/app.js @@ -1,14 +1,14 @@ -import "js/bundles/commons.js"; +import "./commons.js"; // Import Third party libraries -import "third/bootstrap-notify/js/bootstrap-notify.js"; -import "third/jquery-filedrop/jquery.filedrop.js"; +import "../../third/bootstrap-notify/js/bootstrap-notify.js"; +import "../../third/jquery-filedrop/jquery.filedrop.js"; import "jquery-caret-plugin/src/jquery.caret.js"; -import "third/jquery-idle/jquery.idle.js"; +import "../../third/jquery-idle/jquery.idle.js"; import "jquery-autosize"; -import "third/spectrum/spectrum.js"; -import "third/sockjs/sockjs-0.3.4.js"; -import "third/marked/lib/marked.js"; +import "../../third/spectrum/spectrum.js"; +import "../../third/sockjs/sockjs-0.3.4.js"; +import "../../third/marked/lib/marked.js"; import "xdate/src/xdate.js"; import "jquery-validation/dist/jquery.validate.js"; import "blueimp-md5/js/md5.js"; @@ -21,213 +21,213 @@ import "flatpickr/dist/flatpickr.js"; import "flatpickr/dist/plugins/confirmDate/confirmDate.js"; import "error-stack-parser/dist/error-stack-parser.min.js"; import "sortablejs/Sortable.js"; -import "generated/emoji/emoji_codes.js"; -import "generated/pygments_data.js"; +import "../../generated/emoji/emoji_codes.js"; +import "../../generated/pygments_data.js"; // Import App JS -import "js/translations.js"; -import "js/feature_flags.js"; -import "js/loading.js"; -import 'js/schema.js'; -import "js/util.js"; -import "js/search_util.js"; -import "js/keydown_util.js"; -import "js/lightbox_canvas.js"; -import "js/rtl.js"; -import "js/dict.ts"; -import "js/scroll_util.js"; -import "js/components.js"; -import "js/feedback_widget.js"; -import "js/localstorage.js"; -import "js/drafts.js"; -import "js/input_pill.js"; -import "js/user_pill.js"; -import "js/compose_pm_pill.js"; -import "js/channel.js"; -import "js/csrf.js"; -import "js/setup.js"; -import "js/unread_ui.js"; -import "js/unread_ops.js"; -import "js/muting.js"; -import "js/muting_ui.js"; -import "js/message_viewport.js"; -import "js/rows.js"; -import "js/people.js"; -import "js/user_groups.js"; -import "js/unread.js"; -import "js/topic_list.js"; -import "js/pm_list.js"; -import "js/pm_conversations.js"; -import "js/recent_senders.js"; -import "js/stream_sort.js"; -import "js/topic_generator.js"; -import "js/top_left_corner.js"; -import "js/stream_list.js"; -import "js/topic_zoom.js"; -import "js/filter.js"; -import 'js/poll_widget.js'; -import 'js/todo_widget.js'; -import 'js/tictactoe_widget.js'; -import 'js/zform.js'; -import 'js/widgetize.js'; -import 'js/submessage.js'; -import "js/fetch_status.js"; -import "js/message_list_data.js"; -import "js/message_list_view.js"; -import "js/message_list.js"; -import "js/message_live_update.js"; -import "js/narrow_state.js"; -import "js/narrow.js"; -import "js/reload_state.js"; -import "js/reload.js"; -import "js/compose_fade.js"; -import "js/fenced_code.js"; -import "js/markdown.js"; -import 'js/local_message.js'; -import "js/echo.js"; -import "js/socket.js"; -import "js/sent_messages.js"; -import "js/compose_state.js"; -import "js/compose_actions.js"; -import "js/transmit.js"; -import "js/zcommand.js"; -import "js/compose.js"; -import "js/upload.js"; -import "js/color_data.js"; -import "js/stream_color.js"; -import "js/stream_data.js"; -import "js/topic_data.js"; -import "js/stream_muting.js"; -import "js/stream_events.js"; -import "js/stream_create.js"; -import "js/stream_edit.js"; -import "js/subs.js"; -import "js/message_edit.js"; -import "js/condense.js"; -import "js/resize.js"; -import "js/list_render.js"; -import "js/floating_recipient_bar.js"; -import "js/lightbox.js"; -import "js/ui_report.js"; -import "js/message_scroll.js"; -import "js/info_overlay.js"; -import "js/ui.js"; -import "js/night_mode.js"; -import "js/ui_util.js"; -import "js/pointer.js"; -import "js/click_handlers.js"; -import "js/settings_panel_menu.js"; -import "js/settings_toggle.js"; -import "js/scroll_bar.js"; -import "js/gear_menu.js"; -import "js/copy_and_paste.js"; -import "js/stream_popover.js"; -import "js/popovers.js"; -import "js/overlays.js"; -import "js/typeahead_helper.js"; -import "js/search_suggestion.js"; -import "js/search.js"; -import "js/composebox_typeahead.js"; -import "js/navigate.js"; -import "js/list_util.js"; -import "js/hotkey.js"; -import "js/favicon.js"; -import "js/notifications.js"; -import "js/hash_util.js"; -import "js/hashchange.js"; -import "js/invite.js"; -import "js/message_flags.js"; -import "js/starred_messages.js"; -import "js/alert_words.js"; -import "js/alert_words_ui.js"; -import "js/attachments_ui.js"; -import "js/message_store.js"; -import "js/message_util.js"; -import "js/message_events.js"; -import "js/message_fetch.js"; -import "js/server_events.js"; -import "js/server_events_dispatch.js"; -import "js/zulip.js"; -import "js/presence.js"; -import "js/user_search.js"; -import "js/user_status.js"; -import "js/user_status_ui.js"; -import "js/buddy_data.js"; -import "js/padded_widget.js"; -import "js/buddy_list.js"; -import "js/list_cursor.js"; -import "js/activity.js"; -import "js/user_events.js"; -import "js/colorspace.js"; -import "js/timerender.js"; -import "js/tutorial.js"; -import "js/hotspots.js"; -import "js/templates.js"; -import "js/upload_widget.js"; -import "js/avatar.js"; -import "js/realm_icon.js"; -import "js/realm_logo.js"; -import 'js/reminder.js'; -import 'js/confirm_dialog.js'; -import "js/settings_account.js"; -import "js/settings_display.js"; -import "js/settings_notifications.js"; -import "js/settings_bots.js"; -import "js/settings_muting.js"; -import "js/settings_sections.js"; -import "js/settings_emoji.js"; -import "js/settings_org.js"; -import "js/settings_users.js"; -import "js/settings_streams.js"; -import "js/settings_linkifiers.js"; -import "js/settings_invites.js"; -import "js/settings_user_groups.js"; -import "js/settings_profile_fields.js"; -import "js/settings.js"; -import "js/admin.js"; -import "js/tab_bar.js"; -import "js/emoji.js"; -import "js/bot_data.js"; -import "js/reactions.js"; -import "js/typing.js"; -import "js/typing_status.js"; -import "js/typing_data.js"; -import "js/typing_events.js"; -import "js/ui_init.js"; -import "js/emoji_picker.js"; -import "js/compose_ui.js"; -import "js/panels.js"; -import 'js/settings_ui.js'; -import 'js/search_pill.js'; -import 'js/search_pill_widget.js'; -import 'js/stream_ui_updates.js'; +import "../translations.js"; +import "../feature_flags.js"; +import "../loading.js"; +import "../schema.js"; +import "../util.js"; +import "../search_util.js"; +import "../keydown_util.js"; +import "../lightbox_canvas.js"; +import "../rtl.js"; +import "../dict.ts"; +import "../scroll_util.js"; +import "../components.js"; +import "../feedback_widget.js"; +import "../localstorage.js"; +import "../drafts.js"; +import "../input_pill.js"; +import "../user_pill.js"; +import "../compose_pm_pill.js"; +import "../channel.js"; +import "../csrf.js"; +import "../setup.js"; +import "../unread_ui.js"; +import "../unread_ops.js"; +import "../muting.js"; +import "../muting_ui.js"; +import "../message_viewport.js"; +import "../rows.js"; +import "../people.js"; +import "../user_groups.js"; +import "../unread.js"; +import "../topic_list.js"; +import "../pm_list.js"; +import "../pm_conversations.js"; +import "../recent_senders.js"; +import "../stream_sort.js"; +import "../topic_generator.js"; +import "../top_left_corner.js"; +import "../stream_list.js"; +import "../topic_zoom.js"; +import "../filter.js"; +import "../poll_widget.js"; +import "../todo_widget.js"; +import "../tictactoe_widget.js"; +import "../zform.js"; +import "../widgetize.js"; +import "../submessage.js"; +import "../fetch_status.js"; +import "../message_list_data.js"; +import "../message_list_view.js"; +import "../message_list.js"; +import "../message_live_update.js"; +import "../narrow_state.js"; +import "../narrow.js"; +import "../reload_state.js"; +import "../reload.js"; +import "../compose_fade.js"; +import "../fenced_code.js"; +import "../markdown.js"; +import "../local_message.js"; +import "../echo.js"; +import "../socket.js"; +import "../sent_messages.js"; +import "../compose_state.js"; +import "../compose_actions.js"; +import "../transmit.js"; +import "../zcommand.js"; +import "../compose.js"; +import "../upload.js"; +import "../color_data.js"; +import "../stream_color.js"; +import "../stream_data.js"; +import "../topic_data.js"; +import "../stream_muting.js"; +import "../stream_events.js"; +import "../stream_create.js"; +import "../stream_edit.js"; +import "../subs.js"; +import "../message_edit.js"; +import "../condense.js"; +import "../resize.js"; +import "../list_render.js"; +import "../floating_recipient_bar.js"; +import "../lightbox.js"; +import "../ui_report.js"; +import "../message_scroll.js"; +import "../info_overlay.js"; +import "../ui.js"; +import "../night_mode.js"; +import "../ui_util.js"; +import "../pointer.js"; +import "../click_handlers.js"; +import "../settings_panel_menu.js"; +import "../settings_toggle.js"; +import "../scroll_bar.js"; +import "../gear_menu.js"; +import "../copy_and_paste.js"; +import "../stream_popover.js"; +import "../popovers.js"; +import "../overlays.js"; +import "../typeahead_helper.js"; +import "../search_suggestion.js"; +import "../search.js"; +import "../composebox_typeahead.js"; +import "../navigate.js"; +import "../list_util.js"; +import "../hotkey.js"; +import "../favicon.js"; +import "../notifications.js"; +import "../hash_util.js"; +import "../hashchange.js"; +import "../invite.js"; +import "../message_flags.js"; +import "../starred_messages.js"; +import "../alert_words.js"; +import "../alert_words_ui.js"; +import "../attachments_ui.js"; +import "../message_store.js"; +import "../message_util.js"; +import "../message_events.js"; +import "../message_fetch.js"; +import "../server_events.js"; +import "../server_events_dispatch.js"; +import "../zulip.js"; +import "../presence.js"; +import "../user_search.js"; +import "../user_status.js"; +import "../user_status_ui.js"; +import "../buddy_data.js"; +import "../padded_widget.js"; +import "../buddy_list.js"; +import "../list_cursor.js"; +import "../activity.js"; +import "../user_events.js"; +import "../colorspace.js"; +import "../timerender.js"; +import "../tutorial.js"; +import "../hotspots.js"; +import "../templates.js"; +import "../upload_widget.js"; +import "../avatar.js"; +import "../realm_icon.js"; +import "../realm_logo.js"; +import "../reminder.js"; +import "../confirm_dialog.js"; +import "../settings_account.js"; +import "../settings_display.js"; +import "../settings_notifications.js"; +import "../settings_bots.js"; +import "../settings_muting.js"; +import "../settings_sections.js"; +import "../settings_emoji.js"; +import "../settings_org.js"; +import "../settings_users.js"; +import "../settings_streams.js"; +import "../settings_linkifiers.js"; +import "../settings_invites.js"; +import "../settings_user_groups.js"; +import "../settings_profile_fields.js"; +import "../settings.js"; +import "../admin.js"; +import "../tab_bar.js"; +import "../emoji.js"; +import "../bot_data.js"; +import "../reactions.js"; +import "../typing.js"; +import "../typing_status.js"; +import "../typing_data.js"; +import "../typing_events.js"; +import "../ui_init.js"; +import "../emoji_picker.js"; +import "../compose_ui.js"; +import "../panels.js"; +import "../settings_ui.js"; +import "../search_pill.js"; +import "../search_pill_widget.js"; +import "../stream_ui_updates.js"; // Import Styles -import "third/bootstrap-notify/css/bootstrap-notify.css"; -import "third/spectrum/spectrum.css"; +import "../../third/bootstrap-notify/css/bootstrap-notify.css"; +import "../../third/spectrum/spectrum.css"; import "katex/dist/katex.css"; import "flatpickr/dist/flatpickr.css"; import "flatpickr/dist/plugins/confirmDate/confirmDate.css"; -import "styles/components.scss"; -import "styles/app_components.scss"; -import "styles/zulip.scss"; -import "styles/alerts.scss"; -import "styles/settings.scss"; -import "styles/subscriptions.scss"; -import "styles/drafts.scss"; -import "styles/input_pill.scss"; -import "styles/informational-overlays.scss"; -import "styles/compose.scss"; -import "styles/reactions.scss"; -import "styles/user_circles.scss"; -import "styles/left-sidebar.scss"; -import "styles/right-sidebar.scss"; -import "styles/lightbox.scss"; -import "styles/popovers.scss"; -import "styles/media.scss"; -import "styles/typing_notifications.scss"; -import "styles/hotspots.scss"; -import "styles/night_mode.scss"; -import "styles/user_status.scss"; -import "styles/widgets.scss"; +import "../../styles/components.scss"; +import "../../styles/app_components.scss"; +import "../../styles/zulip.scss"; +import "../../styles/alerts.scss"; +import "../../styles/settings.scss"; +import "../../styles/subscriptions.scss"; +import "../../styles/drafts.scss"; +import "../../styles/input_pill.scss"; +import "../../styles/informational-overlays.scss"; +import "../../styles/compose.scss"; +import "../../styles/reactions.scss"; +import "../../styles/user_circles.scss"; +import "../../styles/left-sidebar.scss"; +import "../../styles/right-sidebar.scss"; +import "../../styles/lightbox.scss"; +import "../../styles/popovers.scss"; +import "../../styles/media.scss"; +import "../../styles/typing_notifications.scss"; +import "../../styles/hotspots.scss"; +import "../../styles/night_mode.scss"; +import "../../styles/user_status.scss"; +import "../../styles/widgets.scss"; diff --git a/static/js/bundles/commons.js b/static/js/bundles/commons.js index 2cffe94f1e..87b9fabbda 100644 --- a/static/js/bundles/commons.js +++ b/static/js/bundles/commons.js @@ -3,18 +3,18 @@ import "string.prototype.startswith"; import "string.prototype.codepointat"; import "jquery/dist/jquery.js"; import "underscore/underscore.js"; -import "js/blueslip.js"; -import "third/bootstrap/js/bootstrap.js"; -import "third/bootstrap-typeahead/typeahead.js"; -import "js/common.js"; +import "../blueslip.js"; +import "../../third/bootstrap/js/bootstrap.js"; +import "../../third/bootstrap-typeahead/typeahead.js"; +import "../common.js"; import "moment/min/moment.min.js"; import "moment-timezone/builds/moment-timezone-with-data.min.js"; import "sortablejs/Sortable.js"; -import "third/bootstrap/css/bootstrap.css"; -import "third/bootstrap/css/bootstrap-btn.css"; -import "third/bootstrap/css/bootstrap-responsive.css"; +import "../../third/bootstrap/css/bootstrap.css"; +import "../../third/bootstrap/css/bootstrap-btn.css"; +import "../../third/bootstrap/css/bootstrap-responsive.css"; import "simplebar/dist/simplebar.css"; import "font-awesome/css/font-awesome.css"; -import "generated/icons/style.css"; +import "../../generated/icons/style.css"; import "source-sans-pro/source-sans-pro.css"; -import "styles/pygments.scss"; +import "../../styles/pygments.scss"; diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 07f213f69b..0f514f7302 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -107,7 +107,6 @@ from tools.lib.test_script import assert_provisioning_status_ok assert_provisioning_status_ok(options.force) -os.environ['NODE_PATH'] = 'static' os.environ['TZ'] = 'UTC' INDEX_JS = 'frontend_tests/zjsunit/index.js' diff --git a/tools/webpack.config.ts b/tools/webpack.config.ts index 487623bd45..4faadb2347 100644 --- a/tools/webpack.config.ts +++ b/tools/webpack.config.ts @@ -107,11 +107,6 @@ export default (env?: string): webpack.Configuration => { filename: production ? '[name].[chunkhash].js' : '[name].js', }, resolve: { - modules: [ - resolve(__dirname, "../static"), - "node_modules", - resolve(__dirname, "../"), - ], extensions: [".ts", ".js"], }, // We prefer cheap-module-source-map over any eval-** options