Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#184611345] Chore / Support for rails 6.1 #1

Merged
merged 9 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ source 'https://rubygems.org'
gemspec

group :test do
gem 'rails', '~> 4.0'
gem 'rails', '>= 4.0'
gem 'sprockets', '~> 3'
gem 'sprockets-rails', '> 2.0'
gem 'minitest-power_assert'
gem 'coveralls'
Expand Down
216 changes: 216 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
PATH
remote: .
specs:
typescript-rails (0.6.2.4)
railties
tilt
typescript-node (>= 1.6.2)

GEM
remote: https://rubygems.org/
specs:
actioncable (7.0.4.3)
actionpack (= 7.0.4.3)
activesupport (= 7.0.4.3)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.4.3)
actionpack (= 7.0.4.3)
activejob (= 7.0.4.3)
activerecord (= 7.0.4.3)
activestorage (= 7.0.4.3)
activesupport (= 7.0.4.3)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.4.3)
actionpack (= 7.0.4.3)
actionview (= 7.0.4.3)
activejob (= 7.0.4.3)
activesupport (= 7.0.4.3)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.4.3)
actionview (= 7.0.4.3)
activesupport (= 7.0.4.3)
rack (~> 2.0, >= 2.2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.4.3)
actionpack (= 7.0.4.3)
activerecord (= 7.0.4.3)
activestorage (= 7.0.4.3)
activesupport (= 7.0.4.3)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.4.3)
activesupport (= 7.0.4.3)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.4.3)
activesupport (= 7.0.4.3)
globalid (>= 0.3.6)
activemodel (7.0.4.3)
activesupport (= 7.0.4.3)
activerecord (7.0.4.3)
activemodel (= 7.0.4.3)
activesupport (= 7.0.4.3)
activestorage (7.0.4.3)
actionpack (= 7.0.4.3)
activejob (= 7.0.4.3)
activerecord (= 7.0.4.3)
activesupport (= 7.0.4.3)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.4.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
builder (3.2.4)
concurrent-ruby (1.2.2)
coveralls (0.7.1)
multi_json (~> 1.3)
rest-client
simplecov (>= 0.7)
term-ansicolor
thor
crass (1.0.6)
date (3.3.3)
docile (1.4.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
erubi (1.12.0)
globalid (1.1.0)
activesupport (>= 5.0)
http-accept (1.7.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
loofah (2.20.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
marcel (1.0.2)
method_source (1.0.0)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2023.0218.1)
mini_mime (1.1.2)
minitest (5.18.0)
minitest-power_assert (0.3.1)
minitest
power_assert (>= 1.1)
multi_json (1.15.0)
net-imap (0.3.4)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
timeout
net-smtp (0.3.3)
net-protocol
netrc (0.11.0)
nio4r (2.5.9)
nokogiri (1.14.2-x86_64-darwin)
racc (~> 1.4)
power_assert (2.0.3)
racc (1.6.2)
rack (2.2.6.4)
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.4.3)
actioncable (= 7.0.4.3)
actionmailbox (= 7.0.4.3)
actionmailer (= 7.0.4.3)
actionpack (= 7.0.4.3)
actiontext (= 7.0.4.3)
actionview (= 7.0.4.3)
activejob (= 7.0.4.3)
activemodel (= 7.0.4.3)
activerecord (= 7.0.4.3)
activestorage (= 7.0.4.3)
activesupport (= 7.0.4.3)
bundler (>= 1.15.0)
railties (= 7.0.4.3)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.5.0)
loofah (~> 2.19, >= 2.19.1)
railties (7.0.4.3)
actionpack (= 7.0.4.3)
activesupport (= 7.0.4.3)
method_source
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rake (13.0.6)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sync (0.5.0)
term-ansicolor (1.7.1)
tins (~> 1.0)
thor (1.2.1)
tilt (2.1.0)
timeout (0.3.2)
tins (1.32.1)
sync
typescript-node (1.6.2)
typescript-src (~> 1.6.2)
typescript-src (1.6.2.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.7)

PLATFORMS
x86_64-darwin-21
x86_64-darwin-22

DEPENDENCIES
coveralls
minitest-power_assert
rails (>= 4.0)
simplecov
sprockets (~> 3)
sprockets-rails (> 2.0)
typescript-rails!
tzinfo-data

BUNDLED WITH
2.4.10
3 changes: 3 additions & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
10 changes: 5 additions & 5 deletions lib/typescript/rails/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
require 'typescript-node'

module Typescript::Rails::Compiler
class << self
# @!scope class
cattr_accessor :default_options
# @!scope class
self.cattr_accessor(:default_options)

class << self
# Replace relative paths specified in /// <reference path="..." /> with absolute paths.
#
# @param [String] ts_path Source .ts path
Expand All @@ -18,7 +18,7 @@ def replace_relative_references(ts_path, source)
# Why don't we just use gsub? Because it display odd behavior with File.join on Ruby 2.0
# So we go the long way around.
(source.each_line.map do |l|
if l.starts_with?('///') && !(m = %r!^///\s*<reference\s+path=(?:"([^"]+)"|'([^']+)')\s*/>\s*!.match(l)).nil?
if l.start_with?('///') && !(m = %r!^///\s*<reference\s+path=(?:"([^"]+)"|'([^']+)')\s*/>\s*!.match(l)).nil?
matched_path = m.captures.compact[0]
l = l.sub(matched_path, File.join(escaped_dir, matched_path))
end
Expand All @@ -35,7 +35,7 @@ def get_all_reference_paths(path, source, visited_paths=Set.new, &block)
visited_paths << path
source ||= File.read(path)
source.each_line do |l|
if l.starts_with?('///') && !(m = %r!^///\s*<reference\s+path=(?:"([^"]+)"|'([^']+)')\s*/>\s*!.match(l)).nil?
if l.start_with?('///') && !(m = %r!^///\s*<reference\s+path=(?:"([^"]+)"|'([^']+)')\s*/>\s*!.match(l)).nil?
matched_path = m.captures.compact[0]
abs_matched_path = File.expand_path(matched_path, File.dirname(path))
unless visited_paths.include? abs_matched_path
Expand Down
11 changes: 6 additions & 5 deletions test/assets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ def assets
@app.assets
end

test 'typescript.js is included in Sprockets environment' do
assert { assets["typescript"].filename.to_s.end_with?('/lib/assets/javascripts/typescript.js.erb') }
assert { assets["typescript"].source.include?('var ts;') }
end
# Run all tests in one block to avoid error from calling @app.initialize! multiple times
test 'generates assets successfully' do
# typescript.js is included in Sprockets environment
assert { assets['typescript'].filename.to_s.end_with?('/lib/assets/javascripts/typescript.js.erb') }
assert { assets['typescript'].source.include?('var ts;') }

test 'assets .js.ts is compiled from TypeScript to JavaScript' do
# 'assets .js.ts is compiled from TypeScript to JavaScript'
assert { assets['javascripts/hello.js'].present? }
assert { assets['javascripts/hello.js'].source.include?('var log_to_console = function (x) {') }
assert { assets['javascripts/hello.js'].source.include?('var s = "Hello, world!";') }
Expand Down
8 changes: 4 additions & 4 deletions test/template_handler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ def source

test 'typescript views are served as javascript' do
get '/site/index.js'
assert_match /var x = 5;\s*/,
assert_match (/var x = 5;\s*/),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What effect do the brackets have? I didn't see any difference after removing them when running tests.

Copy link
Collaborator Author

@masonlouchart masonlouchart Apr 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It removes warnings.

❯ bundle exec rake test --trace             
** Invoke test (first_time)
** Execute test
/Users/mason/workspace/NEWROPE/typescript-rails/test/template_handler_test.rb:34: warning: ambiguous first argument; put parentheses or a space even after `/' operator
/Users/mason/workspace/NEWROPE/typescript-rails/test/template_handler_test.rb:40: warning: ambiguous first argument; put parentheses or a space even after `/' operator
/Users/mason/workspace/NEWROPE/typescript-rails/test/template_handler_test.rb:46: warning: ambiguous first argument; put parentheses or a space even after `/' operator
/Users/mason/workspace/NEWROPE/typescript-rails/test/template_handler_test.rb:52: warning: ambiguous first argument; put parentheses or a space even after `/' operator
Run options: --seed 34434

source
end

test '<reference> to other .ts file works' do
get '/site/ref1_2.js'
assert_match /var f = function \(x, y\) \{\s*return x \+ y;\s*\};\s*f\(1, 2\);\s*/,
assert_match (/var f = function \(x, y\) \{\s*return x \+ y;\s*\};\s*f\(1, 2\);\s*/),
source
end

test '<reference> to other .d.ts file works' do
get '/site/ref2_2.js'
assert_match /f\(1, 2\);\s*/,
assert_match (/f\(1, 2\);\s*/),
source
end

test '<reference> to multiple .ts files works' do
get '/site/ref3_1.js'
assert_match /var f1 = function \(\) \{\s*\};\s*var f2 = function \(\) \{\s*\};\s*f1\(\);\s*f2\(\);/,
assert_match (/var f1 = function \(\) \{\s*\};\s*var f2 = function \(\) \{\s*\};\s*f1\(\);\s*f2\(\);/),
source
end

Expand Down
6 changes: 3 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
require 'coveralls'
require 'simplecov'

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
])
SimpleCov.start do
add_filter '.bundle/'
end
Expand All @@ -27,4 +27,4 @@ def copy_routes

FileUtils.mkdir_p(destination)
FileUtils.cp routes, destination
end
end