jakejs / jake

JavaScript build tool, similar to Make or Rake. Built to work with Node.js.
http://jakejs.com
Apache License 2.0
1.97k stars 190 forks source link

jake.createExec not available in latest NPM package (10.4.5) #371

Closed antonio-malcolm closed 3 years ago

antonio-malcolm commented 4 years ago

This is currently an issue, on the latest NPM package (v10.4.5). I can confirm #createExec is not assigned to jake, by: https://github.com/jakejs/jake/blob/ccc9a82ef28d045f57512a4b870a07a47eb9dd7b/lib/jake.js#L45

antonio-malcolm commented 4 years ago

UPDATE: Looks like it's undefined, on jake, for ALL the 10.x tags, as well as 10.3.2 I've found it on 10.3.1.

mde commented 4 years ago

Curious what you're needing the createExec for. Now that we have a reasonable, synchronous way to shell out, why would you need this functionality anymore?

antonio-malcolm commented 4 years ago

What is replacing it? Also, isn't that a somewhat haphazard way of going about this?

"So, folks, SURPRISE, it's a missing method, though the core logic still exists, in the utils!" "Rewrite your logic, if you want to update, with NO deprecation notice!"

antonio-malcolm commented 4 years ago

If there's a new, better way, I'll jump on that, but I haven't written a new Jake project, since v8, and it would have been good, to have some notice you intended to deprecate that functionality, and had done so, without the additional confusion of leaving the stale backing code in the utils.

antonio-malcolm commented 4 years ago

Ok, so, I see there's this, which accomplishes what I'm doing, but, I'm not certain why it's a "better" approach, as opposed to simply "different"?

https://jakejs.com/docs-page.html#item-advanced-usage-evented-tasks

antonio-malcolm commented 3 years ago

Ok, so replacing jake#createExec, with NodeJs child_process APIs, for folks unfamiliar, is done, like so.

Using child_process#exec (or child_process#spawn):

const extbl = child_process.exec(cmd);

extbl.on(
  'exit',
  () => {
    console.log(
      'SUCCESS'
    );
  }
);

extbl.on(
  'error',
  (err) => {
    console.log(
      err
    );

    // call Jake's #fail method...
    fail();
  }
);

Using child_process#execSync:

try {
  child_process.execSync(cmd);

  console.log(
    'SUCCESS'
  );

} catch(err) {
  console.log(
    err
  );

  // call Jake's #fail method...
  fail();
}

Will close this, for now. For folks upgrading older Jake implementations, this will require some refactoring, but the above should be enough, to help cover most use cases, or, at least, get folks started.

antonio-malcolm commented 3 years ago

UPDATE: Because my executables occur in a synchronous fashion, in addition to my previous comment, I moved them all into exported functions, inside external, vanilla .js modules, as Jake was not behaving so well, with them executed as Jake tasks (sometimes, Jake would skip the follow-on tasks).

This also means they can be executed, independently, of any task manager, if needed. (Yes, this also makes for more elegant separations of concerns.)

I import the module(s), then execute their functions, inside of Jake tasks, like so:


const TaskArgSanitizerException = require('../task/sanitizer/TaskArgSanitizerException');
const TaskArgSanitizers = require('../task/sanitizer/TaskArgSanitizers');

const TaskWorkerException = require('../task/worker/TaskWorkerException');
const TaskWorkers = require('../task/worker/TaskWorkers');

namespace(YOUR_NAMESPACE_HERE, function() {

  desc(YOUR_DESCRIPTION_HERE);
  task(
    [YOUR_TASK_HERE],
    function YOUR_TASK() {

      let someEnvVar = process.env[SOME_ENV_VAR];

      try {
        someEnvVar = TaskArgSanitizers.sanitizeEnvVar(someEnvVar);
      } catch (err) {
        fail(
          `${err.name}: ${err.message}`
        );
      }

      try {
        TaskWorkers.update();
        TaskWorkers.build(someEnvVar);
      } catch (err) {
        fail(
          `${err.name}: ${err.message}`
        );
      }

    }
  );

});