| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3143,6 +3143,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) { | |||
| 3143 | 3143 | return; | |
| 3144 | 3144 | } | |
| 3145 | 3145 | ||
| 3146 | + std::string package_initial_file = ""; | ||
| 3147 | + | ||
| 3146 | 3148 | ada::result<ada::url_aggregator> file_path_url; | |
| 3147 | 3149 | std::optional<std::string> initial_file_path; | |
| 3148 | 3150 | std::string file_path; | |
@@ -3165,6 +3167,8 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) { | |||
| 3165 | 3167 | ||
| 3166 | 3168 | node::url::FromNamespacedPath(&initial_file_path.value()); | |
| 3167 | 3169 | ||
| 3170 | + package_initial_file = *initial_file_path; | ||
| 3171 | + | ||
| 3168 | 3172 | for (int i = 0; i < legacy_main_extensions_with_main_end; i++) { | |
| 3169 | 3173 | file_path = *initial_file_path + std::string(legacy_main_extensions[i]); | |
| 3170 | 3174 | ||
@@ -3220,13 +3224,10 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) { | |||
| 3220 | 3224 | } | |
| 3221 | 3225 | } | |
| 3222 | 3226 | ||
| 3223 | - std::optional<std::string> module_path = | ||
| 3224 | - node::url::FileURLToPath(env, *package_json_url); | ||
| 3225 | - std::optional<std::string> module_base; | ||
| 3227 | + if (package_initial_file == "") | ||
| 3228 | + package_initial_file = *initial_file_path + ".js"; | ||
| 3226 | 3229 | ||
| 3227 | - if (!module_path.has_value()) { | ||
| 3228 | - return; | ||
| 3229 | - } | ||
| 3230 | + std::optional<std::string> module_base; | ||
| 3230 | 3231 | ||
| 3231 | 3232 | if (args.Length() >= 3 && args[2]->IsString()) { | |
| 3232 | 3233 | Utf8Value utf8_base_path(isolate, args[2]); | |
@@ -3251,7 +3252,7 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo<Value>& args) { | |||
| 3251 | 3252 | ||
| 3252 | 3253 | THROW_ERR_MODULE_NOT_FOUND(isolate, | |
| 3253 | 3254 | "Cannot find package '%s' imported from %s", | |
| 3254 | - *module_path, | ||
| 3255 | + package_initial_file, | ||
| 3255 | 3256 | *module_base); | |
| 3256 | 3257 | } | |
| 3257 | 3258 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -129,15 +129,28 @@ describe('legacyMainResolve', () => { | |||
| 129 | 129 | ); | |
| 130 | 130 | assert.throws( | |
| 131 | 131 | () => legacyMainResolve(packageJsonUrl, { main: null }, packageJsonUrl), | |
| 132 | - { code: 'ERR_MODULE_NOT_FOUND' }, | ||
| 132 | + { message: /index\.js/, code: 'ERR_MODULE_NOT_FOUND' }, | ||
| 133 | 133 | ); | |
| 134 | 134 | }); | |
| 135 | 135 | ||
| 136 | 136 | it('should not crash when cannot resolve to a file that contains special chars', () => { | |
| 137 | 137 | const packageJsonUrl = pathToFileURL('/c/file%20with%20percents/package.json'); | |
| 138 | 138 | assert.throws( | |
| 139 | 139 | () => legacyMainResolve(packageJsonUrl, { main: null }, packageJsonUrl), | |
| 140 | - { code: 'ERR_MODULE_NOT_FOUND' }, | ||
| 140 | + { message: /index\.js/, code: 'ERR_MODULE_NOT_FOUND' }, | ||
| 141 | + ); | ||
| 142 | + }); | ||
| 143 | + | ||
| 144 | + it('should report main file on error message when not found', () => { | ||
| 145 | + const packageJsonUrl = pathToFileURL( | ||
| 146 | + path.resolve( | ||
| 147 | + fixtures.path('/es-modules/legacy-main-resolver'), | ||
| 148 | + 'package.json' | ||
| 149 | + ) | ||
| 150 | + ); | ||
| 151 | + assert.throws( | ||
| 152 | + () => legacyMainResolve(packageJsonUrl, { main: './index.node' }, packageJsonUrl), | ||
| 153 | + { message: /index\.node/, code: 'ERR_MODULE_NOT_FOUND' }, | ||
| 141 | 154 | ); | |
| 142 | 155 | }); | |
| 143 | 156 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments