Commit 9c6d94ad by Brian Jacobel

Require and Webpack can eat the same files

parent 480a3ca6
......@@ -8,7 +8,7 @@
'underscore.string',
'backbone',
'gettext',
'../../../../common/static/common/js/components/views/feedback_notification',
'../../common/js/components/views/feedback_notification',
'jquery.cookie'
], function(domReady, $, str, Backbone, gettext, NotificationView) {
var main, sendJSON;
......
......@@ -116,7 +116,7 @@ define([
Import.reset();
onComplete();
alert(gettext('Your import has failed.') + '\n\n' + errMsg);
alert(gettext('Your import has failed.') + '\n\n' + errMsg); // eslint-disable-line max-len, no-alert
}
}
});
......
define(['jquery', 'underscore', 'underscore.string', '../../../../common/js/components/views/feedback'],
function($, _, str, SystemFeedbackView) {
var Notification = SystemFeedbackView.extend({
options: $.extend({}, SystemFeedbackView.prototype.options, {
type: 'notification',
closeIcon: false
})
});
// create Notification.Warning, Notification.Confirmation, etc
var capitalCamel, intents;
capitalCamel = _.compose(str.capitalize, str.camelize);
intents = ['warning', 'error', 'confirmation', 'announcement', 'step-required', 'help', 'mini'];
_.each(intents, function(intent) {
var subclass;
subclass = Notification.extend({
options: $.extend({}, Notification.prototype.options, {
intent: intent
(function(define) {
'use strict';
define(['jquery', 'underscore', 'underscore.string', './feedback'],
function($, _, str, SystemFeedbackView) {
var Notification = SystemFeedbackView.extend({
options: $.extend({}, SystemFeedbackView.prototype.options, {
type: 'notification',
closeIcon: false
})
});
Notification[capitalCamel(intent)] = subclass;
});
// set more sensible defaults for Notification.Mini views
var miniOptions = Notification.Mini.prototype.options;
miniOptions.minShown = 1250;
miniOptions.closeIcon = false;
// create Notification.Warning, Notification.Confirmation, etc
var capitalCamel, intents, miniOptions;
capitalCamel = _.compose(str.capitalize, str.camelize);
intents = ['warning', 'error', 'confirmation', 'announcement', 'step-required', 'help', 'mini'];
_.each(intents, function(intent) {
var subclass;
subclass = Notification.extend({
options: $.extend({}, Notification.prototype.options, {
intent: intent
})
});
Notification[capitalCamel(intent)] = subclass;
});
// set more sensible defaults for Notification.Mini views
miniOptions = Notification.Mini.prototype.options;
miniOptions.minShown = 1250;
miniOptions.closeIcon = false;
return Notification;
});
return Notification;
}
);
}).call(this, define || RequireJS.define);
......@@ -253,17 +253,6 @@ class ImportMixin(ImportExportMixin):
"""
return self.q(css='.choose-file-button').present
def is_click_handler_registered(self):
"""
Check if the click handler for the file selector button has been registered yet
"""
script = """
var $ = require('jquery'),
buttonEvents = $._data($('a.choose-file-button')[0], 'events');
return buttonEvents && buttonEvents.hasOwnProperty('click');"""
stripped_script = ''.join([line.strip() for line in script.split('\n')])
return self.browser.execute_script(stripped_script)
@staticmethod
def file_path(filename):
"""
......@@ -325,13 +314,6 @@ class ImportMixin(ImportExportMixin):
"""
return self.q(css='#fileupload .error-block').visible
def wait_for_choose_file_click_handler(self):
"""
Wait for the choose file button click handler to be registered
"""
EmptyPromise(self.is_click_handler_registered, 'Choose File Button Click Handler Registered',
timeout=30).fulfill()
def wait_for_filename_error(self):
"""
Wait for the upload field to display an error.
......
......@@ -168,7 +168,6 @@ class ImportTestMixin(object):
I can select the file and upload it
And the page will give me confirmation that it uploaded successfully
"""
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload()
......@@ -184,7 +183,6 @@ class ImportTestMixin(object):
# import_page timestamp is in (MM/DD/YYYY at HH:mm) so replacing (second, microsecond) to
# keep the comparison consistent
upload_start_time = datetime.utcnow().replace(microsecond=0, second=0)
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload()
......@@ -218,7 +216,6 @@ class ImportTestMixin(object):
Given that I upload a library or course
A button will appear that contains the URL to the library or course's main page
"""
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name)
self.assertEqual(self.import_page.finished_target_url(), self.landing_page.url)
......@@ -228,7 +225,6 @@ class ImportTestMixin(object):
Given that I select a file that is an .mp4 for upload
An error message will appear
"""
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball('funny_cat_video.mp4')
self.import_page.wait_for_filename_error()
......@@ -244,7 +240,6 @@ class ImportTestMixin(object):
# The task list shouldn't be visible to start.
self.assertFalse(self.import_page.is_task_list_showing(), "Task list shown too early.")
self.import_page.wait_for_tasks()
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_tasks(completed=True)
self.assertTrue(self.import_page.is_task_list_showing(), "Task list did not display.")
......@@ -258,7 +253,6 @@ class ImportTestMixin(object):
And the 'Updating' task should be marked failed
And the remaining tasks should not be marked as started
"""
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.bad_tarball_name)
self.import_page.wait_for_tasks(fail_on='Updating')
......@@ -296,7 +290,6 @@ class TestEntranceExamCourseImport(ImportTestMixin, StudioCourseTest):
self.assertRaises(IndexError, self.landing_page.section, "Section")
self.assertRaises(IndexError, self.landing_page.section, "Entrance Exam")
self.import_page.visit()
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload()
self.landing_page.visit()
......@@ -346,7 +339,6 @@ class TestCourseImport(ImportTestMixin, StudioCourseTest):
# Should not exist yet.
self.assertRaises(IndexError, self.landing_page.section, "Section")
self.import_page.visit()
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload()
self.landing_page.visit()
......@@ -373,7 +365,6 @@ class TestCourseImport(ImportTestMixin, StudioCourseTest):
Then timestamp is not visible
"""
self.import_page.visit()
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload()
self.assertTrue(self.import_page.is_timestamp_visible())
......@@ -419,7 +410,6 @@ class TestLibraryImport(ImportTestMixin, StudioLibraryTest):
# No items should be in the library to start.
self.assertEqual(len(self.landing_page.xblocks), 0)
self.import_page.visit()
self.import_page.wait_for_choose_file_click_handler()
self.import_page.upload_tarball(self.tarball_name)
self.import_page.wait_for_upload()
self.landing_page.visit()
......
......@@ -22,6 +22,7 @@
"picturefill": "~3.0.2",
"raw-loader": "^0.5.1",
"requirejs": "~2.3.2",
"string-replace-webpack-plugin": "^0.1.3",
"uglify-js": "2.7.0",
"underscore": "~1.8.3",
"underscore.string": "~3.3.4",
......@@ -32,6 +33,7 @@
"edx-custom-a11y-rules": "0.1.3",
"eslint-config-edx": "^2.0.1",
"eslint-config-edx-es5": "^2.0.0",
"eslint-import-resolver-webpack": "^0.8.1",
"jasmine-core": "^2.4.1",
"jasmine-jquery": "^2.1.1",
"karma": "^0.13.22",
......
......@@ -708,11 +708,11 @@ def execute_webpack(prod, settings=None):
sh(
cmd(
"NODE_ENV={node_env} STATIC_ROOT_LMS={static_root_lms} STATIC_ROOT_CMS={static_root_cms} $(npm bin)/webpack"
.format(
node_env="production" if prod else "development",
static_root_lms=Env.get_django_setting("STATIC_ROOT", "lms", settings=settings),
static_root_cms=Env.get_django_setting("STATIC_ROOT", "cms", settings=settings)
)
.format(
node_env="production" if prod else "development",
static_root_lms=Env.get_django_setting("STATIC_ROOT", "lms", settings=settings),
static_root_cms=Env.get_django_setting("STATIC_ROOT", "cms", settings=settings)
)
)
)
......@@ -720,10 +720,10 @@ def execute_webpack(prod, settings=None):
def execute_webpack_watch(settings=None):
run_background_process(
"STATIC_ROOT_LMS={static_root_lms} STATIC_ROOT_CMS={static_root_cms} $(npm bin)/webpack --watch --watch-poll=200"
.format(
static_root_lms=Env.get_django_setting("STATIC_ROOT", "lms", settings=settings),
static_root_cms=Env.get_django_setting("STATIC_ROOT", "cms", settings=settings)
)
.format(
static_root_lms=Env.get_django_setting("STATIC_ROOT", "lms", settings=settings),
static_root_cms=Env.get_django_setting("STATIC_ROOT", "cms", settings=settings)
)
)
......
......@@ -2378,6 +2378,8 @@ class MakoTemplateLinter(BaseLinter):
</script> | # script tag end
<%static:require_module(_async)?.*?> | # require js script tag start (optionally the _async version)
</%static:require_module(_async)?> | # require js script tag end (optionally the _async version)
<%static:webpack.*?> | # webpack script tag start
</%static:webpack> | # webpack script tag end
<%block[ ]*name=['"]requirejs['"]\w*> | # require js tag start
</%block> # require js tag end
""",
......
......@@ -5,9 +5,15 @@
var path = require('path');
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');
var StringReplace = require('string-replace-webpack-plugin');
var isProd = process.env.NODE_ENV === 'production';
var namespacedRequireFiles = [
path.resolve(__dirname, 'common/static/common/js/components/views/feedback_notification.js'),
path.resolve(__dirname, 'common/static/common/js/components/views/feedback.js')
];
var wpconfig = {
context: __dirname,
......@@ -52,8 +58,29 @@ var wpconfig = {
module: {
rules: [
{
test: namespacedRequireFiles,
loader: StringReplace.replace(
['babel-loader'],
{
replacements: [
{
pattern: /\(function ?\(define\) ?\{/,
replacement: function() { return ''; }
},
{
pattern: /\}\)\.call\(this, define \|\| RequireJS\.define\);/,
replacement: function() { return ''; }
}
]
}
)
},
{
test: /\.js$/,
exclude: /node_modules/,
exclude: [
/node_modules/,
namespacedRequireFiles
],
use: 'babel-loader'
},
{
......@@ -72,7 +99,8 @@ var wpconfig = {
use: {
loader: 'imports-loader',
options: {
AjaxPrefix: 'exports-loader?this.AjaxPrefix!../../../../common/static/coffee/src/ajax_prefix.coffee'
AjaxPrefix:
'exports-loader?this.AjaxPrefix!../../../../common/static/coffee/src/ajax_prefix.coffee'
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment