You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, we use lerna for managing version updates and making new releases. For this to work, all libraries have to be in packages directory and it is expected that all libraries have package.json in packages/<LIB_NAME>/package.json. When a build is triggered, packages generate directory packages/<LIB_NAME>/dist with build files. For release to NPM, the whole packages/<LIB_NAME> dir gets packed and published. There are a couple of issues with this:
package.json that ends up on npm includes things that are relevant only for development - things like scripts, devDependencies, etc.
package.json has to be edited manually to add build-related things like:
This is not really something that should be commited at all. If the build process changes (for example, if we switch to a different bundler) and starts generating different output files in dist, we don't want to update package.json manually and commit to the repository.
packages/<LIB_NAME> dir can contain many things which are not relevant for NPM release and we have to list all of those things in .npmignore. In this process we of course miss some things, as can be seen on the example of @datx/core release that includes things like tsconfig.mobx.json:
tsconfig files are in no way relevant for package that gets pushed to NPM and should not be here. It even references some files which did get properly .npmignored ("extends": "./tsconfig.build.json",) and which are not in the released tarball.
If we move to publishing from dist, we can basically remove all .npmignore files that are currently being maintained tediously for each individual package.
Proposed solution
A solution which would work better is to pack packages/<LIB_NAME>/dist folder for NPM release instead of packing packages/<LIB_NAME>. Build process for all packages should be updated in a way that makes all the required files for publishing to NPM available in packages/<LIB_NAME>/dist. To publish all packages from dist, we would run lerna publish --contents dist
Build process should copy README.md and LICENSE files to dist as well.
Proposed solution should include two package.json files for each package. One that will be used for development and one that will be used as a basis for the build process and packaging (I will call this "release package.json" later in the text). Release package.json should include all the info that is relevant for publishing, but it should not hard-code links to build output files. Instead, the release package.json should be copied over to dist directory and the build process should update it with relevant links to build files.
Example of how this is done for angular packages:
This is the development package.json that should not be the one that is packaged into NPM release - packages/datx-jsonapi-angular/package.json:
This is the package.json that is copied over for release and is "augmented" with links to build bundle files - packages/datx-jsonapi-angular/projects/datx-jsonapi-angular/package.json:
As you can see, this is the file which has all the required metadata for NPM release. It also defines peerDependencies and version, but it has no mention of things like build scripts.
During the build process, this file gets copied over to packages/datx-jsonapi-angular/dist/package.json and gets augmented with links to build files (see what gets appended at the bottom of the file):
To release to NPM< we have to package packages/datx-jsonapi-angular/dist directory that looks like this:
That way we don't have to care about .npmignoring things, all that ends up in dist is what needs to be published.
Unclear things
It is not clear to me how lerna version and publish command will work with two package.json files per project. Maybe we can keep version in development package.json file for each lib to be 0.0.0 and update versions only in release package.json. I do not know how to configure lerna to target specific package.json file (release instead of development file).
The text was updated successfully, but these errors were encountered:
@isBatak clean-packages solves only part of the issue - it strips package.json that gets published to NPM. However, you still have to take care of some things manually yourself:
Relevant version
Relevant libraries
Breaking change
No
Description
Currently, we use lerna for managing version updates and making new releases. For this to work, all libraries have to be in
packages
directory and it is expected that all libraries havepackage.json
inpackages/<LIB_NAME>/package.json
. When a build is triggered, packages generate directorypackages/<LIB_NAME>/dist
with build files. For release to NPM, the wholepackages/<LIB_NAME>
dir gets packed and published. There are a couple of issues with this:package.json
that ends up on npm includes things that are relevant only for development - things likescripts
,devDependencies
, etc.package.json
has to be edited manually to add build-related things like:This is not really something that should be commited at all. If the build process changes (for example, if we switch to a different bundler) and starts generating different output files in dist, we don't want to update package.json manually and commit to the repository.
packages/<LIB_NAME>
dir can contain many things which are not relevant for NPM release and we have to list all of those things in.npmignore
. In this process we of course miss some things, as can be seen on the example of@datx/core
release that includes things liketsconfig.mobx.json
:tsconfig
files are in no way relevant for package that gets pushed to NPM and should not be here. It even references some files which did get properly .npmignored ("extends": "./tsconfig.build.json",
) and which are not in the released tarball.If we move to publishing from dist, we can basically remove all .npmignore files that are currently being maintained tediously for each individual package.
Proposed solution
A solution which would work better is to pack
packages/<LIB_NAME>/dist
folder for NPM release instead of packingpackages/<LIB_NAME>
. Build process for all packages should be updated in a way that makes all the required files for publishing to NPM available inpackages/<LIB_NAME>/dist
. To publish all packages from dist, we would runlerna publish --contents dist
Build process should copy README.md and LICENSE files to dist as well.
Proposed solution should include two package.json files for each package. One that will be used for development and one that will be used as a basis for the build process and packaging (I will call this "release package.json" later in the text). Release package.json should include all the info that is relevant for publishing, but it should not hard-code links to build output files. Instead, the release package.json should be copied over to dist directory and the build process should update it with relevant links to build files.
Example of how this is done for angular packages:
This is the development package.json that should not be the one that is packaged into NPM release -
packages/datx-jsonapi-angular/package.json
:This is the package.json that is copied over for release and is "augmented" with links to build bundle files -
packages/datx-jsonapi-angular/projects/datx-jsonapi-angular/package.json
:As you can see, this is the file which has all the required metadata for NPM release. It also defines peerDependencies and version, but it has no mention of things like build scripts.
During the build process, this file gets copied over to
packages/datx-jsonapi-angular/dist/package.json
and gets augmented with links to build files (see what gets appended at the bottom of the file):To release to NPM< we have to package
packages/datx-jsonapi-angular/dist
directory that looks like this:That way we don't have to care about .npmignoring things, all that ends up in dist is what needs to be published.
Unclear things
It is not clear to me how lerna version and publish command will work with two package.json files per project. Maybe we can keep version in development package.json file for each lib to be
0.0.0
and update versions only in release package.json. I do not know how to configure lerna to target specific package.json file (release instead of development file).The text was updated successfully, but these errors were encountered: