Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
6.3 KiB

  1. npm-package-locks(5) -- An explanation of npm lockfiles
  2. =====================================================
  3. ## DESCRIPTION
  4. Conceptually, the "input" to npm-install(1) is a package.json(5), while its
  5. "output" is a fully-formed `node_modules` tree: a representation of the
  6. dependencies you declared. In an ideal world, npm would work like a pure
  7. function: the same `package.json` should produce the exact same `node_modules`
  8. tree, any time. In some cases, this is indeed true. But in many others, npm is
  9. unable to do this. There are multiple reasons for this:
  10. * different versions of npm (or other package managers) may have been used to install a package, each using slightly different installation algorithms.
  11. * a new version of a direct semver-range package may have been published since the last time your packages were installed, and thus a newer version will be used.
  12. * A dependency of one of your dependencies may have published a new version, which will update even if you used pinned dependency specifiers (`1.2.3` instead of `^1.2.3`)
  13. * The registry you installed from is no longer available, or allows mutation of versions (unlike the primary npm registry), and a different version of a package exists under the same version number now.
  14. As an example, consider package A:
  15. {
  16. "name": "A",
  17. "version": "0.1.0",
  18. "dependencies": {
  19. "B": "<0.1.0"
  20. }
  21. }
  22. package B:
  23. {
  24. "name": "B",
  25. "version": "0.0.1",
  26. "dependencies": {
  27. "C": "<0.1.0"
  28. }
  29. }
  30. and package C:
  31. {
  32. "name": "C",
  33. "version": "0.0.1"
  34. }
  35. If these are the only versions of A, B, and C available in the
  36. registry, then a normal `npm install A` will install:
  37. A@0.1.0
  38. `-- B@0.0.1
  39. `-- C@0.0.1
  40. However, if B@0.0.2 is published, then a fresh `npm install A` will
  41. install:
  42. A@0.1.0
  43. `-- B@0.0.2
  44. `-- C@0.0.1
  45. assuming the new version did not modify B's dependencies. Of course,
  46. the new version of B could include a new version of C and any number
  47. of new dependencies. If such changes are undesirable, the author of A
  48. could specify a dependency on B@0.0.1. However, if A's author and B's
  49. author are not the same person, there's no way for A's author to say
  50. that he or she does not want to pull in newly published versions of C
  51. when B hasn't changed at all.
  52. To prevent this potential issue, npm uses package-lock.json(5) or, if present,
  53. npm-shrinkwrap.json(5). These files are called package locks, or lockfiles.
  54. Whenever you run `npm install`, npm generates or updates your package lock,
  55. which will look something like this:
  56. {
  57. "name": "A",
  58. "version": "0.1.0",
  59. ...metadata fields...
  60. "dependencies": {
  61. "B": {
  62. "version": "0.0.1",
  63. "resolved": "https://registry.npmjs.org/B/-/B-0.0.1.tgz",
  64. "integrity": "sha512-DeAdb33F+"
  65. "dependencies": {
  66. "C": {
  67. "version": "git://github.com/org/C.git#5c380ae319fc4efe9e7f2d9c78b0faa588fd99b4"
  68. }
  69. }
  70. }
  71. }
  72. }
  73. This file describes an *exact*, and more importantly *reproducible*
  74. `node_modules` tree. Once it's present, any future installation will base its
  75. work off this file, instead of recalculating dependency versions off
  76. package.json(5).
  77. The presence of a package lock changes the installation behavior such that:
  78. 1. The module tree described by the package lock is reproduced. This means
  79. reproducing the structure described in the file, using the specific files
  80. referenced in "resolved" if available, falling back to normal package resolution
  81. using "version" if one isn't.
  82. 2. The tree is walked and any missing dependencies are installed in the usual
  83. fashion.
  84. If `preshrinkwrap`, `shrinkwrap` or `postshrinkwrap` are in the `scripts`
  85. property of the `package.json`, they will be executed in order. `preshrinkwrap`
  86. and `shrinkwrap` are executed before the shrinkwrap, `postshrinkwrap` is
  87. executed afterwards. These scripts run for both `package-lock.json` and
  88. `npm-shrinkwrap.json`. For example to run some postprocessing on the generated
  89. file:
  90. "scripts": {
  91. "postshrinkwrap": "json -I -e \"this.myMetadata = $MY_APP_METADATA\""
  92. }
  93. ### Using locked packages
  94. Using a locked package is no different than using any package without a package
  95. lock: any commands that update `node_modules` and/or `package.json`'s
  96. dependencies will automatically sync the existing lockfile. This includes `npm
  97. install`, `npm rm`, `npm update`, etc. To prevent this update from happening,
  98. you can use the `--no-save` option to prevent saving altogether, or
  99. `--no-shrinkwrap` to allow `package.json` to be updated while leaving
  100. `package-lock.json` or `npm-shrinkwrap.json` intact.
  101. It is highly recommended you commit the generated package lock to source
  102. control: this will allow anyone else on your team, your deployments, your
  103. CI/continuous integration, and anyone else who runs `npm install` in your
  104. package source to get the exact same dependency tree that you were developing
  105. on. Additionally, the diffs from these changes are human-readable and will
  106. inform you of any changes npm has made to your `node_modules`, so you can notice
  107. if any transitive dependencies were updated, hoisted, etc.
  108. ### Resolving lockfile conflicts
  109. Occasionally, two separate npm install will create package locks that cause
  110. merge conflicts in source control systems. As of `npm@5.7.0`, these conflicts
  111. can be resolved by manually fixing any `package.json` conflicts, and then
  112. running `npm install [--package-lock-only]` again. npm will automatically
  113. resolve any conflicts for you and write a merged package lock that includes all
  114. the dependencies from both branches in a reasonable tree. If
  115. `--package-lock-only` is provided, it will do this without also modifying your
  116. local `node_modules/`.
  117. To make this process seamless on git, consider installing
  118. [`npm-merge-driver`](https://npm.im/npm-merge-driver), which will teach git how
  119. to do this itself without any user interaction. In short: `$ npx
  120. npm-merge-driver install -g` will let you do this, and even works with
  121. pre-`npm@5.7.0` versions of npm 5, albeit a bit more noisily. Note that if
  122. `package.json` itself conflicts, you will have to resolve that by hand and run
  123. `npm install` manually, even with the merge driver.
  124. ## SEE ALSO
  125. * https://medium.com/@sdboyer/so-you-want-to-write-a-package-manager-4ae9c17d9527
  126. * package.json(5)
  127. * package-lock.json(5)
  128. * npm-shrinkwrap.json(5)
  129. * npm-shrinkwrap(1)