forked from misskey-dev/misskey
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: misskey-js、bubble-game、reversiのビルドをesbuildに統合する (misskey-dev#13600)
* fix: ビルドが遅いパッケージのビルド速度を改善 * dependenciesの整理 * fix ci * ビルド開始時に古いファイルを消す * fix ci * fix ci
- Loading branch information
1 parent
b35ae97
commit 2a85143
Showing
21 changed files
with
422 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,6 @@ | |
}, | ||
"target": "es2022" | ||
}, | ||
"minify": false | ||
"minify": false, | ||
"sourceMaps": "inline" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ node_modules | |
/jest.config.ts | ||
/test | ||
/test-d | ||
build.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.`); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ node_modules | |
/jest.config.ts | ||
/test | ||
/test-d | ||
build.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.`); | ||
}); | ||
} |
Oops, something went wrong.