![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
API-first task runner with three methods: task, run and watch.
(TOC generated by verb using markdown-toc)
Install with npm:
$ npm install --save composer
Heads up the .watch
method was removed in version 0.11.0
. If you need watch functionality, use base-tasks and base-watch.
var Composer = require('composer');
Register a new task with it's options and dependencies.
Dependencies may also be specified as a glob pattern. Be aware that the order cannot be guarenteed when using a glob pattern.
Params
name
{String}: Name of the task to registeroptions
{Object}: Options to set dependencies or control flow.options.deps
{Object}: array of dependenciesoptions.flow
{Object}: How this task will be executed with it's dependencies (series
, parallel
, settleSeries
, settleParallel
)deps
{String|Array|Function}: Additional dependencies for this task.fn
{Function}: Final function is the task to register.returns
{Object}: Return the instance for chainingExample
// register task "site" with composer
app.task('site', ['styles'], function() {
return app.src('templates/pages/*.hbs')
.pipe(app.dest('_gh_pages'));
});
Build a task or array of tasks.
Params
tasks
{String|Array|Function}: List of tasks by name, function, or array of names/functions. (Defaults to [default]
).options
{Object}: Optional options object to merge onto each task's options when building.cb
{Function}: Callback function to be called when all tasks are finished building.Example
app.build('default', function(err, results) {
if (err) return console.error(err);
console.log(results);
});
Compose task or list of tasks into a single function that runs the tasks in series.
Params
tasks
{String|Array|Function}: List of tasks by name, function, or array of names/functions.returns
{Function}: Composed function that may take a callback function.Example
app.task('foo', function(done) {
console.log('this is foo');
done();
});
var fn = app.series('foo', function bar(done) {
console.log('this is bar');
done();
});
fn(function(err) {
if (err) return console.error(err);
console.log('done');
});
//=> this is foo
//=> this is bar
//=> done
Compose task or list of tasks into a single function that runs the tasks in parallel.
Params
tasks
{String|Array|Function}: List of tasks by name, function, or array of names/functions.returns
{Function}: Composed function that may take a callback function.Example
app.task('foo', function(done) {
setTimeout(function() {
console.log('this is foo');
done();
}, 500);
});
var fn = app.parallel('foo', function bar(done) {
console.log('this is bar');
done();
});
fn(function(err) {
if (err) return console.error(err);
console.log('done');
});
//=> this is bar
//=> this is foo
//=> done
When an individual task is executed (or run), a new Run instance is created with start, end, and duration information. This run
object is emitted with some events and also exposed on the task
instance as the .runInfo
property.
The run
instance has the the following properties
.date
The .date
property is an object containing the .start
and .end
date timestamps created with new Date()
.
.hr
The .hr
property is an object containing the .start
, .end
and .duration
properties that are created by using process.hrtime()
. These properties are the actual arrays returned from process.hrtime()
.
There is also .diff
and .offset
computed properties that use the other properties to calculate the difference between .start
and .end
times (.diff
) and the offset (error for time calculations) between the .duration
and the .diff
(this is usually very small).
.duration
The .duration
property is a computed property that uses pretty-time to format the .hr.duration
value into a human readable format.
composer is an event emitter that may emit the following events:
This event is emitted when a build
is starting.
The event emits 2 arguments, the current instance of composer as the app
and an object containing the build runtime information.
app.on('starting', function(app, build) {});
build
exposes a .date
object that has a .start
property containing the start time as a Date
object.build
exposes a .hr
object that has a .start
property containing the start time as an hrtime
array.This event is emitted when a build
has finished.
The event emits 2 arguments, the current instance of composer as the app
and an object containing the build runtime information.
app.on('finished', function(app, build) {});
build
exposes a .date
object that has .start
and .end
properties containing start and end times of the build as Date
objects.build
exposes a .hr
object that has .start
, .end
, .duration
, and .diff
properties containing timing information calculated using process.hrtime
This event is emitted when an error occurrs during a build
.
The event emits 1 argument as an Error
object containing additional information about the build and the task running when the error occurred.
app.on('error', function(err) {});
Additional properties:
app
: current composer instance running the buildbuild
: current build runtime informationtask
: current task instance running when the error occurredrun
: current task runtime informationThis event is emitted when a task is starting. The event emits 2 arguments, the current instance of the task object and an object containing the task runtime information.
app.on('task:starting', function(task, run) {});
The run
parameter exposes:
.date
{Object}: has a .start
property containing the start time as a Date
object..hr
{Object}: has a .start
property containing the start time as an hrtime
array.This event is emitted when a task has finished.
The event emits 2 arguments, the current instance of the task object and an object containing the task runtime information.
app.on('task:finished', function(task, run) {});
The run
parameter exposes:
.date
{Object}: has a .date
object that has .start
and .end
properties containing start and end times of the task as Date
objects.run
{Object}: has an .hr
object that has .start
, .end
, .duration
, and .diff
properties containing timing information calculated using process.hrtime
This event is emitted when an error occurrs while running a task.
The event emits 1 argument as an Error
object containing additional information about the task running when the error occurred.
app.on('task:error', function(err) {});
Additional properties
task
: current task instance running when the error occurredrun
: current task runtime information1.0.0
.'in task "foo":'
prefixed to the error message. see issue #22.runInfo
on the task object for use in event listeners and task functions..duration
to the .run/.runInfo
object that shows the duration in a human friendly format. This will also show the current duration from the time the task started to the time it's called if used inside a task function. see issue #23app.task('foo', function(cb) {
console.log(this.runInfo.duration);
});
options.skip
option to the name of the task or an array of task names.err
properties non-enumerable to cut down on error output..task()
method by passing only the name. Instead do var task = app.tasks[name];
.task()
will result in a noop
task being created.options
may be passed to .build()
, .series()
and .parallel()
options
passed to .build()
will be merged onto task options before running the task.options.run
option to false
..task()
..watch()
. Watch functionality can be added to base applications using base-watch.session
.default
when no tasks are passed to .build()
.task
when adding a task through .task()
.task(name)
with only a name.task:*
events instead of generic *
events. See event docs for more information..task()
is called without a name..task()
is called without a name.err
instances and emitting instead of emitting multiple parameters..run()
to .build()
.watch
returns an instance of FSWatcher
.task()
without a name.Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)
To generate the readme and API documentation with verb:
$ npm install -g verb verb-generate-readme && verb
Install dev dependencies:
$ npm install -d && npm test
Jon Schlinkert
Copyright © 2016, Jon Schlinkert. Released under the MIT license.
This file was generated by verb, v0.9.0, on July 13, 2016.
v0.14.0
1.0.0
.'in task "foo":'
prefixed to the error message. see issue #22.runInfo
on the task object for use in event listeners and task functions..duration
to the .run/.runInfo
object that shows the duration in a human friendly format. This will also show the current duration from the time the task started to the time it's called if used inside a task function. see issue #23app.task('foo', function(cb) {
console.log(this.runInfo.duration);
});
FAQs
Run and compose async tasks. Easily define groups of tasks to run in series or parallel.
The npm package composer receives a total of 26,117 weekly downloads. As such, composer popularity was classified as popular.
We found that composer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.