rill 0.0.1 → 0.0.2
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/rill.rb +14 -13
- metadata +1 -1
data/lib/rill.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
1
3
|
class Rill
|
|
2
4
|
|
|
3
5
|
DEFAULT_CONFIG = {
|
|
@@ -41,7 +43,7 @@ class Rill
|
|
|
41
43
|
|
|
42
44
|
deps = parse_deps_from_define(code)
|
|
43
45
|
deps.each do |dep|
|
|
44
|
-
dep = expand_path(
|
|
46
|
+
dep = expand_path(dep, mod)
|
|
45
47
|
resolve_mod(dep)
|
|
46
48
|
end
|
|
47
49
|
end
|
|
@@ -102,20 +104,19 @@ class Rill
|
|
|
102
104
|
mod.slice(start, fini - start)
|
|
103
105
|
end
|
|
104
106
|
|
|
105
|
-
def expand_path(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
ret = ''
|
|
107
|
+
def expand_path(dep, mod)
|
|
108
|
+
# 与 File.expand_path 的逻辑还是有些分别的
|
|
109
|
+
base = mod.include?('/') ? mod.slice(0, mod.rindex('/') + 1) : ''
|
|
109
110
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
while dep.start_with?('.')
|
|
112
|
+
dep.sub!(/^\.\//, '')
|
|
113
|
+
if dep.start_with?('../')
|
|
114
|
+
dep.sub!('../', '')
|
|
115
|
+
base.sub!(/[^\/]+\/$/, '')
|
|
116
|
+
end
|
|
116
117
|
end
|
|
117
118
|
|
|
118
|
-
|
|
119
|
+
base + dep
|
|
119
120
|
end
|
|
120
121
|
|
|
121
122
|
def parse_deps_from_define(code)
|
|
@@ -127,7 +128,7 @@ class Rill
|
|
|
127
128
|
deps = match[2]
|
|
128
129
|
deps = JSON.parse(deps.gsub("'", '"'))
|
|
129
130
|
deps.delete_if do |d|
|
|
130
|
-
d.
|
|
131
|
+
d.nil? || d =~ /^\s*$/
|
|
131
132
|
end
|
|
132
133
|
else
|
|
133
134
|
pattern = /^define\((['"])[^'"]+\1,\s*(['"])([^\1]+)\1\.split/
|