freeCodeCamp/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/expand-your-project-with-ex...

1.8 KiB
Raw Blame History

id title localeTitle challengeType
587d7fb4367417b2b2512c00 Expand Your Project with External Packages from npm 从npm扩展您的项目与外部包 2

Description

0使用包管理器的一个最大原因是它们强大的依赖关系管理。 npm无需手动确保在新计算机上设置项目时获得所有依赖项npm会自动为您安装所有内容。但是npm怎么能确切地知道你的项目需要什么呢遇到package.json的依赖项部分。 0在dependencies-section中使用以下格式存储项目所需的包 "dependencies": { "package-name": "version", "express": "4.14.0" } 0指令0将软件包时刻的2.14.0版本添加到package.json的依赖项字段中 Moment是一个方便的库用于处理时间和日期。

Instructions

Tests

tests:
  - text: '“依赖”应该包括“时刻”'
    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: '“时刻”版本应为“2.14.0”'
    testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data);  assert.match(packJson.dependencies.moment, /^[\^\~]?2\.14\.0/, ''Wrong version of "moment" installed. It should be 2.14.0''); }, xhr => { throw new Error(xhr.responseText); })'

Challenge Seed

Solution

// solution required