File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
actioncable/lib/rails/generators/channel Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -59,17 +59,17 @@ def create_shared_channel_javascript_files
59
59
def create_channel_javascript_file
60
60
channel_js_path = File . join ( "app/javascript/channels" , class_path , "#{ file_name } _channel" )
61
61
js_template "javascript/channel" , channel_js_path
62
- gsub_file "#{ channel_js_path } .js" , /\. \/ consumer/ , "channels/consumer" unless using_js_runtime ?
62
+ gsub_file "#{ channel_js_path } .js" , /\. \/ consumer/ , "channels/consumer" if using_importmap ?
63
63
end
64
64
65
65
def import_channels_in_javascript_entrypoint
66
66
append_to_file "app/javascript/application.js" ,
67
- using_js_runtime ? ? %(import "./ channels"\n ) : %(import "channels"\n )
67
+ using_importmap ? ? %(import "channels"\n ) : %(import "./ channels"\n )
68
68
end
69
69
70
70
def import_channel_in_javascript_entrypoint
71
71
append_to_file "app/javascript/channels/index.js" ,
72
- using_js_runtime ? ? %(import ". /#{ file_name } _channel"\n ) : %(import "channels /#{ file_name } _channel"\n )
72
+ using_importmap ? ? %(import "channels /#{ file_name } _channel"\n ) : %(import ". /#{ file_name } _channel"\n )
73
73
end
74
74
75
75
def install_javascript_dependencies
Original file line number Diff line number Diff line change @@ -78,6 +78,16 @@ class ChannelGeneratorTest < Rails::Generators::TestCase
78
78
end
79
79
end
80
80
81
+ test "import channels in javascript entrypoint when using a css processor" do
82
+ FileUtils . touch ( "#{ destination_root } /package.json" )
83
+
84
+ run_generator [ "books" ]
85
+
86
+ assert_file "app/javascript/application.js" do |entrypoint |
87
+ assert_match %r|import "channels"| , entrypoint
88
+ end
89
+ end
90
+
81
91
test "import channels in javascript entrypoint under node" do
82
92
use_under_node
83
93
generator ( [ "chat" ] ) . stub ( :install_javascript_dependencies , true ) do
You can’t perform that action at this time.
0 commit comments