diff --git a/.gitignore b/.gitignore index 1fbc882..3aa27e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target result .direnv +node_modules diff --git a/src/workspaces.rs b/src/workspaces.rs index 5b51e93..6a16360 100644 --- a/src/workspaces.rs +++ b/src/workspaces.rs @@ -13,14 +13,12 @@ use crate::{ #[derive(Debug)] pub struct Workspaces { - kind: PackageManagerKind, pub packages: Vec, } impl Workspaces { pub fn new(base_dir: PathBuf, kind: PackageManagerKind, patterns: Option>) -> Self { Self { - kind: kind, packages: match &kind { PackageManagerKind::Npm => Workspaces::resolve_npm_workspaces(base_dir, patterns), PackageManagerKind::Bun => Workspaces::resolve_bun_workspaces(base_dir, patterns), @@ -103,7 +101,6 @@ mod tests { fn test_new_each(case: NewTestCase) { let base_dir = case.input.0; let workspaces = Workspaces::new(base_dir.clone(), case.input.1, case.input.2); - assert_eq!(workspaces.kind, case.expected.kind); assert_eq!( workspaces.packages, case @@ -117,6 +114,52 @@ mod tests { test_each_serial!( test_new, + "npm_evaluate_negate_patterns" => NewTestCase { + input: ( + PathBuf::from("tests/fixtures/workspaces/npm"), + PackageManagerKind::Npm, + Some(vec![ + String::from("packages/*"), + String::from("!packages/c"), + ]), + ), + expected: Workspaces { + packages: vec![ + PathBuf::from("./packages/a"), + PathBuf::from("./packages/b"), + ], + }, + }, + "yarn_evaluate_negate_patterns" => NewTestCase { + input: ( + PathBuf::from("tests/fixtures/workspaces/yarn"), + PackageManagerKind::Yarn, + Some(vec![ + String::from("packages/*"), + String::from("!packages/c"), + ]), + ), + expected: Workspaces { + packages: vec![ + PathBuf::from("./packages/a"), + PathBuf::from("./packages/b"), + PathBuf::from("./packages/c"), + ], + }, + }, + "pnpm_evaluate_negate_patterns" => NewTestCase { + input: ( + PathBuf::from("tests/fixtures/workspaces/pnpm"), + PackageManagerKind::Pnpm, + None, + ), + expected: Workspaces { + packages: vec![ + PathBuf::from("./packages/a"), + PathBuf::from("./packages/b"), + ], + }, + }, "bun" => NewTestCase { input: ( PathBuf::from("tests/fixtures/workspaces/bun"), @@ -127,7 +170,6 @@ mod tests { ]), ), expected: Workspaces { - kind: PackageManagerKind::Bun, packages: vec![ PathBuf::from("./packages/a"), PathBuf::from("./packages/b"), diff --git a/tests/fixtures/workspaces/bun/packages/b/.gitkeep b/tests/fixtures/workspaces/bun/packages/b/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/fixtures/workspaces/npm/package-lock.json b/tests/fixtures/workspaces/npm/package-lock.json new file mode 100644 index 0000000..4bd1921 --- /dev/null +++ b/tests/fixtures/workspaces/npm/package-lock.json @@ -0,0 +1,24 @@ +{ + "name": "npm", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "typescript": "^5.3.3" + } + }, + "node_modules/typescript": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz", + "integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + } + } +} diff --git a/tests/fixtures/workspaces/npm/package.json b/tests/fixtures/workspaces/npm/package.json new file mode 100644 index 0000000..7c88992 --- /dev/null +++ b/tests/fixtures/workspaces/npm/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "typescript": "^5.3.3" + } +} diff --git a/tests/fixtures/workspaces/bun/packages/b/package.json b/tests/fixtures/workspaces/npm/packages/a/package.json similarity index 100% rename from tests/fixtures/workspaces/bun/packages/b/package.json rename to tests/fixtures/workspaces/npm/packages/a/package.json diff --git a/tests/fixtures/workspaces/npm/packages/b/.gitkeep b/tests/fixtures/workspaces/npm/packages/b/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/fixtures/workspaces/npm/packages/c/package.json b/tests/fixtures/workspaces/npm/packages/c/package.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/fixtures/workspaces/npm/packages/c/package.json @@ -0,0 +1 @@ +{} diff --git a/tests/fixtures/workspaces/pnpm/package.json b/tests/fixtures/workspaces/pnpm/package.json new file mode 100644 index 0000000..7c88992 --- /dev/null +++ b/tests/fixtures/workspaces/pnpm/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "typescript": "^5.3.3" + } +} diff --git a/tests/fixtures/workspaces/pnpm/packages/a/package.json b/tests/fixtures/workspaces/pnpm/packages/a/package.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/fixtures/workspaces/pnpm/packages/a/package.json @@ -0,0 +1 @@ +{} diff --git a/tests/fixtures/workspaces/pnpm/packages/b/.gitkeep b/tests/fixtures/workspaces/pnpm/packages/b/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/fixtures/workspaces/pnpm/packages/c/package.json b/tests/fixtures/workspaces/pnpm/packages/c/package.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/fixtures/workspaces/pnpm/packages/c/package.json @@ -0,0 +1 @@ +{} diff --git a/tests/fixtures/workspaces/pnpm/pnpm-lock.yaml b/tests/fixtures/workspaces/pnpm/pnpm-lock.yaml new file mode 100644 index 0000000..87f14d5 --- /dev/null +++ b/tests/fixtures/workspaces/pnpm/pnpm-lock.yaml @@ -0,0 +1,25 @@ +lockfileVersion: '6.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + dependencies: + typescript: + specifier: ^5.3.3 + version: 5.3.3 + + packages/a: {} + + packages/b: {} + +packages: + + /typescript@5.3.3: + resolution: {integrity: sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==} + engines: {node: '>=14.17'} + hasBin: true + dev: false diff --git a/tests/fixtures/workspaces/pnpm/pnpm-workspace.yaml b/tests/fixtures/workspaces/pnpm/pnpm-workspace.yaml new file mode 100644 index 0000000..3c056ee --- /dev/null +++ b/tests/fixtures/workspaces/pnpm/pnpm-workspace.yaml @@ -0,0 +1,3 @@ +packages: + - 'packages/*' + - '!packages/c' diff --git a/tests/fixtures/workspaces/yarn/package.json b/tests/fixtures/workspaces/yarn/package.json new file mode 100644 index 0000000..7c88992 --- /dev/null +++ b/tests/fixtures/workspaces/yarn/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "typescript": "^5.3.3" + } +} diff --git a/tests/fixtures/workspaces/yarn/packages/a/package.json b/tests/fixtures/workspaces/yarn/packages/a/package.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/fixtures/workspaces/yarn/packages/a/package.json @@ -0,0 +1 @@ +{} diff --git a/tests/fixtures/workspaces/yarn/packages/b/.gitkeep b/tests/fixtures/workspaces/yarn/packages/b/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/fixtures/workspaces/yarn/packages/c/package.json b/tests/fixtures/workspaces/yarn/packages/c/package.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/tests/fixtures/workspaces/yarn/packages/c/package.json @@ -0,0 +1 @@ +{} diff --git a/tests/fixtures/workspaces/yarn/yarn.lock b/tests/fixtures/workspaces/yarn/yarn.lock new file mode 100644 index 0000000..cd07bce --- /dev/null +++ b/tests/fixtures/workspaces/yarn/yarn.lock @@ -0,0 +1,8 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +typescript@^5.3.3: + version "5.3.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37" + integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==