From 1e0710558800f14e1065545fdecc879191c465a9 Mon Sep 17 00:00:00 2001 From: kares Date: Tue, 24 Apr 2012 18:50:59 +0200 Subject: [PATCH 01/12] run specs with jruby --1.9 as well + fail on runtime require early on --- .travis.yml | 3 ++- spec/spec_helper.rb | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2535233..3c0c43c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,8 @@ rvm: - 1.9.3 - 1.9.2 - 1.8.7 - - jruby-1.6.7 + - jruby-18mode + - jruby-19mode notifications: recipients: - cowboyd@thefrontside.net diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9adb2f0..d73afc1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,10 +6,14 @@ def env_with_path_value(path) CommonJS::Environment.new new_runtime, :path => path end -def new_runtime - require 'v8' - V8::Context.new -rescue LoadError +if defined?(JRUBY_VERSION) require 'rhino' - Rhino::Context.new -end + def new_runtime + Rhino::Context.new + end +else + require 'v8' + def new_runtime + V8::Context.new + end +end \ No newline at end of file From 158c7d3d632e3488e9f79ffd4f45b17c24d4aa36 Mon Sep 17 00:00:00 2001 From: kares Date: Tue, 24 Apr 2012 18:52:40 +0200 Subject: [PATCH 02/12] update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 02e14fa..60abbfc 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,9 @@ access to the process information, you would say: ### Current * The Ruby Racer (V8) - [https://github.com/cowboyd/therubyracer] +* The Ruby Rhino (JRuby) - [https://github.com/cowboyd/therubyrhino] ### Desired -* The Ruby Rhino (JRuby) - [https://github.com/cowboyd/therubyrhino] * Johnson (TraceMonkey) - [https://github.com/jbarnette/johnson] * Lyndon (MacRuby) - [https://github.com/defunkt/lyndon] From c0901d70a2c73d9e9b0e54343001e310ba247f67 Mon Sep 17 00:00:00 2001 From: Akzhan Abdulin Date: Tue, 15 May 2012 23:44:48 +0400 Subject: [PATCH 03/12] Update README.md --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 60abbfc..3616b0b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ - # CommonJS [![Build Status](https://secure.travis-ci.org/cowboyd/commonjs.rb.png)](http://travis-ci.org/cowboyd/commonjs.rb) Host CommonJS JavaScript environments in Ruby @@ -14,12 +13,12 @@ able to use commonjs applications and libraries? ## Using common JS from Ruby. -`CommonJS` now passes all of the Modules 1.0 unit tests - - env = CommonJS::Environment.new(:path => '/path/to/lib/dir') - env.require('foo.js') - +`CommonJS` now passes all of the Modules 1.0 unit tests. +```ruby +env = CommonJS::Environment.new(:path => '/path/to/lib/dir') +env.require('foo.js') +``` ## Future directions @@ -29,7 +28,9 @@ The plan however, is to allow you to extend your commonjs environment to have wh interfaces you want in it. So for example, if you want to allow filesystem access, as well as access to the process information, you would say: - env.modules :filesystem, :process +```ruby +env.modules :filesystem, :process +``` ## Supported runtimes From 5ec967809604e76b7464cac9718da0be0a09b058 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Thu, 24 May 2012 12:51:09 -0500 Subject: [PATCH 04/12] add commonjs.rb license from The MIT OSI template: http://www.opensource.org/licenses/MIT --- LICENSE.txt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..74457f1 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,7 @@ +Copyright (c) 2011,2012 Charles Lowell + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. From 91c0b06a987082f60a77842e890877d2da04c4d2 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Thu, 24 May 2012 12:55:26 -0500 Subject: [PATCH 05/12] manually word-break LICENSE.txt --- LICENSE.txt | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 74457f1..85dd456 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,7 +1,21 @@ Copyright (c) 2011,2012 Charles Lowell -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of the Software, +and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From dd1a7218c3f2278ad55ec1fe978fcd06e91cbfb0 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Thu, 24 May 2012 12:57:46 -0500 Subject: [PATCH 06/12] clearly indicate which license this is --- LICENSE.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/LICENSE.txt b/LICENSE.txt index 85dd456..982fae1 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,3 +1,5 @@ +(The MIT License: http://www.opensource.org/licenses/MIT) + Copyright (c) 2011,2012 Charles Lowell Permission is hereby granted, free of charge, to any person obtaining From b8cbe4e0bc439a2996649e10a40e2df9be9b071c Mon Sep 17 00:00:00 2001 From: kares Date: Thu, 23 Aug 2012 13:16:54 +0200 Subject: [PATCH 07/12] latest rspec compatibility --- spec/commonjs/path_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/commonjs/path_spec.rb b/spec/commonjs/path_spec.rb index f02a24c..a5c46b7 100644 --- a/spec/commonjs/path_spec.rb +++ b/spec/commonjs/path_spec.rb @@ -11,7 +11,7 @@ end it "fails when a module is not in the path" do - expect {@env.require('not_here')}.should raise_error LoadError + lambda { @env.require('not_here') }.should raise_error LoadError end end From 978d5767667887c7b42285a4096f9a4de5dafad1 Mon Sep 17 00:00:00 2001 From: kares Date: Thu, 23 Aug 2012 13:18:10 +0200 Subject: [PATCH 08/12] fails loading a module when .js file starts/ends with a comment --- lib/commonjs/environment.rb | 3 ++- spec/commonjs/libjs3/foo.js | 3 +++ spec/commonjs/modules_spec.rb | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 spec/commonjs/libjs3/foo.js diff --git a/lib/commonjs/environment.rb b/lib/commonjs/environment.rb index b7423b5..acbfa3e 100644 --- a/lib/commonjs/environment.rb +++ b/lib/commonjs/environment.rb @@ -13,7 +13,8 @@ def initialize(runtime, options = {}) def require(module_id) unless mod = @modules[module_id] filepath = find(module_id) or fail LoadError, "no such module '#{module_id}'" - load = @runtime.eval("(function(module, require, exports) {#{File.read(filepath)}})", filepath.expand_path.to_s) + load_js = "( function(module, require, exports) {\n#{File.read(filepath)}\n} )" + load = @runtime.eval(load_js, filepath.expand_path.to_s) @modules[module_id] = mod = Module.new(module_id, self) load.call(mod, mod.require_function, mod.exports) end diff --git a/spec/commonjs/libjs3/foo.js b/spec/commonjs/libjs3/foo.js new file mode 100644 index 0000000..9b0973c --- /dev/null +++ b/spec/commonjs/libjs3/foo.js @@ -0,0 +1,3 @@ +// some comment +exports.foo = 'foo'; +// another comment \ No newline at end of file diff --git a/spec/commonjs/modules_spec.rb b/spec/commonjs/modules_spec.rb index ec3324d..85468ef 100644 --- a/spec/commonjs/modules_spec.rb +++ b/spec/commonjs/modules_spec.rb @@ -32,3 +32,15 @@ def print end end end + +describe "modules" do + describe "with js comments" do + before do + @env = env_with_path_value File.expand_path('../libjs3', __FILE__) + end + + it "finds modules in that path" do + @env.require('foo').foo.should == 'foo' + end + end +end From 19e5a173bfd0f7b39f590e31a53c0773ad794215 Mon Sep 17 00:00:00 2001 From: kares Date: Thu, 23 Aug 2012 13:20:29 +0200 Subject: [PATCH 09/12] allow any version of therubyrhino >= 1.73.3 --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index b8868f8..b235c7f 100644 --- a/Gemfile +++ b/Gemfile @@ -4,4 +4,4 @@ source 'http://rubygems.org' gemspec gem "therubyracer", :platforms => :ruby -gem "therubyrhino", "~> 1.73.3", :platforms => :jruby \ No newline at end of file +gem "therubyrhino", ">= 1.73.3", :platforms => :jruby \ No newline at end of file From 532ebc7d1100057b4e9541e1f73d599975ea403e Mon Sep 17 00:00:00 2001 From: Vaughan Rouesnel Date: Sat, 20 Jul 2013 17:27:53 +1000 Subject: [PATCH 10/12] Fixes #11. --- lib/commonjs/environment.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/commonjs/environment.rb b/lib/commonjs/environment.rb index b7423b5..60f0073 100644 --- a/lib/commonjs/environment.rb +++ b/lib/commonjs/environment.rb @@ -31,9 +31,12 @@ def new_object private def find(module_id) - if loadpath = @paths.find { |path| path.join("#{module_id}.js").exist? } - loadpath.join("#{module_id}.js") + # Add `.js` extension if neccessary. + target = if File.extname(module_id) == '.js' then module_id else "#{module_id}.js" end + if loadpath = @paths.find { |path| path.join(target).exist? } + loadpath.join(target) end end + end end From 79dbbf05ddba4b312d4fc37413b4a7416c09514c Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Tue, 3 Sep 2013 14:20:28 -0500 Subject: [PATCH 11/12] v0.2.7 --- lib/commonjs/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commonjs/version.rb b/lib/commonjs/version.rb index 8e70498..eebcced 100644 --- a/lib/commonjs/version.rb +++ b/lib/commonjs/version.rb @@ -1,3 +1,3 @@ module CommonJS - VERSION = "0.2.6" + VERSION = "0.2.7" end From 2836e592870abf9584a769cbb713a6c30f458c73 Mon Sep 17 00:00:00 2001 From: Anatol Date: Wed, 11 Dec 2013 20:54:12 -0800 Subject: [PATCH 12/12] Update commonjs.gemspec --- commonjs.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/commonjs.gemspec b/commonjs.gemspec index f2617a8..494a476 100644 --- a/commonjs.gemspec +++ b/commonjs.gemspec @@ -7,6 +7,7 @@ Gem::Specification.new do |gem| gem.description = "Host CommonJS JavaScript environments in Ruby" gem.summary = "Provide access to your Ruby and Operating System runtime via the commonjs API" gem.homepage = "http://github.com/cowboyd/commonjs.rb" + gem.license = "MIT" gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } gem.files = `git ls-files`.split("\n")