2019-05-06 11:31:26 +00:00
|
|
|
---
|
|
|
|
id: 587d7fb4367417b2b2512bff
|
2021-02-16 21:01:20 +00:00
|
|
|
title: 给 package.json 添加版本号
|
2019-05-06 11:31:26 +00:00
|
|
|
challengeType: 2
|
2020-09-17 16:12:32 +00:00
|
|
|
forumTopicId: 301525
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: add-a-version-to-your-package-json
|
2019-05-06 11:31:26 +00:00
|
|
|
---
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --description--
|
|
|
|
|
2021-02-16 21:01:20 +00:00
|
|
|
`version` 是 package.json 文件中必填字段之一, 这个字段描述了当前项目的版本, 如:
|
2020-09-17 16:12:32 +00:00
|
|
|
|
|
|
|
```json
|
|
|
|
"version": "1.2.0",
|
|
|
|
```
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --instructions--
|
2019-05-06 11:31:26 +00:00
|
|
|
|
2021-02-16 21:01:20 +00:00
|
|
|
给 package.json 文件添加项目的版本号(`version`)。
|
2019-05-06 11:31:26 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --hints--
|
2019-05-06 11:31:26 +00:00
|
|
|
|
2021-02-16 21:01:20 +00:00
|
|
|
package.json 应该包含一个有效的 “version” 键
|
2019-05-06 11:31:26 +00:00
|
|
|
|
|
|
|
```js
|
2020-12-16 07:37:30 +00:00
|
|
|
(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);
|
|
|
|
}
|
|
|
|
);
|
2019-05-06 11:31:26 +00:00
|
|
|
```
|
2020-08-13 15:24:35 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --solutions--
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
```js
|
|
|
|
/**
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
```
|