Skip to content

Handle absolute as well as relative paths (issue #969) #1317

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

Merged
merged 3 commits into from
Aug 30, 2018
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/arr/compiler/cli-module-loader.arr
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,21 @@ type CLIContext = {
cache-base-dir :: String
}

fun get-real-path(current-load-path :: String, dep :: CS.Dependency):
this-path = dep.arguments.get(0)
if P.is-absolute(this-path):
P.relative(current-load-path, this-path)
else:
P.join(current-load-path, this-path)
end
end

fun module-finder(ctxt :: CLIContext, dep :: CS.Dependency):
cases(CS.Dependency) dep:
| dependency(protocol, args) =>
if protocol == "file":
clp = ctxt.current-load-path
this-path = dep.arguments.get(0)
real-path = P.join(clp, this-path)
real-path = get-real-path(clp, dep)
new-context = ctxt.{current-load-path: P.dirname(real-path)}
if F.file-exists(real-path):
CL.located(get-file-locator(ctxt.cache-base-dir, real-path), new-context)
Expand All @@ -255,8 +263,7 @@ fun module-finder(ctxt :: CLIContext, dep :: CS.Dependency):
CL.located(force-check-mode, ctxt)
else if protocol == "file-no-cache":
clp = ctxt.current-load-path
this-path = dep.arguments.get(0)
real-path = P.join(clp, this-path)
real-path = get-real-path(clp, dep)
new-context = ctxt.{current-load-path: P.dirname(real-path)}
if F.file-exists(real-path):
CL.located(FL.file-locator(real-path, CS.standard-globals), new-context)
Expand All @@ -265,8 +272,7 @@ fun module-finder(ctxt :: CLIContext, dep :: CS.Dependency):
end
else if protocol == "js-file":
clp = ctxt.current-load-path
this-path = dep.arguments.get(0)
real-path = P.join(clp, this-path)
real-path = get-real-path(clp, dep)
new-context = ctxt.{current-load-path: P.dirname(real-path)}
locator = JSF.make-jsfile-locator(real-path)
CL.located(locator, new-context)
Expand Down
7 changes: 5 additions & 2 deletions src/js/trove/pathlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@
var sext = RUNTIME.unwrap(ext);
return RUNTIME.makeString(path.basename(s, sext));
}),
"path-sep": RUNTIME.makeString(path.sep)
"is-absolute": RUNTIME.makeFunction(function(p) {
return path.isAbsolute(p);
}),
"path-sep": RUNTIME.makeString(path.sep),
};
return RUNTIME.makeModuleReturn(values, {});
}
}
})