|
| 1 | +- Start Date: 2017-02-11 |
| 2 | +- RFC PR: (leave this empty) |
| 3 | +- Yarn Issue: (leave this empty) |
| 4 | + |
| 5 | +# Summary |
| 6 | + |
| 7 | +It would be helpful to have a built-in method to remove unneeded tarballs |
| 8 | +from an offline mirror. |
| 9 | + |
| 10 | +# Motivation |
| 11 | + |
| 12 | +`yarn add` and `yarn remove` keep `package.json`, `node_modules`, and |
| 13 | +`yarn.lock` in sync, so when a package is removed, it is removed in all three |
| 14 | +places if possible. The same is not true for an offline mirror. When |
| 15 | +a package is removed, it does not get deleted from the mirror, even if no other |
| 16 | +package depends on it. |
| 17 | + |
| 18 | +This behavior would be desirable in an environment where many projects share |
| 19 | +the same offline mirror. However, when an offline mirror is only used by one |
| 20 | +project, it would be reasonable to trim tarballs from the mirror when they are |
| 21 | +no longer required. Developers would be able to keep the offline mirror as |
| 22 | +small as possible, which is particularly beneficial when the mirror is checked |
| 23 | +into source control. |
| 24 | + |
| 25 | +# Detailed design |
| 26 | + |
| 27 | +The feature can be controlled through a new configuration setting that turns on |
| 28 | +automatic pruning. When `yarn-offline-mirror-pruning` is set to `true`, `yarn` |
| 29 | +will check the offline mirror whenever `yarn.lock` is changed. If a package |
| 30 | +exists in the mirror but no longer exists in `yarn.lock`, the package will be |
| 31 | +deleted from the mirror. |
| 32 | + |
| 33 | +Setting `yarn-offline-mirror-pruning` to `false` should result in the current |
| 34 | +behavior (no pruning), which would also be the default behavior. |
| 35 | + |
| 36 | +# How We Teach This |
| 37 | + |
| 38 | +This feature should be presented as an extension to the current workflow for |
| 39 | +maintaining an offline mirror. With a proper setup, the developer does not need |
| 40 | +to worry about adding a package to the mirror. `yarn add` handles that work. |
| 41 | +Similarly, with pruning turned on through the configuration, the developer |
| 42 | +would not need to worry about removing packages from the mirror. |
| 43 | + |
| 44 | +We would want to add an explanation for this feature to the existing |
| 45 | +documentation. It would not be a priority to teach this feature to |
| 46 | +brand new Yarn users since it is not critical functionality and only applies |
| 47 | +to people who want to use an offline mirror. |
| 48 | + |
| 49 | +# Drawbacks |
| 50 | + |
| 51 | +Turning on the feature may add non-neglibile processing time for certain `yarn` |
| 52 | +commands if the offline mirror is large. |
| 53 | + |
| 54 | +In a monorepo setting, one project that turns on pruning may accidentally |
| 55 | +wipe out a significant portion of a shared offline mirror. |
| 56 | + |
| 57 | +# Alternatives |
| 58 | + |
| 59 | +Users could just let their offline mirrors grow indefinitely. |
| 60 | + |
| 61 | +They could also write their own script that parses `yarn.lock` and removes |
| 62 | +uneeded packages from the offline mirror. |
| 63 | + |
| 64 | +# Unresolved questions |
| 65 | + |
| 66 | +Do we need to worry about a project turning on the feature when using a shared |
| 67 | +offline mirror? |
| 68 | + |
| 69 | +Should we also add a new flag to the CLI commands to do pruning on demand rather |
| 70 | +than only being able to rely on automatic pruning? I can't think of a good use |
| 71 | +case for only wanting to do pruning sometimes rather than always or never. |
0 commit comments