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 compile status with help command #6439

Merged
merged 7 commits into from
Oct 30, 2023

Conversation

DZakh
Copy link
Contributor

@DZakh DZakh commented Oct 13, 2023

Fixes: #6435 (comment) (only the comment)

jscomp/build_tests/cli_help/input.js Outdated Show resolved Hide resolved
jscomp/build_tests/cli_help/input.js Outdated Show resolved Hide resolved
jscomp/build_tests/cli_help/input.js Outdated Show resolved Hide resolved
jscomp/build_tests/cli_help/input.js Outdated Show resolved Hide resolved
jscomp/build_tests/cli_help/input.js Outdated Show resolved Hide resolved
Comment on lines +515 to +523
const isDefinitelyBuild =
maybeSubcommand === undefined ||
(maybeSubcommand === "build" && process_argv.length === 3);

if (isDefinitelyBuild) {
logStartCompiling();
delegateCommand(process_argv.slice(2), logFinishCompiling);
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A little bit hacky, but I think better, than nothing. Ideally, to move all the args parsing logic on the js side in one place.

Copy link
Member

Choose a reason for hiding this comment

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

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 was actually thinking of using minimist, but https://github.com/pkgjs/parseargs also looks good.

Copy link
Member

Choose a reason for hiding this comment

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

If we are more tolerant of external dependencies we can even import more, like clipanion 😂

@DZakh DZakh changed the title Fx compile status with help command Fix compile status with help command Oct 17, 2023
@zth
Copy link
Collaborator

zth commented Oct 21, 2023

@cknitt you've been reviewing changes here before, up for reviewing this too?

Copy link
Member

@cknitt cknitt left a comment

Choose a reason for hiding this comment

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

Thanks for adding those tests, this is great! 👍

jscomp/build_tests/cli_help/input.js Outdated Show resolved Hide resolved
jscomp/build_tests/cli_help/input.js Outdated Show resolved Hide resolved
jscomp/build_tests/cli_help/input.js Outdated Show resolved Hide resolved
rescript Outdated Show resolved Hide resolved
@DZakh
Copy link
Contributor Author

DZakh commented Oct 23, 2023

Thanks for feedback, I'll return back with the improvements

@DZakh
Copy link
Contributor Author

DZakh commented Oct 26, 2023

Should we use status 1 or 2 for the unknown arg error?

@DZakh DZakh force-pushed the fix-compile-status-in-help branch from b8b680c to 514b317 Compare October 26, 2023 14:46
@DZakh
Copy link
Contributor Author

DZakh commented Oct 26, 2023

@cknitt It's ready for re review

Comment on lines -89 to -95
b +> "unknown option: '";
b +> "Unknown option \"";
b +> s;
b +> "'.\n"
b +> "\".\n"
| Missing s ->
b +> "option '";
b +> "Option \"";
b +> s;
b +> "' needs an argument.\n");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, the code is not used in my case. I've just decided to make it consistent with bsb_arg.ml.

break;
case "-h":
case "-help":
case "--help":
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added --help here

Comment on lines +560 to +561
case "--version":
case "version":
Copy link
Contributor Author

@DZakh DZakh Oct 26, 2023

Choose a reason for hiding this comment

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

Added --version and version here

Comment on lines +565 to +567
console.error(
`Error: Unknown command or flag "${maybeSubcommand}".\n${helpMessage}`
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now everything will come to stderr. Before helpMessage was shown in stdout while Unknown command or flag in stdout. That's also the reason why I have both stdout and stderr check in the tests.

Comment on lines +84 to +99
// FIXME: Help works incorrectly in watch mode
out = child_process.spawnSync(`../../../rescript`, ["build", "-w", "--help"], {
encoding: "utf8",
cwd: __dirname,
});
// FIXME: Shouldn't have "Start compiling" for help
assert.equal(out.stdout, ">>>> Start compiling\n" + buildHelp);
// FIXME: Don't run the watcher when showing help
assert.match(
out.stderr,
new RegExp(
"Uncaught Exception Error: ENOENT: no such file or directory, watch 'bsconfig.json'\n"
)
);
// FIXME: Should be 0
assert.equal(out.status, 1);
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'll be only possible to fix by moving the args parsing logic in one place. I want to do it when I have more free time.

Copy link
Member

Choose a reason for hiding this comment

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

What about the other three FIXMEs above? Also something for later?

Copy link
Contributor Author

@DZakh DZakh Oct 27, 2023

Choose a reason for hiding this comment

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

Yeah, they are all caused by one problem

@DZakh DZakh requested a review from cknitt October 26, 2023 14:55
"\n" +
"`rescript build` builds the project with dependencies\n" +
"\n" +
"`rescript -- -h` for Ninja options (internal usage only; unstable)\n" +
Copy link
Member

Choose a reason for hiding this comment

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

Should be rescript build -- -h.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to have tests 😁 Fixed 👌

Comment on lines +84 to +99
// FIXME: Help works incorrectly in watch mode
out = child_process.spawnSync(`../../../rescript`, ["build", "-w", "--help"], {
encoding: "utf8",
cwd: __dirname,
});
// FIXME: Shouldn't have "Start compiling" for help
assert.equal(out.stdout, ">>>> Start compiling\n" + buildHelp);
// FIXME: Don't run the watcher when showing help
assert.match(
out.stderr,
new RegExp(
"Uncaught Exception Error: ENOENT: no such file or directory, watch 'bsconfig.json'\n"
)
);
// FIXME: Should be 0
assert.equal(out.status, 1);
Copy link
Member

Choose a reason for hiding this comment

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

What about the other three FIXMEs above? Also something for later?

@cknitt
Copy link
Member

cknitt commented Oct 28, 2023

@DZakh Just wanted to merge this for rc.5, but there are conflicts, could you resolve them?

@DZakh
Copy link
Contributor Author

DZakh commented Oct 28, 2023

I'll fix on Monday

@DZakh DZakh force-pushed the fix-compile-status-in-help branch from ab20cdb to f1d4059 Compare October 30, 2023 13:10
@cknitt cknitt merged commit 5b2c5bd into rescript-lang:master Oct 30, 2023
14 checks passed
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.

Watch mode is not working in 11.0.0-rc.4
4 participants