Properly handle rjs options.dir if used #703

Merged
merged 1 commit into from Nov 20, 2012

5 participants

@theshortcut
Contributor

In rjs task if options.dir is set it is an absolute path, so using path.join on it and options.baseUrl (also an absolute path) creates a path to non-existant files. This is helpful if building named modules with rjs rather than a single file from usemin.

@addyosmani
Member

I think this is useful to land. Anyone opposed?

@sindresorhus
Member

lgtm

@netzzwerg

This fix is necessary if you want use named modules in rjs. There is an other pull request with nearly the same problem #711

@addyosmani addyosmani merged commit a63ce3d into yeoman:master Nov 20, 2012

1 check passed

default The Travis build passed
Details
@cheton
cheton commented Dec 7, 2012

The original code of using path.join(options.dir, options.baseUrl, m.name + '.js') is the correct usage. The only problem is that both of options.dir and options.baseUrl become absolute path in the rjs.optimize's callback function..

Instead of using var basePath = options.dir || options.baseUrl to determine basePath, please use the following one instead.

grunt.registerHelper('rjs:optimize:js', function(options, cb) {
    var baseUrl = options.baseUrl; // copy options.baseUrl to baseUrl
        :    :    :
    rjs.optimize(options, function(out) {                                                                                                                        
        originals.forEach(function(m) {                                                                                                                            
        var filepath = path.join(options.dir, baseUrl, m.name + '.js'); // it will fix the problem
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment