spade 0.0.3 → 0.0.4

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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spade (0.0.2)
4
+ spade (0.0.3)
5
5
  eventmachine (~> 0.12.10)
6
6
  gemcutter (~> 0.6.1)
7
7
  highline (~> 1.6.1)
@@ -67,7 +67,6 @@ var spade ;
67
67
  }
68
68
 
69
69
  function normalize(id, contextId, contextPkg, _asPackage) {
70
-
71
70
  // slice separator off the end since it is not used...
72
71
  if (id[id.length-1]==='/') id = id.slice(0,-1);
73
72
 
@@ -77,18 +76,17 @@ var spade ;
77
76
  idx = 0,
78
77
  len = id.length,
79
78
  part, next,
79
+ packageName = parts[0],
80
80
  useTilde = false;
81
81
 
82
- var module = parts.pop(); // get rid of the last path element since it is a module.
83
-
82
+ if (contextPkg && contextPkg.main && contextId === packageName+'/main') {
84
83
  // If we're requiring from main we need to handle relative requires specially
85
- // I'm not sure if this is required by spec, but at least some CommonJS packages require it (jsdom)
86
- if (module === 'main' && contextPkg && contextPkg.main) {
87
84
  useTilde = true;
88
85
  parts = contextPkg.main.replace(/^\.?\//, '').split('/');
89
- parts.pop(); // Remove module
90
86
  }
91
87
 
88
+ parts.pop(); // get rid of the last path element since it is a module.
89
+
92
90
  while(idx<len) {
93
91
  next = id.indexOf('/', idx);
94
92
  if (next<0) next = len;
@@ -102,16 +100,7 @@ var spade ;
102
100
  id = parts.join('/');
103
101
 
104
102
  // Make the path into a root relative path
105
- if (useTilde) {
106
- var dirPath;
107
- for (var name in contextPkg.directories) {
108
- dirPath = contextPkg.directories[name].replace(/^\.?\//, '');
109
- if (id.substring(0, dirPath.length) === dirPath) {
110
- id = id.replace(dirPath, contextPkg.name+'/~'+name);
111
- break;
112
- }
113
- }
114
- }
103
+ if (useTilde) { id = packageName+'/~'+id; }
115
104
 
116
105
  // else, just slice off beginning '/' if needed
117
106
  } else if (id[0]==='/') id = id.slice(1);
@@ -124,7 +113,12 @@ var spade ;
124
113
  // slice separators off begin and end
125
114
  if (id[0]==='/') id = id.slice(1);
126
115
 
127
-
116
+ // Convert root relative paths to normal paths where possible
117
+ if (contextPkg && contextPkg.directories) {
118
+ var libPath = contextPkg.directories['lib'];
119
+ if (libPath) { id = id.replace('~'+libPath.replace(/^\.?\//, '')+'/', ''); }
120
+ }
121
+
128
122
  return remap(id, contextPkg);
129
123
  }
130
124
 
@@ -24,6 +24,9 @@ module Spade
24
24
 
25
25
  installed = []
26
26
 
27
+
28
+ #TODO: Clean up duplication here
29
+
27
30
  Dir.glob(File.join(BUILTIN_PACKAGES, '*')).each do |path|
28
31
  next unless File.exists? File.join(path, 'package.json')
29
32
 
@@ -35,6 +38,23 @@ module Spade
35
38
  puts "Installing built-in package #{File.basename(path)}" if verbose
36
39
  end
37
40
 
41
+ # Do this to get the Gem.dir right
42
+ env = Spade::Environment.new
43
+ Dir.glob(File.join(env.spade_dir, 'gems', '*')).each do |path|
44
+ package_def = File.join(path, 'package.json')
45
+ next unless File.exists?(package_def)
46
+
47
+ next if installed.include? path
48
+ installed << path
49
+
50
+ json = JSON.load File.read(package_def)
51
+ package_name = json['name']
52
+ new_path = File.join(spade_path, 'packages', package_name)
53
+ FileUtils.ln_s path, new_path, :force => true
54
+ puts "Installing system package #{File.basename(path)}" if verbose
55
+ end
56
+
57
+
38
58
  Dir.glob(File.join(rootdir, 'packages', '*')).each do |path|
39
59
  next unless File.exists? File.join(path, 'package.json')
40
60
 
@@ -0,0 +1,103 @@
1
+ require 'spade/installer'
2
+
3
+ module Spade
4
+ class DependencyInstaller < Gem::DependencyInstaller
5
+
6
+ # Had to overwrite this all just to change the match from /gem$/ to /spd$/
7
+ def find_spec_by_name_and_version(gem_name,
8
+ version = Gem::Requirement.default,
9
+ prerelease = false)
10
+ spec_and_source = nil
11
+
12
+ glob = if File::ALT_SEPARATOR then
13
+ gem_name.gsub File::ALT_SEPARATOR, File::SEPARATOR
14
+ else
15
+ gem_name
16
+ end
17
+
18
+ local_gems = Dir["#{glob}*"].sort.reverse
19
+
20
+ unless local_gems.empty? then
21
+ local_gems.each do |gem_file|
22
+ next unless gem_file =~ /spd$/
23
+ begin
24
+ spec = Gem::Format.from_file_by_path(gem_file).spec
25
+ spec_and_source = [spec, gem_file]
26
+ break
27
+ rescue SystemCallError, Gem::Package::FormatError
28
+ end
29
+ end
30
+ end
31
+
32
+ if spec_and_source.nil? then
33
+ dep = Gem::Dependency.new gem_name, version
34
+ dep.prerelease = true if prerelease
35
+ spec_and_sources = find_gems_with_sources(dep).reverse
36
+
37
+ spec_and_source = spec_and_sources.find { |spec, source|
38
+ Gem::Platform.match spec.platform
39
+ }
40
+ end
41
+
42
+ if spec_and_source.nil? then
43
+ raise Gem::GemNotFoundException.new(
44
+ "Could not find a valid spd '#{gem_name}' (#{version}) locally or in a repository",
45
+ gem_name, version, @errors)
46
+ end
47
+
48
+ @specs_and_sources = [spec_and_source]
49
+ end
50
+
51
+ # Overwrite this to use our custom installer
52
+ def install dep_or_name, version = Gem::Requirement.default
53
+ if String === dep_or_name then
54
+ find_spec_by_name_and_version dep_or_name, version, @prerelease
55
+ else
56
+ dep_or_name.prerelease = @prerelease
57
+ @specs_and_sources = [find_gems_with_sources(dep_or_name).last]
58
+ end
59
+
60
+ @installed_gems = []
61
+
62
+ gather_dependencies
63
+
64
+ @gems_to_install.each do |spec|
65
+ last = spec == @gems_to_install.last
66
+ # HACK is this test for full_name acceptable?
67
+ next if @source_index.any? { |n,_| n == spec.full_name } and not last
68
+
69
+ # TODO: make this sorta_verbose so other users can benefit from it
70
+ say "Installing spd #{spec.full_name}" if Gem.configuration.really_verbose
71
+
72
+ _, source_uri = @specs_and_sources.assoc spec
73
+ begin
74
+ local_gem_path = Gem::RemoteFetcher.fetcher.download spec, source_uri,
75
+ @cache_dir
76
+ rescue Gem::RemoteFetcher::FetchError
77
+ next if @force
78
+ raise
79
+ end
80
+
81
+ inst = Spade::Installer.new local_gem_path,
82
+ :bin_dir => @bin_dir,
83
+ :development => @development,
84
+ :env_shebang => @env_shebang,
85
+ :force => @force,
86
+ :format_executable => @format_executable,
87
+ :ignore_dependencies => @ignore_dependencies,
88
+ :install_dir => @install_dir,
89
+ :security_policy => @security_policy,
90
+ :source_index => @source_index,
91
+ :user_install => @user_install,
92
+ :wrappers => @wrappers
93
+
94
+ spec = inst.install
95
+
96
+ @installed_gems << spec
97
+ end
98
+
99
+ @installed_gems
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,40 @@
1
+ module Spade
2
+ class Installer < Gem::Installer
3
+
4
+ def app_script_text(bin_file_name)
5
+ <<-TEXT
6
+ #{shebang bin_file_name}
7
+ #
8
+ # This file was generated by Spade.
9
+ #
10
+ # The application '#{@spec.name}' is installed as part of an spd, and
11
+ # this file is here to facilitate running it.
12
+ #
13
+
14
+ require 'spade'
15
+
16
+ # Configures RubyGems properly
17
+ env = Spade::Environment.new
18
+
19
+ version = "#{Gem::Requirement.default}"
20
+
21
+ if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
22
+ version = $1
23
+ ARGV.shift
24
+ end
25
+
26
+ gem '#{@spec.name}', version
27
+
28
+ path = Gem.bin_path('#{@spec.name}', '#{bin_file_name}', version)
29
+ shebang = File.open(path){|f| f.readline }
30
+
31
+ if shebang =~ /^\#\!.*ruby/
32
+ load path
33
+ else
34
+ exec path, *ARGV
35
+ end
36
+ TEXT
37
+ end
38
+
39
+ end
40
+ end
@@ -26,8 +26,10 @@ module Spade
26
26
  spec.summary = summary
27
27
  spec.description = description
28
28
  spec.requirements = [metadata.to_json]
29
- spec.files = directory_files + bin_files + ["package.json"]
29
+ spec.files = directory_files + ["package.json"]
30
30
  spec.test_files = glob_files(test_path) if test_path
31
+ spec.bindir = bin_path
32
+ spec.executables = bin_files.map{|p| File.basename(p) } if bin_path
31
33
  spec.rubyforge_project = "spade"
32
34
  def spec.file_name
33
35
  "#{full_name}.#{EXT}"
@@ -77,6 +79,10 @@ module Spade
77
79
  end
78
80
  end
79
81
 
82
+ def bin_path
83
+ @directories["bin"] || "bin"
84
+ end
85
+
80
86
  def lib_path
81
87
  @directories["lib"]
82
88
  end
@@ -1,3 +1,5 @@
1
+ require 'spade/dependency_installer'
2
+
1
3
  module Spade
2
4
  class Remote < Repository
3
5
  extend Gem::GemcutterUtilities
@@ -72,7 +74,7 @@ module Spade
72
74
  end
73
75
 
74
76
  def install(package, version, prerelease)
75
- inst = Gem::DependencyInstaller.new(:prerelease => prerelease)
77
+ inst = Spade::DependencyInstaller.new(:prerelease => prerelease)
76
78
  inst.install package, Gem::Requirement.new([version])
77
79
  inst.installed_gems
78
80
  end
@@ -1,3 +1,3 @@
1
1
  module Spade
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -0,0 +1,8 @@
1
+ require "spec_helper"
2
+
3
+ describe "spade update" do
4
+ it "should create a spade-boot.js"
5
+ it "should use pre-installed packages"
6
+ it "should use system installed packages"
7
+ it "should use local packages"
8
+ end
@@ -1 +1,3 @@
1
+ #!/bin/bash
2
+
1
3
  # Placeholder for test, do not remove
@@ -46,7 +46,6 @@ Ct.test('normalize', function(t) {
46
46
 
47
47
  Ct.test('normalize package', function(t) {
48
48
  var spade = t.spade;
49
-
50
49
  spade.register('sproutcore', {}); // register as a package
51
50
  t.equal(spade.normalize('sproutcore'), 'sproutcore/main');
52
51
  t.equal(spade.normalize('foo/sproutcore'), 'foo/sproutcore');
@@ -54,6 +53,21 @@ Ct.test('normalize package', function(t) {
54
53
 
55
54
  Ct.test('normalize relative require from main', function(t) {
56
55
  // I think this is a valid test, but not certain
57
- t.spade.register('sproutcore', { main: './lib/sproutcore/main' });
58
- t.equal(spade.normalize('./sproutcore/core', 'sproutcore/main'), 'sproutcore/sproutcore/core');
56
+ var spade = t.spade, mainRequire, otherRequire;
57
+ spade.register('foo', { main: './lib/foo', directories: { lib: './lib/foo' } });
58
+ spade.register('foo/main', 'return require;');
59
+ spade.register('foo/other/main', 'return require;');
60
+ mainRequire = spade.require('foo/main');
61
+ otherRequire = spade.require('foo/other/main');
62
+ t.equal(mainRequire.normalize('./foo/adfadf'), 'foo/adfadf', 'works for real main');
63
+ t.equal(otherRequire.normalize('./foo/core'), 'foo/other/foo/core', "no difference for fake main");
64
+ });
65
+
66
+ Ct.test('normalize tilde paths with lib', function(t){
67
+ var spade = t.spade, fooRequire;
68
+ spade.register('foo', { directories: { lib: './lib' }}); // register as a package
69
+ spade.register('foo/main', 'return require;');
70
+ fooRequire = spade.require('foo');
71
+ t.equal(fooRequire.normalize('foo/~lib/main'), 'foo/main');
72
+ t.equal(fooRequire.normalize('foo/~lib/core'), 'foo/core');
59
73
  });
@@ -54,3 +54,5 @@ Ct.test('require a module that was just registered symbolically. This is for co
54
54
  spade.register('not/a-module');
55
55
  t.ok(spade.require('not/a-module'));
56
56
  });
57
+
58
+ Ct.test('require system installed packages');
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: spade
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Charles Jolley
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-30 00:00:00 -07:00
13
+ date: 2011-04-04 00:00:00 -07:00
14
14
  default_executable: spade
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -354,8 +354,10 @@ files:
354
354
  - lib/spade/console.rb
355
355
  - lib/spade/context.rb
356
356
  - lib/spade/credentials.rb
357
+ - lib/spade/dependency_installer.rb
357
358
  - lib/spade/environment.rb
358
359
  - lib/spade/exports.rb
360
+ - lib/spade/installer.rb
359
361
  - lib/spade/loader.rb
360
362
  - lib/spade/local.rb
361
363
  - lib/spade/package.rb
@@ -430,6 +432,7 @@ files:
430
432
  - spec/cli/uninstall_spec.rb
431
433
  - spec/cli/unpack_spec.rb
432
434
  - spec/cli/unyank_spec.rb
435
+ - spec/cli/update_spec.rb
433
436
  - spec/cli/yank_spec.rb
434
437
  - spec/credentials_spec.rb
435
438
  - spec/fixtures/badrake-0.8.7.gem
@@ -516,6 +519,7 @@ test_files:
516
519
  - spec/cli/uninstall_spec.rb
517
520
  - spec/cli/unpack_spec.rb
518
521
  - spec/cli/unyank_spec.rb
522
+ - spec/cli/update_spec.rb
519
523
  - spec/cli/yank_spec.rb
520
524
  - spec/credentials_spec.rb
521
525
  - spec/fixtures/badrake-0.8.7.gem