diff --git a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/add-a-description-to-your-package.json.chinese.md b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/add-a-description-to-your-package.json.chinese.md index faf371ce41..e5dab0a270 100644 --- a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/add-a-description-to-your-package.json.chinese.md +++ b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/add-a-description-to-your-package.json.chinese.md @@ -1,18 +1,27 @@ --- id: 587d7fb3367417b2b2512bfc title: Add a Description to Your package.json -localeTitle: 在package.json中添加一个描述 challengeType: 2 +forumTopicId: 301522 +localeTitle: 给 package.json 添加一个描述 --- ## Description -
0一个好的package.json的下一部分是description-field,其中有关于您的项目的简短但信息丰富的描述。 0如果您有一天计划将软件包发布到npm,请记住这是一个字符串,当他们决定是否安装您的软件包时,应该将该想法卖给用户。然而,这并不是描述的唯一用例:这是总结项目工作的一种很好的方式,对于正常的Node.js项目来说,这对于帮助其他开发人员,未来的维护人员甚至是您未来的自我来理解项目同样重要很快。 0无论您对项目的计划是什么,都建议您使用说明。让我们添加类似的东西: -"description": "A project that does something awesome", 0说明0在Glitch项目中向package.json添加一个描述。 0记住要使用双引号场名称(“)和逗号(,)分隔的字段。 +
+一个好的 package.json 文件的下一部分就是 description 字段,通过简洁的文字来描述你的项目。 +如果你计划将来把这个包发布到 npm,请注意 description 字段的作用是告知用户这个包的用途,这样用户就可以决定是否要安装你发布的包。然而,这并不是描述信息的唯一使用场景:它也是一种很好的总结项目的方式,对于一个普通的 Node.js 项目来说,它可以帮助其它开发者、未来的维护者以及你自己快速地了解项目,这同样非常重要。 +无论你如何计划项目,都建议你使用描述信息。我们来添加类似这样的信息: + +```json +"description": "A project that does something awesome", +``` +
## Instructions -
- +
+在 Glitch 项目的 package.json 中添加描述。 +请记住使用(")包裹字段名并且使用(,)分隔字段。
## Tests @@ -20,7 +29,7 @@ challengeType: 2 ```yml tests: - - text: package.json应该有一个有效的“描述”键 + - text: "package.json 应该有一个有效的 'description' 键。" testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert(packJson.description, ''"description" is missing''); }, xhr => { throw new Error(xhr.responseText); })' ``` @@ -36,7 +45,11 @@ tests:
```js -// solution required +/** + 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. +*/ ``` -/section> +
? diff --git a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/add-a-license-to-your-package.json.chinese.md b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/add-a-license-to-your-package.json.chinese.md index f71c33e5ec..4c84d60564 100644 --- a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/add-a-license-to-your-package.json.chinese.md +++ b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/add-a-license-to-your-package.json.chinese.md @@ -1,18 +1,26 @@ --- id: 587d7fb4367417b2b2512bfe title: Add a License to Your package.json -localeTitle: 向package.json添加许可证 challengeType: 2 +forumTopicId: 301523 +localeTitle: 给 package.json 添加许可证 --- ## Description -
0许可证字段用于通知项目用户他们可以使用它做什么。 0开源项目的一些常见许可证包括MIT和BSD。如果您想了解更多适合您项目的许可证,http://choosealicense.com是一个很好的资源。 0不需要许可证信息。大多数国家/地区的版权法都将授予您默认创建的所有权。但是,明确说明用户可以做什么和不做什么总是一个好习惯。 0示例 -"license": "MIT", 0说明0如果您认为合适,请填写Glitch项目的package.json中的license-field。 +
+license 字段是你告知用户允许他们拿这个项目干什么的地方。 +常见的开源协议是 MIT 和 BSD。如果你想了解更多适合你项目的许可证的信息,那么 http://choosealicense.com 是一个不错的网站。 +许可证信息并不是必须的。大多数国家的版权法会默认让你拥有自己创作的作品的所有权。但是,明确说明用户可以做什么和不能做什么会是一个很好的做法。 +以下是一个 license 字段的示例: +```json +"license": "MIT", +``` +
## Instructions -
- +
+在 Glitch 项目的 package.json 中填写合适的 license 字段。
## Tests @@ -20,7 +28,7 @@ challengeType: 2 ```yml tests: - - text: package.json应该有一个有效的“许可证”密钥 + - text: "package.json 应该有一个有效的 'license' 键。" testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert(packJson.license, ''"license" is missing''); }, xhr => { throw new Error(xhr.responseText); })' ``` @@ -36,7 +44,11 @@ tests:
```js -// solution required +/** + 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. +*/ ``` -/section> +
diff --git a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/add-a-version-to-your-package.json.chinese.md b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/add-a-version-to-your-package.json.chinese.md index 1fbc1550fe..2cc33cec5d 100644 --- a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/add-a-version-to-your-package.json.chinese.md +++ b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/add-a-version-to-your-package.json.chinese.md @@ -1,18 +1,24 @@ --- id: 587d7fb4367417b2b2512bff title: Add a Version to Your package.json -localeTitle: 在package.json中添加一个版本 challengeType: 2 +forumTopicId: 301525 +localeTitle: 给 package.json 添加版本号 --- ## Description -
0该版本与package.json中必填字段之一一起。该字段描述了项目的当前版本。 0示例 -"version": "1.2", 0说明0在Glitch项目中向package.json添加版本。 +
+在 package.json 中 version 和 name 是所必填的字段之一。version 字段描述了当前项目的版本。 + +```json +"version": "1.2.0", +``` +
## Instructions -
- +
+在 Glitch 项目中的 package.json 中添加一个版本号。
## Tests @@ -20,7 +26,7 @@ challengeType: 2 ```yml tests: - - text: package.json应该有一个有效的“版本”密钥 + - text: "package.json 应该包含一个有效的 'version' 键。" testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert(packJson.version, ''"version" is missing''); }, xhr => { throw new Error(xhr.responseText); })' ``` @@ -36,7 +42,11 @@ tests:
```js -// solution required +/** + 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. +*/ ``` -/section> +
diff --git a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/add-keywords-to-your-package.json.chinese.md b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/add-keywords-to-your-package.json.chinese.md index 113bee0e7d..18adc2fbc5 100644 --- a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/add-keywords-to-your-package.json.chinese.md +++ b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/add-keywords-to-your-package.json.chinese.md @@ -1,19 +1,26 @@ --- id: 587d7fb4367417b2b2512bfd title: Add Keywords to Your package.json -localeTitle: 将关键字添加到package.json challengeType: 2 +forumTopicId: 301526 +localeTitle: 给 package.json 添加关键词 --- ## Description -
-keywords-field是您可以使用相关关键字描述项目的地方。 0示例 -"keywords": [ "descriptive", "related", "words" ], 0如您所见,此字段的结构为双引号字符串数组。 0说明0将一组合适的字符串添加到Glitch项目的package.json中的keywords-field。 0其中一个关键字应该是freecodecamp。 +
+你可以在 keywords 字段中使用相关的关键字描述项目。 + +```json +"keywords": [ "descriptive", "related", "words" ], +``` + +正如你所见,这个字段的结构是一个由双引号字符串组成的数组。
## Instructions -
- +
+在 Glitch 项目的 package.json 中,给 keywords 添加适当的字符串数组。 +关键词之一应该是 freecodecamp。
## Tests @@ -21,11 +28,11 @@ keywords-field是您可以使用相关关键字描述项目的地方。 0< ```yml tests: - - text: package.json应该有一个有效的“关键字”键 + - text: "package.json 应该有一个有效的 'keywords' 键。" testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert(packJson.keywords, ''"keywords" is missing''); }, xhr => { throw new Error(xhr.responseText); })' - - text: '“keywords”字段应为Array' + - text: "'keywords' 应该是一个数组。" testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.isArray(packJson.keywords, ''"keywords" is not an array''); }, xhr => { throw new Error(xhr.responseText); })' - - text: '“关键字”应包含“freecodecamp”' + - text: "'keywords' 中应该包含关键词 'freecodecamp'。" testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.include(packJson.keywords, ''freecodecamp'', ''"keywords" does not include "freecodecamp"''); }, xhr => { throw new Error(xhr.responseText); })' ``` @@ -41,7 +48,11 @@ tests:
```js -// solution required +/** + 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. +*/ ``` -/section> +
diff --git a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/expand-your-project-with-external-packages-from-npm.chinese.md b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/expand-your-project-with-external-packages-from-npm.chinese.md index 4361c3c70f..209af13391 100644 --- a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/expand-your-project-with-external-packages-from-npm.chinese.md +++ b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/expand-your-project-with-external-packages-from-npm.chinese.md @@ -1,22 +1,30 @@ --- id: 587d7fb4367417b2b2512c00 title: Expand Your Project with External Packages from npm -localeTitle: 从npm扩展您的项目与外部包 challengeType: 2 +forumTopicId: 301527 +localeTitle: 使用 npm 的外部软件包扩展您的项目 --- ## 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是一个方便的库,用于处理时间和日期。 +
+使用包管理器的最大原因之一是它们强大的依赖管理特性。在新的计算机上开始一个项目时,不用手动确认你已安装所有的依赖,npm 会自动为你安装它们。但是 npm 如何准确的知道你项目需要哪些依赖呢?我们来看看 package.json 中 dependencies 这一部分。 +在 dependencies 这一部分,你的项目需要按照下面这种格式来存储这些依赖包: + +```json +"dependencies": { + "package-name": "version", + "express": "4.14.0" +} + +``` +
## Instructions -
- +
+在 package.json 的 dependencies 字段中添加一个版本号为 2.14.0 的 moment 包。 +Moment 是一个非常方便的库,它用来处理时间和日期。
## Tests @@ -24,9 +32,9 @@ Moment是一个方便的库,用于处理时间和日期。 ```yml tests: - - text: '“依赖”应该包括“时刻”' + - text: "'dependencies' 应该包含 '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: '“时刻”版本应为“2.14.0”' + - text: "'moment' 的版本应该是 '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); })' ``` @@ -42,7 +50,11 @@ tests:
```js -// solution required +/** + 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. +*/ ``` -/section> +
diff --git a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/how-to-use-package.json-the-core-of-any-node.js-project-or-npm-package.chinese.md b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/how-to-use-package.json-the-core-of-any-node.js-project-or-npm-package.chinese.md index e3bdd6a203..1e89c162d9 100644 --- a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/how-to-use-package.json-the-core-of-any-node.js-project-or-npm-package.chinese.md +++ b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/how-to-use-package.json-the-core-of-any-node.js-project-or-npm-package.chinese.md @@ -1,18 +1,28 @@ --- id: 587d7fb3367417b2b2512bfb title: 'How to Use package.json, the Core of Any Node.js Project or npm Package' -localeTitle: '如何使用package.json,任何Node.js项目的核心或npm包' challengeType: 2 +forumTopicId: 301528 +localeTitle: 如何使用 package.json —— 任何 Node.js 项目或 npm 包的核心 --- ## Description -
0文件package.json是任何Node.js项目或npm包的中心。它存储有关项目的信息,就像HTML文档中的<head> -section描述网页内容一样。 package.json由一个JSON对象组成,其中信息存储在“key”:value-pairs中。最小的package.json中只有两个必填字段 - 名称和版本 - 但提供有关您的项目的其他信息可能对未来的用户或维护者有用,这是一个很好的做法。 0作者字段0如果您转到之前设置的Glitch项目并在屏幕左侧查看,您将找到文件树,您可以在其中查看项目中各种文件的概述。在文件树的后端部分,你会找到package.json - 我们将在接下来的几个挑战中改进的文件。 0此文件中最常见的信息之一是author-field,它指定了谁是项目的创建者。它可以是字符串,也可以是具有联系人详细信息的对象。对于较大的项目,建议使用该对象,但在我们的示例中,将使用类似以下示例的简单字符串。 -"author": "Jane Doe", 0说明0将您的名字添加到Glitch项目的package.json中的author-field。 0记住你正在编写JSON。 0所有字段名称必须使用双引号(“),例如”author“ 0所有字段必须用逗号分隔(,) +
+package.json 是任何 Node.js 项目或 npm 包的中心。它存储项目的相关信息,就像 HTML 文档中的 <head> 区域是用来描述网页的通用信息(元信息)一样。package.json 由单个 JSON 对象组成,它以键值对的形式存储项目的信息。一个最小的 package.json 文件至少包含两个必须字段:name 和 version——但是提供有关项目的附加信息是一个更好的做法,在以后它可能对你的用户或者维护者有所帮助。 +author 字段: +如果你转到之前设置的 Glitch 项目并查看屏幕左侧,你会看到一个文件树,你可以在其中查看项目中各种文件的概述。在文件树的末尾部分,你会看到 package.json——我们将在接下来的几个挑战中改进这个文件。 +这个文件中最常见的信息之一是 author 字段,它指定了谁是项目的创建者。它可以是字符串,也可以是带有联系人详细信息的对象。对于较大的项目,建议使用对象,但是在我们的例子中,一个简单的字符串就可以了,比如下面的例子。 + +```json +"author": "Jane Doe", +``` +
## Instructions -
- +
+将你的名字添加到 Glitch 项目中,package.json 的 author 字段。 +注意: 请记住,你正在编写 JSON 文件。所有的字段名必须使用双引号(")包裹, 比如:"author",所有字段必须用逗号(,)分隔。
## Tests @@ -20,7 +30,7 @@ challengeType: 2 ```yml tests: - - text: package.json应该有一个有效的“作者”密钥 + - text: "package.json 应该有一个有效的 'author' 键。" testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert(packJson.author, ''"author" is missing''); }, xhr => { throw new Error(xhr.responseText); })' ``` @@ -36,7 +46,11 @@ tests:
```js -// solution required +/** + 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. +*/ ``` -/section> +
diff --git a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/manage-npm-dependencies-by-understanding-semantic-versioning.chinese.md b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/manage-npm-dependencies-by-understanding-semantic-versioning.chinese.md index 4d45123ca1..69d2c7fd1d 100644 --- a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/manage-npm-dependencies-by-understanding-semantic-versioning.chinese.md +++ b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/manage-npm-dependencies-by-understanding-semantic-versioning.chinese.md @@ -1,22 +1,29 @@ --- id: 587d7fb5367417b2b2512c01 title: Manage npm Dependencies By Understanding Semantic Versioning -localeTitle: 通过了解语义版本控制来管理npm依赖项 challengeType: 2 +forumTopicId: 301529 +localeTitle: 通过理解语义版本化来管理 npm 依赖关系 --- ## Description -
-package.json的dependencies-section中的npm软件包的版本遵循所谓的语义版本控制(SemVer),这是软件版本控制的行业标准,旨在使管理依赖项更容易。在npm上发布的库,框架或其他工具应使用SemVer,以便清楚地传达依赖于程序包的项目在更新时可以期望的更改类型。 -SemVer在没有公共API的项目中没有意义 - 所以除非你的项目与上面的例子类似,否则使用另一种版本控制格式。 0那么为什么你需要了解SemVer? 0了解SemVer在开发使用外部依赖项的软件时非常有用(您几乎总是这样做)。有一天,您对这些数字的理解将使您免于意外地对项目进行重大更改而不理解为什么“昨天有效”的事情突然之间没有。 0这是语义版本控制根据官方网站的工作方式: 0给定版本号MAJOR.MINOR.PATCH,当您进行不兼容的API更改时,增加: -MAJOR版本,当以向后兼容的方式添加功能时,增加 -MINOR版本,当您进行向后兼容的错误修复时,和 -PATCH版本。 0这意味着PATCH是错误修复,MINOR添加了新功能,但它们都没有破坏之前的功能。最后,MAJOR添加了对早期版本无效的更改。 0示例0语义版本号:1.3.8 0说明0在package.json的dependencies-section中,更改时刻版本以匹配MAJOR版本2,MINOR版本10和PATCH版本2 +
+在 package.json 中,dependencies 这部分的 npm 包的版本号遵循所谓的语义化版本(SemVer),它是一种软件版本控制的行业标准,旨在使管理依赖项更加容易。在 npm 上发布的库、框架或其它工具都应该使用语义化版本(SemVer),以便让使用该依赖包的用户能够在依赖包需要升级时,提前规划自己的项目需要为之做出的改动。 +在开发使用外部依赖项的软件(大多数情况都是这样)时,了解语义化版本(SemVer)会很有用。有一天你会明白这些数字的含义,在项目中它可以避免你意外地引入一些非向下兼容的更改,同时也能避免“昨天还能好好的运行,今天就不行了”这种情况发生。 + +```json +"package": "MAJOR.MINOR.PATCH" +``` + +主版本号 MAJOR:当你做了不向下兼容的公共 API 修改, +次版本号 MINOR:当你添加了向下兼容的新功能, +修订号 PATCH:当你做了向下兼容的问题修正。 +这意味着修订号是用来修复错误的,次版本号则是添加了新功能,但它们都没有破坏之前的功能。最后,主版本号的变更则是添加了对早期版本不兼容的更改。
## Instructions -
- +
+在 package.json 中,修改 dependencies 里的 moment 的版本号,让它的主版本是 2,次版本号是 10,修订号是 2。
## Tests @@ -24,9 +31,9 @@ PATCH版本。 0这意味着PATCH是错误修复,MINOR添加了 ```yml tests: - - text: '“依赖”应该包括“时刻”' + - text: "'dependencies' 应该包含 '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: '“时刻”版应该是“2.10.2”' + - text: "'moment' 的版本号应该是 '2.10.2'。" testString: '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); })' ``` @@ -42,7 +49,11 @@ tests:
```js -// solution required +/** + 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. +*/ ``` -/section> +
diff --git a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/remove-a-package-from-your-dependencies.chinese.md b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/remove-a-package-from-your-dependencies.chinese.md index 4e283d4e3d..542049cbe5 100644 --- a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/remove-a-package-from-your-dependencies.chinese.md +++ b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/remove-a-package-from-your-dependencies.chinese.md @@ -1,17 +1,22 @@ --- id: 587d7fb5367417b2b2512c04 title: Remove a Package from Your Dependencies -localeTitle: 从您的依赖项中删除一个包 challengeType: 2 +forumTopicId: 301530 +localeTitle: 从依赖项中删除包 --- ## Description -
0现在,您已经通过使用package.json的dependencies-section测试了一些可以管理项目依赖关系的方法。您已将外部包添加到文件中,甚至通过使用特殊字符作为代字号(〜)或插入符号(^)告诉npm您需要哪些类型的版本。 0但是如果你想删除不再需要的外部包呢?您可能已经猜到了 - 只需从依赖项中删除相应的“key”:value对。 0同样的方法也适用于删除package.json中的其他字段0说明0从依赖项中删除包时刻。 0删除后确保您有相同数量的逗号。 +
+在 package.json 中 dependencies 这一部分,目前尝试了一些管理依赖的方式。你已经添加了一些外部的依赖包到项目中,甚至通过一些特殊的字符比如波浪符号(~)或者插入符号(^)来告诉 npm 你想要的版本类型。 +但是,如果想要删除不需要的依赖包,该怎么办呢?你可能已经猜到了——只需要删除 dependencies 中的键值对就行了。 +同样的方法也适用于删除 package.json 中的其它字段
## Instructions -
- +
+删除 moment 依赖包。 +删除依赖包后,确保没有多余的逗号。
## Tests @@ -19,7 +24,7 @@ challengeType: 2 ```yml tests: - - text: '“依赖”不应该包括“时刻”' + - text: "'dependencies' 不包含 'moment'。" testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.notProperty(packJson.dependencies, ''moment'', ''"dependencies" still includes "moment"''); }, xhr => { throw new Error(xhr.responseText); })' ``` @@ -35,7 +40,11 @@ tests:
```js -// solution required +/** + 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. +*/ ``` -/section> +
diff --git a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/use-the-caret-character-to-use-the-latest-minor-version-of-a-dependency.chinese.md b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/use-the-caret-character-to-use-the-latest-minor-version-of-a-dependency.chinese.md index e9b0507682..c6d0076e99 100644 --- a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/use-the-caret-character-to-use-the-latest-minor-version-of-a-dependency.chinese.md +++ b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/use-the-caret-character-to-use-the-latest-minor-version-of-a-dependency.chinese.md @@ -1,18 +1,27 @@ --- id: 587d7fb5367417b2b2512c03 title: Use the Caret-Character to Use the Latest Minor Version of a Dependency -localeTitle: 使用插入符号来使用最新的次要版本的依赖项 challengeType: 2 +forumTopicId: 301531 +localeTitle: 用插入字符可以使用依赖项的最新次要版本 --- ## Description -
0类似于我们在上一次挑战中学到的波形符(〜)允许npm为依赖项安装最新的PATCH,插入符号(^)允许npm也安装将来的更新。不同之处在于插入符号将允许MINOR更新和PATCH。 0目前,您当前版本的时刻应为~2.10.2,允许npm安装到最新的2.10.x版本。如果我们改为使用插入符号(^)作为我们的版本前缀,则允许npm更新为任何2.xx版本。 0示例 -"some-package-name": "^1.3.8" allows updates to any 1.xx version. 0使用说明0使用插入符(^)为依赖项中的时刻版本添加前缀,并允许npm将其更新为任何新的MINOR版本。 0请注意,不应更改版本号本身。 +
+和上一个挑战中我们学到的波浪符号(~)来安装最新的修订版依赖一样,使用插入符号(^)允许 npm 来安装功能更新。它们的不同之处在于:插入符号(^)允许次版本和修订版更新。 +此刻,你项目中的 moment 依赖包的版本应该是 ~2.10.2,这意味着 npm 可以安装 2.10.x 版的 moment,如果使用插入符号(^)来替换版本号的前缀,那么 npm 可以安装的版本则是 2.x.x。 + +```json +"package": "^1.3.8" +``` + +这会更新 package 到任意的 1.x.x 版本。
## Instructions -
- +
+使用插入符号(^)为依赖项中的 moment 版本添加前缀,允许 npm 更新依赖包到任意向下兼容的新功能版。 +请注意,原本的版本号不用更改。
## Tests @@ -20,9 +29,9 @@ challengeType: 2 ```yml tests: - - text: '“依赖”应该包括“时刻”' + - text: "'dependencies' 应包含 '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”版本应匹配“^ 2.x.x”' + - text: "'moment' 的版本应匹配 '^2.x.x'。" testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/package.json'').then(data => { var packJson = JSON.parse(data); assert.match(packJson.dependencies.moment, /^\^2\./, ''Wrong version of "moment". It should be ^2.10.2''); }, xhr => { throw new Error(xhr.responseText); })' ``` @@ -38,7 +47,12 @@ tests:
```js -// solution required +/** + 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. +*/ ``` -/section> +
+ diff --git a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/use-the-tilde-character-to-always-use-the-latest-patch-version-of-a-dependency.chinese.md b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/use-the-tilde-character-to-always-use-the-latest-patch-version-of-a-dependency.chinese.md index 4fa7b79975..7b8bb95e20 100644 --- a/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/use-the-tilde-character-to-always-use-the-latest-patch-version-of-a-dependency.chinese.md +++ b/curriculum/challenges/chinese/05-apis-and-microservices/managing-packages-with-npm/use-the-tilde-character-to-always-use-the-latest-patch-version-of-a-dependency.chinese.md @@ -1,18 +1,27 @@ --- id: 587d7fb5367417b2b2512c02 title: Use the Tilde-Character to Always Use the Latest Patch Version of a Dependency -localeTitle: 使用Tilde-Character始终使用依赖项的最新修补程序版本 challengeType: 2 +forumTopicId: 301532 +localeTitle: 用波浪字符始终使用依赖项的最新补丁版本 --- ## Description -
0在上一次挑战中,我们告诉npm只包含特定版本的软件包。如果您需要确保项目的不同部分保持彼此兼容,那么这是一种冻结依赖关系的有用方法。但在大多数用例中,您不希望错过错误修复,因为它们通常包含重要的安全补丁,并且(希望)不会破坏这样做。 0要允许npm依赖项更新到最新的PATCH版本,可以使用波形符(〜)为依赖项的版本添加前缀。在package.json中,我们关于npm如何升级时刻的当前规则是仅使用特定版本(2.10.2),但我们希望允许最新的2.10.x版本。 0示例 -"some-package-name": "~1.3.8" allows updates to any 1.3.x version. 0指令0使用波形符(〜)为依赖项中的时刻版本添加前缀,并允许npm将其更新为任何新的PATCH版本。 0请注意,不应更改版本号本身。 +
+在最后一个挑战中,我们告诉 npm 只包含特定版本的依赖包。如果想让项目各个部分保持相互兼容,锁定依赖包版本是一个有效的办法。但是大多数情况下,我们并不希望错过依赖项的问题修复,因为它们通常包含重要的安全补丁,而且它们理论上也会兼容我们既有的代码。 +为了让 npm 依赖项更新到最新的修订版,你可以在依赖包的版本号前加一个波浪符号(~)。在 package.json 中,我们当前的 moment 依赖包更新规则是:仅使用特定版本(2.10.2),但我们想用它最新的 2.10.x 版本。 + +```json +"package": "~1.3.8" +``` +
## Instructions -
- +
+在 package.json 文件中,当前有关 npm 如何升级的规则是使用特定版本(2.10.2)。 但是现在,要允许使用最新的2.10.x版本。 +在 dependencies 中,给 moment 的版本号添加波浪符号(~)前缀,允许 npm 将其更新为最新的修订版。 +请注意,原本的版本号不用更改。
## Tests @@ -20,9 +29,9 @@ challengeType: 2 ```yml tests: - - text: '“依赖”应该包括“时刻”' + - text: "'dependencies' 应该包含 '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: '“时刻”版本应匹配“~2.10.2”' + - text: "'moment' 的版本号应该是 '~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); })' ``` @@ -38,7 +47,11 @@ tests:
```js -// solution required +/** + 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. +*/ ``` -/section> +