55311b1596
Action Cable's JavaScript library can optionally be imported as an ES6 module via `import { … } from "@rails/actioncable/src"`, but that module is broken in most of the releases published on npm: ``` ERROR in ./node_modules/@rails/actioncable/src/connection.js Module not found: Error: Can't resolve './internal' in './node_modules/@rails/actioncable/src' @ ./node_modules/@rails/actioncable/src/connection.js @ ./node_modules/@rails/actioncable/src/index.js ``` Because `internal.js` was gitignored, it would only be included if the publisher happened to have it generated locally. Committing it to version control ensures that won't happen, and gives us better visibility into changes over time. References: - https://github.com/rails/rails/pull/34370 - c0368ad090b79c19300a4aa133bb188b2d9ab611
45 lines
1.0 KiB
Ruby
45 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "base64"
|
|
require "rake/testtask"
|
|
require "pathname"
|
|
require "open3"
|
|
require "action_cable"
|
|
|
|
task default: :test
|
|
|
|
task :package
|
|
|
|
Rake::TestTask.new do |t|
|
|
t.libs << "test"
|
|
t.test_files = Dir.glob("#{__dir__}/test/**/*_test.rb")
|
|
t.warning = true
|
|
t.verbose = true
|
|
t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
|
|
end
|
|
|
|
namespace :test do
|
|
task :isolated do
|
|
Dir.glob("test/**/*_test.rb").all? do |file|
|
|
sh(Gem.ruby, "-w", "-Ilib:test", file)
|
|
end || raise("Failures")
|
|
end
|
|
|
|
task :integration do
|
|
system(Hash[*Base64.decode64(ENV.fetch("ENCODED", "")).split(/[ =]/)], "yarn", "test")
|
|
exit($?.exitstatus) unless $?.success?
|
|
end
|
|
end
|
|
|
|
namespace :assets do
|
|
desc "Generate ActionCable::INTERNAL JS module"
|
|
task :codegen do
|
|
require "json"
|
|
require "action_cable"
|
|
|
|
File.open(File.join(__dir__, "app/javascript/action_cable/internal.js").to_s, "w+") do |file|
|
|
file.write("export default #{JSON.pretty_generate(ActionCable::INTERNAL)}\n")
|
|
end
|
|
end
|
|
end
|