From 4f7aa986a125293649c81b62c731b39e900c434b Mon Sep 17 00:00:00 2001 From: Miguel Ramos Date: Thu, 19 Sep 2024 11:36:51 +0100 Subject: [PATCH] feat: bumps by changes Breaking Change: Bumps will now only relly on changes feature and not only on packages names --- Cargo.toml | 11 ++++------ README.md | 2 ++ index.d.ts | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++---- index.js | 2 ++ src/lib.rs | 47 ++++++++++++++++++++++++++++++++++++++----- 5 files changed, 105 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4e29526..abfd7d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ authors = ["Miguel Ramos "] edition = "2021" name = "websublime_workspace-tools" -version = "0.7.14" +version = "1.0.0" exclude = ["tests/*", "examples/*", "node_modules/*", "target/*"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -11,16 +11,13 @@ exclude = ["tests/*", "examples/*", "node_modules/*", "target/*"] crate-type = ["cdylib"] [dependencies] -napi-derive = "2.16.11" -napi = { version = "2.16.9", default-features = false, features = [ +napi-derive = "2.16.12" +napi = { version = "2.16.10", default-features = false, features = [ "napi9", "serde-json", "tokio_rt", ] } -workspace-node-tools = { version = "1.0.19", features = [ - "napi", - "napi-derive", -] } +workspace-node-tools = { version = "2.0.0", features = ["napi", "napi-derive"] } [build-dependencies] napi-build = "2" diff --git a/README.md b/README.md index aaab1ff..5adc704 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ This package offer a set of functions to retrieve information about the monorepo | `getDefinedPackageManager(root?: string): string or undefined` | Get the package manager defined in the project. | | `detectPackageManager(root: string): PackageManager or undefined` | Detect the package manager defined in the project. | | `getPackages(cwd?: string): Array` | Get the list of packages in the monorepo. | +| `getPackageInfo(package_name: string, cwd?: string): PackageInfo` | Get PackageInfo for a package. | | `getChangedPackages(sha?: string, cwd: string): Array` | Get the list of packages that have changed since the given sha ('main'). | | `git_add(file: string, cwd?: string): boolean` | Stage a file. | | `git_add_all(cwd?: string): boolean` | Stage all files. | @@ -51,6 +52,7 @@ This package offer a set of functions to retrieve information about the monorepo | `change_exist(branch_name: string, packages_name: Array, cwd?: string): boolean` | Check if change already exist. | | `get_change(branch_name: string, cwd?: string): Array` | Get the list of changes for the branch. | | `get_changes(cwd?: string): Changes` | Get all changes. | +| `get_package_change(package_name: string, branch: string, cwd?: string): Changes` | Get a change by package name. | | `changes_file_exist(cwd?: string): boolean` | Check if `.changes.json` file exist | ## Develop requirements diff --git a/index.d.ts b/index.d.ts index 5f09092..1580170 100644 --- a/index.d.ts +++ b/index.d.ts @@ -38,9 +38,9 @@ export enum Bump { } export interface BumpOptions { - packages: Array + changes: Array since?: string - releaseAs: Bump + releaseAs?: Bump fetchAll?: boolean fetchTags?: boolean syncDeps?: boolean @@ -51,8 +51,8 @@ export interface BumpOptions { export interface BumpPackage { from: string to: string - releaseAs: Bump - conventional: ConventionalPackage + packageInfo: PackageInfo + conventionalCommits: any } export interface Change { @@ -136,6 +136,11 @@ export interface ConventionalPackageOptions { title?: string } +export interface DependencyInfo { + name: string + version: string +} + /** * Detect the package manager * @@ -338,6 +343,41 @@ export declare function getLastKnownPublishTagInfoForPackage( cwd?: string | undefined | null, ): PublishTagInfo | null +/** + * Get package change + * + * # Examples + * + * ``` + * const { getPackageChange } = require('workspace-node-tools'); + * const change = getPackageChange("@scope/package-a", "branch-name", process.cwd()); + * ``` + * + * @param package_name - The package name + * @param branch - The branch name + * @param cwd - The root path to start searching from + */ +export declare function getPackageChange( + packageName: string, + branch: string, + cwd?: string | undefined | null, +): Change | null + +/** + * Get PackageInfo for a package + * + * # Examples + * + * ``` + * const { getPackageInfo } = require('workspace-node-tools'); + * const packageInfo = getPackageInfo("package-name", process.cwd()); + * ``` + * + * @param package_name - The name of the package to get info for + * @param cwd - The root path to start searching from + */ +export declare function getPackageInfo(packageName: string, cwd?: string | undefined | null): PackageInfo | null + /** * Get packages available in the monorepo * @@ -630,6 +670,7 @@ export interface PackageInfo { url: string repositoryInfo?: PackageRepositoryInfo changedFiles: Array + dependencies: Array } export enum PackageManager { @@ -651,6 +692,16 @@ export interface PublishTagInfo { package: string } +/** Struct representing the bump package. */ +export interface RecommendBumpPackage { + from: string + to: string + packageInfo: PackageInfo + conventional: ConventionalPackage + changedFiles: Array + deployTo: Array +} + export interface RemoteTags { hash: string tag: string diff --git a/index.js b/index.js index b722dd8..c7f5f29 100644 --- a/index.js +++ b/index.js @@ -378,6 +378,8 @@ module.exports.getDefinedPackageManager = nativeBinding.getDefinedPackageManager module.exports.getDivergedCommit = nativeBinding.getDivergedCommit module.exports.getLastKnownPublishTagInfoForAllPackages = nativeBinding.getLastKnownPublishTagInfoForAllPackages module.exports.getLastKnownPublishTagInfoForPackage = nativeBinding.getLastKnownPublishTagInfoForPackage +module.exports.getPackageChange = nativeBinding.getPackageChange +module.exports.getPackageInfo = nativeBinding.getPackageInfo module.exports.getPackages = nativeBinding.getPackages module.exports.getProjectRootPath = nativeBinding.getProjectRootPath module.exports.getRemoteOrLocalTags = nativeBinding.getRemoteOrLocalTags diff --git a/src/lib.rs b/src/lib.rs index 0603ba0..2348821 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,8 +4,8 @@ use std::path::{Path, PathBuf}; use workspace_node_tools::bumps::{apply_bumps, get_bumps, BumpOptions, BumpPackage}; use workspace_node_tools::changes::{ - add_change, change_exist, changes_file_exist, get_change, get_changes, init_changes, - remove_change, Change, Changes, ChangesFileData, ChangesOptions, + add_change, change_exist, changes_file_exist, get_change, get_changes, get_package_change, + init_changes, remove_change, Change, Changes, ChangesFileData, ChangesOptions, }; use workspace_node_tools::conventional::{ get_conventional_for_package, ConventionalPackage, ConventionalPackageOptions, @@ -20,7 +20,7 @@ use workspace_node_tools::git::{ }; use workspace_node_tools::manager::{detect_package_manager, PackageManager}; use workspace_node_tools::packages::{ - get_changed_packages, get_monorepo_package_manager, get_packages, PackageInfo, + get_changed_packages, get_monorepo_package_manager, get_package_info, get_packages, PackageInfo, }; use workspace_node_tools::paths::get_project_root_path; @@ -90,6 +90,22 @@ pub fn js_get_packages(cwd: Option) -> Vec { get_packages(cwd) } +/// Get PackageInfo for a package +/// +/// # Examples +/// +/// ``` +/// const { getPackageInfo } = require('workspace-node-tools'); +/// const packageInfo = getPackageInfo("package-name", process.cwd()); +/// ``` +/// +/// @param package_name - The name of the package to get info for +/// @param cwd - The root path to start searching from +#[napi(js_name = "getPackageInfo")] +pub fn js_get_package_info(package_name: String, cwd: Option) -> Option { + get_package_info(package_name, cwd) +} + /// Get changed packages /// /// # Examples @@ -495,7 +511,7 @@ pub fn js_get_conventional_for_package( /// @param options - The bump options #[napi(js_name = "getBumps")] pub fn js_get_bumps(options: BumpOptions) -> Vec { - get_bumps(options) + get_bumps(&options) } /// Apply bumps to a package. This will update the package.json version and changelog @@ -511,7 +527,7 @@ pub fn js_get_bumps(options: BumpOptions) -> Vec { /// @param options - The bump options #[napi(js_name = "applyBumps")] pub fn js_apply_bumps(options: BumpOptions) -> Vec { - apply_bumps(options) + apply_bumps(&options) } /// Init changes @@ -616,6 +632,27 @@ pub fn js_get_changes(cwd: Option) -> Changes { get_changes(cwd) } +/// Get package change +/// +/// # Examples +/// +/// ``` +/// const { getPackageChange } = require('workspace-node-tools'); +/// const change = getPackageChange("@scope/package-a", "branch-name", process.cwd()); +/// ``` +/// +/// @param package_name - The package name +/// @param branch - The branch name +/// @param cwd - The root path to start searching from +#[napi(js_name = "getPackageChange")] +pub fn js_get_package_change( + package_name: String, + branch: String, + cwd: Option, +) -> Option { + get_package_change(package_name, branch, cwd) +} + /// Changes file exist /// /// # Examples