yarn.js 6.71 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.installOrRebuild = installOrRebuild;
exports.getGypEnv = getGypEnv;
exports.rebuild = rebuild;

function _bluebirdLst() {
  const data = _interopRequireWildcard(require("bluebird-lst"));

  _bluebirdLst = function () {
    return data;
  };

  return data;
}

function _builderUtil() {
  const data = require("builder-util");

  _builderUtil = function () {
    return data;
  };

  return data;
}

function _fs() {
  const data = require("builder-util/out/fs");

  _fs = function () {
    return data;
  };

  return data;
}

function _os() {
  const data = require("os");

  _os = function () {
    return data;
  };

  return data;
}

var path = _interopRequireWildcard(require("path"));

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

function installOrRebuild(_x, _x2, _x3) {
  return _installOrRebuild.apply(this, arguments);
}

function _installOrRebuild() {
  _installOrRebuild = (0, _bluebirdLst().coroutine)(function* (config, appDir, options, forceInstall = false) {
    const effectiveOptions = Object.assign({
      buildFromSource: config.buildDependenciesFromSource === true,
      additionalArgs: (0, _builderUtil().asArray)(config.npmArgs)
    }, options);

    if (forceInstall || !(yield (0, _fs().exists)(path.join(appDir, "node_modules")))) {
      yield installDependencies(appDir, effectiveOptions);
    } else {
      yield rebuild(appDir, effectiveOptions);
    }
  });
  return _installOrRebuild.apply(this, arguments);
}

function getElectronGypCacheDir() {
  return path.join((0, _os().homedir)(), ".electron-gyp");
}

function getGypEnv(frameworkInfo, platform, arch, buildFromSource) {
  const npmConfigArch = arch === "armv7l" ? "arm" : arch;
  const common = Object.assign({}, process.env, {
    npm_config_arch: npmConfigArch,
    npm_config_target_arch: npmConfigArch,
    npm_config_platform: platform,
    npm_config_build_from_source: buildFromSource,
    // required for node-pre-gyp
    npm_config_target_platform: platform,
    npm_config_update_binary: true,
    npm_config_fallback_to_build: true
  });

  if (platform === "win32") {
    common.npm_config_target_libc = "unknown";
  }

  if (!frameworkInfo.useCustomDist) {
    return common;
  } // https://github.com/nodejs/node-gyp/issues/21


  return Object.assign({}, common, {
    npm_config_disturl: "https://atom.io/download/electron",
    npm_config_target: frameworkInfo.version,
    npm_config_runtime: "electron",
    npm_config_devdir: getElectronGypCacheDir()
  });
}

function installDependencies(appDir, options) {
  const platform = options.platform || process.platform;
  const arch = options.arch || process.arch;
  const additionalArgs = options.additionalArgs;

  _builderUtil().log.info({
    platform,
    arch,
    appDir
  }, `installing production dependencies`);

  let execPath = process.env.npm_execpath || process.env.NPM_CLI_JS;
  const execArgs = ["install", "--production"];

  if (!isRunningYarn(execPath)) {
    if (process.env.NPM_NO_BIN_LINKS === "true") {
      execArgs.push("--no-bin-links");
    }

    execArgs.push("--cache-min", "999999999");
  }

  if (execPath == null) {
    execPath = getPackageToolPath();
  } else {
    execArgs.unshift(execPath);
    execPath = process.env.npm_node_execpath || process.env.NODE_EXE || "node";
  }

  if (additionalArgs != null) {
    execArgs.push(...additionalArgs);
  }

  return (0, _builderUtil().spawn)(execPath, execArgs, {
    cwd: appDir,
    env: getGypEnv(options.frameworkInfo, platform, arch, options.buildFromSource === true)
  });
}

function getPackageToolPath() {
  if (process.env.FORCE_YARN === "true") {
    return process.platform === "win32" ? "yarn.cmd" : "yarn";
  } else {
    return process.platform === "win32" ? "npm.cmd" : "npm";
  }
}

function isRunningYarn(execPath) {
  const userAgent = process.env.npm_config_user_agent;
  return process.env.FORCE_YARN === "true" || execPath != null && path.basename(execPath).startsWith("yarn") || userAgent != null && /\byarn\b/.test(userAgent);
}
/** @internal */


function rebuild(_x4, _x5) {
  return _rebuild.apply(this, arguments);
} function _rebuild() {
  _rebuild = (0, _bluebirdLst().coroutine)(function* (appDir, options) {
    const nativeDeps = yield _bluebirdLst().default.filter((yield options.productionDeps.value), it => (0, _fs().exists)(path.join(it.path, "binding.gyp")), {
      concurrency: 8
    });

    if (nativeDeps.length === 0) {
      _builderUtil().log.info("no native production dependencies");

      return;
    }

    const platform = options.platform || process.platform;
    const arch = options.arch || process.arch;
    const additionalArgs = options.additionalArgs;

    _builderUtil().log.info({
      platform,
      arch
    }, "rebuilding native production dependencies");

    let execPath = process.env.npm_execpath || process.env.NPM_CLI_JS;
    const isYarn = isRunningYarn(execPath);
    const execArgs = [];

    if (execPath == null) {
      execPath = getPackageToolPath();
    } else {
      execArgs.push(execPath);
      execPath = process.env.npm_node_execpath || process.env.NODE_EXE || "node";
    }

    const env = getGypEnv(options.frameworkInfo, platform, arch, options.buildFromSource === true);

    if (isYarn) {
      execArgs.push("run", "install");

      if (additionalArgs != null) {
        execArgs.push(...additionalArgs);
      }

      yield _bluebirdLst().default.map(nativeDeps, dep => {
        _builderUtil().log.info({
          name: dep.name
        }, `rebuilding native dependency`);

        return (0, _builderUtil().spawn)(execPath, execArgs, {
          cwd: dep.path,
          env
        }).catch(error => {
          if (dep.optional) {
            _builderUtil().log.warn({
              dep: dep.name
            }, "cannot build optional native dep");
          } else {
            throw error;
          }
        });
      }, {
        concurrency: process.platform === "win32" ? 1 : 2
      });
    } else {
      execArgs.push("rebuild");

      if (additionalArgs != null) {
        execArgs.push(...additionalArgs);
      }

      execArgs.push(...nativeDeps.map(it => `${it.name}@${it.version}`));
      yield (0, _builderUtil().spawn)(execPath, execArgs, {
        cwd: appDir,
        env
      });
    }
  });
  return _rebuild.apply(this, arguments);
}
// __ts-babel@6.0.4
//# sourceMappingURL=yarn.js.map