summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorおさむのひと <46447427+samunohito@users.noreply.github.com>2024-03-30 15:28:19 +0900
committerGitHub <noreply@github.com>2024-03-30 15:28:19 +0900
commit2a851437ffcd8778d157a6841875f03330c994b5 (patch)
tree14d21c9a022c02d00eeecf932b25acd485af3f89 /packages
parentfix(backend): better `notes/translate` error response (#13631) (diff)
downloadmisskey-2a851437ffcd8778d157a6841875f03330c994b5.tar.gz
misskey-2a851437ffcd8778d157a6841875f03330c994b5.tar.bz2
misskey-2a851437ffcd8778d157a6841875f03330c994b5.zip
fix: misskey-js、bubble-game、reversiのビルドをesbuildに統合する (#13600)
* fix: ビルドが遅いパッケージのビルド速度を改善 * dependenciesの整理 * fix ci * ビルド開始時に古いファイルを消す * fix ci * fix ci
Diffstat (limited to 'packages')
-rw-r--r--packages/backend/.swcrc3
-rw-r--r--packages/misskey-bubble-game/.eslintignore1
-rw-r--r--packages/misskey-bubble-game/build.js114
-rw-r--r--packages/misskey-bubble-game/package.json26
-rw-r--r--packages/misskey-bubble-game/src/index.ts6
-rw-r--r--packages/misskey-bubble-game/tsconfig.json2
-rw-r--r--packages/misskey-js/.eslintignore1
-rw-r--r--packages/misskey-js/api-extractor.json2
-rw-r--r--packages/misskey-js/build.js105
-rw-r--r--packages/misskey-js/package.json29
-rw-r--r--packages/misskey-js/src/api.ts2
-rw-r--r--packages/misskey-js/src/index.ts15
-rw-r--r--packages/misskey-js/tsconfig.json2
-rw-r--r--packages/misskey-reversi/.eslintignore1
-rw-r--r--packages/misskey-reversi/build.js114
-rw-r--r--packages/misskey-reversi/package.json26
-rw-r--r--packages/misskey-reversi/tsconfig.json2
17 files changed, 354 insertions, 97 deletions
diff --git a/packages/backend/.swcrc b/packages/backend/.swcrc
index 0504a2d389..845190b5f4 100644
--- a/packages/backend/.swcrc
+++ b/packages/backend/.swcrc
@@ -19,5 +19,6 @@
},
"target": "es2022"
},
- "minify": false
+ "minify": false,
+ "sourceMaps": "inline"
}
diff --git a/packages/misskey-bubble-game/.eslintignore b/packages/misskey-bubble-game/.eslintignore
index f22128f047..52ea8b3362 100644
--- a/packages/misskey-bubble-game/.eslintignore
+++ b/packages/misskey-bubble-game/.eslintignore
@@ -5,3 +5,4 @@ node_modules
/jest.config.ts
/test
/test-d
+build.js
diff --git a/packages/misskey-bubble-game/build.js b/packages/misskey-bubble-game/build.js
index 4744dfaf7b..0b79f4b915 100644
--- a/packages/misskey-bubble-game/build.js
+++ b/packages/misskey-bubble-game/build.js
@@ -1,31 +1,105 @@
+import * as esbuild from "esbuild";
import { build } from "esbuild";
import { globSync } from "glob";
+import { execa } from "execa";
+import fs from "node:fs";
+import { fileURLToPath } from "node:url";
+import { dirname } from "node:path";
+
+const _filename = fileURLToPath(import.meta.url);
+const _dirname = dirname(_filename);
+const _package = JSON.parse(fs.readFileSync(_dirname + '/package.json', 'utf-8'));
const entryPoints = globSync("./src/**/**.{ts,tsx}");
/** @type {import('esbuild').BuildOptions} */
const options = {
- entryPoints,
- minify: true,
- outdir: "./built/esm",
- target: "es2022",
- platform: "browser",
- format: "esm",
+ entryPoints,
+ minify: process.env.NODE_ENV === 'production',
+ outdir: "./built",
+ target: "es2022",
+ platform: "browser",
+ format: "esm",
+ sourcemap: 'linked',
};
-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);
- }
- },
- };
+// built配下をすべて削除する
+fs.rmSync('./built', { recursive: true, force: true });
+
+if (process.argv.map(arg => arg.toLowerCase()).includes("--watch")) {
+ await watchSrc();
+} else {
+ await buildSrc();
+}
+
+async function buildSrc() {
+ console.log(`[${_package.name}] start building...`);
+
+ await build(options)
+ .then(it => {
+ console.log(`[${_package.name}] build succeeded.`);
+ })
+ .catch((err) => {
+ process.stderr.write(err.stderr);
+ process.exit(1);
+ });
+
+ if (process.env.NODE_ENV === 'production') {
+ console.log(`[${_package.name}] skip building d.ts because NODE_ENV is production.`);
+ } else {
+ await buildDts();
+ }
+
+ console.log(`[${_package.name}] finish building.`);
}
-build(options).catch((err) => {
- process.stderr.write(err.stderr);
- process.exit(1);
-});
+function buildDts() {
+ return execa(
+ 'tsc',
+ [
+ '--project', 'tsconfig.json',
+ '--outDir', 'built',
+ '--declaration', 'true',
+ '--emitDeclarationOnly', 'true',
+ ],
+ {
+ stdout: process.stdout,
+ stderr: process.stderr,
+ }
+ );
+}
+
+async function watchSrc() {
+ const plugins = [{
+ name: 'gen-dts',
+ setup(build) {
+ build.onStart(() => {
+ console.log(`[${_package.name}] detect changed...`);
+ });
+ build.onEnd(async result => {
+ if (result.errors.length > 0) {
+ console.error(`[${_package.name}] watch build failed:`, result);
+ return;
+ }
+ await buildDts();
+ });
+ },
+ }];
+
+ console.log(`[${_package.name}] start watching...`)
+
+ const context = await esbuild.context({ ...options, plugins });
+ await context.watch();
+
+ await new Promise((resolve, reject) => {
+ process.on('SIGHUP', resolve);
+ process.on('SIGINT', resolve);
+ process.on('SIGTERM', resolve);
+ process.on('SIGKILL', resolve);
+ process.on('uncaughtException', reject);
+ process.on('exit', resolve);
+ }).finally(async () => {
+ await context.dispose();
+ console.log(`[${_package.name}] finish watching.`);
+ });
+}
diff --git a/packages/misskey-bubble-game/package.json b/packages/misskey-bubble-game/package.json
index ddc4c2134b..a3aad147a9 100644
--- a/packages/misskey-bubble-game/package.json
+++ b/packages/misskey-bubble-game/package.json
@@ -2,24 +2,21 @@
"type": "module",
"name": "misskey-bubble-game",
"version": "0.0.1",
- "types": "./built/dts/index.d.ts",
+ "main": "./built/index.js",
+ "types": "./built/index.d.ts",
"exports": {
".": {
- "import": "./built/esm/index.js",
- "types": "./built/dts/index.d.ts"
+ "import": "./built/index.js",
+ "types": "./built/index.d.ts"
},
"./*": {
- "import": "./built/esm/*",
- "types": "./built/dts/*"
+ "import": "./built/*",
+ "types": "./built/*"
}
},
"scripts": {
"build": "node ./build.js",
- "build:tsc": "npm run tsc",
- "tsc": "npm run tsc-esm && npm run tsc-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\"",
+ "watch": "nodemon -w package.json -e json --exec \"node ./build.js --watch\"",
"eslint": "eslint . --ext .js,.jsx,.ts,.tsx",
"typecheck": "tsc --noEmit",
"lint": "pnpm typecheck && pnpm eslint"
@@ -27,21 +24,22 @@
"devDependencies": {
"@misskey-dev/eslint-plugin": "1.0.0",
"@types/matter-js": "0.19.6",
- "@types/node": "20.11.5",
"@types/seedrandom": "3.0.8",
+ "@types/node": "20.11.5",
"@typescript-eslint/eslint-plugin": "7.1.0",
"@typescript-eslint/parser": "7.1.0",
"eslint": "8.57.0",
"nodemon": "3.0.2",
- "typescript": "5.3.3"
+ "execa": "8.0.1",
+ "typescript": "5.3.3",
+ "esbuild": "0.19.11",
+ "glob": "10.3.10"
},
"files": [
"built"
],
"dependencies": {
- "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-bubble-game/src/index.ts b/packages/misskey-bubble-game/src/index.ts
index 004a7d008e..c5f1f68062 100644
--- a/packages/misskey-bubble-game/src/index.ts
+++ b/packages/misskey-bubble-game/src/index.ts
@@ -6,5 +6,9 @@
import { DropAndFusionGame, Mono } from './game.js';
export {
- DropAndFusionGame, Mono,
+ DropAndFusionGame,
+};
+
+export type {
+ Mono,
};
diff --git a/packages/misskey-bubble-game/tsconfig.json b/packages/misskey-bubble-game/tsconfig.json
index f56b65e868..6e34e332e0 100644
--- a/packages/misskey-bubble-game/tsconfig.json
+++ b/packages/misskey-bubble-game/tsconfig.json
@@ -6,7 +6,7 @@
"moduleResolution": "nodenext",
"declaration": true,
"declarationMap": true,
- "sourceMap": true,
+ "sourceMap": false,
"outDir": "./built/",
"removeComments": true,
"strict": true,
diff --git a/packages/misskey-js/.eslintignore b/packages/misskey-js/.eslintignore
index f22128f047..52ea8b3362 100644
--- a/packages/misskey-js/.eslintignore
+++ b/packages/misskey-js/.eslintignore
@@ -5,3 +5,4 @@ node_modules
/jest.config.ts
/test
/test-d
+build.js
diff --git a/packages/misskey-js/api-extractor.json b/packages/misskey-js/api-extractor.json
index f80d0f20a8..a95281a6d5 100644
--- a/packages/misskey-js/api-extractor.json
+++ b/packages/misskey-js/api-extractor.json
@@ -45,7 +45,7 @@
*
* SUPPORTED TOKENS: <projectFolder>, <packageName>, <unscopedPackageName>
*/
- "mainEntryPointFilePath": "<projectFolder>/built/dts/index.d.ts",
+ "mainEntryPointFilePath": "<projectFolder>/built/index.d.ts",
/**
* A list of NPM package names whose exports should be treated as part of this package.
diff --git a/packages/misskey-js/build.js b/packages/misskey-js/build.js
new file mode 100644
index 0000000000..0b79f4b915
--- /dev/null
+++ b/packages/misskey-js/build.js
@@ -0,0 +1,105 @@
+import * as esbuild from "esbuild";
+import { build } from "esbuild";
+import { globSync } from "glob";
+import { execa } from "execa";
+import fs from "node:fs";
+import { fileURLToPath } from "node:url";
+import { dirname } from "node:path";
+
+const _filename = fileURLToPath(import.meta.url);
+const _dirname = dirname(_filename);
+const _package = JSON.parse(fs.readFileSync(_dirname + '/package.json', 'utf-8'));
+
+const entryPoints = globSync("./src/**/**.{ts,tsx}");
+
+/** @type {import('esbuild').BuildOptions} */
+const options = {
+ entryPoints,
+ minify: process.env.NODE_ENV === 'production',
+ outdir: "./built",
+ target: "es2022",
+ platform: "browser",
+ format: "esm",
+ sourcemap: 'linked',
+};
+
+// built配下をすべて削除する
+fs.rmSync('./built', { recursive: true, force: true });
+
+if (process.argv.map(arg => arg.toLowerCase()).includes("--watch")) {
+ await watchSrc();
+} else {
+ await buildSrc();
+}
+
+async function buildSrc() {
+ console.log(`[${_package.name}] start building...`);
+
+ await build(options)
+ .then(it => {
+ console.log(`[${_package.name}] build succeeded.`);
+ })
+ .catch((err) => {
+ process.stderr.write(err.stderr);
+ process.exit(1);
+ });
+
+ if (process.env.NODE_ENV === 'production') {
+ console.log(`[${_package.name}] skip building d.ts because NODE_ENV is production.`);
+ } else {
+ await buildDts();
+ }
+
+ console.log(`[${_package.name}] finish building.`);
+}
+
+function buildDts() {
+ return execa(
+ 'tsc',
+ [
+ '--project', 'tsconfig.json',
+ '--outDir', 'built',
+ '--declaration', 'true',
+ '--emitDeclarationOnly', 'true',
+ ],
+ {
+ stdout: process.stdout,
+ stderr: process.stderr,
+ }
+ );
+}
+
+async function watchSrc() {
+ const plugins = [{
+ name: 'gen-dts',
+ setup(build) {
+ build.onStart(() => {
+ console.log(`[${_package.name}] detect changed...`);
+ });
+ build.onEnd(async result => {
+ if (result.errors.length > 0) {
+ console.error(`[${_package.name}] watch build failed:`, result);
+ return;
+ }
+ await buildDts();
+ });
+ },
+ }];
+
+ console.log(`[${_package.name}] start watching...`)
+
+ const context = await esbuild.context({ ...options, plugins });
+ await context.watch();
+
+ await new Promise((resolve, reject) => {
+ process.on('SIGHUP', resolve);
+ process.on('SIGINT', resolve);
+ process.on('SIGTERM', resolve);
+ process.on('SIGKILL', resolve);
+ process.on('uncaughtException', reject);
+ process.on('exit', resolve);
+ }).finally(async () => {
+ await context.dispose();
+ console.log(`[${_package.name}] finish watching.`);
+ });
+}
diff --git a/packages/misskey-js/package.json b/packages/misskey-js/package.json
index 772f001c07..a9c75c95c2 100644
--- a/packages/misskey-js/package.json
+++ b/packages/misskey-js/package.json
@@ -3,23 +3,21 @@
"name": "misskey-js",
"version": "2024.3.1",
"description": "Misskey SDK for JavaScript",
- "types": "./built/dts/index.d.ts",
+ "main": "./built/index.js",
+ "types": "./built/index.d.ts",
"exports": {
".": {
- "import": "./built/esm/index.js",
- "types": "./built/dts/index.d.ts"
+ "import": "./built/index.js",
+ "types": "./built/index.d.ts"
},
"./*": {
- "import": "./built/esm/*",
- "types": "./built/dts/*"
+ "import": "./built/*",
+ "types": "./built/*"
}
},
"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 ts\"",
+ "build": "node ./build.js",
+ "watch": "nodemon -w package.json -e json --exec \"node ./build.js --watch\"",
"tsd": "tsd",
"api": "pnpm api-extractor run --local --verbose",
"api-prod": "pnpm api-extractor run --verbose",
@@ -49,17 +47,16 @@
"mock-socket": "9.3.1",
"ncp": "2.0.0",
"nodemon": "3.1.0",
+ "execa": "8.0.1",
"tsd": "0.30.7",
- "typescript": "5.3.3"
+ "typescript": "5.3.3",
+ "esbuild": "0.19.11",
+ "glob": "10.3.10"
},
"files": [
- "built",
- "built/esm",
- "built/dts"
+ "built"
],
"dependencies": {
- "@swc/cli": "0.1.63",
- "@swc/core": "1.3.105",
"eventemitter3": "5.0.1",
"reconnecting-websocket": "4.4.0"
}
diff --git a/packages/misskey-js/src/api.ts b/packages/misskey-js/src/api.ts
index 134ead0d79..959a634a74 100644
--- a/packages/misskey-js/src/api.ts
+++ b/packages/misskey-js/src/api.ts
@@ -3,7 +3,7 @@ import './autogen/apiClientJSDoc.js';
import { SwitchCaseResponseType } from './api.types.js';
import type { Endpoints } from './api.types.js';
-export {
+export type {
SwitchCaseResponseType,
} from './api.types.js';
diff --git a/packages/misskey-js/src/index.ts b/packages/misskey-js/src/index.ts
index 54cae8ec03..28007a8ade 100644
--- a/packages/misskey-js/src/index.ts
+++ b/packages/misskey-js/src/index.ts
@@ -1,17 +1,20 @@
-import { Endpoints } from './api.types.js';
+import { type Endpoints } from './api.types.js';
import Stream, { Connection } from './streaming.js';
-import { Channels } from './streaming.types.js';
-import { Acct } from './acct.js';
+import { type Channels } from './streaming.types.js';
+import { type Acct } from './acct.js';
import * as consts from './consts.js';
-export {
+export type {
Endpoints,
- Stream,
- Connection as ChannelConnection,
Channels,
Acct,
};
+export {
+ Stream,
+ Connection as ChannelConnection,
+};
+
export const permissions = consts.permissions;
export const notificationTypes = consts.notificationTypes;
export const noteVisibilities = consts.noteVisibilities;
diff --git a/packages/misskey-js/tsconfig.json b/packages/misskey-js/tsconfig.json
index f56b65e868..6e34e332e0 100644
--- a/packages/misskey-js/tsconfig.json
+++ b/packages/misskey-js/tsconfig.json
@@ -6,7 +6,7 @@
"moduleResolution": "nodenext",
"declaration": true,
"declarationMap": true,
- "sourceMap": true,
+ "sourceMap": false,
"outDir": "./built/",
"removeComments": true,
"strict": true,
diff --git a/packages/misskey-reversi/.eslintignore b/packages/misskey-reversi/.eslintignore
index f22128f047..52ea8b3362 100644
--- a/packages/misskey-reversi/.eslintignore
+++ b/packages/misskey-reversi/.eslintignore
@@ -5,3 +5,4 @@ node_modules
/jest.config.ts
/test
/test-d
+build.js
diff --git a/packages/misskey-reversi/build.js b/packages/misskey-reversi/build.js
index 4744dfaf7b..0b79f4b915 100644
--- a/packages/misskey-reversi/build.js
+++ b/packages/misskey-reversi/build.js
@@ -1,31 +1,105 @@
+import * as esbuild from "esbuild";
import { build } from "esbuild";
import { globSync } from "glob";
+import { execa } from "execa";
+import fs from "node:fs";
+import { fileURLToPath } from "node:url";
+import { dirname } from "node:path";
+
+const _filename = fileURLToPath(import.meta.url);
+const _dirname = dirname(_filename);
+const _package = JSON.parse(fs.readFileSync(_dirname + '/package.json', 'utf-8'));
const entryPoints = globSync("./src/**/**.{ts,tsx}");
/** @type {import('esbuild').BuildOptions} */
const options = {
- entryPoints,
- minify: true,
- outdir: "./built/esm",
- target: "es2022",
- platform: "browser",
- format: "esm",
+ entryPoints,
+ minify: process.env.NODE_ENV === 'production',
+ outdir: "./built",
+ target: "es2022",
+ platform: "browser",
+ format: "esm",
+ sourcemap: 'linked',
};
-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);
- }
- },
- };
+// built配下をすべて削除する
+fs.rmSync('./built', { recursive: true, force: true });
+
+if (process.argv.map(arg => arg.toLowerCase()).includes("--watch")) {
+ await watchSrc();
+} else {
+ await buildSrc();
+}
+
+async function buildSrc() {
+ console.log(`[${_package.name}] start building...`);
+
+ await build(options)
+ .then(it => {
+ console.log(`[${_package.name}] build succeeded.`);
+ })
+ .catch((err) => {
+ process.stderr.write(err.stderr);
+ process.exit(1);
+ });
+
+ if (process.env.NODE_ENV === 'production') {
+ console.log(`[${_package.name}] skip building d.ts because NODE_ENV is production.`);
+ } else {
+ await buildDts();
+ }
+
+ console.log(`[${_package.name}] finish building.`);
}
-build(options).catch((err) => {
- process.stderr.write(err.stderr);
- process.exit(1);
-});
+function buildDts() {
+ return execa(
+ 'tsc',
+ [
+ '--project', 'tsconfig.json',
+ '--outDir', 'built',
+ '--declaration', 'true',
+ '--emitDeclarationOnly', 'true',
+ ],
+ {
+ stdout: process.stdout,
+ stderr: process.stderr,
+ }
+ );
+}
+
+async function watchSrc() {
+ const plugins = [{
+ name: 'gen-dts',
+ setup(build) {
+ build.onStart(() => {
+ console.log(`[${_package.name}] detect changed...`);
+ });
+ build.onEnd(async result => {
+ if (result.errors.length > 0) {
+ console.error(`[${_package.name}] watch build failed:`, result);
+ return;
+ }
+ await buildDts();
+ });
+ },
+ }];
+
+ console.log(`[${_package.name}] start watching...`)
+
+ const context = await esbuild.context({ ...options, plugins });
+ await context.watch();
+
+ await new Promise((resolve, reject) => {
+ process.on('SIGHUP', resolve);
+ process.on('SIGINT', resolve);
+ process.on('SIGTERM', resolve);
+ process.on('SIGKILL', resolve);
+ process.on('uncaughtException', reject);
+ process.on('exit', resolve);
+ }).finally(async () => {
+ await context.dispose();
+ console.log(`[${_package.name}] finish watching.`);
+ });
+}
diff --git a/packages/misskey-reversi/package.json b/packages/misskey-reversi/package.json
index 7bfc890fef..45a6120861 100644
--- a/packages/misskey-reversi/package.json
+++ b/packages/misskey-reversi/package.json
@@ -2,24 +2,21 @@
"type": "module",
"name": "misskey-reversi",
"version": "0.0.1",
- "types": "./built/dts/index.d.ts",
+ "main": "./built/index.js",
+ "types": "./built/index.d.ts",
"exports": {
".": {
- "import": "./built/esm/index.js",
- "types": "./built/dts/index.d.ts"
+ "import": "./built/index.js",
+ "types": "./built/index.d.ts"
},
"./*": {
- "import": "./built/esm/*",
- "types": "./built/dts/*"
+ "import": "./built/*",
+ "types": "./built/*"
}
},
"scripts": {
"build": "node ./build.js",
- "build:tsc": "npm run tsc",
- "tsc": "npm run tsc-esm && npm run tsc-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\"",
+ "watch": "nodemon -w package.json -e json --exec \"node ./build.js --watch\"",
"eslint": "eslint . --ext .js,.jsx,.ts,.tsx",
"typecheck": "tsc --noEmit",
"lint": "pnpm typecheck && pnpm eslint"
@@ -30,15 +27,16 @@
"@typescript-eslint/eslint-plugin": "7.1.0",
"@typescript-eslint/parser": "7.1.0",
"eslint": "8.57.0",
+ "execa": "8.0.1",
"nodemon": "3.0.2",
- "typescript": "5.3.3"
+ "typescript": "5.3.3",
+ "esbuild": "0.19.11",
+ "glob": "10.3.10"
},
"files": [
"built"
],
"dependencies": {
- "crc-32": "1.2.2",
- "esbuild": "0.19.11",
- "glob": "10.3.10"
+ "crc-32": "1.2.2"
}
}
diff --git a/packages/misskey-reversi/tsconfig.json b/packages/misskey-reversi/tsconfig.json
index f56b65e868..6e34e332e0 100644
--- a/packages/misskey-reversi/tsconfig.json
+++ b/packages/misskey-reversi/tsconfig.json
@@ -6,7 +6,7 @@
"moduleResolution": "nodenext",
"declaration": true,
"declarationMap": true,
- "sourceMap": true,
+ "sourceMap": false,
"outDir": "./built/",
"removeComments": true,
"strict": true,