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

publishConfig.directory does not get symlinked for workspace packages if the directory does not exist #5219

Closed
michaelwarren1106 opened this issue Aug 17, 2022 · 9 comments · Fixed by #5253
Assignees
Milestone

Comments

@michaelwarren1106
Copy link

michaelwarren1106 commented Aug 17, 2022

When a package in a monorepo is depended on by other packages, and has the following publishConfig settings in package.json:

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

the symlink only gets created if the dist folder actually exists.

This setting breaks repos that follow a typical install => link => build model. Monorepos with lots of cross-repo dependencies cannot successfully build dists without upstream local dependencies also being built first.

pnpm version:

7.9.0

Code to reproduce the issue:

Repro repo here:
https://github.com/michaelwarren1106/pnpm-linking-repro
Steps to reproduce the issue are in the README.md

Expected behavior:

Symlinks are created for the specified publishConfig.directory path (including a package scope directory if necessary) regardless of whether or not the specified directory exists.

Actual behavior:

Symlinks are not created if the specified publishConfig.directory folder does not exist. Warnings are seen in the console instead.

Related issues

#5115
#3901

Related Discussion

#5204 (reply in thread)

@martinbiard
Copy link

I also experience the same issue. For now, I had to abandon the publishConfig feature completely, and instead add this at the end of my app build scripts:

    const libs = Helpers.joinPath(outDir, 'node_modules', '@mycompany')

    Helpers.readDirectory(libs).forEach((item) => {
        if (Helpers.isSymbolicLink(item)) {
            const oldTarget = Helpers.readLink(item)
            const newTarget = Helpers.joinPath(oldTarget, 'build')

            Helpers.ensureSymbolicLink(newTarget, item)
        }
    })

What this does, is, after building my apps, it goes into its node_modules under @mycompany scope, and replaces all links to libs workspace roots with libs build directories instead.

@bertybot
Copy link

I literally just put a placeholder md file in the directory with a note to get rid of it once this issue is fixed, and that work around has been working for me

@michaelwarren1106
Copy link
Author

haha i haven’t thought of that! i think that maybe could work

@jason-ha
Copy link

I was just trying with 7.9.3 where I pre-created the one publishConfig.directory that is used in my monorepo. I did not find that the symlink created in this case to the publish directory. Is the issue qualifying text about "if the directory does not exist" superfluous?

@michaelwarren1106
Copy link
Author

you also need the publishConfig.linkDirectory set to true also in order for pnpm to attempt to symlink the directory. i have both and it doesn’t symlink if the directory listed doesn’t exist

@jason-ha
Copy link

I had linkDirectory=true but the issue was I had already run install once that set the resolution not using the publishConfig.directory. I was trying to refresh by deleting the symlink. But I needed to delete the pnmp-lock.yaml file to force resolution. [ pnpm noob :) ]

@michaelwarren1106
Copy link
Author

thanks! this is awesome! did this fix land in 7.9.4?

@zkochan
Copy link
Member

zkochan commented Aug 24, 2022

No, it will be soon released in 7.9.5

@michaelwarren1106
Copy link
Author

sweet, thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants