Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin-ext: fix local-dir resolution #8385

Merged
merged 1 commit into from
Aug 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<void> {

// 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);
akosyakov marked this conversation as resolved.
Show resolved Hide resolved
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) => {
Expand All @@ -56,10 +55,7 @@ export class LocalDirectoryPluginDeployerResolver implements PluginDeployerResol
});
resolve(true);
});

});

return Promise.resolve();
}
accept(pluginId: string): boolean {
return pluginId.startsWith(LocalDirectoryPluginDeployerResolver.LOCAL_DIR);
Expand Down