16
16
17
17
#include " simdjson.h"
18
18
19
+ #ifdef _WIN32
20
+ #include < windows.h>
21
+ #endif
22
+
19
23
namespace node {
20
24
namespace modules {
21
25
@@ -326,6 +330,18 @@ const BindingData::PackageConfig* BindingData::TraverseParent(
326
330
return nullptr ;
327
331
}
328
332
333
+ #ifdef _WIN32
334
+ std::wstring MaybeWCharTToWString (const std::string& input) {
335
+ bool is_unicode = IsTextUnicode (input.c_str (), input.size (), nullptr );
336
+ auto code_page = is_unicode ? CP_UTF8 : GetACP ();
337
+ int length = MultiByteToWideChar (code_page, 0 , input.c_str (), -1 , nullptr , 0 );
338
+
339
+ std::wstring wide_str (length, 0 );
340
+ MultiByteToWideChar (code_page, 0 , input.c_str (), -1 , &wide_str[0 ], length);
341
+ return wide_str;
342
+ }
343
+ #endif
344
+
329
345
void BindingData::GetNearestParentPackageJSON (
330
346
const v8::FunctionCallbackInfo<v8::Value>& args) {
331
347
CHECK_GE (args.Length (), 1 );
@@ -344,8 +360,16 @@ void BindingData::GetNearestParentPackageJSON(
344
360
path_value_str.push_back (kPathSeparator );
345
361
}
346
362
347
- auto package_json =
348
- TraverseParent (realm, std::filesystem::path (path_value_str));
363
+ std::filesystem::path path;
364
+
365
+ #ifdef _WIN32
366
+ std::wstring wide_path = MaybeWCharTToWString (path_value_str);
367
+ path = std::filesystem::path (wide_path);
368
+ #else
369
+ path = std::filesystem::path (path_value_str);
370
+ #endif
371
+
372
+ auto package_json = TraverseParent (realm, path);
349
373
350
374
if (package_json != nullptr ) {
351
375
args.GetReturnValue ().Set (package_json->Serialize (realm));
@@ -370,8 +394,16 @@ void BindingData::GetNearestParentPackageJSONType(
370
394
path_value_str.push_back (kPathSeparator );
371
395
}
372
396
373
- auto package_json =
374
- TraverseParent (realm, std::filesystem::path (path_value_str));
397
+ std::filesystem::path path;
398
+
399
+ #ifdef _WIN32
400
+ std::wstring wide_path = MaybeWCharTToWString (path_value_str);
401
+ path = std::filesystem::path (wide_path);
402
+ #else
403
+ path = std::filesystem::path (path_value_str);
404
+ #endif
405
+
406
+ auto package_json = TraverseParent (realm, path);
375
407
376
408
if (package_json == nullptr ) {
377
409
return ;
0 commit comments