@verdaccio/config 7.0.0-next-7.20 → 7.0.0-next-8.21

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @verdaccio/config
2
2
 
3
+ ## 7.0.0-next-8.21
4
+
5
+ ### Patch Changes
6
+
7
+ - 8c10a3e: chore: improve debug code and refactor code
8
+ - a05a7d8: fix(config): test runs on Windows
9
+ - Updated dependencies [7c9f3cf]
10
+ - @verdaccio/core@7.0.0-next-8.21
11
+ - @verdaccio/utils@7.0.0-next-8.21
12
+
3
13
  ## 7.0.0-next-7.20
4
14
 
5
15
  ### Patch Changes
@@ -1,12 +1,11 @@
1
- /// <reference types="node" />
2
1
  export type SetupDirectory = {
3
2
  path: string;
4
- type: string;
3
+ type: 'xdg' | 'win' | 'win32' | 'def' | 'old';
5
4
  };
6
5
  /**
7
6
  * Find and get the first config file that match.
8
7
  * @return {String} the config file path
9
8
  */
10
9
  declare function findConfigFile(configPath?: string): string;
11
- export declare function readDefaultConfig(): Buffer;
10
+ export declare function readDefaultConfig(): string;
12
11
  export { findConfigFile };
@@ -8,31 +8,33 @@ exports.readDefaultConfig = readDefaultConfig;
8
8
  var _debug = _interopRequireDefault(require("debug"));
9
9
  var _fs = _interopRequireDefault(require("fs"));
10
10
  var _lodash = _interopRequireDefault(require("lodash"));
11
+ var _os = _interopRequireDefault(require("os"));
11
12
  var _path = _interopRequireDefault(require("path"));
12
- var _core = require("@verdaccio/core");
13
13
  var _configUtils = require("./config-utils");
14
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
15
  const CONFIG_FILE = 'config.yaml';
16
16
  const XDG = 'xdg';
17
- const WIN = 'win';
18
- const WIN32 = 'win32';
19
17
  // eslint-disable-next-line
20
18
  const pkgJSON = {
21
19
  name: 'verdaccio'
22
20
  };
23
- const debug = (0, _debug.default)('verdaccio:config');
21
+ const debug = (0, _debug.default)('verdaccio:config:config-path');
24
22
 
25
23
  /**
26
24
  * Find and get the first config file that match.
27
25
  * @return {String} the config file path
28
26
  */
29
27
  function findConfigFile(configPath) {
28
+ debug('searching for config file %o', configPath);
30
29
  if (typeof configPath !== 'undefined') {
31
- return _path.default.resolve(configPath);
30
+ const configLocation = _path.default.resolve(configPath);
31
+ debug('custom location %s', configLocation);
32
+ return configLocation;
32
33
  }
33
34
  const configPaths = getConfigPaths();
34
35
  debug('%o posible locations found', configPaths.length);
35
- if (_lodash.default.isEmpty(configPaths)) {
36
+ if (configPaths.length === 0) {
37
+ debug('no configuration files can be processed');
36
38
  // this should never happens
37
39
  throw new Error('no configuration files can be processed');
38
40
  }
@@ -40,12 +42,12 @@ function findConfigFile(configPath) {
40
42
  // find the first location that already exist
41
43
  const primaryConf = _lodash.default.find(configPaths, configLocation => (0, _configUtils.fileExists)(configLocation.path));
42
44
  if (typeof primaryConf !== 'undefined') {
43
- debug('previous location exist already %s', primaryConf === null || primaryConf === void 0 ? void 0 : primaryConf.path);
45
+ debug('at least one primary location detected at %s', primaryConf === null || primaryConf === void 0 ? void 0 : primaryConf.path);
44
46
  return primaryConf.path;
45
47
  }
46
-
47
- // @ts-ignore
48
- return createConfigFile(_lodash.default.head(configPaths)).path;
48
+ debug('no previous location found, creating a new one');
49
+ debug('generating the first match path location %s', configPaths[0].path);
50
+ return createConfigFile(configPaths[0]).path;
49
51
  }
50
52
  function createConfigFile(configLocation) {
51
53
  createConfigFolder(configLocation);
@@ -56,22 +58,34 @@ function createConfigFile(configLocation) {
56
58
  function readDefaultConfig() {
57
59
  const pathDefaultConf = _path.default.resolve(__dirname, 'conf/default.yaml');
58
60
  try {
59
- debug('default configuration file %s', pathDefaultConf);
61
+ debug('the path of default config used from %s', pathDefaultConf);
60
62
  _fs.default.accessSync(pathDefaultConf, _fs.default.constants.R_OK);
63
+ debug('configuration file has enough permissions for reading');
61
64
  } catch {
65
+ debug('configuration file does not have enough permissions for reading');
62
66
  throw new TypeError('configuration file does not have enough permissions for reading');
63
67
  }
64
- // @ts-ignore
65
- return _fs.default.readFileSync(pathDefaultConf, _core.CHARACTER_ENCODING.UTF8);
68
+ return _fs.default.readFileSync(pathDefaultConf, 'utf8');
66
69
  }
67
70
  function createConfigFolder(configLocation) {
68
- _fs.default.mkdirSync(_path.default.dirname(configLocation.path), {
71
+ const folder = _path.default.dirname(configLocation.path);
72
+ debug(`creating default config file folder at %o`, folder);
73
+ _fs.default.mkdirSync(folder, {
69
74
  recursive: true
70
75
  });
71
- debug(`Creating default config file in %o`, configLocation === null || configLocation === void 0 ? void 0 : configLocation.path);
76
+ debug(`folder %o created`, folder);
72
77
  }
78
+
79
+ /**
80
+ * Update the storage links to the new location if it is necessary.
81
+ * @param configLocation
82
+ * @param defaultConfig
83
+ * @returns
84
+ */
73
85
  function updateStorageLinks(configLocation, defaultConfig) {
86
+ debug('checking storage links for %s and type %s', configLocation.path, configLocation.type);
74
87
  if (configLocation.type !== XDG) {
88
+ debug(`skip storage override for %s`, configLocation.type);
75
89
  return defaultConfig;
76
90
  }
77
91
 
@@ -97,7 +111,7 @@ function getConfigPaths() {
97
111
  const listPaths = [getXDGDirectory(), getWindowsDirectory(), getRelativeDefaultDirectory(), getOldDirectory()];
98
112
  return listPaths.reduce(function (acc, currentValue) {
99
113
  if (typeof currentValue !== 'undefined') {
100
- debug('directory detected path %s for type %s', currentValue === null || currentValue === void 0 ? void 0 : currentValue.path, currentValue.type);
114
+ debug('posible directory path generated %s for type %s', currentValue === null || currentValue === void 0 ? void 0 : currentValue.path, currentValue.type);
101
115
  acc.push(currentValue);
102
116
  }
103
117
  return acc;
@@ -106,10 +120,21 @@ function getConfigPaths() {
106
120
 
107
121
  /**
108
122
  * Get XDG_CONFIG_HOME or HOME location (usually unix)
123
+ *
124
+ * The XDG_CONFIG_HOME environment variable is also part of the XDG Base Directory Specification,
125
+ * which aims to standardize the locations where applications store configuration files and other
126
+ * user-specific data on Unix-like operating systems.
127
+ *
128
+ *
129
+ *
130
+ * https://specifications.freedesktop.org/basedir-spec/latest/
131
+ *
132
+ *
109
133
  * @returns
110
134
  */
111
135
  const getXDGDirectory = () => {
112
136
  const xDGConfigPath = process.env.XDG_CONFIG_HOME || process.env.HOME && _path.default.join(process.env.HOME, '.config');
137
+ debug('XDGConfig folder path %s', xDGConfigPath);
113
138
  if (xDGConfigPath && (0, _configUtils.folderExists)(xDGConfigPath)) {
114
139
  debug('XDGConfig folder path %s', xDGConfigPath);
115
140
  return {
@@ -125,11 +150,11 @@ const getXDGDirectory = () => {
125
150
  * @returns
126
151
  */
127
152
  const getWindowsDirectory = () => {
128
- if (process.platform === WIN32 && process.env.APPDATA && (0, _configUtils.folderExists)(process.env.APPDATA)) {
129
- debug('is windows appdata: %s', process.env.APPDATA);
153
+ if (_os.default.platform() === 'win32' && process.env.APPDATA && (0, _configUtils.folderExists)(process.env.APPDATA)) {
154
+ debug('windows appdata folder path %s', process.env.APPDATA);
130
155
  return {
131
156
  path: _path.default.resolve(_path.default.join(process.env.APPDATA, pkgJSON.name, CONFIG_FILE)),
132
- type: WIN
157
+ type: 'win'
133
158
  };
134
159
  }
135
160
  };
@@ -140,8 +165,10 @@ const getWindowsDirectory = () => {
140
165
  * @returns
141
166
  */
142
167
  const getRelativeDefaultDirectory = () => {
168
+ const relativePath = _path.default.resolve(_path.default.join('.', pkgJSON.name, CONFIG_FILE));
169
+ debug('relative folder path %s', relativePath);
143
170
  return {
144
- path: _path.default.resolve(_path.default.join('.', pkgJSON.name, CONFIG_FILE)),
171
+ path: relativePath,
145
172
  type: 'def'
146
173
  };
147
174
  };
@@ -151,8 +178,10 @@ const getRelativeDefaultDirectory = () => {
151
178
  * @returns
152
179
  */
153
180
  const getOldDirectory = () => {
181
+ const oldPath = _path.default.resolve(_path.default.join('.', CONFIG_FILE));
182
+ debug('old folder path %s', oldPath);
154
183
  return {
155
- path: _path.default.resolve(_path.default.join('.', CONFIG_FILE)),
184
+ path: oldPath,
156
185
  type: 'old'
157
186
  };
158
187
  };
@@ -1 +1 @@
1
- {"version":3,"file":"config-path.js","names":["_debug","_interopRequireDefault","require","_fs","_lodash","_path","_core","_configUtils","e","__esModule","default","CONFIG_FILE","XDG","WIN","WIN32","pkgJSON","name","debug","buildDebug","findConfigFile","configPath","path","resolve","configPaths","getConfigPaths","length","_","isEmpty","Error","primaryConf","find","configLocation","fileExists","createConfigFile","head","createConfigFolder","defaultConfig","updateStorageLinks","readDefaultConfig","fs","writeFileSync","pathDefaultConf","__dirname","accessSync","constants","R_OK","TypeError","readFileSync","CHARACTER_ENCODING","UTF8","mkdirSync","dirname","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","platform","APPDATA"],"sources":["../src/config-path.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport fs from 'fs';\nimport _ from 'lodash';\nimport path from 'path';\n\nimport { CHARACTER_ENCODING } from '@verdaccio/core';\n\nimport { fileExists, folderExists } from './config-utils';\n\nconst CONFIG_FILE = 'config.yaml';\nconst XDG = 'xdg';\nconst WIN = 'win';\nconst WIN32 = 'win32';\n// eslint-disable-next-line\nconst pkgJSON = {\n name: 'verdaccio',\n};\n\nexport type SetupDirectory = {\n path: string;\n type: string;\n};\n\nconst debug = buildDebug('verdaccio:config');\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 if (typeof configPath !== 'undefined') {\n return path.resolve(configPath);\n }\n\n const configPaths: SetupDirectory[] = getConfigPaths();\n debug('%o posible locations found', configPaths.length);\n if (_.isEmpty(configPaths)) {\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('previous location exist already %s', primaryConf?.path);\n return primaryConf.path;\n }\n\n // @ts-ignore\n return createConfigFile(_.head(configPaths)).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(): Buffer {\n const pathDefaultConf: string = path.resolve(__dirname, 'conf/default.yaml');\n try {\n debug('default configuration file %s', pathDefaultConf);\n fs.accessSync(pathDefaultConf, fs.constants.R_OK);\n } catch {\n throw new TypeError('configuration file does not have enough permissions for reading');\n }\n // @ts-ignore\n return fs.readFileSync(pathDefaultConf, CHARACTER_ENCODING.UTF8);\n}\n\nfunction createConfigFolder(configLocation): void {\n fs.mkdirSync(path.dirname(configLocation.path), { recursive: true });\n debug(`Creating default config file in %o`, configLocation?.path);\n}\n\nfunction updateStorageLinks(configLocation, defaultConfig): string {\n if (configLocation.type !== XDG) {\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('directory detected path %s for type %s', currentValue?.path, currentValue.type);\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 * @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 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 (process.platform === WIN32 && process.env.APPDATA && folderExists(process.env.APPDATA)) {\n debug('is windows appdata: %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 return {\n path: path.resolve(path.join('.', pkgJSON.name, CONFIG_FILE)),\n type: 'def',\n };\n};\n\n/**\n * This should never happens, consider it DEPRECATED\n * @returns\n */\nconst getOldDirectory = (): SetupDirectory => {\n return {\n path: path.resolve(path.join('.', CONFIG_FILE)),\n type: 'old',\n };\n};\n\nexport { findConfigFile };\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,GAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,KAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAEA,IAAAI,KAAA,GAAAJ,OAAA;AAEA,IAAAK,YAAA,GAAAL,OAAA;AAA0D,S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EAAEA,aAAI,CAACqC,IAAI,CAACa,aAAa,EAAExD,OAAO,CAACC,IAAI,EAAEL,WAAW,CAAC;MACzD0C,IAAI,EAAEzC;IACR,CAAC;EACH;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,MAAMoD,mBAAmB,GAAGA,CAAA,KAA6B;EACvD,IAAIT,OAAO,CAACkB,QAAQ,KAAK3D,KAAK,IAAIyC,OAAO,CAACC,GAAG,CAACkB,OAAO,IAAI,IAAAd,yBAAY,EAACL,OAAO,CAACC,GAAG,CAACkB,OAAO,CAAC,EAAE;IAC1FzD,KAAK,CAAC,wBAAwB,EAAEsC,OAAO,CAACC,GAAG,CAACkB,OAAO,CAAC;IACpD,OAAO;MACLrD,IAAI,EAAEA,aAAI,CAACC,OAAO,CAACD,aAAI,CAACqC,IAAI,CAACH,OAAO,CAACC,GAAG,CAACkB,OAAO,EAAE3D,OAAO,CAACC,IAAI,EAAEL,WAAW,CAAC,CAAC;MAC7E0C,IAAI,EAAExC;IACR,CAAC;EACH;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,MAAMoD,2BAA2B,GAAGA,CAAA,KAAsB;EACxD,OAAO;IACL5C,IAAI,EAAEA,aAAI,CAACC,OAAO,CAACD,aAAI,CAACqC,IAAI,CAAC,GAAG,EAAE3C,OAAO,CAACC,IAAI,EAAEL,WAAW,CAAC,CAAC;IAC7D0C,IAAI,EAAE;EACR,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACA;AACA,MAAMa,eAAe,GAAGA,CAAA,KAAsB;EAC5C,OAAO;IACL7C,IAAI,EAAEA,aAAI,CAACC,OAAO,CAACD,aAAI,CAACqC,IAAI,CAAC,GAAG,EAAE/C,WAAW,CAAC,CAAC;IAC/C0C,IAAI,EAAE;EACR,CAAC;AACH,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"config-path.js","names":["_debug","_interopRequireDefault","require","_fs","_lodash","_os","_path","_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 fs from 'fs';\nimport _ from 'lodash';\nimport os from 'os';\nimport path from 'path';\n\nimport { fileExists, folderExists } from './config-utils';\n\nconst CONFIG_FILE = 'config.yaml';\nconst XDG = 'xdg';\n// eslint-disable-next-line\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): 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,GAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,GAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,KAAA,GAAAL,sBAAA,CAAAC,OAAA;AAEA,IAAAK,YAAA,GAAAL,OAAA;AAA0D,SAAAD,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE1D,MAAMG,WAAW,GAAG,aAAa;AACjC,MAAMC,GAAG,GAAG,KAAK;AACjB;AACA,MAAMC,OAAO,GAAG;EACdC,IAAI,EAAE;AACR,CAAC;AAOD,MAAMC,KAAK,GAAG,IAAAC,cAAU,EAAC,8BAA8B,CAAC;;AAExD;AACA;AACA;AACA;AACA,SAASC,cAAcA,CAACC,UAAmB,EAAU;EACnDH,KAAK,CAAC,8BAA8B,EAAEG,UAAU,CAAC;EACjD,IAAI,OAAOA,UAAU,KAAK,WAAW,EAAE;IACrC,MAAMC,cAAc,GAAGC,aAAI,CAACC,OAAO,CAACH,UAAU,CAAC;IAC/CH,KAAK,CAAC,oBAAoB,EAAEI,cAAc,CAAC;IAC3C,OAAOA,cAAc;EACvB;EAEA,MAAMG,WAA6B,GAAGC,cAAc,CAAC,CAAC;EACtDR,KAAK,CAAC,4BAA4B,EAAEO,WAAW,CAACE,MAAM,CAAC;EACvD,IAAIF,WAAW,CAACE,MAAM,KAAK,CAAC,EAAE;IAC5BT,KAAK,CAAC,yCAAyC,CAAC;IAChD;IACA,MAAM,IAAIU,KAAK,CAAC,yCAAyC,CAAC;EAC5D;;EAEA;EACA,MAAM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AACmB,OAAO,IAAI,IAAAf,yBAAY,EAACL,OAAO,CAACC,GAAG,CAACmB,OAAO,CAAC,EAAE;IACzFvD,KAAK,CAAC,gCAAgC,EAAEmC,OAAO,CAACC,GAAG,CAACmB,OAAO,CAAC;IAC5D,OAAO;MACLlD,IAAI,EAAEA,aAAI,CAACC,OAAO,CAACD,aAAI,CAACiC,IAAI,CAACH,OAAO,CAACC,GAAG,CAACmB,OAAO,EAAEzD,OAAO,CAACC,IAAI,EAAEH,WAAW,CAAC,CAAC;MAC7EqC,IAAI,EAAE;IACR,CAAC;EACH;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,MAAMY,2BAA2B,GAAGA,CAAA,KAAsB;EACxD,MAAMW,YAAY,GAAGnD,aAAI,CAACC,OAAO,CAACD,aAAI,CAACiC,IAAI,CAAC,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,aAAI,CAACC,OAAO,CAACD,aAAI,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":[]}
@@ -5,8 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.fileExists = fileExists;
7
7
  exports.folderExists = folderExists;
8
+ var _debug = _interopRequireDefault(require("debug"));
8
9
  var _fs = _interopRequireDefault(require("fs"));
9
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ const debug = (0, _debug.default)('verdaccio:config:config-utils');
12
+
10
13
  /**
11
14
  * Check whether the path already exist.
12
15
  * @param {String} path
@@ -14,9 +17,13 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
14
17
  */
15
18
  function folderExists(path) {
16
19
  try {
20
+ debug('check folder exist', path);
17
21
  const stat = _fs.default.statSync(path);
18
- return stat.isDirectory();
22
+ const isDirectory = stat.isDirectory();
23
+ debug('folder exist', isDirectory);
24
+ return isDirectory;
19
25
  } catch (_) {
26
+ debug('folder %s does not exist', path);
20
27
  return false;
21
28
  }
22
29
  }
@@ -28,9 +35,13 @@ function folderExists(path) {
28
35
  */
29
36
  function fileExists(path) {
30
37
  try {
38
+ debug('check file exist', path);
31
39
  const stat = _fs.default.statSync(path);
32
- return stat.isFile();
40
+ const isFile = stat.isFile();
41
+ debug('file exist', isFile);
42
+ return isFile;
33
43
  } catch (_) {
44
+ debug('file %s does not exist', path);
34
45
  return false;
35
46
  }
36
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"config-utils.js","names":["_fs","_interopRequireDefault","require","e","__esModule","default","folderExists","path","stat","fs","statSync","isDirectory","_","fileExists","isFile"],"sources":["../src/config-utils.ts"],"sourcesContent":["import fs from 'fs';\n\n/**\n * Check whether the path already exist.\n * @param {String} path\n * @return {Boolean}\n */\nexport function folderExists(path: string): boolean {\n try {\n const stat = fs.statSync(path);\n return stat.isDirectory();\n } catch (_: any) {\n return false;\n }\n}\n\n/**\n * Check whether the file already exist.\n * @param {String} path\n * @return {Boolean}\n */\nexport function fileExists(path: string): boolean {\n try {\n const stat = fs.statSync(path);\n return stat.isFile();\n } catch (_: any) {\n return false;\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAoB,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEpB;AACA;AACA;AACA;AACA;AACO,SAASG,YAAYA,CAACC,IAAY,EAAW;EAClD,IAAI;IACF,MAAMC,IAAI,GAAGC,WAAE,CAACC,QAAQ,CAACH,IAAI,CAAC;IAC9B,OAAOC,IAAI,CAACG,WAAW,CAAC,CAAC;EAC3B,CAAC,CAAC,OAAOC,CAAM,EAAE;IACf,OAAO,KAAK;EACd;AACF;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASC,UAAUA,CAACN,IAAY,EAAW;EAChD,IAAI;IACF,MAAMC,IAAI,GAAGC,WAAE,CAACC,QAAQ,CAACH,IAAI,CAAC;IAC9B,OAAOC,IAAI,CAACM,MAAM,CAAC,CAAC;EACtB,CAAC,CAAC,OAAOF,CAAM,EAAE;IACf,OAAO,KAAK;EACd;AACF","ignoreList":[]}
1
+ {"version":3,"file":"config-utils.js","names":["_debug","_interopRequireDefault","require","_fs","e","__esModule","default","debug","buildDebug","folderExists","path","stat","fs","statSync","isDirectory","_","fileExists","isFile"],"sources":["../src/config-utils.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport fs from 'fs';\n\nconst debug = buildDebug('verdaccio:config:config-utils');\n\n/**\n * Check whether the path already exist.\n * @param {String} path\n * @return {Boolean}\n */\nexport function folderExists(path: string): boolean {\n try {\n debug('check folder exist', path);\n const stat = fs.statSync(path);\n const isDirectory = stat.isDirectory();\n debug('folder exist', isDirectory);\n return isDirectory;\n } catch (_: any) {\n debug('folder %s does not exist', path);\n return false;\n }\n}\n\n/**\n * Check whether the file already exist.\n * @param {String} path\n * @return {Boolean}\n */\nexport function fileExists(path: string): boolean {\n try {\n debug('check file exist', path);\n const stat = fs.statSync(path);\n const isFile = stat.isFile();\n debug('file exist', isFile);\n return isFile;\n } catch (_: any) {\n debug('file %s does not exist', path);\n return false;\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,GAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAoB,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEpB,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,+BAA+B,CAAC;;AAEzD;AACA;AACA;AACA;AACA;AACO,SAASC,YAAYA,CAACC,IAAY,EAAW;EAClD,IAAI;IACFH,KAAK,CAAC,oBAAoB,EAAEG,IAAI,CAAC;IACjC,MAAMC,IAAI,GAAGC,WAAE,CAACC,QAAQ,CAACH,IAAI,CAAC;IAC9B,MAAMI,WAAW,GAAGH,IAAI,CAACG,WAAW,CAAC,CAAC;IACtCP,KAAK,CAAC,cAAc,EAAEO,WAAW,CAAC;IAClC,OAAOA,WAAW;EACpB,CAAC,CAAC,OAAOC,CAAM,EAAE;IACfR,KAAK,CAAC,0BAA0B,EAAEG,IAAI,CAAC;IACvC,OAAO,KAAK;EACd;AACF;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASM,UAAUA,CAACN,IAAY,EAAW;EAChD,IAAI;IACFH,KAAK,CAAC,kBAAkB,EAAEG,IAAI,CAAC;IAC/B,MAAMC,IAAI,GAAGC,WAAE,CAACC,QAAQ,CAACH,IAAI,CAAC;IAC9B,MAAMO,MAAM,GAAGN,IAAI,CAACM,MAAM,CAAC,CAAC;IAC5BV,KAAK,CAAC,YAAY,EAAEU,MAAM,CAAC;IAC3B,OAAOA,MAAM;EACf,CAAC,CAAC,OAAOF,CAAM,EAAE;IACfR,KAAK,CAAC,wBAAwB,EAAEG,IAAI,CAAC;IACrC,OAAO,KAAK;EACd;AACF","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verdaccio/config",
3
- "version": "7.0.0-next-7.20",
3
+ "version": "7.0.0-next-8.21",
4
4
  "description": "logger",
5
5
  "main": "./build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -26,12 +26,12 @@
26
26
  "verdaccio"
27
27
  ],
28
28
  "engines": {
29
- "node": ">=12"
29
+ "node": ">=14"
30
30
  },
31
31
  "dependencies": {
32
- "@verdaccio/core": "7.0.0-next-7.20",
33
- "@verdaccio/utils": "7.0.0-next-7.20",
34
- "debug": "4.3.4",
32
+ "@verdaccio/core": "7.0.0-next-8.21",
33
+ "@verdaccio/utils": "7.0.0-next-8.21",
34
+ "debug": "4.3.6",
35
35
  "js-yaml": "4.1.0",
36
36
  "lodash": "4.17.21",
37
37
  "minimatch": "7.4.6"
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "scripts": {
47
47
  "clean": "rimraf ./build",
48
- "test": "jest",
48
+ "test": "vitest run",
49
49
  "type-check": "tsc --noEmit -p tsconfig.build.json",
50
50
  "build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
51
51
  "build:js": "babel src/ --out-dir build/ --copy-files --extensions \".ts,.tsx\" --source-maps",
@@ -1,16 +1,13 @@
1
1
  import buildDebug from 'debug';
2
2
  import fs from 'fs';
3
3
  import _ from 'lodash';
4
+ import os from 'os';
4
5
  import path from 'path';
5
6
 
6
- import { CHARACTER_ENCODING } from '@verdaccio/core';
7
-
8
7
  import { fileExists, folderExists } from './config-utils';
9
8
 
10
9
  const CONFIG_FILE = 'config.yaml';
11
10
  const XDG = 'xdg';
12
- const WIN = 'win';
13
- const WIN32 = 'win32';
14
11
  // eslint-disable-next-line
15
12
  const pkgJSON = {
16
13
  name: 'verdaccio',
@@ -18,23 +15,27 @@ const pkgJSON = {
18
15
 
19
16
  export type SetupDirectory = {
20
17
  path: string;
21
- type: string;
18
+ type: 'xdg' | 'win' | 'win32' | 'def' | 'old';
22
19
  };
23
20
 
24
- const debug = buildDebug('verdaccio:config');
21
+ const debug = buildDebug('verdaccio:config:config-path');
25
22
 
26
23
  /**
27
24
  * Find and get the first config file that match.
28
25
  * @return {String} the config file path
29
26
  */
30
27
  function findConfigFile(configPath?: string): string {
28
+ debug('searching for config file %o', configPath);
31
29
  if (typeof configPath !== 'undefined') {
32
- return path.resolve(configPath);
30
+ const configLocation = path.resolve(configPath);
31
+ debug('custom location %s', configLocation);
32
+ return configLocation;
33
33
  }
34
34
 
35
35
  const configPaths: SetupDirectory[] = getConfigPaths();
36
36
  debug('%o posible locations found', configPaths.length);
37
- if (_.isEmpty(configPaths)) {
37
+ if (configPaths.length === 0) {
38
+ debug('no configuration files can be processed');
38
39
  // this should never happens
39
40
  throw new Error('no configuration files can be processed');
40
41
  }
@@ -45,12 +46,12 @@ function findConfigFile(configPath?: string): string {
45
46
  );
46
47
 
47
48
  if (typeof primaryConf !== 'undefined') {
48
- debug('previous location exist already %s', primaryConf?.path);
49
+ debug('at least one primary location detected at %s', primaryConf?.path);
49
50
  return primaryConf.path;
50
51
  }
51
-
52
- // @ts-ignore
53
- return createConfigFile(_.head(configPaths)).path;
52
+ debug('no previous location found, creating a new one');
53
+ debug('generating the first match path location %s', configPaths[0].path);
54
+ return createConfigFile(configPaths[0]).path;
54
55
  }
55
56
 
56
57
  function createConfigFile(configLocation: SetupDirectory): SetupDirectory {
@@ -63,25 +64,37 @@ function createConfigFile(configLocation: SetupDirectory): SetupDirectory {
63
64
  return configLocation;
64
65
  }
65
66
 
66
- export function readDefaultConfig(): Buffer {
67
+ export function readDefaultConfig(): string {
67
68
  const pathDefaultConf: string = path.resolve(__dirname, 'conf/default.yaml');
68
69
  try {
69
- debug('default configuration file %s', pathDefaultConf);
70
+ debug('the path of default config used from %s', pathDefaultConf);
70
71
  fs.accessSync(pathDefaultConf, fs.constants.R_OK);
72
+ debug('configuration file has enough permissions for reading');
71
73
  } catch {
74
+ debug('configuration file does not have enough permissions for reading');
72
75
  throw new TypeError('configuration file does not have enough permissions for reading');
73
76
  }
74
- // @ts-ignore
75
- return fs.readFileSync(pathDefaultConf, CHARACTER_ENCODING.UTF8);
77
+
78
+ return fs.readFileSync(pathDefaultConf, 'utf8');
76
79
  }
77
80
 
78
81
  function createConfigFolder(configLocation): void {
79
- fs.mkdirSync(path.dirname(configLocation.path), { recursive: true });
80
- debug(`Creating default config file in %o`, configLocation?.path);
82
+ const folder = path.dirname(configLocation.path);
83
+ debug(`creating default config file folder at %o`, folder);
84
+ fs.mkdirSync(folder, { recursive: true });
85
+ debug(`folder %o created`, folder);
81
86
  }
82
87
 
83
- function updateStorageLinks(configLocation, defaultConfig): string {
88
+ /**
89
+ * Update the storage links to the new location if it is necessary.
90
+ * @param configLocation
91
+ * @param defaultConfig
92
+ * @returns
93
+ */
94
+ function updateStorageLinks(configLocation: SetupDirectory, defaultConfig: string): string {
95
+ debug('checking storage links for %s and type %s', configLocation.path, configLocation.type);
84
96
  if (configLocation.type !== XDG) {
97
+ debug(`skip storage override for %s`, configLocation.type);
85
98
  return defaultConfig;
86
99
  }
87
100
 
@@ -114,7 +127,11 @@ function getConfigPaths(): SetupDirectory[] {
114
127
 
115
128
  return listPaths.reduce(function (acc, currentValue: SetupDirectory | void): SetupDirectory[] {
116
129
  if (typeof currentValue !== 'undefined') {
117
- debug('directory detected path %s for type %s', currentValue?.path, currentValue.type);
130
+ debug(
131
+ 'posible directory path generated %s for type %s',
132
+ currentValue?.path,
133
+ currentValue.type
134
+ );
118
135
  acc.push(currentValue);
119
136
  }
120
137
  return acc;
@@ -123,11 +140,22 @@ function getConfigPaths(): SetupDirectory[] {
123
140
 
124
141
  /**
125
142
  * Get XDG_CONFIG_HOME or HOME location (usually unix)
143
+ *
144
+ * The XDG_CONFIG_HOME environment variable is also part of the XDG Base Directory Specification,
145
+ * which aims to standardize the locations where applications store configuration files and other
146
+ * user-specific data on Unix-like operating systems.
147
+ *
148
+ *
149
+ *
150
+ * https://specifications.freedesktop.org/basedir-spec/latest/
151
+ *
152
+ *
126
153
  * @returns
127
154
  */
128
155
  const getXDGDirectory = (): SetupDirectory | void => {
129
156
  const xDGConfigPath =
130
157
  process.env.XDG_CONFIG_HOME || (process.env.HOME && path.join(process.env.HOME, '.config'));
158
+ debug('XDGConfig folder path %s', xDGConfigPath);
131
159
  if (xDGConfigPath && folderExists(xDGConfigPath)) {
132
160
  debug('XDGConfig folder path %s', xDGConfigPath);
133
161
  return {
@@ -143,11 +171,11 @@ const getXDGDirectory = (): SetupDirectory | void => {
143
171
  * @returns
144
172
  */
145
173
  const getWindowsDirectory = (): SetupDirectory | void => {
146
- if (process.platform === WIN32 && process.env.APPDATA && folderExists(process.env.APPDATA)) {
147
- debug('is windows appdata: %s', process.env.APPDATA);
174
+ if (os.platform() === 'win32' && process.env.APPDATA && folderExists(process.env.APPDATA)) {
175
+ debug('windows appdata folder path %s', process.env.APPDATA);
148
176
  return {
149
177
  path: path.resolve(path.join(process.env.APPDATA, pkgJSON.name, CONFIG_FILE)),
150
- type: WIN,
178
+ type: 'win',
151
179
  };
152
180
  }
153
181
  };
@@ -158,8 +186,10 @@ const getWindowsDirectory = (): SetupDirectory | void => {
158
186
  * @returns
159
187
  */
160
188
  const getRelativeDefaultDirectory = (): SetupDirectory => {
189
+ const relativePath = path.resolve(path.join('.', pkgJSON.name, CONFIG_FILE));
190
+ debug('relative folder path %s', relativePath);
161
191
  return {
162
- path: path.resolve(path.join('.', pkgJSON.name, CONFIG_FILE)),
192
+ path: relativePath,
163
193
  type: 'def',
164
194
  };
165
195
  };
@@ -169,8 +199,10 @@ const getRelativeDefaultDirectory = (): SetupDirectory => {
169
199
  * @returns
170
200
  */
171
201
  const getOldDirectory = (): SetupDirectory => {
202
+ const oldPath = path.resolve(path.join('.', CONFIG_FILE));
203
+ debug('old folder path %s', oldPath);
172
204
  return {
173
- path: path.resolve(path.join('.', CONFIG_FILE)),
205
+ path: oldPath,
174
206
  type: 'old',
175
207
  };
176
208
  };
@@ -1,5 +1,8 @@
1
+ import buildDebug from 'debug';
1
2
  import fs from 'fs';
2
3
 
4
+ const debug = buildDebug('verdaccio:config:config-utils');
5
+
3
6
  /**
4
7
  * Check whether the path already exist.
5
8
  * @param {String} path
@@ -7,9 +10,13 @@ import fs from 'fs';
7
10
  */
8
11
  export function folderExists(path: string): boolean {
9
12
  try {
13
+ debug('check folder exist', path);
10
14
  const stat = fs.statSync(path);
11
- return stat.isDirectory();
15
+ const isDirectory = stat.isDirectory();
16
+ debug('folder exist', isDirectory);
17
+ return isDirectory;
12
18
  } catch (_: any) {
19
+ debug('folder %s does not exist', path);
13
20
  return false;
14
21
  }
15
22
  }
@@ -21,9 +28,13 @@ export function folderExists(path: string): boolean {
21
28
  */
22
29
  export function fileExists(path: string): boolean {
23
30
  try {
31
+ debug('check file exist', path);
24
32
  const stat = fs.statSync(path);
25
- return stat.isFile();
33
+ const isFile = stat.isFile();
34
+ debug('file exist', isFile);
35
+ return isFile;
26
36
  } catch (_: any) {
37
+ debug('file %s does not exist', path);
27
38
  return false;
28
39
  }
29
40
  }
@@ -1,6 +1,6 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
- exports[`Config builder should create a configuration file as yaml 1`] = `
3
+ exports[`Config builder > should create a configuration file as yaml 1`] = `
4
4
  "uplinks:
5
5
  upstream:
6
6
  url: https://registry.verdaccio.org
@@ -1,6 +1,6 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
- exports[`parse fromJStoYAML basic conversion roundtrip 1`] = `
3
+ exports[`parse > fromJStoYAML > basic conversion roundtrip 1`] = `
4
4
  "storage: ./storage_default_storage
5
5
  uplinks:
6
6
  npmjs:
@@ -1,3 +1,5 @@
1
+ import { describe, expect, test } from 'vitest';
2
+
1
3
  import { getUserAgent } from '../src';
2
4
 
3
5
  describe('getUserAgent', () => {
@@ -1,3 +1,5 @@
1
+ import { describe, expect, test } from 'vitest';
2
+
1
3
  import { ConfigBuilder } from '../src';
2
4
 
3
5
  describe('Config builder', () => {
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import { describe, expect, test } from 'vitest';
3
4
 
4
5
  import { fileUtils } from '@verdaccio/core';
5
6
 
@@ -1,4 +1,5 @@
1
1
  import path from 'path';
2
+ import { describe, expect, test } from 'vitest';
2
3
 
3
4
  import { fileExists, folderExists } from '../src/config-utils';
4
5
 
@@ -1,76 +1,105 @@
1
+ import fs from 'fs';
1
2
  import os from 'os';
3
+ import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
2
4
 
3
5
  import { findConfigFile } from '../src/config-path';
4
6
 
5
- const mockmkDir = jest.fn();
6
- const mockaccessSync = jest.fn();
7
- const mockwriteFile = jest.fn();
8
-
9
- jest.mock('fs', () => {
10
- const fsOri = jest.requireActual('fs');
11
- return {
12
- ...fsOri,
13
- statSync: (path) => ({
14
- isDirectory: () => {
15
- if (path.match(/fail/)) {
16
- throw Error('file does not exist');
17
- }
18
- return true;
19
- },
20
- }),
21
- accessSync: (a) => mockaccessSync(a),
22
- mkdirSync: (a) => mockmkDir(a),
23
- writeFileSync: (a) => mockwriteFile(a),
7
+ describe('config-path', () => {
8
+ let statSyncMock;
9
+ let mkdirSyncMock;
10
+ let writeFileSyncMock;
11
+ let accessSyncMock;
12
+ let fakeStats = {
13
+ isDirectory: vi.fn().mockReturnValue(true),
24
14
  };
25
- });
26
-
27
- jest.mock('fs');
28
15
 
29
- describe('config-path', () => {
30
16
  beforeEach(() => {
31
- jest.clearAllMocks();
32
- jest.resetAllMocks();
17
+ // Mock only statSync method
18
+ statSyncMock = vi.spyOn(fs, 'statSync');
19
+ mkdirSyncMock = vi.spyOn(fs, 'mkdirSync');
20
+ writeFileSyncMock = vi.spyOn(fs, 'writeFileSync');
21
+ accessSyncMock = vi.spyOn(fs, 'accessSync');
22
+ });
23
+
24
+ afterEach(() => {
25
+ // Restore the original implementation after each test
26
+ statSyncMock.mockRestore();
27
+ vi.unstubAllEnvs();
33
28
  });
34
29
 
30
+ function platformPath(path: string): string {
31
+ return path.replace(/\//g, os.platform() === 'win32' ? '\\' : '/');
32
+ }
33
+
35
34
  describe('findConfigFile', () => {
36
- if (os.platform() !== 'win32') {
37
- describe('using defiled location from arguments', () => {
38
- test('with custom location', () => {
39
- expect(findConfigFile('/home/user/custom/location/config.yaml')).toEqual(
40
- '/home/user/custom/location/config.yaml'
41
- );
42
- expect(mockwriteFile).not.toHaveBeenCalled();
43
- expect(mockmkDir).not.toHaveBeenCalled();
44
- });
35
+ describe('using file location from arguments', () => {
36
+ test('with custom location', () => {
37
+ // mock
38
+ statSyncMock.mockReturnValue(fakeStats);
39
+ mkdirSyncMock.mockReturnValue(true);
40
+ writeFileSyncMock.mockReturnValue(undefined);
41
+ // Note: on Windows, path contains drive letter
42
+ expect(findConfigFile('/home/user/custom/location/config.yaml')).toMatch(
43
+ platformPath('/home/user/custom/location/config.yaml')
44
+ );
45
+ expect(writeFileSyncMock).not.toHaveBeenCalled();
46
+ expect(mkdirSyncMock).not.toHaveBeenCalled();
45
47
  });
48
+ });
46
49
 
47
- describe('whith env variables', () => {
48
- test('with XDG_CONFIG_HOME if directory exist but config file is missing', () => {
49
- process.env.XDG_CONFIG_HOME = '/home/user';
50
- expect(findConfigFile()).toEqual('/home/user/verdaccio/config.yaml');
51
- expect(mockwriteFile).toHaveBeenCalledWith('/home/user/verdaccio/config.yaml');
52
- expect(mockmkDir).toHaveBeenCalledWith('/home/user/verdaccio');
53
- });
50
+ describe('with env variables', () => {
51
+ test('the env XDG_CONFIG_HOME is defined and the directory exist but config file is missing', async () => {
52
+ // mock
53
+ statSyncMock.mockReturnValue(fakeStats);
54
+ mkdirSyncMock.mockReturnValue(true);
55
+ writeFileSyncMock.mockReturnValue(undefined);
56
+ // node env variable
57
+ vi.stubEnv('XDG_CONFIG_HOME', '/home/user');
54
58
 
55
- test('with HOME if directory exist but config file is missing', () => {
56
- delete process.env.XDG_CONFIG_HOME;
57
- process.env.HOME = '/home/user';
58
- expect(findConfigFile()).toEqual('/home/user/.config/verdaccio/config.yaml');
59
- expect(mockwriteFile).toHaveBeenCalledWith('/home/user/.config/verdaccio/config.yaml');
60
- expect(mockmkDir).toHaveBeenCalledWith('/home/user/.config/verdaccio');
61
- });
59
+ expect(findConfigFile()).toEqual(platformPath('/home/user/verdaccio/config.yaml'));
60
+ expect(writeFileSyncMock).toHaveBeenCalledWith(
61
+ platformPath('/home/user/verdaccio/config.yaml'),
62
+ expect.stringContaining('packages')
63
+ );
64
+ });
65
+
66
+ test('with HOME if directory exist but config file is missing', () => {
67
+ // mock
68
+ statSyncMock.mockReturnValue(fakeStats);
69
+ mkdirSyncMock.mockReturnValue(true);
70
+ writeFileSyncMock.mockReturnValue(undefined);
71
+ vi.stubEnv('XDG_CONFIG_HOME', '');
72
+ vi.stubEnv('HOME', '/home/user');
73
+ expect(findConfigFile()).toEqual(platformPath('/home/user/.config/verdaccio/config.yaml'));
74
+ expect(writeFileSyncMock).toHaveBeenCalledWith(
75
+ platformPath('/home/user/.config/verdaccio/config.yaml'),
76
+ expect.stringContaining('packages')
77
+ );
78
+ expect(mkdirSyncMock).toHaveBeenCalledWith(
79
+ platformPath('/home/user/.config/verdaccio'),
80
+ expect.anything()
81
+ );
82
+ });
62
83
 
63
- describe('error handling', () => {
64
- test('XDG_CONFIG_HOME is not directory fallback to default', () => {
65
- process.env.XDG_CONFIG_HOME = '/home/user/fail';
66
- mockaccessSync.mockImplementation(() => {});
67
- mockwriteFile.mockImplementation(() => {});
68
- expect(findConfigFile()).toMatch('packages/config/verdaccio/config.yaml');
84
+ describe('error handling', () => {
85
+ test('XDG_CONFIG_HOME is not directory fallback to default', () => {
86
+ // mock
87
+ statSyncMock.mockReturnValue({
88
+ isDirectory: vi.fn().mockReturnValue(false),
69
89
  });
90
+ mkdirSyncMock.mockReturnValue(true);
91
+ writeFileSyncMock.mockReturnValue(undefined);
92
+ // node env variable
93
+ vi.stubEnv('XDG_CONFIG_HOME', '/home/user/fail');
70
94
 
95
+ expect(findConfigFile()).toMatch(platformPath('packages/config/verdaccio/config.yaml'));
96
+ });
97
+
98
+ // Does not work on Windows
99
+ if (os.platform() !== 'win32') {
71
100
  test('no permissions on read default config file', () => {
72
- process.env.XDG_CONFIG_HOME = '/home/user';
73
- mockaccessSync.mockImplementation(() => {
101
+ vi.stubEnv('XDG_CONFIG_HOME', '/home/user');
102
+ accessSyncMock.mockImplementation(() => {
74
103
  throw new Error('error on write file');
75
104
  });
76
105
 
@@ -78,29 +107,28 @@ describe('config-path', () => {
78
107
  findConfigFile();
79
108
  }).toThrow(/configuration file does not have enough permissions for reading/);
80
109
  });
81
- });
110
+ }
82
111
  });
112
+ });
83
113
 
84
- describe('with no env variables', () => {
114
+ // Note: Trying to mock Windows platform leads to different results (incorrect slashes)
115
+ if (os.platform() === 'win32') {
116
+ describe('with Windows env variables', () => {
85
117
  test('with relative location', () => {
86
- mockaccessSync.mockImplementation(() => {});
87
- delete process.env.XDG_CONFIG_HOME;
88
- delete process.env.HOME;
89
- process.env.APPDATA = '/app/data/';
90
- expect(findConfigFile()).toMatch('packages/config/verdaccio/config.yaml');
91
- expect(mockwriteFile).toHaveBeenCalled();
92
- expect(mockmkDir).toHaveBeenCalled();
118
+ // mock
119
+ statSyncMock.mockReturnValue(fakeStats);
120
+ mkdirSyncMock.mockReturnValue(true);
121
+ writeFileSyncMock.mockReturnValue(undefined);
122
+ accessSyncMock.mockImplementation(() => {});
123
+ // delete process.env.XDG_CONFIG_HOME;
124
+ vi.stubEnv('XDG_CONFIG_HOME', '');
125
+ vi.stubEnv('HOME', '');
126
+ vi.stubEnv('APPDATA', 'C:\\Users\\Tester\\AppData\\');
127
+ expect(findConfigFile()).toEqual('C:\\Users\\Tester\\AppData\\verdaccio\\config.yaml');
128
+ expect(writeFileSyncMock).toHaveBeenCalled();
129
+ expect(mkdirSyncMock).toHaveBeenCalled();
93
130
  });
94
131
  });
95
- } else {
96
- test('with windows as directory exist but config file is missing', () => {
97
- delete process.env.XDG_CONFIG_HOME;
98
- delete process.env.HOME;
99
- process.env.APPDATA = '/app/data/';
100
- expect(findConfigFile()).toMatch('\\app\\data\\verdaccio\\config.yaml');
101
- expect(mockwriteFile).toHaveBeenCalled();
102
- expect(mockmkDir).toHaveBeenCalled();
103
- });
104
132
  }
105
133
  });
106
134
  });
@@ -1,5 +1,6 @@
1
1
  import _ from 'lodash';
2
2
  import path from 'path';
3
+ import { describe, expect, test } from 'vitest';
3
4
 
4
5
  import {
5
6
  Config,
@@ -22,7 +23,7 @@ const resolveConf = (conf) => {
22
23
  return path.join(__dirname, `../src/conf/${name}${ext.startsWith('.') ? ext : '.yaml'}`);
23
24
  };
24
25
 
25
- const itif = (condition) => (condition ? it : it.skip);
26
+ const itif = (condition) => (condition ? test : test.skip);
26
27
 
27
28
  const checkDefaultUplink = (config) => {
28
29
  expect(_.isObject(config.uplinks[DEFAULT_UPLINK])).toBeTruthy();
@@ -1,4 +1,5 @@
1
1
  import _ from 'lodash';
2
+ import { describe, expect, test } from 'vitest';
2
3
 
3
4
  import { parseConfigFile } from '../src';
4
5
  import { PACKAGE_ACCESS, normalisePackageAccess, normalizeUserList } from '../src/package-access';
@@ -1,3 +1,5 @@
1
+ import { expect, test } from 'vitest';
2
+
1
3
  import { TOKEN_VALID_LENGTH, generateRandomSecretKey } from '../src/token';
2
4
 
3
5
  test('token test valid length', () => {
@@ -1,3 +1,5 @@
1
+ import { describe, expect, test } from 'vitest';
2
+
1
3
  import { normalisePackageAccess, parseConfigFile } from '../src';
2
4
  import { hasProxyTo, sanityCheckUplinksProps, uplinkSanityCheck } from '../src/uplinks';
3
5
  import { parseConfigurationFile } from './utils';
@@ -1,3 +1,5 @@
1
+ import { describe, expect, test } from 'vitest';
2
+
1
3
  import { ROLES, createAnonymousRemoteUser, createRemoteUser } from '../src';
2
4
 
3
5
  describe('createRemoteUser and createAnonymousRemoteUser', () => {
package/jest.config.js DELETED
@@ -1,9 +0,0 @@
1
- const config = require('../../jest/config');
2
-
3
- module.exports = Object.assign({}, config, {
4
- coverageThreshold: {
5
- global: {
6
- lines: 90,
7
- },
8
- },
9
- });