From 12eabf03efda23012a5fbf182b312b60caa2554b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Mar=C3=A9chal?= Date: Fri, 14 Aug 2020 08:15:51 -0400 Subject: [PATCH] plugin-ext: fix local-dir resolution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Windows: Extensions are not picked up from the user's home. Node's FS API. Use `FileUri.fsPath` to get a valid system path. Signed-off-by: Paul Maréchal --- .../node/resolvers/plugin-local-dir-resolver.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/plugin-ext/src/main/node/resolvers/plugin-local-dir-resolver.ts b/packages/plugin-ext/src/main/node/resolvers/plugin-local-dir-resolver.ts index 5d7e001591323..7e9de4a3d11c7 100644 --- a/packages/plugin-ext/src/main/node/resolvers/plugin-local-dir-resolver.ts +++ b/packages/plugin-ext/src/main/node/resolvers/plugin-local-dir-resolver.ts @@ -20,6 +20,8 @@ import { PluginDeployerResolver, PluginDeployerResolverContext } from '../../../ import { injectable } from 'inversify'; import * as fs from 'fs'; import * as path from 'path'; +import { FileUri } from '@theia/core/lib/node'; +import URI from '@theia/core/lib/common/uri'; @injectable() export class LocalDirectoryPluginDeployerResolver implements PluginDeployerResolver { @@ -30,23 +32,20 @@ export class LocalDirectoryPluginDeployerResolver implements PluginDeployerResol * Check all files/folder from the local-dir referenced and add them as plugins. */ async resolve(pluginResolverContext: PluginDeployerResolverContext): Promise { - // get directory - const localDirSetting = pluginResolverContext.getOriginId(); - if (!localDirSetting.startsWith(LocalDirectoryPluginDeployerResolver.LOCAL_DIR)) { + const localDirUri = new URI(pluginResolverContext.getOriginId()); + if (localDirUri.scheme !== LocalDirectoryPluginDeployerResolver.LOCAL_DIR) { return; } - // remove prefix - let dirPath = localDirSetting.substring(LocalDirectoryPluginDeployerResolver.LOCAL_DIR.length + 1); + // get fs path + let dirPath = FileUri.fsPath(localDirUri); if (!path.isAbsolute(dirPath)) { dirPath = path.resolve(process.cwd(), dirPath); } - // check directory exists if (!fs.existsSync(dirPath)) { console.warn(`The directory referenced by ${pluginResolverContext.getOriginId()} does not exist.`); return; - } // list all stuff from this directory await new Promise((resolve: any, reject: any) => { @@ -56,10 +55,7 @@ export class LocalDirectoryPluginDeployerResolver implements PluginDeployerResol }); resolve(true); }); - }); - - return Promise.resolve(); } accept(pluginId: string): boolean { return pluginId.startsWith(LocalDirectoryPluginDeployerResolver.LOCAL_DIR);