-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Feature] pack/publish non-workspace folder #705
Comments
I'm not super enthusiast about this - I feel like fixing #650 would solve the same use case and more, wdyt? (instead of flattening the package, you'd just remap it to expose the lib folder at the root - possibly using something like publishConfig.exports) |
Let's start with: I fully understand the lack of enthusiasm. The package exports proposal looks like it covers a lot of our use case, but…
We can cover most of these "but"s via a yarn plugin:
That being said, I'm not sure if the same is true for some other build tools that output into a different folder, e.g. Google's bazel (which currently uses npm to publish). In any case I'll be trying out some stuff with a plugin, but I'm not happy with the possible solutions so far for point 1. |
For our use case, we have a root level dist folder for a monorepo where all workspaces are compiled to. This issue is keeping us from publishing packages right now. @bgotink did you figure out a workaround with a plugin or something? |
Yeah, @AndyClausen, I'm using a homebrew plugin to publish packages from another folder. The version I'm using daily at work is propietary, but it is more or less identical in idea to this one I've created in my spare time: https://github.com/snuggery/snuggery/blob/main/packages/yarn-plugin-snuggery-workspace/src/commands/publish.ts Note that this plugin makes the assumption that Also note I'm not sure how well (if at all) pre/post pack/publish lifecycle scripts are handled by the plugin. We use the angular CLI to publish via |
Thank you so much for sharing, and for the elaborate explanation! Also, anyone publishing compiled files from berry workspaces will most likely meet this issue. I expect this to become a big problem once more people start using berry. |
I just want to mention that I have the exact same problem with using an angular cli project to manage multiple libraries. The way angular cli builds the packages it creates a root level dist folder with all the libraries ready to publish in there. Which is separate to the workspaces folder. Would be great to get a way to publish those even though they are not part of the workspace. |
I haven't managed to fix this besides an ugly workaround where I change the workspace root to the build folder. There is no reason for this blocker to prevent publishing from a separate folder, is there? Could we get a yes or no on a solution for this, so we know whether to wait and keep using workarounds or to find a more permanent solution ourselves? It's completely understandable if this is just the intended behavior, I just want to know where to put my time and effort. |
For NX users, I've written this plugin. Hope it helps. |
Just want to add my 2cts after spending a day on the exports suggestion... As @arcanis points out exports should be able to handle this. It also shouldn't be that hard to programmatically generate exports for every directory in That said, I tried using I noticed
So I thought, let's just try to import
This all brings us back to the original question of permitting publish from within another directory, because this compatibility approach still requires all export paths under the package root instead of in a subdirectory. After analyzing all this I'm contemplating life's choices. Sometimes I think I should stop using NPM, Yarn, TypeScript and JavaScript altogether. Professionally I'm a C# developer (although our function descriptions do list TypeScript these days and I'm the very person who introduced it to the company), I consider myself a polyglot, but I just hate how hard it is to get anything built in this ecosystem (and don't get me wrong, I think Yarn is way better than NPM if we're talking quality of life for developers). But since we've got projects to deliver and I do hope for a future where this all gets easier, I see the following options:
As for option 1, I can be quite short: It doesn't work for me either. If the So option 2 it is then, with all the possible drawbacks of that choice. Since my packages get build on a CI system that starts from scratch for every commit I don't really need to worry about the pollution that much. I don't need to build during development, although that means I'm never actually testing if the build works until it hits CI (and even then I currently have no guarantee that the built package is actually usable, that's why I ended up here in the first place). I can probably gitignore all the artifacts as well, since the sources are in the |
Does it need to? I feel like yarn is trying to be too much. It shouldn't force a version workflow. It should potentially enable a version workflow, but why should my package manager force how I version my packages in this way, especially if my use case isn't exactly covered in how they've imagined it. It's overreaching, imho.
This is what I've (begrudgingly) resorted to. And it works fine, despite the "dirtiness" of having to use two package managers to do something that one should (and used to) be capable of. What issues are you having with this flow? |
I'm sorry but you totally missed this point. Yarn isn't forcing a version workflow, I'm actually using GitVersion instead of whatever Yarn approach you could take. What is important though is that if I have 5 packages in their own workspaces which have dependencies between them that those are kept in sync when I publish my packages (because a dependency version of
See the linked issue 😉 |
This sounds great of course, but I can't actually build from |
I totally get what you're saying. You have peer projects that depend on each other and yarn keeps them in sync. What I'm saying, is I shouldn't be forced to keep them in sync. What if I just want to use a version range (e.g. ^ or ~) or manually sync them. I can't because yarn forces their version syncing, which is what i meant by forcing a version workflow. I should be able to opt out of that if i want to sync my peer package deps differently, which would free all these commands to be able to operate outside of the workspace like yarn 1.x does. |
Just to illustrate the point. Let's say I have
{
"name": "pkg-a"
"version": "1.0.0"
...
}
{
"name": "pkg-b"
"version": "1.0.0"
"dependencies": {
"pkg-a": "^1.0.0"
}
} If I bump the version of |
@michaelfaith I think you're wrong and maybe Workspaces | Yarn can help you out. More importantly, let's stop this discussion in this thread. I'd love to think along, but let's keep the issues clean and focused. Feel free to mention me or email me if you want to continue this discussion with me. |
Well, definitely not wrong. I encountered this issue, which is why I'm even here. But I agree, let's keep this issue on task. Happy to discuss with you off-thread. |
OK, I want to reiterate on my previous messages and at my new findings. I can't stand when something (allegedly) doesn't work as documented, so I started with a small sample. Turns out that after all, it does work. I started with a handcrafted package with CommonJS and ES module, in Adding Vite to the mix I first struggled with So there we are, this now works, but updating my package to satisfy these constraints will then require me to update my In relation to the issue at hand, @arcanis suggestion to use exports to overcome the issue of not being able to publish from a non-workspace directory just won't work. It doesn't fix the problem we're having. It opens up a whole new set of problems. Maybe we'll have to face those problems some day anyway, but I'd appreciate if today's not the day. |
Final comment on the current situation from me. I resorted to using I still hope there's an opportunity to improve this situation and that my travel notes here will help others in the same situation. |
Unfortunately having the same issue in an angular monorepo where we build and publish libraries. I had to resort to making my built Either I'm missing something, and I'm not seeing the recommended way to publish built packages with Yarn, or everyone who wants to publish built packages will run into this issue, or have to make complicated third-party tools to deal with this new restriction. This was not an issue when we used Yarn Classic, and has made migrating a very tedious process. We could also resort to using npm to publish but we'd of course rather use Yarn everywhere for consistency because we appreciate it. |
Same issue here. We are using Also, now we would like to have @arethetypeswrong/cli in our devDependencies and run it with |
Describe the user story
As a developer I have a build step in my package but I want to publish a flat package.
For example, my package's typescript sources are in a
src
subfolder. In the published package I don't want there to be adist
orlib
folder with the resulting javascript files. I want the javascript files to be in the root of the published package. See also: the angular package format (spec)On the other hand, I don't want to have these javascript files dirty my workspace. Our current approach is to have a
dist
folder which contains the built javascript files, the package manifest and any assets, which then gets published instead of publishing the workspace folder.Describe the solution you'd like
I'd like to be able to use
yarn npm publish
andyarn pack
to publish folders that are not a workspace.I can see two ways for this to work at first glance:
yarn pack
andyarn npm publish
commands work in any folder, regardless of whether it's a workspace<repo root>/dist/@scope/package
as output folder)Describe the drawbacks of your solution
yarn pack
in a subfolder of a packageDescribe alternatives you've considered
index.js
that loadsts-node
and then re-exports thesrc/index.ts
file to allow us to run our workspace packages from source within the workspace.@scope/package/entry-point
)The text was updated successfully, but these errors were encountered: