-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide node-pty package for plugins
- Loading branch information
Showing
4 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/plugin-ext/src/hosted/node/plugin-require-override.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
} |