Currenly, I know only one working method of runnig the Gulp task without gulpfile and CLI:
import Gulp from "gulp";
const TASK_NAME: string = "EXAMPLE_TASK";
Gulp.task(TASK_NAME, Gulp.parallel([
// ... imported task fuctions ...
]);
Gulp.task(TASK_NAME)(
(error?: Error | null): void => { if (isNeitherUndefinedNorNull(error)) { console.error(error); } }
);
It is not the subject of question; I just explained what I doing and why my code is such as, but if you know
the better method of executing of Gulp task without gulpfile and CLI, please let me now.
Now about the subject. Until recently, the last part of the code (Gulp.task(TASK_NAME)(/* ... */))
has not been rejected by no-floating-promises rule if typescript-eslint. By after latest update of @types/gulp (or typescript-eslint - now it's hard to explore which one)
typescript-eslint warn me:
Promises must be handled appropriately or explicitly marked as ignored with the
voidoperator
there. I know it's not the false alarm. Sometimes my Gulp tasks chain broken with unhandled promise rejection, but it was not obvious where promise was. Now I had the hint, but it's still unclear.
I explored that:
Gulp.task()returned theUndertaker.TaskFunctionWrappedTaskFunctionWrappedextends theTaskFunctionBaseTaskFunctionBaseis(done: TaskCallback): ReturnType<AsyncTask>;- The
AsyncTaskis:
export type AsyncTask<R = any> =
((done: VoidCallback) => void)
| ((done: Callback<R>) => void)
| (() => ChildProcess | EventEmitter | Observable<R> | PromiseLike<R> | Stream);
According documentation, the task function must return the ChildProcess, EventEmitter , Observable, Promise or Stream. But how to handle it? Gult.task()() is not thenable:
Error texting:
TS2339: Property 'catch' does not exist on type 'void | EventEmitter | ChildProcess | Stream | Observable | PromiseLike'.
Update: @TheBumpaster solution try
Unfortunately, the @typescript/eslint still tells me "Promises must be handled appropriately or explicitly marked as ignored with the void operator" in Gulp.task(ProjectBuilder.GULP_TASK_NAME) line.
const task: Promise<void> = new Promise<void>((resolve: () => void, reject: (error: Error) => void): void => {
console.log("checkpoint1");
Gulp.task(ProjectBuilder.GULP_TASK_NAME)(
(error?: Error | null): void => {
if (isNeitherUndefinedNorNull(error)) {
console.log("checkpoint2-A");
reject(error);
} else {
console.log("checkpoint2-B");
resolve();
}
}
);
});
task.catch((error: Error): void => { console.error(error); });
I intentionally rise the error in some of gulp plugins. The project builder reaches the "checkpoint1" but neither "checkpoint2-A" nor "checkpoint2-B". The output is:
D:\XXX\node_modules\async-done\index.js:18
throw err;
^
Error [ERR_UNHANDLED_ERROR]: Unhandled error. ({
uid: 0,
name: '<anonymous>',
branch: false,
error: AssertionError [ERR_ASSERTION]:
Maybe it's indirectly indicates that @typescript/eslint yelling is not a lip service...
