@theia/plugin-ext-vscode 1.77.0-next.99 → 1.77.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/plugin-vscode-commands-contribution.js +209 -236
- package/lib/browser/plugin-vscode-commands-contribution.js.map +1 -1
- package/lib/browser/plugin-vscode-commands-contribution.spec.js +61 -64
- package/lib/browser/plugin-vscode-commands-contribution.spec.js.map +1 -1
- package/lib/browser/plugin-vscode-contribution.js +11 -14
- package/lib/browser/plugin-vscode-contribution.js.map +1 -1
- package/lib/browser/plugin-vscode-frontend-module.js +12 -14
- package/lib/browser/plugin-vscode-frontend-module.js.map +1 -1
- package/lib/common/plugin-vscode-environment.js +12 -16
- package/lib/common/plugin-vscode-environment.js.map +1 -1
- package/lib/common/plugin-vscode-types.d.ts +1 -1
- package/lib/common/plugin-vscode-types.js +3 -6
- package/lib/common/plugin-vscode-types.js.map +1 -1
- package/lib/common/plugin-vscode-uri.js +5 -9
- package/lib/common/plugin-vscode-uri.js.map +1 -1
- package/lib/node/context/plugin-vscode-init-fe.d.ts +1 -2
- package/lib/node/context/plugin-vscode-init-fe.d.ts.map +1 -1
- package/lib/node/context/plugin-vscode-init-fe.js +3 -2
- package/lib/node/context/plugin-vscode-init-fe.js.map +1 -1
- package/lib/node/local-vsix-file-plugin-deployer-resolver.d.ts +3 -1
- package/lib/node/local-vsix-file-plugin-deployer-resolver.d.ts.map +1 -1
- package/lib/node/local-vsix-file-plugin-deployer-resolver.js +31 -32
- package/lib/node/local-vsix-file-plugin-deployer-resolver.js.map +1 -1
- package/lib/node/package.spec.d.ts +1 -0
- package/lib/node/package.spec.js +1 -1
- package/lib/node/package.spec.js.map +1 -1
- package/lib/node/plugin-vscode-backend-module.js +22 -24
- package/lib/node/plugin-vscode-backend-module.js.map +1 -1
- package/lib/node/plugin-vscode-cli-contribution.js +10 -13
- package/lib/node/plugin-vscode-cli-contribution.js.map +1 -1
- package/lib/node/plugin-vscode-deployer-participant.d.ts +1 -1
- package/lib/node/plugin-vscode-deployer-participant.d.ts.map +1 -1
- package/lib/node/plugin-vscode-deployer-participant.js +17 -22
- package/lib/node/plugin-vscode-deployer-participant.js.map +1 -1
- package/lib/node/plugin-vscode-directory-handler.js +23 -28
- package/lib/node/plugin-vscode-directory-handler.js.map +1 -1
- package/lib/node/plugin-vscode-file-handler.d.ts +3 -1
- package/lib/node/plugin-vscode-file-handler.d.ts.map +1 -1
- package/lib/node/plugin-vscode-file-handler.js +26 -28
- package/lib/node/plugin-vscode-file-handler.js.map +1 -1
- package/lib/node/plugin-vscode-init.d.ts.map +1 -1
- package/lib/node/plugin-vscode-init.js +12 -16
- package/lib/node/plugin-vscode-init.js.map +1 -1
- package/lib/node/plugin-vscode-init.spec.js +8 -11
- package/lib/node/plugin-vscode-init.spec.js.map +1 -1
- package/lib/node/plugin-vscode-utils.d.ts +6 -4
- package/lib/node/plugin-vscode-utils.d.ts.map +1 -1
- package/lib/node/plugin-vscode-utils.js +24 -32
- package/lib/node/plugin-vscode-utils.js.map +1 -1
- package/lib/node/plugin-vscode-utils.spec.d.ts +2 -0
- package/lib/node/plugin-vscode-utils.spec.d.ts.map +1 -0
- package/lib/node/plugin-vscode-utils.spec.js +151 -0
- package/lib/node/plugin-vscode-utils.spec.js.map +1 -0
- package/lib/node/scanner-vscode.js +19 -22
- package/lib/node/scanner-vscode.js.map +1 -1
- package/lib/node/scanner-vscode.spec.js +12 -15
- package/lib/node/scanner-vscode.spec.js.map +1 -1
- package/package.json +26 -19
- package/src/browser/plugin-vscode-commands-contribution.spec.ts +2 -2
- package/src/browser/plugin-vscode-commands-contribution.ts +1 -1
- package/src/browser/plugin-vscode-frontend-module.ts +3 -3
- package/src/node/context/plugin-vscode-init-fe.ts +2 -1
- package/src/node/local-vsix-file-plugin-deployer-resolver.ts +10 -6
- package/src/node/plugin-vscode-backend-module.ts +7 -7
- package/src/node/plugin-vscode-cli-contribution.ts +1 -1
- package/src/node/plugin-vscode-deployer-participant.ts +2 -2
- package/src/node/plugin-vscode-directory-handler.ts +1 -1
- package/src/node/plugin-vscode-file-handler.ts +7 -3
- package/src/node/plugin-vscode-init.spec.ts +1 -1
- package/src/node/plugin-vscode-init.ts +4 -3
- package/src/node/plugin-vscode-utils.spec.ts +170 -0
- package/src/node/plugin-vscode-utils.ts +26 -11
- package/src/node/scanner-vscode.spec.ts +1 -1
- package/src/node/scanner-vscode.ts +2 -2
|
@@ -18,10 +18,11 @@ import * as path from 'path';
|
|
|
18
18
|
import { inject, injectable, named } from '@theia/core/shared/inversify';
|
|
19
19
|
import { DuplicateExtensionError, PluginDeployerResolverContext, PluginIdentifiers } from '@theia/plugin-ext';
|
|
20
20
|
import { LocalPluginDeployerResolver } from '@theia/plugin-ext/lib/main/node/resolvers/local-plugin-deployer-resolver';
|
|
21
|
-
import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment';
|
|
22
|
-
import { isVSCodePluginFile } from './plugin-vscode-file-handler';
|
|
23
|
-
import { existsInDeploymentDir, unpackToDeploymentDir, extractExtensionIdentityFromVsix } from './plugin-vscode-utils';
|
|
21
|
+
import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment.js';
|
|
22
|
+
import { isVSCodePluginFile } from './plugin-vscode-file-handler.js';
|
|
23
|
+
import { existsInDeploymentDir, unpackToDeploymentDir, extractExtensionIdentityFromVsix } from './plugin-vscode-utils.js';
|
|
24
24
|
import { ILogger } from '@theia/core';
|
|
25
|
+
import { ArchiveExtractor } from '@theia/filesystem/lib/node/archive/archive-extractor';
|
|
25
26
|
|
|
26
27
|
@injectable()
|
|
27
28
|
export class LocalVSIXFilePluginDeployerResolver extends LocalPluginDeployerResolver {
|
|
@@ -33,6 +34,9 @@ export class LocalVSIXFilePluginDeployerResolver extends LocalPluginDeployerReso
|
|
|
33
34
|
@inject(ILogger) @named('plugin-ext-vscode:LocalVSIXFilePluginDeployerResolver')
|
|
34
35
|
protected override readonly logger: ILogger;
|
|
35
36
|
|
|
37
|
+
@inject(ArchiveExtractor)
|
|
38
|
+
protected readonly archiveExtractor: ArchiveExtractor;
|
|
39
|
+
|
|
36
40
|
protected get supportedScheme(): string {
|
|
37
41
|
return LocalVSIXFilePluginDeployerResolver.LOCAL_FILE;
|
|
38
42
|
}
|
|
@@ -45,7 +49,7 @@ export class LocalVSIXFilePluginDeployerResolver extends LocalPluginDeployerReso
|
|
|
45
49
|
// Extract the true extension identity from the VSIX package.json
|
|
46
50
|
// This prevents duplicate installations when the same extension is installed from VSIX files with different filenames
|
|
47
51
|
// See: https://github.com/eclipse-theia/theia/issues/16845
|
|
48
|
-
const components = await extractExtensionIdentityFromVsix(localPath);
|
|
52
|
+
const components = await extractExtensionIdentityFromVsix(localPath, this.archiveExtractor);
|
|
49
53
|
|
|
50
54
|
if (!components) {
|
|
51
55
|
// Fallback to filename-based ID if package.json cannot be read
|
|
@@ -58,7 +62,7 @@ export class LocalVSIXFilePluginDeployerResolver extends LocalPluginDeployerReso
|
|
|
58
62
|
return;
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
const fallbackDeploymentDir = await unpackToDeploymentDir(this.environment, localPath, fallbackId);
|
|
65
|
+
const fallbackDeploymentDir = await unpackToDeploymentDir(this.environment, localPath, fallbackId, this.archiveExtractor);
|
|
62
66
|
pluginResolverContext.addPlugin(fallbackId, fallbackDeploymentDir);
|
|
63
67
|
return;
|
|
64
68
|
}
|
|
@@ -71,7 +75,7 @@ export class LocalVSIXFilePluginDeployerResolver extends LocalPluginDeployerReso
|
|
|
71
75
|
throw DuplicateExtensionError.create(`Extension ${unversionedId} is already installed (version: ${components.version}).`);
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
const extensionDeploymentDir = await unpackToDeploymentDir(this.environment, localPath, versionedId);
|
|
78
|
+
const extensionDeploymentDir = await unpackToDeploymentDir(this.environment, localPath, versionedId, this.archiveExtractor);
|
|
75
79
|
pluginResolverContext.addPlugin(versionedId, extensionDeploymentDir);
|
|
76
80
|
}
|
|
77
81
|
}
|
|
@@ -18,15 +18,15 @@ import { ContainerModule } from '@theia/core/shared/inversify';
|
|
|
18
18
|
import {
|
|
19
19
|
PluginDeployerFileHandler, PluginDeployerDirectoryHandler, PluginScanner, PluginDeployerParticipant, PluginDeployerResolver
|
|
20
20
|
} from '@theia/plugin-ext';
|
|
21
|
-
import { PluginVsCodeFileHandler } from './plugin-vscode-file-handler';
|
|
22
|
-
import { PluginVsCodeDirectoryHandler } from './plugin-vscode-directory-handler';
|
|
23
|
-
import { VsCodePluginScanner } from './scanner-vscode';
|
|
24
|
-
import { PluginVsCodeCliContribution } from './plugin-vscode-cli-contribution';
|
|
21
|
+
import { PluginVsCodeFileHandler } from './plugin-vscode-file-handler.js';
|
|
22
|
+
import { PluginVsCodeDirectoryHandler } from './plugin-vscode-directory-handler.js';
|
|
23
|
+
import { VsCodePluginScanner } from './scanner-vscode.js';
|
|
24
|
+
import { PluginVsCodeCliContribution } from './plugin-vscode-cli-contribution.js';
|
|
25
25
|
import { CliContribution } from '@theia/core/lib/node';
|
|
26
26
|
import { PluginHostEnvironmentVariable } from '@theia/plugin-ext/lib/common';
|
|
27
|
-
import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment';
|
|
28
|
-
import { PluginVSCodeDeployerParticipant } from './plugin-vscode-deployer-participant';
|
|
29
|
-
import { LocalVSIXFilePluginDeployerResolver } from './local-vsix-file-plugin-deployer-resolver';
|
|
27
|
+
import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment.js';
|
|
28
|
+
import { PluginVSCodeDeployerParticipant } from './plugin-vscode-deployer-participant.js';
|
|
29
|
+
import { LocalVSIXFilePluginDeployerResolver } from './local-vsix-file-plugin-deployer-resolver.js';
|
|
30
30
|
|
|
31
31
|
export default new ContainerModule(bind => {
|
|
32
32
|
bind(PluginVSCodeEnvironment).toSelf().inSingletonScope();
|
|
@@ -18,7 +18,7 @@ import { injectable } from '@theia/core/shared/inversify';
|
|
|
18
18
|
import { Argv, Arguments } from '@theia/core/shared/yargs';
|
|
19
19
|
import { CliContribution } from '@theia/core/lib/node/cli';
|
|
20
20
|
import { PluginHostEnvironmentVariable } from '@theia/plugin-ext/lib/common';
|
|
21
|
-
import { VSCODE_DEFAULT_API_VERSION } from '../common/plugin-vscode-types';
|
|
21
|
+
import { VSCODE_DEFAULT_API_VERSION } from '../common/plugin-vscode-types.js';
|
|
22
22
|
import { Deferred } from '@theia/core/lib/common/promise-util';
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
import { injectable, inject, named } from '@theia/core/shared/inversify';
|
|
18
18
|
import * as fs from '@theia/core/shared/fs-extra';
|
|
19
19
|
import { FileUri } from '@theia/core/lib/node';
|
|
20
|
-
import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment';
|
|
20
|
+
import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment.js';
|
|
21
21
|
import { PluginDeployerParticipant, PluginDeployerStartContext } from '@theia/plugin-ext/lib/common/plugin-protocol';
|
|
22
|
-
import { LocalVSIXFilePluginDeployerResolver } from './local-vsix-file-plugin-deployer-resolver';
|
|
22
|
+
import { LocalVSIXFilePluginDeployerResolver } from './local-vsix-file-plugin-deployer-resolver.js';
|
|
23
23
|
import { ILogger } from '@theia/core';
|
|
24
24
|
|
|
25
25
|
@injectable()
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
PluginDeployerEntryType, PluginPackage, PluginIdentifiers
|
|
25
25
|
} from '@theia/plugin-ext';
|
|
26
26
|
import { PluginCliContribution } from '@theia/plugin-ext/lib/main/node/plugin-cli-contribution';
|
|
27
|
-
import { TMP_DIR_PREFIX } from './plugin-vscode-utils';
|
|
27
|
+
import { TMP_DIR_PREFIX } from './plugin-vscode-utils.js';
|
|
28
28
|
|
|
29
29
|
/** Fields read while resolving a VS Code extension directory */
|
|
30
30
|
type PluginPackageResolveInput = Partial<Pick<PluginPackage, 'name' | 'version' | 'publisher' | 'engines'>>;
|
|
@@ -18,10 +18,11 @@ import { PluginDeployerFileHandler, PluginDeployerEntry, PluginDeployerFileHandl
|
|
|
18
18
|
import filenamify from 'filenamify';
|
|
19
19
|
import { inject, injectable, named } from '@theia/core/shared/inversify';
|
|
20
20
|
import * as fs from '@theia/core/shared/fs-extra';
|
|
21
|
-
import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment';
|
|
21
|
+
import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment.js';
|
|
22
22
|
import { FileUri } from '@theia/core/lib/common/file-uri';
|
|
23
|
-
import { unpackToDeploymentDir } from './plugin-vscode-utils';
|
|
23
|
+
import { unpackToDeploymentDir } from './plugin-vscode-utils.js';
|
|
24
24
|
import { ILogger } from '@theia/core';
|
|
25
|
+
import { ArchiveExtractor } from '@theia/filesystem/lib/node/archive/archive-extractor';
|
|
25
26
|
|
|
26
27
|
export const isVSCodePluginFile = (pluginPath?: string) => Boolean(pluginPath && (pluginPath.endsWith('.vsix') || pluginPath.endsWith('.tgz')));
|
|
27
28
|
|
|
@@ -33,6 +34,9 @@ export class PluginVsCodeFileHandler implements PluginDeployerFileHandler {
|
|
|
33
34
|
@inject(ILogger) @named('plugin-ext-vscode:PluginVsCodeFileHandler')
|
|
34
35
|
protected readonly logger: ILogger;
|
|
35
36
|
|
|
37
|
+
@inject(ArchiveExtractor)
|
|
38
|
+
protected readonly archiveExtractor: ArchiveExtractor;
|
|
39
|
+
|
|
36
40
|
async accept(resolvedPlugin: PluginDeployerEntry): Promise<boolean> {
|
|
37
41
|
return resolvedPlugin.isFile().then(file => {
|
|
38
42
|
if (!file) {
|
|
@@ -44,7 +48,7 @@ export class PluginVsCodeFileHandler implements PluginDeployerFileHandler {
|
|
|
44
48
|
|
|
45
49
|
async handle(context: PluginDeployerFileHandlerContext): Promise<void> {
|
|
46
50
|
const id = this.getNormalizedExtensionId(context.pluginEntry().id());
|
|
47
|
-
const extensionDeploymentDir = await unpackToDeploymentDir(this.environment, context.pluginEntry().path(), id);
|
|
51
|
+
const extensionDeploymentDir = await unpackToDeploymentDir(this.environment, context.pluginEntry().path(), id, this.archiveExtractor);
|
|
48
52
|
context.pluginEntry().updatePath(extensionDeploymentDir);
|
|
49
53
|
this.logger.info(`root path: ${context.pluginEntry().rootPath}`);
|
|
50
54
|
const originalPath = context.pluginEntry().originalPath();
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import { expect } from 'chai';
|
|
20
20
|
import * as path from 'path';
|
|
21
21
|
import { Plugin } from '@theia/plugin-ext';
|
|
22
|
-
import { findPlugin } from './plugin-vscode-init';
|
|
22
|
+
import { findPlugin } from './plugin-vscode-init.js';
|
|
23
23
|
|
|
24
24
|
const PLUGIN_A_FOLDER = path.join(path.sep, 'p', 'sample-namespace.plugin-esm');
|
|
25
25
|
const PLUGIN_B_FOLDER = path.join(path.sep, 'p', 'sample-namespace.plugin-esm-mjs');
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
|
|
17
17
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
18
18
|
|
|
19
|
-
import { register } from 'node:module';
|
|
19
|
+
import Module, { register } from 'node:module';
|
|
20
20
|
import * as theia from '@theia/plugin';
|
|
21
21
|
import { isEqualOrParent } from '@theia/core/lib/common/paths';
|
|
22
22
|
import { BackendInitializationFn, PluginAPIFactory, Plugin, emptyPlugin } from '@theia/plugin-ext';
|
|
23
|
-
import { VSCODE_DEFAULT_API_VERSION } from '../common/plugin-vscode-types';
|
|
23
|
+
import { VSCODE_DEFAULT_API_VERSION } from '../common/plugin-vscode-types.js';
|
|
24
24
|
|
|
25
25
|
process.env['VSCODE_PID'] = process.env['THEIA_PARENT_PID'];
|
|
26
26
|
|
|
@@ -50,7 +50,8 @@ function createVSCodeAPI(apiFactory: PluginAPIFactory, plugin: Plugin): typeof t
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
function overrideInternalLoad(): void {
|
|
53
|
-
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
+
const module: any = Module;
|
|
54
55
|
const vscodeModuleName = 'vscode';
|
|
55
56
|
// save original load method
|
|
56
57
|
const internalLoad = module._load;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 EclipseSource GmbH and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import * as fs from 'fs';
|
|
18
|
+
import * as os from 'os';
|
|
19
|
+
import * as path from 'path';
|
|
20
|
+
import { expect } from 'chai';
|
|
21
|
+
import { FileUri } from '@theia/core/lib/common/file-uri';
|
|
22
|
+
import { ArchiveExtractor, ArchiveExtractorImpl } from '@theia/filesystem/lib/node/archive/archive-extractor';
|
|
23
|
+
import { createTestTar, createTestZip } from '@theia/filesystem/lib/node/archive/test/test-archives';
|
|
24
|
+
import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment.js';
|
|
25
|
+
import { decompressExtension, extractExtensionIdentityFromVsix, TMP_DIR_PREFIX, unpackToDeploymentDir } from './plugin-vscode-utils.js';
|
|
26
|
+
|
|
27
|
+
describe('plugin-vscode-utils', () => {
|
|
28
|
+
|
|
29
|
+
let workspace: string;
|
|
30
|
+
let deploymentDir: string;
|
|
31
|
+
let environment: PluginVSCodeEnvironment;
|
|
32
|
+
const originalConsole = { log: console.log, warn: console.warn, error: console.error };
|
|
33
|
+
|
|
34
|
+
beforeEach(async () => {
|
|
35
|
+
workspace = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'plugin-vscode-utils-'));
|
|
36
|
+
deploymentDir = path.join(workspace, 'deployedPlugins');
|
|
37
|
+
environment = { getDeploymentDirUri: async () => FileUri.create(deploymentDir) } as PluginVSCodeEnvironment;
|
|
38
|
+
// The functions under test report their progress on the console.
|
|
39
|
+
console.log = console.warn = console.error = () => { };
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
afterEach(async () => {
|
|
43
|
+
Object.assign(console, originalConsole);
|
|
44
|
+
await fs.promises.rm(workspace, { recursive: true, force: true });
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
async function writeFile(name: string, content: Buffer): Promise<string> {
|
|
48
|
+
const filePath = path.join(workspace, name);
|
|
49
|
+
await fs.promises.writeFile(filePath, content);
|
|
50
|
+
return filePath;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function createVsix(packageJson?: object): Buffer {
|
|
54
|
+
return createTestZip([
|
|
55
|
+
{ name: 'extension.vsixmanifest', data: '<PackageManifest/>' },
|
|
56
|
+
...(packageJson ? [{ name: 'extension/package.json', data: JSON.stringify(packageJson) }] : []),
|
|
57
|
+
{ name: 'extension/out/main.js', data: 'exports.activate = () => { };' }
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
describe('extractExtensionIdentityFromVsix', () => {
|
|
62
|
+
|
|
63
|
+
it('reads the identity from the package.json of the extension', async () => {
|
|
64
|
+
const vsix = await writeFile('test.vsix', createVsix({ publisher: 'theia', name: 'test', version: '1.2.3' }));
|
|
65
|
+
expect(await extractExtensionIdentityFromVsix(vsix)).to.deep.equal({ publisher: 'theia', name: 'test', version: '1.2.3' });
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('returns undefined if the package.json is missing', async () => {
|
|
69
|
+
const vsix = await writeFile('test.vsix', createVsix());
|
|
70
|
+
expect(await extractExtensionIdentityFromVsix(vsix)).to.be.undefined;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('returns undefined if the package.json has no version', async () => {
|
|
74
|
+
const vsix = await writeFile('test.vsix', createVsix({ publisher: 'theia', name: 'test' }));
|
|
75
|
+
expect(await extractExtensionIdentityFromVsix(vsix)).to.be.undefined;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('returns undefined if the file is not an archive', async () => {
|
|
79
|
+
const vsix = await writeFile('test.vsix', Buffer.from('not an archive'));
|
|
80
|
+
expect(await extractExtensionIdentityFromVsix(vsix)).to.be.undefined;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('uses the given extractor', async () => {
|
|
84
|
+
const vsix = await writeFile('test.vsix', createVsix({ publisher: 'theia', name: 'test', version: '1.2.3' }));
|
|
85
|
+
const readSources: unknown[] = [];
|
|
86
|
+
const extractor: ArchiveExtractor = {
|
|
87
|
+
extract: () => Promise.reject(new Error('unexpected')),
|
|
88
|
+
readFiles: source => {
|
|
89
|
+
readSources.push(source);
|
|
90
|
+
return new ArchiveExtractorImpl().readFiles(source);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
await extractExtensionIdentityFromVsix(vsix, extractor);
|
|
94
|
+
expect(readSources).to.deep.equal([vsix]);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('decompressExtension', () => {
|
|
99
|
+
|
|
100
|
+
it('extracts a VSIX', async () => {
|
|
101
|
+
const vsix = await writeFile('test.vsix', createVsix({ name: 'test', version: '1.2.3' }));
|
|
102
|
+
const target = path.join(workspace, 'target');
|
|
103
|
+
expect(await decompressExtension(vsix, target)).to.be.true;
|
|
104
|
+
expect(fs.existsSync(path.join(target, 'extension', 'out', 'main.js'))).to.be.true;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('extracts the node_modules shipped with a built-in .tgz extension', async () => {
|
|
108
|
+
const nodeModules = createTestZip([{ name: 'some-dependency/index.js', data: 'module.exports = 1;' }]);
|
|
109
|
+
const tgz = await writeFile('builtin.tgz', await createTestTar([
|
|
110
|
+
{ name: 'package/package.json', data: '{"name":"builtin","version":"1.0.0"}' },
|
|
111
|
+
{ name: 'package/vscode_node_modules.zip', data: nodeModules }
|
|
112
|
+
], true));
|
|
113
|
+
const target = path.join(workspace, 'target');
|
|
114
|
+
await decompressExtension(tgz, target);
|
|
115
|
+
expect(await fs.promises.readFile(path.join(target, 'package', 'node_modules', 'some-dependency', 'index.js'), 'utf8')).to.equal('module.exports = 1;');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('rejects an archive with an entry that leaves the target', async () => {
|
|
119
|
+
const vsix = await writeFile('evil.vsix', createTestZip([{ name: '../evil.txt', data: 'evil' }]));
|
|
120
|
+
let error: unknown;
|
|
121
|
+
try {
|
|
122
|
+
await decompressExtension(vsix, path.join(workspace, 'target'));
|
|
123
|
+
} catch (e) {
|
|
124
|
+
error = e;
|
|
125
|
+
}
|
|
126
|
+
expect(String(error)).to.match(/invalid relative path|leaves the extraction directory/);
|
|
127
|
+
expect(fs.existsSync(path.join(workspace, 'evil.txt'))).to.be.false;
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('unpackToDeploymentDir', () => {
|
|
132
|
+
|
|
133
|
+
it('unpacks into the deployment directory of the extension', async () => {
|
|
134
|
+
const vsix = await writeFile('test.vsix', createVsix({ name: 'test', version: '1.2.3' }));
|
|
135
|
+
const extensionDir = await unpackToDeploymentDir(environment, vsix, 'theia.test-1.2.3');
|
|
136
|
+
expect(extensionDir).to.equal(FileUri.fsPath(FileUri.create(deploymentDir).resolve('theia.test-1.2.3')));
|
|
137
|
+
expect(fs.existsSync(path.join(extensionDir, 'extension', 'out', 'main.js'))).to.be.true;
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('removes the temporary directory if unpacking fails', async () => {
|
|
141
|
+
const vsix = await writeFile('evil.vsix', createTestZip([
|
|
142
|
+
{ name: 'extension/package.json', data: '{}' },
|
|
143
|
+
{ name: '../evil.txt', data: 'evil' }
|
|
144
|
+
]));
|
|
145
|
+
let rejected = false;
|
|
146
|
+
try {
|
|
147
|
+
await unpackToDeploymentDir(environment, vsix, 'theia.evil');
|
|
148
|
+
} catch {
|
|
149
|
+
rejected = true;
|
|
150
|
+
}
|
|
151
|
+
expect(rejected).to.be.true;
|
|
152
|
+
expect((await fs.promises.readdir(deploymentDir)).filter(name => name.startsWith(TMP_DIR_PREFIX))).to.be.empty;
|
|
153
|
+
expect(fs.existsSync(path.join(deploymentDir, 'theia.evil'))).to.be.false;
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('uses the given extractor', async () => {
|
|
157
|
+
const vsix = await writeFile('test.vsix', createVsix({ name: 'test', version: '1.2.3' }));
|
|
158
|
+
const extracted: unknown[] = [];
|
|
159
|
+
const extractor: ArchiveExtractor = {
|
|
160
|
+
extract: (source, destination) => {
|
|
161
|
+
extracted.push(source);
|
|
162
|
+
return new ArchiveExtractorImpl().extract(source, destination);
|
|
163
|
+
},
|
|
164
|
+
readFiles: () => Promise.reject(new Error('unexpected'))
|
|
165
|
+
};
|
|
166
|
+
await unpackToDeploymentDir(environment, vsix, 'theia.test-1.2.3', extractor);
|
|
167
|
+
expect(extracted).to.deep.equal([vsix]);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -14,13 +14,15 @@
|
|
|
14
14
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
|
-
import decompress from 'decompress';
|
|
18
17
|
import * as path from 'path';
|
|
19
18
|
import filenamify from 'filenamify';
|
|
20
19
|
import { FileUri } from '@theia/core/lib/node';
|
|
21
20
|
import * as fs from '@theia/core/shared/fs-extra';
|
|
22
|
-
import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment';
|
|
21
|
+
import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment.js';
|
|
23
22
|
import { PluginIdentifiers, PluginPackage } from '@theia/plugin-ext/lib/common/plugin-protocol';
|
|
23
|
+
import { ArchiveExtractor, ArchiveExtractorImpl } from '@theia/filesystem/lib/node/archive/archive-extractor';
|
|
24
|
+
|
|
25
|
+
const defaultArchiveExtractor = new ArchiveExtractorImpl();
|
|
24
26
|
|
|
25
27
|
/**
|
|
26
28
|
* Extracts extension identity from a VSIX file by reading its package.json.
|
|
@@ -29,13 +31,17 @@ import { PluginIdentifiers, PluginPackage } from '@theia/plugin-ext/lib/common/p
|
|
|
29
31
|
* This function extracts only the `extension/package.json` file to read the extension metadata.
|
|
30
32
|
*
|
|
31
33
|
* @param vsixPath Path to the VSIX file
|
|
34
|
+
* @param archiveExtractor the extractor used to read the VSIX file
|
|
32
35
|
* @returns PluginIdentifiers.Components (publisher?, name, version), or undefined if the package.json cannot be read or is invalid
|
|
33
36
|
*/
|
|
34
|
-
export async function extractExtensionIdentityFromVsix(
|
|
37
|
+
export async function extractExtensionIdentityFromVsix(
|
|
38
|
+
vsixPath: string,
|
|
39
|
+
archiveExtractor: ArchiveExtractor = defaultArchiveExtractor
|
|
40
|
+
): Promise<PluginIdentifiers.Components | undefined> {
|
|
35
41
|
try {
|
|
36
|
-
//
|
|
37
|
-
const files = await
|
|
38
|
-
filter:
|
|
42
|
+
// Read only the package.json file from the VSIX
|
|
43
|
+
const files = await archiveExtractor.readFiles(vsixPath, {
|
|
44
|
+
filter: entryPath => entryPath === 'extension/package.json'
|
|
39
45
|
});
|
|
40
46
|
|
|
41
47
|
if (files.length === 0) {
|
|
@@ -65,15 +71,19 @@ export async function extractExtensionIdentityFromVsix(vsixPath: string): Promis
|
|
|
65
71
|
}
|
|
66
72
|
}
|
|
67
73
|
|
|
68
|
-
export async function decompressExtension(
|
|
74
|
+
export async function decompressExtension(
|
|
75
|
+
sourcePath: string,
|
|
76
|
+
destPath: string,
|
|
77
|
+
archiveExtractor: ArchiveExtractor = defaultArchiveExtractor
|
|
78
|
+
): Promise<boolean> {
|
|
69
79
|
try {
|
|
70
|
-
await
|
|
80
|
+
await archiveExtractor.extract(sourcePath, destPath);
|
|
71
81
|
if (sourcePath.endsWith('.tgz')) {
|
|
72
82
|
// unzip node_modules from built-in extensions, see https://github.com/eclipse-theia/theia/issues/5756
|
|
73
83
|
const extensionPath = path.join(destPath, 'package');
|
|
74
84
|
const vscodeNodeModulesPath = path.join(extensionPath, 'vscode_node_modules.zip');
|
|
75
85
|
if (await fs.pathExists(vscodeNodeModulesPath)) {
|
|
76
|
-
await
|
|
86
|
+
await archiveExtractor.extract(vscodeNodeModulesPath, path.join(extensionPath, 'node_modules'));
|
|
77
87
|
}
|
|
78
88
|
}
|
|
79
89
|
return true;
|
|
@@ -88,7 +98,12 @@ export async function existsInDeploymentDir(env: PluginVSCodeEnvironment, extens
|
|
|
88
98
|
}
|
|
89
99
|
|
|
90
100
|
export const TMP_DIR_PREFIX = 'tmp-vscode-unpacked-';
|
|
91
|
-
export async function unpackToDeploymentDir(
|
|
101
|
+
export async function unpackToDeploymentDir(
|
|
102
|
+
env: PluginVSCodeEnvironment,
|
|
103
|
+
sourcePath: string,
|
|
104
|
+
extensionId: string,
|
|
105
|
+
archiveExtractor: ArchiveExtractor = defaultArchiveExtractor
|
|
106
|
+
): Promise<string> {
|
|
92
107
|
const extensionDeploymentDir = await getExtensionDeploymentDir(env, extensionId);
|
|
93
108
|
if (await fs.pathExists(extensionDeploymentDir)) {
|
|
94
109
|
console.log(`[${extensionId}]: deployment dir "${extensionDeploymentDir}" already exists`);
|
|
@@ -98,7 +113,7 @@ export async function unpackToDeploymentDir(env: PluginVSCodeEnvironment, source
|
|
|
98
113
|
const tempDir = await getTempDir(env, TMP_DIR_PREFIX);
|
|
99
114
|
try {
|
|
100
115
|
console.log(`[${extensionId}]: trying to decompress "${sourcePath}" into "${tempDir}"...`);
|
|
101
|
-
if (!await decompressExtension(sourcePath, tempDir)) {
|
|
116
|
+
if (!await decompressExtension(sourcePath, tempDir, archiveExtractor)) {
|
|
102
117
|
await fs.remove(tempDir);
|
|
103
118
|
const msg = `[${extensionId}]: decompressing "${sourcePath}" to "${tempDir}" failed`;
|
|
104
119
|
console.error(msg);
|
|
@@ -20,7 +20,7 @@ import { expect } from 'chai';
|
|
|
20
20
|
import * as os from 'os';
|
|
21
21
|
import * as path from 'path';
|
|
22
22
|
import * as fs from 'fs';
|
|
23
|
-
import { VsCodePluginScanner } from './scanner-vscode';
|
|
23
|
+
import { VsCodePluginScanner } from './scanner-vscode.js';
|
|
24
24
|
import { PluginPackage } from '@theia/plugin-ext';
|
|
25
25
|
import URI from '@theia/core/lib/common/uri';
|
|
26
26
|
|
|
@@ -19,7 +19,7 @@ import { injectable } from '@theia/core/shared/inversify';
|
|
|
19
19
|
import { PluginScanner, PluginEngine, PluginPackage, PluginModel, PluginLifecycle, PluginIdentifiers, UIKind } from '@theia/plugin-ext';
|
|
20
20
|
import { TheiaPluginScanner } from '@theia/plugin-ext/lib/hosted/node/scanners/scanner-theia';
|
|
21
21
|
import { environment } from '@theia/core/shared/@theia/application-package/lib/environment';
|
|
22
|
-
import { VSCodeExtensionUri } from '../common/plugin-vscode-uri';
|
|
22
|
+
import { VSCodeExtensionUri } from '../common/plugin-vscode-uri.js';
|
|
23
23
|
import { buildLifecycle, buildModelForVsCode } from '@theia/plugin-utils/lib/common/plugin-model';
|
|
24
24
|
|
|
25
25
|
const uiKind = environment.electron.is() ? UIKind.Desktop : UIKind.Web;
|
|
@@ -64,7 +64,7 @@ export class VsCodePluginScanner extends TheiaPluginScanner implements PluginSca
|
|
|
64
64
|
override getLifecycle(plugin: PluginPackage): PluginLifecycle {
|
|
65
65
|
return {
|
|
66
66
|
...buildLifecycle(plugin, 'vscode'),
|
|
67
|
-
backendInitPath: path.join(
|
|
67
|
+
backendInitPath: path.join(import.meta.dirname, 'plugin-vscode-init'),
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
|