简体   繁体   中英

How to install Node.js packages from Git repository inside specific folders

I am aware of how to install from Git, my question is different:

I have a repository structured somewhat like this:

project
--packages
  --moduleA
    --dist
      --index.js
      --package.json
    --src
      --index.mjs
    --package.json
  --moduleB
    --dist
      --index.js
      --package.json
    --src
      --index.mjs
    --package.json

And I want to know if it's possible to install both moduleA and moduleB using the same Git repository, and isntalling both from their respective dist directory. In other words, if their respective package.json declare their module names as @company/moduleA and @company/moduleB , then I want my node_modules to look like

node_modules
--@company
  --moduleA
    --index.js
    --package.json
  --moduleB
    --index.js
    --package.json

Is this possible using either npm or yarn ?

Yes, it is possible. You can use napa for that.

add this to your package.json . you can use the folder name as key in napa object.

{
  "scripts": {
    "install-from-github": "napa"
  },
  "napa": {
    "install_as_foo": "username/repo",
    "install_as_bar": "git@example.com:user/repo"
  }
}

run npm run install-from-github to run napa; or just do npx napa

actual complete example: this will insttall noop2 repo under @company/test1 and @company/test2

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "author": "",
  "license": "ISC",
  "dependencies": {
    "napa": "^3.0.0"
  },
  "scripts": {
    "install-from-github": "napa"
  },
  "napa": {
    "@company/test1": "yoshuawuyts/noop2",
    "@company/test2": "yoshuawuyts/noop2"
  }
}

output

在此处输入图像描述

I have currently settled with gitpkg and yarn has package manager.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM