cspell 9.1.2 → 9.1.5
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/README.md +29 -21
- package/bin.mjs +1 -1
- package/dist/esm/app.d.ts +19 -0
- package/dist/esm/app.js +1033 -0
- package/dist/esm/application-D-NwS6qb.js +2573 -0
- package/dist/esm/application-DbOQYm56.d.ts +116 -0
- package/dist/esm/application.d.ts +3 -0
- package/dist/esm/application.js +3 -0
- package/dist/esm/index.d.ts +55 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/options-ChaXtdFn.d.ts +387 -0
- package/package.json +27 -25
- package/dist/esm/app.d.mts +0 -5
- package/dist/esm/app.mjs +0 -34
- package/dist/esm/application.d.mts +0 -17
- package/dist/esm/application.mjs +0 -99
- package/dist/esm/cli-reporter.d.ts +0 -38
- package/dist/esm/cli-reporter.js +0 -386
- package/dist/esm/commandCheck.d.ts +0 -3
- package/dist/esm/commandCheck.js +0 -52
- package/dist/esm/commandConfig.d.ts +0 -3
- package/dist/esm/commandConfig.js +0 -18
- package/dist/esm/commandDictionaries.d.ts +0 -3
- package/dist/esm/commandDictionaries.js +0 -40
- package/dist/esm/commandHelpers.d.ts +0 -18
- package/dist/esm/commandHelpers.js +0 -30
- package/dist/esm/commandInit.d.ts +0 -3
- package/dist/esm/commandInit.js +0 -25
- package/dist/esm/commandLink.d.ts +0 -3
- package/dist/esm/commandLink.js +0 -48
- package/dist/esm/commandLint.d.ts +0 -3
- package/dist/esm/commandLint.js +0 -226
- package/dist/esm/commandSuggestion.d.ts +0 -3
- package/dist/esm/commandSuggestion.js +0 -61
- package/dist/esm/commandTrace.d.ts +0 -3
- package/dist/esm/commandTrace.js +0 -91
- package/dist/esm/config/adjustConfig.d.ts +0 -7
- package/dist/esm/config/adjustConfig.js +0 -137
- package/dist/esm/config/config.d.ts +0 -5
- package/dist/esm/config/config.js +0 -18
- package/dist/esm/config/configInit.d.ts +0 -3
- package/dist/esm/config/configInit.js +0 -104
- package/dist/esm/config/constants.d.ts +0 -17
- package/dist/esm/config/constants.js +0 -23
- package/dist/esm/config/index.d.ts +0 -3
- package/dist/esm/config/index.js +0 -2
- package/dist/esm/config/options.d.ts +0 -62
- package/dist/esm/config/options.js +0 -2
- package/dist/esm/config/updateConfig.d.ts +0 -3
- package/dist/esm/config/updateConfig.js +0 -2
- package/dist/esm/console.d.ts +0 -25
- package/dist/esm/console.js +0 -53
- package/dist/esm/dictionaries/index.d.ts +0 -3
- package/dist/esm/dictionaries/index.js +0 -2
- package/dist/esm/dictionaries/listDictionaries.d.ts +0 -33
- package/dist/esm/dictionaries/listDictionaries.js +0 -131
- package/dist/esm/dirname.d.ts +0 -2
- package/dist/esm/dirname.js +0 -13
- package/dist/esm/emitters/DictionaryPathFormat.d.ts +0 -3
- package/dist/esm/emitters/DictionaryPathFormat.js +0 -12
- package/dist/esm/emitters/dictionaryListEmitter.d.ts +0 -19
- package/dist/esm/emitters/dictionaryListEmitter.js +0 -82
- package/dist/esm/emitters/helpers.d.ts +0 -14
- package/dist/esm/emitters/helpers.js +0 -67
- package/dist/esm/emitters/suggestionsEmitter.d.ts +0 -13
- package/dist/esm/emitters/suggestionsEmitter.js +0 -79
- package/dist/esm/emitters/traceEmitter.d.ts +0 -19
- package/dist/esm/emitters/traceEmitter.js +0 -87
- package/dist/esm/environment.d.ts +0 -39
- package/dist/esm/environment.js +0 -30
- package/dist/esm/featureFlags/featureFlags.d.ts +0 -4
- package/dist/esm/featureFlags/featureFlags.js +0 -21
- package/dist/esm/featureFlags/index.d.ts +0 -2
- package/dist/esm/featureFlags/index.js +0 -2
- package/dist/esm/index.d.mts +0 -6
- package/dist/esm/index.mjs +0 -4
- package/dist/esm/link.d.ts +0 -8
- package/dist/esm/link.js +0 -39
- package/dist/esm/lint/LintRequest.d.ts +0 -26
- package/dist/esm/lint/LintRequest.js +0 -83
- package/dist/esm/lint/index.d.ts +0 -3
- package/dist/esm/lint/index.js +0 -3
- package/dist/esm/lint/lint.d.ts +0 -8
- package/dist/esm/lint/lint.js +0 -515
- package/dist/esm/models.d.ts +0 -15
- package/dist/esm/models.js +0 -2
- package/dist/esm/options.d.ts +0 -353
- package/dist/esm/options.js +0 -9
- package/dist/esm/pkgInfo.d.ts +0 -14
- package/dist/esm/pkgInfo.js +0 -7
- package/dist/esm/repl/index.d.ts +0 -18
- package/dist/esm/repl/index.js +0 -52
- package/dist/esm/util/InMemoryReporter.d.ts +0 -31
- package/dist/esm/util/InMemoryReporter.js +0 -49
- package/dist/esm/util/LintFileResult.d.ts +0 -14
- package/dist/esm/util/LintFileResult.js +0 -2
- package/dist/esm/util/async.d.ts +0 -3
- package/dist/esm/util/async.js +0 -4
- package/dist/esm/util/cache/CSpellLintResultCache.d.ts +0 -20
- package/dist/esm/util/cache/CSpellLintResultCache.js +0 -2
- package/dist/esm/util/cache/CacheOptions.d.ts +0 -34
- package/dist/esm/util/cache/CacheOptions.js +0 -2
- package/dist/esm/util/cache/DiskCache.d.ts +0 -63
- package/dist/esm/util/cache/DiskCache.js +0 -214
- package/dist/esm/util/cache/DummyCache.d.ts +0 -11
- package/dist/esm/util/cache/DummyCache.js +0 -18
- package/dist/esm/util/cache/ObjectCollection.d.ts +0 -17
- package/dist/esm/util/cache/ObjectCollection.js +0 -127
- package/dist/esm/util/cache/createCache.d.ts +0 -31
- package/dist/esm/util/cache/createCache.js +0 -69
- package/dist/esm/util/cache/file-entry-cache.d.mts +0 -4
- package/dist/esm/util/cache/file-entry-cache.mjs +0 -5
- package/dist/esm/util/cache/fileEntryCache.d.ts +0 -9
- package/dist/esm/util/cache/fileEntryCache.js +0 -79
- package/dist/esm/util/cache/index.d.ts +0 -4
- package/dist/esm/util/cache/index.js +0 -2
- package/dist/esm/util/canUseColor.d.ts +0 -2
- package/dist/esm/util/canUseColor.js +0 -10
- package/dist/esm/util/configFileHelper.d.ts +0 -15
- package/dist/esm/util/configFileHelper.js +0 -43
- package/dist/esm/util/constants.d.ts +0 -6
- package/dist/esm/util/constants.js +0 -6
- package/dist/esm/util/errors.d.ts +0 -24
- package/dist/esm/util/errors.js +0 -60
- package/dist/esm/util/extractContext.d.ts +0 -5
- package/dist/esm/util/extractContext.js +0 -75
- package/dist/esm/util/fileHelper.d.ts +0 -44
- package/dist/esm/util/fileHelper.js +0 -165
- package/dist/esm/util/glob.d.ts +0 -45
- package/dist/esm/util/glob.js +0 -147
- package/dist/esm/util/pad.d.ts +0 -45
- package/dist/esm/util/pad.js +0 -191
- package/dist/esm/util/prefetch.d.ts +0 -2
- package/dist/esm/util/prefetch.js +0 -15
- package/dist/esm/util/reporters.d.ts +0 -30
- package/dist/esm/util/reporters.js +0 -209
- package/dist/esm/util/stdin.d.ts +0 -2
- package/dist/esm/util/stdin.js +0 -5
- package/dist/esm/util/stdinUrl.d.ts +0 -9
- package/dist/esm/util/stdinUrl.js +0 -26
- package/dist/esm/util/table.d.ts +0 -41
- package/dist/esm/util/table.js +0 -115
- package/dist/esm/util/timer.d.ts +0 -4
- package/dist/esm/util/timer.js +0 -9
- package/dist/esm/util/types.d.ts +0 -7
- package/dist/esm/util/types.js +0 -5
- package/dist/esm/util/unindent.d.ts +0 -14
- package/dist/esm/util/unindent.js +0 -55
- package/dist/esm/util/util.d.ts +0 -14
- package/dist/esm/util/util.js +0 -30
- package/dist/esm/util/writeFile.d.ts +0 -3
- package/dist/esm/util/writeFile.js +0 -30
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { CSpellUserSettings } from 'cspell-lib';
|
|
2
|
-
import { CSpellConfigFile } from '../options.js';
|
|
3
|
-
export interface ConfigInfo {
|
|
4
|
-
source: string;
|
|
5
|
-
config: CSpellUserSettings;
|
|
6
|
-
}
|
|
7
|
-
export interface FileConfigInfo {
|
|
8
|
-
configInfo: ConfigInfo;
|
|
9
|
-
filename: string;
|
|
10
|
-
text: string;
|
|
11
|
-
languageIds: string[];
|
|
12
|
-
}
|
|
13
|
-
export declare function readConfig(configFile: string | CSpellConfigFile | undefined, root: string | undefined, stopConfigSearchAt?: (URL | string)[] | undefined): Promise<ConfigInfo>;
|
|
14
|
-
export declare function readConfigFile(filename: string | URL): Promise<CSpellConfigFile>;
|
|
15
|
-
//# sourceMappingURL=configFileHelper.d.ts.map
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { toFilePathOrHref } from '@cspell/url';
|
|
2
|
-
import * as cspell from 'cspell-lib';
|
|
3
|
-
import { environmentKeys, getEnvironmentVariable } from '../environment.js';
|
|
4
|
-
import { filenameToUrl } from './fileHelper.js';
|
|
5
|
-
export async function readConfig(configFile, root, stopConfigSearchAt) {
|
|
6
|
-
configFile ??= getEnvironmentVariable(environmentKeys.CSPELL_CONFIG_PATH);
|
|
7
|
-
if (configFile) {
|
|
8
|
-
const cfgFile = typeof configFile === 'string' ? await readConfigHandleError(configFile) : configFile;
|
|
9
|
-
return configFileToConfigInfo(cfgFile);
|
|
10
|
-
}
|
|
11
|
-
const config = await cspell.searchForConfig(root, { stopSearchAt: stopConfigSearchAt });
|
|
12
|
-
const defaultConfigFile = getEnvironmentVariable(environmentKeys.CSPELL_DEFAULT_CONFIG_PATH);
|
|
13
|
-
if (!config && defaultConfigFile) {
|
|
14
|
-
const cfgFile = await readConfigFile(defaultConfigFile).catch(() => undefined);
|
|
15
|
-
if (cfgFile) {
|
|
16
|
-
return configFileToConfigInfo(cfgFile);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return { source: config?.__importRef?.filename || 'None found', config: config || {} };
|
|
20
|
-
}
|
|
21
|
-
async function configFileToConfigInfo(cfgFile) {
|
|
22
|
-
const config = await cspell.resolveConfigFileImports(cfgFile);
|
|
23
|
-
const source = toFilePathOrHref(cfgFile.url);
|
|
24
|
-
return { source, config };
|
|
25
|
-
}
|
|
26
|
-
export function readConfigFile(filename) {
|
|
27
|
-
return cspell.readConfigFile(filename);
|
|
28
|
-
}
|
|
29
|
-
async function readConfigHandleError(filename) {
|
|
30
|
-
try {
|
|
31
|
-
return await readConfigFile(filename);
|
|
32
|
-
}
|
|
33
|
-
catch (e) {
|
|
34
|
-
const settings = {
|
|
35
|
-
__importRef: {
|
|
36
|
-
filename: filename.toString(),
|
|
37
|
-
error: e,
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
return { url: filenameToUrl(filename), settings };
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=configFileHelper.js.map
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export declare class CheckFailed extends Error {
|
|
2
|
-
readonly exitCode: number;
|
|
3
|
-
constructor(message: string, exitCode?: number);
|
|
4
|
-
}
|
|
5
|
-
export declare class ApplicationError extends Error {
|
|
6
|
-
readonly exitCode: number;
|
|
7
|
-
readonly cause?: Error | undefined;
|
|
8
|
-
constructor(message: string, exitCode?: number, cause?: Error | undefined);
|
|
9
|
-
}
|
|
10
|
-
export declare class IOError extends ApplicationError {
|
|
11
|
-
readonly cause: NodeError;
|
|
12
|
-
constructor(message: string, cause: NodeError);
|
|
13
|
-
get code(): string | undefined;
|
|
14
|
-
isNotFound(): boolean;
|
|
15
|
-
}
|
|
16
|
-
export declare function toError(e: unknown): NodeError;
|
|
17
|
-
export declare function isError(e: unknown): e is NodeError;
|
|
18
|
-
export declare function isErrorLike(e: unknown): e is NodeError;
|
|
19
|
-
export declare function toApplicationError(e: unknown, message?: string): ApplicationError;
|
|
20
|
-
export interface NodeError extends Error {
|
|
21
|
-
code?: string;
|
|
22
|
-
toString?: () => string;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=errors.d.ts.map
|
package/dist/esm/util/errors.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { format } from 'node:util';
|
|
2
|
-
export class CheckFailed extends Error {
|
|
3
|
-
exitCode;
|
|
4
|
-
constructor(message, exitCode = 1) {
|
|
5
|
-
super(message);
|
|
6
|
-
this.exitCode = exitCode;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export class ApplicationError extends Error {
|
|
10
|
-
exitCode;
|
|
11
|
-
cause;
|
|
12
|
-
constructor(message, exitCode = 1, cause) {
|
|
13
|
-
super(message);
|
|
14
|
-
this.exitCode = exitCode;
|
|
15
|
-
this.cause = cause;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export class IOError extends ApplicationError {
|
|
19
|
-
cause;
|
|
20
|
-
constructor(message, cause) {
|
|
21
|
-
super(message, undefined, cause);
|
|
22
|
-
this.cause = cause;
|
|
23
|
-
}
|
|
24
|
-
get code() {
|
|
25
|
-
return this.cause.code;
|
|
26
|
-
}
|
|
27
|
-
isNotFound() {
|
|
28
|
-
return this.cause.code === 'ENOENT';
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export function toError(e) {
|
|
32
|
-
if (isError(e))
|
|
33
|
-
return e;
|
|
34
|
-
if (isErrorLike(e)) {
|
|
35
|
-
const ex = new Error(e.message, { cause: e });
|
|
36
|
-
if (e.code !== undefined)
|
|
37
|
-
ex.code = e.code;
|
|
38
|
-
return ex;
|
|
39
|
-
}
|
|
40
|
-
const message = format(e);
|
|
41
|
-
return new Error(message);
|
|
42
|
-
}
|
|
43
|
-
export function isError(e) {
|
|
44
|
-
return e instanceof Error;
|
|
45
|
-
}
|
|
46
|
-
export function isErrorLike(e) {
|
|
47
|
-
if (e instanceof Error)
|
|
48
|
-
return true;
|
|
49
|
-
if (!e || typeof e !== 'object')
|
|
50
|
-
return false;
|
|
51
|
-
const ex = e;
|
|
52
|
-
return typeof ex.message === 'string';
|
|
53
|
-
}
|
|
54
|
-
export function toApplicationError(e, message) {
|
|
55
|
-
if (e instanceof ApplicationError && !message)
|
|
56
|
-
return e;
|
|
57
|
-
const err = toError(e);
|
|
58
|
-
return new ApplicationError(message ?? err.message, undefined, err);
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=errors.js.map
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { TextDocumentOffset, TextOffset } from '@cspell/cspell-types';
|
|
2
|
-
export declare function fixOffsetToBeginningOfChar(text: string, offset: number): number;
|
|
3
|
-
export declare function lineContext(lineText: string, start: number, end: number, contextRange: number): TextOffset;
|
|
4
|
-
export declare function extractContext(tdo: Pick<TextDocumentOffset, 'line' | 'offset' | 'text'>, contextRange: number): TextOffset;
|
|
5
|
-
//# sourceMappingURL=extractContext.d.ts.map
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
export function fixOffsetToBeginningOfChar(text, offset) {
|
|
2
|
-
const code = text.charCodeAt(offset) || 0;
|
|
3
|
-
return offset + ((code & 0xfc00) === 0xdc00 ? 1 : 0);
|
|
4
|
-
}
|
|
5
|
-
function prefCharIndex(text, offset, count = 1) {
|
|
6
|
-
if (offset - count < 0)
|
|
7
|
-
return 0;
|
|
8
|
-
for (; count > 0 && offset > 0; count--) {
|
|
9
|
-
let code = text.charCodeAt(--offset) || 0;
|
|
10
|
-
if (code === 0xfe0f) {
|
|
11
|
-
// Remove zero-width joiner
|
|
12
|
-
code = text.charCodeAt(--offset) || 0;
|
|
13
|
-
}
|
|
14
|
-
offset -= (code & 0xfc00) === 0xdc00 ? 1 : 0;
|
|
15
|
-
}
|
|
16
|
-
return offset < 0 ? 0 : offset;
|
|
17
|
-
}
|
|
18
|
-
function nextCharIndex(text, offset, count = 1) {
|
|
19
|
-
if (offset + count >= text.length)
|
|
20
|
-
return text.length;
|
|
21
|
-
for (; count > 0 && offset < text.length; count--) {
|
|
22
|
-
const code = text.charCodeAt(offset++) || 0;
|
|
23
|
-
offset += (code & 0xfc00) === 0xd800 ? 1 : 0;
|
|
24
|
-
if (text.charCodeAt(offset) === 0xfe0f) {
|
|
25
|
-
// Skip zero-width joiner
|
|
26
|
-
offset++;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return offset > text.length ? text.length : offset;
|
|
30
|
-
}
|
|
31
|
-
export function lineContext(lineText, start, end, contextRange) {
|
|
32
|
-
let left = prefCharIndex(lineText, start, contextRange);
|
|
33
|
-
let right = nextCharIndex(lineText, end, contextRange);
|
|
34
|
-
const isLetter = /^\p{L}$/u;
|
|
35
|
-
const isMark = /^\p{M}$/u;
|
|
36
|
-
for (let n = contextRange / 2; n > 0 && left > 0; n--, left--) {
|
|
37
|
-
const c = lineText[left - 1];
|
|
38
|
-
if (isMark.test(c)) {
|
|
39
|
-
if (!isLetter.test(lineText[left - 2])) {
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
left--;
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
if (!isLetter.test(lineText[left - 1])) {
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
for (let n = contextRange / 2; n > 0 && right < lineText.length; n--, right++) {
|
|
50
|
-
if (!isLetter.test(lineText[right])) {
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
if (isMark.test(lineText[right + 1])) {
|
|
54
|
-
right++;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
left = left < 0 ? 0 : left;
|
|
58
|
-
const t0 = lineText.slice(left, right);
|
|
59
|
-
const tLeft = t0.trimStart();
|
|
60
|
-
left = Math.min(left + t0.length - tLeft.length, start);
|
|
61
|
-
const text = tLeft.trimEnd();
|
|
62
|
-
const context = {
|
|
63
|
-
text,
|
|
64
|
-
offset: left,
|
|
65
|
-
};
|
|
66
|
-
return context;
|
|
67
|
-
}
|
|
68
|
-
export function extractContext(tdo, contextRange) {
|
|
69
|
-
const { line, offset, text } = tdo;
|
|
70
|
-
const start = offset - line.offset;
|
|
71
|
-
const context = lineContext(line.text, start, start + text.length, contextRange);
|
|
72
|
-
context.offset += line.offset;
|
|
73
|
-
return context;
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=extractContext.js.map
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { BufferEncoding } from 'cspell-io';
|
|
2
|
-
import type { Document } from 'cspell-lib';
|
|
3
|
-
import * as cspell from 'cspell-lib';
|
|
4
|
-
import type { GlobOptions } from './glob.js';
|
|
5
|
-
export interface FileInfo {
|
|
6
|
-
filename: string;
|
|
7
|
-
text?: string;
|
|
8
|
-
errorCode?: string;
|
|
9
|
-
}
|
|
10
|
-
export type Perf = cspell.SpellCheckFilePerf;
|
|
11
|
-
export declare function fileInfoToDocument(fileInfo: FileInfo, languageId: string | undefined, locale: string | undefined): Document;
|
|
12
|
-
export declare function filenameToUrl(filename: string | URL, cwd?: string): URL;
|
|
13
|
-
export declare function filenameToUri(filename: string, cwd?: string): URL;
|
|
14
|
-
export declare function isBinaryFile(filename: string, cwd?: string): boolean;
|
|
15
|
-
export interface ReadFileInfoResult extends FileInfo {
|
|
16
|
-
text: string;
|
|
17
|
-
}
|
|
18
|
-
export declare function resolveFilename(filename: string, cwd?: string): string;
|
|
19
|
-
export declare function readFileInfo(filename: string, encoding?: BufferEncoding, handleNotFound?: boolean): Promise<ReadFileInfoResult>;
|
|
20
|
-
export declare function readFile(filename: string, encoding?: BufferEncoding): Promise<string>;
|
|
21
|
-
/**
|
|
22
|
-
* Looks for matching glob patterns or stdin
|
|
23
|
-
* @param globPatterns patterns or stdin
|
|
24
|
-
*/
|
|
25
|
-
export declare function findFiles(globPatterns: string[], options: GlobOptions): Promise<string[]>;
|
|
26
|
-
/**
|
|
27
|
-
* Read
|
|
28
|
-
* @param listFiles - array of file paths to read that will contain a list of files. Paths contained in each
|
|
29
|
-
* file will be resolved relative to the containing file.
|
|
30
|
-
* @returns - a list of files to be processed.
|
|
31
|
-
*/
|
|
32
|
-
export declare function readFileListFiles(listFiles: string[]): AsyncIterable<string>;
|
|
33
|
-
/**
|
|
34
|
-
* Read a `listFile` and return the containing file paths resolved relative to the `listFile`.
|
|
35
|
-
* @param listFiles - array of file paths to read that will contain a list of files. Paths contained in each
|
|
36
|
-
* file will be resolved relative to the containing file.
|
|
37
|
-
* @returns - a list of files to be processed.
|
|
38
|
-
*/
|
|
39
|
-
export declare function readFileListFile(listFile: string): Promise<string[]>;
|
|
40
|
-
export declare function isFile(filename: string): Promise<boolean>;
|
|
41
|
-
export declare function isDir(filename: string): Promise<boolean>;
|
|
42
|
-
export declare function isNotDir(filename: string): Promise<boolean>;
|
|
43
|
-
export declare function relativeToCwd(filename: string | URL, cwd?: string | URL): string;
|
|
44
|
-
//# sourceMappingURL=fileHelper.d.ts.map
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { promises as fsp } from 'node:fs';
|
|
2
|
-
import * as path from 'node:path';
|
|
3
|
-
import streamConsumers from 'node:stream/consumers';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { toFileDirURL, toFilePathOrHref, toFileURL, urlRelative } from '@cspell/url';
|
|
6
|
-
import { readFileText as cioReadFile, toURL } from 'cspell-io';
|
|
7
|
-
import { fileToDocument, isBinaryFile as isUriBinaryFile } from 'cspell-lib';
|
|
8
|
-
import { asyncAwait, asyncFlatten, asyncMap, asyncPipe, mergeAsyncIterables } from './async.js';
|
|
9
|
-
import { FileUrlPrefix, STDIN, STDINProtocol, STDINUrlPrefix, UTF8 } from './constants.js';
|
|
10
|
-
import { IOError, toApplicationError, toError } from './errors.js';
|
|
11
|
-
import { globP } from './glob.js';
|
|
12
|
-
import { readStdin } from './stdin.js';
|
|
13
|
-
import { isStdinUrl, resolveStdinUrl } from './stdinUrl.js';
|
|
14
|
-
import { clean } from './util.js';
|
|
15
|
-
export function fileInfoToDocument(fileInfo, languageId, locale) {
|
|
16
|
-
const { filename, text } = fileInfo;
|
|
17
|
-
languageId = languageId || undefined;
|
|
18
|
-
locale = locale || undefined;
|
|
19
|
-
const uri = filenameToUrl(filename);
|
|
20
|
-
if (uri.href.startsWith(STDINProtocol)) {
|
|
21
|
-
return clean({
|
|
22
|
-
uri: uri.href,
|
|
23
|
-
text,
|
|
24
|
-
languageId,
|
|
25
|
-
locale,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return fileToDocument(uri.href, text, languageId, locale);
|
|
29
|
-
}
|
|
30
|
-
export function filenameToUrl(filename, cwd = '.') {
|
|
31
|
-
if (filename instanceof URL)
|
|
32
|
-
return filename;
|
|
33
|
-
const cwdURL = toFileDirURL(cwd);
|
|
34
|
-
if (filename === STDIN)
|
|
35
|
-
return new URL('stdin:///');
|
|
36
|
-
if (isStdinUrl(filename)) {
|
|
37
|
-
return new URL(resolveStdinUrl(filename, cwd));
|
|
38
|
-
}
|
|
39
|
-
return toFileURL(filename, cwdURL);
|
|
40
|
-
}
|
|
41
|
-
export function filenameToUri(filename, cwd) {
|
|
42
|
-
return toURL(filenameToUrl(filename, cwd));
|
|
43
|
-
}
|
|
44
|
-
export function isBinaryFile(filename, cwd) {
|
|
45
|
-
const uri = filenameToUri(filename, cwd);
|
|
46
|
-
if (uri.protocol.startsWith('stdin'))
|
|
47
|
-
return false;
|
|
48
|
-
return isUriBinaryFile(uri);
|
|
49
|
-
}
|
|
50
|
-
export function resolveFilename(filename, cwd) {
|
|
51
|
-
cwd = cwd || process.cwd();
|
|
52
|
-
if (filename === STDIN)
|
|
53
|
-
return STDINUrlPrefix;
|
|
54
|
-
if (filename.startsWith(FileUrlPrefix)) {
|
|
55
|
-
const url = new URL(filename.slice(FileUrlPrefix.length), toFileDirURL(cwd));
|
|
56
|
-
return fileURLToPath(url);
|
|
57
|
-
}
|
|
58
|
-
if (isStdinUrl(filename)) {
|
|
59
|
-
return resolveStdinUrl(filename, cwd);
|
|
60
|
-
}
|
|
61
|
-
return path.resolve(cwd, filename);
|
|
62
|
-
}
|
|
63
|
-
export function readFileInfo(filename, encoding = UTF8, handleNotFound = false) {
|
|
64
|
-
filename = resolveFilename(filename);
|
|
65
|
-
const pText = filename.startsWith(STDINProtocol)
|
|
66
|
-
? streamConsumers.text(process.stdin)
|
|
67
|
-
: cioReadFile(filename, encoding);
|
|
68
|
-
return pText.then((text) => ({ text, filename }), (e) => {
|
|
69
|
-
const error = toError(e);
|
|
70
|
-
return handleNotFound && error.code === 'EISDIR'
|
|
71
|
-
? Promise.resolve({ text: '', filename, errorCode: error.code })
|
|
72
|
-
: handleNotFound && error.code === 'ENOENT'
|
|
73
|
-
? Promise.resolve({ text: '', filename, errorCode: error.code })
|
|
74
|
-
: Promise.reject(new IOError(`Error reading file: "${filename}"`, error));
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
export function readFile(filename, encoding = UTF8) {
|
|
78
|
-
return readFileInfo(filename, encoding).then((info) => info.text);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Looks for matching glob patterns or stdin
|
|
82
|
-
* @param globPatterns patterns or stdin
|
|
83
|
-
*/
|
|
84
|
-
export async function findFiles(globPatterns, options) {
|
|
85
|
-
const stdin = [];
|
|
86
|
-
const globPats = globPatterns.filter((filename) => !isStdin(filename) && !filename.startsWith(FileUrlPrefix) ? true : (stdin.push(filename), false));
|
|
87
|
-
const globResults = globPats.length ? await globP(globPats, options) : [];
|
|
88
|
-
const cwd = options.cwd || process.cwd();
|
|
89
|
-
return [...stdin, ...globResults].map((filename) => resolveFilename(filename, cwd));
|
|
90
|
-
}
|
|
91
|
-
const resolveFilenames = asyncMap(resolveFilename);
|
|
92
|
-
/**
|
|
93
|
-
* Read
|
|
94
|
-
* @param listFiles - array of file paths to read that will contain a list of files. Paths contained in each
|
|
95
|
-
* file will be resolved relative to the containing file.
|
|
96
|
-
* @returns - a list of files to be processed.
|
|
97
|
-
*/
|
|
98
|
-
export function readFileListFiles(listFiles) {
|
|
99
|
-
let useStdin = false;
|
|
100
|
-
const files = listFiles.filter((file) => {
|
|
101
|
-
const isStdin = file === 'stdin';
|
|
102
|
-
useStdin = useStdin || isStdin;
|
|
103
|
-
return !isStdin;
|
|
104
|
-
});
|
|
105
|
-
const found = asyncPipe(files, asyncMap((file) => readFileListFile(file)), asyncAwait(), asyncFlatten());
|
|
106
|
-
// Move `stdin` to the end.
|
|
107
|
-
const stdin = useStdin ? readStdin() : [];
|
|
108
|
-
return asyncPipe(mergeAsyncIterables(found, stdin), resolveFilenames);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Read a `listFile` and return the containing file paths resolved relative to the `listFile`.
|
|
112
|
-
* @param listFiles - array of file paths to read that will contain a list of files. Paths contained in each
|
|
113
|
-
* file will be resolved relative to the containing file.
|
|
114
|
-
* @returns - a list of files to be processed.
|
|
115
|
-
*/
|
|
116
|
-
export async function readFileListFile(listFile) {
|
|
117
|
-
try {
|
|
118
|
-
const relTo = path.resolve(path.dirname(listFile));
|
|
119
|
-
const content = await readFile(listFile);
|
|
120
|
-
const lines = content
|
|
121
|
-
.split('\n')
|
|
122
|
-
.map((a) => a.trim())
|
|
123
|
-
.filter((a) => !!a)
|
|
124
|
-
.map((file) => path.resolve(relTo, file));
|
|
125
|
-
return lines;
|
|
126
|
-
}
|
|
127
|
-
catch (err) {
|
|
128
|
-
throw toApplicationError(err, `Error reading file list from: "${listFile}"`);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
function isStdin(filename) {
|
|
132
|
-
return filename === STDIN || isStdinUrl(filename);
|
|
133
|
-
}
|
|
134
|
-
export async function isFile(filename) {
|
|
135
|
-
if (isStdin(filename))
|
|
136
|
-
return true;
|
|
137
|
-
try {
|
|
138
|
-
const stat = await fsp.stat(filename);
|
|
139
|
-
return stat.isFile();
|
|
140
|
-
}
|
|
141
|
-
catch {
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
export async function isDir(filename) {
|
|
146
|
-
try {
|
|
147
|
-
const stat = await fsp.stat(filename);
|
|
148
|
-
return stat.isDirectory();
|
|
149
|
-
}
|
|
150
|
-
catch {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
export function isNotDir(filename) {
|
|
155
|
-
return isDir(filename).then((a) => !a);
|
|
156
|
-
}
|
|
157
|
-
export function relativeToCwd(filename, cwd = process.cwd()) {
|
|
158
|
-
const urlCwd = toFileDirURL(cwd);
|
|
159
|
-
const url = toFileURL(filename, urlCwd);
|
|
160
|
-
const rel = urlRelative(urlCwd, url);
|
|
161
|
-
if (rel.startsWith('..'))
|
|
162
|
-
return toFilePathOrHref(url);
|
|
163
|
-
return rel;
|
|
164
|
-
}
|
|
165
|
-
//# sourceMappingURL=fileHelper.js.map
|
package/dist/esm/util/glob.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { CSpellUserSettings, Glob } from '@cspell/cspell-types';
|
|
2
|
-
import type { GlobPatternWithRoot } from 'cspell-glob';
|
|
3
|
-
import { GlobMatcher } from 'cspell-glob';
|
|
4
|
-
/**
|
|
5
|
-
* This is a subset of IOptions from 'glob'.
|
|
6
|
-
*/
|
|
7
|
-
export interface GlobOptions {
|
|
8
|
-
cwd?: string | undefined;
|
|
9
|
-
root?: string | undefined;
|
|
10
|
-
dot?: boolean | undefined;
|
|
11
|
-
nodir?: boolean | undefined;
|
|
12
|
-
ignore?: string | Array<string> | undefined;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @param pattern - glob patterns and NOT file paths. It can be a file path turned into a glob.
|
|
17
|
-
* @param options - search options.
|
|
18
|
-
*/
|
|
19
|
-
export declare function globP(pattern: string | string[], options?: GlobOptions): Promise<string[]>;
|
|
20
|
-
export declare function calcGlobs(commandLineExclude: string[] | undefined): {
|
|
21
|
-
globs: string[];
|
|
22
|
-
source: string;
|
|
23
|
-
};
|
|
24
|
-
export interface GlobSrcInfo {
|
|
25
|
-
matcher: GlobMatcher;
|
|
26
|
-
source: string;
|
|
27
|
-
}
|
|
28
|
-
interface ExtractPatternResult {
|
|
29
|
-
glob: GlobPatternWithRoot;
|
|
30
|
-
source: string;
|
|
31
|
-
}
|
|
32
|
-
export declare function extractPatterns(globs: GlobSrcInfo[]): ExtractPatternResult[];
|
|
33
|
-
export declare function calcExcludeGlobInfo(root: string, commandLineExclude: string[] | string | undefined): GlobSrcInfo[];
|
|
34
|
-
export declare function extractGlobExcludesFromConfig(root: string, source: string, config: CSpellUserSettings): GlobSrcInfo[];
|
|
35
|
-
/**
|
|
36
|
-
* Build GlobMatcher from command line or config file globs.
|
|
37
|
-
* @param globs Glob patterns or file paths
|
|
38
|
-
* @param root - directory to use as the root
|
|
39
|
-
*/
|
|
40
|
-
export declare function buildGlobMatcher(globs: Glob[], root: string, isExclude: boolean): GlobMatcher;
|
|
41
|
-
export declare function extractGlobsFromMatcher(globMatcher: GlobMatcher): string[];
|
|
42
|
-
export declare function normalizeGlobsToRoot(globs: Glob[], root: string, isExclude: boolean): string[];
|
|
43
|
-
export declare function normalizeFileOrGlobsToRoot(globs: Glob[], root: string): Promise<string[]>;
|
|
44
|
-
export {};
|
|
45
|
-
//# sourceMappingURL=glob.d.ts.map
|
package/dist/esm/util/glob.js
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from 'node:fs';
|
|
2
|
-
import * as path from 'node:path';
|
|
3
|
-
import { posix } from 'node:path';
|
|
4
|
-
import { fileOrGlobToGlob, GlobMatcher, workaroundPicomatchBug } from 'cspell-glob';
|
|
5
|
-
import { glob as tinyGlob } from 'tinyglobby';
|
|
6
|
-
import { clean } from './util.js';
|
|
7
|
-
const defaultExcludeGlobs = ['node_modules/**'];
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @param pattern - glob patterns and NOT file paths. It can be a file path turned into a glob.
|
|
11
|
-
* @param options - search options.
|
|
12
|
-
*/
|
|
13
|
-
export async function globP(pattern, options) {
|
|
14
|
-
const cwd = options?.root || options?.cwd || process.cwd();
|
|
15
|
-
const ignoreRaw = typeof options?.ignore === 'string' ? [options.ignore] : options?.ignore;
|
|
16
|
-
const ignore = ignoreRaw?.filter((g) => !g.startsWith('../'));
|
|
17
|
-
const onlyFiles = options?.nodir;
|
|
18
|
-
const dot = options?.dot;
|
|
19
|
-
const patterns = typeof pattern === 'string' ? [pattern] : pattern;
|
|
20
|
-
const useOptions = clean({
|
|
21
|
-
cwd,
|
|
22
|
-
onlyFiles,
|
|
23
|
-
dot,
|
|
24
|
-
ignore,
|
|
25
|
-
absolute: true,
|
|
26
|
-
followSymbolicLinks: false,
|
|
27
|
-
expandDirectories: false,
|
|
28
|
-
// debug: true,
|
|
29
|
-
});
|
|
30
|
-
const compare = new Intl.Collator('en').compare;
|
|
31
|
-
const absolutePaths = (await glob(patterns, useOptions)).sort(compare);
|
|
32
|
-
const relativePaths = absolutePaths.map((absFilename) => path.relative(cwd, absFilename));
|
|
33
|
-
return relativePaths;
|
|
34
|
-
}
|
|
35
|
-
export function calcGlobs(commandLineExclude) {
|
|
36
|
-
const globs = new Set((commandLineExclude || []).flatMap((glob) => glob.split(/(?<!\\)\s+/g)).map((g) => g.replaceAll('\\ ', ' ')));
|
|
37
|
-
const commandLineExcludes = {
|
|
38
|
-
globs: [...globs],
|
|
39
|
-
source: 'arguments',
|
|
40
|
-
};
|
|
41
|
-
const defaultExcludes = {
|
|
42
|
-
globs: defaultExcludeGlobs,
|
|
43
|
-
source: 'default',
|
|
44
|
-
};
|
|
45
|
-
return commandLineExcludes.globs.length ? commandLineExcludes : defaultExcludes;
|
|
46
|
-
}
|
|
47
|
-
export function extractPatterns(globs) {
|
|
48
|
-
const r = globs.reduce((info, g) => {
|
|
49
|
-
const source = g.source;
|
|
50
|
-
const patterns = g.matcher.patternsNormalizedToRoot;
|
|
51
|
-
return [...info, ...patterns.map((glob) => ({ glob, source }))];
|
|
52
|
-
}, []);
|
|
53
|
-
return r;
|
|
54
|
-
}
|
|
55
|
-
export function calcExcludeGlobInfo(root, commandLineExclude) {
|
|
56
|
-
commandLineExclude = typeof commandLineExclude === 'string' ? [commandLineExclude] : commandLineExclude;
|
|
57
|
-
const choice = calcGlobs(commandLineExclude);
|
|
58
|
-
const matcher = new GlobMatcher(choice.globs, { root, dot: true });
|
|
59
|
-
return [
|
|
60
|
-
{
|
|
61
|
-
matcher,
|
|
62
|
-
source: choice.source,
|
|
63
|
-
},
|
|
64
|
-
];
|
|
65
|
-
}
|
|
66
|
-
export function extractGlobExcludesFromConfig(root, source, config) {
|
|
67
|
-
if (!config.ignorePaths || !config.ignorePaths.length) {
|
|
68
|
-
return [];
|
|
69
|
-
}
|
|
70
|
-
const matcher = new GlobMatcher(config.ignorePaths, { root, dot: true });
|
|
71
|
-
return [{ source, matcher }];
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Build GlobMatcher from command line or config file globs.
|
|
75
|
-
* @param globs Glob patterns or file paths
|
|
76
|
-
* @param root - directory to use as the root
|
|
77
|
-
*/
|
|
78
|
-
export function buildGlobMatcher(globs, root, isExclude) {
|
|
79
|
-
const withRoots = globs.map((g) => {
|
|
80
|
-
const source = typeof g === 'string' ? 'command line' : undefined;
|
|
81
|
-
return { source, ...fileOrGlobToGlob(g, root) };
|
|
82
|
-
});
|
|
83
|
-
return new GlobMatcher(withRoots, { root, mode: isExclude ? 'exclude' : 'include' });
|
|
84
|
-
}
|
|
85
|
-
export function extractGlobsFromMatcher(globMatcher) {
|
|
86
|
-
return globMatcher.patternsNormalizedToRoot.map((g) => g.glob);
|
|
87
|
-
}
|
|
88
|
-
export function normalizeGlobsToRoot(globs, root, isExclude) {
|
|
89
|
-
const urls = globs.filter((g) => typeof g === 'string' && isPossibleUrlRegExp.test(g));
|
|
90
|
-
const onlyGlobs = globs.filter((g) => typeof g !== 'string' || !isPossibleUrlRegExp.test(g));
|
|
91
|
-
return [urls, extractGlobsFromMatcher(buildGlobMatcher(onlyGlobs, root, isExclude))].flat();
|
|
92
|
-
}
|
|
93
|
-
const isPossibleGlobRegExp = /[()*?[{}]/;
|
|
94
|
-
const isPossibleUrlRegExp = /^[\d_a-z-]{3,}:\/\//;
|
|
95
|
-
/**
|
|
96
|
-
* If a 'glob' is a path to a directory, then append `**` so that
|
|
97
|
-
* directory searches work.
|
|
98
|
-
* @param glob - a glob, file, or directory
|
|
99
|
-
* @param root - root to use.
|
|
100
|
-
* @returns `**` is appended directories.
|
|
101
|
-
*/
|
|
102
|
-
async function adjustPossibleDirectory(glob, root) {
|
|
103
|
-
const g = typeof glob === 'string'
|
|
104
|
-
? {
|
|
105
|
-
glob,
|
|
106
|
-
root,
|
|
107
|
-
}
|
|
108
|
-
: {
|
|
109
|
-
glob: glob.glob,
|
|
110
|
-
root: glob.root ?? root,
|
|
111
|
-
};
|
|
112
|
-
// Do not ask the file system to look up obvious glob patterns.
|
|
113
|
-
if (isPossibleGlobRegExp.test(g.glob)) {
|
|
114
|
-
return glob;
|
|
115
|
-
}
|
|
116
|
-
if (isPossibleUrlRegExp.test(g.glob)) {
|
|
117
|
-
return glob;
|
|
118
|
-
}
|
|
119
|
-
const dirPath = path.resolve(g.root, g.glob);
|
|
120
|
-
try {
|
|
121
|
-
const stat = await fs.stat(dirPath);
|
|
122
|
-
if (stat.isDirectory()) {
|
|
123
|
-
const useGlob = posix.join(posixPath(g.glob), '**');
|
|
124
|
-
return typeof glob === 'string' ? useGlob : { ...glob, glob: useGlob };
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
// it was not possible to access the dirPath, no problem, just let the file glob search look for it.
|
|
129
|
-
return glob;
|
|
130
|
-
}
|
|
131
|
-
return glob;
|
|
132
|
-
}
|
|
133
|
-
function posixPath(p) {
|
|
134
|
-
return path.sep === '\\' ? p.replaceAll('\\', '/') : p;
|
|
135
|
-
}
|
|
136
|
-
export async function normalizeFileOrGlobsToRoot(globs, root) {
|
|
137
|
-
const adjustedGlobs = await Promise.all(globs.map((g) => adjustPossibleDirectory(g, root)));
|
|
138
|
-
return normalizeGlobsToRoot(adjustedGlobs, root, false);
|
|
139
|
-
}
|
|
140
|
-
function glob(patterns, options) {
|
|
141
|
-
patterns =
|
|
142
|
-
typeof patterns === 'string'
|
|
143
|
-
? workaroundPicomatchBug(patterns)
|
|
144
|
-
: patterns.map((g) => workaroundPicomatchBug(g));
|
|
145
|
-
return tinyGlob(patterns, options);
|
|
146
|
-
}
|
|
147
|
-
//# sourceMappingURL=glob.js.map
|