diff --git a/lib/configuration.js b/lib/configuration.js index 1dc0f20..1110613 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -5,7 +5,7 @@ var Module = require('module') var yaml = require('js-yaml') var json = require('parse-json') var debug = require('debug')('unified-engine:configuration') -var resolve = require('load-plugin').resolve +var loadPlugin = require('load-plugin') var plain = require('is-plain-obj') var fault = require('fault') var FindUp = require('./find-up') @@ -13,10 +13,6 @@ var FindUp = require('./find-up') module.exports = Config var own = {}.hasOwnProperty -var extname = path.extname -var basename = path.basename -var dirname = path.dirname -var relative = path.relative var loaders = { '.json': loadJson, @@ -30,8 +26,6 @@ var defaultLoader = loadJson Config.prototype.load = load function Config(options) { - var rcName = options.rcName - var packageField = options.packageField var names = [] this.cwd = options.cwd @@ -40,14 +34,22 @@ function Config(options) { this.configTransform = options.configTransform this.defaultConfig = options.defaultConfig - 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 + ) } this.given = {settings: options.settings, plugins: options.plugins} @@ -64,9 +66,8 @@ function Config(options) { function load(filePath, callback) { 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) function done(error, file) { if (error || file) { @@ -79,31 +80,37 @@ function load(filePath, callback) { 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} var result = {settings: {}, plugins: []} var contents = buf ? fn.apply(self, arguments) : undefined - 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 } if (contents === undefined) { - if (defaults) { - merge(result, defaults, Object.assign({}, options, {root: self.cwd})) + if (self.defaultConfig) { + merge( + result, + self.defaultConfig, + Object.assign({}, options, {root: self.cwd}) + ) } } else { merge( result, contents, - Object.assign({}, options, {root: dirname(filePath)}) + Object.assign({}, options, {root: path.dirname(filePath)}) ) } @@ -119,7 +126,7 @@ function loadScript(buf, filePath) { if (!submodule) { submodule = new Module(filePath, module) submodule.filename = filePath - submodule.paths = Module._nodeModulePaths(dirname(filePath)) + submodule.paths = Module._nodeModulePaths(path.dirname(filePath)) submodule._compile(String(buf), filePath) submodule.loaded = true Module._cache[filePath] = submodule @@ -129,13 +136,13 @@ function loadScript(buf, filePath) { } function loadYaml(buf, filePath) { - return yaml.safeLoad(buf, {filename: basename(filePath)}) + return yaml.safeLoad(buf, {filename: path.basename(filePath)}) } function loadJson(buf, filePath) { var result = json(buf, filePath) - if (basename(filePath) === 'package.json') { + if (path.basename(filePath) === 'package.json') { result = result[this.packageField] } @@ -143,10 +150,6 @@ function loadJson(buf, filePath) { } function merge(target, raw, options) { - var root = options.root - var cwd = options.cwd - var prefix = options.prefix - if (typeof raw === 'object' && raw !== null) { addPreset(raw) } else { @@ -176,11 +179,10 @@ function merge(target, raw, options) { } function addEach(result) { - var length = result.length var index = -1 var value - while (++index < length) { + while (++index < result.length) { value = result[index] if (value !== null && typeof value === 'object' && 'length' in value) { @@ -210,7 +212,7 @@ function merge(target, raw, options) { } function addModule(id, value) { - var fp = resolve(id, {cwd: root, prefix: prefix}) + var fp = loadPlugin.resolve(id, {cwd: options.root, prefix: options.prefix}) var result if (fp) { @@ -219,7 +221,7 @@ function merge(target, raw, options) { } catch (error) { throw fault( 'Cannot parse script `%s`\n%s', - relative(root, fp), + path.relative(options.root, fp), error.stack ) } @@ -228,17 +230,21 @@ function merge(target, raw, options) { if (typeof result === 'function') { addPlugin(result, value) } else { - merge(target, result, Object.assign({}, options, {root: dirname(fp)})) + merge( + target, + result, + Object.assign({}, options, {root: path.dirname(fp)}) + ) } } catch (_) { throw fault( 'Error: Expected preset or plugin, not %s, at `%s`', 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( failingModule(fp, new Error('Could not find module `' + id + '`')), value @@ -266,15 +272,11 @@ function reconfigure(entry, value) { } 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] } } } diff --git a/lib/file-pipeline/configure.js b/lib/file-pipeline/configure.js index 93e86a2..6616f55 100644 --- a/lib/file-pipeline/configure.js +++ b/lib/file-pipeline/configure.js @@ -8,22 +8,16 @@ module.exports = configure // Collect configuration for a file based on the context. function configure(context, file, fileSet, next) { - var config = context.configuration - var processor = context.processor - if (stats(file).fatal) { return next() } - config.load(file.path, handleConfiguration) + context.configuration.load(file.path, handleConfiguration) function handleConfiguration(error, configuration) { - var plugins - var options + var index = -1 var plugin - var length - var index - var name + var options if (error) { return next(error) @@ -31,17 +25,13 @@ function configure(context, file, fileSet, next) { // Store configuration on the context object. debug('Using settings `%j`', configuration.settings) - processor.data('settings', configuration.settings) - - plugins = configuration.plugins - length = plugins.length - index = -1 + context.processor.data('settings', configuration.settings) - debug('Using `%d` plugins', length) + debug('Using `%d` plugins', configuration.plugins.length) - while (++index < length) { - plugin = plugins[index][0] - options = plugins[index][1] + while (++index < configuration.plugins.length) { + plugin = configuration.plugins[index][0] + options = configuration.plugins[index][1] if (options === false) { continue @@ -52,11 +42,14 @@ function configure(context, file, fileSet, next) { options = undefined } - 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_) { /* istanbul ignore next - Should not happen anymore! */ return next(error_) diff --git a/lib/file-pipeline/copy.js b/lib/file-pipeline/copy.js index 12a8d0e..75350c3 100644 --- a/lib/file-pipeline/copy.js +++ b/lib/file-pipeline/copy.js @@ -6,15 +6,9 @@ var debug = require('debug')('unified-engine:file-pipeline:copy') module.exports = copy -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 var currentPath = file.path @@ -23,11 +17,11 @@ function copy(context, file, fileSet, next) { return next() } - outpath = resolve(context.cwd, outpath) + outpath = path.resolve(context.cwd, outpath) debug('Copying `%s`', currentPath) - stat(outpath, onstatfile) + fs.stat(outpath, onstatfile) function onstatfile(error, stats) { if (error) { @@ -40,7 +34,7 @@ function copy(context, file, fileSet, next) { ) } - stat(dirname(outpath), onstatparent) + fs.stat(path.dirname(outpath), onstatparent) } else { done(stats.isDirectory()) } @@ -57,13 +51,13 @@ function copy(context, file, fileSet, next) { } function done(directory) { - if (!directory && multi) { + if (!directory && fileSet.expected > 1) { return next( 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) debug('Copying document from %s to %s', currentPath, file.path) diff --git a/lib/file-pipeline/file-system.js b/lib/file-pipeline/file-system.js index ec0aa64..f3be897 100644 --- a/lib/file-pipeline/file-system.js +++ b/lib/file-pipeline/file-system.js @@ -7,9 +7,6 @@ var stats = require('vfile-statistics') module.exports = fileSystem -var writeFile = fs.writeFile -var resolve = path.resolve - // Write a virtual file to the file-system. // Ignored when `output` is not given. function fileSystem(context, file, fileSet, next) { @@ -37,10 +34,10 @@ function fileSystem(context, file, fileSet, next) { return next() } - destinationPath = resolve(context.cwd, destinationPath) + destinationPath = path.resolve(context.cwd, destinationPath) debug('Writing document to `%s`', destinationPath) file.stored = true - writeFile(destinationPath, file.toString(), next) + fs.writeFile(destinationPath, file.toString(), next) } diff --git a/lib/file-pipeline/read.js b/lib/file-pipeline/read.js index a2e94a5..3f0d5aa 100644 --- a/lib/file-pipeline/read.js +++ b/lib/file-pipeline/read.js @@ -7,9 +7,6 @@ var stats = require('vfile-statistics') module.exports = read -var resolve = path.resolve -var readFile = fs.readFile - // Fill a file with its contents when not already filled. function read(context, file, fileSet, next) { var filePath = file.path @@ -21,10 +18,10 @@ function read(context, file, fileSet, next) { debug('Not reading failed file `%s`', filePath) 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) } function onread(error, contents) { diff --git a/lib/file-pipeline/stringify.js b/lib/file-pipeline/stringify.js index 16c406b..092ce0e 100644 --- a/lib/file-pipeline/stringify.js +++ b/lib/file-pipeline/stringify.js @@ -9,8 +9,6 @@ module.exports = stringify // Stringify a tree. function stringify(context, file) { - var processor = context.processor - var tree = context.tree var value if (stats(file).fatal) { @@ -31,7 +29,7 @@ function stringify(context, file) { file.extname = '.txt' } - value = inspect[context.color ? 'color' : 'noColor'](tree) + '\n' + value = inspect[context.color ? 'color' : 'noColor'](context.tree) + '\n' } else if (context.treeOut) { // Add a `json` extension to ensure the file is correctly seen as JSON. // Only add it if there is a path — not if the file is for example stdin. @@ -40,9 +38,9 @@ function stringify(context, file) { } // 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) } if (value === undefined || value === null) { diff --git a/lib/file-set-pipeline/file-system.js b/lib/file-set-pipeline/file-system.js index fe71b72..5edf834 100644 --- a/lib/file-set-pipeline/file-system.js +++ b/lib/file-set-pipeline/file-system.js @@ -7,13 +7,11 @@ module.exports = fileSystem // Find files from the file-system. function fileSystem(context, settings, next) { - var input = context.files - - if (input.length === 0) { + if (context.files.length === 0) { next() } else { find( - input, + context.files, { cwd: settings.cwd, extensions: settings.extensions, diff --git a/lib/file-set-pipeline/log.js b/lib/file-set-pipeline/log.js index 331acfb..4f107da 100644 --- a/lib/file-set-pipeline/log.js +++ b/lib/file-set-pipeline/log.js @@ -5,15 +5,13 @@ var report = require('vfile-reporter') module.exports = log -var prefix = 'vfile-reporter' - function log(context, settings, next) { var reporter = settings.reporter || report var diagnostics if (typeof reporter === 'string') { try { - reporter = load(reporter, {cwd: settings.cwd, prefix: prefix}) + reporter = load(reporter, {cwd: settings.cwd, prefix: 'vfile-reporter'}) } catch (_) { next(new Error('Could not find reporter `' + reporter + '`')) return diff --git a/lib/file-set-pipeline/stdin.js b/lib/file-set-pipeline/stdin.js index aedcd6f..376eefa 100644 --- a/lib/file-set-pipeline/stdin.js +++ b/lib/file-set-pipeline/stdin.js @@ -7,7 +7,6 @@ var concat = require('concat-stream') module.exports = stdin function stdin(context, settings, next) { - var streamIn = settings.streamIn var error if (settings.files && settings.files.length > 0) { @@ -24,7 +23,7 @@ function stdin(context, settings, next) { return } - if (streamIn.isTTY) { + if (settings.streamIn.isTTY) { debug('Cannot read from `tty` stream') next(new Error('No input')) @@ -33,7 +32,7 @@ function stdin(context, settings, next) { debug('Reading from `streamIn`') - streamIn.pipe(concat({encoding: 'string'}, read)) + settings.streamIn.pipe(concat({encoding: 'string'}, read)) function read(value) { var file = vfile(settings.filePath || undefined) diff --git a/lib/file-set.js b/lib/file-set.js index 0aff04c..1aa2686 100644 --- a/lib/file-set.js +++ b/lib/file-set.js @@ -69,20 +69,17 @@ function use(plugin) { // Only runs `file-pipeline` on files which have not `failed` before addition. function add(file) { var self = this - var origin if (typeof file === 'string') { file = vfile(file) } // 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]) // Add. self.valueOf().push(file) diff --git a/lib/find-up.js b/lib/find-up.js index fd17558..786d9fb 100644 --- a/lib/find-up.js +++ b/lib/find-up.js @@ -7,17 +7,10 @@ var debug = require('debug')('unified-engine:find-up') 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 function FindUp(options) { var self = this - var fp = options.filePath self.cache = {} self.cwd = options.cwd @@ -25,29 +18,24 @@ function FindUp(options) { self.names = options.names self.create = options.create - if (fp) { - self.givenFilePath = resolve(options.cwd, fp) + if (options.filePath) { + self.givenFilePath = path.resolve(options.cwd, options.filePath) } } function load(filePath, callback) { 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) { apply(callback, givenFile) } else { givenFile = [callback] self.givenFile = givenFile - debug('Checking given file `%s`', givenFilePath) - read(givenFilePath, loadGiven) + debug('Checking given file `%s`', self.givenFilePath) + fs.readFile(self.givenFilePath, loadGiven) } return @@ -57,13 +45,13 @@ function load(filePath, callback) { return callback() } - 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) } @@ -74,7 +62,7 @@ function load(filePath, callback) { if (error) { result = fault( 'Cannot read given file `%s`\n%s', - relative(cwd, givenFilePath), + path.relative(self.cwd, self.givenFilePath), error.stack ) result.code = 'ENOENT' @@ -82,12 +70,12 @@ function load(filePath, callback) { result.syscall = error.syscall } else { try { - result = create(buf, givenFilePath) - debug('Read given file `%s`', givenFilePath) + result = self.create(buf, self.givenFilePath) + debug('Read given file `%s`', self.givenFilePath) } catch (error_) { result = fault( 'Cannot parse given file `%s`\n%s', - relative(cwd, givenFilePath), + path.relative(self.cwd, self.givenFilePath), error_.stack ) debug(error_.message) @@ -101,7 +89,6 @@ function load(filePath, callback) { function find(directory) { var index = -1 - var length = names.length next() @@ -111,26 +98,25 @@ function load(filePath, callback) { // Try to read the next file. // We do not use `readdir` because on huge directories, that could be // *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) if (directory === parent) { debug('No files found for `%s`', filePath) 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) } } } function done(error, buf) { - var name = names[index] - var fp = join(directory, name) + var fp = path.join(directory, self.names[index]) var contents /* istanbul ignore if - Hard to test. */ @@ -141,7 +127,7 @@ function load(filePath, callback) { error = fault( 'Cannot read file `%s`\n%s', - relative(cwd, fp), + path.relative(self.cwd, fp), error.message ) debug(error.message) @@ -149,10 +135,14 @@ function load(filePath, callback) { } try { - contents = create(buf, fp) + contents = self.create(buf, fp) } catch (error_) { return found( - fault('Cannot parse file `%s`\n%s', relative(cwd, fp), error_.message) + fault( + 'Cannot parse file `%s`\n%s', + path.relative(self.cwd, fp), + error_.message + ) ) } @@ -166,8 +156,8 @@ function load(filePath, callback) { } 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) } } diff --git a/lib/finder.js b/lib/finder.js index a28632f..bcc1b81 100644 --- a/lib/finder.js +++ b/lib/finder.js @@ -6,16 +6,6 @@ var gitignore = require('ignore') var glob = require('glob') var vfile = require('to-vfile') -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 // Search `patterns`, a mix of globs, paths, and files. @@ -36,7 +26,6 @@ function find(input, options, callback) { // Expand the given glob patterns, search given and found directories, and map // to vfiles. function expand(input, options, next) { - var cwd = options.cwd var paths = [] var actual = 0 var expected = 0 @@ -50,17 +39,18 @@ function expand(input, options, next) { function each(file) { 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] paths.push(file) } @@ -98,10 +88,6 @@ function expand(input, options, next) { // Search `paths`. 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) var files = [] var expected = 0 @@ -116,7 +102,7 @@ function search(input, options, next) { return each function each(file) { - var ext = typeof file === 'string' ? extname(file) : file.extname + var ext = typeof file === 'string' ? path.extname(file) : file.extname var part // Normalise globs. @@ -126,7 +112,7 @@ function search(input, options, next) { part = base(file) - if (nested && (part.charAt(0) === '.' || part === 'node_modules')) { + if (options.nested && (part.charAt(0) === '.' || part === 'node_modules')) { return } @@ -142,25 +128,25 @@ function search(input, options, next) { var ignored = result && result.ignored var dir = result && result.stats && result.stats.isDirectory() - if (ignored && (nested || silent)) { + if (ignored && (options.nested || options.silentlyIgnore)) { return one(null, []) } 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 ) { return one(null, []) } file = vfile(file) - file.cwd = cwd + file.cwd = options.cwd if (ignored) { try { @@ -186,7 +172,7 @@ function search(input, options, next) { * first, which was ok, but reading it is not. */ if (error) { file = vfile(filePath(file)) - file.cwd = cwd + file.cwd = options.cwd try { file.fail('Cannot read directory') @@ -217,17 +203,14 @@ function search(input, options, next) { } function concat(value) { - return join(filePath(file), value) + return path.join(filePath(file), value) } } } 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 var actual = 0 var stats @@ -235,10 +218,10 @@ function statAndIgnore(file, options, callback) { if (!file.contents) { expected++ - stat(fp, handleStat) + fs.stat(fp, handleStat) } - ignore.check(fp, handleIgnore) + options.ignore.check(fp, handleIgnore) function handleStat(error, value) { stats = value @@ -263,17 +246,17 @@ function statAndIgnore(file, options, callback) { ignored || (normal === '' || 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)) }) } } } function base(file) { - return typeof file === 'string' ? basename(file) : file.basename + return typeof file === 'string' ? path.basename(file) : file.basename } function filePath(file) { diff --git a/lib/ignore.js b/lib/ignore.js index 9a681da..9f24aad 100644 --- a/lib/ignore.js +++ b/lib/ignore.js @@ -8,11 +8,6 @@ module.exports = Ignore Ignore.prototype.check = check -var sep = path.sep -var dirname = path.dirname -var relative = path.relative -var resolve = path.resolve - function Ignore(options) { this.cwd = options.cwd this.ignorePathResolveFrom = options.ignorePathResolveFrom @@ -37,19 +32,19 @@ function check(filePath, callback) { if (error) { callback(error) } 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) ) if ( normal === '' || normal === '..' || - normal.charAt(0) === sep || - normal.slice(0, 3) === '..' + sep + normal.charAt(0) === path.sep || + normal.slice(0, 3) === '..' + path.sep ) { callback(null, false) } else { @@ -63,6 +58,6 @@ function check(filePath, callback) { function create(buf, filePath) { var ignore = gitignore().add(String(buf)) - ignore.filePath = dirname(filePath) + ignore.filePath = path.dirname(filePath) return ignore }