-
Notifications
You must be signed in to change notification settings - Fork 41
/
build.js
61 lines (53 loc) · 1.73 KB
/
build.js
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
61
#!/usr/bin/env node
/*
* Copyright 2024 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
'use strict'
// If we are going to support Windows, we need some way to cobble together
// the build command that is portable. In other words, we can't rely on a
// Bash subshell, `$(node...)`, to get the current Node version to provide
// to `--target`. So we'll use the scripting language at our disposal that is
// cross platform 😃
const fs = require('fs/promises')
const path = require('path')
const { spawn } = require('child_process')
main()
.then(() => {
// eslint-disable-next-line no-console
console.log('build done')
})
.catch((error) => {
// eslint-disable-next-line no-console
console.error(error)
})
async function main() {
await fs.rm(path.join(__dirname, 'build'), { force: true, recursive: true })
await fs.rm(path.join(__dirname, 'prebuilds'), { force: true, recursive: true })
const bin = process.argv[0]
const args = [
path.join(__dirname, 'node_modules', 'prebuildify', 'bin.js'),
'--strip',
// We want to apply all tags since we are building across multiple
// Node.js versions. If we don't we will stop on the binaries during
// packaging.
'--tag-uv',
'--tag-armv',
'--tag-libc',
// We need to be explicit here so that the ABI tag gets applied.
'--napi=false',
'--target',
`node@${process.versions.node}`
]
return new Promise((res, rej) => {
const proc = spawn(bin, args)
proc.stderr.pipe(process.stderr)
proc.stdout.pipe(process.stdout)
proc.on('close', (code, signal) => {
if (code !== 0) {
return rej(Error(`failed with code ${code} and signal ${signal}`))
}
res()
})
})
}