freeCodeCamp/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/manage-npm-dependencies-by-...

2.5 KiB
Raw Blame History

id title challengeType forumTopicId dashedName
587d7fb5367417b2b2512c01 通过语义化版本来管理 npm 依赖关系 2 301529 manage-npm-dependencies-by-understanding-semantic-versioning

--description--

在 package.json 文件的依赖项中npm 包的 Versions 遵循语义化版本SemVerSemantic Versioning它是一种旨在使管理依赖项更加容易的软件版本控制的行业标准。 在 npm 上发布的库、框架或其它工具都应该使用语义化版本,以便让用户清晰地知道如果项目升级将带来哪些改变。

在使用外部依赖项(大多数情况都是这样)进行软件开发时,了解语义化版本会很有用。 这些数字保存着项目的偶然发生的破坏性改变,不会让人对项目昨天还正常,今天却无法运行而百思不解。 根据官网,这是语义化版本的工作方式:

"package": "MAJOR.MINOR.PATCH"

当做了不兼容的 API 修改应该增加主版本号MAJOR 当新增了向下兼容的新功能时应该增加次版本号MINOR 当修复了向下兼容的 bug 时应该增加修订号PATCH。 这意味着修订号是用来修复错误的,次版本号则是添加了新功能,但它们都没有破坏之前的功能。 主版本号MAJOR是添加了不兼容早期版本的更改。

--instructions--

在 package.json 文件的依赖项中,修改 moment 的version,让它的主版本是 2次版本号是 10修订号是 2。

--hints--

“dependencies”字段应该包含“moment”

(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);
    }
  );

“moment”的版本号应该是“2.10.2”

(getUserInput) =>
  $.get(getUserInput('url') + '/_api/package.json').then(
    (data) => {
      var packJson = JSON.parse(data);
      assert.equal(
        packJson.dependencies.moment,
        '2.10.2',
        'Wrong version of "moment". It should be 2.10.2'
      );
    },
    (xhr) => {
      throw new Error(xhr.responseText);
    }
  );

--solutions--

/**
  Backend challenges don't need solutions, 
  because they would need to be tested against a full working project. 
  Please check our contributing guidelines to learn more.
*/