"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/asar/lib/snapshot.js" (11 Apr 2017, 2336 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 (function() {
    2   var createSnapshot, dumpObjectToJS, fs, mksnapshot, path, stripBOM, vm, wrapModuleCode;
    3 
    4   fs = require('fs');
    5 
    6   path = require('path');
    7 
    8   mksnapshot = require('mksnapshot');
    9 
   10   vm = require('vm');
   11 
   12   stripBOM = function(content) {
   13     if (content.charCodeAt(0) === 0xFEFF) {
   14       content = content.slice(1);
   15     }
   16     return content;
   17   };
   18 
   19   wrapModuleCode = function(script) {
   20     script = script.replace(/^\#\!.*/, '');
   21     return "(function(exports, require, module, __filename, __dirname) { " + script + " \n});";
   22   };
   23 
   24   dumpObjectToJS = function(content) {
   25     var filename, func, result;
   26     result = 'var __ATOM_SHELL_SNAPSHOT = {\n';
   27     for (filename in content) {
   28       func = content[filename].toString();
   29       result += "  '" + filename + "': " + func + ",\n";
   30     }
   31     result += '};\n';
   32     return result;
   33   };
   34 
   35   createSnapshot = function(src, dest, filenames, metadata, options, callback) {
   36     var arch, builddir, compiled, content, error, file, filename, relativeFilename, script, snapshotdir, str, target, version, _i, _len;
   37     try {
   38       src = path.resolve(src);
   39       content = {};
   40       for (_i = 0, _len = filenames.length; _i < _len; _i++) {
   41         filename = filenames[_i];
   42         file = metadata[filename];
   43         if ((file.type === 'file' || file.type === 'link') && filename.substr(-3) === '.js') {
   44           script = wrapModuleCode(stripBOM(fs.readFileSync(filename, 'utf8')));
   45           relativeFilename = path.relative(src, filename);
   46           try {
   47             compiled = vm.runInThisContext(script, {
   48               filename: relativeFilename
   49             });
   50             content[relativeFilename] = compiled;
   51           } catch (_error) {
   52             error = _error;
   53             console.error('Ignoring ' + relativeFilename + ' for ' + error.name);
   54           }
   55         }
   56       }
   57     } catch (_error) {
   58       error = _error;
   59       return callback(error);
   60     }
   61     str = dumpObjectToJS(content);
   62     version = options.version, arch = options.arch, builddir = options.builddir, snapshotdir = options.snapshotdir;
   63     if (snapshotdir == null) {
   64       snapshotdir = path.dirname(dest);
   65     }
   66     target = path.resolve(snapshotdir, 'snapshot_blob.bin');
   67     return mksnapshot(str, target, version, arch, builddir, callback);
   68   };
   69 
   70   module.exports = createSnapshot;
   71 
   72 }).call(this);