@@ -142,7 +142,7 @@ index 69f73f829706deddc4f328b78af9d58434af647d..1d53a2a47423150e822bb917b2725d3a
142
142
143
143
const encodedSepRegEx = /%2F|%5C/i;
144
144
diff --git a/src/node_file.cc b/src/node_file.cc
145
- index b0aa53420c4efb45ccb129cd4db5579de9f3e401..3e3aa383f54f45ab6dd134be29a2dbcf35760163 100644
145
+ index 80ff36f2463035ed32cb8b7b826bfe94c339dbe2..cca6c6775bc8dd35b897498c7dd65b2e3957ee40 100644
146
146
--- a/src/node_file.cc
147
147
+++ b/src/node_file.cc
148
148
@@ -19,14 +19,11 @@
@@ -160,7 +160,7 @@ index b0aa53420c4efb45ccb129cd4db5579de9f3e401..3e3aa383f54f45ab6dd134be29a2dbcf
160
160
#include "node_process-inl.h"
161
161
#include "node_stat_watcher.h"
162
162
#include "node_url.h"
163
- @@ -3116,134 +3113 ,6 @@ constexpr std::array<std::string_view, 10> legacy_main_extensions = {
163
+ @@ -3127,135 +3124 ,6 @@ constexpr std::array<std::string_view, 10> legacy_main_extensions = {
164
164
165
165
} // namespace
166
166
@@ -180,6 +180,8 @@ index b0aa53420c4efb45ccb129cd4db5579de9f3e401..3e3aa383f54f45ab6dd134be29a2dbcf
180
180
- return;
181
181
- }
182
182
-
183
+ - std::string package_initial_file = "";
184
+ -
183
185
- ada::result<ada::url_aggregator> file_path_url;
184
186
- std::optional<std::string> initial_file_path;
185
187
- std::string file_path;
@@ -202,6 +204,8 @@ index b0aa53420c4efb45ccb129cd4db5579de9f3e401..3e3aa383f54f45ab6dd134be29a2dbcf
202
204
-
203
205
- node::url::FromNamespacedPath(&initial_file_path.value());
204
206
-
207
+ - package_initial_file = *initial_file_path;
208
+ -
205
209
- for (int i = 0; i < legacy_main_extensions_with_main_end; i++) {
206
210
- file_path = *initial_file_path + std::string(legacy_main_extensions[i]);
207
211
-
@@ -257,13 +261,10 @@ index b0aa53420c4efb45ccb129cd4db5579de9f3e401..3e3aa383f54f45ab6dd134be29a2dbcf
257
261
- }
258
262
- }
259
263
-
260
- - std::optional<std::string> module_path =
261
- - node::url::FileURLToPath(env, *package_json_url);
262
- - std::optional<std::string> module_base;
264
+ - if (package_initial_file == "")
265
+ - package_initial_file = *initial_file_path + ".js";
263
266
-
264
- - if (!module_path.has_value()) {
265
- - return;
266
- - }
267
+ - std::optional<std::string> module_base;
267
268
-
268
269
- if (args.Length() >= 3 && args[2]->IsString()) {
269
270
- Utf8Value utf8_base_path(isolate, args[2]);
@@ -288,14 +289,14 @@ index b0aa53420c4efb45ccb129cd4db5579de9f3e401..3e3aa383f54f45ab6dd134be29a2dbcf
288
289
-
289
290
- THROW_ERR_MODULE_NOT_FOUND(isolate,
290
291
- "Cannot find package '%s' imported from %s",
291
- - *module_path ,
292
+ - package_initial_file ,
292
293
- *module_base);
293
294
- }
294
295
-
295
296
void BindingData::MemoryInfo(MemoryTracker* tracker) const {
296
297
tracker->TrackField("stats_field_array", stats_field_array);
297
298
tracker->TrackField("stats_field_bigint_array", stats_field_bigint_array);
298
- @@ -3343 ,19 +3212 ,6 @@ InternalFieldInfoBase* BindingData::Serialize(int index) {
299
+ @@ -3355 ,19 +3223 ,6 @@ InternalFieldInfoBase* BindingData::Serialize(int index) {
299
300
return info;
300
301
}
301
302
@@ -315,15 +316,15 @@ index b0aa53420c4efb45ccb129cd4db5579de9f3e401..3e3aa383f54f45ab6dd134be29a2dbcf
315
316
static void CreatePerIsolateProperties(IsolateData* isolate_data,
316
317
Local<ObjectTemplate> target) {
317
318
Isolate* isolate = isolate_data->isolate();
318
- @@ -3410 ,7 +3266 ,6 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
319
+ @@ -3422 ,7 +3277 ,6 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
319
320
SetMethod(isolate, target, "mkdtemp", Mkdtemp);
320
321
321
322
StatWatcher::CreatePerIsolateProperties(isolate_data, target);
322
323
- BindingData::CreatePerIsolateProperties(isolate_data, target);
323
324
324
325
target->Set(
325
326
FIXED_ONE_BYTE_STRING(isolate, "kFsStatsFieldsNumber"),
326
- @@ -3483 ,7 +3338 ,6 @@ BindingData* FSReqBase::binding_data() {
327
+ @@ -3495 ,7 +3349 ,6 @@ BindingData* FSReqBase::binding_data() {
327
328
void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
328
329
registry->Register(Access);
329
330
StatWatcher::RegisterExternalReferences(registry);
@@ -350,7 +351,7 @@ index 6f1b55284db0f4f8c70081b4834a074c717f3cc9..a969fff32bd156aa9393c1db9eec474e
350
351
SET_SELF_SIZE(BindingData)
351
352
SET_MEMORY_INFO_NAME(BindingData)
352
353
diff --git a/test/es-module/test-cjs-legacyMainResolve.js b/test/es-module/test-cjs-legacyMainResolve.js
353
- index 1dc7d8faafe6eb5cea7e43e9783041f2a994be0d..d86d501689b2b72f2b964d6e2a91c5d36b6b62f5 100644
354
+ index 0bfeb567a22b1f9d9116b749d6cb3a8fda6bcc6a..17f137c595a9fef5f051fafc4682f206034c214c 100644
354
355
--- a/test/es-module/test-cjs-legacyMainResolve.js
355
356
+++ b/test/es-module/test-cjs-legacyMainResolve.js
356
357
@@ -82,7 +82,7 @@ describe('legacyMainResolve', () => {
@@ -366,7 +367,7 @@ index 1dc7d8faafe6eb5cea7e43e9783041f2a994be0d..d86d501689b2b72f2b964d6e2a91c5d3
366
367
);
367
368
assert.throws(
368
369
() => legacyMainResolve(packageJsonUrl, { main: null }, packageJsonUrl),
369
- - { code: 'ERR_MODULE_NOT_FOUND' },
370
+ - { message: /index\.js/, code: 'ERR_MODULE_NOT_FOUND' },
370
371
+ { code: 'ERR_INTERNAL_ASSERTION' },
371
372
);
372
373
});
@@ -375,12 +376,21 @@ index 1dc7d8faafe6eb5cea7e43e9783041f2a994be0d..d86d501689b2b72f2b964d6e2a91c5d3
375
376
const packageJsonUrl = pathToFileURL('/c/file%20with%20percents/package.json');
376
377
assert.throws(
377
378
() => legacyMainResolve(packageJsonUrl, { main: null }, packageJsonUrl),
378
- - { code: 'ERR_MODULE_NOT_FOUND' },
379
+ - { message: /index\.js/, code: 'ERR_MODULE_NOT_FOUND' },
379
380
+ { code: 'ERR_INTERNAL_ASSERTION' },
380
381
);
381
382
});
382
383
383
384
@@ -150,7 +150,7 @@ describe('legacyMainResolve', () => {
385
+ );
386
+ assert.throws(
387
+ () => legacyMainResolve(packageJsonUrl, { main: './index.node' }, packageJsonUrl),
388
+ - { message: /index\.node/, code: 'ERR_MODULE_NOT_FOUND' },
389
+ + { code: 'ERR_INTERNAL_ASSERTION' },
390
+ );
391
+ });
392
+
393
+ @@ -163,7 +163,7 @@ describe('legacyMainResolve', () => {
384
394
);
385
395
assert.throws(
386
396
() => legacyMainResolve(packageJsonUrl, { main: null }, undefined),
0 commit comments