Skip to content
Open
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
19 changes: 18 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ module.exports = {
"no-param-reassign": "off",
"no-bitwise": "off",
"class-methods-use-this": "off",
"@typescript-eslint/no-use-before-define": ["error"],
"@typescript-eslint/no-use-before-define": ["off"],
"no-console": "off",
"no-unused-vars": "warn",
"react/function-component-definition": [
2,
{
Expand All @@ -62,6 +64,21 @@ module.exports = {
"no-continue": "off",
"no-return-await": "off",
"prettier/prettier": "off",
"prefer-destructuring": "off",
"no-else-return": "off",
"prefer-template": "off",
"object-shorthand": "off",
"camelcase": "off",
"consistent-return": "off",
"lines-between-class-members": "off",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": [
"webpack-plugins/*"
]
}
],
},
settings: {
"import/resolver": {
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ jobs:
name: Build
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
cache: 'pnpm'

- name: Package with Node
env:
Expand All @@ -32,8 +34,8 @@ jobs:
mkdir dist
echo "$CHROME_PEM" > ./dist/scriptcat.pem
chmod 600 ./dist/scriptcat.pem
npm ci
npm run pack
pnpm i --frozen-lockfile
pnpm run pack

- name: Archive production artifacts
uses: actions/upload-artifact@v4
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/packageRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'
cache: 'pnpm'

- name: Package with Node
env:
Expand All @@ -25,9 +27,9 @@ jobs:
mkdir dist
echo "$CHROME_PEM" > ./dist/scriptcat.pem
chmod 600 ./dist/scriptcat.pem
npm ci
npm test
npm run pack
pnpm i --frozen-lockfile
pnpm test
pnpm run pack

- name: Create Release
id: create_release
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ jobs:
runs-on: ubuntu-latest
name: Run tests
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4

- name: Use Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
node-version: 22
cache: 'pnpm'

- name: Unit Test
run: |
npm ci
npm test
pnpm i --frozen-lockfile
pnpm test

- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
28 changes: 14 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ ScriptCat 引起的,欢迎提交 Issue。在提交时,请附带详细的复

## Pull Request

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

```bash
# 安装 node.js 依赖
npm install
pnpm install
```

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

```bash
# 设置代理
npm config set proxy=http://127.0.0.1:1080
pnpm config set proxy=http://127.0.0.1:1080
```

### Commit 规范
Expand Down Expand Up @@ -68,8 +68,8 @@ ScriptCat
dev server:

```bash
npm install
npm start
pnpm install
pnpm start
```

### 帮助我们翻译
Expand All @@ -81,7 +81,7 @@ npm start

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

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

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

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

```bash
npm test
npm run lint
pnpm test
pnpm run lint
```

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

```bash
npm run dev
pnpm run dev
```

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

```bash
npm run pack
pnpm run pack
```

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

# 注意问题

- 使用`yarn install`时可能会出现错误,最好使用`npm i`
- `npm run dev`之后需要把`dist/ext`目录里面内容在浏览器扩展里面导入加载,然后开始改代码保存即可,浏览器是实时更新的
- 使用`yarn install`时可能会出现错误,最好使用`pnpm i`
- `pnpm run dev`之后需要把`dist/ext`目录里面内容在浏览器扩展里面导入加载,然后开始改代码保存即可,浏览器是实时更新的
33 changes: 1 addition & 32 deletions build/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,6 @@ const package = require("../package.json");

// --- utils ---

const MAX_CHUNK_SIZE = 3 * 1024 * 1024; // 3 MiB

function addFileInChunks(zip, filePath, toDir, baseName, maxChunkSize = MAX_CHUNK_SIZE) {
const buffer = fs.readFileSync(filePath);
let offset = 0;

const chunks = [];
while (offset < buffer.length) {
const end = Math.min(offset + maxChunkSize, buffer.length);
const chunk = buffer.subarray(offset, end);
chunks.push(chunk);
offset = end;
}
const len = chunks.length;

for (let idx = 0; idx < len; idx += 1) {
const chunk = chunks[idx];
// e.g. src/ts.worker.js.part30, src/ts.worker.js.part31, ...
const chunkPath = `${toDir}${baseName}.part${idx}`;
zip.file(chunkPath, chunk);
}
}

const createJSZip = () => {
const currDate = new Date();
const dateWithOffset = new Date(currDate.getTime() - currDate.getTimezoneOffset() * 60000);
Expand Down Expand Up @@ -154,15 +131,7 @@ chrome.file("manifest.json", JSON.stringify(chromeManifest));
firefox.file("manifest.json", JSON.stringify(firefoxManifest));

addDir(chrome, "./dist/ext", "", ["manifest.json"]);
addDir(firefox, "./dist/ext", "", ["manifest.json", "ts.worker.js"]);

// Now split ts.worker.js into chunks (<4MB each) for Firefox
addFileInChunks(
firefox,
"./dist/ext/src/ts.worker.js", // source file on disk
"src/", // folder path inside zip
"ts.worker.js" // base name for chunked file
);
addDir(firefox, "./dist/ext", "", ["manifest.json"]);

// 导出zip包
chrome
Expand Down
4 changes: 3 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ module.exports = {
"\\.[jt]s$": "babel-jest",
"\\.m[jt]s$": "babel-jest",
},
transformIgnorePatterns: ["node_modules/(?!(uuid|dexi|yaml|webdav))"],
transformIgnorePatterns: [
"node_modules/(?!(.pnpm/)?(uuid|dexi|yaml|webdav)\\W)",
],
setupFiles: ["./pkg/chrome-extension-mock/index.ts", "<rootDir>/jest.setup.js"],
moduleDirectories: ["node_modules", "src"],
watch: false,
Expand Down
Loading
Loading