Commit edfbee3
module: resolve self-references
Adds the ability to `import` or `require` a package from within its
own source code. This allows tests and examples to be written using
the package name, making them easier to reuse by consumers of the
package.
Assuming the `name` field in `package.json` is set to `my-pkg`, its
test could use `require('my-pkg')` or `import 'my-pkg'` even if
there's no `node_modules/my-pkg` while testing the package itself.
An important difference between this and relative specifiers like
`require('../')` is that self-references use the public interface
of the package as defined in the `exports` field while relative
specifiers don't.
This behavior is guarded by a new experimental flag
(`--experimental-resolve-self`).
PR-URL: #29327
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>1 parent 0d9ae1b commit edfbee3Copy full SHA for edfbee3
File tree
Expand file treeCollapse file tree
12 files changed
+294
-44
lines changedOpen diff view settings
Filter options
- doc/api
- lib/internal/modules/cjs
- src
- test
- es-module
- fixtures/node_modules/pkgexports
- lib
Expand file treeCollapse file tree
12 files changed
+294
-44
lines changedOpen diff view settings
Collapse file
+9Lines changed: 9 additions & 0 deletions
- Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
196 | 196 | |
197 | 197 | |
198 | 198 | |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | + |
| 203 | + |
| 204 | + |
| 205 | + |
| 206 | + |
199 | 207 | |
200 | 208 | |
201 | 209 | |
| ||
1010 | 1018 | |
1011 | 1019 | |
1012 | 1020 | |
| 1021 | + |
1013 | 1022 | |
1014 | 1023 | |
1015 | 1024 | |
|
Collapse file
+24-4Lines changed: 24 additions & 4 deletions
- Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
839 | 839 | |
840 | 840 | |
841 | 841 | |
842 | | - |
843 | | - |
844 | | - |
845 | 842 | |
846 | 843 | |
847 | 844 | |
| ||
855 | 852 | |
856 | 853 | |
857 | 854 | |
858 | | - |
| 855 | + |
859 | 856 | |
860 | 857 | |
861 | 858 | |
| ||
878 | 875 | |
879 | 876 | |
880 | 877 | |
| 878 | + |
| 879 | + |
| 880 | + |
881 | 881 | |
882 | 882 | |
| 883 | + |
| 884 | + |
| 885 | + |
| 886 | + |
| 887 | + |
| 888 | + |
| 889 | + |
| 890 | + |
| 891 | + |
| 892 | + |
| 893 | + |
| 894 | + |
| 895 | + |
| 896 | + |
| 897 | + |
| 898 | + |
| 899 | + |
| 900 | + |
| 901 | + |
| 902 | + |
883 | 903 | |
884 | 904 | |
885 | 905 | |
|
Collapse file
+10-2Lines changed: 10 additions & 2 deletions
- Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
159 | 159 | |
160 | 160 | |
161 | 161 | |
162 | | - |
163 | | - |
| 162 | + |
| 163 | + |
| 164 | + |
164 | 165 | |
165 | 166 | |
166 | 167 | |
| ||
200 | 201 | |
201 | 202 | |
202 | 203 | |
| 204 | + |
| 205 | + |
| 206 | + |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | + |
203 | 211 | |
204 | 212 | |
205 | 213 | |
|
Collapse file
lib/internal/modules/cjs/loader.js
Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js+129-37Lines changed: 129 additions & 37 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
58 | 58 | |
59 | 59 | |
60 | 60 | |
| 61 | + |
61 | 62 | |
62 | 63 | |
63 | 64 | |
| ||
241 | 242 | |
242 | 243 | |
243 | 244 | |
| 245 | + |
244 | 246 | |
245 | 247 | |
246 | 248 | |
| ||
370 | 372 | |
371 | 373 | |
372 | 374 | |
| 375 | + |
| 376 | + |
| 377 | + |
| 378 | + |
| 379 | + |
| 380 | + |
| 381 | + |
| 382 | + |
| 383 | + |
| 384 | + |
| 385 | + |
| 386 | + |
| 387 | + |
| 388 | + |
| 389 | + |
| 390 | + |
| 391 | + |
| 392 | + |
| 393 | + |
| 394 | + |
| 395 | + |
| 396 | + |
| 397 | + |
| 398 | + |
| 399 | + |
| 400 | + |
| 401 | + |
| 402 | + |
| 403 | + |
| 404 | + |
| 405 | + |
| 406 | + |
| 407 | + |
| 408 | + |
| 409 | + |
| 410 | + |
| 411 | + |
| 412 | + |
| 413 | + |
| 414 | + |
| 415 | + |
| 416 | + |
| 417 | + |
| 418 | + |
| 419 | + |
| 420 | + |
| 421 | + |
| 422 | + |
| 423 | + |
| 424 | + |
| 425 | + |
| 426 | + |
| 427 | + |
| 428 | + |
| 429 | + |
| 430 | + |
| 431 | + |
| 432 | + |
| 433 | + |
| 434 | + |
| 435 | + |
| 436 | + |
| 437 | + |
| 438 | + |
| 439 | + |
| 440 | + |
| 441 | + |
| 442 | + |
| 443 | + |
| 444 | + |
| 445 | + |
| 446 | + |
| 447 | + |
| 448 | + |
| 449 | + |
| 450 | + |
| 451 | + |
| 452 | + |
| 453 | + |
| 454 | + |
| 455 | + |
| 456 | + |
| 457 | + |
| 458 | + |
| 459 | + |
| 460 | + |
| 461 | + |
| 462 | + |
| 463 | + |
| 464 | + |
| 465 | + |
| 466 | + |
| 467 | + |
| 468 | + |
| 469 | + |
| 470 | + |
| 471 | + |
| 472 | + |
| 473 | + |
| 474 | + |
| 475 | + |
| 476 | + |
| 477 | + |
| 478 | + |
| 479 | + |
| 480 | + |
| 481 | + |
| 482 | + |
| 483 | + |
| 484 | + |
| 485 | + |
| 486 | + |
| 487 | + |
| 488 | + |
| 489 | + |
| 490 | + |
| 491 | + |
| 492 | + |
| 493 | + |
373 | 494 | |
374 | 495 | |
375 | 496 | |
| ||
384 | 505 | |
385 | 506 | |
386 | 507 | |
387 | | - |
388 | | - |
389 | | - |
390 | | - |
391 | | - |
392 | | - |
393 | | - |
394 | | - |
395 | | - |
396 | | - |
397 | | - |
398 | | - |
399 | | - |
400 | | - |
401 | | - |
402 | | - |
403 | | - |
404 | | - |
405 | | - |
406 | | - |
407 | | - |
408 | | - |
409 | | - |
410 | | - |
411 | | - |
412 | | - |
413 | | - |
414 | | - |
415 | | - |
416 | | - |
417 | | - |
418 | | - |
419 | | - |
420 | | - |
421 | | - |
422 | | - |
423 | | - |
| 508 | + |
424 | 509 | |
425 | 510 | |
426 | 511 | |
| ||
536 | 621 | |
537 | 622 | |
538 | 623 | |
| 624 | + |
| 625 | + |
| 626 | + |
| 627 | + |
| 628 | + |
| 629 | + |
| 630 | + |
539 | 631 | |
540 | 632 | |
541 | 633 | |
|
Collapse file
+3Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
93 | 93 | |
94 | 94 | |
95 | 95 | |
| 96 | + |
96 | 97 | |
97 | 98 | |
98 | 99 | |
99 | 100 | |
100 | 101 | |
101 | 102 | |
| 103 | + |
| 104 | + |
102 | 105 | |
103 | 106 | |
104 | 107 | |
|
0 commit comments