Skip to content

Conversation

@samunohito
Copy link
Member

@samunohito samunohito commented Nov 27, 2025

What

#16852 向け。developではなくminify-backendブランチに向けています
backendのminifyが可能かどうかを検証 →node_modulesは含んでいないが、バックエンド単体のminifyそのものは出来た

Why

Additional info (optional)

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests

package.json Outdated
"start": "cd packages/backend && node ./built/entry.js",
"start:inspect": "cd packages/backend && node --inspect ./built/entry.js",
"start:test": "ncp ./.github/misskey/test.yml ./.config/test.yml && cd packages/backend && cross-env NODE_ENV=test node ./built/entry.js",
"start": "cd packages/backend && node ./built/boot/entry.js",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

バックエンドのビルド成果物に依存しているcheck_connect.jsが動かないので、代替手段を考える必要がある

Comment on lines 13 to 26
const resolveTsPathsPlugin = {
name: 'resolve-ts-paths',
setup(build) {
build.onResolve({ filter: /^\.{1,2}\/.*\.js$/ }, (args) => {
if (args.importer) {
const absPath = join(args.resolveDir, args.path);
const tsPath = absPath.slice(0, -3) + '.ts';
if (fs.existsSync(tsPath)) {
return { path: tsPath };
}
}
});
},
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

拡張子.jsを愚直にimportしようとするため、tsに置き換えておかないとfile not foundになる

Comment on lines +28 to +35
const externalIpaddrPlugin = {
name: 'external-ipaddr',
setup(build) {
build.onResolve({ filter: /^ipaddr\.js$/ }, (args) => {
return { path: args.path, external: true };
});
},
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

esbuildがipaddr.jsを外部パッケージだと認識しないので

//minify: process.env.NODE_ENV === 'production',
minify: false,
minify: true,
keepNames: true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これが無いとNestJSのDIが破綻する

format: 'esm',
sourcemap: false,
sourcemap: 'linked',
packages: 'external',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

とりあえずnode_modulesは除外中

Comment on lines +59 to +80
swcPlugin({
jsc: {
parser: {
syntax: 'typescript',
decorators: true,
dynamicImport: true,
},
transform: {
legacyDecorator: true,
decoratorMetadata: true,
},
experimental: {
keepImportAssertions: true,
},
baseUrl: join(_dirname, 'src'),
paths: {
'@/*': ['*'],
},
target: 'esnext',
keepClassNames: true,
},
}),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

esbuild単体だとレガシーデコレーターの解釈が出来ずバックエンドの起動に失敗するため、SWCの力を借りる必要があった

Comment on lines 112 to 117
const rootDir = resolve(_dirname, '../..');
await Promise.all([
copyBackendViews(rootDir),
buildBackendScript(rootDir, buildLocales()),
buildBackendStyle(rootDir),
]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

build-assetsでコピーされるファイル群。
パスの解決やLANGSの置き換えなど、結構厳しい部分が残っているのでこれを機に整理するのが良さそう

*/
const dir = `${_dirname}/../../../.config`;
/** Path of repository root directory */
const rootDir = resolve(_dirname, '../../../../');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ビルド後のファイルからの相対パス

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

バックエンドから無理くり引き回すため切り離したファイル。
前述したが、静的ファイルのコピーなどは改めて見直した方が良さそう

@syuilo
Copy link
Member

syuilo commented Nov 30, 2025

これブランチ追従してもらうことできるかしら

@samunohito
Copy link
Member Author

いちおう現時点までの最新まで追従しますが、 #16889 も入れないと完全にはならなさそうです

@syuilo
Copy link
Member

syuilo commented Nov 30, 2025

バンドルなしでnode_modulesのminifyは #16904 で一応可能ということが分かったのでひとまずバックエンド単体のminifyで十分かもしれない

# Conflicts:
#	packages/backend/package.json
#	pnpm-lock.yaml
#	scripts/build-assets.mjs
@samunohito
Copy link
Member Author

@codecov
Copy link

codecov bot commented Nov 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (minify-backend@e44f993). Learn more about missing BASE report.

Additional details and impacted files
@@                Coverage Diff                @@
##             minify-backend   #16878   +/-   ##
=================================================
  Coverage                  ?   14.00%           
=================================================
  Files                     ?      237           
  Lines                     ?    11287           
  Branches                  ?     3733           
=================================================
  Hits                      ?     1581           
  Misses                    ?     7584           
  Partials                  ?     2122           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@samunohito
Copy link
Member Author

@syuilo
追従はしました(がテストがいっぱいしんでる)

@syuilo
Copy link
Member

syuilo commented Dec 3, 2025

#16889 は入った

@syuilo
Copy link
Member

syuilo commented Dec 3, 2025

時間のあるとき再度ブランチ追従してもらえると助かる

@syuilo
Copy link
Member

syuilo commented Dec 24, 2025

引き継ごうかしら

@samunohito
Copy link
Member Author

(返信あったの気づいてなかった)

@samunohito
Copy link
Member Author

あとでやっておきますわ

# Conflicts:
#	package.json
#	packages/backend/package.json
#	packages/backend/src/config.ts
#	pnpm-lock.yaml
#	scripts/build-assets.mjs
@samunohito
Copy link
Member Author

やっておきましたわ

@syuilo
Copy link
Member

syuilo commented Dec 24, 2025

🙏

@samunohito
Copy link
Member Author

最新のdevelopを直接取り込んでおります

@syuilo
Copy link
Member

syuilo commented Dec 31, 2025

すごい、30MB減った

Before
スクリーンショット 2025-12-31 140706

After
スクリーンショット 2025-12-31 140412

どちらも強制GC済み

@syuilo
Copy link
Member

syuilo commented Dec 31, 2025

Before

image image

After

image image

@syuilo syuilo marked this pull request as ready for review December 31, 2025 05:13
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Dec 31, 2025
@samunohito
Copy link
Member Author

向き先はdevelopではなくminify-backendなので、よさそうであればそのまま持って行っちゃってください

@syuilo syuilo merged commit 8bba886 into misskey-dev:minify-backend Dec 31, 2025
21 of 29 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in [実験中] 管理用 Dec 31, 2025
@syuilo
Copy link
Member

syuilo commented Dec 31, 2025

🙏🏻

@syuilo
Copy link
Member

syuilo commented Dec 31, 2025

若干だけど起動も速くなったような気がしないでもない

syuilo added a commit that referenced this pull request Jan 5, 2026
* wip

* Update build.js

* Update build.js

* [minify-backend用] フィジビリティ検証 (#16878)

* fix: minify-backend

* 間違えて入れちゃったのを戻す

* 追従

* fix

---------

Co-authored-by: syuilo <[email protected]>

* test

* use node 24

* Revert "use node 24"

This reverts commit 7ae2deb.

* Revert "test"

This reverts commit d919879.

* Update package.json

* wip

* Update compile_config.js

* Revert "Update compile_config.js"

This reverts commit 0ee286f.

* Update config.ts

* wip

* Update .swcrc

* Update ClientServerService.ts

* [ci skip] update CHANGELOG

---------

Co-authored-by: おさむのひと <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages/backend:test packages/backend Server side specific issue/PR packages/frontend Client side specific issue/PR packages/misskey-js packages/sw size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Development

Successfully merging this pull request may close these issues.

2 participants