Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react): use and detect local npx to create-react-app #85

Merged
merged 4 commits into from
Mar 17, 2021
Merged

Conversation

olamothe
Copy link
Member

Try to detect valid node version 10.16.0 ( https://github.com/facebook/create-react-app#creating-an-app ) + npx.

Otherwise, warn and exit, with some (hopefully) helpful message about how to install node with nvm.

https://coveord.atlassian.net/browse/CDX-102

@github-actions
Copy link
Contributor

Pull Request Report

PR Title

✅ Title follows the conventional commit spec.

return false;
}

if (stdio.stderr) {
Copy link
Contributor

@y-lakhdar y-lakhdar Mar 16, 2021

Choose a reason for hiding this comment

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

npx depends on update-notifier.
What would happen if the user has an older version of npx and gets the update warning message? Will it be redirected to stderr?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've tested this and it seems everything will be okay/will still function properly with an older version of npm/node/npx 🤞, as long as it's higher than Node 10.16, and npx is globally available (no matter the version).

Copy link
Collaborator

@louis-bompart louis-bompart left a comment

Choose a reason for hiding this comment

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

Few suggestions.
More importantly, I would write a markdown page (maybe on the wiki of the repo?) to explains in more length what's what to the user and put a link to it in the message

Comment on lines 163 to 166
this.warn('Please visit https://nodejs.org/ for installation or upgrade.');
this.warn(
'Or use (strongly recommended) https://github.com/nvm-sh/nvm and https://github.com/coreybutler/nvm-windows to manage multiple version of Node.js'
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use a template string instead of two warn

Suggested change
this.warn('Please visit https://nodejs.org/ for installation or upgrade.');
this.warn(
'Or use (strongly recommended) https://github.com/nvm-sh/nvm and https://github.com/coreybutler/nvm-windows to manage multiple version of Node.js'
);
this.warn(
`Please visit https://nodejs.org/ for installation or upgrade.
Or use (strongly recommended) https://github.com/nvm-sh/nvm and https://github.com/coreybutler/nvm-windows to manage multiple version of Node.js`
);

import {Storage} from '../../../lib/oauth/storage';
import AuthenticationRequired from '../../../lib/decorators/authenticationRequired';
import {AuthenticatedClient} from '../../../lib/platform/authenticatedClient';

import {lt} from 'semver';
Copy link
Collaborator

Choose a reason for hiding this comment

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

that's a really cryptic name, can you use an as to rename it to something more meaningful?

Copy link
Member Author

Choose a reason for hiding this comment

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

lt gt for lessThan, greaterThan. That's the same in HTML ;)

I can alias, sure !

private async checkIfUserHasNpx() {
const stdio = await spawnProcessStdio('npx', ['--version']);

if (stdio.stderr && stdio.stderr.match(/ENOENT/i)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would assert on the actual exit code (int). I do a few suggestions, starting here:

Suggested change
if (stdio.stderr && stdio.stderr.match(/ENOENT/i)) {
if (stdio.exitcode === constants.errno.ENOENT) {

import {Storage} from '../../../lib/oauth/storage';
import AuthenticationRequired from '../../../lib/decorators/authenticationRequired';
import {AuthenticatedClient} from '../../../lib/platform/authenticatedClient';

import {lt} from 'semver';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Adding constants from os for the kill code assertion

Suggested change
import {lt} from 'semver';
import {lt} from 'semver';
import {constants} from 'os';

options: SpawnOptions = {}
): Promise<{stdout: string; stderr: string}> {
return new Promise((resolve) => {
const stdio = {stdout: '', stderr: ''};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add exitCode to the stdio (prolly should be renamed to something else like processOutputs)

Suggested change
const stdio = {stdout: '', stderr: ''};
const stdio = {stdout: '', stderr: '', exitCode: null};

Comment on lines 61 to 63
child.on('close', () => {
resolve(stdio);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
child.on('close', () => {
resolve(stdio);
});
child.on('close', (code) => {
stdio.exitCode = code;
resolve(stdio);
});

import {Storage} from '../../../lib/oauth/storage';
import AuthenticationRequired from '../../../lib/decorators/authenticationRequired';
import {AuthenticatedClient} from '../../../lib/platform/authenticatedClient';

import {lt} from 'semver';
Copy link
Member Author

Choose a reason for hiding this comment

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

lt gt for lessThan, greaterThan. That's the same in HTML ;)

I can alias, sure !

return false;
}

if (stdio.stderr) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I've tested this and it seems everything will be okay/will still function properly with an older version of npm/node/npx 🤞, as long as it's higher than Node 10.16, and npx is globally available (no matter the version).

private async checkIfUserHasNodeGreaterThan10() {
const output = await spawnProcessOutput('node', ['--version']);
if (this.isMissingExecutable(output)) {
this.warn(`
Copy link
Member Author

Choose a reason for hiding this comment

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

You will see I've split up all the warn message with an empty line at the start and end of the message.

It help readability in the CLI at the end, with a nice "paragraph" separation kinda thing.

eg:

›   Warning:
›         ui:create:react requires a valid Node.js installation to run.
›         An unknown error happened while trying to determine your node version with node --version
›         spawn foo ENOENT

@olamothe olamothe merged commit b7ac6dd into master Mar 17, 2021
@olamothe olamothe deleted the CDX-102 branch March 17, 2021 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants