Skip to content

Added stdout to output when Typescript compilation error occurs #6

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

Merged
merged 1 commit into from
Jul 7, 2015
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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v1.4.1 2015-07-06 22:36:25+0300

* Added stdout to output when Typescript compilation error occurs

## v1.1.1 2015-04-19 15:40:00+0900

* Use capture3 instead of popen3 to handle tsc I/O.
Expand Down
35 changes: 17 additions & 18 deletions lib/typescript-node.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require "tmpdir"
require "tempfile"
require "typescript-src"
require "typescript-node/version"
require "typescript-node/compile_result"
require "open3"
require 'tmpdir'
require 'tempfile'
require 'typescript-src'
require 'typescript-node/version'
require 'typescript-node/compile_result'
require 'open3'

module TypeScript
module Node
Expand All @@ -23,15 +23,15 @@ def tsc(*args)
# @return [TypeScript::Node::CompileResult] compile result
def compile_file(source_file, *tsc_options)
Dir.mktmpdir do |output_dir|
output_file = File.join(output_dir, "out.js")
output_file = File.join(output_dir, 'out.js')
stdout, stderr, exit_status = tsc(*tsc_options, '--out', output_file, source_file)

output_js = File.exists?(output_file) ? File.read(output_file) : nil
CompileResult.new(
output_js,
exit_status,
stdout,
stderr,
output_js,
exit_status,
stdout,
stderr,
)
end
end
Expand All @@ -40,15 +40,15 @@ def compile_file(source_file, *tsc_options)
# @param [String] source TypeScript to be compiled
# @return [String] Resulted JavaScript
def compile(source, *tsc_options)
js_file = Tempfile.new(["typescript-node", ".ts"])
js_file = Tempfile.new(%w(typescript-node .ts))
begin
js_file.write(source)
js_file.close
result = compile_file(js_file.path, *tsc_options)
if result.success?
result.js
else
raise result.stderr
raise result.stderr + result.stdout
end
ensure
js_file.unlink
Expand All @@ -58,11 +58,11 @@ def compile(source, *tsc_options)
# node command
# TS_NODE environmental variable is used when it is set.
def node
ENV["TS_NODE"] || "node"
ENV['TS_NODE'] || 'node'
end

def locate_executable(cmd)
if RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ && File.extname(cmd) == ""
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ && File.extname(cmd) == ""
cmd << ".exe"
end

Expand All @@ -79,12 +79,11 @@ def locate_executable(cmd)

def check_node
unless locate_executable(node)
raise "typescript-node requires node command, but it's not found. Please install it. " +
"Set TS_NODE environmental variable If you want to use node command in non-standard path."
raise "typescript-node requires node command, but it's not found. Please install it. Set TS_NODE environmental variable If you want to use node command in non-standard path."
end
end
end
end
end

TypeScript::Node.check_node
TypeScript::Node.check_node
2 changes: 1 addition & 1 deletion lib/typescript-node/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module TypeScript
module Node
VERSION = '1.1.1'
VERSION = '1.4.1'
end
end
3 changes: 1 addition & 2 deletions test/test_typescript-node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def test_compile_file_in_failure

assert { subject.exit_status != 0 }
assert { !subject.success? }
assert { subject.stdout == '' }
assert { subject.stderr != '' }
assert { subject.stdout != '' || subject.stderr != '' }
end

def test_compile_file_with_es5
Expand Down
12 changes: 6 additions & 6 deletions typescript-node.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
require File.expand_path('../lib/typescript-node/version', __FILE__)

Gem::Specification.new do |gem|
gem.name = "typescript-node"
gem.name = 'typescript-node'

gem.authors = ["KAWACHI Takashi"]
gem.email = ["[email protected]"]
gem.authors = ['KAWACHI Takashi']
gem.email = ['[email protected]']
gem.description = %q{TypeScript ruby interface using Node.js}
gem.summary = gem.description
gem.homepage = "https://github.com/typescript-ruby/typescript-node-ruby"
gem.homepage = 'https://github.com/typescript-ruby/typescript-node-ruby'

gem.files = `git ls-files`.split($\)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
gem.version = TypeScript::Node::VERSION

gem.add_dependency 'typescript-src', '~> 1.0.1'
gem.add_dependency 'typescript-src', '~> 1.4.1'
gem.add_development_dependency 'rake'

gem.required_ruby_version = ">= 1.9.3"
gem.required_ruby_version = '>= 1.9.3'
end