Skip to content

Commit

Permalink
Merge 7cd5aff into 1b466cf
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S committed Jan 26, 2022
2 parents 1b466cf + 7cd5aff commit 750353d
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 18 deletions.
1 change: 1 addition & 0 deletions packages/cspell/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/api
111 changes: 110 additions & 1 deletion packages/cspell/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/cspell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
],
"scripts": {
"clean": "rimraf dist coverage .tsbuildinfo",
"build": "npm run compile",
"build": "npm run compile && npm run build-api",
"build-api": "rollup -c rollup.config.mjs",
"build-dev": "tsc -p tsconfig.dev.json",
"clean-build": "npm run clean && npm run build",
"compile": "tsc -p .",
Expand Down Expand Up @@ -101,6 +102,8 @@
"jest": "^27.4.7",
"micromatch": "^4.0.4",
"minimatch": "^3.0.4",
"rimraf": "^3.0.2"
"rimraf": "^3.0.2",
"rollup": "^2.66.1",
"rollup-plugin-dts": "^4.1.0"
}
}
21 changes: 21 additions & 0 deletions packages/cspell/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import dts from 'rollup-plugin-dts';

const config = [
{
input: './dist/index.d.ts',
output: [{ file: './api/index.d.ts', format: 'es' }],
plugins: [dts()],
},
{
input: './dist/application.d.ts',
output: [{ file: './api/application.d.ts', format: 'es' }],
plugins: [dts()],
},
{
input: './dist/app.d.ts',
output: [{ file: './api/app.d.ts', format: 'es' }],
plugins: [dts()],
},
];

export default config;
13 changes: 7 additions & 6 deletions packages/cspell/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import * as commander from 'commander';
import type { Command } from 'commander';
import { program } from 'commander';
import * as path from 'path';
import * as semver from 'semver';
import { satisfies as semverSatisfies } from 'semver';
import { commandCheck } from './commandCheck';
import { commandLink } from './commandLink';
import { commandLint } from './commandLint';
import { commandTrace } from './commandTrace';
import { commandSuggestion } from './commandSuggestion';
import { commandTrace } from './commandTrace';
import { ApplicationError } from './util/errors';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const npmPackage = require(path.join(__dirname, '..', 'package.json'));

export { LinterCliOptions as Options } from './options';
export { CheckFailed } from './util/errors';

export async function run(program?: commander.Command, argv?: string[]): Promise<void> {
const prog = program || commander.program;
export async function run(command?: Command, argv?: string[]): Promise<void> {
const prog = command || program;
const args = argv || process.argv;

prog.exitOverride();

prog.version(npmPackage.version).description('Spelling Checker for Code').name('cspell');

if (!semver.satisfies(process.versions.node, npmPackage.engines.node)) {
if (!semverSatisfies(process.versions.node, npmPackage.engines.node)) {
throw new ApplicationError(
`Unsupported NodeJS version (${process.versions.node}); ${npmPackage.engines.node} is required`
);
Expand Down
22 changes: 15 additions & 7 deletions packages/cspell/src/application.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import type { CSpellReporter, RunResult } from '@cspell/cspell-types';
import * as cspell from 'cspell-lib';
import { CheckTextInfo, TraceResult, traceWordsAsync, suggestionsForWords, SuggestionError } from 'cspell-lib';
import type { CheckTextInfo, SuggestionsForWordResult, TraceResult } from 'cspell-lib';
import {
checkText as cspellLibCheckText,
getDefaultSettings,
getGlobalSettings,
mergeSettings,
SuggestionError,
suggestionsForWords,
traceWordsAsync,
} from 'cspell-lib';
import * as path from 'path';
import { calcFinalConfigInfo, readConfig, readFile } from './util/fileHelper';
import { LintRequest, runLint } from './lint';
import { BaseOptions, fixLegacy, LegacyOptions, LinterOptions, SuggestionOptions, TraceOptions } from './options';
import * as async from './util/async';
import { calcFinalConfigInfo, readConfig, readFile } from './util/fileHelper';
import { readStdin } from './util/stdin';
import * as util from './util/util';
import * as async from './util/async';
export { IncludeExcludeFlag } from 'cspell-lib';
export type { TraceResult } from 'cspell-lib';

Expand All @@ -24,7 +32,7 @@ export async function* trace(words: string[], options: TraceOptions): AsyncItera
const iWords = options.stdin ? async.mergeAsyncIterables(words, readStdin()) : words;
const { languageId, locale, allowCompoundWords, ignoreCase } = options;
const configFile = await readConfig(options.config, undefined);
const config = cspell.mergeSettings(cspell.getDefaultSettings(), cspell.getGlobalSettings(), configFile.config);
const config = mergeSettings(getDefaultSettings(), getGlobalSettings(), configFile.config);
yield* traceWordsAsync(iWords, config, { languageId, locale, ignoreCase, allowCompoundWords });
}

Expand All @@ -39,13 +47,13 @@ export async function checkText(filename: string, options: BaseOptions & LegacyO
language: options.locale || options.local || undefined,
});
const info = calcFinalConfigInfo(foundSettings, settingsFromCommandLine, filename, text);
return cspell.checkText(text, info.configInfo.config);
return cspellLibCheckText(text, info.configInfo.config);
}

export async function* suggestions(
words: string[],
options: SuggestionOptions
): AsyncIterable<cspell.SuggestionsForWordResult> {
): AsyncIterable<SuggestionsForWordResult> {
options = fixLegacy(options);
const configFile = await readConfig(options.config, undefined);
const iWords = options.useStdin ? async.mergeAsyncIterables(words, readStdin()) : words;
Expand Down
14 changes: 12 additions & 2 deletions packages/cspell/src/util/glob.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import type { CSpellUserSettings, Glob } from '@cspell/cspell-types';
import { fileOrGlobToGlob, GlobMatcher, GlobPatternWithRoot } from 'cspell-glob';
import glob from 'glob';
import type { IGlob, IOptions as IGlobOptions } from 'glob';
import * as path from 'path';

export type GlobOptions = IGlobOptions;
/**
* This is a subset of IOptions from 'glob'.
*/
export interface GlobOptions {
cwd?: string | undefined;
root?: string | undefined;
dot?: boolean | undefined;
nodir?: boolean | undefined; // cspell:ignore nodir
ignore?: string | ReadonlyArray<string> | undefined;
}

type IGlob = ReturnType<typeof glob>;

const defaultExcludeGlobs = ['node_modules/**'];

Expand Down

0 comments on commit 750353d

Please sign in to comment.