duojs / duo

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

Unable to require components with a prefix e.g. `js-`, `npm-` in the repo name #428

Open jameslnewell opened 9 years ago

jameslnewell commented 9 years ago

Hi,

I've finally found some time to play with Duo. It looks like there are some neat improvements over Component!

However, I use prefixes in my repo names so at a glance I know what language/environment they're written for. Component coped with the prefixes but Duo looks like it doesn't support them?

e.g.

Would this be difficult to add via a plugin? What methods in duo.js would I need to look at?

Thanks.

stephenmathieson commented 9 years ago

yeah, duo doesn't support component.json's name property. there's currently no way to build a plugin for this :/

jameslnewell commented 9 years ago

I had a bit of a hack and was able to get it working by overriding and copy/paste/modifying the duo.dependency method. If it fails to resolve a package name it tries to resolve it again with a prefix. This is obviously a bit slower and will break whenever the method internals are updated in duo.

    // `dep` is a remote dependency
    var pkg = this.package(dep, file);
    if (!pkg) {
        dep = 'js-'+dep;
        pkg = this.package(dep, file);
        if (!pkg) {
            debug('1: %s: cannot resolve "%s"', file.id, dep);
            return false;
        }
    }

ty. :disappointed:

stephenmathieson commented 9 years ago

yeah, that's a bit of a hack :p