Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

making mojito to work on windows #1103

Merged
merged 14 commits into from
May 17, 2013
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/app/addons/rs/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ YUI.add('addon-rs-url', function(Y, NAME) {
var libfs = require('fs'),
liburl = require('url'),
libpath = require('path'),
libutil = require('../../../util.js'),
existsSync = libfs.existsSync || libpath.existsSync,
URL_PARTS = ['frameworkName', 'appName', 'prefix'],
// TODO: needs a more future-proof way to do this
Expand Down Expand Up @@ -152,7 +153,7 @@ YUI.add('addon-rs-url', function(Y, NAME) {
var env = evt.args.env,
mojitRes = evt.args.mojitRes,
details = evt.mojitDetails;
details.assetsRoot = mojitRes.url + '/assets';
details.assetsRoot = libutil.webpath(mojitRes.url, 'assets');
},


Expand Down Expand Up @@ -182,7 +183,7 @@ YUI.add('addon-rs-url', function(Y, NAME) {
// in conjuntion with "base", "comboBase" and "root"
// from application.json->yui->config
urlParts.push(res.yui.name + '.js');
res.url = urlParts.join('/');
res.url = libutil.webpath(urlParts);
return;
}

Expand Down Expand Up @@ -212,13 +213,13 @@ YUI.add('addon-rs-url', function(Y, NAME) {

if ('mojit' === res.type) {
if ('shared' !== res.name) {
res.url = urlParts.join('/');
res.url = libutil.webpath(urlParts);
}
return;
}

urlParts.push(relativePath);
res.url = urlParts.join('/');
res.url = libutil.webpath(urlParts);
}


Expand Down
8 changes: 4 additions & 4 deletions lib/app/addons/rs/yui.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ YUI.add('addon-rs-yui', function(Y, NAME) {
libvm = require('vm'),
libmime = require('mime'),
liburl = require('url'),
libutil = require('../../../util.js'),

WARN_SERVER_MODULES = /\b(dom-[\w\-]+|node-[\w\-]+|io-upload-iframe)/ig,
MODULE_SUBDIRS = {
Expand Down Expand Up @@ -130,7 +131,6 @@ YUI.add('addon-rs-yui', function(Y, NAME) {
'},"",{requires:["loader-base"]});'
};


function RSAddonYUI() {
RSAddonYUI.superclass.constructor.apply(this, arguments);
}
Expand Down Expand Up @@ -163,7 +163,7 @@ YUI.add('addon-rs-yui', function(Y, NAME) {

this.staticAppConfig = config.host.getStaticAppConfig() || {};
this.staticHandling = this.staticAppConfig.staticHandling || {};
this.staticPrefix = libpath.join('/', (this.staticHandling.prefix || 'static'), "/");
this.staticPrefix = libutil.webpath('/', (this.staticHandling.prefix || 'static'), "/");
this.yuiConfig = (this.staticAppConfig.yui && this.staticAppConfig.yui.config) || {};
this.langs = {}; // keys are list of languages in the app, values are simply "true"
this.resContents = {}; // res.id: contents
Expand Down Expand Up @@ -253,7 +253,7 @@ YUI.add('addon-rs-yui', function(Y, NAME) {
*/
getYUIConfig: function(ctx) {
var version = Y.version,
yuiPrefix = libpath.join(this.staticPrefix, 'yui/'),
yuiPrefix = libutil.webpath(this.staticPrefix, 'yui/'),
appConfig = this.get('host').getAppConfig(ctx),
yuiConfig;

Expand Down Expand Up @@ -779,7 +779,7 @@ YUI.add('addon-rs-yui', function(Y, NAME) {
modules[name] = store.makeStaticHandlerDetails({
type: 'yui-module',
name: name,
url: libpath.join(this.staticPrefix, 'yui', modules[name].path),
url: libutil.webpath(this.staticPrefix, 'yui', modules[name].path),
path: modules[name].path,
source: {
fs: {
Expand Down
32 changes: 11 additions & 21 deletions lib/app/autoload/store.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
'model': 'server',
'spec': 'common',
'view': 'common'
};
},
PATH_SEP = require('path').sep;

libs.fs = require('fs');
libs.glob = require('glob');
Expand Down Expand Up @@ -792,9 +793,7 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
for (p = 0; p < routesFiles.length; p += 1) {
path = routesFiles[p];
// relative paths are relative to the application
if ('/' !== path.charAt(1)) {
path = this._libs.path.join(this._config.root, path);
}
path = this._libs.path.resolve(this._config.root, path);
routes = this.config.readConfigYCB(path, ctx);
Y.mix(out, routes, true);
}
Expand Down Expand Up @@ -1035,7 +1034,7 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
rootDir: dir,
rootType: dirType,
subDir: subdir,
subDirArray: subdir.split('/'),
subDirArray: subdir.split(PATH_SEP),
isFile: isFile,
ext: this._libs.path.extname(file)
};
Expand Down Expand Up @@ -1344,7 +1343,7 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
Y.log('invalid ' + type + ' filename. skipping ' + fs.fullPath, 'warn', NAME);
return;
}
res.name = this._libs.path.join(fs.subDirArray.join('/'), baseParts.join('.'));
res.name = this._libs.path.join(fs.subDirArray.join(PATH_SEP), baseParts.join('.'));
res.id = [res.type, res.subtype, res.name].join('-');
// special case
if ('addon' === type && ADDON_SUBTYPES_APPLEVEL[res.subtype]) {
Expand All @@ -1370,7 +1369,7 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
Y.log('invalid ' + type + ' filename. skipping ' + fs.fullPath, 'warn', NAME);
return;
}
res.name = this._libs.path.join(fs.subDirArray.join('/'), baseParts.join('.'));
res.name = this._libs.path.join(fs.subDirArray.join(PATH_SEP), baseParts.join('.'));
res.id = [res.type, res.subtype, res.name].join('-');
return res;
}
Expand Down Expand Up @@ -1414,7 +1413,7 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
Y.log('invalid view filename. skipping ' + fs.fullPath, 'warn', NAME);
return;
}
res.name = this._libs.path.join(fs.subDirArray.join('/'), baseParts.join('.'));
res.name = this._libs.path.join(fs.subDirArray.join(PATH_SEP), baseParts.join('.'));
res.id = [res.type, res.subtype, res.name].join('-');
// for performance reasons, we might want to preload all
// views in memory.
Expand Down Expand Up @@ -1779,11 +1778,7 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
children,
childName,
childPath;

if ('/' !== dir.charAt(0)) {
dir = this._libs.path.join(this._config.root, dir);
}

dir = this._libs.path.resolve(this._config.root, dir);
if (!(this._libs.fs.existsSync || this._libs.path.existsSync)(dir)) {
return;
}
Expand Down Expand Up @@ -1817,10 +1812,7 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
ress,
r,
res;

if ('/' !== dir.charAt(0)) {
dir = this._libs.path.join(this._config.root, dir);
}
dir = this._libs.path.resolve(this._config.root, dir);

if (!(this._libs.fs.existsSync || this._libs.path.existsSync)(dir)) {
return;
Expand Down Expand Up @@ -1981,7 +1973,7 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
if ('object' === typeof ret) {
if (ret.skipSubdirParts) {
source.fs.subDirArray = source.fs.subDirArray.slice(ret.skipSubdirParts);
source.fs.subDir = source.fs.subDirArray.join('/') || '.';
source.fs.subDir = source.fs.subDirArray.join(PATH_SEP) || '.';
}
res = me.parseResourceVersion(source, ret.type, ret.subtype, mojitType);
if ('object' === typeof res) {
Expand Down Expand Up @@ -2095,9 +2087,7 @@ YUI.add('mojito-resource-store', function(Y, NAME) {
glob;
for (i = 0; i < list.length; i += 1) {
glob = list[i];
if ('/' !== glob.charAt(0)) {
glob = this._libs.path.join(prefix, glob);
}
glob = this._libs.path.resolve(prefix, glob);
found = found.concat(this._libs.glob.sync(glob, {}));
}
return found;
Expand Down
3 changes: 2 additions & 1 deletion lib/app/middleware/mojito-handler-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/
var liburl = require('url'),
libpath = require('path'),
libutil = require('../../util.js'),

NAME = 'StaticHandler';

Expand Down Expand Up @@ -177,7 +178,7 @@ function staticProvider(store, logger, Y) {
options = appConfig.staticHandling || {},
cache = options.cache,
maxAge = options.maxAge,
staticPath = liburl.resolve('/', (options.prefix || 'static') + '/'),
staticPath = libutil.webpath(liburl.resolve('/', (options.prefix || 'static') + '/')),
comboPath = '/combo~';

if (cache && !maxAge) {
Expand Down
6 changes: 4 additions & 2 deletions lib/app/middleware/mojito-handler-tunnel-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var RE_TRAILING_SLASHES = /\/+$/;
module.exports = function (config) {
var liburl = require('url'),
libpath = require('path'),
libutil = require('../../util.js'),
appConfig = config.store.getAppConfig({}) || {},
staticPrefix,
tunnelPrefix;
Expand All @@ -34,8 +35,9 @@ module.exports = function (config) {
tunnelPrefix = libpath.normalize('/' + tunnelPrefix);
}

staticPrefix = staticPrefix || '/static';
tunnelPrefix = tunnelPrefix || '/tunnel';
// normalizing the prefixes (this helps with windows runtime)
staticPrefix = libutil.webpath(staticPrefix || '/static');
tunnelPrefix = libutil.webpath(tunnelPrefix || '/tunnel');

return function (req, res, next) {
var hasTunnelPrefix = req.url.indexOf(tunnelPrefix) === 0,
Expand Down
38 changes: 38 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2013, Yahoo! Inc. All rights reserved.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/

/*jslint node:true, nomen: true */

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file might need a @module yuidoc section. (If missing I think its methods get added to the module in the previously processed file 😞 .)

'use strict';

var libpath = require('path');

/**
Produces a normalized web path by joining all the parts and normalizing the
filesystem-like path into web compatible url. This is useful when you have to
generate urls based on filesystem path where unix uses `/` and windows uses `\\`.
Node is pretty smart and it will do the heavy lifting, we just need to adjust
the separtor so it uses the `/`. This method also support relative and absolute
paths.

util.webpath('foo/bar' ,'baz');
// => foo/bar/baz
util.webpath('foo\\bar', 'baz/');
// => foo/bar/baz/
util.webpath('./foo/bar', './baz');
// => foo/bar/baz
util.webpath(['foo', 'bar', 'baz']);
// => foo/bar/baz

@method webpath
@param {Array|String*} url the list of parts to be joined and normalized
@return {String} The joined and normalized url
**/
exports.webpath = function (url) {
var args = [].concat.apply([], arguments),
parts = libpath.join.apply(libpath, args).split(libpath.sep);
return parts.join('/');
};