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

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

Closed
manzoorwanijk opened this issue Jan 19, 2024 · 3 comments · Fixed by #201
Closed

Comments

@manzoorwanijk
Copy link
Contributor

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

/**
* Given a starting folder, search that folder and its parents until a supported monorepo
* is found, and return the collection of packages and a corresponding monorepo `Tool`
* object.
*
* By default, all predefined `Tool` implementations are included in the search -- the
* caller can provide a list of desired tools to restrict the types of monorepos discovered,
* or to provide a custom tool implementation.
*/
export async function getPackages(
dir: string,
options?: GetPackagesOptions
): Promise<Packages> {
const monorepoRoot: MonorepoRoot = await findRoot(dir, options);
const packages: Packages = await monorepoRoot.tool.getPackages(dir);

Structure:

├──📄 package.json
├──📁 packages
│	├──📁 pkg-a
│	│	├──📄 index.mjs
│	│	├──📄 package.json
│	├──📁 cli
│	│	├──📄 bin.mjs
│	│	├──📄 package.json
├──📁 apps
│	├──📁 app-a
│	│	├──📄 package.json
│	│	├──📁 src
  • cli package is consumed by monorepo root

Steps:

  • Open Codesandbox Devbox - https://codesandbox.io/p/devbox/manypkg-get-packages-bug-5zdymd
  • Sign in or download the devbox
  • Install the dependencies - yarn or you can also set it up using pnpm
  • In the root of the monorepo, run yarn dev-cli
  • Verify the outfit from the CLI package
  • cd packages/pkg-a and run yarn dev-cli again

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
Copy link
Collaborator

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

@manzoorwanijk
Copy link
Contributor Author

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
Copy link
Contributor Author

Created #201

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants