@verdaccio/config 8.1.4 → 8.2.0

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.
Files changed (61) hide show
  1. package/build/_virtual/_rolldown/runtime.js +23 -0
  2. package/build/address.js +80 -102
  3. package/build/address.js.map +1 -1
  4. package/build/address.mjs +86 -0
  5. package/build/address.mjs.map +1 -0
  6. package/build/agent.js +11 -16
  7. package/build/agent.js.map +1 -1
  8. package/build/agent.mjs +12 -0
  9. package/build/agent.mjs.map +1 -0
  10. package/build/builder.js +128 -131
  11. package/build/builder.js.map +1 -1
  12. package/build/builder.mjs +129 -0
  13. package/build/builder.mjs.map +1 -0
  14. package/build/conf/index.js +10 -11
  15. package/build/conf/index.js.map +1 -1
  16. package/build/conf/index.mjs +12 -0
  17. package/build/conf/index.mjs.map +1 -0
  18. package/build/config-path.js +154 -163
  19. package/build/config-path.js.map +1 -1
  20. package/build/config-path.mjs +171 -0
  21. package/build/config-path.mjs.map +1 -0
  22. package/build/config-utils.js +37 -41
  23. package/build/config-utils.js.map +1 -1
  24. package/build/config-utils.mjs +40 -0
  25. package/build/config-utils.mjs.map +1 -0
  26. package/build/config.js +154 -203
  27. package/build/config.js.map +1 -1
  28. package/build/config.mjs +153 -0
  29. package/build/config.mjs.map +1 -0
  30. package/build/index.js +52 -167
  31. package/build/index.mjs +14 -0
  32. package/build/package-access.js +52 -68
  33. package/build/package-access.js.map +1 -1
  34. package/build/package-access.mjs +52 -0
  35. package/build/package-access.mjs.map +1 -0
  36. package/build/parse.js +83 -100
  37. package/build/parse.js.map +1 -1
  38. package/build/parse.mjs +85 -0
  39. package/build/parse.mjs.map +1 -0
  40. package/build/security.js +15 -22
  41. package/build/security.js.map +1 -1
  42. package/build/security.mjs +16 -0
  43. package/build/security.mjs.map +1 -0
  44. package/build/serverSettings.js +10 -15
  45. package/build/serverSettings.js.map +1 -1
  46. package/build/serverSettings.mjs +12 -0
  47. package/build/serverSettings.mjs.map +1 -0
  48. package/build/token.js +10 -13
  49. package/build/token.js.map +1 -1
  50. package/build/token.mjs +13 -0
  51. package/build/token.mjs.map +1 -0
  52. package/build/uplinks.js +47 -55
  53. package/build/uplinks.js.map +1 -1
  54. package/build/uplinks.mjs +50 -0
  55. package/build/uplinks.mjs.map +1 -0
  56. package/build/user.js +42 -37
  57. package/build/user.js.map +1 -1
  58. package/build/user.mjs +48 -0
  59. package/build/user.mjs.map +1 -0
  60. package/package.json +22 -9
  61. package/build/index.js.map +0 -1
@@ -1,187 +1,178 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.findConfigFile = findConfigFile;
7
- exports.readDefaultConfig = readDefaultConfig;
8
- var _debug = _interopRequireDefault(require("debug"));
9
- var _lodash = _interopRequireDefault(require("lodash"));
10
- var _nodeFs = _interopRequireDefault(require("node:fs"));
11
- var _nodeOs = _interopRequireDefault(require("node:os"));
12
- var _nodePath = _interopRequireDefault(require("node:path"));
13
- var _configUtils = require("./config-utils");
14
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
- const CONFIG_FILE = 'config.yaml';
16
- const XDG = 'xdg';
17
- const pkgJSON = {
18
- name: 'verdaccio'
19
- };
20
- const debug = (0, _debug.default)('verdaccio:config:config-path');
21
-
1
+ const require_runtime = require("./_virtual/_rolldown/runtime.js");
2
+ const require_config_utils = require("./config-utils.js");
3
+ let debug = require("debug");
4
+ debug = require_runtime.__toESM(debug);
5
+ let lodash = require("lodash");
6
+ lodash = require_runtime.__toESM(lodash);
7
+ let node_fs = require("node:fs");
8
+ node_fs = require_runtime.__toESM(node_fs);
9
+ let node_os = require("node:os");
10
+ node_os = require_runtime.__toESM(node_os);
11
+ let node_path = require("node:path");
12
+ node_path = require_runtime.__toESM(node_path);
13
+ let node_url = require("node:url");
14
+ //#region src/config-path.ts
15
+ var CONFIG_FILE = "config.yaml";
16
+ var XDG = "xdg";
17
+ var pkgJSON = { name: "verdaccio" };
18
+ var debug$1 = (0, debug.default)("verdaccio:config:config-path");
22
19
  /**
23
- * Find and get the first config file that match.
24
- * @return {String} the config file path
25
- */
20
+ * Find and get the first config file that match.
21
+ * @return {String} the config file path
22
+ */
26
23
  function findConfigFile(configPath) {
27
- debug('searching for config file %o', configPath);
28
- if (typeof configPath !== 'undefined') {
29
- const configLocation = _nodePath.default.resolve(configPath);
30
- debug('custom location %s', configLocation);
31
- return configLocation;
32
- }
33
- const configPaths = getConfigPaths();
34
- debug('%o posible locations found', configPaths.length);
35
- if (configPaths.length === 0) {
36
- debug('no configuration files can be processed');
37
- // this should never happens
38
- throw new Error('no configuration files can be processed');
39
- }
40
-
41
- // find the first location that already exist
42
- const primaryConf = _lodash.default.find(configPaths, configLocation => (0, _configUtils.fileExists)(configLocation.path));
43
- if (typeof primaryConf !== 'undefined') {
44
- debug('at least one primary location detected at %s', primaryConf?.path);
45
- return primaryConf.path;
46
- }
47
- debug('no previous location found, creating a new one');
48
- debug('generating the first match path location %s', configPaths[0].path);
49
- return createConfigFile(configPaths[0]).path;
24
+ debug$1("searching for config file %o", configPath);
25
+ if (typeof configPath !== "undefined") {
26
+ const configLocation = node_path.default.resolve(configPath);
27
+ debug$1("custom location %s", configLocation);
28
+ return configLocation;
29
+ }
30
+ const configPaths = getConfigPaths();
31
+ debug$1("%o posible locations found", configPaths.length);
32
+ if (configPaths.length === 0) {
33
+ debug$1("no configuration files can be processed");
34
+ throw new Error("no configuration files can be processed");
35
+ }
36
+ const primaryConf = lodash.default.find(configPaths, (configLocation) => require_config_utils.fileExists(configLocation.path));
37
+ if (typeof primaryConf !== "undefined") {
38
+ debug$1("at least one primary location detected at %s", primaryConf?.path);
39
+ return primaryConf.path;
40
+ }
41
+ debug$1("no previous location found, creating a new one");
42
+ debug$1("generating the first match path location %s", configPaths[0].path);
43
+ return createConfigFile(configPaths[0]).path;
50
44
  }
51
45
  function createConfigFile(configLocation) {
52
- createConfigFolder(configLocation);
53
- const defaultConfig = updateStorageLinks(configLocation, readDefaultConfig());
54
- _nodeFs.default.writeFileSync(configLocation.path, defaultConfig);
55
- return configLocation;
46
+ createConfigFolder(configLocation);
47
+ const defaultConfig = updateStorageLinks(configLocation, readDefaultConfig());
48
+ node_fs.default.writeFileSync(configLocation.path, defaultConfig);
49
+ return configLocation;
56
50
  }
57
51
  function readDefaultConfig() {
58
- const pathDefaultConf = _nodePath.default.resolve(__dirname, 'conf/default.yaml');
59
- try {
60
- debug('the path of default config used from %s', pathDefaultConf);
61
- _nodeFs.default.accessSync(pathDefaultConf, _nodeFs.default.constants.R_OK);
62
- debug('configuration file has enough permissions for reading');
63
- } catch {
64
- debug('configuration file does not have enough permissions for reading');
65
- throw new TypeError('configuration file does not have enough permissions for reading');
66
- }
67
- return _nodeFs.default.readFileSync(pathDefaultConf, 'utf8');
52
+ const currentDir = {}.url ? node_path.default.dirname((0, node_url.fileURLToPath)({}.url)) : __dirname;
53
+ const pathDefaultConf = node_path.default.resolve(currentDir, "conf/default.yaml");
54
+ try {
55
+ debug$1("the path of default config used from %s", pathDefaultConf);
56
+ node_fs.default.accessSync(pathDefaultConf, node_fs.default.constants.R_OK);
57
+ debug$1("configuration file has enough permissions for reading");
58
+ } catch {
59
+ debug$1("configuration file does not have enough permissions for reading");
60
+ throw new TypeError("configuration file does not have enough permissions for reading");
61
+ }
62
+ return node_fs.default.readFileSync(pathDefaultConf, "utf8");
68
63
  }
69
64
  function createConfigFolder(configLocation) {
70
- const folder = _nodePath.default.dirname(configLocation.path);
71
- debug(`creating default config file folder at %o`, folder);
72
- _nodeFs.default.mkdirSync(folder, {
73
- recursive: true
74
- });
75
- debug(`folder %o created`, folder);
65
+ const folder = node_path.default.dirname(configLocation.path);
66
+ debug$1(`creating default config file folder at %o`, folder);
67
+ node_fs.default.mkdirSync(folder, { recursive: true });
68
+ debug$1(`folder %o created`, folder);
76
69
  }
77
-
78
70
  /**
79
- * Update the storage links to the new location if it is necessary.
80
- * @param configLocation
81
- * @param defaultConfig
82
- * @returns
83
- */
71
+ * Update the storage links to the new location if it is necessary.
72
+ * @param configLocation
73
+ * @param defaultConfig
74
+ * @returns
75
+ */
84
76
  function updateStorageLinks(configLocation, defaultConfig) {
85
- debug('checking storage links for %s and type %s', configLocation.path, configLocation.type);
86
- if (configLocation.type !== XDG) {
87
- debug(`skip storage override for %s`, configLocation.type);
88
- return defaultConfig;
89
- }
90
-
91
- // $XDG_DATA_HOME defines the base directory relative to which user specific data
92
- // files should be stored, If $XDG_DATA_HOME is either not set or empty, a default
93
- // equal to $HOME/.local/share should be used.
94
- let dataDir = process.env.XDG_DATA_HOME || _nodePath.default.join(process.env.HOME, '.local', 'share');
95
- if ((0, _configUtils.folderExists)(dataDir)) {
96
- debug(`previous storage located`);
97
- debug(`update storage links to %s`, dataDir);
98
- dataDir = _nodePath.default.resolve(_nodePath.default.join(dataDir, pkgJSON.name, 'storage'));
99
- return defaultConfig.replace(/^storage: .\/storage$/m, `storage: ${dataDir}`);
100
- }
101
- debug(`could not find a previous storage location, skip override`);
102
- return defaultConfig;
77
+ debug$1("checking storage links for %s and type %s", configLocation.path, configLocation.type);
78
+ if (configLocation.type !== XDG) {
79
+ debug$1(`skip storage override for %s`, configLocation.type);
80
+ return defaultConfig;
81
+ }
82
+ let dataDir = process.env.XDG_DATA_HOME || node_path.default.join(process.env.HOME, ".local", "share");
83
+ if (require_config_utils.folderExists(dataDir)) {
84
+ debug$1(`previous storage located`);
85
+ debug$1(`update storage links to %s`, dataDir);
86
+ dataDir = node_path.default.resolve(node_path.default.join(dataDir, pkgJSON.name, "storage"));
87
+ return defaultConfig.replace(/^storage: .\/storage$/m, `storage: ${dataDir}`);
88
+ }
89
+ debug$1(`could not find a previous storage location, skip override`);
90
+ return defaultConfig;
103
91
  }
104
-
105
92
  /**
106
- * Return a list of configuration locations by platform.
107
- * @returns
108
- */
93
+ * Return a list of configuration locations by platform.
94
+ * @returns
95
+ */
109
96
  function getConfigPaths() {
110
- const listPaths = [getXDGDirectory(), getWindowsDirectory(), getRelativeDefaultDirectory(), getOldDirectory()];
111
- return listPaths.reduce(function (acc, currentValue) {
112
- if (typeof currentValue !== 'undefined') {
113
- debug('posible directory path generated %s for type %s', currentValue?.path, currentValue.type);
114
- acc.push(currentValue);
115
- }
116
- return acc;
117
- }, []);
97
+ return [
98
+ getXDGDirectory(),
99
+ getWindowsDirectory(),
100
+ getRelativeDefaultDirectory(),
101
+ getOldDirectory()
102
+ ].reduce(function(acc, currentValue) {
103
+ if (typeof currentValue !== "undefined") {
104
+ debug$1("posible directory path generated %s for type %s", currentValue?.path, currentValue.type);
105
+ acc.push(currentValue);
106
+ }
107
+ return acc;
108
+ }, []);
118
109
  }
119
-
120
110
  /**
121
- * Get XDG_CONFIG_HOME or HOME location (usually unix)
122
- *
123
- * The XDG_CONFIG_HOME environment variable is also part of the XDG Base Directory Specification,
124
- * which aims to standardize the locations where applications store configuration files and other
125
- * user-specific data on Unix-like operating systems.
126
- *
127
- *
128
- *
129
- * https://specifications.freedesktop.org/basedir-spec/latest/
130
- *
131
- *
132
- * @returns
133
- */
134
- const getXDGDirectory = () => {
135
- const xDGConfigPath = process.env.XDG_CONFIG_HOME || process.env.HOME && _nodePath.default.join(process.env.HOME, '.config');
136
- debug('XDGConfig folder path %s', xDGConfigPath);
137
- if (xDGConfigPath && (0, _configUtils.folderExists)(xDGConfigPath)) {
138
- debug('XDGConfig folder path %s', xDGConfigPath);
139
- return {
140
- path: _nodePath.default.join(xDGConfigPath, pkgJSON.name, CONFIG_FILE),
141
- type: XDG
142
- };
143
- }
111
+ * Get XDG_CONFIG_HOME or HOME location (usually unix)
112
+ *
113
+ * The XDG_CONFIG_HOME environment variable is also part of the XDG Base Directory Specification,
114
+ * which aims to standardize the locations where applications store configuration files and other
115
+ * user-specific data on Unix-like operating systems.
116
+ *
117
+ *
118
+ *
119
+ * https://specifications.freedesktop.org/basedir-spec/latest/
120
+ *
121
+ *
122
+ * @returns
123
+ */
124
+ var getXDGDirectory = () => {
125
+ const xDGConfigPath = process.env.XDG_CONFIG_HOME || process.env.HOME && node_path.default.join(process.env.HOME, ".config");
126
+ debug$1("XDGConfig folder path %s", xDGConfigPath);
127
+ if (xDGConfigPath && require_config_utils.folderExists(xDGConfigPath)) {
128
+ debug$1("XDGConfig folder path %s", xDGConfigPath);
129
+ return {
130
+ path: node_path.default.join(xDGConfigPath, pkgJSON.name, CONFIG_FILE),
131
+ type: XDG
132
+ };
133
+ }
144
134
  };
145
-
146
135
  /**
147
- * Detect windows location, APPDATA
148
- * usually something like C:\User\<Build User>\AppData\Local
149
- * @returns
150
- */
151
- const getWindowsDirectory = () => {
152
- if (_nodeOs.default.platform() === 'win32' && process.env.APPDATA && (0, _configUtils.folderExists)(process.env.APPDATA)) {
153
- debug('windows appdata folder path %s', process.env.APPDATA);
154
- return {
155
- path: _nodePath.default.resolve(_nodePath.default.join(process.env.APPDATA, pkgJSON.name, CONFIG_FILE)),
156
- type: 'win'
157
- };
158
- }
136
+ * Detect windows location, APPDATA
137
+ * usually something like C:\User\<Build User>\AppData\Local
138
+ * @returns
139
+ */
140
+ var getWindowsDirectory = () => {
141
+ if (node_os.default.platform() === "win32" && process.env.APPDATA && require_config_utils.folderExists(process.env.APPDATA)) {
142
+ debug$1("windows appdata folder path %s", process.env.APPDATA);
143
+ return {
144
+ path: node_path.default.resolve(node_path.default.join(process.env.APPDATA, pkgJSON.name, CONFIG_FILE)),
145
+ type: "win"
146
+ };
147
+ }
159
148
  };
160
-
161
149
  /**
162
- * Return relative directory, this is the default.
163
- * It will cretate config in your {currentLocation/verdaccio/config.yaml}
164
- * @returns
165
- */
166
- const getRelativeDefaultDirectory = () => {
167
- const relativePath = _nodePath.default.resolve(_nodePath.default.join('.', pkgJSON.name, CONFIG_FILE));
168
- debug('relative folder path %s', relativePath);
169
- return {
170
- path: relativePath,
171
- type: 'def'
172
- };
150
+ * Return relative directory, this is the default.
151
+ * It will cretate config in your {currentLocation/verdaccio/config.yaml}
152
+ * @returns
153
+ */
154
+ var getRelativeDefaultDirectory = () => {
155
+ const relativePath = node_path.default.resolve(node_path.default.join(".", pkgJSON.name, CONFIG_FILE));
156
+ debug$1("relative folder path %s", relativePath);
157
+ return {
158
+ path: relativePath,
159
+ type: "def"
160
+ };
173
161
  };
174
-
175
162
  /**
176
- * This should never happens, consider it DEPRECATED
177
- * @returns
178
- */
179
- const getOldDirectory = () => {
180
- const oldPath = _nodePath.default.resolve(_nodePath.default.join('.', CONFIG_FILE));
181
- debug('old folder path %s', oldPath);
182
- return {
183
- path: oldPath,
184
- type: 'old'
185
- };
163
+ * This should never happens, consider it DEPRECATED
164
+ * @returns
165
+ */
166
+ var getOldDirectory = () => {
167
+ const oldPath = node_path.default.resolve(node_path.default.join(".", CONFIG_FILE));
168
+ debug$1("old folder path %s", oldPath);
169
+ return {
170
+ path: oldPath,
171
+ type: "old"
172
+ };
186
173
  };
174
+ //#endregion
175
+ exports.findConfigFile = findConfigFile;
176
+ exports.readDefaultConfig = readDefaultConfig;
177
+
187
178
  //# sourceMappingURL=config-path.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config-path.js","names":["_debug","_interopRequireDefault","require","_lodash","_nodeFs","_nodeOs","_nodePath","_configUtils","e","__esModule","default","CONFIG_FILE","XDG","pkgJSON","name","debug","buildDebug","findConfigFile","configPath","configLocation","path","resolve","configPaths","getConfigPaths","length","Error","primaryConf","_","find","fileExists","createConfigFile","createConfigFolder","defaultConfig","updateStorageLinks","readDefaultConfig","fs","writeFileSync","pathDefaultConf","__dirname","accessSync","constants","R_OK","TypeError","readFileSync","folder","dirname","mkdirSync","recursive","type","dataDir","process","env","XDG_DATA_HOME","join","HOME","folderExists","replace","listPaths","getXDGDirectory","getWindowsDirectory","getRelativeDefaultDirectory","getOldDirectory","reduce","acc","currentValue","push","xDGConfigPath","XDG_CONFIG_HOME","os","platform","APPDATA","relativePath","oldPath"],"sources":["../src/config-path.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nimport { fileExists, folderExists } from './config-utils';\n\nconst CONFIG_FILE = 'config.yaml';\nconst XDG = 'xdg';\n\nconst pkgJSON = {\n name: 'verdaccio',\n};\n\nexport type SetupDirectory = {\n path: string;\n type: 'xdg' | 'win' | 'win32' | 'def' | 'old';\n};\n\nconst debug = buildDebug('verdaccio:config:config-path');\n\n/**\n * Find and get the first config file that match.\n * @return {String} the config file path\n */\nfunction findConfigFile(configPath?: string): string {\n debug('searching for config file %o', configPath);\n if (typeof configPath !== 'undefined') {\n const configLocation = path.resolve(configPath);\n debug('custom location %s', configLocation);\n return configLocation;\n }\n\n const configPaths: SetupDirectory[] = getConfigPaths();\n debug('%o posible locations found', configPaths.length);\n if (configPaths.length === 0) {\n debug('no configuration files can be processed');\n // this should never happens\n throw new Error('no configuration files can be processed');\n }\n\n // find the first location that already exist\n const primaryConf: SetupDirectory | void = _.find(configPaths, (configLocation: SetupDirectory) =>\n fileExists(configLocation.path)\n );\n\n if (typeof primaryConf !== 'undefined') {\n debug('at least one primary location detected at %s', primaryConf?.path);\n return primaryConf.path;\n }\n debug('no previous location found, creating a new one');\n debug('generating the first match path location %s', configPaths[0].path);\n return createConfigFile(configPaths[0]).path;\n}\n\nfunction createConfigFile(configLocation: SetupDirectory): SetupDirectory {\n createConfigFolder(configLocation);\n\n const defaultConfig = updateStorageLinks(configLocation, readDefaultConfig());\n\n fs.writeFileSync(configLocation.path, defaultConfig);\n\n return configLocation;\n}\n\nexport function readDefaultConfig(): string {\n const pathDefaultConf: string = path.resolve(__dirname, 'conf/default.yaml');\n try {\n debug('the path of default config used from %s', pathDefaultConf);\n fs.accessSync(pathDefaultConf, fs.constants.R_OK);\n debug('configuration file has enough permissions for reading');\n } catch {\n debug('configuration file does not have enough permissions for reading');\n throw new TypeError('configuration file does not have enough permissions for reading');\n }\n\n return fs.readFileSync(pathDefaultConf, 'utf8');\n}\n\nfunction createConfigFolder(configLocation: SetupDirectory): void {\n const folder = path.dirname(configLocation.path);\n debug(`creating default config file folder at %o`, folder);\n fs.mkdirSync(folder, { recursive: true });\n debug(`folder %o created`, folder);\n}\n\n/**\n * Update the storage links to the new location if it is necessary.\n * @param configLocation\n * @param defaultConfig\n * @returns\n */\nfunction updateStorageLinks(configLocation: SetupDirectory, defaultConfig: string): string {\n debug('checking storage links for %s and type %s', configLocation.path, configLocation.type);\n if (configLocation.type !== XDG) {\n debug(`skip storage override for %s`, configLocation.type);\n return defaultConfig;\n }\n\n // $XDG_DATA_HOME defines the base directory relative to which user specific data\n // files should be stored, If $XDG_DATA_HOME is either not set or empty, a default\n // equal to $HOME/.local/share should be used.\n let dataDir =\n process.env.XDG_DATA_HOME || path.join(process.env.HOME as string, '.local', 'share');\n if (folderExists(dataDir)) {\n debug(`previous storage located`);\n debug(`update storage links to %s`, dataDir);\n dataDir = path.resolve(path.join(dataDir, pkgJSON.name, 'storage'));\n return defaultConfig.replace(/^storage: .\\/storage$/m, `storage: ${dataDir}`);\n }\n debug(`could not find a previous storage location, skip override`);\n return defaultConfig;\n}\n\n/**\n * Return a list of configuration locations by platform.\n * @returns\n */\nfunction getConfigPaths(): SetupDirectory[] {\n const listPaths: (SetupDirectory | void)[] = [\n getXDGDirectory(),\n getWindowsDirectory(),\n getRelativeDefaultDirectory(),\n getOldDirectory(),\n ];\n\n return listPaths.reduce(function (acc, currentValue: SetupDirectory | void): SetupDirectory[] {\n if (typeof currentValue !== 'undefined') {\n debug(\n 'posible directory path generated %s for type %s',\n currentValue?.path,\n currentValue.type\n );\n acc.push(currentValue);\n }\n return acc;\n }, [] as SetupDirectory[]);\n}\n\n/**\n * Get XDG_CONFIG_HOME or HOME location (usually unix)\n *\n * The XDG_CONFIG_HOME environment variable is also part of the XDG Base Directory Specification,\n * which aims to standardize the locations where applications store configuration files and other\n * user-specific data on Unix-like operating systems.\n *\n *\n *\n * https://specifications.freedesktop.org/basedir-spec/latest/\n *\n *\n * @returns\n */\nconst getXDGDirectory = (): SetupDirectory | void => {\n const xDGConfigPath =\n process.env.XDG_CONFIG_HOME || (process.env.HOME && path.join(process.env.HOME, '.config'));\n debug('XDGConfig folder path %s', xDGConfigPath);\n if (xDGConfigPath && folderExists(xDGConfigPath)) {\n debug('XDGConfig folder path %s', xDGConfigPath);\n return {\n path: path.join(xDGConfigPath, pkgJSON.name, CONFIG_FILE),\n type: XDG,\n };\n }\n};\n\n/**\n * Detect windows location, APPDATA\n * usually something like C:\\User\\<Build User>\\AppData\\Local\n * @returns\n */\nconst getWindowsDirectory = (): SetupDirectory | void => {\n if (os.platform() === 'win32' && process.env.APPDATA && folderExists(process.env.APPDATA)) {\n debug('windows appdata folder path %s', process.env.APPDATA);\n return {\n path: path.resolve(path.join(process.env.APPDATA, pkgJSON.name, CONFIG_FILE)),\n type: 'win',\n };\n }\n};\n\n/**\n * Return relative directory, this is the default.\n * It will cretate config in your {currentLocation/verdaccio/config.yaml}\n * @returns\n */\nconst getRelativeDefaultDirectory = (): SetupDirectory => {\n const relativePath = path.resolve(path.join('.', pkgJSON.name, CONFIG_FILE));\n debug('relative folder path %s', relativePath);\n return {\n path: relativePath,\n type: 'def',\n };\n};\n\n/**\n * This should never happens, consider it DEPRECATED\n * @returns\n */\nconst getOldDirectory = (): SetupDirectory => {\n const oldPath = path.resolve(path.join('.', CONFIG_FILE));\n debug('old folder path %s', oldPath);\n return {\n path: oldPath,\n type: 'old',\n };\n};\n\nexport { findConfigFile };\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,OAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,SAAA,GAAAL,sBAAA,CAAAC,OAAA;AAEA,IAAAK,YAAA,GAAAL,OAAA;AAA0D,SAAAD,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,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C,GAAG,EAAExC,OAAO,CAACC,IAAI,EAAEH,WAAW,CAAC,CAAC;EAC5EI,KAAK,CAAC,yBAAyB,EAAEwD,YAAY,CAAC;EAC9C,OAAO;IACLnD,IAAI,EAAEmD,YAAY;IAClBvB,IAAI,EAAE;EACR,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMa,eAAe,GAAGA,CAAA,KAAsB;EAC5C,MAAMW,OAAO,GAAGpD,iBAAI,CAACC,OAAO,CAACD,iBAAI,CAACiC,IAAI,CAAC,GAAG,EAAE1C,WAAW,CAAC,CAAC;EACzDI,KAAK,CAAC,oBAAoB,EAAEyD,OAAO,CAAC;EACpC,OAAO;IACLpD,IAAI,EAAEoD,OAAO;IACbxB,IAAI,EAAE;EACR,CAAC;AACH,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"config-path.js","names":[],"sources":["../src/config-path.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport { fileExists, folderExists } from './config-utils';\n\nconst CONFIG_FILE = 'config.yaml';\nconst XDG = 'xdg';\n\nconst pkgJSON = {\n name: 'verdaccio',\n};\n\nexport type SetupDirectory = {\n path: string;\n type: 'xdg' | 'win' | 'win32' | 'def' | 'old';\n};\n\nconst debug = buildDebug('verdaccio:config:config-path');\n\n/**\n * Find and get the first config file that match.\n * @return {String} the config file path\n */\nfunction findConfigFile(configPath?: string): string {\n debug('searching for config file %o', configPath);\n if (typeof configPath !== 'undefined') {\n const configLocation = path.resolve(configPath);\n debug('custom location %s', configLocation);\n return configLocation;\n }\n\n const configPaths: SetupDirectory[] = getConfigPaths();\n debug('%o posible locations found', configPaths.length);\n if (configPaths.length === 0) {\n debug('no configuration files can be processed');\n // this should never happens\n throw new Error('no configuration files can be processed');\n }\n\n // find the first location that already exist\n const primaryConf: SetupDirectory | void = _.find(configPaths, (configLocation: SetupDirectory) =>\n fileExists(configLocation.path)\n );\n\n if (typeof primaryConf !== 'undefined') {\n debug('at least one primary location detected at %s', primaryConf?.path);\n return primaryConf.path;\n }\n debug('no previous location found, creating a new one');\n debug('generating the first match path location %s', configPaths[0].path);\n return createConfigFile(configPaths[0]).path;\n}\n\nfunction createConfigFile(configLocation: SetupDirectory): SetupDirectory {\n createConfigFolder(configLocation);\n\n const defaultConfig = updateStorageLinks(configLocation, readDefaultConfig());\n\n fs.writeFileSync(configLocation.path, defaultConfig);\n\n return configLocation;\n}\n\nexport function readDefaultConfig(): string {\n // import.meta.url is only defined in the ESM build; the CJS build falls back to __dirname\n const currentDir = import.meta.url ? path.dirname(fileURLToPath(import.meta.url)) : __dirname;\n const pathDefaultConf: string = path.resolve(currentDir, 'conf/default.yaml');\n try {\n debug('the path of default config used from %s', pathDefaultConf);\n fs.accessSync(pathDefaultConf, fs.constants.R_OK);\n debug('configuration file has enough permissions for reading');\n } catch {\n debug('configuration file does not have enough permissions for reading');\n throw new TypeError('configuration file does not have enough permissions for reading');\n }\n\n return fs.readFileSync(pathDefaultConf, 'utf8');\n}\n\nfunction createConfigFolder(configLocation: SetupDirectory): void {\n const folder = path.dirname(configLocation.path);\n debug(`creating default config file folder at %o`, folder);\n fs.mkdirSync(folder, { recursive: true });\n debug(`folder %o created`, folder);\n}\n\n/**\n * Update the storage links to the new location if it is necessary.\n * @param configLocation\n * @param defaultConfig\n * @returns\n */\nfunction updateStorageLinks(configLocation: SetupDirectory, defaultConfig: string): string {\n debug('checking storage links for %s and type %s', configLocation.path, configLocation.type);\n if (configLocation.type !== XDG) {\n debug(`skip storage override for %s`, configLocation.type);\n return defaultConfig;\n }\n\n // $XDG_DATA_HOME defines the base directory relative to which user specific data\n // files should be stored, If $XDG_DATA_HOME is either not set or empty, a default\n // equal to $HOME/.local/share should be used.\n let dataDir =\n process.env.XDG_DATA_HOME || path.join(process.env.HOME as string, '.local', 'share');\n if (folderExists(dataDir)) {\n debug(`previous storage located`);\n debug(`update storage links to %s`, dataDir);\n dataDir = path.resolve(path.join(dataDir, pkgJSON.name, 'storage'));\n return defaultConfig.replace(/^storage: .\\/storage$/m, `storage: ${dataDir}`);\n }\n debug(`could not find a previous storage location, skip override`);\n return defaultConfig;\n}\n\n/**\n * Return a list of configuration locations by platform.\n * @returns\n */\nfunction getConfigPaths(): SetupDirectory[] {\n const listPaths: (SetupDirectory | void)[] = [\n getXDGDirectory(),\n getWindowsDirectory(),\n getRelativeDefaultDirectory(),\n getOldDirectory(),\n ];\n\n return listPaths.reduce(function (acc, currentValue: SetupDirectory | void): SetupDirectory[] {\n if (typeof currentValue !== 'undefined') {\n debug(\n 'posible directory path generated %s for type %s',\n currentValue?.path,\n currentValue.type\n );\n acc.push(currentValue);\n }\n return acc;\n }, [] as SetupDirectory[]);\n}\n\n/**\n * Get XDG_CONFIG_HOME or HOME location (usually unix)\n *\n * The XDG_CONFIG_HOME environment variable is also part of the XDG Base Directory Specification,\n * which aims to standardize the locations where applications store configuration files and other\n * user-specific data on Unix-like operating systems.\n *\n *\n *\n * https://specifications.freedesktop.org/basedir-spec/latest/\n *\n *\n * @returns\n */\nconst getXDGDirectory = (): SetupDirectory | void => {\n const xDGConfigPath =\n process.env.XDG_CONFIG_HOME || (process.env.HOME && path.join(process.env.HOME, '.config'));\n debug('XDGConfig folder path %s', xDGConfigPath);\n if (xDGConfigPath && folderExists(xDGConfigPath)) {\n debug('XDGConfig folder path %s', xDGConfigPath);\n return {\n path: path.join(xDGConfigPath, pkgJSON.name, CONFIG_FILE),\n type: XDG,\n };\n }\n};\n\n/**\n * Detect windows location, APPDATA\n * usually something like C:\\User\\<Build User>\\AppData\\Local\n * @returns\n */\nconst getWindowsDirectory = (): SetupDirectory | void => {\n if (os.platform() === 'win32' && process.env.APPDATA && folderExists(process.env.APPDATA)) {\n debug('windows appdata folder path %s', process.env.APPDATA);\n return {\n path: path.resolve(path.join(process.env.APPDATA, pkgJSON.name, CONFIG_FILE)),\n type: 'win',\n };\n }\n};\n\n/**\n * Return relative directory, this is the default.\n * It will cretate config in your {currentLocation/verdaccio/config.yaml}\n * @returns\n */\nconst getRelativeDefaultDirectory = (): SetupDirectory => {\n const relativePath = path.resolve(path.join('.', pkgJSON.name, CONFIG_FILE));\n debug('relative folder path %s', relativePath);\n return {\n path: relativePath,\n type: 'def',\n };\n};\n\n/**\n * This should never happens, consider it DEPRECATED\n * @returns\n */\nconst getOldDirectory = (): SetupDirectory => {\n const oldPath = path.resolve(path.join('.', CONFIG_FILE));\n debug('old folder path %s', oldPath);\n return {\n path: oldPath,\n type: 'old',\n };\n};\n\nexport { findConfigFile };\n"],"mappings":";;;;;;;;;;;;;;AASA,IAAM,cAAc;AACpB,IAAM,MAAM;AAEZ,IAAM,UAAU,EACd,MAAM,YACR;AAOA,IAAM,WAAA,GAAA,MAAA,SAAmB,8BAA8B;;;;;AAMvD,SAAS,eAAe,YAA6B;CACnD,QAAM,gCAAgC,UAAU;CAChD,IAAI,OAAO,eAAe,aAAa;EACrC,MAAM,iBAAiB,UAAA,QAAK,QAAQ,UAAU;EAC9C,QAAM,sBAAsB,cAAc;EAC1C,OAAO;CACT;CAEA,MAAM,cAAgC,eAAe;CACrD,QAAM,8BAA8B,YAAY,MAAM;CACtD,IAAI,YAAY,WAAW,GAAG;EAC5B,QAAM,yCAAyC;EAE/C,MAAM,IAAI,MAAM,yCAAyC;CAC3D;CAGA,MAAM,cAAqC,OAAA,QAAE,KAAK,cAAc,mBAC9D,qBAAA,WAAW,eAAe,IAAI,CAChC;CAEA,IAAI,OAAO,gBAAgB,aAAa;EACtC,QAAM,gDAAgD,aAAa,IAAI;EACvE,OAAO,YAAY;CACrB;CACA,QAAM,gDAAgD;CACtD,QAAM,gDAAgD,YAAY,GAAG,IAAI;CACzE,OAAO,iBAAiB,YAAY,EAAE,EAAE;AAC1C;AAEA,SAAS,iBAAiB,gBAAgD;CACxE,mBAAmB,cAAc;CAEjC,MAAM,gBAAgB,mBAAmB,gBAAgB,kBAAkB,CAAC;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 -0,0 +1,171 @@
1
+ import { fileExists, folderExists } from "./config-utils.mjs";
2
+ import buildDebug from "debug";
3
+ import _ from "lodash";
4
+ import fs from "node:fs";
5
+ import os from "node:os";
6
+ import path from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+ //#region src/config-path.ts
9
+ var CONFIG_FILE = "config.yaml";
10
+ var XDG = "xdg";
11
+ var pkgJSON = { name: "verdaccio" };
12
+ var debug = buildDebug("verdaccio:config:config-path");
13
+ /**
14
+ * Find and get the first config file that match.
15
+ * @return {String} the config file path
16
+ */
17
+ function findConfigFile(configPath) {
18
+ debug("searching for config file %o", configPath);
19
+ if (typeof configPath !== "undefined") {
20
+ const configLocation = path.resolve(configPath);
21
+ debug("custom location %s", configLocation);
22
+ return configLocation;
23
+ }
24
+ const configPaths = getConfigPaths();
25
+ debug("%o posible locations found", configPaths.length);
26
+ if (configPaths.length === 0) {
27
+ debug("no configuration files can be processed");
28
+ throw new Error("no configuration files can be processed");
29
+ }
30
+ const primaryConf = _.find(configPaths, (configLocation) => fileExists(configLocation.path));
31
+ if (typeof primaryConf !== "undefined") {
32
+ debug("at least one primary location detected at %s", primaryConf?.path);
33
+ return primaryConf.path;
34
+ }
35
+ debug("no previous location found, creating a new one");
36
+ debug("generating the first match path location %s", configPaths[0].path);
37
+ return createConfigFile(configPaths[0]).path;
38
+ }
39
+ function createConfigFile(configLocation) {
40
+ createConfigFolder(configLocation);
41
+ const defaultConfig = updateStorageLinks(configLocation, readDefaultConfig());
42
+ fs.writeFileSync(configLocation.path, defaultConfig);
43
+ return configLocation;
44
+ }
45
+ function readDefaultConfig() {
46
+ const currentDir = import.meta.url ? path.dirname(fileURLToPath(import.meta.url)) : __dirname;
47
+ const pathDefaultConf = path.resolve(currentDir, "conf/default.yaml");
48
+ try {
49
+ debug("the path of default config used from %s", pathDefaultConf);
50
+ fs.accessSync(pathDefaultConf, fs.constants.R_OK);
51
+ debug("configuration file has enough permissions for reading");
52
+ } catch {
53
+ debug("configuration file does not have enough permissions for reading");
54
+ throw new TypeError("configuration file does not have enough permissions for reading");
55
+ }
56
+ return fs.readFileSync(pathDefaultConf, "utf8");
57
+ }
58
+ function createConfigFolder(configLocation) {
59
+ const folder = path.dirname(configLocation.path);
60
+ debug(`creating default config file folder at %o`, folder);
61
+ fs.mkdirSync(folder, { recursive: true });
62
+ debug(`folder %o created`, folder);
63
+ }
64
+ /**
65
+ * Update the storage links to the new location if it is necessary.
66
+ * @param configLocation
67
+ * @param defaultConfig
68
+ * @returns
69
+ */
70
+ function updateStorageLinks(configLocation, defaultConfig) {
71
+ debug("checking storage links for %s and type %s", configLocation.path, configLocation.type);
72
+ if (configLocation.type !== XDG) {
73
+ debug(`skip storage override for %s`, configLocation.type);
74
+ return defaultConfig;
75
+ }
76
+ let dataDir = process.env.XDG_DATA_HOME || path.join(process.env.HOME, ".local", "share");
77
+ if (folderExists(dataDir)) {
78
+ debug(`previous storage located`);
79
+ debug(`update storage links to %s`, dataDir);
80
+ dataDir = path.resolve(path.join(dataDir, pkgJSON.name, "storage"));
81
+ return defaultConfig.replace(/^storage: .\/storage$/m, `storage: ${dataDir}`);
82
+ }
83
+ debug(`could not find a previous storage location, skip override`);
84
+ return defaultConfig;
85
+ }
86
+ /**
87
+ * Return a list of configuration locations by platform.
88
+ * @returns
89
+ */
90
+ function getConfigPaths() {
91
+ return [
92
+ getXDGDirectory(),
93
+ getWindowsDirectory(),
94
+ getRelativeDefaultDirectory(),
95
+ getOldDirectory()
96
+ ].reduce(function(acc, currentValue) {
97
+ if (typeof currentValue !== "undefined") {
98
+ debug("posible directory path generated %s for type %s", currentValue?.path, currentValue.type);
99
+ acc.push(currentValue);
100
+ }
101
+ return acc;
102
+ }, []);
103
+ }
104
+ /**
105
+ * Get XDG_CONFIG_HOME or HOME location (usually unix)
106
+ *
107
+ * The XDG_CONFIG_HOME environment variable is also part of the XDG Base Directory Specification,
108
+ * which aims to standardize the locations where applications store configuration files and other
109
+ * user-specific data on Unix-like operating systems.
110
+ *
111
+ *
112
+ *
113
+ * https://specifications.freedesktop.org/basedir-spec/latest/
114
+ *
115
+ *
116
+ * @returns
117
+ */
118
+ var getXDGDirectory = () => {
119
+ const xDGConfigPath = process.env.XDG_CONFIG_HOME || process.env.HOME && path.join(process.env.HOME, ".config");
120
+ debug("XDGConfig folder path %s", xDGConfigPath);
121
+ if (xDGConfigPath && folderExists(xDGConfigPath)) {
122
+ debug("XDGConfig folder path %s", xDGConfigPath);
123
+ return {
124
+ path: path.join(xDGConfigPath, pkgJSON.name, CONFIG_FILE),
125
+ type: XDG
126
+ };
127
+ }
128
+ };
129
+ /**
130
+ * Detect windows location, APPDATA
131
+ * usually something like C:\User\<Build User>\AppData\Local
132
+ * @returns
133
+ */
134
+ var getWindowsDirectory = () => {
135
+ if (os.platform() === "win32" && process.env.APPDATA && folderExists(process.env.APPDATA)) {
136
+ debug("windows appdata folder path %s", process.env.APPDATA);
137
+ return {
138
+ path: path.resolve(path.join(process.env.APPDATA, pkgJSON.name, CONFIG_FILE)),
139
+ type: "win"
140
+ };
141
+ }
142
+ };
143
+ /**
144
+ * Return relative directory, this is the default.
145
+ * It will cretate config in your {currentLocation/verdaccio/config.yaml}
146
+ * @returns
147
+ */
148
+ var getRelativeDefaultDirectory = () => {
149
+ const relativePath = path.resolve(path.join(".", pkgJSON.name, CONFIG_FILE));
150
+ debug("relative folder path %s", relativePath);
151
+ return {
152
+ path: relativePath,
153
+ type: "def"
154
+ };
155
+ };
156
+ /**
157
+ * This should never happens, consider it DEPRECATED
158
+ * @returns
159
+ */
160
+ var getOldDirectory = () => {
161
+ const oldPath = path.resolve(path.join(".", CONFIG_FILE));
162
+ debug("old folder path %s", oldPath);
163
+ return {
164
+ path: oldPath,
165
+ type: "old"
166
+ };
167
+ };
168
+ //#endregion
169
+ export { findConfigFile, readDefaultConfig };
170
+
171
+ //# sourceMappingURL=config-path.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-path.mjs","names":[],"sources":["../src/config-path.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport _ from 'lodash';\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport { fileExists, folderExists } from './config-utils';\n\nconst CONFIG_FILE = 'config.yaml';\nconst XDG = 'xdg';\n\nconst pkgJSON = {\n name: 'verdaccio',\n};\n\nexport type SetupDirectory = {\n path: string;\n type: 'xdg' | 'win' | 'win32' | 'def' | 'old';\n};\n\nconst debug = buildDebug('verdaccio:config:config-path');\n\n/**\n * Find and get the first config file that match.\n * @return {String} the config file path\n */\nfunction findConfigFile(configPath?: string): string {\n debug('searching for config file %o', configPath);\n if (typeof configPath !== 'undefined') {\n const configLocation = path.resolve(configPath);\n debug('custom location %s', configLocation);\n return configLocation;\n }\n\n const configPaths: SetupDirectory[] = getConfigPaths();\n debug('%o posible locations found', configPaths.length);\n if (configPaths.length === 0) {\n debug('no configuration files can be processed');\n // this should never happens\n throw new Error('no configuration files can be processed');\n }\n\n // find the first location that already exist\n const primaryConf: SetupDirectory | void = _.find(configPaths, (configLocation: SetupDirectory) =>\n fileExists(configLocation.path)\n );\n\n if (typeof primaryConf !== 'undefined') {\n debug('at least one primary location detected at %s', primaryConf?.path);\n return primaryConf.path;\n }\n debug('no previous location found, creating a new one');\n debug('generating the first match path location %s', configPaths[0].path);\n return createConfigFile(configPaths[0]).path;\n}\n\nfunction createConfigFile(configLocation: SetupDirectory): SetupDirectory {\n createConfigFolder(configLocation);\n\n const defaultConfig = updateStorageLinks(configLocation, readDefaultConfig());\n\n fs.writeFileSync(configLocation.path, defaultConfig);\n\n return configLocation;\n}\n\nexport function readDefaultConfig(): string {\n // import.meta.url is only defined in the ESM build; the CJS build falls back to __dirname\n const currentDir = import.meta.url ? path.dirname(fileURLToPath(import.meta.url)) : __dirname;\n const pathDefaultConf: string = path.resolve(currentDir, 'conf/default.yaml');\n try {\n debug('the path of default config used from %s', pathDefaultConf);\n fs.accessSync(pathDefaultConf, fs.constants.R_OK);\n debug('configuration file has enough permissions for reading');\n } catch {\n debug('configuration file does not have enough permissions for reading');\n throw new TypeError('configuration file does not have enough permissions for reading');\n }\n\n return fs.readFileSync(pathDefaultConf, 'utf8');\n}\n\nfunction createConfigFolder(configLocation: SetupDirectory): void {\n const folder = path.dirname(configLocation.path);\n debug(`creating default config file folder at %o`, folder);\n fs.mkdirSync(folder, { recursive: true });\n debug(`folder %o created`, folder);\n}\n\n/**\n * Update the storage links to the new location if it is necessary.\n * @param configLocation\n * @param defaultConfig\n * @returns\n */\nfunction updateStorageLinks(configLocation: SetupDirectory, defaultConfig: string): string {\n debug('checking storage links for %s and type %s', configLocation.path, configLocation.type);\n if (configLocation.type !== XDG) {\n debug(`skip storage override for %s`, configLocation.type);\n return defaultConfig;\n }\n\n // $XDG_DATA_HOME defines the base directory relative to which user specific data\n // files should be stored, If $XDG_DATA_HOME is either not set or empty, a default\n // equal to $HOME/.local/share should be used.\n let dataDir =\n process.env.XDG_DATA_HOME || path.join(process.env.HOME as string, '.local', 'share');\n if (folderExists(dataDir)) {\n debug(`previous storage located`);\n debug(`update storage links to %s`, dataDir);\n dataDir = path.resolve(path.join(dataDir, pkgJSON.name, 'storage'));\n return defaultConfig.replace(/^storage: .\\/storage$/m, `storage: ${dataDir}`);\n }\n debug(`could not find a previous storage location, skip override`);\n return defaultConfig;\n}\n\n/**\n * Return a list of configuration locations by platform.\n * @returns\n */\nfunction getConfigPaths(): SetupDirectory[] {\n const listPaths: (SetupDirectory | void)[] = [\n getXDGDirectory(),\n getWindowsDirectory(),\n getRelativeDefaultDirectory(),\n getOldDirectory(),\n ];\n\n return listPaths.reduce(function (acc, currentValue: SetupDirectory | void): SetupDirectory[] {\n if (typeof currentValue !== 'undefined') {\n debug(\n 'posible directory path generated %s for type %s',\n currentValue?.path,\n currentValue.type\n );\n acc.push(currentValue);\n }\n return acc;\n }, [] as SetupDirectory[]);\n}\n\n/**\n * Get XDG_CONFIG_HOME or HOME location (usually unix)\n *\n * The XDG_CONFIG_HOME environment variable is also part of the XDG Base Directory Specification,\n * which aims to standardize the locations where applications store configuration files and other\n * user-specific data on Unix-like operating systems.\n *\n *\n *\n * https://specifications.freedesktop.org/basedir-spec/latest/\n *\n *\n * @returns\n */\nconst getXDGDirectory = (): SetupDirectory | void => {\n const xDGConfigPath =\n process.env.XDG_CONFIG_HOME || (process.env.HOME && path.join(process.env.HOME, '.config'));\n debug('XDGConfig folder path %s', xDGConfigPath);\n if (xDGConfigPath && folderExists(xDGConfigPath)) {\n debug('XDGConfig folder path %s', xDGConfigPath);\n return {\n path: path.join(xDGConfigPath, pkgJSON.name, CONFIG_FILE),\n type: XDG,\n };\n }\n};\n\n/**\n * Detect windows location, APPDATA\n * usually something like C:\\User\\<Build User>\\AppData\\Local\n * @returns\n */\nconst getWindowsDirectory = (): SetupDirectory | void => {\n if (os.platform() === 'win32' && process.env.APPDATA && folderExists(process.env.APPDATA)) {\n debug('windows appdata folder path %s', process.env.APPDATA);\n return {\n path: path.resolve(path.join(process.env.APPDATA, pkgJSON.name, CONFIG_FILE)),\n type: 'win',\n };\n }\n};\n\n/**\n * Return relative directory, this is the default.\n * It will cretate config in your {currentLocation/verdaccio/config.yaml}\n * @returns\n */\nconst getRelativeDefaultDirectory = (): SetupDirectory => {\n const relativePath = path.resolve(path.join('.', pkgJSON.name, CONFIG_FILE));\n debug('relative folder path %s', relativePath);\n return {\n path: relativePath,\n type: 'def',\n };\n};\n\n/**\n * This should never happens, consider it DEPRECATED\n * @returns\n */\nconst getOldDirectory = (): SetupDirectory => {\n const oldPath = path.resolve(path.join('.', CONFIG_FILE));\n debug('old folder path %s', oldPath);\n return {\n path: oldPath,\n type: 'old',\n };\n};\n\nexport { findConfigFile };\n"],"mappings":";;;;;;;;AASA,IAAM,cAAc;AACpB,IAAM,MAAM;AAEZ,IAAM,UAAU,EACd,MAAM,YACR;AAOA,IAAM,QAAQ,WAAW,8BAA8B;;;;;AAMvD,SAAS,eAAe,YAA6B;CACnD,MAAM,gCAA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