Skip to content

Commit 8266abb

Browse files
committed
re-export common packages
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 re-exporting @theia/application-package/lib/environment separately. Signed-off-by: Paul <paul.marechal@ericsson.com>
1 parent 73a1732 commit 8266abb

File tree

887 files changed

+1638
-1170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

887 files changed

+1638
-1170
lines changed

configs/errors.eslintrc.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"guard-for-in": "error",
3535
"id-blacklist": "off",
3636
"id-match": "off",
37-
"import/no-extraneous-dependencies": "off",
37+
"import/no-extraneous-dependencies": "error",
3838
"max-len": [
3939
"error",
4040
{
@@ -130,5 +130,15 @@
130130
}
131131
}
132132
]
133-
}
133+
},
134+
"overrides": [
135+
{
136+
"files": [
137+
"*.{spec,espec,slow-spec}.{js,ts}"
138+
],
139+
"rules": {
140+
"import/no-extraneous-dependencies": "off"
141+
}
142+
}
143+
]
134144
}

dev-packages/application-manager/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"url-loader": "^1.1.2",
5454
"webpack": "^4.0.0",
5555
"webpack-cli": "2.0.12",
56-
"worker-loader": "^1.1.1"
56+
"worker-loader": "^1.1.1",
57+
"yargs": "^15.3.1"
5758
},
5859
"devDependencies": {
5960
"@theia/ext-scripts": "1.11.0"

dev-packages/application-manager/src/expose-loader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

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

2323
const modulePackages: { dir: string, name?: string }[] = [];

dev-packages/electron/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ The post-install scripts can be skipped by setting an environment variable:
2929
- Windows (cmd): `set THEIA_ELECTRON_SKIP_REPLACE_FFMPEG=1`
3030
- Windows (ps): `$env:THEIA_ELECTRON_SKIP_REPLACE_FFMPEG=1`
3131

32+
## Re-exports
33+
34+
- `electron` through `@theia/electron`
35+
- `native-keymap` through `@theia/electron/native-keymap`
36+
3237
## Additional Information
3338

3439
- [Theia - GitHub](https://github.com/eclipse-theia/theia)

dev-packages/electron/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Electron = require('electron');
2+
export = Electron;

dev-packages/electron/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('electron');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from 'native-keymap'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const { __exportStar } = require('tslib');
2+
__exportStar(require('native-keymap'), exports);

dev-packages/electron/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"url": "https://github.com/eclipse-theia/theia/issues"
1515
},
1616
"homepage": "https://github.com/eclipse-theia/theia",
17+
"main": "index.js",
18+
"types": "index.d.ts",
1719
"bin": {
1820
"electron": "electron-cli.js",
1921
"electron-codecs-test": "electron-codecs-test.js",
@@ -26,6 +28,7 @@
2628
"fix-path": "^3.0.0",
2729
"native-keymap": "^2.1.2",
2830
"node-gyp": "^7.0.0",
31+
"tslib": "^2.1.0",
2932
"unzipper": "^0.9.11",
3033
"yargs": "^15.3.1"
3134
},

examples/api-samples/compile.tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
},
1818
{
1919
"path": "../../packages/vsx-registry/compile.tsconfig.json"
20+
},
21+
{
22+
"path": "../../packages/filesystem/compile.tsconfig.json"
23+
},
24+
{
25+
"path": "../../packages/workspace/compile.tsconfig.json"
2026
}
2127
]
2228
}

0 commit comments

Comments
 (0)