Skip to content

Commit af8dd62

Browse files
committed
refactor(@angular-devkit/build-angular): remove esbuild-check workaround
This check is no longer needed as of `0.14.29` as now esbuild correctly propagates errors. See: https://github.com/evanw/esbuild/blob/master/CHANGELOG.md#01429
1 parent 6a6386a commit af8dd62

File tree

4 files changed

+7
-34
lines changed

4 files changed

+7
-34
lines changed

packages/angular_devkit/build_angular/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ ts_library(
8181
include = [
8282
"package.json",
8383
"builders.json",
84-
"esbuild-check.js",
8584
"src/**/schema.json",
8685
"src/**/*.js",
8786
"src/**/*.html",

packages/angular_devkit/build_angular/esbuild-check.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/angular_devkit/build_angular/src/webpack/plugins/esbuild-executor.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { spawnSync } from 'child_process';
109
import type {
1110
FormatMessagesOptions,
1211
PartialMessage,
1312
TransformOptions,
1413
TransformResult,
1514
} from 'esbuild';
16-
import * as path from 'path';
1715

1816
/**
1917
* Provides the ability to execute esbuild regardless of the current platform's support
@@ -44,23 +42,15 @@ export class EsbuildExecutor
4442
/**
4543
* Determines whether the native variant of esbuild can be used on the current platform.
4644
*
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.
4846
*/
49-
static hasNativeSupport(): boolean {
47+
static async hasNativeSupport(): Promise<boolean> {
5048
// 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.
5849
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' });
6252

63-
return status === 0 && error === undefined;
53+
return true;
6454
} catch {
6555
return false;
6656
}
@@ -77,7 +67,7 @@ export class EsbuildExecutor
7767
}
7868

7969
// 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())) {
8171
await this.useWasm();
8272
this.initialized = true;
8373

packages/angular_devkit/build_angular/src/webpack/plugins/javascript-optimizer-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export class JavaScriptOptimizerPlugin {
178178
// Perform a single native esbuild support check.
179179
// This removes the need for each worker to perform the check which would
180180
// otherwise require spawning a separate process per worker.
181-
alwaysUseWasm: !EsbuildExecutor.hasNativeSupport(),
181+
alwaysUseWasm: !(await EsbuildExecutor.hasNativeSupport()),
182182
};
183183

184184
// Sort scripts so larger scripts start first - worker pool uses a FIFO queue

0 commit comments

Comments
 (0)