|
| 1 | +- Start Date: 2016-12-13 |
| 2 | +- RFC PR: (leave this empty) |
| 3 | +- Yarn Issue: (leave this empty) |
| 4 | + |
| 5 | +# Summary |
| 6 | + |
| 7 | +`yarn install` should be idempotent. |
| 8 | + |
| 9 | +Ideally, the result of `yarn install` would not be statefully dependent on the contents of an existing `node_modules`, and would ensure the resulting `node_modules` is identical regardless of whether there is an existing `node_modules` or not. This seems very inline with the spirit of yarn's goal of deterministic builds (same `node_modules` independent of whether `node_modules` exists or the version of node that generated it). |
| 10 | + |
| 11 | +# Motivation |
| 12 | + |
| 13 | +Presently, a major headache with `npm` / binary `node_modules` (e.g., `heapdump`) is the need to manually run `npm rebuild` when upgrading node. Communicating this preemptively to developers prior to an upgrade is logistically very manual, leading to "Why is this broken for me?" when errors are not obvious (e.g., `Error: Cannot find module '../build/Debug/addon'`). |
| 14 | + |
| 15 | +Since `yarn install` is near instant when dependencies are unchanged, having developers run `yarn install` after a `git pull` is no big deal. However, having developers regularly run `yarn install --force` with many dependencies is a non-starter (1s vs 100s). |
| 16 | + |
| 17 | +# Detailed design |
| 18 | + |
| 19 | +Assuming both a `package.json` and `yarn.lock` in the project's root... |
| 20 | + |
| 21 | +*NOTE: A primed / clean yarn cache and/or `yarn-offline-mirror` are not applicable / relevant.* |
| 22 | + |
| 23 | +**Path A (`node_modules` dne, node@X):** |
| 24 | + |
| 25 | +- `yarn install` => binaries for node@X |
| 26 | + |
| 27 | +**Path B: (`node_modules` installed w/ node@X, node@Y)** |
| 28 | + |
| 29 | +- **Current, non-ideal**: `yarn install` => binaries for node@X |
| 30 | +- **Ideal**: `yarn install` => binaries for **node@Y** |
| 31 | + |
| 32 | + |
| 33 | +# How We Teach This |
| 34 | + |
| 35 | +*What names and terminology work best for these concepts and why?* |
| 36 | + |
| 37 | + "`node_modules`" for node context, "rebuild" & "build" for npm legacy; "idempotent" for technical accuracy; "install" & "force" for yarn context (i.e., `yarn install`). |
| 38 | + |
| 39 | +*How is this idea best presented?* |
| 40 | + |
| 41 | +As a continuation of existing Yarn patterns: "deterministic builds". |
| 42 | + |
| 43 | +*Would the acceptance of this proposal mean the Yarn documentation must be re-organized or altered?* |
| 44 | + |
| 45 | +No. |
| 46 | + |
| 47 | +*Does it change how Yarn is taught to new users at any level?* |
| 48 | + |
| 49 | +Yes. This will all but eliminate the need to explain why rebuilds are needed after an upgrade. |
| 50 | + |
| 51 | +*How should this feature be introduced and taught to existing Yarn users?* |
| 52 | + |
| 53 | +By assuring users: |
| 54 | + |
| 55 | +> `yarn install` ensures a consistent outcome. |
| 56 | +
|
| 57 | +No need to caveat ^ this with: |
| 58 | + |
| 59 | +> Unless you upgraded node, then you need rebuild your binary modules with `yarn install --force`, |
| 60 | +but don't worry about it reinstalling all your modules, even the non-binary ones. |
| 61 | + |
| 62 | +# Drawbacks |
| 63 | + |
| 64 | +Complexity of detection / knowing when to rebuild. |
| 65 | + |
| 66 | +# Alternatives |
| 67 | + |
| 68 | +Use a flag: `yarn install --check-rebuild` and/or support it in `.yarnrc` (`install-check-rebuild true`) |
0 commit comments