2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

yarn publish & yarn link

Last updated at Posted at 2019-01-16

yarn publish & yarn link

リポジトリサーバ(nexus)にnpmモジュールをpublishしてそれをpullする。

ソースは github にあげました。

リポジトリサーバをローカルに立てる

  • 参考サイト

実装

library(yarn-fetch-library)

yarn-fetch-library/package.json
{
  "name": "@va034600/yarn-fetch-library",
  "version": "1.0.5",
  "description": "",
  "main": "./src/index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "underscore": "^1.9.1"
  },
  "files": [
    "src"
  ],
  "publishConfig": {
    "registry": "http://localhost:9998/repository/my-npm-hosted-repo/"
  }
}
yarn-fetch-library/yarn.lock
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


underscore@^1.9.1:
  version "1.9.1"
  resolved "http://localhost:8081/repository/my-npm-group-repo/underscore/-/underscore-1.9.1.tgz#06dce34a0e68a7babc29b365b8e74b8925203961"
  integrity sha512-5/4etnCkd9c8gwgowi5/om/mYO5ajCaOgdzj/oW+0eQV9WxKBDZw5+ycmKmeaTXjInS/W0BzpGLo2xR2aBwZdg==
yarn-fetch-library/src/index.js
var _ = require('underscore');
var https = require('https');

function fetchSample(path) {
    var req = https.request(path, (res) => {
        res.on('data', (chunk) => {
            console.log(`BODY: ${chunk}`);
        });
    })
    req.end();
    _.each([1, 2, 3], console.log);
};

module.exports = fetchSample;

main(yarn-fetch-main)

yarn-fetch-main/package.json
{
  "name": "yarn-fetch-main",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.js",
  "private": false,
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@va034600/yarn-fetch-library": "^1.0.5"
  }
}
yarn-fetch-main/yarn.lock
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"@va034600/yarn-fetch-library@^1.0.5":
  version "1.0.5"
  resolved "http://localhost:8081/repository/my-npm-group-repo/@va034600/yarn-fetch-library/-/yarn-fetch-library-1.0.5.tgz#354fb62ff73126f480152421d901ba654e84914b"
  integrity sha512-ccvs3zrAY1Y5DW0S68ljJNyn1IoBFZUu/8Jqk6hDBxAqtmTlpzlsWIL0OVxxjYleX+SRIHqpE1/Ig3KtcWoSeg==
  dependencies:
    underscore "^1.9.1"

underscore@^1.9.1:
  version "1.9.1"
  resolved "http://localhost:8081/repository/my-npm-group-repo/underscore/-/underscore-1.9.1.tgz#06dce34a0e68a7babc29b365b8e74b8925203961"
  integrity sha512-5/4etnCkd9c8gwgowi5/om/mYO5ajCaOgdzj/oW+0eQV9WxKBDZw5+ycmKmeaTXjInS/W0BzpGLo2xR2aBwZdg==
yarn-fetch-main/src/index.js
console.log("-----")

var fetchSample = require("@va034600/yarn-fetch-library")
fetchSample("https://google.com")

console.log("-----")

実行

npm認証情報

~/.npmrc に以下を追加

email=va034600@gmail.com
always-auth=true
# $ echo -n 'admin:admin123' | openssl base64
_auth=YWRtaW46YWRtaW4xMjM=

registry=http://localhost:9998/repository/my-npm-group-repo/

yarn publish

$ cd yarn-fetch-library
$ yarn publish

yarn install

$ yarn install

yarn-fetch-library/src/index.js 修正

# 4 を追加
_.each([1, 2, 3, 4], console.log);

test1

$ cd yarn-fetch-main
$ node src/index.js

console.logから反映されないこと確認

yarn link

$ cd yarn-fetch-library
$ yarn link
$ cd yarn-fetch-main
$ yarn link @va034600/yarn-fetch-library

test2

$ cd yarn-fetch-main
$ node src/index.js

console.logから反映されていること確認

最後に

やっぱりrepository serverですよね

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?