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