Skip to content

Commit 8aaf65e

Browse files
author
Akos Kitta
committed
fix: workaround for # in the app path
Signed-off-by: Akos Kitta <[email protected]>
1 parent 26d3963 commit 8aaf65e

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

arduino-ide-extension/src/node/arduino-ide-backend-module.ts

+11
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ import { MessagingContribution } from './theia/core/messaging-contribution';
113113
import { MessagingService } from '@theia/core/lib/node/messaging/messaging-service';
114114
import { HostedPluginReader } from './theia/plugin-ext/plugin-reader';
115115
import { HostedPluginReader as TheiaHostedPluginReader } from '@theia/plugin-ext/lib/hosted/node/plugin-reader';
116+
import { PluginDeployer } from '@theia/plugin-ext/lib/common/plugin-protocol';
117+
import {
118+
LocalDirectoryPluginDeployerResolverWithFallback,
119+
PluginDeployer_GH_12064,
120+
} from './theia/plugin-ext/plugin-deployer';
116121

117122
export default new ContainerModule((bind, unbind, isBound, rebind) => {
118123
bind(BackendApplication).toSelf().inSingletonScope();
@@ -392,6 +397,12 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
392397
// https://github.com/arduino/arduino-ide/pull/1706#pullrequestreview-1195595080
393398
bind(HostedPluginReader).toSelf().inSingletonScope();
394399
rebind(TheiaHostedPluginReader).toService(HostedPluginReader);
400+
401+
// https://github.com/eclipse-theia/theia/issues/12064
402+
bind(LocalDirectoryPluginDeployerResolverWithFallback)
403+
.toSelf()
404+
.inSingletonScope();
405+
rebind(PluginDeployer).to(PluginDeployer_GH_12064).inSingletonScope();
395406
});
396407

397408
function bindChildLogger(bind: interfaces.Bind, name: string): void {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { URI } from '@theia/core/lib/common/uri';
2+
import {
3+
inject,
4+
injectable,
5+
postConstruct,
6+
} from '@theia/core/shared/inversify';
7+
import {
8+
PluginDeployerResolver,
9+
PluginDeployerResolverContext,
10+
} from '@theia/plugin-ext/lib/common/plugin-protocol';
11+
import { PluginDeployerImpl } from '@theia/plugin-ext/lib/main/node/plugin-deployer-impl';
12+
import { LocalDirectoryPluginDeployerResolver } from '@theia/plugin-ext/lib/main/node/resolvers/local-directory-plugin-deployer-resolver';
13+
import { constants, promises as fs } from 'fs';
14+
import { isAbsolute, resolve } from 'path';
15+
16+
@injectable()
17+
export class LocalDirectoryPluginDeployerResolverWithFallback extends LocalDirectoryPluginDeployerResolver {
18+
override async resolve(
19+
pluginResolverContext: PluginDeployerResolverContext
20+
): Promise<void> {
21+
let localPath = await this.originalResolveLocalPluginPath(
22+
pluginResolverContext,
23+
this.supportedScheme
24+
);
25+
// If local plugins folder was not resoled, fallback to the hack.
26+
if (!localPath) {
27+
localPath = await resolveLocalPluginPath(
28+
pluginResolverContext,
29+
this.supportedScheme
30+
);
31+
}
32+
if (localPath) {
33+
await this.resolveFromLocalPath(pluginResolverContext, localPath);
34+
}
35+
}
36+
37+
private async originalResolveLocalPluginPath(
38+
context: PluginDeployerResolverContext,
39+
scheme: string
40+
): Promise<string | null> {
41+
const object = <Record<string, unknown>>this;
42+
if (
43+
'resolveLocalPluginPath' in object &&
44+
typeof object['resolveLocalPluginPath'] === 'function'
45+
) {
46+
return object['resolveLocalPluginPath'](context, scheme);
47+
}
48+
return null;
49+
}
50+
}
51+
52+
async function resolveLocalPluginPath(
53+
context: PluginDeployerResolverContext,
54+
scheme: string
55+
): Promise<string | null> {
56+
const origin = context.getOriginId();
57+
const uri = new URI(origin);
58+
if (uri.scheme === scheme) {
59+
let fsPath = origin.substring(`${scheme}:`.length);
60+
if (!isAbsolute(fsPath)) {
61+
fsPath = resolve(process.cwd(), fsPath);
62+
}
63+
try {
64+
await fs.access(fsPath, constants.R_OK);
65+
return fsPath;
66+
} catch {
67+
console.warn(
68+
`The local plugin referenced by ${context.getOriginId()} does not exist.`
69+
);
70+
}
71+
}
72+
return null;
73+
}
74+
75+
@injectable()
76+
export class PluginDeployer_GH_12064 extends PluginDeployerImpl {
77+
@inject(LocalDirectoryPluginDeployerResolverWithFallback)
78+
private readonly pluginResolver: LocalDirectoryPluginDeployerResolverWithFallback;
79+
80+
@postConstruct()
81+
protected adjustPluginResolvers(): void {
82+
const pluginResolvers = <PluginDeployerResolver[]>(
83+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
84+
(this as any).pluginResolvers
85+
);
86+
const index = pluginResolvers.findIndex(
87+
(pluginResolver) =>
88+
pluginResolver instanceof LocalDirectoryPluginDeployerResolver
89+
);
90+
if (index >= 0) {
91+
pluginResolvers.splice(index, 1, this.pluginResolver);
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)