MCPcopy Create free account
hub / github.com/socketstream/socketstream / wrapCode

Function wrapCode

lib/client/bundler/proto.js:315–364  ·  view source on GitHub ↗

* @ngdoc method * @name bundler.default:default#wrapCode * @methodOf bundler.default:default * @function * @description * Before client-side code is sent to the browser any file which is NOT a library (e.g. /client/code/libs) * is wrapped in a module wrapper (to keep vars local and

(code, entry, opts)

Source from the content-addressed store, hash-verified

313 * @returns {[AssetEntry]} List of output entries
314 */
315 function wrapCode(code, entry, opts) {
316 var pathAry = entry.file.split('/');
317
318 // Don't touch the code if it's in a 'libs' directory
319 if (pathAry.indexOf('libs') >= 0) { //TODO [code,libs] & options.dirs.libs location
320 return code;
321 }
322
323 // if it's configured in excludes, return raw code
324 if (pathAry.indexOf('entry.js') === -1 && options && options.browserifyExcludePaths) {
325 for(var i, p; (p = options.browserifyExcludePaths[i]); ++i) {
326 if ( entry.file.split( p )[0] === '' ) {
327 return code;
328 }
329 }
330 }
331
332 var last = pathAry[pathAry.length-1],
333 modPath,
334 extPos = last.lastIndexOf('.');
335 if (extPos > -1) {
336 pathAry[pathAry.length-1] = last.substring(0,extPos);
337 }
338
339 //TODO configurable system locations with array instead of string
340 // Don't add a leading slash if this is a 'system' module
341 if (entry.file.indexOf(options.dirs['system'].substring(1)) === 0) { //TODO [code,system] & improve test to allow parallel system dir
342 // Take everything after the /system/ part of the path
343 modPath = pathAry.slice(pathAry.indexOf('system')+1).join('/');
344 } else {
345
346 // Otherwise treat as a regular module
347 modPath = pathAry.join('/');
348
349 // Work out namespace for module
350 if (opts.pathPrefix) {
351
352 // Ignore any filenames in the path
353 if (opts.pathPrefix.indexOf('.') > 0) {
354 var sp = opts.pathPrefix.split('/');
355 sp.pop();
356 opts.pathPrefix = sp.join('/');
357 }
358 modPath = '/' + path.substr(opts.pathPrefix.length + 1);
359 } else {
360 modPath = '/' + modPath;
361 }
362 }
363 return ss.bundler.wrapModule(modPath, code);
364 }
365
366 function UpdateCachedDevAssets() {
367 var url = 'assets/'+this.client.name+'/'+this.client.id+'.html';

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected