From 59e754e3c4292aca76474effd9f85e77caceaa2e Mon Sep 17 00:00:00 2001 From: Asger F Date: Tue, 22 Apr 2025 13:47:03 +0200 Subject: [PATCH] Avoid unhandled errors in build streams The .pipe() method on Node.js streams have a gotcha in that they do not propagate errors downstream. In this case this meant that if compilation failed with an error, it would not be visible to Gulp because Gulp only sees the stream that writes to a file, not the intermediate 'esbuild' stream that generated the error. This changes a few uses of .pipe() to the more modern stream.pipeline(), which propagates errors correctly. --- extensions/ql-vscode/gulpfile.ts/textmate.ts | 9 +++-- .../ql-vscode/gulpfile.ts/typescript.ts | 35 ++++++++++--------- extensions/ql-vscode/gulpfile.ts/view.ts | 35 ++++++++++--------- 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/extensions/ql-vscode/gulpfile.ts/textmate.ts b/extensions/ql-vscode/gulpfile.ts/textmate.ts index 0b7d2b88fac..8e061b440f9 100644 --- a/extensions/ql-vscode/gulpfile.ts/textmate.ts +++ b/extensions/ql-vscode/gulpfile.ts/textmate.ts @@ -9,6 +9,7 @@ import type { Pattern, TextmateGrammar, } from "./textmate-grammar"; +import { pipeline } from "stream/promises"; /** * Replaces all rule references with the match pattern of the referenced rule. @@ -276,7 +277,9 @@ export function transpileTextMateGrammar() { } export function compileTextMateGrammar() { - return src("syntaxes/*.tmLanguage.yml") - .pipe(transpileTextMateGrammar()) - .pipe(dest("out/syntaxes")); + return pipeline( + src("syntaxes/*.tmLanguage.yml"), + transpileTextMateGrammar(), + dest("out/syntaxes"), + ); } diff --git a/extensions/ql-vscode/gulpfile.ts/typescript.ts b/extensions/ql-vscode/gulpfile.ts/typescript.ts index c7f12785507..abd3591b096 100644 --- a/extensions/ql-vscode/gulpfile.ts/typescript.ts +++ b/extensions/ql-vscode/gulpfile.ts/typescript.ts @@ -4,6 +4,7 @@ import esbuild from "gulp-esbuild"; import type { reporter } from "gulp-typescript"; import { createProject } from "gulp-typescript"; import del from "del"; +import { pipeline } from "stream/promises"; export function goodReporter(): reporter.Reporter { return { @@ -37,23 +38,23 @@ export function cleanOutput() { } export function compileEsbuild() { - return src("./src/extension.ts") - .pipe( - esbuild({ - outfile: "extension.js", - bundle: true, - external: ["vscode", "fsevents"], - format: "cjs", - platform: "node", - target: "es2020", - sourcemap: "linked", - sourceRoot: "..", - loader: { - ".node": "copy", - }, - }), - ) - .pipe(dest("out")); + return pipeline( + src("./src/extension.ts"), + esbuild({ + outfile: "extension.js", + bundle: true, + external: ["vscode", "fsevents"], + format: "cjs", + platform: "node", + target: "es2020", + sourcemap: "linked", + sourceRoot: "..", + loader: { + ".node": "copy", + }, + }), + dest("out"), + ); } export function watchEsbuild() { diff --git a/extensions/ql-vscode/gulpfile.ts/view.ts b/extensions/ql-vscode/gulpfile.ts/view.ts index fea09031d70..698f39c113e 100644 --- a/extensions/ql-vscode/gulpfile.ts/view.ts +++ b/extensions/ql-vscode/gulpfile.ts/view.ts @@ -3,28 +3,29 @@ import esbuild from "gulp-esbuild"; import { createProject } from "gulp-typescript"; import { goodReporter } from "./typescript"; +import { pipeline } from "stream/promises"; import chromiumVersion from "./chromium-version.json"; const tsProject = createProject("src/view/tsconfig.json"); export function compileViewEsbuild() { - return src("./src/view/webview.tsx") - .pipe( - esbuild({ - outfile: "webview.js", - bundle: true, - format: "iife", - platform: "browser", - target: `chrome${chromiumVersion.chromiumVersion}`, - jsx: "automatic", - sourcemap: "linked", - sourceRoot: "..", - loader: { - ".ttf": "file", - }, - }), - ) - .pipe(dest("out")); + return pipeline( + src("./src/view/webview.tsx"), + esbuild({ + outfile: "webview.js", + bundle: true, + format: "iife", + platform: "browser", + target: `chrome${chromiumVersion.chromiumVersion}`, + jsx: "automatic", + sourcemap: "linked", + sourceRoot: "..", + loader: { + ".ttf": "file", + }, + }), + dest("out"), + ); } export function watchViewEsbuild() {