Skip to content

FileTask when not needed is hanging around and failing the build #441

@Michael-Downton

Description

@Michael-Downton

The problem is that when a FileTask resolves as not needed, it does not remove itself from the stack and produces output like below.

Output:

> jake meta
Starting 'required'...
Finished 'required' after 30 ms
Starting 'target'...
Finished 'path/to/my/index.html' after 1773964666381 ms
>

Example:


desc('required stuff');
task('required', [], function() {});

desc('builds stuff');
task('build', [], function() { /*...makes the file path/to/my/index.html*/ });

//desc("Build a website file if not already built")
file('path/to/my/index.html', [], function() {
  return RunTask('build');
});


desc('target stuff');
task('target', [
  'required',
  'storybook-static/index.html',
], function () { /*target stuff*/ });


desc('neverrunstuff');
task('neverrun', [], function () { /*important stuff never run when called via meta target*/ });

desc('Meta Target stuff');
task('Meta', [
  'target',
  'neverrun'
], { async: true }, function () { /*target stuff*/ });

function RunTask(taskName) {
  let t = jake.Task[taskName];
  return new Promise((resolve, reject) => {
    try
    {
      t.addListener('complete', () => {
        resolve();
      });
      t.addListener('skip', () => {
        resolve();
      });
      t.addListener('error', (e) => {
        reject(e);
      })
      t.invoke();
    }
    catch (e)
    {
      throw new Error(`Error while creating Task for '${taskName}'`, e);
    }
  });
}

In fact analysis reveals that this is the case for any task that resolves as not needed. Because task._initInvocationChain() pushes the task to the stack (jake._invocationChain) and is called on task.invoke() and task.execute().

When a task skips (like a file task does) the task.run() checks to see if it needs to be evaluated (if (!this.isNeeded())) and if not, skips the task. Unfortunately, it leaves the task on the stack causing
some weird finished task messaging and usually leads to early bailing. As above were the meta task isn't ever called.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions