1
1
import fs from 'fs-extra' ;
2
2
import path from 'path' ;
3
- import execa from 'execa' ;
3
+ import execa , { ExecaError } from 'execa' ;
4
4
import toml from '@iarna/toml' ;
5
5
import {
6
6
glob ,
@@ -16,6 +16,9 @@ import {
16
16
} from '@vercel/build-utils' ;
17
17
import { installRustAndFriends } from './install-rust' ;
18
18
19
+ type RustEnv = Record < 'RUSTFLAGS' | 'PATH' , string > &
20
+ Record < string , string | undefined > ;
21
+
19
22
interface CargoConfig {
20
23
env : Record < string , any > ;
21
24
cwd : string ;
@@ -67,6 +70,10 @@ async function runUserScripts(entrypoint: string) {
67
70
}
68
71
}
69
72
73
+ function isExecaError ( err : Error ) : err is ExecaError {
74
+ return 'stderr' in err ;
75
+ }
76
+
70
77
async function cargoLocateProject ( config : CargoConfig ) {
71
78
try {
72
79
const { stdout : projectDescriptionStr } = await execa (
@@ -79,10 +86,12 @@ async function cargoLocateProject(config: CargoConfig) {
79
86
return projectDescription . root ;
80
87
}
81
88
} catch ( e ) {
82
- if ( ! / c o u l d n o t f i n d / g. test ( e . stderr ) ) {
83
- console . error ( "Couldn't run `cargo locate-project`" ) ;
84
- throw e ;
89
+ if ( e instanceof Error && isExecaError ( e ) ) {
90
+ if ( ! / c o u l d n o t f i n d / g. test ( e . stderr ) ) {
91
+ console . error ( "Couldn't run `cargo locate-project`" ) ;
92
+ }
85
93
}
94
+ throw e ;
86
95
}
87
96
88
97
return null ;
@@ -164,7 +173,7 @@ async function buildSingleFile(
164
173
{ entrypoint, workPath, meta = { } } : BuildOptions ,
165
174
downloadedFiles : DownloadedFiles ,
166
175
extraFiles : DownloadedFiles ,
167
- rustEnv : Record < string , string >
176
+ rustEnv : RustEnv
168
177
) {
169
178
debug ( 'Building single file' ) ;
170
179
const entrypointPath = downloadedFiles [ entrypoint ] . fsPath ;
@@ -250,7 +259,7 @@ export async function build(opts: BuildOptions) {
250
259
const entryPath = downloadedFiles [ entrypoint ] . fsPath ;
251
260
252
261
const { PATH , HOME } = process . env ;
253
- const rustEnv : Record < string , string > = {
262
+ const rustEnv : RustEnv = {
254
263
...process . env ,
255
264
PATH : `${ path . join ( HOME ! , '.cargo/bin' ) } :${ PATH } ` ,
256
265
RUSTFLAGS : [ process . env . RUSTFLAGS , ...codegenFlags ]
@@ -277,7 +286,7 @@ export async function prepareCache({
277
286
targetFolderDir = path . dirname ( path . join ( workPath , entrypoint ) ) ;
278
287
} else {
279
288
const { PATH , HOME } = process . env ;
280
- const rustEnv : Record < string , string > = {
289
+ const rustEnv : RustEnv = {
281
290
...process . env ,
282
291
PATH : `${ path . join ( HOME ! , '.cargo/bin' ) } :${ PATH } ` ,
283
292
RUSTFLAGS : [ process . env . RUSTFLAGS , ...codegenFlags ]
0 commit comments