From af2d81a9902944929f8932db5665141724cadd9c Mon Sep 17 00:00:00 2001 From: tamaina Date: Tue, 23 Jan 2024 06:36:44 +0900 Subject: [PATCH] =?UTF-8?q?perf:=20(production=E3=81=AE)dependencies?= =?UTF-8?q?=E3=81=8B=E3=82=89@types=E3=82=92=E5=89=8A=E9=99=A4=E3=80=81rev?= =?UTF-8?q?ersi/bubble-game=E3=82=92esbuild=E3=81=AB=E3=81=99=E3=82=8B=20(?= =?UTF-8?q?#13067)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf: (productionの)dependenciesから@typesを削除、reversi/bubble-gameをesbuildにする * fix * fix --- .github/workflows/lint.yml | 2 +- packages/misskey-bubble-game/build.js | 31 +++++++++++++++++++ packages/misskey-bubble-game/package.json | 17 ++++++----- packages/misskey-reversi/.eslintrc.cjs | 1 + packages/misskey-reversi/build.js | 31 +++++++++++++++++++ packages/misskey-reversi/package.json | 13 ++++---- pnpm-lock.yaml | 36 ++++++++++++++--------- 7 files changed, 104 insertions(+), 27 deletions(-) create mode 100644 packages/misskey-bubble-game/build.js create mode 100644 packages/misskey-reversi/build.js diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index fe2d7fce4..86fca995d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -92,6 +92,6 @@ jobs: - run: pnpm i --frozen-lockfile - run: pnpm --filter misskey-js run build if: ${{ matrix.workspace == 'backend' }} - - run: pnpm --filter misskey-reversi run build + - run: pnpm --filter misskey-reversi run build:tsc if: ${{ matrix.workspace == 'backend' }} - run: pnpm --filter ${{ matrix.workspace }} run typecheck diff --git a/packages/misskey-bubble-game/build.js b/packages/misskey-bubble-game/build.js new file mode 100644 index 000000000..4744dfaf7 --- /dev/null +++ b/packages/misskey-bubble-game/build.js @@ -0,0 +1,31 @@ +import { build } from "esbuild"; +import { globSync } from "glob"; + +const entryPoints = globSync("./src/**/**.{ts,tsx}"); + +/** @type {import('esbuild').BuildOptions} */ +const options = { + entryPoints, + minify: true, + outdir: "./built/esm", + target: "es2022", + platform: "browser", + format: "esm", +}; + +if (process.env.WATCH === "true") { + options.watch = { + onRebuild(error, result) { + if (error) { + console.error("watch build failed:", error); + } else { + console.log("watch build succeeded:", result); + } + }, + }; +} + +build(options).catch((err) => { + process.stderr.write(err.stderr); + process.exit(1); +}); diff --git a/packages/misskey-bubble-game/package.json b/packages/misskey-bubble-game/package.json index 1dfa7afcd..5a6b952e0 100644 --- a/packages/misskey-bubble-game/package.json +++ b/packages/misskey-bubble-game/package.json @@ -13,18 +13,21 @@ } }, "scripts": { - "build": "npm run ts", - "ts": "npm run ts-esm && npm run ts-dts", - "ts-esm": "tsc --outDir built/esm", - "ts-dts": "tsc --outDir built/dts --declaration true --emitDeclarationOnly true --declarationMap true", - "watch": "nodemon -w src -e ts,js,cjs,mjs,json --exec \"pnpm run build\"", + "build": "node ./build.js", + "build:tsc": "npm run tsc", + "tsc": "npm run ts-esm && npm run ts-dts", + "tsc-esm": "tsc --outDir built/esm", + "tsc-dts": "tsc --outDir built/dts --declaration true --emitDeclarationOnly true --declarationMap true", + "watch": "nodemon -w src -e ts,js,cjs,mjs,json --exec \"pnpm run build:tsc\"", "eslint": "eslint . --ext .js,.jsx,.ts,.tsx", "typecheck": "tsc --noEmit", "lint": "pnpm typecheck && pnpm eslint" }, "devDependencies": { "@misskey-dev/eslint-plugin": "1.0.0", + "@types/matter-js": "0.19.6", "@types/node": "20.11.5", + "@types/seedrandom": "3.0.8", "@typescript-eslint/eslint-plugin": "6.18.1", "@typescript-eslint/parser": "6.18.1", "eslint": "8.56.0", @@ -35,9 +38,9 @@ "built" ], "dependencies": { - "@types/matter-js": "0.19.6", - "@types/seedrandom": "3.0.8", + "esbuild": "0.19.11", "eventemitter3": "5.0.1", + "glob": "^10.3.10", "matter-js": "0.19.0", "seedrandom": "3.0.5" } diff --git a/packages/misskey-reversi/.eslintrc.cjs b/packages/misskey-reversi/.eslintrc.cjs index e2e31e9e3..db37a0109 100644 --- a/packages/misskey-reversi/.eslintrc.cjs +++ b/packages/misskey-reversi/.eslintrc.cjs @@ -1,4 +1,5 @@ module.exports = { + root: true, parserOptions: { tsconfigRootDir: __dirname, project: ['./tsconfig.json'], diff --git a/packages/misskey-reversi/build.js b/packages/misskey-reversi/build.js new file mode 100644 index 000000000..4744dfaf7 --- /dev/null +++ b/packages/misskey-reversi/build.js @@ -0,0 +1,31 @@ +import { build } from "esbuild"; +import { globSync } from "glob"; + +const entryPoints = globSync("./src/**/**.{ts,tsx}"); + +/** @type {import('esbuild').BuildOptions} */ +const options = { + entryPoints, + minify: true, + outdir: "./built/esm", + target: "es2022", + platform: "browser", + format: "esm", +}; + +if (process.env.WATCH === "true") { + options.watch = { + onRebuild(error, result) { + if (error) { + console.error("watch build failed:", error); + } else { + console.log("watch build succeeded:", result); + } + }, + }; +} + +build(options).catch((err) => { + process.stderr.write(err.stderr); + process.exit(1); +}); diff --git a/packages/misskey-reversi/package.json b/packages/misskey-reversi/package.json index e65e484b6..7940b9bac 100644 --- a/packages/misskey-reversi/package.json +++ b/packages/misskey-reversi/package.json @@ -13,11 +13,12 @@ } }, "scripts": { - "build": "npm run ts", - "ts": "npm run ts-esm && npm run ts-dts", - "ts-esm": "tsc --outDir built/esm", - "ts-dts": "tsc --outDir built/dts --declaration true --emitDeclarationOnly true --declarationMap true", - "watch": "nodemon -w src -e ts,js,cjs,mjs,json --exec \"pnpm run build\"", + "build": "node ./build.js", + "build:tsc": "npm run ts", + "tsc": "npm run ts-esm && npm run ts-dts", + "tsc-esm": "tsc --outDir built/esm", + "tsc-dts": "tsc --outDir built/dts --declaration true --emitDeclarationOnly true --declarationMap true", + "watch": "nodemon -w src -e ts,js,cjs,mjs,json --exec \"pnpm run build:tsc\"", "eslint": "eslint . --ext .js,.jsx,.ts,.tsx", "typecheck": "tsc --noEmit", "lint": "pnpm typecheck && pnpm eslint" @@ -35,5 +36,7 @@ "built" ], "dependencies": { + "esbuild": "0.19.11", + "glob": "^10.3.10" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fd6a58c0d..05c245a10 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1031,15 +1031,15 @@ importers: packages/misskey-bubble-game: dependencies: - '@types/matter-js': - specifier: 0.19.6 - version: 0.19.6 - '@types/seedrandom': - specifier: 3.0.8 - version: 3.0.8 + esbuild: + specifier: 0.19.11 + version: 0.19.11 eventemitter3: specifier: 5.0.1 version: 5.0.1 + glob: + specifier: ^10.3.10 + version: 10.3.10 matter-js: specifier: 0.19.0 version: 0.19.0 @@ -1050,9 +1050,15 @@ importers: '@misskey-dev/eslint-plugin': specifier: 1.0.0 version: 1.0.0(@typescript-eslint/eslint-plugin@6.18.1)(@typescript-eslint/parser@6.18.1)(eslint-plugin-import@2.29.1)(eslint@8.56.0) + '@types/matter-js': + specifier: 0.19.6 + version: 0.19.6 '@types/node': specifier: 20.11.5 version: 20.11.5 + '@types/seedrandom': + specifier: 3.0.8 + version: 3.0.8 '@typescript-eslint/eslint-plugin': specifier: 6.18.1 version: 6.18.1(@typescript-eslint/parser@6.18.1)(eslint@8.56.0)(typescript@5.3.3) @@ -1170,6 +1176,13 @@ importers: version: 5.3.3 packages/misskey-reversi: + dependencies: + esbuild: + specifier: 0.19.11 + version: 0.19.11 + glob: + specifier: ^10.3.10 + version: 10.3.10 devDependencies: '@misskey-dev/eslint-plugin': specifier: 1.0.0 @@ -8107,6 +8120,7 @@ packages: /@types/matter-js@0.19.6: resolution: {integrity: sha512-ffk6tqJM5scla+ThXmnox+mdfCo3qYk6yMjQsNcrbo6eQ5DqorVdtnaL+1agCoYzxUjmHeiNB7poBMAmhuLY7w==} + dev: true /@types/mdx@2.0.3: resolution: {integrity: sha512-IgHxcT3RC8LzFLhKwP3gbMPeaK7BM9eBH46OdapPA7yvuIUJ8H6zHZV53J8hGZcTSnt95jANt+rTBNUUc22ACQ==} @@ -8295,7 +8309,7 @@ packages: /@types/seedrandom@3.0.8: resolution: {integrity: sha512-TY1eezMU2zH2ozQoAFAQFOPpvP15g+ZgSfTZt31AUUH/Rxtnz3H+A/Sv1Snw2/amp//omibc+AEkTaA8KUeOLQ==} - dev: false + dev: true /@types/semver@7.5.6: resolution: {integrity: sha512-dn1l8LaMea/IjDoHNd9J52uBbInB796CDffS6VdIxvqYCPSG0V0DzHp76GpaWnlhg88uYyPbXCDIowa86ybd5A==} @@ -9967,7 +9981,7 @@ packages: clone-response: 1.0.3 get-stream: 5.2.0 http-cache-semantics: 4.1.1 - keyv: 4.5.2 + keyv: 4.5.4 lowercase-keys: 2.0.0 normalize-url: 6.1.0 responselike: 2.0.1 @@ -14648,12 +14662,6 @@ packages: safe-buffer: 5.2.1 dev: false - /keyv@4.5.2: - resolution: {integrity: sha512-5MHbFaKn8cNSmVW7BYnijeAVlE4cYA/SVkifVgrh7yotnfhKmjuXpDKjrABLnT0SfHWV21P8ow07OGfRrNDg8g==} - dependencies: - json-buffer: 3.0.1 - dev: false - /keyv@4.5.4: resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==} dependencies: