From a63d87e842dfc294b94409e63bf1d5b1e4f8f16b Mon Sep 17 00:00:00 2001 From: Miguel Ramos Date: Fri, 19 Jul 2024 12:12:10 +0100 Subject: [PATCH] chore: tests --- __test__/index.spec.ts | 10 ++- package.json | 5 +- pnpm-lock.yaml | 16 +++++ src/lib.rs | 144 ++++++++++++++++++++--------------------- 4 files changed, 101 insertions(+), 74 deletions(-) diff --git a/__test__/index.spec.ts b/__test__/index.spec.ts index dddfda9..e65d022 100644 --- a/__test__/index.spec.ts +++ b/__test__/index.spec.ts @@ -1,7 +1,15 @@ import test from 'ava'; -import { getDefinedPackageManager, PackageManager } from '../index'; +import { + getDefinedPackageManager, + PackageManager, + getProjectRootPath +} from '../index'; test('get defined package manager', (t) => { t.is(getDefinedPackageManager(), PackageManager.Pnpm); }); + +test('get project root path', (t) => { + t.is(getProjectRootPath(process.cwd()), process.cwd()); +}); \ No newline at end of file diff --git a/package.json b/package.json index e18e753..8205a9a 100644 --- a/package.json +++ b/package.json @@ -110,5 +110,8 @@ "singleQuote": true, "arrowParens": "always" }, - "packageManager": "pnpm@9.4.0" + "packageManager": "pnpm@9.4.0", + "dependencies": { + "@types/node": "^20.14.11" + } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 723c97a..c4bd7cc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,6 +7,10 @@ settings: importers: .: + dependencies: + '@types/node': + specifier: ^20.14.11 + version: 20.14.11 devDependencies: '@emnapi/core': specifier: ^1.1.1 @@ -598,6 +602,9 @@ packages: '@tybys/wasm-util@0.9.0': resolution: {integrity: sha512-6+7nlbMVX/PVDCwaIQ8nTOPveOcFLSt8GcXdx8hD0bt39uWxYT88uXzqTd4fTvqta7oeUJqudepapKNt2DYJFw==} + '@types/node@20.14.11': + resolution: {integrity: sha512-kprQpL8MMeszbz6ojB5/tU8PLN4kesnN8Gjzw349rDlNgsSzg90lAVj3llK99Dh7JON+t9AuscPPFW6mPbTnSA==} + '@vercel/nft@0.26.4': resolution: {integrity: sha512-j4jCOOXke2t8cHZCIxu1dzKLHLcFmYzC3yqAK6MfZznOL1QIJKd0xcFsXK3zcqzU7ScsE2zWkiMMNHGMHgp+FA==} engines: {node: '>=16'} @@ -1643,6 +1650,9 @@ packages: engines: {node: '>=14.17'} hasBin: true + undici-types@5.26.5: + resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} + unicorn-magic@0.1.0: resolution: {integrity: sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==} engines: {node: '>=18'} @@ -2174,6 +2184,10 @@ snapshots: dependencies: tslib: 2.6.2 + '@types/node@20.14.11': + dependencies: + undici-types: 5.26.5 + '@vercel/nft@0.26.4': dependencies: '@mapbox/node-pre-gyp': 1.0.11 @@ -3174,6 +3188,8 @@ snapshots: typescript@5.4.5: {} + undici-types@5.26.5: {} + unicorn-magic@0.1.0: {} universal-user-agent@6.0.1: {} diff --git a/src/lib.rs b/src/lib.rs index 409e3d6..ccbe4c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,14 +23,14 @@ use workspace_node_tools::paths::get_project_root_path; extern crate napi_derive; /// Get the project root path -/// +/// /// # Examples -/// +/// /// ``` /// const { getProjectRootPath } = require('workspace-node-tools'); /// const project_root = getProjectRootPath(process.cwd()); /// ``` -/// +/// /// @param root - The root path to start searching from #[napi(js_name = "getProjectRootPath")] pub fn js_project_root_path(root: Option) -> Option { @@ -41,14 +41,14 @@ pub fn js_project_root_path(root: Option) -> Option { } /// Get the defined package manager -/// +/// /// # Examples -/// +/// /// ``` /// const { getDefinedPackageManager } = require('workspace-node-tools'); /// const packageManager = getDefinedPackageManager(process.cwd()); /// ``` -/// +/// /// @param root - The root path to start searching from #[napi(js_name = "getDefinedPackageManager")] pub fn js_define_package_manager(root: Option) -> Option { @@ -56,14 +56,14 @@ pub fn js_define_package_manager(root: Option) -> Option } /// Detect the package manager -/// +/// /// # Examples -/// +/// /// ``` /// const { detectPackageManager } = require('workspace-node-tools'); /// const packageManager = detectPackageManager(process.cwd()); /// ``` -/// +/// /// @param root - The root path to start searching from #[napi(js_name = "detectPackageManager")] pub fn js_detect_package_manager(root: String) -> Option { @@ -71,14 +71,14 @@ pub fn js_detect_package_manager(root: String) -> Option { } /// Get packages available in the monorepo -/// +/// /// # Examples -/// +/// /// ``` /// const { getPackages } = require('workspace-node-tools'); /// const packages = getPackages(process.cwd()); /// ``` -/// +/// /// @param cwd - The root path to start searching from #[napi(js_name = "getPackages")] pub fn js_get_packages(cwd: Option) -> Vec { @@ -86,14 +86,14 @@ pub fn js_get_packages(cwd: Option) -> Vec { } /// Get changed packages -/// +/// /// # Examples -/// +/// /// ``` /// const { getChangedPackages } = require('workspace-node-tools'); /// const changedPackages = getChangedPackages("main", process.cwd()); /// ``` -/// +/// /// @param sha - The commit sha to compare against (normally main branch) /// @param cwd - The root path to start searching from #[napi(js_name = "getChangedPackages")] @@ -102,14 +102,14 @@ pub fn js_get_changed_packages(sha: Option, cwd: Option) -> Vec< } /// Fetch all git changes -/// +/// /// # Examples -/// +/// /// ``` /// const { gitFetchAll } = require('workspace-node-tools'); /// gitFetchAll(process.cwd(), true); /// ``` -/// +/// /// @param cwd - The root path to start searching from /// @param fetch_tags - Fetch tags from remote #[napi(js_name = "gitFetchAll")] @@ -118,14 +118,14 @@ pub fn js_git_fetch_all(cwd: Option, fetch_tags: Option) -> bool { } /// Commit changes to git -/// +/// /// # Examples -/// +/// /// ``` /// const { gitCommit } = require('workspace-node-tools'); /// gitCommit("feat: add new feature", "body", "footer", process.cwd()); /// ``` -/// +/// /// @param message - The commit message /// @param body - The commit body /// @param footer - The commit footer @@ -141,14 +141,14 @@ pub fn js_git_commit( } /// Tag a git commit -/// +/// /// # Examples -/// +/// /// ``` /// const { gitTag } = require('workspace-node-tools'); /// gitTag("v1.0.0", "message", process.cwd()); /// ``` -/// +/// /// @param tag - The tag to apply /// @param message - The tag message /// @param cwd - The root path to start searching from @@ -158,14 +158,14 @@ pub fn js_git_tag(tag: String, message: Option, cwd: Option) -> } /// Push changes to git -/// +/// /// # Examples -/// +/// /// ``` /// const { gitPush } = require('workspace-node-tools'); /// gitPush(process.cwd(), true); /// ``` -/// +/// /// @param cwd - The root path to start searching from /// @param follow_tags - Follow tags #[napi(js_name = "gitPush")] @@ -174,14 +174,14 @@ pub fn js_git_push(cwd: Option, follow_tags: Option) -> bool { } /// Get the current branch -/// +/// /// # Examples -/// +/// /// ``` /// const { gitCurrentBranch } = require('workspace-node-tools'); /// const branch = gitCurrentBranch(process.cwd()); /// ``` -/// +/// /// @param cwd - The root path to start searching from #[napi(js_name = "gitCurrentBranch")] pub fn js_git_current_branch(cwd: Option) -> Option { @@ -189,14 +189,14 @@ pub fn js_git_current_branch(cwd: Option) -> Option { } /// Get the current commit id -/// +/// /// # Examples -/// +/// /// ``` /// const { gitCurrentSha } = require('workspace-node-tools'); /// const sha = gitCurrentSha(process.cwd()); /// ``` -/// +/// /// @param cwd - The root path to start searching from #[napi(js_name = "gitCurrentSha")] pub fn js_git_current_sha(cwd: Option) -> String { @@ -204,14 +204,14 @@ pub fn js_git_current_sha(cwd: Option) -> String { } /// Get the previous commit id -/// +/// /// # Examples -/// +/// /// ``` /// const { gitPreviousSha } = require('workspace-node-tools'); /// const sha = gitPreviousSha(process.cwd()); /// ``` -/// +/// /// @param cwd - The root path to start searching from #[napi(js_name = "gitPreviousSha")] pub fn js_git_previous_sha(cwd: Option) -> Option { @@ -219,14 +219,14 @@ pub fn js_git_previous_sha(cwd: Option) -> Option { } /// Get the first commit id -/// +/// /// # Examples -/// +/// /// ``` /// const { gitFirstSha } = require('workspace-node-tools'); /// const sha = gitFirstSha(process.cwd()); /// ``` -/// +/// /// @param cwd - The root path to start searching from #[napi(js_name = "gitFirstSha")] pub fn js_git_first_sha(cwd: Option, branch: Option) -> Option { @@ -234,14 +234,14 @@ pub fn js_git_first_sha(cwd: Option, branch: Option) -> Option) -> bool { @@ -249,14 +249,14 @@ pub fn js_git_workdir_unclean(cwd: Option) -> bool { } /// Get the branch name from a commit id -/// +/// /// # Examples -/// +/// /// ``` /// const { gitCommitBranchName } = require('workspace-node-tools'); /// const branch = gitCommitBranchName("sha", process.cwd()); /// ``` -/// +/// /// @param sha - The commit id /// @param cwd - The root path to start searching from #[napi(js_name = "gitCommitBranchName")] @@ -265,14 +265,14 @@ pub fn js_git_branch_from_commit(sha: String, cwd: Option) -> Option) -> V } /// Get the diverged commit -/// +/// /// # Examples -/// +/// /// ``` /// const { getDivergedCommit } = require('workspace-node-tools'); /// const diverged = getDivergedCommit("main", process.cwd()); /// ``` -/// +/// /// @param refer - The branch to compare against /// @param cwd - The root path to start searching from #[napi(js_name = "getDivergedCommit")] @@ -297,14 +297,14 @@ pub fn js_get_diverged_commit(refer: String, cwd: Option) -> Option, local: Option) -> } /// Get the conventional for a package -/// +/// /// # Examples -/// +/// /// ``` /// const { getConventionalForPackage } = require('workspace-node-tools'); /// const conventional = getConventionalForPackage(PackageInfo{}, false, process.cwd(), ConventionalPackageOptions{}); /// ``` -/// +/// /// @param package_info - The package info /// @param no_fetch_all - Do not fetch all commits /// @param cwd - The root path to start searching from @@ -416,14 +416,14 @@ pub fn js_get_conventional_for_package( } /// Get bumps -/// +/// /// # Examples -/// +/// /// ``` /// const { getBumps } = require('workspace-node-tools'); /// const bumps = getBumps(BumpOptions{}); /// ``` -/// +/// /// @param options - The bump options #[napi(js_name = "getBumps")] pub fn js_get_bumps(options: BumpOptions) -> Vec {