anodynos / uRequire

The Ultimate JavaScript Module Builder & Automagical Task Runner. Convert AMD & CommonJS/NodeJS modules to UMD, AMD, CommonJS or bundle them as `combined.js` (rjs & almond, AMDclean soon) & automagically run/test/watch them on nodejs, Web/AMD or Web/Script. Declarative & DRY config with inheritance. Manipulate & inject dependencies, module code, banners, version etc while building with a single line. Support two kinds of plugins, ResourceConverter (i.e file level) and AfterBuilder (i.e the whole bundle). Transparent support for Coffeescript, IcedCoffeescript, Coco, LiveScript – they’re just JavaScript :-)
http://anodynos.github.io/uRequire
MIT License
265 stars 20 forks source link

m.replaceDep does not update properly paths if dependency is in lower/same directory #67

Closed demurgos closed 9 years ago

demurgos commented 9 years ago

Hi I discovered recently resource-converters and with them a small issue:

Using m.replaceDep in a resource converter with "newDep" being a bundle dependency returns a local dependency instead if the converted module and its dependency are in the same directory.

Here is an example : https://github.com/Demurgos/urequire-replaceDep (it happens when compiling target2, it's explained in the readme)

The issue boils down to the use of path.join dropping the leading ./ of paths in Dependency.protototype.update. I'm not so familiar with .coffee syntax, but I could fix it in my case with the following JS code after newDepString = upath.join.apply null, newDepPaths:

if(_.startsWith(newDepPaths[0], './') && !(_.startsWith(newDepString, './') || _.startsWith(newDepString, '../'))){
    newDepString = './'+newDepString;
}

The test would be better with && !upath.isAbsolute(newDepString) but isAbsolute lands in the path module only in Node 0.12.x.

anodynos commented 9 years ago

Charles (@Demurgos) thank you so much for your detailed issue description - I am sorry for the late response but I have been very busy lately. I will check it and get back to you soon!

PS: Coffeescript is just javascript, trust me it only takes a few hours to get used to the sugar syntax and then you're free :-)

anodynos commented 9 years ago

@Demurgos the issue you reported was spot on, and I incorporated the solution on upath.joinSafe Using beta.21 now builds the https://github.com/Demurgos/urequire-replaceDep properly.

Sorry for taking so long to fix :-/

demurgos commented 9 years ago

Thank you, neither am I very quick to respond but the most important is that it works now ;)

anodynos commented 9 years ago

:+1: