Merge pull request #413 from forehalo/fix/build-script

fix(cli): fix random node process got killed issue
This commit is contained in:
LongYinan 2021-01-07 23:53:27 +08:00 committed by GitHub
commit 27dda517ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View file

@ -8,7 +8,7 @@ import toml from 'toml'
import { getNapiConfig } from './consts' import { getNapiConfig } from './consts'
import { debugFactory } from './debug' import { debugFactory } from './debug'
import { getDefaultTargetTriple, parseTriple } from './parse-triple' import { getDefaultTargetTriple, parseTriple } from './parse-triple'
import { existsAsync, readFileAsync, writeFileAsync } from './utils' import { copyFileAsync, existsAsync, readFileAsync, unlinkAsync } from './utils'
const debug = debugFactory('build') const debug = debugFactory('build')
@ -173,13 +173,14 @@ export class BuildCommand extends Command {
} }
const sourcePath = join(dir, 'target', targetDir, `${dylibName}${libExt}`) const sourcePath = join(dir, 'target', targetDir, `${dylibName}${libExt}`)
debug(`Read [${chalk.yellowBright(sourcePath)}] content`)
const dylibContent = await readFileAsync(sourcePath) if (await existsAsync(distModulePath)) {
debug(`remove old binary [${chalk.yellowBright(sourcePath)}]`)
await unlinkAsync(distModulePath)
}
debug(`Write binary content to [${chalk.yellowBright(distModulePath)}]`) debug(`Write binary content to [${chalk.yellowBright(distModulePath)}]`)
await copyFileAsync(sourcePath, distModulePath)
await writeFileAsync(distModulePath, dylibContent)
} }
} }

View file

@ -1,6 +1,8 @@
import { readFile, writeFile, exists } from 'fs' import { readFile, writeFile, exists, copyFile, unlink } from 'fs'
import { promisify } from 'util' import { promisify } from 'util'
export const readFileAsync = promisify(readFile) export const readFileAsync = promisify(readFile)
export const writeFileAsync = promisify(writeFile) export const writeFileAsync = promisify(writeFile)
export const existsAsync = promisify(exists) export const existsAsync = promisify(exists)
export const unlinkAsync = promisify(unlink)
export const copyFileAsync = promisify(copyFile)