cspell-lib 8.2.4 → 8.3.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/esm/Settings/Controller/configLoader/configLoader.d.ts +9 -0
- package/dist/esm/Settings/Controller/configLoader/configLoader.js +36 -5
- package/dist/esm/Settings/Controller/configLoader/configSearch.d.ts +8 -1
- package/dist/esm/Settings/Controller/configLoader/configSearch.js +20 -3
- package/dist/esm/Settings/DefaultSettings.js +1 -1
- package/dist/esm/Settings/constants.d.ts +1 -0
- package/dist/esm/Settings/constants.js +1 -0
- package/package.json +14 -14
|
@@ -49,6 +49,7 @@ export interface IConfigLoader {
|
|
|
49
49
|
* @returns the resulting settings
|
|
50
50
|
*/
|
|
51
51
|
searchForConfig(searchFrom: URL | string | undefined, pnpSettings?: PnPSettingsOptional): Promise<CSpellSettingsI | undefined>;
|
|
52
|
+
resolveConfigFileLocation(filenameOrURL: string | URL, relativeTo?: string | URL): Promise<URL | undefined>;
|
|
52
53
|
getGlobalSettingsAsync(): Promise<CSpellSettingsI>;
|
|
53
54
|
/**
|
|
54
55
|
* The loader caches configuration files for performance. This method clears the cache.
|
|
@@ -71,12 +72,15 @@ export interface IConfigLoader {
|
|
|
71
72
|
*/
|
|
72
73
|
dispose(): void;
|
|
73
74
|
getStats(): Readonly<Record<string, Readonly<Record<string, number>>>>;
|
|
75
|
+
readonly isTrusted: boolean;
|
|
76
|
+
setIsTrusted(isTrusted: boolean): void;
|
|
74
77
|
}
|
|
75
78
|
export declare class ConfigLoader implements IConfigLoader {
|
|
76
79
|
readonly fs: VFileSystem;
|
|
77
80
|
readonly templateVariables: Record<string, string>;
|
|
78
81
|
onReady: Promise<void>;
|
|
79
82
|
readonly fileResolver: FileResolver;
|
|
83
|
+
private _isTrusted;
|
|
80
84
|
/**
|
|
81
85
|
* Use `createConfigLoader`
|
|
82
86
|
* @param virtualFs - virtual file system to use.
|
|
@@ -107,7 +111,9 @@ export declare class ConfigLoader implements IConfigLoader {
|
|
|
107
111
|
getGlobalSettings(): CSpellSettingsI;
|
|
108
112
|
getGlobalSettingsAsync(): Promise<CSpellSettingsI>;
|
|
109
113
|
clearCachedSettingsFiles(): void;
|
|
114
|
+
protected init(): Promise<void>;
|
|
110
115
|
protected prefetchGlobalSettingsAsync(): Promise<void>;
|
|
116
|
+
protected resolveDefaultConfig(): Promise<URL>;
|
|
111
117
|
protected importSettings(fileRef: ImportFileRef, pnpSettings: PnPSettingsOptional | undefined, backReferences: string[]): ImportedConfigEntry;
|
|
112
118
|
private setupPnp;
|
|
113
119
|
mergeConfigFileWithImports(cfgFile: CSpellConfigFile, pnpSettings: PnPSettingsOptional | undefined, referencedBy?: string[] | undefined): Promise<CSpellSettingsI>;
|
|
@@ -124,7 +130,10 @@ export declare class ConfigLoader implements IConfigLoader {
|
|
|
124
130
|
cacheMergeListUnique: Readonly<import("../../../util/AutoResolve.js").CacheStats>;
|
|
125
131
|
cacheMergeLists: Readonly<import("../../../util/AutoResolve.js").CacheStats>;
|
|
126
132
|
};
|
|
133
|
+
resolveConfigFileLocation(filenameOrURL: string | URL, relativeTo: string | URL): Promise<URL | undefined>;
|
|
127
134
|
private resolveFilename;
|
|
135
|
+
get isTrusted(): boolean;
|
|
136
|
+
setIsTrusted(isTrusted: boolean): void;
|
|
128
137
|
}
|
|
129
138
|
declare class ConfigLoaderInternal extends ConfigLoader {
|
|
130
139
|
constructor(vfs: VFileSystem);
|
|
@@ -4,6 +4,7 @@ import { isUrlLike, toFileURL } from 'cspell-io';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
6
6
|
import { URI, Utils as UriUtils } from 'vscode-uri';
|
|
7
|
+
import { srcDirectory } from '../../../../lib-cjs/index.cjs';
|
|
7
8
|
import { onClearCache } from '../../../events/index.js';
|
|
8
9
|
import { getVirtualFS } from '../../../fileSystem.js';
|
|
9
10
|
import { createCSpellSettingsInternal as csi } from '../../../Models/CSpellSettingsInternalDef.js';
|
|
@@ -12,7 +13,7 @@ import { logError, logWarning } from '../../../util/logger.js';
|
|
|
12
13
|
import { FileResolver } from '../../../util/resolveFile.js';
|
|
13
14
|
import { envToTemplateVars } from '../../../util/templates.js';
|
|
14
15
|
import { addTrailingSlash, cwdURL, resolveFileWithURL, toFilePathOrHref, windowsDriveLetterToUpper, } from '../../../util/url.js';
|
|
15
|
-
import { configSettingsFileVersion0_1, configSettingsFileVersion0_2, currentSettingsFileVersion, ENV_CSPELL_GLOB_ROOT, } from '../../constants.js';
|
|
16
|
+
import { configSettingsFileVersion0_1, configSettingsFileVersion0_2, currentSettingsFileVersion, defaultConfigFileModuleRef, ENV_CSPELL_GLOB_ROOT, } from '../../constants.js';
|
|
16
17
|
import { getMergeStats, mergeSettings } from '../../CSpellSettingsServer.js';
|
|
17
18
|
import { getGlobalConfig } from '../../GlobalSettings.js';
|
|
18
19
|
import { ImportError } from '../ImportError.js';
|
|
@@ -28,11 +29,19 @@ const setOfSupportedConfigVersions = Object.freeze(new Set(supportedCSpellConfig
|
|
|
28
29
|
export const sectionCSpell = 'cSpell';
|
|
29
30
|
export const defaultFileName = 'cspell.json';
|
|
30
31
|
let defaultConfigLoader = undefined;
|
|
32
|
+
const defaultExtensions = ['.json', '.yaml', '.yml', '.jsonc'];
|
|
33
|
+
const defaultJsExtensions = ['.js', '.cjs', '.mjs'];
|
|
34
|
+
const trustedSearch = new Map([
|
|
35
|
+
['*', defaultExtensions],
|
|
36
|
+
['file:', [...defaultExtensions, ...defaultJsExtensions]],
|
|
37
|
+
]);
|
|
38
|
+
const unTrustedSearch = new Map([['*', defaultExtensions]]);
|
|
31
39
|
export class ConfigLoader {
|
|
32
40
|
fs;
|
|
33
41
|
templateVariables;
|
|
34
42
|
onReady;
|
|
35
43
|
fileResolver;
|
|
44
|
+
_isTrusted = true;
|
|
36
45
|
/**
|
|
37
46
|
* Use `createConfigLoader`
|
|
38
47
|
* @param virtualFs - virtual file system to use.
|
|
@@ -40,10 +49,10 @@ export class ConfigLoader {
|
|
|
40
49
|
constructor(fs, templateVariables = envToTemplateVars(process.env)) {
|
|
41
50
|
this.fs = fs;
|
|
42
51
|
this.templateVariables = templateVariables;
|
|
43
|
-
this.configSearch = new ConfigSearch(searchPlaces, fs);
|
|
52
|
+
this.configSearch = new ConfigSearch(searchPlaces, trustedSearch, fs);
|
|
44
53
|
this.cspellConfigFileReaderWriter = createReaderWriter(undefined, undefined, createIO(fs));
|
|
45
54
|
this.fileResolver = new FileResolver(fs, this.templateVariables);
|
|
46
|
-
this.onReady = this.
|
|
55
|
+
this.onReady = this.init();
|
|
47
56
|
this.subscribeToEvents();
|
|
48
57
|
}
|
|
49
58
|
subscribeToEvents() {
|
|
@@ -140,10 +149,19 @@ export class ConfigLoader {
|
|
|
140
149
|
this.cachedMergedConfig = new WeakMap();
|
|
141
150
|
this.prefetchGlobalSettingsAsync();
|
|
142
151
|
}
|
|
143
|
-
|
|
144
|
-
this.onReady = this.
|
|
152
|
+
init() {
|
|
153
|
+
this.onReady = Promise.all([this.prefetchGlobalSettingsAsync(), this.resolveDefaultConfig()]).then(() => undefined);
|
|
145
154
|
return this.onReady;
|
|
146
155
|
}
|
|
156
|
+
async prefetchGlobalSettingsAsync() {
|
|
157
|
+
await this.getGlobalSettingsAsync().catch((e) => logError(e));
|
|
158
|
+
}
|
|
159
|
+
async resolveDefaultConfig() {
|
|
160
|
+
const r = await this.fileResolver.resolveFile(defaultConfigFileModuleRef, srcDirectory);
|
|
161
|
+
const url = toFileURL(r.filename);
|
|
162
|
+
this.cspellConfigFileReaderWriter.setTrustedUrls([new URL('../..', url)]);
|
|
163
|
+
return url;
|
|
164
|
+
}
|
|
147
165
|
importSettings(fileRef, pnpSettings, backReferences) {
|
|
148
166
|
const url = toFileURL(fileRef.filename);
|
|
149
167
|
const cacheKey = url.href;
|
|
@@ -318,6 +336,10 @@ export class ConfigLoader {
|
|
|
318
336
|
getStats() {
|
|
319
337
|
return { ...getMergeStats() };
|
|
320
338
|
}
|
|
339
|
+
async resolveConfigFileLocation(filenameOrURL, relativeTo) {
|
|
340
|
+
const r = await this.fileResolver.resolveFile(filenameOrURL, relativeTo);
|
|
341
|
+
return r.found ? toFileURL(r.filename) : undefined;
|
|
342
|
+
}
|
|
321
343
|
async resolveFilename(filename, relativeTo) {
|
|
322
344
|
if (filename instanceof URL)
|
|
323
345
|
return { filename: toFilePathOrHref(filename) };
|
|
@@ -332,6 +354,15 @@ export class ConfigLoader {
|
|
|
332
354
|
error: r.found ? undefined : new Error(`Failed to resolve file: "${filename}"`),
|
|
333
355
|
};
|
|
334
356
|
}
|
|
357
|
+
get isTrusted() {
|
|
358
|
+
return this._isTrusted;
|
|
359
|
+
}
|
|
360
|
+
setIsTrusted(isTrusted) {
|
|
361
|
+
this._isTrusted = isTrusted;
|
|
362
|
+
this.clearCachedSettingsFiles();
|
|
363
|
+
this.configSearch = new ConfigSearch(searchPlaces, isTrusted ? trustedSearch : unTrustedSearch, this.fs);
|
|
364
|
+
this.cspellConfigFileReaderWriter.setUntrustedExtensions(isTrusted ? [] : defaultJsExtensions);
|
|
365
|
+
}
|
|
335
366
|
}
|
|
336
367
|
class ConfigLoaderInternal extends ConfigLoader {
|
|
337
368
|
constructor(vfs) {
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { VFileSystem } from '../../../fileSystem.js';
|
|
2
2
|
export declare class ConfigSearch {
|
|
3
3
|
readonly searchPlaces: readonly string[];
|
|
4
|
+
readonly allowedExtensionsByProtocol: Map<string, readonly string[]>;
|
|
4
5
|
private fs;
|
|
5
6
|
private searchCache;
|
|
6
7
|
private searchDirCache;
|
|
7
|
-
|
|
8
|
+
private searchPlacesByProtocol;
|
|
9
|
+
/**
|
|
10
|
+
* @param searchPlaces - The list of file names to search for.
|
|
11
|
+
* @param allowedExtensionsByProtocol - Map of allowed extensions by protocol, '*' is used to match all protocols.
|
|
12
|
+
* @param fs - The file system to use.
|
|
13
|
+
*/
|
|
14
|
+
constructor(searchPlaces: readonly string[], allowedExtensionsByProtocol: Map<string, readonly string[]>, fs: VFileSystem);
|
|
8
15
|
searchForConfig(searchFromURL: URL): Promise<URL | undefined>;
|
|
9
16
|
clearCache(): void;
|
|
10
17
|
private findUpConfigPath;
|
|
@@ -1,15 +1,25 @@
|
|
|
1
|
+
import { extname } from 'node:path/posix';
|
|
1
2
|
import { urlBasename } from 'cspell-io';
|
|
2
3
|
import { createAutoResolveCache } from '../../../util/AutoResolve.js';
|
|
3
4
|
import { findUpFromUrl } from '../../../util/findUpFromUrl.js';
|
|
4
5
|
export class ConfigSearch {
|
|
5
6
|
searchPlaces;
|
|
7
|
+
allowedExtensionsByProtocol;
|
|
6
8
|
fs;
|
|
7
9
|
searchCache = new Map();
|
|
8
10
|
searchDirCache = new Map();
|
|
9
|
-
|
|
11
|
+
searchPlacesByProtocol;
|
|
12
|
+
/**
|
|
13
|
+
* @param searchPlaces - The list of file names to search for.
|
|
14
|
+
* @param allowedExtensionsByProtocol - Map of allowed extensions by protocol, '*' is used to match all protocols.
|
|
15
|
+
* @param fs - The file system to use.
|
|
16
|
+
*/
|
|
17
|
+
constructor(searchPlaces, allowedExtensionsByProtocol, fs) {
|
|
10
18
|
this.searchPlaces = searchPlaces;
|
|
19
|
+
this.allowedExtensionsByProtocol = allowedExtensionsByProtocol;
|
|
11
20
|
this.fs = fs;
|
|
12
|
-
this.
|
|
21
|
+
this.searchPlacesByProtocol = setupSearchPlacesByProtocol(searchPlaces, allowedExtensionsByProtocol);
|
|
22
|
+
this.searchPlaces = this.searchPlacesByProtocol.get('*') || searchPlaces;
|
|
13
23
|
}
|
|
14
24
|
searchForConfig(searchFromURL) {
|
|
15
25
|
const dirUrl = new URL('.', searchFromURL);
|
|
@@ -105,7 +115,8 @@ export class ConfigSearch {
|
|
|
105
115
|
const hasFile = this.fs.getCapabilities(dir).readDirectory
|
|
106
116
|
? this.createHasFileDirSearch()
|
|
107
117
|
: this.createHasFileStatCheck();
|
|
108
|
-
|
|
118
|
+
const searchPlaces = this.searchPlacesByProtocol.get(dir.protocol) || this.searchPlaces;
|
|
119
|
+
for (const searchPlace of searchPlaces) {
|
|
109
120
|
const file = new URL(searchPlace, dir);
|
|
110
121
|
const found = await hasFile(file);
|
|
111
122
|
if (found) {
|
|
@@ -118,6 +129,12 @@ export class ConfigSearch {
|
|
|
118
129
|
return undefined;
|
|
119
130
|
}
|
|
120
131
|
}
|
|
132
|
+
function setupSearchPlacesByProtocol(searchPlaces, allowedExtensionsByProtocol) {
|
|
133
|
+
const map = new Map([...allowedExtensionsByProtocol.entries()]
|
|
134
|
+
.map(([k, v]) => [k, new Set(v)])
|
|
135
|
+
.map(([protocol, exts]) => [protocol, searchPlaces.filter((url) => exts.has(extname(url)))]));
|
|
136
|
+
return map;
|
|
137
|
+
}
|
|
121
138
|
async function checkPackageJson(fs, filename) {
|
|
122
139
|
try {
|
|
123
140
|
const file = await fs.readFile(filename);
|
|
@@ -3,11 +3,11 @@ import { srcDirectory } from '../../lib-cjs/index.cjs';
|
|
|
3
3
|
import { createCSpellSettingsInternal } from '../Models/CSpellSettingsInternalDef.js';
|
|
4
4
|
import { PatternRegExp } from '../Models/PatternRegExp.js';
|
|
5
5
|
import { resolveFile } from '../util/resolveFile.js';
|
|
6
|
+
import { defaultConfigFileModuleRef } from './constants.js';
|
|
6
7
|
import { readSettings } from './Controller/configLoader/index.js';
|
|
7
8
|
import { mergeSettings } from './CSpellSettingsServer.js';
|
|
8
9
|
import * as LanguageSettings from './LanguageSettings.js';
|
|
9
10
|
import * as RegPat from './RegExpPatterns.js';
|
|
10
|
-
const defaultConfigFileModuleRef = '@cspell/cspell-bundled-dicts/cspell-default.json';
|
|
11
11
|
// Do not use require.resolve because webpack will mess it up.
|
|
12
12
|
const defaultConfigFile = () => resolveConfigModule(defaultConfigFileModuleRef);
|
|
13
13
|
const regExpSpellCheckerDisable = [
|
|
@@ -2,4 +2,5 @@ export declare const configSettingsFileVersion0_1 = "0.1";
|
|
|
2
2
|
export declare const configSettingsFileVersion0_2 = "0.2";
|
|
3
3
|
export declare const currentSettingsFileVersion = "0.2";
|
|
4
4
|
export declare const ENV_CSPELL_GLOB_ROOT = "CSPELL_GLOB_ROOT";
|
|
5
|
+
export declare const defaultConfigFileModuleRef = "@cspell/cspell-bundled-dicts/cspell-default.json";
|
|
5
6
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -2,4 +2,5 @@ export const configSettingsFileVersion0_1 = '0.1';
|
|
|
2
2
|
export const configSettingsFileVersion0_2 = '0.2';
|
|
3
3
|
export const currentSettingsFileVersion = configSettingsFileVersion0_2;
|
|
4
4
|
export const ENV_CSPELL_GLOB_ROOT = 'CSPELL_GLOB_ROOT';
|
|
5
|
+
export const defaultConfigFileModuleRef = '@cspell/cspell-bundled-dicts/cspell-default.json';
|
|
5
6
|
//# sourceMappingURL=constants.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-lib",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.3.0",
|
|
4
4
|
"description": "A library of useful functions used across various cspell tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -57,21 +57,21 @@
|
|
|
57
57
|
},
|
|
58
58
|
"homepage": "https://github.com/streetsidesoftware/cspell#readme",
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@cspell/cspell-bundled-dicts": "8.
|
|
61
|
-
"@cspell/cspell-pipe": "8.
|
|
62
|
-
"@cspell/cspell-resolver": "8.
|
|
63
|
-
"@cspell/cspell-types": "8.
|
|
64
|
-
"@cspell/dynamic-import": "8.
|
|
65
|
-
"@cspell/strong-weak-map": "8.
|
|
60
|
+
"@cspell/cspell-bundled-dicts": "8.3.0",
|
|
61
|
+
"@cspell/cspell-pipe": "8.3.0",
|
|
62
|
+
"@cspell/cspell-resolver": "8.3.0",
|
|
63
|
+
"@cspell/cspell-types": "8.3.0",
|
|
64
|
+
"@cspell/dynamic-import": "8.3.0",
|
|
65
|
+
"@cspell/strong-weak-map": "8.3.0",
|
|
66
66
|
"clear-module": "^4.1.2",
|
|
67
67
|
"comment-json": "^4.2.3",
|
|
68
68
|
"configstore": "^6.0.0",
|
|
69
|
-
"cspell-config-lib": "8.
|
|
70
|
-
"cspell-dictionary": "8.
|
|
71
|
-
"cspell-glob": "8.
|
|
72
|
-
"cspell-grammar": "8.
|
|
73
|
-
"cspell-io": "8.
|
|
74
|
-
"cspell-trie-lib": "8.
|
|
69
|
+
"cspell-config-lib": "8.3.0",
|
|
70
|
+
"cspell-dictionary": "8.3.0",
|
|
71
|
+
"cspell-glob": "8.3.0",
|
|
72
|
+
"cspell-grammar": "8.3.0",
|
|
73
|
+
"cspell-io": "8.3.0",
|
|
74
|
+
"cspell-trie-lib": "8.3.0",
|
|
75
75
|
"fast-equals": "^5.0.1",
|
|
76
76
|
"gensequence": "^6.0.0",
|
|
77
77
|
"import-fresh": "^3.3.0",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
"cspell-dict-nl-nl": "^1.1.2",
|
|
96
96
|
"lorem-ipsum": "^2.0.8"
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "019c7ccd326b7fc9e106069ddf6008d5079bbd12"
|
|
99
99
|
}
|