- Timestamp:
- 12/12/24 17:06:06 (5 weeks ago)
- Branches:
- main
- Parents:
- d565449
- Location:
- imaps-frontend/node_modules/@humanwhocodes/config-array
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/@humanwhocodes/config-array/api.js
rd565449 r0c6b92a 155 155 const CONFIG_TYPES = new Set(['array', 'function']); 156 156 157 /** 158 * Fields that are considered metadata and not part of the config object. 159 */ 160 const META_FIELDS = new Set(['name']); 161 157 162 const FILES_AND_IGNORES_SCHEMA = new objectSchema.ObjectSchema(filesAndIgnoresSchema); 163 164 /** 165 * Wrapper error for config validation errors that adds a name to the front of the 166 * error message. 167 */ 168 class ConfigError extends Error { 169 170 /** 171 * Creates a new instance. 172 * @param {string} name The config object name causing the error. 173 * @param {number} index The index of the config object in the array. 174 * @param {Error} source The source error. 175 */ 176 constructor(name, index, { cause, message }) { 177 178 179 const finalMessage = message || cause.message; 180 181 super(`Config ${name}: ${finalMessage}`, { cause }); 182 183 // copy over custom properties that aren't represented 184 if (cause) { 185 for (const key of Object.keys(cause)) { 186 if (!(key in this)) { 187 this[key] = cause[key]; 188 } 189 } 190 } 191 192 /** 193 * The name of the error. 194 * @type {string} 195 * @readonly 196 */ 197 this.name = 'ConfigError'; 198 199 /** 200 * The index of the config object in the array. 201 * @type {number} 202 * @readonly 203 */ 204 this.index = index; 205 } 206 } 207 208 /** 209 * Gets the name of a config object. 210 * @param {object} config The config object to get the name of. 211 * @returns {string} The name of the config object. 212 */ 213 function getConfigName(config) { 214 if (config && typeof config.name === 'string' && config.name) { 215 return `"${config.name}"`; 216 } 217 218 return '(unnamed)'; 219 } 220 221 /** 222 * Rethrows a config error with additional information about the config object. 223 * @param {object} config The config object to get the name of. 224 * @param {number} index The index of the config object in the array. 225 * @param {Error} error The error to rethrow. 226 * @throws {ConfigError} When the error is rethrown for a config. 227 */ 228 function rethrowConfigError(config, index, error) { 229 const configName = getConfigName(config); 230 throw new ConfigError(configName, index, error); 231 } 158 232 159 233 /** … … 167 241 168 242 /** 169 * Asserts that the files and ignores keys of a config object are valid as per base schema. 170 * @param {object} config The config object to check. 243 * Creates a function that asserts that the config is valid 244 * during normalization. This checks that the config is not nullish 245 * and that files and ignores keys of a config object are valid as per base schema. 246 * @param {Object} config The config object to check. 247 * @param {number} index The index of the config object in the array. 171 248 * @returns {void} 172 * @throws {TypeError} If the files and ignores keys of a config object are not valid. 173 */ 174 function assertValidFilesAndIgnores(config) { 175 if (!config || typeof config !== 'object') { 176 return; 177 } 249 * @throws {ConfigError} If the files and ignores keys of a config object are not valid. 250 */ 251 function assertValidBaseConfig(config, index) { 252 253 if (config === null) { 254 throw new ConfigError(getConfigName(config), index, { message: 'Unexpected null config.' }); 255 } 256 257 if (config === undefined) { 258 throw new ConfigError(getConfigName(config), index, { message: 'Unexpected undefined config.' }); 259 } 260 261 if (typeof config !== 'object') { 262 throw new ConfigError(getConfigName(config), index, { message: 'Unexpected non-object config.' }); 263 } 264 178 265 const validateConfig = { }; 266 179 267 if ('files' in config) { 180 268 validateConfig.files = config.files; 181 269 } 270 182 271 if ('ignores' in config) { 183 272 validateConfig.ignores = config.ignores; 184 273 } 185 FILES_AND_IGNORES_SCHEMA.validate(validateConfig); 274 275 try { 276 FILES_AND_IGNORES_SCHEMA.validate(validateConfig); 277 } catch (validationError) { 278 rethrowConfigError(config, index, { cause: validationError }); 279 } 186 280 } 187 281 … … 378 472 const relativeFilePath = path.relative(basePath, filePath); 379 473 380 return Object.keys(config). length > 1 &&474 return Object.keys(config).filter(key => !META_FIELDS.has(key)).length > 1 && 381 475 !shouldIgnorePath(config.ignores, filePath, relativeFilePath); 382 476 } … … 512 606 * Tracks if the array has been normalized. 513 607 * @property isNormalized 514 * @type boolean608 * @type {boolean} 515 609 * @private 516 610 */ … … 531 625 * This is used to calculate filename matches. 532 626 * @property basePath 533 * @type string627 * @type {string} 534 628 */ 535 629 this.basePath = basePath; … … 540 634 * The supported config types. 541 635 * @property configTypes 542 * @type Array<string>636 * @type {Array<string>} 543 637 */ 544 638 this.extraConfigTypes = Object.freeze([...extraConfigTypes]); … … 547 641 * A cache to store calculated configs for faster repeat lookup. 548 642 * @property configCache 549 * @type Map643 * @type {Map<string, Object>} 550 644 * @private 551 645 */ … … 646 740 * are additional keys, then ignores act like exclusions. 647 741 */ 648 if (config.ignores && Object.keys(config). length === 1) {742 if (config.ignores && Object.keys(config).filter(key => !META_FIELDS.has(key)).length === 1) { 649 743 result.push(...config.ignores); 650 744 } … … 678 772 this.length = 0; 679 773 this.push(...normalizedConfigs.map(this[ConfigArraySymbol.preprocessConfig].bind(this))); 680 this.forEach(assertValid FilesAndIgnores);774 this.forEach(assertValidBaseConfig); 681 775 this[ConfigArraySymbol.isNormalized] = true; 682 776 … … 700 794 this.length = 0; 701 795 this.push(...normalizedConfigs.map(this[ConfigArraySymbol.preprocessConfig].bind(this))); 702 this.forEach(assertValid FilesAndIgnores);796 this.forEach(assertValidBaseConfig); 703 797 this[ConfigArraySymbol.isNormalized] = true; 704 798 … … 933 1027 934 1028 finalConfig = matchingConfigIndices.reduce((result, index) => { 935 return this[ConfigArraySymbol.schema].merge(result, this[index]); 1029 try { 1030 return this[ConfigArraySymbol.schema].merge(result, this[index]); 1031 } catch (validationError) { 1032 rethrowConfigError(this[index], index, { cause: validationError}); 1033 } 936 1034 }, {}, this); 937 1035 -
imaps-frontend/node_modules/@humanwhocodes/config-array/package.json
rd565449 r0c6b92a 1 1 { 2 2 "name": "@humanwhocodes/config-array", 3 "version": "0.1 1.14",3 "version": "0.13.0", 4 4 "description": "Glob-based configuration matching.", 5 5 "author": "Nicholas C. Zakas", 6 6 "main": "api.js", 7 7 "files": [ 8 "api.js" 8 "api.js", 9 "LICENSE", 10 "README.md" 9 11 ], 10 12 "repository": { … … 43 45 }, 44 46 "dependencies": { 45 "@humanwhocodes/object-schema": "^2.0. 2",47 "@humanwhocodes/object-schema": "^2.0.3", 46 48 "debug": "^4.3.1", 47 49 "minimatch": "^3.0.5"
Note:
See TracChangeset
for help on using the changeset viewer.