|
1 | | -import spawn from 'cross-spawn'; |
| 1 | +import { execa } from 'execa'; |
2 | 2 | import { copyFile, writeFile } from 'fs/promises'; |
3 | 3 | import { existsSync } from 'node:fs'; |
4 | 4 | import { join } from 'node:path'; |
5 | 5 | import { ensureDir, type BuildConfig } from './util'; |
6 | 6 |
|
7 | 7 | export async function buildPlatformBinding(config: BuildConfig) { |
8 | | - await new Promise((resolve, reject) => { |
9 | | - try { |
10 | | - ensureDir(config.distQwikPkgDir); |
11 | | - ensureDir(config.distBindingsDir); |
12 | | - |
13 | | - const cmd = `napi`; |
14 | | - const args = [ |
15 | | - `build`, |
16 | | - `--cargo-name`, |
17 | | - 'qwik_napi', |
18 | | - `--platform`, |
19 | | - `--config=packages/qwik/src/napi/napi.config.json`, |
20 | | - config.distBindingsDir, |
21 | | - ]; |
22 | | - |
23 | | - if (config.platformTarget) { |
24 | | - args.push(`--target`, config.platformTarget); |
25 | | - } |
26 | | - if (!config.dev) { |
27 | | - args.push(`--release`); |
28 | | - args.push(`--strip`); |
29 | | - } |
| 8 | + ensureDir(config.distQwikPkgDir); |
| 9 | + ensureDir(config.distBindingsDir); |
30 | 10 |
|
31 | | - const napiCwd = join(config.rootDir); |
| 11 | + const cmd = `napi`; |
| 12 | + const args = [ |
| 13 | + `build`, |
| 14 | + `--cargo-name`, |
| 15 | + 'qwik_napi', |
| 16 | + `--platform`, |
| 17 | + `--config=packages/qwik/src/napi/napi.config.json`, |
| 18 | + config.distBindingsDir, |
| 19 | + ]; |
| 20 | + |
| 21 | + if (config.platformTarget) { |
| 22 | + args.push(`--target`, config.platformTarget); |
| 23 | + } |
| 24 | + if (!config.dev) { |
| 25 | + args.push(`--release`); |
| 26 | + args.push(`--strip`); |
| 27 | + } |
32 | 28 |
|
33 | | - const child = spawn(cmd, args, { stdio: 'inherit', cwd: napiCwd }); |
34 | | - child.on('error', reject); |
| 29 | + const napiCwd = join(config.rootDir); |
35 | 30 |
|
36 | | - child.on('close', (code) => { |
37 | | - if (code === 0) { |
38 | | - resolve(child.stdout); |
39 | | - } else { |
40 | | - reject(`napi exited with code ${code}`); |
41 | | - } |
42 | | - }); |
43 | | - } catch (e) { |
44 | | - reject(e); |
45 | | - } |
| 31 | + await execa(cmd, args, { |
| 32 | + stdio: 'inherit', |
| 33 | + cwd: napiCwd, |
46 | 34 | }); |
47 | 35 |
|
48 | 36 | console.log('🐯 native binding'); |
@@ -99,21 +87,7 @@ export async function copyPlatformBindingWasm(config: BuildConfig) { |
99 | 87 | // now unpack the package using tar, into the cache directory |
100 | 88 | const unpackedPath = join(cacheDir, `${realPackageName}-unpacked`); |
101 | 89 | ensureDir(unpackedPath); |
102 | | - await new Promise((resolve, reject) => { |
103 | | - const child = spawn('tar', ['-xvf', cachedPath, '-C', unpackedPath]); |
104 | | - child.on('error', (e) => { |
105 | | - console.error(e); |
106 | | - reject(e); |
107 | | - }); |
108 | | - child.on('close', (code) => { |
109 | | - if (code === 0) { |
110 | | - resolve(child.stdout); |
111 | | - } else { |
112 | | - console.error(child.stdout); |
113 | | - reject(`tar exited with code ${code}`); |
114 | | - } |
115 | | - }); |
116 | | - }); |
| 90 | + await execa('tar', ['-xvf', cachedPath, '-C', unpackedPath]); |
117 | 91 |
|
118 | 92 | // now we need to find the bindings in the package |
119 | 93 | cacheVersionDir = join(unpackedPath, 'package', 'bindings'); |
|
0 commit comments