Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a48483c

Browse filesBrowse files
abetomoDeviaVir
authored andcommitted
Bugfix _filecopy exclude (motdotla#253)
* Bugfix `_fileCopy` exclude Add test of cases that were missing consideration * Bugfix `_fileCopy` exclude Add test of cases that were missing consideration * Fix to get from `path.sep` * Fix to make exclude specified separator `path.sep` * Remove unnecessary semicolon
1 parent 1aeae22 commit a48483c
Copy full SHA for a48483c

File tree

Expand file treeCollapse file tree

2 files changed

+53
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+53
-7
lines changed
Open diff view settings
Collapse file

‎lib/main.js‎

Copy file name to clipboardExpand all lines: lib/main.js
+20-5Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,26 @@ Lambda.prototype._fileCopy = function (program, src, dest, excludeNodeModules, c
197197
'.editorconfig',
198198
'deploy.env',
199199
'*.log',
200-
'/build/'
200+
path.join(path.sep, 'build', path.sep)
201201
]
202202
.concat(program.excludeGlobs ? program.excludeGlobs.split(' ') : [])
203-
.concat(excludeNodeModules ? ['/node_modules'] : []);
203+
.concat(excludeNodeModules ? [path.join(path.sep, 'node_modules')] : []);
204204
})();
205205

206+
// Formatting for `filter` of `fs.copy`
207+
const dirBlobs = [];
206208
const pattern = '{' + excludes.map(function (str) {
207-
if (str.charAt(0) == '/')
209+
if (str.charAt(str.length - 1) == path.sep) {
210+
str = str.substr(0, str.length - 1);
211+
dirBlobs.push(str);
212+
}
213+
if (str.charAt(0) == path.sep)
208214
return path.join(srcAbsolutePath, str);
215+
if (str.indexOf(path.sep) >= 0)
216+
return path.join(path.resolve('/**'), str);
209217
return str;
210-
}).join(',') + '}'
218+
}).join(',') + '}';
219+
const dirPatternRegExp = new RegExp(`(${dirBlobs.join('|')})$`);
211220

212221
fs.mkdirs(dest, function (err) {
213222
if (err) {
@@ -220,7 +229,13 @@ Lambda.prototype._fileCopy = function (program, src, dest, excludeNodeModules, c
220229
// include package.json unless prebuiltDirectory is set
221230
return true;
222231
}
223-
return !minimatch(src, pattern, { matchBase: true });
232+
233+
if (!minimatch(src, pattern, { matchBase: true }))
234+
return true;
235+
// Directory check. Even if `src` is a directory it will not end with '/'.
236+
if (!dirPatternRegExp.test(src))
237+
return false;
238+
return !fs.statSync(src).isDirectory();
224239
}
225240
};
226241
fs.copy(src, dest, options, function (err) {
Collapse file

‎test/main.js‎

Copy file name to clipboardExpand all lines: test/main.js
+33-2Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,19 @@ describe('node-lambda', function () {
176176
});
177177

178178
function rsyncTests(funcName) {
179+
before(function () {
180+
fs.mkdirSync('build');
181+
fs.mkdirsSync(path.join('__unittest', 'hoge'));
182+
fs.mkdirsSync(path.join('__unittest', 'fuga'));
183+
fs.writeFileSync(path.join('__unittest', 'hoge', 'piyo'));
184+
fs.writeFileSync('fuga');
185+
});
186+
after(function () {
187+
['build', 'fuga', '__unittest'].forEach(function (path) {
188+
fs.removeSync(path);
189+
});
190+
});
191+
179192
beforeEach(function (done) {
180193
lambda._cleanDirectory(codeDirectory, done);
181194
});
@@ -186,7 +199,7 @@ describe('node-lambda', function () {
186199
['index.js', 'package.json'].forEach(function (needle) {
187200
assert.include(contents, needle, `Target: "${needle}"`);
188201
});
189-
['node_modules'].forEach(function (needle) {
202+
['node_modules', 'build'].forEach(function (needle) {
190203
assert.notInclude(contents, needle, `Target: "${needle}"`);
191204
});
192205
done();
@@ -197,7 +210,13 @@ describe('node-lambda', function () {
197210
beforeEach(function (done) {
198211
// *main* => lib/main.js
199212
// In case of specifying files under the directory with wildcards
200-
program.excludeGlobs = '*.png test *main*';
213+
program.excludeGlobs = [
214+
'*.png',
215+
'test',
216+
'*main*',
217+
path.join('__unittest', 'hoge', '*'),
218+
path.join('fuga', path.sep)
219+
].join(' ');
201220
done();
202221
});
203222

@@ -214,11 +233,23 @@ describe('node-lambda', function () {
214233
it(funcName + ' excludes files matching excludeGlobs', function (done) {
215234
lambda[funcName](program, '.', codeDirectory, true, function (err, result) {
216235
var contents = fs.readdirSync(codeDirectory);
236+
['__unittest', 'fuga'].forEach(function (needle) {
237+
assert.include(contents, needle, `Target: "${needle}"`);
238+
});
239+
217240
['node-lambda.png', 'test'].forEach(function (needle) {
218241
assert.notInclude(contents, needle, `Target: "${needle}"`);
219242
});
243+
220244
contents = fs.readdirSync(path.join(codeDirectory, 'lib'));
221245
assert.notInclude(contents, 'main.js', 'Target: "lib/main.js"');
246+
247+
contents = fs.readdirSync(path.join(codeDirectory, '__unittest'));
248+
assert.include(contents, 'hoge', 'Target: "__unittest/hoge"');
249+
assert.notInclude(contents, 'fuga', 'Target: "__unittest/fuga"');
250+
251+
contents = fs.readdirSync(path.join(codeDirectory, '__unittest', 'hoge'));
252+
assert.isTrue(contents.length == 0, 'directory:__unittest/hoge is empty');
222253
done();
223254
});
224255
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.