Fix a bug that was preventing require('ui') from working, and improve resolveRequire while I'm in there.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3195 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2016-04-09 18:36:43 +00:00
parent 4b2877dbad
commit bea0ae23dd
2 changed files with 10 additions and 5 deletions

View File

@ -124,7 +124,7 @@ function editPage(event) {
}
// XXX: Why do I need .js?
require("ui.js").fileList({
require("ui").fileList({
title: "Live Markdeep Editor",
edit: editPage,
});

View File

@ -726,15 +726,20 @@ void Task::configureFromStdin() {
std::string Task::resolveRequire(const std::string& require) {
std::string result;
for (size_t i = 0; i < _path.size(); ++i) {
std::string& path = _path[i];
std::cout << "Looking in " << path << " for " << require << "\n";
std::string test;
if (require.find("..") == std::string::npos && require.find('/') == std::string::npos) {
result = path + require;
test = path + require;
}
if (result.size() && require.rfind(".js") != require.size() - 3) {
result += ".js";
if (test.size() && (require.size() < 3 || require.rfind(".js") != require.size() - 3)) {
test += ".js";
}
uv_fs_t request;
if (uv_fs_access(_loop, &request, test.c_str(), R_OK, 0) == 0) {
result = test;
break;
}
}
return result;