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.
Files changed (2) hide show
  1. data/lib/rill.rb +14 -13
  2. metadata +1 -1
@@ -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(mod, dep)
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(mod, dep)
106
- context = mod.include?('/') ? mod.slice(0, mod.rindex('/')) : ''
107
- dep_bare = dep.slice(dep.index('/') || 0, dep.length)
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
- if dep.starts_with?('./')
111
- ret = context + dep_bare
112
- elsif dep.starts_with?('../')
113
- ret = context.slice(0, context.rindex('/')) + dep_bare
114
- else
115
- ret = dep
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
- ret
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.blank?
131
+ d.nil? || d =~ /^\s*$/
131
132
  end
132
133
  else
133
134
  pattern = /^define\((['"])[^'"]+\1,\s*(['"])([^\1]+)\1\.split/
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: