Skip to content

Commit

Permalink
♻️ Sort field & Spport CLI (#296)
Browse files Browse the repository at this point in the history
之前的方式添加看了头皮发麻,大家添加的都很随意,也没有按照字母进行排序。


1. 使用 eslint 规则解决排序问题
2. 添加 CLI 方便用户直接命令行添加(开发者不需要处理排序问题

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Introduced a command-line interface (CLI) utility for adding packages
and scopes.
- Enhanced `README.md` with clearer instructions and examples for
managing packages via CLI.
  
- **Bug Fixes**
- Updated `.gitignore` to exclude `package_draft.json`, preventing
unnecessary tracking.

- **Refactor**
- Replaced the old ESLint configuration with a new setup that improves
JSON file linting.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: 静雨·安婵 <[email protected]>
Co-authored-by: 云遮夏靥 <[email protected]>
Co-authored-by: semantic-release-bot <[email protected]>
  • Loading branch information
4 people authored Oct 10, 2024
1 parent 61d6cfa commit fa5c428
Show file tree
Hide file tree
Showing 6 changed files with 4,530 additions and 4,339 deletions.
5 changes: 0 additions & 5 deletions .eslintrc

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,5 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

package_draft.json
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@

## 添加白名单方式

1、直接在线修改 [package.json](https://github.com/cnpm/unpkg-white-list/edit/master/package.json) 中的 `allowPackages` 字段,
添加你想开启 unpkg 文件同步的 npm 包名和版本号,全量同步版本号可以设置为 `*`
> [!NOTE]
> 尽量使用 CLI 添加白名单,它可以确保字段顺序和格式正确,避免手动修改 `package.json` 文件
以同步 [urllib](https://npmmirror.com/package/urllib) 为示例,配置如下:
### 添加指定包名和版本号

用 CLI 添加你想开启 unpkg 文件同步的 npm 包名和版本号,全量同步版本号可以设置为 `*`,以同步 [urllib](https://npmmirror.com/package/urllib) 为示例:

```bash
npm run add -- --pkg=urllib:* # 同步 urllib 所有版本
# or
npm run add -- --pkg=urllib:1.0.0 # 同步 urllib 1.0.0 版本
# or
npm run add -- "--pkg=urllib:>=1.0.0" # 同步 urllib 大于等于 1.0.0 版本
```

_你将会看到 package.json 文件中的 `allowPackages` 字段被更新,如下所示:_

```json
"allowPackages": {
Expand All @@ -22,7 +34,15 @@
}
```

当然你发布的是 scoped package,可以直接添加 scope 到白名单 `allowScopes`
### 添加指定 scope

当然你发布的是 scoped package,可以用 CLI 添加 scope 到白名单 `allowScopes`

```bash
npm run add -- --scope=@eggjs
```

_你将会看到 package.json 文件中的 `allowPackages` 字段被更新,如下所示:_

```json
"allowScopes": [
Expand Down
28 changes: 28 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pluginJsonc from "eslint-plugin-jsonc";
import parserJsonc from "jsonc-eslint-parser";

export default [
...pluginJsonc.configs['flat/recommended-with-json'],
{
files: ["package{_draft,}.json"],
languageOptions: {
parser: parserJsonc,
},
rules: {
"jsonc/sort-array-values": [
"error",
{
pathPattern: 'allowScopes',
order: { type: "asc" },
},
],
"jsonc/sort-keys": [
"error",
{
pathPattern: 'allowPackages',
order: { type: "asc" },
}
],
},
}
];
Loading

0 comments on commit fa5c428

Please sign in to comment.