npm-files

Turns your files/objects into NPM artifacts

License

License

MIT
GroupId

GroupId

com.yegor256
ArtifactId

ArtifactId

npm-files
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

npm-files
Turns your files/objects into NPM artifacts
Project URL

Project URL

https://github.com/yegor256/npm-files
Project Organization

Project Organization

jcabi.com
Source Code Management

Source Code Management

https://github.com/yegor256/npm-files

Download npm-files

How to add to project

<!-- https://jarcasting.com/artifacts/com.yegor256/npm-files/ -->
<dependency>
    <groupId>com.yegor256</groupId>
    <artifactId>npm-files</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.yegor256/npm-files/
implementation 'com.yegor256:npm-files:0.2.0'
// https://jarcasting.com/artifacts/com.yegor256/npm-files/
implementation ("com.yegor256:npm-files:0.2.0")
'com.yegor256:npm-files:jar:0.2.0'
<dependency org="com.yegor256" name="npm-files" rev="0.2.0">
  <artifact name="npm-files" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.yegor256', module='npm-files', version='0.2.0')
)
libraryDependencies += "com.yegor256" % "npm-files" % "0.2.0"
[com.yegor256/npm-files "0.2.0"]

Dependencies

compile (2)

Group / Artifact Type Version
com.jcabi : jcabi-log jar 0.18.1
com.yegor256 : asto jar 0.0.1

provided (1)

Group / Artifact Type Version
javax.json : javax.json-api jar 1.1.4

runtime (1)

Group / Artifact Type Version
org.glassfish : javax.json jar 1.1.4

test (6)

Group / Artifact Type Version
io.vertx : vertx-core jar 3.8.4
io.vertx : vertx-web jar 3.8.4
io.reactivex.rxjava2 : rxjava jar 2.2.12
io.vertx : vertx-rx-java2 jar 3.8.4
org.slf4j : slf4j-simple jar 1.7.21
com.jcabi : jcabi-matchers jar 1.4

Project Modules

There are no modules declared in this project.

EO principles respected here DevOps By Rultor.com We recommend IntelliJ IDEA

Maven Build Javadoc License Hits-of-Code Maven Central PDD status

Similar solutions:

References:

This is the dependency you need:

<dependency>
  <groupId>com.artipie</groupId>
  <artifactId>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:
npm publish --registry=http://localhost:8080

By invoking such command npm sends following http request:

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.

  1. Let's say now we want to install our package via command:
npm install --registry=http://localhost:8080  @hello/simple-npm-project

First NPM sends following request to get the meta data:

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:

{
  "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/[email protected]",
      "_nodeVersion": "10.15.1",
      "_npmVersion": "6.13.6",
      "maintainers": [
        {}
      ],
      "dist": {
        "integrity": "sha512-uTxRHajE8jAoeUMI32YjujfWTxD6D2Ng2hZoeR8jd8Wvx+3cJsda8mh64Cq4pFYvl65Za8OkzLAo2/vU/ibq9A==",
        "shasum": "d20a235fc4fe4f68b02649f349bfeb324178d9b1",
        "tarball": "http://127.0.0.1:8080/@hello/simple-npm-project/-/@hello/simple-npm-project-1.0.1.tgz"
      }
    }
  },
  "_attachments": {},
  "dist-tags": {
    "latest": "1.0.1"
  }
}

Then NPM using such meta info sends another request to get a package:

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@http://127.0.0.1:8080/@hello/simple-npm-project/-/@hello/simple-npm-project-1.0.1.tgz",
  "accept": "*/*",
  "host": "127.0.0.1:8080" 
}

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+.

Versions

Version
0.2.0
0.1.0