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: Fail-fast if the path to npm cache contains whitespaces #11517

Merged
merged 21 commits into from
Aug 9, 2021

Conversation

mshabarov
Copy link
Contributor

@mshabarov mshabarov commented Aug 4, 2021

Description

Checks that the npm version accepts whitespaces in user home path and explains how to fix that otherwise.

Fixes #10084

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

Additional for Feature type of change

  • Enhancement / new feature was discussed in a corresponding GitHub issue and Acceptance Criteria were created.


private ToolStubInfo(boolean stubbed, String version) {
this.stubbed = stubbed;
assert !stubbed || version != null && !version
Copy link

Choose a reason for hiding this comment

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

OperatorPrecedence: Use grouping parenthesis to make the operator precedence explicit
(at-me in a reply with help or ignore)

File binDir = new File(baseDir, "node/node_modules/npm/bin");
FileUtils.forceMkdir(binDir);
String stub = "process.argv.includes('--version') && console.log('6.14.10');";
String stub = String.format("process.argv.includes('--version') && "
+ "console.log(%s);", stubNpm.getVersion());
FileUtils.writeStringToFile(new File(binDir, "npm-cli.js"), stub,
StandardCharsets.UTF_8);
FileUtils.writeStringToFile(new File(binDir, "npx-cli.js"), stub,
StandardCharsets.UTF_8);
}
boolean isWindows = System.getProperty("os.name").startsWith("Windows");
Copy link

Choose a reason for hiding this comment

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

NULL_DEREFERENCE: object returned by getProperty("os.name") could be null and is dereferenced at line 76.
(at-me in a reply with help or ignore)

npmCacheCommand.add("--global");
String output = FrontendUtils.executeCommand(npmCacheCommand);
output = parseCommandOutput(output);
if (output.isEmpty()) {
Copy link

Choose a reason for hiding this comment

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

NULL_DEREFERENCE: object output last assigned on line 524 could be null and is dereferenced at line 525.
(at-me in a reply with help or ignore)

@vaadin vaadin deleted a comment from vaadin-bot Aug 5, 2021
@mshabarov
Copy link
Contributor Author

mshabarov commented Aug 5, 2021

TaskRunPnpmInstallTest and FrontendToolsTest tests successfully run on Windows agent and show the message as expected.

@mshabarov mshabarov changed the title fix: Fail with a message if user home contains whitespaces fix: Fail-fast if the path to npm cache contains whitespaces Aug 6, 2021
@@ -724,4 +799,11 @@ private String doGetNodeExecutable() {
return getNodeExecutable();
}
}

private String parseCommandOutput(String output) {
Copy link
Contributor

Choose a reason for hiding this comment

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

parse ?
What kind of parsing?
This is rather a conversation or just a "normalization"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's not a parsing, renamed to removeLineBreaks.

@vaadin-bot
Copy link
Collaborator

SonarQube analysis reported 15 issues

  • MAJOR 6 major
  • MINOR 8 minor
  • INFO 1 info

Top 10 issues

  1. MAJOR FrontendTools.java#L525: A "NullPointerException" could be thrown; "output" is nullable here. rule
  2. MAJOR TaskRunNpmInstall.java#L92: Remove this unused "classFinder" private field. rule
  3. MAJOR TaskRunNpmInstall.java#L294: Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed. rule
  4. MAJOR FrontendStubs.java#L82: Exceptional return value of java.io.File.createNewFile() ignored in com.vaadin.flow.testutil.FrontendStubs.createStubNode(FrontendStubs$ToolStubInfo, FrontendStubs$ToolStubInfo, String) rule
  5. MAJOR FrontendStubs.java#L89: This block of commented-out lines of code should be removed. rule
  6. MAJOR FrontendStubs.java#L148: Exceptional return value of java.io.File.createNewFile() ignored in com.vaadin.flow.testutil.FrontendStubs.createStubWebpackServer(String, int, String, boolean) rule
  7. MINOR FrontendTools.java#L517: Remove the declaration of thrown exception 'java.lang.IllegalStateException' which is a runtime exception. rule
  8. MINOR FrontendUtils.java#L482: Remove this use of "closeQuietly"; it is deprecated. rule
  9. MINOR FrontendUtils.java#L536: Remove this use of "closeQuietly"; it is deprecated. rule
  10. MINOR TaskRunNpmInstall.java#L527: Remove the declaration of thrown exception 'java.lang.IllegalStateException' which is a runtime exception. rule

@denis-anisimov denis-anisimov merged commit ec02a2a into master Aug 9, 2021
@denis-anisimov denis-anisimov deleted the fix/whitespaces-user-home branch August 9, 2021 06:00
@vaadin-bot
Copy link
Collaborator

Hi @mshabarov and @denis-anisimov, when i performed cherry-pick to this commit to 2.7, i have encountered the following issue. Can you take a look and pick it manually?
Error Message:
Error: Command failed: git cherry-pick ec02a2a
error: could not apply ec02a2a... fix: Fail-fast if the path to npm cache contains whitespaces (#11517)
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add ' or 'git rm '
hint: and commit the result with 'git commit'

@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with platform 22.0.0.alpha2 and is also targeting the upcoming stable 22.0.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

npx pnpm fails on Windows if home directory contains space
3 participants