UNPKG

@rushstack/lockfile-explorer

Version:

Rush Lockfile Explorer: The UI for solving version conflicts quickly in a large monorepo

117 lines 6.23 kB
"use strict"; // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.init = void 0; // This function will read the current directory and try to figure out if it's a rush project or regular pnpm workspace // Currently it will throw error if neither can be determined const node_path_1 = __importDefault(require("node:path")); const node_core_library_1 = require("@rushstack/node-core-library"); const RushConfiguration_1 = require("@microsoft/rush-lib/lib/api/RushConfiguration"); const lockfilePath = __importStar(require("../graph/lockfilePath")); const init = (options) => { const { lockfileExplorerProjectRoot, appVersion, debugMode, subspaceName } = options; const currentWorkingDirectory = node_path_1.default.resolve(process.cwd()); let appState; let currentFolder = node_core_library_1.Path.convertToSlashes(currentWorkingDirectory); while (currentFolder.includes('/')) { // Look for a rush.json [rush project] or pnpm-lock.yaml file [regular pnpm workspace] const rushJsonPath = currentFolder + '/rush.json'; const pnpmLockPath = currentFolder + '/pnpm-lock.yaml'; if (node_core_library_1.FileSystem.exists(rushJsonPath)) { console.log('Found a Rush workspace: ', rushJsonPath); const rushConfiguration = RushConfiguration_1.RushConfiguration.loadFromConfigurationFile(rushJsonPath); const subspace = rushConfiguration.getSubspace(subspaceName); const commonTempFolder = subspace.getSubspaceTempFolderPath(); const pnpmLockfileAbsolutePath = node_path_1.default.join(commonTempFolder, 'pnpm-lock.yaml'); const relativeCommonTempFolder = node_core_library_1.Path.convertToSlashes(node_path_1.default.relative(currentFolder, subspace.getSubspaceTempFolderPath())); const pnpmLockfileRelativePath = lockfilePath.join(relativeCommonTempFolder, 'pnpm-lock.yaml'); const pnpmFileRelativePath = lockfilePath.join(relativeCommonTempFolder, '.pnpmfile.cjs'); const relativeCommonConfigFolder = node_core_library_1.Path.convertToSlashes(node_path_1.default.relative(currentFolder, subspace.getSubspaceConfigFolderPath())); const rushPnpmFileRelativePath = lockfilePath.join(relativeCommonConfigFolder, '.pnpmfile.cjs'); appState = { currentWorkingDirectory, appVersion, debugMode, lockfileExplorerProjectRoot, pnpmLockfileLocation: pnpmLockfileAbsolutePath, pnpmfileLocation: commonTempFolder + '/.pnpmfile.cjs', projectRoot: currentFolder, lfxWorkspace: { workspaceRootFullPath: currentFolder, pnpmLockfilePath: node_core_library_1.Path.convertToSlashes(pnpmLockfileRelativePath), pnpmLockfileFolder: node_core_library_1.Path.convertToSlashes(node_path_1.default.dirname(pnpmLockfileRelativePath)), pnpmfilePath: node_core_library_1.Path.convertToSlashes(pnpmFileRelativePath), rushConfig: { rushVersion: rushConfiguration.rushConfigurationJson.rushVersion, subspaceName: subspaceName !== null && subspaceName !== void 0 ? subspaceName : '', rushPnpmfilePath: rushPnpmFileRelativePath } } }; break; } else if (node_core_library_1.FileSystem.exists(pnpmLockPath)) { appState = { currentWorkingDirectory, appVersion, debugMode, lockfileExplorerProjectRoot, pnpmLockfileLocation: currentFolder + '/pnpm-lock.yaml', pnpmfileLocation: currentFolder + '/.pnpmfile.cjs', projectRoot: currentFolder, lfxWorkspace: { workspaceRootFullPath: currentFolder, pnpmLockfilePath: node_core_library_1.Path.convertToSlashes(node_path_1.default.relative(currentFolder, pnpmLockPath)), pnpmLockfileFolder: '', pnpmfilePath: '.pnpmfile.cjs', rushConfig: undefined } }; break; } currentFolder = currentFolder.substring(0, currentFolder.lastIndexOf('/')); } if (!appState) { throw new Error('Could not find a Rush or PNPM workspace!'); } return appState; }; exports.init = init; //# sourceMappingURL=init.js.map