@storm-software/workspace-tools
Version:
Tools for managing a Storm workspace, including various Nx generators and executors for common development tasks.
214 lines (200 loc) • 10.1 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
var _chunkANHKV7HZjs = require('./chunk-ANHKV7HZ.js');
var _chunkHTGUYSQTjs = require('./chunk-HTGUYSQT.js');
var _chunkBSW6NZVBjs = require('./chunk-BSW6NZVB.js');
// src/release/rust-version-actions.ts
var _devkit = require('@nx/devkit');
var _release = require('nx/release');
var StormRustVersionActions = (_class = class extends _release.VersionActions {
__init() {this.validManifestFilenames = ["Cargo.toml"]}
/**
* The Storm workspace configuration object, which is loaded from the `storm-workspace.json` file.
*
* @remarks
* This member variable is populated during the {@link init} method.
*/
__init2() {this.workspaceConfig = null}
constructor(releaseGroup, projectGraphNode, finalConfigForProject) {
super(releaseGroup, projectGraphNode, finalConfigForProject);_class.prototype.__init.call(this);_class.prototype.__init2.call(this);;
}
/**
* Asynchronous initialization of the version actions and resolution of manifest paths.
*
* @remarks
* This does NOT validate that manifest files exist - that happens later in validate().
*
* @params tree - The file system tree to read from.
*/
async init(tree) {
this.workspaceConfig = await _chunkBSW6NZVBjs.getWorkspaceConfig.call(void 0, );
return super.init(tree);
}
async readCurrentVersionFromSourceManifest(tree) {
const sourceCargoTomlPath = _devkit.joinPathFragments.call(void 0,
this.projectGraphNode.data.root,
"Cargo.toml"
);
try {
const cargoToml = _chunkHTGUYSQTjs.parseCargoTomlWithTree.call(void 0,
tree,
this.projectGraphNode.data.root,
this.projectGraphNode.name
);
return {
manifestPath: sourceCargoTomlPath,
currentVersion: cargoToml.package.version
};
} catch (e) {
throw new Error(
`Unable to determine the current version for project "${this.projectGraphNode.name}" from ${sourceCargoTomlPath}, please ensure that the "version" field is set within the Cargo.toml file`
);
}
}
async readCurrentVersionFromRegistry(tree, currentVersionResolverMetadata) {
const cargoToml = _chunkHTGUYSQTjs.parseCargoTomlWithTree.call(void 0,
tree,
this.projectGraphNode.data.root,
this.projectGraphNode.name
);
const crateName = cargoToml.package.name;
const metadata = currentVersionResolverMetadata;
const registryArg = typeof _optionalChain([metadata, 'optionalAccess', _ => _.registry]) === "string" ? metadata.registry : _optionalChain([this, 'access', _2 => _2.workspaceConfig, 'optionalAccess', _3 => _3.registry, 'optionalAccess', _4 => _4.cargo]) || "https://crates.io";
const tagArg = typeof _optionalChain([metadata, 'optionalAccess', _5 => _5.tag]) === "string" ? metadata.tag : "latest";
let currentVersion = null;
try {
currentVersion = await _chunkANHKV7HZjs.getCrateRegistryVersion.call(void 0,
crateName,
tagArg,
registryArg
);
} catch (e2) {
}
return {
currentVersion: currentVersion || "0.0.0",
// Make troubleshooting easier by including the registry and tag data in the log text
logText: `"cargoRegistry=${registryArg}" tag=${tagArg}`
};
}
async readCurrentVersionOfDependency(tree, projectGraph, dependencyProjectName) {
const cargoToml = _chunkHTGUYSQTjs.parseCargoTomlWithTree.call(void 0,
tree,
this.projectGraphNode.data.root,
this.projectGraphNode.name
);
if (!_optionalChain([projectGraph, 'access', _6 => _6.nodes, 'access', _7 => _7[dependencyProjectName], 'optionalAccess', _8 => _8.data, 'optionalAccess', _9 => _9.root])) {
return {
currentVersion: null,
dependencyCollection: null
};
}
const dependencyCargoToml = _chunkHTGUYSQTjs.parseCargoTomlWithTree.call(void 0,
tree,
_optionalChain([projectGraph, 'access', _10 => _10.nodes, 'access', _11 => _11[dependencyProjectName], 'optionalAccess', _12 => _12.data, 'access', _13 => _13.root]),
dependencyProjectName
);
if (!_optionalChain([dependencyCargoToml, 'optionalAccess', _14 => _14.package, 'optionalAccess', _15 => _15.name])) {
return {
currentVersion: null,
dependencyCollection: null
};
}
let currentVersion = null;
let dependencyCollection = null;
for (const depType of ["dependencies", "dev-dependencies"]) {
if (cargoToml[depType] && cargoToml[depType][dependencyCargoToml.package.name]) {
currentVersion = typeof cargoToml[depType][dependencyCargoToml.package.name] === "string" ? cargoToml[depType][dependencyCargoToml.package.name] : cargoToml[depType][dependencyCargoToml.package.name].version;
dependencyCollection = depType;
break;
}
}
return {
currentVersion,
dependencyCollection
};
}
async updateProjectVersion(tree, newVersion) {
const logMessages = [];
for (const manifestToUpdate of this.manifestsToUpdate) {
const cargoTomlString = _optionalChain([tree, 'access', _16 => _16.read, 'call', _17 => _17(manifestToUpdate.manifestPath), 'optionalAccess', _18 => _18.toString, 'call', _19 => _19()]);
if (!cargoTomlString) {
throw new Error(
`Unable to read Cargo.toml at path: ${manifestToUpdate.manifestPath}`
);
}
const cargoToml = _chunkHTGUYSQTjs.parseCargoToml.call(void 0, cargoTomlString);
cargoToml.package.version = newVersion;
tree.write(manifestToUpdate.manifestPath, _chunkHTGUYSQTjs.stringifyCargoToml.call(void 0, cargoToml));
logMessages.push(
`\u270D\uFE0F New version ${newVersion} written to manifest: ${manifestToUpdate.manifestPath}`
);
}
return logMessages;
}
/**
* Updates the dependencies of the project in the specified Cargo.toml files.
*
* @param tree - The file system tree to read from and write to.
* @param projectGraph - The project graph to use for resolving dependencies.
* @param dependenciesToUpdate - A mapping of dependency names to their new versions.
* @returns An array of log messages indicating the results of the updates.
*/
async updateProjectDependencies(tree, projectGraph, dependenciesToUpdate = {}) {
const numDependenciesToUpdate = Object.keys(dependenciesToUpdate).length;
if (numDependenciesToUpdate === 0) {
return [];
}
const logMessages = [];
for (const manifestToUpdate of this.manifestsToUpdate) {
const cargoTomlString = _optionalChain([tree, 'access', _20 => _20.read, 'call', _21 => _21(manifestToUpdate.manifestPath), 'optionalAccess', _22 => _22.toString, 'call', _23 => _23()]);
if (!cargoTomlString) {
throw new Error(
`Unable to read Cargo.toml at path: ${manifestToUpdate.manifestPath}`
);
}
const cargoToml = _chunkHTGUYSQTjs.parseCargoToml.call(void 0, cargoTomlString);
for (const depType of ["dependencies", "dev-dependencies"]) {
if (cargoToml[depType]) {
for (const [dep, version] of Object.entries(dependenciesToUpdate)) {
try {
const projectRoot = _optionalChain([projectGraph, 'access', _24 => _24.nodes, 'access', _25 => _25[dep], 'optionalAccess', _26 => _26.data, 'access', _27 => _27.root]);
if (!projectRoot) {
throw new Error(
`Unable to determine the project root for "${dep}" from the project graph metadata, please ensure that the "@storm-software/workspace-tools" plugin is installed and the project graph has been built. If the issue persists, please report this issue on https://github.com/storm-software/storm-ops/issues`
);
}
const dependencyCargoTomlString = _optionalChain([tree, 'access', _28 => _28.read, 'call', _29 => _29(manifestToUpdate.manifestPath), 'optionalAccess', _30 => _30.toString, 'call', _31 => _31()]);
if (!dependencyCargoTomlString) {
throw new Error(
`Unable to read Cargo.toml at path: ${manifestToUpdate.manifestPath}`
);
}
const dependencyCargoToml = _chunkHTGUYSQTjs.parseCargoToml.call(void 0,
dependencyCargoTomlString
);
const dependencyCrateName = cargoToml[depType][dependencyCargoToml.package.name] ? dependencyCargoToml.package.name : dep;
if (typeof cargoToml[depType][dependencyCrateName] === "string") {
cargoToml[depType][dependencyCrateName] = version;
} else {
cargoToml[depType][dependencyCrateName].version = version;
}
tree.write(
manifestToUpdate.manifestPath,
_chunkHTGUYSQTjs.stringifyCargoToml.call(void 0, cargoToml)
);
} catch (error) {
throw new Error(
`Unable to update ${depType === "dev-dependencies" ? "dev-dependency" : "dependency"} "${dep}" in manifest at path: ${manifestToUpdate.manifestPath}.`,
{ cause: error }
);
}
}
}
}
logMessages.push(
`\u270D\uFE0F Updated ${numDependenciesToUpdate} ${numDependenciesToUpdate === 1 ? "dependency" : "dependencies"} in manifest: ${manifestToUpdate.manifestPath}`
);
}
return logMessages;
}
}, _class);
exports.StormRustVersionActions = StormRustVersionActions;