-
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
publishes TS files in combination with default (integrated) generators
#21855
Comments
I ran into the same issue with an Angular project with some "publishable" libraries. #21560 When I publish them (via either "nx release" or via "nx run my-library:nx-release-publish") the resulting npm package is the source code i.e. the "my-library/src/" folder. I expected it to publish the the compiled "dist/my-library" |
@lorenzodejong are you trying to have a standalone nx workspace? Or a nx workspace that could eventually contain multiple packages? Your description and steps to reproduce are not completely clear for me. However, as I'm an nx enthusiast, I saw your issue and tried to see if I could be of any help. https://github.com/thdk/nx-release-standalone-ts-library/tree/nrwl/nx/issues/21855 I have also documented my steps in the readme file in order to get it published using The final output looks like: ❯ npx nx release publish --dry-run
> NX Running target nx-release-publish for project my-lib:
- my-lib
With additional flags:
--dryRun=true
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
> nx run my-lib:nx-release-publish
📦 @my-org/my-lib@0.0.1
=== Tarball Contents ===
1.1kB LICENSE
10.3kB README.md
30B dist/index.d.ts
200B dist/index.js
116B dist/index.js.map
41B dist/lib/my-lib.d.ts
200B dist/lib/my-lib.js
172B dist/lib/my-lib.js.map
10.6kB dist/README.md
1.0kB package.json
=== Tarball Details ===
name: @my-org/my-lib
version: 0.0.1
filename: my-org-my-lib-0.0.1.tgz
package size: 4.3 kB
unpacked size: 23.8 kB
shasum: 759b65eeb426b540ea9d93f946c0854f352dcd4b
integrity: sha512-KLpammVULAbED[...]xZDugQ6nIdk4w==
total files: 10
Would publish to https://registry.npmjs.org/ with tag "latest", but [dry-run] was set
———————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
> NX Successfully ran target nx-release-publish for project my-lib There is one downside on my setup, it doesn't use the generated Update: below is the solution which sets the Either configure per project in "targets": {
"nx-release-publish": {
"options": {
"packageRoot": "dist/{packageName}"
}
}
}, or globally as "targetDefaults": {
"nx-release-publish": {
"options": {
"packageRoot": "dist/{packageName}"
}
}
}, The result output for running ❯ npx nx release publish --dry-run
With additional flags: ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
📦 @my-org/my-lib@1.1.0 276B CHANGELOG.md Would publish to https://registry.npmjs.org/ with tag "latest", but [dry-run] was set |
@thdk thanks for the extensive answer! I think my original message was indeed incorrect, i'm creating a monorepo with multiple packages. I think you have to choose for either a The point you touch upon with the generated |
Think I found the solution. When running > NX Successfully ran target nx-release-publish for project my-lib Note the name of the target. When I now look at the "targetDefaults": {
"nx-release-publish": {
"options": {
"packageRoot": "build/packages/{projectName}"
}
},
} So assuming you have a folder "targetDefaults": {
"nx-release-publish": {
"options": {
"packageRoot": "dist/packages/{projectName}"
}
},
} We can also tell Nx to bump the version in the generated "release": {
"git": {
"commit": true,
"tag": true
},
"projectsRelationship": "independent",
"version": {
"generatorOptions": {
"specifierSource": "conventional-commits",
"currentVersionResolver": "git-tag",
"fallbackCurrentVersionResolver": "disk",
"packageRoot": "dist/packages/{projectName}"
}
},
} Using conventional commits here to get the new version and git tags to find previously released versions since the version will not be bumped in the project's Example repo: https://github.com/thdk/nx-release-ts-packages |
I'm running into the same root issue. After adding But the next problem is that the version in the source code If i understand the comment above, you can workaround this issue by configuring release version to update the dist folder? But then the source folder is not matching still and that could lead to confusion as well? You'd just be relying on git tags to know what version your pkgs are on? |
Yeah i also played around a bit more with this setup and i'm running into the same issue as @acc-nicholas is mentioning. The Also in the last comment of @thdk it's important to note that the configuration option is "release": {
"git": {
"commit": true,
"tag": true
},
"projectsRelationship": "independent",
"version": {
"generatorOptions": {
"specifierSource": "conventional-commits",
"currentVersionResolver": "git-tag",
"fallbackCurrentVersionResolver": "disk",
"packageRoot": "dist/packages/{projectName}"
}
},
} |
i tried adding
|
Sorry for the type in my previous comment (and linked repo). I have fixed that for future readers. But you are right that, also as far as I know at the moment, with this setup git tags would become your source of truth. The version property of your This now becomes the same issue as my raised issue here: #20936 |
@fahslaj could you perhaps provide some insight in the recommended approach here? It feels like the Currently it's possible to set the
I would actually love to contribute here, it would be great if we can either support this workflow from the logic or write documentation on how to achieve this. Up until now i've had a pretty rough time discovering all the configuration options and the resulting output, so i feel like there's room for improvement. |
I have the same problem and wonder how many cases we can publish the source code directly. @JamesHenry, could you help us out here a little bit? Thanks! |
Thank you for the clear explanation. I agree that this flow should be supported better. For now, as a workaround, you can create a release script that uses the programmatic api. It would call However, I do think this should be supported entirely from the CLI. I'll bring this up with the team and follow up when I have updates. |
@fahslaj thanks for getting back to us! That's indeed what i ended up doing, however it did take some extra effort to only build the specific packages that are actually about to be released. I've created a gist with the current For anyone interested on how to actually utilise it: you can use $ node -r @swc-node/register tools/scripts/publish.ts I've also included a specific flow in which a prerelease only creates a Git tag for version tracking purposes, whereas the
For my team this is the ideal workflow, this allows you to test prerelease changes easily without being conflicted with version release commits on the PR branch. Potential bugOne thing i've noticed however with this workflow is that an incorrect version gets released when creating the prerelease using the @fahslaj i'm not sure if this bug has been reported already? Otherwise i'd be happy to create another more specific report for this with reproduction steps. |
@lorenzodejong I am glad you were able to make it work with that script! As for the potential bug, if you could create a specific report with repro steps that would be greatly appreciated! |
Hi @fahslaj, thanks for the prompt answer but I think that this should become top priority. At the moment, nx release feels like a smartphone than can do everything except making phone calls... you know what I mean 😅 |
@rainerhahnekamp let’s try and keep the discourse productive. typescript-eslint and angular-eslint are significant repos that are publishing their source files just fine with nx release, as are many others |
It's actually awesome work you guys have put into this new feature, i can already see it's a very useful tool for our team. Even though our workflow isn't fully supported yet from the default configuration, i do feel like it's close to being supported. That was also the reason for me to open this issue. If there's anything i can contribute to i'd be more than happy to take a shot at it. I've opened an issue for the specific issue regarding the prerelease version resolver: #22150 |
I tried this as well and it actually solves the issue of an outdated dist folder. In my pipeline I run {
"targetDefaults": {
"nx-release-publish": {
"dependsOn": ["build"],
"options": {
"packageRoot": "{workspaceRoot}/dist/libs/{projectName}"
}
}
},
"release": {
"projectsRelationship": "independent",
"projects": ["libs/*", "!libs/workspace-extensions"],
"releaseTagPattern": "{projectName}-{version}",
"git": {
"commitMessage": "chore({projectName}): release version {version} [skip-ci]"
},
"version": {
"conventionalCommits": true
},
"changelog": {
"projectChangelogs": {
"createRelease": "github"
}
}
},
}
|
@raketeFlo does the |
@ryan-mcginty-alation The only thing I don't like about this approach is that the build could fail and then I already versioned and pushed the changes... |
@JamesHenry thanks for this comment, I've started looking at typescript-eslint as a reference in trying to implement Interestingly, it also uses Are these tweaks all necessary to get an |
I've been trying to solve this problem for the last couple of days (for a react vite library), and finally settled on the following:
On publishing. this resulted in the following package, which I can consume:
Given the intent of project crystal, is this not a better approch than trying to mess with the nx release process? |
This repaired it for me. I want to say its just documentation issue rather than a actual bug |
@fahslaj i see this is closed as completed, is this solution the recommended/correct approach? #21855 (comment) |
My comment above seems to me the solution. It's missing documentation maybe worth a PR to fix |
This eventually also fixed the issue for me, however the only minor difference in my solution is that i targeted the The reason for this being that if you want to commit the updated |
I still don't have a fix for this. Is my only option to spend time figuring out my own custom release script like @lorenzodejong has done? Not sure why this is closed. The recommended fix of doing |
Reopening this, as I do think more documentation and clarification is needed. Depending on your workspace structure, @Jordan-Hall or @lorenzodejong 's solutions may work for you. There definitely needs to be more documentation on how Nx release handles the In the meantime, this comment from James on another thread might shed some light on the matter: #20978 (comment) Update: Additional documentation on the supported cases can be found on the docs site here. |
@fahslaj I' still wondering does the problem solved by NX or we should rely on workarounds? |
@HosseinSalmanian If you need the version of the package within source control to be updated, but also need to publish a different |
Normally, during CI we have a step for |
While true this enforces it to run. Nx cache will just use the cache build |
This comment was marked as outdated.
This comment was marked as outdated.
I commented this line in my local node_modules and everything worked well, release now works based on configured graph, not overwritten one: https://github.com/nrwl/nx/blame/c4c8b0150d827657632596656d92040108a338aa/packages/nx/src/utils/package-json.ts#L191 |
#22720 is a duplicate issue which is also impacted |
Current Behavior
Currently setting up a default (integrated) monorepo preset yields incorrect behavior when using
nx release
. By default, packages generated from@nx/js
with thepublishable
option will generate aproject.json
which outputs changes to the /dist folder on the root of the monorepo. However thepackage.json
in the src folder points to./src/package.json
.Running the
nx release
command seems to be directly publishing the package from the source directory, causing the actual TypeScript source files to be published instead of the resolved build output in thedist
folder.It seems like the current implementation of
nx release
is only intended to be used in package-based repositories, where you specify your package.json to point to adist
folder present in the actual source folder.The documentation also seems to be incorrect on this regard. If you look at the example of the published tarball you'll see that actual
.ts
files are getting published:Expected Behavior
I expect
nx release
to be directly compatible with projects generated from the default provided Nx generators, without having to change the behavior of thepackage.json
andproject.json
.GitHub Repo
No response
Steps to Reproduce
npx create-nx-workspace release-example-workspace
, select to create anIntegrated Monorepo
when asked for it.npx nx g @nx/js:lib mylib
npx nx release --first-release --dry-run
npx nx release publish --dry-run
Observed behavior:
.ts
files are present in the tarball.Nx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
No response
The text was updated successfully, but these errors were encountered: