freeCodeCamp/curriculum/challenges/english/05-apis-and-microservices/managing-packages-with-npm/use-the-tilde-character-to-...

48 lines
2.1 KiB
Markdown
Raw Normal View History

2018-10-25 18:29:56 +00:00
---
id: 587d7fb5367417b2b2512c02
title: Use the Tilde-Character to Always Use the Latest Patch Version of a Dependency
challengeType: 2
---
## Description
<section id='description'>
In the last challenge, we told npm to only include a specific version of a package. Thats a useful way to freeze your dependencies if you need to make sure that different parts of your project stay compatible with each other. But in most use cases you dont want to miss bug fixes, since they often include important security patches and (hopefully) dont break things in doing so.
To allow a npm dependency to get updated to the latest PATCH-version, you can prefix the dependencys version with the tilde-character (~). In package.json, our current rule for how npm may upgrade moment is to use a specific version only (2.10.2), but we want to allow the latest 2.10.x-version.
Example
<code>"some-package-name": "~1.3.8" allows updates to any 1.3.x version.</code>
Instructions
Use the tilde-character (~) to prefix the version of moment in your dependencies and allow npm to update it to any new PATCH release.
Note that the version numbers themselves not should be changed.
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
- text: '"dependencies" should include "moment"'
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.property(packJson.dependencies, ''moment'', ''"dependencies" does not include "moment"''); }, xhr => { throw new Error(xhr.responseText); })'
- text: '"moment" version should match "~2.10.2"'
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.match(packJson.dependencies.moment, /^\~2\.10\.2/, ''Wrong version of "moment". It should be ~2.10.2''); }, xhr => { throw new Error(xhr.responseText); })'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>