Restore action_cable.js UMD module support. Fixes #28366

This commit is contained in:
Javan Makhmali 2017-03-11 12:33:11 -05:00
parent 158a01e73f
commit 2d2b3025ec
3 changed files with 38 additions and 1 deletions

View File

@ -84,6 +84,7 @@ group :cable do
gem "blade", require: false, platforms: [:ruby]
gem "blade-sauce_labs_plugin", require: false, platforms: [:ruby]
gem "sprockets-export", require: false
end
# Add your own local bundler stuff.

View File

@ -319,6 +319,7 @@ GEM
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-export (0.9.1)
sprockets-rails (3.2.0)
actionpack (>= 4.0)
activesupport (>= 4.0)
@ -414,6 +415,7 @@ DEPENDENCIES
sequel
sidekiq
sneakers
sprockets-export
sqlite3 (~> 1.3.6)
stackprof
sucker_punch

View File

@ -1,12 +1,13 @@
require "rake/testtask"
require "pathname"
require "open3"
require "action_cable"
dir = File.dirname(__FILE__)
task default: :test
task package: "assets:compile"
task package: %w( assets:compile assets:verify )
Rake::TestTask.new do |t|
t.libs << "test"
@ -37,6 +38,39 @@ namespace :assets do
desc "Compile Action Cable assets"
task :compile do
require "blade"
require "sprockets"
require "sprockets/export"
Blade.build
end
desc "Verify compiled Action Cable assets"
task :verify do
file = "lib/assets/compiled/action_cable.js"
pathname = Pathname.new("#{dir}/#{file}")
print "[verify] #{file} exists "
if pathname.exist?
puts "[OK]"
else
$stderr.puts "[FAIL]"
fail
end
print "[verify] #{file} is a UMD module "
if pathname.read =~ /module\.exports.*define\.amd/m
puts "[OK]"
else
$stderr.puts "[FAIL]"
fail
end
print "[verify] #{dir} can be required as a module "
stdout, stderr, status = Open3.capture3("node", "--print", "window = {}; require('#{dir}');")
if status.success?
puts "[OK]"
else
$stderr.puts "[FAIL]\n#{stderr}"
fail
end
end
end