Skip to content

Commit ba6cee2

Browse files
committed
FirefoxMV2 简易修正
1 parent 1295807 commit ba6cee2

46 files changed

Lines changed: 15847 additions & 646 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.cjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ module.exports = {
4242
"no-param-reassign": "off",
4343
"no-bitwise": "off",
4444
"class-methods-use-this": "off",
45-
"@typescript-eslint/no-use-before-define": ["error"],
45+
"@typescript-eslint/no-use-before-define": ["off"],
46+
"no-console": "off",
47+
"no-unused-vars": "warn",
4648
"react/function-component-definition": [
4749
2,
4850
{
@@ -62,6 +64,21 @@ module.exports = {
6264
"no-continue": "off",
6365
"no-return-await": "off",
6466
"prettier/prettier": "off",
67+
"prefer-destructuring": "off",
68+
"no-else-return": "off",
69+
"prefer-template": "off",
70+
"object-shorthand": "off",
71+
"camelcase": "off",
72+
"consistent-return": "off",
73+
"lines-between-class-members": "off",
74+
"import/no-extraneous-dependencies": [
75+
"error",
76+
{
77+
"devDependencies": [
78+
"webpack-plugins/*"
79+
]
80+
}
81+
],
6582
},
6683
settings: {
6784
"import/resolver": {

.github/workflows/build.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ jobs:
1919
name: Build
2020
steps:
2121
- uses: actions/checkout@v4
22+
- uses: pnpm/action-setup@v4
23+
2224
- name: Use Node.js
2325
uses: actions/setup-node@v4
2426
with:
2527
node-version: 22
26-
cache: 'npm'
28+
cache: 'pnpm'
2729

2830
- name: Package with Node
2931
env:
@@ -32,8 +34,8 @@ jobs:
3234
mkdir dist
3335
echo "$CHROME_PEM" > ./dist/scriptcat.pem
3436
chmod 600 ./dist/scriptcat.pem
35-
npm ci
36-
npm run pack
37+
pnpm i --frozen-lockfile
38+
pnpm run pack
3739
3840
- name: Archive production artifacts
3941
uses: actions/upload-artifact@v4

.github/workflows/packageRelease.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ jobs:
1212

1313
steps:
1414
- uses: actions/checkout@v4
15+
- uses: pnpm/action-setup@v4
16+
1517
- name: Use Node.js
1618
uses: actions/setup-node@v4
1719
with:
1820
node-version: 22
19-
cache: 'npm'
21+
cache: 'pnpm'
2022

2123
- name: Package with Node
2224
env:
@@ -25,9 +27,9 @@ jobs:
2527
mkdir dist
2628
echo "$CHROME_PEM" > ./dist/scriptcat.pem
2729
chmod 600 ./dist/scriptcat.pem
28-
npm ci
29-
npm test
30-
npm run pack
30+
pnpm i --frozen-lockfile
31+
pnpm test
32+
pnpm run pack
3133
3234
- name: Create Release
3335
id: create_release

.github/workflows/test.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ jobs:
1414
runs-on: ubuntu-latest
1515
name: Run tests
1616
steps:
17-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4
18+
- uses: pnpm/action-setup@v4
19+
1820
- name: Use Node.js
19-
uses: actions/setup-node@v3
21+
uses: actions/setup-node@v4
2022
with:
21-
node-version: 20
22-
cache: 'npm'
23+
node-version: 22
24+
cache: 'pnpm'
2325

2426
- name: Unit Test
2527
run: |
26-
npm ci
27-
npm test
28+
pnpm i --frozen-lockfile
29+
pnpm test
2830
2931
- name: Upload coverage reports to Codecov with GitHub Action
3032
uses: codecov/codecov-action@v3

CONTRIBUTING.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ ScriptCat 引起的,欢迎提交 Issue。在提交时,请附带详细的复
2020

2121
## Pull Request
2222

23-
ScriptCat 使用 [npm](https://www.npmjs.com/) 来管理项目依赖。如果你已经安装了
24-
npm,以下的命令可以帮助你快速配置开发环境:
23+
ScriptCat 使用 [pnpm](https://www.npmjs.com/) 来管理项目依赖。如果你已经安装了
24+
pnpm,以下的命令可以帮助你快速配置开发环境:
2525

2626
```bash
2727
# 安装 node.js 依赖
28-
npm install
28+
pnpm install
2929
```
3030

31-
我们推荐使用代理来解决 npm 的网络问题,而不是使用镜像。
31+
我们推荐使用代理来解决 pnpm 的网络问题,而不是使用镜像。
3232

3333
```bash
3434
# 设置代理
35-
npm config set proxy=http://127.0.0.1:1080
35+
pnpm config set proxy=http://127.0.0.1:1080
3636
```
3737

3838
### Commit 规范
@@ -68,8 +68,8 @@ ScriptCat
6868
dev server:
6969

7070
```bash
71-
npm install
72-
npm start
71+
pnpm install
72+
pnpm start
7373
```
7474

7575
### 帮助我们翻译
@@ -81,7 +81,7 @@ npm start
8181

8282
#### 扩展开启所见即所得模式
8383

84-
扩展开启所见即所得模式需要使用`npm run i18n`模式进行构建,然后通过控制台设置伪语言`localStorage['language']='ach-UG';`,然后刷新页面。
84+
扩展开启所见即所得模式需要使用`pnpm run i18n`模式进行构建,然后通过控制台设置伪语言`localStorage['language']='ach-UG';`,然后刷新页面。
8585

8686
#### 脚本站开启所见即所得模式
8787

@@ -93,8 +93,8 @@ ScriptCat 使用 ESLint 来规范代码风格,使用 Jest
9393
来进行单元测试。你可以使用以下命令来运行:
9494

9595
```bash
96-
npm test
97-
npm run lint
96+
pnpm test
97+
pnpm run lint
9898
```
9999

100100
ScriptCat 的页面开发使用了以下技术:
@@ -106,18 +106,18 @@ ScriptCat 的页面开发使用了以下技术:
106106
如果你想在本地运行 ScriptCat,可以使用以下命令:
107107

108108
```bash
109-
npm run dev
109+
pnpm run dev
110110
```
111111

112112
如果你想打包扩展,可以使用以下命令:
113113

114114
```bash
115-
npm run pack
115+
pnpm run pack
116116
```
117117

118118
在打包前,请确保在`dist`目录下生成了`scriptcat.pem`文件。
119119

120120
# 注意问题
121121

122-
- 使用`yarn install`时可能会出现错误,最好使用`npm i`
123-
- `npm run dev`之后需要把`dist/ext`目录里面内容在浏览器扩展里面导入加载,然后开始改代码保存即可,浏览器是实时更新的
122+
- 使用`yarn install`时可能会出现错误,最好使用`pnpm i`
123+
- `pnpm run dev`之后需要把`dist/ext`目录里面内容在浏览器扩展里面导入加载,然后开始改代码保存即可,浏览器是实时更新的

build/pack.js

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,6 @@ const package = require("../package.json");
88

99
// --- utils ---
1010

11-
const MAX_CHUNK_SIZE = 3 * 1024 * 1024; // 3 MiB
12-
13-
function addFileInChunks(zip, filePath, toDir, baseName, maxChunkSize = MAX_CHUNK_SIZE) {
14-
const buffer = fs.readFileSync(filePath);
15-
let offset = 0;
16-
17-
const chunks = [];
18-
while (offset < buffer.length) {
19-
const end = Math.min(offset + maxChunkSize, buffer.length);
20-
const chunk = buffer.subarray(offset, end);
21-
chunks.push(chunk);
22-
offset = end;
23-
}
24-
const len = chunks.length;
25-
26-
for (let idx = 0; idx < len; idx += 1) {
27-
const chunk = chunks[idx];
28-
// e.g. src/ts.worker.js.part30, src/ts.worker.js.part31, ...
29-
const chunkPath = `${toDir}${baseName}.part${idx}`;
30-
zip.file(chunkPath, chunk);
31-
}
32-
}
33-
3411
const createJSZip = () => {
3512
const currDate = new Date();
3613
const dateWithOffset = new Date(currDate.getTime() - currDate.getTimezoneOffset() * 60000);
@@ -154,15 +131,7 @@ chrome.file("manifest.json", JSON.stringify(chromeManifest));
154131
firefox.file("manifest.json", JSON.stringify(firefoxManifest));
155132

156133
addDir(chrome, "./dist/ext", "", ["manifest.json"]);
157-
addDir(firefox, "./dist/ext", "", ["manifest.json", "ts.worker.js"]);
158-
159-
// Now split ts.worker.js into chunks (<4MB each) for Firefox
160-
addFileInChunks(
161-
firefox,
162-
"./dist/ext/src/ts.worker.js", // source file on disk
163-
"src/", // folder path inside zip
164-
"ts.worker.js" // base name for chunked file
165-
);
134+
addDir(firefox, "./dist/ext", "", ["manifest.json"]);
166135

167136
// 导出zip包
168137
chrome

jest.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ module.exports = {
1212
"\\.[jt]s$": "babel-jest",
1313
"\\.m[jt]s$": "babel-jest",
1414
},
15-
transformIgnorePatterns: ["node_modules/(?!(uuid|dexi|yaml|webdav))"],
15+
transformIgnorePatterns: [
16+
"node_modules/(?!(.pnpm/)?(uuid|dexi|yaml|webdav)\\W)",
17+
],
1618
setupFiles: ["./pkg/chrome-extension-mock/index.ts", "<rootDir>/jest.setup.js"],
1719
moduleDirectories: ["node_modules", "src"],
1820
watch: false,

0 commit comments

Comments
 (0)