Commit df86793
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 e08c008 commit df86793Copy full SHA for df86793
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 | |
| ||
1053 | 1061 | |
1054 | 1062 | |
1055 | 1063 | |
| 1064 | + |
1056 | 1065 | |
1057 | 1066 | |
1058 | 1067 | |
|
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 |
|---|---|---|
| ||
838 | 838 | |
839 | 839 | |
840 | 840 | |
841 | | - |
842 | | - |
843 | | - |
844 | 841 | |
845 | 842 | |
846 | 843 | |
| ||
854 | 851 | |
855 | 852 | |
856 | 853 | |
857 | | - |
| 854 | + |
858 | 855 | |
859 | 856 | |
860 | 857 | |
| ||
877 | 874 | |
878 | 875 | |
879 | 876 | |
| 877 | + |
| 878 | + |
| 879 | + |
880 | 880 | |
881 | 881 | |
| 882 | + |
| 883 | + |
| 884 | + |
| 885 | + |
| 886 | + |
| 887 | + |
| 888 | + |
| 889 | + |
| 890 | + |
| 891 | + |
| 892 | + |
| 893 | + |
| 894 | + |
| 895 | + |
| 896 | + |
| 897 | + |
| 898 | + |
| 899 | + |
| 900 | + |
| 901 | + |
882 | 902 | |
883 | 903 | |
884 | 904 | |
|
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 |
|---|---|---|
| ||
160 | 160 | |
161 | 161 | |
162 | 162 | |
163 | | - |
164 | | - |
| 163 | + |
| 164 | + |
| 165 | + |
165 | 166 | |
166 | 167 | |
167 | 168 | |
| ||
201 | 202 | |
202 | 203 | |
203 | 204 | |
| 205 | + |
| 206 | + |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | + |
| 211 | + |
204 | 212 | |
205 | 213 | |
206 | 214 | |
|
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 |
|---|---|---|
| ||
59 | 59 | |
60 | 60 | |
61 | 61 | |
| 62 | + |
62 | 63 | |
63 | 64 | |
64 | 65 | |
| ||
237 | 238 | |
238 | 239 | |
239 | 240 | |
| 241 | + |
240 | 242 | |
241 | 243 | |
242 | 244 | |
| ||
366 | 368 | |
367 | 369 | |
368 | 370 | |
| 371 | + |
| 372 | + |
| 373 | + |
| 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 | + |
369 | 490 | |
370 | 491 | |
371 | 492 | |
| ||
380 | 501 | |
381 | 502 | |
382 | 503 | |
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 | | - |
| 504 | + |
420 | 505 | |
421 | 506 | |
422 | 507 | |
| ||
532 | 617 | |
533 | 618 | |
534 | 619 | |
| 620 | + |
| 621 | + |
| 622 | + |
| 623 | + |
| 624 | + |
| 625 | + |
| 626 | + |
535 | 627 | |
536 | 628 | |
537 | 629 | |
|
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