Skip to content

Commit

Permalink
Provide node-pty package for plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Jan 13, 2025
1 parent d8022a1 commit b523d2d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/plugin-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"lodash.clonedeep": "^4.5.0",
"macaddress": "^0.5.3",
"mime": "^2.4.4",
"node-pty": "1.1.0-beta27",
"ps-tree": "^1.2.0",
"semver": "^7.5.4",
"tslib": "^2.6.2",
Expand Down
7 changes: 5 additions & 2 deletions packages/plugin-ext/src/hosted/node/plugin-host-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import { dynamicRequire, removeFromCache } from '@theia/core/lib/node/dynamic-require';
import { ContainerModule, inject, injectable, postConstruct, unmanaged } from '@theia/core/shared/inversify';
import { AbstractPluginManagerExtImpl, PluginHost, PluginManagerExtImpl } from '../../plugin/plugin-manager';
import { MAIN_RPC_CONTEXT, Plugin, PluginAPIFactory, PluginManager,
import {
MAIN_RPC_CONTEXT, Plugin, PluginAPIFactory, PluginManager,
LocalizationExt
} from '../../common/plugin-api-rpc';
import { PluginMetadata, PluginModel } from '../../common/plugin-protocol';
Expand All @@ -41,6 +42,7 @@ import { connectProxyResolver } from './plugin-host-proxy';
import { LocalizationExtImpl } from '../../plugin/localization-ext';
import { RPCProtocol, ProxyIdentifier } from '../../common/rpc-protocol';
import { PluginApiCache } from '../../plugin/node/plugin-container-module';
import { overridePluginDependencies } from './plugin-require-override';

/**
* The full set of all possible `Ext` interfaces that a plugin manager can support.
Expand Down Expand Up @@ -107,6 +109,7 @@ export abstract class AbstractPluginHostRPC<PM extends AbstractPluginManagerExtI

@postConstruct()
initialize(): void {
overridePluginDependencies();
this.pluginManager.setPluginHost(this.createPluginHost());

const extInterfaces = this.createExtInterfaces();
Expand Down Expand Up @@ -273,7 +276,7 @@ export abstract class AbstractPluginHostRPC<PM extends AbstractPluginManagerExtI
* @param extApi the extension API to initialize, if appropriate
* @throws if any error occurs in initializing the extension API
*/
protected abstract initExtApi(extApi: ExtPluginApi): void;
protected abstract initExtApi(extApi: ExtPluginApi): void;
}

/**
Expand Down
45 changes: 45 additions & 0 deletions packages/plugin-ext/src/hosted/node/plugin-require-override.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/********************************************************************************
* Copyright (C) 2024 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
********************************************************************************/

import * as nodePty from 'node-pty';

const overrides = [
{
package: 'node-pty',
module: nodePty
}
];

/**
* Some plugins attempt to require some packages from VSCode's node_modules.
* Since we don't have node_modules usually, we need to override the require function to return the expected package.
*
* See also:
* https://github.com/eclipse-theia/theia/issues/14714
* https://github.com/eclipse-theia/theia/issues/13779
*/
export function overridePluginDependencies(): void {
const node_module = require('module');
const original = node_module._load;
node_module._load = function (request: string): unknown {
for (const filter of overrides) {
if (request === filter.package || request.endsWith(`node_modules/${filter.package}`) || request.endsWith(`node_modules\\${filter.package}`)) {
return filter.module;
}
}
return original.apply(this, arguments);
};
}

0 comments on commit b523d2d

Please sign in to comment.