Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Launch Yeoman Generator in separate thread #6

Merged
merged 5 commits into from
Jan 13, 2020

Conversation

vitaliy-guliy
Copy link
Contributor

@vitaliy-guliy vitaliy-guliy commented Dec 26, 2019

As VS Code extension generator goes not take in attention an option specifying the directory for generated projects, it always generate a project into current working directory.
The idea was to run Yeoman generator in separate node instance and change current working directory to /projects.

Fixes issue eclipse-che/che#15443

Subtask of eclipse-che/che#14228

Signed-off-by: Vitaliy Gulyy <[email protected]>
@@ -0,0 +1,38 @@
/*********************************************************************
* Copyright (c) 2018 Red Hat, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

as you're doing a refactoring, copyright date needs to be updated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -0,0 +1,221 @@
/*********************************************************************
* Copyright (c) 2018 Red Hat, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

please update

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

const path = require('path');
const fork = require('child_process').fork;

export class YeomanProcessAdapter {
Copy link
Contributor

Choose a reason for hiding this comment

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

please comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

const currentWorkspace = workspaceFolders[0];

// start Yeoman generator in separate node instance
const scriptPath = this.extensionPath + '/lib/yeoman-process.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

we should use Path.resolve no ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

child.on('message', this.onMessage);

child.stdout.on('data', (data: any) => {
console.log(`## stdout: ${data}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to output to the console stdout or stderr ?

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 helps us to understand the reason when something goes wrong.
Once it helped me to catch an error when running the generator.

Copy link
Contributor

Choose a reason for hiding this comment

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

why it's not part of the output on the UI side then ?

IMHO we shouldn't pollute that console by default (= not when debugging)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

UI displays only the messages related to creating the extension.
The messages form stdout / stderr are printed to Theia backend console, which is not visible in Theia.
It's easy to ignore them, but should we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have reworked it a bit. All the output has been printed to the UI. Looks nice.


const proc = process;

export class YeomanProcess {
Copy link
Contributor

Choose a reason for hiding this comment

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

please comment ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@benoitf
Copy link
Contributor

benoitf commented Jan 9, 2020

Hello,
in the current code (before your pull request), it's doing:

    const currentWorkspace = workspaceFolders[0];	
    yeomanOpts.cwd = currentWorkspace.uri.path;	
    const yeomanEnvironment = yeoman.createEnv(undefined, yeomanOpts, new TheiaYeomanAdapter());

so AFAIK it launches yeoman from the workspace folder which should be /projects no ?
why do we need a fork process ?

@vitaliy-guliy
Copy link
Contributor Author

Hello,
in the current code (before your pull request), it's doing:

    const currentWorkspace = workspaceFolders[0];	
    yeomanOpts.cwd = currentWorkspace.uri.path;	
    const yeomanEnvironment = yeoman.createEnv(undefined, yeomanOpts, new TheiaYeomanAdapter());

so AFAIK it launches yeoman from the workspace folder which should be /projects no ?
why do we need a fork process ?

VS Code extension generator does not take into account cwd configuration property and always generate the project into current working directory, which is /home/theia. That's why we need to launch a separate process and change the working directory on /projects.

In the current code, VS Code yeoman generator is running in current node instance, not in separate.

Signed-off-by: Vitaliy Gulyy <[email protected]>
Signed-off-by: Vitaliy Guliy <[email protected]>
Copy link
Contributor

@benoitf benoitf left a comment

Choose a reason for hiding this comment

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

I tested. Works fine.

FYI build is failing with CI
Probably you need to replace theia:plugin by theia-plugin in package.json file

@vitaliy-guliy
Copy link
Contributor Author

I tried to do it before. You could scroll up to see the commit where I returned it back to 'theia:plugin'.
On the local machine 'theia-plugin' does not work also

yarn run v1.17.3
$ yarn run format-code && yarn run compile && yarn run tslint-fix && theia-plugin pack
$ tsfmt -r
$ tsc
$ tslint --fix --project .
/bin/sh: 1: theia-plugin: not found
error Command failed with exit code 127.

@vitaliy-guliy
Copy link
Contributor Author

@benoitf could you merge this PR? It seems only you have right do it.

@benoitf
Copy link
Contributor

benoitf commented Jan 13, 2020

I can merge but we need to fix first the ci issue else it won't be built and then it won't be available

Signed-off-by: Vitaliy Gulyy <[email protected]>
@benoitf benoitf merged commit 7a0f742 into eclipse-theia:master Jan 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants