lib/modules.js
function translate(id, filename, buffer, options, next) {
	var ext = (filename.match(extexp) || [])[1] || '',
		encoding = options.encoding || exports.defaults.encoding,
		trans = options.translate, js, nowrap;

	// make a list of what not to wrap
	nowrap = options.nowrap || exports.defaults.nowrap;
	nowrap = [ 'define', 'define.min', 'define.shim' ].concat(nowrap);
	// should this code get wrapped with a define?
	nowrap = nowrap.some(function(no) {
		return no.test ? no.test(id) : (no === id);
	});

	// convert commonjs to amd
	function wrap(err, js) {
		if (err) { return next(err); }

		var deps = exports.dependencies(id, js), params = [], undef = '';

		// make sure require, exports, and module are properly passed into the factory
		if (/\brequire\b/.test(js)) { params.push('require'); }
		if (/\bexports\b/.test(js)) { params.push('exports'); }
		if (/\bmodule\b/.test(js)) { params.push('module'); }

		// make sure code follows the `exports` path instead of `define` path once wrapped
		if (/\bdefine\.amd\b/.test(js)) { undef = 'var define;'; }

		if (deps.length) {
			deps = ',' + JSON.stringify(params.concat(deps));
		} else if (params.length) {
			params = [ 'require', 'exports', 'module' ];
		}

		js = 'define(' + JSON.stringify(id) + deps + ',function(' + params + ')' +
				'{' + js + '\n' + undef + '}' + // rely on hoisting for define
			');\n';
		next(null, js);
	}

	// find the translate function
	trans = trans && (trans[filename] || trans[id] || trans[ext]);
	if (trans) { // user configured translation
		return trans(
			{ id:id, filename:filename, buffer:buffer },
			options, (nowrap ? next : wrap)
		);
	}

	js = buffer.toString(encoding);

	// handle javascript files
	if ('js' === ext) {
		return (nowrap ? next : wrap)(null, js);
	}

	// handle non-javascript files
	if ('json' !== ext) { js = JSON.stringify(js); } // export file as json string
	if (nowrap) { return next(null, 'return ' + js); }
	return next(null, 'define(' + JSON.stringify(id) + ',' + js + ');\n');
}
function translate(id, filename, buffer, options, next) {
	var ext = (filename.match(extexp) || [])[1] || '',
		encoding = options.encoding || exports.defaults.encoding,
		trans = options.translate, js, nowrap;

	// make a list of what not to wrap
	nowrap = options.nowrap || exports.defaults.nowrap;
	nowrap = [ 'define', 'define.min', 'define.shim' ].concat(nowrap);
	// should this code get wrapped with a define?
	nowrap = nowrap.some(function(no) {
		return no.test ? no.test(id) : (no === id);
	});

	// convert commonjs to amd
	function wrap(err, js) {
		if (err) { return next(err); }

		var deps = exports.dependencies(id, js), params = [], undef = '';

		// make sure require, exports, and module are properly passed into the factory
		if (/\brequire\b/.test(js)) { params.push('require'); }
		if (/\bexports\b/.test(js)) { params.push('exports'); }
		if (/\bmodule\b/.test(js)) { params.push('module'); }

		// make sure code follows the `exports` path instead of `define` path once wrapped
		if (/\bdefine\.amd\b/.test(js)) { undef = 'var define;'; }

		if (deps.length) {
			deps = ',' + JSON.stringify(params.concat(deps));
		} else if (params.length) {
			params = [ 'require', 'exports', 'module' ];
		}

		js = 'define(' + JSON.stringify(id) + deps + ',function(' + params + ')' +
				'{' + js + '\n' + undef + '}' + // rely on hoisting for define
			');\n';
		next(null, js);
	}

	// find the translate function
	trans = trans && (trans[filename] || trans[id] || trans[ext]);
	if (trans) { // user configured translation
		return trans(
			{ id:id, filename:filename, buffer:buffer },
			options, (nowrap ? next : wrap)
		);
	}

	js = buffer.toString(encoding);

	// handle javascript files
	if ('js' === ext) {
		return (nowrap ? next : wrap)(null, js);
	}

	// handle non-javascript files
	if ('json' !== ext) { js = JSON.stringify(js); } // export file as json string
	if (nowrap) { return next(null, 'return ' + js); }
	return next(null, 'define(' + JSON.stringify(id) + ',' + js + ');\n');
}
function translate ( id , filename , buffer , options , next ) { var ext = ( filename . match ( extexp ) || [ ] ) [ 1 ] || '' , encoding = options . encoding || exports . defaults . encoding , trans = options . translate , js , nowrap ; // make a list of what not to wrap nowrap = options . nowrap || exports . defaults . nowrap ; nowrap = [ 'define' , 'define.min' , 'define.shim' ] . concat ( nowrap ) ; // should this code get wrapped with a define? nowrap = nowrap . some ( function ( no ) { return no . test ? no . test ( id ) : ( no === id ) ; } ) ; // convert commonjs to amd function wrap ( err , js ) { if ( err ) { return next ( err ) ; } var deps = exports . dependencies ( id , js ) , params = [ ] , undef = '' ; // make sure require, exports, and module are properly passed into the factory if ( / \brequire\b / . test ( js ) ) { params . push ( 'require' ) ; } if ( / \bexports\b / . test ( js ) ) { params . push ( 'exports' ) ; } if ( / \bmodule\b / . test ( js ) ) { params . push ( 'module' ) ; } // make sure code follows the `exports` path instead of `define` path once wrapped if ( / \bdefine\.amd\b / . test ( js ) ) { undef = 'var define;' ; } if ( deps . length ) { deps = ',' + JSON . stringify ( params . concat ( deps ) ) ; } else if ( params . length ) { params = [ 'require' , 'exports' , 'module' ] ; } js = 'define(' + JSON . stringify ( id ) + deps + ',function(' + params + ')' + '{' + js + '\n' + undef + '}' + // rely on hoisting for define ');\n' ; next ( null , js ) ; } // find the translate function trans = trans && ( trans [ filename ] || trans [ id ] || trans [ ext ] ) ; if ( trans ) { // user configured translation return trans ( { id : id , filename : filename , buffer : buffer } , options , ( nowrap ? next : wrap ) ) ; } js = buffer . toString ( encoding ) ; // handle javascript files if ( 'js' === ext ) { return ( nowrap ? next : wrap ) ( null , js ) ; } // handle non-javascript files if ( 'json' !== ext ) { js = JSON . stringify ( js ) ; } // export file as json string if ( nowrap ) { return next ( null , 'return ' + js ) ; } return next ( null , 'define(' + JSON . stringify ( id ) + ',' + js + ');\n' ) ; }
Convert arbitrary file to commonjs+return exports
Convert arbitrary file to commonjs + return exports