Skip to content

Commit

Permalink
re-export common packages
Browse files Browse the repository at this point in the history
Enable errors for import/no-extraneous-dependencies.

Relying on hoisting makes building Theia application somewhat unstable.
In general cases, everything is fine. But as soon as Yarn decides to
hoist things differently then it can become difficult to fix.

This commit fixes the issue by re-exporting dependencies from
@theia/core, this way instead of relying on implicit dependencies one
can directly import what @theia/core uses like:

    import * as dep from '@theia/core/shared/dep'

To make this work I added a 'shared' folder under 'packages/core' with
js scripts that re-export everything from their matching library.

To ease with the development there is a script named
'packages/core/scripts/generate-shared.js' that will read values
from 'packages/core/package.json#theiaReExports' in order to more easily
add new packages. Depending on how the package exports things we need to
re-export things the same way.

@theia/electron now re-exports all members from electron. This
prevents having to use electron as an implicit dependency.

@theia/electron now also is a @theia/core optional peer dependency. This
directly represent the use case we have for this package where we will
only use electron features if this package is installed by application
makers.

If people don't know about this way to consume @theia/core's shared
dependencies then nothing will change and they might keep using implicit
dependencies. But the new recommended method is to use those re-exports
in order to make builds more stable in the face of hoisting and other
dependency tree optimizations.

Noteworthy: There was an issue with sharing @theia/application-package
since I only re-export the main 'index.js' it tried to include
Node-specific code in frontend applications. I fixed this by adding a
webpack IgnorePlugin to filter out non-relevant files from the frontend
bundles.

Signed-off-by: Paul <paul.marechal@ericsson.com>
  • Loading branch information
paul-marechal committed Feb 25, 2021
1 parent 24e268c commit 6944273
Show file tree
Hide file tree
Showing 888 changed files with 1,643 additions and 1,170 deletions.
14 changes: 12 additions & 2 deletions configs/errors.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"guard-for-in": "error",
"id-blacklist": "off",
"id-match": "off",
"import/no-extraneous-dependencies": "off",
"import/no-extraneous-dependencies": "error",
"max-len": [
"error",
{
Expand Down Expand Up @@ -130,5 +130,15 @@
}
}
]
}
},
"overrides": [
{
"files": [
"*.{spec,espec,slow-spec}.{js,ts}"
],
"rules": {
"import/no-extraneous-dependencies": "off"
}
}
]
}
3 changes: 2 additions & 1 deletion dev-packages/application-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"url-loader": "^1.1.2",
"webpack": "^4.0.0",
"webpack-cli": "2.0.12",
"worker-loader": "^1.1.1"
"worker-loader": "^1.1.1",
"yargs": "^15.3.1"
},
"devDependencies": {
"@theia/ext-scripts": "1.10.0"
Expand Down
4 changes: 2 additions & 2 deletions dev-packages/application-manager/src/expose-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

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

const modulePackages: { dir: string, name?: string }[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ plugins.push(new CircularDependencyPlugin({
exclude: /(node_modules|examples)[\\\\|\/]./,
failOnError: false // https://github.com/nodejs/readable-stream/issues/280#issuecomment-297076462
}));
plugins.push(new webpack.IgnorePlugin({
checkResource(resource, context) {
if (process.platform === 'win32') {
context = context.replace(/\\\\/g, '/');
}
if (context.endsWith('/application-package/lib') && resource !== './environment') {
return true;
}
}
}));
module.exports = {
entry: path.resolve(__dirname, 'src-gen/frontend/index.js'),
Expand Down
5 changes: 5 additions & 0 deletions dev-packages/electron/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ The post-install scripts can be skipped by setting an environment variable:
- Windows (cmd): `set THEIA_ELECTRON_SKIP_REPLACE_FFMPEG=1`
- Windows (ps): `$env:THEIA_ELECTRON_SKIP_REPLACE_FFMPEG=1`

## Re-exports

- `electron` through `@theia/electron`
- `native-keymap` through `@theia/electron/native-keymap`

## Additional Information

- [Theia - GitHub](https://github.com/eclipse-theia/theia)
Expand Down
2 changes: 2 additions & 0 deletions dev-packages/electron/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Electron = require('electron');
export = Electron;
1 change: 1 addition & 0 deletions dev-packages/electron/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('electron');
1 change: 1 addition & 0 deletions dev-packages/electron/native-keymap.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from 'native-keymap'
2 changes: 2 additions & 0 deletions dev-packages/electron/native-keymap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const { __exportStar } = require('tslib');
__exportStar(require('native-keymap'), exports);
3 changes: 3 additions & 0 deletions dev-packages/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"url": "https://github.com/eclipse-theia/theia/issues"
},
"homepage": "https://github.com/eclipse-theia/theia",
"main": "index.js",
"types": "index.d.ts",
"bin": {
"electron": "electron-cli.js",
"electron-codecs-test": "electron-codecs-test.js",
Expand All @@ -26,6 +28,7 @@
"fix-path": "^3.0.0",
"native-keymap": "^2.1.2",
"node-gyp": "^7.0.0",
"tslib": "^2.1.0",
"unzipper": "^0.9.11",
"yargs": "^15.3.1"
},
Expand Down
6 changes: 6 additions & 0 deletions examples/api-samples/compile.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
},
{
"path": "../../packages/vsx-registry/compile.tsconfig.json"
},
{
"path": "../../packages/filesystem/compile.tsconfig.json"
},
{
"path": "../../packages/workspace/compile.tsconfig.json"
}
]
}
2 changes: 2 additions & 0 deletions examples/api-samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"description": "Theia - Example code to demonstrate Theia API",
"dependencies": {
"@theia/core": "1.10.0",
"@theia/filesystem": "1.10.0",
"@theia/output": "1.10.0",
"@theia/workspace": "1.10.0",
"@theia/vsx-registry": "1.10.0"
},
"theiaExtensions": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { ContainerModule } from 'inversify';
import { ContainerModule } from '@theia/core/shared/inversify';
import { bindDynamicLabelProvider } from './label/sample-dynamic-label-provider-command-contribution';
import { bindSampleUnclosableView } from './view/sample-unclosable-view-contribution';
import { bindSampleOutputChannelWithSeverity } from './output/sample-output-channel-with-severity';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { postConstruct, injectable, inject, interfaces } from 'inversify';
import { postConstruct, injectable, inject, interfaces } from '@theia/core/shared/inversify';
import {
createPreferenceProxy, FrontendApplicationContribution, LabelProvider,
PreferenceContribution, PreferenceProxy, PreferenceSchema, PreferenceService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, inject, interfaces } from 'inversify';
import { injectable, inject, interfaces } from '@theia/core/shared/inversify';
import { Command, CommandContribution, CommandRegistry, CommandHandler } from '@theia/core';
import { FrontendApplicationContribution, LabelProviderContribution } from '@theia/core/lib/browser';
import { SampleDynamicLabelProviderContribution } from './sample-dynamic-label-provider-contribution';
Expand Down Expand Up @@ -59,4 +59,3 @@ export const bindDynamicLabelProvider = (bind: interfaces.Bind) => {
bind(LabelProviderContribution).toService(SampleDynamicLabelProviderContribution);
bind(CommandContribution).to(SampleDynamicLabelProviderCommandContribution).inSingletonScope();
};

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable } from 'inversify';
import { injectable } from '@theia/core/shared/inversify';
import { DefaultUriLabelProviderContribution, DidChangeLabelEvent } from '@theia/core/lib/browser/label-provider';
import URI from '@theia/core/lib/common/uri';
import { Emitter, Event } from '@theia/core';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, ContainerModule } from 'inversify';
import { Menu as MenuWidget } from '@phosphor/widgets';
import { injectable, ContainerModule } from '@theia/core/shared/inversify';
import { Menu as MenuWidget } from '@theia/core/shared/@phosphor/widgets';
import { Disposable } from '@theia/core/lib/common/disposable';
import { MenuNode, CompositeMenuNode } from '@theia/core/lib/common/menu';
import { BrowserMainMenuFactory, MenuCommandRegistry, DynamicMenuWidget } from '@theia/core/lib/browser/menu/browser-menu-plugin';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
********************************************************************************/

import { Command, CommandContribution, CommandRegistry, MAIN_MENU_BAR, MenuContribution, MenuModelRegistry, MenuNode, SubMenuOptions } from '@theia/core/lib/common';
import { injectable, interfaces } from 'inversify';
import { injectable, interfaces } from '@theia/core/shared/inversify';

const SampleCommand: Command = {
id: 'sample-command',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
import { inject, injectable, interfaces } from 'inversify';
import { inject, injectable, interfaces } from '@theia/core/shared/inversify';
import { OutputChannelManager, OutputChannelSeverity } from '@theia/output/lib/common/output-channel';

@injectable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { inject, injectable, interfaces } from 'inversify';
import { inject, injectable, interfaces } from '@theia/core/shared/inversify';
import { AbstractViewContribution, bindViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
import { Command, CommandRegistry, MessageService } from '@theia/core/lib/common';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
********************************************************************************/

import { ReactWidget } from '@theia/core/lib/browser';
import { injectable, postConstruct } from 'inversify';
import * as React from 'react';
import { injectable, postConstruct } from '@theia/core/shared/inversify';
import * as React from '@theia/core/shared/react';

/**
* This sample view is used to demo the behavior of "Widget.title.closable".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { inject, injectable, interfaces } from 'inversify';
import { inject, injectable, interfaces } from '@theia/core/shared/inversify';
import { VSXEnvironment } from '@theia/vsx-registry/lib/common/vsx-environment';
import { Command, CommandContribution, CommandRegistry, MessageService } from '@theia/core/lib/common';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, ContainerModule } from 'inversify';
import { injectable, ContainerModule } from '@theia/core/shared/inversify';
import { CompositeMenuNode } from '@theia/core/lib/common/menu';
import { ElectronMainMenuFactory, ElectronMenuOptions } from '@theia/core/lib/electron-browser/menu/electron-main-menu-factory';
import { PlaceholderMenuNode } from '../../browser/menu/sample-menu-contribution';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { remote, Menu, BrowserWindow } from 'electron';
import { inject, injectable, postConstruct } from 'inversify';
import { remote, Menu, BrowserWindow } from '@theia/core/shared/electron';
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
import { isOSX } from '@theia/core/lib/common/os';
import { CommonMenus } from '@theia/core/lib/browser';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { ContainerModule } from 'inversify';
import { ContainerModule } from '@theia/core/shared/inversify';
import { ElectronIpcConnectionProvider } from '@theia/core/lib/electron-browser/messaging/electron-ipc-connection-provider';
import { CommandContribution, MenuContribution } from '@theia/core/lib/common';
import { SampleUpdater, SampleUpdaterPath, SampleUpdaterClient } from '../../common/updater/sample-updater';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable } from 'inversify';
import { injectable } from '@theia/core/shared/inversify';
import { ElectronMainApplication, ElectronMainApplicationContribution } from '@theia/core/lib/electron-main/electron-main-application';
import { SampleUpdater, SampleUpdaterClient, UpdateStatus } from '../../common/updater/sample-updater';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { ContainerModule } from 'inversify';
import { ContainerModule } from '@theia/core/shared/inversify';
import { JsonRpcConnectionHandler } from '@theia/core/lib/common/messaging/proxy-factory';
import { ElectronMainApplicationContribution } from '@theia/core/lib/electron-main/electron-main-application';
import { ElectronConnectionHandler } from '@theia/core/lib/electron-common/messaging/electron-connection-handler';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"scripts": {
"preinstall": "node-gyp install",
"postinstall": "node scripts/post-install.js",
"prepare": "yarn prepare:references && yarn prepare:build && yarn prepare:hoisting && yarn download:plugins",
"prepare": "yarn prepare:references && yarn --cwd packages/core prepare && yarn prepare:build && yarn prepare:hoisting && yarn download:plugins",
"prepare:references": "node scripts/compile-references.js",
"prepare:build": "yarn build && run lint && run build \"@theia/example-*\" --stream --parallel",
"prepare:hoisting": "theia check:hoisted -s",
Expand Down
2 changes: 1 addition & 1 deletion packages/bulk-edit/src/browser/bulk-edit-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, inject } from 'inversify';
import { injectable, inject } from '@theia/core/shared/inversify';
import { Widget } from '@theia/core/lib/browser/widgets/widget';
import { CommandRegistry } from '@theia/core/lib/common';
import { AbstractViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { ContainerModule } from 'inversify';
import { ContainerModule } from '@theia/core/shared/inversify';
import { WidgetFactory } from '@theia/core/lib/browser/widget-manager';
import { BulkEditTreeWidget, BULK_EDIT_TREE_WIDGET_ID, createBulkEditTreeWidget, InMemoryTextResourceResolver } from './bulk-edit-tree';
import { FrontendApplicationContribution, LabelProviderContribution } from '@theia/core/lib/browser';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, inject } from 'inversify';
import { injectable, inject } from '@theia/core/shared/inversify';
import { LabelProvider, LabelProviderContribution, DidChangeLabelEvent } from '@theia/core/lib/browser/label-provider';
import { BulkEditInfoNode } from './bulk-edit-tree';
import { TreeLabelProvider } from '@theia/core/lib/browser/tree/tree-label-provider';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { interfaces, Container } from 'inversify';
import { interfaces, Container } from '@theia/core/shared/inversify';
import { BulkEditTreeWidget } from './bulk-edit-tree-widget';
import { BulkEditTree } from './bulk-edit-tree';
import { BulkEditTreeModel } from './bulk-edit-tree-model';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, inject } from 'inversify';
import { injectable, inject } from '@theia/core/shared/inversify';
import { BulkEditNode, BulkEditTree } from './bulk-edit-tree';
import { TreeModelImpl, OpenerService, open, TreeNode } from '@theia/core/lib/browser';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, inject } from 'inversify';
import { injectable, inject } from '@theia/core/shared/inversify';
import {
TreeWidget, TreeProps, ContextMenuRenderer, TreeNode, TreeModel,
CompositeTreeNode, NodeProps
} from '@theia/core/lib/browser';
import * as React from 'react';
import * as React from '@theia/core/shared/react';
import { BulkEditInfoNode, BulkEditNode } from './bulk-edit-tree';
import { BulkEditTreeModel } from './bulk-edit-tree-model';
import { FileResourceResolver } from '@theia/filesystem/lib/browser';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ FrontendApplicationConfigProvider.set({
...ApplicationProps.DEFAULT.frontend.config
});

import { Container } from 'inversify';
import { Container } from '@theia/core/shared/inversify';
import { BulkEditInfoNode, BulkEditTree } from './bulk-edit-tree';

global.monaco = sinon.stub() as unknown as typeof monaco;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable } from 'inversify';
import { injectable } from '@theia/core/shared/inversify';
import { TreeNode, CompositeTreeNode, SelectableTreeNode, ExpandableTreeNode, TreeImpl } from '@theia/core/lib/browser';
import { UriSelection } from '@theia/core/lib/common/selection';
import { BulkEditNodeSelection } from './bulk-edit-node-selection';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable } from 'inversify';
import { injectable } from '@theia/core/shared/inversify';
import URI from '@theia/core/lib/common/uri';
import { Resource, ResourceResolver } from '@theia/core/lib/common';
import { MaybePromise } from '@theia/core';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, inject } from 'inversify';
import { injectable, inject } from '@theia/core/shared/inversify';
import { MenuModelRegistry, Command, CommandRegistry } from '@theia/core/lib/common';
import { AbstractViewContribution, OpenViewArguments, KeybindingRegistry } from '@theia/core/lib/browser';
import { EDITOR_CONTEXT_MENU } from '@theia/editor/lib/browser';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { CALLHIERARCHY_ID } from './callhierarchy';
import { createHierarchyTreeWidget } from './callhierarchy-tree';
import { CurrentEditorAccess } from './current-editor-access';

import { ContainerModule } from 'inversify';
import { ContainerModule } from '@theia/core/shared/inversify';

import '../../src/browser/style/index.css';

Expand Down
4 changes: 2 additions & 2 deletions packages/callhierarchy/src/browser/callhierarchy-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, inject, named, postConstruct } from 'inversify';
import { Position, DocumentUri } from 'vscode-languageserver-types';
import { injectable, inject, named, postConstruct } from '@theia/core/shared/inversify';
import { Position, DocumentUri } from '@theia/core/shared/vscode-languageserver-types';
import { Definition, Caller, Callee } from './callhierarchy';
import { ContributionProvider } from '@theia/core/lib/common';
import { LanguageSelector, score } from '../common/language-selector';
Expand Down
Loading

0 comments on commit 6944273

Please sign in to comment.