@theia/plugin-ext-vscode 1.77.0-next.95 → 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.
Files changed (75) hide show
  1. package/lib/browser/plugin-vscode-commands-contribution.d.ts.map +1 -1
  2. package/lib/browser/plugin-vscode-commands-contribution.js +213 -240
  3. package/lib/browser/plugin-vscode-commands-contribution.js.map +1 -1
  4. package/lib/browser/plugin-vscode-commands-contribution.spec.js +122 -59
  5. package/lib/browser/plugin-vscode-commands-contribution.spec.js.map +1 -1
  6. package/lib/browser/plugin-vscode-contribution.js +11 -14
  7. package/lib/browser/plugin-vscode-contribution.js.map +1 -1
  8. package/lib/browser/plugin-vscode-frontend-module.js +12 -14
  9. package/lib/browser/plugin-vscode-frontend-module.js.map +1 -1
  10. package/lib/common/plugin-vscode-environment.js +12 -16
  11. package/lib/common/plugin-vscode-environment.js.map +1 -1
  12. package/lib/common/plugin-vscode-types.d.ts +1 -1
  13. package/lib/common/plugin-vscode-types.js +3 -6
  14. package/lib/common/plugin-vscode-types.js.map +1 -1
  15. package/lib/common/plugin-vscode-uri.js +5 -9
  16. package/lib/common/plugin-vscode-uri.js.map +1 -1
  17. package/lib/node/context/plugin-vscode-init-fe.d.ts +1 -2
  18. package/lib/node/context/plugin-vscode-init-fe.d.ts.map +1 -1
  19. package/lib/node/context/plugin-vscode-init-fe.js +3 -2
  20. package/lib/node/context/plugin-vscode-init-fe.js.map +1 -1
  21. package/lib/node/local-vsix-file-plugin-deployer-resolver.d.ts +3 -1
  22. package/lib/node/local-vsix-file-plugin-deployer-resolver.d.ts.map +1 -1
  23. package/lib/node/local-vsix-file-plugin-deployer-resolver.js +31 -32
  24. package/lib/node/local-vsix-file-plugin-deployer-resolver.js.map +1 -1
  25. package/lib/node/package.spec.d.ts +1 -0
  26. package/lib/node/package.spec.js +1 -1
  27. package/lib/node/package.spec.js.map +1 -1
  28. package/lib/node/plugin-vscode-backend-module.js +22 -24
  29. package/lib/node/plugin-vscode-backend-module.js.map +1 -1
  30. package/lib/node/plugin-vscode-cli-contribution.js +10 -13
  31. package/lib/node/plugin-vscode-cli-contribution.js.map +1 -1
  32. package/lib/node/plugin-vscode-deployer-participant.d.ts +1 -1
  33. package/lib/node/plugin-vscode-deployer-participant.d.ts.map +1 -1
  34. package/lib/node/plugin-vscode-deployer-participant.js +17 -22
  35. package/lib/node/plugin-vscode-deployer-participant.js.map +1 -1
  36. package/lib/node/plugin-vscode-directory-handler.js +23 -28
  37. package/lib/node/plugin-vscode-directory-handler.js.map +1 -1
  38. package/lib/node/plugin-vscode-file-handler.d.ts +3 -1
  39. package/lib/node/plugin-vscode-file-handler.d.ts.map +1 -1
  40. package/lib/node/plugin-vscode-file-handler.js +26 -28
  41. package/lib/node/plugin-vscode-file-handler.js.map +1 -1
  42. package/lib/node/plugin-vscode-init.d.ts.map +1 -1
  43. package/lib/node/plugin-vscode-init.js +12 -16
  44. package/lib/node/plugin-vscode-init.js.map +1 -1
  45. package/lib/node/plugin-vscode-init.spec.js +8 -11
  46. package/lib/node/plugin-vscode-init.spec.js.map +1 -1
  47. package/lib/node/plugin-vscode-utils.d.ts +6 -4
  48. package/lib/node/plugin-vscode-utils.d.ts.map +1 -1
  49. package/lib/node/plugin-vscode-utils.js +24 -32
  50. package/lib/node/plugin-vscode-utils.js.map +1 -1
  51. package/lib/node/plugin-vscode-utils.spec.d.ts +2 -0
  52. package/lib/node/plugin-vscode-utils.spec.d.ts.map +1 -0
  53. package/lib/node/plugin-vscode-utils.spec.js +151 -0
  54. package/lib/node/plugin-vscode-utils.spec.js.map +1 -0
  55. package/lib/node/scanner-vscode.js +19 -22
  56. package/lib/node/scanner-vscode.js.map +1 -1
  57. package/lib/node/scanner-vscode.spec.js +12 -15
  58. package/lib/node/scanner-vscode.spec.js.map +1 -1
  59. package/package.json +26 -19
  60. package/src/browser/plugin-vscode-commands-contribution.spec.ts +84 -2
  61. package/src/browser/plugin-vscode-commands-contribution.ts +14 -11
  62. package/src/browser/plugin-vscode-frontend-module.ts +3 -3
  63. package/src/node/context/plugin-vscode-init-fe.ts +2 -1
  64. package/src/node/local-vsix-file-plugin-deployer-resolver.ts +10 -6
  65. package/src/node/plugin-vscode-backend-module.ts +7 -7
  66. package/src/node/plugin-vscode-cli-contribution.ts +1 -1
  67. package/src/node/plugin-vscode-deployer-participant.ts +2 -2
  68. package/src/node/plugin-vscode-directory-handler.ts +1 -1
  69. package/src/node/plugin-vscode-file-handler.ts +7 -3
  70. package/src/node/plugin-vscode-init.spec.ts +1 -1
  71. package/src/node/plugin-vscode-init.ts +4 -3
  72. package/src/node/plugin-vscode-utils.spec.ts +170 -0
  73. package/src/node/plugin-vscode-utils.ts +26 -11
  74. package/src/node/scanner-vscode.spec.ts +1 -1
  75. package/src/node/scanner-vscode.ts +2 -2
@@ -33,8 +33,10 @@ import { CommandRegistry, InMemoryTextResource, URI } from '@theia/core';
33
33
  import { MultiDiffEditorUri } from '@theia/scm/lib/browser/multi-diff-editor/multi-diff-editor-uri';
34
34
  import { ScmService } from '@theia/scm/lib/browser/scm-service';
35
35
  import { DuplicateExtensionError } from '@theia/plugin-ext/lib/common/plugin-protocol';
36
- import { VSCodeExtensionUri } from '../common/plugin-vscode-uri';
37
- import { EditorGroupNavigationRect, PluginVscodeCommandsContribution } from './plugin-vscode-commands-contribution';
36
+ import { Title, Widget } from '@theia/core/lib/browser';
37
+ import { EditorWidget } from '@theia/editor/lib/browser';
38
+ import { VSCodeExtensionUri } from '../common/plugin-vscode-uri.js';
39
+ import { EditorGroupNavigationRect, PluginVscodeCommandsContribution } from './plugin-vscode-commands-contribution.js';
38
40
 
39
41
  after(() => disableJSDOM());
40
42
 
@@ -206,4 +208,84 @@ describe('PluginVscodeCommandsContribution', () => {
206
208
  expect(calls[0][2]).to.deep.equal({ version: '1.2.3', ignoreOtherVersions: true });
207
209
  });
208
210
  });
211
+
212
+ describe('editor close commands', () => {
213
+ /** A shell with one tab bar whose `closeTabs` relies on `this`, like `ApplicationShell`. */
214
+ class FakeShell {
215
+ readonly closed: string[] = [];
216
+ readonly saved: string[] = [];
217
+ readonly tabBar: { titles: Title<Widget>[] };
218
+ readonly otherTabBar: { titles: Title<Widget>[] };
219
+
220
+ constructor(readonly widgets: Widget[], readonly currentWidget: Widget, otherGroup: Widget[]) {
221
+ this.tabBar = { titles: widgets.map(widget => widget.title) };
222
+ this.otherTabBar = { titles: otherGroup.map(widget => widget.title) };
223
+ }
224
+
225
+ get allTabBars(): unknown[] {
226
+ return [this.tabBar, this.otherTabBar];
227
+ }
228
+
229
+ getTabBarFor(): unknown {
230
+ return this.tabBar;
231
+ }
232
+
233
+ async closeMany(targets: Widget[]): Promise<Widget[]> {
234
+ this.closed.push(...targets.map(target => target.id));
235
+ return targets;
236
+ }
237
+
238
+ async closeTabs(tabBar: { titles: Title<Widget>[] }, filter?: (title: Title<Widget>, index: number) => boolean): Promise<void> {
239
+ await this.closeMany(this.getWidgetTitles(tabBar, filter).map(title => title.owner));
240
+ }
241
+
242
+ saveTabs(tabBar: { titles: Title<Widget>[] }, filter?: (title: Title<Widget>, index: number) => boolean): void {
243
+ this.saved.push(...this.getWidgetTitles(tabBar, filter).map(title => title.owner.id));
244
+ }
245
+
246
+ getWidgetTitles(tabBar: { titles: Title<Widget>[] }, filter?: (title: Title<Widget>, index: number) => boolean): Title<Widget>[] {
247
+ return filter ? tabBar.titles.filter(filter) : tabBar.titles;
248
+ }
249
+ }
250
+
251
+ function editor(id: string, pinned = false): EditorWidget {
252
+ const widget: EditorWidget = Object.create(EditorWidget.prototype);
253
+ Object.defineProperties(widget, { id: { value: id }, title: { value: { owner: widget, closable: !pinned } } });
254
+ return widget;
255
+ }
256
+
257
+ let shell: FakeShell;
258
+ let commands: CommandRegistry;
259
+
260
+ beforeEach(() => {
261
+ const widgets = [editor('a', true), editor('b'), editor('c'), editor('d', true), editor('e')];
262
+ shell = new FakeShell(widgets, widgets[2], [editor('f', true), editor('g')]);
263
+ Object.assign(contribution, { shell, editorManager: { currentEditor: widgets[2], all: widgets } });
264
+ commands = new CommandRegistry({ getContributions: () => [] });
265
+ contribution.registerCommands(commands);
266
+ });
267
+
268
+ const expectations: [string, string[]][] = [
269
+ ['workbench.action.closeAllEditors', ['b', 'c', 'e']],
270
+ ['workbench.action.closeOtherEditors', ['b', 'e']],
271
+ ['workbench.action.closeEditorsInGroup', ['b', 'c', 'e']],
272
+ ['workbench.action.closeEditorsToTheLeft', ['b']],
273
+ ['workbench.action.closeEditorsToTheRight', ['e']],
274
+ ['workbench.action.closeEditorsInOtherGroups', ['g']]
275
+ ];
276
+ for (const [command, closed] of expectations) {
277
+ it(`${command} should leave pinned editors open`, async () => {
278
+ await commands.executeCommand(command);
279
+ await new Promise(resolve => setTimeout(resolve));
280
+
281
+ expect(shell.closed).to.deep.equal(closed);
282
+ });
283
+ }
284
+
285
+ it('workbench.files.saveAllInGroup should save every editor in the group, pinned ones included', async () => {
286
+ await commands.executeCommand('workbench.files.saveAllInGroup');
287
+
288
+ expect(shell.saved).to.deep.equal(['a', 'b', 'c', 'd', 'e']);
289
+ });
290
+ });
209
291
  });
@@ -78,7 +78,7 @@ import { CustomEditorOpener } from '@theia/plugin-ext/lib/main/browser/custom-ed
78
78
  import { nls } from '@theia/core/lib/common/nls';
79
79
  import { WindowService } from '@theia/core/lib/browser/window/window-service';
80
80
  import * as monaco from '@theia/monaco-editor-core';
81
- import { VSCodeExtensionUri } from '../common/plugin-vscode-uri';
81
+ import { VSCodeExtensionUri } from '../common/plugin-vscode-uri.js';
82
82
  import { CodeEditorWidgetUtil } from '@theia/plugin-ext/lib/main/browser/menus/vscode-theia-menu-mappings';
83
83
  import { OutlineViewContribution } from '@theia/outline-view/lib/browser/outline-view-contribution';
84
84
  import { CompletionList, Range, Position as PluginPosition } from '@theia/plugin';
@@ -660,7 +660,7 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
660
660
  return (resourceUri && resourceUri.toString()) === uriString;
661
661
  });
662
662
  }
663
- const toClose = this.shell.widgets.filter(widget => widget !== editor && CodeEditorWidgetUtil.is(widget));
663
+ const toClose = this.shell.widgets.filter(widget => widget !== editor && CodeEditorWidgetUtil.is(widget) && widget.title.closable);
664
664
  await this.shell.closeMany(toClose);
665
665
  }
666
666
  });
@@ -668,7 +668,7 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
668
668
  const performActionOnGroup = (
669
669
  cb: (
670
670
  tabBarOrArea: TabBar<Widget> | ApplicationShell.Area,
671
- filter?: ((title: Title<Widget>, index: number) => boolean) | undefined
671
+ filter: (title: Title<Widget>, index: number) => boolean
672
672
  ) => void,
673
673
  uri?: monaco.Uri
674
674
  ): void => {
@@ -692,13 +692,16 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
692
692
  id: 'workbench.action.closeEditorsInGroup',
693
693
  label: nls.localizeByDefault('Close All Editors in Group')
694
694
  }, {
695
- execute: (uri?: monaco.Uri) => performActionOnGroup(this.shell.closeTabs, uri)
695
+ execute: (uri?: monaco.Uri) => performActionOnGroup(
696
+ (tabBar, filter) => this.shell.closeTabs(tabBar, (title, index) => title.closable && filter(title, index)),
697
+ uri
698
+ )
696
699
  });
697
700
  commands.registerCommand({
698
701
  id: 'workbench.files.saveAllInGroup',
699
702
  label: nls.localizeByDefault('Save All in Group')
700
703
  }, {
701
- execute: (uri?: monaco.Uri) => performActionOnGroup(this.shell.saveTabs, uri)
704
+ execute: (uri?: monaco.Uri) => performActionOnGroup((tabBar, filter) => this.shell.saveTabs(tabBar, filter), uri)
702
705
  });
703
706
  commands.registerCommand({ id: 'workbench.action.closeEditorsInOtherGroups' }, {
704
707
  execute: () => {
@@ -708,7 +711,7 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
708
711
  for (const tabBar of this.shell.allTabBars) {
709
712
  if (tabBar !== editorTabBar) {
710
713
  this.shell.closeTabs(tabBar,
711
- ({ owner }) => CodeEditorWidgetUtil.is(owner)
714
+ ({ owner, closable }) => closable && CodeEditorWidgetUtil.is(owner)
712
715
  );
713
716
  }
714
717
  }
@@ -723,12 +726,12 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
723
726
  if (tabBar) {
724
727
  let left = true;
725
728
  this.shell.closeTabs(tabBar,
726
- ({ owner }) => {
729
+ ({ owner, closable }) => {
727
730
  if (owner === editor) {
728
731
  left = false;
729
732
  return false;
730
733
  }
731
- return left && CodeEditorWidgetUtil.is(owner);
734
+ return left && closable && CodeEditorWidgetUtil.is(owner);
732
735
  }
733
736
  );
734
737
  }
@@ -743,12 +746,12 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
743
746
  if (tabBar) {
744
747
  let left = true;
745
748
  this.shell.closeTabs(tabBar,
746
- ({ owner }) => {
749
+ ({ owner, closable }) => {
747
750
  if (owner === editor) {
748
751
  left = false;
749
752
  return false;
750
753
  }
751
- return !left && CodeEditorWidgetUtil.is(owner);
754
+ return !left && closable && CodeEditorWidgetUtil.is(owner);
752
755
  }
753
756
  );
754
757
  }
@@ -757,7 +760,7 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
757
760
  });
758
761
  commands.registerCommand({ id: 'workbench.action.closeAllEditors' }, {
759
762
  execute: async () => {
760
- const toClose = this.shell.widgets.filter(widget => CodeEditorWidgetUtil.is(widget));
763
+ const toClose = this.shell.widgets.filter(widget => CodeEditorWidgetUtil.is(widget) && widget.title.closable);
761
764
  await this.shell.closeMany(toClose);
762
765
  }
763
766
  });
@@ -16,9 +16,9 @@
16
16
 
17
17
  import { ContainerModule } from '@theia/core/shared/inversify';
18
18
  import { CommandContribution } from '@theia/core';
19
- import { PluginVscodeCommandsContribution } from './plugin-vscode-commands-contribution';
20
- import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment';
21
- import { PluginVSCodeContribution } from './plugin-vscode-contribution';
19
+ import { PluginVscodeCommandsContribution } from './plugin-vscode-commands-contribution.js';
20
+ import { PluginVSCodeEnvironment } from '../common/plugin-vscode-environment.js';
21
+ import { PluginVSCodeContribution } from './plugin-vscode-contribution.js';
22
22
  import { FileServiceContribution } from '@theia/filesystem/lib/browser/file-service';
23
23
 
24
24
  export default new ContainerModule(bind => {
@@ -14,8 +14,9 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
+ // The scope of the plugin worker, which loads this script with `importScripts`.
17
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
- const _scope = (this as any);
19
+ const _scope = (self as any);
19
20
  _scope.exports = {};
20
21
 
21
22
  const _getModule = () => {
@@ -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
- const module = require('module');
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
+ });