install-run-rush.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // THIS FILE WAS GENERATED BY A TOOL. ANY MANUAL MODIFICATIONS WILL GET OVERWRITTEN WHENEVER RUSH IS UPGRADED.
  2. //
  3. // This script is intended for usage in an automated build environment where the Rush command may not have
  4. // been preinstalled, or may have an unpredictable version. This script will automatically install the version of Rush
  5. // specified in the rush.json configuration file (if not already installed), and then pass a command-line to it.
  6. // An example usage would be:
  7. //
  8. // node common/scripts/install-run-rush.js install
  9. //
  10. // For more information, see: https://rushjs.io/pages/maintainer/setup_new_repo/
  11. //
  12. // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
  13. // See the @microsoft/rush package's LICENSE file for details.
  14. /******/ (() => { // webpackBootstrap
  15. /******/ "use strict";
  16. /******/ var __webpack_modules__ = ({
  17. /***/ 179896:
  18. /*!*********************!*\
  19. !*** external "fs" ***!
  20. \*********************/
  21. /***/ ((module) => {
  22. module.exports = require("fs");
  23. /***/ }),
  24. /***/ 16928:
  25. /*!***********************!*\
  26. !*** external "path" ***!
  27. \***********************/
  28. /***/ ((module) => {
  29. module.exports = require("path");
  30. /***/ })
  31. /******/ });
  32. /************************************************************************/
  33. /******/ // The module cache
  34. /******/ var __webpack_module_cache__ = {};
  35. /******/
  36. /******/ // The require function
  37. /******/ function __webpack_require__(moduleId) {
  38. /******/ // Check if module is in cache
  39. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  40. /******/ if (cachedModule !== undefined) {
  41. /******/ return cachedModule.exports;
  42. /******/ }
  43. /******/ // Create a new module (and put it into the cache)
  44. /******/ var module = __webpack_module_cache__[moduleId] = {
  45. /******/ // no module.id needed
  46. /******/ // no module.loaded needed
  47. /******/ exports: {}
  48. /******/ };
  49. /******/
  50. /******/ // Execute the module function
  51. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  52. /******/
  53. /******/ // Return the exports of the module
  54. /******/ return module.exports;
  55. /******/ }
  56. /******/
  57. /************************************************************************/
  58. /******/ /* webpack/runtime/compat get default export */
  59. /******/ (() => {
  60. /******/ // getDefaultExport function for compatibility with non-harmony modules
  61. /******/ __webpack_require__.n = (module) => {
  62. /******/ var getter = module && module.__esModule ?
  63. /******/ () => (module['default']) :
  64. /******/ () => (module);
  65. /******/ __webpack_require__.d(getter, { a: getter });
  66. /******/ return getter;
  67. /******/ };
  68. /******/ })();
  69. /******/
  70. /******/ /* webpack/runtime/define property getters */
  71. /******/ (() => {
  72. /******/ // define getter functions for harmony exports
  73. /******/ __webpack_require__.d = (exports, definition) => {
  74. /******/ for(var key in definition) {
  75. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  76. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  77. /******/ }
  78. /******/ }
  79. /******/ };
  80. /******/ })();
  81. /******/
  82. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  83. /******/ (() => {
  84. /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  85. /******/ })();
  86. /******/
  87. /******/ /* webpack/runtime/make namespace object */
  88. /******/ (() => {
  89. /******/ // define __esModule on exports
  90. /******/ __webpack_require__.r = (exports) => {
  91. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  92. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  93. /******/ }
  94. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  95. /******/ };
  96. /******/ })();
  97. /******/
  98. /************************************************************************/
  99. var __webpack_exports__ = {};
  100. // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
  101. (() => {
  102. /*!************************************************!*\
  103. !*** ./lib-esnext/scripts/install-run-rush.js ***!
  104. \************************************************/
  105. __webpack_require__.r(__webpack_exports__);
  106. /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! path */ 16928);
  107. /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);
  108. /* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! fs */ 179896);
  109. /* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_1__);
  110. // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
  111. // See LICENSE in the project root for license information.
  112. /* eslint-disable no-console */
  113. const { installAndRun, findRushJsonFolder, RUSH_JSON_FILENAME, runWithErrorAndStatusCode } = require('./install-run');
  114. const PACKAGE_NAME = '@microsoft/rush';
  115. const RUSH_PREVIEW_VERSION = 'RUSH_PREVIEW_VERSION';
  116. const INSTALL_RUN_RUSH_LOCKFILE_PATH_VARIABLE = 'INSTALL_RUN_RUSH_LOCKFILE_PATH';
  117. function _getRushVersion(logger) {
  118. const rushPreviewVersion = process.env[RUSH_PREVIEW_VERSION];
  119. if (rushPreviewVersion !== undefined) {
  120. logger.info(`Using Rush version from environment variable ${RUSH_PREVIEW_VERSION}=${rushPreviewVersion}`);
  121. return rushPreviewVersion;
  122. }
  123. const rushJsonFolder = findRushJsonFolder();
  124. const rushJsonPath = path__WEBPACK_IMPORTED_MODULE_0__.join(rushJsonFolder, RUSH_JSON_FILENAME);
  125. try {
  126. const rushJsonContents = fs__WEBPACK_IMPORTED_MODULE_1__.readFileSync(rushJsonPath, 'utf-8');
  127. // Use a regular expression to parse out the rushVersion value because rush.json supports comments,
  128. // but JSON.parse does not and we don't want to pull in more dependencies than we need to in this script.
  129. const rushJsonMatches = rushJsonContents.match(/\"rushVersion\"\s*\:\s*\"([0-9a-zA-Z.+\-]+)\"/);
  130. return rushJsonMatches[1];
  131. }
  132. catch (e) {
  133. throw new Error(`Unable to determine the required version of Rush from ${RUSH_JSON_FILENAME} (${rushJsonFolder}). ` +
  134. `The 'rushVersion' field is either not assigned in ${RUSH_JSON_FILENAME} or was specified ` +
  135. 'using an unexpected syntax.');
  136. }
  137. }
  138. function _getBin(scriptName) {
  139. switch (scriptName.toLowerCase()) {
  140. case 'install-run-rush-pnpm.js':
  141. return 'rush-pnpm';
  142. case 'install-run-rushx.js':
  143. return 'rushx';
  144. default:
  145. return 'rush';
  146. }
  147. }
  148. function _run() {
  149. const [nodePath /* Ex: /bin/node */, scriptPath /* /repo/common/scripts/install-run-rush.js */, ...packageBinArgs /* [build, --to, myproject] */] = process.argv;
  150. // Detect if this script was directly invoked, or if the install-run-rushx script was invokved to select the
  151. // appropriate binary inside the rush package to run
  152. const scriptName = path__WEBPACK_IMPORTED_MODULE_0__.basename(scriptPath);
  153. const bin = _getBin(scriptName);
  154. if (!nodePath || !scriptPath) {
  155. throw new Error('Unexpected exception: could not detect node path or script path');
  156. }
  157. let commandFound = false;
  158. let logger = { info: console.log, error: console.error };
  159. for (const arg of packageBinArgs) {
  160. if (arg === '-q' || arg === '--quiet') {
  161. // The -q/--quiet flag is supported by both `rush` and `rushx`, and will suppress
  162. // any normal informational/diagnostic information printed during startup.
  163. //
  164. // To maintain the same user experience, the install-run* scripts pass along this
  165. // flag but also use it to suppress any diagnostic information normally printed
  166. // to stdout.
  167. logger = {
  168. info: () => { },
  169. error: console.error
  170. };
  171. }
  172. else if (!arg.startsWith('-') || arg === '-h' || arg === '--help') {
  173. // We either found something that looks like a command (i.e. - doesn't start with a "-"),
  174. // or we found the -h/--help flag, which can be run without a command
  175. commandFound = true;
  176. }
  177. }
  178. if (!commandFound) {
  179. console.log(`Usage: ${scriptName} <command> [args...]`);
  180. if (scriptName === 'install-run-rush-pnpm.js') {
  181. console.log(`Example: ${scriptName} pnpm-command`);
  182. }
  183. else if (scriptName === 'install-run-rush.js') {
  184. console.log(`Example: ${scriptName} build --to myproject`);
  185. }
  186. else {
  187. console.log(`Example: ${scriptName} custom-command`);
  188. }
  189. process.exit(1);
  190. }
  191. runWithErrorAndStatusCode(logger, () => {
  192. const version = _getRushVersion(logger);
  193. logger.info(`The ${RUSH_JSON_FILENAME} configuration requests Rush version ${version}`);
  194. const lockFilePath = process.env[INSTALL_RUN_RUSH_LOCKFILE_PATH_VARIABLE];
  195. if (lockFilePath) {
  196. logger.info(`Found ${INSTALL_RUN_RUSH_LOCKFILE_PATH_VARIABLE}="${lockFilePath}", installing with lockfile.`);
  197. }
  198. return installAndRun(logger, PACKAGE_NAME, version, bin, packageBinArgs, lockFilePath);
  199. });
  200. }
  201. _run();
  202. //# sourceMappingURL=install-run-rush.js.map
  203. })();
  204. module.exports = __webpack_exports__;
  205. /******/ })()
  206. ;
  207. //# sourceMappingURL=install-run-rush.js.map