Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repository -> PackageManagerRoot #6441

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/turbo-repository/__tests__/detect.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import * as path from "node:path";
import { Repository } from "../js/dist/index.js";
import { PackageManagerRoot } from "../js/dist/index.js";

describe("detect", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

want to change this and the test file name also?

it("detects a repo", async () => {
const repo = await Repository.detectJS();
console.log(repo);
const packageManagerRoot = await PackageManagerRoot.find();
console.log(packageManagerRoot);
const expectedRoot = path.resolve(__dirname, "../../..");
expect(repo.root).toBe(expectedRoot);
expect(packageManagerRoot.root).toBe(expectedRoot);
});

it("enumerates workspaces", async () => {
const repo = await Repository.detectJS();
const workspaces = await repo.workspaces();
const packageManagerRoot = await PackageManagerRoot.find();
const workspaces = await packageManagerRoot.packages();
expect(workspaces.length).not.toBe(0);
});

Expand Down
8 changes: 4 additions & 4 deletions packages/turbo-repository/js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

/* auto-generated by NAPI-RS */

export class Repository {
export class PackageManagerRoot {
readonly root: string;
readonly isMonorepo: boolean;
static detectJS(path?: string | undefined | null): Promise<Repository>;
readonly isSinglePackage: boolean;
static find(path?: string | undefined | null): Promise<PackageManagerRoot>;
packageManager(): PackageManager;
workspaces(): Promise<Array<Workspace>>;
packages(): Promise<Array<Workspace>>;
}
export class PackageManager {
readonly name: string;
Expand Down
5 changes: 3 additions & 2 deletions packages/turbo-repository/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ switch (platform) {

nativeBinding = loadViaSuffix(suffix);

const { Repository, PackageManager } = nativeBinding;
const { PackageManagerRoot, PackageManager, Workspace } = nativeBinding;

module.exports.Repository = Repository;
module.exports.PackageManagerRoot = PackageManagerRoot;
module.exports.PackageManager = PackageManager;
module.exports.Workspace = Workspace;
10 changes: 5 additions & 5 deletions packages/turbo-repository/rust/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use turborepo_repository::{
package_manager,
};

use crate::{Repository, Workspace};
use crate::{PackageManagerRoot, Workspace};

/// This module is used to isolate code with defined errors
/// from code in lib.rs that needs to have errors coerced to strings /
Expand Down Expand Up @@ -42,8 +42,8 @@ impl From<Error> for napi::Error<Status> {
}
}

impl Repository {
pub(crate) async fn detect_js_internal(path: Option<String>) -> Result<Self, Error> {
impl PackageManagerRoot {
pub(crate) async fn find_internal(path: Option<String>) -> Result<Self, Error> {
let reference_dir = path
.map(|path| {
AbsoluteSystemPathBuf::from_cwd(&path).map_err(|path_error| Error::StartingPath {
Expand All @@ -62,11 +62,11 @@ impl Repository {
Ok(Self {
root: repo_state.root.to_string(),
repo_state,
is_monorepo,
is_single_package: !is_monorepo,
})
}

pub(crate) async fn workspaces_internal(&self) -> Result<Vec<Workspace>, Error> {
pub(crate) async fn packages_internal(&self) -> Result<Vec<Workspace>, Error> {
// Note: awkward error handling because we memoize the error from package
// manager discovery. That probably isn't the best design. We should
// address it when we decide how we want to handle possibly finding a
Expand Down
16 changes: 8 additions & 8 deletions packages/turbo-repository/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use turborepo_repository::{
mod internal;

#[napi]
pub struct Repository {
pub struct PackageManagerRoot {
repo_state: RepoState,
#[napi(readonly)]
pub root: String,
#[napi(readonly)]
pub is_monorepo: bool,
pub is_single_package: bool,
}

#[napi]
Expand Down Expand Up @@ -53,10 +53,10 @@ impl From<RustPackageManager> for PackageManager {
}

#[napi]
impl Repository {
#[napi(factory, js_name = "detectJS")]
pub async fn detect_js_repository(path: Option<String>) -> Result<Repository, napi::Error> {
Self::detect_js_internal(path).await.map_err(|e| e.into())
impl PackageManagerRoot {
#[napi(factory)]
pub async fn find(path: Option<String>) -> Result<PackageManagerRoot, napi::Error> {
Self::find_internal(path).await.map_err(|e| e.into())
}

#[napi]
Expand All @@ -71,7 +71,7 @@ impl Repository {
}

#[napi]
pub async fn workspaces(&self) -> std::result::Result<Vec<Workspace>, napi::Error> {
self.workspaces_internal().await.map_err(|e| e.into())
pub async fn packages(&self) -> std::result::Result<Vec<Workspace>, napi::Error> {
self.packages_internal().await.map_err(|e| e.into())
}
}
Loading