Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

feat(namespace): Export @eclipse-che/plugin namespace using VS Code extension mechanism #994

Merged
merged 1 commit into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions che-theia-init-sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ sources:
- extensions/eclipse-che-theia-remote-impl-che-server
plugins:
- plugins/containers-plugin
- plugins/ext-plugin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something more descriptive? E.g. che-api-export-plugin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the folder can be as long as you want (can change it easily) but for the name of the plug-in it looks a bit too long/verbose for consumers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, it's important to have the name as short as possible here. I just forgot it's supposed to be used by the external VS Code extensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you've a better short name suggestion, I can rename it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good. Nevermind )

- plugins/workspace-plugin
- plugins/resource-monitor-plugin
- plugins/ports-plugin
Expand Down
4 changes: 4 additions & 0 deletions plugins/ext-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib/
node_modules/
*.theia
coverage
15 changes: 15 additions & 0 deletions plugins/ext-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Ext Plug-in
This plug-in is exposing some Eclipse Che API to be consumed by other VS Code extensions using the VS Code extension mechanism.

## Example

```typescript
const eclipseCheExtPlugin = vscode.extensions.getExtension('@eclipse-che.ext-plugin');
if (eclipseCheExtPlugin) {
// grab user
const user = await eclipseCheExtPlugin.exports.user.getCurrentUser();
vscode.window.showInformationMessage(`Eclipse Che user information: id ${user.id} with name ${user.name}`);
}
```

Exported code is coming from https://github.com/eclipse/che-theia/blob/master/extensions/eclipse-che-theia-plugin/src/che-proposed.d.ts
28 changes: 28 additions & 0 deletions plugins/ext-plugin/__mocks__/@eclipse-che/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**********************************************************************
* Copyright (c) 2021 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/

/**
* Mock of @eclipse-che/plugin module
* @author Florent Benoit
*/
const che: any = {};
let currentWorkspace: any = undefined;

che.setWorkspaceOutput = (input: any) => {
currentWorkspace = input;
};

che.workspace = {};

che.workspace.getCurrentWorkspace = () => {
return currentWorkspace;
};

module.exports = che;
62 changes: 62 additions & 0 deletions plugins/ext-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "ext-plugin",
"publisher": "@eclipse-che",
"version": "0.0.1",
"keywords": [
"theia-plugin"
],
"description": "Exports @eclipse-che/plugin namespace",
"license": "EPL-2.0",
"files": [
"src"
],
"activationEvents": [
"*"
],
"dependencies": {},
"devDependencies": {
"@eclipse-che/plugin": "latest",
"@theia/plugin": "next",
"@theia/plugin-packager": "latest"
},
"scripts": {
"prepare": "yarn clean && yarn build && yarn lint:fix && yarn test",
"clean": "rimraf lib",
"format": "if-env SKIP_FORMAT=true && echo 'skip format check' || prettier --check '{src,tests}/**/*.ts' package.json",
"format:fix": "prettier --write '{src,tests}/**/*.ts' package.json",
"lint": "if-env SKIP_LINT=true && echo 'skip lint check' || eslint --cache=true --no-error-on-unmatched-pattern=true '{src,tests}/**/*.ts'",
"lint:fix": "eslint --fix --cache=true --no-error-on-unmatched-pattern=true \"{src,tests}/**/*.{ts,tsx}\"",
"compile": "tsc",
"build": "concurrently -n \"format,lint,compile\" -c \"red,green,blue\" \"yarn format\" \"yarn lint\" \"yarn compile\" && theia-plugin pack",
"watch": "tsc -w",
"test": "if-env SKIP_TEST=true && echo 'skip test' || jest --forceExit",
"test-watch": "jest --watchAll"
},
"engines": {
"theiaPlugin": "next"
},
"theiaPlugin": {
"backend": "lib/ext-plugin.js"
},
"jest": {
"collectCoverage": true,
"collectCoverageFrom": [
"src/**/*.ts"
],
"coverageDirectory": "./coverage",
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"modulePathIgnorePatterns": [
"<rootDir>/dist"
],
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
]
}
}
18 changes: 18 additions & 0 deletions plugins/ext-plugin/src/ext-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**********************************************************************
* Copyright (c) 2021 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/

import * as che from '@eclipse-che/plugin';
/**
* Export @eclipse-che/plugin namespace as extensions.getExtension('@eclipse-che/ext-plugin') value
*/
export async function start(): Promise<unknown> {
const apiObject = che;
return apiObject;
}
25 changes: 25 additions & 0 deletions plugins/ext-plugin/tests/ext-plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**********************************************************************
* Copyright (c) 2021 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
***********************************************************************/

/* eslint-disable @typescript-eslint/no-explicit-any */

import * as che from '@eclipse-che/plugin';
import * as extPlugin from '../src/ext-plugin';

describe('Test ExtPlugin', () => {
test('start', async () => {
(che as any).setWorkspaceOutput({ id: '1234' });

const api: any = await extPlugin.start();
expect(api).toBeDefined();
const workspace = await api.workspace.getCurrentWorkspace();
expect(workspace.id).toBe('1234');
});
});
19 changes: 19 additions & 0 deletions plugins/ext-plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../configs/base.tsconfig",
"compilerOptions": {
"target": "es5",
"lib": [
"es6",
"webworker"
],
"sourceMap": true,
"rootDir": "src",
"outDir": "lib",
"types": [
"node", "jest"
]
},
"include": [
"src"
]
}
3 changes: 2 additions & 1 deletion plugins/workspace-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"@theia/plugin-packager": "latest"
},
"extensionDependencies": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't get why the Workspace Plug-in has to depend on it?
Could you please elaborate a bit?

If it's just for bootstrapping, isn't the * activation event enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to make sure that it's loaded as first plug-ins because there is no concept of optional dependency in VScode api

"Eclipse Che.@eclipse-che/theia-ssh-plugin"
"Eclipse Che.@eclipse-che/theia-ssh-plugin",
"@eclipse-che.ext-plugin"
],
"scripts": {
"prepare": "yarn clean && yarn lint:fix && yarn build && yarn test",
Expand Down