最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

monorepo - pnpm locally referenced modules contain more than just dist folder contents - Stack Overflow

programmeradmin2浏览0评论

I have a very simple monorepo using a pnpm workspace with an api folder and a packages folder. My packages folder contains a "common" package, which has been added to the api project. The dist folder in common looks good, but when I look in /api/node_modules/common, I expected to see the contents of my common/dist folder. Instead I see EVERYTHING from inside my common folder.

Am I mistaken to expect to only see the contents of the dist folder in the consuming app's node_modules? I thought having the following in my common/package.json would cause only the dist folder to be included... "files": [ "dist" ],

Here is a snapshot...

I have a very simple monorepo using a pnpm workspace with an api folder and a packages folder. My packages folder contains a "common" package, which has been added to the api project. The dist folder in common looks good, but when I look in /api/node_modules/common, I expected to see the contents of my common/dist folder. Instead I see EVERYTHING from inside my common folder.

Am I mistaken to expect to only see the contents of the dist folder in the consuming app's node_modules? I thought having the following in my common/package.json would cause only the dist folder to be included... "files": [ "dist" ],

Here is a snapshot...

Share Improve this question asked Nov 19, 2024 at 0:04 Tim HardyTim Hardy 1,7671 gold badge19 silver badges44 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

As I've learned more about pnpm, I believe it uses symlinks for local/monorepo references, which would mean it's simply a link to the folder within the monorepo.

I really wish pnpm's documentation would publicize this better. The main problem with it is that a developer could very easily import something as follows...

import {CustomError} from 'common/src/errors/custom.error';

...even if that file is not exposed in the public api for the module - really no better than relative pathing. If the module were then to be published as an actual npm package, all that code would break.

I would have liked it if pnpm would honor the public api of a module, even when used locally in a monorepo, or at least honor the "files" property in package.json. This would promote good, modular coding. Perhaps it's impossible. If anyone knows of a workaround to honor a library's public api in a pnpm monorepo, I'd love to hear about it.

发布评论

评论列表(0)

  1. 暂无评论