-
Notifications
You must be signed in to change notification settings - Fork 471
Reliably determine @rescript/runtime path #7637
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
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ef3039b
Move all rescript legacy js sources to rescript-legacy folder
cknitt 87a55c9
Remove unused rewatch.cmd
cknitt 58f2ef2
New module Runtime_package
cknitt 841a29e
bsc: add -runtime-path option
cknitt 5bcb28c
Rewatch determine runtime path via oxc_resolver and pass to bsc
cknitt 3160c0b
Add -runtime-path handling to bsc.js
cknitt 891e238
Perform installation test with new build system
cknitt 66a167a
Also resolve rescript legacy via oxc_resolver
cknitt 2670fe1
Use ESM way to determine runtime path
cknitt 10ece02
Set -runtime-path in legacy build (bsb), too
cknitt 714223d
Also test legacy build in installation test
cknitt be31ab7
Log warning if runtime path couldn't be determined
cknitt 290f40c
Fix legacy clean
cknitt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// @ts-check | ||
import { fileURLToPath } from "node:url"; | ||
import * as path from "node:path"; | ||
|
||
const runtimePackageJsonUrl = await import.meta.resolve( | ||
"@rescript/runtime/package.json", | ||
); | ||
const runtimePackageJsonPath = fileURLToPath(runtimePackageJsonUrl); | ||
|
||
export const runtimePath = path.dirname(runtimePackageJsonPath); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,5 +25,3 @@ | |
val version : string | ||
|
||
val header : string | ||
|
||
val package_name : string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,3 @@ | ||
(* This resolves the location of the standard library starting from the location of bsc.exe | ||
(@rescript/{platform}/bin/bsc.exe), handling different supported package layouts. *) | ||
let runtime_module_path = | ||
let build_path rest path = | ||
String.concat Filename.dir_sep (List.rev_append rest path) | ||
in | ||
match | ||
Sys.executable_name |> Filename.dirname | ||
|> String.split_on_char Filename.dir_sep.[0] | ||
|> List.rev | ||
with | ||
(* 1. Packages installed via pnpm | ||
- bin: node_modules/.pnpm/@[email protected]/node_modules/@rescript/darwin-arm64/bin | ||
- runtime: node_modules/.pnpm/node_modules/@rescript/runtime (symlink) | ||
*) | ||
| "bin" :: _platform :: "@rescript" :: "node_modules" :: _package :: ".pnpm" | ||
:: "node_modules" :: rest -> | ||
build_path rest | ||
["node_modules"; ".pnpm"; "node_modules"; "@rescript"; "runtime"] | ||
(* 2. Packages installed via npm | ||
- bin: node_modules/@rescript/{platform}/bin | ||
- runtime: node_modules/@rescript/runtime | ||
*) | ||
| "bin" :: _platform :: "@rescript" :: "node_modules" :: rest -> | ||
build_path rest ["node_modules"; "@rescript"; "runtime"] | ||
(* 3. Several other cases that can occur in local development, e.g. | ||
- bin: <repo>/packages/@rescript/{platform}/bin, <repo>/_build/install/default/bin | ||
- runtime: <repo>/packages/@rescript/runtime | ||
*) | ||
| _ :: _ :: _ :: _ :: rest -> | ||
build_path rest ["packages"; "@rescript"; "runtime"] | ||
| _ -> "" | ||
|
||
let standard_library = | ||
let ( // ) = Filename.concat in | ||
runtime_module_path // "lib" // "ocaml" | ||
|
||
let cmi_magic_number = "Caml1999I022" | ||
|
||
and ast_impl_magic_number = "Caml1999M022" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
let name = "@rescript/runtime" | ||
|
||
(* Simple default approach to find the runtime package path. This will not work with all package managers/layouts. *) | ||
let default_path = | ||
let build_path rest path = | ||
String.concat Filename.dir_sep (List.rev_append rest path) | ||
in | ||
match | ||
Sys.executable_name |> Filename.dirname | ||
|> String.split_on_char Filename.dir_sep.[0] | ||
|> List.rev | ||
with | ||
(* 1. Packages installed via npm | ||
- bin: node_modules/@rescript/{platform}/bin | ||
- runtime: node_modules/@rescript/runtime | ||
*) | ||
| "bin" :: _platform :: "@rescript" :: "node_modules" :: rest -> | ||
build_path rest ["node_modules"; "@rescript"; "runtime"] | ||
(* 2. Several other cases that can occur in local development, e.g. | ||
- bin: <repo>/packages/@rescript/{platform}/bin, <repo>/_build/install/default/bin | ||
- runtime: <repo>/packages/@rescript/runtime | ||
*) | ||
| _ :: _ :: _ :: _ :: rest -> | ||
build_path rest ["packages"; "@rescript"; "runtime"] | ||
| _ -> "" | ||
|
||
(* To support pnpm and other package managers/layouts, we determine the path on the JS side and pass it in | ||
via -runtime-path to override the default. *) | ||
let path = ref default_path |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
val name : string | ||
|
||
val path : string ref |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So this happens when we run
bunx bsc
directly. It makes me wonder if we could just reuse this and pass it to Rewatch via an environment variable.I'm not against
oxc_resolver
per se, but doesn't this create two different mechanisms for resolving the-runtime-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.
Passing the runtime path to rewatch via an env var or command line flag was my original intention, but then I thought it was better if rewatch can remain self-contained here so that you can just invoke the binary directly and it does the resolution itself.
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.
Well, my experience with calling rewatch directly is that I need to set
RESCRIPT_BSC_EXE
, so it seems a bit weird that we do this for the runtime but not the compiler.