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...
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.