Skip to content

Commit

Permalink
- use of worker-loader in order to assemble worker in its own file
Browse files Browse the repository at this point in the history
- do not need anymore the extension service to provide the worker content file
  • Loading branch information
benoitf committed Mar 14, 2018
1 parent 2a48ec6 commit 40a4eba
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
3 changes: 2 additions & 1 deletion dev-packages/application-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"source-map-support": "^0.4.18",
"umd-compat-loader": "^2.1.1",
"url-loader": "^0.5.8",
"webpack": "^2.2.1"
"webpack": "^2.2.1",
"worker-loader": "^1.1.1"
},
"devDependencies": {
"@theia/ext-scripts": "^0.2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ module.exports = {
},
module: {
rules: [
{
test: /worker-main\\.js$/,
loader: 'worker-loader',
options: {
name: 'worker-ext.[hash].js'
}
},
{
test: /\\.css$/,
exclude: /\\.useable\\.css$/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import { MaybePromise } from "@theia/core/lib/common";
export default new ContainerModule(bind => {
bind(FrontendApplicationContribution).toDynamicValue(ctx => ({
onStart(app: FrontendApplication): MaybePromise<void> {
const worker = new Worker('/webworker/worker-main.ts');

const worker: Worker = new (require('../worker/worker-main'));
worker.addEventListener('message', message => {
console.log(message);
console.log('message is', message);
});
}
}));
Expand Down
5 changes: 0 additions & 5 deletions packages/isolated-extension-api/src/node/extension-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,5 @@ export class ExtensionApiContribution implements BackendApplicationContribution
const filePath: string = req.params.path;
res.sendFile(extensionPath + filePath);
});

app.get('/webworker/:file', (req, res) => {
const filePath: string = req.params.file;
res.sendFile(__dirname + filePath);
});
}
}
4 changes: 3 additions & 1 deletion packages/isolated-extension-api/src/worker/worker-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ export interface MainThreadCommandsShape extends Disposable {
$getCommands(): Thenable<string[]>;
}

const ctx: Worker = self as any;

const emmitter = new Emitter();
const rpc = new RPCProtocolImpl({
onMessage: emmitter.event,
send: (m: {}) => {
postMessage(m);
ctx.postMessage(m);
}
});
addEventListener('message', (message: any) => {
Expand Down
28 changes: 27 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ ajv-keywords@^1.1.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-1.5.1.tgz#314dd0a4b3368fad3dfcdc54ede6171b886daf3c"

ajv-keywords@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.1.0.tgz#ac2b27939c543e95d2c06e7f7f5c27be4aa543be"

ajv@^4.7.0, ajv@^4.9.1:
version "4.11.8"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.11.8.tgz#82ffb02b29e662ae53bdc20af15947706739c536"
Expand All @@ -382,6 +386,14 @@ ajv@^5.0.0, ajv@^5.1.0, ajv@^5.2.2:
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.3.0"

ajv@^6.1.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.2.1.tgz#28a6abc493a2abe0fb4c8507acaedb43fa550671"
dependencies:
fast-deep-equal "^1.0.0"
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.3.0"

align-text@^0.1.1, align-text@^0.1.3:
version "0.1.4"
resolved "https://registry.yarnpkg.com/align-text/-/align-text-0.1.4.tgz#0cd90a561093f35d0a99256c22b7069433fad117"
Expand Down Expand Up @@ -4505,7 +4517,7 @@ loader-utils@^0.2.15, loader-utils@^0.2.16, loader-utils@^0.2.5, loader-utils@~0
json5 "^0.5.0"
object-assign "^4.0.1"

loader-utils@^1.0.2, loader-utils@^1.0.3, loader-utils@^1.1.0:
loader-utils@^1.0.0, loader-utils@^1.0.2, loader-utils@^1.0.3, loader-utils@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.1.0.tgz#c98aef488bcceda2ffb5e2de646d6a754429f5cd"
dependencies:
Expand Down Expand Up @@ -6788,6 +6800,13 @@ schema-utils@^0.3.0:
dependencies:
ajv "^5.0.0"

schema-utils@^0.4.0:
version "0.4.5"
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-0.4.5.tgz#21836f0608aac17b78f9e3e24daff14a5ca13a3e"
dependencies:
ajv "^6.1.0"
ajv-keywords "^3.1.0"

seek-bzip@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/seek-bzip/-/seek-bzip-1.0.5.tgz#cfe917cb3d274bcffac792758af53173eb1fabdc"
Expand Down Expand Up @@ -8346,6 +8365,13 @@ wordwrap@~0.0.2:
version "0.0.3"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107"

worker-loader@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/worker-loader/-/worker-loader-1.1.1.tgz#920d74ddac6816fc635392653ed8b4af1929fd92"
dependencies:
loader-utils "^1.0.0"
schema-utils "^0.4.0"

wrap-ansi@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"
Expand Down

0 comments on commit 40a4eba

Please sign in to comment.