Skip to content

Commit caeda4c

Browse files
authored
Merge pull request #217 from znz/run-js-mime-type
Rename js/run.mjs to js/run.js to survive strict MIME checking
2 parents 872ccb6 + 052eeb1 commit caeda4c

8 files changed

Lines changed: 22 additions & 19 deletions

File tree

data/bitclust/template.offline/layout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<script src="<%=h custom_js_url('js/search_init.js') %>"></script>
2424
<% if run_ruby_wasm_url %>
2525
<meta name="rurema-run-ruby-wasm" content="<%=h run_ruby_wasm_url %>">
26-
<script type="module" src="<%=h custom_js_url('js/run.mjs') %>"></script>
26+
<script type="module" src="<%=h custom_js_url('js/run.js') %>"></script>
2727
<% end %>
2828
</head>
2929
<body>

data/bitclust/template/layout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<link rel="search" type="application/opensearchdescription+xml" title="<%= _('Ruby %s Reference Manual', ruby_version()) %>" href="<%=h opensearchdescription_url() %>">
1414
<% if run_ruby_wasm_url %>
1515
<meta name="rurema-run-ruby-wasm" content="<%=h run_ruby_wasm_url %>">
16-
<script type="module" src="<%=h custom_js_url('js/run.mjs') %>"></script>
16+
<script type="module" src="<%=h custom_js_url('js/run.js') %>"></script>
1717
<% end %>
1818
</head>
1919
<body>

lib/bitclust/subcommands/statichtml_command.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,17 +328,17 @@ def create_search_index(outputdir, db, fdb)
328328
end
329329

330330
# Copy the RUN-button script (statichtml --run-ruby-wasm). A themedir
331-
# without js/run.mjs is tolerated: warn and skip instead of aborting the
331+
# without js/run.js is tolerated: warn and skip instead of aborting the
332332
# whole build.
333333
def copy_run_ruby_wasm_script
334-
run_mjs = @manager_config[:themedir] + "js" + "run.mjs"
335-
unless run_mjs.file?
336-
$stderr.puts "warning: #{run_mjs} not found; RUN button script not copied"
334+
run_js = @manager_config[:themedir] + "js" + "run.js"
335+
unless run_js.file?
336+
$stderr.puts "warning: #{run_js} not found; RUN button script not copied"
337337
return
338338
end
339339
jsdir = @outputdir + "js"
340340
FileUtils.mkdir_p(jsdir) unless jsdir.directory?
341-
FileUtils.cp(run_mjs.to_s, jsdir.to_s, :verbose => @verbose, :preserve => true)
341+
FileUtils.cp(run_js.to_s, jsdir.to_s, :verbose => @verbose, :preserve => true)
342342
end
343343

344344
def create_html_file(entry, manager, outputdir, db)

test/js/test_run.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// QuickJS-based tests for the pure logic in theme/default/js/run.mjs.
1+
// QuickJS-based tests for the pure logic in theme/default/js/run.js.
22
// Run with: qjs test/js/test_run.mjs (see the "test:js" rake task)
33
// Importing the module doubles as a syntax/eval smoke test: its DOM setup is
44
// guarded by `typeof window !== 'undefined'`.
5-
import { createOnceLoader, PRELUDE, formatRunError, truncateOutput } from '../../theme/default/js/run.mjs'
5+
import { createOnceLoader, PRELUDE, formatRunError, truncateOutput } from '../../theme/default/js/run.js'
66

77
let failures = 0
88
function assert(cond, message) {

test/test_run_ruby_wasm.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ def render(manager_options)
3232
def test_run_script_is_loaded_when_enabled
3333
html = render(:run_ruby_wasm => WASM_URL)
3434
assert_include(html, META_TAG)
35-
assert_include(html, 'js/run.mjs')
35+
assert_include(html, 'js/run.js')
3636
end
3737

3838
def test_run_script_is_not_loaded_by_default
3939
html = render({})
4040
assert_not_include(html, 'rurema-run-ruby-wasm')
41-
assert_not_include(html, 'run.mjs')
41+
assert_not_include(html, 'run.js')
4242
end
4343

4444
def test_wasm_url_is_html_escaped

test/test_statichtml_command.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ def test_option_is_parsed
5050
assert_equal(url, cmd.instance_variable_get(:@run_ruby_wasm))
5151
end
5252

53-
def test_run_mjs_is_copied
53+
def test_run_js_is_copied
5454
Dir.mktmpdir do |dir|
5555
themedir = File.join(dir, 'theme')
5656
outputdir = File.join(dir, 'out')
5757
FileUtils.mkdir_p(File.join(themedir, 'js'))
5858
FileUtils.mkdir_p(outputdir)
59-
File.write(File.join(themedir, 'js', 'run.mjs'), "// run\n")
59+
File.write(File.join(themedir, 'js', 'run.js'), "// run\n")
6060
cmd = build_command(themedir, outputdir)
6161
cmd.send(:copy_run_ruby_wasm_script)
62-
assert_true(File.file?(File.join(outputdir, 'js', 'run.mjs')))
62+
assert_true(File.file?(File.join(outputdir, 'js', 'run.js')))
6363
end
6464
end
6565

66-
def test_theme_without_run_mjs_is_tolerated
66+
def test_theme_without_run_js_is_tolerated
6767
Dir.mktmpdir do |dir|
6868
themedir = File.join(dir, 'theme')
6969
outputdir = File.join(dir, 'out')
@@ -73,11 +73,11 @@ def test_theme_without_run_mjs_is_tolerated
7373
orig_stderr, $stderr = $stderr, StringIO.new
7474
begin
7575
assert_nothing_raised { cmd.send(:copy_run_ruby_wasm_script) }
76-
assert_match(/run\.mjs not found/, $stderr.string)
76+
assert_match(/run\.js not found/, $stderr.string)
7777
ensure
7878
$stderr = orig_stderr
7979
end
80-
assert_false(File.exist?(File.join(outputdir, 'js', 'run.mjs')))
80+
assert_false(File.exist?(File.join(outputdir, 'js', 'run.js')))
8181
end
8282
end
8383
end
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// RUN button for Ruby sample code: executes the sample in-browser with
2-
// ruby.wasm. Enabled per page via
2+
// ruby.wasm. Named .js rather than .mjs: module scripts are subject to
3+
// strict MIME checking, and servers whose MIME table lacks an "mjs" entry
4+
// (e.g. nginx before 1.21.4) serve .mjs as application/octet-stream, which
5+
// browsers refuse to execute. Enabled per page via
36
// <meta name="rurema-run-ruby-wasm" content="<ruby+stdlib.wasm URL>">
47
// which the layout emits when statichtml was invoked with --run-ruby-wasm.
58
// The wasm URL is chosen by the build side to match the documented Ruby

theme/default/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pre.highlight {
142142
position: relative;
143143
}
144144

145-
/* for RUN (js/run.mjs, statichtml --run-ruby-wasm) */
145+
/* for RUN (js/run.js, statichtml --run-ruby-wasm) */
146146
.highlight__run-button {
147147
float: right;
148148
margin: 0 0 0.25em 0.5em;

0 commit comments

Comments
 (0)