unified-engine
Advanced tools
Comparing version 8.0.0 to 8.1.0
@@ -8,3 +8,3 @@ 'use strict' | ||
var debug = require('debug')('unified-engine:configuration') | ||
var resolve = require('load-plugin').resolve | ||
var loadPlugin = require('load-plugin') | ||
var plain = require('is-plain-obj') | ||
@@ -17,6 +17,2 @@ var fault = require('fault') | ||
var own = {}.hasOwnProperty | ||
var extname = path.extname | ||
var basename = path.basename | ||
var dirname = path.dirname | ||
var relative = path.relative | ||
@@ -35,4 +31,2 @@ var loaders = { | ||
function Config(options) { | ||
var rcName = options.rcName | ||
var packageField = options.packageField | ||
var names = [] | ||
@@ -46,10 +40,18 @@ | ||
if (rcName) { | ||
names.push(rcName, rcName + '.js', rcName + '.yml', rcName + '.yaml') | ||
if (options.rcName) { | ||
names.push( | ||
options.rcName, | ||
options.rcName + '.js', | ||
options.rcName + '.yml', | ||
options.rcName + '.yaml' | ||
) | ||
debug('Looking for `%s` configuration files', names) | ||
} | ||
if (packageField) { | ||
if (options.packageField) { | ||
names.push('package.json') | ||
debug('Looking for `%s` fields in `package.json` files', packageField) | ||
debug( | ||
'Looking for `%s` fields in `package.json` files', | ||
options.packageField | ||
) | ||
} | ||
@@ -71,5 +73,4 @@ | ||
var self = this | ||
var searchPath = filePath || path.resolve(this.cwd, 'stdin.js') | ||
self.findUp.load(searchPath, done) | ||
self.findUp.load(filePath || path.resolve(this.cwd, 'stdin.js'), done) | ||
@@ -81,11 +82,11 @@ function done(error, file) { | ||
callback(null, self.create()) | ||
self.create().then(function (result) { | ||
callback(null, result) | ||
}, callback) | ||
} | ||
} | ||
function create(buf, filePath) { | ||
async function create(buf, filePath) { | ||
var self = this | ||
var transform = self.configTransform | ||
var defaults = self.defaultConfig | ||
var fn = (filePath && loaders[extname(filePath)]) || defaultLoader | ||
var fn = (filePath && loaders[path.extname(filePath)]) || defaultLoader | ||
var options = {prefix: self.pluginPrefix, cwd: self.cwd} | ||
@@ -95,8 +96,12 @@ var result = {settings: {}, plugins: []} | ||
if (transform && contents !== undefined) { | ||
contents = transform(contents, filePath) | ||
if (self.configTransform && contents !== undefined) { | ||
contents = self.configTransform(contents, filePath) | ||
} | ||
// Exit if we did find a `package.json`, but it does not have configuration. | ||
if (buf && contents === undefined && basename(filePath) === 'package.json') { | ||
if ( | ||
buf && | ||
contents === undefined && | ||
path.basename(filePath) === 'package.json' | ||
) { | ||
return | ||
@@ -106,14 +111,18 @@ } | ||
if (contents === undefined) { | ||
if (defaults) { | ||
merge(result, defaults, Object.assign({}, options, {root: self.cwd})) | ||
if (self.defaultConfig) { | ||
await merge( | ||
result, | ||
self.defaultConfig, | ||
Object.assign({}, options, {root: self.cwd}) | ||
) | ||
} | ||
} else { | ||
merge( | ||
await merge( | ||
result, | ||
contents, | ||
Object.assign({}, options, {root: dirname(filePath)}) | ||
Object.assign({}, options, {root: path.dirname(filePath)}) | ||
) | ||
} | ||
merge(result, self.given, Object.assign({}, options, {root: self.cwd})) | ||
await merge(result, self.given, Object.assign({}, options, {root: self.cwd})) | ||
@@ -130,3 +139,3 @@ return result | ||
submodule.filename = filePath | ||
submodule.paths = Module._nodeModulePaths(dirname(filePath)) | ||
submodule.paths = Module._nodeModulePaths(path.dirname(filePath)) | ||
submodule._compile(String(buf), filePath) | ||
@@ -141,3 +150,3 @@ submodule.loaded = true | ||
function loadYaml(buf, filePath) { | ||
return yaml.safeLoad(buf, {filename: basename(filePath)}) | ||
return yaml.safeLoad(buf, {filename: path.basename(filePath)}) | ||
} | ||
@@ -148,3 +157,3 @@ | ||
if (basename(filePath) === 'package.json') { | ||
if (path.basename(filePath) === 'package.json') { | ||
result = result[this.packageField] | ||
@@ -156,9 +165,5 @@ } | ||
function merge(target, raw, options) { | ||
var root = options.root | ||
var cwd = options.cwd | ||
var prefix = options.prefix | ||
async function merge(target, raw, options) { | ||
if (typeof raw === 'object' && raw !== null) { | ||
addPreset(raw) | ||
await addPreset(raw) | ||
} else { | ||
@@ -170,3 +175,3 @@ throw new Error('Expected preset, not `' + raw + '`') | ||
function addPreset(result) { | ||
async function addPreset(result) { | ||
var plugins = result.plugins | ||
@@ -177,7 +182,3 @@ | ||
} else if (typeof plugins === 'object' && plugins !== null) { | ||
if ('length' in plugins) { | ||
addEach(plugins) | ||
} else { | ||
addIn(plugins) | ||
} | ||
await ('length' in plugins ? addEach(plugins) : addIn(plugins)) | ||
} else { | ||
@@ -192,51 +193,71 @@ throw new Error( | ||
function addEach(result) { | ||
var length = result.length | ||
async function addEach(result) { | ||
var index = -1 | ||
var value | ||
while (++index < length) { | ||
while (++index < result.length) { | ||
value = result[index] | ||
if (value !== null && typeof value === 'object' && 'length' in value) { | ||
use.apply(null, value) | ||
} else { | ||
use(value) | ||
} | ||
// Keep order sequential instead of parallel. | ||
// eslint-disable-next-line no-await-in-loop | ||
await (value !== null && typeof value === 'object' && 'length' in value | ||
? use.apply(null, value) | ||
: use(value)) | ||
} | ||
} | ||
function addIn(result) { | ||
async function addIn(result) { | ||
var key | ||
for (key in result) { | ||
use(key, result[key]) | ||
// Keep order sequential instead of parallel. | ||
// eslint-disable-next-line no-await-in-loop | ||
await use(key, result[key]) | ||
} | ||
} | ||
function use(usable, value) { | ||
async function use(usable, value) { | ||
if (typeof usable === 'string') { | ||
addModule(usable, value) | ||
await addModule(usable, value) | ||
} else if (typeof usable === 'function') { | ||
addPlugin(usable, value) | ||
} else { | ||
merge(target, usable, options) | ||
await merge(target, usable, options) | ||
} | ||
} | ||
function addModule(id, value) { | ||
var fp = resolve(id, {cwd: root, prefix: prefix}) | ||
async function addModule(id, value) { | ||
var fp = loadPlugin.resolve(id, {cwd: options.root, prefix: options.prefix}) | ||
var ext | ||
var result | ||
if (fp) { | ||
try { | ||
result = require(fp) | ||
} catch (error) { | ||
throw fault( | ||
'Cannot parse script `%s`\n%s', | ||
relative(root, fp), | ||
error.stack | ||
) | ||
ext = path.extname(fp) | ||
/* istanbul ignore next - To do next major: Tests don’t run on Node 10 */ | ||
if (ext !== '.mjs') { | ||
try { | ||
result = require(fp) | ||
} catch (error) { | ||
if (ext !== '.cjs' && error.code === 'ERR_REQUIRE_ESM') { | ||
ext = '.mjs' | ||
} else { | ||
throw fault( | ||
'Cannot parse script `%s`\n%s', | ||
path.relative(options.root, fp), | ||
error.stack | ||
) | ||
} | ||
} | ||
if (result && typeof result === 'object' && result.__esModule) { | ||
result = result.default | ||
} | ||
} | ||
/* istanbul ignore next - To do next major: Tests don’t run on Node 10 */ | ||
if (ext === '.mjs') { | ||
result = (await import(fp)).default | ||
} | ||
try { | ||
@@ -246,3 +267,7 @@ if (typeof result === 'function') { | ||
} else { | ||
merge(target, result, Object.assign({}, options, {root: dirname(fp)})) | ||
await merge( | ||
target, | ||
result, | ||
Object.assign({}, options, {root: path.dirname(fp)}) | ||
) | ||
} | ||
@@ -253,7 +278,7 @@ } catch (_) { | ||
result, | ||
relative(root, fp) | ||
path.relative(options.root, fp) | ||
) | ||
} | ||
} else { | ||
fp = relative(cwd, path.resolve(root, id)) | ||
fp = path.relative(options.cwd, path.resolve(options.root, id)) | ||
addPlugin( | ||
@@ -286,11 +311,7 @@ failingModule(fp, new Error('Could not find module `' + id + '`')), | ||
function find(entries, plugin) { | ||
var length = entries.length | ||
var index = -1 | ||
var entry | ||
while (++index < length) { | ||
entry = entries[index] | ||
if (entry[0] === plugin) { | ||
return entry | ||
while (++index < entries.length) { | ||
if (entries[index][0] === plugin) { | ||
return entries[index] | ||
} | ||
@@ -297,0 +318,0 @@ } |
@@ -11,5 +11,2 @@ 'use strict' | ||
function configure(context, file, fileSet, next) { | ||
var config = context.configuration | ||
var processor = context.processor | ||
if (stats(file).fatal) { | ||
@@ -19,11 +16,8 @@ return next() | ||
config.load(file.path, handleConfiguration) | ||
context.configuration.load(file.path, handleConfiguration) | ||
function handleConfiguration(error, configuration) { | ||
var plugins | ||
var index = -1 | ||
var plugin | ||
var options | ||
var plugin | ||
var length | ||
var index | ||
var name | ||
@@ -36,14 +30,10 @@ if (error) { | ||
debug('Using settings `%j`', configuration.settings) | ||
processor.data('settings', configuration.settings) | ||
context.processor.data('settings', configuration.settings) | ||
plugins = configuration.plugins | ||
length = plugins.length | ||
index = -1 | ||
debug('Using `%d` plugins', configuration.plugins.length) | ||
debug('Using `%d` plugins', length) | ||
while (++index < configuration.plugins.length) { | ||
plugin = configuration.plugins[index][0] | ||
options = configuration.plugins[index][1] | ||
while (++index < length) { | ||
plugin = plugins[index][0] | ||
options = plugins[index][1] | ||
if (options === false) { | ||
@@ -58,7 +48,10 @@ continue | ||
name = plugin.displayName || plugin.name || 'function' | ||
debug('Using plugin `%s`, with options `%j`', name, options) | ||
debug( | ||
'Using plugin `%s`, with options `%j`', | ||
plugin.displayName || plugin.name || 'function', | ||
options | ||
) | ||
try { | ||
processor.use(plugin, options, fileSet) | ||
context.processor.use(plugin, options, fileSet) | ||
} catch (error_) { | ||
@@ -65,0 +58,0 @@ /* istanbul ignore next - Should not happen anymore! */ |
@@ -9,11 +9,5 @@ 'use strict' | ||
var stat = fs.stat | ||
var dirname = path.dirname | ||
var resolve = path.resolve | ||
var relative = path.relative | ||
// Move a file. | ||
function copy(context, file, fileSet, next) { | ||
var output = context.output | ||
var multi = fileSet.expected > 1 | ||
var outpath = output | ||
@@ -27,7 +21,7 @@ var currentPath = file.path | ||
outpath = resolve(context.cwd, outpath) | ||
outpath = path.resolve(context.cwd, outpath) | ||
debug('Copying `%s`', currentPath) | ||
stat(outpath, onstatfile) | ||
fs.stat(outpath, onstatfile) | ||
@@ -45,3 +39,3 @@ function onstatfile(error, stats) { | ||
stat(dirname(outpath), onstatparent) | ||
fs.stat(path.dirname(outpath), onstatparent) | ||
} else { | ||
@@ -63,3 +57,3 @@ done(stats.isDirectory()) | ||
function done(directory) { | ||
if (!directory && multi) { | ||
if (!directory && fileSet.expected > 1) { | ||
return next( | ||
@@ -70,3 +64,3 @@ new Error('Cannot write multiple files to single output: ' + outpath) | ||
file[directory ? 'dirname' : 'path'] = relative(file.cwd, outpath) | ||
file[directory ? 'dirname' : 'path'] = path.relative(file.cwd, outpath) | ||
@@ -73,0 +67,0 @@ debug('Copying document from %s to %s', currentPath, file.path) |
@@ -10,5 +10,2 @@ 'use strict' | ||
var writeFile = fs.writeFile | ||
var resolve = path.resolve | ||
// Write a virtual file to the file-system. | ||
@@ -41,3 +38,3 @@ // Ignored when `output` is not given. | ||
destinationPath = resolve(context.cwd, destinationPath) | ||
destinationPath = path.resolve(context.cwd, destinationPath) | ||
debug('Writing document to `%s`', destinationPath) | ||
@@ -47,3 +44,3 @@ | ||
writeFile(destinationPath, file.toString(), next) | ||
fs.writeFile(destinationPath, file.toString(), next) | ||
} |
@@ -10,5 +10,2 @@ 'use strict' | ||
var resolve = path.resolve | ||
var readFile = fs.readFile | ||
// Fill a file with its contents when not already filled. | ||
@@ -25,6 +22,6 @@ function read(context, file, fileSet, next) { | ||
} else { | ||
filePath = resolve(context.cwd, filePath) | ||
filePath = path.resolve(context.cwd, filePath) | ||
debug('Reading `%s` in `%s`', filePath, 'utf8') | ||
readFile(filePath, 'utf8', onread) | ||
fs.readFile(filePath, 'utf8', onread) | ||
} | ||
@@ -31,0 +28,0 @@ |
@@ -12,4 +12,2 @@ 'use strict' | ||
function stringify(context, file) { | ||
var processor = context.processor | ||
var tree = context.tree | ||
var value | ||
@@ -35,3 +33,3 @@ | ||
value = inspect[context.color ? 'color' : 'noColor'](tree) + '\n' | ||
value = inspect[context.color ? 'color' : 'noColor'](context.tree) + '\n' | ||
} else if (context.treeOut) { | ||
@@ -45,5 +43,5 @@ // Add a `json` extension to ensure the file is correctly seen as JSON. | ||
// Add the line feed to create a valid UNIX file. | ||
value = JSON.stringify(tree, null, 2) + '\n' | ||
value = JSON.stringify(context.tree, null, 2) + '\n' | ||
} else { | ||
value = processor.stringify(tree, file) | ||
value = context.processor.stringify(context.tree, file) | ||
} | ||
@@ -50,0 +48,0 @@ |
@@ -10,9 +10,7 @@ 'use strict' | ||
function fileSystem(context, settings, next) { | ||
var input = context.files | ||
if (input.length === 0) { | ||
if (context.files.length === 0) { | ||
next() | ||
} else { | ||
find( | ||
input, | ||
context.files, | ||
{ | ||
@@ -19,0 +17,0 @@ cwd: settings.cwd, |
@@ -8,4 +8,2 @@ 'use strict' | ||
var prefix = 'vfile-reporter' | ||
function log(context, settings, next) { | ||
@@ -17,3 +15,3 @@ var reporter = settings.reporter || report | ||
try { | ||
reporter = load(reporter, {cwd: settings.cwd, prefix: prefix}) | ||
reporter = load(reporter, {cwd: settings.cwd, prefix: 'vfile-reporter'}) | ||
} catch (_) { | ||
@@ -20,0 +18,0 @@ next(new Error('Could not find reporter `' + reporter + '`')) |
@@ -10,6 +10,5 @@ 'use strict' | ||
function stdin(context, settings, next) { | ||
var streamIn = settings.streamIn | ||
var error | ||
if (settings.files && settings.files.length !== 0) { | ||
if (settings.files && settings.files.length > 0) { | ||
debug('Ignoring `streamIn`') | ||
@@ -28,3 +27,3 @@ | ||
if (streamIn.isTTY) { | ||
if (settings.streamIn.isTTY) { | ||
debug('Cannot read from `tty` stream') | ||
@@ -38,3 +37,3 @@ next(new Error('No input')) | ||
streamIn.pipe(concat({encoding: 'string'}, read)) | ||
settings.streamIn.pipe(concat({encoding: 'string'}, read)) | ||
@@ -41,0 +40,0 @@ function read(value) { |
@@ -72,3 +72,2 @@ 'use strict' | ||
var self = this | ||
var origin | ||
@@ -80,9 +79,7 @@ if (typeof file === 'string') { | ||
// Prevent files from being added multiple times. | ||
origin = file.history[0] | ||
if (self.origins.indexOf(origin) !== -1) { | ||
if (self.origins.indexOf(file.history[0]) !== -1) { | ||
return self | ||
} | ||
self.origins.push(origin) | ||
self.origins.push(file.history[0]) | ||
@@ -89,0 +86,0 @@ // Add. |
@@ -7,11 +7,6 @@ 'use strict' | ||
var debug = require('debug')('unified-engine:find-up') | ||
var wrap = require('trough/wrap') | ||
module.exports = FindUp | ||
var read = fs.readFile | ||
var resolve = path.resolve | ||
var relative = path.relative | ||
var join = path.join | ||
var dirname = path.dirname | ||
FindUp.prototype.load = load | ||
@@ -21,3 +16,2 @@ | ||
var self = this | ||
var fp = options.filePath | ||
@@ -30,4 +24,4 @@ self.cache = {} | ||
if (fp) { | ||
self.givenFilePath = resolve(options.cwd, fp) | ||
if (options.filePath) { | ||
self.givenFilePath = path.resolve(options.cwd, options.filePath) | ||
} | ||
@@ -38,11 +32,6 @@ } | ||
var self = this | ||
var cache = self.cache | ||
var givenFilePath = self.givenFilePath | ||
var givenFile = self.givenFile | ||
var names = self.names | ||
var create = self.create | ||
var cwd = self.cwd | ||
var parent | ||
if (givenFilePath) { | ||
if (self.givenFilePath) { | ||
if (givenFile) { | ||
@@ -53,4 +42,4 @@ apply(callback, givenFile) | ||
self.givenFile = givenFile | ||
debug('Checking given file `%s`', givenFilePath) | ||
read(givenFilePath, loadGiven) | ||
debug('Checking given file `%s`', self.givenFilePath) | ||
fs.readFile(self.givenFilePath, loadGiven) | ||
} | ||
@@ -65,9 +54,9 @@ | ||
filePath = resolve(cwd, filePath) | ||
parent = dirname(filePath) | ||
filePath = path.resolve(self.cwd, filePath) | ||
parent = path.dirname(filePath) | ||
if (parent in cache) { | ||
apply(callback, cache[parent]) | ||
if (parent in self.cache) { | ||
apply(callback, self.cache[parent]) | ||
} else { | ||
cache[parent] = [callback] | ||
self.cache[parent] = [callback] | ||
find(parent) | ||
@@ -83,3 +72,3 @@ } | ||
'Cannot read given file `%s`\n%s', | ||
relative(cwd, givenFilePath), | ||
path.relative(self.cwd, self.givenFilePath), | ||
error.stack | ||
@@ -90,19 +79,28 @@ ) | ||
result.syscall = error.syscall | ||
loaded(result) | ||
} else { | ||
try { | ||
result = create(buf, givenFilePath) | ||
debug('Read given file `%s`', givenFilePath) | ||
} catch (error_) { | ||
result = fault( | ||
'Cannot parse given file `%s`\n%s', | ||
relative(cwd, givenFilePath), | ||
error_.stack | ||
wrap(self.create, onparse)(buf, self.givenFilePath) | ||
} | ||
function onparse(error, result) { | ||
if (error) { | ||
debug(error.message) | ||
loaded( | ||
fault( | ||
'Cannot parse given file `%s`\n%s', | ||
path.relative(self.cwd, self.givenFilePath), | ||
error.stack | ||
) | ||
) | ||
debug(error_.message) | ||
} else { | ||
debug('Read given file `%s`', self.givenFilePath) | ||
loaded(result) | ||
} | ||
} | ||
givenFile = result | ||
self.givenFile = result | ||
applyAll(cbs, result) | ||
function loaded(result) { | ||
givenFile = result | ||
self.givenFile = result | ||
applyAll(cbs, result) | ||
} | ||
} | ||
@@ -112,3 +110,2 @@ | ||
var index = -1 | ||
var length = names.length | ||
@@ -123,6 +120,6 @@ next() | ||
// *very* slow. | ||
if (++index < length) { | ||
read(join(directory, names[index]), done) | ||
if (++index < self.names.length) { | ||
fs.readFile(path.join(directory, self.names[index]), done) | ||
} else { | ||
parent = dirname(directory) | ||
parent = path.dirname(directory) | ||
@@ -132,6 +129,6 @@ if (directory === parent) { | ||
found() | ||
} else if (parent in cache) { | ||
apply(found, cache[parent]) | ||
} else if (parent in self.cache) { | ||
apply(found, self.cache[parent]) | ||
} else { | ||
cache[parent] = [found] | ||
self.cache[parent] = [found] | ||
find(parent) | ||
@@ -143,5 +140,3 @@ } | ||
function done(error, buf) { | ||
var name = names[index] | ||
var fp = join(directory, name) | ||
var contents | ||
var fp = path.join(directory, self.names[index]) | ||
@@ -154,25 +149,29 @@ /* istanbul ignore if - Hard to test. */ | ||
error = fault( | ||
'Cannot read file `%s`\n%s', | ||
relative(cwd, fp), | ||
error.message | ||
) | ||
debug(error.message) | ||
return found(error) | ||
} | ||
try { | ||
contents = create(buf, fp) | ||
} catch (error_) { | ||
return found( | ||
fault('Cannot parse file `%s`\n%s', relative(cwd, fp), error_.message) | ||
fault( | ||
'Cannot read file `%s`\n%s', | ||
path.relative(self.cwd, fp), | ||
error.message | ||
) | ||
) | ||
} | ||
/* istanbul ignore else - maybe used in the future. */ | ||
if (contents) { | ||
debug('Read file `%s`', fp) | ||
found(null, contents) | ||
} else { | ||
next() | ||
wrap(self.create, onparse)(buf, fp) | ||
function onparse(error, result) { | ||
if (error) { | ||
found( | ||
fault( | ||
'Cannot parse file `%s`\n%s', | ||
path.relative(self.cwd, fp), | ||
error.message | ||
) | ||
) | ||
} else if (result) { | ||
debug('Read file `%s`', fp) | ||
found(null, result) | ||
} else { | ||
next() | ||
} | ||
} | ||
@@ -182,4 +181,4 @@ } | ||
function found(error, result) { | ||
var cbs = cache[directory] | ||
cache[directory] = error || result | ||
var cbs = self.cache[directory] | ||
self.cache[directory] = error || result | ||
applyAll(cbs, error || result) | ||
@@ -186,0 +185,0 @@ } |
@@ -9,12 +9,2 @@ 'use strict' | ||
var readdir = fs.readdir | ||
var stat = fs.stat | ||
var sep = path.sep | ||
var join = path.join | ||
var relative = path.relative | ||
var resolve = path.resolve | ||
var basename = path.basename | ||
var extname = path.extname | ||
var magic = glob.hasMagic | ||
module.exports = find | ||
@@ -40,3 +30,2 @@ | ||
function expand(input, options, next) { | ||
var cwd = options.cwd | ||
var paths = [] | ||
@@ -55,13 +44,14 @@ var actual = 0 | ||
if (typeof file === 'string') { | ||
if (magic(file)) { | ||
if (glob.hasMagic(file)) { | ||
expected++ | ||
glob(file, {cwd: cwd}, one) | ||
glob(file, {cwd: options.cwd}, one) | ||
} else { | ||
// `relative` to make the paths canonical. | ||
file = relative(cwd, resolve(cwd, file)) || '.' | ||
file = | ||
path.relative(options.cwd, path.resolve(options.cwd, file)) || '.' | ||
paths.push(file) | ||
} | ||
} else { | ||
file.cwd = cwd | ||
file.path = relative(cwd, file.path) | ||
file.cwd = options.cwd | ||
file.path = path.relative(options.cwd, file.path) | ||
file.history = [file.path] | ||
@@ -104,6 +94,2 @@ paths.push(file) | ||
function search(input, options, next) { | ||
var cwd = options.cwd | ||
var silent = options.silentlyIgnore | ||
var nested = options.nested | ||
var extensions = options.extensions | ||
var extraIgnore = gitignore().add(options.ignorePatterns) | ||
@@ -123,3 +109,3 @@ var files = [] | ||
function each(file) { | ||
var ext = typeof file === 'string' ? extname(file) : file.extname | ||
var ext = typeof file === 'string' ? path.extname(file) : file.extname | ||
var part | ||
@@ -134,3 +120,3 @@ | ||
if (nested && (part.charAt(0) === '.' || part === 'node_modules')) { | ||
if (options.nested && (part.charAt(0) === '.' || part === 'node_modules')) { | ||
return | ||
@@ -151,3 +137,3 @@ } | ||
if (ignored && (nested || silent)) { | ||
if (ignored && (options.nested || options.silentlyIgnore)) { | ||
return one(null, []) | ||
@@ -157,10 +143,10 @@ } | ||
if (!ignored && dir) { | ||
return readdir(resolve(cwd, filePath(file)), directory) | ||
return fs.readdir(path.resolve(options.cwd, filePath(file)), directory) | ||
} | ||
if ( | ||
nested && | ||
!dir && | ||
extensions.length !== 0 && | ||
extensions.indexOf(ext) === -1 | ||
options.nested && | ||
options.extensions.length > 0 && | ||
options.extensions.indexOf(ext) === -1 | ||
) { | ||
@@ -171,3 +157,3 @@ return one(null, []) | ||
file = vfile(file) | ||
file.cwd = cwd | ||
file.cwd = options.cwd | ||
@@ -198,3 +184,3 @@ if (ignored) { | ||
file = vfile(filePath(file)) | ||
file.cwd = cwd | ||
file.cwd = options.cwd | ||
@@ -230,3 +216,3 @@ try { | ||
function concat(value) { | ||
return join(filePath(file), value) | ||
return path.join(filePath(file), value) | ||
} | ||
@@ -237,7 +223,4 @@ } | ||
function statAndIgnore(file, options, callback) { | ||
var ignore = options.ignore | ||
var extraIgnore = options.extraIgnore | ||
var cwd = options.cwd | ||
var fp = resolve(cwd, filePath(file)) | ||
var normal = relative(cwd, fp) | ||
var fp = path.resolve(options.cwd, filePath(file)) | ||
var normal = path.relative(options.cwd, fp) | ||
var expected = 1 | ||
@@ -250,6 +233,6 @@ var actual = 0 | ||
expected++ | ||
stat(fp, handleStat) | ||
fs.stat(fp, handleStat) | ||
} | ||
ignore.check(fp, handleIgnore) | ||
options.ignore.check(fp, handleIgnore) | ||
@@ -279,6 +262,6 @@ function handleStat(error, value) { | ||
normal === '..' || | ||
normal.charAt(0) === sep || | ||
normal.slice(0, 3) === '..' + sep | ||
normal.charAt(0) === path.sep || | ||
normal.slice(0, 3) === '..' + path.sep | ||
? false | ||
: extraIgnore.ignores(normal)) | ||
: options.extraIgnore.ignores(normal)) | ||
}) | ||
@@ -290,3 +273,3 @@ } | ||
function base(file) { | ||
return typeof file === 'string' ? basename(file) : file.basename | ||
return typeof file === 'string' ? path.basename(file) : file.basename | ||
} | ||
@@ -293,0 +276,0 @@ |
@@ -11,7 +11,2 @@ 'use strict' | ||
var sep = path.sep | ||
var dirname = path.dirname | ||
var relative = path.relative | ||
var resolve = path.resolve | ||
function Ignore(options) { | ||
@@ -41,8 +36,8 @@ this.cwd = options.cwd | ||
} else if (ignore) { | ||
normal = relative( | ||
resolve( | ||
normal = path.relative( | ||
path.resolve( | ||
self.cwd, | ||
self.ignorePathResolveFrom === 'cwd' ? '.' : ignore.filePath | ||
), | ||
resolve(self.cwd, filePath) | ||
path.resolve(self.cwd, filePath) | ||
) | ||
@@ -53,4 +48,4 @@ | ||
normal === '..' || | ||
normal.charAt(0) === sep || | ||
normal.slice(0, 3) === '..' + sep | ||
normal.charAt(0) === path.sep || | ||
normal.slice(0, 3) === '..' + path.sep | ||
) { | ||
@@ -69,4 +64,4 @@ callback(null, false) | ||
var ignore = gitignore().add(String(buf)) | ||
ignore.filePath = dirname(filePath) | ||
ignore.filePath = path.dirname(filePath) | ||
return ignore | ||
} |
{ | ||
"name": "unified-engine", | ||
"version": "8.0.0", | ||
"version": "8.1.0", | ||
"description": "Engine to process multiple files with unified", | ||
@@ -48,21 +48,22 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@types/node": "^13.0.0", | ||
"@types/node": "^14.0.0", | ||
"@types/unist": "^2.0.0", | ||
"dtslint": "^3.0.0", | ||
"dtslint": "^4.0.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^2.0.0", | ||
"remark": "^11.0.0", | ||
"remark-cli": "^7.0.0", | ||
"remark-preset-wooorm": "^6.0.0", | ||
"remark": "^13.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"remark-toc": "^7.0.0", | ||
"semver": "^7.0.0", | ||
"strip-ansi": "^6.0.0", | ||
"tape": "^4.0.0", | ||
"tape": "^5.0.0", | ||
"unified": "^9.0.0", | ||
"vfile": "^4.0.0", | ||
"vfile-reporter-json": "^2.0.0", | ||
"vfile-reporter-pretty": "^4.0.0", | ||
"xo": "^0.28.0" | ||
"vfile-reporter-pretty": "^5.0.0", | ||
"xo": "^0.38.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write \"**/*.{js,ts}\" && xo --fix --ignore types", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node test", | ||
@@ -103,9 +104,15 @@ "test-coverage": "nyc --reporter lcov tape test/index.js", | ||
"esnext": false, | ||
"ignore": [ | ||
"types" | ||
], | ||
"rules": { | ||
"unicorn/prefer-includes": "off", | ||
"unicorn/string-content": "off", | ||
"complexity": "off", | ||
"guard-for-in": "off" | ||
"guard-for-in": "off", | ||
"unicorn/no-array-callback-reference": "off", | ||
"unicorn/no-array-for-each": "off", | ||
"unicorn/no-this-assignment": "off", | ||
"unicorn/prefer-optional-catch-binding": "off", | ||
"unicorn/prefer-includes": "off" | ||
} | ||
} | ||
} |
@@ -199,5 +199,5 @@ # unified-engine | ||
[build-badge]: https://img.shields.io/travis/unifiedjs/unified-engine.svg | ||
[build-badge]: https://github.com/unifiedjs/unified-engine/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/unifiedjs/unified-engine | ||
[build]: https://github.com/unifiedjs/unified-engine/actions | ||
@@ -218,5 +218,5 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/unifiedjs/unified-engine.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[chat]: https://spectrum.chat/unified | ||
[chat]: https://github.com/unifiedjs/unified/discussions | ||
@@ -227,7 +227,7 @@ [npm]: https://docs.npmjs.com/cli/install | ||
[contributing]: https://github.com/unifiedjs/.github/blob/master/contributing.md | ||
[contributing]: https://github.com/unifiedjs/.github/blob/HEAD/contributing.md | ||
[support]: https://github.com/unifiedjs/.github/blob/master/support.md | ||
[support]: https://github.com/unifiedjs/.github/blob/HEAD/support.md | ||
[coc]: https://github.com/unifiedjs/.github/blob/master/code-of-conduct.md | ||
[coc]: https://github.com/unifiedjs/.github/blob/HEAD/code-of-conduct.md | ||
@@ -234,0 +234,0 @@ [license]: license |
@@ -249,4 +249,2 @@ // TypeScript Version: 3.0 | ||
interface Completer { | ||
(fileSet: FileSet, next?: CompleterNext): Error | Promise<void> | ||
/** | ||
@@ -259,2 +257,4 @@ * Plugins specified through various mechanisms are attached to a new processor for each file. | ||
pluginId?: string | ||
(fileSet: FileSet, next?: CompleterNext): Error | Promise<void> | ||
} | ||
@@ -261,0 +261,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64313
17
1722