@@ -2909,11 +2909,19 @@ BindingData::FilePathIsFileReturnType BindingData::FilePathIsFile(
2909
2909
return BindingData::FilePathIsFileReturnType::kIsNotFile ;
2910
2910
}
2911
2911
2912
+ namespace {
2913
+
2914
+ // define the final index of the algorithm resolution
2915
+ // when packageConfig.main is defined.
2916
+ constexpr uint8_t legacy_main_extensions_with_main_end = 7 ;
2917
+ // define the final index of the algorithm resolution
2918
+ // when packageConfig.main is NOT defined
2919
+ constexpr uint8_t legacy_main_extensions_package_fallback_end = 10 ;
2912
2920
// the possible file extensions that should be tested
2913
2921
// 0-6: when packageConfig.main is defined
2914
2922
// 7-9: when packageConfig.main is NOT defined,
2915
2923
// or when the previous case didn't found the file
2916
- const std::array<std::string , 10 > BindingData:: legacy_main_extensions = {
2924
+ constexpr std::array<std::string_view , 10 > legacy_main_extensions = {
2917
2925
" " ,
2918
2926
" .js" ,
2919
2927
" .json" ,
@@ -2925,6 +2933,8 @@ const std::array<std::string, 10> BindingData::legacy_main_extensions = {
2925
2933
" .json" ,
2926
2934
" .node" };
2927
2935
2936
+ } // namespace
2937
+
2928
2938
void BindingData::LegacyMainResolve (const FunctionCallbackInfo<Value>& args) {
2929
2939
CHECK_GE (args.Length (), 1 );
2930
2940
CHECK (args[0 ]->IsString ());
@@ -2965,9 +2975,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
2965
2975
2966
2976
FromNamespacedPath (&initial_file_path);
2967
2977
2968
- for (int i = 0 ; i < BindingData::legacy_main_extensions_with_main_end;
2969
- i++) {
2970
- file_path = initial_file_path + BindingData::legacy_main_extensions[i];
2978
+ for (int i = 0 ; i < legacy_main_extensions_with_main_end; i++) {
2979
+ file_path = initial_file_path + std::string (legacy_main_extensions[i]);
2971
2980
2972
2981
switch (FilePathIsFile (env, file_path)) {
2973
2982
case BindingData::FilePathIsFileReturnType::kIsFile :
@@ -3000,10 +3009,10 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
3000
3009
3001
3010
FromNamespacedPath (&initial_file_path);
3002
3011
3003
- for (int i = BindingData:: legacy_main_extensions_with_main_end;
3004
- i < BindingData:: legacy_main_extensions_package_fallback_end;
3012
+ for (int i = legacy_main_extensions_with_main_end;
3013
+ i < legacy_main_extensions_package_fallback_end;
3005
3014
i++) {
3006
- file_path = initial_file_path + BindingData:: legacy_main_extensions[i];
3015
+ file_path = initial_file_path + std::string ( legacy_main_extensions[i]) ;
3007
3016
3008
3017
switch (FilePathIsFile (env, file_path)) {
3009
3018
case BindingData::FilePathIsFileReturnType::kIsFile :
0 commit comments