From 80326aed8b73f588bd8842153ef8ced8aec69778 Mon Sep 17 00:00:00 2001 From: Denis Bashkatov <2485095+Denrox@users.noreply.github.com> Date: Wed, 1 Oct 2025 18:11:27 +0300 Subject: [PATCH 1/4] public packages --- README.md | 48 ++- .../routes/documentation/documentation.tsx | 70 ++++- admin/app/routes/npm/npm.tsx | 286 +++++++++++++++++- admin/app/utils/server-auth.ts | 18 ++ 4 files changed, 403 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index bb97029..dad8212 100644 --- a/README.md +++ b/README.md @@ -83,11 +83,13 @@ The script will: ### NPM Proxy (npm.mirror.intra) - Optional - **URL**: `http://npm.mirror.intra` -- **Purpose**: Local npm package registry cache +- **Purpose**: Local npm package registry cache and private package hosting - **Features**: - Caches npm packages locally for faster installs - Reduces bandwidth usage - Transparent proxy to npmjs.org + - Private package publishing (requires authentication) + - Private packages stored separately and never forwarded to npmjs.org ## Usage @@ -142,6 +144,50 @@ The npm proxy will: - Serve cached packages for subsequent requests - Automatically fetch from npmjs.org if not cached +### Publishing NPM Packages + +The npm proxy supports publishing private packages using standard npm commands. + +#### Authentication + +**Method 1: Using npm login (recommended)** + +For npm 9.x+, use the `--auth-type=legacy` flag: + +```bash +npm login --registry=http://npm.mirror.intra --auth-type=legacy +# Enter your username and password when prompted +npm whoami --registry=http://npm.mirror.intra +``` + +**Method 2: Manual token configuration** + +If `npm login` doesn't work, you can manually obtain and configure the token: + +```bash +TOKEN=$(curl -X PUT http://npm.mirror.intra/-/user/org.couchdb.user:admin \ + -H "Content-Type: application/json" \ + -d '{"name": "admin", "password": "your-password"}' \ + | jq -r .token) +echo "//npm.mirror.intra/:_authToken=$TOKEN" >> ~/.npmrc +npm whoami --registry=http://npm.mirror.intra +``` + +#### Publishing Packages + +Once authenticated, publish packages normally: + +```bash +npm publish +``` + +**Important Notes:** +- All published packages are treated as private packages +- Private packages are stored in `data/data/npm/private/` +- Published packages are **NOT** forwarded to npmjs.org +- Private packages take precedence over cached public packages +- Authentication tokens for npm are JWT-based and valid for 1 year + ### File Hosting Use the file repository at `http://files.mirror.intra` to: diff --git a/admin/app/routes/documentation/documentation.tsx b/admin/app/routes/documentation/documentation.tsx index 0edd83b..92772ea 100644 --- a/admin/app/routes/documentation/documentation.tsx +++ b/admin/app/routes/documentation/documentation.tsx @@ -295,8 +295,9 @@ export default function Documentation() {
The NPM Proxy provides a local caching layer for npm packages, - speeding up installations and reducing bandwidth usage. It acts as - a transparent proxy to the official npm registry. + speeding up installations and reducing bandwidth usage. It also supports + publishing private packages that are stored locally and never forwarded + to the public npm registry.
+ You can publish private npm packages to this registry. All packages are stored locally and never forwarded to npmjs.org. +
+ +For npm 9.x+, use the --auth-type=legacy flag:
+Enter your username and password when prompted, then verify:
+If npm login doesn't work, get a token manually:
+Once authenticated, publish normally:
+- Cached npm packages are stored in the data/npm/ directory and can - be viewed and managed through the File Manager in the admin - interface. + Cached npm packages are stored in the data/npm/ directory and private packages in data/npm/private/. Both can be viewed and managed through the File Manager.
- Cached npm packages are stored in the data/npm/ directory and private packages in data/npm/private/. Both can be viewed and managed through the File Manager. + NPM packages are organized in the data/npm/ directory: public packages (cached from npmjs.org) in data/npm/public/ and private packages (published locally) in data/npm/private/. Both can be viewed and managed through the File Manager.