File size: 3,333 Bytes
d739b1b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | // ํ์ ๋ค์ดํฐ๋ธ ๋ชจ๋๋ง ์ค๋นํ๋ค. SSH์ ์ ํ์ CPU/์ํธ ๊ฐ์๊ธฐ๋ JS ๊ฒฝ๋ก๋ฅผ ์ ์งํ๋ค.
// ์ค๋ช
๋ฌธ์: docs/specs/bong-dependency-repair.md (v1.0.0)
const fs = require('node:fs');
const path = require('node:path');
async function prepareNative({ appDir = path.resolve(__dirname, '..'), platform = process.platform,
arch = process.arch, electronVersion = require('electron/package.json').version } = {}) {
if (platform !== process.platform) {
// ๊ต์ฐจ ํ๋ซํผ ํจํค์ง(์: macOS์์ Windows ๋น๋) ์ ํธ์คํธ node-gyp๊ฐ ๋์ OS์ ๋ค๋ฅธ ๋ฐ์ด๋๋ฆฌ๋ก
// ๋ฎ์ด์ฐ์ง ์๋๋ก ๋๋ด๋ N-API ์ฌ์ ๋น๋(better-sqlite3, node-pty) ์กด์ฌ ์ฌ๋ถ๋ฅผ ๊ฒ์ฆํ๋ค.
const sqlitePrebuild = path.join(appDir, 'node_modules/better-sqlite3/prebuilds', `${platform}-${arch}.node`);
const ptyPrebuild = path.join(appDir, 'node_modules/node-pty/prebuilds', `${platform}-${arch}`, 'pty.node');
if (fs.existsSync(sqlitePrebuild) && fs.existsSync(ptyPrebuild)) {
if (platform === 'darwin') {
const helper = path.join(appDir, 'node_modules/node-pty/prebuilds', `${platform}-${arch}`, 'spawn-helper');
if (fs.existsSync(helper)) fs.chmodSync(helper, fs.statSync(helper).mode | 0o111);
}
return;
}
}
const { rebuild } = await import('@electron/rebuild');
await rebuild({
buildPath: appDir,
electronVersion,
platform,
arch,
onlyModules: ['better-sqlite3', 'node-pty']
});
if (platform === 'darwin') {
// npm --ignore-scripts ์ค์น์ ๊ต์ฐจ ์ํคํ
์ฒ ํจํค์ง์๋ ์คํ ๊ถํ์ ๋ณต์ํ๋ค.
const helper = path.join(appDir, 'node_modules/node-pty/prebuilds', `${platform}-${arch}`, 'spawn-helper');
fs.chmodSync(helper, fs.statSync(helper).mode | 0o111);
}
// Linux์๋ PTY ์ฌ์ ๋น๋๊ฐ ์์ผ๋ฏ๋ก ์ rebuild๊ฐ ์ ์ ์์ค ๋น๋๋ฅผ ์ํํด์ผ ํ๋ค.
// ์คํจ๋ ๊ทธ๋๋ก ์ ํํ๋ค. beforeBuild=false๋ ๋น๋ 26์ ์์กด์ฑ ์์ง๊น์ง ์๋ตํ๋ฏ๋ก ์ฌ์ฉํ์ง ์๋๋ค.
}
module.exports = async ({ appOutDir, packager, electronPlatformName, arch }) => {
const unpackedNodePtyBuild = appOutDir
? path.join(appOutDir, 'resources/app.asar.unpacked/node_modules/node-pty/build')
: null;
if (unpackedNodePtyBuild && fs.existsSync(path.join(appOutDir, 'resources/app.asar.unpacked'))) {
if (electronPlatformName !== process.platform && fs.existsSync(unpackedNodePtyBuild)) {
// ๊ต์ฐจ ํ๋ซํผ ํจํค์ง ์ฐ์ถ๋ฌผ์์ ํธ์คํธ OS์ node-pty/build ์์ฌ๋ฌผ์ ์ ๊ฑฐํด prebuilds/<platform>-<arch>๋ฅผ ๋ก๋ํ๊ฒ ํ๋ค.
fs.rmSync(unpackedNodePtyBuild, { recursive: true, force: true });
}
return;
}
const options = { appDir: packager.appDir, platform: electronPlatformName,
arch: require('builder-util').Arch[arch], electronVersion: packager.info.framework.version };
// ์๋ชป๋ OS/์ํคํ
์ฒ์ ๋ด์ฅ ๋ธ๋ก์ปค๋ฅผ ์กฐ์ฉํ ๋ฐฐํฌํ์ง ์๋๋ค. ์ค์น ์์๋ ์๊ตฌํ์ง ์๋๋ค.
// ์ค๋ช
๋ฌธ์: docs/specs/app-lifecycle.md v1.0.0
require('../src/services/nats-binary').validateNatsBinary(options);
return prepareNative(options);
};
if (require.main === module) prepareNative().catch(error => {
console.error('[Native dependencies]', error.message);
process.exitCode = 1;
});
|