6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { spawnSync } from 'child_process' ;
10
9
import type {
11
10
FormatMessagesOptions ,
12
11
PartialMessage ,
13
12
TransformOptions ,
14
13
TransformResult ,
15
14
} from 'esbuild' ;
16
- import * as path from 'path' ;
17
15
18
16
/**
19
17
* Provides the ability to execute esbuild regardless of the current platform's support
@@ -44,23 +42,15 @@ export class EsbuildExecutor
44
42
/**
45
43
* Determines whether the native variant of esbuild can be used on the current platform.
46
44
*
47
- * @returns True , if the native variant of esbuild is support; False , if the WASM variant is required.
45
+ * @returns A promise which resolves to `true` , if the native variant of esbuild is support or `false` , if the WASM variant is required.
48
46
*/
49
- static hasNativeSupport ( ) : boolean {
47
+ static async hasNativeSupport ( ) : Promise < boolean > {
50
48
// Try to use native variant to ensure it is functional for the platform.
51
- // Spawning a separate esbuild check process is used to determine if the native
52
- // variant is viable. If check fails, the WASM variant is initialized instead.
53
- // Attempting to call one of the native esbuild functions is not a viable test
54
- // currently since esbuild spawn errors are currently not propagated through the
55
- // call stack for the esbuild function. If this limitation is removed in the future
56
- // then the separate process spawn check can be removed in favor of a direct function
57
- // call check.
58
49
try {
59
- const { status, error } = spawnSync ( process . execPath , [
60
- path . join ( __dirname , '../../../esbuild-check.js' ) ,
61
- ] ) ;
50
+ const { formatMessages } = await import ( 'esbuild' ) ;
51
+ await formatMessages ( [ ] , { kind : 'error' } ) ;
62
52
63
- return status === 0 && error === undefined ;
53
+ return true ;
64
54
} catch {
65
55
return false ;
66
56
}
@@ -77,7 +67,7 @@ export class EsbuildExecutor
77
67
}
78
68
79
69
// If the WASM variant was preferred at class construction or native is not supported, use WASM
80
- if ( this . alwaysUseWasm || ! EsbuildExecutor . hasNativeSupport ( ) ) {
70
+ if ( this . alwaysUseWasm || ! ( await EsbuildExecutor . hasNativeSupport ( ) ) ) {
81
71
await this . useWasm ( ) ;
82
72
this . initialized = true ;
83
73
0 commit comments