Skip to content

Publish does not resolve workspace dep when its name doesn't match its directory path #251

Open
@chuckdries

Description

@chuckdries

In a monorepo setup using yarn workspaces (possibly others, haven't checked), the name of each package in the monorepo is determined by the name field in that package.json. This can be the same as the name of the folder it resides in, but they are allowed by yarn to be different.

Take a repo set up like this

package.json (with "workspaces": ["packages/*"])
packages
| foo
| | package.json (with "name": "@my-org/foo-lib")
| bar
| | package.json (with "name": "@my-org/bar-lib")

foo lists @my-org/bar-lib in its package.json dependencies (and can import from that package using that name just fine)

When you try to yalc publish in packages/foo, you'll get a warning Could not resolve workspace package location for @my-org/shared-lib.

It looks like it attempts to resolve workspace dependencies by assuming their directory names match their package names

const pkgPath = require.resolve(join(pkgName, 'package.json'), {

Instead, it probably needs to traverse every package in the root package.json's workspaces and collect a map of their names to their directory paths.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions