-
Notifications
You must be signed in to change notification settings - Fork 455
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
Handle absolute paths in typegen #7104
Conversation
Would you do make test
make test-gentype The last command should produce no difference in the output. |
@cristianoc Yes, will do. Tests are failing locally. I will keep working on it. |
@cristianoc I added the resolved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments
compiler/gentype/GenTypeConfig.ml
Outdated
@@ -105,6 +105,26 @@ let set_debug ~gtconf = | |||
let compiler_config_file = "rescript.json" | |||
let legacy_compiler_config_file = "bsconfig.json" | |||
|
|||
let default_config ~project_root ~bsb_project_root = | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ default with project_root; bsb_project_root }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it into a local function instead. with the syntactic improvement.
9f29767
to
10a5d70
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's pretty much ready to go, modulo a couple of comments.
And, some testing with rewatch: @mununki
compiler/gentype/Paths.ml
Outdated
@@ -29,17 +29,43 @@ let find_name_space cmt = | |||
cmt |> Filename.basename |> (Filename.chop_extension [@doesNotRaise]) | |||
|> keep_after_dash | |||
|
|||
let get_output_file_relative ~config cmt = | |||
(cmt |> handle_namespace) ^ ModuleExtension.ts_input_file_suffix ~config | |||
let remove_project_root_from_absolute_path ~(config : Config.t) source_path = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the bit that I haven't really reviewed properly yet.
Might not be a robust way to get a relative path. Especially Windows vs linux etc.
Can't remember if the code already does this somewhere else.
Or, poking around in the Filename module, there's more one can use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored the function to use Filename.concat
for appending the directory separator when missing. Additionally, it now verifies if the prefix exists and returns the original path if not. I also renamed the function for better clarity.
This may not be related to this PR, but the genType output for v12 still differs from v11 in this way. // Title.res
@genType @react.component
let make = (~text) => {
<div className="title"> {text->React.string} </div>
} v11 /* TypeScript file generated from Title.res by genType. */
/* eslint-disable */
/* tslint:disable */
import * as TitleJS from './Title.mjs';
export type props<text> = { readonly text: text };
export const make: React.ComponentType<{ readonly text: string }> = TitleJS.make as any; v12 /* TypeScript file generated from Title.res by genType. */
/* eslint-disable */
/* tslint:disable */
import * as TitleJS from './Title.mjs';
import type {element as Jsx_element} from './Jsx.gen.tsx'; // Error: module not found
export type props<text> = { readonly text: text };
export const make: (_1:props<string>) => Jsx_element = TitleJS.make as any; |
would you open an issue for this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ready to go -- would you update the CHAGELOG?
Also, has it been tested on some rewatch project?
CI seems to fail still. |
Yes looks like there's a little annotation missing after refactoring to please the static exception checker. |
Nice 🥳 I could swear that the static checker previously ran without having to explicitly |
I only tested the initial version of this PR while I had it based on the v11 branch. |
@Bushuo this will need backporting to v11 anyway so if you want you could do a PR on top of this that just backports this to v11 and try it that way. |
@zth Sure, I can do it. I haven't backported before, though, so if you could give me a quick rundown of the ideal process, that'd be great. I might not get to it today though. |
Sure! It's really simple, and basically what you did before - just base a separate PR of this work off of So, after that, you'll have 2 PRs:
Clear? |
@cristianoc @zth On the v11 branch, the function returns The config file is at the root level. "sources": {
"dir": "jscomp/test/"
} In contrast, configuring a similar test in v12 still returns an absolute path. |
@zth why do we need v11 support? |
Because it's likely a large portion of users will remain on v11 for a good while. Backporting this will mean that those can move to rewatch if they're using gentype as well before it ships in the compiler itself only. |
9759b80
to
5780c0a
Compare
5780c0a
to
5bb3db9
Compare
I made some changes and now it also seems to work on v11. Could you please take a look again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
@Bushuo great work! ⭐ |
* refactor: extract fun from process_cmt_file * refactor: read the .cmt earlier * feat: handle paths via source_file instead of cmt_file * add project root to default config * refactor: extract funs to remove duplication * fix: consider file seperators * fix: please static checker * make find source file return only absolute paths * refactor: cleanup getOutputFile and getOutputFileRelative * chore: update changelog
Like discussed in rescript-lang/rewatch#102 this PR enables gentype to handle passing of absolute file paths.
Instead of manipulating the path to the
.cmt
file it gets the source file path from the.cmt
file first.Then constructs the output file paths from there.