From bea0ae23dd0cfa909af6e40840a2a8bae8c80590 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sat, 9 Apr 2016 18:36:43 +0000 Subject: [PATCH] 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 --- packages/cory/wiki/wiki.js | 2 +- src/Task.cpp | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/cory/wiki/wiki.js b/packages/cory/wiki/wiki.js index e5ba0316..24ff26fb 100644 --- a/packages/cory/wiki/wiki.js +++ b/packages/cory/wiki/wiki.js @@ -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, }); \ No newline at end of file diff --git a/src/Task.cpp b/src/Task.cpp index ff696a73..33d3e7a9 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -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;