2019-05-06 07:31:26 -04:00
|
|
|
---
|
|
|
|
id: 587d7fb4367417b2b2512bfe
|
2021-02-16 13:01:20 -08:00
|
|
|
title: 给 package.json 添加许可证
|
2019-05-06 07:31:26 -04:00
|
|
|
challengeType: 2
|
2020-09-18 00:12:32 +08:00
|
|
|
forumTopicId: 301523
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: add-a-license-to-your-package-json
|
2019-05-06 07:31:26 -04:00
|
|
|
---
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --description--
|
|
|
|
|
2021-02-16 13:01:20 -08:00
|
|
|
`license` 字段将告知用户允许他们拿这个项目干什么。
|
2020-09-18 00:12:32 +08:00
|
|
|
|
2021-02-16 13:01:20 -08:00
|
|
|
开源项目常见的协议有 MIT 和 BSD 等。 许可证信息并不是必须的。 大多数国家的版权法会默认让你拥有自己创作的作品的所有权。 但是,明确说明用户可以做什么和不能做什么会是一个很好的做法。 这里有一个 license 字段的例子:
|
2019-05-06 07:31:26 -04:00
|
|
|
|
2021-02-06 04:42:36 +00:00
|
|
|
```json
|
2020-12-16 00:37:30 -07:00
|
|
|
"license": "MIT",
|
2021-02-06 04:42:36 +00:00
|
|
|
```
|
2019-05-06 07:31:26 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --instructions--
|
2019-05-06 07:31:26 -04:00
|
|
|
|
2021-02-16 13:01:20 -08:00
|
|
|
在项目的 package.json 文件中补充合适的 `license` 字段。
|
2020-12-16 00:37:30 -07:00
|
|
|
|
|
|
|
# --hints--
|
2019-05-06 07:31:26 -04:00
|
|
|
|
2021-02-16 13:01:20 -08:00
|
|
|
package.json 应该包含一个有效的“license”键
|
2019-05-06 07:31:26 -04:00
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
(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);
|
|
|
|
}
|
|
|
|
);
|
2019-05-06 07:31:26 -04:00
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --solutions--
|
|
|
|
|
2021-01-13 03:31:00 +01: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.
|
|
|
|
*/
|
|
|
|
```
|