From 3e925b9d7c3de36fb6126a50e9f40a69a642ac01 Mon Sep 17 00:00:00 2001 From: chemzqm Date: Thu, 13 Jun 2019 22:52:57 +0800 Subject: [PATCH] replace find-up --- package.json | 2 -- src/server/features/watchBuild.ts | 11 +++++------ src/server/utils/modules.ts | 14 ++++++-------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 94110ce..ee96810 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/server/features/watchBuild.ts b/src/server/features/watchBuild.ts index 7abb2f2..b68b007 100644 --- a/src/server/features/watchBuild.ts +++ b/src/server/features/watchBuild.ts @@ -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 { 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 { + 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 diff --git a/src/server/utils/modules.ts b/src/server/utils/modules.ts index 717d386..6d137a6 100644 --- a/src/server/utils/modules.ts +++ b/src/server/utils/modules.ts @@ -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 { return new Promise((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 { + 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 { + let res = await workspace.findUp(['package.json']) if (!res) return null return path.dirname(res) } @@ -74,7 +72,7 @@ export function distinct(array: T[], keyFn?: (t: T) => string): T[] { export async function installModules(uri: string, names: string[]): Promise { 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 s != null) if (!exists.length) return let devs = exists.filter(s => s.startsWith('@types'))