|
|
@ -1,10 +1,9 @@ |
|
|
|
import flatten from 'arr-flatten'; |
|
|
|
import unique from 'array-unique'; |
|
|
|
import minimatch from 'minimatch'; |
|
|
|
import IGNORED from './ignored'; |
|
|
|
import { resolve } from 'path'; |
|
|
|
import { stat, readdir, readFile } from 'fs-promise'; |
|
|
|
import parser from 'gitignore-parser'; |
|
|
|
import ignore from 'ignore'; |
|
|
|
|
|
|
|
/** |
|
|
|
* Returns a list of files in the given |
|
|
@ -41,19 +40,19 @@ export async function npm (path, pkg, { |
|
|
|
|
|
|
|
// compile list of ignored patterns and files
|
|
|
|
const npmIgnore = await maybeRead(resolve(path, '.npmignore'), null); |
|
|
|
const ignored = parser.compile( |
|
|
|
const filter = ignore().add( |
|
|
|
IGNORED + |
|
|
|
'\n' + |
|
|
|
clearRelative(null != npmIgnore |
|
|
|
? npmIgnore |
|
|
|
: await maybeRead(resolve(path, '.gitignore'))) |
|
|
|
); |
|
|
|
).createFilter(); |
|
|
|
|
|
|
|
// if debugging is turned on, describe which files
|
|
|
|
// are being ignored
|
|
|
|
const prefixLength = path.length + 1; |
|
|
|
const accepts = function (file) { |
|
|
|
const accepted = ignored.accepts(file.substr(prefixLength)); |
|
|
|
const relativePath = file.substr(prefixLength); |
|
|
|
if ('' === relativePath) return true; |
|
|
|
const accepted = filter(relativePath); |
|
|
|
if (!accepted && debug) { |
|
|
|
console.log('> [debug] ignoring "%s"', file); |
|
|
|
} |
|
|
@ -61,9 +60,9 @@ export async function npm (path, pkg, { |
|
|
|
}; |
|
|
|
|
|
|
|
// locate files
|
|
|
|
if (debug) console.time('> [debug] locating files'); |
|
|
|
if (debug) console.time(`> [debug] locating files ${path}`); |
|
|
|
const files = await explode(search, { accepts, limit, debug }); |
|
|
|
if (debug) console.timeEnd('> [debug] locating files'); |
|
|
|
if (debug) console.timeEnd(`> [debug] locating files ${path}`); |
|
|
|
|
|
|
|
// always include manifest as npm does not allow ignoring it
|
|
|
|
// source: https://docs.npmjs.com/files/package.json#files
|
|
|
@ -97,17 +96,17 @@ export async function docker (path, { |
|
|
|
const search = search_.map((file) => asAbsolute(file, path)); |
|
|
|
|
|
|
|
// compile list of ignored patterns and files
|
|
|
|
const ignored = parser.compile( |
|
|
|
const filter = ignore().add( |
|
|
|
IGNORED + |
|
|
|
'\n' + |
|
|
|
await maybeRead(resolve(path, '.dockerignore')) |
|
|
|
); |
|
|
|
).createFilter(); |
|
|
|
|
|
|
|
// if debugging is turned on, describe which files
|
|
|
|
// are being ignored
|
|
|
|
const prefixLength = path.length + 1; |
|
|
|
const accepts = function (file) { |
|
|
|
const accepted = ignored.accepts(file.substr(prefixLength)); |
|
|
|
const relativePath = file.substr(prefixLength); |
|
|
|
if ('' === relativePath) return true; |
|
|
|
const accepted = filter(relativePath); |
|
|
|
if (!accepted && debug) { |
|
|
|
console.log('> [debug] ignoring "%s"', file); |
|
|
|
} |
|
|
@ -115,9 +114,9 @@ export async function docker (path, { |
|
|
|
}; |
|
|
|
|
|
|
|
// locate files
|
|
|
|
if (debug) console.time('> [debug] locating files'); |
|
|
|
if (debug) console.time(`> [debug] locating files ${path}`); |
|
|
|
const files = await explode(search, { accepts, limit, debug }); |
|
|
|
if (debug) console.timeEnd('> [debug] locating files'); |
|
|
|
if (debug) console.timeEnd(`> [debug] locating files ${path}`); |
|
|
|
|
|
|
|
// always include manifest as npm does not allow ignoring it
|
|
|
|
// source: https://docs.npmjs.com/files/package.json#files
|
|
|
@ -215,4 +214,4 @@ const maybeRead = async function (path, default_ = '') { |
|
|
|
|
|
|
|
const clearRelative = function (str) { |
|
|
|
return str.replace(/(\n|^)\.\//g, '$1'); |
|
|
|
} |
|
|
|
}; |
|
|
|