"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/dedupe.js" (8 Mar 2017, 6114 Bytes) of archive /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 Command, Dedupe, _, async, config, fs, path, yargs,
    3     extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
    4     hasProp = {}.hasOwnProperty,
    5     slice = [].slice;
    6 
    7   path = require('path');
    8 
    9   async = require('async');
   10 
   11   _ = require('underscore-plus');
   12 
   13   yargs = require('yargs');
   14 
   15   config = require('./apm');
   16 
   17   Command = require('./command');
   18 
   19   fs = require('./fs');
   20 
   21   module.exports = Dedupe = (function(superClass) {
   22     extend(Dedupe, superClass);
   23 
   24     Dedupe.commandNames = ['dedupe'];
   25 
   26     function Dedupe() {
   27       this.atomDirectory = config.getAtomDirectory();
   28       this.atomPackagesDirectory = path.join(this.atomDirectory, 'packages');
   29       this.atomNodeDirectory = path.join(this.atomDirectory, '.node-gyp');
   30       this.atomNpmPath = require.resolve('npm/bin/npm-cli');
   31       this.atomNodeGypPath = require.resolve('node-gyp/bin/node-gyp');
   32     }
   33 
   34     Dedupe.prototype.parseOptions = function(argv) {
   35       var options;
   36       options = yargs(argv).wrap(100);
   37       options.usage("\nUsage: apm dedupe [<package_name>...]\n\nReduce duplication in the node_modules folder in the current directory.\n\nThis command is experimental.");
   38       return options.alias('h', 'help').describe('help', 'Print this usage message');
   39     };
   40 
   41     Dedupe.prototype.installNode = function(callback) {
   42       var env, installNodeArgs;
   43       installNodeArgs = ['install'];
   44       installNodeArgs.push("--runtime=electron");
   45       installNodeArgs.push("--target=" + this.electronVersion);
   46       installNodeArgs.push("--dist-url=" + (config.getElectronUrl()));
   47       installNodeArgs.push("--arch=" + (config.getElectronArch()));
   48       installNodeArgs.push('--ensure');
   49       env = _.extend({}, process.env, {
   50         HOME: this.atomNodeDirectory,
   51         RUSTUP_HOME: config.getRustupHomeDirPath()
   52       });
   53       if (config.isWin32()) {
   54         env.USERPROFILE = env.HOME;
   55       }
   56       fs.makeTreeSync(this.atomDirectory);
   57       return config.loadNpm((function(_this) {
   58         return function(error, npm) {
   59           var proxy, ref, useStrictSsl;
   60           useStrictSsl = (ref = npm.config.get('strict-ssl')) != null ? ref : true;
   61           if (!useStrictSsl) {
   62             env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
   63           }
   64           proxy = npm.config.get('https-proxy') || npm.config.get('proxy') || env.HTTPS_PROXY || env.HTTP_PROXY;
   65           if (proxy) {
   66             installNodeArgs.push("--proxy=" + proxy);
   67           }
   68           return _this.fork(_this.atomNodeGypPath, installNodeArgs, {
   69             env: env,
   70             cwd: _this.atomDirectory
   71           }, function(code, stderr, stdout) {
   72             if (stderr == null) {
   73               stderr = '';
   74             }
   75             if (stdout == null) {
   76               stdout = '';
   77             }
   78             if (code === 0) {
   79               return callback();
   80             } else {
   81               return callback(stdout + "\n" + stderr);
   82             }
   83           });
   84         };
   85       })(this));
   86     };
   87 
   88     Dedupe.prototype.getVisualStudioFlags = function() {
   89       var vsVersion;
   90       if (vsVersion = config.getInstalledVisualStudioFlag()) {
   91         return "--msvs_version=" + vsVersion;
   92       }
   93     };
   94 
   95     Dedupe.prototype.dedupeModules = function(options, callback) {
   96       process.stdout.write('Deduping modules ');
   97       return this.forkDedupeCommand(options, (function(_this) {
   98         return function() {
   99           var args;
  100           args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
  101           return _this.logCommandResults.apply(_this, [callback].concat(slice.call(args)));
  102         };
  103       })(this));
  104     };
  105 
  106     Dedupe.prototype.forkDedupeCommand = function(options, callback) {
  107       var dedupeArgs, dedupeOptions, env, i, len, packageName, ref, vsArgs;
  108       dedupeArgs = ['--globalconfig', config.getGlobalConfigPath(), '--userconfig', config.getUserConfigPath(), 'dedupe'];
  109       dedupeArgs.push("--runtime=electron");
  110       dedupeArgs.push("--target=" + this.electronVersion);
  111       dedupeArgs.push("--arch=" + (config.getElectronArch()));
  112       if (options.argv.silent) {
  113         dedupeArgs.push('--silent');
  114       }
  115       if (options.argv.quiet) {
  116         dedupeArgs.push('--quiet');
  117       }
  118       if (vsArgs = this.getVisualStudioFlags()) {
  119         dedupeArgs.push(vsArgs);
  120       }
  121       ref = options.argv._;
  122       for (i = 0, len = ref.length; i < len; i++) {
  123         packageName = ref[i];
  124         dedupeArgs.push(packageName);
  125       }
  126       env = _.extend({}, process.env, {
  127         HOME: this.atomNodeDirectory,
  128         RUSTUP_HOME: config.getRustupHomeDirPath()
  129       });
  130       if (config.isWin32()) {
  131         env.USERPROFILE = env.HOME;
  132       }
  133       dedupeOptions = {
  134         env: env
  135       };
  136       if (options.cwd) {
  137         dedupeOptions.cwd = options.cwd;
  138       }
  139       return this.fork(this.atomNpmPath, dedupeArgs, dedupeOptions, callback);
  140     };
  141 
  142     Dedupe.prototype.createAtomDirectories = function() {
  143       fs.makeTreeSync(this.atomDirectory);
  144       return fs.makeTreeSync(this.atomNodeDirectory);
  145     };
  146 
  147     Dedupe.prototype.run = function(options) {
  148       var callback, commands, cwd;
  149       callback = options.callback, cwd = options.cwd;
  150       options = this.parseOptions(options.commandArgs);
  151       options.cwd = cwd;
  152       this.createAtomDirectories();
  153       commands = [];
  154       commands.push((function(_this) {
  155         return function(callback) {
  156           return _this.loadInstalledAtomMetadata(callback);
  157         };
  158       })(this));
  159       commands.push((function(_this) {
  160         return function(callback) {
  161           return _this.installNode(callback);
  162         };
  163       })(this));
  164       commands.push((function(_this) {
  165         return function(callback) {
  166           return _this.dedupeModules(options, callback);
  167         };
  168       })(this));
  169       return async.waterfall(commands, callback);
  170     };
  171 
  172     return Dedupe;
  173 
  174   })(Command);
  175 
  176 }).call(this);