7

At my organization, we are trying to create a monorepo of react components so they can be used on several sites.

We currently have a repo called react-components hosted on bitbucket and we wanted to set it up as a monorepo using lerna.js so the structure would look like

packages
    package_1
         package.json
         dist
    package_2
         package.json
         dist

However we don't host our npm packages on a registry but rather bitbucket and install them from there

so I'd like to be able to install each package into our websites via package.json like

"@company_name/react_components/package_1": "git+ssh://git@bitbucket.ds.company_name.com:7999/np/react-components.git#personal/jdaly/testBranch",

however I don't think you can have that path in a package.json so it should be more like

"@company_name/react_components": "git+ssh://git@bitbucket.ds.company_name.com:7999/np/react-components.git#personal/jdaly/testBranch",

and import like

import package_1 from "@company_name/react_components"

is it possible to set up a monorepo without using a package registry and just import all the monerepo packages via a git link? Haven't found much information on the web

I followed this tutorial https://blog.npmjs.org/post/186494959890/monorepos-and-npm But you're still importing your modules/packages via a package registry rather thank installing via a git link

After I build my packages I push them to the repo and in my website package.json I am referencing it like so

"@company_name/react-components": "git+ssh://git@bitbucket.ds.comapany_name.com:7999/np/react-components.git#personal/jdaly/firstCommit",

and when I go to node_modules the structure is

node_modules
     @company_name
          react_components
               packages
                    package_1
                    package_2
                    package_3
               lerna.json
               package.json

when it should be

node_modules
     @company_name
          react_components
                    package_1
                    package_2
                    package_3

Any help appreciated

James Daly
  • 1,357
  • 16
  • 26
  • perhaps you can improve your original question, I am not clear what you are asking. – Peter Jul 30 '19 at 18:48
  • The main question is in bold now is it possible to set up a monorepo without using a package registry and just import packages via a git link? Haven't found much information on the web – James Daly Jul 30 '19 at 18:52

3 Answers3

5

To anyone who stumbles upon this question - the answer is simple. In order to use lerna and create a monorepo system you need to have a package registry. That could be NPM or another product like https://verdaccio.org/ which is essentially a package registry you can use locally

James Daly
  • 1,357
  • 16
  • 26
0

Try the following:

npm install git+ssh://git@bitbucket.org/{user}/{repository}.git

Sources:

Peter
  • 2,796
  • 1
  • 17
  • 29
  • 1
    we already have existing private repos in which we install packages - but we don't have anything like a monorepo set up which is different than installing individual node packages – James Daly Jul 30 '19 at 18:40
0

For some, this will suffice:

You may install packages from the same monorepo, without installing from a registry, by referencing the folder in the same repo or a tarball built in a separate folder in the same repo.

Examples:

  • npm install ../package_1
  • npm install ../package_1.tgz

Reference: https://docs.npmjs.com/cli/install

See npm install <folder> and npm install <tarball file>

However, consider carefully before going this route for production codebases intended to be long lived. This is excellent for quick and dirty solution w/o using registry, but consider...

  • How you will support multiple versions as packages produce backward-incompatible changes (major version bumps)
  • How will your packages be built through your build CI/CD pipeline
lance.dolan
  • 3,493
  • 27
  • 36