F.map doesn't work in windows
Only related to Windows!!
The problem is that following mapping
F.map('/admin/', F.path.root() + '/admin/');
will produce
self.routes.mapping[ '/admin/D:\myApp\admin\app.js' ] = 'D:\myApp\admin\app.js';
since replacing doesn't do anything because variable replace in map function has forward slashes whereas variable file has backslashes
replace = 'D:/myApp/admin/';
file = 'D:\myApp\admin\';
//as expected this won't change anything
file.replace(replace, '');
what seems to work ok for me is placing filename = filename.replace(/\\/g, '/'); at the top of map function and replacing
var file = files[i].replace(replace, '');
with
var file = files[i].replace(/\\/g, '/').replace(replace, '');
Hi @molda,
yes, please try to download latest beta npm install total.js@beta, it's stable and give me a feedback.
Thanks.
node.js : v4.2.1 total.js : v1.9.3-23
Hi @petersirka following code still fails to find anything in my admin folder
F.map('/admin/', '/admin/');
as soon as i remove "/" from second argument F.map('/admin/', 'admin/'); it's working
and this
F.map('/admin/', path.join(F.path.private(), 'admin'));
wil produce
self.routes.mapping['/admin/D:/totaljs-beta/private/admin/app.js'] = 'D:/totaljs-beta/private/admin/app.js';
if (framework.isWindows) files[i] = files[i].replace(filename, '').replace(/\\/g, '/');
will not replace anything since
filename == 'D:\totaljs-beta\private\admin/' // notice one forward slash
files[i] == 'D:\totaljs-beta\private\admin\app.js'
F.map('/admin/', path.join(F.path.private(), 'admin'));
framework_utils.ls(framework.isWindows ? filename.replace(/\//g, '\\') : filename, function(files) {
console.log(files); // output = [ 'D:\\totaljs-beta\\private\\admin\\app.js' ]
self.routes.mapping[key] = plus + files[i];
console.log(key + ' = ' + plus + files[i]);
// output = /admin/D:/totaljs-beta/private/admin/app.js = D:/totaljs-beta/private/admin/app.js
I have found a problem in total.js documentation.
// This must works:
F.map('/admin/', F.path.private('admin'));
The problem is in the paths between Windows and Unix. For mapping that will work you must use F.path object. Please try it and I must change the documentation.
Cool i didn't realize i can use F.path.private('admin') instead of path.join(F.path.private(), 'admin')
I'll read docs more carefuly next time!
However it still isn't possible to use
F.map('/admin/', F.path.root('admin'));
since it will create mapping to /admin/D:/totaljs-beta/admin/app.js
and
F.map('/admin/', '/admin/');
doesn't work with the leading slash. only working is
F.map('/admin/', 'admin');
Notice about this in docs would be cool. Thanks.
EDIT
I have following folders
/admin
/private/admin
and i tried this
console.log(F.path.private('admin')); // D:/totaljs-beta/private/admin
console.log(F.path.root('admin')); // D:\totaljs-beta\admin
F.path.private returns forward slashes and F.path.root returns backslashes which is inconsistent and probably causes some problems too.
I have published a new beta version (I have fixed paths). Please try it and give me a feedback.
Thanks
v1.9.3-25
F.map('/admin/', '/admin/');
doesn't work in windows, framework_utils.ls returns empty array
the leading slash is the problem, following works ok
F.map('/admin/', 'admin/');
also the framework.isWindows check doesn't seem to have any effect in
framework_utils.ls(framework.isWindows ? filename.replace(/\//g, '\\') : filename...
this
framework_utils.ls(filename...
works ok
Hi @molda,
please try it again npm install total.js@beta. Thanks.
Great, it seems to work s expected now
and one more thing :)
in map function following check
// Checks if the directory exists
if (!isPackage && !filename.startsWith(directory)) {
will not work as expected (again windows only) since in my case directory = D:\totaljs-beta //back slash and filename = D:/totaljs-beta/private/admin // forward slashes
Thanks a lot
@molda I have published a new beta version. Can you test it on your computer? I have only the virtual pc and my view can be wrong.
Thanks!
v1.9.3-27
Cool, both variables directory and filename now have forward slashes
Thanks
Great, thanks!