Browse Source

Parse glob patterns and ignore special files (#130)

* Revert "Ignore special files on deploy (#115)"

This reverts commit 1de3b40fc4.
Fixes #127

* Parse glob patterns and ignore special files

Currently glob patterns are not parsed when selecting files to be
uploaded.

Fixes #127
Fixes #112

* Include dot files in matches

* Fix resolving of the glob promise array
master
Olli Vanhoja 8 years ago
committed by Leo Lamprecht
parent
commit
89940c1362
  1. 52
      lib/get-files.js
  2. 2
      package.json

52
lib/get-files.js

@ -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

2
package.json

@ -79,6 +79,7 @@
"email-prompt": "0.1.8", "email-prompt": "0.1.8",
"email-validator": "1.0.7", "email-validator": "1.0.7",
"fs-promise": "0.5.0", "fs-promise": "0.5.0",
"glob": "7.1.1",
"graceful-fs": "4.1.9", "graceful-fs": "4.1.9",
"ignore": "3.2.0", "ignore": "3.2.0",
"ini": "1.3.4", "ini": "1.3.4",
@ -92,7 +93,6 @@
"socket.io-client": "1.4.8", "socket.io-client": "1.4.8",
"spdy": "3.4.4", "spdy": "3.4.4",
"split-array": "1.0.1", "split-array": "1.0.1",
"stat-mode": "0.2.2",
"text-table": "0.2.0" "text-table": "0.2.0"
}, },
"devDependencies": { "devDependencies": {

Loading…
Cancel
Save