cujojs / curl

curl.js is small, fast, extensible module loader that handles AMD, CommonJS Modules/1.1, CSS, HTML/text, and legacy scripts.
https://github.com/cujojs/curl/wiki
Other
1.89k stars 216 forks source link

Curl doesn't add file extension if ".js" in directory name #218

Closed webpro closed 10 years ago

webpro commented 10 years ago

When a directory contains .js in a paths config, curl is not adding the .js to the end of the path anymore. E.g.:

paths: {
    postal: 'lib/postal.js/lib/postal'
}

And curl tries to fetch lib/postal.js/lib/postal (instead of lib/postal.js/lib/postal.js).

unscriptable commented 10 years ago

You can use the dontAddFileExt config option for this:

curl.config({
    dontAddFileExt: /\.js$/
});

https://github.com/cujojs/curl/wiki/Configuring-curl.js#curljss-common-configuration-options

webpro commented 10 years ago

But I want it to add the extension (the default behavior).

unscriptable commented 10 years ago

Silly me. Will this work?

curl.config({
    dontAddFileExt: /\.js\//
});
webpro commented 10 years ago

Yes, that works, thanks. But shouldn't adding .js if not matching /\.js$/ be the default behavior?

unscriptable commented 10 years ago

I had that originally, but people complained when using a module-locator service like the following:

paths: { foo: 'getModuleService?version=3.1.1' } // shouldn't add ".js"

But people are also doing this:

paths: { foo: 'foo.js.minified' } // should add ".js"

So now it uses this by default: /\?|\.js\b/ // don't add .js if there are query params or a ".js" anywhere

Maybe this is the best thing? /\?|\.js\// // don't add .js if it's part of a path

-- J

webpro commented 10 years ago

I understand the issues from your/curl's perspective. Imho, I think that your very first suggestion should be the default behavior. Thanks for clarifying.