Skip to content

Commit 82ad4c5

Browse files
committed
Allow as CWD for preopen
1 parent 390e8e0 commit 82ad4c5

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/file.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ inline static std::string wstring_to_string(const std::wstring &wstr)
5050
#endif
5151

5252
#ifdef _WASM
53-
inline static std::string get_cwd_from_env()
53+
inline static std::string get_cwd_from_env(const char* default_pwd)
5454
{
5555
char* value = getenv("PWD");
56-
if (!value) return "/";
56+
if (!value) return default_pwd;
5757
return value;
5858
}
5959
#endif
@@ -68,8 +68,8 @@ namespace Sass {
6868
{
6969
#ifdef _WASM
7070
// the WASI does not implement getcwd() yet --
71-
// check the environment variables or default to "/".
72-
std::string cwd = get_cwd_from_env();
71+
// check the environment variables or default to "./".
72+
std::string cwd = get_cwd_from_env("./");
7373
#else
7474
const size_t wd_len = 4096;
7575
#ifndef _WIN32
@@ -189,7 +189,9 @@ namespace Sass {
189189
while((pos = path.find("/./", pos)) != std::string::npos) path.erase(pos, 2);
190190

191191
// remove all leading and trailing self references
192-
while(path.size() >= 2 && path[0] == '.' && path[1] == '/') path.erase(0, 2);
192+
#ifndef PREOPEN_COMPATIBLE
193+
while(path.size() >= 2 && path[0] == '.' && path[1] == '/') path.erase(0, 2);
194+
#endif
193195
while((pos = path.length()) > 1 && path[pos - 2] == '/' && path[pos - 1] == '.') path.erase(pos - 2);
194196

195197

src/sass.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
// enable loading of plugins for non-wasm
4242
#ifndef _WASM
4343
# define ENABLE_LOAD_PLUGINS
44+
#else
45+
# define PREOPEN_COMPATIBLE
4446
#endif
4547

4648
// path separation char

0 commit comments

Comments
 (0)