@ -3,9 +3,9 @@ import {resolve} from 'path'
// Packages
// Packages
import flatten from 'arr-flatten'
import flatten from 'arr-flatten'
import ignore from 'ignore'
import Mode from 'stat-mode'
import unique from 'array-unique'
import unique from 'array-unique'
import ignore from 'ignore'
import _ glob from 'glob'
import { stat , readdir , readFile } from 'fs-promise'
import { stat , readdir , readFile } from 'fs-promise'
// Ours
// Ours
@ -40,7 +40,7 @@ export async function npm(path, pkg, {
}
}
// convert all filenames into absolute paths
// convert all filenames into absolute paths
const search = search_ . map ( file => asAbsolute ( file , path ) )
const search = Array . prototype . concat . apply ( [ ] , ( await Promise . all ( search_ . map ( file => glob ( file , { cwd : path , absolute : true , dot : true } ) ) ) ) )
// compile list of ignored patterns and files
// compile list of ignored patterns and files
const npmIgnore = await maybeRead ( resolve ( path , '.npmignore' ) , null )
const npmIgnore = await maybeRead ( resolve ( path , '.npmignore' ) , null )
@ -52,22 +52,13 @@ export async function npm(path, pkg, {
) . createFilter ( )
) . createFilter ( )
const prefixLength = path . length + 1
const prefixLength = path . length + 1
const accepts = async function ( file ) {
const accepts = function ( file ) {
const relativePath = file . substr ( prefixLength )
const relativePath = file . substr ( prefixLength )
if ( relativePath === '' ) {
if ( relativePath === '' ) {
return true
return true
}
}
const st = await stat ( file )
const mode = new Mode ( st )
if ( ! ( mode . isDirectory ( ) || mode . isFile ( ) || mode . isSymbolicLink ( ) ) ) {
if ( debug ) {
console . log ( '> [debug] ignoring special file "%s"' , file )
}
return false
}
const accepted = filter ( relativePath )
const accepted = filter ( relativePath )
if ( ! accepted && debug ) {
if ( ! accepted && debug ) {
console . log ( '> [debug] ignoring "%s"' , file )
console . log ( '> [debug] ignoring "%s"' , file )
@ -145,22 +136,13 @@ export async function docker(path, {
) . createFilter ( )
) . createFilter ( )
const prefixLength = path . length + 1
const prefixLength = path . length + 1
const accepts = async function ( file ) {
const accepts = function ( file ) {
const relativePath = file . substr ( prefixLength )
const relativePath = file . substr ( prefixLength )
if ( relativePath === '' ) {
if ( relativePath === '' ) {
return true
return true
}
}
const st = await stat ( file )
const mode = new Mode ( st )
if ( ! ( mode . isDirectory ( ) || mode . isFile ( ) || mode . isSymbolicLink ( ) ) ) {
if ( debug ) {
console . log ( '> [debug] ignoring special file "%s"' , file )
}
return false
}
const accepted = filter ( relativePath )
const accepted = filter ( relativePath )
if ( ! accepted && debug ) {
if ( ! accepted && debug ) {
console . log ( '> [debug] ignoring "%s"' , file )
console . log ( '> [debug] ignoring "%s"' , file )
@ -187,6 +169,18 @@ export async function docker(path, {
return unique ( files )
return unique ( files )
}
}
const glob = async function ( pattern , options ) {
return new Promise ( ( resolve , reject ) => {
_ glob ( pattern , options , ( error , files ) => {
if ( error ) {
reject ( error )
} else {
resolve ( files )
}
} )
} )
}
/ * *
/ * *
* Explodes directories into a full list of files .
* Explodes directories into a full list of files .
* Eg :
* Eg :
@ -201,12 +195,12 @@ export async function docker(path, {
* @ return { Array } of { String } s of full paths
* @ return { Array } of { String } s of full paths
* /
* /
const explode = async function ( paths , { accepts } ) {
const explode = async function ( paths , { accepts , debug } ) {
const list = async file => {
const list = async file => {
let path = file
let path = file
let s
let s
if ( ! ( await accepts ( file ) ) ) {
if ( ! accepts ( file ) ) {
return null
return null
}
}
@ -220,6 +214,9 @@ const explode = async function (paths, {accepts}) {
try {
try {
s = await stat ( path )
s = await stat ( path )
} catch ( e2 ) {
} catch ( e2 ) {
if ( debug ) {
console . log ( '> [debug] ignoring invalid file "%s"' , file )
}
return null
return null
}
}
}
}
@ -227,6 +224,11 @@ const explode = async function (paths, {accepts}) {
if ( s . isDirectory ( ) ) {
if ( s . isDirectory ( ) ) {
const all = await readdir ( file )
const all = await readdir ( file )
return many ( all . map ( subdir => asAbsolute ( subdir , file ) ) )
return many ( all . map ( subdir => asAbsolute ( subdir , file ) ) )
} else if ( ! s . isFile ( ) ) {
if ( debug ) {
console . log ( '> [debug] ignoring special file "%s"' , file )
}
return null
}
}
return path
return path