Skip to content

Commit

Permalink
feat: only import exclusive dependencies from vite-plugin-checker-vls
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Jul 17, 2021
1 parent 8823409 commit 8ba0641
Show file tree
Hide file tree
Showing 6 changed files with 614 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/checker-vls/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,14 @@ declare const VlsChecker: (

export { VlsChecker }
export type { VlsConfig }

import commander from 'commander'

export * as vscodeLanguageserverProtocol from 'vscode-languageserver-protocol'
export * as vscodeUri from 'vscode-uri'
export * as chokidar from 'chokidar'
export * as vls from 'vls'
export { commander }

export * as vscodeLanguageserverNode from 'vscode-languageserver/node'
export * as vscodeLanguageserverTextdocument from 'vscode-languageserver-textdocument'
47 changes: 47 additions & 0 deletions packages/vite-plugin-checker/src/checkers/vls2/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// import { Command, Option } from 'commander'
import { commander } from 'vite-plugin-checker-vls'

import { diagnostics, LogLevel, logLevels } from './commands/diagnostics'

function getVersion(): string {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { version }: { version: string } = require('../package.json')
return `v${version}`
}

function validateLogLevel(logLevelInput: unknown): logLevelInput is LogLevel {
return (
typeof logLevelInput === 'string' &&
(logLevels as ReadonlyArray<string>).includes(logLevelInput)
)
}

;(async () => {
const program = new commander.Command()
program.name('vti').description('Vetur Terminal Interface').version(getVersion())

program
.command('diagnostics [workspace]')
.description('Print all diagnostics')
.addOption(
new commander.Option('-l, --log-level <logLevel>', 'Log level to print')
.default('WARN')
// logLevels is readonly array but .choices need read-write array (because of weak typing)
.choices(logLevels as unknown as string[])
)
.action(async (workspace, options) => {
const logLevelOption: unknown = options.logLevel

if (!validateLogLevel(logLevelOption)) {
throw new Error(`Invalid log level: ${logLevelOption}`)
}

await diagnostics(workspace, logLevelOption)
})

program.parse(process.argv)
})().catch((err) => {
console.error(`VTI operation failed with error`)
console.error(err.stack)
process.exit(1)
})
Loading

0 comments on commit 8ba0641

Please sign in to comment.