Skip to content

Using smartbundle-powered monorepos as git deps #162

Description

@MOZGIII

yarn (and pnpm, but with different approach - so it is not relevant) allows using repos with multiple packages as a git dependency. The way it works is you specify git path instead of version, passing #workspace=<package name> and it will locate the package in the repo and use it, instead of using root package.

Before placing the package at the node_modules, yarn will execute the pack command, which, in turn, will execute prepack action.

So, a typical usage would be to have a package that has "prepack": "yarn build" script, and for the build script of the said package to have the "build": "tsup" or something. Then yarn makes the packaged archive and then uses that for node_modules (as opposed to raw git source).

So, this works really great - except for the development of the packages inside the said repo. This is the problem that smartbundle's monorepo doc refers to - if you use exports field as package.json you can't use publishConfig and thus can specify different files for local, non-packed, version of the package.

Now, here's the problem. smartbundle tries to solve this with linking via a special command - but that isn't going to work for this use case I've described with git dependencies involved. Why? Because yarn won't call that magic command smartbundle-monorepo-link. It can't be added to "prepack" script cause it's too late - yarn will fail to find the right package in the workspace and will bail earlier.

However, I think this puzzle can be solved, and the answer is corepack. If smartbundle registers itself as a packageManager and simply wraps yarn and proxies all invocations to yarn scripts with prepending that linking magic - it will also work with git repo.

Thanks for your attention.

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