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

ReScript cli clean up + watcher fix #6404

Merged
merged 4 commits into from
Sep 27, 2023

Conversation

DZakh
Copy link
Contributor

@DZakh DZakh commented Sep 14, 2023

Fixed dependencies reinitialization on every save in watch mode.

Before:
Screenshot 2023-09-15 at 03 27 26
After:
Screenshot 2023-09-15 at 03 29 13

Also:

  • Actualized help for commands
  • Started showing the compile time for rescript build command without watch mode
  • Pass through the -verbose flag to builds in watch mode

What I want to do next:

  • Fix the build needed condition.
  • Resolve the problems with duplicated builds (existed before the changes)
  • Enable watch mode for pinned dependencies 🤔
  • Update documentation

@@ -26,7 +26,7 @@ let () = Bsb_log.setup ()

let separator = "--"

let watch_mode = ref false
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've separated the watch mode from other delegated commands to handle it separately. So now we have better control over it, and the ref is unnecessary.

Before:

  • Trigger build and exit with 1
  • Start watching changes
  • Trigger build

After:

  • Trigger build
  • Start watching changes

@@ -26,7 +26,7 @@ let () = Bsb_log.setup ()

let separator = "--"

let watch_mode = ref false
let no_deps_mode = ref false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first build should be done with dependencies. Builds on change should be without dependencies.

@@ -84,13 +84,13 @@ let ninja_command_exit (type t) (ninja_args : string array) : t =
ninja -C _build
*)
let clean_usage =
"Usage: rescript.exe clean <options>\n\n\
`rescript clean` only cleans the current project\n"
"Usage: rescript clean <options>\n\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.

Removed exe and updated the description. It's more relevant now, since the -with-deps is deprecated.

Comment on lines +117 to +121
("-w", unit_set_spec (ref false), "Watch mode");
( "-ws",
string_set_spec (ref ""),
"[host]:port set up host & port for WebSocket build notifications" );
("-verbose", call_spec Bsb_log.verbose, "Set the output to be verbose");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorted in the order:

  • Public
  • Deprecated
  • Internal

( "-regen",
unit_set_spec force_regenerate,
"*internal* \n\
Always regenerate build.ninja no matter bsconfig.json is changed or \
not" );
("-verbose", call_spec Bsb_log.verbose, "Set the output to be verbose");
("-no-deps", unit_set_spec no_deps_mode, "*internal* Needed for watcher to build without dependencies on file change");
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 don't see a usecase for it, so I've added the flag as internal

.listen(webSocketPort, webSocketHost);
}

function watchBuild(watchConfig) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function is not touched. Only the watchGenerated definition moved to a higher scope.

Comment on lines +361 to +369
return !(
fileName === ".merlin" ||
fileName.endsWith(".js") ||
fileName.endsWith(".mjs") ||
fileName.endsWith(".cjs") ||
fileName.endsWith(genTypeFileExtension) ||
watchGenerated.indexOf(fileName) >= 0 ||
fileName.endsWith(".swp")
);
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 a big question about the logic. Why not check only .res,.resi,.ml,.mli changes?
Also, since the whole condition is negated the watchGenerated.indexOf(fileName) >= 0 doesn't trigger rebuild on generated file change 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For example, if ReScript is used in a codebase mixed with ts. It'll recompile on every ts file change

Copy link
Member

Choose a reason for hiding this comment

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

Good question. Maybe @bobzhang can comment?

Comment on lines -450 to -453
if (postBuild) {
dlog(`running postbuild command: ${postBuild}`);
child_process.exec(postBuild);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

logStartCompiling();
delegateCommand(delegatedArgs, () => {
startWatchMode(withWebSocket);
buildFinishedCallback(0);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line initializes file watchers.

Comment on lines +524 to +534
case "info":
case "clean": {
delegateCommand(process_argv.slice(2));
break;
}
case undefined:
case "build": {
logStartCompiling();
delegateCommand(process_argv.slice(2), logFinishCompiling);
break;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This way, we can separate the watcher-specific code.

@DZakh
Copy link
Contributor Author

DZakh commented Sep 19, 2023

The PR is ready for review

@cristianoc
Copy link
Collaborator

@cknitt up for a review?

@cknitt
Copy link
Member

cknitt commented Sep 19, 2023

Great work @DZakh! I'll test it tomorrow against our current project.

"Usage: rescript.exe clean <options>\n\n\
`rescript clean` only cleans the current project\n"
"Usage: rescript clean <options>\n\n\
`rescript clean` cleans build artifacts. It is useful for edge-case reasons in case you get into a stale build\n"
Copy link
Member

Choose a reason for hiding this comment

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

Not sure about the wording here or if we should mention edge cases/stale builds at all.

Maybe just

Suggested change
`rescript clean` cleans build artifacts. It is useful for edge-case reasons in case you get into a stale build\n"
`rescript clean` cleans build artifacts\n"

?

What do you think @cristianoc?

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 cleaner

Copy link
Member

Choose a reason for hiding this comment

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

Ok, then could you accept my change suggestion @DZakh?

@cknitt
Copy link
Member

cknitt commented Sep 20, 2023

Great work @DZakh! I'll test it tomorrow against our current project.

Ok, our current project is a monorepo project with its own watcher, so I wasn't able to test the watch mode changes against it.

I tested briefly against an example project and everything seemed fine though.

@DZakh
Copy link
Contributor Author

DZakh commented Sep 20, 2023

Done 👌

CHANGELOG.md Outdated Show resolved Hide resolved
@DZakh
Copy link
Contributor Author

DZakh commented Sep 21, 2023

I think it's ready to be merged

@zth
Copy link
Collaborator

zth commented Sep 26, 2023

@DZakh seems we missed our window and there's now a few conflicts. Care fixing and we can merge after?

@DZakh
Copy link
Contributor Author

DZakh commented Sep 27, 2023

Done

@zth zth merged commit 7e2e81f into rescript-lang:master Sep 27, 2023
7 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.

None yet

4 participants