11

In my react project, I am trying to install a private package using the git URL. I want to specify a branch name in the URL which will be dynamic.

In the package.json file, when I hardcode the branch name it works fine.

dependencies: {
    ...
    my-package: "git+https://<git-url-of-my-package>#develop",
    ...
}

The problem is when I use the variable, it does not work as expected.

dependencies: {
    ...
    my-package: "git+https://<git-url-of-my-package>#$BRANCH_NAME",
    ...
}

I am not sure here how to pass the branch name dynamically and I need some help in understanding the same.

Note: I don't want to install <my-package> using another npm script. I want to install it with other dependencies using npm-install.

Thanks in advance.

Prayag Choraria
  • 710
  • 5
  • 15
  • I'm using MacOs and linux – Prayag Choraria Jun 04 '21 at 08:41
  • 2
    Using variables in a regular dependency is not possible as far as I know, but if you use a `postinstall` script, a script can be run automatically after calling `npm install`. An example close to your situation: https://stackoverflow.com/a/56639755/15706847 – Vincent Bitter Jun 07 '21 at 05:14
  • Using environment variables can be done in scripts section. So you can create a preinstall script https://docs.npmjs.com/cli/v7/using-npm/scripts that pulls the code into some directory. And then point to the local directory in your dependencies. – Yazeed Sabri Jun 08 '21 at 16:30

1 Answers1

0

Check URL as dependency, You can specify tarball URL

https://docs.npmjs.com/cli/v7/configuring-npm/package-json#urls-as-dependencies

Check This also - Using the git urls with specific branch or commit version in package.json does not work - https://github.com/yWorks/svg2pdf.js/issues/102

kkchaitu
  • 631
  • 2
  • 5
  • 24