cspell-lib 6.8.1 → 6.8.2

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.
@@ -1,564 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.__testing__ = exports.extractImportErrors = exports.clearCachedSettingsFiles = exports.getCachedFileSize = exports.getGlobalSettings = exports.readSettingsFiles = exports.readRawSettings = exports.loadPnPSync = exports.loadPnP = exports.loadConfigSync = exports.loadConfig = exports.searchForConfigSync = exports.searchForConfig = exports.readSettings = exports.defaultConfigFilenames = exports.defaultFileName = exports.sectionCSpell = void 0;
27
- const json = __importStar(require("comment-json"));
28
- const cosmiconfig_1 = require("cosmiconfig");
29
- const path = __importStar(require("path"));
30
- const vscode_uri_1 = require("vscode-uri");
31
- const CSpellSettingsInternalDef_1 = require("../../Models/CSpellSettingsInternalDef");
32
- const logger_1 = require("../../util/logger");
33
- const resolveFile_1 = require("../../util/resolveFile");
34
- const util = __importStar(require("../../util/util"));
35
- const CSpellSettingsServer_1 = require("../CSpellSettingsServer");
36
- const DictionarySettings_1 = require("../DictionarySettings");
37
- const GlobalSettings_1 = require("../GlobalSettings");
38
- const ImportError_1 = require("./ImportError");
39
- const pnpLoader_1 = require("./pnpLoader");
40
- const supportedCSpellConfigVersions = [CSpellSettingsServer_1.configSettingsFileVersion0_2];
41
- const setOfSupportedConfigVersions = new Set(supportedCSpellConfigVersions);
42
- exports.sectionCSpell = 'cSpell';
43
- exports.defaultFileName = 'cspell.json';
44
- /**
45
- * Logic of the locations:
46
- * - Support backward compatibility with the VS Code Spell Checker
47
- * the spell checker extension can only write to `.json` files because
48
- * it would be too difficult to automatically modify a `.js` or `.cjs` file.
49
- * - To support `cspell.config.js` in a VS Code environment, have a `cspell.json` import
50
- * the `cspell.config.js`.
51
- */
52
- const searchPlaces = [
53
- 'package.json',
54
- // Original locations
55
- '.cspell.json',
56
- 'cspell.json',
57
- '.cSpell.json',
58
- 'cSpell.json',
59
- // Original locations jsonc
60
- '.cspell.jsonc',
61
- 'cspell.jsonc',
62
- // Alternate locations
63
- '.vscode/cspell.json',
64
- '.vscode/cSpell.json',
65
- '.vscode/.cspell.json',
66
- // Standard Locations
67
- 'cspell.config.json',
68
- 'cspell.config.jsonc',
69
- 'cspell.config.yaml',
70
- 'cspell.config.yml',
71
- 'cspell.yaml',
72
- 'cspell.yml',
73
- // Dynamic config is looked for last
74
- 'cspell.config.js',
75
- 'cspell.config.cjs',
76
- ];
77
- const cspellCosmiconfig = {
78
- searchPlaces,
79
- loaders: {
80
- '.json': parseJson,
81
- '.jsonc': parseJson,
82
- },
83
- };
84
- function parseJson(_filename, content) {
85
- return json.parse(content);
86
- }
87
- exports.defaultConfigFilenames = Object.freeze(searchPlaces.concat());
88
- const cspellConfigExplorer = (0, cosmiconfig_1.cosmiconfig)('cspell', cspellCosmiconfig);
89
- const cspellConfigExplorerSync = (0, cosmiconfig_1.cosmiconfigSync)('cspell', cspellCosmiconfig);
90
- let globalSettings;
91
- const defaultSettings = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({
92
- id: 'default',
93
- name: 'default',
94
- version: CSpellSettingsServer_1.currentSettingsFileVersion,
95
- });
96
- const defaultPnPSettings = {};
97
- const cachedFiles = new Map();
98
- /**
99
- * Read a config file and inject the fileRef.
100
- * @param fileRef - filename plus context, injected into the resulting config.
101
- */
102
- function readConfig(fileRef) {
103
- // cspellConfigExplorerSync
104
- const { filename, error } = fileRef;
105
- if (error) {
106
- fileRef.error =
107
- error instanceof ImportError_1.ImportError ? error : new ImportError_1.ImportError(`Failed to read config file: "${filename}"`, error);
108
- return { __importRef: fileRef };
109
- }
110
- const s = {};
111
- try {
112
- const r = cspellConfigExplorerSync.load(filename);
113
- if (!r?.config)
114
- throw new Error(`not found: "${filename}"`);
115
- Object.assign(s, r.config);
116
- normalizeRawConfig(s);
117
- validateRawConfig(s, fileRef);
118
- }
119
- catch (err) {
120
- fileRef.error =
121
- err instanceof ImportError_1.ImportError ? err : new ImportError_1.ImportError(`Failed to read config file: "${filename}"`, err);
122
- }
123
- s.__importRef = fileRef;
124
- return s;
125
- }
126
- /**
127
- * normalizeSettings handles correcting all relative paths, anchoring globs, and importing other config files.
128
- * @param rawSettings - raw configuration settings
129
- * @param pathToSettingsFile - path to the source file of the configuration settings.
130
- */
131
- function normalizeSettings(rawSettings, pathToSettingsFile, pnpSettings) {
132
- const id = rawSettings.id ||
133
- [path.basename(path.dirname(pathToSettingsFile)), path.basename(pathToSettingsFile)].join('/');
134
- const name = rawSettings.name || id;
135
- // Try to load any .pnp files before reading dictionaries or other config files.
136
- const { usePnP = pnpSettings.usePnP, pnpFiles = pnpSettings.pnpFiles } = rawSettings;
137
- const pnpSettingsToUse = {
138
- usePnP,
139
- pnpFiles,
140
- };
141
- const pathToSettingsDir = path.dirname(pathToSettingsFile);
142
- loadPnPSync(pnpSettingsToUse, vscode_uri_1.URI.file(pathToSettingsDir));
143
- // Fix up dictionaryDefinitions
144
- const settings = {
145
- version: defaultSettings.version,
146
- ...rawSettings,
147
- id,
148
- name,
149
- globRoot: resolveGlobRoot(rawSettings, pathToSettingsFile),
150
- languageSettings: normalizeLanguageSettings(rawSettings.languageSettings),
151
- };
152
- const pathToSettings = path.dirname(pathToSettingsFile);
153
- const normalizedDictionaryDefs = normalizeDictionaryDefs(settings, pathToSettingsFile);
154
- const normalizedSettingsGlobs = normalizeSettingsGlobs(settings, pathToSettingsFile);
155
- const normalizedOverrides = normalizeOverrides(settings, pathToSettingsFile);
156
- const normalizedReporters = normalizeReporters(settings, pathToSettingsFile);
157
- const normalizedGitignoreRoot = normalizeGitignoreRoot(settings, pathToSettingsFile);
158
- const normalizedCacheSettings = normalizeCacheSettings(settings, pathToSettingsDir);
159
- const imports = typeof settings.import === 'string' ? [settings.import] : settings.import || [];
160
- const source = settings.source || {
161
- name: settings.name,
162
- filename: pathToSettingsFile,
163
- };
164
- const fileSettings = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({
165
- ...settings,
166
- source,
167
- ...normalizedDictionaryDefs,
168
- ...normalizedSettingsGlobs,
169
- ...normalizedOverrides,
170
- ...normalizedReporters,
171
- ...normalizedGitignoreRoot,
172
- ...normalizedCacheSettings,
173
- });
174
- if (!imports.length) {
175
- return fileSettings;
176
- }
177
- const importedSettings = imports
178
- .map((name) => resolveFilename(name, pathToSettings))
179
- .map((ref) => ((ref.referencedBy = [source]), ref))
180
- .map((ref) => importSettings(ref, undefined, pnpSettingsToUse))
181
- .reduce((a, b) => (0, CSpellSettingsServer_1.mergeSettings)(a, b));
182
- const finalizeSettings = (0, CSpellSettingsServer_1.mergeSettings)(importedSettings, fileSettings);
183
- finalizeSettings.name = settings.name || finalizeSettings.name || '';
184
- finalizeSettings.id = settings.id || finalizeSettings.id || '';
185
- return finalizeSettings;
186
- }
187
- function mergeSourceList(orig, append) {
188
- const collection = new Map(orig.map((s) => [s.name + (s.filename || ''), s]));
189
- for (const s of append || []) {
190
- const key = s.name + (s.filename || '');
191
- if (!collection.has(key)) {
192
- collection.set(key, s);
193
- }
194
- }
195
- return [...collection.values()];
196
- }
197
- function importSettings(fileRef, defaultValues, pnpSettings) {
198
- defaultValues = defaultValues ?? defaultSettings;
199
- const { filename } = fileRef;
200
- const importRef = { ...fileRef };
201
- const cached = cachedFiles.get(filename);
202
- if (cached) {
203
- const cachedImportRef = cached.__importRef || importRef;
204
- cachedImportRef.referencedBy = mergeSourceList(cachedImportRef.referencedBy || [], importRef.referencedBy);
205
- cached.__importRef = cachedImportRef;
206
- return cached;
207
- }
208
- const id = [path.basename(path.dirname(filename)), path.basename(filename)].join('/');
209
- const name = id;
210
- const finalizeSettings = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({ id, name, __importRef: importRef });
211
- cachedFiles.set(filename, finalizeSettings); // add an empty entry to prevent circular references.
212
- const settings = { ...defaultValues, id, name, ...readConfig(importRef) };
213
- Object.assign(finalizeSettings, normalizeSettings(settings, filename, pnpSettings));
214
- const finalizeSrc = { name: path.basename(filename), ...finalizeSettings.source };
215
- finalizeSettings.source = { ...finalizeSrc, filename };
216
- cachedFiles.set(filename, finalizeSettings);
217
- return finalizeSettings;
218
- }
219
- function readSettings(filename, relativeToOrDefault, defaultValue) {
220
- const relativeTo = typeof relativeToOrDefault === 'string' ? relativeToOrDefault : process.cwd();
221
- defaultValue = defaultValue || (typeof relativeToOrDefault !== 'string' ? relativeToOrDefault : undefined);
222
- const ref = resolveFilename(filename, relativeTo);
223
- return importSettings(ref, defaultValue, defaultValue || defaultPnPSettings);
224
- }
225
- exports.readSettings = readSettings;
226
- async function normalizeSearchForConfigResultAsync(searchPath, searchResult, pnpSettings) {
227
- let result;
228
- try {
229
- result = (await searchResult) || undefined;
230
- }
231
- catch (cause) {
232
- result = new ImportError_1.ImportError(`Failed to find config file at: "${searchPath}"`, cause);
233
- }
234
- return normalizeSearchForConfigResult(searchPath, result, pnpSettings);
235
- }
236
- function normalizeSearchForConfigResult(searchPath, searchResult, pnpSettings) {
237
- const error = searchResult instanceof ImportError_1.ImportError ? searchResult : undefined;
238
- const result = searchResult instanceof ImportError_1.ImportError ? undefined : searchResult;
239
- const filepath = result?.filepath;
240
- if (filepath) {
241
- const cached = cachedFiles.get(filepath);
242
- if (cached) {
243
- return {
244
- config: cached,
245
- filepath,
246
- error,
247
- };
248
- }
249
- }
250
- const { config = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({}) } = result || {};
251
- const filename = result?.filepath ?? searchPath;
252
- const importRef = { filename: filename, error };
253
- const id = [path.basename(path.dirname(filename)), path.basename(filename)].join('/');
254
- const name = result?.filepath ? id : `Config not found: ${id}`;
255
- const finalizeSettings = (0, CSpellSettingsInternalDef_1.createCSpellSettingsInternal)({ id, name, __importRef: importRef });
256
- const settings = { id, ...config };
257
- cachedFiles.set(filename, finalizeSettings); // add an empty entry to prevent circular references.
258
- Object.assign(finalizeSettings, normalizeSettings(settings, filename, pnpSettings));
259
- return {
260
- config: finalizeSettings,
261
- filepath,
262
- error,
263
- };
264
- }
265
- function searchForConfig(searchFrom, pnpSettings = defaultPnPSettings) {
266
- return normalizeSearchForConfigResultAsync(searchFrom || process.cwd(), cspellConfigExplorer.search(searchFrom), pnpSettings).then((r) => (r.filepath ? r.config : undefined));
267
- }
268
- exports.searchForConfig = searchForConfig;
269
- function searchForConfigSync(searchFrom, pnpSettings = defaultPnPSettings) {
270
- let searchResult;
271
- try {
272
- searchResult = cspellConfigExplorerSync.search(searchFrom) || undefined;
273
- }
274
- catch (err) {
275
- searchResult = new ImportError_1.ImportError(`Failed to find config file from: "${searchFrom}"`, err);
276
- }
277
- return normalizeSearchForConfigResult(searchFrom || process.cwd(), searchResult, pnpSettings).config;
278
- }
279
- exports.searchForConfigSync = searchForConfigSync;
280
- /**
281
- * Load a CSpell configuration files.
282
- * @param file - path or package reference to load.
283
- * @param pnpSettings - PnP settings
284
- * @returns normalized CSpellSettings
285
- */
286
- function loadConfig(file, pnpSettings = defaultPnPSettings) {
287
- const cached = cachedFiles.get(path.resolve(file));
288
- if (cached) {
289
- return Promise.resolve(cached);
290
- }
291
- return normalizeSearchForConfigResultAsync(file, cspellConfigExplorer.load(file), pnpSettings).then((r) => r.config);
292
- }
293
- exports.loadConfig = loadConfig;
294
- /**
295
- * Load a CSpell configuration files.
296
- * @param filename - path or package reference to load.
297
- * @param pnpSettings - PnP settings
298
- * @returns normalized CSpellSettings
299
- */
300
- function loadConfigSync(filename, pnpSettings = defaultPnPSettings) {
301
- const cached = cachedFiles.get(path.resolve(filename));
302
- if (cached) {
303
- return cached;
304
- }
305
- let searchResult;
306
- try {
307
- searchResult = cspellConfigExplorerSync.load(filename) || undefined;
308
- }
309
- catch (err) {
310
- searchResult = new ImportError_1.ImportError(`Failed to find config file at: "${filename}"`, err);
311
- }
312
- return normalizeSearchForConfigResult(filename, searchResult, pnpSettings).config;
313
- }
314
- exports.loadConfigSync = loadConfigSync;
315
- function loadPnP(pnpSettings, searchFrom) {
316
- if (!pnpSettings.usePnP) {
317
- return Promise.resolve(undefined);
318
- }
319
- const loader = (0, pnpLoader_1.pnpLoader)(pnpSettings.pnpFiles);
320
- return loader.load(searchFrom);
321
- }
322
- exports.loadPnP = loadPnP;
323
- function loadPnPSync(pnpSettings, searchFrom) {
324
- if (!pnpSettings.usePnP) {
325
- return undefined;
326
- }
327
- const loader = (0, pnpLoader_1.pnpLoader)(pnpSettings.pnpFiles);
328
- return loader.loadSync(searchFrom);
329
- }
330
- exports.loadPnPSync = loadPnPSync;
331
- function readRawSettings(filename, relativeTo) {
332
- relativeTo = relativeTo || process.cwd();
333
- const ref = resolveFilename(filename, relativeTo);
334
- return readConfig(ref);
335
- }
336
- exports.readRawSettings = readRawSettings;
337
- /**
338
- *
339
- * @param filenames - settings files to read
340
- * @returns combined configuration
341
- * @deprecated true
342
- */
343
- function readSettingsFiles(filenames) {
344
- return filenames.map((filename) => readSettings(filename)).reduce((a, b) => (0, CSpellSettingsServer_1.mergeSettings)(a, b), defaultSettings);
345
- }
346
- exports.readSettingsFiles = readSettingsFiles;
347
- function resolveFilename(filename, relativeTo) {
348
- const r = (0, resolveFile_1.resolveFile)(filename, relativeTo);
349
- return {
350
- filename: r.filename,
351
- error: r.found ? undefined : new Error(`Failed to resolve file: "${filename}"`),
352
- };
353
- }
354
- function getGlobalSettings() {
355
- if (!globalSettings) {
356
- const globalConf = (0, GlobalSettings_1.getRawGlobalSettings)();
357
- globalSettings = {
358
- id: 'global_config',
359
- ...normalizeSettings(globalConf || {}, './global_config', {}),
360
- };
361
- }
362
- return globalSettings;
363
- }
364
- exports.getGlobalSettings = getGlobalSettings;
365
- function getCachedFileSize() {
366
- return cachedFiles.size;
367
- }
368
- exports.getCachedFileSize = getCachedFileSize;
369
- function clearCachedSettingsFiles() {
370
- globalSettings = undefined;
371
- cachedFiles.clear();
372
- cspellConfigExplorer.clearCaches();
373
- cspellConfigExplorerSync.clearCaches();
374
- }
375
- exports.clearCachedSettingsFiles = clearCachedSettingsFiles;
376
- function mergeImportRefs(left, right = {}) {
377
- const imports = new Map(left.__imports || []);
378
- if (left.__importRef) {
379
- imports.set(left.__importRef.filename, left.__importRef);
380
- }
381
- if (right.__importRef) {
382
- imports.set(right.__importRef.filename, right.__importRef);
383
- }
384
- const rightImports = right.__imports?.values() || [];
385
- for (const ref of rightImports) {
386
- imports.set(ref.filename, ref);
387
- }
388
- return imports.size ? imports : undefined;
389
- }
390
- function isImportFileRefWithError(ref) {
391
- return !!ref.error;
392
- }
393
- function extractImportErrors(settings) {
394
- const imports = mergeImportRefs(settings);
395
- return !imports ? [] : [...imports.values()].filter(isImportFileRefWithError);
396
- }
397
- exports.extractImportErrors = extractImportErrors;
398
- function resolveGlobRoot(settings, pathToSettingsFile) {
399
- const settingsFileDirRaw = path.dirname(pathToSettingsFile);
400
- const isVSCode = path.basename(settingsFileDirRaw) === '.vscode';
401
- const settingsFileDir = isVSCode ? path.dirname(settingsFileDirRaw) : settingsFileDirRaw;
402
- const envGlobRoot = process.env[CSpellSettingsServer_1.ENV_CSPELL_GLOB_ROOT];
403
- const defaultGlobRoot = envGlobRoot ?? '${cwd}';
404
- const rawRoot = settings.globRoot ??
405
- (settings.version === CSpellSettingsServer_1.configSettingsFileVersion0_1 ||
406
- (envGlobRoot && !settings.version) ||
407
- (isVSCode && !settings.version)
408
- ? defaultGlobRoot
409
- : settingsFileDir);
410
- const globRoot = rawRoot.startsWith('${cwd}') ? rawRoot : path.resolve(settingsFileDir, rawRoot);
411
- return globRoot;
412
- }
413
- function resolveFilePath(filename, pathToSettingsFile) {
414
- const cwd = process.cwd();
415
- return path.resolve(pathToSettingsFile, filename.replace('${cwd}', cwd));
416
- }
417
- function toGlobDef(g, root, source) {
418
- if (g === undefined)
419
- return undefined;
420
- if (Array.isArray(g)) {
421
- return g.map((g) => toGlobDef(g, root, source));
422
- }
423
- if (typeof g === 'string') {
424
- const glob = { glob: g };
425
- if (root !== undefined) {
426
- glob.root = root;
427
- }
428
- return toGlobDef(glob, root, source);
429
- }
430
- if (source) {
431
- return { ...g, source };
432
- }
433
- return g;
434
- }
435
- function normalizeDictionaryDefs(settings, pathToSettingsFile) {
436
- const dictionaryDefinitions = (0, DictionarySettings_1.mapDictDefsToInternal)(settings.dictionaryDefinitions, pathToSettingsFile);
437
- const languageSettings = settings.languageSettings?.map((langSetting) => util.clean({
438
- ...langSetting,
439
- dictionaryDefinitions: (0, DictionarySettings_1.mapDictDefsToInternal)(langSetting.dictionaryDefinitions, pathToSettingsFile),
440
- }));
441
- return util.clean({
442
- dictionaryDefinitions,
443
- languageSettings,
444
- });
445
- }
446
- function normalizeOverrides(settings, pathToSettingsFile) {
447
- const { globRoot = path.dirname(pathToSettingsFile) } = settings;
448
- const overrides = settings.overrides?.map((override) => {
449
- const filename = toGlobDef(override.filename, globRoot, pathToSettingsFile);
450
- const { dictionaryDefinitions, languageSettings } = normalizeDictionaryDefs(override, pathToSettingsFile);
451
- return util.clean({
452
- ...override,
453
- filename,
454
- dictionaryDefinitions,
455
- languageSettings: normalizeLanguageSettings(languageSettings),
456
- });
457
- });
458
- return overrides ? { overrides } : {};
459
- }
460
- function normalizeReporters(settings, pathToSettingsFile) {
461
- if (settings.reporters === undefined)
462
- return {};
463
- const folder = path.dirname(pathToSettingsFile);
464
- function resolve(s) {
465
- const r = (0, resolveFile_1.resolveFile)(s, folder);
466
- if (!r.found) {
467
- throw new Error(`Not found: "${s}"`);
468
- }
469
- return r.filename;
470
- }
471
- function resolveReporter(s) {
472
- if (typeof s === 'string') {
473
- return resolve(s);
474
- }
475
- if (!Array.isArray(s) || typeof s[0] !== 'string')
476
- throw new Error('Invalid Reporter');
477
- // Preserve the shape of Reporter Setting while resolving the reporter file.
478
- const [r, ...rest] = s;
479
- return [resolve(r), ...rest];
480
- }
481
- return {
482
- reporters: settings.reporters.map(resolveReporter),
483
- };
484
- }
485
- function normalizeLanguageSettings(languageSettings) {
486
- if (!languageSettings)
487
- return undefined;
488
- function fixLocale(s) {
489
- const { local: locale, ...rest } = s;
490
- return util.clean({ locale, ...rest });
491
- }
492
- return languageSettings.map(fixLocale);
493
- }
494
- function normalizeGitignoreRoot(settings, pathToSettingsFile) {
495
- const { gitignoreRoot } = settings;
496
- if (!gitignoreRoot)
497
- return {};
498
- const dir = path.dirname(pathToSettingsFile);
499
- const roots = Array.isArray(gitignoreRoot) ? gitignoreRoot : [gitignoreRoot];
500
- return {
501
- gitignoreRoot: roots.map((p) => path.resolve(dir, p)),
502
- };
503
- }
504
- function normalizeSettingsGlobs(settings, pathToSettingsFile) {
505
- const { globRoot } = settings;
506
- if (settings.ignorePaths === undefined)
507
- return {};
508
- const ignorePaths = toGlobDef(settings.ignorePaths, globRoot, pathToSettingsFile);
509
- return {
510
- ignorePaths,
511
- };
512
- }
513
- function normalizeCacheSettings(settings, pathToSettingsDir) {
514
- const { cache } = settings;
515
- if (cache === undefined)
516
- return {};
517
- const { cacheLocation } = cache;
518
- if (cacheLocation === undefined)
519
- return { cache };
520
- return { cache: { ...cache, cacheLocation: resolveFilePath(cacheLocation, pathToSettingsDir) } };
521
- }
522
- function validationMessage(msg, fileRef) {
523
- return msg + `\n File: "${fileRef.filename}"`;
524
- }
525
- function validateRawConfigVersion(config, fileRef) {
526
- const { version } = config;
527
- if (version === undefined)
528
- return;
529
- if (typeof version !== 'string') {
530
- (0, logger_1.logError)(validationMessage(`Unsupported config file version: "${version}", string expected`, fileRef));
531
- return;
532
- }
533
- if (setOfSupportedConfigVersions.has(version))
534
- return;
535
- if (!/^\d+(\.\d+)*$/.test(version)) {
536
- (0, logger_1.logError)(validationMessage(`Unsupported config file version: "${version}"`, fileRef));
537
- return;
538
- }
539
- const msg = version > CSpellSettingsServer_1.currentSettingsFileVersion
540
- ? `Newer config file version found: "${version}". Supported version is "${CSpellSettingsServer_1.currentSettingsFileVersion}"`
541
- : `Legacy config file version found: "${version}", upgrade to "${CSpellSettingsServer_1.currentSettingsFileVersion}"`;
542
- (0, logger_1.logWarning)(validationMessage(msg, fileRef));
543
- }
544
- function validateRawConfigExports(config, fileRef) {
545
- if (config.default) {
546
- throw new ImportError_1.ImportError(validationMessage('Module `export default` is not supported.\n Use `module.exports =` instead.', fileRef));
547
- }
548
- }
549
- function normalizeRawConfig(config) {
550
- if (typeof config.version === 'number') {
551
- config.version = config.version.toString();
552
- }
553
- }
554
- function validateRawConfig(config, fileRef) {
555
- const validations = [validateRawConfigExports, validateRawConfigVersion];
556
- validations.forEach((fn) => fn(config, fileRef));
557
- }
558
- exports.__testing__ = {
559
- normalizeCacheSettings,
560
- normalizeSettings,
561
- validateRawConfigExports,
562
- validateRawConfigVersion,
563
- };
564
- //# sourceMappingURL=configLoader.js.map