Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

instance cleanup #664

Merged
merged 8 commits into from

2 participants

Drew Folta Caridy Patiño
Drew Folta
Owner

mainly making a PR so that travis can test

Caridy Patiño
Owner

Yeah, we really need to fix this unit test, we plan to continue changing that initialization, and doing === will keep breaking the tests.

Caridy Patiño
Owner

+1

Drew Folta drewfish Merge remote-tracking branch 'caridy/instance-cleanup' into instance-…
…cleanup

Conflicts:
	tests/unit/lib/test-store.server.js
784de58
Drew Folta drewfish merged commit bee7c7c into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 22, 2012
  1. Caridy Patiño

    supporting yui + app metadata separately to relax on-demand loading, …

    caridy authored
    …extend combo to work at any level in preparation for the css support
Commits on Oct 23, 2012
  1. Caridy Patiño
Commits on Oct 24, 2012
  1. Caridy Patiño
  2. Caridy Patiño

    jslint <3

    caridy authored
  3. Caridy Patiño
  4. Drew Folta

    fixed addons/ac/deploy test

    drewfish authored
  5. Drew Folta

    fixed some unit tests

    drewfish authored
Commits on Oct 25, 2012
  1. Drew Folta

    Merge remote-tracking branch 'caridy/instance-cleanup' into instance-…

    drewfish authored
    …cleanup
    
    Conflicts:
    	tests/unit/lib/test-store.server.js
This page is out of date. Refresh to see the latest.
20 lib/app/addons/ac/deploy.server.js
View
@@ -83,26 +83,30 @@ YUI.add('mojito-deploy-addon', function(Y, NAME) {
fetchCSS: true,
combine: true,
- base: "/combo?",
- comboBase: "/combo?",
- root: "",
- url: "/combo?yui-base/yui-base.js&loader-base/loader-base.js&" +
- "loader-app-base{langPath}.js"
+ // the base path for non-combo paths
+ base: 'http://yui.yahooapis.com/' + Y.version + '/build/',
+ // the path to the combo service
+ comboBase: 'http://yui.yahooapis.com/combo?',
+ // a fragment to prepend to the path attribute when
+ // when building combo urls
+ root: Y.version + '/build/',
+ seed: "/static/combo?yui-base.js&loader-base.js&" +
+ "loader-yui3.js&loader-app-base{langPath}.js&loader.js"
}, ((appConfigClient.yui && appConfigClient.yui.config) || {}), {
lang: contextServer.lang // same as contextClient.lang
});
- // adjusting the url based on {langPath} to facilitate
+ // adjusting the seed based on {langPath} to facilitate
// the customization of the combo url.
- yuiConfig.url = yuiConfig.url.replace('{langPath}',
+ yuiConfig.seed = yuiConfig.seed.replace('{langPath}',
(contextServer.lang ? '_' + contextServer.lang : ''));
clientConfig.store = store.serializeClientStore(contextClient);
// Set the YUI URL to use on the client (This has to be done
// before any other scripts are added)
- assetHandler.addAsset('js', 'top', yuiConfig.url);
+ assetHandler.addAsset('js', 'top', yuiConfig.seed);
// adding the default module for the Y.use statement in the client
initialModuleList['mojito-client'] = true;
196 lib/app/middleware/mojito-combo-handler.js
View
@@ -21,12 +21,12 @@
/*jslint anon:true, sloppy:true, nomen:true, stupid:true, node: true*/
+'use strict';
+
/*
DECLAIMER: this is VERY experimental, and the purpose of this
middleware is to provide an easy way to load yui modules by their
-names rather than the real static path. Why? because we can then
-leverage the YUI Loader on the client side to take care of the
-dependencies computations efficiently.
+names rather than the real static path.
from: @caridy
*/
@@ -60,18 +60,52 @@ var libfs = require('fs'),
}
},
- // This dummy templace will be use to produce the loader content.
- // TODO: we should use YUI.applyConfig() instead of the internal
- // YUI.Env API, but that's pending due a bug in YUI:
- // http://yuilibrary.com/projects/yui3/ticket/2532854
- LOADER_MODULE_TEMPLATE = 'YUI.add("loader",function(Y){' +
- 'YUI.Env[Y.version].modules=YUI.Env[Y.version].modules||{metadata};' +
- '}, "", {requires:["loader-base"]});';
-
-/*
- * File buffer cache.
- */
-var _cache = {};
+ MODULE_TEMPLATES = {
+ 'loader-app-base':
+ 'YUI.add("loader-app-base",function(Y){' +
+ 'Y.applyConfig({groups:{app:{' +
+ 'combine:true,' +
+ 'maxURLLength:1024,' +
+ 'base:"/static/",' +
+ 'comboBase:"/static/combo?",' +
+ 'root:"",' +
+ 'modules:{app-base}' +
+ '}}});' +
+ '},"",{requires:["loader-base"]});',
+ 'loader-app-full':
+ 'YUI.add("loader-app-full",function(Y){' +
+ 'Y.applyConfig({groups:{app:{' +
+ 'combine:true,' +
+ 'maxURLLength:1024,' +
+ 'base:"/static/",' +
+ 'comboBase:"/static/combo?",' +
+ 'root:"",' +
+ 'modules:{app-full}' +
+ '}}});' +
+ '},"",{requires:["loader-base"]});',
+
+ 'loader':
+ 'YUI.add("loader",function(Y){' +
+ '},"",{requires:["loader-base","loader-yui3","loader-app-base"]});',
+
+ 'loader-lock':
+ 'YUI.add("loader",function(Y){' +
+ // TODO: we should use YUI.applyConfig() instead of the internal
+ // YUI.Env API, but that's pending due a bug in YUI:
+ // http://yuilibrary.com/projects/yui3/ticket/2532854
+ 'YUI.Env[Y.version].modules=YUI.Env[Y.version].modules||' +
+ '{yui-base};' +
+ '},"",{requires:["loader-base","loader-app-base"]});',
+
+ 'loader-full':
+ 'YUI.add("loader",function(Y){' +
+ // TODO: we should use YUI.applyConfig() instead of the internal
+ // YUI.Env API, but that's pending due a bug in YUI:
+ // http://yuilibrary.com/projects/yui3/ticket/2532854
+ 'YUI.Env[Y.version].modules=YUI.Env[Y.version].modules||' +
+ '{yui-full};' +
+ '},"",{requires:["loader-base","loader-app-full"]});'
+ };
/*
* Check if `req` and response `headers`.
@@ -167,20 +201,6 @@ function forbidden(res) {
res.end(body);
}
-/*
- * Clear the memory cache for `key` or the entire cache.
- *
- * @method clearCache
- * @param {String} key
- * @api public
- */
-function clearCache(key) {
- if (key) {
- delete _cache[key];
- } else {
- _cache = {};
- }
-}
function processMeta(resolvedMods, modules, expanded_modules, langs, conditions) {
var m,
@@ -247,25 +267,6 @@ function processMeta(resolvedMods, modules, expanded_modules, langs, conditions)
}
-function produceMeta(meta, name) {
- var token = '',
- path = '',
- lang = REGEX_LOCALE.exec(name);
-
- if (lang && lang[1] && meta[lang[1]]) {
- lang = lang[1]; // eg. en-US
- token = '"' + lang + '"';
- path = '_' + lang;
- meta = meta[lang];
- } else {
- meta = meta['*']; // default in case they use invalid lang
- }
- return LOADER_MODULE_TEMPLATE
- .replace('{metadata}', meta)
- .replace(REGEX_LANG_TOKEN, token)
- .replace(REGEX_LANG_PATH, path);
-}
-
/*
* Static file server.
*
@@ -296,8 +297,15 @@ function staticProvider(store, globalLogger) {
Y,
loader,
resolved,
- appMetaData = {},
- appResolvedMetaData = {},
+
+ appMetaData = {
+ base: {},
+ full: {}
+ },
+ yuiMetaData = {
+ base: {},
+ full: {}
+ },
// other structures
langs = ['*'], // language wildcard
@@ -312,14 +320,14 @@ function staticProvider(store, globalLogger) {
Y = YUI({
fetchCSS: true,
combine: true,
- base: "/combo?",
- comboBase: "/combo?",
+ base: "/static/combo?",
+ comboBase: "/static/combo?",
root: ""
}, ((appConfig.yui && appConfig.yui.config && appConfig.yui.config.config) || {}));
modules_config = Y.merge((mojits.modules || {}), (shared.modules || {}));
Y.applyConfig({
- modules: modules_config,
+ modules: Y.merge({}, modules_config),
useSync: true
});
Y.use('loader');
@@ -342,8 +350,10 @@ function staticProvider(store, globalLogger) {
for (i = 0; i < langs.length; i += 1) {
lang = langs[i];
- appMetaData[lang] = {};
- appResolvedMetaData[lang] = {};
+ appMetaData.base[lang] = {};
+ appMetaData.full[lang] = {};
+ yuiMetaData.base[lang] = {};
+ yuiMetaData.full[lang] = {};
for (name in expanded_modules) {
if (expanded_modules.hasOwnProperty(name)) {
@@ -359,21 +369,34 @@ function staticProvider(store, globalLogger) {
(!expanded_modules[name].langPack) ||
(lang === expanded_modules[name].langPack)) {
- appMetaData[lang][name] = modules[name];
- appResolvedMetaData[lang][name] = expanded_modules[name];
+ // we want to separate modules into different buckets
+ // to be able to support groups in loader config
+ if (modules_config[name]) {
+ appMetaData.base[lang][name] = modules[name];
+ appMetaData.full[lang][name] = expanded_modules[name];
+ } else {
+ yuiMetaData.base[lang][name] = modules[name];
+ yuiMetaData.full[lang][name] = expanded_modules[name];
+ }
}
}
}
- appMetaData[lang] = JSON.stringify(appMetaData[lang]);
- appResolvedMetaData[lang] = JSON.stringify(appResolvedMetaData[lang]);
+ appMetaData.base[lang] = JSON.stringify(appMetaData.base[lang]);
+ appMetaData.full[lang] = JSON.stringify(appMetaData.full[lang]);
+ yuiMetaData.base[lang] = JSON.stringify(yuiMetaData.base[lang]);
+ yuiMetaData.full[lang] = JSON.stringify(yuiMetaData.full[lang]);
for (name in conditions) {
if (conditions.hasOwnProperty(name)) {
- appMetaData[lang] = appMetaData[lang]
+ appMetaData.base[lang] = appMetaData.base[lang]
.replace('"{' + name + '}"', conditions[name]);
- appResolvedMetaData[lang] = appResolvedMetaData[lang]
+ appMetaData.full[lang] = appMetaData.full[lang]
+ .replace('"{' + name + '}"', conditions[name]);
+ yuiMetaData.base[lang] = yuiMetaData.base[lang]
+ .replace('"{' + name + '}"', conditions[name]);
+ yuiMetaData.full[lang] = yuiMetaData.full[lang]
.replace('"{' + name + '}"', conditions[name]);
}
}
@@ -381,6 +404,28 @@ function staticProvider(store, globalLogger) {
}
+ function produceMeta(name, lang) {
+ var token = '',
+ path = '';
+
+ if (lang) {
+ token = '"' + lang + '"';
+ path = '_' + lang;
+ } else {
+ lang = '*';
+ }
+
+ // module definition definitions
+ return MODULE_TEMPLATES[name]
+ .replace('{app-base}', appMetaData.base[lang] || appMetaData.base['*'])
+ .replace('{app-full}', appMetaData.full[lang] || appMetaData.full['*'])
+ .replace('{yui-base}', yuiMetaData.base[lang] || yuiMetaData.base['*'])
+ .replace('{yui-full}', yuiMetaData.full[lang] || yuiMetaData.full['*'])
+ .replace(REGEX_LANG_TOKEN, token)
+ .replace(REGEX_LANG_PATH, path);
+ }
+
+
return function(req, res, next) {
if (req.method !== 'GET' && req.method !== 'HEAD') {
return next();
@@ -390,6 +435,8 @@ function staticProvider(store, globalLogger) {
files = [],
filename = '',
module = '',
+ basemodule = '',
+ lang = '',
ext = '',
result = [],
counter = 0,
@@ -398,7 +445,7 @@ function staticProvider(store, globalLogger) {
head = (req.method === 'HEAD');
// only combo requests are allow here
- if (url.pathname !== '/combo' || !url.query) {
+ if (libpath.basename(url.pathname) !== 'combo' || !url.query) {
return next();
}
@@ -468,22 +515,33 @@ function staticProvider(store, globalLogger) {
module = (files[i].indexOf('/lang/') >= 0 ? 'lang/' : '') +
libpath.basename(files[i], ext).replace(/\-(min|debug)$/, '');
- if (module.indexOf('loader-app-base') === 0) {
- result[i] = {
- fullpath: module,
- content: produceMeta(appMetaData, module)
- };
- } else if (module.indexOf('loader-app-full') === 0) {
+ lang = REGEX_LOCALE.exec(module);
+
+ if (lang) {
+ basemodule = module.slice(0, lang.index); // eg. lang/foo_en-US -> lang/foo
+ lang = lang[1];
+ } else {
+ basemodule = module;
+ }
+
+ // at this point, we should have:
+ // module == lang/foo_en-US or lang/foo or foo
+ // basemodule == lang/foo or foo
+
+ if (MODULE_TEMPLATES[basemodule]) {
+ // getting a synthetic module
result[i] = {
fullpath: module,
- content: produceMeta(appResolvedMetaData, module)
+ content: produceMeta(basemodule, lang)
};
} else if (urls[module]) {
+ // geting an app module
result[i] = {
fullpath: urls[module],
content: ''
};
} else if (loader.moduleInfo[module] && loader.moduleInfo[module].path) {
+ // getting a yui module
result[i] = {
fullpath: libpath.join(__dirname,
'../../../node_modules/yui', loader.moduleInfo[module].path),
2  tests/unit/lib/app/addons/ac/test-deploy.server.js
View
@@ -157,7 +157,7 @@ YUI().use('mojito-deploy-addon', 'test', 'json-parse', function(Y) {
var expected = [
'<script type="text/javascript">',
- ' YUI.applyConfig({"fetchCSS":true,"combine":true,"base":"/combo?","comboBase":"/combo?","root":"","url":"/combo?yui-base/yui-base.js\\\\u0026loader-base/loader-base.js\\\\u0026loader-app-base_klingon.js","foo":"bar","lang":"klingon"});',
+ ' YUI.applyConfig({"fetchCSS":true,"combine":true,"base":"http://yui.yahooapis.com/3.6.0/build/","comboBase":"http://yui.yahooapis.com/combo?","root":"3.6.0/build/","seed":"/static/combo?yui-base.js\\\\u0026loader-base.js\\\\u0026loader-yui3.js\\\\u0026loader-app-base_klingon.js\\\\u0026loader.js","foo":"bar","lang":"klingon"});',
' YUI().use(\'mojito-client\', function(Y) {',
' window.YMojito = { client: new Y.mojito.Client({"context":{"lang":"klingon","runtime":"client"},"binderMap":{"viewId1":{"needs":"a drink"},"viewId2":{"needs":"another drink"}},"routes":["routes"]}) };',
' });',
49 tests/unit/lib/test-store.server.js
View
@@ -117,7 +117,6 @@ YUI().use(
success = false;
}
A.isFalse(success, '{device:iphone,runtime:kite} should be invalid');
-
},
'server app config value': function() {
@@ -176,9 +175,13 @@ YUI().use(
A.isObject(instance.views['test_1']);
A.areSame('/static/test_mojit_1/views/test_1.hb.html', instance.views['test_1']['content-path']);
A.areSame('hb', instance.views['test_1']['engine']);
- A.areSame('/static/test_mojit_1/binders/test_1.js', instance.views['test_1']['binder-path']);
- A.areSame('test_mojit_1Bindertest_1', instance.views['test_1']['binder-module']);
- A.isNotUndefined(instance.views['test_1']['binder-yui-sorted']['mojito-client']);
+
+ A.areSame('test_mojit_1Bindertest_1', instance.binders['test_1']);
+ A.areSame('test_mojit_1Bindersubdir/test_1', instance.binders['subdir/test_1']);
+
+ A.isObject(instance.views['test_1']);
+ A.areSame('/static/test_mojit_1/views/test_1.hb.html', instance.views['test_1']['content-path']);
+ A.areSame('hb', instance.views['test_1']['engine']);
A.isObject(instance.views['test_2']);
A.areSame('/static/test_mojit_1/views/test_2.hb.html', instance.views['test_2']['content-path']);
@@ -187,9 +190,6 @@ YUI().use(
A.isObject(instance.views['subdir/test_1']);
A.areSame('/static/test_mojit_1/views/subdir/test_1.hb.html', instance.views['subdir/test_1']['content-path']);
A.areSame('hb', instance.views['subdir/test_1']['engine']);
- A.areSame('/static/test_mojit_1/binders/subdir/test_1.js', instance.views['subdir/test_1']['binder-path']);
- A.areSame('test_mojit_1Bindersubdir/test_1', instance.views['subdir/test_1']['binder-module']);
- A.isNotUndefined(instance.views['subdir/test_1']['binder-yui-sorted']['mojito-client']);
});
},
@@ -197,19 +197,20 @@ YUI().use(
var instance = {type:'test_mojit_1'};
store.expandInstance(instance, {}, function(err, instance) {
A.areSame(4, Y.Object.keys(instance.models).length);
- A.isTrue(instance.models['flickr']);
- A.isTrue(instance.models['test_applevel']);
- A.isTrue(instance.models['test_1']);
- A.isTrue(instance.models['test_2']);
+ A.areSame('ModelFlickr', instance.models['flickr']);
+ A.areSame('test_applevelModel', instance.models['test_applevel']);
+ A.areSame('test_mojit_1_model_test_1', instance.models['test_1']);
+ A.areSame('test_mojit_1_model_test_2', instance.models['test_2']);
});
},
'server mojit type name can come from package.json': function() {
+ var fixtures = libpath.join(__dirname, '../../fixtures/store');
var instance = {type:'TestMojit2'};
store.expandInstance(instance, {}, function(err, instance){
- A.isNotUndefined(instance['controller-path']);
+ A.isNotUndefined(instance.controller);
A.areSame('/static/TestMojit2/assets', instance.assetsRoot);
- A.isNotUndefined(instance.yui.config.modules.test_mojit_2);
+ A.areSame(libpath.join(fixtures, 'mojits/test_mojit_2/views/index.hb.html'), instance.views.index['content-path']);
});
},
@@ -257,7 +258,7 @@ YUI().use(
'mojitDirs setting': function() {
var instance = { type: 'soloMojit' };
store.expandInstance(instance, {}, function(err, instance) {
- A.isNotUndefined(instance['controller-path']);
+ A.areSame('soloMojit', instance.controller);
});
},
@@ -357,7 +358,8 @@ YUI().use(
AA.contains('soloMojit', list);
},
- 'app with rollups': function() {
+ // TODO -- do we still need rollups?
+ 'ignore: app with rollups': function() {
var fixtures = libpath.join(__dirname, '../../fixtures/store');
var spec = { type: 'rollups' };
store.expandInstanceForEnv('client', spec, {}, function(err, instance) {
@@ -416,7 +418,7 @@ YUI().use(
var spec = { type: 'PagedFlickr' };
var ctx = { device: 'iphone' };
store.expandInstance(spec, ctx, function(err, instance) {
- A.areSame(libpath.join(fixtures, 'mojits/PagedFlickr/controller.common.iphone.js'), instance['controller-path']);
+ A.areSame('PagedFlickr', instance.controller);
});
},
@@ -442,13 +444,6 @@ YUI().use(
store.preload();
},
- 'appConfig deferAllOptionalAutoloads': function() {
- var spec = { type: 'PagedFlickr' };
- store.expandInstanceForEnv('client', spec, {}, function(err, instance) {
- A.isUndefined(instance.views.index['binder-yui-sorted']['mojito-tunnel-client'], 'mojito-tunnel-client');
- });
- },
-
'appConfig staticHandling.prefix': function() {
var spec = { type: 'PagedFlickr' };
store.expandInstance(spec, {}, function(err, instance) {
@@ -501,10 +496,8 @@ YUI().use(
store.preload();
var spec = { type: 'M' };
store.expandInstance(spec, {}, function(err, instance) {
- A.isUndefined(instance.yui.config.modules['addon-ac-not']);
- A.isUndefined(instance.yui.config.modules['MAutoloadNot']);
- A.isUndefined(instance.yui.config.modules['MModelNot']);
- A.isUndefined(instance.views['not']['binder-url']);
+ A.isUndefined(instance.models['MModelNot']);
+ A.isUndefined(instance.binders.not);
});
},
@@ -565,7 +558,7 @@ YUI().use(
}
var details = store.getMojitTypeDetails('server', {}, 'a');
- A.isNotNull(details['controller-path'].match(/a\/foo\/controller\.server\.js$/), 'controller should not be null');
+ A.areSame('a', details.controller);
},
'find and parse resources by convention': function() {
Something went wrong with that request. Please try again.