Thinkmill / manypkg

β˜”οΈ An umbrella for your monorepo
MIT License
891 stars 48 forks source link

`getPackages` fails when given a monorepo subdirectory instead of root directory. #200

Closed manzoorwanijk closed 6 months ago

manzoorwanijk commented 8 months ago

getPackages expects dir argument to be the monorepo root but its description says otherwise.

https://github.com/Thinkmill/manypkg/blob/52d5dcb469b1d6781f56cff15b3556c8856ce8ca/packages/get-packages/src/index.ts#L26-L40

Structure:

β”œβ”€β”€πŸ“„ package.json
β”œβ”€β”€πŸ“ packages
β”‚   β”œβ”€β”€πŸ“ pkg-a
β”‚   β”‚   β”œβ”€β”€πŸ“„ index.mjs
β”‚   β”‚   β”œβ”€β”€πŸ“„ package.json
β”‚   β”œβ”€β”€πŸ“ cli
β”‚   β”‚   β”œβ”€β”€πŸ“„ bin.mjs
β”‚   β”‚   β”œβ”€β”€πŸ“„ package.json
β”œβ”€β”€πŸ“ apps
β”‚   β”œβ”€β”€πŸ“ app-a
β”‚   β”‚   β”œβ”€β”€πŸ“„ package.json
β”‚   β”‚   β”œβ”€β”€πŸ“ src

Steps:

Expected Behavior:

The command should be successful and should be able to output the monorepo packages

Actual Behavior:

It throws an error - TypeError: Cannot read properties of undefined (reading 'packages')

Should it be

const monorepoRoot: MonorepoRoot = await findRoot(dir, options);
const packages: Packages = await monorepoRoot.tool.getPackages(monorepoRoot.rootDir);
//                                                             ^^^^^^^^^^^^^^^^^^^^

instead of

const monorepoRoot: MonorepoRoot = await findRoot(dir, options);
const packages: Packages = await monorepoRoot.tool.getPackages(dir);
//                                                             ^^^
Andarist commented 8 months ago

The proposed solution sounds plausible. We'd appreciate a PR with this fix and the appropriate test case.

manzoorwanijk commented 8 months ago

The proposed solution sounds plausible. We'd appreciate a PR with this fix and the appropriate test case.

Sure, I will try to create one.

manzoorwanijk commented 8 months ago

Created #201 βœ