fix: misskey-js、bubble-game、reversiのビルドをesbuildに統合する (#13600)

* fix: ビルドが遅いパッケージのビルド速度を改善

* dependenciesの整理

* fix ci

* ビルド開始時に古いファイルを消す

* fix ci

* fix ci
This commit is contained in:
おさむのひと
2024-03-30 15:28:19 +09:00
committed by GitHub
parent b35ae97ba7
commit 2a851437ff
21 changed files with 421 additions and 281 deletions

View File

@@ -5,3 +5,4 @@ node_modules
/jest.config.ts
/test
/test-d
build.js

View File

@@ -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.

View File

@@ -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.`);
});
}

View File

@@ -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"
}

View File

@@ -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';

View File

@@ -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;

View File

@@ -6,7 +6,7 @@
"moduleResolution": "nodenext",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"sourceMap": false,
"outDir": "./built/",
"removeComments": true,
"strict": true,