cspell-lib 6.1.3 → 6.2.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.
@@ -1,12 +1,13 @@
1
- import { CSpellSettingsWithSourceTrace, DictionaryDefinitionAugmented, DictionaryDefinitionCustom, DictionaryDefinitionPreferred } from '@cspell/cspell-types';
1
+ import { AdvancedCSpellSettingsWithSourceTrace, CSpellSettingsWithSourceTrace, DictionaryDefinitionAugmented, DictionaryDefinitionCustom, DictionaryDefinitionPreferred, Parser } from '@cspell/cspell-types';
2
2
  import { WeightMap } from 'cspell-trie-lib';
3
3
  import { OptionalOrUndefined } from '../util/types';
4
4
  export declare const SymbolCSpellSettingsInternal: unique symbol;
5
- export interface CSpellSettingsInternal extends Omit<CSpellSettingsWithSourceTrace, 'dictionaryDefinitions'> {
5
+ export interface CSpellSettingsInternal extends Omit<AdvancedCSpellSettingsWithSourceTrace, 'dictionaryDefinitions'> {
6
6
  [SymbolCSpellSettingsInternal]: true;
7
7
  dictionaryDefinitions?: DictionaryDefinitionInternal[];
8
8
  }
9
9
  export interface CSpellSettingsInternalFinalized extends CSpellSettingsInternal {
10
+ parserFn: Parser | undefined;
10
11
  finalized: true;
11
12
  ignoreRegExpList: RegExp[];
12
13
  includeRegExpList: RegExp[];
@@ -1,8 +1,8 @@
1
- import type { CSpellSettingsWithSourceTrace, Glob, ImportFileRef } from '@cspell/cspell-types';
1
+ import type { AdvancedCSpellSettingsWithSourceTrace, Glob, ImportFileRef } from '@cspell/cspell-types';
2
2
  import { CSpellSettingsInternal, CSpellSettingsInternalFinalized } from '../Models/CSpellSettingsInternalDef';
3
3
  import { OptionalOrUndefined } from '../util/types';
4
- declare type CSpellSettingsWST = CSpellSettingsWithSourceTrace;
5
- declare type CSpellSettingsWSTO = OptionalOrUndefined<CSpellSettingsWithSourceTrace>;
4
+ declare type CSpellSettingsWST = AdvancedCSpellSettingsWithSourceTrace;
5
+ declare type CSpellSettingsWSTO = OptionalOrUndefined<AdvancedCSpellSettingsWithSourceTrace>;
6
6
  declare type CSpellSettingsI = CSpellSettingsInternal;
7
7
  export declare const configSettingsFileVersion0_1 = "0.1";
8
8
  export declare const configSettingsFileVersion0_2 = "0.2";
@@ -228,7 +228,7 @@ function _finalizeSettings(settings) {
228
228
  finalized: true,
229
229
  ignoreRegExpList: (0, patterns_1.resolvePatterns)(settings.ignoreRegExpList, settings.patterns),
230
230
  includeRegExpList: (0, patterns_1.resolvePatterns)(settings.includeRegExpList, settings.patterns),
231
- parser: resolveParser(settings),
231
+ parserFn: resolveParser(settings),
232
232
  };
233
233
  finalized.name = 'Finalized ' + (finalized.name || '');
234
234
  finalized.source = { name: settings.name || 'src', sources: [settings] };
@@ -50,14 +50,17 @@ function fixPath(def) {
50
50
  if (def instanceof _DictionaryDefinitionInternalWithSource) {
51
51
  return def;
52
52
  }
53
- const { path: filePath = '', file = '' } = def;
54
- const newPath = !filePath && !file ? '' : path.join(filePath, file);
53
+ const newPath = fixDicPath(def.path, def.file);
55
54
  return {
56
55
  ...def,
57
56
  file: undefined,
58
57
  path: newPath,
59
58
  };
60
59
  }
60
+ function fixDicPath(defPath, defFile) {
61
+ const parts = [defPath || '', defFile || ''].filter((p) => !!p);
62
+ return parts.length > 1 ? path.join(...parts) : parts[0] || '';
63
+ }
61
64
  function mapDictDefsToInternal(defs, pathToSettingsFile) {
62
65
  return defs?.map((def) => mapDictDefToInternal(def, pathToSettingsFile));
63
66
  }
@@ -103,7 +106,7 @@ class _DictionaryDefinitionInternalWithSource {
103
106
  const defAll = def;
104
107
  const { path: relPath = '', file = '', addWords, description, dictionaryInformation, type, repMap, noSuggest, scope, useCompounds, } = defAll;
105
108
  const defaultPath = path.dirname(__source);
106
- const filePath = path.join(relPath, file);
109
+ const filePath = fixDicPath(relPath, file);
107
110
  const name = determineName(filePath, def);
108
111
  const r = (0, resolveFile_1.resolveFile)(filePath, defaultPath);
109
112
  const ddi = {
@@ -1,3 +1,4 @@
1
+ import { Stats } from 'cspell-io';
1
2
  import { DictionaryDefinitionInternal } from '../Models/CSpellSettingsInternalDef';
2
3
  import { SpellingDictionary } from './SpellingDictionary';
3
4
  export declare type LoadOptions = DictionaryDefinitionInternal;
@@ -49,37 +50,6 @@ export declare const testing: {
49
50
  loadEntry: typeof loadEntry;
50
51
  load: typeof load;
51
52
  };
52
- /**
53
- * Copied from the Node definition to avoid a dependency upon a specific version of Node
54
- */
55
- interface StatsBase<T> {
56
- isFile(): boolean;
57
- isDirectory(): boolean;
58
- isBlockDevice(): boolean;
59
- isCharacterDevice(): boolean;
60
- isSymbolicLink(): boolean;
61
- isFIFO(): boolean;
62
- isSocket(): boolean;
63
- dev: T;
64
- ino: T;
65
- mode: T;
66
- nlink: T;
67
- uid: T;
68
- gid: T;
69
- rdev: T;
70
- size: T;
71
- blksize: T;
72
- blocks: T;
73
- atimeMs: T;
74
- mtimeMs: T;
75
- ctimeMs: T;
76
- birthtimeMs: T;
77
- atime: Date;
78
- mtime: Date;
79
- ctime: Date;
80
- birthtime: Date;
81
- }
82
- export declare type Stats = StatsBase<number>;
83
53
  export declare const __testing__: {
84
54
  debugLog: string[];
85
55
  };
@@ -24,11 +24,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.__testing__ = exports.testing = exports.refreshCacheEntries = exports.loadDictionarySync = exports.loadDictionary = void 0;
27
- const fs_1 = require("fs");
27
+ const cspell_io_1 = require("cspell-io");
28
28
  const gensequence_1 = require("gensequence");
29
29
  const path = __importStar(require("path"));
30
30
  const util_1 = require("util");
31
- const errors_1 = require("../util/errors");
32
31
  const fileReader_1 = require("../util/fileReader");
33
32
  const createSpellingDictionary_1 = require("./createSpellingDictionary");
34
33
  const SpellingDictionaryError_1 = require("./SpellingDictionaryError");
@@ -120,7 +119,7 @@ async function refreshEntry(entry, maxAge, now) {
120
119
  // Write to the ts, so the next one will not do it.
121
120
  entry.sig = sig;
122
121
  entry.ts = now;
123
- const pStat = getStat(entry.uri);
122
+ const pStat = (0, cspell_io_1.getStat)(entry.uri);
124
123
  const [newStat] = await Promise.all([pStat, entry.pending]);
125
124
  const hasChanged = !isEqual(newStat, entry.stat);
126
125
  const sigMatches = entry.sig === sig;
@@ -150,7 +149,7 @@ function isEqual(a, b) {
150
149
  if (isError(a)) {
151
150
  return isError(b) && a.message === b.message && a.name === b.name;
152
151
  }
153
- return !isError(b) && (a.mtimeMs === b.mtimeMs || a.size === b.size);
152
+ return !isError(b) && a.mtimeMs === b.mtimeMs && a.size === b.size && a.eTag === b.eTag;
154
153
  }
155
154
  function isError(e) {
156
155
  const err = e;
@@ -158,7 +157,7 @@ function isError(e) {
158
157
  }
159
158
  function loadEntry(uri, options, now = Date.now()) {
160
159
  const pDictionary = load(uri, options).catch((e) => (0, createSpellingDictionary_1.createFailedToLoadDictionary)(new SpellingDictionaryError_1.SpellingDictionaryLoadError(uri, options, e, 'failed to load')));
161
- const pStat = getStat(uri);
160
+ const pStat = (0, cspell_io_1.getStat)(uri);
162
161
  const pending = Promise.all([pDictionary, pStat]);
163
162
  const sig = now + Math.random();
164
163
  const entry = {
@@ -181,7 +180,7 @@ function loadEntry(uri, options, now = Date.now()) {
181
180
  return entry;
182
181
  }
183
182
  function loadEntrySync(uri, options, now = Date.now()) {
184
- const stat = getStatSync(uri);
183
+ const stat = (0, cspell_io_1.getStatSync)(uri);
185
184
  const sig = now + Math.random();
186
185
  try {
187
186
  const dictionary = loadSync(uri, options);
@@ -289,24 +288,6 @@ exports.testing = {
289
288
  loadEntry,
290
289
  load,
291
290
  };
292
- function toError(e) {
293
- if ((0, errors_1.isErrnoException)(e))
294
- return e;
295
- if (e instanceof Error)
296
- return e;
297
- return new Error((0, util_1.format)(e));
298
- }
299
- function getStat(uri) {
300
- return fs_1.promises.stat(uri).catch((e) => toError(e));
301
- }
302
- function getStatSync(uri) {
303
- try {
304
- return (0, fs_1.statSync)(uri);
305
- }
306
- catch (e) {
307
- return toError(e);
308
- }
309
- }
310
291
  exports.__testing__ = {
311
292
  debugLog,
312
293
  };
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import * as Link from './Settings/index.link';
4
4
  import { SpellingDictionaryCollection } from './SpellingDictionary';
5
5
  import * as Text from './util/text';
6
6
  export * from '@cspell/cspell-types';
7
- export * from 'cspell-io';
7
+ export { asyncIterableToArray, readFile, readFileSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from 'cspell-io';
8
8
  export { ExcludeFilesGlobMap, ExclusionFunction } from './exclusionHelper';
9
9
  export { getLanguagesForExt } from './LanguageIds';
10
10
  export { createTextDocument, updateTextDocument } from './Models/TextDocument';
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getDictionary = exports.clearCachedFiles = exports.ExclusionHelper = exports.Link = exports.Text = exports.validateText = exports.IncludeExcludeFlag = exports.checkText = exports.resolveFile = exports.setLogger = exports.getLogger = exports.traceWordsAsync = exports.traceWords = exports.DocumentValidator = exports.suggestionsForWords = exports.suggestionsForWord = exports.SuggestionError = exports.SpellingDictionaryLoadError = exports.SpellingDictionaryCollection = exports.refreshDictionaryCache = exports.isSpellingDictionaryLoadError = exports.createSpellingDictionary = exports.CompoundWordsMethod = exports.spellCheckFile = exports.spellCheckDocument = exports.isBinaryFile = exports.fileToDocument = exports.determineFinalDocumentSettings = exports.constructSettingsForText = exports.combineTextAndLanguageSettings = exports.defaultSettingsFilename = exports.updateTextDocument = exports.createTextDocument = exports.getLanguagesForExt = void 0;
29
+ exports.getDictionary = exports.clearCachedFiles = exports.ExclusionHelper = exports.Link = exports.Text = exports.validateText = exports.IncludeExcludeFlag = exports.checkText = exports.resolveFile = exports.setLogger = exports.getLogger = exports.traceWordsAsync = exports.traceWords = exports.DocumentValidator = exports.suggestionsForWords = exports.suggestionsForWord = exports.SuggestionError = exports.SpellingDictionaryLoadError = exports.SpellingDictionaryCollection = exports.refreshDictionaryCache = exports.isSpellingDictionaryLoadError = exports.createSpellingDictionary = exports.CompoundWordsMethod = exports.spellCheckFile = exports.spellCheckDocument = exports.isBinaryFile = exports.fileToDocument = exports.determineFinalDocumentSettings = exports.constructSettingsForText = exports.combineTextAndLanguageSettings = exports.defaultSettingsFilename = exports.updateTextDocument = exports.createTextDocument = exports.getLanguagesForExt = exports.writeToFileIterableP = exports.writeToFileIterable = exports.writeToFile = exports.readFileSync = exports.readFile = exports.asyncIterableToArray = void 0;
30
30
  const ExclusionHelper = __importStar(require("./exclusionHelper"));
31
31
  exports.ExclusionHelper = ExclusionHelper;
32
32
  const Settings_1 = require("./Settings");
@@ -37,7 +37,13 @@ const SpellingDictionary_1 = require("./SpellingDictionary");
37
37
  const Text = __importStar(require("./util/text"));
38
38
  exports.Text = Text;
39
39
  __exportStar(require("@cspell/cspell-types"), exports);
40
- __exportStar(require("cspell-io"), exports);
40
+ var cspell_io_1 = require("cspell-io");
41
+ Object.defineProperty(exports, "asyncIterableToArray", { enumerable: true, get: function () { return cspell_io_1.asyncIterableToArray; } });
42
+ Object.defineProperty(exports, "readFile", { enumerable: true, get: function () { return cspell_io_1.readFile; } });
43
+ Object.defineProperty(exports, "readFileSync", { enumerable: true, get: function () { return cspell_io_1.readFileSync; } });
44
+ Object.defineProperty(exports, "writeToFile", { enumerable: true, get: function () { return cspell_io_1.writeToFile; } });
45
+ Object.defineProperty(exports, "writeToFileIterable", { enumerable: true, get: function () { return cspell_io_1.writeToFileIterable; } });
46
+ Object.defineProperty(exports, "writeToFileIterableP", { enumerable: true, get: function () { return cspell_io_1.writeToFileIterableP; } });
41
47
  var LanguageIds_1 = require("./LanguageIds");
42
48
  Object.defineProperty(exports, "getLanguagesForExt", { enumerable: true, get: function () { return LanguageIds_1.getLanguagesForExt; } });
43
49
  var TextDocument_1 = require("./Models/TextDocument");
@@ -256,7 +256,7 @@ class DocumentValidator {
256
256
  }
257
257
  _parse() {
258
258
  (0, assert_1.default)(this._preparations, ERROR_NOT_PREPARED);
259
- const parser = this._preparations.finalSettings.parser;
259
+ const parser = this._preparations.finalSettings.parserFn;
260
260
  if (typeof parser !== 'object')
261
261
  return this.defaultParser();
262
262
  return parser.parse(this.document.text, this.document.uri.path).parsedTexts;
@@ -42,13 +42,14 @@ const testNodeModules = /^node_modules\//;
42
42
  function resolveFile(filename, relativeTo) {
43
43
  filename = filename.replace(/^~/, os.homedir());
44
44
  const steps = [
45
- { filename: filename, fn: tryNodeResolve },
45
+ { filename, fn: tryUrl },
46
+ { filename, fn: tryNodeResolve },
46
47
  { filename: path.resolve(relativeTo, filename), fn: tryResolveExists },
47
48
  { filename: path.resolve(filename), fn: tryResolveExists },
48
- { filename: filename, fn: tryNodeResolveDefaultPaths },
49
- { filename: filename, fn: tryResolveFrom },
49
+ { filename, fn: tryNodeResolveDefaultPaths },
50
+ { filename, fn: tryResolveFrom },
50
51
  { filename: filename.replace(testNodeModules, ''), fn: tryResolveFrom },
51
- { filename: filename, fn: tryResolveGlobal },
52
+ { filename, fn: tryResolveGlobal },
52
53
  ];
53
54
  for (const step of steps) {
54
55
  const r = step.fn(step.filename, relativeTo);
@@ -58,6 +59,23 @@ function resolveFile(filename, relativeTo) {
58
59
  return { filename: path.resolve(relativeTo, filename), relativeTo, found: false };
59
60
  }
60
61
  exports.resolveFile = resolveFile;
62
+ const isUrlRegExp = /^\w+:\/\//i;
63
+ /**
64
+ * Check to see if it is a URL.
65
+ * Note: URLs are absolute!
66
+ * @param filename - url string
67
+ * @returns ResolveFileResult
68
+ */
69
+ function tryUrl(filename, relativeTo) {
70
+ if (isUrlRegExp.test(filename)) {
71
+ return { filename, relativeTo: undefined, found: true };
72
+ }
73
+ if (isUrlRegExp.test(relativeTo)) {
74
+ const url = new URL(filename, relativeTo);
75
+ return { filename: url.href, relativeTo, found: true };
76
+ }
77
+ return { filename, relativeTo: undefined, found: false };
78
+ }
61
79
  function tryNodeResolveDefaultPaths(filename) {
62
80
  try {
63
81
  const r = require.resolve(filename);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cspell-lib",
3
- "version": "6.1.3",
3
+ "version": "6.2.0",
4
4
  "description": "A library of useful functions used across various cspell tools.",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -48,16 +48,16 @@
48
48
  },
49
49
  "homepage": "https://github.com/streetsidesoftware/cspell#readme",
50
50
  "dependencies": {
51
- "@cspell/cspell-bundled-dicts": "^6.1.3",
52
- "@cspell/cspell-pipe": "^6.1.3",
53
- "@cspell/cspell-types": "^6.1.3",
51
+ "@cspell/cspell-bundled-dicts": "^6.2.0",
52
+ "@cspell/cspell-pipe": "^6.2.0",
53
+ "@cspell/cspell-types": "^6.2.0",
54
54
  "clear-module": "^4.1.2",
55
55
  "comment-json": "^4.2.2",
56
56
  "configstore": "^5.0.1",
57
57
  "cosmiconfig": "^7.0.1",
58
- "cspell-glob": "^6.1.3",
59
- "cspell-io": "^6.1.3",
60
- "cspell-trie-lib": "^6.1.3",
58
+ "cspell-glob": "^6.2.0",
59
+ "cspell-io": "^6.2.0",
60
+ "cspell-trie-lib": "^6.2.0",
61
61
  "fast-equals": "^4.0.1",
62
62
  "find-up": "^5.0.0",
63
63
  "fs-extra": "^10.1.0",
@@ -72,7 +72,7 @@
72
72
  "node": ">=14"
73
73
  },
74
74
  "devDependencies": {
75
- "@cspell/dict-cpp": "^3.1.0",
75
+ "@cspell/dict-cpp": "^3.1.1",
76
76
  "@cspell/dict-csharp": "^3.0.1",
77
77
  "@cspell/dict-css": "^1.0.13",
78
78
  "@cspell/dict-fa-ir": "^2.0.0",
@@ -85,12 +85,12 @@
85
85
  "@types/jest": "^28.1.3",
86
86
  "@types/node": "^18.0.0",
87
87
  "cspell-dict-nl-nl": "^1.1.2",
88
- "jest": "^28.1.1",
88
+ "jest": "^28.1.2",
89
89
  "lorem-ipsum": "^2.0.8",
90
90
  "rimraf": "^3.0.2",
91
91
  "rollup": "^2.75.7",
92
92
  "rollup-plugin-dts": "^4.2.2",
93
93
  "ts-jest": "^28.0.5"
94
94
  },
95
- "gitHead": "e96b313542f2ec0a38ac04d1422d97e724ded3a6"
95
+ "gitHead": "ef9bf8e390692145b067843dbcc44a6dc2d9aa31"
96
96
  }