UNPKG

verdaccio

Version:

A lightweight private npm proxy registry

103 lines (102 loc) • 4.46 kB
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); const require_runtime = require("../_virtual/_rolldown/runtime.cjs"); const require_lib_legacy_storage_adapter = require("./legacy-storage-adapter.cjs"); let lodash_es = require("lodash-es"); let _verdaccio_core = require("@verdaccio/core"); let debug = require("debug"); debug = require_runtime.__toESM(debug); let node_assert = require("node:assert"); node_assert = require_runtime.__toESM(node_assert); let _verdaccio_loaders = require("@verdaccio/loaders"); let _verdaccio_local_storage = require("@verdaccio/local-storage"); _verdaccio_local_storage = require_runtime.__toESM(_verdaccio_local_storage); let _verdaccio_store = require("@verdaccio/store"); //#region src/lib/storage.ts var debug$1 = (0, debug.default)("verdaccio:storage"); var LocalDatabase = _verdaccio_local_storage.default.default || _verdaccio_local_storage.default; var storageSanityCheck = (plugin) => typeof plugin?.getPackageStorage !== "undefined"; /** * Drop-in replacement for `@verdaccio/store`'s internal `LocalStorage` that * loads the configured storage plugin exactly like upstream, but wraps a * legacy callback-based plugin in a promisifying adapter so it satisfies the * promise contract the rest of `@verdaccio/store` relies on. * * `@verdaccio/store` only ever calls `init()`, `getSecret()` and * `getStoragePlugin()` on this object, so that is the entire surface we mirror. */ var CompatLocalStorage = class { storagePlugin = null; config; logger; constructor(config, logger) { this.config = config; this.logger = logger.child({ sub: "fs" }); } async init() { if (this.storagePlugin === null) { const loaded = await this.loadStorage(); this.storagePlugin = require_lib_legacy_storage_adapter.isLegacyStoragePlugin(loaded) ? require_lib_legacy_storage_adapter.wrapLegacyStoragePlugin(loaded, this.logger) : loaded; debug$1("storage plugin init"); await this.storagePlugin.init(); debug$1("storage plugin initialized"); } else this.logger.warn("storage plugin has been already initialized"); } getStoragePlugin() { if (this.storagePlugin === null) throw _verdaccio_core.errorUtils.getInternalError("storage plugin is not initialized"); return this.storagePlugin; } async getSecret(config) { const secretKey = await this.storagePlugin.getSecret(); return this.storagePlugin.setSecret(config.checkSecretKey(secretKey)); } async loadStorage() { const Storage = await this.loadStorePlugin(); if ((0, lodash_es.isNil)(Storage)) { (0, node_assert.default)(this.config.storage, "CONFIG: storage path not defined"); debug$1("no custom storage found, loading default storage @verdaccio/local-storage"); const localStorage = new LocalDatabase(this.config, this.logger); this.logger.info({ name: "@verdaccio/local-storage", pluginCategory: _verdaccio_core.PLUGIN_CATEGORY.STORAGE }, "plugin @{name} successfully loaded (@{pluginCategory})"); return localStorage; } return Storage; } async loadStorePlugin() { const plugins = await (0, _verdaccio_loaders.asyncLoadPlugin)(this.config.store, { config: this.config, logger: this.logger }, storageSanityCheck, true, this.config.server?.pluginPrefix ?? _verdaccio_core.PLUGIN_PREFIX, _verdaccio_core.PLUGIN_CATEGORY.STORAGE); if (plugins.length > 1) this.logger.warn("more than one storage plugins has been detected, multiple storage are not supported, one will be selected automatically"); return (0, lodash_es.head)(plugins); } }; /** * `@verdaccio/store` Storage, with one change: it loads the storage plugin * through {@link CompatLocalStorage} so legacy callback plugins keep working. * * The base `init()` only creates its internal `LocalStorage` when * `this.localStorage` is still null; by pre-populating it we reuse the entire * rest of the upstream Storage implementation (including filter loading via * `super.init`) unchanged. */ var Storage = class extends _verdaccio_store.Storage { async init(config) { if (this.localStorage === null) { const localStorage = new CompatLocalStorage(this.config, this.logger); await localStorage.init(); await localStorage.getSecret(config); this.localStorage = localStorage; debug$1("compat local storage initialized"); } await super.init(config); } }; //#endregion exports.Storage = Storage; exports.default = Storage; //# sourceMappingURL=storage.cjs.map