Merge pull request #5808 from serverless/sls-5745

Replace \ with / in paths on windows before passing to nanomatch
This commit is contained in:
Daniel Schep 2019-02-08 10:06:34 -05:00 committed by GitHub
commit d21557a430
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -197,14 +197,17 @@ module.exports = {
nodir: true,
}).then(allFilePaths => {
const filePathStates = allFilePaths.reduce((p, c) => Object.assign(p, { [c]: true }), {});
patterns.forEach(p => {
const exclude = p.startsWith('!');
const pattern = exclude ? p.slice(1) : p;
nanomatch(allFilePaths, [pattern], { dot: true })
.forEach(key => {
filePathStates[key] = !exclude;
});
});
patterns
// nanomatch only does / style path delimiters, so convert them if on windows
.map(p => (process.platform === 'win32' ? p.replace(/\\/g, '/') : p))
.forEach(p => {
const exclude = p.startsWith('!');
const pattern = exclude ? p.slice(1) : p;
nanomatch(allFilePaths, [pattern], { dot: true })
.forEach(key => {
filePathStates[key] = !exclude;
});
});
const filePaths = _.toPairs(filePathStates).filter(r => r[1] === true).map(r => r[0]);
if (filePaths.length !== 0) return filePaths;
throw new this.serverless.classes.Error('No file matches include / exclude patterns');