Commit a4e9966
authored
feat(install): create node_modules for workspace members (#34970)
When installing a workspace, `deno install` previously created only a
single `node_modules` directory at the workspace root. Native Node.js
tooling run from within a workspace member (for example `svelte-check`,
`astro`, or `eslint` plugins) expects a local `node_modules` containing
the member's dependencies, the way npm and pnpm lay workspaces out, and
fails without it. Sharing only the root `node_modules` also hides
missing dependencies, since a member can resolve a package that only a
sibling declares.
This makes both linker modes create a `node_modules` directory inside
each workspace member and symlink that member's direct dependencies into
it: npm dependencies point at their resolved location (the shared
`node_modules/.deno` store for the isolated linker, or the package's
top-level or nested directory for the hoisted linker) and sibling
workspace members are linked to their directories. Each member's
`node_modules/.bin` is also populated with its direct dependencies'
executables, so a tool invoked as `node_modules/.bin/<tool>` from within
a member (eslint, svelte-check, astro, ...) resolves the member's own
copy. The workspace root is left untouched and members without
dependencies get no directory.
Stale links are pruned on reinstall the same way the root `node_modules`
prunes them: when a member drops a dependency (or a sibling member is
removed), its link is removed from the member's `node_modules` before
re-linking so the dropped dependency stops being resolvable. The
member's `.bin` is likewise rebuilt from its current dependencies so a
dropped dependency's executable stops resolving. Only symlinks and
junctions are touched, so real files a user placed in the member's
`node_modules` are left alone.
Known limitations (left for follow-ups):
- Sibling workspace members are not npm packages, so they do not yet
contribute executables to a member's `node_modules/.bin`.
- In the hoisted linker, when two members depend on different versions
of the same package the higher version is hoisted to the root and the
lower one is not placed in the layout, so the member declaring the
lower version does not get it linked into its own `node_modules` and
resolves the hoisted version instead. The skip is logged at debug
level.
Closes #26743
Closes #275501 parent e855ab5 commit a4e9966
19 files changed
Lines changed: 735 additions & 1 deletion
File tree
- libs/npm_installer
- tests/specs/install
- workspace_member_node_modules_version_conflict
- package1
- package2
- workspace_member_node_modules
- package1
- package2
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
594 | 594 | | |
595 | 595 | | |
596 | 596 | | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
597 | 710 | | |
598 | 711 | | |
599 | 712 | | |
| |||
872 | 985 | | |
873 | 986 | | |
874 | 987 | | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
875 | 1020 | | |
876 | 1021 | | |
877 | 1022 | | |
| |||
0 commit comments