Yarn: Yarn doesn't respect `publishConfig.directory` or doesn't support an alternative of that.

Created on 24 Oct 2019  路  6Comments  路  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?

bug, I think. Or a missing feature may be, let's find out.

What is the current behavior?
yarn doesn鈥檛 respect publishConfig.directory config.

If the current behavior is a bug, please provide the steps to reproduce.

In a monorepo, create 2 packages
packages/pkg-a
packages/pkg-b

pkg-b has a dependency on pkg-a.
pkg-a builds in build directory which contains individual modules, so not a single entry point like build/index.js. It鈥檚 supposed to be used as import some from 'pkg-a/some'.

Now, do yarn from the monorepo, it creates a symlink for pkg-a in node_modules. But that symlink points to the root directory of pkg-a, not the build. So the import paths gets messed up and I have to import as import some from 'pkg-a/build/some'.

What is the expected behavior?
Symlink should point to the directory set in publishConfig.directory OR at least a substitute that allows similar behaviour.

Please mention your node.js, yarn and operating system version.
yarn: 1.19.0
node: 10.13.0
os: Mojave 10.14.5

Most helpful comment

@Kadeluxe the way we solved this is by creating a custom script that runs on postinstall, and relinks everything taking publishConfig into account: https://github.com/webiny/webiny-js/blob/master/packages/project-utils/packages/linkPackages.js

Hope it's applicable in your project, works wonders for us :)

All 6 comments

This feature would be wonderful! Because of this, we are now getting away with tons of webpack aliases to help it resolve to the proper build|dist|lib (whatever you call it) folder. It would make our lives so easier if we could do it using the proposed publishConfig.directory or any other package level config.

I would be glad to work on this if we can get some feedback from the maintainers whether or not they would accept this.

Is that still not available? Any ways to achieve described behavior?

@Kadeluxe the way we solved this is by creating a custom script that runs on postinstall, and relinks everything taking publishConfig into account: https://github.com/webiny/webiny-js/blob/master/packages/project-utils/packages/linkPackages.js

Hope it's applicable in your project, works wonders for us :)

@Pavel910 this is useful, thank you! I actually don't mind having postinstall scripts as I already have several to do code-generation for some packages. I'm gonna use your solution as a reference.

@Pavel910 super effective script! thank you

I ended up using 'lerna link' command.
My script looks like:
"postinstall": "lerna bootstrap && lerna run build --scope=shared-lib && lerna link"

Was this page helpful?
0 / 5 - 0 ratings