verdaccio
Version:
A lightweight private npm proxy registry
58 lines (57 loc) • 1.94 kB
JavaScript
import Config from "./config.mjs";
import { logger } from "./logger/index.mjs";
import { Storage } from "./storage.mjs";
import { getPackageVersion, initLogger } from "./utils.mjs";
import * as _ from "lodash-es";
import { initServer as initServer$1, runServer as runServer$1 } from "@verdaccio/node-api";
import { defineAPI } from "@verdaccio/server";
//#region src/lib/run-server.ts
/**
* Build the Express app from a raw config by reusing @verdaccio/server's
* composition (defineAPI), but inject 7.x's Storage so legacy callback storage
* plugins keep working. Exposed for tests that need the app without a listener.
*/
async function endPointAPI(configHash) {
const appConfig = new Config(_.cloneDeep(configHash));
const storage = new Storage(appConfig, logger);
await storage.init(appConfig);
return defineAPI(appConfig, storage, { version: getPackageVersion() });
}
/**
* Server factory passed to @verdaccio/node-api / @verdaccio/cli: maps the
* deprecated `logs` config key then builds the app with 7.x's legacy-aware
* Storage (via {@link endPointAPI}).
*/
async function startServer(config) {
await initLogger(config);
return endPointAPI(config);
}
/**
* Exposes a server factory to be instantiated programmatically.
*
```ts
const app = await runServer(); // default configuration
const app = await runServer('./config/config.yaml');
const app = await runServer({ configuration });
app.listen(4000, (event) => {
// do something
});
```
* @param config
*/
async function runServer(config) {
return runServer$1(config, startServer);
}
/**
* Start the server on the port defined (or the port defined in the config file)
* @param config
* @param port
* @param version
* @param pkgName
*/
async function initServer(config, port, version, pkgName) {
return initServer$1(config, port, version, pkgName, startServer);
}
//#endregion
export { endPointAPI, initServer, runServer, startServer };
//# sourceMappingURL=run-server.mjs.map