Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Sort field & Spport CLI #296

Merged
merged 9 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading