@verdaccio/node-api 9.0.0-next-9.2 → 9.0.0-next-9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ exports.__toESM = __toESM;
@@ -1,20 +1,17 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.displayExperimentsInfoBox = displayExperimentsInfoBox;
7
- var _logger = require("@verdaccio/logger");
1
+ require("./_virtual/_rolldown/runtime.js");
2
+ let _verdaccio_logger = require("@verdaccio/logger");
3
+ //#region src/experiments.ts
8
4
  function displayExperimentsInfoBox(flags) {
9
- if (!flags) {
10
- return;
11
- }
12
- var experimentList = Object.keys(flags);
13
- if (experimentList.length >= 1) {
14
- _logger.logger.warn("experiments are enabled, it is recommended do not use experiments in production comment out this section to disable it");
15
- experimentList.forEach(function (experiment) {
16
- _logger.logger.info("support for experiment [".concat(experiment, "] ").concat(flags[experiment] ? 'is enabled' : ' is disabled'));
17
- });
18
- }
5
+ if (!flags) return;
6
+ const experimentList = Object.keys(flags);
7
+ if (experimentList.length >= 1) {
8
+ _verdaccio_logger.logger.warn(`experiments are enabled, it is recommended do not use experiments in production comment out this section to disable it`);
9
+ experimentList.forEach((experiment) => {
10
+ _verdaccio_logger.logger.info(`support for experiment [${experiment}] ${flags[experiment] ? "is enabled" : " is disabled"}`);
11
+ });
12
+ }
19
13
  }
14
+ //#endregion
15
+ exports.displayExperimentsInfoBox = displayExperimentsInfoBox;
16
+
20
17
  //# sourceMappingURL=experiments.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"experiments.js","names":["_logger","require","displayExperimentsInfoBox","flags","experimentList","Object","keys","length","logger","warn","forEach","experiment","info","concat"],"sources":["../src/experiments.ts"],"sourcesContent":["import { logger } from '@verdaccio/logger';\n\nexport function displayExperimentsInfoBox(flags) {\n if (!flags) {\n return;\n }\n\n const experimentList = Object.keys(flags);\n if (experimentList.length >= 1) {\n logger.warn(\n `experiments are enabled, it is recommended do not use experiments in production comment out this section to disable it`\n );\n experimentList.forEach((experiment) => {\n logger.info(\n `support for experiment [${experiment}] ${\n flags[experiment] ? 'is enabled' : ' is disabled'\n }`\n );\n });\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAEO,SAASC,yBAAyBA,CAACC,KAAK,EAAE;EAC/C,IAAI,CAACA,KAAK,EAAE;IACV;EACF;EAEA,IAAMC,cAAc,GAAGC,MAAM,CAACC,IAAI,CAACH,KAAK,CAAC;EACzC,IAAIC,cAAc,CAACG,MAAM,IAAI,CAAC,EAAE;IAC9BC,cAAM,CAACC,IAAI,yHAEX,CAAC;IACDL,cAAc,CAACM,OAAO,CAAC,UAACC,UAAU,EAAK;MACrCH,cAAM,CAACI,IAAI,4BAAAC,MAAA,CACkBF,UAAU,QAAAE,MAAA,CACnCV,KAAK,CAACQ,UAAU,CAAC,GAAG,YAAY,GAAG,cAAc,CAErD,CAAC;IACH,CAAC,CAAC;EACJ;AACF","ignoreList":[]}
1
+ {"version":3,"file":"experiments.js","names":[],"sources":["../src/experiments.ts"],"sourcesContent":["import { logger } from '@verdaccio/logger';\n\nexport function displayExperimentsInfoBox(flags) {\n if (!flags) {\n return;\n }\n\n const experimentList = Object.keys(flags);\n if (experimentList.length >= 1) {\n logger.warn(\n `experiments are enabled, it is recommended do not use experiments in production comment out this section to disable it`\n );\n experimentList.forEach((experiment) => {\n logger.info(\n `support for experiment [${experiment}] ${\n flags[experiment] ? 'is enabled' : ' is disabled'\n }`\n );\n });\n }\n}\n"],"mappings":";;;AAEA,SAAgB,0BAA0B,OAAO;AAC/C,KAAI,CAAC,MACH;CAGF,MAAM,iBAAiB,OAAO,KAAK,MAAM;AACzC,KAAI,eAAe,UAAU,GAAG;AAC9B,oBAAA,OAAO,KACL,yHACD;AACD,iBAAe,SAAS,eAAe;AACrC,qBAAA,OAAO,KACL,2BAA2B,WAAW,IACpC,MAAM,cAAc,eAAe,iBAEtC;IACD"}
@@ -0,0 +1,16 @@
1
+ import { logger } from "@verdaccio/logger";
2
+ //#region src/experiments.ts
3
+ function displayExperimentsInfoBox(flags) {
4
+ if (!flags) return;
5
+ const experimentList = Object.keys(flags);
6
+ if (experimentList.length >= 1) {
7
+ logger.warn(`experiments are enabled, it is recommended do not use experiments in production comment out this section to disable it`);
8
+ experimentList.forEach((experiment) => {
9
+ logger.info(`support for experiment [${experiment}] ${flags[experiment] ? "is enabled" : " is disabled"}`);
10
+ });
11
+ }
12
+ }
13
+ //#endregion
14
+ export { displayExperimentsInfoBox };
15
+
16
+ //# sourceMappingURL=experiments.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"experiments.mjs","names":[],"sources":["../src/experiments.ts"],"sourcesContent":["import { logger } from '@verdaccio/logger';\n\nexport function displayExperimentsInfoBox(flags) {\n if (!flags) {\n return;\n }\n\n const experimentList = Object.keys(flags);\n if (experimentList.length >= 1) {\n logger.warn(\n `experiments are enabled, it is recommended do not use experiments in production comment out this section to disable it`\n );\n experimentList.forEach((experiment) => {\n logger.info(\n `support for experiment [${experiment}] ${\n flags[experiment] ? 'is enabled' : ' is disabled'\n }`\n );\n });\n }\n}\n"],"mappings":";;AAEA,SAAgB,0BAA0B,OAAO;AAC/C,KAAI,CAAC,MACH;CAGF,MAAM,iBAAiB,OAAO,KAAK,MAAM;AACzC,KAAI,eAAe,UAAU,GAAG;AAC9B,SAAO,KACL,yHACD;AACD,iBAAe,SAAS,eAAe;AACrC,UAAO,KACL,2BAA2B,WAAW,IACpC,MAAM,cAAc,eAAe,iBAEtC;IACD"}
package/build/index.js CHANGED
@@ -1,19 +1,7 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
5
4
  });
6
- Object.defineProperty(exports, "initServer", {
7
- enumerable: true,
8
- get: function get() {
9
- return _server.initServer;
10
- }
11
- });
12
- Object.defineProperty(exports, "runServer", {
13
- enumerable: true,
14
- get: function get() {
15
- return _server.runServer;
16
- }
17
- });
18
- var _server = require("./server");
19
- //# sourceMappingURL=index.js.map
5
+ const require_server = require("./server.js");
6
+ exports.initServer = require_server.initServer;
7
+ exports.runServer = require_server.runServer;
@@ -0,0 +1,2 @@
1
+ import { initServer, runServer } from "./server.mjs";
2
+ export { initServer, runServer };
package/build/server.js CHANGED
@@ -1,220 +1,135 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createServerFactory = createServerFactory;
7
- exports.initServer = initServer;
8
- exports.runServer = runServer;
9
- var _debug = _interopRequireDefault(require("debug"));
10
- var _lodash = require("lodash");
11
- var _nodeConstants = _interopRequireDefault(require("node:constants"));
12
- var _nodeFs = _interopRequireDefault(require("node:fs"));
13
- var _nodeHttp = _interopRequireDefault(require("node:http"));
14
- var _nodeHttps = _interopRequireDefault(require("node:https"));
15
- var _nodeUrl = _interopRequireDefault(require("node:url"));
16
- var _config = require("@verdaccio/config");
17
- var _logger = require("@verdaccio/logger");
18
- var _server = _interopRequireDefault(require("@verdaccio/server"));
19
- var _experiments = require("./experiments");
20
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
21
- function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
22
- function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
23
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
24
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
25
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
26
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
27
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
28
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
29
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
30
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* eslint-disable */
31
- var debug = (0, _debug["default"])('verdaccio:node-api');
1
+ const require_runtime = require("./_virtual/_rolldown/runtime.js");
2
+ const require_experiments = require("./experiments.js");
3
+ let debug = require("debug");
4
+ debug = require_runtime.__toESM(debug);
5
+ let lodash = require("lodash");
6
+ let node_constants = require("node:constants");
7
+ node_constants = require_runtime.__toESM(node_constants);
8
+ let node_fs = require("node:fs");
9
+ node_fs = require_runtime.__toESM(node_fs);
10
+ let node_http = require("node:http");
11
+ node_http = require_runtime.__toESM(node_http);
12
+ let node_https = require("node:https");
13
+ node_https = require_runtime.__toESM(node_https);
14
+ let node_url = require("node:url");
15
+ node_url = require_runtime.__toESM(node_url);
16
+ let _verdaccio_config = require("@verdaccio/config");
17
+ let _verdaccio_logger = require("@verdaccio/logger");
18
+ let _verdaccio_server = require("@verdaccio/server");
19
+ _verdaccio_server = require_runtime.__toESM(_verdaccio_server);
20
+ //#region src/server.ts
21
+ var debug$1 = (0, debug.default)("verdaccio:node-api");
32
22
  function unlinkAddressPath(addr) {
33
- if (addr.path && _nodeFs["default"].existsSync(addr.path)) {
34
- _nodeFs["default"].unlinkSync(addr.path);
35
- }
23
+ if (addr.path && node_fs.default.existsSync(addr.path)) node_fs.default.unlinkSync(addr.path);
36
24
  }
37
-
38
25
  /**
39
- * Return a native HTTP/HTTPS server instance
40
- * @param config
41
- * @param addr
42
- * @param app
43
- */
26
+ * Return a native HTTP/HTTPS server instance
27
+ * @param config
28
+ * @param addr
29
+ * @param app
30
+ */
44
31
  function createServerFactory(config, addr, app) {
45
- var serverFactory;
46
- if (addr.proto === 'https') {
47
- debug('https enabled');
48
- try {
49
- var httpsOptions = {
50
- // disable insecure SSLv2 and SSLv3
51
- secureOptions: _nodeConstants["default"].SSL_OP_NO_SSLv2 | _nodeConstants["default"].SSL_OP_NO_SSLv3
52
- };
53
- var keyCertConfig = config.https;
54
- var pfxConfig = config.https;
55
-
56
- // https must either have key and cert or a pfx and (optionally) a passphrase
57
- if (!(keyCertConfig.key && keyCertConfig.cert || pfxConfig.pfx)) {
58
- // logHTTPSError(configPath);
59
- throw Error('bad format https configuration');
60
- }
61
- if (pfxConfig.pfx) {
62
- var pfx = pfxConfig.pfx,
63
- passphrase = pfxConfig.passphrase;
64
- httpsOptions = (0, _lodash.assign)(httpsOptions, {
65
- pfx: _nodeFs["default"].readFileSync(pfx),
66
- passphrase: passphrase || ''
67
- });
68
- } else {
69
- var key = keyCertConfig.key,
70
- cert = keyCertConfig.cert,
71
- ca = keyCertConfig.ca;
72
- httpsOptions = (0, _lodash.assign)(httpsOptions, _objectSpread({
73
- key: _nodeFs["default"].readFileSync(key),
74
- cert: _nodeFs["default"].readFileSync(cert)
75
- }, ca && {
76
- ca: _nodeFs["default"].readFileSync(ca)
77
- }));
78
- }
79
- // TODO: enable http2 as feature
80
- // if (config.server.http2) <-- check if force http2
81
- serverFactory = _nodeHttps["default"].createServer(httpsOptions, app);
82
- } catch (err) {
83
- throw new Error("cannot create https server: ".concat(err.message));
84
- }
85
- } else {
86
- // http
87
- debug('http enabled');
88
- serverFactory = _nodeHttp["default"].createServer(app);
89
- }
90
- debug('server created');
91
- if (config.server && typeof config.server.keepAliveTimeout !== 'undefined' &&
92
- // @ts-ignore
93
- config.server.keepAliveTimeout !== 'null') {
94
- // library definition for node is not up to date (doesn't contain recent 8.0 changes)
95
- serverFactory.keepAliveTimeout = config.server.keepAliveTimeout * 1000;
96
- }
97
- // FIXE: I could not find the reason of this code.
98
- unlinkAddressPath(addr);
99
- return serverFactory;
32
+ let serverFactory;
33
+ if (addr.proto === "https") {
34
+ debug$1("https enabled");
35
+ try {
36
+ let httpsOptions = { secureOptions: node_constants.default.SSL_OP_NO_SSLv2 | node_constants.default.SSL_OP_NO_SSLv3 };
37
+ const keyCertConfig = config.https;
38
+ const pfxConfig = config.https;
39
+ if (!(keyCertConfig.key && keyCertConfig.cert || pfxConfig.pfx)) throw Error("bad format https configuration");
40
+ if (pfxConfig.pfx) {
41
+ const { pfx, passphrase } = pfxConfig;
42
+ httpsOptions = (0, lodash.assign)(httpsOptions, {
43
+ pfx: node_fs.default.readFileSync(pfx),
44
+ passphrase: passphrase || ""
45
+ });
46
+ } else {
47
+ const { key, cert, ca } = keyCertConfig;
48
+ httpsOptions = (0, lodash.assign)(httpsOptions, {
49
+ key: node_fs.default.readFileSync(key),
50
+ cert: node_fs.default.readFileSync(cert),
51
+ ...ca && { ca: node_fs.default.readFileSync(ca) }
52
+ });
53
+ }
54
+ serverFactory = node_https.default.createServer(httpsOptions, app);
55
+ } catch (err) {
56
+ throw new Error(`cannot create https server: ${err.message}`);
57
+ }
58
+ } else {
59
+ debug$1("http enabled");
60
+ serverFactory = node_http.default.createServer(app);
61
+ }
62
+ debug$1("server created");
63
+ if (config.server && typeof config.server.keepAliveTimeout !== "undefined" && config.server.keepAliveTimeout !== "null") serverFactory.keepAliveTimeout = config.server.keepAliveTimeout * 1e3;
64
+ unlinkAddressPath(addr);
65
+ return serverFactory;
100
66
  }
101
-
102
67
  /**
103
- * Start the server on the port defined (or the port defined in the config file)
104
- * @param config
105
- * @param port
106
- * @param version
107
- * @param pkgName
108
- */
109
- function initServer(_x, _x2, _x3, _x4) {
110
- return _initServer.apply(this, arguments);
68
+ * Start the server on the port defined (or the port defined in the config file)
69
+ * @param config
70
+ * @param port
71
+ * @param version
72
+ * @param pkgName
73
+ */
74
+ async function initServer(config, port, version, pkgName) {
75
+ return new Promise(async (resolve, reject) => {
76
+ const logger = (0, _verdaccio_logger.setup)(config?.log);
77
+ const addr = (0, _verdaccio_config.getListenAddress)(port ?? config?.listen, logger);
78
+ require_experiments.displayExperimentsInfoBox(config.flags);
79
+ const serverFactory = createServerFactory(config, addr, await (0, _verdaccio_server.default)(config));
80
+ serverFactory.listen(addr.port || addr.path, addr.host, () => {
81
+ if ((0, lodash.isFunction)(process.send)) process.send({ verdaccio_started: true });
82
+ const addressServer = `${addr.path ? node_url.default.format({
83
+ protocol: "unix",
84
+ pathname: addr.path
85
+ }) : node_url.default.format({
86
+ protocol: addr.proto,
87
+ hostname: addr.host,
88
+ port: addr.port,
89
+ pathname: "/"
90
+ })}`;
91
+ logger.info({ addressServer }, "http address: @{addressServer}");
92
+ logger.info({ version }, "version: @{version}");
93
+ resolve();
94
+ }).on("error", function(err) {
95
+ reject(err);
96
+ process.exitCode = 1;
97
+ });
98
+ function handleShutdownGracefully() {
99
+ logger.info("received shutdown signal - closing server gracefully...");
100
+ serverFactory.close(() => {
101
+ logger.info("server closed.");
102
+ process.exit(0);
103
+ });
104
+ }
105
+ for (const signal of [
106
+ "SIGINT",
107
+ "SIGTERM",
108
+ "SIGHUP"
109
+ ]) process.once(signal, handleShutdownGracefully);
110
+ });
111
111
  }
112
112
  /**
113
- * Exposes a server factory to be instantiated programmatically.
114
- *
115
- ```ts
116
- const app = await runServer(); // default configuration
117
- const app = await runServer('./config/config.yaml');
118
- const app = await runServer({ configuration });
119
- app.listen(4000, (event) => {
120
- // do something
121
- });
122
- ```
123
- * @param config
124
- */
125
- function _initServer() {
126
- _initServer = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(config, port, version, pkgName) {
127
- return _regenerator().w(function (_context2) {
128
- while (1) switch (_context2.n) {
129
- case 0:
130
- return _context2.a(2, new Promise(/*#__PURE__*/function () {
131
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(resolve, reject) {
132
- var logger, addr, app, serverFactory, handleShutdownGracefully, _i, _arr, signal;
133
- return _regenerator().w(function (_context) {
134
- while (1) switch (_context.n) {
135
- case 0:
136
- handleShutdownGracefully = function _handleShutdownGracef() {
137
- logger.info('received shutdown signal - closing server gracefully...');
138
- serverFactory.close(function () {
139
- logger.info('server closed.');
140
- process.exit(0);
141
- });
142
- };
143
- logger = (0, _logger.setup)(config === null || config === void 0 ? void 0 : config.log);
144
- addr = (0, _config.getListenAddress)(port !== null && port !== void 0 ? port : config === null || config === void 0 ? void 0 : config.listen, logger);
145
- (0, _experiments.displayExperimentsInfoBox)(config.flags);
146
- _context.n = 1;
147
- return (0, _server["default"])(config);
148
- case 1:
149
- app = _context.v;
150
- serverFactory = createServerFactory(config, addr, app);
151
- serverFactory.listen(addr.port || addr.path, addr.host, function () {
152
- // send a message for test
153
- if ((0, _lodash.isFunction)(process.send)) {
154
- process.send({
155
- verdaccio_started: true
156
- });
157
- }
158
- var addressServer = "".concat(addr.path ? _nodeUrl["default"].format({
159
- protocol: 'unix',
160
- pathname: addr.path
161
- }) : _nodeUrl["default"].format({
162
- protocol: addr.proto,
163
- hostname: addr.host,
164
- port: addr.port,
165
- pathname: '/'
166
- }));
167
- logger.info({
168
- addressServer: addressServer
169
- }, 'http address: @{addressServer}');
170
- logger.info({
171
- version: version
172
- }, 'version: @{version}');
173
- resolve();
174
- }).on('error', function (err) {
175
- reject(err);
176
- process.exitCode = 1;
177
- });
178
- for (_i = 0, _arr = ['SIGINT', 'SIGTERM', 'SIGHUP']; _i < _arr.length; _i++) {
179
- signal = _arr[_i];
180
- // Use once() so that receiving double signals exit the app.
181
- process.once(signal, handleShutdownGracefully);
182
- }
183
- case 2:
184
- return _context.a(2);
185
- }
186
- }, _callee);
187
- }));
188
- return function (_x6, _x7) {
189
- return _ref.apply(this, arguments);
190
- };
191
- }()));
192
- }
193
- }, _callee2);
194
- }));
195
- return _initServer.apply(this, arguments);
196
- }
197
- function runServer(_x5) {
198
- return _runServer.apply(this, arguments);
199
- }
200
- function _runServer() {
201
- _runServer = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(config) {
202
- var configurationParsed, addr, app;
203
- return _regenerator().w(function (_context3) {
204
- while (1) switch (_context3.n) {
205
- case 0:
206
- configurationParsed = (0, _config.getConfigParsed)(config);
207
- (0, _logger.setup)(configurationParsed.log);
208
- (0, _experiments.displayExperimentsInfoBox)(configurationParsed.flags);
209
- addr = (0, _config.getListenAddress)(configurationParsed.listen, _logger.logger);
210
- _context3.n = 1;
211
- return (0, _server["default"])(configurationParsed);
212
- case 1:
213
- app = _context3.v;
214
- return _context3.a(2, createServerFactory(configurationParsed, addr, app));
215
- }
216
- }, _callee3);
217
- }));
218
- return _runServer.apply(this, arguments);
113
+ * Exposes a server factory to be instantiated programmatically.
114
+ *
115
+ ```ts
116
+ const app = await runServer(); // default configuration
117
+ const app = await runServer('./config/config.yaml');
118
+ const app = await runServer({ configuration });
119
+ app.listen(4000, (event) => {
120
+ // do something
121
+ });
122
+ ```
123
+ * @param config
124
+ */
125
+ async function runServer(config) {
126
+ const configurationParsed = (0, _verdaccio_config.getConfigParsed)(config);
127
+ (0, _verdaccio_logger.setup)(configurationParsed.log);
128
+ require_experiments.displayExperimentsInfoBox(configurationParsed.flags);
129
+ return createServerFactory(configurationParsed, (0, _verdaccio_config.getListenAddress)(configurationParsed.listen, _verdaccio_logger.logger), await (0, _verdaccio_server.default)(configurationParsed));
219
130
  }
131
+ //#endregion
132
+ exports.initServer = initServer;
133
+ exports.runServer = runServer;
134
+
220
135
  //# sourceMappingURL=server.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","names":["_debug","_interopRequireDefault","require","_lodash","_nodeConstants","_nodeFs","_nodeHttp","_nodeHttps","_nodeUrl","_config","_logger","_server","_experiments","e","__esModule","_regenerator","t","r","Symbol","n","iterator","o","toStringTag","i","c","prototype","Generator","u","Object","create","_regeneratorDefine2","f","p","y","G","v","a","d","bind","length","l","TypeError","call","done","value","GeneratorFunction","GeneratorFunctionPrototype","getPrototypeOf","setPrototypeOf","__proto__","displayName","w","m","defineProperty","_regeneratorDefine","_invoke","enumerable","configurable","writable","_typeof","constructor","asyncGeneratorStep","Promise","resolve","then","_asyncToGenerator","arguments","apply","_next","_throw","ownKeys","keys","getOwnPropertySymbols","filter","getOwnPropertyDescriptor","push","_objectSpread","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","_toPropertyKey","_toPrimitive","toPrimitive","String","Number","debug","buildDebug","unlinkAddressPath","addr","path","fs","existsSync","unlinkSync","createServerFactory","config","app","serverFactory","proto","httpsOptions","secureOptions","constants","SSL_OP_NO_SSLv2","SSL_OP_NO_SSLv3","keyCertConfig","https","pfxConfig","key","cert","pfx","Error","passphrase","assign","readFileSync","ca","createServer","err","concat","message","http","server","keepAliveTimeout","initServer","_x","_x2","_x3","_x4","_initServer","_callee2","port","version","pkgName","_context2","_ref","_callee","reject","logger","handleShutdownGracefully","_i","_arr","signal","_context","_handleShutdownGracef","info","close","process","exit","setup","log","getListenAddress","listen","displayExperimentsInfoBox","flags","expressServer","host","isFunction","send","verdaccio_started","addressServer","url","format","protocol","pathname","hostname","on","exitCode","once","_x6","_x7","runServer","_x5","_runServer","_callee3","configurationParsed","_context3","getConfigParsed"],"sources":["../src/server.ts"],"sourcesContent":["/* eslint-disable */\nimport buildDebug from 'debug';\nimport { assign, isFunction } from 'lodash';\nimport constants from 'node:constants';\nimport fs from 'node:fs';\nimport http from 'node:http';\nimport https from 'node:https';\nimport url from 'node:url';\n\nimport { getConfigParsed, getListenAddress } from '@verdaccio/config';\nimport { logger, setup } from '@verdaccio/logger';\nimport expressServer from '@verdaccio/server';\nimport { ConfigYaml, HttpsConfKeyCert, HttpsConfPfx } from '@verdaccio/types';\n\nimport { displayExperimentsInfoBox } from './experiments';\n\nconst debug = buildDebug('verdaccio:node-api');\n\nfunction unlinkAddressPath(addr) {\n if (addr.path && fs.existsSync(addr.path)) {\n fs.unlinkSync(addr.path);\n }\n}\n\n/**\n * Return a native HTTP/HTTPS server instance\n * @param config\n * @param addr\n * @param app\n */\nexport function createServerFactory(config: ConfigYaml, addr, app) {\n let serverFactory;\n if (addr.proto === 'https') {\n debug('https enabled');\n try {\n let httpsOptions = {\n // disable insecure SSLv2 and SSLv3\n secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3,\n };\n\n const keyCertConfig = config.https as HttpsConfKeyCert;\n const pfxConfig = config.https as HttpsConfPfx;\n\n // https must either have key and cert or a pfx and (optionally) a passphrase\n if (!((keyCertConfig.key && keyCertConfig.cert) || pfxConfig.pfx)) {\n // logHTTPSError(configPath);\n throw Error('bad format https configuration');\n }\n\n if (pfxConfig.pfx) {\n const { pfx, passphrase } = pfxConfig;\n httpsOptions = assign(httpsOptions, {\n pfx: fs.readFileSync(pfx),\n passphrase: passphrase || '',\n });\n } else {\n const { key, cert, ca } = keyCertConfig;\n httpsOptions = assign(httpsOptions, {\n key: fs.readFileSync(key),\n cert: fs.readFileSync(cert),\n ...(ca && {\n ca: fs.readFileSync(ca),\n }),\n });\n }\n // TODO: enable http2 as feature\n // if (config.server.http2) <-- check if force http2\n serverFactory = https.createServer(httpsOptions, app);\n } catch (err: any) {\n throw new Error(`cannot create https server: ${err.message}`);\n }\n } else {\n // http\n debug('http enabled');\n serverFactory = http.createServer(app);\n }\n\n debug('server created');\n\n if (\n config.server &&\n typeof config.server.keepAliveTimeout !== 'undefined' &&\n // @ts-ignore\n config.server.keepAliveTimeout !== 'null'\n ) {\n // library definition for node is not up to date (doesn't contain recent 8.0 changes)\n serverFactory.keepAliveTimeout = config.server.keepAliveTimeout * 1000;\n }\n // FIXE: I could not find the reason of this code.\n unlinkAddressPath(addr);\n\n return serverFactory;\n}\n\n/**\n * Start the server on the port defined (or the port defined in the config file)\n * @param config\n * @param port\n * @param version\n * @param pkgName\n */\nexport async function initServer(\n config: ConfigYaml,\n port: string | void,\n version: string,\n pkgName: string\n): Promise<void> {\n return new Promise(async (resolve, reject) => {\n const logger = setup(config?.log as any);\n const addr = getListenAddress(port ?? config?.listen, logger);\n displayExperimentsInfoBox(config.flags);\n\n let app = await expressServer(config);\n const serverFactory = createServerFactory(config, addr, app);\n serverFactory\n .listen(addr.port || addr.path, addr.host, (): void => {\n // send a message for test\n if (isFunction(process.send)) {\n process.send({\n verdaccio_started: true,\n });\n }\n const addressServer = `${\n addr.path\n ? url.format({\n protocol: 'unix',\n pathname: addr.path,\n })\n : url.format({\n protocol: addr.proto,\n hostname: addr.host,\n port: addr.port,\n pathname: '/',\n })\n }`;\n logger.info({ addressServer }, 'http address: @{addressServer}');\n logger.info({ version }, 'version: @{version}');\n resolve();\n })\n .on('error', function (err): void {\n reject(err);\n process.exitCode = 1;\n });\n function handleShutdownGracefully() {\n logger.info('received shutdown signal - closing server gracefully...');\n serverFactory.close(() => {\n logger.info('server closed.');\n process.exit(0);\n });\n }\n\n for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {\n // Use once() so that receiving double signals exit the app.\n process.once(signal, handleShutdownGracefully);\n }\n });\n}\n\n/**\n * Exposes a server factory to be instantiated programmatically.\n *\n ```ts\n const app = await runServer(); // default configuration\n const app = await runServer('./config/config.yaml');\n const app = await runServer({ configuration });\n app.listen(4000, (event) => {\n // do something\n });\n ```\n * @param config\n */\nexport async function runServer(config?: string | ConfigYaml): Promise<any> {\n const configurationParsed = getConfigParsed(config);\n setup(configurationParsed.log as any);\n displayExperimentsInfoBox(configurationParsed.flags);\n const addr = getListenAddress(configurationParsed.listen, logger);\n const app = await expressServer(configurationParsed);\n return createServerFactory(configurationParsed, addr, app);\n}\n"],"mappings":";;;;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,cAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,OAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,SAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,UAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,QAAA,GAAAP,sBAAA,CAAAC,OAAA;AAEA,IAAAO,OAAA,GAAAP,OAAA;AACA,IAAAQ,OAAA,GAAAR,OAAA;AACA,IAAAS,OAAA,GAAAV,sBAAA,CAAAC,OAAA;AAGA,IAAAU,YAAA,GAAAV,OAAA;AAA0D,SAAAD,uBAAAY,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,gBAAAA,CAAA;AAAA,SAAAE,aAAA,IAb1D,uKAAAF,CAAA,EAAAG,CAAA,EAAAC,CAAA,wBAAAC,MAAA,GAAAA,MAAA,OAAAC,CAAA,GAAAF,CAAA,CAAAG,QAAA,kBAAAC,CAAA,GAAAJ,CAAA,CAAAK,WAAA,8BAAAC,EAAAN,CAAA,EAAAE,CAAA,EAAAE,CAAA,EAAAE,CAAA,QAAAC,CAAA,GAAAL,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AsI,kBAAa,EAACoB,mBAAmB,CAAC;QAAA;UAA9C7E,GAAG,GAAA8E,SAAA,CAAA3I,CAAA;UAAA,OAAA2I,SAAA,CAAA1I,CAAA,IACF0D,mBAAmB,CAAC+E,mBAAmB,EAAEpF,IAAI,EAAEO,GAAG,CAAC;MAAA;IAAA,GAAA4E,QAAA;EAAA,CAC3D;EAAA,OAAAD,UAAA,CAAAxG,KAAA,OAAAD,SAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"server.js","names":[],"sources":["../src/server.ts"],"sourcesContent":["/* eslint-disable */\nimport buildDebug from 'debug';\nimport { assign, isFunction } from 'lodash';\nimport constants from 'node:constants';\nimport fs from 'node:fs';\nimport http from 'node:http';\nimport https from 'node:https';\nimport url from 'node:url';\n\nimport { getConfigParsed, getListenAddress } from '@verdaccio/config';\nimport { logger, setup } from '@verdaccio/logger';\nimport expressServer from '@verdaccio/server';\nimport { ConfigYaml, HttpsConfKeyCert, HttpsConfPfx } from '@verdaccio/types';\n\nimport { displayExperimentsInfoBox } from './experiments';\n\nconst debug = buildDebug('verdaccio:node-api');\n\nfunction unlinkAddressPath(addr) {\n if (addr.path && fs.existsSync(addr.path)) {\n fs.unlinkSync(addr.path);\n }\n}\n\n/**\n * Return a native HTTP/HTTPS server instance\n * @param config\n * @param addr\n * @param app\n */\nexport function createServerFactory(config: ConfigYaml, addr, app) {\n let serverFactory;\n if (addr.proto === 'https') {\n debug('https enabled');\n try {\n let httpsOptions = {\n // disable insecure SSLv2 and SSLv3\n secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3,\n };\n\n const keyCertConfig = config.https as HttpsConfKeyCert;\n const pfxConfig = config.https as HttpsConfPfx;\n\n // https must either have key and cert or a pfx and (optionally) a passphrase\n if (!((keyCertConfig.key && keyCertConfig.cert) || pfxConfig.pfx)) {\n // logHTTPSError(configPath);\n throw Error('bad format https configuration');\n }\n\n if (pfxConfig.pfx) {\n const { pfx, passphrase } = pfxConfig;\n httpsOptions = assign(httpsOptions, {\n pfx: fs.readFileSync(pfx),\n passphrase: passphrase || '',\n });\n } else {\n const { key, cert, ca } = keyCertConfig;\n httpsOptions = assign(httpsOptions, {\n key: fs.readFileSync(key),\n cert: fs.readFileSync(cert),\n ...(ca && {\n ca: fs.readFileSync(ca),\n }),\n });\n }\n // TODO: enable http2 as feature\n // if (config.server.http2) <-- check if force http2\n serverFactory = https.createServer(httpsOptions, app);\n } catch (err: any) {\n throw new Error(`cannot create https server: ${err.message}`);\n }\n } else {\n // http\n debug('http enabled');\n serverFactory = http.createServer(app);\n }\n\n debug('server created');\n\n if (\n config.server &&\n typeof config.server.keepAliveTimeout !== 'undefined' &&\n // @ts-ignore\n config.server.keepAliveTimeout !== 'null'\n ) {\n // library definition for node is not up to date (doesn't contain recent 8.0 changes)\n serverFactory.keepAliveTimeout = config.server.keepAliveTimeout * 1000;\n }\n // FIXE: I could not find the reason of this code.\n unlinkAddressPath(addr);\n\n return serverFactory;\n}\n\n/**\n * Start the server on the port defined (or the port defined in the config file)\n * @param config\n * @param port\n * @param version\n * @param pkgName\n */\nexport async function initServer(\n config: ConfigYaml,\n port: string | void,\n version: string,\n pkgName: string\n): Promise<void> {\n return new Promise(async (resolve, reject) => {\n const logger = setup(config?.log as any);\n const addr = getListenAddress(port ?? config?.listen, logger);\n displayExperimentsInfoBox(config.flags);\n\n let app = await expressServer(config);\n const serverFactory = createServerFactory(config, addr, app);\n serverFactory\n .listen(addr.port || addr.path, addr.host, (): void => {\n // send a message for test\n if (isFunction(process.send)) {\n process.send({\n verdaccio_started: true,\n });\n }\n const addressServer = `${\n addr.path\n ? url.format({\n protocol: 'unix',\n pathname: addr.path,\n })\n : url.format({\n protocol: addr.proto,\n hostname: addr.host,\n port: addr.port,\n pathname: '/',\n })\n }`;\n logger.info({ addressServer }, 'http address: @{addressServer}');\n logger.info({ version }, 'version: @{version}');\n resolve();\n })\n .on('error', function (err): void {\n reject(err);\n process.exitCode = 1;\n });\n function handleShutdownGracefully() {\n logger.info('received shutdown signal - closing server gracefully...');\n serverFactory.close(() => {\n logger.info('server closed.');\n process.exit(0);\n });\n }\n\n for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {\n // Use once() so that receiving double signals exit the app.\n process.once(signal, handleShutdownGracefully);\n }\n });\n}\n\n/**\n * Exposes a server factory to be instantiated programmatically.\n *\n ```ts\n const app = await runServer(); // default configuration\n const app = await runServer('./config/config.yaml');\n const app = await runServer({ configuration });\n app.listen(4000, (event) => {\n // do something\n });\n ```\n * @param config\n */\nexport async function runServer(config?: string | ConfigYaml): Promise<any> {\n const configurationParsed = getConfigParsed(config);\n setup(configurationParsed.log as any);\n displayExperimentsInfoBox(configurationParsed.flags);\n const addr = getListenAddress(configurationParsed.listen, logger);\n const app = await expressServer(configurationParsed);\n return createServerFactory(configurationParsed, addr, app);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAgBA,IAAM,WAAA,GAAA,MAAA,SAAmB,qBAAqB;AAE9C,SAAS,kBAAkB,MAAM;AAC/B,KAAI,KAAK,QAAQ,QAAA,QAAG,WAAW,KAAK,KAAK,CACvC,SAAA,QAAG,WAAW,KAAK,KAAK;;;;;;;;AAU5B,SAAgB,oBAAoB,QAAoB,MAAM,KAAK;CACjE,IAAI;AACJ,KAAI,KAAK,UAAU,SAAS;AAC1B,UAAM,gBAAgB;AACtB,MAAI;GACF,IAAI,eAAe,EAEjB,eAAe,eAAA,QAAU,kBAAkB,eAAA,QAAU,iBACtD;GAED,MAAM,gBAAgB,OAAO;GAC7B,MAAM,YAAY,OAAO;AAGzB,OAAI,EAAG,cAAc,OAAO,cAAc,QAAS,UAAU,KAE3D,OAAM,MAAM,iCAAiC;AAG/C,OAAI,UAAU,KAAK;IACjB,MAAM,EAAE,KAAK,eAAe;AAC5B,oBAAA,GAAA,OAAA,QAAsB,cAAc;KAClC,KAAK,QAAA,QAAG,aAAa,IAAI;KACzB,YAAY,cAAc;KAC3B,CAAC;UACG;IACL,MAA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AAK,EAAE,eAAe,EAAE,iCAAiC;AAChE,UAAO,KAAK,EAAE,SAAS,EAAE,sBAAsB;AAC/C,YAAS;IACT,CACD,GAAG,SAAS,SAAU,KAAW;AAChC,UAAO,IAAI;AACX,WAAQ,WAAW;IACnB;EACJ,SAAS,2BAA2B;AAClC,UAAO,KAAK,0DAA0D;AACtE,iBAAc,YAAY;AACxB,WAAO,KAAK,iBAAiB;AAC7B,YAAQ,KAAK,EAAE;KACf;;AAGJ,OAAK,MAAM,UAAU;GAAC;GAAU;GAAW;GAAS,CAElD,SAAQ,KAAK,QAAQ,yBAAyB;GAEhD;;;;;;;;;;;;;;;AAgBJ,eAAsB,UAAU,QAA4C;CAC1E,MAAM,uBAAA,GAAA,kBAAA,iBAAsC,OAAO;AACnD,EAAA,GAAA,kBAAA,OAAM,oBAAoB,IAAW;AACrC,qBAAA,0BAA0B,oBAAoB,MAAM;AAGpD,QAAO,oBAAoB,sBAAA,GAAA,kBAAA,kBAFG,oBAAoB,QAAQ,kBAAA,OAAO,EACrD,OAAA,GAAA,kBAAA,SAAoB,oBAAoB,CACM"}
@@ -0,0 +1,126 @@
1
+ import { displayExperimentsInfoBox } from "./experiments.mjs";
2
+ import buildDebug from "debug";
3
+ import { assign, isFunction } from "lodash";
4
+ import constants from "node:constants";
5
+ import fs from "node:fs";
6
+ import http from "node:http";
7
+ import https from "node:https";
8
+ import url from "node:url";
9
+ import { getConfigParsed, getListenAddress } from "@verdaccio/config";
10
+ import { logger, setup } from "@verdaccio/logger";
11
+ import expressServer from "@verdaccio/server";
12
+ //#region src/server.ts
13
+ var debug = buildDebug("verdaccio:node-api");
14
+ function unlinkAddressPath(addr) {
15
+ if (addr.path && fs.existsSync(addr.path)) fs.unlinkSync(addr.path);
16
+ }
17
+ /**
18
+ * Return a native HTTP/HTTPS server instance
19
+ * @param config
20
+ * @param addr
21
+ * @param app
22
+ */
23
+ function createServerFactory(config, addr, app) {
24
+ let serverFactory;
25
+ if (addr.proto === "https") {
26
+ debug("https enabled");
27
+ try {
28
+ let httpsOptions = { secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3 };
29
+ const keyCertConfig = config.https;
30
+ const pfxConfig = config.https;
31
+ if (!(keyCertConfig.key && keyCertConfig.cert || pfxConfig.pfx)) throw Error("bad format https configuration");
32
+ if (pfxConfig.pfx) {
33
+ const { pfx, passphrase } = pfxConfig;
34
+ httpsOptions = assign(httpsOptions, {
35
+ pfx: fs.readFileSync(pfx),
36
+ passphrase: passphrase || ""
37
+ });
38
+ } else {
39
+ const { key, cert, ca } = keyCertConfig;
40
+ httpsOptions = assign(httpsOptions, {
41
+ key: fs.readFileSync(key),
42
+ cert: fs.readFileSync(cert),
43
+ ...ca && { ca: fs.readFileSync(ca) }
44
+ });
45
+ }
46
+ serverFactory = https.createServer(httpsOptions, app);
47
+ } catch (err) {
48
+ throw new Error(`cannot create https server: ${err.message}`);
49
+ }
50
+ } else {
51
+ debug("http enabled");
52
+ serverFactory = http.createServer(app);
53
+ }
54
+ debug("server created");
55
+ if (config.server && typeof config.server.keepAliveTimeout !== "undefined" && config.server.keepAliveTimeout !== "null") serverFactory.keepAliveTimeout = config.server.keepAliveTimeout * 1e3;
56
+ unlinkAddressPath(addr);
57
+ return serverFactory;
58
+ }
59
+ /**
60
+ * Start the server on the port defined (or the port defined in the config file)
61
+ * @param config
62
+ * @param port
63
+ * @param version
64
+ * @param pkgName
65
+ */
66
+ async function initServer(config, port, version, pkgName) {
67
+ return new Promise(async (resolve, reject) => {
68
+ const logger = setup(config?.log);
69
+ const addr = getListenAddress(port ?? config?.listen, logger);
70
+ displayExperimentsInfoBox(config.flags);
71
+ const serverFactory = createServerFactory(config, addr, await expressServer(config));
72
+ serverFactory.listen(addr.port || addr.path, addr.host, () => {
73
+ if (isFunction(process.send)) process.send({ verdaccio_started: true });
74
+ const addressServer = `${addr.path ? url.format({
75
+ protocol: "unix",
76
+ pathname: addr.path
77
+ }) : url.format({
78
+ protocol: addr.proto,
79
+ hostname: addr.host,
80
+ port: addr.port,
81
+ pathname: "/"
82
+ })}`;
83
+ logger.info({ addressServer }, "http address: @{addressServer}");
84
+ logger.info({ version }, "version: @{version}");
85
+ resolve();
86
+ }).on("error", function(err) {
87
+ reject(err);
88
+ process.exitCode = 1;
89
+ });
90
+ function handleShutdownGracefully() {
91
+ logger.info("received shutdown signal - closing server gracefully...");
92
+ serverFactory.close(() => {
93
+ logger.info("server closed.");
94
+ process.exit(0);
95
+ });
96
+ }
97
+ for (const signal of [
98
+ "SIGINT",
99
+ "SIGTERM",
100
+ "SIGHUP"
101
+ ]) process.once(signal, handleShutdownGracefully);
102
+ });
103
+ }
104
+ /**
105
+ * Exposes a server factory to be instantiated programmatically.
106
+ *
107
+ ```ts
108
+ const app = await runServer(); // default configuration
109
+ const app = await runServer('./config/config.yaml');
110
+ const app = await runServer({ configuration });
111
+ app.listen(4000, (event) => {
112
+ // do something
113
+ });
114
+ ```
115
+ * @param config
116
+ */
117
+ async function runServer(config) {
118
+ const configurationParsed = getConfigParsed(config);
119
+ setup(configurationParsed.log);
120
+ displayExperimentsInfoBox(configurationParsed.flags);
121
+ return createServerFactory(configurationParsed, getListenAddress(configurationParsed.listen, logger), await expressServer(configurationParsed));
122
+ }
123
+ //#endregion
124
+ export { initServer, runServer };
125
+
126
+ //# sourceMappingURL=server.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.mjs","names":[],"sources":["../src/server.ts"],"sourcesContent":["/* eslint-disable */\nimport buildDebug from 'debug';\nimport { assign, isFunction } from 'lodash';\nimport constants from 'node:constants';\nimport fs from 'node:fs';\nimport http from 'node:http';\nimport https from 'node:https';\nimport url from 'node:url';\n\nimport { getConfigParsed, getListenAddress } from '@verdaccio/config';\nimport { logger, setup } from '@verdaccio/logger';\nimport expressServer from '@verdaccio/server';\nimport { ConfigYaml, HttpsConfKeyCert, HttpsConfPfx } from '@verdaccio/types';\n\nimport { displayExperimentsInfoBox } from './experiments';\n\nconst debug = buildDebug('verdaccio:node-api');\n\nfunction unlinkAddressPath(addr) {\n if (addr.path && fs.existsSync(addr.path)) {\n fs.unlinkSync(addr.path);\n }\n}\n\n/**\n * Return a native HTTP/HTTPS server instance\n * @param config\n * @param addr\n * @param app\n */\nexport function createServerFactory(config: ConfigYaml, addr, app) {\n let serverFactory;\n if (addr.proto === 'https') {\n debug('https enabled');\n try {\n let httpsOptions = {\n // disable insecure SSLv2 and SSLv3\n secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3,\n };\n\n const keyCertConfig = config.https as HttpsConfKeyCert;\n const pfxConfig = config.https as HttpsConfPfx;\n\n // https must either have key and cert or a pfx and (optionally) a passphrase\n if (!((keyCertConfig.key && keyCertConfig.cert) || pfxConfig.pfx)) {\n // logHTTPSError(configPath);\n throw Error('bad format https configuration');\n }\n\n if (pfxConfig.pfx) {\n const { pfx, passphrase } = pfxConfig;\n httpsOptions = assign(httpsOptions, {\n pfx: fs.readFileSync(pfx),\n passphrase: passphrase || '',\n });\n } else {\n const { key, cert, ca } = keyCertConfig;\n httpsOptions = assign(httpsOptions, {\n key: fs.readFileSync(key),\n cert: fs.readFileSync(cert),\n ...(ca && {\n ca: fs.readFileSync(ca),\n }),\n });\n }\n // TODO: enable http2 as feature\n // if (config.server.http2) <-- check if force http2\n serverFactory = https.createServer(httpsOptions, app);\n } catch (err: any) {\n throw new Error(`cannot create https server: ${err.message}`);\n }\n } else {\n // http\n debug('http enabled');\n serverFactory = http.createServer(app);\n }\n\n debug('server created');\n\n if (\n config.server &&\n typeof config.server.keepAliveTimeout !== 'undefined' &&\n // @ts-ignore\n config.server.keepAliveTimeout !== 'null'\n ) {\n // library definition for node is not up to date (doesn't contain recent 8.0 changes)\n serverFactory.keepAliveTimeout = config.server.keepAliveTimeout * 1000;\n }\n // FIXE: I could not find the reason of this code.\n unlinkAddressPath(addr);\n\n return serverFactory;\n}\n\n/**\n * Start the server on the port defined (or the port defined in the config file)\n * @param config\n * @param port\n * @param version\n * @param pkgName\n */\nexport async function initServer(\n config: ConfigYaml,\n port: string | void,\n version: string,\n pkgName: string\n): Promise<void> {\n return new Promise(async (resolve, reject) => {\n const logger = setup(config?.log as any);\n const addr = getListenAddress(port ?? config?.listen, logger);\n displayExperimentsInfoBox(config.flags);\n\n let app = await expressServer(config);\n const serverFactory = createServerFactory(config, addr, app);\n serverFactory\n .listen(addr.port || addr.path, addr.host, (): void => {\n // send a message for test\n if (isFunction(process.send)) {\n process.send({\n verdaccio_started: true,\n });\n }\n const addressServer = `${\n addr.path\n ? url.format({\n protocol: 'unix',\n pathname: addr.path,\n })\n : url.format({\n protocol: addr.proto,\n hostname: addr.host,\n port: addr.port,\n pathname: '/',\n })\n }`;\n logger.info({ addressServer }, 'http address: @{addressServer}');\n logger.info({ version }, 'version: @{version}');\n resolve();\n })\n .on('error', function (err): void {\n reject(err);\n process.exitCode = 1;\n });\n function handleShutdownGracefully() {\n logger.info('received shutdown signal - closing server gracefully...');\n serverFactory.close(() => {\n logger.info('server closed.');\n process.exit(0);\n });\n }\n\n for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {\n // Use once() so that receiving double signals exit the app.\n process.once(signal, handleShutdownGracefully);\n }\n });\n}\n\n/**\n * Exposes a server factory to be instantiated programmatically.\n *\n ```ts\n const app = await runServer(); // default configuration\n const app = await runServer('./config/config.yaml');\n const app = await runServer({ configuration });\n app.listen(4000, (event) => {\n // do something\n });\n ```\n * @param config\n */\nexport async function runServer(config?: string | ConfigYaml): Promise<any> {\n const configurationParsed = getConfigParsed(config);\n setup(configurationParsed.log as any);\n displayExperimentsInfoBox(configurationParsed.flags);\n const addr = getListenAddress(configurationParsed.listen, logger);\n const app = await expressServer(configurationParsed);\n return createServerFactory(configurationParsed, addr, app);\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,IAAM,QAAQ,WAAW,qBAAqB;AAE9C,SAAS,kBAAkB,MAAM;AAC/B,KAAI,KAAK,QAAQ,GAAG,WAAW,KAAK,KA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MAAM,gBAAgB,oBAAoB,QAAQ,MADxC,MAAM,cAAc,OAAO,CACuB;AAC5D,gBACG,OAAO,KAAK,QAAQ,KAAK,MAAM,KAAK,YAAkB;AAErD,OAAI,WAAW,QAAQ,KAAK,CAC1B,SAAQ,KAAK,EACX,mBAAmB,MACpB,CAAC;GAEJ,MAAM,gBAAgB,GACpB,KAAK,OACD,IAAI,OAAO;IACT,UAAU;IACV,UAAU,KAAK;IAChB,CAAC,GACF,IAAI,OAAO;IACT,UAAU,KAAK;IACf,UAAU,KAAK;IACf,MAAM,KAAK;IACX,UAAU;IACX,CAAC;AAER,UAAO,KAAK,EAAE,eAAe,EAAE,iCAAiC;AAChE,UAAO,KAAK,EAAE,SAAS,EAAE,sBAAsB;AAC/C,YAAS;IACT,CACD,GAAG,SAAS,SAAU,KAAW;AAChC,UAAO,IAAI;AACX,WAAQ,WAAW;IACnB;EACJ,SAAS,2BAA2B;AAClC,UAAO,KAAK,0DAA0D;AACtE,iBAAc,YAAY;AACxB,WAAO,KAAK,iBAAiB;AAC7B,YAAQ,KAAK,EAAE;KACf;;AAGJ,OAAK,MAAM,UAAU;GAAC;GAAU;GAAW;GAAS,CAElD,SAAQ,KAAK,QAAQ,yBAAyB;GAEhD;;;;;;;;;;;;;;;AAgBJ,eAAsB,UAAU,QAA4C;CAC1E,MAAM,sBAAsB,gBAAgB,OAAO;AACnD,OAAM,oBAAoB,IAAW;AACrC,2BAA0B,oBAAoB,MAAM;AAGpD,QAAO,oBAAoB,qBAFd,iBAAiB,oBAAoB,QAAQ,OAAO,EACrD,MAAM,cAAc,oBAAoB,CACM"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdaccio/node-api",
3
- "version": "9.0.0-next-9.2",
3
+ "version": "9.0.0-next-9.4",
4
4
  "description": "Verdaccio Node API",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -33,14 +33,14 @@
33
33
  },
34
34
  "license": "MIT",
35
35
  "dependencies": {
36
- "@verdaccio/config": "9.0.0-next-9.2",
37
- "@verdaccio/logger": "9.0.0-next-9.2",
38
- "@verdaccio/server": "9.0.0-next-9.2",
36
+ "@verdaccio/config": "9.0.0-next-9.4",
37
+ "@verdaccio/logger": "9.0.0-next-9.4",
38
+ "@verdaccio/server": "9.0.0-next-9.4",
39
39
  "debug": "4.4.3",
40
40
  "lodash": "4.17.23"
41
41
  },
42
42
  "devDependencies": {
43
- "@verdaccio/types": "14.0.0-next-9.0",
43
+ "@verdaccio/types": "14.0.0-next-9.1",
44
44
  "supertest": "7.1.4",
45
45
  "vitest": "3.2.4"
46
46
  },
@@ -51,13 +51,24 @@
51
51
  "type": "opencollective",
52
52
  "url": "https://opencollective.com/verdaccio"
53
53
  },
54
+ "module": "./build/index.mjs",
55
+ "exports": {
56
+ ".": {
57
+ "import": {
58
+ "types": "./build/index.d.ts",
59
+ "default": "./build/index.mjs"
60
+ },
61
+ "require": {
62
+ "types": "./build/index.d.ts",
63
+ "default": "./build/index.js"
64
+ }
65
+ },
66
+ "./build/*": "./build/*"
67
+ },
54
68
  "scripts": {
55
69
  "clean": "rimraf ./build",
56
- "type-check": "tsc --noEmit -p tsconfig.build.json",
57
- "build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
58
- "build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
59
- "watch": "pnpm build:js -- --watch",
60
- "build": "pnpm run build:js && pnpm run build:types",
70
+ "watch": "vite build --watch",
71
+ "build": "vite build",
61
72
  "test": "vitest run"
62
73
  }
63
74
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["_server","require"],"sources":["../src/index.ts"],"sourcesContent":["export { initServer, runServer } from './server';\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA","ignoreList":[]}