replace find-up
This commit is contained in:
parent
0d84cdf870
commit
3e925b9d7c
3 changed files with 11 additions and 16 deletions
|
@ -470,7 +470,6 @@
|
|||
"@chemzqm/tsconfig": "^0.0.3",
|
||||
"@chemzqm/tslint-config": "^1.0.18",
|
||||
"@types/fast-diff": "^1.2.0",
|
||||
"@types/find-up": "^2.1.1",
|
||||
"@types/node": "^12.0.7",
|
||||
"coc.nvim": "^0.0.69",
|
||||
"rimraf": "^2.6.3",
|
||||
|
@ -478,7 +477,6 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"fast-diff": "^1.2.0",
|
||||
"find-up": "^4.0.0",
|
||||
"semver": "^6.1.1",
|
||||
"tslib": "^1.9.3",
|
||||
"typescript": "3.5.1",
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { Uri, disposeAll, StatusBarItem, TaskOptions, workspace } from 'coc.nvim'
|
||||
import { CommandManager } from 'coc.nvim/lib/commands'
|
||||
import Task from 'coc.nvim/lib/model/task'
|
||||
import findUp from 'find-up'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { Disposable, Location } from 'vscode-languageserver-protocol'
|
||||
|
@ -37,7 +36,7 @@ export default class WatchProject implements Disposable {
|
|||
this.statusItem = workspace.createStatusBarItem(1, { progress: true })
|
||||
let task = this.task = workspace.createTask('TSC')
|
||||
this.disposables.push(commandManager.registerCommand(WatchProject.id, async () => {
|
||||
let opts = this.options = this.getOptions()
|
||||
let opts = this.options = await this.getOptions()
|
||||
await this.start(opts)
|
||||
}))
|
||||
task.onExit(code => {
|
||||
|
@ -65,7 +64,7 @@ export default class WatchProject implements Disposable {
|
|||
private async check(): Promise<void> {
|
||||
let running = await this.task.running
|
||||
if (running) {
|
||||
this.options = this.getOptions()
|
||||
this.options = await this.getOptions()
|
||||
this.statusItem.isProgress = false
|
||||
this.statusItem.text = '?'
|
||||
this.statusItem.show()
|
||||
|
@ -115,8 +114,8 @@ export default class WatchProject implements Disposable {
|
|||
}
|
||||
}
|
||||
|
||||
public getOptions(): TaskOptions {
|
||||
let res = findUp.sync(['node_modules'], { cwd: workspace.root })
|
||||
public async getOptions(): Promise<TaskOptions> {
|
||||
let res = await workspace.findUp(['node_modules'])
|
||||
let root: string
|
||||
let cmd: string
|
||||
// let root: string
|
||||
|
@ -136,7 +135,7 @@ export default class WatchProject implements Disposable {
|
|||
workspace.showMessage(`Local & global tsc not found`, 'error')
|
||||
return
|
||||
}
|
||||
let find = findUp.sync(['tsconfig.json'], { cwd: root })
|
||||
let find = await workspace.findUp(['tsconfig.json'])
|
||||
if (!find) {
|
||||
workspace.showMessage('tsconfig.json not found!', 'error')
|
||||
return
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { exec } from 'child_process'
|
||||
import path from 'path'
|
||||
import { Uri, workspace } from 'coc.nvim'
|
||||
import findUp from 'find-up'
|
||||
|
||||
export function runCommand(cmd: string, cwd: string, timeout?: number): Promise<string> {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
|
@ -22,15 +21,14 @@ export function runCommand(cmd: string, cwd: string, timeout?: number): Promise<
|
|||
})
|
||||
}
|
||||
|
||||
function getManager(uri: string): string {
|
||||
let dir = path.dirname(Uri.parse(uri).fsPath)
|
||||
let res = findUp.sync(['yarn.lock', 'package-lock.json'], { cwd: dir })
|
||||
async function getManager(): Promise<string> {
|
||||
let res = await workspace.findUp(['yarn.lock', 'package-lock.json'])
|
||||
if (!res) return 'yarn'
|
||||
return res.endsWith('yarn.lock') ? 'yarn' : 'npm'
|
||||
}
|
||||
|
||||
function getRoot(): string | null {
|
||||
let res = findUp.sync(['package.json'], { cwd: workspace.cwd })
|
||||
async function getRoot(): Promise<string | null> {
|
||||
let res = await workspace.findUp(['package.json'])
|
||||
if (!res) return null
|
||||
return path.dirname(res)
|
||||
}
|
||||
|
@ -74,7 +72,7 @@ export function distinct<T>(array: T[], keyFn?: (t: T) => string): T[] {
|
|||
|
||||
export async function installModules(uri: string, names: string[]): Promise<void> {
|
||||
names = distinct(names)
|
||||
let root = getRoot()
|
||||
let root = await getRoot()
|
||||
if (!root) {
|
||||
workspace.showMessage(`package.json not found from cwd: ${workspace.cwd}`, 'error')
|
||||
return
|
||||
|
@ -88,7 +86,7 @@ export async function installModules(uri: string, names: string[]): Promise<void
|
|||
return exists ? name : null
|
||||
})
|
||||
}))
|
||||
let manager = getManager(uri)
|
||||
let manager = await getManager()
|
||||
exists = exists.filter(s => s != null)
|
||||
if (!exists.length) return
|
||||
let devs = exists.filter(s => s.startsWith('@types'))
|
||||
|
|
Loading…
Reference in a new issue