skip to Main Content

For security reasons I need to setup a custom npm-registry.

I configure a local http-registry (nginx) using this command:

npm config set @example:registry=http://localhost/

Then I place two files to nginx

.
..
@example%2fmodel
model.tgz

The contents of @example%2fmodel is:

{
  "name":"Model", 
  "dist-tags":{"foo":"1.0.0"},
  "versions":{
    "1.0.0":{
      "version":"1.0.0", 
      "dist":{"tarball":"model.tgz"}
    }
  }
}

The content of model.tgz is the package.json and the Model.ts.

The the Model.ts (from tarball) is:

export const URL = 'https://example.com/';
export const USER = 'apiv2';
export const PASS = '***';

The package.json (from tarball) is:

{"name":"Model","version":"1.0.0","files":"*.ts"}

As you can see, its all minimal and all straightforward.

Then I do a:

npm install @example/model
added 1 package in 0.347s
npm info ok

That worked well. But my Model.ts is missing

2

Answers


  1. The optional files attribute field is an array of file patterns.
    So based on the above, your package.json should look like the following:

    {
       "name":"Model",
       "version":"1.0.0",
       "files":["*.ts"]
    }
    

    The square array brackets [] ensures any declared type of file within it will be included in the tarball when it’s packed.

    See documentation here: Configuring NPM: package.json – files attribute

    Login or Signup to reply.
  2. Adding fileCount and unpackedSize under the dist object in @example%2fmodel could help

    • fileCount – the total count of files included in the tarball (in your case it’s 2)
    • unpackedSize – the size of unpacked package, in bytes

    The @example%2fmodel file then looks something like this:

    {
      "name":"Model", 
      "dist-tags":{"foo":"1.0.0"},
      "versions":{
        "1.0.0":{
          "version":"1.0.0", 
          "dist":{
            "tarball":"model.tgz",
            "fileCount":2,
            "unpackedSize":0,
          }
        }
      }
    }
    

    Change the unpackedSize to the actual size of te package.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search