requirejs / r.js

Runs RequireJS in Node and Rhino, and used to run the RequireJS optimizer
Other
2.57k stars 673 forks source link

win32 incorrect assigned module names when filenames created via path.join / resolve #426

Open DimitarChristoff opened 11 years ago

DimitarChristoff commented 11 years ago

Using r.js for a custom builder of components on osx and win32 machines. for various reasons, path management in the builder is done via path.join / resolve / relative etc, which is taking into account path.sep (/ or ).

Example passed to config for r.js:

this.basePath = '../src;
this.componentPath = 'components';
var componentId = 'widget';
config.include = [ path.join(this.basePath, this.componentPath, componentId, 'main') ];

on osx this results in ../src/components/widget/main' and the resulting module gets a normalizedname` of (relative to the correct baseUrl):

define("components/widget/main", [deps], function(){});

on windows, we get the ..\\src\\components\\widget\\main passed to r.js and the module name becomes:

define("components\widget\main", [deps], function(){});

... which simply does not match any require statements in the code after. since it's for web building (URI), shouldn't there be a way to normalize the names for that?

robertgorecki commented 11 years ago

I would also vote for that. We work in multiple environments (osx, windows) and such path normalization during r.js build would be nice.

jrburke commented 11 years ago

The main, include, exclude, excludeShallow, and insertRequire options expect module IDs, which should all be front slashed strings, not back-slashed ones. In this case, using path.join is not necessary.

I need to do a better job though of enforcing that, as I can see where it is not obvious. Putting this in the 2.2.0 bucket.

DimitarChristoff commented 11 years ago

yes, path.join is not needed here but this is written to illustrate a point. the context is a cli builder that works with files to find what and how to build and it passes the end result to require optimizer. I am currently working around this by replacing \ with / beforehand anyway, just thought it was never going to be useful to leave \ in the module names.