commonjs 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/commonjs/environment.rb +4 -6
- data/lib/commonjs/module.rb +2 -1
- data/lib/commonjs/version.rb +1 -1
- data/spec/commonjs/libjs/assign_module_exports.js +1 -0
- data/spec/commonjs/libjs/one.js +1 -0
- data/spec/commonjs/libjs/three.js +1 -0
- data/spec/commonjs/libjs2/one.js +1 -0
- data/spec/commonjs/libjs2/two.js +1 -0
- data/spec/commonjs/modules_extensions_spec.rb +10 -0
- data/spec/commonjs/path_spec.rb +33 -0
- data/spec/spec_helper.rb +2 -1
- metadata +59 -73
data/lib/commonjs/environment.rb
CHANGED
@@ -6,16 +6,16 @@ module CommonJS
|
|
6
6
|
|
7
7
|
def initialize(runtime, options = {})
|
8
8
|
@runtime = runtime
|
9
|
-
@
|
9
|
+
@paths = [options[:path]].flatten.map {|path| Pathname(path)}
|
10
10
|
@modules = {}
|
11
11
|
end
|
12
12
|
|
13
13
|
def require(module_id)
|
14
14
|
unless mod = @modules[module_id]
|
15
15
|
filepath = find(module_id) or fail LoadError, "no such module '#{module_id}'"
|
16
|
-
load = @runtime.eval("(function(require, exports) {#{File.read(filepath)}})", filepath.expand_path)
|
16
|
+
load = @runtime.eval("(function(module, require, exports) {#{File.read(filepath)}})", filepath.expand_path)
|
17
17
|
@modules[module_id] = mod = Module.new(module_id, self)
|
18
|
-
load.call(mod.require_function, mod.exports)
|
18
|
+
load.call(mod, mod.require_function, mod.exports)
|
19
19
|
end
|
20
20
|
return mod.exports
|
21
21
|
end
|
@@ -31,9 +31,7 @@ module CommonJS
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def find(module_id)
|
34
|
-
|
35
|
-
filepath if filepath.exist?
|
34
|
+
@paths.find { |path| path.join("#{module_id}.js").exist? }.join("#{module_id}.js")
|
36
35
|
end
|
37
|
-
|
38
36
|
end
|
39
37
|
end
|
data/lib/commonjs/module.rb
CHANGED
data/lib/commonjs/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
module.exports = function() {return 'I am your exports'}
|
@@ -0,0 +1 @@
|
|
1
|
+
exports.one = 'one'
|
@@ -0,0 +1 @@
|
|
1
|
+
exports.three = 'three'
|
@@ -0,0 +1 @@
|
|
1
|
+
exports.one = 1
|
@@ -0,0 +1 @@
|
|
1
|
+
exports.two = 2
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'modules extensions' do
|
4
|
+
before do
|
5
|
+
@env = CommonJS::Environment.new(V8::Context.new, :path => File.expand_path('../libjs', __FILE__))
|
6
|
+
end
|
7
|
+
it "allows the exports object to be completely replaced" do
|
8
|
+
@env.require('assign_module_exports').call().should eql "I am your exports"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "load paths: " do
|
4
|
+
describe "with a single path" do
|
5
|
+
before do
|
6
|
+
@env = env_with_path_value File.expand_path('../libjs', __FILE__)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "finds modules in that path" do
|
10
|
+
@env.require('one').one.should eql 'one'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "with multilpe paths" do
|
15
|
+
before do
|
16
|
+
@env = env_with_path_value [File.expand_path('../libjs2', __FILE__), File.expand_path('../libjs', __FILE__)]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "finds modules in both paths" do
|
20
|
+
@env.require('two').two.should eql 2
|
21
|
+
@env.require('three').three.should eql 'three'
|
22
|
+
end
|
23
|
+
|
24
|
+
it "respects the order in which paths were specified" do
|
25
|
+
@env.require('one').one.should eql 1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def env_with_path_value(path)
|
30
|
+
CommonJS::Environment.new V8::Context.new, :path => path
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,76 +1,56 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: commonjs
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
version: 0.2.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Charles Lowell
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-03-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: therubyracer
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2156255820 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
18
|
+
requirements:
|
26
19
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 41
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
- 9
|
32
|
-
- 9
|
20
|
+
- !ruby/object:Gem::Version
|
33
21
|
version: 0.9.9
|
34
22
|
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: rake
|
38
23
|
prerelease: false
|
39
|
-
|
24
|
+
version_requirements: *2156255820
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &2156255280 !ruby/object:Gem::Requirement
|
40
28
|
none: false
|
41
|
-
requirements:
|
42
|
-
- -
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
|
45
|
-
segments:
|
46
|
-
- 0
|
47
|
-
version: "0"
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
48
33
|
type: :development
|
49
|
-
version_requirements: *id002
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
-
name: rspec
|
52
34
|
prerelease: false
|
53
|
-
|
35
|
+
version_requirements: *2156255280
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &2156254640 !ruby/object:Gem::Requirement
|
54
39
|
none: false
|
55
|
-
requirements:
|
56
|
-
- -
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
59
|
-
segments:
|
60
|
-
- 0
|
61
|
-
version: "0"
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
62
44
|
type: :development
|
63
|
-
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2156254640
|
64
47
|
description: Host CommonJS JavaScript environments in Ruby
|
65
|
-
email:
|
48
|
+
email:
|
66
49
|
- cowboyd@thefrontside.net
|
67
50
|
executables: []
|
68
|
-
|
69
51
|
extensions: []
|
70
|
-
|
71
52
|
extra_rdoc_files: []
|
72
|
-
|
73
|
-
files:
|
53
|
+
files:
|
74
54
|
- .gitignore
|
75
55
|
- .gitmodules
|
76
56
|
- Gemfile
|
@@ -81,41 +61,47 @@ files:
|
|
81
61
|
- lib/commonjs/environment.rb
|
82
62
|
- lib/commonjs/module.rb
|
83
63
|
- lib/commonjs/version.rb
|
64
|
+
- spec/commonjs/libjs/assign_module_exports.js
|
65
|
+
- spec/commonjs/libjs/one.js
|
66
|
+
- spec/commonjs/libjs/three.js
|
67
|
+
- spec/commonjs/libjs2/one.js
|
68
|
+
- spec/commonjs/libjs2/two.js
|
69
|
+
- spec/commonjs/modules_extensions_spec.rb
|
84
70
|
- spec/commonjs/modules_spec.rb
|
71
|
+
- spec/commonjs/path_spec.rb
|
85
72
|
- spec/spec_helper.rb
|
86
73
|
homepage: http://github.com/cowboyd/commonjs
|
87
74
|
licenses: []
|
88
|
-
|
89
75
|
post_install_message:
|
90
76
|
rdoc_options: []
|
91
|
-
|
92
|
-
require_paths:
|
77
|
+
require_paths:
|
93
78
|
- lib
|
94
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
80
|
none: false
|
96
|
-
requirements:
|
97
|
-
- -
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
|
100
|
-
|
101
|
-
- 0
|
102
|
-
version: "0"
|
103
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
86
|
none: false
|
105
|
-
requirements:
|
106
|
-
- -
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
|
109
|
-
segments:
|
110
|
-
- 0
|
111
|
-
version: "0"
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
112
91
|
requirements: []
|
113
|
-
|
114
92
|
rubyforge_project:
|
115
|
-
rubygems_version: 1.8.
|
93
|
+
rubygems_version: 1.8.17
|
116
94
|
signing_key:
|
117
95
|
specification_version: 3
|
118
|
-
summary: Provide access to your Ruby and Operating System runtime via the commonjs
|
119
|
-
|
96
|
+
summary: Provide access to your Ruby and Operating System runtime via the commonjs
|
97
|
+
API
|
98
|
+
test_files:
|
99
|
+
- spec/commonjs/libjs/assign_module_exports.js
|
100
|
+
- spec/commonjs/libjs/one.js
|
101
|
+
- spec/commonjs/libjs/three.js
|
102
|
+
- spec/commonjs/libjs2/one.js
|
103
|
+
- spec/commonjs/libjs2/two.js
|
104
|
+
- spec/commonjs/modules_extensions_spec.rb
|
120
105
|
- spec/commonjs/modules_spec.rb
|
106
|
+
- spec/commonjs/path_spec.rb
|
121
107
|
- spec/spec_helper.rb
|