cspell-lib 8.1.0 → 8.1.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.
@@ -31,7 +31,46 @@ interface CacheMergeConfigFileWithImports {
31
31
  referencedBy: string[] | undefined;
32
32
  result: Promise<CSpellSettingsI>;
33
33
  }
34
- export declare class ConfigLoader {
34
+ export interface IConfigLoader {
35
+ readSettingsAsync(filename: string | URL, relativeTo?: string | URL, pnpSettings?: PnPSettingsOptional): Promise<CSpellSettingsI>;
36
+ /**
37
+ * Read a cspell configuration file.
38
+ * @param filenameOrURL - URL, relative path, absolute path, or package name.
39
+ * @param relativeTo - optional URL, defaults to `pathToFileURL('./')`
40
+ */
41
+ readConfigFile(filenameOrURL: string | URL, relativeTo?: string | URL): Promise<CSpellConfigFile | Error>;
42
+ searchForConfigFileLocation(searchFrom: URL | string | undefined): Promise<URL | undefined>;
43
+ searchForConfigFile(searchFrom: URL | string | undefined): Promise<CSpellConfigFile | undefined>;
44
+ /**
45
+ * This is an alias for `searchForConfigFile` and `mergeConfigFileWithImports`.
46
+ * @param searchFrom the directory / file URL to start searching from.
47
+ * @param pnpSettings - related to Using Yarn PNP.
48
+ * @returns the resulting settings
49
+ */
50
+ searchForConfig(searchFrom: URL | string | undefined, pnpSettings?: PnPSettingsOptional): Promise<CSpellSettingsI | undefined>;
51
+ getGlobalSettingsAsync(): Promise<CSpellSettingsI>;
52
+ /**
53
+ * The loader caches configuration files for performance. This method clears the cache.
54
+ */
55
+ clearCachedSettingsFiles(): void;
56
+ /**
57
+ * Resolve imports and merge.
58
+ * @param cfgFile - configuration file.
59
+ * @param pnpSettings - optional settings related to Using Yarn PNP.
60
+ */
61
+ mergeConfigFileWithImports(cfgFile: CSpellConfigFile, pnpSettings?: PnPSettingsOptional | undefined): Promise<CSpellSettingsI>;
62
+ /**
63
+ * Create an in memory CSpellConfigFile.
64
+ * @param filename - URL to the file. Used to resolve imports.
65
+ * @param settings - settings to use.
66
+ */
67
+ createCSpellConfigFile(filename: URL | string, settings: CSpellUserSettings): CSpellConfigFile;
68
+ /**
69
+ * Unsubscribe from any events and dispose of any resources including caches.
70
+ */
71
+ dispose(): void;
72
+ }
73
+ export declare class ConfigLoader implements IConfigLoader {
35
74
  readonly cspellIO: CSpellIO;
36
75
  onReady: Promise<void>;
37
76
  /**
@@ -64,6 +103,7 @@ export declare class ConfigLoader {
64
103
  getGlobalSettings(): CSpellSettingsI;
65
104
  getGlobalSettingsAsync(): Promise<CSpellSettingsI>;
66
105
  clearCachedSettingsFiles(): void;
106
+ protected prefetchGlobalSettingsAsync(): Promise<void>;
67
107
  protected importSettings(fileRef: ImportFileRef, pnpSettings: PnPSettingsOptional | undefined, backReferences: string[]): ImportedConfigEntry;
68
108
  private setupPnp;
69
109
  mergeConfigFileWithImports(cfgFile: CSpellConfigFile, pnpSettings: PnPSettingsOptional | undefined, referencedBy?: string[] | undefined): Promise<CSpellSettingsI>;
@@ -83,7 +123,7 @@ declare class ConfigLoaderInternal extends ConfigLoader {
83
123
  }
84
124
  export declare function loadPnP(pnpSettings: PnPSettingsOptional, searchFrom: URL): Promise<LoaderResult>;
85
125
  declare function validateRawConfigVersion(config: CSpellConfigFile): void;
86
- export declare function createConfigLoader(cspellIO?: CSpellIO): ConfigLoader;
126
+ export declare function createConfigLoader(cspellIO?: CSpellIO): IConfigLoader;
87
127
  export declare function getDefaultConfigLoaderInternal(): ConfigLoaderInternal;
88
128
  export declare const __testing__: {
89
129
  getDefaultConfigLoaderInternal: typeof getDefaultConfigLoaderInternal;
@@ -2,7 +2,7 @@ import assert from 'assert';
2
2
  import { createReaderWriter, CSpellConfigFileInMemory } from 'cspell-config-lib';
3
3
  import { getDefaultCSpellIO } from 'cspell-io';
4
4
  import * as path from 'path';
5
- import { fileURLToPath } from 'url';
5
+ import { fileURLToPath, pathToFileURL } from 'url';
6
6
  import { onClearCache } from '../../../events/index.js';
7
7
  import { createCSpellSettingsInternal as csi } from '../../../Models/CSpellSettingsInternalDef.js';
8
8
  import { AutoResolveCache } from '../../../util/AutoResolve.js';
@@ -35,7 +35,7 @@ export class ConfigLoader {
35
35
  constructor(cspellIO) {
36
36
  this.cspellIO = cspellIO;
37
37
  this.cspellConfigFileReaderWriter = createReaderWriter(undefined, undefined, createIO(cspellIO));
38
- this.onReady = this.getGlobalSettingsAsync().then(() => undefined, (e) => logError(e));
38
+ this.onReady = this.prefetchGlobalSettingsAsync();
39
39
  this.subscribeToEvents();
40
40
  }
41
41
  subscribeToEvents() {
@@ -50,12 +50,13 @@ export class ConfigLoader {
50
50
  configSearch = new ConfigSearch(searchPlaces);
51
51
  toDispose = [];
52
52
  async readSettingsAsync(filename, relativeTo, pnpSettings) {
53
- const ref = resolveFilename(filename, relativeTo || process.cwd());
53
+ await this.onReady;
54
+ const ref = resolveFilename(filename, relativeTo || pathToFileURL('./'));
54
55
  const entry = this.importSettings(ref, pnpSettings || defaultPnPSettings, []);
55
56
  return entry.onReady;
56
57
  }
57
58
  async readConfigFile(filenameOrURL, relativeTo) {
58
- const ref = resolveFilename(filenameOrURL.toString(), relativeTo || process.cwd());
59
+ const ref = resolveFilename(filenameOrURL.toString(), relativeTo || pathToFileURL('./'));
59
60
  const url = this.cspellIO.toFileURL(ref.filename);
60
61
  const href = url.href;
61
62
  if (ref.error)
@@ -103,7 +104,7 @@ export class ConfigLoader {
103
104
  return this.mergeConfigFileWithImports(configFile, pnpSettings);
104
105
  }
105
106
  getGlobalSettings() {
106
- assert(this.globalSettings);
107
+ assert(this.globalSettings, 'Global settings not loaded');
107
108
  return this.globalSettings;
108
109
  }
109
110
  async getGlobalSettingsAsync() {
@@ -123,6 +124,11 @@ export class ConfigLoader {
123
124
  this.cachedPendingConfigFile.clear();
124
125
  this.cspellConfigFileReaderWriter.clearCachedFiles();
125
126
  this.cachedMergedConfig = new WeakMap();
127
+ this.prefetchGlobalSettingsAsync();
128
+ }
129
+ prefetchGlobalSettingsAsync() {
130
+ this.onReady = this.getGlobalSettingsAsync().then(() => undefined, (e) => logError(e));
131
+ return this.onReady;
126
132
  }
127
133
  importSettings(fileRef, pnpSettings, backReferences) {
128
134
  const url = this.cspellIO.toFileURL(fileRef.filename);
@@ -1,5 +1,5 @@
1
1
  import type { CSpellConfigFile } from 'cspell-config-lib';
2
- import type { ConfigLoader } from './configLoader.js';
2
+ import type { IConfigLoader } from './configLoader.js';
3
3
  import type { PnPSettingsOptional } from './PnPSettings.js';
4
4
  import type { CSpellSettingsI, CSpellSettingsWST } from './types.js';
5
5
  /**
@@ -29,6 +29,6 @@ export declare function getGlobalSettings(): CSpellSettingsI;
29
29
  export declare function getGlobalSettingsAsync(): Promise<CSpellSettingsI>;
30
30
  export declare function getCachedFileSize(): number;
31
31
  export declare function clearCachedSettingsFiles(): void;
32
- export declare function getDefaultConfigLoader(): ConfigLoader;
32
+ export declare function getDefaultConfigLoader(): IConfigLoader;
33
33
  export declare function readRawSettings(filename: string | URL, relativeTo?: string | URL): Promise<CSpellSettingsWST>;
34
34
  //# sourceMappingURL=defaultConfigLoader.d.ts.map
@@ -1,6 +1,6 @@
1
1
  export { __testing__, ConfigLoader, createConfigLoader, defaultFileName, loadPnP, sectionCSpell, } from './configLoader.js';
2
2
  export { defaultConfigFilenames } from './configLocations.js';
3
- export { clearCachedSettingsFiles, getCachedFileSize, getGlobalSettings, getGlobalSettingsAsync, loadConfig, readRawSettings, searchForConfig, } from './defaultConfigLoader.js';
3
+ export { clearCachedSettingsFiles, getCachedFileSize, getDefaultConfigLoader, getGlobalSettings, getGlobalSettingsAsync, loadConfig, readRawSettings, searchForConfig, } from './defaultConfigLoader.js';
4
4
  export { extractImportErrors, ImportFileRefWithError } from './extractImportErrors.js';
5
5
  export { readSettings } from './readSettings.js';
6
6
  export { readSettingsFiles } from './readSettingsFiles.js';
@@ -1,6 +1,6 @@
1
1
  export { __testing__, ConfigLoader, createConfigLoader, defaultFileName, loadPnP, sectionCSpell, } from './configLoader.js';
2
2
  export { defaultConfigFilenames } from './configLocations.js';
3
- export { clearCachedSettingsFiles, getCachedFileSize, getGlobalSettings, getGlobalSettingsAsync, loadConfig, readRawSettings, searchForConfig, } from './defaultConfigLoader.js';
3
+ export { clearCachedSettingsFiles, getCachedFileSize, getDefaultConfigLoader, getGlobalSettings, getGlobalSettingsAsync, loadConfig, readRawSettings, searchForConfig, } from './defaultConfigLoader.js';
4
4
  export { extractImportErrors } from './extractImportErrors.js';
5
5
  export { readSettings } from './readSettings.js';
6
6
  export { readSettingsFiles } from './readSettingsFiles.js';
@@ -1,7 +1,6 @@
1
1
  import { getDefaultConfigLoader } from './defaultConfigLoader.js';
2
2
  export async function readSettings(filename, relativeToOrPnP, pnpSettings) {
3
3
  const loader = getDefaultConfigLoader();
4
- await loader.onReady;
5
4
  const relativeTo = typeof relativeToOrPnP === 'string' || relativeToOrPnP instanceof URL ? relativeToOrPnP : undefined;
6
5
  const pnp = pnpSettings
7
6
  ? pnpSettings
@@ -1,7 +1,7 @@
1
1
  export { calcOverrideSettings } from './calcOverrideSettings.js';
2
2
  export { checkFilenameMatchesGlob } from './checkFilenameMatchesGlob.js';
3
3
  export { currentSettingsFileVersion, ENV_CSPELL_GLOB_ROOT } from './constants.js';
4
- export { clearCachedSettingsFiles, defaultConfigFilenames, defaultFileName, extractImportErrors, getCachedFileSize, getGlobalSettings, getGlobalSettingsAsync, loadConfig, loadPnP, readRawSettings, readSettings, readSettingsFiles, searchForConfig, sectionCSpell, } from './Controller/configLoader/index.js';
4
+ export { clearCachedSettingsFiles, createConfigLoader, defaultConfigFilenames, defaultFileName, extractImportErrors, getCachedFileSize, getDefaultConfigLoader, getGlobalSettings, getGlobalSettingsAsync, loadConfig, loadPnP, readRawSettings, readSettings, readSettingsFiles, searchForConfig, sectionCSpell, } from './Controller/configLoader/index.js';
5
5
  export { ImportError } from './Controller/ImportError.js';
6
6
  export type { ConfigurationDependencies, ImportFileRefWithError } from './CSpellSettingsServer.js';
7
7
  export { extractDependencies, finalizeSettings, getSources, mergeInDocSettings, mergeSettings, } from './CSpellSettingsServer.js';
@@ -1,7 +1,7 @@
1
1
  export { calcOverrideSettings } from './calcOverrideSettings.js';
2
2
  export { checkFilenameMatchesGlob } from './checkFilenameMatchesGlob.js';
3
3
  export { currentSettingsFileVersion, ENV_CSPELL_GLOB_ROOT } from './constants.js';
4
- export { clearCachedSettingsFiles, defaultConfigFilenames, defaultFileName, extractImportErrors, getCachedFileSize, getGlobalSettings, getGlobalSettingsAsync, loadConfig, loadPnP, readRawSettings, readSettings, readSettingsFiles, searchForConfig, sectionCSpell, } from './Controller/configLoader/index.js';
4
+ export { clearCachedSettingsFiles, createConfigLoader, defaultConfigFilenames, defaultFileName, extractImportErrors, getCachedFileSize, getDefaultConfigLoader, getGlobalSettings, getGlobalSettingsAsync, loadConfig, loadPnP, readRawSettings, readSettings, readSettingsFiles, searchForConfig, sectionCSpell, } from './Controller/configLoader/index.js';
5
5
  export { ImportError } from './Controller/ImportError.js';
6
6
  export { extractDependencies, finalizeSettings, getSources, mergeInDocSettings, mergeSettings, } from './CSpellSettingsServer.js';
7
7
  export { defaultSettingsLoader, getDefaultBundledSettingsAsync, getDefaultSettings } from './DefaultSettings.js';
@@ -8,7 +8,7 @@ export { FeatureFlag, FeatureFlags, getSystemFeatureFlags, UnknownFeatureFlagErr
8
8
  export { getLanguagesForBasename as getLanguageIdsForBaseFilename, getLanguagesForExt } from './LanguageIds.js';
9
9
  export type { CreateTextDocumentParams, TextDocument, TextDocumentLine, TextDocumentRef, } from './Models/TextDocument.js';
10
10
  export { createTextDocument, updateTextDocument } from './Models/TextDocument.js';
11
- export { calcOverrideSettings, checkFilenameMatchesGlob, type ConfigurationDependencies, currentSettingsFileVersion, defaultConfigFilenames, defaultFileName, ENV_CSPELL_GLOB_ROOT, extractDependencies, extractImportErrors, finalizeSettings, getCachedFileSize, getDefaultBundledSettingsAsync, getDefaultSettings, getGlobalSettings, getGlobalSettingsAsync, getSources, ImportError, type ImportFileRefWithError, loadConfig, loadPnP, mergeInDocSettings, mergeSettings, readRawSettings, readSettings, readSettingsFiles, searchForConfig, sectionCSpell, } from './Settings/index.js';
11
+ export { calcOverrideSettings, checkFilenameMatchesGlob, type ConfigurationDependencies, createConfigLoader, currentSettingsFileVersion, defaultConfigFilenames, defaultFileName, ENV_CSPELL_GLOB_ROOT, extractDependencies, extractImportErrors, finalizeSettings, getCachedFileSize, getDefaultBundledSettingsAsync, getDefaultConfigLoader, getDefaultSettings, getGlobalSettings, getGlobalSettingsAsync, getSources, ImportError, type ImportFileRefWithError, loadConfig, loadPnP, mergeInDocSettings, mergeSettings, readRawSettings, readSettings, readSettingsFiles, searchForConfig, sectionCSpell, } from './Settings/index.js';
12
12
  export { defaultFileName as defaultSettingsFilename } from './Settings/index.js';
13
13
  export { combineTextAndLanguageSettings, combineTextAndLanguageSettings as constructSettingsForText, } from './Settings/TextDocumentSettings.js';
14
14
  export { determineFinalDocumentSettings, DetermineFinalDocumentSettingsResult, spellCheckDocument, spellCheckFile, SpellCheckFileOptions, SpellCheckFileResult, } from './spellCheckFile.js';
package/dist/esm/index.js CHANGED
@@ -5,7 +5,7 @@ export { fileToDocument, fileToTextDocument, isBinaryFile } from './Document/ind
5
5
  export { FeatureFlags, getSystemFeatureFlags, UnknownFeatureFlagError } from './FeatureFlags/index.js';
6
6
  export { getLanguagesForBasename as getLanguageIdsForBaseFilename, getLanguagesForExt } from './LanguageIds.js';
7
7
  export { createTextDocument, updateTextDocument } from './Models/TextDocument.js';
8
- export { calcOverrideSettings, checkFilenameMatchesGlob, currentSettingsFileVersion, defaultConfigFilenames, defaultFileName, ENV_CSPELL_GLOB_ROOT, extractDependencies, extractImportErrors, finalizeSettings, getCachedFileSize, getDefaultBundledSettingsAsync, getDefaultSettings, getGlobalSettings, getGlobalSettingsAsync, getSources, ImportError, loadConfig, loadPnP, mergeInDocSettings, mergeSettings, readRawSettings, readSettings, readSettingsFiles, searchForConfig, sectionCSpell, } from './Settings/index.js';
8
+ export { calcOverrideSettings, checkFilenameMatchesGlob, createConfigLoader, currentSettingsFileVersion, defaultConfigFilenames, defaultFileName, ENV_CSPELL_GLOB_ROOT, extractDependencies, extractImportErrors, finalizeSettings, getCachedFileSize, getDefaultBundledSettingsAsync, getDefaultConfigLoader, getDefaultSettings, getGlobalSettings, getGlobalSettingsAsync, getSources, ImportError, loadConfig, loadPnP, mergeInDocSettings, mergeSettings, readRawSettings, readSettings, readSettingsFiles, searchForConfig, sectionCSpell, } from './Settings/index.js';
9
9
  export { defaultFileName as defaultSettingsFilename } from './Settings/index.js';
10
10
  export { combineTextAndLanguageSettings, combineTextAndLanguageSettings as constructSettingsForText, } from './Settings/TextDocumentSettings.js';
11
11
  export { determineFinalDocumentSettings, spellCheckDocument, spellCheckFile, } from './spellCheckFile.js';
@@ -15,8 +15,7 @@ export function toFilePathOrHref(url) {
15
15
  * @returns URL for the source directory
16
16
  */
17
17
  export function getSourceDirectoryUrl() {
18
- const base = pathToFileURL(srcDirectory);
19
- const srcDirectoryURL = new URL(base.pathname + '/', base);
18
+ const srcDirectoryURL = pathToFileURL(path.join(srcDirectory, '/'));
20
19
  return srcDirectoryURL;
21
20
  }
22
21
  /**
@@ -28,7 +27,7 @@ export function relativeTo(path, relativeTo) {
28
27
  return new URL(normalizePathSlashesForUrl(path), relativeTo || cwdURL());
29
28
  }
30
29
  export function cwdURL() {
31
- return pathToFileURL(process.cwd() + '/');
30
+ return pathToFileURL('./');
32
31
  }
33
32
  export function resolveFileWithURL(file, relativeToURL) {
34
33
  if (file instanceof URL)
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.srcDirectory = void 0;
4
+ // import { join } from 'path';
5
+ // export const srcDirectory = join(__dirname, '/');
4
6
  exports.srcDirectory = __dirname;
5
7
  //# sourceMappingURL=pkg-info.cjs.map
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "cspell-lib",
3
- "version": "8.1.0",
3
+ "version": "8.1.2",
4
4
  "description": "A library of useful functions used across various cspell tools.",
5
5
  "type": "module",
6
+ "sideEffects": false,
6
7
  "types": "dist/esm/index.d.ts",
7
8
  "module": "dist/esm/index.js",
8
9
  "exports": {
@@ -56,21 +57,21 @@
56
57
  },
57
58
  "homepage": "https://github.com/streetsidesoftware/cspell#readme",
58
59
  "dependencies": {
59
- "@cspell/cspell-bundled-dicts": "8.1.0",
60
- "@cspell/cspell-pipe": "8.1.0",
61
- "@cspell/cspell-resolver": "8.1.0",
62
- "@cspell/cspell-types": "8.1.0",
63
- "@cspell/dynamic-import": "8.1.0",
64
- "@cspell/strong-weak-map": "8.1.0",
60
+ "@cspell/cspell-bundled-dicts": "8.1.2",
61
+ "@cspell/cspell-pipe": "8.1.2",
62
+ "@cspell/cspell-resolver": "8.1.2",
63
+ "@cspell/cspell-types": "8.1.2",
64
+ "@cspell/dynamic-import": "8.1.2",
65
+ "@cspell/strong-weak-map": "8.1.2",
65
66
  "clear-module": "^4.1.2",
66
67
  "comment-json": "^4.2.3",
67
68
  "configstore": "^6.0.0",
68
- "cspell-config-lib": "8.1.0",
69
- "cspell-dictionary": "8.1.0",
70
- "cspell-glob": "8.1.0",
71
- "cspell-grammar": "8.1.0",
72
- "cspell-io": "8.1.0",
73
- "cspell-trie-lib": "8.1.0",
69
+ "cspell-config-lib": "8.1.2",
70
+ "cspell-dictionary": "8.1.2",
71
+ "cspell-glob": "8.1.2",
72
+ "cspell-grammar": "8.1.2",
73
+ "cspell-io": "8.1.2",
74
+ "cspell-trie-lib": "8.1.2",
74
75
  "fast-equals": "^5.0.1",
75
76
  "gensequence": "^6.0.0",
76
77
  "import-fresh": "^3.3.0",
@@ -94,5 +95,5 @@
94
95
  "cspell-dict-nl-nl": "^1.1.2",
95
96
  "lorem-ipsum": "^2.0.8"
96
97
  },
97
- "gitHead": "28568808deaf39b9ffa71fd0f722441ff1b8c794"
98
+ "gitHead": "ba4eef94480562e7641298b32cb99723fd64aeca"
98
99
  }