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 ConvertToWideString (const std::string& str) {
335
+ auto cp = GetACP ();
336
+ int size_needed = MultiByteToWideChar (
337
+ cp, 0 , &str[0 ], static_cast <int >(str.size ()), nullptr , 0 );
338
+ std::wstring wstrTo (size_needed, 0 );
339
+ MultiByteToWideChar (
340
+ cp, 0 , &str[0 ], static_cast <int >(str.size ()), &wstrTo[0 ], size_needed);
341
+ return wstrTo;
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 = ConvertToWideString (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 = ConvertToWideString (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