From 681dc821aab9f031b959c802f172f06dc6672864 Mon Sep 17 00:00:00 2001 From: osher Date: Mon, 14 Feb 2022 22:05:59 +0200 Subject: [PATCH] feat: new environment variable (storage path) (#2993) * WIP: port PR#2199 to master into 5.x * port PR#2199 to master to 5.x - env.variables.md * port PR#2199 to master to 5.x - config.spec * Update config.spec.ts * Update config.spec.ts * fix format Co-authored-by: Juan Picado --- docs/env.variables.md | 4 ++++ src/lib/config.ts | 2 +- test/unit/modules/config/config.spec.ts | 15 +++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/env.variables.md b/docs/env.variables.md index 23a2afa27..28d8951c0 100644 --- a/docs/env.variables.md +++ b/docs/env.variables.md @@ -41,3 +41,7 @@ The default header to identify the protocol is `X-Forwarded-Proto`, but there ar ``` $ VERDACCIO_FORWARDED_PROTO=CloudFront-Forwarded-Proto verdaccio --listen 5000 ``` + +#### VERDACCIO_STORAGE_PATH + +By default, the storage is taken from config file, but using this variable allows to set it from environment variable. diff --git a/src/lib/config.ts b/src/lib/config.ts index 168922346..21cd61880 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -38,7 +38,7 @@ class Config implements AppConfig { const self = this; this.logger = LoggerApi.logger; this.self_path = config.self_path; - this.storage = config.storage; + this.storage = process.env.VERDACCIO_STORAGE_PATH || config.storage; this.plugins = config.plugins; for (const configProp in config) { diff --git a/test/unit/modules/config/config.spec.ts b/test/unit/modules/config/config.spec.ts index f07706d59..ed693913c 100644 --- a/test/unit/modules/config/config.spec.ts +++ b/test/unit/modules/config/config.spec.ts @@ -91,7 +91,18 @@ describe('Config file', () => { expect(config.auth.htpasswd.file).toBe('./htpasswd'); checkDefaultConfPackages(config); }); - }); - describe('Config file', () => {}); + test('with process.env.VERDACCIO_STORAGE_PATH', () => { + const testPath = '/builds/project/foo/bar/baz'; + // @ts-ignore + process.env.VERDACCIO_STORAGE_PATH = testPath; + try { + const config = new Config(parseConfigFile(resolveConf('default'))); + expect(config.storage).toBe(testPath); + } finally { + // @ts-ignore + delete process.env.VERDACCIO_STORAGE_PATH; + } + }); + }); });