@@ -3120,11 +3120,19 @@ BindingData::FilePathIsFileReturnType BindingData::FilePathIsFile(
3120
3120
return BindingData::FilePathIsFileReturnType::kIsNotFile ;
3121
3121
}
3122
3122
3123
+ namespace {
3124
+
3125
+ // define the final index of the algorithm resolution
3126
+ // when packageConfig.main is defined.
3127
+ constexpr uint8_t legacy_main_extensions_with_main_end = 7 ;
3128
+ // define the final index of the algorithm resolution
3129
+ // when packageConfig.main is NOT defined
3130
+ constexpr uint8_t legacy_main_extensions_package_fallback_end = 10 ;
3123
3131
// the possible file extensions that should be tested
3124
3132
// 0-6: when packageConfig.main is defined
3125
3133
// 7-9: when packageConfig.main is NOT defined,
3126
3134
// or when the previous case didn't found the file
3127
- const std::array<std::string , 10 > BindingData:: legacy_main_extensions = {
3135
+ constexpr std::array<std::string_view , 10 > legacy_main_extensions = {
3128
3136
" " ,
3129
3137
" .js" ,
3130
3138
" .json" ,
@@ -3136,6 +3144,8 @@ const std::array<std::string, 10> BindingData::legacy_main_extensions = {
3136
3144
" .json" ,
3137
3145
" .node" };
3138
3146
3147
+ } // namespace
3148
+
3139
3149
void BindingData::LegacyMainResolve (const FunctionCallbackInfo<Value>& args) {
3140
3150
CHECK_GE (args.Length (), 1 );
3141
3151
CHECK (args[0 ]->IsString ());
@@ -3176,9 +3186,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
3176
3186
3177
3187
FromNamespacedPath (&initial_file_path);
3178
3188
3179
- for (int i = 0 ; i < BindingData::legacy_main_extensions_with_main_end;
3180
- i++) {
3181
- file_path = initial_file_path + BindingData::legacy_main_extensions[i];
3189
+ for (int i = 0 ; i < legacy_main_extensions_with_main_end; i++) {
3190
+ file_path = initial_file_path + std::string (legacy_main_extensions[i]);
3182
3191
3183
3192
switch (FilePathIsFile (env, file_path)) {
3184
3193
case BindingData::FilePathIsFileReturnType::kIsFile :
@@ -3211,10 +3220,10 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) {
3211
3220
3212
3221
FromNamespacedPath (&initial_file_path);
3213
3222
3214
- for (int i = BindingData:: legacy_main_extensions_with_main_end;
3215
- i < BindingData:: legacy_main_extensions_package_fallback_end;
3223
+ for (int i = legacy_main_extensions_with_main_end;
3224
+ i < legacy_main_extensions_package_fallback_end;
3216
3225
i++) {
3217
- file_path = initial_file_path + BindingData:: legacy_main_extensions[i];
3226
+ file_path = initial_file_path + std::string ( legacy_main_extensions[i]) ;
3218
3227
3219
3228
switch (FilePathIsFile (env, file_path)) {
3220
3229
case BindingData::FilePathIsFileReturnType::kIsFile :
0 commit comments