Commit fe38342
authored
## Description
Wires the `NodeImportResolver::with_config_preserving_symlinks`
constructor (added in #11801) through to `swc::Options` as a new
`jsc.preserveSymlinks` boolean config option. When enabled:
- `ModuleConfig::get_resolver` skips the `base.canonicalize()` call on
the input file, so the input path is left at its symlink location.
- `build_resolver` constructs the `NodeImportResolver` via the new
preserve-symlinks constructor, so rewritten module specifiers don't
re-canonicalize target paths.
- The `build_resolver` memoization key is extended with
`preserve_symlinks` so the two modes don't share cached resolver
instances.
Default behaviour is unchanged — canonicalization still happens unless
the flag is explicitly set.
## Motivation
Monorepos that symlink shared source files (e.g. `shared/foo.ts`
symlinked into `packages/app-a/src/foo.ts` and
`packages/app-b/src/foo.ts`) break under the current behaviour: once any
link is followed to the real path, relative imports inside `shared/`
resolve against the real parent directory rather than the importing
package, producing module-not-found errors.
`resolve.symlinks: false` at the bundler level (rspack, webpack) is not
enough if the downstream transformer re-canonicalizes. This PR is the
upstream companion to web-infra-dev/rspack#13762, which exposes a
`preserveSymlinks` option on `builtin:swc-loader` once this lands.
## Test
`crates/swc/tests/preserve_symlinks.rs` (new) exercises the full
`swc::Options` pipeline against a tempdir with the shape:
```
root/
src/index.ts // import "../server/source";
shared/source.ts // export const value = 1;
server/source.ts // symlink -> ../shared/source.ts
```
It asserts that:
- With `jsc.preserveSymlinks = false` (default): the rewritten specifier
is `"../shared/source"` (canonicalized).
- With `jsc.preserveSymlinks = true`: the rewritten specifier remains
`"../server/source"` (symlink preserved).
The existing low-level coverage in
`crates/swc_ecma_transforms_module/tests/path_node.rs::symlink_paths_are_preserved_only_when_opted_in`
is unchanged.
## Related issue:
Closes #11584
1 parent 4fb500c commit fe38342
5 files changed
Lines changed: 185 additions & 13 deletions
File tree
- .changeset
- crates/swc
- src/config
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
| 309 | + | |
309 | 310 | | |
310 | 311 | | |
311 | 312 | | |
312 | 313 | | |
| 314 | + | |
313 | 315 | | |
314 | 316 | | |
315 | 317 | | |
| |||
590 | 592 | | |
591 | 593 | | |
592 | 594 | | |
593 | | - | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
594 | 602 | | |
595 | 603 | | |
596 | 604 | | |
| |||
1391 | 1399 | | |
1392 | 1400 | | |
1393 | 1401 | | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
1394 | 1413 | | |
1395 | 1414 | | |
1396 | 1415 | | |
| |||
1604 | 1623 | | |
1605 | 1624 | | |
1606 | 1625 | | |
| 1626 | + | |
1607 | 1627 | | |
1608 | 1628 | | |
1609 | 1629 | | |
| |||
1612 | 1632 | | |
1613 | 1633 | | |
1614 | 1634 | | |
1615 | | - | |
| 1635 | + | |
1616 | 1636 | | |
1617 | 1637 | | |
1618 | 1638 | | |
1619 | 1639 | | |
1620 | 1640 | | |
1621 | 1641 | | |
1622 | 1642 | | |
1623 | | - | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
1624 | 1650 | | |
1625 | 1651 | | |
1626 | 1652 | | |
1627 | 1653 | | |
1628 | 1654 | | |
1629 | 1655 | | |
| 1656 | + | |
1630 | 1657 | | |
1631 | 1658 | | |
1632 | 1659 | | |
1633 | 1660 | | |
1634 | 1661 | | |
1635 | 1662 | | |
1636 | 1663 | | |
| 1664 | + | |
1637 | 1665 | | |
1638 | 1666 | | |
1639 | 1667 | | |
1640 | 1668 | | |
1641 | 1669 | | |
1642 | 1670 | | |
| 1671 | + | |
1643 | 1672 | | |
1644 | 1673 | | |
1645 | 1674 | | |
1646 | 1675 | | |
1647 | 1676 | | |
1648 | 1677 | | |
| 1678 | + | |
1649 | 1679 | | |
1650 | 1680 | | |
1651 | 1681 | | |
1652 | 1682 | | |
1653 | 1683 | | |
1654 | 1684 | | |
| 1685 | + | |
1655 | 1686 | | |
1656 | 1687 | | |
1657 | 1688 | | |
| |||
1680 | 1711 | | |
1681 | 1712 | | |
1682 | 1713 | | |
| 1714 | + | |
1683 | 1715 | | |
1684 | 1716 | | |
1685 | 1717 | | |
| |||
1997 | 2029 | | |
1998 | 2030 | | |
1999 | 2031 | | |
| 2032 | + | |
2000 | 2033 | | |
2001 | 2034 | | |
2002 | | - | |
| 2035 | + | |
2003 | 2036 | | |
2004 | 2037 | | |
2005 | 2038 | | |
| |||
2021 | 2054 | | |
2022 | 2055 | | |
2023 | 2056 | | |
| 2057 | + | |
2024 | 2058 | | |
2025 | 2059 | | |
2026 | 2060 | | |
| |||
2037 | 2071 | | |
2038 | 2072 | | |
2039 | 2073 | | |
2040 | | - | |
2041 | | - | |
2042 | | - | |
2043 | | - | |
2044 | | - | |
2045 | | - | |
2046 | | - | |
2047 | | - | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
2048 | 2084 | | |
2049 | 2085 | | |
2050 | 2086 | | |
2051 | 2087 | | |
2052 | | - | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
2053 | 2095 | | |
2054 | 2096 | | |
2055 | 2097 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
0 commit comments