Normally, unified plug-ins receive upon attaching two arguments:
processor (the Processor it’s attached to) and
options (an Object users can provide to configure the plug-in).
If a plug-in is attached by unified-engine, a third argument is
given: fileSet.
The following example processes readme.md and uses a plug-in that adds a
“completer” and another file (history.md).
var engine = require('unified-engine')
var remark = require('remark')
/* Ensure the completer runs once per file-set. */
completer.pluginId = 'some-plugin-id'
engine(
{
processor: remark(),
injectedPlugins: [plugin],
files: ['readme.md']
},
done
)
function done(err) {
if (err) throw err
}
function plugin(processor, options, set) {
set.use(completer)
set.add('history.md')
}
function completer(set) {
console.log('done:', set.valueOf().map(path))
}
function path(file) {
return file.path
}Yields:
done: [ 'readme.md', 'history.md' ]
readme.md: no issues foundNote that history.md is not reported: only files given by the user
are reported (or written).
Internally, a fileSet is created to process multiple files through
unified processors. This set, containing all files, is exposed
to plug-ins as an argument to the attacher.
Access the files in a set. Returns a list of VFiles being
processed.
Add a file to be processed. The given file is processed like other files with a few differences. The added files are:
- Ignored when their file-path is already added
- Never written to the file-system or
streamOut - Not reported for
Returns self.
filePath(string) — Path to virtual filefile(VFile) — Virtual file
Attach a completer to a middleware pipeline which runs
when all files are transformed (before compilation). Returns self.
Function invoked when all files are processed.
If an error occurs (either because it’s thrown, returned, rejected, or
passed to next), no further completers run and all files fail.
ErrorPromise— If a promise is returned, the function is asynchronous, and must be resolved (with nothing) or rejected (with anError)
pluginId(string) — Plug-ins specified through various mechanisms are attached to a newprocessorfor each file. If acompleterisused multiple times, it is invoked multiple times as well. To ensure completers don’t get re-attached, specify apluginId. This will ensure only one completer perpluginIdis added.
If the signature of a completer includes next (second argument),
the function may finish asynchronous, and must invoke
next().
err(Error, optional) — Fatal error