Skip to content

@rescript/runtime package #7483

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

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,21 @@ jobs:

- name: Build runtime/stdlib with rewatch
if: ${{ runner.os != 'Windows' }}
run: ./scripts/buildRuntimeRewatch.sh
run: |
yarn workspace @rescript/runtime clean:rewatch
yarn workspace @rescript/runtime build:rewatch
shell: bash

- name: Build runtime/stdlib with bsb (Windows)
if: ${{ runner.os == 'Windows' }}
run: ./scripts/buildRuntime.sh
run: |
yarn workspace @rescript/runtime clean:bsb
yarn workspace @rescript/runtime build:bsb
shell: bash

- name: Check for changes in lib folder
run: git diff --exit-code lib/js lib/es6
working-directory: packages/@rescript/runtime

- name: Version Check
run: yarn constraints
Expand Down
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ reanalyze:
reanalyze.exe -set-exit-code -all-cmt _build/default/compiler _build/default/tests -exclude-paths compiler/outcome_printer,compiler/ml,compiler/frontend,compiler/ext,compiler/depends,compiler/core,compiler/common,compiler/cmij,compiler/bsb_helper,compiler/bsb

lib-bsb:
./scripts/buildRuntime.sh
yarn workspace @rescript/runtime build:bsb

lib:
./scripts/buildRuntimeRewatch.sh
yarn workspace @rescript/runtime build:rewatch

artifacts: lib
./scripts/npmPack.js --updateArtifactList
Expand Down Expand Up @@ -93,8 +93,13 @@ clean-gentype:
clean-rewatch:
cargo clean --manifest-path rewatch/Cargo.toml && rm -f rewatch/rewatch

clean:
(cd runtime && ../cli/rescript.js clean)
clean-lib:
yarn workspace @rescript/runtime clean:rewatch

clean-lib-bsb:
yarn workspace @rescript/runtime clean:bsb

clean: clean-lib
dune clean

clean-all: clean clean-gentype clean-rewatch
Expand Down
28 changes: 13 additions & 15 deletions analysis/src/BuildSystem.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@ let namespacedName namespace name =

let ( /+ ) = Filename.concat

let getBsPlatformDir rootPath =
match !Cfg.isDocGenFromCompiler with
| false -> (
let result =
ModuleResolution.resolveNodeModulePath ~startPath:rootPath "rescript"
in
match result with
| Some path -> Some path
| None ->
let message = "rescript could not be found" in
Log.log message;
None)
| true -> Some rootPath
let getRuntimeDir rootPath =
let result =
ModuleResolution.resolveNodeModulePath ~startPath:rootPath
"@rescript/runtime"
in
match result with
| Some path -> Some path
| None ->
let message = "@rescript/runtime could not be found" in
Log.log message;
None

let getLibBs root = Files.ifExists (root /+ "lib" /+ "bs")

let getStdlib base =
match getBsPlatformDir base with
match getRuntimeDir base with
| None -> None
| Some bsPlatformDir -> Some (bsPlatformDir /+ "lib" /+ "ocaml")
| Some runtimeDir -> Some (runtimeDir /+ "lib" /+ "ocaml")
18 changes: 14 additions & 4 deletions analysis/src/Files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,26 @@ let rec collectDirs path =
|> List.concat)
| _ -> []

let rec collect ?(checkDir = fun _ -> true) path test =
match maybeStat path with
| None -> []
| Some {Unix.st_kind = Unix.S_DIR} ->
let rec collect ?(checkDir = fun _ -> true) ?maxDepth path test =
match (maxDepth, maybeStat path) with
| None, None -> []
| Some 0, _ -> []
| None, Some {Unix.st_kind = Unix.S_DIR} ->
if checkDir path then
readDirectory path
|> List.map (fun name ->
collect ~checkDir (Filename.concat path name) test)
|> List.concat
else []
| Some n, Some {Unix.st_kind = Unix.S_DIR} ->
if checkDir path then
readDirectory path
|> List.map (fun name ->
collect ~checkDir ~maxDepth:(n - 1)
Copy link
Member Author

Choose a reason for hiding this comment

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

This needs to be made a bit more stable.

If users use a monorepo, they may still need to look upward to find the runtime package.

(Filename.concat path name)
test)
|> List.concat
else []
| _ -> if test path then [path] else []

type classifiedFile = Res | Resi | Other
Expand Down
2 changes: 1 addition & 1 deletion analysis/src/FindFiles.ml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ let findProjectFiles ~public ~namespace ~path ~sourceDirectories ~libBs =
in
let files =
dirs |> StringSet.elements
|> List.map (fun name -> Files.collect name isSourceFile)
|> List.map (fun name -> Files.collect ~maxDepth:1 name isSourceFile)
|> List.concat |> StringSet.of_list
in
dirs
Expand Down
7 changes: 7 additions & 0 deletions analysis/src/ModuleResolution.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
let ( /+ ) = Filename.concat

let rec resolveNodeModulePath ~startPath name =
let scope = Filename.dirname name in
let name = Filename.basename name in
let name =
match scope.[0] with
| '@' -> scope /+ name
| _ -> name
in
let path = startPath /+ "node_modules" /+ name in
if Files.exists path then Some path
else if Filename.dirname startPath = startPath then None
Expand Down
2 changes: 1 addition & 1 deletion cli/common/bsb.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import * as fs from "node:fs";
import { createServer } from "node:http";
import * as os from "node:os";
import * as path from "node:path";
import { WebSocket } from "#lib/minisocket";

import { rescript_exe } from "./bins.js";
import { WebSocket } from "./minisocket.js";

const cwd = process.cwd();
const lockFileName = path.join(cwd, ".bsb.lock");
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions cli/rescript-editor-analysis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env node

// @ts-check

import * as child_process from "node:child_process";

import { rescript_editor_analysis_exe } from "./common/bins.js";

const args = process.argv.slice(2);

child_process.spawnSync(rescript_editor_analysis_exe, args, {
stdio: "inherit",
});
9 changes: 0 additions & 9 deletions compiler/bsc/rescript_compiler_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,6 @@ let define_variable s =
Bsc_args.bad_arg ("illegal definition: " ^ s)
| _ -> Bsc_args.bad_arg ("illegal definition: " ^ s)

let print_standard_library () =
let standard_library = Config.standard_library in
print_string standard_library;
print_newline ();
exit 0

let bs_version_string = "ReScript " ^ Bs_version.version

let print_version_string () =
Expand Down Expand Up @@ -366,9 +360,6 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
( "-ignore-parse-errors",
set Clflags.ignore_parse_errors,
"*internal* continue after parse errors" );
( "-where",
unit_call print_standard_library,
"*internal* Print location of standard library and exit" );
( "-verbose",
set Clflags.verbose,
"*internal* Print calls to external commands" );
Expand Down
2 changes: 1 addition & 1 deletion compiler/common/bs_version.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
let version = "12.0.0-alpha.13"
let header = "// Generated by ReScript, PLEASE EDIT WITH CARE"
let package_name = ref "rescript"
let package_name = ref "@rescript/runtime"
39 changes: 5 additions & 34 deletions compiler/ext/config.ml
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
let version = "4.06.1+BS"

(* FIXME: Unreliable resolution *)
let standard_library =
let ( // ) = Filename.concat in
(* @rescript/{platform}/bin/rescript.exe *)
let exe_path = Sys.executable_name in
if Ext_string.contain_substring exe_path ("node_modules" // "@rescript") then
(* node_modules/@rescript/{platform}/bin *)
Filename.dirname exe_path // Filename.parent_dir_name
// Filename.parent_dir_name // Filename.parent_dir_name // "rescript"
// "lib" // "ocaml"
else if Ext_string.contain_substring exe_path ("node_modules" // "rescript")
then
(* node_modules/rescript/{platform} *)
Filename.dirname exe_path // Filename.parent_dir_name // "lib" // "ocaml"
else
(* git repo: rescript/packages/@rescript/{platform}/bin *)
Filename.dirname exe_path // Filename.parent_dir_name
// Filename.parent_dir_name // Filename.parent_dir_name
// Filename.parent_dir_name // "lib" // "ocaml"

let standard_library_default = standard_library
let bin_dir = Filename.dirname exe_path in
let platform_dir = Filename.dirname bin_dir in
let rescript_dir = Filename.dirname platform_dir in
rescript_dir // "runtime" // "lib" // "ocaml"

let unsafe_empty_array = ref false

Expand All @@ -32,20 +20,3 @@ and ast_intf_magic_number = "Caml1999N022"
and cmt_magic_number = "Caml1999T022"

let load_path = ref ([] : string list)

(* This is normally the same as in obj.ml, but we have to define it
separately because it can differ when we're in the middle of a
bootstrapping phase. *)

let print_config oc =
let p name valu = Printf.fprintf oc "%s: %s\n" name valu in
p "version" version;
p "standard_library_default" standard_library_default;
p "standard_library" standard_library;

(* print the magic number *)
p "cmi_magic_number" cmi_magic_number;
p "ast_impl_magic_number" ast_impl_magic_number;
p "ast_intf_magic_number" ast_intf_magic_number;
p "cmt_magic_number" cmt_magic_number;
flush oc
2 changes: 0 additions & 2 deletions compiler/ext/config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,3 @@ val ast_impl_magic_number : string
(* Magic number for file holding an implementation syntax tree *)
val cmt_magic_number : string
(* Magic number for compiled interface files *)

val print_config : out_channel -> unit
1 change: 0 additions & 1 deletion lib/es6/package.json

This file was deleted.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"bsc": "cli/bsc.js",
"bstracing": "cli/bstracing.js",
"rescript": "cli/rescript.js",
"rescript-editor-analysis": "cli/rescript-editor-analysis.js",
"rescript-tools": "cli/rescript-tools.js",
"rewatch": "cli/rewatch.js"
},
Expand All @@ -61,7 +62,6 @@
"CREDITS.md",
"ninja.COPYING",
"docs/docson/build-schema.json",
"lib",
"cli"
],
"exports": {
Expand All @@ -71,8 +71,10 @@
},
"imports": {
"#cli/*": "./cli/common/*.js",
"#dev/*": "./lib_dev/*.js",
"#lib/minisocket": "./lib/minisocket.js"
"#dev/*": "./lib_dev/*.js"
},
"dependencies": {
"@rescript/runtime": "workspace:packages/@rescript/runtime"
},
"optionalDependencies": {
"@rescript/darwin-arm64": "workspace:packages/@rescript/darwin-arm64",
Expand Down
3 changes: 3 additions & 0 deletions packages/@rescript/runtime/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lib/bs
lib/ocaml
*.lock
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ let rec getUndefined = (n, x: key) =>

let rec getExn = (n, x: key) =>
switch n {
| None => raise(Not_found)
| None => throw(Not_found)
| Some(n) =>
let v = n.N.key
if x == v {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ let rec getUndefined = (n: t, x: value) =>

let rec getExn = (n: t, x: value) =>
switch n {
| None => raise(Not_found)
| None => throw(Not_found)
| Some(t) =>
let v = t.value
if x == v {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,24 @@ let findFirstByU: (t<'v>, (key, 'v) => bool) => option<(key, 'v)>
`findFirstBy(m, p)` uses funcion `f` to find the first key value pair
to match predicate `p`.

## Examples

```rescript
let s0 = fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2,"(3, ""))])
findFirstBy(s0, (k, v) => k == 4) == option((4, "4"))
#ifdef TYPE_STRING
let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")])

mapString->
Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one")
->assertEqual(Some("1", "one"))
#elif defined TYPE_INT
let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")])

mapInt->
Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one")
->assertEqual(Some(1, "one"))
#else
[%error "unknown type"]
#endif
```
*/
let findFirstBy: (t<'v>, (key, 'v) => bool) => option<(key, 'v)>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading