nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.5k stars 2.34k forks source link

Make existing library publishable #2329

Closed sumitparakh closed 3 years ago

sumitparakh commented 4 years ago

Is there any way to convert existing non-publishable nrwl library into a publishable library using any CLI command?

juristr commented 4 years ago

@sumitparakh Thanks for submitting this question. Right now there is no automated schematic that would be able to convert an existing library into a publishable one. We're going to take a look at this, but it requires some larger changes as it involves potentially multiple libraries (angular, node, react).

Meanwhile, you could manually adjust your library. I suggest

  1. creating a new nx workspace in separate folder with the same npmScope etc as your current workspace.
  2. Generate a new publishable library in that new workspace with the same name as the library you'd like to convert

That way you have the right names in the various files and you can copy them over to your existing workspace.

Once we decide to implement an automated migration, we'll let you know 😃

gaalvarez commented 4 years ago

Additionally to copy new files created by --publishable flag in the @juristr solution , is necessary some changes in the next files:

angular.json: ... "architect": { "build": { "builder": "@nrwl/angular:package", "options": { "tsConfig": "libs/<lib-name>/tsconfig.lib.json", "project": "libs/<lib-name>/ng-package.json" }, "configurations": { "production": { "tsConfig": "libs/<lib-name>/tsconfig.lib.prod.json" } } }, ... package.json: add 1 dependency: tslib y 2 devdependencies: @angular-devkit/build-ng-packagr y ng-packagr.

deshmanedarshan commented 4 years ago

Hi folks, do we have any progress on this ? I have a shared angular library in NX morepo workspace which is not publishable. I at least want it to be packageable (create .tgz package) so that I can push to AZURE artifacts and us it from there. Can anyone please help me with this like what steps to do so that I can package it ? Thanks !

lazarljubenovic commented 3 years ago

Disappointed that this is not an option yet.

Either way, I tried making a library publishable manually, but I can't figure out the differences between libraries made --publishable and --buildable. I looked into nx.json and workspace.json, their package.json, TypeScript config, but found everything exactly the same. What's the actual observable difference of --publishable and --buildable? It shouldn't be difficult to write a custom executor for this task then.

PS. This was in a project generated with the oss default; all libraries are node libraries.

juristr commented 3 years ago

@lazarljubenovic this is something we'd like to work on, but haven't come around yet.

Right now the main visible difference is the builder in workspace.json or angular.json. For instance the Angular package builder uses @nrwl/angular:ng-packagr-lite. Conceptually the difference is that "buildable" libs are just there for building purpose, while "publishable" are for publishing. Right now they're pretty similar based on the result they produce, but that might change in the future.

Meanwhile you might want to give this community schematic a look, which helps converting existing libraries to buildable ones: https://www.npmjs.com/package/@trellisorg/make-buildable

I'll close this issue for now, given there's the community schematic to help convert to buildable libraries.

mackelito commented 3 years ago

@lazarljubenovic did you try the make-buildable schematics? Did it work?

dobromyslov commented 3 years ago

npm repo has no link to the github. Here is the source code and readme for @trellisorg/make-buildable:

@mackelito i tried versions trellisorg/make-buildable 0.0.10 and NX 12.5.9 but it works with some issues and requires manual fixing. It replaces dashes with slashes in the package name and also slightly reformats workspace.json (angular.json) file.

roblevintennis commented 3 years ago

Thanks for a nice tool and sorry to piggyback, but…

I had to just generate a new library project and copy my files over since we can't make existing a --publishable. It was surprisingly painless though and I took notes: https://roblevin.hashnode.dev/adventures-in-creating-an-npm-library-with-nrwlnx -- just in case someone else faces this and gets as stressed out as I did :-) Also, the nx remove command is available so cleaning up the previous version is doable as well. All said, it'd be nice addition to be able to do generator updates but I have to imagine that's gonna be quite a bit of work for the nx team to code up for all frameworks supported!

Falven commented 2 years ago

Thanks for a nice tool and sorry to piggyback, but…

I had to just generate a new library project and copy my files over since we can't make existing a --publishable. It was surprisingly painless though and I took notes: https://roblevin.hashnode.dev/adventures-in-creating-an-npm-library-with-nrwlnx -- just in case someone else faces this and gets as stressed out as I did :-) Also, the nx remove command is available so cleaning up the previous version is doable as well.

Surprised nobodys written a simple script to do this yet

All said, it'd be nice addition to be able to do generator updates but I have to imagine that's gonna be quite a bit of work for the nx team to code up for all frameworks supported!

Yeah but this seems like a large oversight. I'm sure many others have started writing some shared functionality, had a eureka moment on how useful your functionality is and want to share it with others.

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.