-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
nx release
: allow restoring replaced workspace:
/file:
references after publishing
#20978
Comments
@virtuallyunknown I'm afraid it isn't documented yet, but right now for consistency reasons we have basically two different approaches when it comes to versioning dependencies:
Having said that, we now have some extra capabilities in I will leave this issue open to track |
nx release publish
: prefer pnpm
over of npm
internally in a pnpm workspace to publish packages to the registry.nx release
: allow restoring replaced workspace:
/file:
references after publishing
@JamesHenry thanks for the reply. I actually watched your YouTube video on About your comment - the first approach seems pretty self-explanatory, but in the 2nd approach where you use the NPM registry, what happens if for example one of your projects is set to private (private as in not published on any registry)? What would be the source of truth for the version number in that case? I think for the time being I will stick with the first approach with explicit versions in the Just a follow up question, is it possible to prevent Cheers! |
@virtuallyunknown are you packages released independently? Regarding the versioning performing formatting, it should only perform formatting based on your configured prettier installation. If you do not want your package.json files to be formatted, you should be able to add them to your |
@JamesHenry, I am using "fixed" versioning for the time being.
Is there any prior setup for prettier required for the I did follow your advice and added a {
"tabWidth": 12
} This actually worked, however I don't want prettier in my project, and it seems like the |
Ok that seems strange then, @fahslaj will take a look, do you have a repo you can share? UPDATE: If I had to guess, I would say it isn't actually formatting per se, it is just standard JSON serialization and deserialization happening as we patch the JSON data in the file. The vast majority of our userbase use prettier to standardize their formatting so that there is no manual enforcement required, which is why we automatically invoke it whenever it is available and this becomes a non-issue |
Yes, here it is actually, I was about to make an edit: https://github.com/virtuallyunknown/nx-monorepo It's very similar to the one I created for #20993. A dry run can be performed via |
Hopefully you saw my updated comment above, I posted it at the same time |
So if I'm understanding correctly, what you're saying is that Or in other words, I need prettier to get around this problem, or alternatively do some post-processing of the EDIT: Ok, yep. Apparently if you add prettier as a dependency then nx detects that and it will format the package.json files according to the specified `.prettierrc. config. Not ideal for me because I need an extra dependency, and it also messes with my global prettier configuration (coming from the VSCode extension), but I understand I'm probably in the tiny minority that will ever have such problem here so it is what it is. Thanks again for helping out. |
@virtuallyunknown yes exactly. So it sounds like you do value automated, deterministic formatting if you are using prettier via vscode... I have honestly never encountered a set up where you do seem to care about formatting but don't want to enforce that formatting on your project (and just run it ad hoc via your editor). Usually folks either use prettier in their project and editor, or not at all. Are all your projects currently only single developer? i.e. you don't need to worry about other people contributing using different formatting given it's not being checked or enforced at the project level? I think you're right that this is an edge case for that reason and probably not something that will be addressed within nx release |
@JamesHenry you are correct, I work as a single developer for the vast majority of the time and as such, the vscode extension is a good solution since you can have one global config file that applies everywhere. All formatting is basically enforced by the editor on save, and I don't have to pollute the project directory space with unnecessary config files. Though obviously this is not a good solution for collaborative projects. I am also not a big fan of prettier, even thought I understand the value it brings, so maybe I will even migrate to dprint once I have the time to look into it. Either way, not to make this too long, what you're saying makes total sense and I agree nx shouldn't try and cover every edge case out there. All that said, nx doesn't force any formatter (or not formatter) upon me so I can just work around the issue, or alternatively just install prettier. Please feel free to close the issue necessary. Cheers! |
Cool thanks @virtuallyunknown makes sense! We will keep the issue open because it primarily relates to the restoration of workspace/file references in source files, which as I mentioned I think is worth reevaluating now that we have the all in one |
What is the recommendation here? It seems most monorepo users are using Yarn or pnpm, and most are using the workspace protocol? It seems then that you cannot publish any packages using the Nx tooling, including the The recommendation is to implement the somewhat convoluted (with dependencies manually maintained) solution that the Nx repo uses? Or are you expecting the |
@isshesure my comment above covers the current case with workspace protocol:
The relevant configuration on the nx repo to make this work is here: Lines 41 to 53 in 69523f1
You will need to set the custom As stated in that comment, we are going to look again at this case now that the Technically if you wanted though I believe you could already script this to work on your source using the programmatic API. The version command returns an object covering the versions before and after, so you could use that to restore the files back to the workspace protocol after publishing. Again, I'm not saying this is as good as it can be, but that is the current workable state. Hope that helps for now, follow along with this issue for updates on both the docs for this and the improved DX that @fahslaj is working on |
Hi! Just faced this behaviour. I didn't provide any valuable input, but hope to somehow facilitate the complete support for yarn and pnpm publishing. |
👆 Adding to my recent comment: Is it expected? I also wouldn't say I'm experienced with nx, but I'm trying to find a complete tool for managing monorepo's builds, releases and versioning.
But after discovering Please, let me know If nx is the right tool here, maybe I have to stick to changesets/lerna for this kind of task. Thanks! Dump: repo link: https://github.com/eddienubes/carnytools UPDATE packages/styles/package.json
"name": "@carnytools/styles",
- "version": "0.0.1",
+ "version": "0.0.2",
"private": false,
UPDATE packages/types/package.json
"name": "@carnytools/types",
- "version": "0.0.1",
+ "version": "0.0.2",
"private": false,
"devDependencies": {
- "@carnytools/styles": "workspace:*"
+ "@carnytools/styles": "0.0.2"
}
NX Updating pnpm lock file
NX Error updating lock file with command 'pnpm install --lockfile-only'
Verify that 'pnpm install --lockfile-only' succeeds when run from the workspace root.
To configure a string of arguments to be passed to this command, set the 'release.version.generatorOptions.installArgs' property in nx.json.
To ignore install lifecycle scripts, set 'release.version.generatorOptions.installIgnoreScripts' to true in nx.json.
To disable this step entirely, set 'release.version.skipLockFileUpdate' to true in nx.json.
NX Command failed: pnpm install --lockfile-only |
The same issue. The solution proposed here looks more like a hack than a normal solution. |
@JamesHenry Please let us know if there is anything we can do. |
Hi Folks, Just to give an update on this one and a recap of why things behave the way they do right now: During the early stages,
One of the most powerful features of Later, we added the overall When dealing with any non semantic versioning references in package.json files (such as As folks have encountered, there is currently no automated way to revert these updated values back to the
I can appreciate that people do want the best of both worlds here, they want to be able to use I have therefore begun prototyping a utility to apply the restoration of the references after the publishing step takes place. It's functional already, I just want to make sure the DX is optimal. NOTE: It will not be possible to support this via the individual use of the CLI subcommands because it require passing around too much data, however it should be supportable for folks who use the overall I will share an update on here once I am happy with the DX and the utility/option is available. Many thanks! |
hey @JamesHenry I just stumbled upon this issue myself and seems there is no resolution for it so far. Is there any update on the utility you mentioned above? Or maybe in the meantime an option in nx come up to life which would preserve |
In the meantime I come up with following workaround in my pipeline in GitHub Actions:
It's not perfect since it creates additional commit after publish (only when workspace dependency has been removed), but better then nothing. |
Any update on an official solution? |
Question: wouldn't changing
According to: https://pnpm.io/workspaces#publishing-workspace-packages
So wouldn't using pnpm publish, when pnpm is the package manager, automagically fix the versions? Or am I misinterpreting something? |
We have a similar issue. I am just learning |
@ryanbas21 Thanks for pointing out this pnpm feature, I was not aware of it and am looking into it now. @dan-lee We may well expose it as an option to the existing executor, pending exploration into the differences with |
Maybe |
@wood3n That is only workable if during the versioning step those references are preserved. I do a combination of these approaches is workable when Therefore, the first step is open as a PR here: #27787 With the new version generatorOption, you will able to tell We will then be able to make a separate update to the publish executor to use |
I've taken #27787 further and added the detection for pnpm, and running pnpm publish in that case, which supports dynamically replacing the local package protocols during the publish step |
After releasing one of our NPM packages, we need to restore the workspace:* protocol in the package.json for local pnpm module resolution. For more informartion see nrwl/nx#20978
After releasing one of our NPM packages, we need to restore the workspace:* protocol in the package.json for local pnpm module resolution. For more informartion see nrwl/nx#20978
After releasing one of our NPM packages, we need to restore the workspace:* protocol in the package.json for local pnpm module resolution. For more informartion see nrwl/nx#20978
Shouldn't updateDependents 'never' also result in file: and workspace: references being preserved? This is not the case for us on v19.7.4. Actually it seems updateDependents does not take effect, we keep getting the references replaced by the new version. We also still end up with a file:. reference in the published npm. I thought #27787 should make sure pnpm publish is used and this is replaced correctly? nx report from CI that published the above package.
https://github.com/airlookjs/airlookjs/actions/runs/10941204631/job/30375312611 |
Hi there, |
For people that get here through search I suggest to see this angular-eslint/angular-eslint@d793c6f until proper documentation lands here. Be sure to add the following into
|
Description
Greetings. I just started learning with nx a few days ago, so in case I'm missing something obvious, sorry in advance.
That said, I've noticed that the
nx release publish
command is using npm under the hood to handle publishing to the registry, even if you are in a pnpm workspace. Unfortunately, this has some unintended side effects in relation to this particular pnpm feature:https://pnpm.io/workspaces#publishing-workspace-packages
In other words, if you're using the so called pnpm "workspace protocol" for internal dependencies in your monorepo, npm will pack an archive containing the word
workspace:
as a value for dependency versions (which is not valid for other package managers), instead of dynamically replacing these values with the appropriate versions like pnpm does.Motivation
I think
nx
being able to detect you're in a pnpm workspace (I think it already does that?) and then prefer the pnpm's equivalent ofpublish
would be beneficial for people who rely on the feature I linked to above.Alternatively, it would be even better if nx made this a configurable options or a cli parameter, similar to how
registry
works.Cheers!
EDIT: Okay so I actually just noticed that the
nx release version
command which I use beforepublish
is replacing allworkspace:
version occurrences with the actual version string for internal dependencies. I suppose this is intended, but then how do I make use the workspace protocol, or should I even do that?I also noticed that this commands reformats the package json files and changes all indentation, is there any way to disable it?
The text was updated successfully, but these errors were encountered: