Skip to content

Commit

Permalink
Abstracts package API like dune (#47)
Browse files Browse the repository at this point in the history
* Abstracts package API like dune

* Windows: unnecessary Sys.path_sep

* Look for entrypoint in Index.re first
  • Loading branch information
ManasJayanth authored Sep 20, 2019
1 parent bb6658c commit ffd36e6
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Util.Util.foo();
Util.foo();
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Util.Util.foo();
Util.foo();
/* Bar.bar() from util.foo.bar is not available here */
print_endline("Add Your Test Cases Here");
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Library.Util.foo();
Bar.Bar.bar();
Bar.bar();
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Library.Util.foo();
Bar.Bar.bar();
Bar.bar();
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Library.Util.foo();
Bar.Bar.bar();
Bar.bar();
81 changes: 74 additions & 7 deletions lib/PesyConf.re
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ let resolveRelativePath = path => {
};
};

String.concat(separator, resolve(revParts, 0, []));
let dirSepChar = Filename.dir_sep.[0];
(path.[0] == dirSepChar ? Filename.dir_sep : "")
++ String.concat(separator, resolve(revParts, 0, []));
};

/* let%expect_test _ = { */
Expand Down Expand Up @@ -398,12 +400,77 @@ let toPesyConf = (projectPath: string, json: JSON.t): t => {
};

PesyModule.Alias.create(
~alias=
sprintf(
"module %s = %s;",
importedNamespace,
exportedNamespace,
),
~alias={
switch (
List.fold_left(
(accExt, ext) =>
List.fold_left(
(accEntry, entry) => {
switch (accEntry) {
| Some(x) => Some(x)
| None =>
if (findIndex(libraryAsPath, rootName) != 0) {
Some(
sprintf(
"module %s = %s;",
importedNamespace,
exportedNamespace,
),
);
} else {
let stripRootName =
Str.global_replace(
Str.regexp(rootName ++ "/"),
"",
);
let basePathToRequirePkg =
libraryAsPath
|> stripRootName
|> (x => Path.(projectPath / x))
|> resolveRelativePath;
if (Sys.file_exists(
Path.(basePathToRequirePkg / entry)
++ ext,
)
|| Sys.file_exists(
Path.(
basePathToRequirePkg
/ String.lowercase_ascii(
entry,
)
)
++ ext,
)) {
Some(
sprintf(
"module %s = %s.%s;",
importedNamespace,
exportedNamespace,
entry,
),
);
} else {
None;
};
}
}
},
accExt,
["Index", importedNamespace] /* If it finds, Index.re, it doesn't look for Bar.re */
),
None,
[".re", ".ml"],
)
) {
| Some(x) => x
| None =>
sprintf(
"module %s = %s;",
importedNamespace,
exportedNamespace,
)
};
},
~library=pathToOCamlLibName(libraryAsPath),
~originalNamespace=importedNamespace,
);
Expand Down

0 comments on commit ffd36e6

Please sign in to comment.