duojs / duo

A next-generation package manager for the front-end
3.42k stars 118 forks source link

Get last tag using semver and read `package.json` and `bower.json` for main file #238

Open mgonto opened 10 years ago

mgonto commented 10 years ago

Hey,

I was trying to require jquery/jquery for example. Doing require('jquery/jquery') tries to fetch tag version 1.0. I think it should actually fetch the last available tag based on Semver. What do you guys think?

Also, I see that jQuery has a bower.json and a package.json, both specifying main files. However, duo tries to find index.js on root. Shouldn't it parse the available package definition json to search for the main files?

Thanks for all the hard work and great tool :)

matthewmueller commented 10 years ago

Oh yah, it should definitely fetch the latest tag, which would probably be: 2.1.1

matthewmueller commented 10 years ago

@yields do you mind looking into this one? I think it's related to gh-resolve.

matthewmueller commented 10 years ago
$ echo "require('jquery/jquery:dist/jquery.js')" | duo -t js

     building : from stdin/Users/matt/Projects/duo/node_modules/duo-package/node_modules/semver/semver.js:273
    throw new TypeError('Invalid Version: ' + version);
          ^
TypeError: Invalid Version: 1.0
    at new SemVer (/Users/matt/Projects/duo/node_modules/duo-package/node_modules/semver/semver.js:273:11)
    at compare (/Users/matt/Projects/duo/node_modules/duo-package/node_modules/semver/semver.js:460:10)
    at arrange (/Users/matt/Projects/duo/node_modules/duo-package/node_modules/gh-resolve/index.js:133:13)
    at Array.sort (native)
    at /Users/matt/Projects/duo/node_modules/duo-package/node_modules/gh-resolve/index.js:69:31
    at ChildProcess.exithandler (child_process.js:720:7)
    at ChildProcess.EventEmitter.emit (events.js:110:17)
    at maybeClose (child_process.js:992:16)
    at Process.ChildProcess._handle.onexit (child_process.js:1059:5)
mgonto commented 10 years ago

Exactly that one!.

And what about getting the main from bower.json or package.json? Do you want me to put that in another issue?

matthewmueller commented 10 years ago

we probably won't support that unless we go all out on browserify support, which is part of a larger discussion

mgonto commented 10 years ago

@MatthewMueller why? I think just getting the main from bower.json is a pretty good compromise.

Main file from package.json does have other requires from browserify which would make it not work with Duo, I agree.

However, main from bower.json is always the JS file to use. Why not support it?

Thanks!

matthewmueller commented 10 years ago

Yah, bower.json probably wouldn't be too tough, feel free to open another issue to get the main from bower.json. We can chat about it more there :-)

endel commented 10 years ago

Getting main from bower.json right now is the way to go. It's user-friendly: "just require this thing". IMHO duo should embrace the ecosystem that is already there. bower.json support could be replaced with anything else in the future.

endel commented 10 years ago

Example: CodeMirror's bower.json

With the current version (0.8.4), the only way to include the target main files is to knowing exactly the relative path of them. Example:

// js
require('codemirror/CodeMirror:lib/codemirror.js');
/* css */
@import 'codemirror/CodeMirror:lib/codemirror.css';

But there is a .css and a .js file defined as main files on bower.json. Why can't we just require codemirror/CodeMirror in the source files like this?

// js
require('codemirror/CodeMirror');
/* css */
@import 'codemirror/CodeMirror';

It sounds totally feasible and removes complexity for the developer.