Skip to content

Commit

Permalink
Add support for running a local NPM Registry via Verdaccio.
Browse files Browse the repository at this point in the history
A single new npm run command is added "start:npm-local".
This will start an Verdaccio Registry and handle only the `@wvr` packages.
All other packages are proxied.
Custom settings are added to ensure that this does not cache proxied packages (the packages from the upstream NPM Registry).

This is designed to operate anonymously.
A connection to the local Verdaccio NPM Registry should not need an account.
The more recent versions of NPM have made this more difficult by removing anonymous support.
This is worked around by adding a .npmrc that injects a fake token specifically for the localhost registry.o

This utilizes a verdaccio-memory module to have verdaccio store the registry in memory, keeping the local filesystem clean.
This can be disabled by uncommenting the the appropriate section.
The rest of the registry is already configured to work if the in-memory support is disabled.
If uncommented, then be sure to handle cleaning up the .verdaccio directory yourself.

I wanted to have the following in the package.json:
```
  "publishConfig": {
    "access": "public",
    "registry": "http://localhost:4873/"
  },
```
Which would also necessitate the following in `.npmrc`:
```
registry=http://localhost:4873/
```

This cannot happen because the NPM developers have yet to realize the usefullness of a command line argument like `--registry`:
```
npm publish --registry https://registry.npmjs.org
```

The lack of the command like argument necessitates manually setting the localhost registry:
```
npm registry set http://localhost:4873/
```

This increases the possibility of mistakes, so I suggest always performing a dry run as a practice before actual publishing:
```
npm publish --dry-run
```

Once done with the local Verdaccio NPM Registry, you can reset the registry like this:
```
npm set registry https://registry.npmjs.org/
```

There are also additional configurations that reduce the needed changes for custom situations.
1) The `allow_offline` is enabled because localhost interaction should not require an active internet connection.
2) The `security.*` settings are provided in case one wants to set `web.login` to `true`.
  • Loading branch information
kaladay committed Jul 13, 2022
1 parent 7161664 commit 64e2230
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -21,3 +21,5 @@ app/config/appConfig.js
app/bower_components
app/resources/styles/*
!app/resources/styles/sass/

.verdaccio
2 changes: 2 additions & 0 deletions .npmrc
@@ -0,0 +1,2 @@
# Work-around NPM trying to fake authentication and allow anonymous publishing.
//localhost:4873/:_authToken="fake"
7 changes: 5 additions & 2 deletions package.json
Expand Up @@ -16,7 +16,8 @@
"preupdate-webdriver": "npm install",
"update-webdriver": "webdriver-manager update",
"preprotractor": "npm run update-webdriver",
"protractor": "protractor e2e-tests/protractor.conf.js"
"protractor": "protractor e2e-tests/protractor.conf.js",
"start:npm-local": "verdaccio --listen localhost:4873 --config ./verdaccio-config.yaml"
},
"dependencies": {
"angular": "1.8.2",
Expand Down Expand Up @@ -52,6 +53,8 @@
"karma-jasmine": "4.0.2",
"karma-junit-reporter": "2.0.1",
"karma-ng-html2js-preprocessor": "1.0.0",
"protractor": "7.0.0"
"protractor": "7.0.0",
"verdaccio": "^5.13.1",
"verdaccio-memory": "^10.3.0"
}
}
61 changes: 61 additions & 0 deletions verdaccio-config.yaml
@@ -0,0 +1,61 @@
# https://verdaccio.org/docs/configuration/

# Path to a directory with all packages.
storage: .verdaccio/storage

# Path to a directory with plugins to include.
plugins: .verdaccio/plugins

web:
title: Verdaccio - Weaver - Localhost

# Disable login requirement for localhost.
login: false

# List of other known repositories to use.
uplinks:
npmjs:
url: https://registry.npmjs.org/
cache: false

# For verdaccio-memory, designate memory limit.
# Comment this out to store package in .verdaccio directory rather than in memory.
store:
memory:
limit: 10000

packages:
'@wvr/*':
# Choices: "$all", "$anonymous", "$authenticated".
access: $all
publish: $all
unpublish: $all

'**':
access: $all

# Proxy non-local packages to 'npmjs' registry.
proxy: npmjs

# Allow for publishing while offline.
publish:
allow_offline: true

server:
keepAliveTimeout: 60

security:
api:
jwt:
sign:
expiresIn: 15d
notBefore: 0
web:
sign:
expiresIn: 1h

middlewares:
audit:
enabled: true

logs: { type: stdout, format: pretty, level: http }

0 comments on commit 64e2230

Please sign in to comment.