Skip to content

Commit

Permalink
melstd: rename Melstd.Path to Paths (#1261)
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro authored Dec 21, 2024
1 parent b1f1182 commit 6fd7c64
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 43 deletions.
2 changes: 1 addition & 1 deletion bin/melc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let print_backtrace () =
let set_abs_input_name sourcefile =
let sourcefile =
if !Clflags.absname && Filename.is_relative sourcefile then
Path.absolute_cwd_path sourcefile
Paths.absolute_cwd_path sourcefile
else sourcefile in
Location.set_input_name sourcefile;
sourcefile
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/include_dirs.dev.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ open Import

let paths =
let jscomp = "jscomp" in
Path.
Paths.
[
(* [melange] / [Stdlib] *)
jscomp // "stdlib" // ".stdlib.objs";
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/include_dirs.release.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ open Import

let paths =
let lib = "lib" and package_name = "melange" in
Path.
Paths.
[
(* [melange] / [Stdlib] *)
lib // package_name;
Expand Down
6 changes: 3 additions & 3 deletions jscomp/core/js_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
open Import

let executable_name =
lazy (Unix.realpath (Path.normalize_absolute_path Sys.executable_name))
lazy (Unix.realpath (Paths.normalize_absolute_path Sys.executable_name))

let stdlib_paths =
let ( // ) = Path.( // ) in
let ( // ) = Paths.( // ) in
let package_name = "melange" in
lazy
(match Sys.getenv "MELANGELIB" with
| value -> (
let dirs =
String.split_on_char ~sep:Path.path_sep value
String.split_on_char ~sep:Paths.path_sep value
|> List.filter_map ~f:(function
| "" -> None
| dir ->
Expand Down
18 changes: 9 additions & 9 deletions jscomp/core/js_name_of_module_id.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

open Import

let ( // ) = Path.( // )
let ( // ) = Paths.( // )

let fix_path_for_windows : string -> string =
let replace_backward_slash (x : string) =
Expand Down Expand Up @@ -73,10 +73,10 @@ let get_runtime_module_path ~package_info ~output_info
(* // Module_system.runtime_dir module_system *)
in
(* TODO(anmonteiro): This doesn't work yet *)
Path.rel_normalized_absolute_path
Paths.rel_normalized_absolute_path
~from:
(Js_packages_info.get_output_dir
package_info (* ~package_dir:(Lazy.force Path.package_dir) *)
package_info (* ~package_dir:(Lazy.force Paths.package_dir) *)
~package_dir:(Sys.getcwd ()) module_system)
(* Invariant: the package path to `node_modules/melange`, it is used to
calculate relative js path *)
Expand Down Expand Up @@ -131,18 +131,18 @@ let string_of_module_id ~package_info ~output_info
| true ->
(* If this is the same package, we know all imports are
relative. *)
Path.node_rebase_file ~from:cur_pkg.rel_path
Paths.node_rebase_file ~from:cur_pkg.rel_path
~to_:dep_info.rel_path js_file
| false -> (
match module_system with
| CommonJS | ESM -> dep_info.pkg_rel_path // js_file
(* Note we did a post-processing when working on Windows *)
| ESM_global ->
Path.rel_normalized_absolute_path
Paths.rel_normalized_absolute_path
~from:
(Js_packages_info.get_output_dir
package_info
(* ~package_dir:(Lazy.force Path.package_dir) *)
(* ~package_dir:(Lazy.force Paths.package_dir) *)
(* FIXME *)
~package_dir:(Sys.getcwd ()) module_system)
(* FIXME: https://github.com/melange-re/melange/issues/559 *)
Expand All @@ -157,9 +157,9 @@ let string_of_module_id ~package_info ~output_info
| file ->
let basename = Filename.basename file in
let dirname = Filename.dirname file in
Path.node_rebase_file
~from:(Path.absolute_cwd_path output_dir)
~to_:(Path.absolute_cwd_path dirname)
Paths.node_rebase_file
~from:(Paths.absolute_cwd_path output_dir)
~to_:(Paths.absolute_cwd_path dirname)
basename
| exception Not_found -> Mel_exception.error (Js_not_found js_file))
))
14 changes: 9 additions & 5 deletions jscomp/core/js_packages_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

open Import

let ( // ) = Path.( // )
let ( // ) = Paths.( // )

type file_case = Uppercase | Lowercase
type output_info = { module_system : Module_system.t; suffix : Js_suffix.t }
Expand Down Expand Up @@ -207,16 +207,20 @@ let add_npm_package_path (t : t) ?module_name s =
let is_lower_case c =
(c >= 'a' && c <= 'z')
|| c
>= (* à *)
>=
(* à *)
'\224'
&& c
<= (* ö *)
<=
(* ö *)
'\246'
|| c
>= (* ø *)
>=
(* ø *)
'\248'
&& c
<= (* ÿ *)
<=
(* ÿ *)
'\255'

let module_case t ~output_prefix =
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_compile_main.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ let write_to_file ~package_info ~output_info ~output_prefix lambda_output file
oc)

let lambda_as_module =
let (//) = Path.(//) in
let (//) = Paths.(//) in
fun ~package_info (lambda_output : J.deps_program) (output_prefix : string) ->
let make_basename suffix =
(Filename.basename output_prefix) ^ (Js_suffix.to_string suffix)
Expand Down
2 changes: 1 addition & 1 deletion jscomp/melstd/melstd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module Modulename = Modulename
module Module_system = Module_system
module Ordered_hash_map_local_ident = Ordered_hash_map_local_ident
module Polyvariant = Polyvariant
module Path = Path
module Paths = Paths
module Js_pp = Js_pp
module Scc = Scc
module String = String
Expand Down
2 changes: 1 addition & 1 deletion jscomp/melstd/module_system.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let compatible ~dep t =
(* As a dependency Leaf Node, it is the same either [global] or [not] *)

let runtime_package_path =
let ( // ) = Path.( // ) in
let ( // ) = Paths.( // ) in
let melange_js = "melange.js" in
fun js_file -> melange_js // js_file

Expand Down
File renamed without changes.
File renamed without changes.
43 changes: 23 additions & 20 deletions test/unit-tests/ounit_path_tests.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Melstd

let ( >:: ), ( >::: ) = OUnit.(( >:: ), ( >::: ))
let normalize = Path.normalize_absolute_path
let normalize = Paths.normalize_absolute_path

let os_adapt s =
let regexp = Str.regexp "\\(/\\)" in
Expand Down Expand Up @@ -51,18 +51,18 @@ let suites =
=~ os_adapt "/a/b/c" );
( __LOC__ >:: fun _ ->
let aux a b result =
Path.rel_normalized_absolute_path ~from:a b =~ result;
Paths.rel_normalized_absolute_path ~from:a b =~ result;

Path.rel_normalized_absolute_path
Paths.rel_normalized_absolute_path
~from:(String.sub a ~pos:0 ~len:(String.length a - 1))
b
=~ result;

Path.rel_normalized_absolute_path ~from:a
Paths.rel_normalized_absolute_path ~from:a
(String.sub b ~pos:0 ~len:(String.length b - 1))
=~ result;

Path.rel_normalized_absolute_path
Paths.rel_normalized_absolute_path
~from:(String.sub a ~pos:0 ~len:(String.length a - 1))
(String.sub b ~pos:0 ~len:(String.length b - 1))
=~ result
Expand All @@ -76,45 +76,48 @@ let suites =
(* This is still correct just not optimal depends
on user's perspective *)
( __LOC__ >:: fun _ ->
Path.rel_normalized_absolute_path ~from:"/a/b/c/d" "/x/y"
Paths.rel_normalized_absolute_path ~from:"/a/b/c/d" "/x/y"
=~ os_adapt "../../../../x/y";

Path.rel_normalized_absolute_path
Paths.rel_normalized_absolute_path
~from:"/a/b/c/d/e/./src/bindings/Navigation" "/a/b/c/d/e"
=~ os_adapt "../../..";

Path.rel_normalized_absolute_path ~from:"/a/b/c/./d" "/a/b/c" =~ "..";
Paths.rel_normalized_absolute_path ~from:"/a/b/c/./d" "/a/b/c"
=~ "..";

Path.rel_normalized_absolute_path ~from:"/a/b/c/./src" "/a/b/d/./src"
Paths.rel_normalized_absolute_path ~from:"/a/b/c/./src"
"/a/b/d/./src"
=~ os_adapt "../../d/src" );
(* used in module system: [es6-global] and [amdjs-global] *)
( __LOC__ >:: fun _ ->
Path.rel_normalized_absolute_path
Paths.rel_normalized_absolute_path
~from:"/usr/local/lib/node_modules/" "//"
=~ os_adapt "../../../..";
Path.rel_normalized_absolute_path
Paths.rel_normalized_absolute_path
~from:"/usr/local/lib/node_modules/" "/"
=~ os_adapt "../../../..";
Path.rel_normalized_absolute_path ~from:"./"
Paths.rel_normalized_absolute_path ~from:"./"
"./node_modules/xx/./xx.js"
=~ os_adapt "./node_modules/xx/xx.js";
Path.rel_normalized_absolute_path ~from:"././"
Paths.rel_normalized_absolute_path ~from:"././"
"./node_modules/xx/./xx.js"
=~ os_adapt "./node_modules/xx/xx.js" );
( __LOC__ >:: fun _ ->
Path.node_rebase_file ~to_:"lib/js/src/a" ~from:"lib/js/src" "b"
Paths.node_rebase_file ~to_:"lib/js/src/a" ~from:"lib/js/src" "b"
=~ "./a/b";
Path.node_rebase_file ~to_:"lib/js/src/" ~from:"lib/js/src" "b"
Paths.node_rebase_file ~to_:"lib/js/src/" ~from:"lib/js/src" "b"
=~ "./b";
Path.node_rebase_file ~to_:"lib/js/src" ~from:"lib/js/src/a" "b"
Paths.node_rebase_file ~to_:"lib/js/src" ~from:"lib/js/src/a" "b"
=~ "../b";
Path.node_rebase_file ~to_:"lib/js/src/a" ~from:"lib/js/" "b"
Paths.node_rebase_file ~to_:"lib/js/src/a" ~from:"lib/js/" "b"
=~ "./src/a/b";
Path.node_rebase_file ~to_:"lib/js/./src/a" ~from:"lib/js/src/a/" "b"
Paths.node_rebase_file ~to_:"lib/js/./src/a" ~from:"lib/js/src/a/"
"b"
=~ "./b";

Path.node_rebase_file ~to_:"lib/js/src/a" ~from:"lib/js/src/a/" "b"
Paths.node_rebase_file ~to_:"lib/js/src/a" ~from:"lib/js/src/a/" "b"
=~ "./b";
Path.node_rebase_file ~to_:"lib/js/src/a/" ~from:"lib/js/src/a/" "b"
Paths.node_rebase_file ~to_:"lib/js/src/a/" ~from:"lib/js/src/a/" "b"
=~ "./b" );
]

0 comments on commit 6fd7c64

Please sign in to comment.