Skip to content

Commit

Permalink
WIP lalalal
Browse files Browse the repository at this point in the history
  • Loading branch information
akosyakov committed Jan 14, 2020
1 parent b445b08 commit c9f0f1e
Show file tree
Hide file tree
Showing 43 changed files with 1,119 additions and 1,670 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lerna-debug.log
coverage
errorShots
examples/*/src-gen
examples/*/webpack.config.js
examples/*/gen-webpack.config.js
.browser_modules
**/docs/api
package-backup.json
Expand Down
2 changes: 2 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ image:
ports:
- port: 3000 # Theia
- port: 3030 # VS Code extension tests
- port: 9229 # Node.js debug port
onOpen: ignore
- port: 9339 # Node.js debug port
onOpen: ignore
- port: 6080
Expand Down
6 changes: 0 additions & 6 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,6 @@ vscode-java-debug (0.15.0)

* License: MIT

webdriverio (n/a)

* License: MIT
* Project: http://webdriver.io/
* Source: https://github.com/webdriverio/webdriverio.git

when (3.7.8)

* License: MIT
Expand Down
1 change: 1 addition & 0 deletions configs/mocha.opts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
--require reflect-metadata/Reflect
--reporter spec
--watch-extensions js
--exit
1 change: 1 addition & 0 deletions dev-packages/application-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@theia/application-package": "^0.14.0",
"@theia/compression-webpack-plugin": "^3.0.0",
"@types/fs-extra": "^4.0.2",
"@types/webpack": "^4.41.2",
"babel-loader": "^8.0.6",
"circular-dependency-plugin": "^5.0.0",
"copy-webpack-plugin": "^4.5.0",
Expand Down
73 changes: 73 additions & 0 deletions dev-packages/application-manager/src/expose-loader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/********************************************************************************
* Copyright (C) 2019 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 WITH Classpath-exception-2.0
********************************************************************************/

import * as path from 'path';
import * as webpack from 'webpack';
// tslint:disable:no-implicit-dependencies
import { RawSourceMap } from 'source-map';
import { ApplicationPackage } from '@theia/application-package/lib/application-package';

const modulePackages: { dir: string, name?: string }[] = [];
for (const extensionPackage of new ApplicationPackage({ projectPath: process.cwd() }).extensionPackages) {
modulePackages.push({
name: extensionPackage.name,
dir: path.dirname(extensionPackage.raw.installed!.packagePath)
});
}

function exposeModule(modulePackage: { dir: string, name?: string }, resourcePath: string, source: string): string {
if (!modulePackage.name) {
return source;
}
const { dir, name } = path.parse(resourcePath);
let moduleName = path.join(modulePackage.name, dir.substring(modulePackage.dir.length));
if (name !== 'index') {
moduleName = path.join(moduleName, name);
}
if (path.sep !== '/') {
moduleName = moduleName.split(path.sep).join('/');
}
return source + `\nif (!global) global = {};\n(global['theia'] = global['theia'] || {})['${moduleName}'] = this;\n`;
}

export = function (this: webpack.loader.LoaderContext, source: string, sourceMap?: RawSourceMap): string | undefined {
if (this.cacheable) {
this.cacheable();
}

let modulePackage = modulePackages.find(({ dir }) => this.resourcePath.startsWith(dir));
if (modulePackage) {
this.callback(undefined, exposeModule(modulePackage, this.resourcePath, source), sourceMap);
return;
}
const index = this.resourcePath.lastIndexOf('/node_modules');
if (index !== -1) {
const nodeModulesPath = this.resourcePath.substring(0, index + '/node_modules'.length);
let dir = this.resourcePath;
while ((dir = path.dirname(dir)) !== nodeModulesPath) {
try {
const { name } = require(path.join(dir, 'package.json'));
modulePackage = { name, dir };
modulePackages.push(modulePackage);
this.callback(undefined, exposeModule(modulePackage, this.resourcePath, source), sourceMap);
return;
} catch {
/** no-op */
}
}
}
this.callback(undefined, source, sourceMap);
};
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ function load(raw) {
}
function start() {
(window['theia'] = window['theia'] || {}).container = container;
const themeService = ThemeService.get();
themeService.loadUserTheme();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,45 @@
********************************************************************************/

import * as paths from 'path';
import * as fs from 'fs-extra';
import { AbstractGenerator } from './abstract-generator';

export class WebpackGenerator extends AbstractGenerator {

async generate(): Promise<void> {
await this.write(this.configPath, this.compileWebpackConfig());
await this.write(this.genConfigPath, this.compileWebpackConfig());
if (await this.shouldGenerateUserWebpackConfig()) {
await this.write(this.configPath, this.compileUserWebpackConfig());
}
}

protected async shouldGenerateUserWebpackConfig(): Promise<boolean> {
try {
const content = await fs.readFile(this.configPath, 'utf8');
return content.indexOf('gen-webpack.config') === -1;
} catch {
return true;
}
}

get configPath(): string {
return this.pck.path('webpack.config.js');
}

get genConfigPath(): string {
return this.pck.path('gen-webpack.config.js');
}

protected resolve(moduleName: string, path: string): string {
return this.pck.resolveModulePath(moduleName, path).split(paths.sep).join('/');
}

protected compileWebpackConfig(): string {
return `// @ts-check
return `/**
* Don't touch this file. It will be renerated by theia build.
* To customize webpack configuration change ${this.configPath}
*/
// @ts-check
const path = require('path');
const webpack = require('webpack');
const yargs = require('yargs');
Expand Down Expand Up @@ -201,4 +222,24 @@ module.exports = {
};`;
}

protected compileUserWebpackConfig(): string {
return `/**
* This file can be edited to customize webpack configuration.
* To reset delete this file and rerun yarn build again.
*/
// @ts-check
const config = require('${this.genConfigPath}');
/**
* Expose bundled modules on window.theia.moduleName namespace, e.g.
* window['theia']['@theia/core/lib/common/uri'].
* Such syntax can be used by external code, for instance, for testing.
config.module.rules.push({
test: /\\.js$/,
loader: require.resolve('@theia/application-manager/lib/expose-loader')
}); */
module.exports = config;`;
}

}
20 changes: 20 additions & 0 deletions examples/api-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@theia/api-tests",
"version": "0.14.0",
"description": "Theia API tests",
"dependencies": {
"@theia/core": "^0.14.0"
},
"license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0",
"repository": {
"type": "git",
"url": "https://github.com/eclipse-theia/theia.git"
},
"bugs": {
"url": "https://github.com/eclipse-theia/theia/issues"
},
"homepage": "https://github.com/eclipse-theia/theia",
"files": [
"src"
]
}
42 changes: 42 additions & 0 deletions examples/api-tests/src/editors.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/********************************************************************************
* Copyright (C) 2020 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 WITH Classpath-exception-2.0
********************************************************************************/

// @ts-check
describe('Editors', function () {

const { assert } = chai;

const { EditorManager } = require('@theia/editor/lib/browser/editor-manager');
const Uri = require('@theia/core/lib/common/uri');
const { WorkspaceService } = require('@theia/workspace/lib/browser/workspace-service');

/** @type {import('inversify').Container} */
const container = window['theia'].container;
const editorManager = container.get(EditorManager);
const workspaceService = container.get(WorkspaceService);

before(() => editorManager.closeAll());

it('open', async () => {
const root = (await workspaceService.roots)[0];
assert.equal(editorManager.all.length, 0);
await editorManager.open(new Uri.default(root.uri).resolve('package.json'), {
mode: 'reveal'
});
assert.equal(editorManager.all.length, 1);
});

});
55 changes: 55 additions & 0 deletions examples/api-tests/src/menus.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/********************************************************************************
* Copyright (C) 2020 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 WITH Classpath-exception-2.0
********************************************************************************/

// @ts-check
describe('Menus', function () {

const { MenuBarWidget } = require('@theia/core/lib/browser/menu/browser-menu-plugin');
const { ApplicationShell } = require('@theia/core/lib/browser/shell/application-shell');
const { CallHierarchyContribution } = require('@theia/callhierarchy/lib/browser/callhierarchy-contribution');
const { FileNavigatorContribution } = require('@theia/navigator/lib/browser/navigator-contribution');
const { ScmContribution } = require('@theia/scm/lib/browser/scm-contribution');
const { GitHistoryContribution } = require('@theia/git/lib/browser/history/git-history-contribution');
const { OutlineViewContribution } = require('@theia/outline-view/lib/browser/outline-view-contribution');
const { OutputContribution } = require('@theia/output/lib/browser/output-contribution');
const { PluginFrontendViewContribution } = require('@theia/plugin-ext/lib/main/browser/plugin-frontend-view-contribution');
const { ProblemContribution } = require('@theia/markers/lib/browser/problem/problem-contribution');
const { SearchInWorkspaceFrontendContribution } = require('@theia/search-in-workspace/lib/browser/search-in-workspace-frontend-contribution');

/** @type {import('inversify').Container} */
const container = window['theia'].container;
const shell = container.get(ApplicationShell);
const menuBar = /** @type {MenuBarWidget} */ (shell.topPanel.widgets.find(w => w instanceof MenuBarWidget));

for (const contribution of [
container.get(CallHierarchyContribution),
container.get(FileNavigatorContribution),
container.get(ScmContribution),
container.get(GitHistoryContribution),
container.get(OutlineViewContribution),
container.get(OutputContribution),
container.get(PluginFrontendViewContribution),
container.get(ProblemContribution),
container.get(SearchInWorkspaceFrontendContribution)
]) {
it(`should toggle '${contribution.viewLabel}' view`, async () => {
await contribution.closeView();
await menuBar.triggerMenuItem('View', contribution.viewLabel);
await shell.waitForActivation(contribution.viewId);
});
}

});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (C) 2017 Ericsson and others.
* Copyright (C) 2020 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
Expand All @@ -14,37 +14,29 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

/* tslint:disable:no-unused-expression*/
import { MainPage } from './main-page';
import { expect } from 'chai';
// @ts-check
describe('Shell', function () {

let mainPage: MainPage;
let driver: WebdriverIO.Client<void>;
const { assert } = chai;

describe('theia main page', () => {
const { ApplicationShell } = require('@theia/core/lib/browser/shell/application-shell');
const { StatusBarImpl } = require('@theia/core/lib/browser/status-bar');

before(() => {
const url = '/';
driver = browser;
driver.url(url);
mainPage = new MainPage(driver);
// Make sure that the application shell is loaded
mainPage.waitForStartup();
});
/** @type {import('inversify').Container} */
const container = window['theia'].container;
const shell = container.get(ApplicationShell);
const statusBar = container.get(StatusBarImpl);

it('should show the application shell', () => {
expect(mainPage.applicationShellExists()).to.be.true;
it('should be shown', () => {
assert.isTrue(shell.isAttached && shell.isVisible);
});

it('should show the main content panel', () => {
expect(mainPage.mainContentPanelExists()).to.be.true;
});

it('should show the left and right sidebars', () => {
expect(mainPage.rightSideBarExists() && mainPage.leftSideBarExists()).to.be.true;
assert.isTrue(shell.mainPanel.isAttached && shell.mainPanel.isVisible);
});

it('should show the status bar', () => {
expect(mainPage.statusBarExists()).to.be.true;
assert.isTrue(statusBar.isAttached && statusBar.isVisible);
});

});
Loading

0 comments on commit c9f0f1e

Please sign in to comment.