question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[gulp 4] allow forward references to tasks

See original GitHub issue

Currently, forward references to tasks do not work in gulp 4 (and gulp 3, but I don’t care about that):

gulp.task('default', gulp.series('clean', 'build', 'watch', 'server'));

gulp.task('clean', function () {
    // do something
});
...

This results in AssertionError: Task never defined: clean.

From a stylistic standpoint, many people prefer to place the broadest tasks first and then define component tasks later, since this is how most people think and design code. Also the current ‘bottom up’, Forth-like restriction is no longer necessary considering how gulp 4 works.

From a design standpoint, since tasks are interchangeable with functions now, and since functions (like most stuff in Javascript) can be referenced from anywhere within the current scope regardless of where it was declared, to be consistent tasks should work the same way.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:3
  • Comments:77 (43 by maintainers)

github_iconTop GitHub Comments

18reactions
mryellowcommented, Mar 25, 2019

This makes migration to v4 much more time-consuming than it needs to be.

what’s the point of a registry if everything needs to be defined in order?

I’m defining tasks here, with names as strings. I expect them to exist.

My fear with that approach is that users will see in G4 a product that is too different from the product they’re already used to and like,

Upon discovering this, I’m ready to stick with v3 for the next 6 decades.

16reactions
yocontracommented, Dec 2, 2014

I kind of agree with @alvint here - what’s the point of a registry if everything needs to be defined in order? It seems super inflexible. If construction of the function is really a perf problem why can’t we use caching to only construct once on first run?

Possible use case for this is splitting tasks across multiple files, which with the current impl would all have to be loaded in the right order.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Forward reference tasks not defined before use
Use the require-dir package to include all files within the ./tasks/ directory. · convert tasks that were designed for gulp@3.9.1 into functions ......
Read more >
How to use the gulp.registry function in gulp
@todo: Do we need the svg-sprite task? gulp.task("default", ... require('undertaker-forward-reference'); // NOTE: Allow tasks to be referenced in any order ...
Read more >
AssesrtionError: Task never defined : clean; on gulp version 4
In newer versions, you'll get an error, with the message "Task never defined", if you try to use forward references. You may experience...
Read more >
Learn How to Use Gulp
Node's require() function allows us to specify the plugins that are needed in order to run our Gulp tasks. These are called dependencies....
Read more >
run-task — AWS CLI 1.27.38 Command Reference
Description¶. Starts a new task using the specified task definition. You can allow Amazon ECS to place tasks for you, or you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found