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

Fix self-hosting on Windows #6316

Merged
merged 1 commit into from
Jan 8, 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
41 changes: 14 additions & 27 deletions packages/plugin-dev/src/node/hosted-plugins-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import { inject, injectable } from 'inversify';
import * as cp from 'child_process';
import * as fs from 'fs';
import { sep as PATH_SEPARATOR } from 'path';
import * as path from 'path';
import { FileUri } from '@theia/core/lib/node';
import { HostedPluginSupport } from '@theia/plugin-ext/lib/hosted/node/hosted-plugin';
import { LogType } from '@theia/plugin-ext/lib/common/types';

Expand Down Expand Up @@ -60,7 +61,7 @@ export class HostedPluginsManagerImpl implements HostedPluginsManager {
}

runWatchCompilation(uri: string): Promise<void> {
const pluginRootPath = this.getFsPath(uri);
const pluginRootPath = FileUri.fsPath(uri);

if (this.watchCompilationRegistry.has(pluginRootPath)) {
throw new Error('Watcher is already running in ' + pluginRootPath);
Expand All @@ -78,7 +79,7 @@ export class HostedPluginsManagerImpl implements HostedPluginsManager {
}

stopWatchCompilation(uri: string): Promise<void> {
const pluginPath = this.getFsPath(uri);
const pluginPath = FileUri.fsPath(uri);

const watchProcess = this.watchCompilationRegistry.get(pluginPath);
if (!watchProcess) {
Expand All @@ -90,27 +91,27 @@ export class HostedPluginsManagerImpl implements HostedPluginsManager {
}

isWatchCompilationRunning(uri: string): Promise<boolean> {
const pluginPath = this.getFsPath(uri);
const pluginPath = FileUri.fsPath(uri);

return new Promise(resolve => resolve(this.watchCompilationRegistry.has(pluginPath)));
}

protected runWatchScript(path: string): Promise<void> {
const watchProcess = cp.spawn('yarn', ['run', 'watch'], { cwd: path });
watchProcess.on('exit', () => this.unregisterWatchScript(path));
protected runWatchScript(pluginRootPath: string): Promise<void> {
const watchProcess = cp.spawn('yarn', ['run', 'watch'], { cwd: pluginRootPath, shell: true });
watchProcess.on('exit', () => this.unregisterWatchScript(pluginRootPath));

this.watchCompilationRegistry.set(path, watchProcess);
this.watchCompilationRegistry.set(pluginRootPath, watchProcess);
this.hostedPluginSupport.sendLog({
data: 'Compilation watcher has been started in ' + path,
data: 'Compilation watcher has been started in ' + pluginRootPath,
type: LogType.Info
});
return Promise.resolve();
}

protected unregisterWatchScript(path: string): void {
this.watchCompilationRegistry.delete(path);
protected unregisterWatchScript(pluginRootPath: string): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, why do we need to rename path to pluginRootPath, it's adding extra changes ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it improves the code, as it better describes the purpose of the variable and puts it more in line with the rest of the module.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westbury Was there a compilation warning/error because of a shadowed module variable path?

Copy link
Contributor Author

@westbury westbury Oct 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akosyakov The rename was not technically required, as I could have used a different name for the path import. I thought it was a good idea to make the code a little bit clearer by using the same name for paths that are specifically a path to the plugin root.

this.watchCompilationRegistry.delete(pluginRootPath);
this.hostedPluginSupport.sendLog({
data: 'Compilation watcher has been stopped in ' + path,
data: 'Compilation watcher has been stopped in ' + pluginRootPath,
type: LogType.Info
});
}
Expand All @@ -121,7 +122,7 @@ export class HostedPluginsManagerImpl implements HostedPluginsManager {
* @param pluginPath path to plugin's root directory
*/
protected checkWatchScript(pluginPath: string): boolean {
const pluginPackageJsonPath = pluginPath + 'package.json';
const pluginPackageJsonPath = path.join(pluginPath, 'package.json');
if (fs.existsSync(pluginPackageJsonPath)) {
const packageJson = require(pluginPackageJsonPath);
const scripts = packageJson['scripts'];
Expand All @@ -132,18 +133,4 @@ export class HostedPluginsManagerImpl implements HostedPluginsManager {
return false;
}

protected getFsPath(uri: string): string {
if (!uri.startsWith('file')) {
throw new Error('Plugin uri ' + uri + ' is not supported.');
}

const path = uri.substring(uri.indexOf('://') + 3);

if (!path.endsWith(PATH_SEPARATOR)) {
return path + PATH_SEPARATOR;
}

return path;
}

}