@rushstack/lockfile-explorer
Version:
Rush Lockfile Explorer: The UI for solving version conflicts quickly in a large monorepo
73 lines • 3.54 kB
JavaScript
;
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
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_core_library_1 = require("@rushstack/node-core-library");
const RushConfiguration_1 = require("@microsoft/rush-lib/lib/api/RushConfiguration");
const path_1 = __importDefault(require("path"));
const state_1 = require("../state");
const init = (options) => {
const { lockfileExplorerProjectRoot, appVersion, debugMode, subspaceName } = options;
const currDir = process.cwd();
let appState;
let currExploredDir = node_core_library_1.Path.convertToSlashes(currDir);
while (currExploredDir.includes('/')) {
// Look for a rush.json [rush project] or pnpm-lock.yaml file [regular pnpm workspace]
const rushJsonPath = path_1.default.resolve(currExploredDir, 'rush.json');
const pnpmLockPath = path_1.default.resolve(currExploredDir, 'pnpm-lock.yaml');
if (node_core_library_1.FileSystem.exists(rushJsonPath)) {
console.log('Found a Rush workspace: ', rushJsonPath);
const rushConfiguration = RushConfiguration_1.RushConfiguration.tryLoadFromDefaultLocation();
const subspace = rushConfiguration.getSubspace(subspaceName);
const workspaceFolder = subspace.getSubspaceTempFolderPath();
const projectsByProjectFolder = new Map();
for (const project of rushConfiguration.projects) {
projectsByProjectFolder.set(project.projectFolder, {
projectName: project.packageName,
projectFolder: project.projectFolder
});
}
appState = {
currDir,
appVersion,
debugMode,
lockfileExplorerProjectRoot,
projectType: state_1.ProjectType.RUSH_PROJECT,
pnpmLockfileLocation: path_1.default.resolve(workspaceFolder, 'pnpm-lock.yaml'),
pnpmfileLocation: path_1.default.resolve(workspaceFolder, '.pnpmfile.cjs'),
projectRoot: currExploredDir,
rush: {
rushJsonPath,
projectsByProjectFolder
}
};
break;
}
else if (node_core_library_1.FileSystem.exists(pnpmLockPath)) {
appState = {
currDir,
appVersion,
debugMode,
lockfileExplorerProjectRoot,
projectType: state_1.ProjectType.PNPM_WORKSPACE,
pnpmLockfileLocation: path_1.default.resolve(currExploredDir, 'pnpm-lock.yaml'),
pnpmfileLocation: path_1.default.resolve(currExploredDir, '.pnpmfile.cjs'),
projectRoot: currExploredDir
};
break;
}
currExploredDir = currExploredDir.substring(0, currExploredDir.lastIndexOf('/'));
}
if (!appState) {
throw new Error('Could not find a Rush or PNPM workspace!');
}
return appState;
};
exports.init = init;
//# sourceMappingURL=init.js.map