From 89940c1362547e38294571b4de07919b76e65652 Mon Sep 17 00:00:00 2001 From: Olli Vanhoja Date: Fri, 18 Nov 2016 03:35:58 -0800 Subject: [PATCH] Parse glob patterns and ignore special files (#130) * Revert "Ignore special files on deploy (#115)" This reverts commit 1de3b40fc438011ccfd4e92e56e6bdc51c9b4c7a. 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 --- lib/get-files.js | 52 +++++++++++++++++++++++++----------------------- package.json | 2 +- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/lib/get-files.js b/lib/get-files.js index 5daec1a..f540558 100644 --- a/lib/get-files.js +++ b/lib/get-files.js @@ -3,9 +3,9 @@ import {resolve} from 'path' // Packages import flatten from 'arr-flatten' -import ignore from 'ignore' -import Mode from 'stat-mode' import unique from 'array-unique' +import ignore from 'ignore' +import _glob from 'glob' import {stat, readdir, readFile} from 'fs-promise' // Ours @@ -40,7 +40,7 @@ export async function npm(path, pkg, { } // 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 const npmIgnore = await maybeRead(resolve(path, '.npmignore'), null) @@ -52,22 +52,13 @@ export async function npm(path, pkg, { ).createFilter() const prefixLength = path.length + 1 - const accepts = async function (file) { + const accepts = function (file) { const relativePath = file.substr(prefixLength) if (relativePath === '') { 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) if (!accepted && debug) { console.log('> [debug] ignoring "%s"', file) @@ -145,22 +136,13 @@ export async function docker(path, { ).createFilter() const prefixLength = path.length + 1 - const accepts = async function (file) { + const accepts = function (file) { const relativePath = file.substr(prefixLength) if (relativePath === '') { 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) if (!accepted && debug) { console.log('> [debug] ignoring "%s"', file) @@ -187,6 +169,18 @@ export async function docker(path, { 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. * Eg: @@ -201,12 +195,12 @@ export async function docker(path, { * @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 => { let path = file let s - if (!(await accepts(file))) { + if (!accepts(file)) { return null } @@ -220,6 +214,9 @@ const explode = async function (paths, {accepts}) { try { s = await stat(path) } catch (e2) { + if (debug) { + console.log('> [debug] ignoring invalid file "%s"', file) + } return null } } @@ -227,6 +224,11 @@ const explode = async function (paths, {accepts}) { if (s.isDirectory()) { const all = await readdir(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 diff --git a/package.json b/package.json index b702827..1e091bf 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "email-prompt": "0.1.8", "email-validator": "1.0.7", "fs-promise": "0.5.0", + "glob": "7.1.1", "graceful-fs": "4.1.9", "ignore": "3.2.0", "ini": "1.3.4", @@ -92,7 +93,6 @@ "socket.io-client": "1.4.8", "spdy": "3.4.4", "split-array": "1.0.1", - "stat-mode": "0.2.2", "text-table": "0.2.0" }, "devDependencies": {