Skip to content

Commit 651710b

Browse files
committed
chore: lint update
1 parent c1fd5f5 commit 651710b

34 files changed

Lines changed: 422 additions & 390 deletions

File tree

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,62 @@ Baize CLI 是一个轻量、规范且高效的前端项目脚手架工具,旨
361361
362362
## 🤝 Show your support
363363
364+
---
365+
366+
## ⚙️ CI / 部署
367+
368+
本项目在 CI/部署 环境中支持可选的 Sentry 集成(用于上传 release 与 source maps),且在未配置上传凭证时会自动跳过以避免构建警告。
369+
370+
- 目的:在需要时将 release/source maps 上传到 Sentry;在本地或未配置 token 时跳过上传,避免泄露凭证或出现不必要警告。
371+
- 关键环境变量:
372+
- `SENTRY_AUTH_TOKEN` — Sentry API token(CI secrets),用于 `sentry-webpack-plugin` 上传 artifacts。
373+
- `SENTRY_ORG` — Sentry 组织 slug。
374+
- `SENTRY_PROJECT` — Sentry 项目 slug。
375+
- `SENTRY_DSN` — 前端运行时使用的 DSN(可在部署时注入至运行时代码)。
376+
- `SENTRY_TRACES_SAMPLE_RATE` — 可选,transactions 采样率(例如 `0.2`)。
377+
378+
为什么会出现警告
379+
- `sentry-webpack-plugin` 在没有 `authToken` 时会打印警告并跳过上传;本仓库的 `webpack/webpack.prod.js` 已修改为:仅当 `SENTRY_AUTH_TOKEN` 存在时才注册该插件,否则构建继续并输出简短提示。
380+
381+
GitHub Actions 示例
382+
383+
```yaml
384+
name: Build
385+
on: [push]
386+
jobs:
387+
build:
388+
runs-on: ubuntu-latest
389+
steps:
390+
- uses: actions/checkout@v4
391+
- name: Use Node.js
392+
uses: actions/setup-node@v4
393+
with:
394+
node-version: '18'
395+
- name: Install
396+
run: npm ci
397+
- name: Build (production)
398+
env:
399+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
400+
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
401+
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
402+
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
403+
SENTRY_TRACES_SAMPLE_RATE: 0.2
404+
run: npm run build:production
405+
```
406+
407+
Vercel / Netlify
408+
- 在项目的 Environment Variables / Build settings 中添加 `SENTRY_AUTH_TOKEN``SENTRY_ORG``SENTRY_PROJECT``SENTRY_DSN`,部署时这些变量会注入到构建与运行时环境。
409+
410+
本地开发
411+
- 不要在本地把 `SENTRY_AUTH_TOKEN` 写入源码或提交到仓库。可在本地 `.env` 或 CI 的 secrets 中临时添加 `SENTRY_DSN` 用于运行时错误上报测试,但将 `SENTRY_AUTH_TOKEN` 保持为空以跳过上传步骤。
412+
413+
如何创建 `SENTRY_AUTH_TOKEN`
414+
- 前往 https://sentry.io/settings/<ORG>/api/,创建一个具有 `project:releases``org:read` 权限的 token,并把它存入 CI 的 secrets。
415+
416+
注意
417+
- `SENTRY_DSN`(运行时)与 `SENTRY_AUTH_TOKEN`(CI 上传)用途不同,请勿混淆;本项目的运行时代码会优先使用 `process.env.SENTRY_DSN`,构建时的插件仅在 `SENTRY_AUTH_TOKEN` 存在时运行。
418+
419+
364420
<!-- Give a ⭐️ if this project helped you! -->
365421
366422
If you like the project, give it a star ⭐️, it will be a great encouragement to me.

babel.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ const plugins = [
22
['@babel/plugin-syntax-dynamic-import'],
33
['@babel/plugin-proposal-decorators', { legacy: true }],
44
['@babel/plugin-transform-runtime'],
5-
['@babel/plugin-transform-modules-commonjs'],
65
['@babel/plugin-transform-object-rest-spread'],
76
['babel-plugin-react-compiler'],
87
]
98

10-
module.exports = {
9+
export default {
1110
presets: [
1211
[
1312
'@babel/preset-env',

docs/SENTRY-CI.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
**Sentry CI / Build Integration**
2+
3+
这是仓库中针对 Sentry 在 CI 和生产构建中如何配置的说明(用于 `sentry-webpack-plugin` 和运行时代码)。
4+
5+
- 目的:让构建在需要时上传 release / source maps 到 Sentry;在本地或未配置 token 时跳过上传以避免警告。
6+
- 关键环境变量:
7+
- `SENTRY_AUTH_TOKEN` — Sentry API token,用于 `sentry-webpack-plugin` 上传 source maps / 创建 release(敏感,存为 CI secret)。
8+
- `SENTRY_ORG` — Sentry 组织 slug(用于插件配置)。
9+
- `SENTRY_PROJECT` — Sentry 项目 slug(用于插件配置)。
10+
- `SENTRY_DSN` — 前端运行时使用的 DSN(可通过环境注入到运行时构建或在部署处注入)。
11+
- `SENTRY_TRACES_SAMPLE_RATE` — 可选,采样率(例如 `0.2`)。
12+
13+
为什么会出现警告
14+
- `sentry-webpack-plugin` 在没有 `authToken` 时会打印警告并不上传 source maps(这是正常的保护行为)。我们的 `webpack/webpack.prod.js` 已修改为:仅当 `SENTRY_AUTH_TOKEN` 存在时才注册该插件;否则构建继续并输出简短提示。
15+
16+
示例:GitHub Actions
17+
```
18+
name: Build
19+
on: [push]
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- name: Use Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: '18'
29+
- name: Install
30+
run: npm ci
31+
- name: Build (production)
32+
env:
33+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
34+
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
35+
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
36+
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
37+
SENTRY_TRACES_SAMPLE_RATE: 0.2
38+
run: npm run build:production
39+
```
40+
41+
示例:Vercel / Netlify
42+
- 在项目的 Environment Variables / Build settings 中添加 `SENTRY_AUTH_TOKEN``SENTRY_ORG``SENTRY_PROJECT``SENTRY_DSN`。部署构建时这些变量会注入到构建环境。
43+
44+
本地开发
45+
- 不要在本地把 token 写入源码。可在本地 `.env` 文件中临时添加 `SENTRY_DSN`(用于运行时代码),但不要添加 `SENTRY_AUTH_TOKEN`,这样本地构建将跳过上传。
46+
47+
如何创建 `SENTRY_AUTH_TOKEN`
48+
- 前往 https://sentry.io/settings/<ORG>/api/,创建一个具有 `project:releases``org:read` 权限的 token。将该 token 存入 CI 的 secrets。
49+
50+
注意
51+
- `SENTRY_DSN` 是前端运行时用来发送事件的 DSN;`SENTRY_AUTH_TOKEN` 是 CI 用来上传 artifacts(source maps / releases)的私密 token,两者用途不同,不要混淆。
52+
- 我们的 `src/utils/sentry/index.js` 会优先使用 `process.env.SENTRY_DSN`,并允许在运行时代码中通过环境变量或构建时间注入替换。
53+
54+
如需我:
55+
- 可以把这段内容合并到 `README.md` 的“部署”或“CI”节;或创建更详细的 `docs/` 页面并添加示例 workflow(我可以代为修改)。

eslint-report.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

faker/app/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const Router = require('koa-router')
2-
const { delay } = require('../utils/index')
1+
import Router from 'koa-router'
2+
import { delay } from '../utils/index.js'
33

44
const user = new Router()
55

@@ -12,4 +12,4 @@ user.get('/api/user/list', async (ctx) => {
1212
ctx.body = [{ name: 'wkylin', sex: 'man', age: 18 }]
1313
})
1414

15-
module.exports = user
15+
export default user

faker/index.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
// import Koa from 'koa' package.json type: module
2-
// Within a package, the package.json "type" field defines how Node.js should interpret .js files. If a package.json file does not have a "type" field, .js files are treated as CommonJS.
3-
// A package.json "type" value of "module" tells Node.js to interpret .js files within that package as using ES module syntax.
4-
// https://demopark.github.io/koa-docs-Zh-CN
1+
// faker server (ESM)
2+
import Koa from 'koa'
3+
import Router from 'koa-router'
4+
import bodyParser from 'koa-bodyparser'
5+
import cors from '@koa/cors'
6+
import portfinder from 'portfinder'
57

6-
const Koa = require('koa')
7-
const Router = require('koa-router')
8-
const bodyParser = require('koa-bodyparser')
9-
const cors = require('@koa/cors')
10-
const portfinder = require('portfinder')
8+
import shops from './shops/index.js'
9+
import user from './app/index.js'
1110

1211
const app = new Koa()
1312
const router = new Router()
1413
app.use(bodyParser())
1514
app.use(cors())
1615

17-
const shops = require('./shops')
18-
const user = require('./app')
19-
2016
router.use('/shops', shops.routes())
2117
router.use('/app', user.routes())
2218

faker/shops/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const Router = require('koa-router')
2-
const { Mock, Random } = require('../utils/index')
1+
import Router from 'koa-router'
2+
import { Mock, Random } from '../utils/index.js'
33

44
const shops = new Router()
55

@@ -28,4 +28,4 @@ const handler = (ctx) => {
2828
shops.get('/', handler)
2929
shops.post('/', handler)
3030

31-
module.exports = shops
31+
export default shops

faker/utils/delay.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ const delay = (time) =>
22
new Promise((resolve) => {
33
setTimeout(() => resolve(), time)
44
})
5-
module.exports = delay
5+
6+
export default delay

faker/utils/index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
const delay = require('./delay')
2-
const { Mock, Random } = require('./mock')
1+
import delay from './delay.js'
2+
import { Mock, Random } from './mock.js'
33

4-
module.exports = {
5-
Mock,
6-
Random,
7-
delay,
8-
}
4+
export { Mock, Random, delay }

faker/utils/mock.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
// https://www.npmjs.com/package/faker
33
// https://www.npmjs.com/package/better-mock
44

5+
import { createRequire } from 'module'
6+
const require = createRequire(import.meta.url)
57
const Mock = require('better-mock')
6-
78
const { Random } = Mock
89
Random.extend({
910
mobile() {
@@ -16,7 +17,4 @@ Random.extend({
1617
},
1718
})
1819

19-
module.exports = {
20-
Mock,
21-
Random,
22-
}
20+
export { Mock, Random }

0 commit comments

Comments
 (0)