• S5_370234
  • 302.7KB
  • zip
  • 0
  • VIP专享
  • 0
  • 2022-05-29 02:02
类似的解决方案: 参考: 这是您需要的依赖项: < dependency> < groupId>com.artipie</ groupId> < artifactId>npm-adapter</ artifactId> < version>[...]</ version> </ dependency> 怎么运行的? 首先,您上传由npm publish生成的json文件。然后,调用Npm#publish ,它触发meta.json文件的更新/生成和.tgz源代码档案的创建。 这提供了您需要对npm intall <package>命令生成的一系列请求进行响应的任何内容。 可以在找到meta.json的示例 NPM命令如何与NPMSlice一起使用。 假设我们通过以下方式使用npm publish : npm publish --registry=
<img src="" width="64px" height="64px"/> [![EO principles respected here](]( [![DevOps By](]( [![We recommend IntelliJ IDEA](]( [![Javadoc](]( [![License](]( [![codecov](]( [![Hits-of-Code](]( [![Maven Central](]( [![PDD status](]( Similar solutions: * [Artifactory]( * [Package cloud]( * [Verdaccio]( References: * [NPM registry internals]( * [CommonJS Package Registry specification]( * [The JavaScript Package Registry]( This is the dependency you need: ```xml <dependency> <groupId>com.artipie</groupId> <artifactId rel='nofollow' onclick='return false;'>npm-adapter</artifactId> <version>[...]</version> </dependency> ``` ## How it works? First, you upload a json file generated by `npm publish`. Then, you call `Npm#publish`, which triggers `meta.json` file update/generation and `.tgz` source code archives creation. This gives anything you need to respond on a series of requests generated by `npm intall <package_name>` command. An example of `meta.json` can be found [here]( ## How NPM commands work with NPMSlice. 1. Let's say we use `npm publish` in the following way: ```bash npm publish --registry=http://localhost:8080 ``` By invoking such command npm sends following http request: ```json method: "PUT" url: "/@hello%2fsimple-npm-project" headers: { "connection": "keep-alive", "user-agent": "npm/6.13.6 node/v10.15.1 darwin x64", "npm-in-ci": "false", "npm-scope": "@hello", "npm-session": "52b4a33613bae565", "referer": "publish", "content-type": "application/json", "accept": "*/*", "content-length": "1331", "accept-encoding": "gzip,deflate", "host": "localhost:8080" } ``` With request body which contains `data` field which contains `base64` content of the package. Then we generate the meta data and `.tar` package and save it into asto. 2. Let's say now we want to install our package via command: ```bash npm install --registry=http://localhost:8080 @hello/simple-npm-project ``` First NPM sends following request to get the meta data: ```json method: "GET" url: "/@hello%2fsimple-npm-project" headers: { "connection": "keep-alive", "user-agent": "npm/6.13.6 node/v10.15.1 darwin x64", "npm-in-ci": "false", "npm-scope": "@hello", "npm-session": "ee324ef71224a7ee", "referer": "install [REDACTED]", "pacote-req-type": "packument", "pacote-pkg-id": "registry:@hello/simple-npm-project", "accept": "application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*", "accept-encoding": "gzip,deflate", "host": "localhost:8080" } ``` and expect following response body with meta info from asto like: ```json { "name": "@hello/simple-npm-project", "_id": "@hello/simple-npm-project", "readme": "ERROR: No README data found!", "time": { "created": "2020-03-12T14:51:34.44" }, "users": {}, "versions": { "1.0.1": { "name": "@hello/simple-npm-project", "version": "1.0.1", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "readme": "ERROR: No README data found!", "_id": "@hello/simple-npm-project@1.0.1", "_nodeVersion": "10.15.1", "_npmVersion": "6.13.6", "maintainers": [ {} ], "dist": { "integrity": "sha512-uTxRHajE8jAoeUMI32YjujfWTxD6D2Ng2hZoeR8jd8Wvx+3cJsda8mh64Cq4pFYvl65Za8OkzLAo2/vU/ibq9A==", "shasum": "d20a235fc4fe4f68b02649f349bfeb324178d9b1", "tarball": "" } } }, "_attachments": {}, "dist-tags": { "latest": "1.0.1" } } ``` Then NPM using such meta info sends another request to get a package: ```json method: "GET" url: "/@hello/simple-npm-project/-/@hello/simple-npm-project-1.0.1.tgz" headers: { "connection": "keep-alive", "user-agent": "npm/6.13.6 node/v10.15.1 darwin x64", "npm-in-ci": "false", "npm-scope": "@hello", "npm-session": "ee324ef71224a7ee", "referer": "install [REDACTED]", "pacote-req-type": "tarball", "pacote-pkg-id": "registry:@hello/simple-npm-project@", "accept": "*/*", "host": "" } ``` ## NPM Proxy NPM proxy repository could be created using `NpmProxySlice`. Proxy repository forwards HTTP requests to specified URL and adapter processes them. After receiving artifact from the remote server, it caches received data and transforms it before sending it back to client and saves to local storage. Similar request received afterwords will not require remote repository call - the cached data will be used. Detailed explanation about used algorithms and protocols used for proxy implementation can be found [here]( ## How to contribute Fork repository, make changes, send us a pull request. We will review your changes and apply them to the `master` branch shortly, provided they don't violate our quality standards. To avoid frustration, before sending us your pull request please run full Maven build: ``` $ mvn clean install -Pqulice ``` To avoid build errors use Maven 3.2+.