2 Copyright (c) 2012, Yahoo! Inc. All rights reserved.
3 Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
6 //EXPERIMENTAL code: do not rely on this in anyway until the docs say it is allowed
8 var path = require('path'),
9 yuiRegexp = /yui-nodejs\.js$/;
11 module.exports = function (matchFn, transformFn, verbose) {
12 return function (file) {
13 if (!file.match(yuiRegexp)) {
16 var YMain = require(file),
23 loaderFn = YUI.Env && YUI.Env.mods && YUI.Env.mods['loader-base'] ? YUI.Env.mods['loader-base'].fn : null;
24 if (!loaderFn) { return; }
25 if (verbose) { console.log('Applying YUI load post-hook'); }
26 YUI.Env.mods['loader-base'].fn = function (Y) {
27 loaderFn.call(null, Y);
28 origGet = Y.Get._exec;
29 Y.Get._exec = function (data, url, cb) {
30 if (matchFn(url) || matchFn(path.resolve(url))) { //allow for relative paths as well
32 console.log('Transforming [' + url + ']');
35 data = transformFn(data, url);
37 console.error('Error transforming: ' + url + ' return original code');
38 console.error(ex.message || ex);
39 if (ex.stack) { console.error(ex.stack); }
42 return origGet.call(Y, data, url, cb);