2017-03-30 09:11:38 -07:00
# Contribution guide
2024-03-04 12:21:46 -08:00
We're glad you're interested in contributing to Sharkey! In this document you will find the information you need to contribute to the project.
2021-08-27 23:42:27 -07:00
2022-03-27 04:11:43 -07:00
## Roadmap
2024-03-04 12:21:46 -08:00
See [ROADMAP.md ](./ROADMAP.md ) for the upstream Misskey roadmap.
2022-03-27 04:11:43 -07:00
2018-09-01 02:02:04 -07:00
## Issues
2021-09-20 07:24:07 -07:00
Before creating an issue, please check the following:
- To avoid duplication, please search for similar issues before creating a new issue.
2021-10-16 13:21:36 -07:00
- Do not use Issues to ask questions or troubleshooting.
- Issues should only be used to feature requests, suggestions, and bug tracking.
2024-03-04 12:21:46 -08:00
- Please ask questions or troubleshooting in [Discord ](https://discord.gg/6VgKmEqHNk ).
2022-05-21 22:49:53 -07:00
> **Warning**
> Do not close issues that are about to be resolved. It should remain open until a commit that actually resolves it is merged.
2021-09-20 07:24:07 -07:00
## Before implementation
2024-03-04 12:21:46 -08:00
When you want to add a feature or fix a bug, *please open an issue* ,
don't just start writing code. We may suggest different approaches, or
show that the "bug" is actually intended behaviour (and offer
work-arounds), or maybe we won't be able to merge your new feature
because it would make it too hard to incorporate future changes from
Misskey. Each of these examples have actually happened!
2021-09-20 07:24:07 -07:00
2024-03-04 12:21:46 -08:00
On the other hand, it's very likely that we'll tell you "go
ahead!". We try our best to incorporate improvements from our users!
2022-02-06 04:49:04 -08:00
2021-09-20 07:24:07 -07:00
Also, when you start implementation, assign yourself to the Issue (if you cannot do it yourself, ask another member to assign you). By expressing your intention to work the Issue, you can prevent conflicts in the work.
## Well-known branches
2024-03-04 12:21:46 -08:00
- **`stable`** branch is tracking the latest release and used for production purposes.
2021-08-30 04:11:22 -07:00
- **`develop`** branch is where we work for the next release.
2021-09-20 07:24:07 -07:00
- When you create a PR, basically target it to this branch.
2019-07-21 22:57:23 -07:00
2021-09-20 07:24:07 -07:00
## Creating a PR
Thank you for your PR! Before creating a PR, please check the following:
- If possible, prefix the title with a keyword that identifies the type of this PR, as shown below.
- `fix` / `refactor` / `feat` / `enhance` / `perf` / `chore` etc
- Also, make sure that the granularity of this PR is appropriate. Please do not include more than one type of change or interest in a single PR.
- If there is an Issue which will be resolved by this PR, please include a reference to the Issue in the text.
2024-03-04 12:21:46 -08:00
- Please add the summary of the changes to [`CHANGELOG.md` ](CHANGELOG.md ). However, this is not necessary for changes that do not affect the users, such as refactoring.
2021-09-20 07:24:07 -07:00
- Check if there are any documents that need to be created or updated due to this change.
- If you have added a feature or fixed a bug, please add a test case if possible.
- Please make sure that tests and Lint are passed in advance.
2023-02-02 10:11:26 -08:00
- You can run it with `pnpm test` and `pnpm lint` . [See more info ](#testing )
2021-09-20 07:24:07 -07:00
- If this PR includes UI changes, please attach a screenshot in the text.
Thanks for your cooperation 🤗
2022-02-06 04:58:14 -08:00
## Reviewers guide
2022-02-06 05:03:19 -08:00
Be willing to comment on the good points and not just the things you want fixed 💯
2022-02-06 04:58:14 -08:00
### Review perspective
- Scope
- Are the goals of the PR clear?
- Is the granularity of the PR appropriate?
- Security
- Does merging this PR create a vulnerability?
- Performance
- Will merging this PR cause unexpected performance degradation?
- Is there a more efficient way?
- Testing
- Does the test ensure the expected behavior?
- Are there any omissions or gaps?
- Does it check for anomalies?
2022-05-05 02:33:24 -07:00
## Merge
## Release
### Release Instructions
2024-03-04 12:21:46 -08:00
1. Commit version changes in the `develop` branch ([package.json](https://activitypub.software/TransFem-org/Sharkey/-/blob/develop/package.json))
2022-06-04 00:01:11 -07:00
2. Create a release PR.
2024-03-04 12:21:46 -08:00
- Into `stable` from `develop` branch.
2022-06-04 00:01:11 -07:00
- The title must be in the format `Release: x.y.z` .
- `x.y.z` is the new version you are trying to release.
2022-06-08 13:55:58 -07:00
3. Deploy and perform a simple QA check. Also verify that the tests passed.
2023-02-23 03:49:09 -08:00
4. Merge it. (Do not squash commit)
2024-03-04 12:21:46 -08:00
5. Create a [release ](https://activitypub.software/TransFem-org/Sharkey/-/releases )
- The target branch must be `stable`
2022-06-04 00:01:27 -07:00
- The tag name must be the version
2022-05-05 02:33:24 -07:00
2023-02-23 16:14:58 -08:00
> **Note**
> Why this instruction is necessary:
> - To perform final QA checks
> - To distribute responsibility
> - To check direct commits to develop
> - To celebrate the release together 🎉
2018-09-01 02:02:04 -07:00
## Localization (l10n)
2019-05-24 03:31:40 -07:00
Misskey uses [Crowdin ](https://crowdin.com/project/misskey ) for localization management.
You can improve our translations with your Crowdin account.
2019-07-21 22:57:23 -07:00
Your changes in Crowdin are automatically submitted as a PR (with the title "New Crowdin translations") to the repository.
The owner [@syuilo ](https://github.com/syuilo ) merges the PR into the develop branch before the next release.
2019-05-24 03:31:40 -07:00
2019-07-21 22:57:23 -07:00
If your language is not listed in Crowdin, please open an issue.
2017-03-26 05:32:19 -07:00
2018-09-01 02:15:25 -07:00
![Crowdin ](https://d322cqt584bo4o.cloudfront.net/misskey/localized.svg )
2017-03-26 05:32:19 -07:00
2021-11-18 21:57:07 -08:00
## Development
2023-07-07 15:08:16 -07:00
During development, it is useful to use the
2022-12-19 20:05:36 -08:00
```
2023-02-02 10:11:26 -08:00
pnpm dev
2022-12-19 20:05:36 -08:00
```
command.
- Server-side source files and automatically builds them if they are modified. Automatically start the server process(es).
- Vite HMR (just the `vite` command) is available. The behavior may be different from production.
- Service Worker is watched by esbuild.
2023-12-07 16:00:23 -08:00
- The front end can be viewed by accessing `http://localhost:5173` .
- The backend listens on the port configured with `port` in .config/default.yml.
If you have not changed it from the default, it will be "http://localhost:3000".
If "port" in .config/default.yml is set to something other than 3000, you need to change the proxy settings in packages/frontend/vite.config.local-dev.ts.
2021-11-18 21:57:07 -08:00
2024-02-12 07:54:34 -08:00
### `MK_DEV_PREFER=backend pnpm dev`
pnpm dev has another mode with `MK_DEV_PREFER=backend` .
```
MK_DEV_PREFER=backend pnpm dev
```
- This mode is closer to the production environment than the default mode.
- Vite runs behind the backend (the backend will proxy Vite at /vite).
- You can see Misskey by accessing `http://localhost:3000` (Replace `3000` with the port configured with `port` in .config/default.yml).
- To change the port of Vite, specify with `VITE_PORT` environment variable.
- HMR may not work in some environments such as Windows.
2023-02-11 16:07:56 -08:00
### Dev Container
Instead of running `pnpm` locally, you can use Dev Container to set up your development environment.
2023-02-13 20:17:34 -08:00
To use Dev Container, open the project directory on VSCode with Dev Containers installed.
**Note:** If you are using Windows, please clone the repository with WSL. Using Git for Windows will result in broken files due to the difference in how newlines are handled.
2023-02-11 16:07:56 -08:00
It will run the following command automatically inside the container.
``` bash
git submodule update --init
pnpm install --frozen-lockfile
cp .devcontainer/devcontainer.yml .config/default.yml
pnpm build
pnpm migrate
```
After finishing the migration, run the `pnpm dev` command to start the development server.
``` bash
pnpm dev
```
2021-08-30 04:11:22 -07:00
## Testing
2024-03-04 12:21:46 -08:00
- Test codes are located in [`/packages/backend/test` ](packages/backend/test ).
2018-09-01 02:02:04 -07:00
2021-08-30 04:11:22 -07:00
### Run test
2021-10-16 01:12:20 -07:00
Create a config file.
```
2022-12-12 05:43:20 -08:00
cp .github/misskey/test.yml .config/
2021-10-16 01:12:20 -07:00
```
Prepare DB/Redis for testing.
```
2023-02-05 03:34:22 -08:00
docker compose -f packages/backend/test/docker-compose.yml up
2021-10-16 01:12:20 -07:00
```
2023-07-07 15:08:16 -07:00
Alternatively, prepare an empty (data can be erased) DB and edit `.config/test.yml` .
2021-10-16 01:12:20 -07:00
Run all test.
2021-08-30 04:11:22 -07:00
```
2023-02-02 10:11:26 -08:00
pnpm test
2021-08-30 04:11:22 -07:00
```
#### Run specify test
2021-08-18 19:26:26 -07:00
```
2023-02-02 10:11:26 -08:00
pnpm jest -- foo.ts
2021-08-18 19:26:26 -07:00
```
2021-08-30 04:11:22 -07:00
### e2e tests
TODO
2023-04-29 07:26:47 -07:00
## Environment Variable
- `MISSKEY_CONFIG_YML` : Specify the file path of config.yml instead of default.yml (e.g. `2nd.yml` ).
- `MISSKEY_WEBFINGER_USE_HTTP` : If it's set true, WebFinger requests will be http instead of https, useful for testing federation between servers in localhost. NEVER USE IN PRODUCTION.
2018-09-01 02:02:04 -07:00
## Continuous integration
2024-03-04 12:21:46 -08:00
Sharkey uses GitLab CI for executing automated tests.
Configuration files are located in [`/.gitlab-ci.yml` ](.gitlab-ci.yml ).
2018-12-19 10:01:02 -08:00
2021-12-10 03:42:01 -08:00
## Vue
Misskey uses Vue(v3) as its front-end framework.
2022-01-25 10:27:19 -08:00
- Use TypeScript.
- **When creating a new component, please use the Composition API (with [setup sugar ](https://v3.vuejs.org/api/sfc-script-setup.html ) and [ref sugar ](https://github.com/vuejs/rfcs/discussions/369 )) instead of the Options API.**
- Some of the existing components are implemented in the Options API, but it is an old implementation. Refactors that migrate those components to the Composition API are also welcome.
2021-12-10 03:42:01 -08:00
2022-07-21 08:35:30 -07:00
## nirax
niraxは、Misskeyで使用しているオリジナルのフロントエンドルーティングシステムです。
**vue-routerから影響を多大に受けているので、まずはvue-routerについて学ぶことをお勧めします。**
### ルート定義
ルート定義は、以下の形式のオブジェクトの配列です。
``` ts
{
name?: string;
path: string;
component: Component;
query?: Record< string , string > ;
loginRequired?: boolean;
hash?: string;
globalCacheKey?: string;
children?: RouteDef[];
}
```
> **Warning**
> 現状、ルートは定義された順に評価されます。
> たとえば、`/foo/:id`ルート定義の次に`/foo/bar`ルート定義がされていた場合、後者がマッチすることはありません。
### 複数のルーター
vue-routerとの最大の違いは、niraxは複数のルーターが存在することを許可している点です。
これにより、アプリ内ウィンドウでブラウザとは個別にルーティングすることなどが可能になります。
2023-04-03 17:38:34 -07:00
## Storybook
Misskey uses [Storybook ](https://storybook.js.org/ ) for UI development.
### Setup & Run
2023-07-20 01:41:48 -07:00
#### Setup
2023-04-03 17:38:34 -07:00
```bash
pnpm --filter misskey-js build
```
2023-07-20 01:41:48 -07:00
#### Run
2023-04-03 17:38:34 -07:00
```bash
pnpm --filter frontend storybook-dev
```
### Usage
When you create a new component (in this example, `MyComponent.vue` ), the story file (`MyComponent.stories.ts`) will be automatically generated by the `.storybook/generate.js` script.
You can override the default story by creating a impl story file (`MyComponent.stories.impl.ts`).
```ts
/* eslint-disable @typescript -eslint/explicit-function-return-type */
import { StoryObj } from '@storybook/vue3';
import MyComponent from './MyComponent.vue';
export const Default = {
render(args) {
return {
components: {
MyComponent,
},
setup() {
return {
args,
};
},
computed: {
props() {
return {
...this.args,
};
},
},
template: '< MyComponent v-bind = "props" / > ',
};
},
args: {
foo: 'bar',
},
parameters: {
layout: 'centered',
},
} satisfies StoryObj< typeof MkAvatar > ;
```
If you want to opt-out from the automatic generation, create a `MyComponent.stories.impl.ts` file and add the following line to the file.
```ts
import MyComponent from './MyComponent.vue';
void MyComponent;
```
You can override the component meta by creating a meta story file (`MyComponent.stories.meta.ts`).
```ts
export const argTypes = {
scale: {
control: {
type: 'range',
min: 1,
max: 4,
},
2024-02-07 20:28:49 -08:00
},
2023-04-03 17:38:34 -07:00
};
```
Also, you can use msw to mock API requests in the storybook. Creating a `MyComponent.stories.msw.ts` file to define the mock handlers.
```ts
2024-02-07 20:28:49 -08:00
import { HttpResponse, http } from 'msw';
2023-04-03 17:38:34 -07:00
export const handlers = [
2024-02-07 20:28:49 -08:00
http.post('/api/notes/timeline', ({ request }) => {
return HttpResponse.json([]);
2023-04-03 17:38:34 -07:00
}),
];
```
Don't forget to re-run the `.storybook/generate.js` script after adding, editing, or removing the above files.
2024-03-04 21:26:16 -08:00
## Nest
### Nest Service Circular dependency / Nestでサービスの循環参照でエラーが起きた場合
#### forwardRef
まずは簡単に`forwardRef`を試してみる
```typescript
export class FooService {
constructor(
@Inject (forwardRef(() => BarService))
private barService: BarService
) {
}
}
```
#### OnModuleInit
できなければ`OnModuleInit`を使う
```typescript
import { Injectable, OnModuleInit } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { BarService } from '@/core/BarService';
@Injectable ()
export class FooService implements OnModuleInit {
private barService: BarService // constructorから移動してくる
constructor(
private moduleRef: ModuleRef,
) {
}
async onModuleInit() {
this.barService = this.moduleRef.get(BarService.name);
}
public async niceMethod() {
return await this.barService.incredibleMethod({ hoge: 'fuga' });
}
}
```
##### Service Unit Test
テストで`onModuleInit`を呼び出す必要がある
```typescript
// import ...
describe('test', () => {
let app: TestingModule;
let fooService: FooService; // for test case
let barService: BarService; // for test case
beforeEach(async () => {
app = await Test.createTestingModule({
imports: ...,
providers: [
FooService,
{ // mockする (mockは必須ではないかもしれない)
provide: BarService,
useFactory: () => ({
incredibleMethod: jest.fn(),
}),
},
{ // Provideにする
provide: BarService.name,
useExisting: BarService,
},
],
})
.useMocker(...
.compile();
fooService = app.get< FooService > (FooService);
barService = app.get< BarService > (BarService) as jest.Mocked< BarService > ;
// onModuleInitを実行する
await fooService.onModuleInit();
});
test('nice', () => {
await fooService.niceMethod();
expect(barService.incredibleMethod).toHaveBeenCalled();
expect(barService.incredibleMethod.mock.lastCall![0])
.toEqual({ hoge: 'fuga' });
});
})
```
2021-08-30 04:00:31 -07:00
## Notes
2023-08-26 17:45:23 -07:00
### Misskeyのドメイン固有の概念は`Mi`をprefixする
例えばGoogleが自社サービスをMap、Earth、DriveではなくGoogle Map、Google Earth、Google Driveのように命名するのと同じ
コード上でMisskeyのドメイン固有の概念には`Mi`をprefixすることで、他のドメインの同様の概念と区別できるほか、名前の衝突を防ぐ。
ただし、文脈上Misskeyのものを指すことが明らかであり、名前の衝突の恐れがない場合は、一時的なローカル変数に限って`Mi`を省略してもよい。
2023-02-02 10:11:26 -08:00
### How to resolve conflictions occurred at pnpm-lock.yaml?
2019-07-15 05:32:09 -07:00
2023-02-02 10:11:26 -08:00
Just execute `pnpm` to fix it.
2019-07-13 18:05:19 -07:00
2022-01-25 07:52:34 -08:00
### INSERTするときにはsaveではなくinsertを使用する
#6441
2019-04-07 05:50:36 -07:00
### placeholder
SQLをクエリビルダで組み立てる際、使用するプレースホルダは重複してはならない
例えば
``` ts
query.andWhere(new Brackets(qb => {
for (const type of ps.fileType) {
qb.orWhere(`:type = ANY(note.attachedFileTypes)`, { type: type });
}
}));
```
と書くと、ループ中で`type`というプレースホルダが複数回使われてしまいおかしくなる
だから次のようにする必要がある
```ts
query.andWhere(new Brackets(qb => {
for (const type of ps.fileType) {
const i = ps.fileType.indexOf(type);
qb.orWhere(`:type${i} = ANY(note.attachedFileTypes)`, { [`type${i}`]: type });
}
}));
```
2019-05-20 05:44:16 -07:00
### Not `null` in TypeORM
```ts
const foo = await Foos.findOne({
bar: Not(null)
});
```
のようなクエリ(`bar`が`null`ではない)は期待通りに動作しない。
次のようにします:
```ts
const foo = await Foos.findOne({
bar: Not(IsNull())
});
```
2019-04-07 05:50:36 -07:00
### `null` in SQL
SQLを発行する際、パラメータが`null`になる可能性のある場合はSQL文を出し分けなければならない
例えば
``` ts
query.where('file.folderId = :folderId', { folderId: ps.folderId });
```
という処理で、`ps.folderId`が`null`だと結果的に`file.folderId = null`のようなクエリが発行されてしまい、これは正しいSQLではないので期待した結果が得られない
だから次のようにする必要がある
``` ts
if (ps.folderId) {
query.where('file.folderId = :folderId', { folderId: ps.folderId });
} else {
query.where('file.folderId IS NULL');
}
```
### `[]` in SQL
SQLを発行する際、`IN`のパラメータが`[]`(空の配列)になる可能性のある場合はSQL文を出し分けなければならない
例えば
``` ts
const users = await Users.find({
id: In(userIds)
});
```
という処理で、`userIds`が`[]`だと結果的に`user.id IN ()`のようなクエリが発行されてしまい、これは正しいSQLではないので期待した結果が得られない
だから次のようにする必要がある
``` ts
const users = userIds.length > 0 ? await Users.find({
id: In(userIds)
}) : [];
```
2019-04-12 22:04:29 -07:00
### 配列のインデックス in SQL
SQLでは配列のインデックスは**1始まり**。
`[a, b, c]` の `a` にアクセスしたいなら`[0]`ではなく`[1]`と書く
2021-10-19 04:25:47 -07:00
### null IN
nullが含まれる可能性のあるカラムにINするときは、そのままだとおかしくなるのでORなどでnullのハンドリングをしよう。
2023-02-23 03:33:49 -08:00
### enumの削除は気をつける
enumの列挙の内容の削除は、その値をもつレコードを全て削除しないといけない
削除が重たかったり不可能だったりする場合は、削除しないでおく
2019-05-13 10:57:04 -07:00
### Migration作成方法
2022-03-25 23:34:00 -07:00
packages/backendで:
```sh
2023-02-02 10:11:26 -08:00
pnpm dlx typeorm migration:generate -d ormconfig.js -o < migration name >
2019-05-13 10:57:04 -07:00
```
2022-03-25 23:34:00 -07:00
- 生成後、ファイルをmigration下に移してください
- 作成されたスクリプトは不必要な変更を含むため除去してください
2019-09-08 05:21:08 -07:00
2023-02-25 18:28:05 -08:00
### JSON SchemaのobjectでanyOfを使うとき
JSON Schemaで、objectに対してanyOfを使う場合、anyOfの中でpropertiesを定義しないこと。
バリデーションが効かないため。( SchemaTypeもそのように作られており、objectのanyOf内のpropertiesは捨てられます)
https://github.com/misskey-dev/misskey/pull/10082
テキストhogeおよびfugaについて、片方を必須としつつ両方の指定もありうる場合:
```
export const paramDef = {
type: 'object',
properties: {
hoge: { type: 'string', minLength: 1 },
fuga: { type: 'string', minLength: 1 },
},
anyOf: [
{ required: ['hoge'] },
{ required: ['fuga'] },
],
} as const;
```
2021-07-25 19:12:06 -07:00
### コネクションには`markRaw`せよ
**Vueのコンポーネントのdataオプションとして**misskey.jsのコネクションを設定するとき、必ず`markRaw`でラップしてください。インスタンスが不必要にリアクティブ化されることで、misskey.js内の処理で不具合が発生するとともに、パフォーマンス上の問題にも繋がる。なお、Composition APIを使う場合はこの限りではない(リアクティブ化はマニュアルなため)。
2021-08-20 05:34:56 -07:00
### JSONのimportに気を付けよう
TypeScriptでjsonをimportすると、tscでコンパイルするときにそのjsonファイルも一緒にdistディレクトリに吐き出されてしまう。この挙動により、意図せずファイルの書き換えが発生することがあるので、jsonをimportするときは書き換えられても良いものかどうか確認すること。書き換えされて欲しくない場合は、importで読み込むのではなく、`fs.readFileSync`などの関数を使って読み込むようにすればよい。
2021-09-29 08:50:45 -07:00
### コンポーネントのスタイル定義でmarginを持たせない
コンポーネント自身がmarginを設定するのは問題の元となることはよく知られている
marginはそのコンポーネントを使う側が設定する
2019-09-08 05:21:08 -07:00
## その他
### HTMLのクラス名で follow という単語は使わない
広告ブロッカーで誤ってブロックされる
2023-09-14 22:28:29 -07:00
### indexというファイル名を使うな
ESMではディレクトリインポートは廃止されているのと、ディレクトリインポートせずともファイル名が index だと何故か一部のライブラリ?でディレクトリインポートだと見做されてエラーになる
2024-03-04 12:21:46 -08:00
## Merging from Misskey into Sharkey
Make sure you have both remotes in the same clone (`git remote add misskey
https://github.com/misskey-dev/misskey.git`), then:
git remote update
git checkout develop # this is Sharkey's develop
git checkout -m merge/$(date +%Y-%m-%d) # or whatever
git merge --no-ff misskey/develop
fix conflicts and *commit* !
*after that commit*, do all the extra work, on the same branch:
* copy all changes:
2024-03-05 08:54:31 -08:00
* from `NoteCreateService.create` to `NoteCreateService.import` (and
vice versa if `git` got confused!)
2024-03-04 12:21:46 -08:00
* from `NoteCreateService` to `NoteEditService`
* from `ApNoteService.createNote` to `ApNoteService.updateNote`
* from `endoints/notes/create.ts` to `endoints/notes/edit.ts`
* from `MkNote*` to `SkNote*` (if sensible)
* run tests `pnpm test` and fix as much as you can
* run lint `pnpm --filter=backend lint` + `pnpm --filter=frontend
eslint` and fix as much as you can
Then push and open a Merge Request.