This plugin requires Gulp 5 and Node.js >=18.18.0. It is an ES module and must
be loaded using
an import or import() statement,
not require(). If TypeScript is used, it must be configured to
output ES modules,
not CommonJS.
The promise will be resolved with the
command result. If
the command failed, the promise will be rejected with a nice
error. If the
reject: false option was used,
the promise will be resolved with that error instead.
Returns a stream that executes a command on each input file.
function must:
take a Vinyl file
as argument. The most useful property is file.path but
other properties
are available as well.
return either:
a command string
an options object with a command property
undefined
import { pipeline } from 'node:stream/promises'import gulp from 'gulp'import { stream } from 'gulp-execa'export const sort = () => pipeline( gulp.src('*.txt'), stream(({ path }) => `sort ${path}`), gulp.dest('sorted'), )
Each file in the stream will spawn a separate process. This can consume lots of
resources so you should only use this method when there are no alternatives such
as:
firing a command programmatically instead of spawning a child process
passing several files, a directory or a globbing pattern as arguments to the
command
By default no shell interpreter (like Bash or cmd.exe) is used. This means
command must be just the program and its arguments. No escaping/quoting is
needed, except for significant spaces (with a backslash).
Shell features such as globbing, variables and operators (like &&>;)
should not be used. All of this can be done directly in Node.js instead.
Shell interpreters are slower, less secure and less cross-platform. However, you
can still opt-in to using them with the
shell option.
import { pipeline } from 'node:stream/promises'import gulp from 'gulp'import { stream } from 'gulp-execa'import through from 'through2'export const task = () => pipeline( gulp.src('*.js'), // Prints the number of lines of each file stream(({ path }) => `wc -l ${path}`, { result: 'save' }), through.obj((file, encoding, func) => { console.log(file.execa[0].stdout) func(null, file) }), )
from
Type: string Value: 'stdout', 'stderr' or 'all' Default: 'stdout'
import { pipeline } from 'node:stream/promises'import gulp from 'gulp'import { stream } from 'gulp-execa'import through from 'through2'export const task = () => pipeline( gulp.src('*.js'), // Prints the number of lines of each file, including `stderr` stream(({ path }) => `wc -l ${path}`, { result: 'replace', from: 'all' }), through.obj((file, encoding, func) => { console.log(file.contents.toString()) func(null, file) }), )
maxConcurrency
Type: integer Default: 100
With stream(), how many commands to run in parallel
at once.