Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-yui

Package Overview
Dependencies
Maintainers
6
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-yui - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

lib/loader-patch.js

23

HISTORY.md

@@ -7,5 +7,28 @@ Express YUI Change History

1.1.0 (2014-01-21)
------------------
* add api to allow patching the YUI instance before the loader `use` statement
* `app.yui.patchServer(patchFn)` for patching the server instance
* `app.yui.patchClient(patchFn)` for patching the client instance
* `app.yui.patch(patchFn, anotherFn)` for patching both the client and server instances
* all default patches are accesible thru: `require('express-yui/lib/patches/optional-requires')`
* add default `logLevel` to be `warn` by default to avoid
the masive amount of logs from yui core modules.
## Important (non-backward compatible) changes:
* __[!]__ Patches for loader to support `templates: []` and `Y.Template.get()` are disabled by default.
* __[!]__ Patches for loader to support `langBundles: []` and `Y.Intl.get()` are disabled by default.
* __[!]__ Patches for loader to support `optionalRequires: []` is disabled by default.
1.0.1 (2013-12-04)
------------------
* add debugging messages to log when name collision happens while express-yui tries to add those modules into clientModules or serverModules collection.
* PR #38: Fix jshint npm script to work on Windows
* Fix early calls of `flush()` inside of the bootstrap code. ([#41][])
[#41]: https://github.com/yahoo/express-yui/issues/41
1.0.0 (2013-10-26)

@@ -12,0 +35,0 @@ ------------------

59

lib/client.js

@@ -87,52 +87,2 @@ /*

function patchLoader() {
var Y = self._Y,
getRequires = Y.Env._loader.getRequires;
Y.Env._loader.getRequires = function (mod) {
var i, m, lang;
if (!mod) {
return [];
}
if (mod._parsed) {
return mod.expanded || [];
}
mod.requires = mod.requires || [];
// expanding requirements with templates
if (mod.templates) {
for (i = 0; i < mod.templates.length; i += 1) {
m = this.getModule(mod.group + '-template-' + mod.templates[i]);
if (m) {
mod.requires.push(m.name);
}
}
}
// expanding requirements with lang bundles
if (mod.langBundles) {
lang = (Y.config.lang && Y.config.lang[0]) || Y.config.lang || 'en'; // TODO: nasty hack
for (i = 0; i < mod.langBundles.length; i += 1) {
m = this.getModule(mod.group + '-lang-' + mod.langBundles[i] + '_' + Y.config.lang);
if (m) {
mod.requires.push(m.name);
} else {
// trying to use the generic lang
m = this.getModule(mod.group + '-lang-' + mod.langBundles[i]);
if (m) {
mod.requires.push(m.name);
}
}
}
}
// expanding requirements with optional requires
if (mod.optionalRequires) {
for (i = 0; i < mod.optionalRequires.length; i += 1) {
m = this.getModule(mod.optionalRequires[i]);
if (m) {
mod.requires.push(m.name);
}
}
}
return getRequires.apply(this, arguments);
};
}
function load() {

@@ -165,2 +115,4 @@ if (!config.seed) {

callback.push(function () {
var i;
if (!self._Y) {

@@ -172,3 +124,8 @@ // extend core (YUI_config.extendedCore)

self.use = self._Y.use;
patchLoader();
if (config.patches && config.patches.length) {
for (i = 0; i < config.patches.length; i += 1) {
config.patches[i](self._Y);
}
}
}

@@ -175,0 +132,0 @@ // call use for arguments

@@ -151,3 +151,3 @@ /*

if (config.seed && config.seed.length > 0) {
console.warn('YUI seed has already been set, and you could ' +
debug('YUI seed has already been set, and you could ' +
'potentially be overwriting the default: ' +

@@ -154,0 +154,0 @@ config.seed.join(', '));

@@ -102,117 +102,2 @@ /*

/**
Patches `Y.Loader` to support `optionalRequires`, which enables you
to require modules that might not be available in a runtime, and avoid
to throw when that happens.
@method _patchLoader
@protected
**/
_patchLoader: function () {
var getRequires = this._Y.Env._loader.getRequires;
this._Y.Env._loader.getRequires = function (mod) {
var i, m;
if (!mod) {
return [];
}
if (mod._parsed) {
return mod.expanded || [];
}
mod.requires = mod.requires || [];
// expanding requirements with optional requires
if (mod.optionalRequires) {
for (i = 0; i < mod.optionalRequires.length; i += 1) {
m = this.getModule(mod.optionalRequires[i]);
if (m) {
mod.requires.push(m.name);
}
}
}
// mod.templates and mod.langBundles are not used on the server side
return getRequires.apply(this, arguments);
};
},
/**
Patches `Y.Template.get` to use the templates produced by
`locator-handlebars` or any other similar plugin, and will be available thru locator's bundle
objects.
@method _patchTemplate
@protected
**/
_patchTemplate: function () {
// monkey patching Y.Template
var locator = this._app.get('locator'),
// looking in the root bundle (hermes has only one bundle)
// that's the most common use-case where the app bundle holds all templates
rootBundle = locator.getRootBundle(),
originalTemplateGet = this._Y.use('template-base').Template.get;
this._Y.Template.get = function (name) {
var pos = name.indexOf('/'),
bundleName,
bundle,
template = name;
if (pos > 0) {
bundleName = name.slice(0, pos);
template = name.slice(pos + 1, name.length);
}
bundle = bundleName ? locator.getBundle(bundleName) : rootBundle;
if (bundle.template && bundle.template[template]) {
return bundle.template[template];
}
// if the template is not in the specified bundle, look for a global/root template
if (bundle !== rootBundle && rootBundle.template && rootBundle.template[name]) {
return rootBundle.template[name];
}
// falling back to the original implementation
return originalTemplateGet.apply(this, arguments);
};
},
/**
Patches `Y.Intl.get` to use the language bundles produced by
`locator-lang` plugin, and will be available thru locator's bundle
objects.
@method _patchIntl
@protected
**/
_patchIntl: function () {
// monkey patching Y.Intl
var locator = this._app.get('locator'),
// looking in the root bundle (hermes has only one bundle)
// that's the most common use-case where the app bundle holds all lang bundles
rootBundle = locator.getRootBundle(),
originalInltGet = this._Y.use('intl').Intl.get;
this._Y.Intl.get = function (name, key, lang) {
var pos = name.indexOf('/'),
bundleName,
bundle,
langBundle = name;
function output(entries) {
// returning a specific key or all entries (todo: should be make a copy?)
return (key ? entries[key] : entries);
}
if (pos > 0) {
bundleName = name.slice(0, pos);
langBundle = name.slice(pos + 1, name.length);
}
bundle = bundleName ? locator.getBundle(bundleName) : rootBundle;
if (bundle.lang && bundle.lang[lang] && bundle.lang[lang][langBundle]) {
return output(bundle.lang[lang][langBundle]);
}
// if the lang bundle is not in the specified bundle, look for a global/root lang bundle
if (bundle !== rootBundle && rootBundle.lang && rootBundle.lang[lang] && rootBundle.lang[lang][name]) {
return output(rootBundle.lang[lang][name]);
}
// fallbacking back to the original implementation
return originalInltGet.apply(this, arguments);
};
},
/**
Waits for the app to be ready, including the YUI instance to notify back that the

@@ -312,6 +197,9 @@ `ready` state of the app was reached by calling the `callback`. The ready state is

});
// patching Y
this._patchLoader();
this._patchTemplate();
this._patchIntl();
// patching serverside Y
if (this._patches && this._patches.length) {
this._patches.forEach(function (patch) {
patch(Y);
}, this);
}
}

@@ -318,0 +206,0 @@

@@ -21,2 +21,3 @@ /*

server = require('./server'),
patch = require('./loader-patch'),

@@ -27,2 +28,3 @@ // utilities

/**

@@ -104,2 +106,8 @@ The `express-yui/lib/yui` exports the class used to create the `app.yui`

this.setCoreFromCDN();
// Default clientside patches
this._config.patches = [];
// Default serverside patches
this._patches = [];
}

@@ -181,2 +189,3 @@

filter: (utils.debugMode ? 'debug' : 'min'),
logLevel: (utils.debugMode ? 'warn' : 'error'),
combine: !utils.debugMode

@@ -191,4 +200,4 @@ }, loaderConfig);

utils.extend(YUIClass.prototype, seed, origin, server);
utils.extend(YUIClass.prototype, seed, origin, server, patch);
module.exports = YUIClass;
{
"name": "express-yui",
"description": "Express extension for YUI Applications",
"version": "1.0.1",
"version": "1.1.0",
"homepage": "https://github.com/yahoo/express-yui",

@@ -6,0 +6,0 @@ "author": "Caridy Patino <caridy@yahoo-inc.com> (http://github.com/caridy)",

@@ -257,4 +257,4 @@ Express YUI

See the [CONTRIBUTE file][] for info.
See the [CONTRIBUTING file][] for info.
[CONTRIBUTE file]: https://github.com/yahoo/express-yui/blob/master/CONTRIBUTE.md
[CONTRIBUTING file]: https://github.com/yahoo/express-yui/blob/master/CONTRIBUTING.md
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc