Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publishDirectory appears to break monorepos #5115

Closed
antony opened this issue Jul 29, 2022 · 7 comments · Fixed by #5125
Closed

publishDirectory appears to break monorepos #5115

antony opened this issue Jul 29, 2022 · 7 comments · Fixed by #5125
Assignees
Labels
area: monorepo Everything related to the pnpm workspace feature type: bug
Milestone

Comments

@antony
Copy link

antony commented Jul 29, 2022

pnpm version: 7.7.0

The addition of publishDirectory to the lockfile, and subsequent pointing of devDependencies to publish directories breaks monorepos where builds are required to publish the dependencies.

Often, the publishDirectory doesn't exist at development time.

Code to reproduce the issue:

Working on a repro, but offering this as a heads-up whilst that happens.

Expected behavior:

'@beyonk/brand': link:../../components/brand

With pnpm < 7.7.0, dependencies within the lockfile point to the development files, not the published files, which might not yet have been built. They certainly aren't build during development, because it would require running (for example) the svelte-kit package command on every change.

Package is run at build time, on CI, and may not even exist locally.

pnpm does not point dev dependencies to published directories.

Actual behavior:

'@beyonk/brand': link:../../components/brand/package

pnpm adds publishDirectory: package to the lockfile, and points the dependency path to the publishDirectory.

Additional information:

  • node -v prints: v16.15.0
  • Windows, macOS, or Linux?: Linux
  • SvelteKit, pnpm 7.7.0, monorepo.
@zkochan
Copy link
Member

zkochan commented Jul 29, 2022

This appears to be the expected behavior, see #3901

As a workaround, you may use linked dependencies if the issue is with devDependencies. So in your package.json you may actually use:

"@beyonk/brand": "link:../../components/brand"

@zkochan zkochan added the area: monorepo Everything related to the pnpm workspace feature label Jul 29, 2022
@zkochan
Copy link
Member

zkochan commented Jul 29, 2022

But looks like it is a breaking change, so I will make it opt-in for now.

@gfellerph
Copy link

I'm running into something similar for swisspost/design-system#225. The dist folders don't exist when pnpm install is running, therefore (my guess), the link is not set up correctly in the node_modules of dependents.

A fix would be creating an empty dist folder and linking that. In the building phase, the package files will appear in the folder and dependents would be able to use the packages.

@zaripych
Copy link

I'm running into an issue here as well. My monorepo is designed in a way that publishDirectory is only used for publishing a package (as the name of the config clearly suggests). It worked just fine before v7.7.0.

This was possible for me as packages in my monorepo reference each others TypeScript files directly, instead of using compilation/bundler targets. Before release I could pretty much do anything without having to explicitly build packages - with any code changes being picked up immediately, with every package linked to each other - now nothing works unless I bundle everything first. It's quite inconvenient and slows down development a lot to have to bundle packages just to see type system pick up changes from another package. I don't know how widely adopted this approach is - but it would be shame as dev experience is much more superior this way.

Additionally - publishDirectory is expected to contain another package.json which is result of bundling, possibly with different dependencies in it. This could happen as some dependencies are bundled-in and some remain unchanged. This is possible if dependencies are inlined via rollup. Or when devDependencies are completely removed for cleanliness. Which of these package.json would be used as the source of truth for dependencies is a little unclear.

I would recommend reverting the change in v.7.7.0 related to publishDirectory and possibly introducing a separate configuration (e.g. maybe named linkDirectory?) with edge cases of different dependencies documented somewhere. 👍

@zkochan
Copy link
Member

zkochan commented Jul 30, 2022

I can revert it and add a new setting to publishConfig that will tell pnpm to symlink the package from the publish directory. Something like

{
  "publishConfig": {
    "directory": "dist",
    "linkDirectory": true
  }
}

@antony
Copy link
Author

antony commented Jul 30, 2022 via email

@zkochan
Copy link
Member

zkochan commented Jul 30, 2022

This is how publishConfig.directory works in Lerna.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: monorepo Everything related to the pnpm workspace feature type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants